Search in sources :

Example 6 with SystemService

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

the class UploadRequest method getFileUploadInMemorySizeThreshold.

private static int getFileUploadInMemorySizeThreshold() {
    ServiceLocator locator = ServiceLocator.getInstance();
    int sizeThreshold = DiskFileItemFactory.DEFAULT_SIZE_THRESHOLD;
    try {
        SystemService systemService = locator.getService(SystemService.class);
        sizeThreshold = Integer.parseInt(systemService.getProperties().getProperty("file.upload.in.memory.size.threshold", String.valueOf(DiskFileItemFactory.DEFAULT_SIZE_THRESHOLD)));
    } catch (GwtKuraException e) {
        s_logger.error("Error locating SystemService", e);
    }
    return sizeThreshold;
}
Also used : ServiceLocator(org.eclipse.kura.web.server.util.ServiceLocator) GwtKuraException(org.eclipse.kura.web.shared.GwtKuraException) SystemService(org.eclipse.kura.system.SystemService)

Example 7 with SystemService

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

the class UploadRequest method doPostConfigurationSnapshot.

private void doPostConfigurationSnapshot(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    UploadRequest upload = new UploadRequest(this.m_diskFileItemFactory);
    try {
        upload.parse(req);
    } catch (FileUploadException e) {
        s_logger.error("Error parsing the file upload request");
        throw new ServletException("Error parsing the file upload request", e);
    }
    // BEGIN XSRF - Servlet dependent code
    Map<String, String> formFields = upload.getFormFields();
    try {
        GwtXSRFToken token = new GwtXSRFToken(formFields.get("xsrfToken"));
        KuraRemoteServiceServlet.checkXSRFToken(req, token);
    } catch (Exception e) {
        throw new ServletException("Security error: please retry this operation correctly.", e);
    }
    // END XSRF security check
    List<FileItem> fileItems = upload.getFileItems();
    if (fileItems.size() != 1) {
        s_logger.error("expected 1 file item but found {}", fileItems.size());
        throw new ServletException("Wrong number of file items");
    }
    FileItem fileItem = fileItems.get(0);
    byte[] data = fileItem.get();
    String xmlString = new String(data, "UTF-8");
    XmlComponentConfigurations xmlConfigs;
    try {
        xmlConfigs = XmlUtil.unmarshal(xmlString, XmlComponentConfigurations.class);
    } catch (Exception e) {
        s_logger.error("Error unmarshaling device configuration", e);
        throw new ServletException("Error unmarshaling device configuration", e);
    }
    ServiceLocator locator = ServiceLocator.getInstance();
    try {
        ConfigurationService cs = locator.getService(ConfigurationService.class);
        List<ComponentConfigurationImpl> configImpls = xmlConfigs.getConfigurations();
        List<ComponentConfiguration> configs = new ArrayList<ComponentConfiguration>();
        configs.addAll(configImpls);
        cs.updateConfigurations(configs);
        // 
        // Add an additional delay after the configuration update
        // to give the time to the device to apply the received
        // configuration
        SystemService ss = locator.getService(SystemService.class);
        long delay = Long.parseLong(ss.getProperties().getProperty("console.updateConfigDelay", "5000"));
        if (delay > 0) {
            Thread.sleep(delay);
        }
    } catch (Exception e) {
        s_logger.error("Error updating device configuration: {}", e);
        throw new ServletException("Error updating device configuration", e);
    }
}
Also used : ComponentConfigurationImpl(org.eclipse.kura.core.configuration.ComponentConfigurationImpl) XmlComponentConfigurations(org.eclipse.kura.core.configuration.XmlComponentConfigurations) ArrayList(java.util.ArrayList) GwtXSRFToken(org.eclipse.kura.web.shared.model.GwtXSRFToken) ServletException(javax.servlet.ServletException) GwtKuraException(org.eclipse.kura.web.shared.GwtKuraException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) FileUploadException(org.apache.commons.fileupload.FileUploadException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ServletException(javax.servlet.ServletException) ServiceLocator(org.eclipse.kura.web.server.util.ServiceLocator) ComponentConfiguration(org.eclipse.kura.configuration.ComponentConfiguration) FileItem(org.apache.commons.fileupload.FileItem) SystemService(org.eclipse.kura.system.SystemService) ConfigurationService(org.eclipse.kura.configuration.ConfigurationService) FileUploadException(org.apache.commons.fileupload.FileUploadException)

Example 8 with SystemService

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

the class LinuxProcessUtil method isUsingBusyBox.

// 
// Private Methods
// 
private static boolean isUsingBusyBox() {
    if (usingBusybox != null) {
        return usingBusybox;
    }
    final BundleContext ctx = FrameworkUtil.getBundle(LinuxProcessUtil.class).getBundleContext();
    final ServiceReference<SystemService> systemServiceRef = ctx.getServiceReference(SystemService.class);
    if (systemServiceRef == null) {
        throw new IllegalStateException("Unable to find instance of: " + SystemService.class.getName());
    }
    final SystemService service = ctx.getService(systemServiceRef);
    if (service == null) {
        throw new IllegalStateException("Unable to get instance of: " + SystemService.class.getName());
    }
    try {
        usingBusybox = PLATFORM_INTEL_EDISON.equals(service.getPlatform());
    } finally {
        ctx.ungetService(systemServiceRef);
    }
    return usingBusybox;
}
Also used : SystemService(org.eclipse.kura.system.SystemService) BundleContext(org.osgi.framework.BundleContext)

Example 9 with SystemService

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

the class ThreadGroupComparator method stopBundle.

@Override
public void stopBundle(GwtXSRFToken xsrfToken, String bundleId) throws GwtKuraException {
    checkXSRFToken(xsrfToken);
    SystemService systemService = ServiceLocator.getInstance().getService(SystemService.class);
    Bundle[] bundles = systemService.getBundles();
    s_logger.info("Stopping bundle with ID: {}", bundleId);
    for (Bundle b : bundles) {
        if (b.getBundleId() == Long.parseLong(bundleId)) {
            try {
                b.stop();
                return;
            } catch (BundleException e) {
                s_logger.error("Failed to stop 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 10 with SystemService

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

the class ThreadGroupComparator method findBundles.

@Override
public ArrayList<GwtGroupedNVPair> findBundles(GwtXSRFToken xsrfToken) throws GwtKuraException {
    checkXSRFToken(xsrfToken);
    List<GwtGroupedNVPair> pairs = new ArrayList<GwtGroupedNVPair>();
    SystemService systemService = ServiceLocator.getInstance().getService(SystemService.class);
    Bundle[] bundles = systemService.getBundles();
    if (bundles != null) {
        for (Bundle bundle : bundles) {
            if (bundle != null) {
                GwtGroupedNVPair pair = new GwtGroupedNVPair();
                pair.setId(String.valueOf(bundle.getBundleId()));
                pair.setName(getName(bundle));
                pair.setStatus(toStateString(bundle));
                pair.setVersion(getHeaderValue(bundle, Constants.BUNDLE_VERSION));
                pairs.add(pair);
            }
        }
    }
    return new ArrayList<GwtGroupedNVPair>(pairs);
}
Also used : SystemService(org.eclipse.kura.system.SystemService) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) GwtGroupedNVPair(org.eclipse.kura.web.shared.model.GwtGroupedNVPair)

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