@Test(dataProvider = "operations") public void testOperation(Operation operation, PowerVmOp expectedPowerOp, VmState previousState, VmState expectedState) throws Exception { vm.setState(previousState); VmPowerOpStepCmd command = getVmPowerOpStepCmd(); vm.setAgent("some-agent"); step.setOperation(operation); when(hostClient.powerVmOp(anyString(), any(PowerVmOp.class))).thenReturn( new PowerVmOpResponse(PowerVmOpResultCode.OK)); command.execute(); InOrder inOrder = inOrder(hostClient, vmBackend); inOrder.verify(hostClient).setHostIp("host-ip"); inOrder.verify(hostClient).powerVmOp("vm-1", expectedPowerOp); inOrder.verify(vmBackend).updateState(vm, expectedState); verifyNoMoreInteractions(hostClient, vmBackend); }
@Override protected void execute() throws ApiFeException, InterruptedException, RpcException { Operation operation = step.getOperation(); PowerVmOp powerOp = OP_MAPPING.get(operation); checkArgument(powerOp != null, "Invalid operation: {}", operation); List<VmEntity> entityList = step.getTransientResourceEntities(Vm.KIND); checkArgument(entityList.size() == 1, "There should be only 1 VM referenced by step %s", step.getId()); VmEntity vm = entityList.get(0); try { taskCommand.getHostClient(vm).powerVmOp(vm.getId(), powerOp); } catch (VmNotFoundException ex) { taskCommand.getHostClient(vm, false).powerVmOp(vm.getId(), powerOp); } vmBackend.updateState(vm, OP_STATE.get(powerOp)); logger.info("Operation of {} is completed for VM {}", powerOp, vm); }
VmPowerOpStepCmd extends StepCommand { @Override protected void execute() throws ApiFeException, InterruptedException, RpcException { Operation operation = step.getOperation(); PowerVmOp powerOp = OP_MAPPING.get(operation); checkArgument(powerOp != null, "Invalid operation: {}", operation); List<VmEntity> entityList = step.getTransientResourceEntities(Vm.KIND); checkArgument(entityList.size() == 1, "There should be only 1 VM referenced by step %s", step.getId()); VmEntity vm = entityList.get(0); try { taskCommand.getHostClient(vm).powerVmOp(vm.getId(), powerOp); } catch (VmNotFoundException ex) { taskCommand.getHostClient(vm, false).powerVmOp(vm.getId(), powerOp); } vmBackend.updateState(vm, OP_STATE.get(powerOp)); logger.info("Operation of {} is completed for VM {}", powerOp, vm); } }
VmPowerOpStepCmd extends StepCommand { @Override protected void execute() throws ApiFeException, InterruptedException, RpcException { Operation operation = step.getOperation(); PowerVmOp powerOp = OP_MAPPING.get(operation); checkArgument(powerOp != null, "Invalid operation: {}", operation); List<VmEntity> entityList = step.getTransientResourceEntities(Vm.KIND); checkArgument(entityList.size() == 1, "There should be only 1 VM referenced by step %s", step.getId()); VmEntity vm = entityList.get(0); try { taskCommand.getHostClient(vm).powerVmOp(vm.getId(), powerOp); } catch (VmNotFoundException ex) { taskCommand.getHostClient(vm, false).powerVmOp(vm.getId(), powerOp); } vmBackend.updateState(vm, OP_STATE.get(powerOp)); logger.info("Operation of {} is completed for VM {}", powerOp, vm); } VmPowerOpStepCmd(TaskCommand taskCommand,
                          StepBackend stepBackend,
                          StepEntity step,
                          VmBackend vmBackend); }
VmPowerOpStepCmd extends StepCommand { @Override protected void execute() throws ApiFeException, InterruptedException, RpcException { Operation operation = step.getOperation(); PowerVmOp powerOp = OP_MAPPING.get(operation); checkArgument(powerOp != null, "Invalid operation: {}", operation); List<VmEntity> entityList = step.getTransientResourceEntities(Vm.KIND); checkArgument(entityList.size() == 1, "There should be only 1 VM referenced by step %s", step.getId()); VmEntity vm = entityList.get(0); try { taskCommand.getHostClient(vm).powerVmOp(vm.getId(), powerOp); } catch (VmNotFoundException ex) { taskCommand.getHostClient(vm, false).powerVmOp(vm.getId(), powerOp); } vmBackend.updateState(vm, OP_STATE.get(powerOp)); logger.info("Operation of {} is completed for VM {}", powerOp, vm); } VmPowerOpStepCmd(TaskCommand taskCommand,
                          StepBackend stepBackend,
                          StepEntity step,
                          VmBackend vmBackend);  }
VmPowerOpStepCmd extends StepCommand { @Override protected void execute() throws ApiFeException, InterruptedException, RpcException { Operation operation = step.getOperation(); PowerVmOp powerOp = OP_MAPPING.get(operation); checkArgument(powerOp != null, "Invalid operation: {}", operation); List<VmEntity> entityList = step.getTransientResourceEntities(Vm.KIND); checkArgument(entityList.size() == 1, "There should be only 1 VM referenced by step %s", step.getId()); VmEntity vm = entityList.get(0); try { taskCommand.getHostClient(vm).powerVmOp(vm.getId(), powerOp); } catch (VmNotFoundException ex) { taskCommand.getHostClient(vm, false).powerVmOp(vm.getId(), powerOp); } vmBackend.updateState(vm, OP_STATE.get(powerOp)); logger.info("Operation of {} is completed for VM {}", powerOp, vm); } VmPowerOpStepCmd(TaskCommand taskCommand,
                          StepBackend stepBackend,
                          StepEntity step,
                          VmBackend vmBackend);   }