2 * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netconf.keystore.legacy.impl;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.collect.ImmutableClassToInstanceMap;
13 import com.google.common.util.concurrent.Futures;
14 import com.google.common.util.concurrent.ListenableFuture;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.opendaylight.aaa.encrypt.AAAEncryptionService;
17 import org.opendaylight.mdsal.binding.api.DataBroker;
18 import org.opendaylight.mdsal.binding.api.RpcProviderService;
19 import org.opendaylight.mdsal.singleton.api.ClusterSingletonService;
20 import org.opendaylight.mdsal.singleton.api.ServiceGroupIdentifier;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev231109.AddKeystoreEntry;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev231109.AddPrivateKey;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev231109.AddTrustedCertificate;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev231109.RemoveKeystoreEntry;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev231109.RemovePrivateKey;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev231109.RemoveTrustedCertificate;
27 import org.opendaylight.yangtools.concepts.Registration;
28 import org.opendaylight.yangtools.yang.binding.Rpc;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 final class RpcSingleton implements ClusterSingletonService {
33 private static final Logger LOG = LoggerFactory.getLogger(RpcSingleton.class);
34 private static final @NonNull ServiceGroupIdentifier SGI = new ServiceGroupIdentifier("netconf-keystore-rpc");
36 private final AAAEncryptionService encryptionService;
37 private final RpcProviderService rpcProvider;
38 private final DataBroker dataBroker;
40 private Registration reg;
42 RpcSingleton(final DataBroker dataBroker, final RpcProviderService rpcProvider,
43 final AAAEncryptionService encryptionService) {
44 this.dataBroker = requireNonNull(dataBroker);
45 this.rpcProvider = requireNonNull(rpcProvider);
46 this.encryptionService = requireNonNull(encryptionService);
50 public ServiceGroupIdentifier getIdentifier() {
55 public void instantiateServiceInstance() {
57 LOG.warn("Instiatiating while already running, very weird", new Throwable());
61 LOG.debug("Registering RPC implementations");
62 reg = rpcProvider.registerRpcImplementations(ImmutableClassToInstanceMap.<Rpc<?, ?>>builder()
63 .put(AddKeystoreEntry.class, new DefaultAddKeystoreEntry(dataBroker, encryptionService))
64 .put(RemoveKeystoreEntry.class, new DefaultRemoveKeystoreEntry(dataBroker))
65 .put(AddPrivateKey.class, new DefaultAddPrivateKey(dataBroker))
66 .put(RemovePrivateKey.class, new DefaultRemovePrivateKey(dataBroker))
67 .put(AddTrustedCertificate.class, new DefaultAddTrustedCertificate(dataBroker))
68 .put(RemoveTrustedCertificate.class, new DefaultRemoveTrustedCertificate(dataBroker))
70 LOG.info("This node is now owning NETCONF keystore configuration");
74 public ListenableFuture<?> closeServiceInstance() {
76 LOG.debug("Unregistering RPC implementations");
79 LOG.info("This node is no longer owning NETCONF keystore configuration");
81 return Futures.immediateVoidFuture();