Search in sources :

Example 1 with RestServerSBDevice

use of org.onosproject.drivers.server.devices.RestServerSBDevice in project onos by opennetworkinglab.

the class ServerDevicesDiscovery method getMonitoringStatistics.

/**
 * Query a server to retrieve monitoring statistics for a
 * specific resource (i.e., traffic class).
 *
 * @param deviceId the device ID to be queried
 * @param tcId the ID of the traffic class to be monitored
 * @return resource-specific monitoring statistics
 */
private MonitoringStatistics getMonitoringStatistics(DeviceId deviceId, URI tcId) {
    // Monitoring statistics to return
    MonitoringStatistics monStats = null;
    RestServerSBDevice device = null;
    try {
        device = (RestServerSBDevice) getDevice(deviceId);
    } catch (ClassCastException ccEx) {
        log.error("Failed to retrieve monitoring statistics from device {}", deviceId);
        return monStats;
    }
    if (device == null) {
        return monStats;
    }
    // Create a resource-specific URL
    String scUrl = URL_SERVICE_CHAINS_STATS + SLASH + tcId.toString();
    // Hit the path that provides the server's specific resources
    InputStream response = null;
    try {
        response = getController().get(deviceId, scUrl, JSON);
    } catch (ProcessingException pEx) {
        log.error("Failed to retrieve monitoring statistics from device {}", deviceId);
        raiseDeviceDisconnect(device);
        return monStats;
    }
    // Load the JSON into objects
    ObjectMapper mapper = new ObjectMapper();
    Map<String, Object> jsonMap = null;
    JsonNode jsonNode = null;
    ObjectNode objNode = null;
    try {
        jsonMap = mapper.readValue(response, Map.class);
        jsonNode = mapper.convertValue(jsonMap, JsonNode.class);
        objNode = (ObjectNode) jsonNode;
    } catch (IOException ioEx) {
        log.error("Failed to retrieve monitoring statistics from device {}", deviceId);
        raiseDeviceDisconnect(device);
        return monStats;
    }
    if (jsonMap == null) {
        log.error("Failed to retrieve monitoring statistics from device {}", deviceId);
        raiseDeviceDisconnect(device);
        return monStats;
    }
    // Get the ID of the traffic class
    String id = get(jsonNode, PARAM_ID);
    // And verify that this is the traffic class we want to monitor
    if (!id.equals(tcId.toString())) {
        throw new IllegalStateException("Failed to retrieve monitoring data for traffic class " + tcId + ". Traffic class ID does not agree.");
    }
    // Get a list of CPU statistics per core
    Collection<CpuStatistics> cpuStats = parseCpuStatistics(deviceId, objNode);
    // Get main memory statistics
    MemoryStatistics memStats = parseMemoryStatistics(deviceId, objNode);
    // Get a list of port statistics
    Collection<PortStatistics> nicStats = parseNicStatistics(deviceId, objNode);
    // Get timing statistics
    TimingStatistics timinsgStats = parseTimingStatistics(objNode);
    // Construct a global monitoring statistics object out of smaller ones
    monStats = DefaultMonitoringStatistics.builder().setDeviceId(deviceId).setTimingStatistics(timinsgStats).setCpuStatistics(cpuStats).setMemoryStatistics(memStats).setNicStatistics(nicStats).build();
    // When a device reports monitoring data, it means it is alive
    raiseDeviceReconnect(device);
    log.debug("Monitoring statistics: {}", monStats.toString());
    return monStats;
}
Also used : DefaultTimingStatistics(org.onosproject.drivers.server.impl.stats.DefaultTimingStatistics) TimingStatistics(org.onosproject.drivers.server.stats.TimingStatistics) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DefaultMonitoringStatistics(org.onosproject.drivers.server.impl.stats.DefaultMonitoringStatistics) MonitoringStatistics(org.onosproject.drivers.server.stats.MonitoringStatistics) InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) DefaultRestServerSBDevice(org.onosproject.drivers.server.impl.devices.DefaultRestServerSBDevice) RestServerSBDevice(org.onosproject.drivers.server.devices.RestServerSBDevice) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) PortStatistics(org.onosproject.net.device.PortStatistics) MemoryStatistics(org.onosproject.drivers.server.stats.MemoryStatistics) DefaultMemoryStatistics(org.onosproject.drivers.server.impl.stats.DefaultMemoryStatistics) DefaultCpuStatistics(org.onosproject.drivers.server.impl.stats.DefaultCpuStatistics) CpuStatistics(org.onosproject.drivers.server.stats.CpuStatistics) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ProcessingException(javax.ws.rs.ProcessingException)

Example 2 with RestServerSBDevice

use of org.onosproject.drivers.server.devices.RestServerSBDevice in project onos by opennetworkinglab.

the class ServerDevicesDiscovery method getGlobalMonitoringStatistics.

/**
 * Query a server to retrieve its global monitoring statistics.
 *
 * @param deviceId the device ID to be queried
 * @return global monitoring statistics
 */
public MonitoringStatistics getGlobalMonitoringStatistics(DeviceId deviceId) {
    // Monitoring statistics to return
    MonitoringStatistics monStats = null;
    RestServerSBDevice device = null;
    try {
        device = (RestServerSBDevice) getDevice(deviceId);
    } catch (ClassCastException ccEx) {
        log.error("Failed to retrieve global monitoring statistics from device {}", deviceId);
        return monStats;
    }
    if ((device == null) || (!device.isActive())) {
        return monStats;
    }
    // Hit the path that provides the server's global resources
    InputStream response = null;
    try {
        response = getController().get(deviceId, URL_SRV_GLOBAL_STATS, JSON);
    } catch (ProcessingException pEx) {
        log.error("Failed to retrieve global monitoring statistics from device {}", deviceId);
        raiseDeviceDisconnect(device);
        return monStats;
    }
    // Load the JSON into objects
    ObjectMapper mapper = new ObjectMapper();
    Map<String, Object> jsonMap = null;
    ObjectNode objNode = null;
    try {
        jsonMap = mapper.readValue(response, Map.class);
        JsonNode jsonNode = mapper.convertValue(jsonMap, JsonNode.class);
        objNode = (ObjectNode) jsonNode;
    } catch (IOException ioEx) {
        log.error("Failed to retrieve global monitoring statistics from device {}", deviceId);
        raiseDeviceDisconnect(device);
        return monStats;
    }
    if (jsonMap == null) {
        log.error("Failed to retrieve global monitoring statistics from device {}", deviceId);
        raiseDeviceDisconnect(device);
        return monStats;
    }
    // Get high-level CPU statistics
    int busyCpus = objNode.path(PARAM_MON_BUSY_CPUS).asInt();
    int freeCpus = objNode.path(PARAM_MON_FREE_CPUS).asInt();
    // Get a list of CPU statistics per core
    Collection<CpuStatistics> cpuStats = parseCpuStatistics(deviceId, objNode);
    // Get main memory statistics
    MemoryStatistics memStats = parseMemoryStatistics(deviceId, objNode);
    // Get a list of port statistics
    Collection<PortStatistics> nicStats = parseNicStatistics(deviceId, objNode);
    // Get zero timing statistics
    TimingStatistics timinsgStats = getZeroTimingStatistics();
    // Construct a global monitoring statistics object out of smaller ones
    monStats = DefaultMonitoringStatistics.builder().setDeviceId(deviceId).setTimingStatistics(timinsgStats).setCpuStatistics(cpuStats).setMemoryStatistics(memStats).setNicStatistics(nicStats).build();
    // When a device reports monitoring data, it means it is alive
    raiseDeviceReconnect(device);
    log.debug("Global monitoring statistics: {}", monStats.toString());
    return monStats;
}
Also used : DefaultTimingStatistics(org.onosproject.drivers.server.impl.stats.DefaultTimingStatistics) TimingStatistics(org.onosproject.drivers.server.stats.TimingStatistics) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DefaultMonitoringStatistics(org.onosproject.drivers.server.impl.stats.DefaultMonitoringStatistics) MonitoringStatistics(org.onosproject.drivers.server.stats.MonitoringStatistics) InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) DefaultRestServerSBDevice(org.onosproject.drivers.server.impl.devices.DefaultRestServerSBDevice) RestServerSBDevice(org.onosproject.drivers.server.devices.RestServerSBDevice) DefaultPortStatistics(org.onosproject.net.device.DefaultPortStatistics) PortStatistics(org.onosproject.net.device.PortStatistics) MemoryStatistics(org.onosproject.drivers.server.stats.MemoryStatistics) DefaultMemoryStatistics(org.onosproject.drivers.server.impl.stats.DefaultMemoryStatistics) DefaultCpuStatistics(org.onosproject.drivers.server.impl.stats.DefaultCpuStatistics) CpuStatistics(org.onosproject.drivers.server.stats.CpuStatistics) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ProcessingException(javax.ws.rs.ProcessingException)

Example 3 with RestServerSBDevice

use of org.onosproject.drivers.server.devices.RestServerSBDevice in project onos by opennetworkinglab.

the class ServerDevicesDiscovery method getDeviceDetails.

/**
 * Query a server to retrieve its features.
 *
 * @param deviceId the device ID to be queried
 * @return a DeviceDescription with the device's features
 */
private DeviceDescription getDeviceDetails(DeviceId deviceId) {
    // Retrieve the device ID, if null given
    if (deviceId == null) {
        deviceId = getDeviceId();
        checkNotNull(deviceId, MSG_DEVICE_ID_NULL);
    }
    // Get the device
    RestSBDevice device = getDevice(deviceId);
    checkNotNull(device, MSG_DEVICE_NULL);
    // Hit the path that provides the server's resources
    InputStream response = null;
    try {
        response = getController().get(deviceId, URL_SRV_RESOURCE_DISCOVERY, JSON);
    } catch (ProcessingException pEx) {
        log.error("Failed to discover the device details of: {}", deviceId);
        return null;
    }
    // Load the JSON into objects
    ObjectMapper mapper = new ObjectMapper();
    Map<String, Object> jsonMap = null;
    JsonNode jsonNode = null;
    ObjectNode objNode = null;
    try {
        jsonMap = mapper.readValue(response, Map.class);
        jsonNode = mapper.convertValue(jsonMap, JsonNode.class);
        objNode = (ObjectNode) jsonNode;
    } catch (IOException ioEx) {
        log.error("Failed to discover the device details of: {}", deviceId);
        return null;
    }
    if (jsonMap == null) {
        log.error("Failed to discover the device details of: {}", deviceId);
        return null;
    }
    // Get all the attributes
    String id = get(jsonNode, PARAM_ID);
    String vendor = get(jsonNode, PARAM_MANUFACTURER);
    String hw = get(jsonNode, PARAM_HW_VENDOR);
    String sw = get(jsonNode, PARAM_SW_VENDOR);
    String serial = get(jsonNode, PARAM_SERIAL);
    long chassisId = objNode.path(PARAM_CHASSIS_ID).asLong();
    // Pass the southbound protocol as an annotation
    DefaultAnnotations.Builder annotations = DefaultAnnotations.builder();
    annotations.set(AnnotationKeys.PROTOCOL, "REST");
    // Parse CPU devices
    Collection<CpuDevice> cpuSet = parseCpuDevices(objNode);
    // Parse memory hierarchy device
    MemoryHierarchyDevice memHierarchyDev = parseMemoryHierarchyDevice(objNode);
    // Parse CPU cache hierachy device
    CpuCacheHierarchyDevice cacheHierarchyDev = parseCpuCacheHierarchyDevice(objNode);
    // NICs are composite attributes too
    Collection<NicDevice> nicSet = parseNicDevices(mapper, objNode, annotations);
    // Construct a server device,
    // i.e., a RestSBDevice extended with CPU, cache, memory, and NIC information
    RestServerSBDevice dev = new DefaultRestServerSBDevice(device.ip(), device.port(), device.username(), device.password(), device.protocol(), device.url(), device.isActive(), device.testUrl().orElse(""), vendor, hw, sw, cpuSet, cacheHierarchyDev, memHierarchyDev, nicSet);
    checkNotNull(dev, MSG_DEVICE_NULL);
    // Set alive
    raiseDeviceReconnect(dev);
    // Updates the controller with the complete device information
    getController().removeDevice(deviceId);
    getController().addDevice((RestSBDevice) dev);
    // Create a description for this server device
    ServerDeviceDescription desc = null;
    try {
        desc = new DefaultServerDeviceDescription(new URI(id), Device.Type.SERVER, vendor, hw, sw, serial, new ChassisId(chassisId), cpuSet, cacheHierarchyDev, memHierarchyDev, nicSet, annotations.build());
    } catch (URISyntaxException uEx) {
        log.error("Failed to create a server device description for: {}", deviceId);
        return null;
    }
    log.info("Device's {} details sent to the controller", deviceId);
    return desc;
}
Also used : DefaultServerDeviceDescription(org.onosproject.drivers.server.impl.devices.DefaultServerDeviceDescription) ServerDeviceDescription(org.onosproject.drivers.server.devices.ServerDeviceDescription) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) CpuCacheHierarchyDevice(org.onosproject.drivers.server.devices.cpu.CpuCacheHierarchyDevice) DefaultCpuCacheHierarchyDevice(org.onosproject.drivers.server.impl.devices.DefaultCpuCacheHierarchyDevice) DefaultRestServerSBDevice(org.onosproject.drivers.server.impl.devices.DefaultRestServerSBDevice) JsonNode(com.fasterxml.jackson.databind.JsonNode) DefaultCpuDevice(org.onosproject.drivers.server.impl.devices.DefaultCpuDevice) CpuDevice(org.onosproject.drivers.server.devices.cpu.CpuDevice) URISyntaxException(java.net.URISyntaxException) DefaultServerDeviceDescription(org.onosproject.drivers.server.impl.devices.DefaultServerDeviceDescription) URI(java.net.URI) NicDevice(org.onosproject.drivers.server.devices.nic.NicDevice) DefaultNicDevice(org.onosproject.drivers.server.impl.devices.DefaultNicDevice) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ProcessingException(javax.ws.rs.ProcessingException) MemoryHierarchyDevice(org.onosproject.drivers.server.devices.memory.MemoryHierarchyDevice) DefaultMemoryHierarchyDevice(org.onosproject.drivers.server.impl.devices.DefaultMemoryHierarchyDevice) ChassisId(org.onlab.packet.ChassisId) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) InputStream(java.io.InputStream) IOException(java.io.IOException) DefaultRestServerSBDevice(org.onosproject.drivers.server.impl.devices.DefaultRestServerSBDevice) RestServerSBDevice(org.onosproject.drivers.server.devices.RestServerSBDevice) RestSBDevice(org.onosproject.protocol.rest.RestSBDevice) Map(java.util.Map)

Example 4 with RestServerSBDevice

use of org.onosproject.drivers.server.devices.RestServerSBDevice in project onos by opennetworkinglab.

the class ServerDevicesDiscovery method discoverPortDetails.

@Override
public List<PortDescription> discoverPortDetails() {
    // Retrieve the device ID
    DeviceId deviceId = getDeviceId();
    checkNotNull(deviceId, MSG_DEVICE_ID_NULL);
    // .. and object
    RestServerSBDevice device = null;
    try {
        device = (RestServerSBDevice) getDevice(deviceId);
    } catch (ClassCastException ccEx) {
        log.error("Failed to discover ports for device {}", deviceId);
        return Collections.EMPTY_LIST;
    }
    if (device == null) {
        log.error("No device with ID {} is available for port discovery", deviceId);
        return Collections.EMPTY_LIST;
    }
    if ((device.nics() == null) || (device.nics().size() == 0)) {
        log.error("No ports available on {}", deviceId);
        return Collections.EMPTY_LIST;
    }
    // List of port descriptions to return
    List<PortDescription> portDescriptions = Lists.newArrayList();
    // Sorted list of NIC ports
    Set<NicDevice> nics = new TreeSet(device.nics());
    // Iterate through the NICs of this device to populate the list
    for (NicDevice nic : nics) {
        // Include the name of this device as an annotation
        DefaultAnnotations.Builder annotations = DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, nic.name());
        // Create a port description and add it to the list
        portDescriptions.add(DefaultPortDescription.builder().withPortNumber(PortNumber.portNumber(nic.portNumber())).isEnabled(nic.status()).type(nic.portType()).portSpeed(nic.speed()).annotations(annotations.build()).build());
        log.info("Port discovery on device {}: NIC {} is {} at {} Mbps", deviceId, nic.portNumber(), nic.status() ? "up" : "down", nic.speed());
    }
    return ImmutableList.copyOf(portDescriptions);
}
Also used : NicDevice(org.onosproject.drivers.server.devices.nic.NicDevice) DefaultNicDevice(org.onosproject.drivers.server.impl.devices.DefaultNicDevice) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) DeviceId(org.onosproject.net.DeviceId) TreeSet(java.util.TreeSet) PortDescription(org.onosproject.net.device.PortDescription) DefaultPortDescription(org.onosproject.net.device.DefaultPortDescription) DefaultRestServerSBDevice(org.onosproject.drivers.server.impl.devices.DefaultRestServerSBDevice) RestServerSBDevice(org.onosproject.drivers.server.devices.RestServerSBDevice)

Example 5 with RestServerSBDevice

use of org.onosproject.drivers.server.devices.RestServerSBDevice in project onos by opennetworkinglab.

the class BasicServerDriver method findNicInterfaceWithPort.

/**
 * Finds the NIC name that corresponds to a device's port number.
 *
 * @param deviceId a device ID
 * @param port a NIC port number
 * @return device's NIC name
 */
public static String findNicInterfaceWithPort(DeviceId deviceId, long port) {
    if (controller == null) {
        return null;
    }
    RestServerSBDevice device = null;
    try {
        device = (RestServerSBDevice) controller.getDevice(deviceId);
    } catch (ClassCastException ccEx) {
        return null;
    }
    checkNotNull(device, MSG_DEVICE_NULL);
    return device.portNameFromNumber(port);
}
Also used : RestServerSBDevice(org.onosproject.drivers.server.devices.RestServerSBDevice)

Aggregations

RestServerSBDevice (org.onosproject.drivers.server.devices.RestServerSBDevice)8 DefaultRestServerSBDevice (org.onosproject.drivers.server.impl.devices.DefaultRestServerSBDevice)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 NicDevice (org.onosproject.drivers.server.devices.nic.NicDevice)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 Map (java.util.Map)3 ProcessingException (javax.ws.rs.ProcessingException)3 DeviceId (org.onosproject.net.DeviceId)3 DefaultPortStatistics (org.onosproject.net.device.DefaultPortStatistics)3 PortStatistics (org.onosproject.net.device.PortStatistics)3 TreeSet (java.util.TreeSet)2 DefaultNicDevice (org.onosproject.drivers.server.impl.devices.DefaultNicDevice)2 DefaultCpuStatistics (org.onosproject.drivers.server.impl.stats.DefaultCpuStatistics)2 DefaultMemoryStatistics (org.onosproject.drivers.server.impl.stats.DefaultMemoryStatistics)2 DefaultMonitoringStatistics (org.onosproject.drivers.server.impl.stats.DefaultMonitoringStatistics)2 DefaultTimingStatistics (org.onosproject.drivers.server.impl.stats.DefaultTimingStatistics)2 CpuStatistics (org.onosproject.drivers.server.stats.CpuStatistics)2