2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
20 package org.onap.so.bpmn.infrastructure.pnf.delegate;
22 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.MODEL_UUID;
23 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_CORRELATION_ID;
24 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_UUID;
25 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PRC_CUSTOMIZATION_UUID;
26 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.SERVICE_INSTANCE_ID;
28 import java.io.IOException;
29 import java.util.Optional;
30 import org.camunda.bpm.engine.delegate.DelegateExecution;
31 import org.camunda.bpm.engine.delegate.JavaDelegate;
32 import org.onap.aai.domain.yang.Pnf;
33 import org.onap.so.bpmn.infrastructure.pnf.management.PnfManagement;
34 import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean;
35 import org.onap.so.client.cds.beans.ConfigDeployPropertiesForPnf;
36 import org.onap.so.client.cds.beans.ConfigDeployRequestPnf;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.stereotype.Component;
41 * This implementation of {@link JavaDelegate} is used to prepare for config Deploy.
43 * It queries the PNF resource customization table and construct the {@link AbstractCDSPropertiesBean} as
47 public class PrepareConfigDeployDelegate extends PrepareCdsCallDelegate {
50 private PnfManagement pnfManagement;
52 public PrepareConfigDeployDelegate() {
53 this.actionName = "config-deploy";
58 protected String getRequestObject(DelegateExecution delegateExecution){
60 ConfigDeployPropertiesForPnf configDeployProperties = new ConfigDeployPropertiesForPnf();
62 configDeployProperties.setServiceInstanceId((String) delegateExecution.getVariable(SERVICE_INSTANCE_ID));
65 * PNF Name matches the name in AAI, i.e., correlationID as in customized workflow.
67 configDeployProperties.setPnfName((String) delegateExecution.getVariable(PNF_CORRELATION_ID));
70 * PNF id match AAI entry, i.e, PNF UUID.
72 configDeployProperties.setPnfId((String) delegateExecution.getVariable(PNF_UUID));
73 configDeployProperties.setPnfCustomizationUuid((String) delegateExecution.getVariable(PRC_CUSTOMIZATION_UUID));
74 configDeployProperties.setServiceModelUuid((String) delegateExecution.getVariable(MODEL_UUID));
75 setIpAddress(configDeployProperties, delegateExecution);
77 ConfigDeployRequestPnf configDeployRequest = new ConfigDeployRequestPnf();
78 configDeployRequest.setConfigDeployPropertiesForPnf(configDeployProperties);
81 * Resolution key is the same as PNF name.
83 configDeployRequest.setResolutionKey((String) delegateExecution.getVariable(PNF_CORRELATION_ID));
85 return configDeployRequest.toString();
88 private void setIpAddress(ConfigDeployPropertiesForPnf configDeployProperties, DelegateExecution delegateExecution) {
91 * Retrieve PNF entry from AAI.
94 String pnfName = (String) delegateExecution.getVariable(PNF_CORRELATION_ID);
95 Optional<Pnf> pnfOptional = pnfManagement.getEntryFor(pnfName);
96 if ( pnfOptional.isPresent()){
97 Pnf pnf = pnfOptional.get();
98 configDeployProperties.setPnfIpV4Address(pnf.getPnfIpv4Address());
99 configDeployProperties.setPnfIpV6Address(pnf.getPnfIpv6Address());
101 exceptionUtil.buildAndThrowWorkflowException(delegateExecution, ERROR_CODE, "AAI entry for PNF: " + pnfName + " does not exist");
103 } catch (IOException e) {
104 logger.warn(e.getMessage(), e);
105 exceptionUtil.buildAndThrowWorkflowException(delegateExecution, ERROR_CODE, "Unable to fetch from AAI" + e.getMessage());