Merge of new rebased code
[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  * openECOMP : APP-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
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  */
21
22 package org.openecomp.appc.dg.common.impl;
23
24 import org.openecomp.appc.exceptions.APPCException;
25 import org.openecomp.appc.i18n.Msg;
26 import com.att.eelf.i18n.EELFResourceManager;
27 import org.openecomp.sdnc.sli.SvcLogicContext;
28
29 import java.util.Map;
30
31 import org.openecomp.appc.dg.common.DgResolverPlugin;
32
33 public class DgResolverPluginImpl implements DgResolverPlugin {
34
35     @Override
36     public void resolveDg(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
37
38         String DGName, DGVersion, DGModule = null;
39         String prefix = params.containsKey("prefix") ? params.get("prefix") + "." : "";
40         AbstractResolver resolver = ResolverFactory.createResolver(params.get("DGResolutionType"));
41         FlowKey flowKey = null;
42         try {
43
44             if(params.get("DGResolutionType").equalsIgnoreCase("VNFC")) {
45                  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));
46             }else if(params.get("DGResolutionType").equalsIgnoreCase("VNF")){
47                  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));
48             }
49             if (flowKey != null) {
50                 DGName = flowKey.name();
51                 ctx.setAttribute(prefix + Constants.OUT_PARAM_DG_NAME, DGName);
52                 DGVersion = flowKey.version();
53                 ctx.setAttribute(prefix + Constants.OUT_PARAM_DG_VERSION, DGVersion);
54                 DGModule = flowKey.module();
55                 ctx.setAttribute(prefix + Constants.OUT_PARAM_DG_MODULE, DGModule);
56             } else {
57                 throw new RuntimeException(params.get("DGResolutionType")+ " DG not found for vnf type :" + params.get(Constants.IN_PARAM_VNF_TYPE)
58                         + " vnfc type : " + params.get(Constants.IN_PARAM_VNFC_TYPE)
59                         + " action : " + params.get(Constants.IN_PARAM_ACTION)
60                         + " api version : " + params.get(Constants.IN_PARAM_API_VERSION));
61             }
62         } catch (Exception e) {
63             String msg = EELFResourceManager.format(Msg.FAILURE_RETRIEVE_VNFC_DG,params.get(Constants.IN_PARAM_VNFC_TYPE), e.getMessage());
64             ctx.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE,msg);
65             throw new RuntimeException(e);
66         }
67     }
68 }