private void getResourcePool(ContainerAllocationTaskState state, Consumer<String> callbackFunction) { getResourcePlacementState(state, (placementState) -> { if (placementState.resourcePoolLink == null) { failTask(null, new LocalizableValidationException( "Placement state has no resourcePoolLink", "request.container.allocation.missing.resource-pool")); return; } callbackFunction.accept(placementState.resourcePoolLink); }); }
private void getResourcePlacementState(ContainerAllocationTaskState state, Consumer<GroupResourcePlacementState> callbackFunction) { sendRequest(Operation.createGet(this, state.groupResourcePlacementLink) .setCompletion((o, e) -> { if (e != null) { failTask("Failure retrieving GroupResourcePlacement", e); return; } GroupResourcePlacementState placementState = o .getBody(GroupResourcePlacementState.class); callbackFunction.accept(placementState); })); }
private void getContainerDescription(ContainerAllocationTaskState state, Consumer<ContainerDescription> callbackFunction) { if (containerDescription != null) { callbackFunction.accept(containerDescription); return; } sendRequest(Operation.createGet(this, state.resourceDescriptionLink) .setCompletion((o, e) -> { if (e != null) { failTask("Failure retrieving description state", e); return; } ContainerDescription desc = o.getBody(ContainerDescription.class); this.containerDescription = desc; callbackFunction.accept(desc); })); }
private void getCompositeComponent(ContainerAllocationTaskState state, Consumer<Boolean> callbackFunction) { String contextId = state.customProperties.get(FIELD_NAME_CONTEXT_ID_KEY); String compositeComponentLink = UriUtils .buildUriPath(CompositeComponentFactoryService.SELF_LINK, contextId); sendRequest(Operation.createGet(this, compositeComponentLink) .setCompletion((o, e) -> { if (o.getStatusCode() == Operation.STATUS_CODE_NOT_FOUND) { callbackFunction.accept(Boolean.FALSE); } else if (e != null) { failTask("Failure retrieving CompositeComponent", e); } else { callbackFunction.accept(Boolean.TRUE); } })); }
private void fetchContainerState(String containerSelfLink, Consumer<ContainerState> callback) { sendRequest(Operation.createGet(getHost(), containerSelfLink) .setCompletion((o, e) -> { if (e != null) { failTask("Cannot retrieve the container state: " + containerSelfLink, e); return; } ContainerState containerState = o.getBody(ContainerState.class); callback.accept(containerState); })); }
.whenComplete((props, ex) -> { if (ex != null) { failTask( "Error retrieving health configuration environment variables: ", ex);
private void selectPlacementComputeHost(ContainerAllocationTaskState state, String resourcePoolLink) { if (!state.postAllocation && state.resourceNames == null || state.resourceNames.isEmpty()) { failTask(null, new LocalizableValidationException("resource names expected at" + " this stage.", "request.container.allocation.resource-names.missing")); .setCompletion((o, e) -> { if (e != null) { failTask("Failure creating placement task", e); return;
private void proceedAfterHostSelection(ContainerAllocationTaskState state) { if (!state.postAllocation && state.hostSelections == null && state.resourceNames == null) { failTask(null, new LocalizableValidationException( "computeHostLink and resourceNames can't be null at this state", "request.container.allocation.host.missing")); } else if (state.postAllocation || (state.hostSelections != null && state.resourceNames != null)) { final Map<String, HostSelection> resourceNameToHostSelection = !state.postAllocation ? selectHostPerResourceName(state.resourceNames, state.hostSelections) : null; if (state.instanceAdapterReference == null) { // reload container description if null getContainerDescription(state, (contDesc) -> { proceedTo(SubStage.HOST_ALLOCATED, s -> { s.instanceAdapterReference = contDesc.instanceAdapterReference; s.resourceNameToHostSelection = resourceNameToHostSelection; s.customProperties = mergeCustomProperties(state.customProperties, contDesc.customProperties); }); }); } else { proceedTo(SubStage.HOST_ALLOCATED, s -> { s.resourceNameToHostSelection = resourceNameToHostSelection; }); } } }
failTask("System failure creating ContainerStates", e);
private void createContainerInstanceRequests(ContainerAllocationTaskState state, ServiceTaskCallback taskCallback, String containerSelfLink) { AdapterRequest adapterRequest = new AdapterRequest(); adapterRequest.resourceReference = UriUtils.buildUri(getHost(), containerSelfLink); adapterRequest.serviceTaskCallback = taskCallback; adapterRequest.operationTypeId = ContainerOperationType.CREATE.id; adapterRequest.customProperties = state.customProperties; sendRequest(Operation.createPatch(getHost(), state.instanceAdapterReference.toString()) .setBody(adapterRequest) .setContextId(getSelfId()) .setCompletion((o, e) -> { if (e != null) { failTask("AdapterRequest failed for container: " + containerSelfLink, e); return; } logInfo("Container provisioning started for: %s", containerSelfLink); })); }
private void allocatePorts(ContainerAllocationTaskState state) { final boolean allocationRequest = isAllocationRequest(state); // if it is composition allocation request, move to COMPLETED SubStage when complete // if it is Admiral provisioning request, move to START_PROVISIONING SubStage when complete SubStage completionStage = allocationRequest ? SubStage.COMPLETED : SubStage.START_PROVISIONING; ContainerPortsAllocationTaskService.ContainerPortsAllocationTaskState portsAllocationTask = new ContainerPortsAllocationTaskService.ContainerPortsAllocationTaskState(); portsAllocationTask.containerStateLinks = state.resourceLinks; portsAllocationTask.serviceTaskCallback = ServiceTaskCallback.create(getSelfLink(), TaskStage.STARTED, completionStage, TaskStage.STARTED, SubStage.ERROR); portsAllocationTask.documentSelfLink = getSelfId(); portsAllocationTask.requestTrackerLink = state.requestTrackerLink; sendRequest(Operation.createPost(this, ContainerPortsAllocationTaskService.FACTORY_LINK) .setBody(portsAllocationTask) .setCompletion((o, e) -> { if (e != null) { failTask("Failure creating port allocation task", e); return; } })); }
private void createResourcePrefixNameSelectionTask(ContainerAllocationTaskState state, ContainerDescription containerDescription) { if (containerDescription == null) { getContainerDescription(state, (contDesc) -> this.createResourcePrefixNameSelectionTask(state, contDesc)); return; } // create resource prefix name selection tasks ResourceNamePrefixTaskState namePrefixTask = new ResourceNamePrefixTaskState(); namePrefixTask.documentSelfLink = getSelfId(); namePrefixTask.resourceCount = state.resourceCount; namePrefixTask.baseResourceNameFormat = ResourceNamePrefixService .getDefaultResourceNameFormat(containerDescription.name); namePrefixTask.tenantLinks = state.tenantLinks; namePrefixTask.customProperties = state.customProperties; namePrefixTask.serviceTaskCallback = ServiceTaskCallback.create(getSelfLink(), TaskStage.STARTED, SubStage.RESOURCES_NAMED, TaskStage.STARTED, SubStage.ERROR); namePrefixTask.requestTrackerLink = state.requestTrackerLink; sendRequest(Operation.createPost(this, ResourceNamePrefixTaskService.FACTORY_LINK) .setBody(namePrefixTask) .setCompletion((o, e) -> { if (e != null) { failTask("Failure creating resource name prefix task", e); return; } })); }