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