+++ /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.restconf.nb.rfc8040;
-
-import com.google.common.base.Preconditions;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
-import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService;
-import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
-import org.opendaylight.mdsal.dom.api.DOMSchemaService;
-import org.opendaylight.restconf.nb.rfc8040.handlers.DOMDataBrokerHandler;
-import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
-import org.opendaylight.restconf.nb.rfc8040.handlers.NotificationServiceHandler;
-import org.opendaylight.restconf.nb.rfc8040.handlers.RpcServiceHandler;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
-import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
-import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServiceWrapper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Provider for restconf draft18.
- *
- */
-public class RestConnectorProvider<T extends ServiceWrapper> implements RestconfConnector, AutoCloseable {
-
- private static final Logger LOG = LoggerFactory.getLogger(RestConnectorProvider.class);
-
- private final DOMRpcService rpcService;
- private final DOMNotificationService notificationService;
- private final DOMSchemaService domSchemaService;
- private final TransactionChainHandler transactionChainHandler;
- private final DOMDataBroker dataBroker;
- private final SchemaContextHandler schemaCtxHandler;
- private final DOMMountPointServiceHandler mountPointServiceHandler;
- private final T wrapperServices;
-
- public RestConnectorProvider(final DOMDataBroker domDataBroker, final DOMSchemaService domSchemaService,
- final DOMRpcService rpcService, final DOMNotificationService notificationService,
- final TransactionChainHandler transactionChainHandler,
- final SchemaContextHandler schemaCtxHandler, final DOMMountPointServiceHandler mountPointServiceHandler,
- final T wrapperServices) {
- this.wrapperServices = wrapperServices;
- this.domSchemaService = Preconditions.checkNotNull(domSchemaService);
- this.rpcService = Preconditions.checkNotNull(rpcService);
- this.notificationService = Preconditions.checkNotNull(notificationService);
- this.transactionChainHandler = Preconditions.checkNotNull(transactionChainHandler);
- this.dataBroker = Preconditions.checkNotNull(domDataBroker);
- this.schemaCtxHandler = Preconditions.checkNotNull(schemaCtxHandler);
- this.mountPointServiceHandler = Preconditions.checkNotNull(mountPointServiceHandler);
- }
-
- public synchronized void start() {
- final DOMDataBrokerHandler brokerHandler = new DOMDataBrokerHandler(dataBroker);
-
- final RpcServiceHandler rpcServiceHandler = new RpcServiceHandler(rpcService);
-
- final NotificationServiceHandler notificationServiceHandler =
- new NotificationServiceHandler(notificationService);
-
- if (wrapperServices != null) {
- wrapperServices.setHandlers(this.schemaCtxHandler, mountPointServiceHandler,
- transactionChainHandler, brokerHandler, rpcServiceHandler,
- notificationServiceHandler, domSchemaService);
- }
- }
-
- @Override
- public void close() {
- }
-}
import org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch.XmlToPatchBodyReader;
import org.opendaylight.restconf.nb.rfc8040.jersey.providers.schema.SchemaExportContentYangBodyWriter;
import org.opendaylight.restconf.nb.rfc8040.jersey.providers.schema.SchemaExportContentYinBodyWriter;
-import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapperImpl;
+import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapper;
public class RestconfApplication extends Application {
private final SchemaContextHandler schemaContextHandler = SchemaContextHandler.instance();
@Override
public Set<Object> getSingletons() {
final Set<Object> singletons = new HashSet<>();
- singletons.add(ServicesWrapperImpl.getInstance());
+ singletons.add(ServicesWrapper.getInstance());
singletons.add(new JsonNormalizedNodeBodyReader(schemaContextHandler, mountPointServiceHandler));
singletons.add(new JsonToPatchBodyReader(schemaContextHandler, mountPointServiceHandler));
singletons.add(new XmlNormalizedNodeBodyReader(schemaContextHandler, mountPointServiceHandler));
+++ /dev/null
-/*
- * Copyright (c) 2014, 2015 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.restconf.nb.rfc8040;
-
-/*
- * This is a simple dummy interface to allow us to create instances of RestconfProvider
- * via the config subsystem.
- */
-public interface RestconfConnector {
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2017 Pantheon Technologies, s.r.o. 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.restconf.nb.rfc8040.services.wrapper;
-
-import org.opendaylight.mdsal.dom.api.DOMSchemaService;
-import org.opendaylight.restconf.nb.rfc8040.handlers.DOMDataBrokerHandler;
-import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
-import org.opendaylight.restconf.nb.rfc8040.handlers.NotificationServiceHandler;
-import org.opendaylight.restconf.nb.rfc8040.handlers.RpcServiceHandler;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
-import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
-
-public interface ServiceWrapper {
-
- void setHandlers(SchemaContextHandler schemaCtxHandler, DOMMountPointServiceHandler domMountPointServiceHandler,
- TransactionChainHandler transactionChainHandler, DOMDataBrokerHandler domDataBrokerHandler,
- RpcServiceHandler rpcServiceHandler, NotificationServiceHandler notificationServiceHandler,
- DOMSchemaService domSchemaService);
-}
*
*/
@Path("/")
-public final class ServicesWrapperImpl implements BaseServicesWrapper, TransactionServicesWrapper, ServiceWrapper {
+public final class ServicesWrapper implements BaseServicesWrapper, TransactionServicesWrapper {
private RestconfDataService delegRestconfDataService;
private RestconfInvokeOperationsService delegRestconfInvokeOpsService;
private RestconfSchemaService delegRestSchService;
private RestconfService delegRestService;
- private ServicesWrapperImpl() {
+ @Deprecated
+ private ServicesWrapper() {
}
private static class InstanceHolder {
- public static final ServicesWrapperImpl INSTANCE = new ServicesWrapperImpl();
+ public static final ServicesWrapper INSTANCE = new ServicesWrapper();
}
- public static ServicesWrapperImpl getInstance() {
+ @Deprecated
+ public static ServicesWrapper getInstance() {
+ return InstanceHolder.INSTANCE;
+ }
+
+ public static ServicesWrapper newInstance(final SchemaContextHandler schemaCtxHandler,
+ final DOMMountPointServiceHandler domMountPointServiceHandler,
+ final TransactionChainHandler transactionChainHandler, final DOMDataBrokerHandler domDataBrokerHandler,
+ final RpcServiceHandler rpcServiceHandler, final NotificationServiceHandler notificationServiceHandler,
+ final DOMSchemaService domSchemaService) {
+ InstanceHolder.INSTANCE.delegRestOpsService =
+ new RestconfOperationsServiceImpl(schemaCtxHandler, domMountPointServiceHandler);
+ final DOMYangTextSourceProvider yangTextSourceProvider =
+ (DOMYangTextSourceProvider) domSchemaService.getSupportedExtensions()
+ .get(DOMYangTextSourceProvider.class);
+ InstanceHolder.INSTANCE.delegRestSchService =
+ new RestconfSchemaServiceImpl(schemaCtxHandler, domMountPointServiceHandler,
+ yangTextSourceProvider);
+ InstanceHolder.INSTANCE.delegRestconfSubscrService =
+ new RestconfStreamsSubscriptionServiceImpl(domDataBrokerHandler,
+ notificationServiceHandler, schemaCtxHandler, transactionChainHandler);
+ InstanceHolder.INSTANCE.delegRestconfDataService =
+ new RestconfDataServiceImpl(schemaCtxHandler, transactionChainHandler, domMountPointServiceHandler,
+ InstanceHolder.INSTANCE.delegRestconfSubscrService);
+ InstanceHolder.INSTANCE.delegRestconfInvokeOpsService =
+ new RestconfInvokeOperationsServiceImpl(rpcServiceHandler, schemaCtxHandler);
+ InstanceHolder.INSTANCE.delegRestService = new RestconfImpl(schemaCtxHandler);
return InstanceHolder.INSTANCE;
}
public NormalizedNodeContext getLibraryVersion() {
return this.delegRestService.getLibraryVersion();
}
-
- @Override
- public void setHandlers(final SchemaContextHandler schemaCtxHandler,
- final DOMMountPointServiceHandler domMountPointServiceHandler,
- final TransactionChainHandler transactionChainHandler, final DOMDataBrokerHandler domDataBrokerHandler,
- final RpcServiceHandler rpcServiceHandler, final NotificationServiceHandler notificationServiceHandler,
- final DOMSchemaService domSchemaService) {
- this.delegRestOpsService = new RestconfOperationsServiceImpl(schemaCtxHandler, domMountPointServiceHandler);
- final DOMYangTextSourceProvider yangTextSourceProvider =
- (DOMYangTextSourceProvider) domSchemaService.getSupportedExtensions()
- .get(DOMYangTextSourceProvider.class);
- this.delegRestSchService = new RestconfSchemaServiceImpl(schemaCtxHandler, domMountPointServiceHandler,
- yangTextSourceProvider);
- this.delegRestconfSubscrService = new RestconfStreamsSubscriptionServiceImpl(domDataBrokerHandler,
- notificationServiceHandler, schemaCtxHandler, transactionChainHandler);
- this.delegRestconfDataService =
- new RestconfDataServiceImpl(schemaCtxHandler, transactionChainHandler, domMountPointServiceHandler,
- this.delegRestconfSubscrService);
- this.delegRestconfInvokeOpsService =
- new RestconfInvokeOperationsServiceImpl(rpcServiceHandler, schemaCtxHandler);
- this.delegRestService = new RestconfImpl(schemaCtxHandler);
- }
}
ext:filter="(type=@{databroker-service-type})"/>
<reference id="domSchemaService" interface="org.opendaylight.mdsal.dom.api.DOMSchemaService"/>
- <bean id="wrapper" class="org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapperImpl"
- factory-method="getInstance" />
-
<bean id="transactionChainHandler" class="org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler"
destroy-method="close">
<argument ref="domDataBroker"/>
<argument ref="domMountPointService"/>
</bean>
- <bean id="restconfProvider" class="org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider"
- init-method="start" destroy-method="close">
+ <bean id="dataBrokerHandler" class="org.opendaylight.restconf.nb.rfc8040.handlers.DOMDataBrokerHandler">
<argument ref="domDataBroker"/>
- <argument ref="domSchemaService"/>
+ </bean>
+
+ <bean id="rpcServiceHandler" class="org.opendaylight.restconf.nb.rfc8040.handlers.RpcServiceHandler">
<argument ref="domRpcService"/>
+ </bean>
+
+ <bean id="notificationServiceHandler" class="org.opendaylight.restconf.nb.rfc8040.handlers.NotificationServiceHandler">
<argument ref="domNotificationService"/>
- <argument ref="transactionChainHandler"/>
+ </bean>
+
+ <bean id="servicesWrapper" class="org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapper"
+ factory-method="newInstance">
<argument ref="schemaContextHandler"/>
<argument ref="mountPointServiceHandler"/>
- <argument ref="wrapper"/>
+ <argument ref="transactionChainHandler"/>
+ <argument ref="dataBrokerHandler"/>
+ <argument ref="rpcServiceHandler"/>
+ <argument ref="notificationServiceHandler"/>
+ <argument ref="domSchemaService"/>
</bean>
- <service ref="restconfProvider"
- interface="org.opendaylight.restconf.nb.rfc8040.RestconfConnector" />
-
<!-- JSONRestconfService -->
- <bean id="jsonRestconfService" depends-on="restconfProvider"
+ <bean id="jsonRestconfService"
class="org.opendaylight.restconf.nb.rfc8040.rests.services.impl.JSONRestconfServiceRfc8040Impl"
destroy-method="close">
- <argument ref="wrapper"/>
+ <argument ref="servicesWrapper"/>
<argument ref="mountPointServiceHandler"/>
<argument ref="schemaContextHandler"/>
</bean>
+++ /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.restconf.nb.rfc8040;
-
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.verify;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-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.mdsal.dom.api.DOMSchemaService;
-import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
-import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
-import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapperImpl;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
-
-/**
- * Unit tests for {@link RestConnectorProvider}.
- */
-public class RestConnectorProviderTest {
- // service under test
- private RestConnectorProvider<?> connectorProvider;
-
- @Mock private DOMMountPointService mockMountPointService;
- @Mock private DOMDataBroker mockDataBroker;
- @Mock private DOMRpcService mockRpcService;
- @Mock private DOMNotificationService mockNotificationService;
- @Mock DOMTransactionChain mockTransactionChain;
- @Mock private ListenerRegistration<SchemaContextListener> mockRegistration;
- @Mock
- private DOMSchemaService domSchemaService;
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- @Before
- public void init() {
- MockitoAnnotations.initMocks(this);
-
- doReturn(mockTransactionChain).when(mockDataBroker).createTransactionChain(Mockito.any());
- doReturn(mockRegistration).when(domSchemaService).registerSchemaContextListener(
- Mockito.any(SchemaContextHandler.class));
-
- final TransactionChainHandler transactionChainHandler = new TransactionChainHandler(mockDataBroker);
- this.connectorProvider = new RestConnectorProvider<>(mockDataBroker, domSchemaService, mockRpcService,
- mockNotificationService, transactionChainHandler,
- SchemaContextHandler.newInstance(transactionChainHandler, domSchemaService),
- DOMMountPointServiceHandler.newInstance(mockMountPointService),
- ServicesWrapperImpl.getInstance());
- }
-
- /**
- * Test for successful start when all conditions are satisfied.
- */
- @Test
- public void successfulStartTest() {
- // test
- this.connectorProvider.start();
-
- // verify interactions
- verify(mockDataBroker).createTransactionChain(Mockito.any());
- }
-
- /**
- * Test of closing <code>null</code> registration.
- */
- @Test
- public void closeNotOpenTest() throws Exception {
- this.connectorProvider.close();
- }
-
- /**
- * Test of creating and closing not <code>null</code> registration.
- */
- @Test
- public void closeOpenTest() throws Exception {
- // start
- this.connectorProvider.start();
-
- // close
- this.connectorProvider.close();
- }
-}
import org.opendaylight.restconf.nb.rfc8040.handlers.RpcServiceHandler;
import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
-import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapperImpl;
+import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapper;
import org.opendaylight.yangtools.yang.common.OperationFailedException;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
DOMMountPointServiceHandler.newInstance(mockMountPointService);
final DOMNotificationService mockNotificationService = mock(DOMNotificationService.class);
- ServicesWrapperImpl.getInstance().setHandlers(schemaContextHandler, mountPointServiceHandler,
- txChainHandler, new DOMDataBrokerHandler(mockDOMDataBroker),
- new RpcServiceHandler(mockRpcService),
- new NotificationServiceHandler(mockNotificationService), domSchemaService);
+ final ServicesWrapper servicesWrapper = ServicesWrapper.newInstance(schemaContextHandler,
+ mountPointServiceHandler, txChainHandler, new DOMDataBrokerHandler(mockDOMDataBroker),
+ new RpcServiceHandler(mockRpcService), new NotificationServiceHandler(mockNotificationService),
+ domSchemaService);
- service = new JSONRestconfServiceRfc8040Impl(ServicesWrapperImpl.getInstance(), mountPointServiceHandler,
+ service = new JSONRestconfServiceRfc8040Impl(servicesWrapper, mountPointServiceHandler,
schemaContextHandler);
}