/*
- * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2015, 2016 Ericsson India Global Services Pvt Ltd. 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,
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.op.rev150701.dpn.endpoints.DPNTEPsInfo;
import com.google.common.base.Optional;
-
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.config.rev151102.TunnelMonitorEnabled;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.config.rev151102.TunnelMonitorInterval;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.config.rev151102.TunnelMonitorEnabledBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.itm.config.rev151102.TunnelMonitorIntervalBuilder;
public class ITMManager implements AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(ITMManager.class);
public void setNotificationPublishService(NotificationPublishService notificationPublishService) {
this.notificationPublishService = notificationPublishService;
}
+ protected void initTunnelMonitorDataInConfigDS() {
+ new Thread() {
+ public void run() {
+ boolean readSucceeded = false;
+ InstanceIdentifier<TunnelMonitorEnabled> monitorPath = InstanceIdentifier.builder(TunnelMonitorEnabled.class).build();
+ while (!readSucceeded) {
+ try {
+ Optional<TunnelMonitorEnabled> storedTunnelMonitor = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, monitorPath, broker);
+ // Store default values only when tunnel monitor data is not initialized
+ if (!storedTunnelMonitor.isPresent()) {
+ TunnelMonitorEnabled monitorEnabled =
+ new TunnelMonitorEnabledBuilder().setEnabled(ITMConstants.DEFAULT_MONITOR_ENABLED).build();
+ ItmUtils.asyncUpdate(LogicalDatastoreType.CONFIGURATION, monitorPath, monitorEnabled, broker, ItmUtils.DEFAULT_CALLBACK);
+
+ InstanceIdentifier<TunnelMonitorInterval> intervalPath = InstanceIdentifier.builder(TunnelMonitorInterval.class).build();
+ TunnelMonitorInterval monitorInteval =
+ new TunnelMonitorIntervalBuilder().setInterval(ITMConstants.DEFAULT_MONITOR_INTERVAL).build();
+ ItmUtils.asyncUpdate(LogicalDatastoreType.CONFIGURATION, intervalPath, monitorInteval, broker, ItmUtils.DEFAULT_CALLBACK);
+ }
+ readSucceeded = true;
+ } catch (Exception e) {
+ LOG.warn("Unable to read monitor enabled info; retrying after some delay");
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException ie) {
+ return;
+ }
+ }
+ }
+ }
+ }.start();
+ }
+ protected boolean getTunnelMonitorEnabledFromConfigDS() {
+ boolean tunnelMonitorEnabled = true;
+ InstanceIdentifier<TunnelMonitorEnabled> path = InstanceIdentifier.builder(TunnelMonitorEnabled.class).build();
+ Optional<TunnelMonitorEnabled> storedTunnelMonitor = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, broker);
+ if (storedTunnelMonitor.isPresent()) {
+ tunnelMonitorEnabled = storedTunnelMonitor.get().isEnabled();
+ }
+ return tunnelMonitorEnabled;
+ }
+
+ protected int getTunnelMonitorIntervalFromConfigDS() {
+ int tunnelMonitorInterval = ITMConstants.DEFAULT_MONITOR_INTERVAL;
+ InstanceIdentifier<TunnelMonitorInterval> path = InstanceIdentifier.builder(TunnelMonitorInterval.class).build();
+ Optional<TunnelMonitorInterval> storedTunnelMonitor = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, broker);
+ if (storedTunnelMonitor.isPresent()) {
+ tunnelMonitorInterval = storedTunnelMonitor.get().getInterval();
+ }
+ return tunnelMonitorInterval;
+ }
}