diff options
author | tragait <rahul.tyagi@est.tech> | 2021-08-19 15:17:56 +0100 |
---|---|---|
committer | tragait <rahul.tyagi@est.tech> | 2021-08-20 15:31:31 +0100 |
commit | 888dcd495ecb63bf678e7234e9dc34e0743cb412 (patch) | |
tree | 65e1208beacc9a11eeb08985a1d4b28a90f3864c /cps-ncmp-service/src/main/java/org/onap | |
parent | dc5ed75c841da857611713bceed8bf9988204d3d (diff) |
Get resource data from pass through running (Ncmp impl.)
Issue-ID: CPS-580
Signed-off-by: tragait <rahul.tyagi@est.tech>
Change-Id: I6dc37d9516078c87efc3f0c5bbd2b7b8a7155d48
Diffstat (limited to 'cps-ncmp-service/src/main/java/org/onap')
3 files changed, 124 insertions, 39 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java index 82be7bf55c..3e715e5e75 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java @@ -23,6 +23,7 @@ package org.onap.cps.ncmp.api; import java.util.Collection; +import javax.validation.constraints.NotNull; import org.checkerframework.checker.nullness.qual.NonNull; import org.onap.cps.ncmp.api.models.DmiPluginRegistration; import org.onap.cps.spi.FetchDescendantsOption; @@ -117,9 +118,26 @@ public interface NetworkCmProxyDataService { * @param depth depth query * @return {@code Object} resource data */ - Object getResourceDataOperationalFoCmHandle(@NonNull String cmHandle, - @NonNull String resourceIdentifier, - String accept, - String fields, - Integer depth); + Object getResourceDataOperationalForCmHandle(@NotNull String cmHandle, + @NotNull String resourceIdentifier, + String accept, + String fields, + Integer depth); + + /** + * Get resource data for data store pass-through running + * using dmi. + * + * @param cmHandle cm handle + * @param resourceIdentifier resource identifier + * @param accept accept param + * @param fields fields query + * @param depth depth query + * @return {@code Object} resource data + */ + Object getResourceDataPassThroughRunningForCmHandle(@NotNull String cmHandle, + @NotNull String resourceIdentifier, + String accept, + String fields, + Integer depth); } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java index 84dcc770d9..c2be9e9db5 100755 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java @@ -29,6 +29,7 @@ import java.util.Collection; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import javax.validation.constraints.NotNull; import lombok.extern.slf4j.Slf4j; import org.onap.cps.api.CpsDataService; import org.onap.cps.api.CpsQueryService; @@ -149,17 +150,17 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService } @Override - public Object getResourceDataOperationalFoCmHandle(final String cmHandle, - final String resourceIdentifier, - final String acceptParam, - final String fieldsQueryParam, - final Integer depthQueryParam) { - - final DataNode dataNode = fetchDataNodeFromDmiRegistryForCmHandle(cmHandle); - final String dmiServiceName = String.valueOf(dataNode.getLeaves().get("dmi-service-name")); + public Object getResourceDataOperationalForCmHandle(final @NotNull String cmHandle, + final @NotNull String resourceIdentifier, + final String acceptParam, + final String fieldsQueryParam, + final Integer depthQueryParam) { + + final var dataNode = fetchDataNodeFromDmiRegistryForCmHandle(cmHandle); + final var dmiServiceName = String.valueOf(dataNode.getLeaves().get("dmi-service-name")); final Collection<DataNode> additionalPropsList = dataNode.getChildDataNodes(); - final String jsonBody = prepareOperationBody(GenericRequestBody.OperationEnum.READ, additionalPropsList); - final ResponseEntity<Object> response = dmiOperations.getResouceDataFromDmi(dmiServiceName, + final var jsonBody = prepareOperationBody(GenericRequestBody.OperationEnum.READ, additionalPropsList); + final ResponseEntity<Object> response = dmiOperations.getResouceDataOperationalFromDmi(dmiServiceName, cmHandle, resourceIdentifier, fieldsQueryParam, @@ -169,6 +170,26 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService return handleResponse(response); } + @Override + public Object getResourceDataPassThroughRunningForCmHandle(final @NotNull String cmHandle, + final @NotNull String resourceIdentifier, + final String accept, + final String fields, + final Integer depth) { + final var cmHandleDataNode = fetchDataNodeFromDmiRegistryForCmHandle(cmHandle); + final var dmiServiceName = String.valueOf(cmHandleDataNode.getLeaves().get("dmi-service-name")); + final Collection<DataNode> additionalPropsList = cmHandleDataNode.getChildDataNodes(); + final var dmiRequesBody = prepareOperationBody(GenericRequestBody.OperationEnum.READ, additionalPropsList); + final ResponseEntity<Object> response = dmiOperations.getResouceDataPassThroughRunningFromDmi(dmiServiceName, + cmHandle, + resourceIdentifier, + fields, + depth, + accept, + dmiRequesBody); + return handleResponse(response); + } + private DataNode fetchDataNodeFromDmiRegistryForCmHandle(final String cmHandle) { final String xpathForDmiRegistryToFetchCmHandle = "/dmi-registry/cm-handles[@id='" + cmHandle + "']"; final var dataNode = cpsDataService.getDataNode(NCMP_DATASPACE_NAME, @@ -180,12 +201,12 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService private String prepareOperationBody(final GenericRequestBody.OperationEnum operation, final Collection<DataNode> additionalPropertyList) { - final GenericRequestBody requestBody = new GenericRequestBody(); + final var requestBody = new GenericRequestBody(); final Map<String, String> additionalPropertyMap = getAdditionalPropertiesMap(additionalPropertyList); requestBody.setOperation(GenericRequestBody.OperationEnum.READ); requestBody.setCmHandleProperties(additionalPropertyMap); try { - final String requestJson = objectMapper.writeValueAsString(requestBody); + final var requestJson = objectMapper.writeValueAsString(requestBody); return requestJson; } catch (final JsonProcessingException je) { log.error("Parsing error occurred while converting Object to JSON."); @@ -199,7 +220,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService return null; } final Map<String, String> additionalPropertyMap = new LinkedHashMap<>(); - for (final DataNode node: additionalPropertyList) { + for (final var node: additionalPropertyList) { additionalPropertyMap.put(String.valueOf(node.getLeaves().get("name")), String.valueOf(node.getLeaves().get("value"))); } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operation/DmiOperations.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operation/DmiOperations.java index c7554bc482..2b13d165f2 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operation/DmiOperations.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operation/DmiOperations.java @@ -20,6 +20,8 @@ package org.onap.cps.ncmp.api.impl.operation; +import com.fasterxml.jackson.annotation.JsonValue; +import lombok.Getter; import org.jetbrains.annotations.NotNull; import org.onap.cps.ncmp.api.impl.client.DmiRestClient; import org.springframework.http.HttpHeaders; @@ -29,10 +31,27 @@ import org.springframework.stereotype.Component; @Component public class DmiOperations { + @Getter + public enum PassThroughEnum { + OPERATIONAL("/ncmp-datastore:passthrough-operational/"), + RUNNING("/ncmp-datastore:passthrough-running/"); + private String value; + + PassThroughEnum(final String value) { + this.value = value; + } + + @Override + @JsonValue + public String toString() { + return String.valueOf(value); + } + } + private DmiRestClient dmiRestClient; - private static final String GET_RESOURCE_DATA_FOR_PASSTHROUGH_OPERATIONAL = - "/v1/ch/{cmHandle}/data/ds/ncmp-datastore:passthrough-operational/"; - private int indexCmHandleForGetOperational; + private static final String PARENT_CM_HANDLE_URI = + "/v1/ch/{cmHandle}/data/ds"; + private final int indexCmHandleInUri; /** * Constructor for {@code DmiOperations}. This method also manipulates url properties. @@ -41,12 +60,38 @@ public class DmiOperations { */ public DmiOperations(final DmiRestClient dmiRestClient) { this.dmiRestClient = dmiRestClient; - indexCmHandleForGetOperational = GET_RESOURCE_DATA_FOR_PASSTHROUGH_OPERATIONAL.indexOf("{cmHandle}"); + indexCmHandleInUri = PARENT_CM_HANDLE_URI.indexOf("{cmHandle}"); + } + + /** + * This method fetches the resource data from operational data store for given cm handle + * identifier on given resource using dmi client. + * + * @param dmiBasePath dmi base path + * @param cmHandle network resource identifier + * @param resourceId resource identifier + * @param fieldsQuery fields query + * @param depthQuery depth query + * @param acceptParam accept parameter + * @param jsonBody json body for put operation + * @return {@code ResponseEntity} response entity + */ + public ResponseEntity<Object> getResouceDataOperationalFromDmi(final String dmiBasePath, + final String cmHandle, + final String resourceId, + final String fieldsQuery, + final Integer depthQuery, + final String acceptParam, + final String jsonBody) { + final var builder = getDmiResourceDataUrl(dmiBasePath, cmHandle, resourceId, + fieldsQuery, depthQuery, PassThroughEnum.OPERATIONAL); + final var httpHeaders = prepareHeader(acceptParam); + return dmiRestClient.putOperationWithJsonData(builder.toString(), jsonBody, httpHeaders); } /** - * This method fetches the resource data for given cm handle identifier on given resource - * using dmi client. + * This method fetches the resource data from pass-through running data store for given cm handle + * identifier on given resource using dmi client. * * @param dmiBasePath dmi base path * @param cmHandle network resource identifier @@ -57,15 +102,16 @@ public class DmiOperations { * @param jsonBody json body for put operation * @return {@code ResponseEntity} response entity */ - public ResponseEntity<Object> getResouceDataFromDmi(final String dmiBasePath, - final String cmHandle, - final String resourceId, - final String fieldsQuery, - final Integer depthQuery, - final String acceptParam, - final String jsonBody) { - final StringBuilder builder = getDmiResourceDataUrl(dmiBasePath, cmHandle, resourceId, fieldsQuery, depthQuery); - final HttpHeaders httpHeaders = prepareHeader(acceptParam); + public ResponseEntity<Object> getResouceDataPassThroughRunningFromDmi(final String dmiBasePath, + final String cmHandle, + final String resourceId, + final String fieldsQuery, + final Integer depthQuery, + final String acceptParam, + final String jsonBody) { + final var builder = getDmiResourceDataUrl(dmiBasePath, cmHandle, resourceId, + fieldsQuery, depthQuery, PassThroughEnum.RUNNING); + final var httpHeaders = prepareHeader(acceptParam); return dmiRestClient.putOperationWithJsonData(builder.toString(), jsonBody, httpHeaders); } @@ -74,10 +120,10 @@ public class DmiOperations { final String cmHandle, final String resourceId, final String fieldsQuery, - final Integer depthQuery) { - final StringBuilder builder = new StringBuilder(GET_RESOURCE_DATA_FOR_PASSTHROUGH_OPERATIONAL); - builder.replace(indexCmHandleForGetOperational, - indexCmHandleForGetOperational + "{cmHandle}".length(), cmHandle); + final Integer depthQuery, + final PassThroughEnum passThrough) { + final var builder = new StringBuilder(PARENT_CM_HANDLE_URI.replace("{cmHandle}", cmHandle)); + builder.append(passThrough.getValue()); builder.insert(builder.length(), resourceId); appendFieldsAndDepth(fieldsQuery, depthQuery, builder); builder.insert(0, dmiBasePath); @@ -85,7 +131,7 @@ public class DmiOperations { } private void appendFieldsAndDepth(final String fieldsQuery, final Integer depthQuery, final StringBuilder builder) { - final boolean doesFieldExists = (fieldsQuery != null && !fieldsQuery.isEmpty()); + final var doesFieldExists = (fieldsQuery != null && !fieldsQuery.isEmpty()); if (doesFieldExists) { builder.append("?").append("fields=").append(fieldsQuery); } @@ -100,7 +146,7 @@ public class DmiOperations { } private HttpHeaders prepareHeader(final String acceptParam) { - final HttpHeaders httpHeaders = new HttpHeaders(); + final var httpHeaders = new HttpHeaders(); if (acceptParam != null && !acceptParam.isEmpty()) { httpHeaders.set(HttpHeaders.ACCEPT, acceptParam); } |