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