2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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=========================================================
22 package org.openecomp.appc.dg.aai.impl;
24 import org.openecomp.appc.dg.aai.AAIPlugin;
25 import org.openecomp.appc.dg.aai.impl.Constants;
26 import org.openecomp.appc.exceptions.APPCException;
27 import com.att.eelf.configuration.EELFLogger;
28 import com.att.eelf.configuration.EELFManager;
29 import org.openecomp.sdnc.sli.SvcLogicContext;
30 import org.openecomp.sdnc.sli.SvcLogicException;
31 import org.openecomp.sdnc.sli.SvcLogicResource;
32 import org.openecomp.sdnc.sli.aai.AAIClient;
33 import org.openecomp.sdnc.sli.aai.AAIService;
34 import org.osgi.framework.BundleContext;
35 import org.osgi.framework.FrameworkUtil;
36 import org.osgi.framework.ServiceReference;
38 import java.util.HashMap;
42 public class AAIPluginImpl implements AAIPlugin {
43 private AAIClient aaiClient;
44 private static final EELFLogger logger = EELFManager.getInstance().getLogger(AAIPluginImpl.class);
46 public AAIPluginImpl() {
47 BundleContext bctx = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
48 ServiceReference sref = bctx.getServiceReference(AAIService.class);
49 aaiClient = (AAIClient) bctx.getService(sref);
53 public void postGenericVnfData(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
54 String vnf_id = ctx.getAttribute(Constants.VNF_ID_PARAM_NAME);
55 String prefix = ctx.getAttribute(Constants.AAI_PREFIX_PARAM_NAME);
57 String key = "vnf-id = '" + vnf_id + "'";
59 Map<String, String> data = new HashMap<>();
60 for (Map.Entry<String, String> entry : params.entrySet()) {
61 String paramKey = entry.getKey();
62 int pos = paramKey.indexOf(Constants.AAI_INPUT_DATA);
64 data.put(paramKey.substring(Constants.AAI_INPUT_DATA.length()+1), entry.getValue());
69 SvcLogicResource.QueryStatus response = aaiClient.update("generic-vnf", key, data, prefix, ctx);
70 if (SvcLogicResource.QueryStatus.NOT_FOUND.equals(response)) {
71 String errorMessage = String.format("VNF not found for vnf_id = %s", vnf_id);
72 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, errorMessage);
73 throw new APPCException(errorMessage);
75 logger.info("AAIResponse: " + response.toString());
76 if (SvcLogicResource.QueryStatus.FAILURE.equals(response)) {
77 String errorMessage = String.format("Error Querying AAI with vnfID = %s", vnf_id);
78 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, errorMessage);
79 throw new APPCException(errorMessage);
81 } catch (SvcLogicException e) {
82 String errorMessage = String.format("Error in postVnfdata %s", e);
83 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, errorMessage);
84 logger.error(errorMessage);
85 throw new APPCException(e);
90 public void getGenericVnfData(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
91 String vnf_id = ctx.getAttribute(Constants.VNF_ID_PARAM_NAME);
92 String prefix = ctx.getAttribute(Constants.AAI_PREFIX_PARAM_NAME);
94 String key = "vnf-id = '" + vnf_id + "'";
96 SvcLogicResource.QueryStatus response = aaiClient.query("generic-vnf", false, null, key, prefix, null, ctx);
97 if (SvcLogicResource.QueryStatus.NOT_FOUND.equals(response)) {
98 String errorMessage = String.format("VNF not found for vnf_id = %s", vnf_id);
99 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, errorMessage);
100 throw new APPCException(errorMessage);
101 } else if (SvcLogicResource.QueryStatus.FAILURE.equals(response)) {
102 String errorMessage = String.format("Error Querying AAI with vnfID = %s", vnf_id);
103 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, errorMessage);
104 throw new APPCException(errorMessage);
106 String aaiEntitlementPoolUuid = ctx.getAttribute(Constants.AAI_ENTITLMENT_POOL_UUID_NAME);
107 if (null == aaiEntitlementPoolUuid) aaiEntitlementPoolUuid = "";
108 String aaiLicenseKeyGroupUuid = ctx.getAttribute(Constants.AAI_LICENSE_KEY_UUID_NAME);
109 if (null == aaiLicenseKeyGroupUuid) aaiLicenseKeyGroupUuid = "";
111 ctx.setAttribute(Constants.IS_RELEASE_ENTITLEMENT_REQUIRE, Boolean.toString(!aaiEntitlementPoolUuid.isEmpty()));
112 ctx.setAttribute(Constants.IS_RELEASE_LICENSE_REQUIRE, Boolean.toString(!aaiLicenseKeyGroupUuid.isEmpty()));
114 logger.info("AAIResponse: " + response.toString());
115 } catch (SvcLogicException e) {
116 String errorMessage = String.format("Error in getVnfdata %s", e);
117 ctx.setAttribute(Constants.DG_OUTPUT_STATUS_MESSAGE, errorMessage);
118 logger.error(errorMessage);
119 throw new APPCException(e);