@Test public void testStaleAgent() throws Exception { when(hostClient.getNfcServiceTicket(anyString())).thenThrow(new DatastoreNotFoundException("datastore not found")) .thenReturn(serviceTicketResponse); step.createOrUpdateTransientResource(ImageUploadStepCmd.INPUT_STREAM, isoStream); when(vsphereIsoStore.uploadIsoFile(anyString(), any(InputStream.class))).thenReturn(isoSize); command.execute(); InOrder inOrder = inOrder(hostClient, vsphereIsoStore, vmBackend); inOrder.verify(hostClient, times(2)).getNfcServiceTicket(vmEntity.getDatastore()); inOrder.verify(hostClient).getHostIp(); inOrder.verify(vsphereIsoStore).setTarget(any(com.vmware.transfer.nfc.HostServiceTicket.class), anyString(), anyString()); inOrder.verify(vsphereIsoStore).uploadIsoFile( String.format("%s/%s", vmEntity.buildVmFolderPath(), isoEntity.getName()), isoStream); inOrder.verify(vmBackend).updateIsoEntitySize(isoEntity, isoSize); verifyNoMoreInteractions(hostClient, vsphereIsoStore, vmBackend); }
@Override protected void execute() throws ApiFeException, InterruptedException { InputStream inputStream = (InputStream) step.getTransientResource(INPUT_STREAM); checkNotNull(inputStream, "InputStream is not defined in TransientResource"); List<BaseEntity> vmList = step.getTransientResourceEntities(Vm.KIND); Preconditions.checkArgument(vmList.size() == 1, "There should be only 1 VM referenced by step %s", step.getId()); VmEntity vmEntity = (VmEntity) vmList.get(0); List<IsoEntity> isoList = step.getTransientResourceEntities(IsoEntity.KIND); Preconditions.checkArgument(isoList.size() == 1, "There should be only 1 ISO referenced by step %s", step.getId()); IsoEntity isoEntity = isoList.get(0); try { HostServiceTicket ticket = getNfcServiceTicketOp(vmEntity); isoStore.setTarget(ticket, vmEntity.getId(), vmEntity.getDatastoreName()); long size = isoStore.uploadIsoFile(String.format("%s/%s", vmEntity.buildVmFolderPath(), isoEntity.getName()), inputStream); vmBackend.updateIsoEntitySize(isoEntity, size); } catch (Exception e) { vmBackend.tombstoneIsoEntity(isoEntity); throw new ApiFeException(e); } }
IsoUploadStepCmd extends StepCommand { @Override protected void execute() throws ApiFeException, InterruptedException { InputStream inputStream = (InputStream) step.getTransientResource(INPUT_STREAM); checkNotNull(inputStream, "InputStream is not defined in TransientResource"); List<BaseEntity> vmList = step.getTransientResourceEntities(Vm.KIND); Preconditions.checkArgument(vmList.size() == 1, "There should be only 1 VM referenced by step %s", step.getId()); VmEntity vmEntity = (VmEntity) vmList.get(0); List<IsoEntity> isoList = step.getTransientResourceEntities(IsoEntity.KIND); Preconditions.checkArgument(isoList.size() == 1, "There should be only 1 ISO referenced by step %s", step.getId()); IsoEntity isoEntity = isoList.get(0); try { HostServiceTicket ticket = getNfcServiceTicketOp(vmEntity); isoStore.setTarget(ticket, vmEntity.getId(), vmEntity.getDatastoreName()); long size = isoStore.uploadIsoFile(String.format("%s/%s", vmEntity.buildVmFolderPath(), isoEntity.getName()), inputStream); vmBackend.updateIsoEntitySize(isoEntity, size); } catch (Exception e) { vmBackend.tombstoneIsoEntity(isoEntity); throw new ApiFeException(e); } } }
IsoUploadStepCmd extends StepCommand { @Override protected void execute() throws ApiFeException, InterruptedException { InputStream inputStream = (InputStream) step.getTransientResource(INPUT_STREAM); checkNotNull(inputStream, "InputStream is not defined in TransientResource"); List<BaseEntity> vmList = step.getTransientResourceEntities(Vm.KIND); Preconditions.checkArgument(vmList.size() == 1, "There should be only 1 VM referenced by step %s", step.getId()); VmEntity vmEntity = (VmEntity) vmList.get(0); List<IsoEntity> isoList = step.getTransientResourceEntities(IsoEntity.KIND); Preconditions.checkArgument(isoList.size() == 1, "There should be only 1 ISO referenced by step %s", step.getId()); IsoEntity isoEntity = isoList.get(0); try { HostServiceTicket ticket = getNfcServiceTicketOp(vmEntity); isoStore.setTarget(ticket, vmEntity.getId(), vmEntity.getDatastoreName()); long size = isoStore.uploadIsoFile(String.format("%s/%s", vmEntity.buildVmFolderPath(), isoEntity.getName()), inputStream); vmBackend.updateIsoEntitySize(isoEntity, size); } catch (Exception e) { vmBackend.tombstoneIsoEntity(isoEntity); throw new ApiFeException(e); } } IsoUploadStepCmd(TaskCommand taskCommand, StepBackend stepBackend, StepEntity step,
                          VmBackend vmBackend, VsphereIsoStore isoStore); }
IsoUploadStepCmd extends StepCommand { @Override protected void execute() throws ApiFeException, InterruptedException { InputStream inputStream = (InputStream) step.getTransientResource(INPUT_STREAM); checkNotNull(inputStream, "InputStream is not defined in TransientResource"); List<BaseEntity> vmList = step.getTransientResourceEntities(Vm.KIND); Preconditions.checkArgument(vmList.size() == 1, "There should be only 1 VM referenced by step %s", step.getId()); VmEntity vmEntity = (VmEntity) vmList.get(0); List<IsoEntity> isoList = step.getTransientResourceEntities(IsoEntity.KIND); Preconditions.checkArgument(isoList.size() == 1, "There should be only 1 ISO referenced by step %s", step.getId()); IsoEntity isoEntity = isoList.get(0); try { HostServiceTicket ticket = getNfcServiceTicketOp(vmEntity); isoStore.setTarget(ticket, vmEntity.getId(), vmEntity.getDatastoreName()); long size = isoStore.uploadIsoFile(String.format("%s/%s", vmEntity.buildVmFolderPath(), isoEntity.getName()), inputStream); vmBackend.updateIsoEntitySize(isoEntity, size); } catch (Exception e) { vmBackend.tombstoneIsoEntity(isoEntity); throw new ApiFeException(e); } } IsoUploadStepCmd(TaskCommand taskCommand, StepBackend stepBackend, StepEntity step,
                          VmBackend vmBackend, VsphereIsoStore isoStore);  }
IsoUploadStepCmd extends StepCommand { @Override protected void execute() throws ApiFeException, InterruptedException { InputStream inputStream = (InputStream) step.getTransientResource(INPUT_STREAM); checkNotNull(inputStream, "InputStream is not defined in TransientResource"); List<BaseEntity> vmList = step.getTransientResourceEntities(Vm.KIND); Preconditions.checkArgument(vmList.size() == 1, "There should be only 1 VM referenced by step %s", step.getId()); VmEntity vmEntity = (VmEntity) vmList.get(0); List<IsoEntity> isoList = step.getTransientResourceEntities(IsoEntity.KIND); Preconditions.checkArgument(isoList.size() == 1, "There should be only 1 ISO referenced by step %s", step.getId()); IsoEntity isoEntity = isoList.get(0); try { HostServiceTicket ticket = getNfcServiceTicketOp(vmEntity); isoStore.setTarget(ticket, vmEntity.getId(), vmEntity.getDatastoreName()); long size = isoStore.uploadIsoFile(String.format("%s/%s", vmEntity.buildVmFolderPath(), isoEntity.getName()), inputStream); vmBackend.updateIsoEntitySize(isoEntity, size); } catch (Exception e) { vmBackend.tombstoneIsoEntity(isoEntity); throw new ApiFeException(e); } } IsoUploadStepCmd(TaskCommand taskCommand, StepBackend stepBackend, StepEntity step,
                          VmBackend vmBackend, VsphereIsoStore isoStore);  static final String INPUT_STREAM; }