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;
}
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;
}
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;
}
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);
}
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);
}
Aggregations