*/
package org.opendaylight.openflowplugin.api.openflow.device.handlers;
-import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
+import org.opendaylight.openflowplugin.api.openflow.lifecycle.MastershipChangeListener;
/**
* Interface handles MASTER initialization on ownership change.
public interface ClusterInitializationPhaseHandler {
/**
- * Method for initialization cycle between contexts.
- * @param connectionContext to check actual connection state
+ * Method for initialization cycle between contexts
+ * @param mastershipChangeListener - listener if something goes wrong with initialization
*/
- boolean onContextInstantiateService(final ConnectionContext connectionContext);
+ boolean onContextInstantiateService(final MastershipChangeListener mastershipChangeListener);
/**
* Method for initial submit transaction after successful initial gathering.
import org.opendaylight.openflowplugin.api.openflow.device.handlers.ClusterInitializationPhaseHandler;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
+import org.opendaylight.openflowplugin.api.openflow.lifecycle.MastershipChangeListener;
import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
import org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey;
import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
}
@Override
- public boolean onContextInstantiateService(final ConnectionContext connectionContext) {
+ public boolean onContextInstantiateService(final MastershipChangeListener mastershipChangeListener) {
if (getPrimaryConnectionContext().getConnectionState().equals(ConnectionContext.CONNECTION_STATE.RIP)) {
LOG.warn("Connection on device {} was interrupted, will stop starting master services.",
return false;
}
- Futures.addCallback(sendRoleChangeToDevice(OfpRole.BECOMEMASTER), new RpcResultFutureCallback());
+ Futures.addCallback(sendRoleChangeToDevice(OfpRole.BECOMEMASTER),
+ new RpcResultFutureCallback(mastershipChangeListener));
final ListenableFuture<List<Optional<FlowCapableNode>>> deviceFlowRegistryFill = getDeviceFlowRegistry().fill();
Futures.addCallback(deviceFlowRegistryFill, new DeviceFlowRegistryCallback(deviceFlowRegistryFill));
- return this.clusterInitializationPhaseHandler.onContextInstantiateService(getPrimaryConnectionContext());
+ return this.clusterInitializationPhaseHandler.onContextInstantiateService(mastershipChangeListener);
}
@VisibleForTesting
}
private class RpcResultFutureCallback implements FutureCallback<RpcResult<SetRoleOutput>> {
+
+ private final MastershipChangeListener mastershipChangeListener;
+
+ RpcResultFutureCallback(final MastershipChangeListener mastershipChangeListener) {
+ this.mastershipChangeListener = mastershipChangeListener;
+ }
+
@Override
public void onSuccess(@Nullable RpcResult<SetRoleOutput> setRoleOutputRpcResult) {
if (LOG.isDebugEnabled()) {
@Override
public void onFailure(final Throwable throwable) {
LOG.warn("Was not able to set MASTER role on device, node {}", deviceInfo.getLOGValue());
- shutdownConnection();
+ mastershipChangeListener.onNotAbleToStartMastership(deviceInfo);
}
}
@Override
public void makeDeviceSlave(final DeviceContext deviceContext) {
+ final DeviceInfo deviceInf = Objects.isNull(deviceInfo) ? deviceContext.getDeviceInfo() : deviceInfo;
+
Futures.addCallback(deviceContext.makeDeviceSlave(), new FutureCallback<RpcResult<SetRoleOutput>>() {
@Override
public void onSuccess(@Nullable RpcResult<SetRoleOutput> setRoleOutputRpcResult) {
if (LOG.isDebugEnabled()) {
LOG.debug("Role SLAVE was successfully propagated on device, node {}", deviceContext.getDeviceInfo().getLOGValue());
}
- mastershipChangeListener.onSlaveRoleAcquired(deviceInfo);
+ mastershipChangeListener.onSlaveRoleAcquired(deviceInf);
}
@Override
public void onFailure(Throwable throwable) {
LOG.warn("Was not able to set role SLAVE to device on node {} ",deviceContext.getDeviceInfo().getLOGValue());
- mastershipChangeListener.onSlaveRoleNotAcquired(deviceInfo);
+ mastershipChangeListener.onSlaveRoleNotAcquired(deviceInf);
}
});
LOG.info("Starting clustering MASTER services for node {}", deviceInfo.getLOGValue());
if (!clusterInitializationPhaseHandler.onContextInstantiateService(null)) {
mastershipChangeListener.onNotAbleToStartMastership(deviceInfo);
+ } else {
+ mastershipChangeListener.onMasterRoleAcquired(deviceInfo);
}
}
import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.ClusterInitializationPhaseHandler;
+import org.opendaylight.openflowplugin.api.openflow.lifecycle.MastershipChangeListener;
import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider;
}
@Override
- public boolean onContextInstantiateService(final ConnectionContext connectionContext) {
- if (connectionContext.getConnectionState().equals(ConnectionContext.CONNECTION_STATE.RIP)) {
- LOG.warn("Connection on device {} was interrupted, will stop starting master services.", deviceInfo.getLOGValue());
- return false;
- }
+ public boolean onContextInstantiateService(final MastershipChangeListener mastershipChangeListener) {
MdSalRegistrationUtils.registerServices(this, deviceContext, extensionConverterProvider, convertorExecutor);
import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.ClusterInitializationPhaseHandler;
+import org.opendaylight.openflowplugin.api.openflow.lifecycle.MastershipChangeListener;
import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsManager;
}
@Override
- public boolean onContextInstantiateService(final ConnectionContext connectionContext) {
- if (connectionContext.getConnectionState().equals(ConnectionContext.CONNECTION_STATE.RIP)) {
- LOG.warn("Connection on device {} was interrupted, will stop starting master services.", deviceInfo.getLOGValue());
- return false;
- }
+ public boolean onContextInstantiateService(final MastershipChangeListener mastershipChangeListener) {
LOG.info("Starting statistics context cluster services for node {}", deviceInfo.getLOGValue());
@Override
public void onFailure(@Nonnull Throwable throwable) {
LOG.warn("Initial gathering statistics unsuccessful for node {}", deviceInfo.getLOGValue());
+ mastershipChangeListener.onNotAbleToStartMastership(deviceInfo);
}
});
myManager.startScheduling(deviceInfo);
}
- return this.clusterInitializationPhaseHandler.onContextInstantiateService(connectionContext);
+ return this.clusterInitializationPhaseHandler.onContextInstantiateService(mastershipChangeListener);
}
@Override
final MultipartWriterProvider statisticsWriterProvider = MultipartWriterProviderFactory
.createDefaultProvider(deviceContext);
- return deviceContext.canUseSingleLayerSerialization() ?
+ final StatisticsContext statisticsContext =
+ deviceContext.canUseSingleLayerSerialization() ?
new StatisticsContextImpl<MultipartReply>(
isStatisticsPollingOn,
deviceContext,
converterExecutor,
this,
statisticsWriterProvider);
+ contexts.putIfAbsent(deviceContext.getDeviceInfo(), statisticsContext);
+
+ return statisticsContext;
}
public void onDeviceRemoved(DeviceInfo deviceInfo) {