Search in sources :

Example 26 with MastershipRole

use of org.onosproject.net.MastershipRole in project onos by opennetworkinglab.

the class SimpleMastershipStore method relinquishRole.

@Override
public synchronized CompletableFuture<MastershipEvent> relinquishRole(NodeId nodeId, DeviceId deviceId) {
    MastershipRole role = getRole(nodeId, deviceId);
    switch(role) {
        case MASTER:
            NodeId backup = reelect(deviceId, nodeId);
            masterMap.put(deviceId, backup);
            incrementTerm(deviceId);
            return CompletableFuture.completedFuture(new MastershipEvent(MASTER_CHANGED, deviceId, getMastership(deviceId)));
        case STANDBY:
            if (removeFromBackups(deviceId, nodeId)) {
                return CompletableFuture.completedFuture(new MastershipEvent(BACKUPS_CHANGED, deviceId, getMastership(deviceId)));
            }
            break;
        case NONE:
            break;
        default:
            log.warn("unknown Mastership Role {}", role);
    }
    return CompletableFuture.completedFuture(null);
}
Also used : MastershipEvent(org.onosproject.mastership.MastershipEvent) NodeId(org.onosproject.cluster.NodeId) MastershipRole(org.onosproject.net.MastershipRole)

Example 27 with MastershipRole

use of org.onosproject.net.MastershipRole in project onos by opennetworkinglab.

the class SimpleMastershipStore method setMaster.

@Override
public synchronized CompletableFuture<MastershipEvent> setMaster(NodeId nodeId, DeviceId deviceId) {
    MastershipRole role = getRole(nodeId, deviceId);
    switch(role) {
        case MASTER:
            // no-op
            return CompletableFuture.completedFuture(null);
        case STANDBY:
        case NONE:
            NodeId prevMaster = masterMap.put(deviceId, nodeId);
            incrementTerm(deviceId);
            removeFromBackups(deviceId, nodeId);
            addToBackup(deviceId, prevMaster);
            break;
        default:
            log.warn("unknown Mastership Role {}", role);
            return null;
    }
    return CompletableFuture.completedFuture(new MastershipEvent(MASTER_CHANGED, deviceId, getMastership(deviceId)));
}
Also used : MastershipEvent(org.onosproject.mastership.MastershipEvent) NodeId(org.onosproject.cluster.NodeId) MastershipRole(org.onosproject.net.MastershipRole)

Example 28 with MastershipRole

use of org.onosproject.net.MastershipRole in project onos by opennetworkinglab.

the class SimpleMastershipStore method requestRole.

@Override
public synchronized CompletableFuture<MastershipRole> requestRole(DeviceId deviceId) {
    // query+possible reelection
    NodeId node = clusterService.getLocalNode().id();
    MastershipRole role = getRole(node, deviceId);
    switch(role) {
        case MASTER:
            return CompletableFuture.completedFuture(MastershipRole.MASTER);
        case STANDBY:
            if (getMaster(deviceId) == null) {
                // no master => become master
                masterMap.put(deviceId, node);
                incrementTerm(deviceId);
                // remove from backup list
                removeFromBackups(deviceId, node);
                notifyDelegate(new MastershipEvent(MASTER_CHANGED, deviceId, getMastership(deviceId)));
                return CompletableFuture.completedFuture(MastershipRole.MASTER);
            }
            return CompletableFuture.completedFuture(MastershipRole.STANDBY);
        case NONE:
            if (getMaster(deviceId) == null) {
                // no master => become master
                masterMap.put(deviceId, node);
                incrementTerm(deviceId);
                notifyDelegate(new MastershipEvent(MASTER_CHANGED, deviceId, getMastership(deviceId)));
                return CompletableFuture.completedFuture(MastershipRole.MASTER);
            }
            // add to backup list
            if (addToBackup(deviceId, node)) {
                notifyDelegate(new MastershipEvent(BACKUPS_CHANGED, deviceId, getMastership(deviceId)));
            }
            return CompletableFuture.completedFuture(MastershipRole.STANDBY);
        default:
            log.warn("unknown Mastership Role {}", role);
    }
    return CompletableFuture.completedFuture(role);
}
Also used : MastershipEvent(org.onosproject.mastership.MastershipEvent) NodeId(org.onosproject.cluster.NodeId) MastershipRole(org.onosproject.net.MastershipRole)

Example 29 with MastershipRole

use of org.onosproject.net.MastershipRole in project onos by opennetworkinglab.

the class MastershipWebResource method requestRoleFor.

/**
 * Returns the mastership status of the local controller for a given
 * device forcing master selection if necessary.
 *
 * @param deviceId device identifier
 * @return 200 OK with the role of this controller instance
 * @onos.rsModel MastershipRole
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{deviceId}/request")
public Response requestRoleFor(@PathParam("deviceId") String deviceId) {
    MastershipService mastershipService = get(MastershipService.class);
    DeviceService deviceService = get(DeviceService.class);
    DeviceId id = DeviceId.deviceId(deviceId);
    nullIsNotFound(deviceService.getDevice(id), DEVICE_ID_NOT_FOUND);
    MastershipRole role = nullIsNotFound(mastershipService.requestRoleForSync(id), MASTERSHIP_ROLE_NOT_FOUND);
    ObjectNode root = codec(MastershipRole.class).encode(role, this);
    return ok(root).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceId(org.onosproject.net.DeviceId) DeviceService(org.onosproject.net.device.DeviceService) MastershipService(org.onosproject.mastership.MastershipService) MastershipRole(org.onosproject.net.MastershipRole) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 30 with MastershipRole

use of org.onosproject.net.MastershipRole in project onos by opennetworkinglab.

the class MastershipWebResource method getLocalRole.

/**
 * Returns the role of the local node for the specified device.
 *
 * @param deviceId device identifier
 * @return 200 OK with role of the current node
 * @onos.rsModel MastershipRole
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{deviceId}/local")
public Response getLocalRole(@PathParam("deviceId") String deviceId) {
    MastershipService mastershipService = get(MastershipService.class);
    MastershipRole role = mastershipService.getLocalRole(DeviceId.deviceId(deviceId));
    ObjectNode root = codec(MastershipRole.class).encode(role, this);
    return ok(root).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MastershipService(org.onosproject.mastership.MastershipService) MastershipRole(org.onosproject.net.MastershipRole) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

MastershipRole (org.onosproject.net.MastershipRole)32 NodeId (org.onosproject.cluster.NodeId)19 MastershipEvent (org.onosproject.mastership.MastershipEvent)10 DeviceId (org.onosproject.net.DeviceId)10 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 MastershipTerm (org.onosproject.mastership.MastershipTerm)4 ImmutableList (com.google.common.collect.ImmutableList)3 List (java.util.List)3 Map (java.util.Map)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ControllerNode (org.onosproject.cluster.ControllerNode)3 MastershipAdminService (org.onosproject.mastership.MastershipAdminService)3 MastershipInfo (org.onosproject.mastership.MastershipInfo)3 MastershipService (org.onosproject.mastership.MastershipService)3 DeviceEvent (org.onosproject.net.device.DeviceEvent)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Instant (java.time.Instant)2 HashSet (java.util.HashSet)2 Objects (java.util.Objects)2