use of org.eclipse.kura.system.SystemAdminService in project kura by eclipse.
the class LifeCyclePayloadBuilder method buildDeviceProfile.
public KuraDeviceProfile buildDeviceProfile() {
SystemService systemService = this.m_cloudServiceImpl.getSystemService();
SystemAdminService sysAdminService = this.m_cloudServiceImpl.getSystemAdminService();
NetworkService networkService = this.m_cloudServiceImpl.getNetworkService();
PositionService positionService = this.m_cloudServiceImpl.getPositionService();
//
// get the network information
StringBuilder sbConnectionIp = null;
StringBuilder sbConnectionInterface = null;
try {
List<NetInterface<? extends NetInterfaceAddress>> nis = networkService.getActiveNetworkInterfaces();
if (!nis.isEmpty()) {
sbConnectionIp = new StringBuilder();
sbConnectionInterface = new StringBuilder();
for (NetInterface<? extends NetInterfaceAddress> ni : nis) {
List<? extends NetInterfaceAddress> nias = ni.getNetInterfaceAddresses();
if (nias != null && !nias.isEmpty()) {
sbConnectionInterface.append(buildConnectionInterface(ni)).append(",");
sbConnectionIp.append(buildConnectionIp(ni)).append(",");
}
}
// Remove trailing comma
sbConnectionIp.deleteCharAt(sbConnectionIp.length() - 1);
sbConnectionInterface.deleteCharAt(sbConnectionInterface.length() - 1);
}
} catch (Exception se) {
s_logger.warn("Error while getting ConnetionIP and ConnectionInterface", se);
}
String connectionIp = sbConnectionIp != null ? sbConnectionIp.toString() : "UNKNOWN";
String connectionInterface = sbConnectionInterface != null ? sbConnectionInterface.toString() : "UNKNOWN";
//
// get the network information
// String primaryNetInterface = systemService.getPrimaryNetworkInterfaceName();
// String connectionIp = UNKNOWN;
// String connectionInterface = UNKNOWN;
// try {
// List<NetInterface<? extends NetInterfaceAddress>> nis = networkService.getActiveNetworkInterfaces();
// if (!nis.isEmpty()) {
//
// // look for the primary network interface first
// for (NetInterface<? extends NetInterfaceAddress> ni : nis) {
// if (ni.getName().equals(primaryNetInterface)) {
// List<? extends NetInterfaceAddress> nias = ni.getNetInterfaceAddresses();
// if (nias != null && !nias.isEmpty()) {
// connectionInterface = buildConnectionInterface(ni);
// connectionIp = buildConnectionIp(ni);
// break;
// }
// }
// }
//
// // if not resolved, loop through all network interfaces until we find one with an address
// if (UNKNOWN.equals(connectionIp) || UNKNOWN.equals(connectionInterface)) {
// s_logger.warn("Unresolved connectionIp for primary Network Interface. Looping through all interfaces...");
// for (NetInterface<? extends NetInterfaceAddress> ni : nis) {
// List<? extends NetInterfaceAddress> nias = ni.getNetInterfaceAddresses();
// if (nias != null && !nias.isEmpty()) {
// connectionInterface = buildConnectionInterface(ni);
// connectionIp = buildConnectionIp(ni);
// break;
// }
// }
// }
// }
//
// if (UNKNOWN.equals(connectionIp) || UNKNOWN.equals(connectionInterface)) {
// s_logger.warn("Unresolved NetworkService reference or IP address. Defaulting to JVM Networking
// Information.");
// InetAddress addr = NetUtil.getCurrentInetAddress();
// if (addr != null) {
// connectionIp = addr.getHostAddress();
// NetworkInterface netInterface = NetworkInterface.getByInetAddress(addr);
// if (netInterface != null) {
// connectionInterface = NetUtil.hardwareAddressToString(netInterface.getHardwareAddress());
// }
// }
// }
// }
// catch (Exception se) {
// s_logger.warn("Error while getting ConnetionIP and ConnectionInterface", se);
// }
//
// get the position information
double latitude = 0.0;
double longitude = 0.0;
double altitude = 0.0;
if (positionService != null) {
NmeaPosition position = positionService.getNmeaPosition();
if (position != null) {
latitude = position.getLatitude();
longitude = position.getLongitude();
altitude = position.getAltitude();
} else {
s_logger.warn("Unresolved PositionService reference.");
}
}
//
// build the profile
KuraDeviceProfile KuraDeviceProfile = new KuraDeviceProfile(sysAdminService.getUptime(), systemService.getDeviceName(), systemService.getModelName(), systemService.getModelId(), systemService.getPartNumber(), systemService.getSerialNumber(), systemService.getFirmwareVersion(), systemService.getBiosVersion(), systemService.getOsName(), systemService.getOsVersion(), systemService.getJavaVmName(), systemService.getJavaVmVersion() + " " + systemService.getJavaVmInfo(), systemService.getJavaVendor() + " " + systemService.getJavaVersion(), systemService.getKuraVersion(), connectionInterface, connectionIp, latitude, longitude, altitude, String.valueOf(systemService.getNumberOfProcessors()), String.valueOf(systemService.getTotalMemory()), systemService.getOsArch(), systemService.getOsgiFwName(), systemService.getOsgiFwVersion());
return KuraDeviceProfile;
}
use of org.eclipse.kura.system.SystemAdminService in project kura by eclipse.
the class ThreadGroupComparator method findDeviceConfiguration.
@Override
public ArrayList<GwtGroupedNVPair> findDeviceConfiguration(GwtXSRFToken xsrfToken) throws GwtKuraException {
checkXSRFToken(xsrfToken);
List<GwtGroupedNVPair> pairs = new ArrayList<GwtGroupedNVPair>();
SystemService systemService = ServiceLocator.getInstance().getService(SystemService.class);
SystemAdminService systemAdminService = ServiceLocator.getInstance().getService(SystemAdminService.class);
try {
Properties systemProperties = systemService.getProperties();
pairs.add(new GwtGroupedNVPair("devInfo", "devKuraVersion", systemService.getKuraVersion()));
pairs.add(new GwtGroupedNVPair("devInfo", "devClientId", systemService.getPrimaryMacAddress() != null ? systemService.getPrimaryMacAddress() : UNKNOWN));
pairs.add(new GwtGroupedNVPair("devInfo", "devDisplayName", systemService.getDeviceName()));
pairs.add(new GwtGroupedNVPair("devInfo", "devUptime", formatUptime(Long.parseLong(systemAdminService.getUptime()))));
pairs.add(new GwtGroupedNVPair("devInfo", "devLastWifiChannel", String.valueOf(systemService.getKuraWifiTopChannel())));
pairs.add(new GwtGroupedNVPair("devHw", "devModelName", systemService.getModelName()));
pairs.add(new GwtGroupedNVPair("devHw", "devModelId", systemService.getModelId()));
pairs.add(new GwtGroupedNVPair("devHw", "devPartNumber", systemService.getPartNumber()));
pairs.add(new GwtGroupedNVPair("devHw", "devSerialNumber", systemService.getSerialNumber()));
pairs.add(new GwtGroupedNVPair("devSw", "devFirmwareVersion", systemService.getFirmwareVersion()));
pairs.add(new GwtGroupedNVPair("devSw", "devBiosVersion", systemService.getBiosVersion()));
pairs.add(new GwtGroupedNVPair("devSw", "devOsVersion", systemService.getOsVersion()));
pairs.add(new GwtGroupedNVPair("devSw", "devOs", systemService.getOsName()));
pairs.add(new GwtGroupedNVPair("devSw", "devOsArch", systemService.getOsArch()));
pairs.add(new GwtGroupedNVPair("devJava", "devJvmName", systemProperties.getProperty(SystemService.KEY_JAVA_VM_NAME)));
pairs.add(new GwtGroupedNVPair("devJava", "devJvmVersion", systemProperties.getProperty(SystemService.KEY_JAVA_VM_VERSION)));
pairs.add(new GwtGroupedNVPair("devJava", "devJvmProfile", systemService.getJavaVendor() + " " + systemService.getJavaVersion()));
pairs.add(new GwtGroupedNVPair("devJava", "devOsgiFramework", systemProperties.getProperty(SystemService.KEY_OSGI_FW_NAME)));
pairs.add(new GwtGroupedNVPair("devJava", "devOsgiFrameworkVersion", systemProperties.getProperty(SystemService.KEY_OSGI_FW_VERSION)));
if (systemService.getNumberOfProcessors() != -1) {
pairs.add(new GwtGroupedNVPair("devJava", "devNumProc", String.valueOf(systemService.getNumberOfProcessors())));
}
pairs.add(new GwtGroupedNVPair("devJava", "devRamTot", String.valueOf(systemService.getTotalMemory()) + " kB"));
pairs.add(new GwtGroupedNVPair("devJava", "devRamFree", String.valueOf(systemService.getFreeMemory()) + " kB"));
// TODO: Add cloud status information in the Denali Device Profile
// deviceConfig.deviceStatus
// deviceConfig.setAcceptEncoding(null);
// deviceConfig.setApplicationIdentifiers(null);
// deviceConfig.setLastEventOn(new Date());
// deviceConfig.setLastEventType("UNKNOWN");
} catch (Exception e) {
throw new GwtKuraException(GwtKuraErrorCode.INTERNAL_ERROR, e);
}
return new ArrayList<GwtGroupedNVPair>(pairs);
}
use of org.eclipse.kura.system.SystemAdminService in project kura by eclipse.
the class LifeCyclePayloadBuilder method buildDisconnectPayload.
public KuraDisconnectPayload buildDisconnectPayload() {
SystemService systemService = this.m_cloudServiceImpl.getSystemService();
SystemAdminService sysAdminService = this.m_cloudServiceImpl.getSystemAdminService();
CloudServiceOptions cloudOptions = this.m_cloudServiceImpl.getCloudServiceOptions();
// build device name
String deviceName = cloudOptions.getDeviceDisplayName();
if (deviceName == null) {
deviceName = systemService.getDeviceName();
}
// build payload
KuraDisconnectPayload payload = new KuraDisconnectPayload(sysAdminService.getUptime(), deviceName);
return payload;
}
Aggregations