<packaging>bundle</packaging>
<dependencies>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ </dependency>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-data-util</artifactId>
+ <artifactId>concepts</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-common</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>rfc7952-data-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-data-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-data-codec-xml</artifactId>
</dependency>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yang-data-impl</artifactId>
</dependency>
-
<dependency>
- <groupId>${project.groupId}</groupId>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-data-util</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-model-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-model-util</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-repo-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-repo-spi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.mdsal</groupId>
+ <artifactId>mdsal-common-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.mdsal</groupId>
+ <artifactId>mdsal-dom-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.netconf</groupId>
<artifactId>netconf-api</artifactId>
</dependency>
<dependency>
- <groupId>${project.groupId}</groupId>
+ <groupId>org.opendaylight.netconf</groupId>
<artifactId>netconf-mapping-api</artifactId>
</dependency>
<dependency>
- <groupId>${project.groupId}</groupId>
+ <groupId>org.opendaylight.netconf</groupId>
<artifactId>netconf-util</artifactId>
</dependency>
<dependency>
- <groupId>com.google.guava</groupId>
- <artifactId>guava</artifactId>
+ <groupId>org.opendaylight.netconf.model</groupId>
+ <artifactId>rfc6241</artifactId>
</dependency>
-
<dependency>
- <groupId>org.opendaylight.mdsal</groupId>
- <artifactId>mdsal-dom-api</artifactId>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.service.component.annotations</artifactId>
</dependency>
+
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>mockito-configuration</artifactId>
</dependency>
<dependency>
- <groupId>org.opendaylight.netconf.model</groupId>
- <artifactId>rfc6241</artifactId>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>util</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-test-util</artifactId>
</dependency>
<dependency>
<groupId>org.opendaylight.mdsal</groupId>
<artifactId>mdsal-dom-broker</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.mdsal</groupId>
+ <artifactId>mdsal-dom-spi</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.opendaylight.mdsal</groupId>
<artifactId>mdsal-dom-inmemory-datastore</artifactId>
<scope>test</scope>
</dependency>
<dependency>
- <groupId>${project.groupId}</groupId>
+ <groupId>org.opendaylight.netconf</groupId>
<artifactId>netconf-util</artifactId>
<type>test-jar</type>
<scope>test</scope>
<artifactId>xmlunit-legacy</artifactId>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-test-util</artifactId>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-data-codec-xml</artifactId>
- </dependency>
</dependencies>
</project>
final Set<Capability> addedCaps = MdsalNetconfOperationServiceFactory.transformCapabilities(
currentContext.get(), rootSchemaSourceProvider);
for (final CapabilityListener listener : listeners1) {
- listener.onCapabilitiesChanged(addedCaps, Collections.emptySet());
+ listener.onCapabilitiesChanged(addedCaps, Set.of());
}
}
public Registration registerCapabilityListener(final CapabilityListener listener) {
listener.onCapabilitiesChanged(MdsalNetconfOperationServiceFactory.transformCapabilities(currentContext.get(),
- rootSchemaSourceProvider), Collections.emptySet());
+ rootSchemaSourceProvider), Set.of());
listeners1.add(listener);
return () -> listeners1.remove(listener);
}
*/
package org.opendaylight.netconf.mdsal.connector;
-import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;
import com.google.common.io.CharStreams;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
-import java.util.Collections;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+@Component(service = NetconfOperationServiceFactory.class, immediate = true, property = "type=mdsal-netconf-connector")
public final class MdsalNetconfOperationServiceFactory implements NetconfOperationServiceFactory, AutoCloseable {
-
private static final Logger LOG = LoggerFactory.getLogger(MdsalNetconfOperationServiceFactory.class);
private static final BasicCapability VALIDATE_CAPABILITY =
new BasicCapability("urn:ietf:params:netconf:capability:validate:1.0");
private final SchemaSourceProvider<YangTextSchemaSource> rootSchemaSourceProviderDependency;
private final NetconfOperationServiceFactoryListener netconfOperationServiceFactoryListener;
- private MdsalNetconfOperationServiceFactory(
- final DOMSchemaService schemaService,
- final NetconfOperationServiceFactoryListener netconfOperationServiceFactoryListener,
- final DOMDataBroker dataBroker,
- final DOMRpcService rpcService) {
-
- this.dataBroker = dataBroker;
- this.rpcService = rpcService;
+ @Activate
+ public MdsalNetconfOperationServiceFactory(@Reference final DOMSchemaService schemaService,
+ @Reference final DOMDataBroker dataBroker, @Reference final DOMRpcService rpcService,
+ @Reference(target = "(type=mapper-aggregator-registry)")
+ final NetconfOperationServiceFactoryListener netconfOperationServiceFactoryListener) {
+ this.dataBroker = requireNonNull(dataBroker);
+ this.rpcService = requireNonNull(rpcService);
+ this.netconfOperationServiceFactoryListener = requireNonNull(netconfOperationServiceFactoryListener);
rootSchemaSourceProviderDependency = schemaService.getExtensions()
.getInstance(DOMYangTextSourceProvider.class);
currentSchemaContext = CurrentSchemaContext.create(requireNonNull(schemaService),
rootSchemaSourceProviderDependency);
- this.netconfOperationServiceFactoryListener = netconfOperationServiceFactoryListener;
+ netconfOperationServiceFactoryListener.onAddNetconfOperationServiceFactory(this);
}
- // keep spotbugs from complaining about overridable method in constructor
- public static MdsalNetconfOperationServiceFactory create(
- final DOMSchemaService schemaService,
- final NetconfOperationServiceFactoryListener netconfOperationServiceFactoryListener,
- final DOMDataBroker dataBroker,
- final DOMRpcService rpcService) {
-
- var factory = new MdsalNetconfOperationServiceFactory(schemaService, netconfOperationServiceFactoryListener,
- dataBroker, rpcService);
- netconfOperationServiceFactoryListener.onAddNetconfOperationServiceFactory(factory);
-
- return factory;
+ @Deactivate
+ @Override
+ public void close() {
+ netconfOperationServiceFactoryListener.onRemoveNetconfOperationServiceFactory(this);
+ currentSchemaContext.close();
}
@Override
public MdsalNetconfOperationService createService(final String netconfSessionIdForReporting) {
- checkState(dataBroker != null, "MD-SAL provider not yet initialized");
return new MdsalNetconfOperationService(currentSchemaContext, netconfSessionIdForReporting, dataBroker,
rpcService);
}
- @SuppressWarnings("checkstyle:IllegalCatch")
- @Override
- public void close() {
- try {
- currentSchemaContext.close();
- if (netconfOperationServiceFactoryListener != null) {
- netconfOperationServiceFactoryListener.onRemoveNetconfOperationServiceFactory(this);
- }
- } catch (Exception e) {
- LOG.error("Failed to close resources correctly - ignore", e);
- }
- }
-
@Override
public Set<Capability> getCapabilities() {
return transformCapabilities(currentSchemaContext.getCurrentContext(), rootSchemaSourceProviderDependency);
public Registration registerCapabilityListener(final CapabilityListener listener) {
// Advertise validate capability only if DOMDataBroker provides DOMDataTransactionValidator
if (dataBroker.getExtensions().get(DOMDataTransactionValidator.class) != null) {
- listener.onCapabilitiesChanged(Collections.singleton(VALIDATE_CAPABILITY), Collections.emptySet());
+ listener.onCapabilitiesChanged(Set.of(VALIDATE_CAPABILITY), Set.of());
}
// Advertise namespaces of supported YANG models as NETCONF capabilities
return currentSchemaContext.registerCapabilityListener(listener);
return HandlingPriority.CANNOT_HANDLE;
}
- getRpcDefinitionFromModule(module.get(), namespaceURI, netconfOperationName);
+ getRpcDefinitionFromModule(module.orElseThrow(), namespaceURI, netconfOperationName);
return HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY;
-
}
@Override
ErrorType.APPLICATION, ErrorTag.BAD_ELEMENT, ErrorSeverity.ERROR);
}
- final Optional<RpcDefinition> rpcDefinitionOptional = getRpcDefinitionFromModule(moduleOptional.get(),
+ final Optional<RpcDefinition> rpcDefinitionOptional = getRpcDefinitionFromModule(moduleOptional.orElseThrow(),
namespaceURI, netconfOperationName);
if (rpcDefinitionOptional.isEmpty()) {
ErrorType.APPLICATION, ErrorTag.BAD_ELEMENT, ErrorSeverity.ERROR);
}
- final RpcDefinition rpcDefinition = rpcDefinitionOptional.get();
+ final RpcDefinition rpcDefinition = rpcDefinitionOptional.orElseThrow();
final ContainerNode inputNode = rpcToNNode(operationElement, rpcDefinition);
final DOMRpcResult result;
} catch (final InterruptedException | ExecutionException e) {
throw DocumentedException.wrap(e);
}
- if (result.getResult() == null) {
+ if (result.value() == null) {
return XmlUtil.createElement(document, XmlNetconfConstants.OK,
Optional.of(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0));
}
- return transformNormalizedNode(document, result.getResult(),
+ return transformNormalizedNode(document, result.value(),
Absolute.of(rpcDefinition.getQName(), rpcDefinition.getOutput().getQName()));
}
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Copyright (c) 2016 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"
- odl:use-default-for-reference-types="true">
-
- <reference id="domDataBroker" interface="org.opendaylight.mdsal.dom.api.DOMDataBroker"/>
- <reference id="domRpcService" interface="org.opendaylight.mdsal.dom.api.DOMRpcService"/>
- <reference id="schemaService"
- interface="org.opendaylight.mdsal.dom.api.DOMSchemaService"/>
- <reference id="netconfOperationServiceFactoryListener"
- interface="org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactoryListener"
- odl:type="mapper-aggregator-registry"/>
-
- <bean id="mdsalNetconfOperationServiceFactory"
- class="org.opendaylight.netconf.mdsal.connector.MdsalNetconfOperationServiceFactory"
- factory-method="create"
- destroy-method="close">
- <argument ref="schemaService"/>
- <argument ref="netconfOperationServiceFactoryListener"/>
- <argument ref="domDataBroker"/>
- <argument ref="domRpcService"/>
- </bean>
- <service ref="mdsalNetconfOperationServiceFactory"
- interface="org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory"
- odl:type="mdsal-netconf-connector"/>
-
-</blueprint>
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doNothing;
-import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFailedFluentFuture;
-import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFluentFuture;
import com.google.common.base.Preconditions;
import com.google.common.io.ByteSource;
-import com.google.common.util.concurrent.FluentFuture;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
private static final DOMRpcService RPC_SERVICE_VOID_INVOKER = new DOMRpcService() {
@Override
- public FluentFuture<DOMRpcResult> invokeRpc(final QName type, final ContainerNode input) {
- return immediateFluentFuture(new DefaultDOMRpcResult(null, List.of()));
+ public ListenableFuture<DOMRpcResult> invokeRpc(final QName type, final ContainerNode input) {
+ return Futures.immediateFuture(new DefaultDOMRpcResult(null, List.of()));
}
@Override
private static final DOMRpcService RPC_SERVICE_FAILED_INVOCATION = new DOMRpcService() {
@Override
- public FluentFuture<DOMRpcResult> invokeRpc(final QName type, final ContainerNode input) {
- return immediateFailedFluentFuture(new DOMRpcException("rpc invocation not implemented yet") {
+ public ListenableFuture<DOMRpcResult> invokeRpc(final QName type, final ContainerNode input) {
+ return Futures.immediateFailedFuture(new DOMRpcException("rpc invocation not implemented yet") {
private static final long serialVersionUID = 1L;
});
}
private final DOMRpcService rpcServiceSuccessfulInvocation = new DOMRpcService() {
@Override
- public FluentFuture<DOMRpcResult> invokeRpc(final QName type, final ContainerNode input) {
+ public ListenableFuture<DOMRpcResult> invokeRpc(final QName type, final ContainerNode input) {
final Collection<DataContainerChild> children = input.body();
final Module module = SCHEMA_CONTEXT.findModules(type.getNamespace()).stream()
.findFirst().orElse(null);
.withValue(children)
.build();
- return immediateFluentFuture(new DefaultDOMRpcResult(node));
+ return Futures.immediateFuture(new DefaultDOMRpcResult(node));
}
@Override
final SourceIdentifier sId = (SourceIdentifier) invocationOnMock.getArguments()[0];
final YangTextSchemaSource yangTextSchemaSource =
YangTextSchemaSource.delegateForByteSource(sId, ByteSource.wrap("module test".getBytes()));
- return immediateFluentFuture(yangTextSchemaSource);
+ return Futures.immediateFuture(yangTextSchemaSource);
}).when(sourceProvider).getSource(any(SourceIdentifier.class));
currentSchemaContext = CurrentSchemaContext.create(schemaService, sourceProvider);