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