.generatePlacementZone(getHost(), hostState, clusterDetails, clusterName, clusterCreationTime) .thenCompose((generatedZone) -> { return PlacementZoneUtil.generatePlacement(getHost(), generatedZone) .thenApply((generatedPlacement) -> { generatedResourcesIds.add(generatedPlacement.documentSelfLink);
public static boolean isSchedulerPlacementZone(ResourcePoolState placementZone) { return getPlacementZoneType(placementZone) == PlacementZoneType.SCHEDULER; }
resourcePool.name = clusterName; } else { resourcePool.name = buildPlacementZoneDefaultName(hostType, hostState.address);
public static DeferredResult<Void> handlePostOrPut(Service service, Operation op) { ResourcePoolState placementZone = op.getBody(ResourcePoolState.class); if (PlacementZoneUtil.isSchedulerPlacementZone(placementZone)) { try { AssertUtil.assertEmpty(placementZone.tagLinks, "tagLinks"); } catch (LocalizableValidationException ex) { return DeferredResult.failed(ex); } return verifyZoneContainsSingleSchedulerOrNoHost(placementZone.documentSelfLink, op, service); } else { return verifyZoneContainsNoSchedulers(placementZone.documentSelfLink, op, service); } }
public static DeferredResult<ResourcePoolState> generatePlacementZone(ServiceHost serviceHost, ComputeState hostState) { return generatePlacementZone(serviceHost, hostState, null, null, null); }
@Test public void testGetVchCluster() throws Throwable { final String projectLink = buildProjectLink("test-vch-project"); PlacementZoneUtil.buildPlacementZoneDefaultName(ContainerHostType.VCH, COMPUTE_ADDRESS); ContainerHostSpec hostSpec = createContainerHostSpec(Collections.singletonList(projectLink), ContainerHostType.VCH); // mark the host as vch hostSpec.hostState.customProperties.put(PROPERTY_NAME_DRIVER, VMWARE_VIC_DRIVER1); ClusterDto clusterDto = createCluster(hostSpec); assertNotNull(clusterDto.nodeLinks); assertNotNull(clusterDto.nodes); assertEquals(1, clusterDto.nodes.size()); // verify the whole compute object is returned ComputeState vchHost = clusterDto.nodes.values().iterator().next(); assertNotNull(vchHost.customProperties); assertTrue(vchHost.customProperties.size() > 0); }
ContainerHostDataCollectionService.RESOURCE_POOL_CPU_USAGE_CUSTOM_PROP) .orElse(0.0); ClusterType type = PlacementZoneUtil.isSchedulerPlacementZone(resourcePoolState) ? ClusterType.VCH : ClusterType.DOCKER; ePZClusterDto.totalCpu = 0.0; } else { if (PlacementZoneUtil.isSchedulerPlacementZone(resourcePoolState)) { ePZClusterDto.address = computeStates.get(0).address; ePZClusterDto.totalCpu = PropertyUtils.getPropertyDouble(
@Test public void testCreateVchCluster() throws Throwable { final String projectLink = buildProjectLink("test-vch-project"); final String placementZoneName = PlacementZoneUtil .buildPlacementZoneDefaultName(ContainerHostType.VCH, COMPUTE_ADDRESS); ContainerHostSpec hostSpec = createContainerHostSpec(Collections.singletonList(projectLink), ContainerHostType.VCH); verifyCluster(createCluster(hostSpec), ClusterType.VCH, placementZoneName, projectLink); }
public static DeferredResult<Void> handlePatch(Service service, Operation op) { ResourcePoolState patchState = op.getBody(ResourcePoolState.class); Operation getOp = Operation.createGet(op.getUri()).setReferer(service.getUri()); return service.getHost().sendWithDeferredResult(getOp, ResourcePoolState.class) .thenCompose(currentState -> { AssertUtil.assertNotNull(currentState, "currentState"); ResourcePoolState rp = new ResourcePoolState(); rp.customProperties = PropertyUtils.mergeCustomProperties( currentState.customProperties, patchState.customProperties); // Now check whether the unified state is a scheduler if (PlacementZoneUtil.isSchedulerPlacementZone(rp)) { try { // shcedulers can have no tags AssertUtil.assertEmpty(currentState.tagLinks, "tagLinks"); AssertUtil.assertEmpty(patchState.tagLinks, "tagLinks"); } catch (LocalizableValidationException ex) { return DeferredResult.failed(ex); } // schedulers can have a single scheduler host at most return verifyZoneContainsSingleSchedulerOrNoHost( currentState.documentSelfLink, op, service); } else { // docker placement zones can have only docker hosts return verifyZoneContainsNoSchedulers(currentState.documentSelfLink, op, service); } }).thenAccept(ignore -> { }); }
Boolean.toString(true)); PlacementZoneUtil.generatePlacementZone(getHost(), hostState) .thenCompose((generatedZone) -> { generatedResourcesIds.add(generatedZone.documentSelfLink); hostState.resourcePoolLink = generatedZone.documentSelfLink; return PlacementZoneUtil.generatePlacement(getHost(), generatedZone); }) .thenAccept((generatedPlacement) -> {
try { PlacementZoneType zoneType = PlacementZoneUtil .getPlacementZoneType(placementZone); if (zoneType == expectedType) { successCallaback.run();
@Test(expected = LocalizableValidationException.class) public void testAddHostInVCHCluster() throws Throwable { final String projectLinkVCH = buildProjectLink("test-vch-project"); PlacementZoneUtil .buildPlacementZoneDefaultName(ContainerHostType.VCH, COMPUTE_ADDRESS); ContainerHostSpec hostSpecVCH = createContainerHostSpec( Collections.singletonList(projectLinkVCH), ContainerHostType.VCH); ClusterDto clusterVCH = createCluster(hostSpecVCH); ContainerHostSpec hostSpecDocker1 = createContainerHostSpec(projectLinkVCH); addHostInCluster(Service.getId(clusterVCH.documentSelfLink), hostSpecDocker1); }
ElasticPlacementZoneConfigurationState.class) .thenCompose(epzcs -> { if (PlacementZoneUtil.getPlacementZoneType( epzcs.resourcePoolState) == PlacementZoneType.DOCKER) { return sendWithDeferredResult(
@Test public void testDeleteVchCluster() throws Throwable { final String projectLink = buildProjectLink("test-vch-project"); final String placementZoneName = PlacementZoneUtil .buildPlacementZoneDefaultName(ContainerHostType.VCH, COMPUTE_ADDRESS); ContainerHostSpec hostSpec = createContainerHostSpec(Collections.singletonList(projectLink), ContainerHostType.VCH); ClusterDto clusterDto = createCluster(hostSpec); verifyCluster(clusterDto, ClusterType.VCH, placementZoneName, projectLink); Map<String, ClusterDto> allClustersExpand = getClustersExpand(); assertTrue(allClustersExpand.keySet().size() == 2); assertTrue(allClustersExpand.keySet().contains(clusterDto.documentSelfLink)); Map<String, ComputeState> allComputesExpand = getAllComputeExpand(); assertTrue(allComputesExpand.keySet().size() == 1); List<String> placementZonesLinks = getPlacementZonesLinks(); assertEquals(2, placementZonesLinks.size()); List<String> placementsLinks = getPlacementsLinks(); assertEquals(2, placementsLinks.size()); deleteCluster(Service.getId(clusterDto.documentSelfLink)); allClustersExpand = getClustersExpand(); assertTrue(allClustersExpand.keySet().size() == 1); assertTrue(!allClustersExpand.keySet().contains(clusterDto.documentSelfLink)); allComputesExpand = getAllComputeExpand(); assertTrue(allComputesExpand.keySet().isEmpty()); placementZonesLinks = getPlacementZonesLinks(); assertEquals(1, placementZonesLinks.size()); placementsLinks = getPlacementsLinks(); assertEquals(1, placementsLinks.size()); }
@Test public void testDeleteDockerCluster() throws Throwable { final String projectLink = buildProjectLink("test-docker-project"); final String placementZoneName = PlacementZoneUtil .buildPlacementZoneDefaultName(ContainerHostType.DOCKER, COMPUTE_ADDRESS); ContainerHostSpec hostSpec = createContainerHostSpec(Collections.singletonList(projectLink), ContainerHostType.DOCKER); ClusterDto clusterDto = createCluster(hostSpec); verifyCluster(clusterDto, ClusterType.DOCKER, placementZoneName, projectLink); Map<String, ClusterDto> allClustersExpand = getClustersExpand(); assertTrue(allClustersExpand.keySet().size() == 2); assertTrue(allClustersExpand.keySet().contains(clusterDto.documentSelfLink)); Map<String, ComputeState> allComputesExpand = getAllComputeExpand(); assertTrue(allComputesExpand.keySet().size() == 1); List<String> placementZonesLinks = getPlacementZonesLinks(); assertEquals(2, placementZonesLinks.size()); List<String> placementsLinks = getPlacementsLinks(); assertEquals(2, placementsLinks.size()); deleteCluster(Service.getId(clusterDto.documentSelfLink)); allClustersExpand = getClustersExpand(); assertTrue(allClustersExpand.keySet().size() == 1); assertTrue(!allClustersExpand.keySet().contains(clusterDto.documentSelfLink)); allComputesExpand = getAllComputeExpand(); assertTrue(allComputesExpand.keySet().isEmpty()); placementZonesLinks = getPlacementZonesLinks(); assertEquals(1, placementZonesLinks.size()); placementsLinks = getPlacementsLinks(); assertEquals(1, placementsLinks.size()); }
@Test public void testCreateDockerCluster() throws Throwable { final String projectLink = buildProjectLink("test-docker-project"); final String placementZoneName = PlacementZoneUtil .buildPlacementZoneDefaultName(ContainerHostType.DOCKER, COMPUTE_ADDRESS); ContainerHostSpec hostSpec = createContainerHostSpec(Collections.singletonList(projectLink), ContainerHostType.DOCKER); ClusterDto clusterDto = createCluster(hostSpec); verifyCluster(clusterDto, ClusterType.DOCKER, placementZoneName, projectLink); // create the host with the specified id assertNotNull(hostSpec.hostState.id); assertNotEquals("", hostSpec.hostState.id); ComputeState host = getDocument(ComputeState.class, clusterDto.nodeLinks.get(0)); assertEquals(hostSpec.hostState.id, host.id); }
@Test public void testGetSingleHostsInCluster() throws Throwable { final String projectLinkDocker = buildProjectLink("test-docker-project"); PlacementZoneUtil .buildPlacementZoneDefaultName(ContainerHostType.DOCKER, COMPUTE_ADDRESS); ContainerHostSpec hostSpecDocker = createContainerHostSpec( Collections.singletonList(projectLinkDocker), ContainerHostType.DOCKER); final String projectLinkVCH = buildProjectLink("test-vch-project"); PlacementZoneUtil .buildPlacementZoneDefaultName(ContainerHostType.VCH, COMPUTE_ADDRESS); ContainerHostSpec hostSpecVCH = createContainerHostSpec( Collections.singletonList(projectLinkVCH), ContainerHostType.VCH); ClusterDto clusterDocker = createCluster(hostSpecDocker); ClusterDto clusterVCH = createCluster(hostSpecVCH); ComputeState cs = getSingleHostInOneCluster( Service.getId(clusterDocker.documentSelfLink), Service.getId(clusterDocker.nodeLinks.get(0)), false); assertNotNull(cs); assertEquals(clusterDocker.nodeLinks.get(0), cs.documentSelfLink); cs = getSingleHostInOneCluster( Service.getId(clusterVCH.documentSelfLink), Service.getId(clusterDocker.nodeLinks.get(0)), true); assertTrue(cs == null); }
@Test public void testGetOneCluster() throws Throwable { final String projectLinkDocker = buildProjectLink("test-docker-project"); final String placementZoneNameDocker = PlacementZoneUtil .buildPlacementZoneDefaultName(ContainerHostType.DOCKER, COMPUTE_ADDRESS); ContainerHostSpec hostSpecDocker = createContainerHostSpec( Collections.singletonList(projectLinkDocker), ContainerHostType.DOCKER); ClusterDto clusterDocker = createCluster(hostSpecDocker); clusterDocker = getOneCluster(Service.getId(clusterDocker.documentSelfLink)); assertNotNull(clusterDocker); assertEquals(placementZoneNameDocker, clusterDocker.name); }
final String projectLinkDocker = buildProjectLink("test-docker-project"); final String placementZoneNameDocker = PlacementZoneUtil .buildPlacementZoneDefaultName(ContainerHostType.DOCKER, COMPUTE_ADDRESS); .buildPlacementZoneDefaultName(ContainerHostType.VCH, COMPUTE_ADDRESS);
final String projectLinkDocker = buildProjectLink("test-docker-project"); PlacementZoneUtil .buildPlacementZoneDefaultName(ContainerHostType.DOCKER, COMPUTE_ADDRESS);