aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ncmp-service/src/main')
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java27
-rwxr-xr-xcps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java18
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiDataOperations.java17
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/AlternateIdChecker.java34
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmResourceAddress.java25
5 files changed, 67 insertions, 54 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 4230140d26..20545d711d 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
@@ -29,6 +29,7 @@ import org.onap.cps.ncmp.api.impl.inventory.CompositeState;
import org.onap.cps.ncmp.api.impl.operations.OperationType;
import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters;
import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters;
+import org.onap.cps.ncmp.api.models.CmResourceAddress;
import org.onap.cps.ncmp.api.models.DataOperationRequest;
import org.onap.cps.ncmp.api.models.DmiPluginRegistration;
import org.onap.cps.ncmp.api.models.DmiPluginRegistrationResponse;
@@ -53,18 +54,14 @@ public interface NetworkCmProxyDataService {
/**
* Get resource data for given data store using dmi.
*
- * @param datastoreName datastore name
- * @param cmHandleId cm handle identifier
- * @param resourceIdentifier resource identifier
+ * @param cmResourceAddress target datastore, cm handle and resource identifier
* @param optionsParamInQuery options query
* @param topicParamInQuery topic name for (triggering) async responses
* @param requestId unique requestId for async request
* @param authorization contents of Authorization header, or null if not present
* @return {@code Object} resource data
*/
- Object getResourceDataForCmHandle(String datastoreName,
- String cmHandleId,
- String resourceIdentifier,
+ Object getResourceDataForCmHandle(CmResourceAddress cmResourceAddress,
String optionsParamInQuery,
String topicParamInQuery,
String requestId,
@@ -73,15 +70,11 @@ public interface NetworkCmProxyDataService {
/**
* Get resource data for operational.
*
- * @param datastoreName datastore name
- * @param cmHandleId cm handle identifier
- * @param resourceIdentifier resource identifier
+ * @param cmResourceAddress target datastore, cm handle and resource identifier
* @Link FetchDescendantsOption fetch descendants option
* @return {@code Object} resource data
*/
- Object getResourceDataForCmHandle(String datastoreName,
- String cmHandleId,
- String resourceIdentifier,
+ Object getResourceDataForCmHandle(CmResourceAddress cmResourceAddress,
FetchDescendantsOption fetchDescendantsOption);
/**
@@ -110,11 +103,11 @@ public interface NetworkCmProxyDataService {
* @return {@code Object} return data
*/
Object writeResourceDataPassThroughRunningForCmHandle(String cmHandleId,
- String resourceIdentifier,
- OperationType operationType,
- String requestBody,
- String contentType,
- String authorization);
+ String resourceIdentifier,
+ OperationType operationType,
+ String requestBody,
+ String contentType,
+ String authorization);
/**
* Retrieve module references for the given cm handle.
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 6ab6eab653..c15df9c869 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
@@ -72,6 +72,7 @@ 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.CmResourceAddress;
import org.onap.cps.ncmp.api.models.DataOperationRequest;
import org.onap.cps.ncmp.api.models.DmiPluginRegistration;
import org.onap.cps.ncmp.api.models.DmiPluginRegistrationResponse;
@@ -127,15 +128,12 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
}
@Override
- public Object getResourceDataForCmHandle(final String datastoreName,
- final String cmHandleId,
- final String resourceIdentifier,
+ public Object getResourceDataForCmHandle(final CmResourceAddress cmResourceAddress,
final String optionsParamInQuery,
final String topicParamInQuery,
final String requestId,
final String authorization) {
- final ResponseEntity<?> responseEntity = dmiDataOperations.getResourceDataFromDmi(datastoreName, cmHandleId,
- resourceIdentifier,
+ final ResponseEntity<?> responseEntity = dmiDataOperations.getResourceDataFromDmi(cmResourceAddress,
optionsParamInQuery,
topicParamInQuery,
requestId,
@@ -144,12 +142,12 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
}
@Override
- public Object getResourceDataForCmHandle(final String datastoreName,
- final String cmHandleId,
- final String resourceIdentifier,
+ public Object getResourceDataForCmHandle(final CmResourceAddress cmResourceAddress,
final FetchDescendantsOption fetchDescendantsOption) {
- return cpsDataService.getDataNodes(datastoreName, cmHandleId, resourceIdentifier,
- fetchDescendantsOption).iterator().next();
+ return cpsDataService.getDataNodes(cmResourceAddress.datastoreName(),
+ cmResourceAddress.cmHandleId(),
+ cmResourceAddress.resourceIdentifier(),
+ fetchDescendantsOption).iterator().next();
}
@Override
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiDataOperations.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiDataOperations.java
index 2a4bceca23..a9ec1241bc 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiDataOperations.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operations/DmiDataOperations.java
@@ -42,6 +42,7 @@ import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistence;
import org.onap.cps.ncmp.api.impl.utils.DmiServiceUrlBuilder;
import org.onap.cps.ncmp.api.impl.utils.data.operation.ResourceDataOperationRequestUtils;
import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle;
+import org.onap.cps.ncmp.api.models.CmResourceAddress;
import org.onap.cps.ncmp.api.models.DataOperationRequest;
import org.onap.cps.spi.exceptions.CpsException;
import org.onap.cps.utils.JsonObjectMapper;
@@ -70,9 +71,7 @@ public class DmiDataOperations extends DmiOperations {
* This method fetches the resource data from operational data store for given cm handle
* identifier on given resource using dmi client.
*
- * @param dataStoreName name of data store
- * @param cmHandleId network resource identifier
- * @param resourceId resource identifier
+ * @param cmResourceAddress target datastore, cm handle and resource identifier
* @param optionsParamInQuery options query
* @param topicParamInQuery topic name for (triggering) async responses
* @param requestId requestId for async responses
@@ -82,19 +81,17 @@ public class DmiDataOperations extends DmiOperations {
@Timed(value = "cps.ncmp.dmi.get",
description = "Time taken to fetch the resource data from operational data store for given cm handle "
+ "identifier on given resource using dmi client")
- public ResponseEntity<Object> getResourceDataFromDmi(final String dataStoreName,
- final String cmHandleId,
- final String resourceId,
+ public ResponseEntity<Object> getResourceDataFromDmi(final CmResourceAddress cmResourceAddress,
final String optionsParamInQuery,
final String topicParamInQuery,
final String requestId,
final String authorization) {
- final YangModelCmHandle yangModelCmHandle = getYangModelCmHandle(cmHandleId);
+ final YangModelCmHandle yangModelCmHandle = getYangModelCmHandle(cmResourceAddress.cmHandleId());
final CmHandleState cmHandleState = yangModelCmHandle.getCompositeState().getCmHandleState();
validateIfCmHandleStateReady(yangModelCmHandle, cmHandleState);
- final String jsonRequestBody = getDmiRequestBody(READ, requestId, null, null,
- yangModelCmHandle);
- final String dmiResourceDataUrl = getDmiRequestUrl(dataStoreName, cmHandleId, resourceId, optionsParamInQuery,
+ final String jsonRequestBody = getDmiRequestBody(READ, requestId, null, null, yangModelCmHandle);
+ final String dmiResourceDataUrl = getDmiRequestUrl(cmResourceAddress.datastoreName(),
+ cmResourceAddress.cmHandleId(), cmResourceAddress.resourceIdentifier(), optionsParamInQuery,
topicParamInQuery, yangModelCmHandle.resolveDmiServiceName(RequiredDmiService.DATA));
return dmiRestClient.postOperationWithJsonData(dmiResourceDataUrl, jsonRequestBody, READ, authorization);
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/AlternateIdChecker.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/AlternateIdChecker.java
index f14439f690..60f39fcea0 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/AlternateIdChecker.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/AlternateIdChecker.java
@@ -115,23 +115,7 @@ public class AlternateIdChecker {
for (final NcmpServiceCmHandle ncmpServiceCmHandle : newNcmpServiceCmHandles) {
final String cmHandleId = ncmpServiceCmHandle.getCmHandleId();
final String proposedAlternateId = ncmpServiceCmHandle.getAlternateId();
- final boolean isAcceptable;
- if (StringUtils.isEmpty(proposedAlternateId)) {
- isAcceptable = true;
- } else {
- if (acceptedAlternateIds.contains(proposedAlternateId)) {
- isAcceptable = false;
- log.warn("Alternate id update ignored, cannot update cm handle {}, alternate id is already "
- + "assigned to a different cm handle (in this batch)", cmHandleId);
- } else {
- if (Operation.CREATE.equals(operation)) {
- isAcceptable = canApplyAlternateId(cmHandleId, NO_CURRENT_ALTERNATE_ID, proposedAlternateId);
- } else {
- isAcceptable = canApplyAlternateId(cmHandleId, proposedAlternateId);
- }
- }
- }
- if (isAcceptable) {
+ if (isProposedAlternateIdAcceptable(proposedAlternateId, operation, acceptedAlternateIds, cmHandleId)) {
acceptedAlternateIds.add(proposedAlternateId);
} else {
rejectedCmHandleIds.add(cmHandleId);
@@ -140,6 +124,22 @@ public class AlternateIdChecker {
return rejectedCmHandleIds;
}
+ private boolean isProposedAlternateIdAcceptable(final String proposedAlternateId, final Operation operation,
+ final Set<String> acceptedAlternateIds, final String cmHandleId) {
+ if (StringUtils.isEmpty(proposedAlternateId)) {
+ return true;
+ }
+ if (acceptedAlternateIds.contains(proposedAlternateId)) {
+ log.warn("Alternate id update ignored, cannot update cm handle {}, alternate id is already "
+ + "assigned to a different cm handle (in this batch)", cmHandleId);
+ return false;
+ }
+ if (Operation.CREATE.equals(operation)) {
+ return canApplyAlternateId(cmHandleId, NO_CURRENT_ALTERNATE_ID, proposedAlternateId);
+ }
+ return canApplyAlternateId(cmHandleId, proposedAlternateId);
+ }
+
private boolean alternateIdAlreadyInDb(final String alternateId) {
try {
inventoryPersistence.getCmHandleDataNodeByAlternateId(alternateId);
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmResourceAddress.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmResourceAddress.java
new file mode 100644
index 0000000000..21d82fcf56
--- /dev/null
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmResourceAddress.java
@@ -0,0 +1,25 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2024 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.ncmp.api.models;
+
+public record CmResourceAddress(String datastoreName, String cmHandleId, String resourceIdentifier) {
+
+}