Search in sources :

Example 26 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 27 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)

Example 28 with MastershipService

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

the class FujitsuVoltNniLinkConfig method setNniLink.

@Override
public boolean setNniLink(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");
    if (!mastershipService.isLocalMaster(ncDeviceId)) {
        log.warn("Not master for {} Use {} to execute command", ncDeviceId, mastershipService.getMasterFor(ncDeviceId));
        return false;
    }
    String[] data = target.split(COLON);
    if (data.length != THREE) {
        log.error("Invalid number of arguments {}", target);
        return false;
    }
    try {
        int nni = Integer.parseInt(data[FIRST_PART]);
        if (nni <= ZERO) {
            log.error("Invalid integer for nnilink-id:{}", target);
            return false;
        }
    } catch (NumberFormatException e) {
        log.error("Non-number input for nnilink-id:{}", target);
        return false;
    }
    if (!checkSetParam(data[SECOND_PART], data[THIRD_PART])) {
        log.error("Failed to check input {}", target);
        return false;
    }
    try {
        StringBuilder request = new StringBuilder();
        request.append(VOLT_NE_OPEN + VOLT_NE_NAMESPACE).append(ANGLE_RIGHT + NEW_LINE).append(buildStartTag(VOLT_PORTS)).append(buildStartTag(ETH_NNILINK_PORTS)).append(buildStartTag(ETH_NNILINK_PORT)).append(buildStartTag(NNILINK_ID, false)).append(data[FIRST_PART]).append(buildEndTag(NNILINK_ID)).append(buildStartTag(data[SECOND_PART], false)).append(data[THIRD_PART]).append(buildEndTag(data[SECOND_PART])).append(buildEndTag(ETH_NNILINK_PORT)).append(buildEndTag(ETH_NNILINK_PORTS)).append(buildEndTag(VOLT_PORTS)).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)

Example 29 with MastershipService

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

the class FujitsuVoltOnuOperConfig method loopbackEthOnu.

@Override
public String loopbackEthOnu(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;
    String[] data = null;
    String[] ethId = null;
    if (!mastershipService.isLocalMaster(ncDeviceId)) {
        log.warn("Not master for {} Use {} to execute command", ncDeviceId, mastershipService.getMasterFor(ncDeviceId));
        return null;
    }
    data = target.split(COLON);
    if (data.length > TWO) {
        log.error("Invalid number of parameters {}", target);
        return null;
    }
    ethId = checkIdString(data[FIRST_PART], THREE);
    if (ethId == null) {
        log.error("Invalid ETH port identifier {}", data[FIRST_PART]);
        return null;
    }
    if (data.length > ONE) {
        if (!LOOPBACKMODES.contains(data[SECOND_PART])) {
            log.error("Unsupported parameter: {}", data[SECOND_PART]);
            return null;
        }
    }
    try {
        StringBuilder request = new StringBuilder();
        request.append(ANGLE_LEFT + ONU_ETHPORT_LOOPBACK + SPACE);
        request.append(VOLT_NE_NAMESPACE + ANGLE_RIGHT + NEW_LINE);
        request.append(buildStartTag(PONLINK_ID, false)).append(ethId[FIRST_PART]).append(buildEndTag(PONLINK_ID)).append(buildStartTag(ONU_ID, false)).append(ethId[SECOND_PART]).append(buildEndTag(ONU_ID)).append(buildStartTag(ETHPORT_ID, false)).append(ethId[THIRD_PART]).append(buildEndTag(ETHPORT_ID));
        if (data.length > ONE) {
            request.append(buildStartTag(LOOPBACK_MODE, false)).append(data[SECOND_PART]).append(buildEndTag(LOOPBACK_MODE));
        }
        request.append(buildEndTag(ONU_ETHPORT_LOOPBACK));
        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)

Example 30 with MastershipService

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

the class FujitsuVoltOnuOperConfig method rebootOnu.

@Override
public String rebootOnu(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;
    String[] onuId = null;
    if (!mastershipService.isLocalMaster(ncDeviceId)) {
        log.warn("Not master for {} Use {} to execute command", ncDeviceId, mastershipService.getMasterFor(ncDeviceId));
        return null;
    }
    onuId = checkIdString(target, TWO);
    if (onuId == null) {
        log.error("Invalid ONU identifier {}", target);
        return null;
    }
    try {
        StringBuilder request = new StringBuilder();
        request.append(ANGLE_LEFT + ONU_REBOOT + SPACE);
        request.append(VOLT_NE_NAMESPACE + ANGLE_RIGHT + NEW_LINE);
        request.append(buildStartTag(PONLINK_ID, false)).append(onuId[FIRST_PART]).append(buildEndTag(PONLINK_ID)).append(buildStartTag(ONU_ID, false)).append(onuId[SECOND_PART]).append(buildEndTag(ONU_ID)).append(buildEndTag(ONU_REBOOT));
        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)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