@Test public void testSuccessfulVmExecutionWithEphemeralDiskAttached() throws Exception { List<QuotaLineItem> quotaLineItems = new ArrayList<>(); quotaLineItems.add(new QuotaLineItem("ephemeral-disk.cost", "10000.0", com.vmware.photon.controller.flavors.gen.QuotaUnit.COUNT)); quotaLineItems.add(new QuotaLineItem("ephemeral-disk.capacity", "0.0", com.vmware.photon.controller.flavors.gen.QuotaUnit.GB)); quotaLineItems.add(new QuotaLineItem("storage.SHARED_VMFS", "1.0", com.vmware.photon.controller.flavors.gen.QuotaUnit.COUNT)); Flavor expectedDiskFlavor = new Flavor(); expectedDiskFlavor.setName("ephemeral-disk-10000"); expectedDiskFlavor.setCost(quotaLineItems); attachEphemeralDisk(vm); ResourceReserveStepCmd command = getVmReservationCommand(); PlacementTask placementTask = generateResourcePlacementList(); placementTask.resource.getPlacement_list().addToPlacements( generateResourcePlacement(ResourcePlacementType.VM, "vm-id")); placementTask.resource.getPlacement_list().addToPlacements( generateResourcePlacement(ResourcePlacementType.DISK, "disk-id")); Operation placementOperation = new Operation().setBody(placementTask); when(photonControllerXenonRestClient.post(any(), any(), anyLong())).thenReturn(placementOperation); when(hostClient.reserve(any(Resource.class), eq(SUCCESSFUL_GENERATION))).thenReturn(SUCCESSFUL_RESERVE_RESPONSE); command.execute(); verify(photonControllerXenonRestClient).post(any(), placementTaskCaptor.capture(), anyLong()); Resource resource = placementTaskCaptor.getValue().resource; assertThat(resource.getVm().isSetResource_constraints(), is(true)); assertThat(resource.getVm().getResource_constraints().size(), is(2)); assertThat(resource.getVm().getResource_constraints().get(0).getType(), is(ResourceConstraintType.DATASTORE_TAG)); assertThat(resource.getVm().getResource_constraints().get(0).getValues().equals(ImmutableList.of("SHARED_VMFS")), is(true)); assertThat(resource.getVm().getDisks().size(), is(vm.getAttachedDisks().size())); assertThat(resource.getVm().getDisks().get(0).getId(), is("disk1")); assertThat(resource.getVm().getDisks().get(0).getFlavor_info(), is(expectedDiskFlavor)); assertThat(resource.getVm().getDisks().get(0).isSetResource_constraints(), is(false)); assertThat(resource.getPlacement_list().getPlacements().size(), is(1 + vm.getAttachedDisks().size())); assertThat(resource.getPlacement_list().getPlacements().get(0).getType(), is(ResourcePlacementType.VM)); assertThat(resource.getPlacement_list().getPlacements().get(1).getType(), is(ResourcePlacementType.DISK)); }
@Override protected void execute() throws ApiFeException, InterruptedException, RpcException { List<BaseEntity> entityList = step.getTransientResourceEntities(); for (BaseEntity entity : entityList) { if (!entity.getKind().equals(Vm.KIND) && !entity.getKind().equals(PersistentDisk.KIND)) { continue; } infrastructureEntity = (InfrastructureEntity) entity; } Preconditions.checkArgument(infrastructureEntity != null, "There should be at least one InfrastructureEntity referenced by step %s", step.getId()); Resource resource = createResource(infrastructureEntity); taskCommand.setResource(resource); String reservation; if (infrastructureEntity.getKind().equals(Vm.KIND)) { String targetHostIp = ((VmEntity) infrastructureEntity).getHostAffinity(); reservation = loadReservation(resource, targetHostIp, infrastructureEntity.getKind()); } else { reservation = loadReservation(resource, infrastructureEntity.getKind()); } taskCommand.setReservation(reservation); }
ResourceReserveStepCmd extends StepCommand { @Override protected void execute() throws ApiFeException, InterruptedException, RpcException { List<BaseEntity> entityList = step.getTransientResourceEntities(); for (BaseEntity entity : entityList) { if (!entity.getKind().equals(Vm.KIND) && !entity.getKind().equals(PersistentDisk.KIND)) { continue; } infrastructureEntity = (InfrastructureEntity) entity; } Preconditions.checkArgument(infrastructureEntity != null, "There should be at least one InfrastructureEntity referenced by step %s", step.getId()); Resource resource = createResource(infrastructureEntity); taskCommand.setResource(resource); String reservation; if (infrastructureEntity.getKind().equals(Vm.KIND)) { String targetHostIp = ((VmEntity) infrastructureEntity).getHostAffinity(); reservation = loadReservation(resource, targetHostIp, infrastructureEntity.getKind()); } else { reservation = loadReservation(resource, infrastructureEntity.getKind()); } taskCommand.setReservation(reservation); } }
ResourceReserveStepCmd extends StepCommand { @Override protected void execute() throws ApiFeException, InterruptedException, RpcException { List<BaseEntity> entityList = step.getTransientResourceEntities(); for (BaseEntity entity : entityList) { if (!entity.getKind().equals(Vm.KIND) && !entity.getKind().equals(PersistentDisk.KIND)) { continue; } infrastructureEntity = (InfrastructureEntity) entity; } Preconditions.checkArgument(infrastructureEntity != null, "There should be at least one InfrastructureEntity referenced by step %s", step.getId()); Resource resource = createResource(infrastructureEntity); taskCommand.setResource(resource); String reservation; if (infrastructureEntity.getKind().equals(Vm.KIND)) { String targetHostIp = ((VmEntity) infrastructureEntity).getHostAffinity(); reservation = loadReservation(resource, targetHostIp, infrastructureEntity.getKind()); } else { reservation = loadReservation(resource, infrastructureEntity.getKind()); } taskCommand.setReservation(reservation); } ResourceReserveStepCmd(TaskCommand taskCommand,
                                StepBackend stepBackend,
                                StepEntity step,
                                DiskBackend diskBackend,
                                VmBackend vmBackend,
                                NetworkBackend networkBackend,
                                FlavorBackend flavorBackend,
                                Boolean useVirtualNetwork); }
ResourceReserveStepCmd extends StepCommand { @Override protected void execute() throws ApiFeException, InterruptedException, RpcException { List<BaseEntity> entityList = step.getTransientResourceEntities(); for (BaseEntity entity : entityList) { if (!entity.getKind().equals(Vm.KIND) && !entity.getKind().equals(PersistentDisk.KIND)) { continue; } infrastructureEntity = (InfrastructureEntity) entity; } Preconditions.checkArgument(infrastructureEntity != null, "There should be at least one InfrastructureEntity referenced by step %s", step.getId()); Resource resource = createResource(infrastructureEntity); taskCommand.setResource(resource); String reservation; if (infrastructureEntity.getKind().equals(Vm.KIND)) { String targetHostIp = ((VmEntity) infrastructureEntity).getHostAffinity(); reservation = loadReservation(resource, targetHostIp, infrastructureEntity.getKind()); } else { reservation = loadReservation(resource, infrastructureEntity.getKind()); } taskCommand.setReservation(reservation); } ResourceReserveStepCmd(TaskCommand taskCommand,
                                StepBackend stepBackend,
                                StepEntity step,
                                DiskBackend diskBackend,
                                VmBackend vmBackend,
                                NetworkBackend networkBackend,
                                FlavorBackend flavorBackend,
                                Boolean useVirtualNetwork);  }
ResourceReserveStepCmd extends StepCommand { @Override protected void execute() throws ApiFeException, InterruptedException, RpcException { List<BaseEntity> entityList = step.getTransientResourceEntities(); for (BaseEntity entity : entityList) { if (!entity.getKind().equals(Vm.KIND) && !entity.getKind().equals(PersistentDisk.KIND)) { continue; } infrastructureEntity = (InfrastructureEntity) entity; } Preconditions.checkArgument(infrastructureEntity != null, "There should be at least one InfrastructureEntity referenced by step %s", step.getId()); Resource resource = createResource(infrastructureEntity); taskCommand.setResource(resource); String reservation; if (infrastructureEntity.getKind().equals(Vm.KIND)) { String targetHostIp = ((VmEntity) infrastructureEntity).getHostAffinity(); reservation = loadReservation(resource, targetHostIp, infrastructureEntity.getKind()); } else { reservation = loadReservation(resource, infrastructureEntity.getKind()); } taskCommand.setReservation(reservation); } ResourceReserveStepCmd(TaskCommand taskCommand,
                                StepBackend stepBackend,
                                StepEntity step,
                                DiskBackend diskBackend,
                                VmBackend vmBackend,
                                NetworkBackend networkBackend,
                                FlavorBackend flavorBackend,
                                Boolean useVirtualNetwork);  static final String LOGICAL_SWITCH_ID; static final String VIRTUAL_NETWORK_ID; static final String VM_ID; }