aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn
diff options
context:
space:
mode:
authorwaqas.ikram <waqas.ikram@est.tech>2022-06-10 15:43:31 +0100
committerwaqas.ikram <waqas.ikram@est.tech>2022-06-10 18:38:16 +0100
commit9267b3ae36ce0ade8d7f7bcd44ff648e78d3a14e (patch)
treef18b567675d0296bdb2ffc8044f9bf1a1eb455e6 /bpmn
parentff9d4779f0089c884add00ddea5a3d0fca0d4778 (diff)
[SO] Adding logic to invoke cnfm
Change-Id: I2c0e625724a394fe091a0ed1c6efabcd98e606ff Issue-ID: SO-3905 Signed-off-by: waqas.ikram <waqas.ikram@est.tech>
Diffstat (limited to 'bpmn')
-rw-r--r--bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CnfInstantiateBB.bpmn44
-rw-r--r--bpmn/so-bpmn-tasks/pom.xml5
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTask.java131
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceConfiguration.java79
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProvider.java36
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImpl.java83
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmUrlProvider.java47
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/CnfInstantiateTask.java58
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterCreateVnfTaskConfiguration.java5
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterServiceProviderImpl.java4
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterCreateVnfTaskConfigurationTest.java2
11 files changed, 417 insertions, 77 deletions
diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CnfInstantiateBB.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CnfInstantiateBB.bpmn
index 3f2ace3a26..1ed80eeeab 100644
--- a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CnfInstantiateBB.bpmn
+++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CnfInstantiateBB.bpmn
@@ -1,37 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
-<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" id="Definitions_0x13ohc" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.12.0">
- <bpmn:process id="CnfInstantiateBB" name="&#10;CnfInstantiateBB" isExecutable="true">
+<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" id="Definitions_0x13ohc" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.0.0">
+ <bpmn:process id="CnfInstantiateBB" name="&#10;Invoke CNFM" isExecutable="true">
<bpmn:startEvent id="StartEvent_0ru3x55">
<bpmn:outgoing>SequenceFlow_016sgof</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="SequenceFlow_016sgof" sourceRef="StartEvent_0ru3x55" targetRef="ServiceTask_11" />
<bpmn:endEvent id="EndEvent_001k15i">
- <bpmn:incoming>SequenceFlow_18fsqzd</bpmn:incoming>
+ <bpmn:incoming>Flow_1luy180</bpmn:incoming>
</bpmn:endEvent>
- <bpmn:serviceTask id="ServiceTask_11" name="Print Input parameters" camunda:asyncAfter="true" camunda:expression="${CnfInstantiateTask.handleCnfInstatiate(InjectExecution.execute(execution, execution.getVariable(&#34;gBuildingBlockExecution&#34;)))}">
+ <bpmn:serviceTask id="ServiceTask_11" name="Create &#10;CreateAsRequest" camunda:asyncAfter="true" camunda:expression="${CnfInstantiateTask.createCreateAsRequest(InjectExecution.execute(execution, execution.getVariable(&#34;gBuildingBlockExecution&#34;)))}">
<bpmn:incoming>SequenceFlow_016sgof</bpmn:incoming>
- <bpmn:outgoing>SequenceFlow_18fsqzd</bpmn:outgoing>
+ <bpmn:outgoing>Flow_1s7gtbc</bpmn:outgoing>
</bpmn:serviceTask>
- <bpmn:sequenceFlow id="SequenceFlow_18fsqzd" sourceRef="ServiceTask_11" targetRef="EndEvent_001k15i" />
+ <bpmn:serviceTask id="Activity_1y5x7jl" name="Invoke CNFM" camunda:asyncAfter="true" camunda:expression="${CnfInstantiateTask.invokeCnfmWithCreateAsRequest(InjectExecution.execute(execution, execution.getVariable(&#34;gBuildingBlockExecution&#34;)))}">
+ <bpmn:incoming>Flow_1s7gtbc</bpmn:incoming>
+ <bpmn:outgoing>Flow_1luy180</bpmn:outgoing>
+ </bpmn:serviceTask>
+ <bpmn:sequenceFlow id="Flow_1s7gtbc" sourceRef="ServiceTask_11" targetRef="Activity_1y5x7jl" />
+ <bpmn:sequenceFlow id="Flow_1luy180" sourceRef="Activity_1y5x7jl" targetRef="EndEvent_001k15i" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="CnfInstantiateBB">
- <bpmndi:BPMNEdge id="SequenceFlow_18fsqzd_di" bpmnElement="SequenceFlow_18fsqzd">
- <di:waypoint x="400" y="117" />
- <di:waypoint x="522" y="117" />
- </bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="SequenceFlow_016sgof_di" bpmnElement="SequenceFlow_016sgof">
- <di:waypoint x="188" y="117" />
+ <di:waypoint x="218" y="117" />
<di:waypoint x="300" y="117" />
</bpmndi:BPMNEdge>
- <bpmndi:BPMNShape id="StartEvent_0ru3x55_di" bpmnElement="StartEvent_0ru3x55">
- <dc:Bounds x="152" y="99" width="36" height="36" />
+ <bpmndi:BPMNEdge id="Flow_1s7gtbc_di" bpmnElement="Flow_1s7gtbc">
+ <di:waypoint x="400" y="117" />
+ <di:waypoint x="450" y="117" />
+ </bpmndi:BPMNEdge>
+ <bpmndi:BPMNEdge id="Flow_1luy180_di" bpmnElement="Flow_1luy180">
+ <di:waypoint x="550" y="117" />
+ <di:waypoint x="622" y="117" />
+ </bpmndi:BPMNEdge>
+ <bpmndi:BPMNShape id="ServiceTask_1jf7hlc_di" bpmnElement="ServiceTask_11">
+ <dc:Bounds x="300" y="77" width="100" height="80" />
+ </bpmndi:BPMNShape>
+ <bpmndi:BPMNShape id="Activity_1y5x7jl_di" bpmnElement="Activity_1y5x7jl">
+ <dc:Bounds x="450" y="77" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="EndEvent_001k15i_di" bpmnElement="EndEvent_001k15i">
- <dc:Bounds x="522" y="99" width="36" height="36" />
+ <dc:Bounds x="622" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
- <bpmndi:BPMNShape id="ServiceTask_1jf7hlc_di" bpmnElement="ServiceTask_11">
- <dc:Bounds x="300" y="77" width="100" height="80" />
+ <bpmndi:BPMNShape id="StartEvent_0ru3x55_di" bpmnElement="StartEvent_0ru3x55">
+ <dc:Bounds x="182" y="99" width="36" height="36" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
diff --git a/bpmn/so-bpmn-tasks/pom.xml b/bpmn/so-bpmn-tasks/pom.xml
index 64db71339d..d789878728 100644
--- a/bpmn/so-bpmn-tasks/pom.xml
+++ b/bpmn/so-bpmn-tasks/pom.xml
@@ -245,5 +245,10 @@
<artifactId>so-sdn-clients</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.onap.so.so-cnfm.lcm</groupId>
+ <artifactId>so-cnfm-lcm-api</artifactId>
+ <version>1.9.0-SNAPSHOT</version>
+ </dependency>
</dependencies>
</project>
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTask.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTask.java
new file mode 100644
index 0000000000..6d7b3e9287
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTask.java
@@ -0,0 +1,131 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Ericsson. All rights reserved.
+ * ================================================================================
+ * 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.adapter.cnfm.tasks;
+
+import static java.util.Objects.isNull;
+import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.CLOUD_OWNER_PARAM_KEY;
+import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.CLOUD_REGION_PARAM_KEY;
+import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.SERVICE_INSTANCE_ID_PARAM_KEY;
+import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.SERVICE_INSTANCE_NAME_PARAM_KEY;
+import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.TENANT_ID_PARAM_KEY;
+import java.util.Optional;
+import org.apache.groovy.util.Maps;
+import org.onap.logging.filter.base.ONAPComponents;
+import org.onap.so.bpmn.common.BuildingBlockExecution;
+import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
+import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
+import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
+import org.onap.so.client.exception.ExceptionBuilder;
+import org.onap.so.cnfm.lcm.model.AsInstance;
+import org.onap.so.cnfm.lcm.model.CreateAsRequest;
+import org.onap.so.serviceinstancebeans.CloudConfiguration;
+import org.onap.so.serviceinstancebeans.ModelInfo;
+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;
+
+
+/**
+ * This class performs CNF Instantiation
+ *
+ * @author sagar.shetty@est.tech
+ * @author Waqas Ikram (waqas.ikram@est.tech)
+ */
+@Component
+public class CnfInstantiateTask {
+ private static final String CREATE_AS_REQUEST_OBJECT = "CreateAsRequestObject";
+ private static final Logger LOGGER = LoggerFactory.getLogger(CnfInstantiateTask.class);
+ private final ExceptionBuilder exceptionUtil;
+ private final CnfmHttpServiceProvider cnfmHttpServiceProvider;
+
+ @Autowired
+ public CnfInstantiateTask(final CnfmHttpServiceProvider cnfmHttpServiceProvider,
+ final ExceptionBuilder exceptionUtil) {
+ this.cnfmHttpServiceProvider = cnfmHttpServiceProvider;
+ this.exceptionUtil = exceptionUtil;
+ }
+
+ public void createCreateAsRequest(final BuildingBlockExecution execution) {
+ try {
+ LOGGER.debug("Executing createAsRequest task ...");
+ final ExecuteBuildingBlock executeBuildingBlock =
+ (ExecuteBuildingBlock) execution.getVariable("buildingBlock");
+
+ final GeneralBuildingBlock generalBuildingBlock = execution.getGeneralBuildingBlock();
+
+ final RequestDetails requestDetails = executeBuildingBlock.getRequestDetails();
+ LOGGER.debug("RequestDetails: {}", requestDetails);
+
+ if (isNull(requestDetails) && isNull(requestDetails.getModelInfo())
+ && isNull(requestDetails.getRequestInfo()) && isNull(requestDetails.getCloudConfiguration())
+ && isNull(generalBuildingBlock)) {
+ LOGGER.error("Missing Mandatory attribute from RequestDetails: {} or GeneralBuildingBlock: {}",
+ requestDetails, generalBuildingBlock);
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2000,
+ "Missing Mandatory attribute from RequestDetails or GeneralBuildingBlock", ONAPComponents.SO);
+ }
+
+ final ModelInfo modelInfo = requestDetails.getModelInfo();
+ final CloudConfiguration cloudConfiguration = requestDetails.getCloudConfiguration();
+ final ServiceInstance serviceInstance = generalBuildingBlock.getServiceInstance();
+
+ final CreateAsRequest createAsRequest = new CreateAsRequest().asdId(modelInfo.getModelVersionId())
+ .asInstanceName(requestDetails.getRequestInfo().getInstanceName())
+ .additionalParams(Maps.of(CLOUD_OWNER_PARAM_KEY, cloudConfiguration.getCloudOwner(),
+ CLOUD_REGION_PARAM_KEY, cloudConfiguration.getLcpCloudRegionId(), TENANT_ID_PARAM_KEY,
+ cloudConfiguration.getTenantId(), SERVICE_INSTANCE_ID_PARAM_KEY,
+ serviceInstance.getServiceInstanceId(), SERVICE_INSTANCE_NAME_PARAM_KEY,
+ serviceInstance.getServiceInstanceName()));
+
+ LOGGER.debug("Adding CreateAsRequest to execution {}", createAsRequest);
+
+ execution.setVariable(CREATE_AS_REQUEST_OBJECT, createAsRequest);
+ LOGGER.debug("Finished executing createAsRequest task ...");
+
+ } catch (final Exception exception) {
+ LOGGER.error("Unable to create CreateAsRequest", exception);
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2001, exception);
+ }
+ }
+
+ public void invokeCnfmWithCreateAsRequest(final BuildingBlockExecution execution) {
+ try {
+ final CreateAsRequest createAsRequest = execution.getVariable(CREATE_AS_REQUEST_OBJECT);
+
+ final Optional<AsInstance> optional = cnfmHttpServiceProvider.invokeCreateAsRequest(createAsRequest);
+
+ if (optional.isEmpty()) {
+ LOGGER.error("Unable to invoke CNFM for CreateAsRequest : {}", createAsRequest);
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2003,
+ "Unable to invoke CNFM for CreateAsRequest", ONAPComponents.SO);
+ }
+
+ final AsInstance asInstance = optional.get();
+ LOGGER.debug("Successfully invoked CNFM response: {}", asInstance);
+
+ } catch (final Exception exception) {
+ LOGGER.error("Unable to invoke CNFM AsCreateRequest", exception);
+ exceptionUtil.buildAndThrowWorkflowException(execution, 2004, exception);
+ }
+ }
+
+}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceConfiguration.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceConfiguration.java
new file mode 100644
index 0000000000..bd16bda42e
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceConfiguration.java
@@ -0,0 +1,79 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 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.adapter.cnfm.tasks;
+
+import javax.ws.rs.core.MediaType;
+import org.onap.logging.filter.spring.SpringClientPayloadFilter;
+import org.onap.so.configuration.rest.HttpComponentsClientConfiguration;
+import org.onap.so.logging.jaxrs.filter.SOSpringClientFilter;
+import org.onap.so.rest.service.HttpRestServiceProvider;
+import org.onap.so.rest.service.HttpRestServiceProviderImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.client.BufferingClientHttpRequestFactory;
+import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
+import org.springframework.web.client.RestTemplate;
+
+/**
+ * @author waqas.ikram@est.tech
+ */
+@Configuration
+public class CnfmHttpServiceConfiguration {
+
+ private static final Logger logger = LoggerFactory.getLogger(CnfmHttpServiceConfiguration.class);
+ public static final String CNFM_REST_TEMPLATE_CLIENT_BEAN = "cnfmRestTemplateBean";
+ public static final String CNFM_HTTP_REST_SERVICE_PROVIDER_BEAN = "cnfmHttpRestServiceProvider";
+
+ @Bean
+ @Qualifier(CNFM_REST_TEMPLATE_CLIENT_BEAN)
+ public RestTemplate cnfmRestTemplateBean(
+ @Autowired final HttpComponentsClientConfiguration httpComponentsClientConfiguration) {
+ logger.debug("Setting up cnfm RestTemplate bean...");
+ final HttpComponentsClientHttpRequestFactory clientHttpRequestFactory =
+ httpComponentsClientConfiguration.httpComponentsClientHttpRequestFactory();
+
+ final RestTemplate restTemplate =
+ new RestTemplate(new BufferingClientHttpRequestFactory(clientHttpRequestFactory));
+ restTemplate.getInterceptors().add(new SOSpringClientFilter());
+ restTemplate.getInterceptors().add((new SpringClientPayloadFilter()));
+ return restTemplate;
+
+ }
+
+ @Bean
+ @Qualifier(CNFM_HTTP_REST_SERVICE_PROVIDER_BEAN)
+ public HttpRestServiceProvider cnfmHttpRestServiceProvider(
+ @Qualifier(CNFM_REST_TEMPLATE_CLIENT_BEAN) @Autowired final RestTemplate restTemplate) {
+
+ logger.debug("Setting up cnfm HttpRestServiceProvider bean...");
+ final HttpHeaders hearders = new HttpHeaders();
+ hearders.add(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON);
+ hearders.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
+
+ return new HttpRestServiceProviderImpl(restTemplate, hearders);
+ }
+
+}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProvider.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProvider.java
new file mode 100644
index 0000000000..4ff346543f
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProvider.java
@@ -0,0 +1,36 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 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.adapter.cnfm.tasks;
+
+import java.util.Optional;
+import org.onap.so.cnfm.lcm.model.AsInstance;
+import org.onap.so.cnfm.lcm.model.CreateAsRequest;
+
+
+/**
+ * @author Sagar Shetty (sagar.shetty@est.tech)
+ * @author Waqas Ikram (waqas.ikram@est.tech)
+ *
+ */
+public interface CnfmHttpServiceProvider {
+
+ Optional<AsInstance> invokeCreateAsRequest(final CreateAsRequest createAsRequest);
+
+}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImpl.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImpl.java
new file mode 100644
index 0000000000..f861855b99
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmHttpServiceProviderImpl.java
@@ -0,0 +1,83 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Ericsson. All rights reserved.
+ * ================================================================================
+ * 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.adapter.cnfm.tasks;
+
+import static org.onap.so.bpmn.infrastructure.adapter.cnfm.tasks.CnfmHttpServiceConfiguration.CNFM_HTTP_REST_SERVICE_PROVIDER_BEAN;
+import java.util.Optional;
+import org.onap.so.cnfm.lcm.model.AsInstance;
+import org.onap.so.cnfm.lcm.model.CreateAsRequest;
+import org.onap.so.rest.exceptions.HttpResouceNotFoundException;
+import org.onap.so.rest.exceptions.InvalidRestRequestException;
+import org.onap.so.rest.exceptions.RestProcessingException;
+import org.onap.so.rest.service.HttpRestServiceProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
+
+@Service
+public class CnfmHttpServiceProviderImpl implements CnfmHttpServiceProvider {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(CnfmHttpServiceProviderImpl.class);
+ private final CnfmUrlProvider cnfmUrlProvider;
+ private final HttpRestServiceProvider httpServiceProvider;
+
+ @Autowired
+ public CnfmHttpServiceProviderImpl(final CnfmUrlProvider cnfmUrlProvider,
+ @Qualifier(CNFM_HTTP_REST_SERVICE_PROVIDER_BEAN) final HttpRestServiceProvider httpServiceProvider) {
+ this.cnfmUrlProvider = cnfmUrlProvider;
+ this.httpServiceProvider = httpServiceProvider;
+ }
+
+ @Override
+ public Optional<AsInstance> invokeCreateAsRequest(final CreateAsRequest createAsRequest) {
+ try {
+ final String url = cnfmUrlProvider.getCreateAsRequestUrl();
+ final ResponseEntity<AsInstance> response =
+ httpServiceProvider.postHttpRequest(createAsRequest, url, AsInstance.class);
+
+ final HttpStatus httpStatus = response.getStatusCode();
+ if (httpStatus.is2xxSuccessful()) {
+ if (!response.hasBody()) {
+ LOGGER.error("Received response without body: {}", response);
+ return Optional.empty();
+ }
+
+ final AsInstance asInstance = response.getBody();
+ if (asInstance.getAsInstanceid() == null || asInstance.getAsInstanceid().isEmpty()) {
+ LOGGER.error("Received invalid response missing asInstanceid: {}", response);
+ return Optional.empty();
+ }
+ return Optional.of(asInstance);
+ }
+ LOGGER.error("Unable to invoke HTTP POST using URL: {}, Response Code: {}", url, httpStatus.value());
+ return Optional.empty();
+
+ } catch (final RestProcessingException | InvalidRestRequestException
+ | HttpResouceNotFoundException httpInvocationException) {
+ LOGGER.error("Unexpected error while processing create and instantiation request", httpInvocationException);
+ return Optional.empty();
+ }
+ }
+
+}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmUrlProvider.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmUrlProvider.java
new file mode 100644
index 0000000000..3a0e4de6f9
--- /dev/null
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfmUrlProvider.java
@@ -0,0 +1,47 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Ericsson. All rights reserved.
+ * ================================================================================
+ * 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.adapter.cnfm.tasks;
+
+import java.net.URI;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+import org.springframework.web.util.UriComponentsBuilder;
+
+/**
+ * @author Sagar Shetty (sagar.shetty@est.tech)
+ * @author Waqas Ikram (waqas.ikram@est.tech)
+ *
+ */
+@Service
+public class CnfmUrlProvider {
+
+ private final URI baseUri;
+
+ @Autowired
+ public CnfmUrlProvider(@Value("${cnfm.endpoint:http://so-cnfm-lcm.onap:9888}") final String baseUrl) {
+ this.baseUri = UriComponentsBuilder.fromHttpUrl(baseUrl).path("/so/so-cnfm/v1/api/aslcm/v1").build().toUri();
+ }
+
+ public String getCreateAsRequestUrl() {
+ return UriComponentsBuilder.fromUri(baseUri).pathSegment("as_instances").build().toString();
+ }
+
+}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/CnfInstantiateTask.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/CnfInstantiateTask.java
deleted file mode 100644
index 0b24f2608b..0000000000
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/CnfInstantiateTask.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2022 Ericsson. All rights reserved.
- * ================================================================================
- * 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.adapter.vnfm.tasks;
-
-import org.onap.so.bpmn.common.BuildingBlockExecution;
-import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock;
-import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
-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;
-
-
-/**
- * This class performs CNF Instantiation
- *
- * @author sagar.shetty@est.tech
- */
-@Component
-public class CnfInstantiateTask {
- private static final Logger LOGGER = LoggerFactory.getLogger(CnfInstantiateTask.class);
- private final ExtractPojosForBB extractPojosForBB;
-
- @Autowired
- public CnfInstantiateTask(final ExtractPojosForBB extractPojosForBB) {
- this.extractPojosForBB = extractPojosForBB;
- }
-
- public void handleCnfInstatiate(final BuildingBlockExecution execution) {
- try {
- LOGGER.debug("Executing handleCnfInstatiate ...");
- ExecuteBuildingBlock executeBuildingBlock = (ExecuteBuildingBlock) execution.getVariable("buildingBlock");
- RequestDetails requestDetails = executeBuildingBlock.getRequestDetails();
- LOGGER.debug("RequestDetails: {}", requestDetails);
- LOGGER.debug("Finished executing handleCnfInstatiate ...");
- } catch (final Exception exception) {
- LOGGER.error("Unable to instantiate CNF", exception);
- }
- }
-}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterCreateVnfTaskConfiguration.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterCreateVnfTaskConfiguration.java
index c3c0047fff..fc3d6ab96c 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterCreateVnfTaskConfiguration.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterCreateVnfTaskConfiguration.java
@@ -58,6 +58,8 @@ import org.springframework.web.client.RestTemplate;
@Configuration
public class VnfmAdapterCreateVnfTaskConfiguration {
+ public static final String VNFM_HTTP_REST_SERVICE_PROVIDER_BEAN = "vnfmHttpRestServiceProvider";
+
private static final Logger logger = LoggerFactory.getLogger(VnfmAdapterCreateVnfTaskConfiguration.class);
@Value("${rest.http.client.configuration.ssl.trustStore:#{null}}")
@@ -73,7 +75,8 @@ public class VnfmAdapterCreateVnfTaskConfiguration {
private String keyStorePassword;
@Bean
- public HttpRestServiceProvider databaseHttpRestServiceProvider(
+ @Qualifier(VNFM_HTTP_REST_SERVICE_PROVIDER_BEAN)
+ public HttpRestServiceProvider vnfmHttpRestServiceProvider(
@Qualifier(CONFIGURABLE_REST_TEMPLATE) @Autowired final RestTemplate restTemplate,
@Autowired final VnfmBasicHttpConfigProvider etsiVnfmAdapter) {
if (trustStore != null) {
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterServiceProviderImpl.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterServiceProviderImpl.java
index ac2e0bf17a..94213bb93f 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterServiceProviderImpl.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterServiceProviderImpl.java
@@ -20,6 +20,7 @@
package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks;
+import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.VnfmAdapterCreateVnfTaskConfiguration.VNFM_HTTP_REST_SERVICE_PROVIDER_BEAN;
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.DeleteVnfResponse;
@@ -31,6 +32,7 @@ import org.onap.so.rest.service.HttpRestServiceProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
@@ -50,7 +52,7 @@ public class VnfmAdapterServiceProviderImpl implements VnfmAdapterServiceProvide
@Autowired
public VnfmAdapterServiceProviderImpl(final VnfmAdapterUrlProvider urlProvider,
- final HttpRestServiceProvider httpServiceProvider) {
+ @Qualifier(VNFM_HTTP_REST_SERVICE_PROVIDER_BEAN) final HttpRestServiceProvider httpServiceProvider) {
this.urlProvider = urlProvider;
this.httpServiceProvider = httpServiceProvider;
}
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterCreateVnfTaskConfigurationTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterCreateVnfTaskConfigurationTest.java
index 75151d9c6a..6ae9398489 100644
--- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterCreateVnfTaskConfigurationTest.java
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterCreateVnfTaskConfigurationTest.java
@@ -44,7 +44,7 @@ public class VnfmAdapterCreateVnfTaskConfigurationTest {
final VnfmAdapterCreateVnfTaskConfiguration objUnderTest = new VnfmAdapterCreateVnfTaskConfiguration();
final HttpRestServiceProvider actual =
- objUnderTest.databaseHttpRestServiceProvider(restTemplate, getVnfmBasicHttpConfigProvider());
+ objUnderTest.vnfmHttpRestServiceProvider(restTemplate, getVnfmBasicHttpConfigProvider());
assertNotNull(actual);