Remove RESTCONF client dependency on YMS and reinstall BUCK files

Change-Id: Icd6f4cb73a95044cfbd3fa938070c29d26c7cbe1
This commit is contained in:
Henry Yu 2017-05-12 15:07:35 -04:00 committed by Andrea Campanella
parent b25fcb4de1
commit c44787ad42
7 changed files with 31 additions and 166 deletions

View File

@ -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',

View File

@ -42,9 +42,7 @@
<module>snmp</module>
<module>bmv2</module>
<module>lisp</module>
<!-- This currently does not work
<module>restconf</module>
-->
<module>tl1</module>
</modules>

View File

@ -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,
)

View File

@ -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,
)

View File

@ -67,23 +67,6 @@
<version>${project.version}</version>
<type>bundle</type>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-restconf-server-utils</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-app-yms-api</artifactId>
<version>${project.version}</version>
<type>bundle</type>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-ietfte-provider-utils</artifactId>
<version>${project.version}</version>
<type>bundle</type>
</dependency>
</dependencies>
<build>

View File

@ -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;
}
}

View File

@ -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<DeviceId, GetChunksRunnable> 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