<type>xml</type>
<classifier>configrestconfservice</classifier>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.netconf</groupId>
+ <artifactId>sal-rest-connector-config</artifactId>
+ <version>${project.version}</version>
+ <type>cfg</type>
+ <classifier>restconf</classifier>
+ </dependency>
</dependencies>
</project>
-->
<features name="odl-controller-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.2.0">
<feature name="odl-restconf-noauth" version="${project.version}">
- <configfile finalname="${config.configfile.directory}/${config.restconf.configfile}">
+ <configfile finalname="${config.configfile.directory}/${config.restconf.configfile}" override="true">
mvn:org.opendaylight.netconf/sal-rest-connector-config/${project.version}/xml/config
</configfile>
<configfile finalname="${config.configfile.directory}/${config.restconf.service.configfile}">
mvn:org.opendaylight.netconf/sal-rest-connector-config/${project.version}/xml/configrestconfservice
</configfile>
+ <configfile finalname="etc/org.opendaylight.restconf.cfg">
+ mvn:org.opendaylight.netconf/sal-rest-connector-config/${project.version}/cfg/restconf
+ </configfile>
</feature>
</features>
<type>xml</type>
<classifier>configrestconfservice</classifier>
</artifact>
+ <artifact>
+ <file>${project.build.directory}/classes/initial/restconf.cfg</file>
+ <type>cfg</type>
+ <classifier>restconf</classifier>
+ </artifact>
</artifacts>
</configuration>
</execution>
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v1.0 which accompanies this distribution,
and is available at http://www.eclipse.org/legal/epl-v10.html
+
+NOTE: This file is deprecated as wiring is now done via blueprint. This file is kept for backwards
+ compatibility and runtime modifications will not be honored.
-->
<snapshot>
<configuration>
<module>
<type xmlns:rest="urn:opendaylight:params:xml:ns:yang:controller:md:sal:rest:connector">rest:rest-connector-impl</type>
<name>rest-connector-default-impl</name>
- <websocket-port>8185</websocket-port>
- <dom-broker>
- <type xmlns:dom="urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom">dom:dom-broker-osgi-registry</type>
- <name>dom-broker</name>
- </dom-broker>
</module>
</modules>
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v1.0 which accompanies this distribution,
and is available at http://www.eclipse.org/legal/epl-v10.html
+
+NOTE: This file is deprecated as wiring is now done via blueprint. This file is kept for backwards
+ compatibility and runtime modifications will not be honored.
-->
<snapshot>
<configuration>
--- /dev/null
+# The port for the web socket server.
+#websocket-port=8185
<Private-Package>org.opendaylight.netconf.sal.rest.*,
org.opendaylight.restconf.*,
org.opendaylight.netconf.sal.restconf.rpc.*,
- org.opendaylight.netconf.sal.restconf.impl,
+ org.opendaylight.netconf.sal.restconf.impl.*,
org.opendaylight.netconf.md.sal.rest.common.*,
org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.rest.connector.rev140724.*,
</Private-Package>
org.opendaylight.aaa.shiro.realm,
org.opendaylight.aaa.shiro.web.env,
org.opendaylight.aaa.filterchain.filters,
+ org.opendaylight.aaa.api,
org.apache.shiro.web.env
</Import-Package>
<Web-ContextPath>/restconf</Web-ContextPath>
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight;
-
-import org.opendaylight.controller.config.yang.md.sal.rest.connector.RestConnectorRuntimeRegistration;
-import org.opendaylight.controller.config.yang.md.sal.rest.connector.RestConnectorRuntimeRegistrator;
-import org.opendaylight.controller.sal.core.api.Broker;
-import org.opendaylight.netconf.sal.rest.api.RestConnector;
-import org.opendaylight.netconf.sal.restconf.impl.RestconfProviderImpl;
-import org.opendaylight.restconf.RestConnectorProvider;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
-
-/**
- * Wrapping providers from restconf draft02 and draft18.
- *
- */
-public class RestconfWrapperProviders implements AutoCloseable, RestConnector {
-
- // DRAFT02
- private final RestconfProviderImpl providerDraft02;
- // DRAFT18
- private final RestConnectorProvider providerDraft18;
-
- /**
- * Init both providers.
- * <ul>
- * <li>draft02 - {@link RestconfProviderImpl}
- * <li>draft18 - {@link RestConnectorProvider}
- * </ul>
- *
- * @param port port for web sockets in provider for draft02
- */
- public RestconfWrapperProviders(final PortNumber port) {
- // Init draft02 provider
- this.providerDraft02 = new RestconfProviderImpl();
- this.providerDraft02.setWebsocketPort(port);
-
- this.providerDraft18 = new RestConnectorProvider();
- }
-
- /**
- * Register both providers, which will use the SAL layer.
- * <ul>
- * <li>draft02 - {@link RestconfProviderImpl}
- * <li>draft18 - {@link RestConnectorProvider}
- * </ul>
- *
- * @param broker
- * {@link Broker}
- */
- public void registerProviders(final Broker broker) {
- // Register draft02 provider
- broker.registerProvider(this.providerDraft02);
-
- // Register draft18 provider
- broker.registerProvider(this.providerDraft18);
- }
-
- /**
- * Register runtime beans from restconf draft02 {@link RestconfProviderImpl}.
- *
- * @param runtimeRegistration for register runtime beans
- * @return {@link RestConnectorRuntimeRegistration}
- */
- public RestConnectorRuntimeRegistration runtimeRegistration(
- final RestConnectorRuntimeRegistrator runtimeRegistration) {
- return runtimeRegistration.register(this.providerDraft02);
- }
-
- @Override
- public void close() throws Exception {
- this.providerDraft02.close();
- this.providerDraft18.close();
- }
-
-}
package org.opendaylight.controller.config.yang.md.sal.rest.connector;
-import org.opendaylight.RestconfWrapperProviders;
-import org.opendaylight.aaa.api.AAAService;
import org.opendaylight.controller.config.api.osgi.WaitingServiceTracker;
+import org.opendaylight.netconf.sal.rest.api.RestConnector;
import org.osgi.framework.BundleContext;
-
+@Deprecated
public class RestConnectorModule
extends org.opendaylight.controller.config.yang.md.sal.rest.connector.AbstractRestConnectorModule {
- private static RestConnectorRuntimeRegistration runtimeRegistration;
-
private BundleContext bundleContext;
public RestConnectorModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
@Override
public java.lang.AutoCloseable createInstance() {
-
- final WaitingServiceTracker<AAAService> aaaServiceWaitingServiceTracker =
- WaitingServiceTracker.create(AAAService.class, bundleContext);
- aaaServiceWaitingServiceTracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
-
- final RestconfWrapperProviders wrapperProviders = new RestconfWrapperProviders(getWebsocketPort());
- wrapperProviders.registerProviders(getDomBrokerDependency());
-
- if (runtimeRegistration != null) {
- runtimeRegistration.close();
+ final WaitingServiceTracker<RestConnector> tracker =
+ WaitingServiceTracker.create(RestConnector.class, bundleContext);
+ tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
+
+ final class AutoCloseableRestConnector implements RestConnector, AutoCloseable {
+ @Override
+ public void close() {
+ tracker.close();
+ }
}
- runtimeRegistration = wrapperProviders.runtimeRegistration(getRootRuntimeBeanRegistratorWrapper());
-
- return wrapperProviders;
+ return new AutoCloseableRestConnector();
}
public void setBundleContext(final BundleContext bundleContext) {
* <p>
* Do not modify this file unless it is present under src/main directory
*/
+@Deprecated
public class RestConnectorModuleFactory
extends org.opendaylight.controller.config.yang.md.sal.rest.connector.AbstractRestConnectorModuleFactory {
package org.opendaylight.controller.config.yang.sal.restconf.service;
-import org.opendaylight.netconf.sal.restconf.impl.JSONRestconfServiceImpl;
+import com.google.common.base.Optional;
+import org.opendaylight.controller.config.api.osgi.WaitingServiceTracker;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.netconf.sal.restconf.api.JSONRestconfService;
+import org.opendaylight.yangtools.yang.common.OperationFailedException;
+import org.osgi.framework.BundleContext;
+@Deprecated
public class JSONRestconfServiceModule
extends org.opendaylight.controller.config.yang.sal.restconf.service.AbstractJSONRestconfServiceModule {
+
+ private BundleContext bundleContext;
+
public JSONRestconfServiceModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
super(identifier, dependencyResolver);
}
@Override
- public void customValidation() {
- // add custom validation form module attributes here.
+ public java.lang.AutoCloseable createInstance() {
+ final WaitingServiceTracker<JSONRestconfService> tracker =
+ WaitingServiceTracker.create(JSONRestconfService.class, bundleContext);
+ final JSONRestconfService service = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
+
+ final class AutoCloseableJSONRestconfService implements JSONRestconfService, AutoCloseable {
+ @Override
+ public void close() {
+ tracker.close();
+ }
+
+ @Override
+ public void delete(String uriPath) throws OperationFailedException {
+ service.delete(uriPath);
+ }
+
+
+ @Override
+ public void put(String uriPath, String payload) throws OperationFailedException {
+ service.put(uriPath, payload);
+ }
+
+ @Override
+ public void post(String uriPath, String payload) throws OperationFailedException {
+ service.post(uriPath, payload);
+ }
+
+ @Override
+ public Optional<String> get(String uriPath, LogicalDatastoreType datastoreType)
+ throws OperationFailedException {
+ return service.get(uriPath, datastoreType);
+ }
+
+ @Override
+ public Optional<String> invokeRpc(String uriPath, Optional<String> input) throws OperationFailedException {
+ return service.invokeRpc(uriPath, input);
+ }
+ }
+
+ return new AutoCloseableJSONRestconfService();
}
- @Override
- public java.lang.AutoCloseable createInstance() {
- return new JSONRestconfServiceImpl();
+ public void setBundleContext(final BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
}
}
package org.opendaylight.controller.config.yang.sal.restconf.service;
+import org.opendaylight.controller.config.api.DependencyResolver;
+import org.osgi.framework.BundleContext;
+
/**
* Generated file.
*
* <p>
* Do not modify this file unless it is present under src/main directory
*/
+@Deprecated
public class JSONRestconfServiceModuleFactory
extends org.opendaylight.controller.config.yang.sal.restconf.service.AbstractJSONRestconfServiceModuleFactory {
+ @Override
+ public JSONRestconfServiceModule instantiateModule(final String instanceName,
+ final DependencyResolver dependencyResolver, final BundleContext bundleContext) {
+ final JSONRestconfServiceModule restConnectorModule = super.instantiateModule(instanceName,
+ dependencyResolver, bundleContext);
+ restConnectorModule.setBundleContext(bundleContext);
+ return restConnectorModule;
+ }
+ @Override
+ public JSONRestconfServiceModule instantiateModule(final String instanceName,
+ final DependencyResolver dependencyResolver, final JSONRestconfServiceModule oldModule,
+ final AutoCloseable oldInstance, final BundleContext bundleContext) {
+ final JSONRestconfServiceModule restConnectorModule = super.instantiateModule(instanceName,
+ dependencyResolver, oldModule, oldInstance, bundleContext);
+ restConnectorModule.setBundleContext(bundleContext);
+ return restConnectorModule;
+ }
}
import org.opendaylight.controller.md.sal.dom.api.DOMRpcException;
import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
-import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
import org.opendaylight.netconf.sal.streams.listeners.ListenerAdapter;
private static final BrokerFacade INSTANCE = new BrokerFacade();
private volatile DOMRpcService rpcService;
- private volatile ConsumerSession context;
private DOMDataBroker domDataBroker;
private DOMNotificationService domNotification;
this.domNotification = domNotification;
}
- public void setContext(final ConsumerSession context) {
- this.context = context;
- }
-
public static BrokerFacade getInstance() {
return BrokerFacade.INSTANCE;
}
private void checkPreconditions() {
- if (this.context == null || this.domDataBroker == null) {
+ if (this.domDataBroker == null) {
throw new RestconfDocumentedException(Status.SERVICE_UNAVAILABLE);
}
}
*/
package org.opendaylight.netconf.sal.restconf.impl;
+import com.google.common.base.Preconditions;
import java.math.BigInteger;
-import java.util.Collection;
-import java.util.Collections;
-import org.opendaylight.controller.config.yang.md.sal.rest.connector.Config;
-import org.opendaylight.controller.config.yang.md.sal.rest.connector.Delete;
-import org.opendaylight.controller.config.yang.md.sal.rest.connector.Get;
-import org.opendaylight.controller.config.yang.md.sal.rest.connector.Operational;
-import org.opendaylight.controller.config.yang.md.sal.rest.connector.Post;
-import org.opendaylight.controller.config.yang.md.sal.rest.connector.Put;
-import org.opendaylight.controller.config.yang.md.sal.rest.connector.RestConnectorRuntimeMXBean;
-import org.opendaylight.controller.config.yang.md.sal.rest.connector.Rpcs;
+import org.opendaylight.controller.md.sal.common.util.jmx.AbstractMXBean;
import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService;
import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
-import org.opendaylight.controller.sal.core.api.Broker.ProviderSession;
-import org.opendaylight.controller.sal.core.api.Provider;
import org.opendaylight.controller.sal.core.api.model.SchemaService;
import org.opendaylight.netconf.sal.rest.api.RestConnector;
+import org.opendaylight.netconf.sal.restconf.impl.jmx.Config;
+import org.opendaylight.netconf.sal.restconf.impl.jmx.Delete;
+import org.opendaylight.netconf.sal.restconf.impl.jmx.Get;
+import org.opendaylight.netconf.sal.restconf.impl.jmx.Operational;
+import org.opendaylight.netconf.sal.restconf.impl.jmx.Post;
+import org.opendaylight.netconf.sal.restconf.impl.jmx.Put;
+import org.opendaylight.netconf.sal.restconf.impl.jmx.RestConnectorRuntimeMXBean;
+import org.opendaylight.netconf.sal.restconf.impl.jmx.Rpcs;
import org.opendaylight.netconf.sal.streams.websockets.WebSocketServer;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
-public class RestconfProviderImpl implements Provider, AutoCloseable, RestConnector, RestConnectorRuntimeMXBean {
-
+public class RestconfProviderImpl extends AbstractMXBean
+ implements AutoCloseable, RestConnector, RestConnectorRuntimeMXBean {
+ private final DOMDataBroker domDataBroker;
+ private final SchemaService schemaService;
+ private final DOMRpcService rpcService;
+ private final DOMNotificationService notificationService;
+ private final DOMMountPointService mountPointService;
+ private final PortNumber websocketPort;
private final StatisticsRestconfServiceWrapper stats = StatisticsRestconfServiceWrapper.getInstance();
private ListenerRegistration<SchemaContextListener> listenerRegistration;
- private PortNumber port;
private Thread webSocketServerThread;
- public void setWebsocketPort(final PortNumber port) {
- this.port = port;
+ public RestconfProviderImpl(DOMDataBroker domDataBroker, SchemaService schemaService, DOMRpcService rpcService,
+ DOMNotificationService notificationService, DOMMountPointService mountPointService,
+ PortNumber websocketPort) {
+ super("Draft02ProviderStatistics", "restconf-connector", null);
+ this.domDataBroker = Preconditions.checkNotNull(domDataBroker);
+ this.schemaService = Preconditions.checkNotNull(schemaService);
+ this.rpcService = Preconditions.checkNotNull(rpcService);
+ this.notificationService = Preconditions.checkNotNull(notificationService);
+ this.mountPointService = Preconditions.checkNotNull(mountPointService);
+ this.websocketPort = Preconditions.checkNotNull(websocketPort);
}
- @Override
- public void onSessionInitiated(final ProviderSession session) {
- final DOMDataBroker domDataBroker = session.getService(DOMDataBroker.class);
+ public void start() {
+ this.listenerRegistration = schemaService.registerSchemaContextListener(ControllerContext.getInstance());
- BrokerFacade.getInstance().setContext(session);
BrokerFacade.getInstance().setDomDataBroker(domDataBroker);
- final SchemaService schemaService = session.getService(SchemaService.class);
- this.listenerRegistration = schemaService.registerSchemaContextListener(ControllerContext.getInstance());
- BrokerFacade.getInstance().setRpcService(session.getService(DOMRpcService.class));
- BrokerFacade.getInstance().setDomNotificationService(session.getService(DOMNotificationService.class));
+ BrokerFacade.getInstance().setRpcService(rpcService);
+ BrokerFacade.getInstance().setDomNotificationService(notificationService);
ControllerContext.getInstance().setSchemas(schemaService.getGlobalContext());
- ControllerContext.getInstance().setMountService(session.getService(DOMMountPointService.class));
+ ControllerContext.getInstance().setMountService(mountPointService);
- this.webSocketServerThread = new Thread(WebSocketServer.createInstance(this.port.getValue().intValue()));
- this.webSocketServerThread.setName("Web socket server on port " + this.port);
+ this.webSocketServerThread = new Thread(WebSocketServer.createInstance(websocketPort.getValue().intValue()));
+ this.webSocketServerThread.setName("Web socket server on port " + websocketPort);
this.webSocketServerThread.start();
- }
- @Override
- public Collection<ProviderFunctionality> getProviderFunctionality() {
- return Collections.emptySet();
+ registerMBean();
}
@Override
public void close() {
+ BrokerFacade.getInstance().setDomDataBroker(null);
if (this.listenerRegistration != null) {
this.listenerRegistration.close();
}
WebSocketServer.destroyInstance();
- this.webSocketServerThread.interrupt();
+ if (this.webSocketServerThread != null) {
+ this.webSocketServerThread.interrupt();
+ }
+
+ unregisterMBean();
}
@Override
--- /dev/null
+/*
+ * Copyright (c) 2017 Inocybe Technologies and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.netconf.sal.restconf.impl.jmx;
+
+public class Config {
+ private Delete delete;
+
+ private Post post;
+
+ private Get get;
+
+ private Put put;
+
+ public Delete getDelete() {
+ return delete;
+ }
+
+ public void setDelete(Delete delete) {
+ this.delete = delete;
+ }
+
+ public Post getPost() {
+ return post;
+ }
+
+ public void setPost(Post post) {
+ this.post = post;
+ }
+
+ public Get getGet() {
+ return get;
+ }
+
+ public void setGet(Get get) {
+ this.get = get;
+ }
+
+ public Put getPut() {
+ return put;
+ }
+
+ public void setPut(Put put) {
+ this.put = put;
+ }
+
+ @Override
+ public int hashCode() {
+ return java.util.Objects.hash(delete, post, get, put);
+
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+ final Config that = (Config) obj;
+ if (!java.util.Objects.equals(delete, that.delete)) {
+ return false;
+ }
+
+ if (!java.util.Objects.equals(post, that.post)) {
+ return false;
+ }
+
+ if (!java.util.Objects.equals(get, that.get)) {
+ return false;
+ }
+
+ if (!java.util.Objects.equals(put, that.put)) {
+ return false;
+ }
+
+ return true;
+
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Inocybe Technologies and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.netconf.sal.restconf.impl.jmx;
+
+import java.math.BigInteger;
+
+public class Delete {
+ private BigInteger successfulResponses;
+
+ private BigInteger receivedRequests;
+
+ private BigInteger failedResponses;
+
+ public BigInteger getSuccessfulResponses() {
+ return successfulResponses;
+ }
+
+ public void setSuccessfulResponses(BigInteger successfulResponses) {
+ this.successfulResponses = successfulResponses;
+ }
+
+ public BigInteger getReceivedRequests() {
+ return receivedRequests;
+ }
+
+ public void setReceivedRequests(BigInteger receivedRequests) {
+ this.receivedRequests = receivedRequests;
+ }
+
+ public BigInteger getFailedResponses() {
+ return failedResponses;
+ }
+
+ public void setFailedResponses(BigInteger failedResponses) {
+ this.failedResponses = failedResponses;
+ }
+
+ @Override
+ public int hashCode() {
+ return java.util.Objects.hash(successfulResponses, receivedRequests, failedResponses);
+
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+ final Delete that = (Delete) obj;
+ if (!java.util.Objects.equals(successfulResponses, that.successfulResponses)) {
+ return false;
+ }
+
+ if (!java.util.Objects.equals(receivedRequests, that.receivedRequests)) {
+ return false;
+ }
+
+ if (!java.util.Objects.equals(failedResponses, that.failedResponses)) {
+ return false;
+ }
+
+ return true;
+
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Inocybe Technologies and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.netconf.sal.restconf.impl.jmx;
+
+import java.math.BigInteger;
+
+public class Get {
+ private BigInteger successfulResponses;
+
+ private BigInteger receivedRequests;
+
+ private BigInteger failedResponses;
+
+ public BigInteger getSuccessfulResponses() {
+ return successfulResponses;
+ }
+
+ public void setSuccessfulResponses(BigInteger successfulResponses) {
+ this.successfulResponses = successfulResponses;
+ }
+
+ public BigInteger getReceivedRequests() {
+ return receivedRequests;
+ }
+
+ public void setReceivedRequests(BigInteger receivedRequests) {
+ this.receivedRequests = receivedRequests;
+ }
+
+ public BigInteger getFailedResponses() {
+ return failedResponses;
+ }
+
+ public void setFailedResponses(BigInteger failedResponses) {
+ this.failedResponses = failedResponses;
+ }
+
+ @Override
+ public int hashCode() {
+ return java.util.Objects.hash(successfulResponses, receivedRequests, failedResponses);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+ final Get that = (Get) obj;
+ if (!java.util.Objects.equals(successfulResponses, that.successfulResponses)) {
+ return false;
+ }
+
+ if (!java.util.Objects.equals(receivedRequests, that.receivedRequests)) {
+ return false;
+ }
+
+ if (!java.util.Objects.equals(failedResponses, that.failedResponses)) {
+ return false;
+ }
+
+ return true;
+
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Inocybe Technologies and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.netconf.sal.restconf.impl.jmx;
+
+public class Operational {
+ private Get get;
+
+ public Get getGet() {
+ return get;
+ }
+
+ public void setGet(Get get) {
+ this.get = get;
+ }
+
+ @Override
+ public int hashCode() {
+ return java.util.Objects.hash(get);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+ final Operational that = (Operational) obj;
+ if (!java.util.Objects.equals(get, that.get)) {
+ return false;
+ }
+
+ return true;
+
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Inocybe Technologies and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.netconf.sal.restconf.impl.jmx;
+
+import java.math.BigInteger;
+
+public class Post {
+ private BigInteger successfulResponses;
+
+ private BigInteger receivedRequests;
+
+ private BigInteger failedResponses;
+
+ public BigInteger getSuccessfulResponses() {
+ return successfulResponses;
+ }
+
+ public void setSuccessfulResponses(BigInteger successfulResponses) {
+ this.successfulResponses = successfulResponses;
+ }
+
+ public BigInteger getReceivedRequests() {
+ return receivedRequests;
+ }
+
+ public void setReceivedRequests(BigInteger receivedRequests) {
+ this.receivedRequests = receivedRequests;
+ }
+
+ public BigInteger getFailedResponses() {
+ return failedResponses;
+ }
+
+ public void setFailedResponses(BigInteger failedResponses) {
+ this.failedResponses = failedResponses;
+ }
+
+ @Override
+ public int hashCode() {
+ return java.util.Objects.hash(successfulResponses, receivedRequests, failedResponses);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+ final Post that = (Post) obj;
+ if (!java.util.Objects.equals(successfulResponses, that.successfulResponses)) {
+ return false;
+ }
+
+ if (!java.util.Objects.equals(receivedRequests, that.receivedRequests)) {
+ return false;
+ }
+
+ if (!java.util.Objects.equals(failedResponses, that.failedResponses)) {
+ return false;
+ }
+
+ return true;
+
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Inocybe Technologies and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.netconf.sal.restconf.impl.jmx;
+
+import java.math.BigInteger;
+
+public class Put {
+ private BigInteger successfulResponses;
+
+ private BigInteger receivedRequests;
+
+ private BigInteger failedResponses;
+
+ public BigInteger getSuccessfulResponses() {
+ return successfulResponses;
+ }
+
+ public void setSuccessfulResponses(BigInteger successfulResponses) {
+ this.successfulResponses = successfulResponses;
+ }
+
+ public BigInteger getReceivedRequests() {
+ return receivedRequests;
+ }
+
+ public void setReceivedRequests(BigInteger receivedRequests) {
+ this.receivedRequests = receivedRequests;
+ }
+
+ public BigInteger getFailedResponses() {
+ return failedResponses;
+ }
+
+ public void setFailedResponses(BigInteger failedResponses) {
+ this.failedResponses = failedResponses;
+ }
+
+ @Override
+ public int hashCode() {
+ return java.util.Objects.hash(successfulResponses, receivedRequests, failedResponses);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+ final Put that = (Put) obj;
+ if (!java.util.Objects.equals(successfulResponses, that.successfulResponses)) {
+ return false;
+ }
+
+ if (!java.util.Objects.equals(receivedRequests, that.receivedRequests)) {
+ return false;
+ }
+
+ if (!java.util.Objects.equals(failedResponses, that.failedResponses)) {
+ return false;
+ }
+
+ return true;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Inocybe Technologies and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.netconf.sal.restconf.impl.jmx;
+
+public interface RestConnectorRuntimeMXBean {
+ Operational getOperational();
+
+ Rpcs getRpcs();
+
+ Config getConfig();
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Inocybe Technologies and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.netconf.sal.restconf.impl.jmx;
+
+import java.math.BigInteger;
+
+public class Rpcs {
+ private BigInteger successfulResponses;
+
+ private BigInteger receivedRequests;
+
+ private BigInteger failedResponses;
+
+ public BigInteger getSuccessfulResponses() {
+ return successfulResponses;
+ }
+
+ public void setSuccessfulResponses(BigInteger successfulResponses) {
+ this.successfulResponses = successfulResponses;
+ }
+
+ public BigInteger getReceivedRequests() {
+ return receivedRequests;
+ }
+
+ public void setReceivedRequests(BigInteger receivedRequests) {
+ this.receivedRequests = receivedRequests;
+ }
+
+ public BigInteger getFailedResponses() {
+ return failedResponses;
+ }
+
+ public void setFailedResponses(BigInteger failedResponses) {
+ this.failedResponses = failedResponses;
+ }
+
+ @Override
+ public int hashCode() {
+ return java.util.Objects.hash(successfulResponses, receivedRequests, failedResponses);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+ final Rpcs that = (Rpcs) obj;
+ if (!java.util.Objects.equals(successfulResponses, that.successfulResponses)) {
+ return false;
+ }
+
+ if (!java.util.Objects.equals(receivedRequests, that.receivedRequests)) {
+ return false;
+ }
+
+ if (!java.util.Objects.equals(failedResponses, that.failedResponses)) {
+ return false;
+ }
+
+ return true;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 Inocybe Technologies and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+/**
+ * This package contains the statistical JMX classes for the Draft02 restconf implementation. Originally these classes
+ * were generated by the CSS code generator and were moved to this package on conversion to blueprint.
+ */
+package org.opendaylight.netconf.sal.restconf.impl.jmx;
package org.opendaylight.restconf;
import com.google.common.base.Preconditions;
-import java.util.Collection;
-import java.util.Collections;
import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService;
import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
-import org.opendaylight.controller.sal.core.api.Broker.ProviderSession;
-import org.opendaylight.controller.sal.core.api.Provider;
import org.opendaylight.controller.sal.core.api.model.SchemaService;
import org.opendaylight.netconf.sal.rest.api.RestConnector;
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
* Provider for restconf draft18.
*
*/
-public class RestConnectorProvider implements Provider, RestConnector, AutoCloseable {
+public class RestConnectorProvider implements RestConnector, AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(RestConnectorProvider.class);
}
};
- private ListenerRegistration<SchemaContextListener> listenerRegistration;
-
- private SchemaContextHandler schemaCtxHandler;
private static TransactionChainHandler transactionChainHandler;
private static DOMDataBroker dataBroker;
private static DOMMountPointServiceHandler mountPointServiceHandler;
- @Override
- public void onSessionInitiated(final ProviderSession session) {
- final SchemaService schemaService = Preconditions.checkNotNull(session.getService(SchemaService.class));
+ private final SchemaService schemaService;
+ private final DOMRpcService rpcService;
+ private final DOMNotificationService notificationService;
+ private final DOMMountPointService mountPointService;
+ private ListenerRegistration<SchemaContextListener> listenerRegistration;
+
+ private SchemaContextHandler schemaCtxHandler;
+ public RestConnectorProvider(DOMDataBroker domDataBroker, SchemaService schemaService, DOMRpcService rpcService,
+ DOMNotificationService notificationService, DOMMountPointService mountPointService) {
+ this.schemaService = Preconditions.checkNotNull(schemaService);
+ this.rpcService = Preconditions.checkNotNull(rpcService);
+ this.notificationService = Preconditions.checkNotNull(notificationService);
+ this.mountPointService = Preconditions.checkNotNull(mountPointService);
+
+ RestConnectorProvider.dataBroker = Preconditions.checkNotNull(domDataBroker);
+ }
+
+ public void start() {
final ServicesWrapperImpl wrapperServices = ServicesWrapperImpl.getInstance();
- RestConnectorProvider.mountPointServiceHandler = new DOMMountPointServiceHandler(
- session.getService(DOMMountPointService.class));
+ mountPointServiceHandler = new DOMMountPointServiceHandler(mountPointService);
- RestConnectorProvider.dataBroker = session.getService(DOMDataBroker.class);
- final DOMDataBrokerHandler brokerHandler = new DOMDataBrokerHandler(RestConnectorProvider.dataBroker);
+ final DOMDataBrokerHandler brokerHandler = new DOMDataBrokerHandler(dataBroker);
- RestConnectorProvider.transactionChainHandler = new TransactionChainHandler(RestConnectorProvider.dataBroker
+ RestConnectorProvider.transactionChainHandler = new TransactionChainHandler(dataBroker
.createTransactionChain(RestConnectorProvider.TRANSACTION_CHAIN_LISTENER));
this.schemaCtxHandler = new SchemaContextHandler(transactionChainHandler);
this.listenerRegistration = schemaService.registerSchemaContextListener(this.schemaCtxHandler);
- final DOMRpcService rpcService = session.getService(DOMRpcService.class);
final RpcServiceHandler rpcServiceHandler = new RpcServiceHandler(rpcService);
- final DOMNotificationService notificationService = session.getService(DOMNotificationService.class);
final NotificationServiceHandler notificationServiceHandler =
new NotificationServiceHandler(notificationService);
LOG.trace("Resetting TransactionChain({})", chain);
chain.close();
RestConnectorProvider.transactionChainHandler.update(
- Preconditions.checkNotNull(RestConnectorProvider.dataBroker).createTransactionChain(
+ Preconditions.checkNotNull(dataBroker).createTransactionChain(
RestConnectorProvider.TRANSACTION_CHAIN_LISTENER)
);
}
* @return {@link DOMMountPointService}
*/
public static DOMMountPointService getMountPointService() {
- return RestConnectorProvider.mountPointServiceHandler.get();
- }
-
- @Override
- public Collection<ProviderFunctionality> getProviderFunctionality() {
- return Collections.emptySet();
+ return mountPointServiceHandler.get();
}
@Override
}
// close transaction chain
- if ((transactionChainHandler != null) && (transactionChainHandler.get() != null)) {
+ if (transactionChainHandler != null && transactionChainHandler.get() != null) {
transactionChainHandler.get().close();
}
+
+ transactionChainHandler = null;
+ mountPointServiceHandler = null;
+ dataBroker = null;
}
}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright (c) 2017 Inocybe Technologies Inc. and others. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ and is available at http://www.eclipse.org/legal/epl-v10.html
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
+ xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
+ xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.4.0"
+ odl:use-default-for-reference-types="true">
+
+ <!-- JSONRestconfService -->
+
+ <bean id="jsonRestconfService"
+ class="org.opendaylight.netconf.sal.restconf.impl.JSONRestconfServiceImpl"
+ destroy-method="close"/>
+
+ <service ref="jsonRestconfService"
+ interface="org.opendaylight.netconf.sal.restconf.api.JSONRestconfService" />
+
+ <!-- Restconf providers -->
+
+ <cm:property-placeholder persistent-id="org.opendaylight.restconf" update-strategy="reload">
+ <cm:default-properties>
+ <cm:property name="websocket-port" value="8185"/>
+ </cm:default-properties>
+ </cm:property-placeholder>
+
+ <!--
+ This cfg file defines the type of the DOMDataBroker service to use. 'default' indicates to use
+ the default DOMDataBroker provided by MD-SAL. This setting is useful for providing a custom
+ DOMDataBroker implementation that does, e.g., validation or additional security checking on
+ top of the default DOMDataBroker.
+ -->
+ <cm:property-placeholder persistent-id="org.opendaylight.restconf.databroker"
+ placeholder-prefix = "@{" placeholder-suffix = "}" update-strategy="reload">
+ <cm:default-properties>
+ <cm:property name="databroker-service-type" value="default"/>
+ </cm:default-properties>
+ </cm:property-placeholder>
+
+ <!-- We need the AAAService available even though we don't use it -->
+ <reference interface="org.opendaylight.aaa.api.AAAService"/>
+
+ <reference id="schemaService" interface="org.opendaylight.controller.sal.core.api.model.SchemaService"/>
+ <reference id="domRpcService" interface="org.opendaylight.controller.md.sal.dom.api.DOMRpcService"/>
+ <reference id="domMountPointService" interface="org.opendaylight.controller.md.sal.dom.api.DOMMountPointService"/>
+ <reference id="domNotificationService" interface="org.opendaylight.controller.md.sal.dom.api.DOMNotificationService"/>
+ <reference id="domDataBroker" interface="org.opendaylight.controller.md.sal.dom.api.DOMDataBroker"
+ ext:filter="(type=@{databroker-service-type})"/>
+
+ <bean id="webSocketPort" class="org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber">
+ <argument value="${websocket-port}"/>
+ </bean>
+
+ <bean id="restconfProviderDraft02" class="org.opendaylight.netconf.sal.restconf.impl.RestconfProviderImpl"
+ init-method="start" destroy-method="close">
+ <argument ref="domDataBroker"/>
+ <argument ref="schemaService"/>
+ <argument ref="domRpcService"/>
+ <argument ref="domNotificationService"/>
+ <argument ref="domMountPointService"/>
+ <argument ref="webSocketPort"/>
+ </bean>
+
+ <bean id="restconfProviderDraft18" class="org.opendaylight.restconf.RestConnectorProvider"
+ init-method="start" destroy-method="close">
+ <argument ref="domDataBroker"/>
+ <argument ref="schemaService"/>
+ <argument ref="domRpcService"/>
+ <argument ref="domNotificationService"/>
+ <argument ref="domMountPointService"/>
+ </bean>
+
+ <service ref="restconfProviderDraft18"
+ interface="org.opendaylight.netconf.sal.rest.api.RestConnector" />
+
+</blueprint>
import opendaylight-md-sal-dom {prefix dom; revision-date 2013-10-28;}
import opendaylight-md-sal-binding {prefix sal; revision-date 2013-10-28;}
import ietf-inet-types {prefix inet; revision-date 2013-07-15;}
-
+
description
"Service definition for Rest Connector";
-
+
revision "2014-07-24" {
description
"Initial revision";
}
-
+
identity rest-connector {
+ status deprecated;
base "config:service-type";
config:java-class "org.opendaylight.netconf.sal.rest.api.RestConnector";
+ config:disable-osgi-service-registration;
}
-
+
identity rest-connector-impl {
+ status deprecated;
base config:module-type;
config:provided-service rest-connector;
config:java-name-prefix RestConnector;
}
-
- grouping statistics {
- leaf received-requests {
- type uint64;
- }
-
- leaf successful-responses {
- type uint64;
- }
-
- leaf failed-responses {
- type uint64;
- }
- }
augment "/config:modules/config:module/config:configuration" {
case rest-connector-impl {
when "/config:modules/config:module/config:type = 'rest-connector-impl'";
leaf websocket-port {
- mandatory true;
+ mandatory false;
type inet:port-number;
}
container dom-broker {
uses config:service-ref {
refine type {
- mandatory true;
+ mandatory false;
config:required-identity dom:dom-broker-osgi-registry;
}
}
}
}
}
-
- augment "/config:modules/config:module/config:state" {
- case rest-connector-impl {
- when "/config:modules/config:module/config:type = 'rest-connector-impl'";
- container rpcs {
- uses statistics;
- }
-
- container config {
- container get {
- uses statistics;
- }
-
- container post {
- uses statistics;
- }
-
- container put {
- uses statistics;
- }
-
- container delete {
- uses statistics;
- }
- }
-
- container operational {
- container get {
- uses statistics;
- }
- }
- }
- }
}
}
identity json-restconf-service {
+ status deprecated;
base "config:service-type";
config:java-class "org.opendaylight.netconf.sal.restconf.api.JSONRestconfService";
+ config:disable-osgi-service-registration;
}
identity json-restconf-service-impl {
+ status deprecated;
base config:module-type;
config:provided-service json-restconf-service;
config:java-name-prefix JSONRestconfService;
when "/config:modules/config:module/config:type = 'json-restconf-service-impl'";
}
}
-}
\ No newline at end of file
+}
+++ /dev/null
-/*
- * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.lang.reflect.Field;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.opendaylight.controller.config.yang.md.sal.rest.connector.RestConnectorRuntimeRegistration;
-import org.opendaylight.controller.config.yang.md.sal.rest.connector.RestConnectorRuntimeRegistrator;
-import org.opendaylight.controller.sal.core.api.Broker;
-import org.opendaylight.controller.sal.core.api.Provider;
-import org.opendaylight.netconf.sal.restconf.impl.RestconfProviderImpl;
-import org.opendaylight.restconf.RestConnectorProvider;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
-
-public class RestconfWrapperProvidersTest {
-
- private static final PortNumber PORT = new PortNumber(8181);
-
- private RestconfWrapperProviders rwp;
-
- @Before
- public void setUp() throws Exception {
- rwp = new RestconfWrapperProviders(PORT);
- assertNotNull(rwp);
- }
-
- @Test
- public void registerTest() {
- final Broker broker = mock(Broker.class);
- rwp.registerProviders(broker);
-
- Mockito.verify(broker, times(2)).registerProvider(Mockito.any(Provider.class));
- }
-
- @Test
- public void runtimeRegistrationTest() {
- final RestConnectorRuntimeRegistrator runtimeRegistrator = mock(RestConnectorRuntimeRegistrator.class);
- final RestConnectorRuntimeRegistration value = mock(RestConnectorRuntimeRegistration.class);
- when(runtimeRegistrator.register(any())).thenReturn(value);
- final RestConnectorRuntimeRegistration runtimeRegistration = rwp.runtimeRegistration(runtimeRegistrator);
-
- assertEquals(value, runtimeRegistration);
- }
-
- @Test
- public void closeTest() throws Exception {
- final RestconfProviderImpl draft2 = mock(RestconfProviderImpl.class);
- final RestConnectorProvider draft18 = mock(RestConnectorProvider.class);
-
- setDeclaredField(rwp, "providerDraft02", draft2);
- setDeclaredField(rwp, "providerDraft18", draft18);
-
- rwp.close();
-
- verify(draft2, times(1)).close();
- verify(draft18, times(1)).close();
- }
-
- private static void setDeclaredField(final Object rwp, final String name, final Object value) throws Exception {
- final Field declaredField = rwp.getClass().getDeclaredField(name);
- declaredField.setAccessible(true);
- declaredField.set(rwp, value);
- }
-}
import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
-import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession;
import org.opendaylight.netconf.sal.restconf.impl.BrokerFacade;
import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
@Mock
private DOMNotificationService domNotification;
@Mock
- private ConsumerSession context;
- @Mock
private DOMRpcService mockRpcService;
@Mock
private DOMMountPoint mockMountInstance;
this.brokerFacade.setDomDataBroker(this.domDataBroker);
this.brokerFacade.setDomNotificationService(this.domNotification);
this.brokerFacade.setRpcService(this.mockRpcService);
- this.brokerFacade.setContext(this.context);
when(this.domDataBroker.newReadOnlyTransaction()).thenReturn(this.readTransaction);
when(this.domDataBroker.newWriteOnlyTransaction()).thenReturn(this.writeTransaction);
when(this.domDataBroker.newReadWriteTransaction()).thenReturn(this.rwTransaction);
@Test(expected = RestconfDocumentedException.class)
public void testInvokeRpcWithNoConsumerSession() {
- this.brokerFacade.setContext(null);
+ brokerFacade.setDomDataBroker(null);
this.brokerFacade.invokeRpc(this.type, this.dummyNode);
}
package org.opendaylight.restconf;
-import static org.junit.Assert.assertNotNull;
-import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
import org.junit.Before;
import org.junit.Rule;
import org.mockito.MockitoAnnotations;
import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
+import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService;
+import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
-import org.opendaylight.controller.sal.core.api.Broker;
import org.opendaylight.controller.sal.core.api.model.SchemaService;
import org.opendaylight.restconf.handlers.SchemaContextHandler;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
// service under test
private RestConnectorProvider connectorProvider;
- @Mock private Broker.ProviderSession mockSession;
@Mock private SchemaService mockSchemaService;
@Mock private DOMMountPointService mockMountPointService;
+ @Mock private DOMDataBroker mockDataBroker;
+ @Mock private DOMRpcService mockRpcService;
+ @Mock private DOMNotificationService mockNotificationService;
+ @Mock DOMTransactionChain mockTransactionChain;
@Mock private ListenerRegistration<SchemaContextListener> mockRegistration;
@Rule
@Before
public void init() {
MockitoAnnotations.initMocks(this);
- this.connectorProvider = new RestConnectorProvider();
- }
-
- /**
- * Test of successful initialization of {@link RestConnectorProvider}.
- */
- @Test
- public void restConnectorProviderInitTest() {
- assertNotNull("Connector provider should be initialized and not null", this.connectorProvider);
- }
-
- /**
- * Test for successful registration with {@link RestConnectorProvider#onSessionInitiated(Broker.ProviderSession)}
- * when all conditions are satisfied.
- *
- * <p>
- * Condition 1: <code>Broker.ProviderSession</code> contains <code>SchemaService</code>
- * Condition 2: <code>Broker.ProviderSession</code> contains <code>DOMMountPointService</code>
- */
- @Test
- public void successfulRegistrationTest() {
- // prepare conditions
- when(this.mockSession.getService(SchemaService.class)).thenReturn(this.mockSchemaService);
- when(this.mockSession.getService(DOMMountPointService.class)).thenReturn(this.mockMountPointService);
- final DOMDataBroker mockDataBroker = Mockito.mock(DOMDataBroker.class);
- when(this.mockSession.getService(DOMDataBroker.class)).thenReturn(mockDataBroker);
- final DOMTransactionChain mockTransactionChain = Mockito.mock(DOMTransactionChain.class);
- when(mockDataBroker.createTransactionChain(Mockito.any())).thenReturn(mockTransactionChain);
- // test
- this.connectorProvider.onSessionInitiated(this.mockSession);
+ doReturn(mockTransactionChain).when(mockDataBroker).createTransactionChain(Mockito.any());
+ doReturn(mockRegistration).when(mockSchemaService).registerSchemaContextListener(
+ Mockito.any(SchemaContextHandler.class));
- // verify interactions
- verify(this.mockSession, times(1)).getService(SchemaService.class);
- verify(this.mockSession, times(1)).getService(DOMMountPointService.class);
- verify(this.mockSchemaService, times(1)).registerSchemaContextListener(Mockito.any(SchemaContextHandler.class));
+ this.connectorProvider = new RestConnectorProvider(mockDataBroker, mockSchemaService, mockRpcService,
+ mockNotificationService, mockMountPointService);
}
/**
- * Test for successful registration with {@link RestConnectorProvider#onSessionInitiated(Broker.ProviderSession)}
- * without <code>DOMMountPointService</code>.
- *
- * <p>
- * Condition 1: <code>Broker.ProviderSession</code> contains <code>SchemaService</code>
- * Condition 2: <code>Broker.ProviderSession</code> does not contain <code>DOMMountPointService</code>
+ * Test for successful start when all conditions are satisfied.
*/
@Test
- public void successfulRegistrationWithoutMountPointTest() {
- // prepare conditions
- when(this.mockSession.getService(SchemaService.class)).thenReturn(this.mockSchemaService);
- when(this.mockSession.getService(DOMMountPointService.class)).thenReturn(null);
- final DOMDataBroker mockDataBroker = Mockito.mock(DOMDataBroker.class);
- when(this.mockSession.getService(DOMDataBroker.class)).thenReturn(mockDataBroker);
- final DOMTransactionChain mockTransactionChain = Mockito.mock(DOMTransactionChain.class);
- when(mockDataBroker.createTransactionChain(Mockito.any())).thenReturn(mockTransactionChain);
- final DOMMountPointService mockDomMountPoint = Mockito.mock(DOMMountPointService.class);
- when(this.mockSession.getService(DOMMountPointService.class)).thenReturn(mockDomMountPoint);
-
+ public void successfulStartTest() {
// test
- this.connectorProvider.onSessionInitiated(this.mockSession);
+ this.connectorProvider.start();
// verify interactions
- verify(this.mockSession, times(1)).getService(SchemaService.class);
- verify(this.mockSession, times(1)).getService(DOMMountPointService.class);
- verify(this.mockSchemaService, times(1)).registerSchemaContextListener(Mockito.any(SchemaContextHandler.class));
- }
-
- /**
- * Negative test of registration with {@link RestConnectorProvider#onSessionInitiated(Broker.ProviderSession)} with
- * null input. Test is expected to fail with <code>NullPointerException</code>.
- */
- @Test
- public void nullSessionRegistrationNegativeTest() {
- this.thrown.expect(NullPointerException.class);
- this.connectorProvider.onSessionInitiated(null);
- }
-
- /**
- * Negative test of registration with {@link RestConnectorProvider#onSessionInitiated(Broker.ProviderSession)} when
- * <code>Broker.ProviderSession</code> does not contain <code>SchemaService</code>. Test is expected to fail with
- * <code>NullPointerException</code>.
- */
- @Test
- public void withoutSchemaServiceRegistrationNegativeTest() {
- // prepare conditions
- when(this.mockSession.getService(SchemaService.class)).thenReturn(null);
-
- // test
- this.thrown.expect(NullPointerException.class);
- this.connectorProvider.onSessionInitiated(this.mockSession);
-
- // verify interaction
- verify(this.mockSession, times(1)).getService(SchemaService.class);
+ verify(mockDataBroker).createTransactionChain(Mockito.any());
+ verify(mockSchemaService).registerSchemaContextListener(Mockito.any(SchemaContextHandler.class));
}
/**
*/
@Test
public void closeOpenTest() throws Exception {
- // prepare conditions
- when(this.mockSession.getService(SchemaService.class)).thenReturn(this.mockSchemaService);
- when(this.mockSession.getService(DOMMountPointService.class)).thenReturn(this.mockMountPointService);
- when(this.mockSchemaService.registerSchemaContextListener(Mockito.any(SchemaContextHandler.class)))
- .thenReturn(this.mockRegistration);
- final DOMDataBroker mockDataBroker = Mockito.mock(DOMDataBroker.class);
- when(this.mockSession.getService(DOMDataBroker.class)).thenReturn(mockDataBroker);
- final DOMTransactionChain mockTransactionChain = Mockito.mock(DOMTransactionChain.class);
- when(mockDataBroker.createTransactionChain(Mockito.any())).thenReturn(mockTransactionChain);
-
- // register
- this.connectorProvider.onSessionInitiated(this.mockSession);
+ // start
+ this.connectorProvider.start();
- // close registration
+ // close
this.connectorProvider.close();
// verify interaction
- verify(this.mockRegistration, times(1)).close();
- verify(mockTransactionChain, times(1)).close();
+ verify(this.mockRegistration).close();
+ verify(mockTransactionChain).close();
}
}