2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.ccsdk.sli.adaptors.resource.mdsal;
24 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
25 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
26 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29 import org.w3c.dom.Document;
32 import java.util.Properties;
34 public class OperationalResource implements SvcLogicResource {
36 private static final Logger LOG = LoggerFactory.getLogger(OperationalResource.class);
38 private RestService restService;
40 public OperationalResource(MdsalResourcePropertiesProvider propProvider) {
41 Properties props = propProvider.getProperties();
43 String sdncUser = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-user", "admin");
44 String sdncPasswd = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-passwd", "admin");
45 String sdncHost = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-host", "localhost");
46 String sdncProtocol = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-protocol", "https");
47 String sdncPort = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-port", "8443");
49 restService = new RestService(sdncProtocol, sdncHost, sdncPort, sdncUser, sdncPasswd, "XML", "XML");
52 public OperationalResource(String sdncProtocol, String sdncHost, String sdncPort, String sdncUser, String sdncPasswd) {
53 restService = new RestService(sdncProtocol, sdncHost, sdncPort, sdncUser, sdncPasswd, "XML", "XML");
56 public OperationalResource(RestService restService) {
57 this.restService = restService;
61 public QueryStatus isAvailable(String resource, String key, String prefix, SvcLogicContext ctx) throws SvcLogicException {
62 return (query(resource, false, null, key, prefix, null, null));
66 public QueryStatus exists(String resource, String key, String prefix, SvcLogicContext ctx) throws SvcLogicException {
67 return (query(resource, false, null, key, prefix, null, null));
71 public QueryStatus query(String resource, boolean localOnly, String select, String key, String prefix,
72 String orderBy, SvcLogicContext ctx) throws SvcLogicException {
73 String module = resource;
74 StringBuffer restQuery = new StringBuffer();
76 String[] keyParts = key.split("/");
77 for (String keyPart : keyParts) {
78 if (restQuery.length() > 0) {
79 restQuery.append("/");
81 if (keyPart.startsWith("$")) {
82 restQuery.append(ctx.resolve(keyPart.substring(1)));
84 restQuery.append(keyPart);
88 String restQueryStr = restQuery.toString();
89 if ((restQueryStr.startsWith("'") && restQueryStr.endsWith("'")) ||
90 (restQueryStr.startsWith("\"") && restQueryStr.endsWith("\""))) {
91 restQueryStr = restQueryStr.substring(1, restQueryStr.length() - 1);
94 String urlString = "restconf/operational/" + module + ":" + restQueryStr;
95 LOG.info("Querying resource: " + resource + ". At URL: " + urlString);
97 Document results = restService.get(urlString);
99 if (results == null) {
100 return (QueryStatus.NOT_FOUND);
103 ctx.mergeDocument(prefix, results);
105 return (QueryStatus.SUCCESS);
110 public QueryStatus reserve(String resource, String select, String key, String prefix,
111 SvcLogicContext ctx) throws SvcLogicException {
112 return (QueryStatus.SUCCESS);
116 public QueryStatus release(String resource, String key, SvcLogicContext ctx) throws SvcLogicException {
117 return (QueryStatus.SUCCESS);
121 public QueryStatus delete(String arg0, String arg1, SvcLogicContext arg2)
122 throws SvcLogicException {
123 // TODO Auto-generated method stub
124 return (QueryStatus.SUCCESS);
128 public QueryStatus save(String arg0, boolean arg1, boolean localOnly, String arg2,
129 Map<String, String> arg3, String arg4, SvcLogicContext arg5)
130 throws SvcLogicException {
131 // TODO Auto-generated method stub
132 return (QueryStatus.SUCCESS);
136 public QueryStatus notify(String resource, String action, String key,
137 SvcLogicContext ctx) throws SvcLogicException {
138 return (QueryStatus.SUCCESS);
141 public QueryStatus update(String resource, String key,
142 Map<String, String> parms, String prefix, SvcLogicContext ctx)
143 throws SvcLogicException {
144 return (QueryStatus.SUCCESS);