aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/onap/nbi/apis/servicecatalog/ServiceSpecificationResource.java13
-rw-r--r--src/main/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessor.java207
-rw-r--r--src/main/java/org/onap/nbi/apis/serviceorder/SoClient.java36
-rw-r--r--src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/CreateMacroServiceInstanceResponse.java34
-rw-r--r--src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/ModelInfo.java4
-rw-r--r--src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/RequestDetails.java6
-rw-r--r--src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/RequestInfo.java15
-rw-r--r--src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/VFModelInfo.java95
-rw-r--r--src/main/java/org/onap/nbi/apis/serviceorder/workflow/PostSoProcessor.java248
-rw-r--r--src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskProcessor.java38
-rw-r--r--src/main/resources/application-test.properties7
-rw-r--r--src/main/resources/application.properties5
12 files changed, 632 insertions, 76 deletions
diff --git a/src/main/java/org/onap/nbi/apis/servicecatalog/ServiceSpecificationResource.java b/src/main/java/org/onap/nbi/apis/servicecatalog/ServiceSpecificationResource.java
index 3651ec8..f9f5e07 100644
--- a/src/main/java/org/onap/nbi/apis/servicecatalog/ServiceSpecificationResource.java
+++ b/src/main/java/org/onap/nbi/apis/servicecatalog/ServiceSpecificationResource.java
@@ -16,6 +16,7 @@
package org.onap.nbi.apis.servicecatalog;
+import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -43,6 +44,16 @@ public class ServiceSpecificationResource extends ResourceManagement {
public ResponseEntity<Object> getServiceSpecification(@PathVariable String serviceSpecId,
@RequestParam MultiValueMap<String, String> params) {
Map response = serviceSpecificationService.get(serviceSpecId);
+
+ if (response != null) {
+ ArrayList<Map<String, Object>> resourseSpecificationMap= (ArrayList<Map<String, Object>>) response.get("resourceSpecification");
+ for (Map<String, Object> map : resourseSpecificationMap) {
+ map.remove("childResourceSpecification");
+ map.remove("InstanceSpecification");
+ }
+ response.put("resourceSpecification", resourseSpecificationMap);
+ }
+
JsonRepresentation filter = new JsonRepresentation(params);
if (response.get("serviceSpecCharacteristic") != null) {
return this.getResponse(response, filter);
@@ -67,4 +78,4 @@ public class ServiceSpecificationResource extends ResourceManagement {
return this.getResponse(response, filter);
}
-}
+} \ No newline at end of file
diff --git a/src/main/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessor.java b/src/main/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessor.java
index 2153b84..586d0b5 100644
--- a/src/main/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessor.java
+++ b/src/main/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessor.java
@@ -16,12 +16,22 @@ package org.onap.nbi.apis.servicecatalog;
import java.nio.file.Path;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
+
+import org.onap.nbi.apis.serviceorder.model.consumer.VFModelInfo;
+import org.onap.sdc.tosca.parser.api.IEntityDetails;
import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
+import org.onap.sdc.tosca.parser.elements.queries.EntityQuery;
+import org.onap.sdc.tosca.parser.elements.queries.TopologyTemplateQuery;
+import org.onap.sdc.tosca.parser.enums.SdcTypes;
import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
+import org.onap.sdc.tosca.parser.impl.SdcPropertyNames;
import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory;
import org.onap.sdc.toscaparser.api.NodeTemplate;
import org.onap.sdc.toscaparser.api.elements.Metadata;
@@ -47,6 +57,10 @@ public class ToscaInfosProcessor {
@Autowired
private ServiceSpecificationDBManager serviceSpecificationDBManager;
+ private Set<String> vnfInstanceParams = new HashSet<String>(Arrays.asList("onap_private_net_id",
+ "onap_private_subnet_id", "pub_key", "sec_group", "install_script_version", "demo_artifacts_version",
+ "cloud_env", "public_net_id", "aic-cloud-region", "image_name", "flavor_name"));
+
final ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); // jackson databind
private static final Logger LOGGER = LoggerFactory.getLogger(ToscaInfosProcessor.class);
@@ -114,81 +128,148 @@ public class ToscaInfosProcessor {
}
public void buildAndSaveResponseWithSdcToscaParser(Path path, Map serviceCatalogResponse)
- throws SdcToscaParserException {
+ throws SdcToscaParserException {
- SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance();
- ISdcCsarHelper sdcCsarHelper = factory.getSdcCsarHelper(path.toFile().getAbsolutePath(), false);
- List<Input> inputs = sdcCsarHelper.getServiceInputs();
+ SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance();
+ ISdcCsarHelper sdcCsarHelper = factory.getSdcCsarHelper(path.toFile().getAbsolutePath(), false);
+ List<Input> inputs = sdcCsarHelper.getServiceInputs();
- Map<String, Model> definitions = new HashMap<String, Model>();
- Model model = new ModelImpl();
+ List<IEntityDetails> vfEntityList = sdcCsarHelper.getEntity(EntityQuery.newBuilder(SdcTypes.VF).build(),
+ TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE).build(), false);
- if (inputs != null && inputs.size() > 0) {
- for (Input input : inputs) {
- Property property = null;
- if (input.getType().equals("list") || input.getType().equals("map"))
- property = PropertyBuilder.build("array", null, null);
- else
- property = PropertyBuilder.build(input.getType(), null, null);
+ Map<String, String> listOfInstanceParameters = new HashMap<>();
+ if (!vfEntityList.isEmpty()) {
- property.setDescription(input.getDescription());
- property.setRequired(input.isRequired());
+ IEntityDetails iEntityDetails = vfEntityList.get(0);
+ Map<String, org.onap.sdc.toscaparser.api.Property> groupProperties = iEntityDetails.getProperties();
- if (input.getDefault() != null) {
- property.setDefault(input.getDefault().toString());
- }
- ((ModelImpl) model).addProperty(input.getName(), property);
- }
- definitions.put("ServiceCharacteristics", model);
+ for (String key : groupProperties.keySet()) {
+ org.onap.sdc.toscaparser.api.Property property = groupProperties.get(key);
+ String paramName = property.getName();
+ if (paramName != null) {
+ if (vnfInstanceParams.stream()
+ .filter(vnfInstanceParam -> vnfInstanceParam.equalsIgnoreCase(paramName)).findFirst()
+ .isPresent()) {
+ listOfInstanceParameters.put(paramName, property.getValue().toString());
+ }
+ }
+ }
- }
+ }
- String svcCharacteristicsJson = Json.pretty(definitions);
- serviceSpecificationDBManager.saveSpecificationInputSchema(svcCharacteristicsJson, serviceCatalogResponse);
+ // it will build Entity as VfModules
+ List<IEntityDetails> vfModuleEntityList = sdcCsarHelper.getEntity(
+ EntityQuery.newBuilder("org.openecomp.groups.VfModule").build(),
+ TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE)
+ .customizationUUID(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID).build(),
+ false);
+ List<VFModelInfo> listOfVfModelInfo = new ArrayList<>();
- Metadata serviceMetadata = sdcCsarHelper.getServiceMetadata();
- String instantationType = serviceMetadata.getValue("instantiationType");
- serviceCatalogResponse.put("instantiationType", instantationType);
+ if (!vfModuleEntityList.isEmpty()) {
+ // Fetching vfModule metadata in a loop
+ for (IEntityDetails vfModuleEntity : vfModuleEntityList) {
+ VFModelInfo vfModel = new VFModelInfo();
+ Metadata vfMetadata = vfModuleEntity.getMetadata();
+ // Preparing VFModel
+ vfModel.setModelInvariantUuid(
+ testNull(vfMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID)));
+ vfModel.setModelName(testNull(vfMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELNAME)));
+ vfModel.setModelUuid(testNull(vfMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID)));
+ vfModel.setModelVersion(
+ testNull(vfMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELVERSION)));
+ vfModel.setModelCustomizationUuid(testNull(vfMetadata.getValue("vfModuleModelCustomizationUUID")));
- LinkedHashMap inputSchemaRef = new LinkedHashMap();
- // use object to match examples in Specifications
- inputSchemaRef.put("valueType", "object");
- inputSchemaRef.put("@schemaLocation",
- "/serviceSpecification/" + serviceCatalogResponse.get("id") + "/specificationInputSchema");
- inputSchemaRef.put("@type", serviceCatalogResponse.get("name") + "_ServiceCharacteristic");
+ // Adding it to the list
+ listOfVfModelInfo.add(vfModel);
+ }
+ }
- LinkedHashMap serviceSpecCharacteristic = new LinkedHashMap();
- serviceSpecCharacteristic.put("name", serviceCatalogResponse.get("name") + "_ServiceCharacteristics");
- serviceSpecCharacteristic.put("description",
- "This object describes all the inputs needed from the client to interact with the "
- + serviceCatalogResponse.get("name") + " Service Topology");
- serviceSpecCharacteristic.put("valueType", "object");
- serviceSpecCharacteristic.put("@type", "ONAPServiceCharacteristic");
- serviceSpecCharacteristic.put("@schemaLocation", "null");
- serviceSpecCharacteristic.put("serviceSpecCharacteristicValue", inputSchemaRef);
+ Map<String, Model> definitions = new HashMap<String, Model>();
+ Model model = new ModelImpl();
- serviceCatalogResponse.put("serviceSpecCharacteristic", serviceSpecCharacteristic);
+ if (!inputs.isEmpty() && inputs.size() > 0) {
+ for (Input input : inputs) {
+ Property property = null;
+ if (input.getType().equals("list") || input.getType().equals("map"))
+ property = PropertyBuilder.build("array", null, null);
+ else
+ property = PropertyBuilder.build(input.getType(), null, null);
- List<NodeTemplate> nodeTemplates = sdcCsarHelper.getServiceNodeTemplates();
- List<LinkedHashMap> resourceSpecifications =
- (List<LinkedHashMap>) serviceCatalogResponse.get("resourceSpecification");
- for (LinkedHashMap resourceSpecification : resourceSpecifications) {
- if (resourceSpecification.get("id") != null) {
- String id = (String) resourceSpecification.get("id");
- LOGGER.debug("get tosca infos for service id: {}", id);
- NodeTemplate nodeTemplate = null;
- for (NodeTemplate node : nodeTemplates) {
- if (node.getMetaData().getValue("UUID").equals(id)) {
- nodeTemplate = node;
- break;
- }
- }
- if (nodeTemplate == null)
- continue;
- resourceSpecification.put("modelCustomizationId",
- sdcCsarHelper.getNodeTemplateCustomizationUuid(nodeTemplate));
- }
+ property.setDescription(input.getDescription());
+ property.setRequired(input.isRequired());
+
+ if (input.getDefault() != null) {
+ property.setDefault(input.getDefault().toString());
+ }
+ ((ModelImpl) model).addProperty(input.getName(), property);
+ }
+ definitions.put("ServiceCharacteristics", model);
+
+ }
+
+ String svcCharacteristicsJson = Json.pretty(definitions);
+ serviceSpecificationDBManager.saveSpecificationInputSchema(svcCharacteristicsJson, serviceCatalogResponse);
+
+ Metadata serviceMetadata = sdcCsarHelper.getServiceMetadata();
+ String instantationType = serviceMetadata.getValue("instantiationType");
+ serviceCatalogResponse.put("instantiationType", instantationType);
+
+ LinkedHashMap inputSchemaRef = new LinkedHashMap();
+ // use object to match examples in Specifications
+ inputSchemaRef.put("valueType", "object");
+ inputSchemaRef.put("@schemaLocation",
+ "/serviceSpecification/" + serviceCatalogResponse.get("id") + "/specificationInputSchema");
+ inputSchemaRef.put("@type", serviceCatalogResponse.get("name") + "_ServiceCharacteristic");
+
+ LinkedHashMap serviceSpecCharacteristic = new LinkedHashMap();
+ serviceSpecCharacteristic.put("name", serviceCatalogResponse.get("name") + "_ServiceCharacteristics");
+ serviceSpecCharacteristic.put("description",
+ "This object describes all the inputs needed from the client to interact with the "
+ + serviceCatalogResponse.get("name") + " Service Topology");
+ serviceSpecCharacteristic.put("valueType", "object");
+ serviceSpecCharacteristic.put("@type", "ONAPServiceCharacteristic");
+ serviceSpecCharacteristic.put("@schemaLocation", "null");
+ serviceSpecCharacteristic.put("serviceSpecCharacteristicValue", inputSchemaRef);
+
+ serviceCatalogResponse.put("serviceSpecCharacteristic", serviceSpecCharacteristic);
+
+ List<NodeTemplate> nodeTemplates = sdcCsarHelper.getServiceNodeTemplates();
+ List<LinkedHashMap> resourceSpecifications = (List<LinkedHashMap>) serviceCatalogResponse
+ .get("resourceSpecification");
+ for (LinkedHashMap resourceSpecification : resourceSpecifications) {
+ if (resourceSpecification.get("id") != null) {
+ String id = (String) resourceSpecification.get("id");
+ LOGGER.debug("get tosca infos for service id: {}", id);
+ NodeTemplate nodeTemplate = null;
+ for (NodeTemplate node : nodeTemplates) {
+ if (node.getMetaData().getValue("UUID").equals(id)) {
+ nodeTemplate = node;
+ break;
+ }
+ }
+ if (nodeTemplate == null)
+ continue;
+ resourceSpecification.put("modelCustomizationId",
+ sdcCsarHelper.getNodeTemplateCustomizationUuid(nodeTemplate));
+ if (!vfModuleEntityList.isEmpty()) {
+ resourceSpecification.put("childResourceSpecification", listOfVfModelInfo);
+ }
+ resourceSpecification.put("InstanceSpecification", listOfInstanceParameters);
+
+ }
+ }
+ }
+
+ private static String testNull(Object object) {
+ if (object == null) {
+ return "NULL";
+ } else if (object instanceof Integer) {
+ return object.toString();
+ } else if (object instanceof String) {
+ return (String) object;
+ } else {
+ return "Type not recognized";
}
}
-}
+} \ No newline at end of file
diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/SoClient.java b/src/main/java/org/onap/nbi/apis/serviceorder/SoClient.java
index c286d60..95009b8 100644
--- a/src/main/java/org/onap/nbi/apis/serviceorder/SoClient.java
+++ b/src/main/java/org/onap/nbi/apis/serviceorder/SoClient.java
@@ -17,6 +17,7 @@ package org.onap.nbi.apis.serviceorder;
import javax.annotation.PostConstruct;
import org.onap.nbi.OnapComponentsUrlPaths;
import org.onap.nbi.apis.serviceorder.model.consumer.CreateE2EServiceInstanceResponse;
+import org.onap.nbi.apis.serviceorder.model.consumer.CreateMacroServiceInstanceResponse;
import org.onap.nbi.apis.serviceorder.model.consumer.CreateServiceInstanceResponse;
import org.onap.nbi.apis.serviceorder.model.consumer.DeleteE2EServiceInstanceResponse;
import org.onap.nbi.apis.serviceorder.model.consumer.GetE2ERequestStatusResponse;
@@ -119,6 +120,27 @@ public class SoClient {
}
}
+ public ResponseEntity<CreateMacroServiceInstanceResponse> callMacroCreateServiceInstance(MSOPayload msoPayload) {
+
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("Calling SO CreateServiceInstance with msoPayload : " + msoPayload.toString());
+ }
+
+ try {
+ ResponseEntity<CreateMacroServiceInstanceResponse> response = restTemplate.exchange(createSoUrl,
+ HttpMethod.POST, new HttpEntity<>(msoPayload, buildRequestHeader()),CreateMacroServiceInstanceResponse.class);
+
+ logMacroResponsePost(createSoUrl, response);
+ return response;
+ } catch (BackendFunctionalException e) {
+ LOGGER.error(ERROR_ON_CALLING + createSoUrl + " ," + e.getHttpStatus() + " , " + e.getBodyResponse());
+ return new ResponseEntity(e.getBodyResponse(), e.getHttpStatus());
+ } catch (ResourceAccessException e) {
+ LOGGER.error(ERROR_ON_CALLING + createSoUrl + " ," + e.getMessage());
+ return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
+ }
+ }
+
public ResponseEntity<CreateE2EServiceInstanceResponse> callE2ECreateServiceInstance(MSOE2EPayload msoPayloadE2E) {
if (LOGGER.isDebugEnabled()) {
@@ -221,6 +243,18 @@ public class SoClient {
}
}
+ private void logMacroResponsePost(String url, ResponseEntity<CreateMacroServiceInstanceResponse> response) {
+ LOGGER.info(RESPONSE_STATUS + response.getStatusCodeValue());
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("response body : {}", response.getBody().toString());
+ }
+
+ if (LOGGER.isWarnEnabled() && !response.getStatusCode().equals(HttpStatus.CREATED)) {
+ LOGGER.warn("HTTP call SO on {} returns {} , {}", url, response.getStatusCodeValue(),
+ response.getBody().toString());
+ }
+ }
+
private void logE2EResponsePost(String url, ResponseEntity<CreateE2EServiceInstanceResponse> response) {
LOGGER.info(RESPONSE_STATUS + response.getStatusCodeValue());
if (LOGGER.isDebugEnabled()) {
@@ -328,4 +362,4 @@ public class SoClient {
return httpHeaders;
}
-}
+} \ No newline at end of file
diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/CreateMacroServiceInstanceResponse.java b/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/CreateMacroServiceInstanceResponse.java
new file mode 100644
index 0000000..bdd7f29
--- /dev/null
+++ b/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/CreateMacroServiceInstanceResponse.java
@@ -0,0 +1,34 @@
+/**
+ * Copyright (c) 2020 TechMahindra
+ *
+ * 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.
+ */
+package org.onap.nbi.apis.serviceorder.model.consumer;
+
+public class CreateMacroServiceInstanceResponse {
+
+ private RequestReferences requestReferences;
+
+ public RequestReferences getRequestReferences() {
+ return requestReferences;
+ }
+
+ public void setRequestReferences(RequestReferences requestReferences) {
+ this.requestReferences = requestReferences;
+ }
+
+ @Override
+ public String toString() {
+ return "CreateMacroServiceInstanceResponse{" + "requestReferences=" + requestReferences + '}';
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/ModelInfo.java b/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/ModelInfo.java
index 1d5cc6e..477770a 100644
--- a/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/ModelInfo.java
+++ b/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/ModelInfo.java
@@ -16,6 +16,10 @@
package org.onap.nbi.apis.serviceorder.model.consumer;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+
+@JsonInclude(Include.NON_NULL)
public class ModelInfo {
private String modelType;
diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/RequestDetails.java b/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/RequestDetails.java
index 4a38369..4e361b4 100644
--- a/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/RequestDetails.java
+++ b/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/RequestDetails.java
@@ -24,7 +24,7 @@ public class RequestDetails {
private RequestInfo requestInfo;
- private RequestParameters requestParameters;
+ private Object requestParameters;
private CloudConfiguration cloudConfiguration;
@@ -80,11 +80,11 @@ public class RequestDetails {
this.requestInfo = requestInfo;
}
- public RequestParameters getRequestParameters() {
+ public Object getRequestParameters() {
return requestParameters;
}
- public void setRequestParameters(RequestParameters requestParameters) {
+ public void setRequestParameters(Object requestParameters) {
this.requestParameters = requestParameters;
}
diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/RequestInfo.java b/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/RequestInfo.java
index 3aa54cc..6347a18 100644
--- a/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/RequestInfo.java
+++ b/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/RequestInfo.java
@@ -26,6 +26,8 @@ public class RequestInfo {
private String requestorId;
+ private String productFamilyId;
+
public String getInstanceName() {
return instanceName;
}
@@ -58,9 +60,18 @@ public class RequestInfo {
this.requestorId = requestorId;
}
+ public String getProductFamilyId() {
+ return productFamilyId;
+ }
+
+ public void setProductFamilyId(String productFamilyId) {
+ this.productFamilyId = productFamilyId;
+ }
+
@Override
public String toString() {
return "RequestInfo{" + "instanceName='" + instanceName + '\'' + ", source='" + source + '\''
- + ", suppressRollback=" + suppressRollback + ", requestorId='" + requestorId + '\'' + '}';
+ + ", suppressRollback=" + suppressRollback + ", requestorId='" + requestorId + '\''
+ + ", productFamilyId='" + productFamilyId + '\'' +'}';
}
-}
+} \ No newline at end of file
diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/VFModelInfo.java b/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/VFModelInfo.java
new file mode 100644
index 0000000..7dc24c5
--- /dev/null
+++ b/src/main/java/org/onap/nbi/apis/serviceorder/model/consumer/VFModelInfo.java
@@ -0,0 +1,95 @@
+/**
+ * Copyright (c) 2020 TechMahindra
+ *
+ * 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.
+ */
+package org.onap.nbi.apis.serviceorder.model.consumer;
+
+import org.apache.commons.lang3.builder.ToStringBuilder;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonPropertyOrder({ "modelName", "modelUuid", "modelInvariantUuid", "modelVersion", "modelCustomizationUuid" })
+public class VFModelInfo {
+
+ @JsonProperty("modelName")
+ private String modelName;
+ @JsonProperty("modelUuid")
+ private String modelUuid;
+ @JsonProperty("modelInvariantUuid")
+ private String modelInvariantUuid;
+ @JsonProperty("modelVersion")
+ private String modelVersion;
+ @JsonProperty("modelCustomizationUuid")
+ private String modelCustomizationUuid;
+
+ @JsonProperty("modelName")
+ public String getModelName() {
+ return modelName;
+ }
+
+ @JsonProperty("modelName")
+ public void setModelName(String modelName) {
+ this.modelName = modelName;
+ }
+
+ @JsonProperty("modelUuid")
+ public String getModelUuid() {
+ return modelUuid;
+ }
+
+ @JsonProperty("modelUuid")
+ public void setModelUuid(String modelUuid) {
+ this.modelUuid = modelUuid;
+ }
+
+ @JsonProperty("modelInvariantUuid")
+ public String getModelInvariantUuid() {
+ return modelInvariantUuid;
+ }
+
+ @JsonProperty("modelInvariantUuid")
+ public void setModelInvariantUuid(String modelInvariantUuid) {
+ this.modelInvariantUuid = modelInvariantUuid;
+ }
+
+ @JsonProperty("modelVersion")
+ public String getModelVersion() {
+ return modelVersion;
+ }
+
+ @JsonProperty("modelVersion")
+ public void setModelVersion(String modelVersion) {
+ this.modelVersion = modelVersion;
+ }
+
+ @JsonProperty("modelCustomizationUuid")
+ public String getModelCustomizationUuid() {
+ return modelCustomizationUuid;
+ }
+
+ @JsonProperty("modelCustomizationUuid")
+ public void setModelCustomizationUuid(String modelCustomizationUuid) {
+ this.modelCustomizationUuid = modelCustomizationUuid;
+ }
+
+ @Override
+ public String toString() {
+ return new ToStringBuilder(this).append("modelName", modelName).append("modelUuid", modelUuid)
+ .append("modelInvariantUuid", modelInvariantUuid).append("modelVersion", modelVersion)
+ .append("modelCustomizationUuid", modelCustomizationUuid).toString();
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/PostSoProcessor.java b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/PostSoProcessor.java
index 1b0d77f..e590afc 100644
--- a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/PostSoProcessor.java
+++ b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/PostSoProcessor.java
@@ -20,6 +20,8 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+
+import org.onap.nbi.apis.servicecatalog.ServiceSpecificationService;
import org.onap.nbi.apis.serviceorder.SoClient;
import org.onap.nbi.apis.serviceorder.model.ServiceCharacteristic;
import org.onap.nbi.apis.serviceorder.model.ServiceOrder;
@@ -27,6 +29,7 @@ import org.onap.nbi.apis.serviceorder.model.ServiceOrderItem;
import org.onap.nbi.apis.serviceorder.model.StateType;
import org.onap.nbi.apis.serviceorder.model.consumer.CloudConfiguration;
import org.onap.nbi.apis.serviceorder.model.consumer.CreateE2EServiceInstanceResponse;
+import org.onap.nbi.apis.serviceorder.model.consumer.CreateMacroServiceInstanceResponse;
import org.onap.nbi.apis.serviceorder.model.consumer.CreateServiceInstanceResponse;
import org.onap.nbi.apis.serviceorder.model.consumer.MSOE2EPayload;
import org.onap.nbi.apis.serviceorder.model.consumer.MSOPayload;
@@ -41,6 +44,7 @@ import org.onap.nbi.apis.serviceorder.model.consumer.ResourceModel;
import org.onap.nbi.apis.serviceorder.model.consumer.ServiceModel;
import org.onap.nbi.apis.serviceorder.model.consumer.SubscriberInfo;
import org.onap.nbi.apis.serviceorder.model.consumer.UserParams;
+import org.onap.nbi.apis.serviceorder.model.consumer.VFModelInfo;
import org.onap.nbi.apis.serviceorder.model.orchestrator.ServiceOrderInfo;
import org.onap.nbi.apis.serviceorder.service.ServiceOrderService;
import org.slf4j.Logger;
@@ -77,12 +81,24 @@ public class PostSoProcessor {
@Value("${onap.cloudOwner}")
private String cloudOwner;
+
+ @Value("${onap.k8sCloudOwner}")
+ private String k8sCloudOwner;
+
+ @Value("${onap.k8sCloudRegionId}")
+ private String k8sCloudRegionId;
+
+ @Value("${k8s-rb-profile-name}")
+ private String k8sRbProfileName;
@Autowired
private ServiceOrderService serviceOrderService;
@Autowired
private SoClient soClient;
+
+ @Autowired
+ ServiceSpecificationService serviceSpecificationService;
public ResponseEntity<CreateServiceInstanceResponse> postServiceOrderItem(ServiceOrderInfo serviceOrderInfo,
ServiceOrderItem serviceOrderItem) {
@@ -108,6 +124,19 @@ public class PostSoProcessor {
return response;
}
+ public ResponseEntity<CreateMacroServiceInstanceResponse> postMacroServiceOrderItem(ServiceOrderInfo serviceOrderInfo,
+ ServiceOrderItem serviceOrderItem) {
+ ResponseEntity<CreateMacroServiceInstanceResponse> response = null;
+ try {
+ // For Macro Flow
+ response = postSOMacroRequest(serviceOrderItem, serviceOrderInfo);
+ } catch (NullPointerException e) {
+ LOGGER.error("Unable to create service instance for serviceOrderItem.id=" + serviceOrderItem.getId(), e);
+ response = null;
+ }
+ return response;
+ }
+
private ResponseEntity<CreateServiceInstanceResponse> postSORequest(ServiceOrderItem serviceOrderItem,
ServiceOrderInfo serviceOrderInfo) {
RequestDetails requestDetails = buildSoRequest(serviceOrderItem, serviceOrderInfo);
@@ -164,6 +193,221 @@ public class PostSoProcessor {
}
return response;
}
+
+ private ResponseEntity<CreateMacroServiceInstanceResponse> postSOMacroRequest(ServiceOrderItem serviceOrderItem,
+ ServiceOrderInfo serviceOrderInfo) {
+
+ String serviceModuleName = (String) serviceOrderInfo.getServiceOrderItemInfos().get(serviceOrderItem.getId())
+ .getCatalogResponse().get("name");
+
+ RequestDetails requestDetails = buildSoMacroRequest(serviceOrderItem, serviceOrderInfo);
+ MSOPayload msoMacroPayload = new MSOPayload(requestDetails);
+ ResponseEntity<CreateMacroServiceInstanceResponse> response = null;
+
+ switch (serviceOrderItem.getAction()) {
+ case ADD:
+ response = soClient.callMacroCreateServiceInstance(msoMacroPayload);
+ break;
+ case DELETE:
+ // response = soClient.callDeleteServiceInstance(msoPayload,
+ // serviceOrderItem.getService().getId());
+ break;
+ case MODIFY:
+ if (StateType.INPROGRESS_MODIFY_ITEM_TO_CREATE == serviceOrderItem.getState()) {
+ // response = soClient.callCreateServiceInstance(msoPayload);
+ }
+ if (StateType.ACKNOWLEDGED == serviceOrderItem.getState()) {
+ // response = soClient.callDeleteServiceInstance(msoPayload,
+ // serviceOrderItem.getService().getId());
+ }
+ break;
+ default:
+ break;
+ }
+ return response;
+ }
+
+ /**
+ * Build SO MACRO CREATE request from the ServiceOrder and catalog informations from SDC
+ *
+ * @param orderItem
+ * @param serviceOrderInfo
+ * @param subscriberInfo
+ * @return
+ */
+ private RequestDetails buildSoMacroRequest(ServiceOrderItem orderItem, ServiceOrderInfo serviceOrderInfo) {
+
+ RequestDetails requestDetails = new RequestDetails();
+ Map<String, Object> sdcInfos = serviceOrderInfo.getServiceOrderItemInfos().get(orderItem.getId())
+ .getCatalogResponse();
+
+ String id = orderItem.getService().getServiceSpecification().getId();
+ Map responseChildRes = serviceSpecificationService.get(id);
+ ArrayList<Map<String, Object>> resourseSpecificationArray = (ArrayList<Map<String, Object>>) responseChildRes
+ .get("resourceSpecification");
+
+ Map<String, Object> resourseSpecificationMap = resourseSpecificationArray.get(0);
+
+ Map instanceSpecification = (Map) resourseSpecificationMap.get("InstanceSpecification");
+ ArrayList<VFModelInfo> childResourceSpecification = (ArrayList<VFModelInfo>) resourseSpecificationMap
+ .get("childResourceSpecification");
+
+ List<Object> serviceObject = new ArrayList<>();
+
+ ArrayList<Object> vnfInstanceParam = new ArrayList<>();
+
+ //Differentiating vnf with cnf(Can be discussed and improved)
+ if (instanceSpecification.get("public_net_id") != null) {
+ vnfInstanceParam.add(instanceSpecification);
+ } else {
+ Map<String, Object> instanceParam = new HashMap<>();
+ instanceParam.put("k8s-rb-profile-name", k8sRbProfileName);
+ vnfInstanceParam.add(instanceParam);
+ }
+
+ List resSpec = (ArrayList) sdcInfos.get("resourceSpecification");
+ Map resSpecMap = (Map) resSpec.get(0);
+
+ Map<String, String> vnfInfoObject = new HashMap<>();
+ vnfInfoObject.put("modelName", (String) resSpecMap.get("name"));
+ vnfInfoObject.put("modelVersionId", (String) resSpecMap.get("id"));
+ vnfInfoObject.put("modelInvariantUuid", (String) resSpecMap.get("resourceInvariantUUID"));
+ vnfInfoObject.put("modelVersion", (String) resSpecMap.get("version"));
+ vnfInfoObject.put("modelCustomizationId", (String) resSpecMap.get("modelCustomizationId"));
+ vnfInfoObject.put("modelInstanceName", (String) resSpecMap.get("resourceInstanceName"));
+
+ //initialization
+ CloudConfiguration cloudConfiguration = null;
+
+ //Differentiating vnf with cnf(Can be discussed and improved)
+ if (instanceSpecification.get("public_net_id") != null) {
+ cloudConfiguration = new CloudConfiguration(lcpCloudRegionId, tenantId, cloudOwner);
+ } else {
+ cloudConfiguration = new CloudConfiguration(k8sCloudRegionId, tenantId, k8sCloudOwner);
+ }
+
+ Map<String, String> platformName = new HashMap<>();
+ platformName.put("platformName", "test");
+
+ Map<String, String> lob = new HashMap<>();
+ lob.put("lineOfBusinessName", "LOB-Demonstration");
+
+ Map<String, Object> vnfModel = new HashMap<>();
+ vnfModel.put("modelInfo", vnfInfoObject);
+ vnfModel.put("cloudConfiguration", cloudConfiguration);
+ vnfModel.put("platform", platformName);
+ vnfModel.put("lineOfBusiness", lob);
+ vnfModel.put("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb");
+ vnfModel.put("instanceName", (String) resSpecMap.get("resourceInstanceName"));
+ vnfModel.put("instanceParams", vnfInstanceParam);
+
+ List<Object> vfModulesObjects = new ArrayList<>();
+ ArrayList<Map<String, Object>> vfInstanceParam = new ArrayList<>();
+
+ //Differentiate CNF from VNF
+ if (instanceSpecification.get("public_net_id") != null) {
+ vfInstanceParam.add(instanceSpecification);
+
+ } else {
+ Map<String, Object> instanceParam = new HashMap<>();
+ instanceParam.put("k8s-rb-profile-name", k8sRbProfileName);
+ vfInstanceParam.add(instanceParam);
+ }
+
+ for (VFModelInfo crsObject : childResourceSpecification) {
+ Map<String, Object> vfModuleObject = new HashMap<>();
+ Map<String, String> vfModuleInfo = new HashMap<>();
+
+ vfModuleInfo.put("modelName", crsObject.getModelName());
+ vfModuleInfo.put("modelVersionId", crsObject.getModelUuid());
+ vfModuleInfo.put("modelInvariantUuid", crsObject.getModelInvariantUuid());
+ vfModuleInfo.put("modelVersion", crsObject.getModelVersion());
+ vfModuleInfo.put("modelCustomizationId", crsObject.getModelCustomizationUuid());
+ vfModuleObject.put("modelInfo", vfModuleInfo);
+ vfModuleObject.put("instanceName", crsObject.getModelName());
+ vfModuleObject.put("instanceParams", vfInstanceParam);
+
+ vfModulesObjects.add(vfModuleObject);
+ }
+ vnfModel.put("vfModules", vfModulesObjects);
+
+ List<Object> vnfObjects = new ArrayList<>();
+ vnfObjects.add(vnfModel);
+
+ Map<String, Object> vnfData = new HashMap<>();
+ vnfData.put("vnfs", vnfObjects);
+
+ ModelInfo serviceModelInfo = new ModelInfo();
+ serviceModelInfo.setModelType("service");
+ serviceModelInfo.setModelInvariantId((String) sdcInfos.get("invariantUUID"));
+ serviceModelInfo.setModelVersionId(orderItem.getService().getServiceSpecification().getId());
+ serviceModelInfo.setModelName((String) sdcInfos.get("name"));
+ serviceModelInfo.setModelVersion((String) sdcInfos.get("version"));
+
+ // Adding List of instanceParams for service
+ // We can add instanceParams Key Value in Map Object and add it to the List, for
+ // For now it is empty to comply with so request
+
+ List<Map<String, String>> listOfServiceLevelInstanceParams = new ArrayList<>();
+ Map<String, String> serviceInstanceParams= new HashMap<>();
+ listOfServiceLevelInstanceParams.add(serviceInstanceParams);
+
+ Map<String, Object> serviceData = new HashMap<>();
+ serviceData.put("instanceParams", listOfServiceLevelInstanceParams);
+ serviceData.put("instanceName", orderItem.getService().getName());
+ serviceData.put("resources", vnfData);
+ serviceData.put("modelInfo", serviceModelInfo);
+
+ Map<String, String> homingObject = new HashMap<>();
+ homingObject.put("Homing_Solution", "none");
+ serviceObject.add(homingObject);
+
+ Map<String, Object> serviceObject1 = new HashMap<>();
+ serviceObject1.put("service", serviceData);
+ serviceObject.add(serviceObject1);
+ requestDetails.setSubscriberInfo(serviceOrderInfo.getSubscriberInfo());
+
+ ModelInfo modelInfo = new ModelInfo();
+ modelInfo.setModelType("service");
+ modelInfo.setModelInvariantId((String) sdcInfos.get("invariantUUID"));
+ modelInfo.setModelVersionId(orderItem.getService().getServiceSpecification().getId());
+ modelInfo.setModelName((String) sdcInfos.get("name"));
+ modelInfo.setModelVersion((String) sdcInfos.get("version"));
+ requestDetails.setModelInfo(modelInfo);
+
+ RequestInfo requestInfo = new RequestInfo();
+ requestInfo.setInstanceName(orderItem.getService().getName());
+ requestInfo.setSource("VID");
+ requestInfo.setSuppressRollback(false);
+ requestInfo.setRequestorId("NBI");
+ requestInfo.setProductFamilyId("a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb");
+ requestDetails.setRequestInfo(requestInfo);
+
+ // We are taking RequestParameters as map because it has UserParams which gives value as
+ // "name" : "service"
+ // "value" : "", which SO is not accepting
+ Map<String, Object> requestParameters = new HashMap<>();
+
+ // Get value from serviceOrder request or generate one
+ String serviceTypeFromJson = orderItem.getService().getServicetype();
+ requestParameters.put("subscriptionServiceType",
+ serviceTypeFromJson != null ? serviceTypeFromJson : (String) sdcInfos.get("name"));
+ requestParameters.put("userParams", serviceObject);
+ requestParameters.put("aLaCarte", false);
+ requestDetails.setRequestParameters(requestParameters);
+ requestDetails.setCloudConfiguration(cloudConfiguration);
+
+ OwningEntity owningEntity = new OwningEntity();
+ owningEntity.setOwningEntityId(soOwningEntityId);
+ owningEntity.setOwningEntityName(soOwningEntityName);
+ requestDetails.setOwningEntity(owningEntity);
+
+ Project project = new Project();
+ project.setProjectName(soProjectName);
+
+ requestDetails.setProject(project);
+ return requestDetails;
+ }
/**
* Build SO CREATE request from the ServiceOrder and catalog informations from SDC
@@ -262,7 +506,7 @@ public class PostSoProcessor {
if (!userParams.isEmpty()) {
Map<String, String> requestInputs = new HashMap<String, String>();
for (int i = 0; i < userParams.size(); i++) {
- requestInputs.put(userParams.get(i).getName(), userParams.get(i).getValue());
+ requestInputs.put(userParams.get(i).getName(), (String) userParams.get(i).getValue());
}
parameters.setRequestInputs(requestInputs);
@@ -320,4 +564,4 @@ public class PostSoProcessor {
return userParams;
}
-}
+} \ No newline at end of file
diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskProcessor.java b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskProcessor.java
index d63d122..fe0938d 100644
--- a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskProcessor.java
+++ b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskProcessor.java
@@ -24,6 +24,7 @@ import org.onap.nbi.apis.serviceorder.model.ServiceOrder;
import org.onap.nbi.apis.serviceorder.model.ServiceOrderItem;
import org.onap.nbi.apis.serviceorder.model.StateType;
import org.onap.nbi.apis.serviceorder.model.consumer.CreateE2EServiceInstanceResponse;
+import org.onap.nbi.apis.serviceorder.model.consumer.CreateMacroServiceInstanceResponse;
import org.onap.nbi.apis.serviceorder.model.consumer.CreateServiceInstanceResponse;
import org.onap.nbi.apis.serviceorder.model.orchestrator.ExecutionTask;
import org.onap.nbi.apis.serviceorder.model.orchestrator.ServiceOrderInfo;
@@ -92,8 +93,10 @@ public class SOTaskProcessor {
updateE2EServiceOrderItem(response, serviceOrderItem, serviceOrder);
} else if (macroService) {
LOGGER.info("Mode type macro");
- //TODO: Add logic to construct SO macro request body and call SO macro flow.(EXTAPI-368)
-
+ // call SO macro flow.(EXTAPI-368)
+ ResponseEntity<CreateMacroServiceInstanceResponse> response = postSoProcessor
+ .postMacroServiceOrderItem(serviceOrderInfo, serviceOrderItem);
+ updateMacroServiceOrderItem(response, serviceOrderItem, serviceOrder);
} else {
ResponseEntity<CreateServiceInstanceResponse> response =
@@ -216,6 +219,35 @@ public class SOTaskProcessor {
}
}
+ /**
+ * Update ServiceOrderItem with SO response by using serviceOrderRepository with the serviceOrderId
+ */
+ private void updateMacroServiceOrderItem(ResponseEntity<CreateMacroServiceInstanceResponse> response,
+ ServiceOrderItem orderItem, ServiceOrder serviceOrder) {
+
+ if (response == null || !response.getStatusCode().is2xxSuccessful()) {
+ LOGGER.warn("response ko for serviceOrderItem.id=" + orderItem.getId());
+ serviceOrderService.updateOrderItemState(serviceOrder, orderItem, StateType.FAILED);
+ buildOrderMessageIfNeeded(orderItem, serviceOrder, response);
+ } else {
+ CreateMacroServiceInstanceResponse createMacroServiceInstanceResponse = response.getBody();
+ if (createMacroServiceInstanceResponse != null && !orderItem.getState().equals(StateType.FAILED)) {
+ orderItem.getService().setId(createMacroServiceInstanceResponse.getRequestReferences().getInstanceId());
+ orderItem.setRequestId(createMacroServiceInstanceResponse.getRequestReferences().getRequestId());
+ }
+
+ if (!response.getStatusCode().is2xxSuccessful() || response.getBody() == null
+ || response.getBody().getRequestReferences() == null) {
+ serviceOrderService.updateOrderItemState(serviceOrder, orderItem, StateType.FAILED);
+ LOGGER
+ .warn("order item {} failed , status {} , response {}", orderItem.getId(), response.getStatusCode(),
+ response.getBody());
+ } else {
+ serviceOrderService.updateOrderItemState(serviceOrder, orderItem, StateType.INPROGRESS);
+ }
+ }
+ }
+
private void updateOrderItemToInProgress(ServiceOrder serviceOrder, ServiceOrderItem serviceOrderItem) {
if (serviceOrderItem.getAction() != ActionType.MODIFY) {
serviceOrderService.updateOrderItemState(serviceOrder, serviceOrderItem, StateType.INPROGRESS);
@@ -341,4 +373,4 @@ public class SOTaskProcessor {
LOGGER.debug("Difference {} and Polling Duration {}", differenceInMillis, pollingDurationInMins);
return (differenceInMillis > pollingDurationInMillis);
}
-}
+} \ No newline at end of file
diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties
index 1a73f16..ac3efec 100644
--- a/src/main/resources/application-test.properties
+++ b/src/main/resources/application-test.properties
@@ -30,12 +30,17 @@ onap.lcpCloudRegionId = RegionOne
onap.tenantId = 31047205ce114b60833b23e400d6a535
onap.cloudOwner = CloudOwner
+# k8s
+onap.k8sCloudRegionId = k8sregionfour
+onap.k8sCloudOwner = k8scloudowner4
+k8s-rb-profile-name = default
+
# NBI
nbi.url = http://localhost:${server.port}${server.servlet.context-path}
nbi.callForVNF = false
# SCHEDULER
-scheduler.pollingDurationInMins = 0.1
+scheduler.pollingDurationInMins = 0.2
serviceOrder.schedule = 5000
serviceOrder.initial = 1
executionTask.schedule = 2000
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index e719c6f..b010f50 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -40,6 +40,11 @@ onap.lcpCloudRegionId = RegionOne
onap.tenantId = 6e97a2bd51d74f6db5671d8dc1517d82
onap.cloudOwner = CloudOwner
+# k8s
+onap.k8sCloudRegionId = k8sregionfour
+onap.k8sCloudOwner = k8scloudowner4
+k8s-rb-profile-name = default
+
# NBI
nbi.url = https://localhost:${server.port}${server.servlet.context-path}
nbi.public.url = https://${server.public.ip}:${server.port}${server.servlet.context-path}