@Test public void testCustomStatsAdapter() throws Throwable { ResourcePoolState rpState = new ResourcePoolState(); rpState.name = UUID.randomUUID().toString(); ResourcePoolState rpReturnState = postServiceSynchronously(
ResourcePoolService.FACTORY_LINK, clusterId); ResourcePoolState resourcePool = new ResourcePoolState(); resourcePool.documentSelfLink = UriUtils.buildUriPath(ResourcePoolService.FACTORY_LINK, clusterId);
ResourcePoolState rpPatchState = new ResourcePoolState(); rpPatchState.documentSelfLink = resourcePoolState.documentSelfLink; rpPatchState.customProperties = new HashMap<>();
ResourcePoolState resourcePool = new ResourcePoolState(); if (clusterName != null && !clusterName.isEmpty()) { resourcePool.name = clusterName;
doPost(createDeploymentPolicy(), DeploymentPolicyService.FACTORY_LINK); ResourcePoolState resourcePool = new ResourcePoolState(); resourcePool.name = "test-resource-pool"; resourcePool = doPost(resourcePool, ResourcePoolService.FACTORY_LINK);
ComputeDescriptionService.FACTORY_LINK); ResourcePoolState resourcePool = new ResourcePoolState(); resourcePool.name = "test-resource-pool"; resourcePool = doPost(host, resourcePool, ResourcePoolService.FACTORY_LINK);
@Test public void testScheduleTaskUpdateNextMaintenanceTime() throws Throwable { ScheduledTaskService.ScheduledTaskState taskState = buildValidStartState(); Long currentTimeMicros = Utils.getNowMicrosUtc(); taskState.intervalMicros = TimeUnit.SECONDS.toMicros(1); ResourcePoolState inPool = new ResourcePoolState(); inPool.name = UUID.randomUUID().toString(); inPool.id = inPool.name; inPool.minCpuCount = 1L; inPool.minMemoryBytes = 1024L; taskState.factoryLink = ResourcePoolService.FACTORY_LINK; taskState.initialStateJson = Utils.toJson(inPool); ScheduledTaskService.ScheduledTaskState returnState = this.postServiceSynchronously( ScheduledTaskService.FACTORY_LINK, taskState, ScheduledTaskService.ScheduledTaskState.class); assertEquals(taskState.customProperties, returnState.customProperties); assertEquals(taskState.initialStateJson, returnState.initialStateJson); assertEquals(taskState.factoryLink, returnState.factoryLink); assertEquals(taskState.intervalMicros, returnState.intervalMicros); Thread.sleep(3000); Operation getOp = Operation.createGet(UriUtils.buildUri(this.host.getUri(), returnState.documentSelfLink)) .setReferer(this.host.getUri()); Operation response = this.host.waitForResponse(getOp); assertTrue("Error retrieving state", response.getStatusCode() == 200); ScheduledTaskState state = response.getBody(ScheduledTaskState.class); assertNotNull(state.expectedNextMaintenanceTimeMicros); assertTrue(currentTimeMicros < state.expectedNextMaintenanceTimeMicros); } }
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 -> { }); }
private void updateResourcePool(PlacementCapacityUpdateTaskState state) { // calculate average cpu usage per core double totalCpuUsage = 0.0; if (state.aggregatedStats.cpuCoreCount > 0) { totalCpuUsage = state.aggregatedStats.cpuUsageSumAllCores / state.aggregatedStats.cpuCoreCount; } ResourcePoolState rpPatchState = new ResourcePoolState(); rpPatchState.customProperties = new HashMap<>(); rpPatchState.customProperties.put( ContainerHostDataCollectionService.RESOURCE_POOL_CPU_USAGE_CUSTOM_PROP, Double.toString(totalCpuUsage)); rpPatchState.customProperties.put( ContainerHostDataCollectionService.RESOURCE_POOL_AVAILABLE_MEMORY_CUSTOM_PROP, Long.toString(state.aggregatedStats.availableMemoryBytes)); rpPatchState.maxMemoryBytes = state.aggregatedStats.totalMemoryBytes; sendRequest(Operation.createPatch(this, state.resourcePoolLink) .setBody(rpPatchState) .setCompletion((o, e) -> { if (e != null) { failTask(String.format("Unable to update resource pool '%s'", state.resourcePoolLink), e); return; } proceedTo(PlacementCapacityUpdateTaskState.SubStage.UPDATE_PLACEMENTS); })); }
@Test public void testUpdateDockerPZInUseByMultipleVicHostsToSchedulerPZShouldPass() throws Throwable { // First create a docker placement zone. ResourcePoolState createdPlacementZone = createPlacementZone("docker-placement-zone", false); assertNotNull(createdPlacementZone); // Now create 2 VIC hosts that use this placement zone. This can be achieved if the VIC // hosts were initially declared as docker but were later on marked as VIC createComputeState(createdPlacementZone); createComputeState(createdPlacementZone); // Now create a PATCH that updates the type of the zone to scheduler. This should fail // because there will be multiple container in the placement zone (even if they are all // schedulers) ResourcePoolState patchState = new ResourcePoolState(); markSchedulerPlacementZone(patchState); try { doPatch(patchState, createdPlacementZone.documentSelfLink); Assert.fail( "PATCH should fail to update the type of a docker placement " + "zone to a scheduler zone when the placement zone is in use by multiple scheduler hosts"); } catch (Exception ex) { verifyExceptionMessage(ex, SchedulerPlacementZoneInterceptor.MULTIPLE_HOSTS_IN_PLACEMENT_ZONE_MESSAGE); } }
private void createResourcePool(ReservationAllocationTaskState state) { ResourcePoolState poolState = new ResourcePoolState(); poolState.id = state.name + "-" + UUID.randomUUID().toString(); poolState.name = poolState.id; poolState.documentSelfLink = poolState.id; poolState.tenantLinks = state.tenantLinks; sendRequest(Operation .createPost(this, ResourcePoolService.FACTORY_LINK) .setBody(poolState) .setCompletion( (o, e) -> { if (e != null) { failTask( String.format("Failed to create placement zone. Error: %s", Utils.toString(e)), e); return; } ResourcePoolState resourcePool = o.getBody(ResourcePoolState.class); state.resourcePoolLink = resourcePool.documentSelfLink; proceedTo(ReservationAllocationTaskState.SubStage.GROUP_POLICY_CREATED, s -> { s.resourcePoolLink = resourcePool.documentSelfLink; }); })); }
@Test public void testUpdateSchedulerPZInUseToDockerPZShouldFail() throws Throwable { // First create a docker placement zone. ResourcePoolState createdPlacementZone = createPlacementZone("scheduler-placement-zone", true); assertNotNull(createdPlacementZone); // Now create a compute state that uses this placement zone createComputeState(createdPlacementZone, true); // Now create a PATCH that updates the type of the zone to docker. This should fail ResourcePoolState patchState = new ResourcePoolState(); markDockerPlacementZone(patchState); try { doPatch(patchState, createdPlacementZone.documentSelfLink); Assert.fail( "PATCH should fail to update the type of a used " + "scheduler placement zone to a docker zone"); } catch (Exception ex) { verifyExceptionMessage(ex, SchedulerPlacementZoneInterceptor.SCHEDULER_HOSTS_IN_PLACEMENT_ZONE_MESSAGE); } }
@Test public void testUpdateDockerPZInUseToSchedulerPZShouldFail() throws Throwable { // First create a docker placement zone. ResourcePoolState createdPlacementZone = createPlacementZone("docker-placement-zone", false); assertNotNull(createdPlacementZone); // Now create a compute state that uses this placement zone createComputeState(createdPlacementZone); // Now create a PATCH that updates the type of the zone to scheduler. This should fail ResourcePoolState patchState = new ResourcePoolState(); markSchedulerPlacementZone(patchState); try { doPatch(patchState, createdPlacementZone.documentSelfLink); Assert.fail( "PATCH should fail to update the type of a used " + "docker placement zone to a scheduler zone"); } catch (Exception ex) { verifyExceptionMessage(ex, SchedulerPlacementZoneInterceptor.NON_SCHEDULER_HOST_IN_PLACEMENT_ZONE_MESSAGE); } }
/** * Configures the elasticity of the linked resource pool. */ private void setResourcePoolElasticity(ElasticPlacementZoneState epz, Consumer<Throwable> callback) { Operation getRpOp = Operation.createGet(getHost(), epz.resourcePoolLink); sendWithDeferredResult(getRpOp, ResourcePoolState.class) .thenCompose(currentRpState -> { ResourcePoolState patchRpState = new ResourcePoolState(); patchRpState.properties = EnumSet.of(ResourcePoolProperty.ELASTIC); patchRpState.query = generateRpQuery(epz, currentRpState); Operation patchRpOp = Operation .createPatch(getHost(), epz.resourcePoolLink) .setBody(patchRpState); return sendWithDeferredResult(patchRpOp); }) .whenComplete((op, ex) -> callback.accept(ex)); }
public static ResourcePoolState createResourcePool(String poolId, String endpointLink) { ResourcePoolState poolState = new ResourcePoolState(); poolState.name = poolId; poolState.id = poolState.name; poolState.documentSelfLink = poolState.id; poolState.maxCpuCount = 1600L; poolState.minCpuCount = 16L; poolState.minMemoryBytes = 1024L * 1024L * 1024L * 46L; poolState.maxMemoryBytes = poolState.minMemoryBytes * 2; poolState.minDiskCapacityBytes = poolState.maxDiskCapacityBytes = 1024L * 1024L * 1024L * 1024L; poolState.tenantLinks = createTenantLinks(TENANT_NAME); poolState.customProperties = new HashMap<>(3); poolState.customProperties.put(ComputeConstants.ENDPOINT_AUTH_CREDENTIALS_PROP_NAME, CommonTestStateFactory.AUTH_CREDENTIALS_ID); if (endpointLink != null) { poolState.customProperties.put(ComputeProperties.ENDPOINT_LINK_PROP_NAME, endpointLink); } return poolState; }
@Test public void testUpdateDockerPZToSchedulerPZWithTagsShouldFail() throws Throwable { // First create a scheduler placement zone. ResourcePoolState createdPlacementZone = createPlacementZone( "docker-placement-zone-with-tags", false); assertNotNull(createdPlacementZone); // Now create a PATCH with tags. This should fail ResourcePoolState patchState = new ResourcePoolState(); markSchedulerPlacementZone(patchState); addTags(patchState); try { doPatch(patchState, createdPlacementZone.documentSelfLink); Assert.fail("PATCH should fail to set tags for scheduler placement zone"); } catch (Exception ex) { verifyExceptionMessage(ex, TAG_LINKS_MUST_BE_EMPTY_MESSAGE); } }
private GroupResourcePlacementState createPlacement(DeploymentPolicy policy) throws Throwable { ResourcePoolState resourcePool = new ResourcePoolState(); resourcePool.name = ReservationTaskServiceTest.class.toString() + System.currentTimeMillis(); resourcePool = doPost(resourcePool, ResourcePoolService.FACTORY_LINK); addForDeletion(resourcePool); GroupResourcePlacementState rsrvState = new GroupResourcePlacementState(); rsrvState.resourcePoolLink = resourcePool.documentSelfLink; rsrvState.name = ReservationTaskServiceTest.class.toString() + System.currentTimeMillis(); rsrvState.maxNumberInstances = 10; rsrvState.memoryLimit = 0L; rsrvState.cpuShares = 3; if (policy != null) { rsrvState.deploymentPolicyLink = policy.documentSelfLink; } rsrvState = doPost(rsrvState, GroupResourcePlacementService.FACTORY_LINK); addForDeletion(rsrvState); return rsrvState; }
@Test public void testDefaultState() throws Throwable { ScheduledTaskService.ScheduledTaskState taskState = buildValidStartState(); ResourcePoolState inPool = new ResourcePoolState(); inPool.name = UUID.randomUUID().toString(); inPool.id = inPool.name; inPool.minCpuCount = 1L; inPool.minMemoryBytes = 1024L; taskState.factoryLink = ResourcePoolService.FACTORY_LINK; taskState.initialStateJson = Utils.toJson(inPool); ScheduledTaskService.ScheduledTaskState returnState = this.postServiceSynchronously( ScheduledTaskService.FACTORY_LINK, taskState, ScheduledTaskService.ScheduledTaskState.class); assertEquals(taskState.customProperties, returnState.customProperties); assertEquals(taskState.initialStateJson, returnState.initialStateJson); assertEquals(taskState.factoryLink, returnState.factoryLink); assertEquals(taskState.intervalMicros, returnState.intervalMicros); }
@Test public void testUpdateSchedulerPlacementZoneWithTagsShouldFail() throws Throwable { // First create a scheduler placement zone. ResourcePoolState createdPlacementZone = createPlacementZone("docker-placement-zone", true); assertNotNull(createdPlacementZone); // Now create a PATCH with tags. This should fail ResourcePoolState patchState = new ResourcePoolState(); addTags(patchState); try { doPatch(patchState, createdPlacementZone.documentSelfLink); Assert.fail("PATCH should fail to set tags for scheduler placement zone"); } catch (Exception ex) { verifyExceptionMessage(ex, TAG_LINKS_MUST_BE_EMPTY_MESSAGE); } }
private ResourcePoolState createResourcePool(String link, Long maxMemory, Long maxStorage) throws Throwable { ResourcePoolState poolState = new ResourcePoolState(); poolState.id = link + "-" + UUID.randomUUID().toString(); poolState.name = poolState.id; poolState.documentSelfLink = poolState.id; poolState.maxCpuCount = 1600L; poolState.minCpuCount = 16L; poolState.minMemoryBytes = maxMemory / 2; poolState.maxMemoryBytes = maxMemory; poolState.minDiskCapacityBytes = poolState.maxDiskCapacityBytes = maxStorage; ResourcePoolState outResPoolState = doPost(poolState, ResourcePoolService.FACTORY_LINK); assertNotNull(outResPoolState); return outResPoolState; }