2 * ============LICENSE_START======================================================= Copyright (C) 2019 Nordix
3 * Foundation. ================================================================================ Licensed under the
4 * Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may
5 * obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software
8 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
9 * either express or implied. See the License for the specific language governing permissions and limitations under the
12 * SPDX-License-Identifier: Apache-2.0 ============LICENSE_END=========================================================
15 package org.onap.so.bpmn.infrastructure.pnf.delegate;
17 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.MODEL_UUID;
18 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_CORRELATION_ID;
19 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_UUID;
20 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PRC_CUSTOMIZATION_UUID;
21 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.SERVICE_INSTANCE_ID;
22 import java.io.IOException;
23 import java.util.Optional;
24 import org.camunda.bpm.engine.delegate.DelegateExecution;
25 import org.camunda.bpm.engine.delegate.JavaDelegate;
26 import org.onap.aai.domain.yang.Pnf;
27 import org.onap.so.bpmn.infrastructure.pnf.management.PnfManagement;
28 import org.onap.so.client.cds.beans.AbstractCDSPropertiesBean;
29 import org.onap.so.client.cds.beans.ConfigDeployPropertiesForPnf;
30 import org.onap.so.client.cds.beans.ConfigDeployRequestPnf;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.stereotype.Component;
35 * This implementation of {@link JavaDelegate} is used to prepare for config Deploy.
37 * It queries the PNF resource customization table and construct the {@link AbstractCDSPropertiesBean} as
41 public class PrepareConfigDeployDelegate extends PrepareCdsCallDelegate {
44 private PnfManagement pnfManagement;
46 public PrepareConfigDeployDelegate() {
47 this.actionName = "config-deploy";
52 protected String getRequestObject(DelegateExecution delegateExecution) {
54 ConfigDeployPropertiesForPnf configDeployProperties = new ConfigDeployPropertiesForPnf();
56 configDeployProperties.setServiceInstanceId((String) delegateExecution.getVariable(SERVICE_INSTANCE_ID));
59 * PNF Name matches the name in AAI, i.e., correlationID as in customized workflow.
61 configDeployProperties.setPnfName((String) delegateExecution.getVariable(PNF_CORRELATION_ID));
64 * PNF id match AAI entry, i.e, PNF UUID.
66 configDeployProperties.setPnfId((String) delegateExecution.getVariable(PNF_UUID));
67 configDeployProperties.setPnfCustomizationUuid((String) delegateExecution.getVariable(PRC_CUSTOMIZATION_UUID));
68 configDeployProperties.setServiceModelUuid((String) delegateExecution.getVariable(MODEL_UUID));
69 setIpAddress(configDeployProperties, delegateExecution);
71 ConfigDeployRequestPnf configDeployRequest = new ConfigDeployRequestPnf();
72 configDeployRequest.setConfigDeployPropertiesForPnf(configDeployProperties);
75 * Resolution key is the same as PNF name.
77 configDeployRequest.setResolutionKey((String) delegateExecution.getVariable(PNF_CORRELATION_ID));
79 return configDeployRequest.toString();
82 private void setIpAddress(ConfigDeployPropertiesForPnf configDeployProperties,
83 DelegateExecution delegateExecution) {
86 * Retrieve PNF entry from AAI.
89 String pnfName = (String) delegateExecution.getVariable(PNF_CORRELATION_ID);
90 Optional<Pnf> pnfOptional = pnfManagement.getEntryFor(pnfName);
91 if (pnfOptional.isPresent()) {
92 Pnf pnf = pnfOptional.get();
95 * PRH patches the AAI with oam address. Use ipaddress-v4-oam and ipaddress-v6-oam for the config deploy
98 configDeployProperties.setPnfIpV4Address(pnf.getIpaddressV4Oam());
99 configDeployProperties.setPnfIpV6Address(pnf.getIpaddressV6Oam());
101 exceptionUtil.buildAndThrowWorkflowException(delegateExecution, ERROR_CODE,
102 "AAI entry for PNF: " + pnfName + " does not exist");
104 } catch (IOException e) {
105 logger.warn(e.getMessage(), e);
106 exceptionUtil.buildAndThrowWorkflowException(delegateExecution, ERROR_CODE,
107 "Unable to fetch from AAI" + e.getMessage());