private ComputeStats getComputeStats(PlacementCapacityUpdateTaskState state, ComputeState compute, ComputeDescription computeDescription) { if (computeDescription.supportedChildren != null) { if (computeDescription.supportedChildren.contains(ComputeType.DOCKER_CONTAINER.name())) { return getContainerHostStats(compute, computeDescription); } else if (computeDescription.supportedChildren.contains(ComputeType.VM_GUEST.name())) { return getComputeHostStats(compute, computeDescription); } } return null; }
"http://enumerationAdapterReference"); cd.supportedChildren = new ArrayList<>(); cd.supportedChildren.add(ComputeType.VM_GUEST.toString()); cd.environmentName = ComputeDescriptionService.ComputeDescription.ENVIRONMENT_NAME_ON_PREMISE; cd.cpuMhzPerCore = 1000;
ComputeType type = ComputeType.valueOf(supportedChild); switch (type) { case VM_HOST:
if (currentState.type != null && currentState.type.equals(ComputeType.ENDPOINT_HOST)) { if (currentState.environmentName != null && (currentState.environmentName.equals(ENVIRONMENT_NAME_AWS)
typeQuery.setOccurance(Occurance.MUST_OCCUR); typeQuery.setTermPropertyName(ComputeState.FIELD_NAME_TYPE); typeQuery.setTermMatchValue(ComputeType.ENDPOINT_HOST.name()); queries.add(typeQuery);
} else { SubStage nextStage = determineStageFromHostType(ComputeType .valueOf(currentState.computeType)); currentState.taskSubStage = nextStage; currentState.parentLinks = rsp.results.documentLinks;
} else { SubStage nextStage = determineStageFromHostType(ComputeType .valueOf(currentState.computeType)); currentState.taskSubStage = nextStage; currentState.parentLinks = rsp.results.documentLinks;
cd.healthAdapterReference = null; cd.supportedChildren = new ArrayList<>(); cd.supportedChildren.add(ComputeType.DOCKER_CONTAINER.toString()); cd.instanceAdapterReference = null; ComputeDescriptionService.ComputeDescription cd1 = postServiceSynchronously(
ComputeType type = ComputeType.valueOf(supportedChild); switch (type) { case VM_HOST:
desc.environmentName = ComputeDescription.ENVIRONMENT_NAME_ON_PREMISE; desc.supportedChildren = new ArrayList<>( Collections.singletonList(ComputeType.DOCKER_CONTAINER.name())); desc.documentSelfLink = descriptionId; desc.id = descriptionId;
private ComputeState createContainerHost(DeploymentPolicy policy, String resourcePoolLink) throws Throwable { ComputeDescription computeDesc = new ComputeDescription(); computeDesc.supportedChildren = new ArrayList<>( Arrays.asList(ComputeType.DOCKER_CONTAINER.toString())); computeDesc.instanceAdapterReference = UriUtils.buildUri(ServiceHost.LOCAL_HOST, 8484, "compute-test-adapter", null); computeDesc.authCredentialsLink = UriUtils.buildUriPath( AuthCredentialsService.FACTORY_LINK, CommonTestStateFactory.AUTH_CREDENTIALS_ID); computeDesc = doPost(computeDesc, ComputeDescriptionService.FACTORY_LINK); addForDeletion(computeDesc); ComputeState cs = new ComputeState(); Random r = new Random(); cs.address = r.nextInt(256) + "." + r.nextInt(256) + "." + r.nextInt(256) + "." + r.nextInt(256); cs.descriptionLink = computeDesc.documentSelfLink; cs.powerState = PowerState.ON; cs.resourcePoolLink = resourcePoolLink; cs.adapterManagementReference = URI.create("http://localhost:8081"); cs.customProperties = new HashMap<>(); if (policy != null) { cs.customProperties.put(ContainerHostService.CUSTOM_PROPERTY_DEPLOYMENT_POLICY, policy.documentSelfLink); } cs = doPost(cs, ComputeService.FACTORY_LINK); addForDeletion(cs); return cs; }
ComputeType type = ComputeType.valueOf(supportedChild); switch (type) { case PHYSICAL:
private static void validateBootAdapterReference(ComputeDescription state) { if (state.supportedChildren == null) { return; } for (String supportedChild : state.supportedChildren) { ComputeType type = ComputeType.valueOf(supportedChild); switch (type) { case PHYSICAL: case VM_HOST: if (state.bootAdapterReference == null) { throw new IllegalArgumentException( "bootAdapterReference is required"); } if (state.powerAdapterReference == null) { throw new IllegalArgumentException( "powerAdapterReference is required"); } break; case DOCKER_CONTAINER: break; case OS_ON_PHYSICAL: break; case VM_GUEST: break; default: break; } } }
private void sendClusterRequest(ContainerRedeploymentTaskState state) { String cdLink = state.containerDescriptionLink; String contextId = state.contextId; int clusterSize = state.desiredClusterSize; logFine("Cluster container with %s description link, from %s context_id with cluster " + "size: %s", cdLink, contextId, clusterSize); RequestBrokerState rbState = new RequestBrokerState(); rbState.resourceDescriptionLink = cdLink; rbState.resourceCount = clusterSize; rbState.customProperties = new HashMap<>(); rbState.customProperties.put(RequestUtils.FIELD_NAME_CONTEXT_ID_KEY, contextId); rbState.resourceType = ComputeType.DOCKER_CONTAINER.name().toString(); rbState.operation = RequestBrokerState.CLUSTER_RESOURCE_OPERATION; rbState.tenantLinks = state.tenantLinks; rbState.serviceTaskCallback = ServiceTaskCallback.create(getSelfLink(), TaskStage.STARTED, SubStage.COMPLETED, TaskStage.STARTED, SubStage.ERROR); sendRequest(Operation.createPost(this, RequestBrokerFactoryService.SELF_LINK) .setBody(rbState) .setCompletion((o, e) -> { if (e != null) { logSevere(e); return; } })); }
private void removeResources(ContainerRedeploymentTaskState state) { RequestBrokerState requestBrokerState = new RequestBrokerState(); requestBrokerState.resourceType = ComputeType.DOCKER_CONTAINER.name().toString(); requestBrokerState.operation = RequestBrokerState.REMOVE_RESOURCE_OPERATION; requestBrokerState.tenantLinks = state.tenantLinks; requestBrokerState.resourceDescriptionLink = state.containerDescriptionLink; requestBrokerState.resourceLinks = state.containerStateLinks; requestBrokerState.requestTrackerLink = state.requestTrackerLink; requestBrokerState.serviceTaskCallback = ServiceTaskCallback.create(getSelfLink(), TaskStage.STARTED, SubStage.CLUSTER, TaskStage.FAILED, SubStage.ERROR); requestBrokerState.addCustomProperty(FIELD_NAME_CONTEXT_ID_KEY, state.contextId); requestBrokerState.addCustomProperty(CONTAINER_REDEPLOYMENT_CUSTOM_PROP, "container_redeployment"); sendRequest(Operation.createPost(this, RequestBrokerFactoryService.SELF_LINK) .setBody(requestBrokerState).setCompletion((o, e) -> { if (e != null) { logSevere(e); return; } })); }
public static ComputeDescription createDockerHostDescription() { ComputeDescription hostDescription = new ComputeDescription(); // create compute host descriptions first, then link them in the compute host state hostDescription.name = UUID.randomUUID().toString(); hostDescription.environmentName = ComputeDescription.ENVIRONMENT_NAME_ON_PREMISE; hostDescription.id = UUID.randomUUID().toString(); hostDescription.supportedChildren = new ArrayList<>( Arrays.asList(ComputeType.DOCKER_CONTAINER.toString())); hostDescription.documentSelfLink = hostDescription.id; hostDescription.authCredentialsLink = UriUtils.buildUriPath( AuthCredentialsService.FACTORY_LINK, CommonTestStateFactory.AUTH_CREDENTIALS_ID); hostDescription.instanceType = "small"; hostDescription.tenantLinks = createTenantLinks(TENANT_NAME); hostDescription.customProperties = new HashMap<>(); hostDescription.customProperties.put( ComputeConstants.CUSTOM_PROP_IMAGE_ID_NAME, "coreos"); return hostDescription; }
@Test public void testAllocationTaskServiceLifeSelectCorrectHostComputeState() throws Throwable { ComputeDescription noMatchingHostDesc = TestRequestStateFactory .createDockerHostDescription(); noMatchingHostDesc.documentSelfLink = UUID.randomUUID().toString(); noMatchingHostDesc.supportedChildren = new ArrayList<>( Arrays.asList(ComputeType.OS_ON_PHYSICAL.toString())); noMatchingHostDesc = doPost(noMatchingHostDesc, ComputeDescriptionService.FACTORY_LINK); assertNotNull(noMatchingHostDesc); // create a host ComputeState from the same resourcePool but ComputeDesc that doesn't // support containers. Make sure the right one is selected. createDockerHost(noMatchingHostDesc, resourcePool); ContainerAllocationTaskState allocationTask = createContainerAllocationTask(); allocate(allocationTask); }
private static ResourceAllocationTaskState createAllocationRequest( String resourcePool, String computeDescriptionLink) { ResourceAllocationTaskState state = new ResourceAllocationTaskState(); state.taskSubStage = ResourceAllocationTaskService.SubStage.QUERYING_AVAILABLE_COMPUTE_RESOURCES; state.resourceCount = 2; state.resourcePoolLink = resourcePool; state.computeDescriptionLink = computeDescriptionLink; state.computeType = ComputeType.VM_GUEST.toString(); state.customProperties = new HashMap<>(); state.customProperties.put("testProp", "testValue"); // For most tests, we override resourceDescription. state.resourceDescriptionLink = null; return state; }