protected void merge(CounterSubTaskState patchBody) { this.customProperties = mergeCustomProperties(this.customProperties, patchBody.customProperties); } }
private static void transformDriversToComponentTemplate( ContainerNetworkDescription description) { Map<String, String> customProps = new HashMap<>(); if (description.driver != null) { customProps.put(ContainerNetworkDescription.CUSTOM_PROPERTY_NETWORK_DRIVER, description.driver); description.driver = null; } if (description.ipam != null && description.ipam.driver != null) { customProps.put(ContainerNetworkDescription.CUSTOM_PROPERTY_IPAM_DRIVER, description.ipam.driver); description.ipam.driver = null; } if (!customProps.isEmpty()) { description.customProperties = PropertyUtils .mergeCustomProperties(description.customProperties, customProps); } }
@Override public void handlePatch(Operation patch) { ContainerNetworkDescription currentState = getState(patch); ContainerNetworkDescription patchBody = getValidInputFrom(patch, currentState); ServiceDocumentDescription docDesc = getDocumentTemplate().documentDescription; String currentSignature = Utils.computeSignature(currentState, docDesc); PropertyUtils.mergeServiceDocuments(currentState, patchBody, NetworkUtils.SHALLOW_MERGE_SKIP_MAPS_STRATEGY); PropertyUtils.mergeCustomProperties(currentState.options, patchBody.options); if (patchBody.parentDescriptionLink != null && patchBody.parentDescriptionLink.trim().isEmpty()) { currentState.parentDescriptionLink = null; } String newSignature = Utils.computeSignature(currentState, docDesc); boolean changed = !newSignature.equals(currentSignature); if (!changed) { patch.setStatusCode(Operation.STATUS_CODE_NOT_MODIFIED); } patch.complete(); }
@Override public void handlePatch(Operation patch) { ContainerVolumeDescription currentState = getState(patch); ContainerVolumeDescription patchBody = getValidInputFrom(patch, true); ServiceDocumentDescription docDesc = getDocumentTemplate().documentDescription; String currentSignature = Utils.computeSignature(currentState, docDesc); PropertyUtils.mergeServiceDocuments(currentState, patchBody); PropertyUtils.mergeCustomProperties(currentState.customProperties, patchBody.customProperties); if (patchBody.parentDescriptionLink != null && patchBody.parentDescriptionLink.trim().isEmpty()) { currentState.parentDescriptionLink = null; } String newSignature = Utils.computeSignature(currentState, docDesc); boolean changed = !newSignature.equals(currentSignature); if (!changed) { patch.setStatusCode(Operation.STATUS_CODE_NOT_MODIFIED); } patch.complete(); }
/** * Returns whether the projects state signature was changed after the patch. */ private DeferredResult<Boolean> handleProjectPatch(ProjectState currentState, ProjectState patchState) { ServiceDocumentDescription docDesc = getDocumentTemplate().documentDescription; String currentSignature = Utils.computeSignature(currentState, docDesc); DeferredResult<Integer> projectIndex; if (currentState.customProperties == null) { projectIndex = generateProjectIndex(); } else { projectIndex = DeferredResult.completed(Integer.parseInt( currentState.customProperties.get(CUSTOM_PROPERTY_PROJECT_INDEX))); } return projectIndex.thenApply(index -> { Map<String, String> mergedProperties = PropertyUtils.mergeCustomProperties( currentState.customProperties, patchState.customProperties); PropertyUtils.mergeServiceDocuments(currentState, patchState); currentState.customProperties = mergedProperties; handleProjectIndex(index, currentState); String newSignature = Utils.computeSignature(currentState, docDesc); return !currentSignature.equals(newSignature); }); }
private static DockerComposeNetwork fromCompositeComponentToDockerNetwork( ComponentTemplate<ContainerNetworkDescription> component) { assertNotNull(component, "component"); ContainerNetworkDescription description = component.data; transformDriversFromComponentTemplate(description); DockerComposeNetwork network = new DockerComposeNetwork(); network.driver = description.driver; network.driver_opts = PropertyUtils.mergeCustomProperties(description.options, description.customProperties); network.ipam = description.ipam; if (!isNullOrEmpty(description.externalName)) { network.external = new NetworkExternal(); network.external.name = description.externalName; } else if (description.external != null) { network.external = new NetworkExternal(); network.external.value = description.external; } return network; }
private void prepareContext(ContainerVolumeAllocationTaskState state, ContainerVolumeDescription volumeDescription) { assertNotNull(state, "state"); if (volumeDescription == null) { getContainerVolumeDescription(state, (volumeDesc) -> this.prepareContext(state, volumeDesc)); return; } proceedTo(SubStage.CONTEXT_PREPARED, s -> { // merge request/allocation properties over the volume description properties s.customProperties = mergeCustomProperties(volumeDescription.customProperties, state.customProperties); if (s.getCustomProperty(RequestUtils.FIELD_NAME_CONTEXT_ID_KEY) == null) { s.addCustomProperty(RequestUtils.FIELD_NAME_CONTEXT_ID_KEY, getSelfId()); } s.descName = volumeDescription.name; }); }
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; }); } } }
@Override public void handlePatch(Operation patch) { CompositeDescription currentState = getState(patch); CompositeDescription patchBody = patch.getBody(CompositeDescription.class); ServiceDocumentDescription docDesc = getDocumentTemplate().documentDescription; String currentSignature = Utils.computeSignature(currentState, docDesc); currentState.name = mergeProperty(currentState.name, patchBody.name); currentState.status = mergeProperty(currentState.status, patchBody.status); currentState.lastPublished = mergeProperty(currentState.lastPublished, patchBody.lastPublished); if (patchBody.parentDescriptionLink != null && patchBody.parentDescriptionLink.trim().isEmpty()) { currentState.parentDescriptionLink = null; } else { currentState.parentDescriptionLink = mergeProperty(currentState.parentDescriptionLink, patchBody.parentDescriptionLink); } currentState.descriptionLinks = mergeProperty(currentState.descriptionLinks, patchBody.descriptionLinks); currentState.customProperties = mergeCustomProperties( currentState.customProperties, patchBody.customProperties); String newSignature = Utils.computeSignature(currentState, docDesc); // if the signature hasn't change we shouldn't modify the state if (currentSignature.equals(newSignature)) { currentState = null; patch.setStatusCode(Operation.STATUS_CODE_NOT_MODIFIED); } patch.setBody(currentState).complete(); }
private void prepareContext(ContainerAllocationTaskState state, ContainerDescription containerDesc) { if (state.postAllocation) { proceedTo(SubStage.PLACEMENT_HOST_SELECTED); return; } if (containerDesc == null) { getContainerDescription(state, (contDesc) -> this.prepareContext(state, contDesc)); return; } proceedTo(SubStage.CONTEXT_PREPARED, s -> { // merge request/allocation properties over the container description properties s.customProperties = mergeCustomProperties(containerDesc.customProperties, state.customProperties); if (s.getCustomProperty(FIELD_NAME_CONTEXT_ID_KEY) == null) { s.addCustomProperty(FIELD_NAME_CONTEXT_ID_KEY, getSelfId()); } s.descName = containerDesc.name; }); }
private void prepareContext(ContainerNetworkAllocationTaskState state, ContainerNetworkDescription networkDescription) { assertNotNull(state, "state"); if (networkDescription == null) { getContainerNetworkDescription(state, (netwkDesc) -> prepareContext(state, netwkDesc)); return; } proceedTo(SubStage.CONTEXT_PREPARED, s -> { // merge request/allocation properties over the network description properties s.customProperties = mergeCustomProperties(networkDescription.customProperties, state.customProperties); if (s.getCustomProperty(RequestUtils.FIELD_NAME_CONTEXT_ID_KEY) == null) { s.addCustomProperty(RequestUtils.FIELD_NAME_CONTEXT_ID_KEY, getSelfId()); } s.descName = networkDescription.name; }); }
private void prepareContext(ClosureAllocationTaskState state, ClosureDescription closureDescription) { assertNotNull(state, "state"); if (closureDescription == null) { getClosureDescription(state, (closureDesc) -> this.prepareContext(state, closureDesc)); return; } assertNotNull(closureDescription, "closureDescription"); proceedTo(ClosureAllocationTaskState.SubStage.CONTEXT_PREPARED, s -> { // merge request/allocation properties over the custom description properties s.customProperties = mergeCustomProperties( state.customProperties, closureDescription.customProperties); if (state.getCustomProperty(RequestUtils.FIELD_NAME_CONTEXT_ID_KEY) == null) { s.addCustomProperty(RequestUtils.FIELD_NAME_CONTEXT_ID_KEY, getSelfId()); } s.descName = closureDescription.name; }); }
@Override public void handlePatch(Operation patch) { ContainerNetworkState currentState = getState(patch); ConnectedContainersCountIncrement incrementPatch = patch .getBody(ConnectedContainersCountIncrement.class); if (incrementPatch != null && incrementPatch.increment != null) { currentState.connectedContainersCount += incrementPatch.increment; patch.complete(); return; } ContainerNetworkState patchBody = getValidInputFrom(patch, currentState); ServiceDocumentDescription docDesc = getDocumentTemplate().documentDescription; String currentSignature = Utils.computeSignature(currentState, docDesc); List<String> currentCompositeComponentLinks = currentState.compositeComponentLinks; PropertyUtils.mergeServiceDocuments(currentState, patchBody, NetworkUtils.SHALLOW_MERGE_SKIP_MAPS_STRATEGY); PropertyUtils.mergeCustomProperties(currentState.options, patchBody.options); String newSignature = Utils.computeSignature(currentState, docDesc); boolean changed = !newSignature.equals(currentSignature); if (!changed) { patch.setStatusCode(Operation.STATUS_CODE_NOT_MODIFIED); } else { CompositeComponentNotifier.notifyCompositionComponentsOnChange(this, patch.getAction(), currentState.compositeComponentLinks, currentCompositeComponentLinks); } patch.complete(); }
rsrvTask.resourceType = ResourceType.CONTAINER_TYPE.getName(); rsrvTask.resourceDescriptionLink = state.resourceDescriptionLink; rsrvTask.customProperties = mergeCustomProperties( state.customProperties, desc.customProperties); rsrvTask.requestTrackerLink = state.requestTrackerLink;
private void doCreateReservationTasks(RequestBrokerState state, ContainerDescription containerDescription) { ReservationTaskState rsrvTask = new ReservationTaskState(); rsrvTask.documentSelfLink = getSelfId(); rsrvTask.serviceTaskCallback = ServiceTaskCallback.create(getSelfLink(), TaskStage.STARTED, SubStage.RESERVED, TaskStage.STARTED, SubStage.ERROR); rsrvTask.resourceCount = state.actualResourceCount; rsrvTask.tenantLinks = state.tenantLinks; rsrvTask.resourceType = state.resourceType; rsrvTask.resourceDescriptionLink = state.resourceDescriptionLink; rsrvTask.customProperties = mergeCustomProperties( state.customProperties, containerDescription.customProperties); rsrvTask.requestTrackerLink = state.requestTrackerLink; if (state.groupResourcePlacementLink != null) { rsrvTask.groupResourcePlacementLink = state.groupResourcePlacementLink; rsrvTask.taskSubStage = ReservationTaskState.SubStage.RESERVATION_SELECTED; rsrvTask.resourcePoolsPerGroupPlacementLinks = new LinkedHashMap<>(0); } sendRequest(Operation.createPost(this, ReservationTaskFactoryService.SELF_LINK) .setBodyNoCloning(rsrvTask) .setContextId(getSelfId()) .setCompletion((o, e) -> { if (e != null) { failTask("Failure creating reservation task", e); return; } proceedTo(SubStage.RESERVING); })); }
private void notifyCaller(CompositionSubTaskState state) { ServiceTaskCallbackResponse callbackResponse = getFinishedCallbackResponse(state); callbackResponse.customProperties = mergeCustomProperties( callbackResponse.customProperties, state.customProperties); callbackResponse.addProperty(REFERER, this.getSelfLink()); sendRequest(Operation.createPatch(this, state.serviceTaskCallback.serviceSelfLink) .setBody(callbackResponse) // Pragma needed because the service might be still in creation state (asynch // creation) .addPragmaDirective(Operation.PRAGMA_DIRECTIVE_QUEUE_FOR_SERVICE_AVAILABILITY) .setCompletion((o, e) -> { if (e != null) { logWarning("Notifying parent task %s from composition failed: %s", o.getUri(), Utils.toString(e)); } })); }
.getBody(GroupResourcePlacementState.class); complete(s -> { s.customProperties = mergeCustomProperties(state.customProperties, placement.customProperties); s.groupResourcePlacementLink = placement.documentSelfLink;
getSelfLink(), TaskStage.STARTED, SubStage.ALLOCATED, TaskStage.STARTED, SubStage.ERROR); allocationTask.customProperties = mergeCustomProperties( state.customProperties, volumeDescription.customProperties); allocationTask.resourceDescriptionLink = state.resourceDescriptionLink;
rsrvTask.resourceType = ResourceType.CONTAINER_TYPE.getName(); rsrvTask.resourceDescriptionLink = containerDesc.documentSelfLink; rsrvTask.customProperties = mergeCustomProperties( state.customProperties, containerDesc.customProperties); rsrvTask.requestTrackerLink = state.requestTrackerLink;
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 -> { }); }