Merge "RAN Slice YANG Model and Associated Feature code"
[ccsdk/features.git] / sdnr / northbound / ranSlice / provider / src / main / java / org / onap / ccsdk / features / sdnr / northbound / ranSlice / RANSliceClient.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                      reserved.
7  * Modifications Copyright © 2018 IBM.
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  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.ccsdk.features.sdnr.northbound.ranSlice;
24
25
26 import java.util.Properties;
27
28 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
29 import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService;
30 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 public class RANSliceClient {
35
36         private static final Logger LOG = LoggerFactory.getLogger(RANSliceClient.class);
37
38         private final SvcLogicService svcLogicService;
39
40         private String ErrorCode = "error-code";
41
42         public RANSliceClient(final SvcLogicService svcLogicService) {
43                 this.svcLogicService = svcLogicService;
44         }
45
46         public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException
47         {
48                 return svcLogicService.hasGraph(module, rpc, version, mode);
49         }
50
51
52         public Properties execute(String module, String rpc, String version, String mode, Properties parms, DOMDataBroker dataBroker)
53                                 throws SvcLogicException {
54
55
56                 if (LOG.isDebugEnabled())
57                 {
58                         LOG.debug("Parameters passed to SLI");
59
60                         for (Object key : parms.keySet()) {
61                                 String parmName = (String) key;
62                                 String parmValue = parms.getProperty(parmName);
63
64                                 LOG.debug(parmName+" = "+parmValue);
65
66                         }
67                 }
68
69                 Properties respProps = svcLogicService.execute(module, rpc, version, mode, parms, dataBroker);
70
71                 if (LOG.isDebugEnabled())
72                 {
73                         LOG.debug("Parameters returned by SLI");
74
75                         for (Object key : respProps.keySet()) {
76                                 String parmName = (String) key;
77                                 String parmValue = respProps.getProperty(parmName);
78
79                                 LOG.debug(parmName+" = "+parmValue);
80
81                         }
82                 }
83
84                 if ("failure".equalsIgnoreCase(respProps.getProperty("SvcLogic.status"))) {
85
86                         if (!respProps.containsKey(ErrorCode)) {
87                                 respProps.setProperty(ErrorCode, "500");
88                         }
89                 } else {
90                         if (!respProps.containsKey(ErrorCode)) {
91                                 respProps.setProperty(ErrorCode, "200");
92                         }
93                 }
94
95
96                 return respProps;
97         }
98
99 }