Convert cluster-admin to OSGi DS
[controller.git] / opendaylight / md-sal / sal-cluster-admin-impl / src / main / java / org / opendaylight / controller / cluster / datastore / admin / OSGiClusterAdmin.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.cluster.datastore.admin;
9
10 import com.google.common.annotations.Beta;
11 import org.opendaylight.controller.cluster.datastore.DistributedDataStoreInterface;
12 import org.opendaylight.mdsal.binding.api.RpcProviderService;
13 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.ClusterAdminService;
15 import org.opendaylight.yangtools.concepts.ObjectRegistration;
16 import org.osgi.service.component.annotations.Activate;
17 import org.osgi.service.component.annotations.Component;
18 import org.osgi.service.component.annotations.Deactivate;
19 import org.osgi.service.component.annotations.Reference;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 @Beta
24 @Component(immediate = true)
25 public final class OSGiClusterAdmin {
26     private static final Logger LOG = LoggerFactory.getLogger(OSGiClusterAdmin.class);
27
28     @Reference(target = "(type=distributed-config)")
29     DistributedDataStoreInterface configDatastore = null;
30     @Reference(target = "(type=distributed-operational)")
31     DistributedDataStoreInterface operDatastore = null;
32     @Reference
33     BindingNormalizedNodeSerializer serializer = null;
34     @Reference
35     RpcProviderService rpcProviderService = null;
36
37     private ObjectRegistration<?> reg;
38
39     @Activate
40     void activate() {
41         reg = rpcProviderService.registerRpcImplementation(ClusterAdminService.class,
42             new ClusterAdminRpcService(configDatastore, operDatastore, serializer));
43         LOG.info("Cluster Admin services started");
44     }
45
46     @Deactivate
47     void deactivate() {
48         reg.close();
49         LOG.info("Cluster Admin services stopped");
50     }
51 }