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;
25 import java.util.Properties;
27 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
28 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
29 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
30 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33 import org.w3c.dom.Document;
35 public class OperationalResource implements SvcLogicResource {
37 private static final Logger LOG = LoggerFactory.getLogger(OperationalResource.class);
39 private RestService restService;
41 public OperationalResource(MdsalResourcePropertiesProvider propProvider) {
42 Properties props = propProvider.getProperties();
44 String sdncUser = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-user", "admin");
45 String sdncPasswd = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-passwd", "admin");
46 String sdncHost = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-host", "localhost");
47 String sdncProtocol = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-protocol", "https");
48 String sdncPort = props.getProperty("org.onap.ccsdk.sli.adaptors.resource.mdsal.sdnc-port", "8443");
50 restService = new RestService(sdncProtocol, sdncHost, sdncPort, sdncUser, sdncPasswd, RestService.PayloadType.XML);
54 public OperationalResource(String sdncProtocol, String sdncHost, String sdncPort, String sdncUser, String sdncPasswd)
56 restService = new RestService(sdncProtocol, sdncHost, sdncPort, sdncUser, sdncPasswd, RestService.PayloadType.XML);
61 public OperationalResource(RestService restService) {
62 this.restService = restService;
66 public QueryStatus isAvailable(String resource, String key, String prefix, SvcLogicContext ctx) throws SvcLogicException
68 return(query(resource, false, null, key, prefix, null, null));
72 public QueryStatus exists(String resource, String key, String prefix, SvcLogicContext ctx) throws SvcLogicException
75 return(query(resource, false, null, key, prefix, null, null));
80 public QueryStatus query(String resource, boolean localOnly, String select, String key, String prefix,
81 String orderBy, SvcLogicContext ctx) throws SvcLogicException {
84 String module = resource;
85 StringBuffer restQuery = new StringBuffer();
87 String[] keyParts = key.split("/");
89 for (String keyPart : keyParts) {
90 if (restQuery.length() > 0) {
91 restQuery.append("/");
93 if (keyPart.startsWith("$")) {
95 restQuery.append(ctx.resolve(keyPart.substring(1)));
97 restQuery.append(keyPart);
101 String restQueryStr = restQuery.toString();
102 if ((restQueryStr.startsWith("'") && restQueryStr.endsWith("'")) ||
103 (restQueryStr.startsWith("\"") && restQueryStr.endsWith("\""))) {
104 restQueryStr = restQueryStr.substring(1, restQueryStr.length()-1);
107 String urlString = "restconf/operational/" + module + ":" + restQueryStr;
109 LOG.info("Querying resource: " + resource + ". At URL: " + urlString);
111 Document results = restService.get(urlString);
114 if (results == null) {
115 return(QueryStatus.NOT_FOUND);
119 ctx.mergeDocument(prefix, results);
121 return(QueryStatus.SUCCESS);
127 public QueryStatus reserve(String resource, String select, String key, String prefix,
128 SvcLogicContext ctx) throws SvcLogicException {
131 return(QueryStatus.SUCCESS);
136 public QueryStatus release(String resource, String key, SvcLogicContext ctx) throws SvcLogicException {
138 return(QueryStatus.SUCCESS);
142 public QueryStatus delete(String arg0, String arg1, SvcLogicContext arg2)
143 throws SvcLogicException {
144 // TODO Auto-generated method stub
145 return(QueryStatus.SUCCESS);
149 public QueryStatus save(String arg0, boolean arg1, boolean localOnly, String arg2,
150 Map<String, String> arg3, String arg4, SvcLogicContext arg5)
151 throws SvcLogicException {
152 // TODO Auto-generated method stub
153 return(QueryStatus.SUCCESS);
157 public QueryStatus notify(String resource, String action, String key,
158 SvcLogicContext ctx) throws SvcLogicException {
159 return(QueryStatus.SUCCESS);
162 public QueryStatus update(String resource, String key,
163 Map<String, String> parms, String prefix, SvcLogicContext ctx)
164 throws SvcLogicException {
165 return(QueryStatus.SUCCESS);