mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-22 21:01:00 +02:00
MastershipService.relinquishRole returns CompletableFuture + Block deviceDiconnected until role relinquish is complete
Change-Id: I081df48fc05fdca2e452a937a093d5caa16091ed
This commit is contained in:
parent
4859be0403
commit
c6e574f90e
@ -55,8 +55,9 @@ public interface MastershipService {
|
|||||||
* for this device, no master selection will occur.
|
* for this device, no master selection will occur.
|
||||||
*
|
*
|
||||||
* @param deviceId the identifier of the device
|
* @param deviceId the identifier of the device
|
||||||
|
* @return future that is completed when relinquish is complete
|
||||||
*/
|
*/
|
||||||
void relinquishMastership(DeviceId deviceId);
|
CompletableFuture<Void> relinquishMastership(DeviceId deviceId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current master for a given device.
|
* Returns the current master for a given device.
|
||||||
|
@ -38,7 +38,8 @@ public class MastershipServiceAdapter implements MastershipService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void relinquishMastership(DeviceId deviceId) {
|
public CompletableFuture<Void> relinquishMastership(DeviceId deviceId) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -95,12 +95,13 @@ public class MastershipManager
|
|||||||
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
|
||||||
protected MetricsService metricsService;
|
protected MetricsService metricsService;
|
||||||
|
|
||||||
|
private NodeId localNodeId;
|
||||||
private Timer requestRoleTimer;
|
private Timer requestRoleTimer;
|
||||||
|
|
||||||
@Activate
|
@Activate
|
||||||
public void activate() {
|
public void activate() {
|
||||||
requestRoleTimer = createTimer("Mastership", "requestRole", "responseTime");
|
requestRoleTimer = createTimer("Mastership", "requestRole", "responseTime");
|
||||||
|
localNodeId = clusterService.getLocalNode().id();
|
||||||
eventDispatcher.addSink(MastershipEvent.class, listenerRegistry);
|
eventDispatcher.addSink(MastershipEvent.class, listenerRegistry);
|
||||||
store.setDelegate(delegate);
|
store.setDelegate(delegate);
|
||||||
log.info("Started");
|
log.info("Started");
|
||||||
@ -136,11 +137,8 @@ public class MastershipManager
|
|||||||
return CompletableFuture.completedFuture(null);
|
return CompletableFuture.completedFuture(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
return eventFuture.whenComplete((event, error) -> {
|
return eventFuture.thenAccept(this::post)
|
||||||
if (event != null) {
|
.thenApply(v -> null);
|
||||||
post(event);
|
|
||||||
}
|
|
||||||
}).thenApply(v -> null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -152,15 +150,11 @@ public class MastershipManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void relinquishMastership(DeviceId deviceId) {
|
public CompletableFuture<Void> relinquishMastership(DeviceId deviceId) {
|
||||||
checkPermission(Permission.CLUSTER_WRITE);
|
checkPermission(Permission.CLUSTER_WRITE);
|
||||||
|
return store.relinquishRole(localNodeId, deviceId)
|
||||||
store.relinquishRole(clusterService.getLocalNode().id(), deviceId)
|
.thenAccept(this::post)
|
||||||
.whenComplete((event, error) -> {
|
.thenApply(v -> null);
|
||||||
if (event != null) {
|
|
||||||
post(event);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
package org.onosproject.net.device.impl;
|
package org.onosproject.net.device.impl;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import org.apache.felix.scr.annotations.Activate;
|
import org.apache.felix.scr.annotations.Activate;
|
||||||
import org.apache.felix.scr.annotations.Component;
|
import org.apache.felix.scr.annotations.Component;
|
||||||
import org.apache.felix.scr.annotations.Deactivate;
|
import org.apache.felix.scr.annotations.Deactivate;
|
||||||
@ -411,8 +410,15 @@ public class DeviceManager
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
|
try {
|
||||||
//relinquish master role and ability to be backup.
|
//relinquish master role and ability to be backup.
|
||||||
mastershipService.relinquishMastership(deviceId);
|
mastershipService.relinquishMastership(deviceId).get();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
log.warn("Interrupted while reliquishing role for {}", deviceId);
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
} catch (ExecutionException e) {
|
||||||
|
log.error("Exception thrown while relinquishing role for {}", deviceId, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,6 +310,11 @@ public class DeviceManagerTest {
|
|||||||
return CompletableFuture.completedFuture(MastershipRole.MASTER);
|
return CompletableFuture.completedFuture(MastershipRole.MASTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Void> relinquishMastership(DeviceId deviceId) {
|
||||||
|
return CompletableFuture.completedFuture(null);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MastershipTerm getMastershipTerm(DeviceId deviceId) {
|
public MastershipTerm getMastershipTerm(DeviceId deviceId) {
|
||||||
// FIXME: just returning something not null
|
// FIXME: just returning something not null
|
||||||
|
@ -37,6 +37,7 @@ import org.onosproject.net.Annotations;
|
|||||||
import org.onosproject.net.DefaultAnnotations;
|
import org.onosproject.net.DefaultAnnotations;
|
||||||
import org.onosproject.net.Device;
|
import org.onosproject.net.Device;
|
||||||
import org.onosproject.net.DeviceId;
|
import org.onosproject.net.DeviceId;
|
||||||
|
import org.onosproject.net.MastershipRole;
|
||||||
import org.onosproject.net.Port;
|
import org.onosproject.net.Port;
|
||||||
import org.onosproject.net.PortNumber;
|
import org.onosproject.net.PortNumber;
|
||||||
import org.onosproject.net.SparseAnnotations;
|
import org.onosproject.net.SparseAnnotations;
|
||||||
@ -62,6 +63,7 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@ -854,6 +856,10 @@ public class GossipDeviceStoreTest {
|
|||||||
public NodeId getMasterFor(DeviceId deviceId) {
|
public NodeId getMasterFor(DeviceId deviceId) {
|
||||||
return NID1;
|
return NID1;
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<MastershipRole> requestRoleFor(DeviceId deviceId) {
|
||||||
|
return CompletableFuture.completedFuture(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class TestGossipDeviceStore extends GossipDeviceStore {
|
private static final class TestGossipDeviceStore extends GossipDeviceStore {
|
||||||
|
@ -502,8 +502,8 @@ public class LLDPLinkProviderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void relinquishMastership(DeviceId deviceId) {
|
public CompletableFuture<Void> relinquishMastership(DeviceId deviceId) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user