From 3f4981493008ccf8eeb23f2aac5c2fcf40a0be49 Mon Sep 17 00:00:00 2001 From: "Kalkere Ramesh, Sharan (sk720x)" Date: Wed, 26 Aug 2020 04:36:07 -0400 Subject: Bpmn to cnf adapter implementation BPMN changes related to CNF Adapter Change-Id: I4c984b9508076381bb7b3d159955fb6bf724eca8 Issue-ID: SO-3199 Signed-off-by: Kalkere Ramesh, Sharan --- .../generalobjects/RequestContext.java | 10 + .../servicedecomposition/tasks/BBInputSetup.java | 15 +- .../tasks/BBInputSetupParameter.java | 21 ++ .../GeneralBuildingBlockCMExpected.json | 3 +- .../GeneralBuildingBlockExpected.json | 3 +- ...eneralBuildingBlockExpectedWUserParamsInfo.json | 3 +- .../GeneralBuildingBlockInstanceGroupExpected.json | 3 +- .../GeneralBuildingBlockWithVnf.json | 3 +- .../subprocess/BuildingBlock/CreateVfModuleBB.bpmn | 216 +++++++++++++-------- .../adapter/cnf/tasks/CnfAdapterCreateTasks.java | 121 ++++++++++++ .../so/client/adapter/cnf/CnfAdapterClient.java | 97 +++++++++ .../adapter/cnf/CnfAdapterClientException.java | 34 ++++ .../onap/so/client/adapter/cnf/entities/GVK.java | 49 +++++ .../adapter/cnf/entities/InstanceRequest.java | 95 +++++++++ .../adapter/cnf/entities/InstanceResponse.java | 62 ++++++ .../so/client/adapter/cnf/entities/Labels.java | 25 +++ .../so/client/adapter/cnf/entities/Resource.java | 37 ++++ .../so/client/adapter/vnf/mapper/Attributes.java | 23 +++ .../vnf/mapper/VnfAdapterVfModuleObjectMapper.java | 2 +- 19 files changed, 731 insertions(+), 91 deletions(-) create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfAdapterCreateTasks.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClient.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClientException.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/GVK.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/InstanceRequest.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/InstanceResponse.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/Labels.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/Resource.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/Attributes.java diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/generalobjects/RequestContext.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/generalobjects/RequestContext.java index 0193469d93..12abec0b77 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/generalobjects/RequestContext.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/generalobjects/RequestContext.java @@ -57,6 +57,16 @@ public class RequestContext implements Serializable { private List> configurationParameters = new ArrayList<>(); @JsonProperty("application-id") private String applicationId; + @JsonProperty("is-helm") + private Boolean isHelm; + + public Boolean getIsHelm() { + return isHelm; + } + + public void setIsHelm(Boolean isHelm) { + this.isHelm = isHelm; + } public String getServiceURI() { return serviceURI; diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java index 009686d0fc..989bba0a6e 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java @@ -193,6 +193,12 @@ public class BBInputSetup implements JavaDelegate { execution.setVariable(GBB_INPUT_VAR_NAME, outputBB); execution.setVariable(LOOKUP_KEY_MAP_VAR_NAME, lookupKeyMap); + if (outputBB.getRequestContext().getIsHelm()) { + execution.setVariable("isHelm", true); + } else { + execution.setVariable("isHelm", false); + } + BuildingBlockExecution gBuildingBlockExecution = new DelegateExecutionImpl(execution); execution.setVariable("gBuildingBlockExecution", gBuildingBlockExecution); execution.setVariable("RetryCount", 1); @@ -431,7 +437,8 @@ public class BBInputSetup implements JavaDelegate { protected void mapCatalogInstanceGroup(InstanceGroup instanceGroup, ModelInfo modelInfo, Service service) { // @TODO: this will populate the instanceGroup model info. - // Dependent on MSO-5821 653458 US - MSO - Enhance Catalog DB Schema & Adapter to support VNF Groups + // Dependent on MSO-5821 653458 US - MSO - Enhance Catalog DB Schema & Adapter + // to support VNF Groups } protected void populateConfiguration(BBInputSetupParameter parameter) { @@ -613,6 +620,10 @@ public class BBInputSetup implements JavaDelegate { parameter.getServiceModel().getCurrentService(), vnfModelCustomizationUUID); } } + if (vfModule.getModelInfoVfModule() != null && vfModule.getModelInfoVfModule().getModelName() != null + && vfModule.getModelInfoVfModule().getModelName().contains("helm")) { + parameter.setIsHelm(true); + } } else { logger.debug("Related VNF instance Id not found: {}", parameter.getLookupKeyMap().get(ResourceKey.GENERIC_VNF_ID)); @@ -1018,7 +1029,6 @@ public class BBInputSetup implements JavaDelegate { if (requestDetails.getOwningEntity() != null) owningEntity = mapperLayer.mapRequestOwningEntity(requestDetails.getOwningEntity()); - Service service = bbInputSetupUtils.getCatalogServiceByModelUUID(requestDetails.getModelInfo().getModelVersionId()); if (service == null) { @@ -1094,6 +1104,7 @@ public class BBInputSetup implements JavaDelegate { RequestContext requestContext = mapperLayer.mapRequestContext(parameter.getRequestDetails()); requestContext.setAction(parameter.getRequestAction()); requestContext.setMsoRequestId(parameter.getExecuteBB().getRequestId()); + requestContext.setIsHelm(parameter.getIsHelm()); org.onap.aai.domain.yang.CloudRegion aaiCloudRegion = bbInputSetupUtils.getCloudRegion(parameter.getRequestDetails().getCloudConfiguration()); CloudRegion cloudRegion = diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupParameter.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupParameter.java index 36ac0969ee..1290f2aeef 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupParameter.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupParameter.java @@ -45,6 +45,7 @@ public class BBInputSetupParameter { private String applicationId; private boolean isReplace; private ServiceModel serviceModel; + private boolean isHelm; private BBInputSetupParameter(Builder builder) { this.cloudConfiguration = builder.cloudConfiguration; @@ -74,6 +75,7 @@ public class BBInputSetupParameter { this.applicationId = builder.applicationId; this.isReplace = builder.isReplace; this.serviceModel = builder.serviceModel; + this.isHelm = builder.isHelm; } @@ -331,6 +333,15 @@ public class BBInputSetupParameter { this.serviceModel = serviceModel; } + protected boolean getIsHelm() { + return isHelm; + } + + + protected void setIsHelm(boolean isHelm) { + this.isHelm = isHelm; + } + public static class Builder { private CloudConfiguration cloudConfiguration; private ConfigurationResourceKeys configurationResourceKeys; @@ -359,6 +370,7 @@ public class BBInputSetupParameter { private String applicationId; private boolean isReplace; private ServiceModel serviceModel; + private boolean isHelm; public Builder setCloudConfiguration(CloudConfiguration cloudConfiguration) { this.cloudConfiguration = cloudConfiguration; @@ -495,6 +507,15 @@ public class BBInputSetupParameter { return this; } + protected boolean getIsHelm() { + return isHelm; + } + + + protected void setIsHelm(boolean isHelm) { + this.isHelm = isHelm; + } + public BBInputSetupParameter build() { return new BBInputSetupParameter(this); } diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockCMExpected.json b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockCMExpected.json index fe33308d78..7662b995e4 100644 --- a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockCMExpected.json +++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockCMExpected.json @@ -8,7 +8,8 @@ "userParams": [], "aLaCarte": true }, - "configurationParameters": [] + "configurationParameters": [], + "is-helm": false }, "orchContext": { "is-rollback-enabled": false diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockExpected.json b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockExpected.json index b18cad0620..2f26913ffc 100644 --- a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockExpected.json +++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockExpected.json @@ -33,7 +33,8 @@ "availability-zone":"$.vnf-topology.vnf-resource-assignments.availability-zones.availability-zone[0]", "xtz-123":"$.vnf-topology.vnf-resource-assignments.availability-zones.availability-zone[0]" } - ] + ], + "is-helm": false }, "orchContext": { "is-rollback-enabled": false diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockExpectedWUserParamsInfo.json b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockExpectedWUserParamsInfo.json index f07f060b06..0137d42009 100644 --- a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockExpectedWUserParamsInfo.json +++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockExpectedWUserParamsInfo.json @@ -43,7 +43,8 @@ "availability-zone":"$.vnf-topology.vnf-resource-assignments.availability-zones.availability-zone[0]", "xtz-123":"$.vnf-topology.vnf-resource-assignments.availability-zones.availability-zone[0]" } - ] + ], + "is-helm": false }, "orchContext": { "is-rollback-enabled": false diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockInstanceGroupExpected.json b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockInstanceGroupExpected.json index f55717fc91..d8294c0a17 100644 --- a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockInstanceGroupExpected.json +++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockInstanceGroupExpected.json @@ -14,7 +14,8 @@ "requestParameters": { }, - "configurationParameters": [] + "configurationParameters": [], + "is-helm": false }, "orchContext": { "is-rollback-enabled": true diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockWithVnf.json b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockWithVnf.json index ca2b76e4bf..e7fa4debeb 100644 --- a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockWithVnf.json +++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/GeneralBuildingBlockWithVnf.json @@ -33,7 +33,8 @@ "availability-zone":"$.vnf-topology.vnf-resource-assignments.availability-zones.availability-zone[0]", "xtz-123":"$.vnf-topology.vnf-resource-assignments.availability-zones.availability-zone[0]" } - ] + ], + "is-helm": false }, "orchContext": { "is-rollback-enabled": false diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CreateVfModuleBB.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CreateVfModuleBB.bpmn index 61c870b956..7638f34a59 100644 --- a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CreateVfModuleBB.bpmn +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CreateVfModuleBB.bpmn @@ -1,29 +1,26 @@ - + SequenceFlow_1xr6chl SequenceFlow_1s4rpyp - SequenceFlow_15hn8si + SequenceFlow_1ig2ix4 SequenceFlow_1vbwdaw - SequenceFlow_15hn8si - SequenceFlow_16g4dz0 + NoHelm + SequenceFlow_0dehck5 - SequenceFlow_1xr6chl SequenceFlow_1s4rpyp - - @@ -35,8 +32,8 @@ - SequenceFlow_16g4dz0 - SequenceFlow_0ecr393 + SequenceFlow_0dehck5 + SequenceFlow_0uetprw SequenceFlow_0rds4rj @@ -80,7 +77,8 @@ - SequenceFlow_0ecr393 + SequenceFlow_1mg8eym + SequenceFlow_0uetprw SequenceFlow_1io8r33 @@ -89,6 +87,23 @@ SequenceFlow_1yn8o6d + + SequenceFlow_1ig2ix4 + YesHelm + NoHelm + + + YesHelm + SequenceFlow_1mg8eym + + + + + + + + + @@ -102,31 +117,24 @@ - - + + - + - + - + - - - - - - - - - + + @@ -134,124 +142,166 @@ - - - - - - - - - - - - - - - - - + - + - + - + - + - + - + - + - - + + - + - - + + - + - - - - + + + + - + - + - - + + - + - + - - + + - + - + - - + + - + - + - - + + - + - + - - + + + + + - + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfAdapterCreateTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfAdapterCreateTasks.java new file mode 100644 index 0000000000..93d30512b6 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfAdapterCreateTasks.java @@ -0,0 +1,121 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.adapter.cnf.tasks; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; +import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.adapter.cnf.CnfAdapterClient; +import org.onap.so.client.adapter.cnf.entities.InstanceRequest; +import org.onap.so.client.adapter.cnf.entities.InstanceResponse; +import org.onap.so.client.adapter.vnf.mapper.AttributeNameValue; +import org.onap.so.client.adapter.vnf.mapper.Attributes; +import org.onap.so.client.adapter.vnf.mapper.VnfAdapterVfModuleObjectMapper; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.openstack.utils.MsoMulticloudUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +@Component +public class CnfAdapterCreateTasks { + private static final Logger logger = LoggerFactory.getLogger(CnfAdapterCreateTasks.class); + public static final String SDNCQUERY_RESPONSE = "SDNCQueryResponse_"; + + @Autowired + private ExtractPojosForBB extractPojosForBB; + @Autowired + private ExceptionBuilder exceptionUtil; + @Autowired + private CnfAdapterClient cnfAdapterClient; + @Autowired + private VnfAdapterVfModuleObjectMapper vfModuleMapper; + + private ObjectMapper mapper = new ObjectMapper(); + + /** + * This method is used for creating the request for an Instance in Multicloud K8s Plugin. + * + * @param execution + * @return + */ + public void createInstance(BuildingBlockExecution execution) { + try { + GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock(); + ServiceInstance serviceInstance = + gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0); + GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); + VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID); + RequestContext requestContext = gBBInput.getRequestContext(); + CloudRegion cloudRegion = gBBInput.getCloudRegion(); + String sdncVfModuleQueryResponse = execution.getVariable(SDNCQUERY_RESPONSE + vfModule.getVfModuleId()); + String sdncVnfQueryResponse = execution.getVariable(SDNCQUERY_RESPONSE + genericVnf.getVnfId()); + Map paramsMap = vfModuleMapper.buildVfModuleParamsMap(requestContext, serviceInstance, + genericVnf, vfModule, sdncVnfQueryResponse, sdncVfModuleQueryResponse); + Map sdncDirectives = getSdncDirectives(paramsMap); + InstanceRequest createInstanceRequest = createInstanceRequest(vfModule, cloudRegion, sdncDirectives); + InstanceResponse response = cnfAdapterClient.createVfModule(createInstanceRequest); + execution.setVariable("heatStackId", response.getId()); + } catch (Exception ex) { + logger.error("Exception occurred", ex); + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + } + + protected Map getSdncDirectives(Map paramsMap) + throws JsonParseException, JsonMappingException, IOException { + Map sdncDirectivesMap = new HashMap<>(); + String sdncDirectivesString = (String) paramsMap.get(MsoMulticloudUtils.SDNC_DIRECTIVES); + Attributes sdncDirectives = mapper.readValue(sdncDirectivesString, Attributes.class); + for (AttributeNameValue nameVal : sdncDirectives.getAttributes()) { + sdncDirectivesMap.put(nameVal.getAttributeName(), (String) nameVal.getAttributeValue()); + } + return sdncDirectivesMap; + } + + protected InstanceRequest createInstanceRequest(VfModule vfModule, CloudRegion cloudRegion, + Map sdncDirectives) { + InstanceRequest request = new InstanceRequest(); + request.setRbName(vfModule.getModelInfoVfModule().getModelInvariantUUID()); + request.setRbVersion(vfModule.getModelInfoVfModule().getModelUUID()); + request.setCloudRegion(cloudRegion.getLcpCloudRegionId()); + request.setReleaseName(vfModule.getVfModuleId()); + request.setProfileName(sdncDirectives.get("k8s-rb-profile-name")); + request.setOverrideValues(sdncDirectives); + return request; + } + +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClient.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClient.java new file mode 100644 index 0000000000..f44c15ac54 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClient.java @@ -0,0 +1,97 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.adapter.cnf; + +import java.util.ArrayList; +import java.util.List; +import javax.persistence.EntityNotFoundException; +import javax.ws.rs.core.UriBuilder; +import org.apache.http.HttpStatus; +import org.onap.so.client.adapter.cnf.entities.InstanceRequest; +import org.onap.so.client.adapter.cnf.entities.InstanceResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.retry.annotation.Backoff; +import org.springframework.retry.annotation.Retryable; +import org.springframework.stereotype.Component; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.HttpServerErrorException; +import org.springframework.web.client.RestTemplate; + +@Component +public class CnfAdapterClient { + + private static final Logger logger = LoggerFactory.getLogger(CnfAdapterClient.class); + + @Autowired + private RestTemplate restTemplate; + + @Autowired + private Environment env; + + private static final String INSTANCE_CREATE_PATH = "/api/multicloud-k8s/v1/v1/instance"; + + @Retryable(value = {HttpServerErrorException.class}, maxAttempts = 3, backoff = @Backoff(delay = 3000)) + public InstanceResponse createVfModule(InstanceRequest request) throws CnfAdapterClientException { + try { + // String uri = env.getRequiredProperty("mso.cnf.adapter.endpoint"); //TODO: This needs to be added as well + // for configuration + String uri = "https://localhost:32780"; // TODO: What is the correct uri? + String endpoint = UriBuilder.fromUri(uri).path(INSTANCE_CREATE_PATH).build().toString(); + HttpEntity entity = getHttpEntity(request); + ResponseEntity result = + restTemplate.exchange(endpoint, HttpMethod.POST, entity, InstanceResponse.class); + return result.getBody(); + } catch (HttpClientErrorException e) { + logger.error("Error Calling CNF Adapter, e"); + if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { + throw new EntityNotFoundException(e.getResponseBodyAsString()); + } + throw e; + } + } + + protected HttpHeaders getHttpHeaders() { + HttpHeaders headers = new HttpHeaders(); + List acceptableMediaTypes = new ArrayList<>(); + acceptableMediaTypes.add(org.springframework.http.MediaType.APPLICATION_JSON); + headers.setAccept(acceptableMediaTypes); + /* + * try { String userCredentials = CryptoUtils.decrypt(env.getRequiredProperty("mso.cnf.adapter.auth"), + * env.getRequiredProperty("mso.msoKey")); if (userCredentials != null) { headers.add(HttpHeaders.AUTHORIZATION, + * "Basic " + DatatypeConverter.printBase64Binary(userCredentials.getBytes())); } } catch + * (GeneralSecurityException e) { logger.error("Security exception", e); } + */ + return headers; + } + + protected HttpEntity getHttpEntity(InstanceRequest request) { + HttpHeaders headers = getHttpHeaders(); + return new HttpEntity<>(request, headers); + } + +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClientException.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClientException.java new file mode 100644 index 0000000000..d716070ffa --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClientException.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.client.adapter.cnf; + +public class CnfAdapterClientException extends Exception { + + /** + * + */ + private static final long serialVersionUID = -7154784472485852602L; + + public CnfAdapterClientException(String message) { + super(message); + } + +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/GVK.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/GVK.java new file mode 100644 index 0000000000..3ed6894fcf --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/GVK.java @@ -0,0 +1,49 @@ + +package org.onap.so.client.adapter.cnf.entities; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({"Group", "Version", "Kind"}) +public class GVK { + + @JsonProperty("Group") + private String group; + @JsonProperty("Version") + private String version; + @JsonProperty("Kind") + private String kind; + + @JsonProperty("Group") + public String getGroup() { + return group; + } + + @JsonProperty("Group") + public void setGroup(String group) { + this.group = group; + } + + @JsonProperty("Version") + public String getVersion() { + return version; + } + + @JsonProperty("Version") + public void setVersion(String version) { + this.version = version; + } + + @JsonProperty("Kind") + public String getKind() { + return kind; + } + + @JsonProperty("Kind") + public void setKind(String kind) { + this.kind = kind; + } + +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/InstanceRequest.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/InstanceRequest.java new file mode 100644 index 0000000000..e4058097ab --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/InstanceRequest.java @@ -0,0 +1,95 @@ + +package org.onap.so.client.adapter.cnf.entities; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({"rb-name", "rb-version", "profile-name", "release-name", "cloud-region", "labels", + "override-values"}) +public class InstanceRequest { + + @JsonProperty("rb-name") + private String rbName; + @JsonProperty("rb-version") + private String rbVersion; + @JsonProperty("profile-name") + private String profileName; + @JsonProperty("release-name") + private String releaseName; + @JsonProperty("cloud-region") + private String cloudRegion; + @JsonProperty("labels") + private Labels labels; + @JsonProperty(value = "override-values") + private Map overrideValues; + + @JsonProperty("rb-name") + public String getRbName() { + return rbName; + } + + @JsonProperty("rb-name") + public void setRbName(String rbName) { + this.rbName = rbName; + } + + @JsonProperty("rb-version") + public String getRbVersion() { + return rbVersion; + } + + @JsonProperty("rb-version") + public void setRbVersion(String rbVersion) { + this.rbVersion = rbVersion; + } + + @JsonProperty("profile-name") + public String getProfileName() { + return profileName; + } + + @JsonProperty("profile-name") + public void setProfileName(String profileName) { + this.profileName = profileName; + } + + @JsonProperty("cloud-region") + public String getCloudRegion() { + return cloudRegion; + } + + @JsonProperty("cloud-region") + public void setCloudRegion(String cloudRegion) { + this.cloudRegion = cloudRegion; + } + + @JsonProperty("labels") + public Labels getLabels() { + return labels; + } + + @JsonProperty("labels") + public void setLabels(Labels labels) { + this.labels = labels; + } + + public String getReleaseName() { + return releaseName; + } + + public void setReleaseName(String releaseName) { + this.releaseName = releaseName; + } + + public Map getOverrideValues() { + return overrideValues; + } + + public void setOverrideValues(Map overrideValues) { + this.overrideValues = overrideValues; + } + +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/InstanceResponse.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/InstanceResponse.java new file mode 100644 index 0000000000..e38bcc2664 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/InstanceResponse.java @@ -0,0 +1,62 @@ + +package org.onap.so.client.adapter.cnf.entities; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({"id", "request", "namespace", "resources"}) +public class InstanceResponse { + + @JsonProperty("id") + private String id; + @JsonProperty("request") + private InstanceRequest request; + @JsonProperty("namespace") + private String namespace; + @JsonProperty("resources") + private List resources = null; + + @JsonProperty("id") + public String getId() { + return id; + } + + @JsonProperty("id") + public void setId(String id) { + this.id = id; + } + + @JsonProperty("request") + public InstanceRequest getRequest() { + return request; + } + + @JsonProperty("request") + public void setRequest(InstanceRequest request) { + this.request = request; + } + + @JsonProperty("namespace") + public String getNamespace() { + return namespace; + } + + @JsonProperty("namespace") + public void setNamespace(String namespace) { + this.namespace = namespace; + } + + @JsonProperty("resources") + public List getResources() { + return resources; + } + + @JsonProperty("resources") + public void setResources(List resources) { + this.resources = resources; + } + +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/Labels.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/Labels.java new file mode 100644 index 0000000000..1df2e59459 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/Labels.java @@ -0,0 +1,25 @@ + +package org.onap.so.client.adapter.cnf.entities; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({"testCaseName"}) +public class Labels { + + @JsonProperty("testCaseName") + private String testCaseName; + + @JsonProperty("testCaseName") + public String getTestCaseName() { + return testCaseName; + } + + @JsonProperty("testCaseName") + public void setTestCaseName(String testCaseName) { + this.testCaseName = testCaseName; + } + +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/Resource.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/Resource.java new file mode 100644 index 0000000000..bde495aaa2 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/entities/Resource.java @@ -0,0 +1,37 @@ + +package org.onap.so.client.adapter.cnf.entities; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({"GVK", "Name"}) +public class Resource { + + @JsonProperty("GVK") + private GVK gVK; + @JsonProperty("Name") + private String name; + + @JsonProperty("GVK") + public GVK getGVK() { + return gVK; + } + + @JsonProperty("GVK") + public void setGVK(GVK gVK) { + this.gVK = gVK; + } + + @JsonProperty("Name") + public String getName() { + return name; + } + + @JsonProperty("Name") + public void setName(String name) { + this.name = name; + } + +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/Attributes.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/Attributes.java new file mode 100644 index 0000000000..6d79c20616 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/Attributes.java @@ -0,0 +1,23 @@ +package org.onap.so.client.adapter.vnf.mapper; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class Attributes implements Serializable { + + private static final long serialVersionUID = -5782985934617532582L; + + @JsonProperty("attributes") + private List attributes = new ArrayList<>(); + + public List getAttributes() { + return attributes; + } + + public void setAttributes(List attributes) { + this.attributes = attributes; + } + +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapper.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapper.java index bc618e17de..59da22f8e1 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapper.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/mapper/VnfAdapterVfModuleObjectMapper.java @@ -178,7 +178,7 @@ public class VnfAdapterVfModuleObjectMapper { return msoRequest; } - private Map buildVfModuleParamsMap(RequestContext requestContext, ServiceInstance serviceInstance, + public Map buildVfModuleParamsMap(RequestContext requestContext, ServiceInstance serviceInstance, GenericVnf genericVnf, VfModule vfModule, String sdncVnfQueryResponse, String sdncVfModuleQueryResponse) throws IOException, MissingValueTagException { -- cgit 1.2.3-korg