2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Nokia. All rights reserved.
6 * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
7 * =============================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.appc.flow.controller.node;
23 import com.att.eelf.configuration.EELFLogger;
24 import com.att.eelf.configuration.EELFManager;
25 import org.apache.commons.lang3.StringUtils;
26 import org.onap.appc.flow.controller.interfaceData.InventoryInfo;
27 import org.onap.appc.flow.controller.interfaceData.Vm;
28 import org.onap.appc.flow.controller.interfaceData.VnfInfo;
29 import org.onap.appc.flow.controller.interfaceData.Vnfcslist;
30 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
33 * Helper class for FlowControlNode
35 class InventoryInfoExtractor {
37 private static final EELFLogger log = EELFManager.getInstance().getLogger(InventoryInfoExtractor.class);
39 InventoryInfo getInventoryInfo(SvcLogicContext ctx, String vnfId) {
40 String fn = "InventoryInfoExtractor.getInventoryInfo";
42 VnfInfo vnfInfo = new VnfInfo();
43 vnfInfo.setVnfId(vnfId);
44 vnfInfo.setVnfName(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name"));
45 vnfInfo.setVnfType(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type"));
46 vnfInfo.setIdentityUrl(getIdentityUrl(ctx, vnfInfo, vnfId));
48 String vmcount = ctx.getAttribute("tmp.vnfInfo.vm-count");
49 log.info(fn + "vmcount:" + vmcount);
51 int vmCount = (StringUtils.isNotBlank(vmcount)) ? Integer.parseInt(vmcount) : 0;
53 for (int i = 0; i < vmCount; i++) {
54 processVm(ctx, vnfInfo, i);
57 InventoryInfo inventoryInfo = new InventoryInfo();
58 inventoryInfo.setVnfInfo(vnfInfo);
59 log.info(fn + "Inventory Output:" + inventoryInfo.toString());
64 private void processVm(SvcLogicContext ctx, VnfInfo vnfInfo, int index) {
66 vm.setVserverId(ctx.getAttribute("tmp.vnfInfo.vm[" + index + "].vserver-id"));
67 vm.setVmId(ctx.getAttribute("tmp.vnfInfo.vm[" + index + "].vserver-selflink"));
68 int vnfcCount = Integer.parseInt(ctx.getAttribute("tmp.vnfInfo.vm[" + index + "].vnfc-count"));
70 Vnfcslist vnfc = new Vnfcslist();
71 vnfc.setVnfcName(ctx.getAttribute("tmp.vnfInfo.vm[" + index + "].vnfc-name"));
72 vnfc.setVnfcType(ctx.getAttribute("tmp.vnfInfo.vm[" + index + "].vnfc-type"));
73 vnfc.setVnfcFunctionCode(ctx.getAttribute("tmp.vnfInfo.vm[" + index + "].vnfc-function-code"));
76 vnfInfo.getVm().add(vm);
79 public String getIdentityUrl(SvcLogicContext ctx, VnfInfo vnfInfo, String vnfId) {
80 String identityUrl = "";
81 for (String key : ctx.getAttributeKeySet()) {
82 log.debug("InventoryData " + key + "=" + ctx.getAttribute(key));
84 String urlFromPayload = ctx.getAttribute("identity-url");
85 log.info("Url from payload:" + urlFromPayload);
86 String urlFromAAI = ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url");
87 log.info("Url from AAI:" + urlFromAAI);
89 if (StringUtils.isNotBlank(urlFromPayload)) {
90 identityUrl = urlFromPayload;
91 } else if (StringUtils.isNotBlank(urlFromAAI)) {
92 identityUrl = urlFromAAI;