2 * Copyright (c) 2017 Ericsson India Global Services Pvt Ltd. 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.genius.mdsalutil.diagstatus.internal;
10 import javax.annotation.PreDestroy;
11 import javax.inject.Inject;
12 import javax.inject.Singleton;
14 import org.opendaylight.infrautils.diagstatus.DiagStatusService;
15 import org.opendaylight.infrautils.diagstatus.MBeanUtils;
16 import org.opendaylight.infrautils.diagstatus.ServiceDescriptor;
17 import org.opendaylight.infrautils.diagstatus.ServiceState;
18 import org.opendaylight.infrautils.diagstatus.ServiceStatusProvider;
19 import org.ops4j.pax.cdi.api.OsgiService;
20 import org.ops4j.pax.cdi.api.OsgiServiceProvider;
23 @OsgiServiceProvider(classes = ServiceStatusProvider.class)
24 public class DatastoreServiceStatusProvider implements ServiceStatusProvider {
26 private static final String DATASTORE_SERVICE_NAME = "DATASTORE";
27 private volatile ServiceDescriptor serviceDescriptor;
28 private DiagStatusService diagStatusService;
31 public DatastoreServiceStatusProvider(@OsgiService DiagStatusService diagStatusService) {
32 this.diagStatusService = diagStatusService;
33 diagStatusService.register(DATASTORE_SERVICE_NAME);
34 serviceDescriptor = new ServiceDescriptor(DATASTORE_SERVICE_NAME, ServiceState.OPERATIONAL,
36 diagStatusService.report(serviceDescriptor);
41 serviceDescriptor = new ServiceDescriptor(DATASTORE_SERVICE_NAME, ServiceState.UNREGISTERED,
43 diagStatusService.report(serviceDescriptor);
47 public ServiceDescriptor getServiceDescriptor() {
48 ServiceState dataStoreServiceState = ServiceState.ERROR;
50 Boolean operSyncStatusValue = (Boolean) MBeanUtils.readMBeanAttribute("org.opendaylight.controller:type="
51 + "DistributedOperationalDatastore,Category=ShardManager,name=shard-manager-operational",
53 Boolean configSyncStatusValue = (Boolean) MBeanUtils.readMBeanAttribute("org.opendaylight.controller:type="
54 + "DistributedConfigDatastore,Category=ShardManager,name=shard-manager-config",
56 if (operSyncStatusValue != null && configSyncStatusValue != null) {
57 if ((boolean) operSyncStatusValue && (boolean) configSyncStatusValue) {
58 dataStoreServiceState = ServiceState.OPERATIONAL;
59 statusDesc = dataStoreServiceState.name();
61 statusDesc = "datastore out of sync";
64 statusDesc = "Unable to obtain the datastore status";
66 return new ServiceDescriptor(DATASTORE_SERVICE_NAME, dataStoreServiceState, statusDesc);