@Test(dataProvider = "ImageStreams") public void testSuccessfulUploadTwice(InputStream imageStream, ImageReplication replicationType) throws Exception { this.inputStream = imageStream; imageEntity.setReplicationType(replicationType); imageStream = new BufferedInputStream(imageStream); imageStream.mark(MAX_VM_SIZE); step.createOrUpdateTransientResource(ImageUploadStepCmd.INPUT_STREAM, imageStream); ArgumentCaptor<InputStream> inputStreamArgument = ArgumentCaptor.forClass(InputStream.class); Map<String, String> imageSettings = new HashMap<>(); doNothing().when(imageBackend).updateSettings(imageEntity, imageSettings); doNothing().when(imageBackend).updateSize(imageEntity, imageSize); doNothing().when(imageBackend).updateImageDatastore(imageEntity.getId(), datastoreId); command.execute(); imageStream.reset(); command.execute(); verify(imageStore, times(2)).createImage(imageId); verify(imageStore, times(2)).finalizeImage(anyObject()); verify(imageStore, times(2)).getDatastore(); verify(image, times(2)).addDisk(anyString(), inputStreamArgument.capture()); InputStream capturedStream = inputStreamArgument.getAllValues().get(0); String capturedImage = OvaTestModule.readStringFromStream(capturedStream); assertEquals(capturedImage, ova.vmdkContent); verify(imageBackend, times(2)).updateSettings(eq(imageEntity), any(Map.class)); verify(imageBackend, times(2)).updateSize(imageEntity, imageSize); verify(imageBackend, times(2)).updateImageDatastore(eq(imageEntity.getId()), anyString()); verifyNoMoreInteractions(imageStore, imageBackend); }
@Override protected void execute() throws ApiFeException { InputStream inputStream = (InputStream) step.getTransientResource(INPUT_STREAM); checkNotNull(inputStream, "InputStream is not defined in TransientResource"); List<ImageEntity> entityList = step.getTransientResourceEntities(ImageEntity.KIND); checkArgument(entityList.size() == 1, "There should be only 1 image referenced by step %s", step.getId()); ImageEntity imageEntity = entityList.get(0); try { ImageLoader.Result result = getImageLoader().uploadImage(imageEntity, inputStream); imageBackend.updateSettings(imageEntity, result.imageSettings); imageBackend.updateSize(imageEntity, result.imageSize); imageBackend.updateImageDatastore(imageEntity.getId(), imageStore.getDatastore()); } catch (VmdkFormatException e) { imageBackend.updateState(imageEntity, ImageState.ERROR); throw new InvalidVmdkFormatException(e.getMessage()); } catch (ExternalException e) { imageBackend.updateState(imageEntity, ImageState.ERROR); throw e; } catch (Exception e) { imageBackend.updateState(imageEntity, ImageState.ERROR); throw new InternalException(e); } }
ImageUploadStepCmd extends StepCommand { @Override protected void execute() throws ApiFeException { InputStream inputStream = (InputStream) step.getTransientResource(INPUT_STREAM); checkNotNull(inputStream, "InputStream is not defined in TransientResource"); List<ImageEntity> entityList = step.getTransientResourceEntities(ImageEntity.KIND); checkArgument(entityList.size() == 1, "There should be only 1 image referenced by step %s", step.getId()); ImageEntity imageEntity = entityList.get(0); try { ImageLoader.Result result = getImageLoader().uploadImage(imageEntity, inputStream); imageBackend.updateSettings(imageEntity, result.imageSettings); imageBackend.updateSize(imageEntity, result.imageSize); imageBackend.updateImageDatastore(imageEntity.getId(), imageStore.getDatastore()); } catch (VmdkFormatException e) { imageBackend.updateState(imageEntity, ImageState.ERROR); throw new InvalidVmdkFormatException(e.getMessage()); } catch (ExternalException e) { imageBackend.updateState(imageEntity, ImageState.ERROR); throw e; } catch (Exception e) { imageBackend.updateState(imageEntity, ImageState.ERROR); throw new InternalException(e); } } }
ImageUploadStepCmd extends StepCommand { @Override protected void execute() throws ApiFeException { InputStream inputStream = (InputStream) step.getTransientResource(INPUT_STREAM); checkNotNull(inputStream, "InputStream is not defined in TransientResource"); List<ImageEntity> entityList = step.getTransientResourceEntities(ImageEntity.KIND); checkArgument(entityList.size() == 1, "There should be only 1 image referenced by step %s", step.getId()); ImageEntity imageEntity = entityList.get(0); try { ImageLoader.Result result = getImageLoader().uploadImage(imageEntity, inputStream); imageBackend.updateSettings(imageEntity, result.imageSettings); imageBackend.updateSize(imageEntity, result.imageSize); imageBackend.updateImageDatastore(imageEntity.getId(), imageStore.getDatastore()); } catch (VmdkFormatException e) { imageBackend.updateState(imageEntity, ImageState.ERROR); throw new InvalidVmdkFormatException(e.getMessage()); } catch (ExternalException e) { imageBackend.updateState(imageEntity, ImageState.ERROR); throw e; } catch (Exception e) { imageBackend.updateState(imageEntity, ImageState.ERROR); throw new InternalException(e); } } ImageUploadStepCmd(TaskCommand taskCommand, StepBackend stepBackend, StepEntity step,
                            ImageBackend imageBackend, ImageStore imageStore, ImageConfig imageConfig); }
ImageUploadStepCmd extends StepCommand { @Override protected void execute() throws ApiFeException { InputStream inputStream = (InputStream) step.getTransientResource(INPUT_STREAM); checkNotNull(inputStream, "InputStream is not defined in TransientResource"); List<ImageEntity> entityList = step.getTransientResourceEntities(ImageEntity.KIND); checkArgument(entityList.size() == 1, "There should be only 1 image referenced by step %s", step.getId()); ImageEntity imageEntity = entityList.get(0); try { ImageLoader.Result result = getImageLoader().uploadImage(imageEntity, inputStream); imageBackend.updateSettings(imageEntity, result.imageSettings); imageBackend.updateSize(imageEntity, result.imageSize); imageBackend.updateImageDatastore(imageEntity.getId(), imageStore.getDatastore()); } catch (VmdkFormatException e) { imageBackend.updateState(imageEntity, ImageState.ERROR); throw new InvalidVmdkFormatException(e.getMessage()); } catch (ExternalException e) { imageBackend.updateState(imageEntity, ImageState.ERROR); throw e; } catch (Exception e) { imageBackend.updateState(imageEntity, ImageState.ERROR); throw new InternalException(e); } } ImageUploadStepCmd(TaskCommand taskCommand, StepBackend stepBackend, StepEntity step,
                            ImageBackend imageBackend, ImageStore imageStore, ImageConfig imageConfig);  }
ImageUploadStepCmd extends StepCommand { @Override protected void execute() throws ApiFeException { InputStream inputStream = (InputStream) step.getTransientResource(INPUT_STREAM); checkNotNull(inputStream, "InputStream is not defined in TransientResource"); List<ImageEntity> entityList = step.getTransientResourceEntities(ImageEntity.KIND); checkArgument(entityList.size() == 1, "There should be only 1 image referenced by step %s", step.getId()); ImageEntity imageEntity = entityList.get(0); try { ImageLoader.Result result = getImageLoader().uploadImage(imageEntity, inputStream); imageBackend.updateSettings(imageEntity, result.imageSettings); imageBackend.updateSize(imageEntity, result.imageSize); imageBackend.updateImageDatastore(imageEntity.getId(), imageStore.getDatastore()); } catch (VmdkFormatException e) { imageBackend.updateState(imageEntity, ImageState.ERROR); throw new InvalidVmdkFormatException(e.getMessage()); } catch (ExternalException e) { imageBackend.updateState(imageEntity, ImageState.ERROR); throw e; } catch (Exception e) { imageBackend.updateState(imageEntity, ImageState.ERROR); throw new InternalException(e); } } ImageUploadStepCmd(TaskCommand taskCommand, StepBackend stepBackend, StepEntity step,
                            ImageBackend imageBackend, ImageStore imageStore, ImageConfig imageConfig);  static final String INPUT_STREAM; }