diff --git a/modules.defs b/modules.defs index 751ce70bec..e03e8f2a1e 100644 --- a/modules.defs +++ b/modules.defs @@ -55,8 +55,8 @@ CORE = UTILS + API + [ '//protocols/lisp/msg:onos-protocols-lisp-msg', '//protocols/tl1/api:onos-protocols-tl1-api', '//protocols/tl1/ctl:onos-protocols-tl1-ctl', -# '//protocols/restconf/client/api:onos-protocols-restconf-client-api', -# '//protocols/restconf/client/ctl:onos-protocols-restconf-client-ctl', + '//protocols/restconf/client/api:onos-protocols-restconf-client-api', + '//protocols/restconf/client/ctl:onos-protocols-restconf-client-ctl', '//drivers/utilities:onos-drivers-utilities', diff --git a/protocols/pom.xml b/protocols/pom.xml index 537d3d9a37..152a0aacff 100644 --- a/protocols/pom.xml +++ b/protocols/pom.xml @@ -42,9 +42,7 @@ snmp bmv2 lisp - tl1 diff --git a/protocols/restconf/client/api/BUCK b/protocols/restconf/client/api/BUCK new file mode 100644 index 0000000000..c1f3e2c1af --- /dev/null +++ b/protocols/restconf/client/api/BUCK @@ -0,0 +1,10 @@ +COMPILE_DEPS = [ + '//lib:CORE_DEPS', + '//incubator/api:onos-incubator-api', + '//utils/rest:onlab-rest', + '//protocols/rest/api:onos-protocols-rest-api', +] + +osgi_jar_with_tests ( + deps = COMPILE_DEPS, +) diff --git a/protocols/restconf/client/ctl/BUCK b/protocols/restconf/client/ctl/BUCK new file mode 100644 index 0000000000..ce0292e783 --- /dev/null +++ b/protocols/restconf/client/ctl/BUCK @@ -0,0 +1,19 @@ +COMPILE_DEPS = [ + '//lib:CORE_DEPS', + '//lib:jersey-client', + '//lib:jersey-common', + '//lib:httpclient-osgi', + '//lib:httpcore-osgi', + '//lib:javax.ws.rs-api', + '//lib:hk2-api', + '//lib:jersey-guava', + '//lib:aopalliance-repackaged', + '//lib:javax.inject', + '//protocols/restconf/client/api:onos-protocols-restconf-client-api', + '//protocols/rest/api:onos-protocols-rest-api', +] + +osgi_jar_with_tests ( + deps = COMPILE_DEPS, +) + diff --git a/protocols/restconf/client/ctl/pom.xml b/protocols/restconf/client/ctl/pom.xml index 159f58266b..c51054ba33 100644 --- a/protocols/restconf/client/ctl/pom.xml +++ b/protocols/restconf/client/ctl/pom.xml @@ -67,23 +67,6 @@ ${project.version} bundle - - org.onosproject - onos-restconf-server-utils - ${project.version} - - - org.onosproject - onos-app-yms-api - ${project.version} - bundle - - - org.onosproject - onos-ietfte-provider-utils - ${project.version} - bundle - diff --git a/protocols/restconf/client/ctl/src/main/java/org/onosproject/protocol/restconf/ctl/JsonYdtCodec.java b/protocols/restconf/client/ctl/src/main/java/org/onosproject/protocol/restconf/ctl/JsonYdtCodec.java deleted file mode 100644 index 6fda6cd0ce..0000000000 --- a/protocols/restconf/client/ctl/src/main/java/org/onosproject/protocol/restconf/ctl/JsonYdtCodec.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright 2016 Open Networking Laboratory - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onosproject.protocol.restconf.ctl; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; -import org.apache.commons.io.IOUtils; -import org.onosproject.protocol.restconf.server.utils.parser.json.ParserUtils; -import org.onosproject.provider.te.utils.YangCompositeEncodingImpl; -import org.onosproject.yms.ych.YangCompositeEncoding; -import org.onosproject.yms.ych.YangDataTreeCodec; -import org.onosproject.yms.ych.YangResourceIdentifierType; -import org.onosproject.yms.ydt.YdtBuilder; -import org.onosproject.yms.ydt.YdtContext; -import org.onosproject.yms.ydt.YmsOperationType; -import org.onosproject.yms.ymsm.YmsService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.io.InputStream; - -import static org.onosproject.protocol.restconf.server.utils.parser.json.ParserUtils.convertYdtToJson; -import static org.onosproject.protocol.restconf.server.utils.parser.json.ParserUtils.findTopNodeInCompositeYdt; -import static org.onosproject.protocol.restconf.server.utils.parser.json.ParserUtils.getJsonNameFromYdtNode; -import static org.onosproject.protocol.restconf.server.utils.parser.json.ParserUtils.getUriInCompositeYdt; -import static org.onosproject.yms.ydt.YdtContextOperationType.NONE; - - -/** - * JSON/YDT Codec implementation. - */ -public class JsonYdtCodec implements YangDataTreeCodec { - private static final String RESTCONF_ROOT = "restconf/data"; - private static final String EMPTY_JSON_OBJECT = "{}"; - - protected final YmsService ymsService; - - private final Logger log = LoggerFactory.getLogger(getClass()); - - public JsonYdtCodec(YmsService service) { - ymsService = service; - } - - @Override - public String encodeYdtToProtocolFormat(YdtBuilder builder) { - return convertYdtToJson(getJsonNameFromYdtNode(builder.getRootNode()), - builder.getRootNode(), - ymsService.getYdtWalker()).textValue(); - } - - @Override - public YangCompositeEncoding encodeYdtToCompositeProtocolFormat(YdtBuilder builder) { - String uriString = getUriInCompositeYdt(builder); - YdtContext topNode = findTopNodeInCompositeYdt(builder); - if (topNode != null) { - ObjectNode objectNode = convertYdtToJson(getJsonNameFromYdtNode(topNode), - topNode, - ymsService.getYdtWalker()); - return new YangCompositeEncodingImpl(YangResourceIdentifierType.URI, - uriString, - objectNode.toString()); - } - - return new YangCompositeEncodingImpl(YangResourceIdentifierType.URI, - uriString, - EMPTY_JSON_OBJECT); - } - - @Override - public YdtBuilder decodeProtocolDataToYdt(String protocolData, - Object schemaRegistryForYdt, - YmsOperationType opType) { - // Get a new builder - YdtBuilder builder = ymsService.getYdtBuilder(RESTCONF_ROOT, - null, - opType, - schemaRegistryForYdt); - ParserUtils.convertJsonToYdt(getObjectNode(protocolData), builder); - return builder; - } - - @Override - public YdtBuilder decodeCompositeProtocolDataToYdt(YangCompositeEncoding protocolData, - Object schemaRegistryForYdt, - YmsOperationType opType) { - // opType should be QUERY_REPLY - // Get a new builder - YdtBuilder builder = ymsService.getYdtBuilder(RESTCONF_ROOT, - null, - opType, - schemaRegistryForYdt); - // Convert the URI to ydtBuilder - - // YdtContextOperationType should be NONE for URI in QUERY_RESPONSE. - ParserUtils.convertUriToYdt(protocolData.getResourceIdentifier(), builder, NONE); - // Set default operation type for the payload node, is this for resource data? - // NULL/EMPTY for Resource data - builder.setDefaultEditOperationType(null); - - // Convert the payload json body to ydt - ParserUtils.convertJsonToYdt(getObjectNode(protocolData.getResourceInformation()), builder); - return builder; - } - - // Returns an ObjectNode from s JSON string. - private ObjectNode getObjectNode(String json) { - InputStream stream = IOUtils.toInputStream(json); - - ObjectNode rootNode; - ObjectMapper mapper = new ObjectMapper(); - try { - rootNode = (ObjectNode) mapper.readTree(stream); - } catch (IOException e) { - log.error("Can't read stream as a JSON ObjectNode: {}", e); - return null; - } - return rootNode; - } -} diff --git a/protocols/restconf/client/ctl/src/main/java/org/onosproject/protocol/restconf/ctl/RestConfSBControllerImpl.java b/protocols/restconf/client/ctl/src/main/java/org/onosproject/protocol/restconf/ctl/RestConfSBControllerImpl.java index 897f6c7b98..1d812b571a 100644 --- a/protocols/restconf/client/ctl/src/main/java/org/onosproject/protocol/restconf/ctl/RestConfSBControllerImpl.java +++ b/protocols/restconf/client/ctl/src/main/java/org/onosproject/protocol/restconf/ctl/RestConfSBControllerImpl.java @@ -18,8 +18,6 @@ package org.onosproject.protocol.restconf.ctl; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Deactivate; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.ReferenceCardinality; import org.apache.felix.scr.annotations.Service; import org.glassfish.jersey.client.ChunkedInput; import org.onlab.packet.IpAddress; @@ -28,8 +26,6 @@ import org.onosproject.protocol.http.ctl.HttpSBControllerImpl; import org.onosproject.protocol.rest.RestSBDevice; import org.onosproject.protocol.restconf.RestConfSBController; import org.onosproject.protocol.restconf.RestconfNotificationEventListener; -import org.onosproject.yms.ych.YangProtocolEncodingFormat; -import org.onosproject.yms.ymsm.YmsService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -67,19 +63,11 @@ public class RestConfSBControllerImpl extends HttpSBControllerImpl restconfNotificationListenerMap = new ConcurrentHashMap<>(); private Map runnableTable = new ConcurrentHashMap<>(); - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected YmsService ymsService; - ExecutorService executor = Executors.newCachedThreadPool(); @Activate public void activate() { log.info("RESTCONF SBI Started"); - if (ymsService != null) { - ymsService - .registerDefaultCodec(new JsonYdtCodec(ymsService), - YangProtocolEncodingFormat.JSON); - } } @Deactivate