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