/** * Perform shallow merge of ServiceDocuments using reflection * * @param copyTo * @param copyFrom */ public static void mergeServiceDocuments(ServiceDocument copyTo, ServiceDocument copyFrom) { mergeServiceDocuments(copyTo, copyFrom, SHALLOW_MERGE_STRATEGY); }
private static void normalizeClosureDescriptions(CompositeTemplate entity, boolean serialize) { if (!serialize) { return; } for (Entry<String, ComponentTemplate<ClosureDescription>> entry : filterComponentTemplates( entity.components, ClosureDescription.class).entrySet()) { ComponentTemplate<ClosureDescription> component = entry.getValue(); CustomClosureDescription newData = new CustomClosureDescription(); PropertyUtils.mergeServiceDocuments(newData, component.data); if (newData.inputs != null) { newData.serializedInputs = new HashMap<>(); newData.inputs.entrySet().forEach((e -> { newData.serializedInputs.put(e.getKey(), e.getValue().toString()); })); newData.inputs = null; } if (newData.logConfiguration != null) { newData.serializedLogConfiguration = jsonToMap(newData.logConfiguration); newData.logConfiguration = null; } component.data = newData; } }
if (serialize) { CompositeTemplateContainerDescription newData = new CompositeTemplateContainerDescription(); PropertyUtils.mergeServiceDocuments(newData, component.data); if (newData.networks != null) { newData.networks.entrySet().forEach((e -> {
@Override public void handlePatch(Operation patch) { T currentState = getState(patch); T patchState = patch.getBody(stateType); PropertyUtils.mergeServiceDocuments(currentState, patchState); patch.complete(); }
@Override public void handlePatch(Operation patch) { MockDockerContainerToHostState currentState = getState(patch); MockDockerContainerToHostState patchBody = patch .getBody(MockDockerContainerToHostState.class); PropertyUtils.mergeServiceDocuments(currentState, patchBody); patch.setBody(currentState).complete(); } }
@Override public void handlePatch(Operation patch) { ContainerDescription currentState = getState(patch); ContainerDescription patchBody = patch.getBody(ContainerDescription.class); ServiceDocumentDescription docDesc = getDocumentTemplate().documentDescription; String currentSignature = Utils.computeSignature(currentState, docDesc); PropertyUtils.mergeServiceDocuments(currentState, patchBody); if (patchBody.parentDescriptionLink != null && patchBody.parentDescriptionLink.trim().isEmpty()) { currentState.parentDescriptionLink = null; } if (patchBody.networkMode != null && patchBody.networkMode.trim().isEmpty()) { currentState.networkMode = null; } if (patchBody.networks != null) { currentState.networks = patchBody.networks; } if (patchBody.volumes != null) { Set<String> uniqueVolumes = new HashSet<>(Arrays.asList(patchBody.volumes)); currentState.volumes = uniqueVolumes.toArray(new String[uniqueVolumes.size()]); } validateState(currentState); 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(); }
@Override public void handlePatch(Operation patch) { LocalPrincipalState currentState = getState(patch); LocalPrincipalState patchState = patch.getBody(LocalPrincipalState.class); try { validatePrincipalPatch(patchState, currentState); PropertyUtils.mergeServiceDocuments(currentState, patchState); patch.complete(); } catch (Exception ex) { patch.fail(ex); } }
@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); }); }
@Override public void handlePatch(Operation patch) { if (isBodyEmpty(patch)) { return; } ClosureDescription currentState = getState(patch); ClosureDescription patchedState = patch.getBody(ClosureDescription.class); logInfo("Closure source: %s Closure source URL: %s, language: %s", patchedState.source, patchedState.sourceURL, patchedState.runtime); if (patchedState.logConfiguration != null && !patchedState.logConfiguration.isJsonNull()) { currentState.logConfiguration = patchedState.logConfiguration; } patchedState.logConfiguration = null; PropertyUtils.mergeServiceDocuments(currentState, patchedState); if (patchedState.parentDescriptionLink != null && patchedState.parentDescriptionLink.trim().isEmpty()) { currentState.parentDescriptionLink = null; } if (!isValid(patch, currentState)) { return; } verifyResourceConstraints(currentState); formatDependencies(currentState); patch.setBody(currentState).complete(); }
@Override public void handlePatch(Operation patch) { if (!checkForBody(patch)) { return; } ContainerControlLoopState body = patch.getBody(ContainerControlLoopState.class); if (containerDescriptionsToBeProcessed.get() == 0) { logFine("Performing maintenance for: %s", getUri()); performMaintenance(); } else { logFine("Previous maintenance not finished for: %s", getUri()); } ContainerControlLoopState currentState = getState(patch); PropertyUtils.mergeServiceDocuments(currentState, body); patch.complete(); }
@Override public void handlePatch(Operation patch) { ContainerVolumeState currentState = getState(patch); ContainerVolumeState patchBody = getValidInputFrom(patch, true); ServiceDocumentDescription docDesc = getDocumentTemplate().documentDescription; String currentSignature = Utils.computeSignature(currentState, docDesc); List<String> currentCompositeComponentLinks = currentState.compositeComponentLinks; PropertyUtils.mergeServiceDocuments(currentState, patchBody); 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(); }
@Override public void handlePatch(Operation patch) { ContainerState currentState = getState(patch); ContainerState patchBody = patch.getBody(ContainerState.class); if (ContainerStats.KIND.equals(patchBody.documentKind)) { patchContainerStats(patch, currentState); return; } ServiceDocumentDescription docDesc = getDocumentTemplate().documentDescription; String currentSignature = Utils.computeSignature(currentState, docDesc); PropertyUtils.mergeServiceDocuments(currentState, patchBody); String newSignature = Utils.computeSignature(currentState, docDesc); // if the signature hasn't change we shouldn't modify the state if (currentSignature.equals(newSignature)) { patch.setStatusCode(Operation.STATUS_CODE_NOT_MODIFIED); } if (ContainerUtil.isDiscoveredContainer(currentState)) { ContainerUtil.ContainerDescriptionHelper.createInstance(this) .updateDiscoveredContainerDesc(currentState, patchBody); } ContainerUtil.ContainerDescriptionHelper.createInstance(this) .updateContainerPorts(currentState, patchBody); patch.complete(); }
@Override public void handlePatch(Operation op) { if (!checkForBody(op)) { return; } Endpoint currentState = getState(op); Endpoint patchBody = op.getBody(Endpoint.class); ServiceDocumentDescription docDesc = getDocumentTemplate().documentDescription; String currentSignature = Utils.computeSignature(currentState, docDesc); List<String> mergedTenantLinks = mergeTenantLinks(currentState.tenantLinks, patchBody.tenantLinks); PropertyUtils.mergeServiceDocuments(currentState, patchBody); currentState.tenantLinks = mergedTenantLinks; validate(currentState); String newSignature = Utils.computeSignature(currentState, docDesc); // if the signature hasn't change we shouldn't modify the state if (currentSignature.equals(newSignature)) { currentState = null; op.setStatusCode(Operation.STATUS_CODE_NOT_MODIFIED); } op.setBody(currentState).complete(); }
@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(); }