Search in sources :

Example 21 with MastershipService

use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.

the class DistributedVirtualFlowRuleStore method getTableStatistics.

@Override
public Iterable<TableStatisticsEntry> getTableStatistics(NetworkId networkId, DeviceId deviceId) {
    MastershipService mastershipService = vnaService.get(networkId, MastershipService.class);
    NodeId master = mastershipService.getMasterFor(deviceId);
    if (master == null) {
        log.debug("Failed to getTableStats: No master for {}", deviceId);
        return Collections.emptyList();
    }
    if (deviceTableStats.get(networkId) == null) {
        deviceTableStats.put(networkId, Maps.newConcurrentMap());
    }
    List<TableStatisticsEntry> tableStats = deviceTableStats.get(networkId).get(deviceId);
    if (tableStats == null) {
        return Collections.emptyList();
    }
    return ImmutableList.copyOf(tableStats);
}
Also used : NodeId(org.onosproject.cluster.NodeId) MastershipService(org.onosproject.mastership.MastershipService) TableStatisticsEntry(org.onosproject.net.flow.TableStatisticsEntry)

Example 22 with MastershipService

use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.

the class DistributedVirtualFlowRuleStore method removeFlowRule.

@Override
public FlowRuleEvent removeFlowRule(NetworkId networkId, FlowEntry rule) {
    final DeviceId deviceId = rule.deviceId();
    MastershipService mastershipService = vnaService.get(networkId, MastershipService.class);
    NodeId master = mastershipService.getMasterFor(deviceId);
    if (Objects.equals(local, master)) {
        // bypass and handle it locally
        return removeFlowRuleInternal(new VirtualFlowEntry(networkId, rule));
    }
    if (master == null) {
        log.warn("Failed to removeFlowRule: No master for {}", deviceId);
        // TODO: revisit if this should be null (="no-op") or Exception
        return null;
    }
    log.trace("Forwarding removeFlowRule to {}, which is the master for device {}", master, deviceId);
    return Futures.getUnchecked(clusterCommunicator.sendAndReceive(new VirtualFlowEntry(networkId, rule), REMOVE_FLOW_ENTRY, serializer::encode, serializer::decode, master));
}
Also used : VirtualDeviceId(org.onosproject.incubator.net.virtual.store.impl.primitives.VirtualDeviceId) DeviceId(org.onosproject.net.DeviceId) VirtualFlowEntry(org.onosproject.incubator.net.virtual.store.impl.primitives.VirtualFlowEntry) NodeId(org.onosproject.cluster.NodeId) MastershipService(org.onosproject.mastership.MastershipService)

Example 23 with MastershipService

use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.

the class DistributedVirtualFlowRuleStore method getFlowEntry.

@Override
public FlowEntry getFlowEntry(NetworkId networkId, FlowRule rule) {
    MastershipService mastershipService = vnaService.get(networkId, MastershipService.class);
    NodeId master = mastershipService.getMasterFor(rule.deviceId());
    if (master == null) {
        log.debug("Failed to getFlowEntry: No master for {}, vnet {}", rule.deviceId(), networkId);
        return null;
    }
    if (Objects.equals(local, master)) {
        return flowTable.getFlowEntry(networkId, rule);
    }
    log.trace("Forwarding getFlowEntry to {}, which is the primary (master) " + "for device {}, vnet {}", master, rule.deviceId(), networkId);
    VirtualFlowRule vRule = new VirtualFlowRule(networkId, rule);
    return Tools.futureGetOrElse(clusterCommunicator.sendAndReceive(vRule, GET_FLOW_ENTRY, serializer::encode, serializer::decode, master), FLOW_RULE_STORE_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS, null);
}
Also used : NodeId(org.onosproject.cluster.NodeId) MastershipService(org.onosproject.mastership.MastershipService) VirtualFlowRule(org.onosproject.incubator.net.virtual.store.impl.primitives.VirtualFlowRule)

Example 24 with MastershipService

use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.

the class FujitsuVoltAlertConfig method subscribe.

@Override
public boolean subscribe(String mode) {
    DriverHandler handler = handler();
    NetconfController controller = handler.get(NetconfController.class);
    MastershipService mastershipService = handler.get(MastershipService.class);
    DeviceId ncDeviceId = handler.data().deviceId();
    checkNotNull(controller, "Netconf controller is null");
    if (!mastershipService.isLocalMaster(ncDeviceId)) {
        log.warn("Not master for {} Use {} to execute command", ncDeviceId, mastershipService.getMasterFor(ncDeviceId));
        return false;
    }
    if (mode != null) {
        if (!DISABLE.equals(mode)) {
            log.error("Invalid mode: {}", mode);
            return false;
        }
    }
    try {
        if (mode != null) {
            controller.getDevicesMap().get(ncDeviceId).getSession().endSubscription();
        } else {
            StringBuilder request = new StringBuilder();
            request.append(ANGLE_LEFT + NOTIFY_ALERT + SPACE);
            request.append(VOLT_NE_NAMESPACE + SLASH + ANGLE_RIGHT);
            controller.getDevicesMap().get(ncDeviceId).getSession().startSubscription(request.toString());
        }
    } catch (NetconfException e) {
        log.error("Cannot communicate to device {} exception {}", ncDeviceId, e);
        return false;
    }
    return true;
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) DeviceId(org.onosproject.net.DeviceId) DriverHandler(org.onosproject.net.driver.DriverHandler) MastershipService(org.onosproject.mastership.MastershipService) NetconfController(org.onosproject.netconf.NetconfController)

Example 25 with MastershipService

use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.

the class FujitsuVoltAlertConfig method setAlertFilter.

@Override
public boolean setAlertFilter(String severity) {
    DriverHandler handler = handler();
    NetconfController controller = handler.get(NetconfController.class);
    MastershipService mastershipService = handler.get(MastershipService.class);
    DeviceId ncDeviceId = handler.data().deviceId();
    checkNotNull(controller, "Netconf controller is null");
    if (!mastershipService.isLocalMaster(ncDeviceId)) {
        log.warn("Not master for {} Use {} to execute command", ncDeviceId, mastershipService.getMasterFor(ncDeviceId));
        return false;
    }
    if (!SEVERITYLEVELS.contains(severity)) {
        log.error("Invalid severity level: {}", severity);
        return false;
    }
    try {
        StringBuilder request = new StringBuilder();
        request.append(VOLT_NE_OPEN + VOLT_NE_NAMESPACE);
        request.append(ANGLE_RIGHT + NEW_LINE);
        request.append(buildStartTag(VOLT_ALERTS)).append(buildStartTag(ALERT_FILTER, false)).append(severity).append(buildEndTag(ALERT_FILTER)).append(buildEndTag(VOLT_ALERTS)).append(VOLT_NE_CLOSE);
        controller.getDevicesMap().get(ncDeviceId).getSession().editConfig(RUNNING, null, request.toString());
    } catch (NetconfException e) {
        log.error("Cannot communicate to device {} exception {}", ncDeviceId, e);
        return false;
    }
    return true;
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) DeviceId(org.onosproject.net.DeviceId) DriverHandler(org.onosproject.net.driver.DriverHandler) MastershipService(org.onosproject.mastership.MastershipService) NetconfController(org.onosproject.netconf.NetconfController)

Aggregations

MastershipService (org.onosproject.mastership.MastershipService)41 DeviceId (org.onosproject.net.DeviceId)29 DriverHandler (org.onosproject.net.driver.DriverHandler)20 NetconfController (org.onosproject.netconf.NetconfController)20 NetconfException (org.onosproject.netconf.NetconfException)20 NodeId (org.onosproject.cluster.NodeId)9 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 GET (javax.ws.rs.GET)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 ControllerInfo (org.onosproject.net.behaviour.ControllerInfo)5 ArrayList (java.util.ArrayList)4 DeviceService (org.onosproject.net.device.DeviceService)4 ClusterService (org.onosproject.cluster.ClusterService)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Sets (com.google.common.collect.Sets)2 Set (java.util.Set)2 ExecutorService (java.util.concurrent.ExecutorService)2 Executors.newSingleThreadScheduledExecutor (java.util.concurrent.Executors.newSingleThreadScheduledExecutor)2