use of org.onosproject.drivers.server.devices.cpu.CpuDevice 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.cpu.CpuDevice in project onos by opennetworkinglab.
the class ServerDevicesDiscovery method parseCpuDevices.
/**
* Parse the input JSON object, looking for CPU-related
* information. Upon success, construct and return a list
* of CPU devices.
*
* @param objNode input JSON node with CPU device information
* @return list of CPU devices
*/
private Collection<CpuDevice> parseCpuDevices(ObjectNode objNode) {
Collection<CpuDevice> cpuSet = Sets.newHashSet();
JsonNode cpuNode = objNode.path(PARAM_CPUS);
// Construct CPU objects
for (JsonNode cn : cpuNode) {
ObjectNode cpuObjNode = (ObjectNode) cn;
// All the CPU attributes
int physicalCpuId = cpuObjNode.path(PARAM_CPU_ID_PHY).asInt();
int logicalCpuId = cpuObjNode.path(PARAM_CPU_ID_LOG).asInt();
int cpuSocket = cpuObjNode.path(PARAM_CPU_SOCKET).asInt();
String cpuVendorStr = get(cn, PARAM_CPU_VENDOR);
long cpuFrequency = cpuObjNode.path(PARAM_CPU_FREQUENCY).asLong();
// Construct a CPU device and add it to the set
cpuSet.add(DefaultCpuDevice.builder().setCoreId(logicalCpuId, physicalCpuId).setVendor(cpuVendorStr).setSocket(cpuSocket).setFrequency(cpuFrequency).build());
}
return cpuSet;
}
Aggregations