summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/main/java/org/onap
diff options
context:
space:
mode:
authorToine Siebelink <toine.siebelink@est.tech>2021-11-15 17:39:04 +0000
committerGerrit Code Review <gerrit@onap.org>2021-11-15 17:39:04 +0000
commitbc742a1dbe39a3269abab9e62a9d489f460144b0 (patch)
tree7bc2704612a06bd155bbed3b073f07ce35c9af7d /cps-ncmp-service/src/main/java/org/onap
parent9e09fe868b39fd5f13092a923da3474deb0f75b9 (diff)
parent6c7791e04e43b056ab944c3f7935f182fcbb13fb (diff)
Merge "Update operation passthrough running - Service Layer"
Diffstat (limited to 'cps-ncmp-service/src/main/java/org/onap')
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java11
-rwxr-xr-xcps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java42
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operation/DmiOperations.java17
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/GenericRequestBody.java3
4 files changed, 67 insertions, 6 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 e480a46e08..45d5bd911a 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
@@ -168,4 +168,15 @@ public interface NetworkCmProxyDataService {
* given module names
*/
Collection<String> executeCmHandleHasAllModulesSearch(Collection<String> moduleNames);
+
+ /**
+ * Update resource data for data store pass-through running using dmi for the given cm-handle.
+ *
+ * @param cmHandle cm handle
+ * @param resourceIdentifier resource identifier
+ * @param requestBody request body to create resource
+ * @param contentType content type in body
+ */
+ void updateResourceDataPassThroughRunningForCmHandle(String cmHandle, String resourceIdentifier,
+ String requestBody, String contentType);
}
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 94544f389f..80cd297280 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
@@ -49,6 +49,7 @@ import org.onap.cps.ncmp.api.impl.operation.DmiOperations;
import org.onap.cps.ncmp.api.models.CmHandle;
import org.onap.cps.ncmp.api.models.DmiPluginRegistration;
import org.onap.cps.ncmp.api.models.GenericRequestBody;
+import org.onap.cps.ncmp.api.models.GenericRequestBody.OperationEnum;
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;
@@ -228,7 +229,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
cmHandle,
resourceIdentifier,
dmiRequestBody);
- handleResponseForPost(responseEntity);
+ handleResponseFromDmi(responseEntity, "Not able to create resource data.");
}
@Override
@@ -247,6 +248,36 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
return cpsAdminService.queryAnchorNames(NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME, moduleNames);
}
+ /**
+ * Update resource data for data store pass-through running using dmi for given cm-handle.
+ *
+ * @param cmHandle cm handle
+ * @param resourceIdentifier resource identifier
+ * @param requestBody request body to create resource
+ * @param contentType content type in body
+ */
+ @Override
+ public void updateResourceDataPassThroughRunningForCmHandle(final String cmHandle, final String resourceIdentifier,
+ final 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(OperationEnum.UPDATE)
+ .dataType(contentType)
+ .data(requestBody)
+ .cmHandleProperties(cmHandlePropertiesAsMap)
+ .build();
+ final String dmiRequestBody = prepareOperationBody(dmiRequestBodyObject);
+ final ResponseEntity<String> responseEntity = dmiOperations
+ .updateResourceDataPassThroughRunningFromDmi(dmiServiceName,
+ cmHandle,
+ resourceIdentifier,
+ dmiRequestBody);
+ handleResponseFromDmi(responseEntity, "Unable to replace resource data.");
+ }
+
private DataNode fetchDataNodeFromDmiRegistryForCmHandle(final String cmHandle) {
final String xpathForDmiRegistryToFetchCmHandle = "/dmi-registry/cm-handles[@id='" + cmHandle + "']";
return cpsDataService.getDataNode(NCMP_DATASPACE_NAME,
@@ -301,11 +332,12 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
}
}
- private static void handleResponseForPost(final @NotNull ResponseEntity<String> responseEntity) {
+ private static void handleResponseFromDmi(final @NotNull ResponseEntity<String> responseEntity,
+ final String exceptionMessage) {
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());
+ throw new NcmpException(exceptionMessage,
+ "DMI status code: " + responseEntity.getStatusCodeValue()
+ + ", DMI response body: " + responseEntity.getBody());
}
}
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 562c330657..40a47ecf66 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
@@ -174,6 +174,23 @@ public class DmiOperations {
return stringBuilder.toString();
}
+ /**
+ * This method updates the resource data from pass-through running data store for the cm handle identifier on given
+ * resource using dmi client.
+ *
+ * @param dmiServiceName dmi service name
+ * @param cmHandle network resource identifier
+ * @param resourceId resource identifier
+ * @param jsonBody json body for put operation
+ * @return {@code ResponseEntity} response entity
+ */
+ public ResponseEntity<String> updateResourceDataPassThroughRunningFromDmi(final String dmiServiceName,
+ final String cmHandle, final String resourceId, final String jsonBody) {
+ final StringBuilder stringBuilder =
+ getStringBuilderForPassThroughUrl(dmiServiceName, cmHandle, resourceId, DataStoreEnum.PASSTHROUGH_RUNNING);
+ return dmiRestClient.postOperationWithJsonData(stringBuilder.toString(), jsonBody, new HttpHeaders());
+ }
+
private String getDmiDatastoreUrl(final String dmiServiceName,
final String cmHandle,
final String resourceId,
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/GenericRequestBody.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/GenericRequestBody.java
index 4f6f0ef491..3e1ba4a971 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/GenericRequestBody.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/GenericRequestBody.java
@@ -33,7 +33,8 @@ import lombok.Getter;
public class GenericRequestBody {
public enum OperationEnum {
READ("read"),
- CREATE("create");
+ CREATE("create"),
+ UPDATE("update");
private String value;
OperationEnum(final String value) {