Search in sources :

Example 16 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 17 with MastershipService

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

the class FujitsuVoltAlertConfig method getAlertFilter.

@Override
public String getAlertFilter() {
    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_ALERTS)).append(buildEmptyTag(ALERT_FILTER)).append(buildEndTag(VOLT_ALERTS)).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 18 with MastershipService

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

the class FujitsuVoltControllerConfig method getControllers.

@Override
public List<ControllerInfo> getControllers() {
    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");
    List<ControllerInfo> controllers = new ArrayList<>();
    if (mastershipService.isLocalMaster(ncDeviceId)) {
        try {
            StringBuilder request = new StringBuilder();
            request.append(VOLT_NE_OPEN + VOLT_NE_NAMESPACE + ">\n");
            request.append(buildEmptyTag(VOLT_OFCONFIG));
            request.append(VOLT_NE_CLOSE);
            String reply;
            reply = controller.getDevicesMap().get(ncDeviceId).getSession().get(request.toString(), REPORT_ALL);
            log.debug("Reply XML {}", reply);
            controllers.addAll(parseStreamVoltControllers(XmlConfigParser.loadXml(new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8)))));
        } catch (NetconfException e) {
            log.error("Cannot communicate to device {} ", ncDeviceId);
        }
    } else {
        log.warn("I'm not master for {} please use master, {} to execute command", ncDeviceId, mastershipService.getMasterFor(ncDeviceId));
    }
    return ImmutableList.copyOf(controllers);
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) ByteArrayInputStream(java.io.ByteArrayInputStream) DeviceId(org.onosproject.net.DeviceId) DriverHandler(org.onosproject.net.driver.DriverHandler) ArrayList(java.util.ArrayList) MastershipService(org.onosproject.mastership.MastershipService) NetconfController(org.onosproject.netconf.NetconfController) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo)

Example 19 with MastershipService

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

the class FujitsuVoltControllerConfig method setControllers.

@Override
public void setControllers(List<ControllerInfo> controllers) {
    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)) {
        try {
            NetconfDevice device = controller.getNetconfDevice(ncdeviceId);
            String config = createVoltControllersConfig(XmlConfigParser.loadXml(getClass().getResourceAsStream(RESOURCE_XML)), RUNNING, MERGE, controllers);
            device.getSession().editConfig(config.substring(config.indexOf(END_LICENSE_HEADER) + END_LICENSE_HEADER.length()));
        } catch (NetconfException e) {
            log.error("Cannot communicate to device {} , exception {}", ncdeviceId, e);
        }
    } else {
        log.warn("I'm not master for {} please use master, {} to execute command", ncdeviceId, mastershipService.getMasterFor(ncdeviceId));
    }
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) NetconfDevice(org.onosproject.netconf.NetconfDevice) DeviceId(org.onosproject.net.DeviceId) DriverHandler(org.onosproject.net.driver.DriverHandler) MastershipService(org.onosproject.mastership.MastershipService) NetconfController(org.onosproject.netconf.NetconfController)

Example 20 with MastershipService

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

the class FujitsuVoltFwdlConfig method upgradeFirmwareOndemand.

@Override
public String upgradeFirmwareOndemand(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;
    int count;
    if (!mastershipService.isLocalMaster(ncDeviceId)) {
        log.warn("Not master for {} Use {} to execute command", ncDeviceId, mastershipService.getMasterFor(ncDeviceId));
        return null;
    }
    String[] data = target.split(COLON);
    if ((data.length < TWO) || (data.length > THREE)) {
        log.error("Invalid number of arguments");
        return null;
    }
    String[] onuList = data[SECOND_PART].split(COMMA);
    if (onuList.length == ZERO) {
        log.error("No ONU listed");
        return null;
    }
    if ((data.length > TWO) && (!AUTO.equals(data[THIRD_PART]))) {
        log.error("Invalid reboot-mode {}", data[THIRD_PART]);
        return null;
    }
    try {
        StringBuilder request = new StringBuilder();
        request.append(ANGLE_LEFT + ONDEMAND_FIRMWARE_UPGRADE + SPACE);
        request.append(VOLT_NE_NAMESPACE + ANGLE_RIGHT + NEW_LINE);
        request.append(buildStartTag(PARTICIPANT_LIST));
        for (count = ZERO; count < onuList.length; count++) {
            String[] onuId = onuList[count].split(HYPHEN);
            if (onuId.length != TWO) {
                log.error("Invalid ONU identifier");
                return null;
            }
            try {
                int pon;
                pon = Integer.parseInt(onuId[FIRST_PART]);
                if (pon <= ZERO) {
                    log.error("Invalid integer for ponlink-id:{}", onuId[FIRST_PART]);
                    return null;
                }
                int onu;
                onu = Integer.parseInt(onuId[SECOND_PART]);
                if (onu <= ZERO) {
                    log.error("Invalid integer for onu-id:{}", onuId[SECOND_PART]);
                    return null;
                }
            } catch (NumberFormatException e) {
                log.error("Non-number input");
                return null;
            }
            request.append(buildStartTag(MEMBER)).append(buildStartTag(PONLINK_ID)).append(onuId[FIRST_PART]).append(buildEndTag(PONLINK_ID)).append(buildStartTag(ONU_ID)).append(onuId[SECOND_PART]).append(buildEndTag(ONU_ID)).append(buildEndTag(MEMBER));
        }
        request.append(buildEndTag(PARTICIPANT_LIST)).append(buildStartTag(IMAGE_NAME)).append(data[FIRST_PART]).append(buildEndTag(IMAGE_NAME));
        if (data.length == THREE) {
            request.append(buildStartTag(REBOOT_MODE)).append(data[THIRD_PART]).append(buildEndTag(REBOOT_MODE));
        }
        request.append(buildEndTag(ONDEMAND_FIRMWARE_UPGRADE));
        reply = controller.getDevicesMap().get(ncDeviceId).getSession().doWrappedRpc(request.toString());
    } 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)

Aggregations

MastershipService (org.onosproject.mastership.MastershipService)42 DeviceId (org.onosproject.net.DeviceId)30 DriverHandler (org.onosproject.net.driver.DriverHandler)20 NetconfController (org.onosproject.netconf.NetconfController)20 NetconfException (org.onosproject.netconf.NetconfException)20 NodeId (org.onosproject.cluster.NodeId)10 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 DeviceService (org.onosproject.net.device.DeviceService)5 ArrayList (java.util.ArrayList)4 ClusterService (org.onosproject.cluster.ClusterService)4 Set (java.util.Set)3 ExecutorService (java.util.concurrent.ExecutorService)3 Executors.newSingleThreadScheduledExecutor (java.util.concurrent.Executors.newSingleThreadScheduledExecutor)3 Tools.groupedThreads (org.onlab.util.Tools.groupedThreads)3 MastershipRole (org.onosproject.net.MastershipRole)3