optical-service package added for service create
[sdnc/northbound.git] / optical-service / provider / src / main / java / org / onap / sdnc / northbound / OpticalServiceClient.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2019-2020 Fujitsu Limited 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.onap.sdnc.northbound;
23
24 import java.util.Properties;
25
26 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
27 import org.onap.ccsdk.sli.core.sli.provider.MdsalHelper;
28 import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService;
29 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.optical.service.rev191206.OpticalServiceCreateOutputBuilder;
30 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.optical.service.rev191206.OpticalServiceDeleteOutputBuilder;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 public class OpticalServiceClient {
35
36         private static final Logger LOG = LoggerFactory.getLogger(OpticalServiceClient.class);
37
38         private SvcLogicService svcLogicService = null;
39
40         public OpticalServiceClient(final SvcLogicService svcLogicService) {
41                 this.svcLogicService = svcLogicService;
42         }
43
44         public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException {
45                 return svcLogicService.hasGraph(module, rpc, version, mode);
46         }
47
48         public Properties execute(String module, String rpc, String version, String mode,
49                         OpticalServiceCreateOutputBuilder serviceData) throws SvcLogicException {
50
51                 Properties parms = new Properties();
52
53                 return execute(module, rpc, version, mode, serviceData, parms);
54         }
55
56         public Properties execute(String module, String rpc, String version, String mode,
57                         OpticalServiceCreateOutputBuilder serviceData, Properties parms) throws SvcLogicException {
58
59                 Properties localProp;
60                 localProp = MdsalHelper.toProperties(parms, serviceData);
61
62                 if (LOG.isDebugEnabled()) {
63                         LOG.debug("Parameters passed to SLI");
64
65                         for (Object key : localProp.keySet()) {
66                                 String parmName = (String) key;
67                                 String parmValue = localProp.getProperty(parmName);
68
69                                 LOG.debug(parmName + " = " + parmValue);
70
71                         }
72                 }
73
74                 Properties respProps = svcLogicService.execute(module, rpc, version, mode, localProp);
75
76                 if (LOG.isDebugEnabled()) {
77                         LOG.debug("Parameters returned by SLI");
78
79                         for (Object key : respProps.keySet()) {
80                                 String parmName = (String) key;
81                                 String parmValue = respProps.getProperty(parmName);
82
83                                 LOG.debug(parmName + " = " + parmValue);
84
85                         }
86                 }
87                 if ("failure".equalsIgnoreCase(respProps.getProperty("SvcLogic.status"))) {
88                         return respProps;
89                 }
90
91                 MdsalHelper.toBuilder(respProps, serviceData);
92
93                 return respProps;
94         }
95
96         public Properties execute(String module, String rpc, String version, String mode,
97                         OpticalServiceDeleteOutputBuilder serviceData) throws SvcLogicException {
98
99                 Properties parms = new Properties();
100
101                 return execute(module, rpc, version, mode, serviceData, parms);
102         }
103
104         public Properties execute(String module, String rpc, String version, String mode,
105                         OpticalServiceDeleteOutputBuilder serviceData, Properties parms) throws SvcLogicException {
106
107                 Properties localProp;
108                 localProp = MdsalHelper.toProperties(parms, serviceData);
109
110                 if (LOG.isDebugEnabled()) {
111                         LOG.debug("Parameters passed to SLI");
112
113                         for (Object key : localProp.keySet()) {
114                                 String parmName = (String) key;
115                                 String parmValue = localProp.getProperty(parmName);
116
117                                 LOG.debug(parmName + " = " + parmValue);
118
119                         }
120                 }
121
122                 Properties respProps = svcLogicService.execute(module, rpc, version, mode, localProp);
123
124                 if (LOG.isDebugEnabled()) {
125                         LOG.debug("Parameters returned by SLI");
126
127                         for (Object key : respProps.keySet()) {
128                                 String parmName = (String) key;
129                                 String parmValue = respProps.getProperty(parmName);
130
131                                 LOG.debug(parmName + " = " + parmValue);
132
133                         }
134                 }
135                 if ("failure".equalsIgnoreCase(respProps.getProperty("SvcLogic.status"))) {
136                         return respProps;
137                 }
138
139                 MdsalHelper.toBuilder(respProps, serviceData);
140
141                 return respProps;
142         }
143
144 }