Search in sources :

Example 1 with MastershipService

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

the class MastersListCommand method doExecute.

@Override
protected void doExecute() {
    ClusterService service = get(ClusterService.class);
    MastershipService mastershipService = get(MastershipService.class);
    DeviceService deviceService = get(DeviceService.class);
    List<ControllerNode> nodes = newArrayList(service.getNodes());
    Collections.sort(nodes, Comparators.NODE_COMPARATOR);
    if (outputJson()) {
        print("%s", json(service, mastershipService, nodes));
    } else {
        for (ControllerNode node : nodes) {
            List<DeviceId> ids = Lists.newArrayList(mastershipService.getDevicesOf(node.id()));
            ids.removeIf(did -> deviceService.getDevice(did) == null);
            Collections.sort(ids, Comparators.ELEMENT_ID_COMPARATOR);
            print("%s: %d devices", node.id(), ids.size());
            for (DeviceId deviceId : ids) {
                print("  %s", deviceId);
            }
        }
    }
}
Also used : ClusterService(org.onosproject.cluster.ClusterService) DeviceId(org.onosproject.net.DeviceId) DeviceService(org.onosproject.net.device.DeviceService) ControllerNode(org.onosproject.cluster.ControllerNode) MastershipService(org.onosproject.mastership.MastershipService)

Example 2 with MastershipService

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

the class RolesCommand method doExecute.

@Override
protected void doExecute() {
    DeviceService deviceService = get(DeviceService.class);
    MastershipService roleService = get(MastershipService.class);
    if (outputJson()) {
        print("%s", json(roleService, getSortedDevices(deviceService)));
    } else {
        for (Device d : getSortedDevices(deviceService)) {
            DeviceId did = d.id();
            printRoles(roleService, did);
        }
    }
}
Also used : Device(org.onosproject.net.Device) DeviceId(org.onosproject.net.DeviceId) DeviceService(org.onosproject.net.device.DeviceService) MastershipService(org.onosproject.mastership.MastershipService)

Example 3 with MastershipService

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

the class FujitsuVoltNniLinkConfig method getNniLinks.

@Override
public String getNniLinks(String target) {
    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");
    String reply = null;
    if (!mastershipService.isLocalMaster(ncDeviceId)) {
        log.warn("Not master for {} Use {} to execute command", ncDeviceId, mastershipService.getMasterFor(ncDeviceId));
        return null;
    }
    try {
        StringBuilder request = new StringBuilder();
        request.append(VOLT_NE_OPEN + VOLT_NE_NAMESPACE).append(ANGLE_RIGHT + NEW_LINE).append(buildStartTag(VOLT_PORTS));
        if (target != null) {
            int nni;
            try {
                nni = Integer.parseInt(target);
                if (nni <= ZERO) {
                    log.error("Invalid integer for nnilink-id:{}", target);
                    return null;
                }
            } catch (NumberFormatException e) {
                log.error("Non-number input for nnilink-id:{}", target);
                return null;
            }
            request.append(buildStartTag(ETH_NNILINK_PORTS)).append(buildStartTag(ETH_NNILINK_PORT)).append(buildStartTag(NNILINK_ID, false)).append(target).append(buildEndTag(NNILINK_ID)).append(buildEndTag(ETH_NNILINK_PORT)).append(buildEndTag(ETH_NNILINK_PORTS));
        } else {
            request.append(buildEmptyTag(ETH_NNILINK_PORTS));
        }
        request.append(buildEndTag(VOLT_PORTS)).append(VOLT_NE_CLOSE);
        reply = controller.getDevicesMap().get(ncDeviceId).getSession().get(request.toString(), REPORT_ALL);
    } catch (NetconfException e) {
        log.error("Cannot communicate to device {} exception {}", ncDeviceId, e);
    }
    return reply;
}
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 4 with MastershipService

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

the class FujitsuVoltPonLinkConfig method getPonLinks.

@Override
public String getPonLinks(String target) {
    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");
    String reply = null;
    if (!mastershipService.isLocalMaster(ncDeviceId)) {
        log.warn("Not master for {} Use {} to execute command", ncDeviceId, mastershipService.getMasterFor(ncDeviceId));
        return null;
    }
    try {
        StringBuilder request = new StringBuilder();
        request.append(VOLT_NE_OPEN + VOLT_NE_NAMESPACE);
        request.append(ANGLE_RIGHT + NEW_LINE);
        request.append(buildStartTag(VOLT_PORTS));
        if (target != null) {
            int pon;
            try {
                pon = Integer.parseInt(target);
                if (pon <= ZERO) {
                    log.error("Invalid integer for ponlink-id:{}", target);
                    return null;
                }
            } catch (NumberFormatException e) {
                log.error("Non-number input for ponlink-id:{}", target);
                return null;
            }
            request.append(buildStartTag(GPON_PONLINK_PORTS)).append(buildStartTag(GPON_PONLINK_PORT)).append(buildStartTag(PONLINK_ID, false)).append(target).append(buildEndTag(PONLINK_ID)).append(buildEndTag(GPON_PONLINK_PORT)).append(buildEndTag(GPON_PONLINK_PORTS));
        } else {
            request.append(buildEmptyTag(GPON_PONLINK_PORTS));
        }
        request.append(buildEndTag(VOLT_PORTS));
        request.append(VOLT_NE_CLOSE);
        reply = controller.getDevicesMap().get(ncDeviceId).getSession().get(request.toString(), REPORT_ALL);
    } catch (NetconfException e) {
        log.error("Cannot communicate to device {} exception {}", ncDeviceId, e);
    }
    return reply;
}
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 5 with MastershipService

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

the class PolatisAlarmConsumer method consumeAlarms.

@Override
public List<Alarm> consumeAlarms() {
    DriverHandler handler = handler();
    NetconfController controller = handler.get(NetconfController.class);
    checkNotNull(controller, "Netconf controller is null");
    MastershipService mastershipService = handler.get(MastershipService.class);
    deviceId = handler.data().deviceId();
    List<Alarm> alarms = new ArrayList<>();
    if (!mastershipService.isLocalMaster(deviceId)) {
        log.warn("Not master for {} Use {} to execute command", deviceId, mastershipService.getMasterFor(deviceId));
        return ImmutableList.copyOf(alarms);
    }
    try {
        String request = xmlEmpty(KEY_SYSTEMALARMS_XMLNS);
        String reply = controller.getDevicesMap().get(deviceId).getSession().get(request, null);
        if (reply != null) {
            alarms = parseAlarms(reply);
        }
    } catch (NetconfException e) {
        log.error("Error reading alarms for device {} exception {}", deviceId, e);
    }
    return ImmutableList.copyOf(alarms);
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) Alarm(org.onosproject.alarm.Alarm) DefaultAlarm(org.onosproject.alarm.DefaultAlarm) DriverHandler(org.onosproject.net.driver.DriverHandler) ArrayList(java.util.ArrayList) 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