import org.opendaylight.netconf.topology.spi.NetconfClientConfigurationBuilderFactory;
import org.opendaylight.netconf.topology.spi.NetconfNodeUtils;
import org.opendaylight.netconf.topology.spi.NetconfTopologyRPCProvider;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev221225.NetconfNodeTopologyService;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
LOG.debug("Registering datastore listener");
dtclReg = dataBroker.registerDataTreeChangeListener(DataTreeIdentifier.create(
LogicalDatastoreType.CONFIGURATION, createTopologyListPath(topologyId).child(Node.class)), this);
- rpcReg = rpcProviderService.registerRpcImplementation(NetconfNodeTopologyService.class,
- new NetconfTopologyRPCProvider(dataBroker, encryptionService, topologyId));
+ final var nodeTopologyRpcs = new NetconfTopologyRPCProvider(dataBroker, encryptionService, topologyId);
+ rpcReg = rpcProviderService.registerRpcImplementations(nodeTopologyRpcs.getRpcClassToInstanceMap());
}
@PreDestroy
import org.opendaylight.netconf.topology.spi.NetconfNodeUtils;
import org.opendaylight.netconf.topology.spi.NetconfTopologyRPCProvider;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev221225.NetconfNode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev221225.NetconfNodeTopologyService;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
this.builderFactory = requireNonNull(builderFactory);
dataChangeListenerRegistration = registerDataTreeChangeListener();
- rpcReg = rpcProviderService.registerRpcImplementation(NetconfNodeTopologyService.class,
- new NetconfTopologyRPCProvider(dataBroker, encryptionService, topologyId));
+ final var nodeTopologyRpcs = new NetconfTopologyRPCProvider(dataBroker, encryptionService, topologyId);
+ rpcReg = rpcProviderService.registerRpcImplementations(nodeTopologyRpcs.getRpcClassToInstanceMap());
}
@Override
import static java.util.Objects.requireNonNull;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.ClassToInstanceMap;
+import com.google.common.collect.ImmutableClassToInstanceMap;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.device.rev230430.credentials.credentials.LoginPw;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.device.rev230430.credentials.credentials.LoginPwBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.device.rev230430.credentials.credentials.login.pw.LoginPasswordBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev221225.CreateDevice;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev221225.CreateDeviceInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev221225.CreateDeviceOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev221225.CreateDeviceOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev221225.DeleteDevice;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev221225.DeleteDeviceInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev221225.DeleteDeviceOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev221225.DeleteDeviceOutputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev221225.NetconfNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev221225.NetconfNodeBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev221225.NetconfNodeTopologyService;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.Rpc;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Deprecated
-public class NetconfTopologyRPCProvider implements NetconfNodeTopologyService {
+public class NetconfTopologyRPCProvider {
private static final Logger LOG = LoggerFactory.getLogger(NetconfTopologyRPCProvider.class);
private final @NonNull InstanceIdentifier<Topology> topologyPath;
private final @NonNull DataBroker dataBroker;
public NetconfTopologyRPCProvider(final DataBroker dataBroker, final AAAEncryptionService encryptionService,
- final String topologyId) {
+ final String topologyId) {
this.dataBroker = requireNonNull(dataBroker);
this.encryptionService = requireNonNull(encryptionService);
topologyPath = InstanceIdentifier.builder(NetworkTopology.class)
- .child(Topology.class, new TopologyKey(new TopologyId(topologyId)))
- .build();
+ .child(Topology.class, new TopologyKey(new TopologyId(topologyId)))
+ .build();
}
protected final @NonNull InstanceIdentifier<Topology> topologyPath() {
return topologyPath;
}
- @Override
- public final ListenableFuture<RpcResult<CreateDeviceOutput>> createDevice(final CreateDeviceInput input) {
+ private ListenableFuture<RpcResult<CreateDeviceOutput>> createDevice(final CreateDeviceInput input) {
final NetconfNode node = encryptPassword(input);
final SettableFuture<RpcResult<CreateDeviceOutput>> futureResult = SettableFuture.create();
final NodeId nodeId = new NodeId(input.getNodeId());
return futureResult;
}
- @Override
- public final ListenableFuture<RpcResult<DeleteDeviceOutput>> deleteDevice(final DeleteDeviceInput input) {
+ private ListenableFuture<RpcResult<DeleteDeviceOutput>> deleteDevice(final DeleteDeviceInput input) {
final NodeId nodeId = new NodeId(input.getNodeId());
final InstanceIdentifier<Node> niid = topologyPath.child(Node.class, new NodeKey(nodeId));
}
}, MoreExecutors.directExecutor());
}
+
+ public ClassToInstanceMap<Rpc<?, ?>> getRpcClassToInstanceMap() {
+ return ImmutableClassToInstanceMap.<Rpc<?, ?>>builder()
+ .put(CreateDevice.class, this::createDevice)
+ .put(DeleteDevice.class, this::deleteDevice)
+ .build();
+ }
}
import javax.inject.Singleton;
import org.opendaylight.mdsal.binding.api.MountPointService;
import org.opendaylight.mdsal.binding.api.RpcProviderService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ncmount.rev150105.NcmountService;
import org.opendaylight.yangtools.concepts.Registration;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
@Activate
public EndtoendTestService(final @Reference RpcProviderService rpcProviderService,
final @Reference MountPointService mountPointService) {
- registration = rpcProviderService.registerRpcImplementation(NcmountService.class,
- new NcmountServiceImpl(mountPointService));
+ final var ncmountRpcs = new NcmountRpcs(mountPointService);
+ registration = rpcProviderService.registerRpcImplementations(ncmountRpcs.getRpcClassToInstanceMap());
}
@Override
import static java.util.Objects.requireNonNull;
+import com.google.common.collect.ClassToInstanceMap;
+import com.google.common.collect.ImmutableClassToInstanceMap;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
import java.util.Map;
import org.opendaylight.yang.gen.v1.http.cisco.com.ns.yang.cisco.ios.xr.ip._static.cfg.rev130722.vrf.unicast.VrfUnicastBuilder;
import org.opendaylight.yang.gen.v1.http.cisco.com.ns.yang.cisco.xr.types.rev150119.CiscoIosXrString;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ncmount.rev150105.ListNodes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ncmount.rev150105.ListNodesInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ncmount.rev150105.ListNodesOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ncmount.rev150105.NcmountService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ncmount.rev150105.ShowNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ncmount.rev150105.ShowNodeInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ncmount.rev150105.ShowNodeOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ncmount.rev150105.WriteRoutes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ncmount.rev150105.WriteRoutesInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ncmount.rev150105.WriteRoutesOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ncmount.rev150105.WriteRoutesOutputBuilder;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.Rpc;
import org.opendaylight.yangtools.yang.binding.util.BindingMap;
import org.opendaylight.yangtools.yang.common.ErrorType;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
-public class NcmountServiceImpl implements NcmountService {
+public class NcmountRpcs {
private final MountPointService mountPointService;
- public NcmountServiceImpl(final MountPointService mountPointService) {
+ public NcmountRpcs(final MountPointService mountPointService) {
this.mountPointService = requireNonNull(mountPointService);
}
- @Override
- public ListenableFuture<RpcResult<WriteRoutesOutput>> writeRoutes(final WriteRoutesInput input) {
+ private ListenableFuture<RpcResult<WriteRoutesOutput>> writeRoutes(final WriteRoutesInput input) {
final Optional<MountPoint> optMountPoint = mountPointService.getMountPoint(
NetconfNodeUtils.DEFAULT_TOPOLOGY_IID.child(Node.class, new NodeKey(new NodeId(input.getMountName()))));
if (optMountPoint.isEmpty()) {
MoreExecutors.directExecutor());
}
- @Override
- public ListenableFuture<RpcResult<ShowNodeOutput>> showNode(final ShowNodeInput input) {
+ private ListenableFuture<RpcResult<ShowNodeOutput>> showNode(final ShowNodeInput input) {
return RpcResultBuilder.<ShowNodeOutput>failed()
.withError(ErrorType.APPLICATION, "Not implemented")
.buildFuture();
}
- @Override
- public ListenableFuture<RpcResult<ListNodesOutput>> listNodes(final ListNodesInput input) {
+ private ListenableFuture<RpcResult<ListNodesOutput>> listNodes(final ListNodesInput input) {
return RpcResultBuilder.<ListNodesOutput>failed()
.withError(ErrorType.APPLICATION, "Not implemented")
.buildFuture();
}
+
+ public ClassToInstanceMap<Rpc<?, ?>> getRpcClassToInstanceMap() {
+ return ImmutableClassToInstanceMap.<Rpc<?, ?>>builder()
+ .put(WriteRoutes.class, this::writeRoutes)
+ .put(ShowNode.class, this::showNode)
+ .put(ListNodes.class, this::listNodes)
+ .build();
+ }
}
import static java.util.Objects.requireNonNull;
+import com.google.common.collect.ClassToInstanceMap;
+import com.google.common.collect.ImmutableClassToInstanceMap;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
import org.opendaylight.mdsal.binding.api.WriteTransaction;
import org.opendaylight.mdsal.common.api.CommitInfo;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.AddKeystoreEntry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.AddKeystoreEntryInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.AddKeystoreEntryOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.AddKeystoreEntryOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.AddPrivateKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.AddPrivateKeyInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.AddPrivateKeyOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.AddPrivateKeyOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.AddTrustedCertificate;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.AddTrustedCertificateInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.AddTrustedCertificateOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.AddTrustedCertificateOutputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.Keystore;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.NetconfKeystoreService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.RemoveKeystoreEntry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.RemoveKeystoreEntryInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.RemoveKeystoreEntryOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.RemoveKeystoreEntryOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.RemovePrivateKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.RemovePrivateKeyInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.RemovePrivateKeyOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.RemovePrivateKeyOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.RemoveTrustedCertificate;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.RemoveTrustedCertificateInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.RemoveTrustedCertificateOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.RemoveTrustedCertificateOutputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.trusted.certificates.TrustedCertificateKey;
import org.opendaylight.yangtools.concepts.Registration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.Rpc;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
import org.osgi.service.component.annotations.Activate;
@Singleton
@Component(service = { })
-public final class NetconfSalKeystoreService implements NetconfKeystoreService, AutoCloseable {
- private static final Logger LOG = LoggerFactory.getLogger(NetconfSalKeystoreService.class);
+public final class NetconfSalKeystoreRpcs implements AutoCloseable {
+ private static final Logger LOG = LoggerFactory.getLogger(NetconfSalKeystoreRpcs.class);
private static final InstanceIdentifier<Keystore> KEYSTORE_IID = InstanceIdentifier.create(Keystore.class);
// FIXME: we are populating config datastore, but there may be risks with concurrent access. We really should be
@Inject
@Activate
- public NetconfSalKeystoreService(@Reference final DataBroker dataBroker,
+ public NetconfSalKeystoreRpcs(@Reference final DataBroker dataBroker,
@Reference final AAAEncryptionService encryptionService, @Reference final RpcProviderService rpcProvider) {
this.dataBroker = requireNonNull(dataBroker);
this.encryptionService = requireNonNull(encryptionService);
- reg = rpcProvider.registerRpcImplementation(NetconfKeystoreService.class, this);
+ reg = rpcProvider.registerRpcImplementations(getRpcClassToInstanceMap());
LOG.info("NETCONF keystore service started");
}
LOG.info("NETCONF keystore service stopped");
}
- @Override
- public ListenableFuture<RpcResult<RemoveKeystoreEntryOutput>> removeKeystoreEntry(
+ private ListenableFuture<RpcResult<RemoveKeystoreEntryOutput>> removeKeystoreEntry(
final RemoveKeystoreEntryInput input) {
LOG.debug("Removing keypairs: {}", input);
for (final String id : input.getKeyId()) {
writeTransaction.delete(LogicalDatastoreType.CONFIGURATION,
- KEYSTORE_IID.child(KeyCredential.class, new KeyCredentialKey(id)));
+ KEYSTORE_IID.child(KeyCredential.class, new KeyCredentialKey(id)));
}
final SettableFuture<RpcResult<RemoveKeystoreEntryOutput>> rpcResult = SettableFuture.create();
return rpcResult;
}
- @Override
- public ListenableFuture<RpcResult<AddKeystoreEntryOutput>> addKeystoreEntry(final AddKeystoreEntryInput input) {
+ private ListenableFuture<RpcResult<AddKeystoreEntryOutput>> addKeystoreEntry(final AddKeystoreEntryInput input) {
LOG.debug("Adding keypairs: {}", input);
final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
final List<KeyCredential> keypairs = input.nonnullKeyCredential().values().stream()
- .map(keypair -> new KeyCredentialBuilder(keypair)
- .setPrivateKey(encryptionService.encrypt(keypair.getPrivateKey()))
- .setPassphrase(encryptionService.encrypt(keypair.getPassphrase()))
- .build())
- .collect(Collectors.toList());
+ .map(keypair -> new KeyCredentialBuilder(keypair)
+ .setPrivateKey(encryptionService.encrypt(keypair.getPrivateKey()))
+ .setPassphrase(encryptionService.encrypt(keypair.getPassphrase()))
+ .build())
+ .collect(Collectors.toList());
for (KeyCredential keypair : keypairs) {
writeTransaction.merge(LogicalDatastoreType.CONFIGURATION,
- KEYSTORE_IID.child(KeyCredential.class, keypair.key()), keypair);
+ KEYSTORE_IID.child(KeyCredential.class, keypair.key()), keypair);
}
final SettableFuture<RpcResult<AddKeystoreEntryOutput>> rpcResult = SettableFuture.create();
return rpcResult;
}
- @Override
- public ListenableFuture<RpcResult<AddTrustedCertificateOutput>> addTrustedCertificate(
+ private ListenableFuture<RpcResult<AddTrustedCertificateOutput>> addTrustedCertificate(
final AddTrustedCertificateInput input) {
final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
for (TrustedCertificate certificate : input.nonnullTrustedCertificate().values()) {
writeTransaction.merge(LogicalDatastoreType.CONFIGURATION,
- KEYSTORE_IID.child(TrustedCertificate.class, certificate.key()), certificate);
+ KEYSTORE_IID.child(TrustedCertificate.class, certificate.key()), certificate);
}
final SettableFuture<RpcResult<AddTrustedCertificateOutput>> rpcResult = SettableFuture.create();
return rpcResult;
}
- @Override
- public ListenableFuture<RpcResult<RemoveTrustedCertificateOutput>> removeTrustedCertificate(
+ private ListenableFuture<RpcResult<RemoveTrustedCertificateOutput>> removeTrustedCertificate(
final RemoveTrustedCertificateInput input) {
final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
for (final String name : input.getName()) {
writeTransaction.delete(LogicalDatastoreType.CONFIGURATION,
- KEYSTORE_IID.child(TrustedCertificate.class, new TrustedCertificateKey(name)));
+ KEYSTORE_IID.child(TrustedCertificate.class, new TrustedCertificateKey(name)));
}
final SettableFuture<RpcResult<RemoveTrustedCertificateOutput>> rpcResult = SettableFuture.create();
return rpcResult;
}
- @Override
- public ListenableFuture<RpcResult<AddPrivateKeyOutput>> addPrivateKey(final AddPrivateKeyInput input) {
+ private ListenableFuture<RpcResult<AddPrivateKeyOutput>> addPrivateKey(final AddPrivateKeyInput input) {
final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
for (PrivateKey key: input.nonnullPrivateKey().values()) {
writeTransaction.merge(LogicalDatastoreType.CONFIGURATION,
- KEYSTORE_IID.child(PrivateKey.class, key.key()), key);
+ KEYSTORE_IID.child(PrivateKey.class, key.key()), key);
}
final SettableFuture<RpcResult<AddPrivateKeyOutput>> rpcResult = SettableFuture.create();
return rpcResult;
}
- @Override
- public ListenableFuture<RpcResult<RemovePrivateKeyOutput>> removePrivateKey(final RemovePrivateKeyInput input) {
+ private ListenableFuture<RpcResult<RemovePrivateKeyOutput>> removePrivateKey(final RemovePrivateKeyInput input) {
final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
for (final String name : input.getName()) {
writeTransaction.delete(LogicalDatastoreType.CONFIGURATION,
- KEYSTORE_IID.child(PrivateKey.class, new PrivateKeyKey(name)));
+ KEYSTORE_IID.child(PrivateKey.class, new PrivateKeyKey(name)));
}
final SettableFuture<RpcResult<RemovePrivateKeyOutput>> rpcResult = SettableFuture.create();
return rpcResult;
}
+
+ public ClassToInstanceMap<Rpc<?, ?>> getRpcClassToInstanceMap() {
+ return ImmutableClassToInstanceMap.<Rpc<?, ?>>builder()
+ .put(RemoveKeystoreEntry.class, this::removeKeystoreEntry)
+ .put(AddKeystoreEntry.class, this::addKeystoreEntry)
+ .put(AddTrustedCertificate.class, this::addTrustedCertificate)
+ .put(RemoveTrustedCertificate.class, this::removeTrustedCertificate)
+ .put(AddPrivateKey.class, this::addPrivateKey)
+ .put(RemovePrivateKey.class, this::removePrivateKey)
+ .build();
+ }
}
package org.opendaylight.netconf.client.mdsal.impl;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
import org.opendaylight.mdsal.binding.api.WriteTransaction;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.netconf.api.xml.XmlUtil;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.AddPrivateKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.AddPrivateKeyInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.AddPrivateKeyInputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.AddTrustedCertificate;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.AddTrustedCertificateInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.AddTrustedCertificateInputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.NetconfKeystoreService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017._private.keys.PrivateKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017._private.keys.PrivateKeyBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017._private.keys.PrivateKeyKey;
import org.w3c.dom.NodeList;
@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class NetconfSalKeystoreServiceTest {
+public class NetconfSalKeystoreRpcsTest {
private static final String XML_ELEMENT_PRIVATE_KEY = "private-key";
private static final String XML_ELEMENT_NAME = "name";
private static final String XML_ELEMENT_DATA = "data";
doReturn(writeTx).when(dataBroker).newWriteOnlyTransaction();
doNothing().when(writeTx)
.merge(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(DataObject.class));
- doReturn(rpcReg).when(rpcProvider).registerRpcImplementation(eq(NetconfKeystoreService.class), any());
+ doReturn(rpcReg).when(rpcProvider).registerRpcImplementations(any());
doNothing().when(rpcReg).close();
}
@Test
public void testAddPrivateKey() throws Exception {
doReturn(emptyFluentFuture()).when(writeTx).commit();
- try (var keystoreService = new NetconfSalKeystoreService(dataBroker, encryptionService, rpcProvider)) {
+ try (var keystoreService = new NetconfSalKeystoreRpcs(dataBroker, encryptionService, rpcProvider)) {
final AddPrivateKeyInput input = getPrivateKeyInput();
- keystoreService.addPrivateKey(input);
+ keystoreService.getRpcClassToInstanceMap().getInstance(AddPrivateKey.class).invoke(input).get();
verify(writeTx, times(input.nonnullPrivateKey().size()))
.merge(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(DataObject.class));
@Test
public void testAddTrustedCertificate() throws Exception {
doReturn(emptyFluentFuture()).when(writeTx).commit();
- try (var keystoreService = new NetconfSalKeystoreService(dataBroker, encryptionService, rpcProvider)) {
- final AddTrustedCertificateInput input = getTrustedCertificateInput();
- keystoreService.addTrustedCertificate(input);
+ try (var keystoreService = new NetconfSalKeystoreRpcs(dataBroker, encryptionService, rpcProvider)) {
+ final var input = getTrustedCertificateInput();
+ keystoreService.getRpcClassToInstanceMap().getInstance(AddTrustedCertificate.class).invoke(input).get();
verify(writeTx, times(input.nonnullTrustedCertificate().size()))
.merge(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(DataObject.class));