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;
26 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
27 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
28 import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
29 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.w3c.dom.Document;
34 public class OperationalResource implements SvcLogicResource {
36 private static final Logger LOG = LoggerFactory.getLogger(OperationalResource.class);
38 private RestService restService;
40 public OperationalResource(String sdncProtocol, String sdncHost, String sdncPort, String sdncUser, String sdncPasswd)
42 restService = new RestService(sdncProtocol, sdncHost, sdncPort, sdncUser, sdncPasswd, RestService.PayloadType.XML);
48 public QueryStatus isAvailable(String resource, String key, String prefix, SvcLogicContext ctx) throws SvcLogicException
50 return(query(resource, false, null, key, prefix, null, null));
54 public QueryStatus exists(String resource, String key, String prefix, SvcLogicContext ctx) throws SvcLogicException
57 return(query(resource, false, null, key, prefix, null, null));
62 public QueryStatus query(String resource, boolean localOnly, String select, String key, String prefix,
63 String orderBy, SvcLogicContext ctx) throws SvcLogicException {
66 String module = resource;
67 StringBuffer restQuery = new StringBuffer();
69 String[] keyParts = key.split("/");
71 for (String keyPart : keyParts) {
72 if (restQuery.length() > 0) {
73 restQuery.append("/");
75 if (keyPart.startsWith("$")) {
77 restQuery.append(ctx.resolve(keyPart.substring(1)));
79 restQuery.append(keyPart);
83 String restQueryStr = restQuery.toString();
84 if ((restQueryStr.startsWith("'") && restQueryStr.endsWith("'")) ||
85 (restQueryStr.startsWith("\"") && restQueryStr.endsWith("\""))) {
86 restQueryStr = restQueryStr.substring(1, restQueryStr.length()-1);
89 String urlString = "restconf/operational/" + module + ":" + restQueryStr;
91 LOG.info("Querying resource: " + resource + ". At URL: " + urlString);
93 Document results = restService.get(urlString);
96 if (results == null) {
97 return(QueryStatus.NOT_FOUND);
101 ctx.mergeDocument(prefix, results);
103 return(QueryStatus.SUCCESS);
109 public QueryStatus reserve(String resource, String select, String key, String prefix,
110 SvcLogicContext ctx) throws SvcLogicException {
113 return(QueryStatus.SUCCESS);
118 public QueryStatus release(String resource, String key, SvcLogicContext ctx) throws SvcLogicException {
120 return(QueryStatus.SUCCESS);
124 public QueryStatus delete(String arg0, String arg1, SvcLogicContext arg2)
125 throws SvcLogicException {
126 // TODO Auto-generated method stub
127 return(QueryStatus.SUCCESS);
131 public QueryStatus save(String arg0, boolean arg1, boolean localOnly, String arg2,
132 Map<String, String> arg3, String arg4, SvcLogicContext arg5)
133 throws SvcLogicException {
134 // TODO Auto-generated method stub
135 return(QueryStatus.SUCCESS);
139 public QueryStatus notify(String resource, String action, String key,
140 SvcLogicContext ctx) throws SvcLogicException {
141 return(QueryStatus.SUCCESS);
144 public QueryStatus update(String resource, String key,
145 Map<String, String> parms, String prefix, SvcLogicContext ctx)
146 throws SvcLogicException {
147 return(QueryStatus.SUCCESS);