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