@Test public void testInternalException() throws Throwable { doThrow(new IOException()).when(imageLoader).createImageFromVm(image, vm.getId(), vm.getHost()); try { command.execute(); fail("Exception expected."); } catch (InternalException e) { } InOrder inOrder = inOrder(imageBackend, imageLoader); inOrder.verify(imageLoader).createImageFromVm(image, vm.getId(), vm.getHost()); inOrder.verify(imageBackend).updateState(image, ImageState.ERROR); verifyNoMoreInteractions(imageBackend, imageLoader); }
@Override protected void execute() throws ApiFeException, InterruptedException, RpcException { List<VmEntity> vmList = step.getTransientResourceEntities(Vm.KIND); Preconditions.checkArgument(vmList.size() == 1, "There should be only 1 VM referenced by step %s", step.getId()); VmEntity vm = vmList.get(0); List<ImageEntity> imageList = step.getTransientResourceEntities(Image.KIND); Preconditions.checkArgument(imageList.size() == 2, "There should be 2 images referenced by step %s", step.getId()); ImageEntity imageEntity = imageList.get(0); ImageEntity vmImage = imageList.get(1); Preconditions.checkState( Objects.equals(vmImage.getId(), vm.getImageId()), "image id is inconsistent: %s v.s. %s", vmImage.getId(), vm.getImageId()); try { getImageLoader().createImageFromVm(imageEntity, vm.getId(), vm.getHost()); imageBackend.updateImageDatastore(imageEntity.getId(), imageStore.getDatastore()); } catch (ExternalException e) { imageBackend.updateState(imageEntity, ImageState.ERROR); throw e; } catch (Exception e) { imageBackend.updateState(imageEntity, ImageState.ERROR); throw new InternalException(e); } }
VmCreateImageStepCmd extends StepCommand { @Override protected void execute() throws ApiFeException, InterruptedException, RpcException { List<VmEntity> vmList = step.getTransientResourceEntities(Vm.KIND); Preconditions.checkArgument(vmList.size() == 1, "There should be only 1 VM referenced by step %s", step.getId()); VmEntity vm = vmList.get(0); List<ImageEntity> imageList = step.getTransientResourceEntities(Image.KIND); Preconditions.checkArgument(imageList.size() == 2, "There should be 2 images referenced by step %s", step.getId()); ImageEntity imageEntity = imageList.get(0); ImageEntity vmImage = imageList.get(1); Preconditions.checkState( Objects.equals(vmImage.getId(), vm.getImageId()), "image id is inconsistent: %s v.s. %s", vmImage.getId(), vm.getImageId()); try { getImageLoader().createImageFromVm(imageEntity, vm.getId(), vm.getHost()); imageBackend.updateImageDatastore(imageEntity.getId(), imageStore.getDatastore()); } catch (ExternalException e) { imageBackend.updateState(imageEntity, ImageState.ERROR); throw e; } catch (Exception e) { imageBackend.updateState(imageEntity, ImageState.ERROR); throw new InternalException(e); } } }
VmCreateImageStepCmd extends StepCommand { @Override protected void execute() throws ApiFeException, InterruptedException, RpcException { List<VmEntity> vmList = step.getTransientResourceEntities(Vm.KIND); Preconditions.checkArgument(vmList.size() == 1, "There should be only 1 VM referenced by step %s", step.getId()); VmEntity vm = vmList.get(0); List<ImageEntity> imageList = step.getTransientResourceEntities(Image.KIND); Preconditions.checkArgument(imageList.size() == 2, "There should be 2 images referenced by step %s", step.getId()); ImageEntity imageEntity = imageList.get(0); ImageEntity vmImage = imageList.get(1); Preconditions.checkState( Objects.equals(vmImage.getId(), vm.getImageId()), "image id is inconsistent: %s v.s. %s", vmImage.getId(), vm.getImageId()); try { getImageLoader().createImageFromVm(imageEntity, vm.getId(), vm.getHost()); imageBackend.updateImageDatastore(imageEntity.getId(), imageStore.getDatastore()); } catch (ExternalException e) { imageBackend.updateState(imageEntity, ImageState.ERROR); throw e; } catch (Exception e) { imageBackend.updateState(imageEntity, ImageState.ERROR); throw new InternalException(e); } } VmCreateImageStepCmd(TaskCommand taskCommand, StepBackend stepBackend, StepEntity step,
                              ImageBackend imageBackend, ImageStore imageStore); }
VmCreateImageStepCmd extends StepCommand { @Override protected void execute() throws ApiFeException, InterruptedException, RpcException { List<VmEntity> vmList = step.getTransientResourceEntities(Vm.KIND); Preconditions.checkArgument(vmList.size() == 1, "There should be only 1 VM referenced by step %s", step.getId()); VmEntity vm = vmList.get(0); List<ImageEntity> imageList = step.getTransientResourceEntities(Image.KIND); Preconditions.checkArgument(imageList.size() == 2, "There should be 2 images referenced by step %s", step.getId()); ImageEntity imageEntity = imageList.get(0); ImageEntity vmImage = imageList.get(1); Preconditions.checkState( Objects.equals(vmImage.getId(), vm.getImageId()), "image id is inconsistent: %s v.s. %s", vmImage.getId(), vm.getImageId()); try { getImageLoader().createImageFromVm(imageEntity, vm.getId(), vm.getHost()); imageBackend.updateImageDatastore(imageEntity.getId(), imageStore.getDatastore()); } catch (ExternalException e) { imageBackend.updateState(imageEntity, ImageState.ERROR); throw e; } catch (Exception e) { imageBackend.updateState(imageEntity, ImageState.ERROR); throw new InternalException(e); } } VmCreateImageStepCmd(TaskCommand taskCommand, StepBackend stepBackend, StepEntity step,
                              ImageBackend imageBackend, ImageStore imageStore);  }
VmCreateImageStepCmd extends StepCommand { @Override protected void execute() throws ApiFeException, InterruptedException, RpcException { List<VmEntity> vmList = step.getTransientResourceEntities(Vm.KIND); Preconditions.checkArgument(vmList.size() == 1, "There should be only 1 VM referenced by step %s", step.getId()); VmEntity vm = vmList.get(0); List<ImageEntity> imageList = step.getTransientResourceEntities(Image.KIND); Preconditions.checkArgument(imageList.size() == 2, "There should be 2 images referenced by step %s", step.getId()); ImageEntity imageEntity = imageList.get(0); ImageEntity vmImage = imageList.get(1); Preconditions.checkState( Objects.equals(vmImage.getId(), vm.getImageId()), "image id is inconsistent: %s v.s. %s", vmImage.getId(), vm.getImageId()); try { getImageLoader().createImageFromVm(imageEntity, vm.getId(), vm.getHost()); imageBackend.updateImageDatastore(imageEntity.getId(), imageStore.getDatastore()); } catch (ExternalException e) { imageBackend.updateState(imageEntity, ImageState.ERROR); throw e; } catch (Exception e) { imageBackend.updateState(imageEntity, ImageState.ERROR); throw new InternalException(e); } } VmCreateImageStepCmd(TaskCommand taskCommand, StepBackend stepBackend, StepEntity step,
                              ImageBackend imageBackend, ImageStore imageStore);   }