Search in sources :

Example 1 with SystemService

use of org.eclipse.kura.system.SystemService 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;
}
Also used : SystemAdminService(org.eclipse.kura.system.SystemAdminService) NmeaPosition(org.eclipse.kura.position.NmeaPosition) PositionService(org.eclipse.kura.position.PositionService) SystemService(org.eclipse.kura.system.SystemService) NetInterface(org.eclipse.kura.net.NetInterface) KuraDeviceProfile(org.eclipse.kura.core.message.KuraDeviceProfile) NetInterfaceAddress(org.eclipse.kura.net.NetInterfaceAddress) NetworkService(org.eclipse.kura.net.NetworkService)

Example 2 with SystemService

use of org.eclipse.kura.system.SystemService in project kura by eclipse.

the class ShellScriptResourceProcessorImpl method activate.

protected void activate(BundleContext bundleContext) {
    s_logger.info("activate");
    this.m_bundleContext = bundleContext;
    final Properties kuraProperties;
    final ServiceReference<SystemService> systemServiceRef = bundleContext.getServiceReference(SystemService.class);
    if (systemServiceRef == null) {
        throw new IllegalStateException("Unable to find instance of: " + SystemService.class.getName());
    }
    final SystemService systemService = bundleContext.getService(systemServiceRef);
    if (systemService == null) {
        throw new IllegalStateException("Unable to get instance of: " + SystemService.class.getName());
    }
    try {
        kuraProperties = systemService.getProperties();
    } finally {
        bundleContext.ungetService(systemServiceRef);
    }
    String packagesPath = kuraProperties.getProperty(PACKAGES_PATH_PROPNAME);
    if (packagesPath == null || packagesPath.isEmpty()) {
        throw new ComponentException("The value of '" + PACKAGES_PATH_PROPNAME + "' is not defined");
    }
    if (kuraProperties.getProperty(PACKAGES_PATH_PROPNAME) != null && kuraProperties.getProperty(PACKAGES_PATH_PROPNAME).trim().equals("kura/packages")) {
        kuraProperties.setProperty(PACKAGES_PATH_PROPNAME, "/opt/eurotech/kura/kura/packages");
        packagesPath = kuraProperties.getProperty(PACKAGES_PATH_PROPNAME);
        s_logger.warn("Overridding invalid kura.packages location");
    }
    this.m_resourcesRootDirectory = new File(packagesPath, "resources");
    if (!this.m_resourcesRootDirectory.exists()) {
        boolean success = this.m_resourcesRootDirectory.mkdirs();
        if (!success) {
            throw new ComponentException("Failed to make directory: " + this.m_resourcesRootDirectory.getPath());
        }
    }
}
Also used : SystemService(org.eclipse.kura.system.SystemService) ComponentException(org.osgi.service.component.ComponentException) Properties(java.util.Properties) File(java.io.File)

Example 3 with SystemService

use of org.eclipse.kura.system.SystemService in project kura by eclipse.

the class ThreadGroupComparator method startBundle.

@Override
public void startBundle(GwtXSRFToken xsrfToken, String bundleId) throws GwtKuraException {
    checkXSRFToken(xsrfToken);
    SystemService systemService = ServiceLocator.getInstance().getService(SystemService.class);
    Bundle[] bundles = systemService.getBundles();
    s_logger.info("Starting bundle with ID: {}", bundleId);
    for (Bundle b : bundles) {
        if (b.getBundleId() == Long.parseLong(bundleId)) {
            try {
                b.start();
                return;
            } catch (BundleException e) {
                s_logger.error("Failed to start bundle {}", b.getBundleId(), e);
                throw new GwtKuraException(GwtKuraErrorCode.INTERNAL_ERROR);
            }
        }
    }
    // Bundle was not found, throw error
    s_logger.error("Could not find bundle with ID: {}", bundleId);
    throw new GwtKuraException(GwtKuraErrorCode.INTERNAL_ERROR);
}
Also used : GwtKuraException(org.eclipse.kura.web.shared.GwtKuraException) SystemService(org.eclipse.kura.system.SystemService) Bundle(org.osgi.framework.Bundle) BundleException(org.osgi.framework.BundleException)

Example 4 with SystemService

use of org.eclipse.kura.system.SystemService in project kura by eclipse.

the class ThreadGroupComparator method findSystemProperties.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public ArrayList<GwtGroupedNVPair> findSystemProperties(GwtXSRFToken xsrfToken) throws GwtKuraException {
    checkXSRFToken(xsrfToken);
    List<GwtGroupedNVPair> pairs = new ArrayList<GwtGroupedNVPair>();
    // kura properties
    SystemService systemService = ServiceLocator.getInstance().getService(SystemService.class);
    Properties kuraProps = systemService.getProperties();
    SortedSet kuraKeys = new TreeSet(kuraProps.keySet());
    for (Iterator ki = kuraKeys.iterator(); ki.hasNext(); ) {
        Object key = ki.next();
        pairs.add(new GwtGroupedNVPair("propsKura", key.toString(), kuraProps.get(key).toString()));
    }
    return new ArrayList<GwtGroupedNVPair>(pairs);
}
Also used : SystemService(org.eclipse.kura.system.SystemService) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Properties(java.util.Properties) GwtGroupedNVPair(org.eclipse.kura.web.shared.model.GwtGroupedNVPair) SortedSet(java.util.SortedSet)

Example 5 with SystemService

use of org.eclipse.kura.system.SystemService in project kura by eclipse.

the class GwtNetworkServiceImpl method findWifiHotspots.

@Override
public ArrayList<GwtWifiHotspotEntry> findWifiHotspots(GwtXSRFToken xsrfToken, String interfaceName) throws GwtKuraException {
    checkXSRFToken(xsrfToken);
    NetworkAdminService nas = ServiceLocator.getInstance().getService(NetworkAdminService.class);
    SystemService systemService = ServiceLocator.getInstance().getService(SystemService.class);
    List<GwtWifiHotspotEntry> gwtWifiHotspotsEntries = new ArrayList<GwtWifiHotspotEntry>();
    try {
        Map<String, WifiHotspotInfo> wifiHotspotInfoMap = nas.getWifiHotspots(interfaceName);
        if (wifiHotspotInfoMap != null && !wifiHotspotInfoMap.isEmpty()) {
            Collection<WifiHotspotInfo> wifiHotspotInfoCollection = wifiHotspotInfoMap.values();
            Iterator<WifiHotspotInfo> it = wifiHotspotInfoCollection.iterator();
            while (it.hasNext()) {
                WifiHotspotInfo wifiHotspotInfo = it.next();
                String ssid = GwtSafeHtmlUtils.htmlEscape(wifiHotspotInfo.getSsid());
                // }
                if (wifiHotspotInfo.getChannel() <= systemService.getKuraWifiTopChannel() && ssid != null) {
                    GwtWifiHotspotEntry gwtWifiHotspotEntry = new GwtWifiHotspotEntry();
                    gwtWifiHotspotEntry.setMacAddress(wifiHotspotInfo.getMacAddress());
                    gwtWifiHotspotEntry.setSSID(ssid);
                    gwtWifiHotspotEntry.setsignalStrength(wifiHotspotInfo.getSignalLevel());
                    gwtWifiHotspotEntry.setChannel(wifiHotspotInfo.getChannel());
                    gwtWifiHotspotEntry.setFrequency(wifiHotspotInfo.getFrequency());
                    if (wifiHotspotInfo.getSecurity() == WifiSecurity.NONE || wifiHotspotInfo.getSecurity() == WifiSecurity.SECURITY_NONE) {
                        gwtWifiHotspotEntry.setSecurity("None");
                    } else if (wifiHotspotInfo.getSecurity() == WifiSecurity.SECURITY_WEP) {
                        gwtWifiHotspotEntry.setSecurity("WEP");
                    } else if (wifiHotspotInfo.getSecurity() == WifiSecurity.SECURITY_WPA) {
                        gwtWifiHotspotEntry.setSecurity("WPA");
                    } else if (wifiHotspotInfo.getSecurity() == WifiSecurity.SECURITY_WPA2) {
                        gwtWifiHotspotEntry.setSecurity("WPA2");
                    } else if (wifiHotspotInfo.getSecurity() == WifiSecurity.SECURITY_WPA_WPA2) {
                        gwtWifiHotspotEntry.setSecurity("WPA/WPA2");
                    }
                    GwtWifiCiphers gwtPairCiphers = null;
                    GwtWifiCiphers gwtGroupCiphers = null;
                    EnumSet<WifiSecurity> pairCiphers = wifiHotspotInfo.getPairCiphers();
                    Iterator<WifiSecurity> itPairCiphers = pairCiphers.iterator();
                    while (itPairCiphers.hasNext()) {
                        WifiSecurity cipher = itPairCiphers.next();
                        if (gwtPairCiphers == null) {
                            if (cipher == WifiSecurity.PAIR_TKIP) {
                                gwtPairCiphers = GwtWifiCiphers.netWifiCiphers_TKIP;
                            } else if (cipher == WifiSecurity.PAIR_CCMP) {
                                gwtPairCiphers = GwtWifiCiphers.netWifiCiphers_CCMP;
                            }
                        } else if (gwtPairCiphers == GwtWifiCiphers.netWifiCiphers_TKIP) {
                            if (cipher == WifiSecurity.PAIR_CCMP) {
                                gwtPairCiphers = GwtWifiCiphers.netWifiCiphers_CCMP_TKIP;
                            }
                        } else if (gwtPairCiphers == GwtWifiCiphers.netWifiCiphers_CCMP) {
                            if (cipher == WifiSecurity.PAIR_TKIP) {
                                gwtPairCiphers = GwtWifiCiphers.netWifiCiphers_CCMP_TKIP;
                            }
                        }
                    }
                    EnumSet<WifiSecurity> groupCiphers = wifiHotspotInfo.getGroupCiphers();
                    Iterator<WifiSecurity> itGroupCiphers = groupCiphers.iterator();
                    while (itGroupCiphers.hasNext()) {
                        WifiSecurity cipher = itGroupCiphers.next();
                        if (gwtGroupCiphers == null) {
                            if (cipher == WifiSecurity.GROUP_TKIP) {
                                gwtGroupCiphers = GwtWifiCiphers.netWifiCiphers_TKIP;
                            } else if (cipher == WifiSecurity.GROUP_CCMP) {
                                gwtGroupCiphers = GwtWifiCiphers.netWifiCiphers_CCMP;
                            }
                        } else if (gwtGroupCiphers == GwtWifiCiphers.netWifiCiphers_TKIP) {
                            if (cipher == WifiSecurity.GROUP_CCMP) {
                                gwtGroupCiphers = GwtWifiCiphers.netWifiCiphers_CCMP_TKIP;
                            }
                        } else if (gwtGroupCiphers == GwtWifiCiphers.netWifiCiphers_CCMP) {
                            if (cipher == WifiSecurity.GROUP_TKIP) {
                                gwtGroupCiphers = GwtWifiCiphers.netWifiCiphers_CCMP_TKIP;
                            }
                        }
                    }
                    if (gwtPairCiphers != null) {
                        gwtWifiHotspotEntry.setPairwiseCiphers(gwtPairCiphers.name());
                    }
                    if (gwtGroupCiphers != null) {
                        gwtWifiHotspotEntry.setGroupCiphers(gwtGroupCiphers.name());
                    }
                    gwtWifiHotspotsEntries.add(gwtWifiHotspotEntry);
                }
            }
        }
    } catch (Throwable t) {
        s_logger.error("Failed", t);
        KuraExceptionHandler.handle(t);
    }
    return new ArrayList<GwtWifiHotspotEntry>(gwtWifiHotspotsEntries);
}
Also used : GwtWifiCiphers(org.eclipse.kura.web.shared.model.GwtWifiCiphers) ArrayList(java.util.ArrayList) SystemService(org.eclipse.kura.system.SystemService) GwtWifiSecurity(org.eclipse.kura.web.shared.model.GwtWifiSecurity) WifiSecurity(org.eclipse.kura.net.wifi.WifiSecurity) GwtWifiHotspotEntry(org.eclipse.kura.web.shared.model.GwtWifiHotspotEntry) NetworkAdminService(org.eclipse.kura.net.NetworkAdminService) WifiHotspotInfo(org.eclipse.kura.net.wifi.WifiHotspotInfo)

Aggregations

SystemService (org.eclipse.kura.system.SystemService)18 GwtKuraException (org.eclipse.kura.web.shared.GwtKuraException)8 ServiceLocator (org.eclipse.kura.web.server.util.ServiceLocator)6 ArrayList (java.util.ArrayList)5 File (java.io.File)3 IOException (java.io.IOException)3 Properties (java.util.Properties)3 ServletException (javax.servlet.ServletException)3 SystemAdminService (org.eclipse.kura.system.SystemAdminService)3 GwtGroupedNVPair (org.eclipse.kura.web.shared.model.GwtGroupedNVPair)3 Bundle (org.osgi.framework.Bundle)3 BundleException (org.osgi.framework.BundleException)3 ConfigurationService (org.eclipse.kura.configuration.ConfigurationService)2 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Iterator (java.util.Iterator)1 SortedSet (java.util.SortedSet)1 TreeSet (java.util.TreeSet)1