958fceccd8c13d9e33f7adb2a9b9b8b7af597ce9
[appc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * APPC
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
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
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.
21  */
22
23 package org.openecomp.appc.dg.licmgr.impl;
24
25 import java.util.Map;
26
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;
36
37
38
39 public class LicenseManagerPluginImpl implements LicenseManagerPlugin {
40
41     private static EELFLogger logger = EELFManager.getInstance().getApplicationLogger();
42
43     // populated by blueprint framework
44     private LicenseManager licenseManager;
45
46     public void setLicenseManager(LicenseManager licenseManager) {
47         this.licenseManager = licenseManager;
48     }
49
50     /**
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
68      *
69      * @throws APPCException throws in case of any error
70      */
71     @Override
72     public void retrieveLicenseModel(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
73
74         try {
75
76             LicenseModel licenseModel = licenseManager.retrieveLicenseModel(params.get(Constants.VNF_TYPE_FIELD_NAME), params.get(Constants.VNF_RESOURCE_VERSION_FIELD_NAME));
77
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));
87
88
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));
99
100             ctx.setAttribute("license-key", aaiLicenseKeyValue);
101
102         } catch (DataAccessException le) {
103             logger.error("Error " + le.getMessage());
104             ctx.setAttribute("output.status.message", le.getMessage());
105             throw new APPCException(le);
106         }
107
108     }
109
110
111
112     //////// code uses jaxb license model, should be fixed
113     /*
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);
127                 }
128             }
129
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);
139                 }
140             }
141         }
142     }
143     */
144
145
146 }