2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * ================================================================================
9 * Modifications (C) 2019 Ericsson
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.appc.dg.licmgr.impl;
30 import org.onap.appc.dg.licmgr.LicenseManagerPlugin;
31 import org.onap.appc.exceptions.APPCException;
32 import org.onap.appc.licmgr.Constants;
33 import org.onap.appc.licmgr.LicenseManager;
34 import org.onap.appc.licmgr.exception.DataAccessException;
35 import org.onap.appc.licmgr.objects.LicenseModel;
36 import com.att.eelf.configuration.EELFLogger;
37 import com.att.eelf.configuration.EELFManager;
38 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
42 public class LicenseManagerPluginImpl implements LicenseManagerPlugin {
44 private static EELFLogger logger = EELFManager.getInstance().getApplicationLogger();
46 // populated by blueprint framework
47 private LicenseManager licenseManager;
49 public void setLicenseManager(LicenseManager licenseManager) {
50 this.licenseManager = licenseManager;
54 * Retrieves license model from APPC database and populate flags into svc context
55 * @param params map with parameters:
56 * org.onap.appc.vftype - the vnf type / service type;
57 * org.onap.appc.resource-version - the vnf version / service version
58 * @param ctx service logic context
59 * 1. supposed properties already in context:
60 * aai.input.data.entitlement-assignment-group-uuid - entitlement-group-uuid asset tag already stored in AAI
61 * aai.input.data.license-assignment-group-uuid - license-key-uuid asset tag already stored in AAI
62 * 2. properties and flags stored in context after bean execution:
63 * model.entitlement.pool.uuid - entitlement-group-uuid from license model
64 * model.license.key.uuid - license-key-uuid from license model
65 * is.acquire-entitlement.require
66 * is.release-entitlement.require
67 * is.acquire-license.require
68 * is.release-license.require
69 * is.aai-entitlement-update.require
70 * is.aai-license-update.require
72 * @throws APPCException throws in case of any error
75 public void retrieveLicenseModel(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
79 LicenseModel licenseModel = licenseManager.retrieveLicenseModel(params.get(Constants.VNF_TYPE_FIELD_NAME), params.get(Constants.VNF_RESOURCE_VERSION_FIELD_NAME));
81 String modelEntitlementPoolUuid = licenseModel.getEntitlementPoolUuid();
82 if (null == modelEntitlementPoolUuid) {
83 modelEntitlementPoolUuid = "";
85 String aaiEntitlementPoolUuid = ctx.getAttribute(Constants.AAI_ENTITLMENT_POOL_UUID_NAME);
86 if (null == aaiEntitlementPoolUuid) {
87 aaiEntitlementPoolUuid = "";
89 boolean isAcquireEntitlementRequire = !modelEntitlementPoolUuid.isEmpty() && !modelEntitlementPoolUuid.equals(aaiEntitlementPoolUuid);
90 boolean isReleaseEntitlementRequire = !aaiEntitlementPoolUuid.isEmpty() && (isAcquireEntitlementRequire || modelEntitlementPoolUuid.isEmpty());
91 boolean isAAIEntitlementUpdateRequire = isAcquireEntitlementRequire || isReleaseEntitlementRequire;
92 ctx.setAttribute(Constants.MODEL_ENTITLMENT_POOL_UUID_NAME, modelEntitlementPoolUuid);
93 ctx.setAttribute(Constants.IS_ACQUIRE_ENTITLEMENT_REQUIRE, Boolean.toString(isAcquireEntitlementRequire));
94 ctx.setAttribute(Constants.IS_RELEASE_ENTITLEMENT_REQUIRE, Boolean.toString(isReleaseEntitlementRequire));
95 ctx.setAttribute(Constants.IS_AAI_ENTITLEMENT_UPDATE_REQUIRE, Boolean.toString(isAAIEntitlementUpdateRequire));
98 String modelLicenseKeyGroupUuid = licenseModel.getLicenseKeyGroupUuid();
99 if (null == modelLicenseKeyGroupUuid) {
100 modelLicenseKeyGroupUuid = "";
102 String aaiLicenseKeyGroupUuid = ctx.getAttribute(Constants.AAI_LICENSE_KEY_UUID_NAME);
103 if (null == aaiLicenseKeyGroupUuid) {
104 aaiLicenseKeyGroupUuid = "";
106 String aaiLicenseKeyValue = ctx.getAttribute(Constants.AAI_LICENSE_KEY_VALUE);
107 if (null == aaiLicenseKeyValue) {
108 aaiLicenseKeyValue = "";
110 boolean isAcquireLicenseRequire = !modelLicenseKeyGroupUuid.isEmpty() && !modelLicenseKeyGroupUuid.equals(aaiLicenseKeyGroupUuid);
111 boolean isReleaseLicenseRequire = !aaiLicenseKeyGroupUuid.isEmpty() && (isAcquireLicenseRequire || modelLicenseKeyGroupUuid.isEmpty());
112 boolean isAAILicenseUpdateRequire = isAcquireLicenseRequire || isReleaseLicenseRequire;
113 ctx.setAttribute(Constants.MODEL_LICENSE_KEY_UUID_NAME, modelLicenseKeyGroupUuid);
114 ctx.setAttribute(Constants.IS_ACQUIRE_LICENSE_REQUIRE, Boolean.toString(isAcquireLicenseRequire));
115 ctx.setAttribute(Constants.IS_RELEASE_LICENSE_REQUIRE, Boolean.toString(isReleaseLicenseRequire));
116 ctx.setAttribute(Constants.IS_AAI_LICENSE_UPDATE_REQUIRE, Boolean.toString(isAAILicenseUpdateRequire));
118 ctx.setAttribute("license-key", aaiLicenseKeyValue);
120 } catch (DataAccessException le) {
121 logger.error("Error " + le.getMessage());
122 ctx.setAttribute("output.status.message", le.getMessage());
123 throw new APPCException(le);
130 //////// code uses jaxb license model, should be fixed
132 final VfLicenseModel.FeatureGroupList featureGroupList = licenseModel.getFeatureGroupList();
133 if (null != featureGroupList) {
134 final VfLicenseModel.FeatureGroupList.FeatureGroup featureGroup = featureGroupList.getFeatureGroup();
135 if (null != featureGroup) {
136 final VfLicenseModel.FeatureGroupList.FeatureGroup.EntitlementPoolList
137 entitlementPoolList = featureGroup.getEntitlementPoolList();
138 if (null != entitlementPoolList) {
139 final VfLicenseModel.FeatureGroupList.FeatureGroup.EntitlementPoolList.EntitlementPool
140 entitlementPool = entitlementPoolList.getEntitlementPool();
141 if (null != entitlementPool) {
142 final String entitlementPoolUuid = entitlementPool.getEntitlementPoolUuid();
143 // add entitlementPoolUuid into context
144 ctx.setAttribute(Constants.MODEL_ENTITLMENT_POOL_UUID_NAME, entitlementPoolUuid);
148 final VfLicenseModel.FeatureGroupList.FeatureGroup.LicenseKeyGroupList
149 licenseKeyGroupList = featureGroup.getLicenseKeyGroupList();
150 if (null != licenseKeyGroupList) {
151 final VfLicenseModel.FeatureGroupList.FeatureGroup.LicenseKeyGroupList.LicenseKeyGroup
152 licenseKeyGroup = licenseKeyGroupList.getLicenseKeyGroup();
153 if (null != licenseKeyGroup) {
154 final String licenseKeyGroupUuid = licenseKeyGroup.getLicenseKeyGroupUuid();
155 // add licenseKeyGroupUuid into context
156 ctx.setAttribute(Constants.MODEL_LICENSE_KEY_UUID_NAME, licenseKeyGroupUuid);