fb21de4cd9941661bec76bdcec5831f5281dbc5d
[ccsdk/oran.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020 Nordix Foundation.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.ccsdk.features.a1.adapter;
22
23 import java.util.Properties;
24 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
25 import org.onap.ccsdk.sli.core.sli.provider.MdsalHelper;
26 import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService;
27 import org.opendaylight.yang.gen.v1.org.onap.a1.adapter.rev200122.GetA1PolicyTypeOutputBuilder;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 public class A1AdapterClient {
32
33   private static final Logger LOG = LoggerFactory.getLogger(A1AdapterClient.class);
34
35   private SvcLogicService svcLogicService = null;
36
37   public A1AdapterClient(final SvcLogicService svcLogicService) {
38     this.svcLogicService = svcLogicService;
39   }
40
41   public boolean hasGraph(String module, String rpc, String version, String mode)
42       throws SvcLogicException {
43     return svcLogicService.hasGraph(module, rpc, version, mode);
44   }
45
46   public Properties execute(String module, String rpc, String version, String mode,
47       GetA1PolicyTypeOutputBuilder serviceData, Properties parms) throws SvcLogicException {
48     Properties localProp;
49     localProp = MdsalHelper.toProperties(parms, serviceData);
50     if (LOG.isDebugEnabled()) {
51       LOG.debug("Parameters passed to SLI");
52
53       for (Object key : localProp.keySet()) {
54         String parmName = (String) key;
55         String parmValue = localProp.getProperty(parmName);
56
57         LOG.debug(parmName + " = " + parmValue);
58       }
59     }
60     Properties respProps = svcLogicService.execute(module, rpc, version, mode, localProp);
61     if (LOG.isDebugEnabled()) {
62       LOG.debug("Parameters returned by SLI");
63       for (Object key : respProps.keySet()) {
64         String parmName = (String) key;
65         String parmValue = respProps.getProperty(parmName);
66         LOG.debug(parmName + " = " + parmValue);
67       }
68     }
69     if ("failure".equalsIgnoreCase(respProps.getProperty("SvcLogic.status"))) {
70       return respProps;
71     }
72     MdsalHelper.toBuilder(respProps, serviceData);
73     return respProps;
74   }
75 }