@Test public void testSuccessfulDiskExecution() throws Exception { List<LocalityEntity> affinities = new ArrayList<>(); LocalityEntity localityEntity1 = new LocalityEntity(); localityEntity1.setResourceId("vm-1"); localityEntity1.setKind("vm"); LocalityEntity localityEntity2 = new LocalityEntity(); localityEntity2.setResourceId("vm-2"); localityEntity2.setKind("vm"); affinities.add(localityEntity1); affinities.add(localityEntity2); disk.setAffinities(affinities); ResourceReserveStepCmd command = getDiskReservationCommand(); PlacementTask placementTask = generateResourcePlacementList(); 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); when(vmBackend.findDatastoreByVmId("vm-1")).thenReturn("datastore-2"); when(vmBackend.findDatastoreByVmId("vm-2")).thenReturn("datastore-2"); command.execute(); verify(photonControllerXenonRestClient).post(any(), placementTaskCaptor.capture(), anyLong()); Resource resource = placementTaskCaptor.getValue().resource; assertThat(resource.getDisks().get(0).getId(), is("disk-1")); assertThat(resource.getDisks().get(0).getResource_constraints().get(0).getType(), is(ResourceConstraintType.DATASTORE)); assertThat( resource.getDisks().get(0).getResource_constraints().get(0).getValues() .equals(ImmutableList.of("datastore-2")), is(true)); assertThat( resource.getDisks().get(0).getResource_constraints().get(1).getValues() .equals(ImmutableList.of("datastore-2")), is(true)); assertThat(resource.getDisks().get(0).getResource_constraints().get(2).getType(), is(ResourceConstraintType .DATASTORE_TAG)); assertThat(resource.getDisks().get(0).getResource_constraints().get(2).getValues().equals(ImmutableList.of( "LOCAL_VMFS")), is(true)); assertThat(resource.getPlacement_list().getPlacements().get(0).getType(), is(ResourcePlacementType.DISK)); assertThat(resource.getPlacement_list().getPlacements().get(0).getResource_id(), is("disk-id")); 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; }