First part of onap rename
[appc.git] / appc-dg / appc-dg-shared / appc-dg-license-manager / src / main / java / org / openecomp / appc / dg / licmgr / impl / LicenseManagerPluginImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017 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
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
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.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.appc.dg.licmgr.impl;
26
27 import java.util.Map;
28
29 import org.onap.appc.dg.licmgr.LicenseManagerPlugin;
30 import org.onap.appc.exceptions.APPCException;
31 import org.onap.appc.licmgr.Constants;
32 import org.onap.appc.licmgr.LicenseManager;
33 import org.onap.appc.licmgr.exception.DataAccessException;
34 import org.onap.appc.licmgr.objects.LicenseModel;
35 import com.att.eelf.configuration.EELFLogger;
36 import com.att.eelf.configuration.EELFManager;
37 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
38
39
40
41 public class LicenseManagerPluginImpl implements LicenseManagerPlugin {
42
43     private static EELFLogger logger = EELFManager.getInstance().getApplicationLogger();
44
45     // populated by blueprint framework
46     private LicenseManager licenseManager;
47
48     public void setLicenseManager(LicenseManager licenseManager) {
49         this.licenseManager = licenseManager;
50     }
51
52     /**
53      * Retrieves license model from APPC database and populate flags into svc context
54      * @param params map with parameters:
55      *               org.onap.appc.vftype - the vnf type / service type;
56      *               org.onap.appc.resource-version - the vnf version / service version
57      * @param ctx service logic context
58      *            1. supposed properties already in context:
59      *            aai.input.data.entitlement-assignment-group-uuid - entitlement-group-uuid asset tag already stored in AAI
60      *            aai.input.data.license-assignment-group-uuid - license-key-uuid asset tag already stored in AAI
61      *            2. properties and flags stored in context after bean execution:
62      *            model.entitlement.pool.uuid - entitlement-group-uuid from license model
63      *            model.license.key.uuid - license-key-uuid from license model
64      *            is.acquire-entitlement.require
65      *            is.release-entitlement.require
66      *            is.acquire-license.require
67      *            is.release-license.require
68      *            is.aai-entitlement-update.require
69      *            is.aai-license-update.require
70      *
71      * @throws APPCException throws in case of any error
72      */
73     @Override
74     public void retrieveLicenseModel(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
75
76         try {
77
78             LicenseModel licenseModel = licenseManager.retrieveLicenseModel(params.get(Constants.VNF_TYPE_FIELD_NAME), params.get(Constants.VNF_RESOURCE_VERSION_FIELD_NAME));
79
80             String modelEntitlementPoolUuid = licenseModel.getEntitlementPoolUuid(); if (null == modelEntitlementPoolUuid) modelEntitlementPoolUuid = "";
81             String aaiEntitlementPoolUuid = ctx.getAttribute(Constants.AAI_ENTITLMENT_POOL_UUID_NAME); if (null == aaiEntitlementPoolUuid) aaiEntitlementPoolUuid = "";
82             boolean isAcquireEntitlementRequire = !modelEntitlementPoolUuid.isEmpty() && !modelEntitlementPoolUuid.equals(aaiEntitlementPoolUuid);
83             boolean isReleaseEntitlementRequire = !aaiEntitlementPoolUuid.isEmpty() && (isAcquireEntitlementRequire || modelEntitlementPoolUuid.isEmpty());
84             boolean isAAIEntitlementUpdateRequire = isAcquireEntitlementRequire || isReleaseEntitlementRequire;
85             ctx.setAttribute(Constants.MODEL_ENTITLMENT_POOL_UUID_NAME, modelEntitlementPoolUuid);
86             ctx.setAttribute(Constants.IS_ACQUIRE_ENTITLEMENT_REQUIRE, Boolean.toString(isAcquireEntitlementRequire));
87             ctx.setAttribute(Constants.IS_RELEASE_ENTITLEMENT_REQUIRE, Boolean.toString(isReleaseEntitlementRequire));
88             ctx.setAttribute(Constants.IS_AAI_ENTITLEMENT_UPDATE_REQUIRE, Boolean.toString(isAAIEntitlementUpdateRequire));
89
90
91             String modelLicenseKeyGroupUuid = licenseModel.getLicenseKeyGroupUuid(); if (null == modelLicenseKeyGroupUuid) modelLicenseKeyGroupUuid = "";
92             String aaiLicenseKeyGroupUuid = ctx.getAttribute(Constants.AAI_LICENSE_KEY_UUID_NAME); if (null == aaiLicenseKeyGroupUuid) aaiLicenseKeyGroupUuid = "";
93             String aaiLicenseKeyValue = ctx.getAttribute(Constants.AAI_LICENSE_KEY_VALUE); if (null == aaiLicenseKeyValue) aaiLicenseKeyValue = "";
94             boolean isAcquireLicenseRequire = !modelLicenseKeyGroupUuid.isEmpty() && !modelLicenseKeyGroupUuid.equals(aaiLicenseKeyGroupUuid);
95             boolean isReleaseLicenseRequire = !aaiLicenseKeyGroupUuid.isEmpty() && (isAcquireLicenseRequire || modelLicenseKeyGroupUuid.isEmpty());
96             boolean isAAILicenseUpdateRequire = isAcquireLicenseRequire || isReleaseLicenseRequire;
97             ctx.setAttribute(Constants.MODEL_LICENSE_KEY_UUID_NAME, modelLicenseKeyGroupUuid);
98             ctx.setAttribute(Constants.IS_ACQUIRE_LICENSE_REQUIRE, Boolean.toString(isAcquireLicenseRequire));
99             ctx.setAttribute(Constants.IS_RELEASE_LICENSE_REQUIRE, Boolean.toString(isReleaseLicenseRequire));
100             ctx.setAttribute(Constants.IS_AAI_LICENSE_UPDATE_REQUIRE, Boolean.toString(isAAILicenseUpdateRequire));
101
102             ctx.setAttribute("license-key", aaiLicenseKeyValue);
103
104         } catch (DataAccessException le) {
105             logger.error("Error " + le.getMessage());
106             ctx.setAttribute("output.status.message", le.getMessage());
107             throw new APPCException(le);
108         }
109
110     }
111
112
113
114     //////// code uses jaxb license model, should be fixed
115     /*
116     final VfLicenseModel.FeatureGroupList featureGroupList = licenseModel.getFeatureGroupList();
117     if (null != featureGroupList) {
118         final VfLicenseModel.FeatureGroupList.FeatureGroup featureGroup = featureGroupList.getFeatureGroup();
119         if (null != featureGroup) {
120             final VfLicenseModel.FeatureGroupList.FeatureGroup.EntitlementPoolList
121                             entitlementPoolList = featureGroup.getEntitlementPoolList();
122             if (null != entitlementPoolList) {
123                 final VfLicenseModel.FeatureGroupList.FeatureGroup.EntitlementPoolList.EntitlementPool
124                                 entitlementPool = entitlementPoolList.getEntitlementPool();
125                 if (null != entitlementPool) {
126                     final String entitlementPoolUuid = entitlementPool.getEntitlementPoolUuid();
127                     // add entitlementPoolUuid into context
128                     ctx.setAttribute(Constants.MODEL_ENTITLMENT_POOL_UUID_NAME, entitlementPoolUuid);
129                 }
130             }
131
132             final VfLicenseModel.FeatureGroupList.FeatureGroup.LicenseKeyGroupList
133                             licenseKeyGroupList = featureGroup.getLicenseKeyGroupList();
134             if (null != licenseKeyGroupList) {
135                 final VfLicenseModel.FeatureGroupList.FeatureGroup.LicenseKeyGroupList.LicenseKeyGroup
136                                 licenseKeyGroup = licenseKeyGroupList.getLicenseKeyGroup();
137                 if (null != licenseKeyGroup) {
138                     final String licenseKeyGroupUuid = licenseKeyGroup.getLicenseKeyGroupUuid();
139                     // add licenseKeyGroupUuid into context
140                     ctx.setAttribute(Constants.MODEL_LICENSE_KEY_UUID_NAME, licenseKeyGroupUuid);
141                 }
142             }
143         }
144     }
145     */
146
147
148 }