aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-infrastructure-common/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'bpmn/so-bpmn-infrastructure-common/src/main/java')
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java2
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/NfSoftwareUpgradeDispatcher.java168
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/UpdatePnfEntryInAai.java65
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/management/PnfManagement.java2
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/management/PnfManagementImpl.java5
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/service/ServicePluginFactory.java14
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/serviceTask/AbstractSdncOperationTask.java2
7 files changed, 249 insertions, 9 deletions
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java
index fab3496559..3ea8b190ad 100644
--- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java
@@ -35,8 +35,10 @@ public class ExecutionVariableNames {
public final static String TIMEOUT_FOR_NOTIFICATION = "timeoutForPnfEntryNotification";
public final static String PNF_UUID = "pnfUuid";
public final static String SERVICE_INSTANCE_ID = "serviceInstanceId";
+ public final static String REQUEST_ID = "requestId";
public final static String MSO_REQUEST_ID = "msoRequestId";
public final static String MODEL_UUID = "modelUuid";
+ public final static String REQUEST_PAYLOAD = "requestPayload";
public final static String SERVICE_MODEL_INFO = "serviceModelInfo";
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/NfSoftwareUpgradeDispatcher.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/NfSoftwareUpgradeDispatcher.java
new file mode 100644
index 0000000000..6c140061c0
--- /dev/null
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/NfSoftwareUpgradeDispatcher.java
@@ -0,0 +1,168 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 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.so.bpmn.infrastructure.pnf.delegate;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.camunda.bpm.engine.delegate.JavaDelegate;
+import org.onap.aai.domain.yang.Pnf;
+import org.onap.so.bpmn.core.json.JsonUtils;
+import org.onap.so.bpmn.infrastructure.pnf.management.PnfManagement;
+import org.onap.so.client.exception.ExceptionBuilder;
+import org.onap.so.db.catalog.beans.PnfResourceCustomization;
+import org.onap.so.db.catalog.client.CatalogDbClient;
+import org.onap.so.serviceinstancebeans.RequestDetails;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.*;
+
+/**
+ * This implementation of {@link JavaDelegate} is used to populate the execution object for pnf software upgrade
+ */
+@Component
+public class NfSoftwareUpgradeDispatcher implements JavaDelegate {
+
+ private final Logger logger = LoggerFactory.getLogger(getClass());
+ private static final String SERVICE_INSTANCE_NAME = "serviceInstanceName";
+ private static final String BPMN_REQUEST = "bpmnRequest";
+ private static final String RESOURCE_CUSTOMIZATION_UUID_PARAM = "resource_customization_uuid";
+ private static final String PNF_NAME = "pnfName";
+
+ // ERROR CODE for variable not found in the delegation Context
+ private static final int ERROR_CODE = 601;
+
+ @Autowired
+ private PnfManagement pnfManagement;
+
+ @Autowired
+ private ExceptionBuilder exceptionUtil;
+
+ @Autowired
+ private CatalogDbClient catalogDbClient;
+
+ @Autowired
+ private ObjectMapper mapper;
+
+ @Override
+ public void execute(DelegateExecution delegateExecution) throws Exception {
+ logger.debug("Running execute block for activity id: {}, name: {}", delegateExecution.getCurrentActivityId(),
+ delegateExecution.getCurrentActivityName());
+
+ RequestDetails bpmnRequestDetails = requestVerification(delegateExecution);
+
+ final String serviceInstanceName = bpmnRequestDetails.getRequestInfo().getInstanceName();
+ final String pnfName = bpmnRequestDetails.getRequestParameters().getUserParamValue(PNF_NAME);
+ final String serviceModelUuid = bpmnRequestDetails.getModelInfo().getModelUuid();
+ final List<Map<String, Object>> userParams = bpmnRequestDetails.getRequestParameters().getUserParams();
+ final Pnf pnf = getPnfByPnfName(delegateExecution, pnfName);
+ final List<PnfResourceCustomization> pnfCustomizations =
+ getPnfResourceCustomizations(delegateExecution, serviceModelUuid);
+ final PnfResourceCustomization pnfResourceCustomization = pnfCustomizations.get(0);
+ final String payload = bpmnRequestDetails.getRequestParameters().getPayload();
+
+ populateExecution(delegateExecution, bpmnRequestDetails, pnfResourceCustomization, pnf, serviceInstanceName,
+ pnfName, serviceModelUuid, userParams, payload);
+
+ logger.trace("Completed preProcessRequest PnfSoftwareUpgradeServiceRequest Request ");
+ }
+
+ private RequestDetails requestVerification(DelegateExecution delegateExecution) throws IOException {
+ RequestDetails bpmnRequestDetails = mapper.readValue(
+ JsonUtils.getJsonValue(String.valueOf(delegateExecution.getVariable(BPMN_REQUEST)), "requestDetails"),
+ RequestDetails.class);
+
+ throwIfNull(delegateExecution, bpmnRequestDetails.getModelInfo(), SERVICE_MODEL_INFO);
+ throwIfNull(delegateExecution, bpmnRequestDetails.getRequestInfo(), "RequestInfo");
+ throwIfNull(delegateExecution, bpmnRequestDetails.getRequestParameters(), "RequestParameters");
+ throwIfNull(delegateExecution, bpmnRequestDetails.getRequestParameters().getUserParams(), "UserParams");
+
+ return bpmnRequestDetails;
+ }
+
+ private void populateExecution(DelegateExecution delegateExecution, RequestDetails bpmnRequestDetails,
+ PnfResourceCustomization pnfResourceCustomization, Pnf pnf, String serviceInstanceName, String pnfName,
+ String serviceModelUuid, List<Map<String, Object>> userParams, String payload) {
+
+ delegateExecution.setVariable(SERVICE_MODEL_INFO, bpmnRequestDetails.getModelInfo());
+ delegateExecution.setVariable(SERVICE_INSTANCE_NAME, serviceInstanceName);
+ delegateExecution.setVariable(PNF_CORRELATION_ID, pnfName);
+ delegateExecution.setVariable(MODEL_UUID, serviceModelUuid);
+ delegateExecution.setVariable(PNF_UUID, pnf.getPnfId());
+ delegateExecution.setVariable(PRC_BLUEPRINT_NAME, pnfResourceCustomization.getBlueprintName());
+ delegateExecution.setVariable(PRC_BLUEPRINT_VERSION, pnfResourceCustomization.getBlueprintVersion());
+ delegateExecution.setVariable(PRC_CUSTOMIZATION_UUID, pnfResourceCustomization.getModelCustomizationUUID());
+ delegateExecution.setVariable(RESOURCE_CUSTOMIZATION_UUID_PARAM,
+ pnfResourceCustomization.getModelCustomizationUUID());
+ delegateExecution.setVariable(PRC_INSTANCE_NAME, pnfResourceCustomization.getModelInstanceName());
+ delegateExecution.setVariable(PRC_CONTROLLER_ACTOR, pnfResourceCustomization.getControllerActor());
+
+ for (Map<String, Object> param : userParams) {
+ if (param.containsKey("name") && param.containsKey("value")) {
+ delegateExecution.setVariable(param.get("name").toString(), param.get("value").toString());
+ }
+ }
+
+ delegateExecution.setVariable(REQUEST_PAYLOAD, payload);
+ }
+
+ private Pnf getPnfByPnfName(DelegateExecution delegateExecution, String pnfName) {
+ Optional<Pnf> pnfOptional = null;
+ try {
+ pnfOptional = pnfManagement.getEntryFor(pnfName);
+ } catch (IOException e) {
+ logger.warn(e.getMessage(), e);
+ exceptionUtil.buildAndThrowWorkflowException(delegateExecution, ERROR_CODE,
+ "Unable to fetch from AAI" + e.getMessage());
+ }
+ if (pnfOptional == null || !pnfOptional.isPresent()) {
+ exceptionUtil.buildAndThrowWorkflowException(delegateExecution, ERROR_CODE,
+ "AAI entry for PNF: " + pnfName + " does not exist");
+ }
+ return pnfOptional.get();
+ }
+
+ private List<PnfResourceCustomization> getPnfResourceCustomizations(DelegateExecution delegateExecution,
+ String serviceModelUuid) {
+ List<PnfResourceCustomization> pnfCustomizations =
+ catalogDbClient.getPnfResourceCustomizationByModelUuid(serviceModelUuid);
+
+ if (pnfCustomizations == null || pnfCustomizations.isEmpty()) {
+ logger.warn("Unable to find the PNF resource customizations of model service UUID: {}", serviceModelUuid);
+ exceptionUtil.buildAndThrowWorkflowException(delegateExecution, ERROR_CODE,
+ "Unable to find the PNF resource customizations of model service UUID: " + serviceModelUuid);
+ }
+ return pnfCustomizations;
+ }
+
+ private void throwIfNull(DelegateExecution delegateExecution, Object obj, String param) {
+ if (obj == null) {
+ logger.warn("Unable to find the parameter: {} in the execution context", param);
+ exceptionUtil.buildAndThrowWorkflowException(delegateExecution, ERROR_CODE,
+ "Unable to find parameter " + param);
+ }
+ }
+}
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/UpdatePnfEntryInAai.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/UpdatePnfEntryInAai.java
new file mode 100644
index 0000000000..f85be8aab7
--- /dev/null
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/UpdatePnfEntryInAai.java
@@ -0,0 +1,65 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 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.so.bpmn.infrastructure.pnf.delegate;
+
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.camunda.bpm.engine.delegate.JavaDelegate;
+import org.onap.aai.domain.yang.Pnf;
+import org.onap.so.bpmn.infrastructure.pnf.management.PnfManagement;
+import org.onap.so.client.exception.ExceptionBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import java.util.Optional;
+import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_CORRELATION_ID;
+import static org.onap.so.client.cds.PayloadConstants.PRC_TARGET_SOFTWARE_VERSION;
+
+
+@Component
+public class UpdatePnfEntryInAai implements JavaDelegate {
+
+ private final Logger logger = LoggerFactory.getLogger(UpdatePnfEntryInAai.class);
+
+ @Autowired
+ private PnfManagement pnfManagement;
+
+ @Autowired
+ private ExceptionBuilder exceptionUtil;
+
+ @Override
+ public void execute(DelegateExecution execution) throws Exception {
+ String pnfCorrelationId = String.valueOf(execution.getVariable(PNF_CORRELATION_ID));
+ Optional<Pnf> pnfAaiEntry = pnfManagement.getEntryFor(pnfCorrelationId);
+
+ if (!pnfAaiEntry.isPresent()) {
+ exceptionUtil.buildAndThrowWorkflowException(execution, 404,
+ "AAI entry for PNF: " + PNF_CORRELATION_ID + " does not exist");
+ }
+
+ Pnf pnf = pnfAaiEntry.get();
+ String pnfSoftwareVersion = String.valueOf(execution.getVariable(PRC_TARGET_SOFTWARE_VERSION));
+ pnf.setSwVersion(pnfSoftwareVersion);
+
+ pnfManagement.updateEntry(pnfCorrelationId, pnf);
+ logger.debug("AAI entry is updated for pnf correlation id: {}, pnf uuid: {} with swVersion: {}",
+ pnf.getPnfName(), pnfCorrelationId, pnfSoftwareVersion);
+ }
+}
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/management/PnfManagement.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/management/PnfManagement.java
index 9e720fe0a4..46937d0d8c 100644
--- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/management/PnfManagement.java
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/management/PnfManagement.java
@@ -30,5 +30,7 @@ public interface PnfManagement {
void createEntry(String pnfCorrelationId, Pnf entry) throws IOException;
+ void updateEntry(String pnfCorrelationId, Pnf entry) throws IOException;
+
void createRelation(String serviceInstanceId, String pnfName) throws IOException;
}
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/management/PnfManagementImpl.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/management/PnfManagementImpl.java
index b1af8b1e0b..e6df8070a3 100644
--- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/management/PnfManagementImpl.java
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/management/PnfManagementImpl.java
@@ -44,6 +44,11 @@ public class PnfManagementImpl implements PnfManagement {
restClient.createPnf(pnfCorrelationId, entry);
}
+ public void updateEntry(String pnfCorrelationId, Pnf entry) {
+ AAIRestClientImpl restClient = new AAIRestClientImpl();
+ restClient.updatePnf(pnfCorrelationId, entry);
+ }
+
@Override
public void createRelation(String serviceInstanceId, String pnfName) {
AAIResourceUri serviceInstanceURI =
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/service/ServicePluginFactory.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/service/ServicePluginFactory.java
index 7f2cd5c071..c63edc93c7 100644
--- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/service/ServicePluginFactory.java
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/service/ServicePluginFactory.java
@@ -22,12 +22,8 @@
package org.onap.so.bpmn.infrastructure.workflow.service;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializationFeature;
import java.io.IOException;
import java.io.InputStream;
-import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -40,14 +36,12 @@ import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpResponse;
import org.apache.http.ParseException;
-import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpRequestBase;
-import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
@@ -69,13 +63,17 @@ import org.onap.so.client.aai.AAIObjectType;
import org.onap.so.client.aai.AAIResourcesClient;
import org.onap.so.client.aai.entities.AAIResultWrapper;
import org.onap.so.client.aai.entities.Relationships;
+import org.onap.so.client.aai.entities.uri.AAIPluralResourceUri;
import org.onap.so.client.aai.entities.uri.AAIResourceUri;
import org.onap.so.client.aai.entities.uri.AAIUriFactory;
-import org.onap.so.logger.ErrorCode;
+import org.onap.logging.filter.base.ErrorCode;
import org.onap.so.logger.MessageEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.util.UriUtils;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
public class ServicePluginFactory {
@@ -451,7 +449,7 @@ public class ServicePluginFactory {
public Map getTPsfromAAI(String serviceName) {
Map<String, Object> tpInfo = new HashMap<>();
- AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.LOGICAL_LINK);
+ AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.LOGICAL_LINK);
AAIResourcesClient client = new AAIResourcesClient();
Optional<LogicalLinks> result = client.get(LogicalLinks.class, uri);
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/serviceTask/AbstractSdncOperationTask.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/serviceTask/AbstractSdncOperationTask.java
index f933277f3c..de8a35de06 100644
--- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/serviceTask/AbstractSdncOperationTask.java
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/serviceTask/AbstractSdncOperationTask.java
@@ -45,7 +45,7 @@ import org.onap.msb.sdk.httpclient.msb.MSBServiceClient;
import org.onap.so.bpmn.core.UrnPropertiesReader;
import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.GenericResourceApi;
import org.onap.so.db.request.beans.ResourceOperationStatus;
-import org.onap.so.logger.ErrorCode;
+import org.onap.logging.filter.base.ErrorCode;
import org.onap.so.logger.MessageEnum;
import org.onap.so.requestsdb.RequestsDbConstant;
import org.slf4j.Logger;