/*
* ============LICENSE_START=======================================================
* Copyright (C) 2021 highstreet technologies GmbH
- * Modifications Copyright (C) 2021 Nordix Foundation
+ * Modifications Copyright (C) 2021-2023 Nordix Foundation
* Modifications Copyright (C) 2021 Pantheon.tech
- * Modifications Copyright (C) 2021 Bell Canada
+ * Modifications Copyright (C) 2021-2022 Bell Canada
+ * Modifications Copyright (C) 2023 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.cps.ncmp.api.impl;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.gson.Gson;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
+import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLES_NOT_FOUND;
+import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLES_NOT_READY;
+import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLE_ALREADY_EXIST;
+import static org.onap.cps.ncmp.api.NcmpResponseStatus.CM_HANDLE_INVALID_ID;
+import static org.onap.cps.ncmp.api.impl.inventory.LockReasonCategory.MODULE_UPGRADE;
+import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NCMP_DMI_REGISTRY_PARENT;
+import static org.onap.cps.ncmp.api.impl.ncmppersistence.NcmpPersistence.NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME;
+import static org.onap.cps.ncmp.api.impl.utils.RestQueryParametersValidator.validateCmHandleQueryParameters;
+
+import com.google.common.collect.Lists;
+import com.hazelcast.map.IMap;
+import java.text.MessageFormat;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashMap;
-import java.util.LinkedHashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import javax.validation.constraints.NotNull;
+import java.util.Set;
+import java.util.stream.Collectors;
+import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
-import org.onap.cps.api.CpsAdminService;
import org.onap.cps.api.CpsDataService;
-import org.onap.cps.api.CpsModuleService;
-import org.onap.cps.api.CpsQueryService;
+import org.onap.cps.ncmp.api.NetworkCmProxyCmHandleQueryService;
import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
-import org.onap.cps.ncmp.api.impl.exception.NcmpException;
-import org.onap.cps.ncmp.api.impl.operation.DmiOperations;
-import org.onap.cps.ncmp.api.models.CmHandle;
+import org.onap.cps.ncmp.api.impl.events.lcm.LcmEventsCmHandleStateHandler;
+import org.onap.cps.ncmp.api.impl.inventory.CmHandleQueries;
+import org.onap.cps.ncmp.api.impl.inventory.CmHandleState;
+import org.onap.cps.ncmp.api.impl.inventory.CompositeState;
+import org.onap.cps.ncmp.api.impl.inventory.CompositeStateBuilder;
+import org.onap.cps.ncmp.api.impl.inventory.CompositeStateUtils;
+import org.onap.cps.ncmp.api.impl.inventory.DataStoreSyncState;
+import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistence;
+import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations;
+import org.onap.cps.ncmp.api.impl.operations.OperationType;
+import org.onap.cps.ncmp.api.impl.trustlevel.TrustLevel;
+import org.onap.cps.ncmp.api.impl.utils.CmHandleQueryConditions;
+import org.onap.cps.ncmp.api.impl.utils.InventoryQueryConditions;
+import org.onap.cps.ncmp.api.impl.utils.YangDataConverter;
+import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle;
+import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters;
+import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters;
+import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse;
+import org.onap.cps.ncmp.api.models.DataOperationRequest;
import org.onap.cps.ncmp.api.models.DmiPluginRegistration;
-import org.onap.cps.ncmp.api.models.GenericRequestBody;
-import org.onap.cps.ncmp.api.models.PersistenceCmHandle;
-import org.onap.cps.ncmp.api.models.PersistenceCmHandle.AdditionalProperty;
-import org.onap.cps.ncmp.api.models.PersistenceCmHandlesList;
-import org.onap.cps.ncmp.api.models.YangResource;
+import org.onap.cps.ncmp.api.models.DmiPluginRegistrationResponse;
+import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
+import org.onap.cps.ncmp.api.models.UpgradedCmHandles;
import org.onap.cps.spi.FetchDescendantsOption;
+import org.onap.cps.spi.exceptions.AlreadyDefinedException;
+import org.onap.cps.spi.exceptions.CpsException;
import org.onap.cps.spi.exceptions.DataNodeNotFoundException;
import org.onap.cps.spi.exceptions.DataValidationException;
-import org.onap.cps.spi.model.DataNode;
+import org.onap.cps.spi.model.ModuleDefinition;
import org.onap.cps.spi.model.ModuleReference;
-import org.springframework.http.HttpStatus;
+import org.onap.cps.utils.JsonObjectMapper;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
-import org.springframework.util.StringUtils;
@Slf4j
@Service
+@RequiredArgsConstructor
public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService {
- private static final String NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME = "NFP-Operational";
+ private static final int DELETE_BATCH_SIZE = 100;
+ private final JsonObjectMapper jsonObjectMapper;
+ private final DmiDataOperations dmiDataOperations;
+ private final NetworkCmProxyDataServicePropertyHandler networkCmProxyDataServicePropertyHandler;
+ private final InventoryPersistence inventoryPersistence;
+ private final CmHandleQueries cmHandleQueries;
+ private final NetworkCmProxyCmHandleQueryService networkCmProxyCmHandleQueryService;
+ private final LcmEventsCmHandleStateHandler lcmEventsCmHandleStateHandler;
+ private final CpsDataService cpsDataService;
+ private final IMap<String, Object> moduleSyncStartedOnCmHandles;
+ private final Map<String, TrustLevel> trustLevelPerDmiPlugin;
- private static final String NCMP_DATASPACE_NAME = "NCMP-Admin";
-
- private static final String NCMP_DMI_REGISTRY_ANCHOR = "ncmp-dmi-registry";
-
- private static final OffsetDateTime NO_TIMESTAMP = null;
-
- private static final String NCMP_DMI_SERVICE_NAME = "dmi-service-name";
-
- private static final String REVISION = "revision";
-
- private CpsDataService cpsDataService;
-
- private ObjectMapper objectMapper;
+ @Override
+ public DmiPluginRegistrationResponse updateDmiRegistrationAndSyncModule(
+ final DmiPluginRegistration dmiPluginRegistration) {
+ dmiPluginRegistration.validateDmiPluginRegistration();
+ final DmiPluginRegistrationResponse dmiPluginRegistrationResponse = new DmiPluginRegistrationResponse();
+
+ if (!dmiPluginRegistration.getRemovedCmHandles().isEmpty()) {
+ dmiPluginRegistrationResponse.setRemovedCmHandles(
+ parseAndProcessDeletedCmHandlesInRegistration(dmiPluginRegistration.getRemovedCmHandles()));
+ }
- private CpsQueryService cpsQueryService;
+ if (!dmiPluginRegistration.getCreatedCmHandles().isEmpty()) {
+ dmiPluginRegistrationResponse.setCreatedCmHandles(
+ parseAndProcessCreatedCmHandlesInRegistration(dmiPluginRegistration));
+ }
+ if (!dmiPluginRegistration.getUpdatedCmHandles().isEmpty()) {
+ dmiPluginRegistrationResponse.setUpdatedCmHandles(
+ networkCmProxyDataServicePropertyHandler
+ .updateCmHandleProperties(dmiPluginRegistration.getUpdatedCmHandles()));
+ }
+ if (dmiPluginRegistration.getUpgradedCmHandles() != null
+ && !dmiPluginRegistration.getUpgradedCmHandles().getCmHandles().isEmpty()) {
+ dmiPluginRegistrationResponse.setUpgradedCmHandles(
+ parseAndProcessUpgradedCmHandlesInRegistration(dmiPluginRegistration));
+ }
- private DmiOperations dmiOperations;
+ setTrustLevelPerDmiPlugin(dmiPluginRegistration);
- private CpsModuleService cpsModuleService;
+ return dmiPluginRegistrationResponse;
+ }
- private CpsAdminService cpsAdminService;
+ @Override
+ public Object getResourceDataForCmHandle(final String datastoreName,
+ final String cmHandleId,
+ final String resourceIdentifier,
+ final String optionsParamInQuery,
+ final String topicParamInQuery,
+ final String requestId) {
+ final ResponseEntity<?> responseEntity = dmiDataOperations.getResourceDataFromDmi(datastoreName, cmHandleId,
+ resourceIdentifier,
+ optionsParamInQuery,
+ topicParamInQuery,
+ requestId);
+ return responseEntity.getBody();
+ }
- /**
- * Constructor Injection for Dependencies.
- * @param dmiOperations DMI operation
- * @param cpsDataService Data Service Interface
- * @param cpsQueryService Query Service Interface
- * @param objectMapper Object Mapper
- */
- public NetworkCmProxyDataServiceImpl(final DmiOperations dmiOperations,
- final CpsModuleService cpsModuleService,
- final CpsDataService cpsDataService,
- final CpsQueryService cpsQueryService,
- final CpsAdminService cpsAdminService,
- final ObjectMapper objectMapper) {
- this.dmiOperations = dmiOperations;
- this.cpsModuleService = cpsModuleService;
- this.cpsDataService = cpsDataService;
- this.cpsQueryService = cpsQueryService;
- this.cpsAdminService = cpsAdminService;
- this.objectMapper = objectMapper;
+ @Override
+ public Object getResourceDataForCmHandle(final String datastoreName,
+ final String cmHandleId,
+ final String resourceIdentifier,
+ final FetchDescendantsOption fetchDescendantsOption) {
+ return cpsDataService.getDataNodes(datastoreName, cmHandleId, resourceIdentifier,
+ fetchDescendantsOption).iterator().next();
}
@Override
- public DataNode getDataNode(final String cmHandle, final String xpath,
- final FetchDescendantsOption fetchDescendantsOption) {
- return cpsDataService
- .getDataNode(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandle, xpath, fetchDescendantsOption);
+ public void executeDataOperationForCmHandles(final String topicParamInQuery,
+ final DataOperationRequest
+ dataOperationRequest,
+ final String requestId) {
+ dmiDataOperations.requestResourceDataFromDmi(topicParamInQuery, dataOperationRequest, requestId);
}
@Override
- public Collection<DataNode> queryDataNodes(final String cmHandle, final String cpsPath,
- final FetchDescendantsOption fetchDescendantsOption) {
- return cpsQueryService
- .queryDataNodes(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandle, cpsPath, fetchDescendantsOption);
+ public Object writeResourceDataPassThroughRunningForCmHandle(final String cmHandleId,
+ final String resourceIdentifier,
+ final OperationType operationType,
+ final String requestData,
+ final String dataType) {
+ return dmiDataOperations.writeResourceDataPassThroughRunningFromDmi(cmHandleId, resourceIdentifier,
+ operationType, requestData, dataType);
}
@Override
- public void createDataNode(final String cmHandle, final String parentNodeXpath, final String jsonData) {
- if (!StringUtils.hasText(parentNodeXpath) || "/".equals(parentNodeXpath)) {
- cpsDataService.saveData(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandle, jsonData, NO_TIMESTAMP);
- } else {
- cpsDataService
- .saveData(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandle, parentNodeXpath, jsonData, NO_TIMESTAMP);
- }
+ public Collection<ModuleReference> getYangResourcesModuleReferences(final String cmHandleId) {
+ return inventoryPersistence.getYangResourcesModuleReferences(cmHandleId);
}
@Override
- public void addListNodeElements(final String cmHandle, final String parentNodeXpath, final String jsonData) {
- cpsDataService.saveListElements(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandle, parentNodeXpath, jsonData,
- NO_TIMESTAMP);
+ public Collection<ModuleDefinition> getModuleDefinitionsByCmHandleId(final String cmHandleId) {
+ return inventoryPersistence.getModuleDefinitionsByCmHandleId(cmHandleId);
}
+ /**
+ * Retrieve cm handles with details for the given query parameters.
+ *
+ * @param cmHandleQueryApiParameters cm handle query parameters
+ * @return cm handles with details
+ */
@Override
- public void updateNodeLeaves(final String cmHandle, final String parentNodeXpath, final String jsonData) {
- cpsDataService
- .updateNodeLeaves(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandle, parentNodeXpath, jsonData,
- NO_TIMESTAMP);
+ public Collection<NcmpServiceCmHandle> executeCmHandleSearch(
+ final CmHandleQueryApiParameters cmHandleQueryApiParameters) {
+ final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = jsonObjectMapper.convertToValueType(
+ cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class);
+ validateCmHandleQueryParameters(cmHandleQueryServiceParameters, CmHandleQueryConditions.ALL_CONDITION_NAMES);
+ return networkCmProxyCmHandleQueryService.queryCmHandles(cmHandleQueryServiceParameters);
}
+ /**
+ * Retrieve cm handle ids for the given query parameters.
+ *
+ * @param cmHandleQueryApiParameters cm handle query parameters
+ * @return cm handle ids
+ */
@Override
- public void replaceNodeTree(final String cmHandle, final String parentNodeXpath, final String jsonData) {
- cpsDataService.replaceNodeTree(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandle, parentNodeXpath, jsonData,
- NO_TIMESTAMP);
+ public Collection<String> executeCmHandleIdSearch(final CmHandleQueryApiParameters cmHandleQueryApiParameters) {
+ final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = jsonObjectMapper.convertToValueType(
+ cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class);
+ validateCmHandleQueryParameters(cmHandleQueryServiceParameters, CmHandleQueryConditions.ALL_CONDITION_NAMES);
+ return networkCmProxyCmHandleQueryService.queryCmHandleIds(cmHandleQueryServiceParameters);
}
+ /**
+ * Set the data sync enabled flag, along with the data sync state
+ * based on the data sync enabled boolean for the cm handle id provided.
+ *
+ * @param cmHandleId cm handle id
+ * @param dataSyncEnabled data sync enabled flag
+ */
@Override
- public void updateDmiRegistrationAndSyncModule(final DmiPluginRegistration dmiPluginRegistration) {
- try {
- if (dmiPluginRegistration.getCreatedCmHandles() != null) {
- parseAndCreateCmHandlesInDmiRegistrationAndSyncModule(dmiPluginRegistration);
- }
- if (dmiPluginRegistration.getUpdatedCmHandles() != null) {
- parseAndUpdateCmHandlesInDmiRegistration(dmiPluginRegistration);
- }
- if (dmiPluginRegistration.getRemovedCmHandles() != null) {
- parseAndRemoveCmHandlesInDmiRegistration(dmiPluginRegistration);
+ public void setDataSyncEnabled(final String cmHandleId, final boolean dataSyncEnabled) {
+ final CompositeState compositeState = inventoryPersistence.getCmHandleState(cmHandleId);
+ if (compositeState.getDataSyncEnabled().equals(dataSyncEnabled)) {
+ log.info("Data-Sync Enabled flag is already: {} ", dataSyncEnabled);
+ } else if (compositeState.getCmHandleState() != CmHandleState.READY) {
+ throw new CpsException("State mismatch exception.", "Cm-Handle not in READY state. Cm handle state is: "
+ + compositeState.getCmHandleState());
+ } else {
+ final DataStoreSyncState dataStoreSyncState = compositeState.getDataStores()
+ .getOperationalDataStore().getDataStoreSyncState();
+ if (!dataSyncEnabled && dataStoreSyncState == DataStoreSyncState.SYNCHRONIZED) {
+ cpsDataService.deleteDataNode(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandleId,
+ "/netconf-state", OffsetDateTime.now());
}
- } catch (final JsonProcessingException e) {
- handleJsonProcessingException(dmiPluginRegistration, e);
+ CompositeStateUtils.setDataSyncEnabledFlagWithDataSyncState(dataSyncEnabled, compositeState);
+ inventoryPersistence.saveCmHandleState(cmHandleId,
+ compositeState);
}
}
+ /**
+ * Get all cm handle IDs by DMI plugin identifier.
+ *
+ * @param dmiPluginIdentifier DMI plugin identifier
+ * @return set of cm handle IDs
+ */
@Override
- public Object getResourceDataOperationalForCmHandle(final @NotNull String cmHandle,
- final @NotNull String resourceIdentifier,
- final String acceptParamInHeader,
- final String optionsParamInQuery) {
-
- final DataNode cmHandleDataNode = fetchDataNodeFromDmiRegistryForCmHandle(cmHandle);
- final String dmiServiceName = String.valueOf(cmHandleDataNode.getLeaves().get(NCMP_DMI_SERVICE_NAME));
- final String dmiRequestBody = getGenericRequestBody(cmHandleDataNode);
- final ResponseEntity<Object> response = dmiOperations.getResourceDataOperationalFromDmi(dmiServiceName,
- cmHandle,
- resourceIdentifier,
- optionsParamInQuery,
- acceptParamInHeader,
- dmiRequestBody);
- return handleResponse(response);
+ public Collection<String> getAllCmHandleIdsByDmiPluginIdentifier(final String dmiPluginIdentifier) {
+ return cmHandleQueries.getCmHandleIdsByDmiPluginIdentifier(dmiPluginIdentifier);
}
+ /**
+ * Get all cm handle IDs by various properties.
+ *
+ * @param cmHandleQueryServiceParameters cm handle query parameters
+ * @return set of cm handle IDs
+ */
@Override
- public Object getResourceDataPassThroughRunningForCmHandle(final @NotNull String cmHandle,
- final @NotNull String resourceIdentifier,
- final String acceptParamInHeader,
- final String optionsParamInQuery) {
- final DataNode cmHandleDataNode = fetchDataNodeFromDmiRegistryForCmHandle(cmHandle);
- final String dmiServiceName = String.valueOf(cmHandleDataNode.getLeaves().get(NCMP_DMI_SERVICE_NAME));
- final String dmiRequestBody = getGenericRequestBody(cmHandleDataNode);
- final ResponseEntity<Object> response = dmiOperations.getResourceDataPassThroughRunningFromDmi(dmiServiceName,
- cmHandle,
- resourceIdentifier,
- optionsParamInQuery,
- acceptParamInHeader,
- dmiRequestBody);
- return handleResponse(response);
+ public Collection<String> executeCmHandleIdSearchForInventory(
+ final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
+ validateCmHandleQueryParameters(cmHandleQueryServiceParameters, InventoryQueryConditions.ALL_CONDITION_NAMES);
+ return networkCmProxyCmHandleQueryService.queryCmHandleIdsForInventory(cmHandleQueryServiceParameters);
}
+ /**
+ * Retrieve cm handle details for a given cm handle.
+ *
+ * @param cmHandleId cm handle identifier
+ * @return cm handle details
+ */
@Override
- public void createResourceDataPassThroughRunningForCmHandle(final @NotNull String cmHandle,
- final @NotNull String resourceIdentifier,
- final @NotNull String requestBody,
- final String contentType) {
- final DataNode cmHandleDataNode = fetchDataNodeFromDmiRegistryForCmHandle(cmHandle);
- final String dmiServiceName = String.valueOf(cmHandleDataNode.getLeaves().get(NCMP_DMI_SERVICE_NAME));
- final Collection<DataNode> cmHandlePropertiesAsDataNodes = cmHandleDataNode.getChildDataNodes();
- final Map<String, String> cmHandlePropertiesAsMap = getCmHandlePropertiesAsMap(cmHandlePropertiesAsDataNodes);
- final GenericRequestBody dmiRequestBodyObject = GenericRequestBody.builder()
- .operation(GenericRequestBody.OperationEnum.CREATE)
- .dataType(contentType)
- .data(requestBody)
- .cmHandleProperties(cmHandlePropertiesAsMap)
- .build();
- final String dmiRequestBody = prepareOperationBody(dmiRequestBodyObject);
- final ResponseEntity<String> responseEntity = dmiOperations
- .createResourceDataPassThroughRunningFromDmi(dmiServiceName,
- cmHandle,
- resourceIdentifier,
- dmiRequestBody);
- handleResponseForPost(responseEntity);
+ public NcmpServiceCmHandle getNcmpServiceCmHandle(final String cmHandleId) {
+ return YangDataConverter.convertYangModelCmHandleToNcmpServiceCmHandle(
+ inventoryPersistence.getYangModelCmHandle(cmHandleId));
}
+ /**
+ * Get cm handle public properties for a given cm handle id.
+ *
+ * @param cmHandleId cm handle identifier
+ * @return cm handle public properties
+ */
@Override
- public Collection<ModuleReference> getYangResourcesModuleReferences(final String cmHandle) {
- return cpsModuleService.getYangResourcesModuleReferences(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, cmHandle);
+ public Map<String, String> getCmHandlePublicProperties(final String cmHandleId) {
+ final YangModelCmHandle yangModelCmHandle = inventoryPersistence.getYangModelCmHandle(cmHandleId);
+ final List<YangModelCmHandle.Property> yangModelPublicProperties = yangModelCmHandle.getPublicProperties();
+ final Map<String, String> cmHandlePublicProperties = new HashMap<>();
+ YangDataConverter.asPropertiesMap(yangModelPublicProperties, cmHandlePublicProperties);
+ return cmHandlePublicProperties;
}
/**
- * Retrieve cm handle identifiers for the given list of module names.
+ * Get cm handle composite state for a given cm handle id.
*
- * @param moduleNames module names.
- * @return a collection of anchor identifiers
+ * @param cmHandleId cm handle identifier
+ * @return cm handle state
*/
@Override
- public Collection<String> executeCmHandleHasAllModulesSearch(final Collection<String> moduleNames) {
- return cpsAdminService.queryAnchorNames(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, moduleNames);
- }
-
- private DataNode fetchDataNodeFromDmiRegistryForCmHandle(final String cmHandle) {
- final String xpathForDmiRegistryToFetchCmHandle = "/dmi-registry/cm-handles[@id='" + cmHandle + "']";
- return cpsDataService.getDataNode(NCMP_DATASPACE_NAME,
- NCMP_DMI_REGISTRY_ANCHOR,
- xpathForDmiRegistryToFetchCmHandle,
- FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS);
+ public CompositeState getCmHandleCompositeState(final String cmHandleId) {
+ return inventoryPersistence.getYangModelCmHandle(cmHandleId).getCompositeState();
}
- private String prepareOperationBody(final GenericRequestBody requestBodyObject) {
- try {
- return objectMapper.writeValueAsString(requestBodyObject);
- } catch (final JsonProcessingException e) {
- log.error("Parsing error occurred while converting Object to JSON.");
- throw new NcmpException("Parsing error occurred while converting given object to JSON.",
- e.getMessage());
+ /**
+ * THis method registers a cm handle and initiates modules sync.
+ *
+ * @param dmiPluginRegistration dmi plugin registration information.
+ * @return cm-handle registration response for create cm-handle requests.
+ */
+ public List<CmHandleRegistrationResponse> parseAndProcessCreatedCmHandlesInRegistration(
+ final DmiPluginRegistration dmiPluginRegistration) {
+ final Map<YangModelCmHandle, CmHandleState> cmHandleStatePerCmHandle = new HashMap<>();
+ dmiPluginRegistration.getCreatedCmHandles()
+ .forEach(cmHandle -> {
+ final YangModelCmHandle yangModelCmHandle = YangModelCmHandle.toYangModelCmHandle(
+ dmiPluginRegistration.getDmiPlugin(),
+ dmiPluginRegistration.getDmiDataPlugin(),
+ dmiPluginRegistration.getDmiModelPlugin(),
+ cmHandle,
+ cmHandle.getModuleSetTag());
+ cmHandleStatePerCmHandle.put(yangModelCmHandle, CmHandleState.ADVISED);
+ });
+ return registerNewCmHandles(cmHandleStatePerCmHandle);
+ }
+
+ protected List<CmHandleRegistrationResponse> parseAndProcessDeletedCmHandlesInRegistration(
+ final List<String> tobeRemovedCmHandles) {
+ final List<CmHandleRegistrationResponse> cmHandleRegistrationResponses =
+ new ArrayList<>(tobeRemovedCmHandles.size());
+ final Collection<YangModelCmHandle> yangModelCmHandles =
+ inventoryPersistence.getYangModelCmHandles(tobeRemovedCmHandles);
+
+ updateCmHandleStateBatch(yangModelCmHandles, CmHandleState.DELETING);
+
+ final Set<String> notDeletedCmHandles = new HashSet<>();
+ for (final List<String> tobeRemovedCmHandleBatch : Lists.partition(tobeRemovedCmHandles, DELETE_BATCH_SIZE)) {
+ try {
+ batchDeleteCmHandlesFromDbAndModuleSyncMap(tobeRemovedCmHandleBatch);
+ tobeRemovedCmHandleBatch.forEach(cmHandleId ->
+ cmHandleRegistrationResponses.add(CmHandleRegistrationResponse.createSuccessResponse(cmHandleId)));
+
+ } catch (final RuntimeException batchException) {
+ log.error("Unable to de-register cm-handle batch, retrying on each cm handle");
+ for (final String cmHandleId : tobeRemovedCmHandleBatch) {
+ final CmHandleRegistrationResponse cmHandleRegistrationResponse =
+ deleteCmHandleAndGetCmHandleRegistrationResponse(cmHandleId);
+ cmHandleRegistrationResponses.add(cmHandleRegistrationResponse);
+ if (cmHandleRegistrationResponse.getStatus() != CmHandleRegistrationResponse.Status.SUCCESS) {
+ notDeletedCmHandles.add(cmHandleId);
+ }
+ }
+ }
}
- }
- private static Map<String, String> getCmHandlePropertiesAsMap(
- final Collection<DataNode> cmHandlePropertiesAsDataNode) {
- if (cmHandlePropertiesAsDataNode.isEmpty()) {
- return Collections.emptyMap();
- }
- final Map<String, String> cmHandlePropertiesAsMap = new LinkedHashMap<>();
- for (final DataNode dataNode: cmHandlePropertiesAsDataNode) {
- cmHandlePropertiesAsMap.put(String.valueOf(dataNode.getLeaves().get("name")),
- String.valueOf(dataNode.getLeaves().get("value")));
- }
- return cmHandlePropertiesAsMap;
- }
+ yangModelCmHandles.removeIf(yangModelCmHandle -> notDeletedCmHandles.contains(yangModelCmHandle.getId()));
+ updateCmHandleStateBatch(yangModelCmHandles, CmHandleState.DELETED);
+
+ return cmHandleRegistrationResponses;
+ }
+
+ protected List<CmHandleRegistrationResponse> parseAndProcessUpgradedCmHandlesInRegistration(
+ final DmiPluginRegistration dmiPluginRegistration) {
+
+ final UpgradedCmHandles upgradedCmHandles = dmiPluginRegistration.getUpgradedCmHandles();
+ final String moduleSetTag = dmiPluginRegistration.getUpgradedCmHandles().getModuleSetTag();
+ final Map<YangModelCmHandle, CmHandleState> cmHandleStatePerCmHandle =
+ new HashMap<>(upgradedCmHandles.getCmHandles().size());
+ final Collection<String> notReadyCmHandles = new ArrayList<>(upgradedCmHandles.getCmHandles().size());
+ final NcmpServiceCmHandle ncmpServiceCmHandle = new NcmpServiceCmHandle();
+ final String formattedModuleSetTag = MessageFormat.format("new moduleSetTag: {0}", moduleSetTag);
+
+ upgradedCmHandles.getCmHandles().forEach(cmHandleId -> {
+ if (cmHandleQueries.cmHandleHasState(cmHandleId, CmHandleState.READY)) {
+ ncmpServiceCmHandle.setCmHandleId(cmHandleId);
+ ncmpServiceCmHandle.setCompositeState(new CompositeStateBuilder()
+ .withCmHandleState(CmHandleState.READY)
+ .withLockReason(MODULE_UPGRADE, formattedModuleSetTag).build());
+ final YangModelCmHandle yangModelCmHandle = YangModelCmHandle.toYangModelCmHandle(
+ dmiPluginRegistration.getDmiPlugin(),
+ dmiPluginRegistration.getDmiDataPlugin(),
+ dmiPluginRegistration.getDmiModelPlugin(),
+ ncmpServiceCmHandle,
+ moduleSetTag);
+ cmHandleStatePerCmHandle.put(yangModelCmHandle, CmHandleState.LOCKED);
+ } else {
+ notReadyCmHandles.add(cmHandleId);
+ }
+ });
- private static Map<String, String> getCmHandlePropertiesAsMap(
- final List<AdditionalProperty> cmHandlePropertiesAsList) {
- if (cmHandlePropertiesAsList == null || cmHandlePropertiesAsList.isEmpty()) {
- return Collections.emptyMap();
- }
- final Map<String, String> cmHandlePropertiesAsMap = new LinkedHashMap<>();
- for (final AdditionalProperty additionalProperty: cmHandlePropertiesAsList) {
- cmHandlePropertiesAsMap.put(additionalProperty.getName(),
- additionalProperty.getValue());
- }
- return cmHandlePropertiesAsMap;
+ final List<CmHandleRegistrationResponse> cmHandleRegistrationResponses
+ = upgradeCmHandles(cmHandleStatePerCmHandle);
+ cmHandleRegistrationResponses.addAll(CmHandleRegistrationResponse.createFailureResponses(notReadyCmHandles,
+ CM_HANDLES_NOT_READY));
+ return cmHandleRegistrationResponses;
}
- private static Object handleResponse(final @NotNull ResponseEntity<Object> responseEntity) {
- if (responseEntity.getStatusCode() == HttpStatus.OK) {
- return responseEntity.getBody();
- } else {
- throw new NcmpException("Not able to get resource data.",
- "DMI status code: " + responseEntity.getStatusCodeValue()
- + ", DMI response body: " + responseEntity.getBody());
+ private CmHandleRegistrationResponse deleteCmHandleAndGetCmHandleRegistrationResponse(final String cmHandleId) {
+ try {
+ deleteCmHandleFromDbAndModuleSyncMap(cmHandleId);
+ return CmHandleRegistrationResponse.createSuccessResponse(cmHandleId);
+ } catch (final DataNodeNotFoundException dataNodeNotFoundException) {
+ log.error("Unable to find dataNode for cmHandleId : {} , caused by : {}",
+ cmHandleId, dataNodeNotFoundException.getMessage());
+ return CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLES_NOT_FOUND);
+ } catch (final DataValidationException dataValidationException) {
+ log.error("Unable to de-register cm-handle id: {}, caused by: {}",
+ cmHandleId, dataValidationException.getMessage());
+ return CmHandleRegistrationResponse.createFailureResponse(cmHandleId, CM_HANDLE_INVALID_ID);
+ } catch (final Exception exception) {
+ log.error("Unable to de-register cm-handle id : {} , caused by : {}", cmHandleId, exception.getMessage());
+ return CmHandleRegistrationResponse.createFailureResponse(cmHandleId, exception);
}
}
- private static void handleResponseForPost(final @NotNull ResponseEntity<String> responseEntity) {
- if (!HttpStatus.valueOf(responseEntity.getStatusCodeValue()).is2xxSuccessful()) {
- throw new NcmpException("Not able to create resource data.",
- "DMI status code: " + responseEntity.getStatusCodeValue()
- + ", DMI response body: " + responseEntity.getBody());
- }
+ private void updateCmHandleStateBatch(final Collection<YangModelCmHandle> yangModelCmHandles,
+ final CmHandleState cmHandleState) {
+ final Map<YangModelCmHandle, CmHandleState> cmHandleStatePerCmHandle = new HashMap<>(yangModelCmHandles.size());
+ yangModelCmHandles.forEach(yangModelCmHandle -> cmHandleStatePerCmHandle.put(yangModelCmHandle, cmHandleState));
+ lcmEventsCmHandleStateHandler.updateCmHandleStateBatch(cmHandleStatePerCmHandle);
}
- private String getGenericRequestBody(final DataNode cmHandleDataNode) {
- final Collection<DataNode> cmHandlePropertiesAsDataNodes = cmHandleDataNode.getChildDataNodes();
- final Map<String, String> cmHandlePropertiesAsMap = getCmHandlePropertiesAsMap(cmHandlePropertiesAsDataNodes);
- final GenericRequestBody requestBodyObject = GenericRequestBody.builder()
- .operation(GenericRequestBody.OperationEnum.READ)
- .cmHandleProperties(cmHandlePropertiesAsMap)
- .build();
- return prepareOperationBody(requestBodyObject);
+ private void deleteCmHandleFromDbAndModuleSyncMap(final String cmHandleId) {
+ inventoryPersistence.deleteSchemaSetWithCascade(cmHandleId);
+ inventoryPersistence.deleteDataNode(NCMP_DMI_REGISTRY_PARENT + "/cm-handles[@id='" + cmHandleId
+ + "']");
+ removeDeletedCmHandleFromModuleSyncMap(cmHandleId);
}
- private void parseAndUpdateCmHandlesInDmiRegistration(final DmiPluginRegistration dmiPluginRegistration)
- throws JsonProcessingException {
- final PersistenceCmHandlesList updatedPersistenceCmHandlesList = toPersistenceCmHandlesList(
- dmiPluginRegistration.getDmiPlugin(),
- dmiPluginRegistration.getUpdatedCmHandles());
- final String cmHandlesAsJson = objectMapper.writeValueAsString(updatedPersistenceCmHandlesList);
- cpsDataService.updateNodeLeavesAndExistingDescendantLeaves(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- "/dmi-registry", cmHandlesAsJson, NO_TIMESTAMP);
+ private void batchDeleteCmHandlesFromDbAndModuleSyncMap(final Collection<String> tobeRemovedCmHandles) {
+ inventoryPersistence.deleteSchemaSetsWithCascade(tobeRemovedCmHandles);
+ inventoryPersistence.deleteDataNodes(mapCmHandleIdsToXpaths(tobeRemovedCmHandles));
+ tobeRemovedCmHandles.forEach(this::removeDeletedCmHandleFromModuleSyncMap);
}
- private void parseAndCreateCmHandlesInDmiRegistrationAndSyncModule(
- final DmiPluginRegistration dmiPluginRegistration) throws JsonProcessingException {
- final PersistenceCmHandlesList createdPersistenceCmHandlesList = toPersistenceCmHandlesList(
- dmiPluginRegistration.getDmiPlugin(),
- dmiPluginRegistration.getCreatedCmHandles());
- registerAndSyncNewCmHandles(createdPersistenceCmHandlesList);
+ private Collection<String> mapCmHandleIdsToXpaths(final Collection<String> cmHandles) {
+ return cmHandles.stream()
+ .map(cmHandleId -> NCMP_DMI_REGISTRY_PARENT + "/cm-handles[@id='" + cmHandleId + "']")
+ .collect(Collectors.toSet());
}
- private static PersistenceCmHandlesList toPersistenceCmHandlesList(final String dmiPlugin,
- final Collection<CmHandle> cmHandles) {
- final PersistenceCmHandlesList persistenceCmHandlesList = new PersistenceCmHandlesList();
- for (final CmHandle cmHandle : cmHandles) {
- final PersistenceCmHandle persistenceCmHandle = toPersistenceCmHandle(dmiPlugin, cmHandle);
- persistenceCmHandlesList.add(persistenceCmHandle);
+ // CPS-1239 Robustness cleaning of in progress cache
+ private void removeDeletedCmHandleFromModuleSyncMap(final String deletedCmHandleId) {
+ if (moduleSyncStartedOnCmHandles.remove(deletedCmHandleId) != null) {
+ log.debug("{} removed from in progress map", deletedCmHandleId);
}
- return persistenceCmHandlesList;
}
- private static void handleJsonProcessingException(final DmiPluginRegistration dmiPluginRegistration,
- final JsonProcessingException e) {
- final String message = "Parsing error occurred while processing DMI Plugin Registration"
- + dmiPluginRegistration;
- log.error(message);
- throw new DataValidationException(message, e.getMessage(), e);
- }
-
- private void registerAndSyncNewCmHandles(final PersistenceCmHandlesList persistenceCmHandlesList)
- throws JsonProcessingException {
- final String cmHandleJsonData = objectMapper.writeValueAsString(persistenceCmHandlesList);
- cpsDataService.saveListElements(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, "/dmi-registry",
- cmHandleJsonData, NO_TIMESTAMP);
-
- for (final PersistenceCmHandle persistenceCmHandle : persistenceCmHandlesList.getPersistenceCmHandles()) {
- syncModulesAndCreateAnchor(persistenceCmHandle);
+ private List<CmHandleRegistrationResponse> registerNewCmHandles(final Map<YangModelCmHandle, CmHandleState>
+ cmHandleStatePerCmHandle) {
+ final List<String> cmHandleIds = getCmHandleIds(cmHandleStatePerCmHandle);
+ try {
+ lcmEventsCmHandleStateHandler.updateCmHandleStateBatch(cmHandleStatePerCmHandle);
+ return CmHandleRegistrationResponse.createSuccessResponses(cmHandleIds);
+ } catch (final AlreadyDefinedException alreadyDefinedException) {
+ return CmHandleRegistrationResponse.createFailureResponses(
+ alreadyDefinedException.getAlreadyDefinedObjectNames(),
+ CM_HANDLE_ALREADY_EXIST);
+ } catch (final Exception exception) {
+ return CmHandleRegistrationResponse.createFailureResponses(cmHandleIds, exception);
}
}
- protected void syncModulesAndCreateAnchor(final PersistenceCmHandle persistenceCmHandle) {
- fetchAndSyncModules(persistenceCmHandle);
- createAnchor(persistenceCmHandle);
- }
-
- private static PersistenceCmHandle toPersistenceCmHandle(final String dmiPluginService,
- final CmHandle cmHandle) {
- final PersistenceCmHandle persistenceCmHandle = new PersistenceCmHandle();
- persistenceCmHandle.setDmiServiceName(dmiPluginService);
- persistenceCmHandle.setId(cmHandle.getCmHandleID());
- if (cmHandle.getCmHandleProperties() == null) {
- persistenceCmHandle.setAdditionalProperties(Collections.emptyMap());
- } else {
- persistenceCmHandle.setAdditionalProperties(cmHandle.getCmHandleProperties());
+ private List<CmHandleRegistrationResponse> upgradeCmHandles(final Map<YangModelCmHandle, CmHandleState>
+ cmHandleStatePerCmHandle) {
+ final List<String> cmHandleIds = getCmHandleIds(cmHandleStatePerCmHandle);
+ log.info("Moving cm handles : {} into locked (for upgrade) state.", cmHandleIds);
+ try {
+ lcmEventsCmHandleStateHandler.updateCmHandleStateBatch(cmHandleStatePerCmHandle);
+ return CmHandleRegistrationResponse.createSuccessResponses(cmHandleIds);
+ } catch (final Exception exception) {
+ return CmHandleRegistrationResponse.createFailureResponses(cmHandleIds, exception);
}
- return persistenceCmHandle;
}
- private void parseAndRemoveCmHandlesInDmiRegistration(final DmiPluginRegistration dmiPluginRegistration) {
- for (final String cmHandle : dmiPluginRegistration.getRemovedCmHandles()) {
- try {
- cpsDataService.deleteListOrListElement(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR,
- "/dmi-registry/cm-handles[@id='" + cmHandle + "']", NO_TIMESTAMP);
- } catch (final DataNodeNotFoundException e) {
- log.warn("Datanode {} not deleted message {}", cmHandle, e.getMessage());
- }
- }
+ private static List<String> getCmHandleIds(final Map<YangModelCmHandle, CmHandleState> cmHandleStatePerCmHandle) {
+ return cmHandleStatePerCmHandle.keySet().stream().map(YangModelCmHandle::getId).toList();
}
- private void fetchAndSyncModules(final PersistenceCmHandle persistenceCmHandle) {
- final Map<String, String> cmHandlePropertiesAsMap = getCmHandlePropertiesAsMap(
- persistenceCmHandle.getAdditionalProperties());
-
- final List<ModuleReference> moduleReferencesFromCmHandle =
- fetchModuleReferencesFromDmi(persistenceCmHandle, cmHandlePropertiesAsMap);
- final List<ModuleReference> existingModuleReferences = new ArrayList<>();
- final List<ModuleReference> unknownModuleReferences = new ArrayList<>();
- prepareModuleSubsets(moduleReferencesFromCmHandle, existingModuleReferences, unknownModuleReferences);
-
- final Map<String, String> newYangResourcesModuleNameToContentMap;
- if (unknownModuleReferences.isEmpty()) {
- newYangResourcesModuleNameToContentMap = new HashMap<>();
+ private void setTrustLevelPerDmiPlugin(final DmiPluginRegistration dmiPluginRegistration) {
+ if (DmiPluginRegistration.isNullEmptyOrBlank(dmiPluginRegistration.getDmiDataPlugin())) {
+ trustLevelPerDmiPlugin.put(dmiPluginRegistration.getDmiPlugin(), TrustLevel.COMPLETE);
} else {
- newYangResourcesModuleNameToContentMap = getNewYangResourcesFromDmi(persistenceCmHandle,
- unknownModuleReferences, cmHandlePropertiesAsMap);
+ trustLevelPerDmiPlugin.put(dmiPluginRegistration.getDmiDataPlugin(), TrustLevel.COMPLETE);
}
- cpsModuleService
- .createSchemaSetFromModules(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, persistenceCmHandle.getId(),
- newYangResourcesModuleNameToContentMap, existingModuleReferences);
}
- private void prepareModuleSubsets(final List<ModuleReference> moduleReferencesFromCmHandle,
- final List<ModuleReference> existingModuleReferences,
- final List<ModuleReference> unknownModuleReferences) {
-
- final Collection<ModuleReference> knownModuleReferencesInCps =
- cpsModuleService.getYangResourceModuleReferences(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME);
-
- for (final ModuleReference moduleReferenceFromDmiForCmHandle : moduleReferencesFromCmHandle) {
- if (knownModuleReferencesInCps.contains(moduleReferenceFromDmiForCmHandle)) {
- existingModuleReferences.add(moduleReferenceFromDmiForCmHandle);
- } else {
- unknownModuleReferences.add(moduleReferenceFromDmiForCmHandle);
- }
- }
- }
-
- private List<ModuleReference> fetchModuleReferencesFromDmi(final PersistenceCmHandle persistenceCmHandle,
- final Map<String, String> cmHandlePropertiesAsMap) {
- final GenericRequestBody genericRequestBody = GenericRequestBody.builder()
- .cmHandleProperties(cmHandlePropertiesAsMap)
- .build();
- final String jsonBodyWithOnlyCmHandleProperties = prepareOperationBody(genericRequestBody);
- final ResponseEntity<String> dmiFetchModulesResponseEntity =
- dmiOperations.getResourceFromDmiWithJsonData(persistenceCmHandle.getDmiServiceName(),
- jsonBodyWithOnlyCmHandleProperties, persistenceCmHandle.getId(), "modules");
- return toModuleReferences(dmiFetchModulesResponseEntity);
- }
-
- private void createAnchor(final PersistenceCmHandle persistenceCmHandle) {
- cpsAdminService.createAnchor(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, persistenceCmHandle.getId(),
- persistenceCmHandle.getId());
- }
-
- private String getRequestBodyToFetchYangResourceFromDmi(final List<ModuleReference> unknownModuleReferences,
- final Map<String, String> cmHandlePropertiesAsMap) {
- final JsonArray moduleReferencesAsJson = getModuleReferencesAsJson(unknownModuleReferences);
- final JsonObject data = new JsonObject();
- data.add("modules", moduleReferencesAsJson);
- final JsonObject jsonRequestObject = new JsonObject();
- jsonRequestObject.add("data", data);
- final Gson gson = new Gson();
- jsonRequestObject.add("cmHandleProperties", gson.toJsonTree(cmHandlePropertiesAsMap));
- return jsonRequestObject.toString();
- }
-
- private static JsonArray getModuleReferencesAsJson(final List<ModuleReference> unknownModuleReferences) {
- final JsonArray moduleReferences = new JsonArray();
-
- for (final ModuleReference moduleReference : unknownModuleReferences) {
- final JsonObject moduleReferenceAsJson = new JsonObject();
- moduleReferenceAsJson.addProperty("name", moduleReference.getModuleName());
- moduleReferenceAsJson.addProperty(REVISION, moduleReference.getRevision());
- moduleReferences.add(moduleReferenceAsJson);
- }
- return moduleReferences;
- }
-
- private Map<String, String> getNewYangResourcesFromDmi(final PersistenceCmHandle persistenceCmHandle,
- final List<ModuleReference> unknownModuleReferences,
- final Map<String, String> cmHandlePropertiesAsMap) {
- final String jsonDataWithDataAndCmHandleProperties = getRequestBodyToFetchYangResourceFromDmi(
- unknownModuleReferences, cmHandlePropertiesAsMap);
-
- final ResponseEntity<String> moduleResourcesAsJsonString = dmiOperations.getResourceFromDmiWithJsonData(
- persistenceCmHandle.getDmiServiceName(),
- jsonDataWithDataAndCmHandleProperties,
- persistenceCmHandle.getId(),
- "moduleResources");
-
- final JsonArray moduleResources = new Gson().fromJson(moduleResourcesAsJsonString.getBody(),
- JsonArray.class);
- final Map<String, String> newYangResourcesModuleNameToContentMap = new HashMap<>();
-
- for (final JsonElement moduleResource : moduleResources) {
- final YangResource yangResource = toYangResource((JsonObject) moduleResource);
- newYangResourcesModuleNameToContentMap.put(yangResource.getModuleName(), yangResource.getYangSource());
- }
- return newYangResourcesModuleNameToContentMap;
- }
-
- private static YangResource toYangResource(final JsonObject yangResourceAsJson) {
- final YangResource yangResource = new YangResource();
- yangResource.setModuleName(yangResourceAsJson.get("moduleName").getAsString());
- yangResource.setRevision(yangResourceAsJson.get(REVISION).getAsString());
- final String yangSourceJson = yangResourceAsJson.get("yangSource").getAsString();
-
- String yangSource = JsonUtils.removeWrappingTokens(yangSourceJson);
- yangSource = JsonUtils.removeRedundantEscapeCharacters(yangSource);
- yangResource.setYangSource(yangSource);
-
- return yangResource;
- }
-
- private static List<ModuleReference> toModuleReferences(
- final ResponseEntity<String> dmiFetchModulesResponseEntity) {
- final List<ModuleReference> moduleReferences = new ArrayList<>();
- final JsonObject bodyAsJsonObject = new Gson().fromJson(dmiFetchModulesResponseEntity.getBody(),
- JsonObject.class);
- final JsonArray moduleReferencesAsJson = bodyAsJsonObject.getAsJsonArray("schemas");
- for (final JsonElement moduleReferenceAsJson : moduleReferencesAsJson) {
- final ModuleReference moduleReference = toModuleReference((JsonObject) moduleReferenceAsJson);
- moduleReferences.add(moduleReference);
- }
- return moduleReferences;
- }
-
- private static ModuleReference toModuleReference(final JsonObject moduleReferenceAsJson) {
- final ModuleReference moduleReference = new ModuleReference();
- moduleReference.setModuleName(moduleReferenceAsJson.get("moduleName").getAsString());
- moduleReference.setRevision(moduleReferenceAsJson.get(REVISION).getAsString());
- return moduleReference;
- }
}