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