diff options
Diffstat (limited to 'bpmn/MSOCommonBPMN/src/main')
12 files changed, 1026 insertions, 63 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/AbstractCDSProcessingBBUtils.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/AbstractCDSProcessingBBUtils.java index 424a4f3ecc..ebced8e933 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/AbstractCDSProcessingBBUtils.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/AbstractCDSProcessingBBUtils.java @@ -22,14 +22,18 @@ package org.onap.so.client.cds; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; +import com.google.protobuf.InvalidProtocolBufferException; +import com.google.protobuf.Struct; +import com.google.protobuf.Struct.Builder; +import com.google.protobuf.util.JsonFormat; +import io.grpc.Status; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers; import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader; import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType; import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput; import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput; +import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.client.PreconditionFailedException; import org.onap.so.client.RestPropertiesLoader; import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean; @@ -39,15 +43,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import com.google.protobuf.InvalidProtocolBufferException; -import com.google.protobuf.Struct; -import com.google.protobuf.Struct.Builder; -import com.google.protobuf.util.JsonFormat; -import io.grpc.Status; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; /** * Util class to support Call to CDS client - * */ @Component public class AbstractCDSProcessingBBUtils { @@ -60,11 +60,7 @@ public class AbstractCDSProcessingBBUtils { private static final String RESPONSE_PAYLOAD = "CDSResponsePayload"; private static final String CDS_STATUS = "CDSStatus"; private static final String EXEC_INPUT = "executionServiceInput"; - - - /** - * indicate exception thrown. - */ + private static final String EXECUTION_OBJECT = "executionObject"; private static final String EXCEPTION = "Exception"; @Autowired @@ -76,34 +72,33 @@ public class AbstractCDSProcessingBBUtils { * @param execution DelegateExecution object */ public void constructExecutionServiceInputObject(DelegateExecution execution) { - logger.trace("Start AbstractCDSProcessingBBUtils.preProcessRequest "); + logger.trace("Start AbstractCDSProcessingBBUtils.preProcessRequest for DelegateExecution object."); try { AbstractCDSPropertiesBean executionObject = - (AbstractCDSPropertiesBean) execution.getVariable("executionObject"); - - String payload = executionObject.getRequestObject(); - - CommonHeader commonHeader = CommonHeader.newBuilder().setOriginatorId(executionObject.getOriginatorId()) - .setRequestId(executionObject.getRequestId()).setSubRequestId(executionObject.getSubRequestId()) - .build(); - ActionIdentifiers actionIdentifiers = - ActionIdentifiers.newBuilder().setBlueprintName(executionObject.getBlueprintName()) - .setBlueprintVersion(executionObject.getBlueprintVersion()) - .setActionName(executionObject.getActionName()).setMode(executionObject.getMode()).build(); - - Builder struct = Struct.newBuilder(); - try { - JsonFormat.parser().merge(payload, struct); - } catch (InvalidProtocolBufferException e) { - logger.error("Failed to parse received message. blueprint({}:{}) for action({}). {}", - executionObject.getBlueprintVersion(), executionObject.getBlueprintName(), - executionObject.getActionName(), e); - } + (AbstractCDSPropertiesBean) execution.getVariable(EXECUTION_OBJECT); + + ExecutionServiceInput executionServiceInput = prepareExecutionServiceInput(executionObject); + + execution.setVariable(EXEC_INPUT, executionServiceInput); + + } catch (Exception ex) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + } - ExecutionServiceInput executionServiceInput = - ExecutionServiceInput.newBuilder().setCommonHeader(commonHeader) - .setActionIdentifiers(actionIdentifiers).setPayload(struct.build()).build(); + /** + * Extracting data from execution object and building the ExecutionServiceInput Object + * + * @param execution BuildingBlockExecution object + */ + public void constructExecutionServiceInputObject(BuildingBlockExecution execution) { + logger.trace("Start AbstractCDSProcessingBBUtils.preProcessRequest for BuildingBlockExecution object."); + + try { + AbstractCDSPropertiesBean executionObject = execution.getVariable(EXECUTION_OBJECT); + + ExecutionServiceInput executionServiceInput = prepareExecutionServiceInput(executionObject); execution.setVariable(EXEC_INPUT, executionServiceInput); @@ -119,50 +114,98 @@ public class AbstractCDSProcessingBBUtils { */ public void sendRequestToCDSClient(DelegateExecution execution) { - logger.trace("Start AbstractCDSProcessingBBUtils.sendRequestToCDSClient "); + logger.trace("Start AbstractCDSProcessingBBUtils.sendRequestToCDSClient for DelegateExecution object."); try { - CDSProperties props = RestPropertiesLoader.getInstance().getNewImpl(CDSProperties.class); - if (props == null) { - throw new PreconditionFailedException( - "No RestProperty.CDSProperties implementation found on classpath, can't create client."); - } - ExecutionServiceInput executionServiceInput = (ExecutionServiceInput) execution.getVariable(EXEC_INPUT); + CDSResponse cdsResponse = getCdsResponse(executionServiceInput); + execution.setVariable(CDS_STATUS, cdsResponse.status); - CDSResponse cdsResponse = new CDSResponse(); - - try (CDSProcessingClient cdsClient = new CDSProcessingClient(new ResponseHandler(cdsResponse))) { - CountDownLatch countDownLatch = cdsClient.sendRequest(executionServiceInput); - countDownLatch.await(props.getTimeout(), TimeUnit.SECONDS); - } catch (InterruptedException ex) { - logger.error("Caught exception in sendRequestToCDSClient in AbstractCDSProcessingBBUtils : ", ex); - Thread.currentThread().interrupt(); + if (cdsResponse.payload != null) { + String payload = JsonFormat.printer().print(cdsResponse.payload); + execution.setVariable(RESPONSE_PAYLOAD, payload); } - String cdsResponseStatus = cdsResponse.status; + } catch (Exception ex) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + } - /** - * throw CDS failed exception. - */ - if (!cdsResponseStatus.equals(SUCCESS)) { - throw new BadResponseException("CDS call failed with status: " + cdsResponse.status - + " and errorMessage: " + cdsResponse.errorMessage); - } + /** + * get the executionServiceInput object from execution and send a request to CDS Client and wait for TIMEOUT period + * + * @param execution BuildingBlockExecution object + */ + public void sendRequestToCDSClient(BuildingBlockExecution execution) { - execution.setVariable(CDS_STATUS, cdsResponseStatus); + logger.trace("Start AbstractCDSProcessingBBUtils.sendRequestToCDSClient for BuildingBlockExecution object."); + try { + ExecutionServiceInput executionServiceInput = execution.getVariable(EXEC_INPUT); + CDSResponse cdsResponse = getCdsResponse(executionServiceInput); + execution.setVariable(CDS_STATUS, cdsResponse.status); if (cdsResponse.payload != null) { String payload = JsonFormat.printer().print(cdsResponse.payload); execution.setVariable(RESPONSE_PAYLOAD, payload); } - - } catch (Exception ex) { exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); } } + private CDSResponse getCdsResponse(ExecutionServiceInput executionServiceInput) throws BadResponseException { + CDSProperties props = RestPropertiesLoader.getInstance().getNewImpl(CDSProperties.class); + if (props == null) { + throw new PreconditionFailedException( + "No RestProperty.CDSProperties implementation found on classpath, can't create client."); + } + + CDSResponse cdsResponse = new CDSResponse(); + + try (CDSProcessingClient cdsClient = new CDSProcessingClient(new ResponseHandler(cdsResponse))) { + CountDownLatch countDownLatch = cdsClient.sendRequest(executionServiceInput); + countDownLatch.await(props.getTimeout(), TimeUnit.SECONDS); + } catch (InterruptedException ex) { + logger.error("Caught exception in sendRequestToCDSClient in AbstractCDSProcessingBBUtils : ", ex); + Thread.currentThread().interrupt(); + } + + String cdsResponseStatus = cdsResponse.status; + + /** + * throw CDS failed exception. + */ + if (!cdsResponseStatus.equals(SUCCESS)) { + throw new BadResponseException("CDS call failed with status: " + cdsResponse.status + " and errorMessage: " + + cdsResponse.errorMessage); + } + return cdsResponse; + } + + private ExecutionServiceInput prepareExecutionServiceInput(AbstractCDSPropertiesBean executionObject) { + String payload = executionObject.getRequestObject(); + + CommonHeader commonHeader = CommonHeader.newBuilder().setOriginatorId(executionObject.getOriginatorId()) + .setRequestId(executionObject.getRequestId()).setSubRequestId(executionObject.getSubRequestId()) + .build(); + ActionIdentifiers actionIdentifiers = + ActionIdentifiers.newBuilder().setBlueprintName(executionObject.getBlueprintName()) + .setBlueprintVersion(executionObject.getBlueprintVersion()) + .setActionName(executionObject.getActionName()).setMode(executionObject.getMode()).build(); + + Builder struct = Struct.newBuilder(); + try { + JsonFormat.parser().merge(payload, struct); + } catch (InvalidProtocolBufferException e) { + logger.error("Failed to parse received message. blueprint({}:{}) for action({}). {}", + executionObject.getBlueprintVersion(), executionObject.getBlueprintName(), + executionObject.getActionName(), e); + } + + return ExecutionServiceInput.newBuilder().setCommonHeader(commonHeader).setActionIdentifiers(actionIdentifiers) + .setPayload(struct.build()).build(); + } + private class ResponseHandler implements CDSProcessingListener { private CDSResponse cdsResponse; diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/CDSRequestProvider.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/CDSRequestProvider.java new file mode 100644 index 0000000000..e01de69b74 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/CDSRequestProvider.java @@ -0,0 +1,76 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 Bell Canada + * ================================================================================ + * 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.cds; + +import com.google.gson.JsonObject; +import org.onap.so.client.exception.PayloadGenerationException; +import java.util.Optional; +import static org.onap.so.client.cds.PayloadConstants.REQUEST; +import static org.onap.so.client.cds.PayloadConstants.SEPARATOR; + +public interface CDSRequestProvider { + + /** + * Build entire payload for CDS. + * + * @param action - action could be assign/deploy/undeploy etc. + * @return "payload":{ "config-<action>-<scope>":{ // information about resolution key, property configuration and + * template prefix based on the scope and action} + * @throws PayloadGenerationException If fail to build the payload. + */ + Optional<String> buildRequestPayload(String action) throws PayloadGenerationException; + + /** + * Get the blueprint name for CDS payload + * + * @return blueprint name + */ + String getBlueprintName(); + + /** + * Get the blueprint version for CDS payload + * + * @return blueprint version + */ + String getBlueprintVersion(); + + /** + * Set the executionObject(BuildingBlockExecution or DelegateExecution for PNF) + * + * @param executionObject object could be BuildingBlockExecution or DelegateExecution. + */ + <T> void setExecutionObject(T executionObject); + + + /** + * Build Request payload for CDS + * + * @param cdsPropertyObject - Json Object + * @param action - action could be assign/deploy/undeploy etc. + * @return Request Payload + */ + default String buildRequestJsonObject(JsonObject cdsPropertyObject, String action) { + String requestBasedOnAction = action.concat(SEPARATOR).concat(REQUEST); + JsonObject requestObject = new JsonObject(); + requestObject.add(requestBasedOnAction, cdsPropertyObject); + return requestObject.toString(); + } +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModule.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModule.java new file mode 100644 index 0000000000..6f850fa898 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModule.java @@ -0,0 +1,79 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 Bell Canada + * ================================================================================ + * 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.cds; + +import com.google.gson.JsonObject; +import org.onap.so.client.cds.ExtractServiceFromUserParameters; +import org.onap.so.client.exception.PayloadGenerationException; +import org.onap.so.serviceinstancebeans.Service; +import org.onap.so.serviceinstancebeans.VfModules; +import org.onap.so.serviceinstancebeans.Vnfs; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import java.util.List; +import java.util.Map; + +@Component +public class ConfigureInstanceParamsForVfModule { + + @Autowired + private ExtractServiceFromUserParameters extractServiceFromUserParameters; + + /** + * Read instance parameters for VF-Module and put into JsonObject. + * + * @param jsonObject- JsonObject which will hold the payload to send to CDS. + * @param userParamsFromRequest - User parameters for a vf-module + * @param vnfCustomizationUuid - Unique ID for vnf. + * @param vfModuleCustomizationUuid - Unique ID for vf-module. + * @throws PayloadGenerationException- If it doesn't able to populate instance parameters from SO payload. + */ + public void populateInstanceParams(JsonObject jsonObject, List<Map<String, Object>> userParamsFromRequest, + String vnfCustomizationUuid, String vfModuleCustomizationUuid) throws PayloadGenerationException { + try { + Service service = extractServiceFromUserParameters.getServiceFromRequestUserParams(userParamsFromRequest); + + List<Map<String, String>> instanceParamsList = + getInstanceParams(service, vnfCustomizationUuid, vfModuleCustomizationUuid); + + instanceParamsList.stream().flatMap(instanceParamsMap -> instanceParamsMap.entrySet().stream()) + .forEachOrdered(entry -> jsonObject.addProperty(entry.getKey(), entry.getValue())); + } catch (Exception e) { + throw new PayloadGenerationException("Couldn't able to resolve instance parameters", e); + } + } + + private List<Map<String, String>> getInstanceParams(Service service, String vnfCustomizationUuid, + String vfModuleCustomizationUuid) throws PayloadGenerationException { + + Vnfs foundedVnf = service.getResources().getVnfs().stream() + .filter(vnfs -> vnfs.getModelInfo().getModelCustomizationId().equals(vnfCustomizationUuid)).findFirst() + .orElseThrow(() -> new PayloadGenerationException(String + .format("Can not find vnf for genericVnfModelCustomizationUuid: %s", vnfCustomizationUuid))); + + VfModules vfModule = foundedVnf.getVfModules().stream().filter( + vfModules -> vfModules.getModelInfo().getModelCustomizationId().equals(vfModuleCustomizationUuid)) + .findFirst().orElseThrow(() -> new PayloadGenerationException(String + .format("Can not find vnf for vfModuleCustomizationUuid: %s", vfModuleCustomizationUuid))); + + return vfModule.getInstanceParams(); + } +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVnf.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVnf.java new file mode 100644 index 0000000000..22c9a7bee4 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVnf.java @@ -0,0 +1,73 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 Bell Canada + * ================================================================================ + * 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.cds; + +import com.google.gson.JsonObject; +import org.onap.so.client.exception.PayloadGenerationException; +import org.onap.so.serviceinstancebeans.Service; +import org.onap.so.serviceinstancebeans.Vnfs; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +@Component +public class ConfigureInstanceParamsForVnf { + + @Autowired + private ExtractServiceFromUserParameters extractServiceFromUserParameters; + + /** + * Read instance parameters for VNF and put into JsonObject. + * + * @param jsonObject - JsonObject which will hold the payload to send to CDS. + * @param userParamsFromRequest - User parameters. + * @param modelCustomizationUuid - Unique ID for Vnf. + * @throws PayloadGenerationException if it doesn't able to populate instance parameters from SO payload. + */ + public void populateInstanceParams(JsonObject jsonObject, List<Map<String, Object>> userParamsFromRequest, + String modelCustomizationUuid) throws PayloadGenerationException { + try { + Service service = extractServiceFromUserParameters.getServiceFromRequestUserParams(userParamsFromRequest); + List<Map<String, String>> instanceParamsList = getInstanceParamForVnf(service, modelCustomizationUuid); + + instanceParamsList.stream().flatMap(instanceParamsMap -> instanceParamsMap.entrySet().stream()) + .forEachOrdered(entry -> jsonObject.addProperty(entry.getKey(), entry.getValue())); + } catch (Exception e) { + throw new PayloadGenerationException("Couldn't able to resolve instance parameters", e); + } + } + + private List<Map<String, String>> getInstanceParamForVnf(Service service, String genericVnfModelCustomizationUuid) + throws PayloadGenerationException { + Optional<Vnfs> foundedVnf = service.getResources().getVnfs().stream() + .filter(vnfs -> vnfs.getModelInfo().getModelCustomizationId().equals(genericVnfModelCustomizationUuid)) + .findFirst(); + + if (foundedVnf.isPresent()) { + return foundedVnf.get().getInstanceParams(); + } else { + throw new PayloadGenerationException(String.format( + "Can not find vnf for genericVnfModelCustomizationUuid: %s", genericVnfModelCustomizationUuid)); + } + } +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ExtractServiceFromUserParameters.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ExtractServiceFromUserParameters.java new file mode 100644 index 0000000000..43fabd3253 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ExtractServiceFromUserParameters.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 Bell Canada + * ================================================================================ + * 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.cds; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.onap.so.client.exception.PayloadGenerationException; +import org.onap.so.serviceinstancebeans.Service; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import java.util.List; +import java.util.Map; + +@Component +public class ExtractServiceFromUserParameters { + + private static final String SERVICE_KEY = "service"; + + @Autowired + private ObjectMapper objectMapper; + + public Service getServiceFromRequestUserParams(List<Map<String, Object>> userParams) throws Exception { + Map<String, Object> serviceMap = userParams.stream().filter(key -> key.containsKey(SERVICE_KEY)).findFirst() + .orElseThrow(() -> new Exception("Can not find service in userParams section in generalBuildingBlock")); + return getServiceObjectFromServiceMap(serviceMap); + } + + private Service getServiceObjectFromServiceMap(Map<String, Object> serviceMap) throws PayloadGenerationException { + try { + String serviceFromJson = objectMapper.writeValueAsString(serviceMap.get(SERVICE_KEY)); + return objectMapper.readValue(serviceFromJson, Service.class); + } catch (Exception e) { + throw new PayloadGenerationException("An exception occurred while converting json object to Service object", + e); + } + } +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/GeneratePayloadForCds.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/GeneratePayloadForCds.java new file mode 100644 index 0000000000..fb79880572 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/GeneratePayloadForCds.java @@ -0,0 +1,153 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 Bell Canada + * ================================================================================ + * Modifications Copyright (c) 2020 Nordix + * ================================================================================ + * 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.cds; + +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean; +import org.onap.so.client.exception.PayloadGenerationException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import java.util.UUID; + +@Component +public class GeneratePayloadForCds { + + private static final String ORIGINATOR_ID = "SO"; + private static final String BUILDING_BLOCK = "buildingBlock"; + private static final String DEFAULT_SYNC_MODE = "sync"; + private static final String MSO_REQUEST_ID = "msoRequestId"; + + @Autowired + private VnfCDSRequestProvider vnfCDSRequestProvider; + + @Autowired + private VfModuleCDSRequestProvider vfModuleCDSRequestProvider; + + @Autowired + private ServiceCDSRequestProvider serviceCDSRequestProvider; + + @Autowired + private ExtractPojosForBB extractPojosForBB; + + @Autowired + private PnfCDSRequestProvider pnfCDSRequestProvider; + + /** + * Build properties like (blueprint name, version, action etc..) along with the request payload for vnf, vf-module + * and service. + * + * @param execution - A building block execution object. + * @return AbstractCDSPropertiesBean - A POJO which contains CDS related information. + * @throws PayloadGenerationException - Throw an exception if it fails to build payload for CDS. + */ + public AbstractCDSPropertiesBean buildCdsPropertiesBean(BuildingBlockExecution execution) + throws PayloadGenerationException { + + ExecuteBuildingBlock executeBuildingBlock = execution.getVariable(BUILDING_BLOCK); + BuildingBlock buildingBlock = executeBuildingBlock.getBuildingBlock(); + final String requestId = execution.getGeneralBuildingBlock().getRequestContext().getMsoRequestId(); + final String scope = buildingBlock.getBpmnScope(); + final String action = buildingBlock.getBpmnAction(); + + + CDSRequestProvider requestProvider = getRequestProviderByScope(scope); + requestProvider.setExecutionObject(execution); + + final String requestPayload = requestProvider.buildRequestPayload(action) + .orElseThrow(() -> new PayloadGenerationException("Failed to build payload for CDS")); + + return prepareAndSetCdsPropertyBean(requestProvider, requestPayload, requestId, action, DEFAULT_SYNC_MODE); + } + + /** + * Build properties like (blueprint name, version, action etc..) along with the request payload for pnf. + * + * @param execution - A building block execution object. + * @return AbstractCDSPropertiesBean - A POJO which contains CDS related information. + * @throws PayloadGenerationException - Throw an exception if it fails to build payload for CDS. + */ + public AbstractCDSPropertiesBean buildCdsPropertiesBean(DelegateExecution execution) + throws PayloadGenerationException { + + final String scope = String.valueOf(execution.getVariable(PayloadConstants.SCOPE)); + final String action = String.valueOf(execution.getVariable(PayloadConstants.ACTION)); + final String requestId = String.valueOf(execution.getVariable(MSO_REQUEST_ID)); + final String mode = extractAndSetMode(execution); + + CDSRequestProvider requestProvider = getRequestProviderByScope(scope); + requestProvider.setExecutionObject(execution); + + final String requestPayload = requestProvider.buildRequestPayload(action) + .orElseThrow(() -> new PayloadGenerationException("Failed to build payload for CDS")); + + return prepareAndSetCdsPropertyBean(requestProvider, requestPayload, requestId, action, mode); + } + + private AbstractCDSPropertiesBean prepareAndSetCdsPropertyBean(CDSRequestProvider requestProvider, + String requestPayload, String requestId, String action, String mode) { + final AbstractCDSPropertiesBean cdsPropertiesBean = new AbstractCDSPropertiesBean(); + cdsPropertiesBean.setRequestObject(requestPayload); + cdsPropertiesBean.setBlueprintName(requestProvider.getBlueprintName()); + cdsPropertiesBean.setBlueprintVersion(requestProvider.getBlueprintVersion()); + cdsPropertiesBean.setRequestId(requestId); + cdsPropertiesBean.setOriginatorId(ORIGINATOR_ID); + cdsPropertiesBean.setSubRequestId(UUID.randomUUID().toString()); + cdsPropertiesBean.setActionName(action); + cdsPropertiesBean.setMode(mode); + return cdsPropertiesBean; + } + + private String extractAndSetMode(DelegateExecution execution) { + String mode = DEFAULT_SYNC_MODE; + Object obj = execution.getVariable(PayloadConstants.MODE); + if (obj != null && !String.valueOf(obj).isEmpty()) { + mode = String.valueOf(obj); + } + return mode; + } + + private CDSRequestProvider getRequestProviderByScope(String scope) throws PayloadGenerationException { + CDSRequestProvider requestProvider; + switch (scope) { + case PayloadConstants.VNF_SCOPE: + requestProvider = vnfCDSRequestProvider; + break; + case PayloadConstants.VF_MODULE_SCOPE: + requestProvider = vfModuleCDSRequestProvider; + break; + case PayloadConstants.SERVICE_SCOPE: + requestProvider = serviceCDSRequestProvider; + break; + case PayloadConstants.PNF_SCOPE: + requestProvider = pnfCDSRequestProvider; + break; + default: + throw new PayloadGenerationException("No scope defined with " + scope); + } + return requestProvider; + } +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/PayloadConstants.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/PayloadConstants.java new file mode 100644 index 0000000000..808d427d65 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/PayloadConstants.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 Bell Canada + * ================================================================================ + * Modifications Copyright (C) 2020 Nordix + * ================================================================================ + * 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.cds; + +public final class PayloadConstants { + + private PayloadConstants() { + + } + + public static final String REQUEST = "request"; + public static final String PROPERTIES = "properties"; + public static final String SCOPE = "scope"; + public static final String ACTION = "action"; + public static final String MODE = "mode"; + public static final String SEPARATOR = "-"; + public static final String PNF_SCOPE = "pnf"; + public static final String VNF_SCOPE = "vnf"; + public static final String VF_MODULE_SCOPE = "vfModule"; + public static final String SERVICE_SCOPE = "service"; + public static final String RESOLUTION_KEY = "resolution-key"; + public static final String CDS_ACTOR = "cds"; + + public static final String PRC_BLUEPRINT_NAME = "PRC_blueprintName"; + public static final String PRC_BLUEPRINT_VERSION = "PRC_blueprintVersion"; + public static final String PRC_CUSTOMIZATION_UUID = "PRC_customizationUuid"; + public static final String PRC_TARGET_SOFTWARE_VERSION = "targetSoftwareVersion"; + + public final static String PNF_CORRELATION_ID = "pnfCorrelationId"; + public final static String PNF_UUID = "pnfUuid"; + public final static String SERVICE_INSTANCE_ID = "serviceInstanceId"; + public final static String MODEL_UUID = "modelUuid"; +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/PnfCDSRequestProvider.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/PnfCDSRequestProvider.java new file mode 100644 index 0000000000..86bca755ed --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/PnfCDSRequestProvider.java @@ -0,0 +1,78 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix + * ================================================================================ + * 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.client.cds; + +import com.google.gson.JsonObject; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; +import java.util.Optional; +import static org.onap.so.client.cds.PayloadConstants.*; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class PnfCDSRequestProvider implements CDSRequestProvider { + private String blueprintName; + private String blueprintVersion; + private DelegateExecution execution; + + @Override + public String getBlueprintName() { + return blueprintName; + } + + @Override + public String getBlueprintVersion() { + return blueprintVersion; + } + + @Override + public <T> void setExecutionObject(T executionObject) { + execution = (DelegateExecution) executionObject; + } + + @Override + public Optional<String> buildRequestPayload(String action) { + + final JsonObject pnfObject = new JsonObject(); + final String resolutionKey = String.valueOf(execution.getVariable(PNF_CORRELATION_ID)); + blueprintName = String.valueOf(execution.getVariable(PRC_BLUEPRINT_NAME)); + blueprintVersion = String.valueOf(execution.getVariable(PRC_BLUEPRINT_VERSION)); + + extractAndSetExecutionVariable("service-instance-id", SERVICE_INSTANCE_ID, pnfObject); + extractAndSetExecutionVariable("service-model-uuid", MODEL_UUID, pnfObject); + extractAndSetExecutionVariable("pnf-id", PNF_UUID, pnfObject); + extractAndSetExecutionVariable("pnf-name", PNF_CORRELATION_ID, pnfObject); + extractAndSetExecutionVariable("pnf-customization-uuid", PRC_CUSTOMIZATION_UUID, pnfObject); + extractAndSetExecutionVariable("target-software-version", PRC_TARGET_SOFTWARE_VERSION, pnfObject); + + final JsonObject cdsPropertyObject = new JsonObject(); + cdsPropertyObject.addProperty(RESOLUTION_KEY, resolutionKey); + cdsPropertyObject.add(action + SEPARATOR + PROPERTIES, pnfObject); + + return Optional.of(buildRequestJsonObject(cdsPropertyObject, action)); + } + + private void extractAndSetExecutionVariable(String jsonProperty, String executionProperty, JsonObject pnfObject) { + if (execution.getVariable(executionProperty) != null) { + pnfObject.addProperty(jsonProperty, String.valueOf(execution.getVariable(executionProperty))); + } + } +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ServiceCDSRequestProvider.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ServiceCDSRequestProvider.java new file mode 100644 index 0000000000..12c841a2c6 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ServiceCDSRequestProvider.java @@ -0,0 +1,89 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Bell Canada + * ================================================================================ + * 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.cds; + +import com.google.gson.JsonObject; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.exception.PayloadGenerationException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; +import java.util.Optional; +import static org.onap.so.client.cds.PayloadConstants.PROPERTIES; +import static org.onap.so.client.cds.PayloadConstants.SEPARATOR; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class ServiceCDSRequestProvider implements CDSRequestProvider { + + private static final String EMPTY_STRING = ""; + private String resolutionKey; + private BuildingBlockExecution execution; + + @Autowired + private ExtractPojosForBB extractPojosForBB; + + @Override + public String getBlueprintName() { + return EMPTY_STRING; + } + + @Override + public String getBlueprintVersion() { + return EMPTY_STRING; + } + + @Override + public <T> void setExecutionObject(T executionObject) { + execution = (BuildingBlockExecution) executionObject; + } + + @Override + public Optional<String> buildRequestPayload(String action) throws PayloadGenerationException { + JsonObject cdsPropertyObject = new JsonObject(); + JsonObject serviceObject = new JsonObject(); + try { + ServiceInstance serviceInstance = + extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID); + + resolutionKey = serviceInstance.getServiceInstanceName(); + + // TODO Need to figure out how to populate blueprint name and version for service. + + serviceObject.addProperty("service-instance-id", serviceInstance.getServiceInstanceId()); + serviceObject.addProperty("service-model-uuid", + serviceInstance.getModelInfoServiceInstance().getModelUuid()); + + } catch (Exception e) { + throw new PayloadGenerationException("Failed to buildPropertyObjectForService", e); + } + + cdsPropertyObject.addProperty("resolution-key", resolutionKey); + cdsPropertyObject.add(action + SEPARATOR + PROPERTIES, serviceObject); + + return Optional.of(buildRequestJsonObject(cdsPropertyObject, action)); + } + +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VfModuleCDSRequestProvider.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VfModuleCDSRequestProvider.java new file mode 100644 index 0000000000..bba8925f21 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VfModuleCDSRequestProvider.java @@ -0,0 +1,121 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 Bell Canada + * ================================================================================ + * 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.cds; + +import com.google.gson.JsonObject; +import org.onap.so.bpmn.common.BuildingBlockExecution; +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.tasks.ExtractPojosForBB; +import org.onap.so.client.exception.PayloadGenerationException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import static org.onap.so.client.cds.PayloadConstants.PROPERTIES; +import static org.onap.so.client.cds.PayloadConstants.SEPARATOR; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class VfModuleCDSRequestProvider implements CDSRequestProvider { + private String blueprintName; + private String blueprintVersion; + private BuildingBlockExecution execution; + + @Autowired + private ExtractPojosForBB extractPojosForBB; + + @Autowired + private ConfigureInstanceParamsForVfModule configureInstanceParamsForVfModule; + + @Override + public String getBlueprintName() { + return blueprintName; + } + + @Override + public String getBlueprintVersion() { + return blueprintVersion; + } + + @Override + public <T> void setExecutionObject(T executionObject) { + execution = (BuildingBlockExecution) executionObject; + } + + @Override + public Optional<String> buildRequestPayload(String action) throws PayloadGenerationException { + JsonObject cdsPropertyObject = new JsonObject(); + JsonObject vfModuleObject = new JsonObject(); + String vfModuleName; + + try { + ServiceInstance serviceInstance = + extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID); + GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); + + final String modelCustomizationUuidForVnf = genericVnf.getModelInfoGenericVnf().getModelCustomizationUuid(); + + blueprintName = genericVnf.getBlueprintName(); + blueprintVersion = genericVnf.getBlueprintVersion(); + + VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID); + vfModuleName = vfModule.getVfModuleName(); + + final String modelCustomizationUuidForVfModule = + vfModule.getModelInfoVfModule().getModelCustomizationUUID(); + + vfModuleObject.addProperty("service-instance-id", serviceInstance.getServiceInstanceId()); + vfModuleObject.addProperty("service-model-uuid", + serviceInstance.getModelInfoServiceInstance().getModelUuid()); + vfModuleObject.addProperty("vnf-id", genericVnf.getVnfId()); + vfModuleObject.addProperty("vnf-name", genericVnf.getVnfName()); + vfModuleObject.addProperty("vf-module-id", vfModule.getVfModuleId()); + vfModuleObject.addProperty("vf-module-name", vfModule.getVfModuleName()); + vfModuleObject.addProperty("vf-module-customization-uuid", + vfModule.getModelInfoVfModule().getModelCustomizationUUID()); + + final GeneralBuildingBlock buildingBlock = execution.getGeneralBuildingBlock(); + List<Map<String, Object>> userParamsFromRequest = + buildingBlock.getRequestContext().getRequestParameters().getUserParams(); + + configureInstanceParamsForVfModule.populateInstanceParams(vfModuleObject, userParamsFromRequest, + modelCustomizationUuidForVnf, modelCustomizationUuidForVfModule); + } catch (Exception e) { + throw new PayloadGenerationException("Failed to buildPropertyObject for VF-Module", e); + } + + // Not sure for resolutionKey should be same as vfModule name. + cdsPropertyObject.addProperty("resolution-key", vfModuleName); + cdsPropertyObject.addProperty("template-prefix", vfModuleName + action); + cdsPropertyObject.add(action + SEPARATOR + PROPERTIES, vfModuleObject); + + return Optional.of(buildRequestJsonObject(cdsPropertyObject, action)); + } + +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VnfCDSRequestProvider.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VnfCDSRequestProvider.java new file mode 100644 index 0000000000..d33976d229 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VnfCDSRequestProvider.java @@ -0,0 +1,106 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 Bell Canada + * ================================================================================ + * 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.cds; + +import com.google.gson.JsonObject; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.exception.PayloadGenerationException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import static org.onap.so.client.cds.PayloadConstants.PROPERTIES; +import static org.onap.so.client.cds.PayloadConstants.SEPARATOR; + +@Component +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class VnfCDSRequestProvider implements CDSRequestProvider { + private String blueprintName; + private String blueprintVersion; + private BuildingBlockExecution execution; + + @Autowired + private ExtractPojosForBB extractPojosForBB; + + @Autowired + private ConfigureInstanceParamsForVnf configureInstanceParamsForVnf; + + @Override + public String getBlueprintName() { + return blueprintName; + } + + @Override + public String getBlueprintVersion() { + return blueprintVersion; + } + + @Override + public <T> void setExecutionObject(T executionObject) { + execution = (BuildingBlockExecution) executionObject; + } + + @Override + public Optional<String> buildRequestPayload(String action) throws PayloadGenerationException { + JsonObject cdsPropertyObject = new JsonObject(); + JsonObject vnfObject = new JsonObject(); + String resolutionKey; + try { + ServiceInstance serviceInstance = + extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID); + GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); + + final String modelCustomizationUuid = genericVnf.getModelInfoGenericVnf().getModelCustomizationUuid(); + + resolutionKey = genericVnf.getVnfName(); + blueprintName = genericVnf.getBlueprintName(); + blueprintVersion = genericVnf.getBlueprintVersion(); + + vnfObject.addProperty("service-instance-id", serviceInstance.getServiceInstanceId()); + vnfObject.addProperty("service-model-uuid", serviceInstance.getModelInfoServiceInstance().getModelUuid()); + vnfObject.addProperty("vnf-id", genericVnf.getVnfId()); + vnfObject.addProperty("vnf-name", genericVnf.getVnfName()); + vnfObject.addProperty("vnf-customization-uuid", modelCustomizationUuid); + + final GeneralBuildingBlock buildingBlock = execution.getGeneralBuildingBlock(); + List<Map<String, Object>> userParamsFromRequest = + buildingBlock.getRequestContext().getRequestParameters().getUserParams(); + + configureInstanceParamsForVnf.populateInstanceParams(vnfObject, userParamsFromRequest, + modelCustomizationUuid); + } catch (Exception e) { + throw new PayloadGenerationException("Failed to buildPropertyObjectForVnf", e); + } + + cdsPropertyObject.addProperty("resolution-key", resolutionKey); + cdsPropertyObject.add(action + SEPARATOR + PROPERTIES, vnfObject); + + return Optional.of(buildRequestJsonObject(cdsPropertyObject, action)); + } +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/exception/PayloadGenerationException.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/exception/PayloadGenerationException.java new file mode 100644 index 0000000000..3c148a17a5 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/exception/PayloadGenerationException.java @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 Bell Canada + * ================================================================================ + * 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.exception; + +public class PayloadGenerationException extends Exception { + + /** + * @param message The message to dump + */ + public PayloadGenerationException(final String message) { + super(message); + } + + /** + * @param message The message to dump. + * @param cause The throwable cause object. + */ + public PayloadGenerationException(final String message, final Throwable cause) { + super(message, cause); + } +} |