summaryrefslogtreecommitdiffstats
path: root/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java')
-rw-r--r--so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/etsicatalog/EtsiCatalogPackageManagementServiceProvider.java3
-rw-r--r--so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/etsicatalog/EtsiCatalogPackageManagementServiceProviderImpl.java26
-rw-r--r--so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/service/JobExecutorService.java72
-rw-r--r--so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/CreateInstantiateRequest.java167
-rw-r--r--so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/CreateInstantiateVnfTask.java234
-rw-r--r--so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/InstantiateNsTask.java416
6 files changed, 916 insertions, 2 deletions
diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/etsicatalog/EtsiCatalogPackageManagementServiceProvider.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/etsicatalog/EtsiCatalogPackageManagementServiceProvider.java
index a373df43e7..65d982c6cc 100644
--- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/etsicatalog/EtsiCatalogPackageManagementServiceProvider.java
+++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/etsicatalog/EtsiCatalogPackageManagementServiceProvider.java
@@ -22,6 +22,7 @@ package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.etsicatalog;
import java.util.Optional;
import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.NsdInfo;
import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.VnfPkgInfo;
+import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.NetworkServiceDescriptor;
/**
* @author Waqas Ikram (waqas.ikram@est.tech)
@@ -33,4 +34,6 @@ public interface EtsiCatalogPackageManagementServiceProvider {
Optional<VnfPkgInfo> getVnfPkgInfo(final String vnfPkgId);
+ Optional<NetworkServiceDescriptor> getNetworkServiceDescriptor(final String nsdId);
+
}
diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/etsicatalog/EtsiCatalogPackageManagementServiceProviderImpl.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/etsicatalog/EtsiCatalogPackageManagementServiceProviderImpl.java
index 32f7cc1182..75dd7107a7 100644
--- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/etsicatalog/EtsiCatalogPackageManagementServiceProviderImpl.java
+++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/etsicatalog/EtsiCatalogPackageManagementServiceProviderImpl.java
@@ -24,6 +24,8 @@ import java.util.Optional;
import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.NsdInfo;
import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.VnfPkgInfo;
import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.exceptions.EtsiCatalogManagerRequestFailureException;
+import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.NetworkServiceDescriptor;
+import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.NetworkServiceDescriptorParser;
import org.onap.so.rest.service.HttpRestServiceProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -43,12 +45,15 @@ public class EtsiCatalogPackageManagementServiceProviderImpl implements EtsiCata
private final HttpRestServiceProvider httpServiceProvider;
private final EtsiCatalogUrlProvider etsiCatalogUrlProvider;
+ private final NetworkServiceDescriptorParser networkServiceDescriptorParser;
@Autowired
public EtsiCatalogPackageManagementServiceProviderImpl(final EtsiCatalogUrlProvider etsiCatalogUrlProvider,
- @Qualifier(ETSI_CATALOG_SERVICE_PROVIDER_BEAN) final HttpRestServiceProvider httpServiceProvider) {
+ @Qualifier(ETSI_CATALOG_SERVICE_PROVIDER_BEAN) final HttpRestServiceProvider httpServiceProvider,
+ final NetworkServiceDescriptorParser networkServiceDescriptorParser) {
this.etsiCatalogUrlProvider = etsiCatalogUrlProvider;
this.httpServiceProvider = httpServiceProvider;
+ this.networkServiceDescriptorParser = networkServiceDescriptorParser;
}
@Override
@@ -83,4 +88,23 @@ public class EtsiCatalogPackageManagementServiceProviderImpl implements EtsiCata
}
}
+ @Override
+ public Optional<NetworkServiceDescriptor> getNetworkServiceDescriptor(final String nsdId) {
+ try {
+ final ResponseEntity<byte[]> response = httpServiceProvider
+ .getHttpResponse(etsiCatalogUrlProvider.getNsPackageContentUrl(nsdId), byte[].class);
+ if (response.getStatusCode().is2xxSuccessful()) {
+ if (response.hasBody()) {
+ return networkServiceDescriptorParser.parse(response.getBody());
+ }
+ logger.error("Received response without body ...");
+ }
+ return Optional.empty();
+ } catch (final Exception restProcessingException) {
+ logger.error("Caught exception while getting NS package content for: {}", nsdId, restProcessingException);
+ throw new EtsiCatalogManagerRequestFailureException("Internal Server Error Occurred.",
+ restProcessingException);
+ }
+ }
+
}
diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/service/JobExecutorService.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/service/JobExecutorService.java
index 692aff62cd..f3c38e537f 100644
--- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/service/JobExecutorService.java
+++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/service/JobExecutorService.java
@@ -21,12 +21,19 @@ package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.service;
import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.CREATE_NS_REQUEST_PARAM_NAME;
import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.GLOBAL_CUSTOMER_ID_PARAM_NAME;
+import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.INSTANTIATE_NS_REQUEST_PARAM_NAME;
import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.JOB_ID_PARAM_NAME;
+import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.NS_INSTANCE_ID_PARAM_NAME;
+import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.OCC_ID_PARAM_NAME;
import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.SERVICE_TYPE_PARAM_NAME;
import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.Constants.CREATE_NS_WORKFLOW_NAME;
+import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.Constants.INSTANTIATE_NS_WORKFLOW_NAME;
+import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobAction.INSTANTIATE;
import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum.ERROR;
import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum.FINISHED;
import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum.FINISHED_WITH_ERROR;
+import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum.IN_PROGRESS;
+import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum.STARTING;
import static org.slf4j.LoggerFactory.getLogger;
import java.time.Instant;
import java.time.LocalDateTime;
@@ -35,19 +42,25 @@ import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.GsonProvider;
import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.exceptions.NsRequestProcessingException;
import org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobAction;
import org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum;
import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJob;
+import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NsLcmOpOcc;
+import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NsLcmOpType;
+import org.onap.so.etsi.nfvo.ns.lcm.database.beans.OperationStateEnum;
import org.onap.so.etsi.nfvo.ns.lcm.database.service.DatabaseServiceProvider;
import org.onap.so.etsi.nfvo.ns.lcm.model.CreateNsRequest;
import org.onap.so.etsi.nfvo.ns.lcm.model.InlineResponse400;
+import org.onap.so.etsi.nfvo.ns.lcm.model.InstantiateNsRequest;
import org.onap.so.etsi.nfvo.ns.lcm.model.NsInstancesNsInstance;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.google.common.collect.ImmutableSet;
+import com.google.gson.Gson;
/**
* @author Waqas Ikram (waqas.ikram@est.tech)
@@ -69,13 +82,16 @@ public class JobExecutorService {
private final DatabaseServiceProvider databaseServiceProvider;
private final WorkflowExecutorService workflowExecutorService;
private final WorkflowQueryService workflowQueryService;
+ private Gson gson;
@Autowired
public JobExecutorService(final DatabaseServiceProvider databaseServiceProvider,
- final WorkflowExecutorService workflowExecutorService, final WorkflowQueryService workflowQueryService) {
+ final WorkflowExecutorService workflowExecutorService, final WorkflowQueryService workflowQueryService,
+ final GsonProvider gsonProvider) {
this.databaseServiceProvider = databaseServiceProvider;
this.workflowExecutorService = workflowExecutorService;
this.workflowQueryService = workflowQueryService;
+ gson = gsonProvider.getGson();
}
public NsInstancesNsInstance runCreateNsJob(final CreateNsRequest createNsRequest, final String globalCustomerId,
@@ -130,6 +146,50 @@ public class JobExecutorService {
return optional.get();
}
+ public String runInstantiateNsJob(final String nsInstanceId, final InstantiateNsRequest instantiateNsRequest) {
+
+ final NfvoJob newJob = new NfvoJob().startTime(LocalDateTime.now()).jobType("NS").jobAction(INSTANTIATE)
+ .resourceId(nsInstanceId).status(STARTING).progress(0);
+ databaseServiceProvider.addJob(newJob);
+ logger.info("New job created in database :\n{}", newJob);
+
+ final LocalDateTime currentDateTime = LocalDateTime.now();
+ final NsLcmOpOcc newNsLcmOpOcc = new NsLcmOpOcc().id(nsInstanceId).operation(NsLcmOpType.INSTANTIATE)
+ .operationState(OperationStateEnum.PROCESSING).stateEnteredTime(currentDateTime)
+ .startTime(currentDateTime).isAutoInnovation(false).isCancelPending(false)
+ .operationParams(gson.toJson(instantiateNsRequest));
+ databaseServiceProvider.addNSLcmOpOcc(newNsLcmOpOcc);
+ logger.info("New NSLcmOpOcc created in database :\n{}", newNsLcmOpOcc);
+
+ workflowExecutorService.executeWorkflow(newJob.getJobId(), INSTANTIATE_NS_WORKFLOW_NAME,
+ getVariables(nsInstanceId, newJob.getJobId(), newNsLcmOpOcc.getId(), instantiateNsRequest));
+
+ final ImmutableSet<JobStatusEnum> jobFinishedStates =
+ ImmutableSet.of(FINISHED, ERROR, FINISHED_WITH_ERROR, IN_PROGRESS);
+ final ImmutablePair<String, JobStatusEnum> immutablePair =
+ waitForJobToFinish(newJob.getJobId(), jobFinishedStates);
+
+ if (immutablePair.getRight() == null) {
+ final String message = "Failed to Instantiate NS for request: \n" + instantiateNsRequest;
+ logger.error(message);
+ throw new NsRequestProcessingException(message);
+ }
+
+ final JobStatusEnum finalJobStatus = immutablePair.getRight();
+
+ if (IN_PROGRESS.equals(finalJobStatus) || FINISHED.equals(finalJobStatus)) {
+ logger.info("Instantiation Job status: {}", finalJobStatus);
+
+
+ return newNsLcmOpOcc.getId();
+ }
+
+ final String message = "Received unexpected Job Status: " + finalJobStatus
+ + " Failed to instantiate NS for request: \n" + instantiateNsRequest;
+ logger.error(message);
+ throw new NsRequestProcessingException(message);
+ }
+
private ImmutablePair<String, JobStatusEnum> waitForJobToFinish(final String jobId,
final ImmutableSet<JobStatusEnum> jobFinishedStates) {
try {
@@ -179,4 +239,14 @@ public class JobExecutorService {
return variables;
}
+ private Map<String, Object> getVariables(final String nsInstanceId, final String jobId, final String occId,
+ final InstantiateNsRequest instantiateNsRequest) {
+ final Map<String, Object> variables = new HashMap<>();
+ variables.put(NS_INSTANCE_ID_PARAM_NAME, nsInstanceId);
+ variables.put(JOB_ID_PARAM_NAME, jobId);
+ variables.put(OCC_ID_PARAM_NAME, occId);
+ variables.put(INSTANTIATE_NS_REQUEST_PARAM_NAME, instantiateNsRequest);
+ return variables;
+ }
+
}
diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/CreateInstantiateRequest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/CreateInstantiateRequest.java
new file mode 100644
index 0000000000..569d9b3352
--- /dev/null
+++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/CreateInstantiateRequest.java
@@ -0,0 +1,167 @@
+/*-
+ * ============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.etsi.nfvo.ns.lcm.bpmn.flows.tasks;
+
+import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.utils.Utils.toIndentedString;
+import java.io.Serializable;
+import java.util.Map;
+import java.util.Objects;
+import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.Tenant;
+
+/**
+ * @author Waqas Ikram (waqas.ikram@est.tech)
+ *
+ */
+public class CreateInstantiateRequest implements Serializable {
+ private static final long serialVersionUID = -4371264952509580468L;
+ private String nsInstId;
+ private String vnfdId;
+ private String vnfName;
+ private String vnfPkgId;
+ private String nfType;
+ private Tenant tenant;
+ private Map<String, String> additionalParams;
+
+ public String getNsInstId() {
+ return nsInstId;
+ }
+
+ public void setNsInstId(final String nsInstId) {
+ this.nsInstId = nsInstId;
+ }
+
+ public CreateInstantiateRequest nsInstId(final String nsInstId) {
+ this.nsInstId = nsInstId;
+ return this;
+ }
+
+ public final String getVnfdId() {
+ return vnfdId;
+ }
+
+ public final void setVnfdId(final String vnfdId) {
+ this.vnfdId = vnfdId;
+ }
+
+ public CreateInstantiateRequest vnfdId(final String vnfdId) {
+ this.vnfdId = vnfdId;
+ return this;
+ }
+
+ public final String getVnfName() {
+ return vnfName;
+ }
+
+ public final void setVnfName(final String vnfName) {
+ this.vnfName = vnfName;
+ }
+
+ public CreateInstantiateRequest vnfName(final String vnfName) {
+ this.vnfName = vnfName;
+ return this;
+ }
+
+ public final String getVnfPkgId() {
+ return vnfPkgId;
+ }
+
+ public final void setVnfPkgId(final String vnfPkgId) {
+ this.vnfPkgId = vnfPkgId;
+ }
+
+ public CreateInstantiateRequest vnfPkgId(final String vnfPkgId) {
+ this.vnfPkgId = vnfPkgId;
+ return this;
+ }
+
+ public final String getNfType() {
+ return nfType;
+ }
+
+ public final void setNfType(final String nfType) {
+ this.nfType = nfType;
+ }
+
+ public CreateInstantiateRequest nfType(final String nfType) {
+ this.nfType = nfType;
+ return this;
+ }
+
+ public final Tenant getTenant() {
+ return tenant;
+ }
+
+ public final void setTenant(final Tenant tenant) {
+ this.tenant = tenant;
+ }
+
+ public CreateInstantiateRequest tenant(final Tenant tenant) {
+ this.tenant = tenant;
+ return this;
+ }
+
+ public final Map<String, String> getAdditionalParams() {
+ return additionalParams;
+ }
+
+ public final void setAdditionalParams(final Map<String, String> additionalParams) {
+ this.additionalParams = additionalParams;
+ }
+
+ public CreateInstantiateRequest additionalParams(final Map<String, String> additionalParams) {
+ this.additionalParams = additionalParams;
+ return this;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(nsInstId, vnfdId, vnfName, vnfPkgId, nfType, tenant, additionalParams);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (obj instanceof CreateInstantiateRequest) {
+ final CreateInstantiateRequest other = (CreateInstantiateRequest) obj;
+ return Objects.equals(nsInstId, other.nsInstId) && Objects.equals(vnfdId, other.vnfdId)
+ && Objects.equals(vnfName, other.vnfName) && Objects.equals(vnfPkgId, other.vnfPkgId)
+ && Objects.equals(nfType, other.nfType) && Objects.equals(tenant, other.tenant)
+ && Objects.equals(additionalParams, other.additionalParams);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder();
+ sb.append("class CreateInstantiateRequest {\n");
+ sb.append(" nsInstId: ").append(toIndentedString(nsInstId)).append("\n");
+ sb.append(" vnfdId: ").append(toIndentedString(vnfdId)).append("\n");
+ sb.append(" vnfName: ").append(toIndentedString(vnfName)).append("\n");
+ sb.append(" vnfPkgId: ").append(toIndentedString(vnfPkgId)).append("\n");
+ sb.append(" nfType: ").append(toIndentedString(nfType)).append("\n");
+ sb.append(" tenant: ").append(toIndentedString(tenant)).append("\n");
+ sb.append(" additionalParams: ").append(toIndentedString(additionalParams)).append("\n");
+
+ sb.append("}");
+ return sb.toString();
+ }
+
+
+}
diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/CreateInstantiateVnfTask.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/CreateInstantiateVnfTask.java
new file mode 100644
index 0000000000..c33c67e540
--- /dev/null
+++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/CreateInstantiateVnfTask.java
@@ -0,0 +1,234 @@
+/*-
+ * ============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.etsi.nfvo.ns.lcm.bpmn.flows.tasks;
+
+import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.NS_INSTANCE_ID_PARAM_NAME;
+import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum.ERROR;
+import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum.FINISHED;
+import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum.IN_PROGRESS;
+import java.time.LocalDateTime;
+import java.util.Optional;
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.onap.aai.domain.yang.GenericVnf;
+import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.CreateVnfRequest;
+import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.CreateVnfResponse;
+import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.Tenant;
+import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.aai.AaiServiceProvider;
+import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.vnfm.Sol003AdapterServiceProvider;
+import org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum;
+import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNfInst;
+import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNsInst;
+import org.onap.so.etsi.nfvo.ns.lcm.database.beans.State;
+import org.onap.so.etsi.nfvo.ns.lcm.database.service.DatabaseServiceProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author Waqas Ikram (waqas.ikram@est.tech)
+ */
+@Component
+public class CreateInstantiateVnfTask extends AbstractNetworkServiceTask {
+ private static final Logger logger = LoggerFactory.getLogger(CreateInstantiateVnfTask.class);
+ private static final String NF_INST_ID_PARAM_NAME = "NF_INST_ID";
+ public static final String CREATE_VNF_RESPONSE_PARAM_NAME = "createVnfResponse";
+ private final AaiServiceProvider aaiServiceProvider;
+ private final Sol003AdapterServiceProvider sol003AdapterServiceProvider;
+
+ @Autowired
+ public CreateInstantiateVnfTask(final DatabaseServiceProvider databaseServiceProvider,
+ final AaiServiceProvider aaiServiceProvider,
+ final Sol003AdapterServiceProvider sol003AdapterServiceProvider) {
+ super(databaseServiceProvider);
+ this.aaiServiceProvider = aaiServiceProvider;
+ this.sol003AdapterServiceProvider = sol003AdapterServiceProvider;
+ }
+
+ public void checkIfNfInstanceExistsInDb(final DelegateExecution execution) {
+ logger.info("Executing checkIfNfInstanceInDb");
+ final CreateInstantiateRequest request = (CreateInstantiateRequest) execution.getVariable("request");
+ logger.info("request: {}", request);
+
+ setJobStatus(execution, JobStatusEnum.IN_PROGRESS, "Checking if NF Instance record exists in database for "
+ + request.getNsInstId() + " and " + request.getVnfName());
+ if (!databaseServiceProvider.isNsInstExists(request.getNsInstId(), request.getVnfName())) {
+ abortOperation(execution,
+ request.getNsInstId() + " " + request.getVnfName() + " VNF instance already exists");
+ }
+ logger.info("Finished executing checkIfNfInstanceInDb ...");
+
+ }
+
+ public void createNfInstanceInDb(final DelegateExecution execution) {
+ logger.info("Executing createNfInstanceInDb");
+ final CreateInstantiateRequest request = (CreateInstantiateRequest) execution.getVariable("request");
+ logger.info("request: {}", request);
+
+ setJobStatus(execution, IN_PROGRESS, "Creating NF Instance record in database for " + request.getVnfName());
+
+ final Optional<NfvoNsInst> optional = databaseServiceProvider.getNfvoNsInst(request.getNsInstId());
+
+ if (optional.isEmpty()) {
+ abortOperation(execution, "NfvoNsInst: " + request.getNsInstId() + "not founda");
+ }
+
+ final NfvoNsInst nfvoNsInst = optional.get();
+ final LocalDateTime now = LocalDateTime.now();
+ final NfvoNfInst nfvoNfInst = new NfvoNfInst().status(State.NOT_INSTANTIATED).createTime(now)
+ .lastUpdateTime(now).name(request.getVnfName()).vnfdId(request.getVnfdId())
+ .packageId(request.getVnfPkgId()).nfvoNsInst(nfvoNsInst);
+ databaseServiceProvider.saveNfvoNfInst(nfvoNfInst);
+ execution.setVariable(NF_INST_ID_PARAM_NAME, nfvoNfInst.getNfInstId());
+ logger.info("Finished executing createNfInstanceInDb ...");
+
+ }
+
+ public void createGenericVnfInAai(final DelegateExecution execution) {
+ logger.info("Executing createGenericVnfInAai");
+ try {
+ final CreateInstantiateRequest request = (CreateInstantiateRequest) execution.getVariable("request");
+
+ setJobStatus(execution, IN_PROGRESS, "Creating GenericVnf record in AAI for " + request.getVnfName());
+
+ final String nfInstId = (String) execution.getVariable(NF_INST_ID_PARAM_NAME);
+ final String nsInstId = (String) execution.getVariable(NS_INSTANCE_ID_PARAM_NAME);
+ final NfvoNsInst nfvoNsInst = getNfvoNsInst(execution, nsInstId);
+
+ final GenericVnf genericVnf = new GenericVnf();
+ genericVnf.setVnfId(nfInstId);
+ genericVnf.setVnfName(request.getVnfName());
+ genericVnf.setVnfType(nfvoNsInst.getName() + "/" + request.getVnfName());
+ genericVnf.setServiceId(request.getNsInstId());
+ genericVnf.setNfType(request.getNfType());
+ genericVnf.setOperationalStatus("Created");
+ genericVnf.setIsClosedLoopDisabled(false);
+
+ aaiServiceProvider.createGenericVnfAndConnectServiceInstance(nsInstId, nfInstId, genericVnf);
+
+ final Tenant tenant = request.getTenant();
+ aaiServiceProvider.connectGenericVnfToTenant(nfInstId, tenant.getCloudOwner(), tenant.getRegionName(),
+ tenant.getTenantId());
+
+ } catch (final Exception exception) {
+ final String message = "Unable to Create GenericVnf in AAI";
+ logger.error(message, exception);
+ abortOperation(execution, message);
+ }
+
+ logger.info("Finished executing createGenericVnfInAai ...");
+ }
+
+ public void invokeCreateInstantiationRequest(final DelegateExecution execution) {
+ logger.info("Executing invokeCreateInstantiationRequest");
+
+ try {
+ final CreateInstantiateRequest request = (CreateInstantiateRequest) execution.getVariable("request");
+ logger.info("request: {}", request);
+
+ setJobStatus(execution, IN_PROGRESS,
+ "Invoking SOL003 adapter for creating and instantiating VNF: " + request.getVnfName());
+
+ final String nsInstId = (String) execution.getVariable(NS_INSTANCE_ID_PARAM_NAME);
+ final NfvoNsInst nfvoNsInst = getNfvoNsInst(execution, nsInstId);
+ final CreateVnfRequest vnfRequest = new CreateVnfRequest();
+ vnfRequest.setTenant(request.getTenant());
+ vnfRequest.setName(nfvoNsInst.getName() + "." + request.getVnfName());
+ vnfRequest.setPkgId(request.getVnfPkgId());
+ vnfRequest.setAdditionalParams(request.getAdditionalParams());
+ final String vnfId = (String) execution.getVariable(NF_INST_ID_PARAM_NAME);
+ final Optional<CreateVnfResponse> optional =
+ sol003AdapterServiceProvider.invokeCreateInstantiationRequest(vnfId, vnfRequest);
+
+ if (!optional.isPresent()) {
+ final String errorMessage = "Unexpected error while processing create and instantiation request";
+ logger.error(errorMessage);
+ abortOperation(execution, errorMessage);
+ }
+
+ final CreateVnfResponse vnfResponse = optional.get();
+
+ logger.info("Vnf instantiation response: {}", vnfResponse);
+ execution.setVariable(CREATE_VNF_RESPONSE_PARAM_NAME, vnfResponse);
+ setJobStatus(execution, IN_PROGRESS, "Successfully invoked SOL003 adapater creating and instantiating VNF: "
+ + request.getVnfName() + " CreaetVnfResponse Job Id: " + vnfResponse.getJobId());
+ logger.debug("Finished executing invokeCreateInstantiationRequest ...");
+ } catch (final Exception exception) {
+ final String message = "Unable to invoke create and instantiation request";
+ logger.error(message, exception);
+ abortOperation(execution, message);
+ }
+
+ }
+
+ public void updateNfInstanceStatusToInstantiated(final DelegateExecution execution) {
+ logger.info("Executing updateNfInstanceStatusToInstantiated");
+
+ updateNfInstanceStatus(execution, State.INSTANTIATED);
+ final CreateInstantiateRequest request = (CreateInstantiateRequest) execution.getVariable("request");
+ setJobStatus(execution, FINISHED, "Successfully created and Instantiated VNF: " + request.getVnfName()
+ + " will set status to " + State.INSTANTIATED);
+
+ logger.info("Finished executing updateNfInstanceStatusToInstantiated ...");
+
+ }
+
+ public void updateNfInstanceStatusToFailed(final DelegateExecution execution) {
+ logger.info("Executing updateNfInstanceStatusToActive");
+
+ updateNfInstanceStatus(execution, State.FAILED);
+ final CreateInstantiateRequest request = (CreateInstantiateRequest) execution.getVariable("request");
+ setJobStatus(execution, ERROR, "Failed to create and instantiate VNF: " + request.getVnfName()
+ + " will set status to " + State.FAILED);
+
+ logger.info("Finished executing updateNfInstanceStatusToInstantiated ...");
+
+ }
+
+ private void updateNfInstanceStatus(final DelegateExecution execution, final State vnfStatus) {
+ final String nfInstId = (String) execution.getVariable(NF_INST_ID_PARAM_NAME);
+
+ final Optional<NfvoNfInst> optional = databaseServiceProvider.getNfvoNfInst(nfInstId);
+ if (!optional.isPresent()) {
+ final String message = "Unable to find NfvoNfInst record in database using nfInstId: " + nfInstId;
+ logger.error(message);
+
+ abortOperation(execution, message);
+
+ }
+
+ final NfvoNfInst nfvoNfInst = optional.get();
+ nfvoNfInst.setStatus(vnfStatus);
+ databaseServiceProvider.saveNfvoNfInst(nfvoNfInst);
+ }
+
+ private NfvoNsInst getNfvoNsInst(final DelegateExecution execution, final String nsInstId) {
+ logger.info("Getting NfvoNsInst to update with nsInstId: {}", nsInstId);
+ final Optional<NfvoNsInst> optionalNfvoNsInst = databaseServiceProvider.getNfvoNsInst(nsInstId);
+
+ if (!optionalNfvoNsInst.isPresent()) {
+ final String message = "Unable to find NS Instance in datababse using id: " + nsInstId;
+ abortOperation(execution, message);
+ }
+
+ return optionalNfvoNsInst.get();
+ }
+
+}
diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/InstantiateNsTask.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/InstantiateNsTask.java
new file mode 100644
index 0000000000..8d212045ad
--- /dev/null
+++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/InstantiateNsTask.java
@@ -0,0 +1,416 @@
+/*-
+ * ============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.etsi.nfvo.ns.lcm.bpmn.flows.tasks;
+
+import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.INSTANTIATE_NS_REQUEST_PARAM_NAME;
+import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.NETWORK_SERVICE_DESCRIPTOR_PARAM_NAME;
+import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.NS_INSTANCE_ID_PARAM_NAME;
+import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.OCC_ID_PARAM_NAME;
+import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.VNF_CREATE_INSTANTIATE_REQUESTS;
+import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum.FINISHED;
+import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum.IN_PROGRESS;
+import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum.STARTED;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import org.camunda.bpm.engine.delegate.DelegateExecution;
+import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.Tenant;
+import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.NsdInfo;
+import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.VnfPkgInfo;
+import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.exceptions.EtsiCatalogManagerRequestFailureException;
+import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.etsicatalog.EtsiCatalogPackageManagementServiceProvider;
+import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.NetworkServiceDescriptor;
+import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.VirtualNetworkFunction;
+import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNfInst;
+import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNsInst;
+import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NsLcmOpOcc;
+import org.onap.so.etsi.nfvo.ns.lcm.database.beans.OperationStateEnum;
+import org.onap.so.etsi.nfvo.ns.lcm.database.beans.State;
+import org.onap.so.etsi.nfvo.ns.lcm.database.service.DatabaseServiceProvider;
+import org.onap.so.etsi.nfvo.ns.lcm.model.InstantiateNsRequest;
+import org.onap.so.etsi.nfvo.ns.lcm.model.NsInstancesnsInstanceIdinstantiateAdditionalParamsForVnf;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author Andrew Lamb (andrew.a.lamb@est.tech)
+ *
+ */
+@Component
+public class InstantiateNsTask extends AbstractNetworkServiceTask {
+
+ private static final String IS_NS_INSTANTIATION_SUCCESSFUL_PARAM_NAME = "isNsInstantiationSuccessful";
+ private static final String VNFD_ID_TO_VNF_PKG_ID_MAPPING_PARAM_NAME = "vnfdIdToVnfPkgIdMapping";
+ private static final Logger logger = LoggerFactory.getLogger(InstantiateNsTask.class);
+ private final EtsiCatalogPackageManagementServiceProvider etsiCatalogPackageManagementServiceProvider;
+
+ @Autowired
+ public InstantiateNsTask(final DatabaseServiceProvider databaseServiceProvider,
+ final EtsiCatalogPackageManagementServiceProvider etsiCatalogPackageManagementServiceProvider) {
+ super(databaseServiceProvider);
+ this.etsiCatalogPackageManagementServiceProvider = etsiCatalogPackageManagementServiceProvider;
+
+ }
+
+ public void setJobStatusToStarted(final DelegateExecution execution) {
+ setJobStatus(execution, STARTED, "Instantiate NS workflow process started");
+ }
+
+ public void setJobStatusToFinished(final DelegateExecution execution) {
+ setJobStatus(execution, FINISHED, "Instantiate NS workflow process finished");
+ }
+
+ public void updateNsInstanceStatusToInstantiating(final DelegateExecution execution) {
+ logger.info("Executing updateNsInstanceStatusToInstantiating");
+ setJobStatus(execution, IN_PROGRESS, "Updating NfvoNsInst Status to " + State.INSTANTIATING);
+ updateNsInstanceStatus(execution, State.INSTANTIATING);
+
+ logger.info("Finished executing updateNsInstanceStatusToInstantiating ...");
+ }
+
+
+ public void checkIfVnfInstantiationWasSuccessful(final DelegateExecution execution) {
+ logger.info("Executing checkIfVnfInstantiationWasSuccessful");
+
+ @SuppressWarnings("unchecked")
+ final List<CreateInstantiateRequest> requests =
+ (List<CreateInstantiateRequest>) execution.getVariable(VNF_CREATE_INSTANTIATE_REQUESTS);
+
+ final String nsInstId = (String) execution.getVariable(NS_INSTANCE_ID_PARAM_NAME);
+ final List<NfvoNfInst> nfInstances = databaseServiceProvider.getNfvoNfInstByNsInstId(nsInstId);
+
+ if (nfInstances == null || nfInstances.isEmpty()) {
+ final String message = "Found empty nf instances";
+ abortOperation(execution, message);
+ }
+
+ if (requests.size() != nfInstances.size()) {
+ final String message = "Missing nf Instance. Request triggered: " + requests.size()
+ + " Nf Instace reqeust found in database " + nfInstances.size();
+ abortOperation(execution, message);
+ }
+
+ execution.setVariable(IS_NS_INSTANTIATION_SUCCESSFUL_PARAM_NAME, true);
+
+ nfInstances.stream().forEach(instance -> {
+ if (!State.INSTANTIATED.equals(instance.getStatus())) {
+ logger.error("VNF : {} {} instantiation failed", instance.getNfInstId(), instance.getName());
+ execution.setVariable(IS_NS_INSTANTIATION_SUCCESSFUL_PARAM_NAME, false);
+ }
+ });
+
+ logger.info("Finished executing checkIfVnfInstantiationWasSuccessful ...");
+ }
+
+ public void updateNsInstanceStatusToInstantiated(final DelegateExecution execution) {
+ logger.info("Executing updateNsInstanceStatusToInstantiated");
+ final String nsInstId = (String) execution.getVariable(NS_INSTANCE_ID_PARAM_NAME);
+ setJobStatus(execution, FINISHED, "Successfully " + State.INSTANTIATED + " NS: " + nsInstId);
+
+ updateNsInstanceStatus(execution, State.INSTANTIATED);
+ logger.info("Finished executing updateNsInstanceStatusToInstantiated ...");
+ }
+
+ public void getAndParseNsdFromEtsiCatalog(final DelegateExecution execution) {
+ logger.info("Executing getAndParseNsdFromEtsiCatalog");
+ setJobStatus(execution, IN_PROGRESS, "Retrieving and parsing NSD from ETSI Catalog Manager");
+ final NfvoNsInst nfvoNsInst = getNfvoNsInst(execution);
+ final String nsPackageId = nfvoNsInst.getNsPackageId();
+
+ try {
+ final Optional<NetworkServiceDescriptor> optional =
+ etsiCatalogPackageManagementServiceProvider.getNetworkServiceDescriptor(nsPackageId);
+
+ if (!optional.isPresent()) {
+ final String message = "Unable to parse NSD " + nsPackageId;
+ logger.error(message);
+ abortOperation(execution, message);
+ }
+
+ final NetworkServiceDescriptor networkServiceDescriptor = optional.get();
+ logger.info("Found {}", networkServiceDescriptor);
+ execution.setVariable(NETWORK_SERVICE_DESCRIPTOR_PARAM_NAME, networkServiceDescriptor);
+
+ } catch (final EtsiCatalogManagerRequestFailureException failureException) {
+ final String message =
+ "Unexpected exception occured while getting nsd content using nsPackageId: " + nsPackageId;
+ logger.error(message, failureException);
+
+ abortOperation(execution, message);
+ }
+
+ logger.info("Finished executing getAndParseNsdFromEtsiCatalog ...");
+
+ }
+
+ public void prepareCreateInstantiateRequests(final DelegateExecution execution) {
+ logger.info("Executing prepareCreateInstantiateRequests ...");
+ setJobStatus(execution, IN_PROGRESS, "Preparing VNF CreateInstantiate requests");
+ final NetworkServiceDescriptor networkServiceDescriptor =
+ (NetworkServiceDescriptor) execution.getVariable(NETWORK_SERVICE_DESCRIPTOR_PARAM_NAME);
+ final String nsInstId = (String) execution.getVariable(NS_INSTANCE_ID_PARAM_NAME);
+
+ final InstantiateNsRequest instantiateNsRequest =
+ (InstantiateNsRequest) execution.getVariable(INSTANTIATE_NS_REQUEST_PARAM_NAME);
+
+ final List<NsInstancesnsInstanceIdinstantiateAdditionalParamsForVnf> additionalParamsForVnfList =
+ instantiateNsRequest.getAdditionalParamsForVnf();
+
+ @SuppressWarnings("unchecked")
+ final Map<String, String> vnfdIdToVnfPkgIdMapping =
+ (Map<String, String>) execution.getVariable(VNFD_ID_TO_VNF_PKG_ID_MAPPING_PARAM_NAME);
+
+ final List<CreateInstantiateRequest> requests = new ArrayList<>();
+
+ for (final VirtualNetworkFunction vnf : networkServiceDescriptor.getVnfs()) {
+ final List<String> vnfmInfoList = vnf.getVnfmInfoList();
+
+ final String vnfdId = vnf.getVnfdId();
+ final String vnfPkgId = vnfdIdToVnfPkgIdMapping.get(vnfdId);
+ if (vnfdId == null || vnfmInfoList.isEmpty() || vnfPkgId == null) {
+ final String message = "Unable to find VnfdId/vnfmInfo/VnfPkgId for vnf: " + vnf;
+ abortOperation(execution, message);
+ }
+
+ final Optional<Tenant> optional = getTenant(vnfPkgId, additionalParamsForVnfList);
+ if (!optional.isPresent()) {
+ final String message = "Unable to find Tenant information for " + vnfdId + " in instantiateNsRequest : "
+ + instantiateNsRequest;
+ abortOperation(execution, message);
+ }
+
+ final Tenant tenant = optional.get();
+ final CreateInstantiateRequest createInstantiateRequest = new CreateInstantiateRequest().nsInstId(nsInstId)
+ .vnfdId(vnfdId).vnfName(vnf.getVnfName()).vnfPkgId(vnfPkgId).nfType(vnfmInfoList.get(0))
+ .tenant(tenant).additionalParams(getAdditionalParams(vnfPkgId, additionalParamsForVnfList));
+
+ logger.info("Adding request to list: {}", createInstantiateRequest);
+ requests.add(createInstantiateRequest);
+
+ }
+ execution.setVariable(VNF_CREATE_INSTANTIATE_REQUESTS, requests);
+
+ logger.info("Finished executing prepareCreateInstantiateRequests ...");
+ }
+
+ public void getVnfPkgIdForEachVnfdId(final DelegateExecution execution) {
+ logger.info("Executing getVnfPkgIdForEachVnfdId ...");
+
+ setJobStatus(execution, IN_PROGRESS, "Getting VnfPkgId for each VnfdId");
+
+ final String nsInstId = (String) execution.getVariable(NS_INSTANCE_ID_PARAM_NAME);
+ final NfvoNsInst nfvoNsInst = getNfvoNsInst(execution, nsInstId);
+
+ final String nsPackageId = nfvoNsInst.getNsPackageId();
+ final NsdInfo nsdInfo = getNsdInfo(execution, nsPackageId);
+
+ final Map<String, String> vnfdIdToVnfPkgIdMapping = new HashMap<>();
+ try {
+ for (final String vnfPkgId : nsdInfo.getVnfPkgIds()) {
+ final Optional<VnfPkgInfo> optional =
+ etsiCatalogPackageManagementServiceProvider.getVnfPkgInfo(vnfPkgId);
+
+ if (!optional.isPresent()) {
+ final String message = "Unable to find VNF package using NS vnfPkgId: " + vnfPkgId;
+ logger.error(message);
+ abortOperation(execution, message);
+ }
+ final VnfPkgInfo vnfPkgInfo = optional.get();
+ vnfdIdToVnfPkgIdMapping.put(vnfPkgInfo.getVnfdId(), vnfPkgId);
+
+ }
+ logger.info("vnfdIdToVnfPkgIdMapping: {}", vnfdIdToVnfPkgIdMapping);
+ execution.setVariable(VNFD_ID_TO_VNF_PKG_ID_MAPPING_PARAM_NAME, vnfdIdToVnfPkgIdMapping);
+
+ } catch (final EtsiCatalogManagerRequestFailureException failureException) {
+ final String message =
+ "Unexpected exception occured while getting VNF package using nsPackageId: " + nsPackageId;
+ logger.error(message, failureException);
+
+ abortOperation(execution, message);
+ }
+
+ logger.info("Finished executing getVnfPkgIdForEachVnfdId ...");
+
+ }
+
+ public void logTimeOut(final DelegateExecution execution) {
+ logger.error("Vnf instantiation timedOut ...");
+ final String nsInstId = (String) execution.getVariable(NS_INSTANCE_ID_PARAM_NAME);
+ final List<NfvoNfInst> nfInstances = databaseServiceProvider.getNfvoNfInstByNsInstId(nsInstId);
+ if (nfInstances != null) {
+ nfInstances.stream().forEach(instance -> {
+ logger.info("Current status {} of vnf: {}", instance.getStatus(), instance.getName());
+ });
+ }
+ }
+
+ public void setJobStatusToError(final DelegateExecution execution) {
+ updateNsInstanceStatus(execution, State.FAILED);
+ setJobStatusToError(execution, "Instantiate NS workflow process failed");
+ }
+
+
+ public void updateNsLcmOpOccStatusToCompleted(final DelegateExecution execution) {
+ logger.info("Executing updateNsLcmOpOccStatusToCompleted ...");
+ final String occId = (String) execution.getVariable(OCC_ID_PARAM_NAME);
+
+ final Optional<NsLcmOpOcc> optional = databaseServiceProvider.getNsLcmOpOcc(occId);
+
+ if (!optional.isPresent()) {
+ final String message = "Unable to find record for NSLcmOpOcc in database using id: " + occId;
+ logger.error(message);
+ abortOperation(execution, message);
+ }
+
+ final NsLcmOpOcc nsLcmOpOcc = optional.get();
+ final OperationStateEnum operationStateCompleted = OperationStateEnum.COMPLETED;
+ logger.info("Setting operation state to {} for id: {}", operationStateCompleted, occId);
+ nsLcmOpOcc.setOperationState(operationStateCompleted);
+ databaseServiceProvider.addNSLcmOpOcc(nsLcmOpOcc);
+
+ logger.info("Finished executing updateNsLcmOpOccStatusToCompleted ...");
+
+ }
+
+ public void updateNsLcmOpOccStatusToFailed(final DelegateExecution execution) {
+ logger.info("Executing updateNsLcmOpOccStatusToFailed ...");
+ final String occId = (String) execution.getVariable(OCC_ID_PARAM_NAME);
+
+ final Optional<NsLcmOpOcc> optional = databaseServiceProvider.getNsLcmOpOcc(occId);
+
+ if (optional.isPresent()) {
+ final NsLcmOpOcc nsLcmOpOcc = optional.get();
+ final OperationStateEnum operationStateFailed = OperationStateEnum.FAILED;
+ logger.info("Setting operation state to {} for id: {}", operationStateFailed, occId);
+ nsLcmOpOcc.setOperationState(operationStateFailed);
+
+ databaseServiceProvider.addNSLcmOpOcc(nsLcmOpOcc);
+ } else {
+ logger.error("Unable to find record for NSLcmOpOcc in database using id: {}", occId);
+ }
+
+ logger.info("Finished executing updateNsLcmOpOccStatusToFailed ...");
+
+ }
+
+ private NsdInfo getNsdInfo(final DelegateExecution execution, final String nsPackageId) {
+ try {
+ final Optional<NsdInfo> optional =
+ etsiCatalogPackageManagementServiceProvider.getNSPackageModel(nsPackageId);
+
+ if (optional.isPresent()) {
+ final NsdInfo packageModel = optional.get();
+ logger.info("NS Package exists {}", packageModel);
+ return packageModel;
+ }
+
+ } catch (final EtsiCatalogManagerRequestFailureException failureException) {
+ final String message =
+ "Unexpected exception occured while getting ns package using nsPackageId: " + nsPackageId;
+ logger.error(message, failureException);
+
+ abortOperation(execution, message);
+ }
+
+ final String message = "Unable to find NS package using NS package id: " + nsPackageId;
+ logger.error(message);
+ abortOperation(execution, message);
+ return null;
+
+ }
+
+ private void updateNsInstanceStatus(final DelegateExecution execution, final State nsStatus) {
+ final NfvoNsInst nfvoNsInst = getNfvoNsInst(execution);
+ logger.info("Updating NfvoNsInst Status to {} and saving to DB", nsStatus);
+ nfvoNsInst.setStatus(nsStatus);
+ databaseServiceProvider.saveNfvoNsInst(nfvoNsInst);
+ }
+
+ private Optional<Tenant> getTenant(final String vnfPkgId,
+ final List<NsInstancesnsInstanceIdinstantiateAdditionalParamsForVnf> additionalParamsForVnfList) {
+
+ final Optional<NsInstancesnsInstanceIdinstantiateAdditionalParamsForVnf> optional = additionalParamsForVnfList
+ .stream().filter(entry -> vnfPkgId.equals(entry.getVnfProfileId())).findFirst();
+
+ if (optional.isPresent()) {
+ final NsInstancesnsInstanceIdinstantiateAdditionalParamsForVnf additionalParamsForVnf = optional.get();
+ @SuppressWarnings("unchecked")
+ final Map<String, Object> additionalParams =
+ (Map<String, Object>) additionalParamsForVnf.getAdditionalParams();
+ final String vimId = (String) additionalParams.get("vim_id");
+ if (vimId != null) {
+ final String[] splitString = vimId.split("_");
+ if (splitString.length == 3) {
+ logger.info("Found Tenant in instantiateNsRequest using vnfPkgId: {}", vnfPkgId);
+ return Optional.of(new Tenant().cloudOwner(splitString[0]).regionName(splitString[1])
+ .tenantId(splitString[2]));
+ }
+
+ }
+ }
+
+ logger.error("Unable to find Tenant in instantiateNsRequest using vnfPkgId: {}", vnfPkgId);
+ return Optional.empty();
+ }
+
+ @SuppressWarnings("unchecked")
+ private Map<String, String> getAdditionalParams(final String vnfPkgId,
+ final List<NsInstancesnsInstanceIdinstantiateAdditionalParamsForVnf> additionalParamsForVnfList) {
+
+ final Optional<NsInstancesnsInstanceIdinstantiateAdditionalParamsForVnf> optional = additionalParamsForVnfList
+ .stream().filter(entry -> vnfPkgId.equals(entry.getVnfProfileId())).findFirst();
+
+ if (optional.isPresent()) {
+ final NsInstancesnsInstanceIdinstantiateAdditionalParamsForVnf additionalParamsForVnf = optional.get();
+ if (additionalParamsForVnf instanceof Map) {
+ logger.info("Found AdditionalParams in instantiateNsRequest using vnfPkgId: {}", vnfPkgId);
+ return (Map<String, String>) additionalParamsForVnf.getAdditionalParams();
+ }
+ }
+
+ return Collections.emptyMap();
+
+ }
+
+ private NfvoNsInst getNfvoNsInst(final DelegateExecution execution) {
+ final String nsInstId = (String) execution.getVariable(NS_INSTANCE_ID_PARAM_NAME);
+ return getNfvoNsInst(execution, nsInstId);
+ }
+
+ private NfvoNsInst getNfvoNsInst(final DelegateExecution execution, final String nsInstId) {
+ logger.info("Getting NfvoNsInst to update with nsInstId: {}", nsInstId);
+ final Optional<NfvoNsInst> optionalNfvoNsInst = databaseServiceProvider.getNfvoNsInst(nsInstId);
+
+ if (!optionalNfvoNsInst.isPresent()) {
+ final String message = "Unable to find NS Instance in database using id: " + nsInstId;
+ abortOperation(execution, message);
+ }
+
+ return optionalNfvoNsInst.get();
+ }
+
+
+}