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.licmgr.impl;
26 import org.openecomp.appc.dg.licmgr.LicenseManagerPlugin;
27 import org.openecomp.appc.exceptions.APPCException;
28 import org.openecomp.appc.licmgr.Constants;
29 import org.openecomp.appc.licmgr.LicenseManager;
30 import org.openecomp.appc.licmgr.exception.DataAccessException;
31 import org.openecomp.appc.licmgr.objects.LicenseModel;
32 import com.att.eelf.configuration.EELFLogger;
33 import com.att.eelf.configuration.EELFManager;
34 import org.openecomp.sdnc.sli.SvcLogicContext;
38 public class LicenseManagerPluginImpl implements LicenseManagerPlugin {
40 private static EELFLogger logger = EELFManager.getInstance().getApplicationLogger();
42 // populated by blueprint framework
43 private LicenseManager licenseManager;
45 public void setLicenseManager(LicenseManager licenseManager) {
46 this.licenseManager = licenseManager;
50 * Retrieves license model from APPC database and populate flags into svc context
51 * @param params map with parameters:
52 * org.openecomp.appc.vftype - the vnf type / service type;
53 * org.openecomp.appc.resource-version - the vnf version / service version
54 * @param ctx service logic context
55 * 1. supposed properties already in context:
56 * aai.input.data.entitlement-assignment-group-uuid - entitlement-group-uuid asset tag already stored in AAI
57 * aai.input.data.license-assignment-group-uuid - license-key-uuid asset tag already stored in AAI
58 * 2. properties and flags stored in context after bean execution:
59 * model.entitlement.pool.uuid - entitlement-group-uuid from license model
60 * model.license.key.uuid - license-key-uuid from license model
61 * is.acquire-entitlement.require
62 * is.release-entitlement.require
63 * is.acquire-license.require
64 * is.release-license.require
65 * is.aai-entitlement-update.require
66 * is.aai-license-update.require
68 * @throws APPCException throws in case of any error
71 public void retrieveLicenseModel(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
75 LicenseModel licenseModel = licenseManager.retrieveLicenseModel(params.get(Constants.VNF_TYPE_FIELD_NAME), params.get(Constants.VNF_RESOURCE_VERSION_FIELD_NAME));
77 String modelEntitlementPoolUuid = licenseModel.getEntitlementPoolUuid(); if (null == modelEntitlementPoolUuid) modelEntitlementPoolUuid = "";
78 String aaiEntitlementPoolUuid = ctx.getAttribute(Constants.AAI_ENTITLMENT_POOL_UUID_NAME); if (null == aaiEntitlementPoolUuid) aaiEntitlementPoolUuid = "";
79 boolean isAcquireEntitlementRequire = !modelEntitlementPoolUuid.isEmpty() && !modelEntitlementPoolUuid.equals(aaiEntitlementPoolUuid);
80 boolean isReleaseEntitlementRequire = !aaiEntitlementPoolUuid.isEmpty() && (isAcquireEntitlementRequire || modelEntitlementPoolUuid.isEmpty());
81 boolean isAAIEntitlementUpdateRequire = isAcquireEntitlementRequire || isReleaseEntitlementRequire;
82 ctx.setAttribute(Constants.MODEL_ENTITLMENT_POOL_UUID_NAME, modelEntitlementPoolUuid);
83 ctx.setAttribute(Constants.IS_ACQUIRE_ENTITLEMENT_REQUIRE, Boolean.toString(isAcquireEntitlementRequire));
84 ctx.setAttribute(Constants.IS_RELEASE_ENTITLEMENT_REQUIRE, Boolean.toString(isReleaseEntitlementRequire));
85 ctx.setAttribute(Constants.IS_AAI_ENTITLEMENT_UPDATE_REQUIRE, Boolean.toString(isAAIEntitlementUpdateRequire));
88 String modelLicenseKeyGroupUuid = licenseModel.getLicenseKeyGroupUuid(); if (null == modelLicenseKeyGroupUuid) modelLicenseKeyGroupUuid = "";
89 String aaiLicenseKeyGroupUuid = ctx.getAttribute(Constants.AAI_LICENSE_KEY_UUID_NAME); if (null == aaiLicenseKeyGroupUuid) aaiLicenseKeyGroupUuid = "";
90 String aaiLicenseKeyValue = ctx.getAttribute(Constants.AAI_LICENSE_KEY_VALUE); if (null == aaiLicenseKeyValue) aaiLicenseKeyValue = "";
91 boolean isAcquireLicenseRequire = !modelLicenseKeyGroupUuid.isEmpty() && !modelLicenseKeyGroupUuid.equals(aaiLicenseKeyGroupUuid);
92 boolean isReleaseLicenseRequire = !aaiLicenseKeyGroupUuid.isEmpty() && (isAcquireLicenseRequire || modelLicenseKeyGroupUuid.isEmpty());
93 boolean isAAILicenseUpdateRequire = isAcquireLicenseRequire || isReleaseLicenseRequire;
94 ctx.setAttribute(Constants.MODEL_LICENSE_KEY_UUID_NAME, modelLicenseKeyGroupUuid);
95 ctx.setAttribute(Constants.IS_ACQUIRE_LICENSE_REQUIRE, Boolean.toString(isAcquireLicenseRequire));
96 ctx.setAttribute(Constants.IS_RELEASE_LICENSE_REQUIRE, Boolean.toString(isReleaseLicenseRequire));
97 ctx.setAttribute(Constants.IS_AAI_LICENSE_UPDATE_REQUIRE, Boolean.toString(isAAILicenseUpdateRequire));
99 ctx.setAttribute("license-key", aaiLicenseKeyValue);
101 } catch (DataAccessException le) {
102 logger.error("Error " + le.getMessage());
103 ctx.setAttribute("output.status.message", le.getMessage());
104 throw new APPCException(le);
111 //////// code uses jaxb license model, should be fixed
113 final VfLicenseModel.FeatureGroupList featureGroupList = licenseModel.getFeatureGroupList();
114 if (null != featureGroupList) {
115 final VfLicenseModel.FeatureGroupList.FeatureGroup featureGroup = featureGroupList.getFeatureGroup();
116 if (null != featureGroup) {
117 final VfLicenseModel.FeatureGroupList.FeatureGroup.EntitlementPoolList
118 entitlementPoolList = featureGroup.getEntitlementPoolList();
119 if (null != entitlementPoolList) {
120 final VfLicenseModel.FeatureGroupList.FeatureGroup.EntitlementPoolList.EntitlementPool
121 entitlementPool = entitlementPoolList.getEntitlementPool();
122 if (null != entitlementPool) {
123 final String entitlementPoolUuid = entitlementPool.getEntitlementPoolUuid();
124 // add entitlementPoolUuid into context
125 ctx.setAttribute(Constants.MODEL_ENTITLMENT_POOL_UUID_NAME, entitlementPoolUuid);
129 final VfLicenseModel.FeatureGroupList.FeatureGroup.LicenseKeyGroupList
130 licenseKeyGroupList = featureGroup.getLicenseKeyGroupList();
131 if (null != licenseKeyGroupList) {
132 final VfLicenseModel.FeatureGroupList.FeatureGroup.LicenseKeyGroupList.LicenseKeyGroup
133 licenseKeyGroup = licenseKeyGroupList.getLicenseKeyGroup();
134 if (null != licenseKeyGroup) {
135 final String licenseKeyGroupUuid = licenseKeyGroup.getLicenseKeyGroupUuid();
136 // add licenseKeyGroupUuid into context
137 ctx.setAttribute(Constants.MODEL_LICENSE_KEY_UUID_NAME, licenseKeyGroupUuid);