ade2cbb1624e912ee6db7ade39e427f798b34d72
[appc.git] / appc-dg / appc-dg-shared / appc-dg-common / src / main / java / org / onap / appc / dg / common / impl / DgResolverPluginImpl.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.common.impl;
26
27 import com.att.eelf.i18n.EELFResourceManager;
28 import java.util.Map;
29 import org.onap.appc.dg.common.DgResolverPlugin;
30 import org.onap.appc.exceptions.APPCException;
31 import org.onap.appc.i18n.Msg;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
33
34 public class DgResolverPluginImpl implements DgResolverPlugin {
35
36     private static final String PARAM_DG_RESOLUTION_TYPE = "DGResolutionType";
37
38     @Override
39     public void resolveDg(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
40
41         String dgName;
42         String dgVersion;
43         String dgModule;
44
45         String prefix = params.containsKey("prefix") ? params.get("prefix") + "." : "";
46         AbstractResolver resolver = ResolverFactory.createResolver(params.get(PARAM_DG_RESOLUTION_TYPE));
47         FlowKey flowKey = null;
48         try {
49             if (resolver == null)
50                 throw new DgResolverException("Couldn't create resolver of type: " + PARAM_DG_RESOLUTION_TYPE);
51
52             if ("VNFC".equalsIgnoreCase(params.get(PARAM_DG_RESOLUTION_TYPE))) {
53                 flowKey = resolver
54                     .resolve(params.get(Constants.IN_PARAM_ACTION), params.get(Constants.IN_PARAM_VNF_TYPE),
55                         params.get(Constants.IN_PARAM_VNFC_TYPE), params.get(Constants.IN_PARAM_API_VERSION));
56             } else if ("VNF".equalsIgnoreCase(params.get(PARAM_DG_RESOLUTION_TYPE))) {
57                 flowKey = resolver
58                     .resolve(params.get(Constants.IN_PARAM_ACTION), params.get(Constants.IN_PARAM_VNF_TYPE),
59                         params.get("vnfVersion"), params.get(Constants.IN_PARAM_API_VERSION));
60             }
61             if (flowKey != null) {
62                 dgName = flowKey.name();
63                 ctx.setAttribute(prefix + Constants.OUT_PARAM_DG_NAME, dgName);
64                 dgVersion = flowKey.version();
65                 ctx.setAttribute(prefix + Constants.OUT_PARAM_DG_VERSION, dgVersion);
66                 dgModule = flowKey.module();
67                 ctx.setAttribute(prefix + Constants.OUT_PARAM_DG_MODULE, dgModule);
68             } else {
69                 throw new DgResolverException(params.get(PARAM_DG_RESOLUTION_TYPE) + " DG not found for vnf type :" + params
70                     .get(Constants.IN_PARAM_VNF_TYPE)
71                     + " vnfc type : " + params.get(Constants.IN_PARAM_VNFC_TYPE)
72                     + " action : " + params.get(Constants.IN_PARAM_ACTION)
73                     + " api version : " + params.get(Constants.IN_PARAM_API_VERSION));
74             }
75         } catch (Exception e) {
76             String msg = EELFResourceManager
77                 .format(Msg.FAILURE_RETRIEVE_VNFC_DG, params.get(Constants.IN_PARAM_VNFC_TYPE), e.getMessage());
78             ctx.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, msg);
79             throw new DgResolverException(e);
80         }
81     }
82 }