@Test public void testSuccessfulVmExecutionWithDiskAffinities() throws Throwable { List<QuotaLineItem> quotaLineItems = new ArrayList<>(); quotaLineItems.add(new QuotaLineItem("vm.cost", "100.0", com.vmware.photon.controller.flavors.gen.QuotaUnit.COUNT)); Flavor expectedFlavor = new Flavor(); expectedFlavor.setName("vm-100"); expectedFlavor.setCost(quotaLineItems); PersistentDiskEntity disk1 = new PersistentDiskEntity(); PersistentDiskEntity disk2 = new PersistentDiskEntity(); disk1.setDatastore("datastore-1"); disk2.setDatastore("datastore-1"); when(diskBackend.find(PersistentDisk.KIND, "disk-1")).thenReturn(disk1); when(diskBackend.find(PersistentDisk.KIND, "disk-2")).thenReturn(disk2); List<LocalityEntity> affinities = new ArrayList<>(); LocalityEntity localityEntity1 = new LocalityEntity(); localityEntity1.setResourceId("disk-1"); localityEntity1.setKind("disk"); LocalityEntity localityEntity2 = new LocalityEntity(); localityEntity2.setResourceId("disk-2"); localityEntity2.setKind("disk"); affinities.add(localityEntity1); affinities.add(localityEntity2); vm.setAffinities(affinities); PlacementTask placementTask = generateResourcePlacementList(); placementTask.resource.getPlacement_list().addToPlacements( generateResourcePlacement(ResourcePlacementType.VM, "vm-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); ResourceReserveStepCmd command = getVmReservationCommand(); command.execute(); verify(photonControllerXenonRestClient).post(any(), placementTaskCaptor.capture(), anyLong()); Resource resource = placementTaskCaptor.getValue().resource; assertThat(resource.getVm().getResource_constraints().size(), is(vm.getAffinities().size() + 1)); assertThat(resource.getVm().getResource_constraints().get(0).getType(), is(ResourceConstraintType.DATASTORE)); assertThat(resource.getVm().getResource_constraints().get(0).getValues().equals(ImmutableList.of("datastore-1")), is(true)); assertThat(resource.getVm().getResource_constraints().get(1).getType(), is(ResourceConstraintType.DATASTORE)); assertThat(resource.getVm().getResource_constraints().get(1).getValues().equals(ImmutableList.of("datastore-1")), is(true)); verify(photonControllerXenonRestClient).post(any(), placementTaskCaptor.capture(), anyLong()); verify(hostClient).reserve(resourceCaptor.capture(), eq(SUCCESSFUL_GENERATION)); assertThat(placementTaskCaptor.getValue().resource, is(resource)); assertThat(resourceCaptor.getValue(), is(resource)); }
@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; }