@Test(expectedExceptions = InvalidVmPowerStateException.class) public void testFailedResponse() throws Throwable { VmPowerOpStepCmd command = getVmPowerOpStepCmd(); Operation operation = Operation.START_VM; step.setOperation(operation); vm.setAgent("some-agent"); when(hostClient.powerVmOp(anyString(), any(PowerVmOp.class))).thenThrow( new InvalidVmPowerStateException("Error")); command.execute(); }
@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);   }