@Test public void testFailedGetServiceTicket() throws Throwable { when(hostClient.getNfcServiceTicket(anyString())).thenThrow(new SystemErrorException("e")); step.createOrUpdateTransientResource(ImageUploadStepCmd.INPUT_STREAM, isoStream); try { command.execute(); fail("should have failed due to SystemErrorException exception"); } catch (Exception e) { } }
@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; }