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 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 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); })); }
private void completeTask(ContainerAllocationTaskState state) { if (state.hostSelections != null) { try { ContainerHostDataCollectionState body = new ContainerHostDataCollectionState(); body.noHostOperation = true; body.computeContainerHostLinks = new HashSet<String>( state.resourceNameToHostSelection.values() .stream().map((r) -> r.hostLink) .collect(Collectors.toList())); logInfo("Container Host collection started for: [%s]", body.computeContainerHostLinks); sendRequest(Operation.createPatch(this, ContainerHostDataCollectionService.HOST_INFO_DATA_COLLECTION_LINK) .setBody(body) .setCompletion((o, e) -> { if (e != null) { logWarning("Container Host [%s] can't be updated. Error: [%s]", body.computeContainerHostLinks, Utils.toString(e)); } })); } catch (Throwable e) { logSevere(e); } } complete(); }
placementTask.requestTrackerLink = state.requestTrackerLink; sendRequest(Operation.createPost(this, PlacementHostSelectionTaskService.FACTORY_LINK) .setBody(placementTask) .setCompletion((o, 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); })); }
sendRequest(OperationUtil .createForcedPost(this, ContainerFactoryService.SELF_LINK) .setBody(containerState)
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; } })); }