diff --git a/console/module/device/src/main/java/org/eclipse/kapua/app/console/module/device/server/GwtDeviceManagementServiceImpl.java b/console/module/device/src/main/java/org/eclipse/kapua/app/console/module/device/server/GwtDeviceManagementServiceImpl.java index 55da7b1b7b4..abf34b975c0 100644 --- a/console/module/device/src/main/java/org/eclipse/kapua/app/console/module/device/server/GwtDeviceManagementServiceImpl.java +++ b/console/module/device/src/main/java/org/eclipse/kapua/app/console/module/device/server/GwtDeviceManagementServiceImpl.java @@ -106,6 +106,23 @@ public class GwtDeviceManagementServiceImpl extends KapuaRemoteServiceServlet im private static final String PASSWORD_PLACEHOLDER = "You won't know this secret! :P"; + private static final ConsoleSetting CONSOLE_SETTING = ConsoleSetting.getInstance(); + + private static final KapuaLocator LOCATOR = KapuaLocator.getInstance(); + + private static final DeviceBundleManagementService BUNDLE_MANAGEMENT_SERVICE = LOCATOR.getService(DeviceBundleManagementService.class); + + private static final DeviceCommandManagementService COMMAND_MANAGEMENT_SERVICE = LOCATOR.getService(DeviceCommandManagementService.class); + private static final DeviceCommandFactory DEVICE_COMMAND_FACTORY = LOCATOR.getFactory(DeviceCommandFactory.class); + + private static final DeviceConfigurationManagementService CONFIGURATION_MANAGEMENT_SERVICE = LOCATOR.getService(DeviceConfigurationManagementService.class); + private static final DeviceConfigurationFactory DEVICE_CONFIGURATION_FACTORY = LOCATOR.getFactory(DeviceConfigurationFactory.class); + + private static final DevicePackageManagementService PACKAGE_MANAGEMENT_SERVICE = LOCATOR.getService(DevicePackageManagementService.class); + private static final DevicePackageFactory DEVICE_PACKAGE_FACTORY = LOCATOR.getFactory(DevicePackageFactory.class); + + private static final DeviceSnapshotManagementService SNAPSHOT_MANAGEMENT_SERVICE = LOCATOR.getService(DeviceSnapshotManagementService.class); + // // Packages // @@ -114,12 +131,9 @@ public List findDevicePackages(String scopeShortId, String throws GwtKapuaException { List gwtPkgs = new ArrayList(); try { - KapuaLocator locator = KapuaLocator.getInstance(); - DevicePackageManagementService deviceManagementService = locator.getService(DevicePackageManagementService.class); - KapuaId scopeId = KapuaEid.parseCompactId(scopeShortId); KapuaId deviceId = KapuaEid.parseCompactId(deviceShortId); - DevicePackages deploymentPackages = deviceManagementService.getInstalled(scopeId, deviceId, null); + DevicePackages deploymentPackages = PACKAGE_MANAGEMENT_SERVICE.getInstalled(scopeId, deviceId, null); for (DevicePackage deploymentPackage : deploymentPackages.getPackages()) { GwtDeploymentPackage gwtPkg = new GwtDeploymentPackage(); @@ -161,10 +175,7 @@ public void installPackage(GwtXSRFToken xsrfToken, GwtPackageInstallRequest gwtP KapuaId scopeId = KapuaEid.parseCompactId(gwtPackageInstallRequest.getScopeId()); KapuaId deviceId = KapuaEid.parseCompactId(gwtPackageInstallRequest.getDeviceId()); - KapuaLocator locator = KapuaLocator.getInstance(); - DevicePackageFactory devicePackageFactory = locator.getFactory(DevicePackageFactory.class); - - DevicePackageDownloadRequest packageDownloadRequest = devicePackageFactory.newPackageDownloadRequest(); + DevicePackageDownloadRequest packageDownloadRequest = DEVICE_PACKAGE_FACTORY.newPackageDownloadRequest(); URI packageUri = null; try { packageUri = new URI(gwtPackageInstallRequest.getPackageURI()); @@ -178,8 +189,7 @@ public void installPackage(GwtXSRFToken xsrfToken, GwtPackageInstallRequest gwtP packageDownloadRequest.setReboot(gwtPackageInstallRequest.isReboot()); packageDownloadRequest.setRebootDelay(gwtPackageInstallRequest.getRebootDelay()); - DevicePackageManagementService packageManagementService = locator.getService(DevicePackageManagementService.class); - packageManagementService.downloadExec(scopeId, deviceId, packageDownloadRequest, null); + PACKAGE_MANAGEMENT_SERVICE.downloadExec(scopeId, deviceId, packageDownloadRequest, DEVICE_PACKAGE_FACTORY.newDevicePackageDownloadOptions()); } catch (Throwable t) { KapuaExceptionHandler.handle(t); } @@ -190,23 +200,19 @@ public ListLoadResult getDownloadOperations(String scopeSho throws GwtKapuaException { List gwtDeviceOperations = new ArrayList(); try { - - KapuaLocator locator = KapuaLocator.getInstance(); - DevicePackageManagementService deviceManagementService = locator.getService(DevicePackageManagementService.class); - KapuaId scopeId = KapuaEid.parseCompactId(scopeShortId); KapuaId deviceId = KapuaEid.parseCompactId(deviceShortId); - DevicePackageDownloadOperation downloadOperation = deviceManagementService.downloadStatus(scopeId, deviceId, null); + DevicePackageDownloadOperation downloadOperation = PACKAGE_MANAGEMENT_SERVICE.downloadStatus(scopeId, deviceId, null); if (!DevicePackageDownloadStatus.NONE.equals(downloadOperation.getStatus())) { - GwtPackageDownloadOperation gwtDownloadOperation = new GwtPackageDownloadOperation(); + GwtPackageDownloadOperation gwtDownloadOperation = new GwtPackageDownloadOperation(); - gwtDownloadOperation.setId(downloadOperation.getId().toCompactId()); - gwtDownloadOperation.setStatus(downloadOperation.getStatus().name()); - gwtDownloadOperation.setSize(downloadOperation.getSize()); - gwtDownloadOperation.setProgress(downloadOperation.getProgress()); + gwtDownloadOperation.setId(downloadOperation.getId().toCompactId()); + gwtDownloadOperation.setStatus(downloadOperation.getStatus().name()); + gwtDownloadOperation.setSize(downloadOperation.getSize()); + gwtDownloadOperation.setProgress(downloadOperation.getProgress()); - gwtDeviceOperations.add(gwtDownloadOperation); + gwtDeviceOperations.add(gwtDownloadOperation); } } catch (Throwable t) { @@ -223,29 +229,21 @@ public void uninstallPackage(GwtXSRFToken xsrfToken, GwtPackageUninstallRequest checkXSRFToken(xsrfToken); // - // Do install + // Do uninstall try { KapuaId scopeId = KapuaEid.parseCompactId(gwtPackageUninstallRequest.getScopeId()); KapuaId deviceId = KapuaEid.parseCompactId(gwtPackageUninstallRequest.getDeviceId()); - KapuaLocator locator = KapuaLocator.getInstance(); - DevicePackageFactory devicePackageFactory = locator.getFactory(DevicePackageFactory.class); - - DevicePackageUninstallRequest packageUninstallRequest = devicePackageFactory.newPackageUninstallRequest(); + DevicePackageUninstallRequest packageUninstallRequest = DEVICE_PACKAGE_FACTORY.newPackageUninstallRequest(); packageUninstallRequest.setName(gwtPackageUninstallRequest.getPackageName()); packageUninstallRequest.setVersion(gwtPackageUninstallRequest.getPackageVersion()); packageUninstallRequest.setReboot(gwtPackageUninstallRequest.isReboot()); packageUninstallRequest.setRebootDelay(gwtPackageUninstallRequest.getRebootDelay()); - DevicePackageManagementService packageManagementService = locator.getService(DevicePackageManagementService.class); - packageManagementService.uninstallExec(scopeId, - deviceId, - packageUninstallRequest, - null); + PACKAGE_MANAGEMENT_SERVICE.uninstallExec(scopeId, deviceId, packageUninstallRequest, DEVICE_PACKAGE_FACTORY.newDevicePackageUninstallOptions()); } catch (Throwable t) { KapuaExceptionHandler.handle(t); } - } // @@ -256,18 +254,12 @@ public List findDeviceConfigurations(GwtDevice device) throws GwtKapuaException { List gwtConfigs = new ArrayList(); try { - - // get the configuration - KapuaLocator locator = KapuaLocator.getInstance(); - DeviceConfigurationManagementService deviceConfiguratiomManagementService = locator.getService(DeviceConfigurationManagementService.class); - KapuaId scopeId = KapuaEid.parseCompactId(device.getScopeId()); KapuaId deviceId = KapuaEid.parseCompactId(device.getId()); - DeviceConfiguration deviceConfigurations = deviceConfiguratiomManagementService.get(scopeId, - deviceId, - null, - null, - null); + + // + // Get the configuration + DeviceConfiguration deviceConfigurations = CONFIGURATION_MANAGEMENT_SERVICE.get(scopeId, deviceId, null, null, null); if (deviceConfigurations != null) { @@ -291,9 +283,10 @@ public int compare(DeviceComponentConfiguration arg0, DeviceComponentConfigurati } }); - // prepare results - ConsoleSetting consoleConfig = ConsoleSetting.getInstance(); - List serviceIgnore = consoleConfig.getList(String.class, ConsoleSettingKeys.DEVICE_CONFIGURATION_SERVICE_IGNORE); + // + // Prepare results + List serviceIgnore = CONSOLE_SETTING.getList(String.class, ConsoleSettingKeys.DEVICE_CONFIGURATION_SERVICE_IGNORE); + for (DeviceComponentConfiguration config : deviceConfigurations.getComponentConfigurations()) { // ignore items we want to hide @@ -305,10 +298,10 @@ public int compare(DeviceComponentConfiguration arg0, DeviceComponentConfigurati if (ocd != null) { GwtConfigComponent gwtConfig = new GwtConfigComponent(); gwtConfig.setId(config.getId()); - if(config.getProperties() != null && config.getProperties().get("service.factoryPid") != null) { + if (config.getProperties() != null && config.getProperties().get("service.factoryPid") != null) { String componentName = config.getId().substring(config.getId().lastIndexOf('.') + 1); gwtConfig.setName(componentName); - } else if(config.getId().indexOf('.') == -1) { + } else if (config.getId().indexOf('.') == -1) { gwtConfig.setName(config.getId()); } else { gwtConfig.setName(ocd.getName()); @@ -367,7 +360,7 @@ public int compare(DeviceComponentConfiguration arg0, DeviceComponentConfigurati strValues.add(v.toString()); } } - gwtParam.setValues(strValues.toArray(new String[] {})); + gwtParam.setValues(strValues.toArray(new String[]{})); } } } @@ -386,20 +379,15 @@ public int compare(DeviceComponentConfiguration arg0, DeviceComponentConfigurati } @Override - public void updateComponentConfiguration(GwtXSRFToken xsrfToken, - GwtDevice gwtDevice, - GwtConfigComponent gwtCompConfig) + public void updateComponentConfiguration(GwtXSRFToken xsrfToken, GwtDevice gwtDevice, GwtConfigComponent gwtCompConfig) throws GwtKapuaException { // // Checking validity of the given XSRF Token checkXSRFToken(xsrfToken); - KapuaLocator locator = KapuaLocator.getInstance(); - DeviceConfigurationManagementService deviceConfigurationManagementService = locator.getService(DeviceConfigurationManagementService.class); - DeviceConfigurationFactory deviceConfigurationManagementFactory = locator.getFactory(DeviceConfigurationFactory.class); - - // set name and properties - DeviceComponentConfiguration compConfig = deviceConfigurationManagementFactory.newComponentConfigurationInstance(gwtCompConfig.getUnescapedComponentId()); + // + // Set name and properties + DeviceComponentConfiguration compConfig = DEVICE_CONFIGURATION_FACTORY.newComponentConfigurationInstance(gwtCompConfig.getUnescapedComponentId()); compConfig.setName(gwtCompConfig.getUnescapedComponentName()); Map compProps = new HashMap(); @@ -430,10 +418,8 @@ public void updateComponentConfiguration(GwtXSRFToken xsrfToken, try { KapuaId scopeId = KapuaEid.parseCompactId(gwtDevice.getScopeId()); KapuaId deviceId = KapuaEid.parseCompactId(gwtDevice.getId()); - deviceConfigurationManagementService.put(scopeId, - deviceId, - compConfig, - null); + + CONFIGURATION_MANAGEMENT_SERVICE.put(scopeId, deviceId, compConfig, null); // // Add an additional delay after the configuration update @@ -453,19 +439,14 @@ public ListLoadResult findDeviceSnapshots(GwtDevice gwtDevice) throws GwtKapuaException { List snapshots = new ArrayList(); try { - - // execute the command - KapuaLocator locator = KapuaLocator.getInstance(); - DeviceSnapshotManagementService deviceSnapshotManagementService = locator.getService(DeviceSnapshotManagementService.class); - KapuaId scopeId = KapuaEid.parseCompactId(gwtDevice.getScopeId()); KapuaId deviceId = KapuaEid.parseCompactId(gwtDevice.getId()); - DeviceSnapshots snapshotIds = deviceSnapshotManagementService.get(scopeId, - deviceId, - null); - // sort them by most recent first - // sort the list alphabetically by service name + // + // Execute the command + DeviceSnapshots snapshotIds = SNAPSHOT_MANAGEMENT_SERVICE.get(scopeId, deviceId, null); + + // Sort them by most recent first Collections.sort(snapshotIds.getSnapshots(), new Comparator() { @Override @@ -496,15 +477,10 @@ public void rollbackDeviceSnapshot(GwtXSRFToken xsrfToken, GwtDevice gwtDevice, checkXSRFToken(xsrfToken); try { - KapuaLocator locator = KapuaLocator.getInstance(); - DeviceSnapshotManagementService deviceService = locator.getService(DeviceSnapshotManagementService.class); - KapuaId scopeId = KapuaEid.parseCompactId(gwtDevice.getScopeId()); KapuaId deviceId = KapuaEid.parseCompactId(gwtDevice.getId()); - deviceService.rollback(scopeId, - deviceId, - String.valueOf(snapshot.getSnapshotId()), - null); + + SNAPSHOT_MANAGEMENT_SERVICE.rollback(scopeId, deviceId, String.valueOf(snapshot.getSnapshotId()), null); } catch (Throwable t) { KapuaExceptionHandler.handle(t); } @@ -519,16 +495,12 @@ public ListLoadResult findBundles(GwtDevice device) List pairs = new ArrayList(); try { - - // get the configuration - KapuaLocator locator = KapuaLocator.getInstance(); - DeviceBundleManagementService deviceBundleManagementService = locator.getService(DeviceBundleManagementService.class); - KapuaId scopeId = KapuaEid.parseCompactId(device.getScopeId()); KapuaId id = KapuaEid.parseCompactId(device.getId()); - DeviceBundles bundles = deviceBundleManagementService.get(scopeId, - id, - null); + + // + // Get the bundles + DeviceBundles bundles = BUNDLE_MANAGEMENT_SERVICE.get(scopeId, id, null); for (DeviceBundle bundle : bundles.getBundles()) { GwtBundle pair = new GwtBundle(); @@ -554,15 +526,10 @@ public void startBundle(GwtXSRFToken xsrfToken, GwtDevice device, GwtBundle gwtB checkXSRFToken(xsrfToken); try { - KapuaLocator locator = KapuaLocator.getInstance(); - DeviceBundleManagementService deviceBundleManagementService = locator.getService(DeviceBundleManagementService.class); - KapuaId scopeId = KapuaEid.parseCompactId(device.getScopeId()); KapuaId deviceId = KapuaEid.parseCompactId(device.getId()); - deviceBundleManagementService.start(scopeId, - deviceId, - String.valueOf(gwtBundle.getId()), - null); + + BUNDLE_MANAGEMENT_SERVICE.start(scopeId, deviceId, String.valueOf(gwtBundle.getId()), null); } catch (Throwable t) { KapuaExceptionHandler.handle(t); } @@ -576,15 +543,10 @@ public void stopBundle(GwtXSRFToken xsrfToken, GwtDevice device, GwtBundle gwtBu checkXSRFToken(xsrfToken); try { - KapuaLocator locator = KapuaLocator.getInstance(); - DeviceBundleManagementService deviceBundleManagementService = locator.getService(DeviceBundleManagementService.class); - KapuaId scopeId = KapuaEid.parseCompactId(device.getScopeId()); KapuaId deviceId = KapuaEid.parseCompactId(device.getId()); - deviceBundleManagementService.stop(scopeId, - deviceId, - String.valueOf(gwtBundle.getId()), - null); + + BUNDLE_MANAGEMENT_SERVICE.stop(scopeId, deviceId, String.valueOf(gwtBundle.getId()), null); } catch (Throwable t) { KapuaExceptionHandler.handle(t); } @@ -602,12 +564,11 @@ public GwtDeviceCommandOutput executeCommand(GwtXSRFToken xsrfToken, GwtDevice g GwtDeviceCommandOutput gwtCommandOutput = new GwtDeviceCommandOutput(); try { + KapuaId scopeId = KapuaEid.parseCompactId(gwtDevice.getScopeId()); + KapuaId deviceId = KapuaEid.parseCompactId(gwtDevice.getId()); - // execute the command - KapuaLocator locator = KapuaLocator.getInstance(); - DeviceCommandManagementService deviceCommandManagementService = locator.getService(DeviceCommandManagementService.class); - DeviceCommandFactory deviceCommandFactory = locator.getFactory(DeviceCommandFactory.class); - + // + // Execute the command StringTokenizer st = new StringTokenizer(gwtCommandInput.getCommand()); int count = st.countTokens(); @@ -618,21 +579,17 @@ public GwtDeviceCommandOutput executeCommand(GwtXSRFToken xsrfToken, GwtDevice g args[i++] = st.nextToken(); } - DeviceCommandInput commandInput = deviceCommandFactory.newCommandInput(); + DeviceCommandInput commandInput = DEVICE_COMMAND_FACTORY.newCommandInput(); commandInput.setArguments(args); commandInput.setCommand(command); commandInput.setEnvironment(gwtCommandInput.getEnvironment()); - commandInput.setRunAsynch(gwtCommandInput.isRunAsynch() != null && gwtCommandInput.isRunAsynch().booleanValue()); + commandInput.setRunAsynch(gwtCommandInput.isRunAsynch() != null && gwtCommandInput.isRunAsynch()); commandInput.setStdin(gwtCommandInput.getStdin()); commandInput.setTimeout(gwtCommandInput.getTimeout() != null ? gwtCommandInput.getTimeout() : 0); commandInput.setWorkingDir(gwtCommandInput.getWorkingDir()); commandInput.setBody(gwtCommandInput.getZipBytes()); - KapuaId scopeId = KapuaEid.parseCompactId(gwtDevice.getScopeId()); - KapuaId deviceId = KapuaEid.parseCompactId(gwtDevice.getId()); - DeviceCommandOutput commandOutput = deviceCommandManagementService.exec(scopeId, - deviceId, - commandInput, null); + DeviceCommandOutput commandOutput = COMMAND_MANAGEMENT_SERVICE.exec(scopeId, deviceId, commandInput, null); if (commandOutput.getExceptionMessage() != null) { gwtCommandOutput.setExceptionMessage(commandOutput.getExceptionMessage().replace("\n", "
")); @@ -680,36 +637,36 @@ private Object getObjectValue(GwtConfigParameter gwtConfigParam, String strValue if (strValue != null) { GwtConfigParameterType gwtType = gwtConfigParam.getType(); switch (gwtType) { - case LONG: - objValue = Long.parseLong(strValue); - break; - case DOUBLE: - objValue = Double.parseDouble(strValue); - break; - case FLOAT: - objValue = Float.parseFloat(strValue); - break; - case INTEGER: - objValue = Integer.parseInt(strValue); - break; - case SHORT: - objValue = Short.parseShort(strValue); - break; - case BYTE: - objValue = Byte.parseByte(strValue); - break; - case BOOLEAN: - objValue = Boolean.parseBoolean(strValue); - break; - case PASSWORD: - objValue = new Password(strValue); - break; - case CHAR: - objValue = strValue.charAt(0); - break; - case STRING: - objValue = strValue; - break; + case LONG: + objValue = Long.parseLong(strValue); + break; + case DOUBLE: + objValue = Double.parseDouble(strValue); + break; + case FLOAT: + objValue = Float.parseFloat(strValue); + break; + case INTEGER: + objValue = Integer.parseInt(strValue); + break; + case SHORT: + objValue = Short.parseShort(strValue); + break; + case BYTE: + objValue = Byte.parseByte(strValue); + break; + case BOOLEAN: + objValue = Boolean.parseBoolean(strValue); + break; + case PASSWORD: + objValue = new Password(strValue); + break; + case CHAR: + objValue = strValue.charAt(0); + break; + case STRING: + objValue = strValue; + break; } } return objValue; @@ -719,63 +676,63 @@ private Object[] getObjectValue(GwtConfigParameter gwtConfigParam, String[] defa List values = new ArrayList(); GwtConfigParameterType type = gwtConfigParam.getType(); switch (type) { - case BOOLEAN: - for (String value : defaultValues) { - values.add(Boolean.valueOf(value)); - } - return values.toArray(new Boolean[] {}); + case BOOLEAN: + for (String value : defaultValues) { + values.add(Boolean.valueOf(value)); + } + return values.toArray(); - case BYTE: - for (String value : defaultValues) { - values.add(Byte.valueOf(value)); - } - return values.toArray(new Byte[] {}); + case BYTE: + for (String value : defaultValues) { + values.add(Byte.valueOf(value)); + } + return values.toArray(); - case CHAR: - for (String value : defaultValues) { - values.add(value.charAt(0)); - } - return values.toArray(new Character[] {}); + case CHAR: + for (String value : defaultValues) { + values.add(value.charAt(0)); + } + return values.toArray(); - case DOUBLE: - for (String value : defaultValues) { - values.add(Double.valueOf(value)); - } - return values.toArray(new Double[] {}); + case DOUBLE: + for (String value : defaultValues) { + values.add(Double.valueOf(value)); + } + return values.toArray(); - case FLOAT: - for (String value : defaultValues) { - values.add(Float.valueOf(value)); - } - return values.toArray(new Float[] {}); + case FLOAT: + for (String value : defaultValues) { + values.add(Float.valueOf(value)); + } + return values.toArray(); - case INTEGER: - for (String value : defaultValues) { - values.add(Integer.valueOf(value)); - } - return values.toArray(new Integer[] {}); + case INTEGER: + for (String value : defaultValues) { + values.add(Integer.valueOf(value)); + } + return values.toArray(); - case LONG: - for (String value : defaultValues) { - values.add(Long.valueOf(value)); - } - return values.toArray(new Long[] {}); + case LONG: + for (String value : defaultValues) { + values.add(Long.valueOf(value)); + } + return values.toArray(); - case SHORT: - for (String value : defaultValues) { - values.add(Short.valueOf(value)); - } - return values.toArray(new Short[] {}); + case SHORT: + for (String value : defaultValues) { + values.add(Short.valueOf(value)); + } + return values.toArray(); - case PASSWORD: - for (String value : defaultValues) { - values.add(new Password(value)); - } - return values.toArray(new Password[] {}); + case PASSWORD: + for (String value : defaultValues) { + values.add(new Password(value)); + } + return values.toArray(); - case STRING: - default: - return defaultValues; + case STRING: + default: + return defaultValues; } } diff --git a/service/device/commons/src/main/java/org/eclipse/kapua/service/device/management/commons/AbstractDeviceManagementServiceImpl.java b/service/device/commons/src/main/java/org/eclipse/kapua/service/device/management/commons/AbstractDeviceManagementServiceImpl.java index c46d01002bf..02420b4a067 100644 --- a/service/device/commons/src/main/java/org/eclipse/kapua/service/device/management/commons/AbstractDeviceManagementServiceImpl.java +++ b/service/device/commons/src/main/java/org/eclipse/kapua/service/device/management/commons/AbstractDeviceManagementServiceImpl.java @@ -19,6 +19,8 @@ import org.eclipse.kapua.model.id.KapuaId; import org.eclipse.kapua.model.type.ObjectTypeConverter; import org.eclipse.kapua.model.type.ObjectValueConverter; +import org.eclipse.kapua.service.authorization.AuthorizationService; +import org.eclipse.kapua.service.authorization.permission.PermissionFactory; import org.eclipse.kapua.service.device.management.message.notification.OperationStatus; import org.eclipse.kapua.service.device.management.message.request.KapuaRequestMessage; import org.eclipse.kapua.service.device.management.message.response.KapuaResponseMessage; @@ -45,7 +47,10 @@ */ public abstract class AbstractDeviceManagementServiceImpl { - private static final KapuaLocator LOCATOR = KapuaLocator.getInstance(); + protected static final KapuaLocator LOCATOR = KapuaLocator.getInstance(); + + protected static final AuthorizationService AUTHORIZATION_SERVICE = LOCATOR.getService(AuthorizationService.class); + protected static final PermissionFactory PERMISSION_FACTORY = LOCATOR.getFactory(PermissionFactory.class); private static final DeviceEventService DEVICE_EVENT_SERVICE = LOCATOR.getService(DeviceEventService.class); private static final DeviceEventFactory DEVICE_EVENT_FACTORY = LOCATOR.getFactory(DeviceEventFactory.class); diff --git a/service/device/management/asset/internal/src/main/java/org/eclipse/kapua/service/device/management/asset/internal/DeviceAssetManagementServiceImpl.java b/service/device/management/asset/internal/src/main/java/org/eclipse/kapua/service/device/management/asset/internal/DeviceAssetManagementServiceImpl.java index 5ecd16a5646..301ba685499 100644 --- a/service/device/management/asset/internal/src/main/java/org/eclipse/kapua/service/device/management/asset/internal/DeviceAssetManagementServiceImpl.java +++ b/service/device/management/asset/internal/src/main/java/org/eclipse/kapua/service/device/management/asset/internal/DeviceAssetManagementServiceImpl.java @@ -13,12 +13,9 @@ import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.util.ArgumentValidator; -import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.locator.KapuaProvider; import org.eclipse.kapua.model.domain.Actions; import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.service.authorization.AuthorizationService; -import org.eclipse.kapua.service.authorization.permission.PermissionFactory; import org.eclipse.kapua.service.device.management.DeviceManagementDomains; import org.eclipse.kapua.service.device.management.asset.DeviceAssetManagementService; import org.eclipse.kapua.service.device.management.asset.DeviceAssets; @@ -63,10 +60,7 @@ public DeviceAssets get(KapuaId scopeId, KapuaId deviceId, DeviceAssets deviceAs // // Check Access - KapuaLocator locator = KapuaLocator.getInstance(); - AuthorizationService authorizationService = locator.getService(AuthorizationService.class); - PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class); - authorizationService.checkPermission(permissionFactory.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.read, scopeId)); + AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.read, scopeId)); // // Prepare the request @@ -127,10 +121,7 @@ public DeviceAssets read(KapuaId scopeId, KapuaId deviceId, DeviceAssets deviceA // // Check Access - KapuaLocator locator = KapuaLocator.getInstance(); - AuthorizationService authorizationService = locator.getService(AuthorizationService.class); - PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class); - authorizationService.checkPermission(permissionFactory.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.read, scopeId)); + AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.read, scopeId)); // // Prepare the request @@ -192,10 +183,7 @@ public DeviceAssets write(KapuaId scopeId, KapuaId deviceId, DeviceAssets device // // Check Access - KapuaLocator locator = KapuaLocator.getInstance(); - AuthorizationService authorizationService = locator.getService(AuthorizationService.class); - PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class); - authorizationService.checkPermission(permissionFactory.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.write, scopeId)); + AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.write, scopeId)); // // Prepare the request diff --git a/service/device/management/bundle/internal/src/main/java/org/eclipse/kapua/service/device/management/bundle/internal/DeviceBundleManagementServiceImpl.java b/service/device/management/bundle/internal/src/main/java/org/eclipse/kapua/service/device/management/bundle/internal/DeviceBundleManagementServiceImpl.java index 1b60fecfc4e..8423f0afb71 100644 --- a/service/device/management/bundle/internal/src/main/java/org/eclipse/kapua/service/device/management/bundle/internal/DeviceBundleManagementServiceImpl.java +++ b/service/device/management/bundle/internal/src/main/java/org/eclipse/kapua/service/device/management/bundle/internal/DeviceBundleManagementServiceImpl.java @@ -15,12 +15,9 @@ import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.util.ArgumentValidator; import org.eclipse.kapua.commons.util.xml.XmlUtil; -import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.locator.KapuaProvider; import org.eclipse.kapua.model.domain.Actions; import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.service.authorization.AuthorizationService; -import org.eclipse.kapua.service.authorization.permission.PermissionFactory; import org.eclipse.kapua.service.device.management.DeviceManagementDomains; import org.eclipse.kapua.service.device.management.bundle.DeviceBundleManagementService; import org.eclipse.kapua.service.device.management.bundle.DeviceBundles; @@ -60,10 +57,7 @@ public DeviceBundles get(KapuaId scopeId, KapuaId deviceId, Long timeout) // // Check Access - KapuaLocator locator = KapuaLocator.getInstance(); - AuthorizationService authorizationService = locator.getService(AuthorizationService.class); - PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class); - authorizationService.checkPermission(permissionFactory.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.read, scopeId)); + AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.read, scopeId)); // // Prepare the request @@ -133,10 +127,7 @@ public void start(KapuaId scopeId, KapuaId deviceId, String bundleId, Long timeo // // Check Access - KapuaLocator locator = KapuaLocator.getInstance(); - AuthorizationService authorizationService = locator.getService(AuthorizationService.class); - PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class); - authorizationService.checkPermission(permissionFactory.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.execute, scopeId)); + AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.execute, scopeId)); // // Prepare the request @@ -185,10 +176,7 @@ public void stop(KapuaId scopeId, KapuaId deviceId, String bundleId, Long timeou // // Check Access - KapuaLocator locator = KapuaLocator.getInstance(); - AuthorizationService authorizationService = locator.getService(AuthorizationService.class); - PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class); - authorizationService.checkPermission(permissionFactory.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.execute, scopeId)); + AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.execute, scopeId)); // // Prepare the request diff --git a/service/device/management/command/internal/src/main/java/org/eclipse/kapua/service/device/management/command/internal/DeviceCommandManagementServiceImpl.java b/service/device/management/command/internal/src/main/java/org/eclipse/kapua/service/device/management/command/internal/DeviceCommandManagementServiceImpl.java index 2c6d9250676..6d4c27722e3 100644 --- a/service/device/management/command/internal/src/main/java/org/eclipse/kapua/service/device/management/command/internal/DeviceCommandManagementServiceImpl.java +++ b/service/device/management/command/internal/src/main/java/org/eclipse/kapua/service/device/management/command/internal/DeviceCommandManagementServiceImpl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2017 Eurotech and/or its affiliates and others + * Copyright (c) 2016, 2019 Eurotech and/or its affiliates and others * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -13,12 +13,9 @@ import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.util.ArgumentValidator; -import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.locator.KapuaProvider; import org.eclipse.kapua.model.domain.Actions; import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.service.authorization.AuthorizationService; -import org.eclipse.kapua.service.authorization.permission.PermissionFactory; import org.eclipse.kapua.service.device.management.DeviceManagementDomains; import org.eclipse.kapua.service.device.management.command.DeviceCommandInput; import org.eclipse.kapua.service.device.management.command.DeviceCommandManagementService; @@ -39,7 +36,7 @@ /** * {@link DeviceCommandManagementService} implementation. * - * @since 1.0 + * @since 1.0.0 */ @KapuaProvider public class DeviceCommandManagementServiceImpl extends AbstractDeviceManagementServiceImpl implements DeviceCommandManagementService { @@ -56,10 +53,7 @@ public DeviceCommandOutput exec(KapuaId scopeId, KapuaId deviceId, DeviceCommand // // Check Access - KapuaLocator locator = KapuaLocator.getInstance(); - AuthorizationService authorizationService = locator.getService(AuthorizationService.class); - PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class); - authorizationService.checkPermission(permissionFactory.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.execute, scopeId)); + AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.execute, scopeId)); // // Prepare the request diff --git a/service/device/management/configuration/internal/src/main/java/org/eclipse/kapua/service/device/management/configuration/internal/DeviceConfigurationManagementServiceImpl.java b/service/device/management/configuration/internal/src/main/java/org/eclipse/kapua/service/device/management/configuration/internal/DeviceConfigurationManagementServiceImpl.java index f39331948e4..d4215794542 100644 --- a/service/device/management/configuration/internal/src/main/java/org/eclipse/kapua/service/device/management/configuration/internal/DeviceConfigurationManagementServiceImpl.java +++ b/service/device/management/configuration/internal/src/main/java/org/eclipse/kapua/service/device/management/configuration/internal/DeviceConfigurationManagementServiceImpl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2018 Eurotech and/or its affiliates and others + * Copyright (c) 2016, 2019 Eurotech and/or its affiliates and others * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -15,12 +15,9 @@ import org.eclipse.kapua.KapuaIllegalArgumentException; import org.eclipse.kapua.commons.util.ArgumentValidator; import org.eclipse.kapua.commons.util.xml.XmlUtil; -import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.locator.KapuaProvider; import org.eclipse.kapua.model.domain.Actions; import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.service.authorization.AuthorizationService; -import org.eclipse.kapua.service.authorization.permission.PermissionFactory; import org.eclipse.kapua.service.device.management.DeviceManagementDomains; import org.eclipse.kapua.service.device.management.commons.AbstractDeviceManagementServiceImpl; import org.eclipse.kapua.service.device.management.commons.call.DeviceCallExecutor; @@ -50,13 +47,15 @@ import java.util.Date; /** - * {@link DeviceConfigurationManagementService }implementation. + * {@link DeviceConfigurationManagementService} implementation. * - * @since 1.0 + * @since 1.0.0 */ @KapuaProvider public class DeviceConfigurationManagementServiceImpl extends AbstractDeviceManagementServiceImpl implements DeviceConfigurationManagementService { + private static final DeviceConfigurationFactory DEVICE_CONFIGURATION_FACTORY = LOCATOR.getFactory(DeviceConfigurationFactory.class); + @Override public DeviceConfiguration get(KapuaId scopeId, KapuaId deviceId, String configurationId, String configurationComponentPid, Long timeout) throws KapuaException { @@ -67,10 +66,7 @@ public DeviceConfiguration get(KapuaId scopeId, KapuaId deviceId, String configu // // Check Access - KapuaLocator locator = KapuaLocator.getInstance(); - AuthorizationService authorizationService = locator.getService(AuthorizationService.class); - PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class); - authorizationService.checkPermission(permissionFactory.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.read, scopeId)); + AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.read, scopeId)); // // Prepare the request @@ -144,10 +140,7 @@ public void put(KapuaId scopeId, KapuaId deviceId, DeviceComponentConfiguration // // Check Access - KapuaLocator locator = KapuaLocator.getInstance(); - AuthorizationService authorizationService = locator.getService(AuthorizationService.class); - PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class); - authorizationService.checkPermission(permissionFactory.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.write, scopeId)); + AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.write, scopeId)); // // Prepare the request @@ -160,8 +153,7 @@ public void put(KapuaId scopeId, KapuaId deviceId, DeviceComponentConfiguration ConfigurationRequestPayload configurationRequestPayload = new ConfigurationRequestPayload(); try { - DeviceConfigurationFactory deviceConfigurationFactory = locator.getFactory(DeviceConfigurationFactory.class); - DeviceConfiguration deviceConfiguration = deviceConfigurationFactory.newConfigurationInstance(); + DeviceConfiguration deviceConfiguration = DEVICE_CONFIGURATION_FACTORY.newConfigurationInstance(); deviceConfiguration.getComponentConfigurations().add(deviceComponentConfiguration); DeviceManagementSetting deviceManagementConfig = DeviceManagementSetting.getInstance(); @@ -226,10 +218,7 @@ public void put(KapuaId scopeId, KapuaId deviceId, DeviceConfiguration deviceCon // // Check Access - KapuaLocator locator = KapuaLocator.getInstance(); - AuthorizationService authorizationService = locator.getService(AuthorizationService.class); - PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class); - authorizationService.checkPermission(permissionFactory.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.write, scopeId)); + AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.write, scopeId)); // // Prepare the request diff --git a/service/device/management/configuration/internal/src/main/java/org/eclipse/kapua/service/device/management/snapshot/internal/DeviceSnapshotManagementServiceImpl.java b/service/device/management/configuration/internal/src/main/java/org/eclipse/kapua/service/device/management/snapshot/internal/DeviceSnapshotManagementServiceImpl.java index d62f9186212..c5367253524 100644 --- a/service/device/management/configuration/internal/src/main/java/org/eclipse/kapua/service/device/management/snapshot/internal/DeviceSnapshotManagementServiceImpl.java +++ b/service/device/management/configuration/internal/src/main/java/org/eclipse/kapua/service/device/management/snapshot/internal/DeviceSnapshotManagementServiceImpl.java @@ -14,12 +14,9 @@ import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.util.ArgumentValidator; import org.eclipse.kapua.commons.util.xml.XmlUtil; -import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.locator.KapuaProvider; import org.eclipse.kapua.model.domain.Actions; import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.service.authorization.AuthorizationService; -import org.eclipse.kapua.service.authorization.permission.PermissionFactory; import org.eclipse.kapua.service.device.management.DeviceManagementDomains; import org.eclipse.kapua.service.device.management.commons.AbstractDeviceManagementServiceImpl; import org.eclipse.kapua.service.device.management.commons.call.DeviceCallExecutor; @@ -59,10 +56,7 @@ public DeviceSnapshots get(KapuaId scopeId, KapuaId deviceId, Long timeout) // // Check Access - KapuaLocator locator = KapuaLocator.getInstance(); - AuthorizationService authorizationService = locator.getService(AuthorizationService.class); - PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class); - authorizationService.checkPermission(permissionFactory.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.read, scopeId)); + AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.read, scopeId)); // // Prepare the request @@ -130,10 +124,7 @@ public void rollback(KapuaId scopeId, KapuaId deviceId, String snapshotId, Long // // Check Access - KapuaLocator locator = KapuaLocator.getInstance(); - AuthorizationService authorizationService = locator.getService(AuthorizationService.class); - PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class); - authorizationService.checkPermission(permissionFactory.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.execute, scopeId)); + AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.execute, scopeId)); // // Prepare the request diff --git a/service/device/management/packages/api/pom.xml b/service/device/management/packages/api/pom.xml index 598c414fc9f..8b47c6f3934 100644 --- a/service/device/management/packages/api/pom.xml +++ b/service/device/management/packages/api/pom.xml @@ -28,9 +28,17 @@ org.eclipse.kapua kapua-device-api + + org.eclipse.kapua + kapua-device-registry-api + org.eclipse.kapua kapua-device-management-api + + org.eclipse.kapua + kapua-device-management-registry-api + diff --git a/service/device/management/packages/api/src/main/java/org/eclipse/kapua/service/device/management/packages/DevicePackageFactory.java b/service/device/management/packages/api/src/main/java/org/eclipse/kapua/service/device/management/packages/DevicePackageFactory.java index 667cda2c0f8..bdcda4d3b37 100644 --- a/service/device/management/packages/api/src/main/java/org/eclipse/kapua/service/device/management/packages/DevicePackageFactory.java +++ b/service/device/management/packages/api/src/main/java/org/eclipse/kapua/service/device/management/packages/DevicePackageFactory.java @@ -17,42 +17,49 @@ import org.eclipse.kapua.service.device.management.packages.model.DevicePackageBundleInfos; import org.eclipse.kapua.service.device.management.packages.model.DevicePackages; import org.eclipse.kapua.service.device.management.packages.model.download.DevicePackageDownloadOperation; +import org.eclipse.kapua.service.device.management.packages.model.download.DevicePackageDownloadOptions; import org.eclipse.kapua.service.device.management.packages.model.download.DevicePackageDownloadRequest; +import org.eclipse.kapua.service.device.management.packages.model.install.DevicePackageInstallOptions; import org.eclipse.kapua.service.device.management.packages.model.install.DevicePackageInstallRequest; +import org.eclipse.kapua.service.device.management.packages.model.uninstall.DevicePackageUninstallOptions; import org.eclipse.kapua.service.device.management.packages.model.uninstall.DevicePackageUninstallRequest; /** - * Device package service definition. + * {@link DevicePackageFactory} definition. * - * @since 1.0 + * @since 1.0.0 */ public interface DevicePackageFactory extends KapuaObjectFactory { /** * Creates a new {@link DevicePackages} * - * @return + * @return the newly created {@link DevicePackages} + * @since 1.0.0 */ DevicePackages newDeviceDeploymentPackages(); /** * Creates a new {@link DevicePackage} * - * @return + * @return The newly created {@link DevicePackage} + * @since 1.0.0 */ DevicePackage newDeviceDeploymentPackage(); /** - * Creates a new device package bundle information + * Creates a new {@link DevicePackageBundleInfo} * - * @return + * @return the newly created {@link DevicePackageBundleInfo} + * @since 1.0.0 */ DevicePackageBundleInfo newDevicePackageBundleInfo(); /** - * Creates a new device package bundle informations + * Creates a new {@link DevicePackageBundleInfos} * - * @return + * @return the newly created {@link DevicePackageBundleInfos} + * @since 1.0.0 */ DevicePackageBundleInfos newDevicePackageBundleInfos(); @@ -61,16 +68,26 @@ public interface DevicePackageFactory extends KapuaObjectFactory { // /** - * Creates a new device package download request + * Creates a new {@link DevicePackageDownloadRequest} * - * @return + * @return The newly created {@link DevicePackageDownloadRequest} + * @since 1.0.0 */ DevicePackageDownloadRequest newPackageDownloadRequest(); /** - * Creates a new device package download operation + * Creates a new {@link DevicePackageDownloadOptions} * - * @return + * @return the newly created {@link DevicePackageDownloadOptions} + * @since 1.1.0 + */ + DevicePackageDownloadOptions newDevicePackageDownloadOptions(); + + /** + * Creates a new {@link DevicePackageDownloadOperation} + * + * @return the newly created {@link DevicePackageDownloadOperation} + * @since 1.0.0 */ DevicePackageDownloadOperation newPackageDownloadOperation(); @@ -81,18 +98,37 @@ public interface DevicePackageFactory extends KapuaObjectFactory { /** * Creates a new {@link DevicePackageInstallRequest} * - * @return + * @return the newly created {@link DevicePackageInstallRequest} + * @since 1.0.0 */ DevicePackageInstallRequest newPackageInstallRequest(); + /** + * Creates a new {@link DevicePackageInstallOptions} + * + * @return the newly created {@link DevicePackageInstallOptions} + * @since 1.1.0 + */ + DevicePackageInstallOptions newDevicePackageInstallOptions(); + + // // Uninstall operation // /** - * Creates a new device package uninstall request + * Creates a new {@link DevicePackageUninstallRequest} * - * @return + * @return the newly created {@link DevicePackageUninstallRequest} + * @since 1.0.0 */ DevicePackageUninstallRequest newPackageUninstallRequest(); + + /** + * Creates a new {@link DevicePackageUninstallOptions} + * + * @return the newly created {@link DevicePackageUninstallOptions} + * @since 1.1.0 + */ + DevicePackageUninstallOptions newDevicePackageUninstallOptions(); } diff --git a/service/device/management/packages/api/src/main/java/org/eclipse/kapua/service/device/management/packages/DevicePackageManagementService.java b/service/device/management/packages/api/src/main/java/org/eclipse/kapua/service/device/management/packages/DevicePackageManagementService.java index f8f62b43bb1..a30f86be3cb 100644 --- a/service/device/management/packages/api/src/main/java/org/eclipse/kapua/service/device/management/packages/DevicePackageManagementService.java +++ b/service/device/management/packages/api/src/main/java/org/eclipse/kapua/service/device/management/packages/DevicePackageManagementService.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2016 Eurotech and/or its affiliates and others + * Copyright (c) 2016, 2019 Eurotech and/or its affiliates and others * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -16,103 +16,178 @@ import org.eclipse.kapua.service.KapuaService; import org.eclipse.kapua.service.device.management.packages.model.DevicePackages; import org.eclipse.kapua.service.device.management.packages.model.download.DevicePackageDownloadOperation; +import org.eclipse.kapua.service.device.management.packages.model.download.DevicePackageDownloadOptions; import org.eclipse.kapua.service.device.management.packages.model.download.DevicePackageDownloadRequest; import org.eclipse.kapua.service.device.management.packages.model.install.DevicePackageInstallOperation; +import org.eclipse.kapua.service.device.management.packages.model.install.DevicePackageInstallOptions; import org.eclipse.kapua.service.device.management.packages.model.install.DevicePackageInstallRequest; import org.eclipse.kapua.service.device.management.packages.model.uninstall.DevicePackageUninstallOperation; +import org.eclipse.kapua.service.device.management.packages.model.uninstall.DevicePackageUninstallOptions; import org.eclipse.kapua.service.device.management.packages.model.uninstall.DevicePackageUninstallRequest; +import org.eclipse.kapua.service.device.management.registry.operation.DeviceManagementOperation; +import org.eclipse.kapua.service.device.registry.Device; /** - * Device package service definition. + * {@link DevicePackageManagementService} definition. + *

+ * The {@link DevicePackageManagementService} is used to interact with the DEPLOY-V2 {@link org.eclipse.kapua.service.device.registry.Device} application. * - * @since 1.0 + * @since 1.0.0 */ public interface DevicePackageManagementService extends KapuaService { /** - * Get the installed packages list + * Gets the installed {@link DevicePackages}s * - * @param scopeId - * @param deviceId - * @param timeout - * @return - * @throws KapuaException + * @param scopeId The scope {@link KapuaId} of the target {@link Device} + * @param deviceId The {@link KapuaId} of the target {@link Device} + * @param timeout The timeout in milliseconds for the request to complete + * @return The {@link DevicePackages} + * @throws KapuaException if error occurs during processing + * @since 1.0.0 */ DevicePackages getInstalled(KapuaId scopeId, KapuaId deviceId, Long timeout) throws KapuaException; + // + // Download + // + /** - * Starts a download package operation + * Downloads a {@link org.eclipse.kapua.service.device.management.packages.model.DevicePackage} * - * @param scopeId - * @param deviceId - * @param packageDownloadRequest - * @param timeout - * @throws KapuaException + * @param scopeId The scope {@link KapuaId} of the target {@link Device} + * @param deviceId The {@link KapuaId} of the target {@link Device} + * @param packageDownloadRequest The {@link DevicePackageDownloadRequest} for this request + * @param timeout The timeout in milliseconds for the request to complete + * @return the {@link KapuaId} of the {@link DeviceManagementOperation} of this download + * @throws KapuaException if error occurs during processing + * @since 1.0.0 + * @deprecated since 1.1.0. Please make use of {@link #downloadExec(KapuaId, KapuaId, DevicePackageDownloadRequest, DevicePackageDownloadOptions)}. */ - void downloadExec(KapuaId scopeId, KapuaId deviceId, DevicePackageDownloadRequest packageDownloadRequest, Long timeout) throws KapuaException; + @Deprecated + KapuaId downloadExec(KapuaId scopeId, KapuaId deviceId, DevicePackageDownloadRequest packageDownloadRequest, Long timeout) throws KapuaException; /** - * Interrupt a download package operation + * Downloads a {@link org.eclipse.kapua.service.device.management.packages.model.DevicePackage} * - * @param scopeId - * @param deviceId - * @param timeout + * @param scopeId The scope {@link KapuaId} of the target {@link Device} + * @param deviceId The {@link KapuaId} of the target {@link Device} + * @param packageDownloadRequest The {@link DevicePackageDownloadRequest} for this request + * @param packageDownloadOptions The {@link DevicePackageDownloadOptions} for this request + * @return the {@link KapuaId} of the {@link DeviceManagementOperation} of this download + * @throws KapuaException if error occurs during processing + * @since 1.1.0 + */ + KapuaId downloadExec(KapuaId scopeId, KapuaId deviceId, DevicePackageDownloadRequest packageDownloadRequest, DevicePackageDownloadOptions packageDownloadOptions) throws KapuaException; + + /** + * Interrupts a {@link org.eclipse.kapua.service.device.management.packages.model.DevicePackage} download operation + * + * @param scopeId The scope {@link KapuaId} of the target {@link Device} + * @param deviceId The {@link KapuaId} of the target {@link Device} + * @param timeout The timeout in milliseconds for the request to complete * @throws KapuaException + * @since 1.0.0 */ void downloadStop(KapuaId scopeId, KapuaId deviceId, Long timeout) throws KapuaException; /** - * Gets the download package status + * Gets the {@link DevicePackageDownloadOperation} status. * - * @param scopeId - * @param deviceId - * @param timeout - * @return - * @throws KapuaException + * @param scopeId The scope {@link KapuaId} of the target {@link Device} + * @param deviceId The {@link KapuaId} of the target {@link Device} + * @param timeout The timeout in milliseconds for the request to complete + * @return The {@link DevicePackageDownloadOperation} from the {@link Device} + * @throws KapuaException if error occurs during processing + * @since 1.0.0 */ DevicePackageDownloadOperation downloadStatus(KapuaId scopeId, KapuaId deviceId, Long timeout) throws KapuaException; + // + // Install + // + /** - * Installs a package + * Installs a {@link org.eclipse.kapua.service.device.management.packages.model.DevicePackage} * - * @param scopeId - * @param deviceId - * @param packageInstallRequest - * @param timeout - * @throws KapuaException + * @param scopeId The scope {@link KapuaId} of the target {@link Device} + * @param deviceId The {@link KapuaId} of the target {@link Device} + * @param packageInstallRequest The {@link DevicePackageInstallRequest} for this request + * @param timeout The timeout in milliseconds for the request to complete + * @return the {@link KapuaId} of the {@link DeviceManagementOperation} of this install + * @throws KapuaException if error occurs during processing + * @since 1.0.0 + * @deprecated since 1.1.0. Please make use of {@link #installExec(KapuaId, KapuaId, DevicePackageInstallRequest, DevicePackageInstallOptions)}. */ - void installExec(KapuaId scopeId, KapuaId deviceId, DevicePackageInstallRequest packageInstallRequest, Long timeout) throws KapuaException; + @Deprecated + KapuaId installExec(KapuaId scopeId, KapuaId deviceId, DevicePackageInstallRequest packageInstallRequest, Long timeout) throws KapuaException; /** - * Gets the package installation status + * Installs a {@link org.eclipse.kapua.service.device.management.packages.model.DevicePackage} * - * @param scopeId - * @param deviceId - * @param timeout - * @return - * @throws KapuaException + * @param scopeId The scope {@link KapuaId} of the target {@link Device} + * @param deviceId The {@link KapuaId} of the target {@link Device} + * @param packageInstallRequest The {@link DevicePackageInstallRequest} for this request + * @param packageInstallOptions The {@link DevicePackageInstallOptions} for this request + * @return the {@link KapuaId} of the {@link DeviceManagementOperation} of this install + * @throws KapuaException if error occurs during processing + * @since 1.1.0 + */ + KapuaId installExec(KapuaId scopeId, KapuaId deviceId, DevicePackageInstallRequest packageInstallRequest, DevicePackageInstallOptions packageInstallOptions) throws KapuaException; + + /** + * Gets the {@link DevicePackageInstallOperation} status. + * + * @param scopeId The scope {@link KapuaId} of the target {@link Device} + * @param deviceId The {@link KapuaId} of the target {@link Device} + * @param timeout The timeout in milliseconds for the request to complete + * @return The {@link DevicePackageInstallOperation} from the {@link Device}. + * @throws KapuaException if error occurs during processing + * @since 1.0.0 */ DevicePackageInstallOperation installStatus(KapuaId scopeId, KapuaId deviceId, Long timeout) throws KapuaException; + // + // Uninstall + // + /** - * Uninstalls a package + * Uninstalls a {@link org.eclipse.kapua.service.device.management.packages.model.DevicePackage} * - * @param scopeId - * @param deviceId - * @param packageUninstallRequest - * @param timeout - * @throws KapuaException + * @param scopeId The scope {@link KapuaId} of the target {@link Device} + * @param deviceId The {@link KapuaId} of the target {@link Device} + * @param packageUninstallRequest The {@link DevicePackageUninstallRequest} for this request + * @param timeout The timeout in milliseconds for the request to complete + * @return the {@link KapuaId} of the {@link DeviceManagementOperation} of this uninstall + * @throws KapuaException if error occurs during processing + * @since 1.0.0 + * @deprecated since 1.1.0. Please make use of {@link #uninstallExec(KapuaId, KapuaId, DevicePackageUninstallRequest, DevicePackageUninstallOptions)}. */ - void uninstallExec(KapuaId scopeId, KapuaId deviceId, DevicePackageUninstallRequest packageUninstallRequest, Long timeout) throws KapuaException; + @Deprecated + KapuaId uninstallExec(KapuaId scopeId, KapuaId deviceId, DevicePackageUninstallRequest packageUninstallRequest, Long timeout) throws KapuaException; /** - * Gets the package uninstallation status + * Uninstalls a {@link org.eclipse.kapua.service.device.management.packages.model.DevicePackage} * - * @param scopeId - * @param deviceId - * @param timeout - * @return - * @throws KapuaException + * @param scopeId The scope {@link KapuaId} of the target {@link Device} + * @param deviceId The {@link KapuaId} of the target {@link Device} + * @param packageUninstallRequest The {@link DevicePackageUninstallRequest} for this request + * @param packageUninstallOptions The The {@link DevicePackageUninstallOptions} for this request + * @return the {@link KapuaId} of the {@link DeviceManagementOperation} of this uninstall + * @throws KapuaException if error occurs during processing + * @since 1.1.0 + */ + KapuaId uninstallExec(KapuaId scopeId, KapuaId deviceId, DevicePackageUninstallRequest packageUninstallRequest, DevicePackageUninstallOptions packageUninstallOptions) throws KapuaException; + + /** + * Gets the {@link DevicePackageUninstallOperation}. + * + * @param scopeId The scope {@link KapuaId} of the target {@link Device} + * @param deviceId The {@link KapuaId} of the target {@link Device} + * @param timeout The timeout in milliseconds for the request to complete + * @return the {@link DevicePackageUninstallOperation} from the {@link Device} + * @throws KapuaException if error occurs during processing + * @since 1.0.0 */ DevicePackageUninstallOperation uninstallStatus(KapuaId scopeId, KapuaId deviceId, Long timeout) throws KapuaException; } diff --git a/service/device/management/packages/api/src/main/java/org/eclipse/kapua/service/device/management/packages/model/DevicePackageOptions.java b/service/device/management/packages/api/src/main/java/org/eclipse/kapua/service/device/management/packages/model/DevicePackageOptions.java new file mode 100644 index 00000000000..599818ffb49 --- /dev/null +++ b/service/device/management/packages/api/src/main/java/org/eclipse/kapua/service/device/management/packages/model/DevicePackageOptions.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2019 Eurotech and/or its affiliates and others + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eurotech - initial API and implementation + *******************************************************************************/ +package org.eclipse.kapua.service.device.management.packages.model; + +import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.service.device.management.registry.operation.DeviceManagementOperation; + +/** + * {@link DevicePackageOptions} definition. + * + * @since 1.1.0 + */ +public interface DevicePackageOptions { + + /** + * The {@link DeviceManagementOperation} timeout. + * + * @return The {@link DeviceManagementOperation} timeout. + * @since 1.1.0 + */ + Long getTimeout(); + + /** + * Sets the {@link DeviceManagementOperation} timeout. + * + * @param timeout The {@link DeviceManagementOperation} timeout. + * @since 1.1.0 + */ + void setTimeout(Long timeout); + + /** + * Gets the {@link DeviceManagementOperation} forced {@link DeviceManagementOperation#getOperationId()}. + * + * @return The {@link DeviceManagementOperation} forced {@link DeviceManagementOperation#getOperationId()}. + * @since 1.1.0 + */ + KapuaId getForcedOperationId(); + + /** + * The {@link DeviceManagementOperation} forced {@link DeviceManagementOperation#getOperationId()}. + * + * @param forcedOperationId The {@link DeviceManagementOperation} forced {@link DeviceManagementOperation#getOperationId()}. + * @since 1.1.0 + */ + void setForcedOperationId(KapuaId forcedOperationId); +} diff --git a/service/device/management/packages/api/src/main/java/org/eclipse/kapua/service/device/management/packages/model/download/DevicePackageDownloadOptions.java b/service/device/management/packages/api/src/main/java/org/eclipse/kapua/service/device/management/packages/model/download/DevicePackageDownloadOptions.java new file mode 100644 index 00000000000..84b8514043b --- /dev/null +++ b/service/device/management/packages/api/src/main/java/org/eclipse/kapua/service/device/management/packages/model/download/DevicePackageDownloadOptions.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2019 Eurotech and/or its affiliates and others + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eurotech - initial API and implementation + *******************************************************************************/ +package org.eclipse.kapua.service.device.management.packages.model.download; + +import org.eclipse.kapua.service.device.management.packages.model.DevicePackageOptions; + +/** + * {@link DevicePackageDownloadOptions} definition. + * + * @since 1.1.0 + */ +public interface DevicePackageDownloadOptions extends DevicePackageOptions { +} diff --git a/service/device/management/packages/api/src/main/java/org/eclipse/kapua/service/device/management/packages/model/install/DevicePackageInstallOptions.java b/service/device/management/packages/api/src/main/java/org/eclipse/kapua/service/device/management/packages/model/install/DevicePackageInstallOptions.java new file mode 100644 index 00000000000..84cbce7961b --- /dev/null +++ b/service/device/management/packages/api/src/main/java/org/eclipse/kapua/service/device/management/packages/model/install/DevicePackageInstallOptions.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2019 Eurotech and/or its affiliates and others + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eurotech - initial API and implementation + *******************************************************************************/ +package org.eclipse.kapua.service.device.management.packages.model.install; + +import org.eclipse.kapua.service.device.management.packages.model.DevicePackageOptions; + +/** + * {@link DevicePackageInstallOptions} definition. + * + * @since 1.1.0 + */ +public interface DevicePackageInstallOptions extends DevicePackageOptions { +} diff --git a/service/device/management/packages/api/src/main/java/org/eclipse/kapua/service/device/management/packages/model/uninstall/DevicePackageUninstallOptions.java b/service/device/management/packages/api/src/main/java/org/eclipse/kapua/service/device/management/packages/model/uninstall/DevicePackageUninstallOptions.java new file mode 100644 index 00000000000..2986edfa4a8 --- /dev/null +++ b/service/device/management/packages/api/src/main/java/org/eclipse/kapua/service/device/management/packages/model/uninstall/DevicePackageUninstallOptions.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2019 Eurotech and/or its affiliates and others + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eurotech - initial API and implementation + *******************************************************************************/ +package org.eclipse.kapua.service.device.management.packages.model.uninstall; + +import org.eclipse.kapua.service.device.management.packages.model.DevicePackageOptions; + +/** + * {@link DevicePackageUninstallOptions} definition. + * + * @since 1.1.0 + */ +public interface DevicePackageUninstallOptions extends DevicePackageOptions { +} diff --git a/service/device/management/packages/internal/src/main/java/org/eclipse/kapua/service/device/management/packages/internal/DevicePackageFactoryImpl.java b/service/device/management/packages/internal/src/main/java/org/eclipse/kapua/service/device/management/packages/internal/DevicePackageFactoryImpl.java index dec7bfa0c65..0a05ac80f44 100644 --- a/service/device/management/packages/internal/src/main/java/org/eclipse/kapua/service/device/management/packages/internal/DevicePackageFactoryImpl.java +++ b/service/device/management/packages/internal/src/main/java/org/eclipse/kapua/service/device/management/packages/internal/DevicePackageFactoryImpl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2016 Eurotech and/or its affiliates and others + * Copyright (c) 2016, 2019 Eurotech and/or its affiliates and others * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -18,23 +18,28 @@ import org.eclipse.kapua.service.device.management.packages.model.DevicePackageBundleInfos; import org.eclipse.kapua.service.device.management.packages.model.DevicePackages; import org.eclipse.kapua.service.device.management.packages.model.download.DevicePackageDownloadOperation; +import org.eclipse.kapua.service.device.management.packages.model.download.DevicePackageDownloadOptions; import org.eclipse.kapua.service.device.management.packages.model.download.DevicePackageDownloadRequest; import org.eclipse.kapua.service.device.management.packages.model.download.internal.DevicePackageDownloadOperationImpl; +import org.eclipse.kapua.service.device.management.packages.model.download.internal.DevicePackageDownloadOptionsImpl; import org.eclipse.kapua.service.device.management.packages.model.download.internal.DevicePackageDownloadRequestImpl; +import org.eclipse.kapua.service.device.management.packages.model.install.DevicePackageInstallOptions; import org.eclipse.kapua.service.device.management.packages.model.install.DevicePackageInstallRequest; +import org.eclipse.kapua.service.device.management.packages.model.install.internal.DevicePackageInstallOptionsImpl; import org.eclipse.kapua.service.device.management.packages.model.install.internal.DevicePackageInstallRequestImpl; import org.eclipse.kapua.service.device.management.packages.model.internal.DevicePackageBundleInfoImpl; import org.eclipse.kapua.service.device.management.packages.model.internal.DevicePackageBundleInfosImpl; import org.eclipse.kapua.service.device.management.packages.model.internal.DevicePackageImpl; import org.eclipse.kapua.service.device.management.packages.model.internal.DevicePackagesImpl; +import org.eclipse.kapua.service.device.management.packages.model.uninstall.DevicePackageUninstallOptions; import org.eclipse.kapua.service.device.management.packages.model.uninstall.DevicePackageUninstallRequest; +import org.eclipse.kapua.service.device.management.packages.model.uninstall.internal.DevicePackageUninstallOptionsImpl; import org.eclipse.kapua.service.device.management.packages.model.uninstall.internal.DevicePackageUninstallRequestImpl; /** - * Device package service implementation. - * - * @since 1.0 + * {@link DevicePackageFactory} implementation. * + * @since 1.0 */ @KapuaProvider public class DevicePackageFactoryImpl implements DevicePackageFactory { @@ -72,6 +77,11 @@ public DevicePackageDownloadOperation newPackageDownloadOperation() { return new DevicePackageDownloadOperationImpl(); } + @Override + public DevicePackageDownloadOptions newDevicePackageDownloadOptions() { + return new DevicePackageDownloadOptionsImpl(); + } + // // Install operation // @@ -80,6 +90,11 @@ public DevicePackageInstallRequest newPackageInstallRequest() { return new DevicePackageInstallRequestImpl(); } + @Override + public DevicePackageInstallOptions newDevicePackageInstallOptions() { + return new DevicePackageInstallOptionsImpl(); + } + // // Uninstall operation // @@ -88,4 +103,8 @@ public DevicePackageUninstallRequest newPackageUninstallRequest() { return new DevicePackageUninstallRequestImpl(); } + @Override + public DevicePackageUninstallOptions newDevicePackageUninstallOptions() { + return new DevicePackageUninstallOptionsImpl(); + } } diff --git a/service/device/management/packages/internal/src/main/java/org/eclipse/kapua/service/device/management/packages/internal/DevicePackageManagementServiceImpl.java b/service/device/management/packages/internal/src/main/java/org/eclipse/kapua/service/device/management/packages/internal/DevicePackageManagementServiceImpl.java index 76f8f6c5b42..b089b49f663 100644 --- a/service/device/management/packages/internal/src/main/java/org/eclipse/kapua/service/device/management/packages/internal/DevicePackageManagementServiceImpl.java +++ b/service/device/management/packages/internal/src/main/java/org/eclipse/kapua/service/device/management/packages/internal/DevicePackageManagementServiceImpl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2017 Eurotech and/or its affiliates and others + * Copyright (c) 2016, 2019 Eurotech and/or its affiliates and others * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -11,20 +11,15 @@ *******************************************************************************/ package org.eclipse.kapua.service.device.management.packages.internal; -import java.util.Date; - import org.eclipse.kapua.KapuaErrorCodes; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.commons.model.id.IdGenerator; import org.eclipse.kapua.commons.model.id.KapuaEid; import org.eclipse.kapua.commons.util.ArgumentValidator; import org.eclipse.kapua.commons.util.xml.XmlUtil; -import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.locator.KapuaProvider; import org.eclipse.kapua.model.domain.Actions; import org.eclipse.kapua.model.id.KapuaId; -import org.eclipse.kapua.service.authorization.AuthorizationService; -import org.eclipse.kapua.service.authorization.permission.PermissionFactory; import org.eclipse.kapua.service.device.management.DeviceManagementDomains; import org.eclipse.kapua.service.device.management.commons.AbstractDeviceManagementServiceImpl; import org.eclipse.kapua.service.device.management.commons.call.DeviceCallExecutor; @@ -34,6 +29,7 @@ import org.eclipse.kapua.service.device.management.commons.setting.DeviceManagementSettingKey; import org.eclipse.kapua.service.device.management.message.KapuaMethod; import org.eclipse.kapua.service.device.management.message.response.KapuaResponsePayload; +import org.eclipse.kapua.service.device.management.packages.DevicePackageFactory; import org.eclipse.kapua.service.device.management.packages.DevicePackageManagementService; import org.eclipse.kapua.service.device.management.packages.internal.exception.PackageDownloadStatusManagementException; import org.eclipse.kapua.service.device.management.packages.internal.exception.PackageDownloadStopManagementException; @@ -51,31 +47,37 @@ import org.eclipse.kapua.service.device.management.packages.message.internal.PackageResponsePayload; import org.eclipse.kapua.service.device.management.packages.model.DevicePackages; import org.eclipse.kapua.service.device.management.packages.model.download.DevicePackageDownloadOperation; +import org.eclipse.kapua.service.device.management.packages.model.download.DevicePackageDownloadOptions; import org.eclipse.kapua.service.device.management.packages.model.download.DevicePackageDownloadRequest; import org.eclipse.kapua.service.device.management.packages.model.download.internal.DevicePackageDownloadOperationImpl; import org.eclipse.kapua.service.device.management.packages.model.install.DevicePackageInstallOperation; +import org.eclipse.kapua.service.device.management.packages.model.install.DevicePackageInstallOptions; import org.eclipse.kapua.service.device.management.packages.model.install.DevicePackageInstallRequest; import org.eclipse.kapua.service.device.management.packages.model.install.internal.DevicePackageInstallOperationImpl; import org.eclipse.kapua.service.device.management.packages.model.internal.DevicePackagesImpl; import org.eclipse.kapua.service.device.management.packages.model.uninstall.DevicePackageUninstallOperation; +import org.eclipse.kapua.service.device.management.packages.model.uninstall.DevicePackageUninstallOptions; import org.eclipse.kapua.service.device.management.packages.model.uninstall.DevicePackageUninstallRequest; import org.eclipse.kapua.service.device.management.packages.model.uninstall.internal.DevicePackageUninstallOperationImpl; +import java.util.Date; + /** - * Device package service implementation. + * {@link DevicePackageManagementService} implementation. * - * @since 1.0 + * @since 1.0.0 */ @KapuaProvider public class DevicePackageManagementServiceImpl extends AbstractDeviceManagementServiceImpl implements DevicePackageManagementService { + private static final DevicePackageFactory DEVICE_PACKAGE_FACTORY = LOCATOR.getFactory(DevicePackageFactory.class); + // // Installed // @Override - public DevicePackages getInstalled(KapuaId scopeId, KapuaId deviceId, Long timeout) - throws KapuaException { + public DevicePackages getInstalled(KapuaId scopeId, KapuaId deviceId, Long timeout) throws KapuaException { // // Argument Validation ArgumentValidator.notNull(scopeId, "scopeId"); @@ -83,10 +85,7 @@ public DevicePackages getInstalled(KapuaId scopeId, KapuaId deviceId, Long timeo // // Check Access - KapuaLocator locator = KapuaLocator.getInstance(); - AuthorizationService authorizationService = locator.getService(AuthorizationService.class); - PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class); - authorizationService.checkPermission(permissionFactory.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.read, scopeId)); + AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.read, scopeId)); // // Prepare the request @@ -107,8 +106,8 @@ public DevicePackages getInstalled(KapuaId scopeId, KapuaId deviceId, Long timeo // // Do get - DeviceCallExecutor deviceApplicationCall = new DeviceCallExecutor(packageRequestMessage, timeout); - PackageResponseMessage responseMessage = (PackageResponseMessage) deviceApplicationCall.send(); + DeviceCallExecutor deviceApplicationCall = new DeviceCallExecutor<>(packageRequestMessage, timeout); + PackageResponseMessage responseMessage = deviceApplicationCall.send(); // // Create event @@ -150,28 +149,36 @@ public DevicePackages getInstalled(KapuaId scopeId, KapuaId deviceId, Long timeo } // - // Install + // Download // @Override - public void installExec(KapuaId scopeId, KapuaId deviceId, DevicePackageInstallRequest deployInstallRequest, Long timeout) - throws KapuaException { + public KapuaId downloadExec(KapuaId scopeId, KapuaId deviceId, DevicePackageDownloadRequest packageDownloadRequest, Long timeout) throws KapuaException { + DevicePackageDownloadOptions packageDownloadOptions = DEVICE_PACKAGE_FACTORY.newDevicePackageDownloadOptions(); + packageDownloadOptions.setTimeout(timeout); + + return downloadExec(scopeId, deviceId, packageDownloadRequest, packageDownloadOptions); + } + + @Override + public KapuaId downloadExec(KapuaId scopeId, KapuaId deviceId, DevicePackageDownloadRequest packageDownloadRequest, DevicePackageDownloadOptions packageDownloadOptions) throws KapuaException { // // Argument Validation ArgumentValidator.notNull(scopeId, "scopeId"); ArgumentValidator.notNull(deviceId, "deviceId"); - ArgumentValidator.notNull(deployInstallRequest, "deployInstallRequest"); + ArgumentValidator.notNull(packageDownloadRequest, "packageDownloadRequest"); + ArgumentValidator.notNull(packageDownloadRequest.getUri(), "packageDownloadRequest.uri"); + ArgumentValidator.notNull(packageDownloadRequest.getName(), "packageDownloadRequest.name"); + ArgumentValidator.notNull(packageDownloadRequest.getVersion(), "packageDownloadRequest.version"); + ArgumentValidator.notNull(packageDownloadOptions, "packageDownloadOptions"); // // Check Access - KapuaLocator locator = KapuaLocator.getInstance(); - AuthorizationService authorizationService = locator.getService(AuthorizationService.class); - PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class); - authorizationService.checkPermission(permissionFactory.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.write, scopeId)); + AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.write, scopeId)); // // Generate requestId - KapuaId operationId = new KapuaEid(IdGenerator.generate()); + KapuaId operationId = packageDownloadOptions.getForcedOperationId() != null ? packageDownloadOptions.getForcedOperationId() : new KapuaEid(IdGenerator.generate()); // // Prepare the request @@ -179,14 +186,16 @@ public void installExec(KapuaId scopeId, KapuaId deviceId, DevicePackageInstallR packageRequestChannel.setAppName(PackageAppProperties.APP_NAME); packageRequestChannel.setVersion(PackageAppProperties.APP_VERSION); packageRequestChannel.setMethod(KapuaMethod.EXECUTE); - packageRequestChannel.setPackageResource(PackageResource.INSTALL); + packageRequestChannel.setPackageResource(PackageResource.DOWNLOAD); PackageRequestPayload packageRequestPayload = new PackageRequestPayload(); packageRequestPayload.setOperationId(operationId); - packageRequestPayload.setPackageDownloadName(deployInstallRequest.getName()); - packageRequestPayload.setPackageDownloadVersion(deployInstallRequest.getVersion()); - packageRequestPayload.setReboot(deployInstallRequest.isReboot()); - packageRequestPayload.setRebootDelay(deployInstallRequest.getRebootDelay()); + packageRequestPayload.setPackageDownloadURI(packageDownloadRequest.getUri()); + packageRequestPayload.setPackageDownloadName(packageDownloadRequest.getName()); + packageRequestPayload.setPackageDownloadVersion(packageDownloadRequest.getVersion()); + packageRequestPayload.setPackageDownloadnstall(packageDownloadRequest.getInstall()); + packageRequestPayload.setReboot(packageDownloadRequest.getReboot()); + packageRequestPayload.setRebootDelay(packageDownloadRequest.getRebootDelay()); PackageRequestMessage packageRequestMessage = new PackageRequestMessage(); packageRequestMessage.setScopeId(scopeId); @@ -197,12 +206,12 @@ public void installExec(KapuaId scopeId, KapuaId deviceId, DevicePackageInstallR // // Create device management operation - createManagementOperation(scopeId, deviceId, operationId, 1, packageRequestMessage); + KapuaId deviceManagementOperationId = createManagementOperation(scopeId, deviceId, operationId, packageDownloadRequest.getInstall() ? 2 : 1, packageRequestMessage); // - // Do get - DeviceCallExecutor deviceApplicationCall = new DeviceCallExecutor(packageRequestMessage, timeout); - PackageResponseMessage responseMessage = (PackageResponseMessage) deviceApplicationCall.send(); + // Do exec + DeviceCallExecutor deviceApplicationCall = new DeviceCallExecutor<>(packageRequestMessage, packageDownloadOptions.getTimeout()); + PackageResponseMessage responseMessage = deviceApplicationCall.send(); // // Create event @@ -213,13 +222,16 @@ public void installExec(KapuaId scopeId, KapuaId deviceId, DevicePackageInstallR if (!responseMessage.getResponseCode().isAccepted()) { KapuaResponsePayload responsePayload = responseMessage.getPayload(); - throw new PackageInstallExecuteManagementException(responseMessage.getResponseCode(), responsePayload.getExceptionMessage(), responsePayload.getExceptionStack()); + closeManagementOperation(scopeId, deviceId, operationId, responseMessage); + + throw new KapuaException(KapuaErrorCodes.DOWNLOAD_PACKAGE_EXCEPTION); } + + return deviceManagementOperationId; } @Override - public DevicePackageInstallOperation installStatus(KapuaId scopeId, KapuaId deviceId, Long timeout) - throws KapuaException { + public DevicePackageDownloadOperation downloadStatus(KapuaId scopeId, KapuaId deviceId, Long timeout) throws KapuaException { // // Argument Validation ArgumentValidator.notNull(scopeId, "scopeId"); @@ -227,10 +239,7 @@ public DevicePackageInstallOperation installStatus(KapuaId scopeId, KapuaId devi // // Check Access - KapuaLocator locator = KapuaLocator.getInstance(); - AuthorizationService authorizationService = locator.getService(AuthorizationService.class); - PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class); - authorizationService.checkPermission(permissionFactory.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.read, scopeId)); + AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.read, scopeId)); // // Prepare the request @@ -238,7 +247,7 @@ public DevicePackageInstallOperation installStatus(KapuaId scopeId, KapuaId devi packageRequestChannel.setAppName(PackageAppProperties.APP_NAME); packageRequestChannel.setVersion(PackageAppProperties.APP_VERSION); packageRequestChannel.setMethod(KapuaMethod.READ); - packageRequestChannel.setPackageResource(PackageResource.INSTALL); + packageRequestChannel.setPackageResource(PackageResource.DOWNLOAD); PackageRequestPayload packageRequestPayload = new PackageRequestPayload(); @@ -251,8 +260,8 @@ public DevicePackageInstallOperation installStatus(KapuaId scopeId, KapuaId devi // // Do get - DeviceCallExecutor deviceApplicationCall = new DeviceCallExecutor(packageRequestMessage, timeout); - PackageResponseMessage responseMessage = (PackageResponseMessage) deviceApplicationCall.send(); + DeviceCallExecutor deviceApplicationCall = new DeviceCallExecutor<>(packageRequestMessage, timeout); + PackageResponseMessage responseMessage = deviceApplicationCall.send(); // // Create event @@ -263,76 +272,40 @@ public DevicePackageInstallOperation installStatus(KapuaId scopeId, KapuaId devi if (responseMessage.getResponseCode().isAccepted()) { PackageResponsePayload responsePayload = responseMessage.getPayload(); - DeviceManagementSetting config = DeviceManagementSetting.getInstance(); - String charEncoding = config.getString(DeviceManagementSettingKey.CHAR_ENCODING); - - String body = null; - try { - body = new String(responsePayload.getBody(), charEncoding); - } catch (Exception e) { - throw new DeviceManagementException(DeviceManagementErrorCodes.RESPONSE_PARSE_EXCEPTION, e, responsePayload.getBody()); - - } - - DevicePackageInstallOperation installOperation = null; - try { - installOperation = XmlUtil.unmarshal(body, DevicePackageInstallOperationImpl.class); - } catch (Exception e) { - throw new DeviceManagementException(DeviceManagementErrorCodes.RESPONSE_PARSE_EXCEPTION, e, body); - - } + DevicePackageDownloadOperation downloadOperation = new DevicePackageDownloadOperationImpl(); + downloadOperation.setId(responsePayload.getPackageDownloadOperationId()); + downloadOperation.setStatus(responsePayload.getPackageDownloadOperationStatus()); + downloadOperation.setSize(responsePayload.getPackageDownloadOperationSize()); + downloadOperation.setProgress(responsePayload.getPackageDownloadOperationProgress()); - return installOperation; + return downloadOperation; } else { KapuaResponsePayload responsePayload = responseMessage.getPayload(); - throw new PackageInstallStatusManagementException(responseMessage.getResponseCode(), responsePayload.getExceptionMessage(), responsePayload.getExceptionStack()); + throw new PackageDownloadStatusManagementException(responseMessage.getResponseCode(), responsePayload.getExceptionMessage(), responsePayload.getExceptionStack()); } } - // - // Download - // - @Override - public void downloadExec(KapuaId scopeId, KapuaId deviceId, DevicePackageDownloadRequest packageDownloadRequest, Long timeout) - throws KapuaException { + public void downloadStop(KapuaId scopeId, KapuaId deviceId, Long timeout) throws KapuaException { // // Argument Validation ArgumentValidator.notNull(scopeId, "scopeId"); ArgumentValidator.notNull(deviceId, "deviceId"); - ArgumentValidator.notNull(packageDownloadRequest, "packageDownloadRequest"); - ArgumentValidator.notNull(packageDownloadRequest.getUri(), "packageDownloadRequest.uri"); - ArgumentValidator.notNull(packageDownloadRequest.getName(), "packageDownloadRequest.name"); - ArgumentValidator.notNull(packageDownloadRequest.getVersion(), "packageDownloadRequest.version"); // // Check Access - KapuaLocator locator = KapuaLocator.getInstance(); - AuthorizationService authorizationService = locator.getService(AuthorizationService.class); - PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class); - authorizationService.checkPermission(permissionFactory.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.write, scopeId)); - - // - // Generate requestId - KapuaId operationId = new KapuaEid(IdGenerator.generate()); + AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.write, scopeId)); // // Prepare the request PackageRequestChannel packageRequestChannel = new PackageRequestChannel(); packageRequestChannel.setAppName(PackageAppProperties.APP_NAME); packageRequestChannel.setVersion(PackageAppProperties.APP_VERSION); - packageRequestChannel.setMethod(KapuaMethod.EXECUTE); + packageRequestChannel.setMethod(KapuaMethod.DELETE); packageRequestChannel.setPackageResource(PackageResource.DOWNLOAD); PackageRequestPayload packageRequestPayload = new PackageRequestPayload(); - packageRequestPayload.setOperationId(operationId); - packageRequestPayload.setPackageDownloadURI(packageDownloadRequest.getUri()); - packageRequestPayload.setPackageDownloadName(packageDownloadRequest.getName()); - packageRequestPayload.setPackageDownloadVersion(packageDownloadRequest.getVersion()); - packageRequestPayload.setPackageDownloadnstall(packageDownloadRequest.getInstall()); - packageRequestPayload.setReboot(packageDownloadRequest.getReboot()); - packageRequestPayload.setRebootDelay(packageDownloadRequest.getRebootDelay()); PackageRequestMessage packageRequestMessage = new PackageRequestMessage(); packageRequestMessage.setScopeId(scopeId); @@ -342,13 +315,9 @@ public void downloadExec(KapuaId scopeId, KapuaId deviceId, DevicePackageDownloa packageRequestMessage.setChannel(packageRequestChannel); // - // Create device management operation - createManagementOperation(scopeId, deviceId, operationId, packageDownloadRequest.getInstall() ? 2 : 1, packageRequestMessage); - - // - // Do exec - DeviceCallExecutor deviceApplicationCall = new DeviceCallExecutor(packageRequestMessage, timeout); - PackageResponseMessage responseMessage = (PackageResponseMessage) deviceApplicationCall.send(); + // Do del + DeviceCallExecutor deviceApplicationCall = new DeviceCallExecutor<>(packageRequestMessage, timeout); + PackageResponseMessage responseMessage = deviceApplicationCall.send(); // // Create event @@ -359,35 +328,53 @@ public void downloadExec(KapuaId scopeId, KapuaId deviceId, DevicePackageDownloa if (!responseMessage.getResponseCode().isAccepted()) { KapuaResponsePayload responsePayload = responseMessage.getPayload(); - closeManagementOperation(scopeId, deviceId, operationId, responseMessage); - throw new KapuaException(KapuaErrorCodes.DOWNLOAD_PACKAGE_EXCEPTION); + throw new PackageDownloadStopManagementException(responseMessage.getResponseCode(), responsePayload.getExceptionMessage(), responsePayload.getExceptionStack()); } } + // + // Install + // + + @Override + public KapuaId installExec(KapuaId scopeId, KapuaId deviceId, DevicePackageInstallRequest packageInstallRequest, Long timeout) throws KapuaException { + DevicePackageInstallOptions packageInstallOptions = DEVICE_PACKAGE_FACTORY.newDevicePackageInstallOptions(); + packageInstallOptions.setTimeout(timeout); + + return installExec(scopeId, deviceId, packageInstallRequest, packageInstallOptions); + } + @Override - public DevicePackageDownloadOperation downloadStatus(KapuaId scopeId, KapuaId deviceId, Long timeout) - throws KapuaException { + public KapuaId installExec(KapuaId scopeId, KapuaId deviceId, DevicePackageInstallRequest deployInstallRequest, DevicePackageInstallOptions packageInstallOptions) throws KapuaException { // // Argument Validation ArgumentValidator.notNull(scopeId, "scopeId"); ArgumentValidator.notNull(deviceId, "deviceId"); + ArgumentValidator.notNull(deployInstallRequest, "deployInstallRequest"); + ArgumentValidator.notNull(packageInstallOptions, "packageInstallOptions"); // // Check Access - KapuaLocator locator = KapuaLocator.getInstance(); - AuthorizationService authorizationService = locator.getService(AuthorizationService.class); - PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class); - authorizationService.checkPermission(permissionFactory.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.read, scopeId)); + AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.write, scopeId)); + + // + // Generate requestId + KapuaId operationId = packageInstallOptions.getForcedOperationId() != null ? packageInstallOptions.getForcedOperationId() : new KapuaEid(IdGenerator.generate()); // // Prepare the request PackageRequestChannel packageRequestChannel = new PackageRequestChannel(); packageRequestChannel.setAppName(PackageAppProperties.APP_NAME); packageRequestChannel.setVersion(PackageAppProperties.APP_VERSION); - packageRequestChannel.setMethod(KapuaMethod.READ); - packageRequestChannel.setPackageResource(PackageResource.DOWNLOAD); + packageRequestChannel.setMethod(KapuaMethod.EXECUTE); + packageRequestChannel.setPackageResource(PackageResource.INSTALL); PackageRequestPayload packageRequestPayload = new PackageRequestPayload(); + packageRequestPayload.setOperationId(operationId); + packageRequestPayload.setPackageDownloadName(deployInstallRequest.getName()); + packageRequestPayload.setPackageDownloadVersion(deployInstallRequest.getVersion()); + packageRequestPayload.setReboot(deployInstallRequest.isReboot()); + packageRequestPayload.setRebootDelay(deployInstallRequest.getRebootDelay()); PackageRequestMessage packageRequestMessage = new PackageRequestMessage(); packageRequestMessage.setScopeId(scopeId); @@ -396,10 +383,14 @@ public DevicePackageDownloadOperation downloadStatus(KapuaId scopeId, KapuaId de packageRequestMessage.setPayload(packageRequestPayload); packageRequestMessage.setChannel(packageRequestChannel); + // + // Create device management operation + KapuaId deviceManagementOperationId = createManagementOperation(scopeId, deviceId, operationId, 1, packageRequestMessage); + // // Do get - DeviceCallExecutor deviceApplicationCall = new DeviceCallExecutor(packageRequestMessage, timeout); - PackageResponseMessage responseMessage = (PackageResponseMessage) deviceApplicationCall.send(); + DeviceCallExecutor deviceApplicationCall = new DeviceCallExecutor<>(packageRequestMessage, packageInstallOptions.getTimeout()); + PackageResponseMessage responseMessage = deviceApplicationCall.send(); // // Create event @@ -407,26 +398,19 @@ public DevicePackageDownloadOperation downloadStatus(KapuaId scopeId, KapuaId de // // Check response - if (responseMessage.getResponseCode().isAccepted()) { - PackageResponsePayload responsePayload = responseMessage.getPayload(); - - DevicePackageDownloadOperation downloadOperation = new DevicePackageDownloadOperationImpl(); - downloadOperation.setId(responsePayload.getPackageDownloadOperationId()); - downloadOperation.setStatus(responsePayload.getPackageDownloadOperationStatus()); - downloadOperation.setSize(responsePayload.getPackageDownloadOperationSize()); - downloadOperation.setProgress(responsePayload.getPackageDownloadOperationProgress()); - - return downloadOperation; - } else { + if (!responseMessage.getResponseCode().isAccepted()) { KapuaResponsePayload responsePayload = responseMessage.getPayload(); - throw new PackageDownloadStatusManagementException(responseMessage.getResponseCode(), responsePayload.getExceptionMessage(), responsePayload.getExceptionStack()); + closeManagementOperation(scopeId, deviceId, operationId, responseMessage); + + throw new PackageInstallExecuteManagementException(responseMessage.getResponseCode(), responsePayload.getExceptionMessage(), responsePayload.getExceptionStack()); } + + return deviceManagementOperationId; } @Override - public void downloadStop(KapuaId scopeId, KapuaId deviceId, Long timeout) - throws KapuaException { + public DevicePackageInstallOperation installStatus(KapuaId scopeId, KapuaId deviceId, Long timeout) throws KapuaException { // // Argument Validation ArgumentValidator.notNull(scopeId, "scopeId"); @@ -434,18 +418,15 @@ public void downloadStop(KapuaId scopeId, KapuaId deviceId, Long timeout) // // Check Access - KapuaLocator locator = KapuaLocator.getInstance(); - AuthorizationService authorizationService = locator.getService(AuthorizationService.class); - PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class); - authorizationService.checkPermission(permissionFactory.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.write, scopeId)); + AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.read, scopeId)); // // Prepare the request PackageRequestChannel packageRequestChannel = new PackageRequestChannel(); packageRequestChannel.setAppName(PackageAppProperties.APP_NAME); packageRequestChannel.setVersion(PackageAppProperties.APP_VERSION); - packageRequestChannel.setMethod(KapuaMethod.DELETE); - packageRequestChannel.setPackageResource(PackageResource.DOWNLOAD); + packageRequestChannel.setMethod(KapuaMethod.READ); + packageRequestChannel.setPackageResource(PackageResource.INSTALL); PackageRequestPayload packageRequestPayload = new PackageRequestPayload(); @@ -457,9 +438,9 @@ public void downloadStop(KapuaId scopeId, KapuaId deviceId, Long timeout) packageRequestMessage.setChannel(packageRequestChannel); // - // Do del - DeviceCallExecutor deviceApplicationCall = new DeviceCallExecutor(packageRequestMessage, timeout); - PackageResponseMessage responseMessage = (PackageResponseMessage) deviceApplicationCall.send(); + // Do get + DeviceCallExecutor deviceApplicationCall = new DeviceCallExecutor<>(packageRequestMessage, timeout); + PackageResponseMessage responseMessage = deviceApplicationCall.send(); // // Create event @@ -467,10 +448,33 @@ public void downloadStop(KapuaId scopeId, KapuaId deviceId, Long timeout) // // Check response - if (!responseMessage.getResponseCode().isAccepted()) { + if (responseMessage.getResponseCode().isAccepted()) { + PackageResponsePayload responsePayload = responseMessage.getPayload(); + + DeviceManagementSetting config = DeviceManagementSetting.getInstance(); + String charEncoding = config.getString(DeviceManagementSettingKey.CHAR_ENCODING); + + String body = null; + try { + body = new String(responsePayload.getBody(), charEncoding); + } catch (Exception e) { + throw new DeviceManagementException(DeviceManagementErrorCodes.RESPONSE_PARSE_EXCEPTION, e, responsePayload.getBody()); + + } + + DevicePackageInstallOperation installOperation = null; + try { + installOperation = XmlUtil.unmarshal(body, DevicePackageInstallOperationImpl.class); + } catch (Exception e) { + throw new DeviceManagementException(DeviceManagementErrorCodes.RESPONSE_PARSE_EXCEPTION, e, body); + + } + + return installOperation; + } else { KapuaResponsePayload responsePayload = responseMessage.getPayload(); - throw new PackageDownloadStopManagementException(responseMessage.getResponseCode(), responsePayload.getExceptionMessage(), responsePayload.getExceptionStack()); + throw new PackageInstallStatusManagementException(responseMessage.getResponseCode(), responsePayload.getExceptionMessage(), responsePayload.getExceptionStack()); } } @@ -479,23 +483,29 @@ public void downloadStop(KapuaId scopeId, KapuaId deviceId, Long timeout) // @Override - public void uninstallExec(KapuaId scopeId, KapuaId deviceId, DevicePackageUninstallRequest deployUninstallRequest, Long timeout) throws KapuaException { + public KapuaId uninstallExec(KapuaId scopeId, KapuaId deviceId, DevicePackageUninstallRequest packageUninstallRequest, Long timeout) throws KapuaException { + DevicePackageUninstallOptions packageUninstallOptions = DEVICE_PACKAGE_FACTORY.newDevicePackageUninstallOptions(); + packageUninstallOptions.setTimeout(timeout); + + return uninstallExec(scopeId, deviceId, packageUninstallRequest, packageUninstallOptions); + } + + @Override + public KapuaId uninstallExec(KapuaId scopeId, KapuaId deviceId, DevicePackageUninstallRequest packageUninstallRequest, DevicePackageUninstallOptions packageUninstallOptions) throws KapuaException { // // Argument Validation ArgumentValidator.notNull(scopeId, "scopeId"); ArgumentValidator.notNull(deviceId, "deviceId"); - ArgumentValidator.notNull(deployUninstallRequest, "deployUninstallRequest"); + ArgumentValidator.notNull(packageUninstallRequest, "packageUninstallRequest"); + ArgumentValidator.notNull(packageUninstallOptions, "packageUninstallOptions"); // // Check Access - KapuaLocator locator = KapuaLocator.getInstance(); - AuthorizationService authorizationService = locator.getService(AuthorizationService.class); - PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class); - authorizationService.checkPermission(permissionFactory.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.write, scopeId)); + AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.write, scopeId)); // // Generate requestId - KapuaId operationId = new KapuaEid(IdGenerator.generate()); + KapuaId operationId = packageUninstallOptions.getForcedOperationId() != null ? packageUninstallOptions.getForcedOperationId() : new KapuaEid(IdGenerator.generate()); // // Prepare the request @@ -507,10 +517,10 @@ public void uninstallExec(KapuaId scopeId, KapuaId deviceId, DevicePackageUninst PackageRequestPayload packageRequestPayload = new PackageRequestPayload(); packageRequestPayload.setOperationId(operationId); - packageRequestPayload.setPackageUninstallName(deployUninstallRequest.getName()); - packageRequestPayload.setPackageUninstallVersion(deployUninstallRequest.getVersion()); - packageRequestPayload.setReboot(deployUninstallRequest.isReboot()); - packageRequestPayload.setRebootDelay(deployUninstallRequest.getRebootDelay()); + packageRequestPayload.setPackageUninstallName(packageUninstallRequest.getName()); + packageRequestPayload.setPackageUninstallVersion(packageUninstallRequest.getVersion()); + packageRequestPayload.setReboot(packageUninstallRequest.isReboot()); + packageRequestPayload.setRebootDelay(packageUninstallRequest.getRebootDelay()); PackageRequestMessage packageRequestMessage = new PackageRequestMessage(); packageRequestMessage.setScopeId(scopeId); @@ -521,12 +531,12 @@ public void uninstallExec(KapuaId scopeId, KapuaId deviceId, DevicePackageUninst // // Create device management operation - createManagementOperation(scopeId, deviceId, operationId, 1, packageRequestMessage); + KapuaId deviceManagementOperationId = createManagementOperation(scopeId, deviceId, operationId, 1, packageRequestMessage); // // Do get - DeviceCallExecutor deviceApplicationCall = new DeviceCallExecutor(packageRequestMessage, timeout); - PackageResponseMessage responseMessage = (PackageResponseMessage) deviceApplicationCall.send(); + DeviceCallExecutor deviceApplicationCall = new DeviceCallExecutor<>(packageRequestMessage, packageUninstallOptions.getTimeout()); + PackageResponseMessage responseMessage = deviceApplicationCall.send(); // // Create event @@ -541,11 +551,12 @@ public void uninstallExec(KapuaId scopeId, KapuaId deviceId, DevicePackageUninst throw new PackageUninstallExecuteManagementException(responseMessage.getResponseCode(), responsePayload.getExceptionMessage(), responsePayload.getExceptionStack()); } + + return deviceManagementOperationId; } @Override - public DevicePackageUninstallOperation uninstallStatus(KapuaId scopeId, KapuaId deviceId, Long timeout) - throws KapuaException { + public DevicePackageUninstallOperation uninstallStatus(KapuaId scopeId, KapuaId deviceId, Long timeout) throws KapuaException { // // Argument Validation ArgumentValidator.notNull(scopeId, "scopeId"); @@ -553,10 +564,7 @@ public DevicePackageUninstallOperation uninstallStatus(KapuaId scopeId, KapuaId // // Check Access - KapuaLocator locator = KapuaLocator.getInstance(); - AuthorizationService authorizationService = locator.getService(AuthorizationService.class); - PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class); - authorizationService.checkPermission(permissionFactory.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.read, scopeId)); + AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.read, scopeId)); // // Prepare the request @@ -564,7 +572,7 @@ public DevicePackageUninstallOperation uninstallStatus(KapuaId scopeId, KapuaId packageRequestChannel.setAppName(PackageAppProperties.APP_NAME); packageRequestChannel.setVersion(PackageAppProperties.APP_VERSION); packageRequestChannel.setMethod(KapuaMethod.READ); - packageRequestChannel.setPackageResource(PackageResource.INSTALL); + packageRequestChannel.setPackageResource(PackageResource.UNINSTALL); PackageRequestPayload packageRequestPayload = new PackageRequestPayload(); @@ -577,8 +585,8 @@ public DevicePackageUninstallOperation uninstallStatus(KapuaId scopeId, KapuaId // // Do get - DeviceCallExecutor deviceApplicationCall = new DeviceCallExecutor(packageRequestMessage, timeout); - PackageResponseMessage responseMessage = (PackageResponseMessage) deviceApplicationCall.send(); + DeviceCallExecutor deviceApplicationCall = new DeviceCallExecutor<>(packageRequestMessage, timeout); + PackageResponseMessage responseMessage = deviceApplicationCall.send(); // // Create event diff --git a/service/device/management/packages/internal/src/main/java/org/eclipse/kapua/service/device/management/packages/model/download/internal/DevicePackageDownloadOptionsImpl.java b/service/device/management/packages/internal/src/main/java/org/eclipse/kapua/service/device/management/packages/model/download/internal/DevicePackageDownloadOptionsImpl.java new file mode 100644 index 00000000000..20757f9a280 --- /dev/null +++ b/service/device/management/packages/internal/src/main/java/org/eclipse/kapua/service/device/management/packages/model/download/internal/DevicePackageDownloadOptionsImpl.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2019 Eurotech and/or its affiliates and others + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eurotech - initial API and implementation + *******************************************************************************/ +package org.eclipse.kapua.service.device.management.packages.model.download.internal; + +import org.eclipse.kapua.service.device.management.packages.model.download.DevicePackageDownloadOptions; +import org.eclipse.kapua.service.device.management.packages.model.internal.DevicePackageOptionsImpl; + +/** + * {@link DevicePackageDownloadOptions} implementation. + * + * @since 1.1.0 + */ +public class DevicePackageDownloadOptionsImpl extends DevicePackageOptionsImpl implements DevicePackageDownloadOptions { +} diff --git a/service/device/management/packages/internal/src/main/java/org/eclipse/kapua/service/device/management/packages/model/install/internal/DevicePackageInstallOptionsImpl.java b/service/device/management/packages/internal/src/main/java/org/eclipse/kapua/service/device/management/packages/model/install/internal/DevicePackageInstallOptionsImpl.java new file mode 100644 index 00000000000..f4bae076053 --- /dev/null +++ b/service/device/management/packages/internal/src/main/java/org/eclipse/kapua/service/device/management/packages/model/install/internal/DevicePackageInstallOptionsImpl.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2019 Eurotech and/or its affiliates and others + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eurotech - initial API and implementation + *******************************************************************************/ +package org.eclipse.kapua.service.device.management.packages.model.install.internal; + +import org.eclipse.kapua.service.device.management.packages.model.install.DevicePackageInstallOptions; +import org.eclipse.kapua.service.device.management.packages.model.internal.DevicePackageOptionsImpl; + +/** + * {@link DevicePackageInstallOptions} implementation + * + * @since 1.1.0 + */ +public class DevicePackageInstallOptionsImpl extends DevicePackageOptionsImpl implements DevicePackageInstallOptions { +} diff --git a/service/device/management/packages/internal/src/main/java/org/eclipse/kapua/service/device/management/packages/model/internal/DevicePackageOptionsImpl.java b/service/device/management/packages/internal/src/main/java/org/eclipse/kapua/service/device/management/packages/model/internal/DevicePackageOptionsImpl.java new file mode 100644 index 00000000000..ee801088eda --- /dev/null +++ b/service/device/management/packages/internal/src/main/java/org/eclipse/kapua/service/device/management/packages/model/internal/DevicePackageOptionsImpl.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2019 Eurotech and/or its affiliates and others + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eurotech - initial API and implementation + *******************************************************************************/ +package org.eclipse.kapua.service.device.management.packages.model.internal; + +import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.service.device.management.packages.model.DevicePackageOptions; + +/** + * {@link DevicePackageOptions} {@code abstract} implementation. + * + * @since 1.1.0 + */ +public abstract class DevicePackageOptionsImpl implements DevicePackageOptions { + + private Long timeout; + private KapuaId forcedOperationId; + + @Override + public Long getTimeout() { + return timeout; + } + + @Override + public void setTimeout(Long timeout) { + this.timeout = timeout; + } + + @Override + public KapuaId getForcedOperationId() { + return forcedOperationId; + } + + @Override + public void setForcedOperationId(KapuaId forcedOperationId) { + this.forcedOperationId = forcedOperationId; + } +} diff --git a/service/device/management/packages/internal/src/main/java/org/eclipse/kapua/service/device/management/packages/model/uninstall/internal/DevicePackageUninstallOptionsImpl.java b/service/device/management/packages/internal/src/main/java/org/eclipse/kapua/service/device/management/packages/model/uninstall/internal/DevicePackageUninstallOptionsImpl.java new file mode 100644 index 00000000000..2432b38030a --- /dev/null +++ b/service/device/management/packages/internal/src/main/java/org/eclipse/kapua/service/device/management/packages/model/uninstall/internal/DevicePackageUninstallOptionsImpl.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2019 Eurotech and/or its affiliates and others + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Eurotech - initial API and implementation + *******************************************************************************/ +package org.eclipse.kapua.service.device.management.packages.model.uninstall.internal; + +import org.eclipse.kapua.service.device.management.packages.model.internal.DevicePackageOptionsImpl; +import org.eclipse.kapua.service.device.management.packages.model.uninstall.DevicePackageUninstallOptions; + +/** + * {@link DevicePackageUninstallOptions} implementation. + * + * @since 1.1.0 + */ +public class DevicePackageUninstallOptionsImpl extends DevicePackageOptionsImpl implements DevicePackageUninstallOptions { +} diff --git a/service/device/management/request/api/src/main/java/org/eclipse/kapua/service/device/management/request/DeviceRequestManagementService.java b/service/device/management/request/api/src/main/java/org/eclipse/kapua/service/device/management/request/DeviceRequestManagementService.java index b833b852434..2a71eb21699 100644 --- a/service/device/management/request/api/src/main/java/org/eclipse/kapua/service/device/management/request/DeviceRequestManagementService.java +++ b/service/device/management/request/api/src/main/java/org/eclipse/kapua/service/device/management/request/DeviceRequestManagementService.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2017 Eurotech and/or its affiliates and others + * Copyright (c) 2017, 2019 Eurotech and/or its affiliates and others * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -12,6 +12,7 @@ package org.eclipse.kapua.service.device.management.request; import org.eclipse.kapua.KapuaException; +import org.eclipse.kapua.model.id.KapuaId; import org.eclipse.kapua.service.KapuaService; import org.eclipse.kapua.service.device.management.request.message.request.GenericRequestMessage; import org.eclipse.kapua.service.device.management.request.message.response.GenericResponseMessage; @@ -21,10 +22,26 @@ public interface DeviceRequestManagementService extends KapuaService { /** * Execute the given device request with the provided options * - * @param requestInput request input - * @param timeout request timeout - * @return response output - * @throws KapuaException + * @param requestInput The {@link GenericRequestMessage} for this request + * @param timeout The timeout in milliseconds for the request to complete + * @return the response from the device. + * @throws KapuaException if error occurs during processing + * @since 1.0.0 + * @deprecated since 1.1.0. Please make use of {@link #exec(KapuaId, KapuaId, GenericRequestMessage, Long)}. */ + @Deprecated GenericResponseMessage exec(GenericRequestMessage requestInput, Long timeout) throws KapuaException; + + /** + * Execute the given device request with the provided options + * + * @param scopeId The scope {@link KapuaId} of the target device + * @param deviceId The device {@link KapuaId} of the target device + * @param requestInput The {@link GenericRequestMessage} for this request + * @param timeout The timeout in milliseconds for the request to complete + * @return the response from the device + * @throws KapuaException if error occurs during processing + * @since 1.1.0 + */ + GenericResponseMessage exec(KapuaId scopeId, KapuaId deviceId, GenericRequestMessage requestInput, Long timeout) throws KapuaException; } diff --git a/service/device/management/request/internal/src/main/java/org/eclipse/kapua/service/device/management/request/internal/DeviceRequestManagementServiceImpl.java b/service/device/management/request/internal/src/main/java/org/eclipse/kapua/service/device/management/request/internal/DeviceRequestManagementServiceImpl.java index 9cdbf15c720..d34584b79a0 100644 --- a/service/device/management/request/internal/src/main/java/org/eclipse/kapua/service/device/management/request/internal/DeviceRequestManagementServiceImpl.java +++ b/service/device/management/request/internal/src/main/java/org/eclipse/kapua/service/device/management/request/internal/DeviceRequestManagementServiceImpl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2017 Eurotech and/or its affiliates and others + * Copyright (c) 2017, 2019 Eurotech and/or its affiliates and others * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -15,14 +15,13 @@ import org.eclipse.kapua.KapuaErrorCodes; import org.eclipse.kapua.KapuaException; import org.eclipse.kapua.KapuaRuntimeException; -import org.eclipse.kapua.commons.security.KapuaSecurityUtils; import org.eclipse.kapua.commons.util.ArgumentValidator; import org.eclipse.kapua.locator.KapuaLocator; import org.eclipse.kapua.locator.KapuaProvider; import org.eclipse.kapua.model.domain.Actions; -import org.eclipse.kapua.service.authorization.AuthorizationService; -import org.eclipse.kapua.service.authorization.permission.PermissionFactory; +import org.eclipse.kapua.model.id.KapuaId; import org.eclipse.kapua.service.device.management.DeviceManagementDomains; +import org.eclipse.kapua.service.device.management.commons.AbstractDeviceManagementServiceImpl; import org.eclipse.kapua.service.device.management.commons.call.DeviceCallExecutor; import org.eclipse.kapua.service.device.management.request.DeviceRequestManagementService; import org.eclipse.kapua.service.device.management.request.GenericRequestFactory; @@ -30,51 +29,53 @@ import org.eclipse.kapua.service.device.management.request.message.request.GenericRequestMessage; import org.eclipse.kapua.service.device.management.request.message.request.GenericRequestPayload; import org.eclipse.kapua.service.device.management.request.message.response.GenericResponseMessage; -import org.eclipse.kapua.service.device.registry.event.DeviceEventCreator; -import org.eclipse.kapua.service.device.registry.event.DeviceEventFactory; -import org.eclipse.kapua.service.device.registry.event.DeviceEventService; import java.util.Date; +/** + * {@link DeviceRequestManagementService} implementation. + * + * @since 1.0.0 + */ @KapuaProvider -public class DeviceRequestManagementServiceImpl implements DeviceRequestManagementService { +public class DeviceRequestManagementServiceImpl extends AbstractDeviceManagementServiceImpl implements DeviceRequestManagementService { private static final KapuaLocator LOCATOR = KapuaLocator.getInstance(); private static final GenericRequestFactory FACTORY = LOCATOR.getFactory(GenericRequestFactory.class); @Override - public GenericResponseMessage exec( - GenericRequestMessage requestInput, - Long timeout) throws KapuaException { + public GenericResponseMessage exec(GenericRequestMessage requestInput, Long timeout) throws KapuaException { + return exec(requestInput.getScopeId(), requestInput.getDeviceId(), requestInput, timeout); + } + + @Override + public GenericResponseMessage exec(KapuaId scopeId, KapuaId deviceId, GenericRequestMessage requestInput, Long timeout) throws KapuaException { // // Argument Validation ArgumentValidator.notNull(requestInput, "requestInput"); // // Check Access - KapuaLocator locator = KapuaLocator.getInstance(); - AuthorizationService authorizationService = locator.getService(AuthorizationService.class); - PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class); Actions action; switch (requestInput.getChannel().getMethod()) { - case EXECUTE: - action = Actions.execute; - break; - case READ: - case OPTIONS: - action = Actions.read; - break; - case CREATE: - case WRITE: - action = Actions.write; - break; - case DELETE: - action = Actions.delete; - break; - default: - throw new KapuaRuntimeException(KapuaErrorCodes.OPERATION_NOT_SUPPORTED); + case EXECUTE: + action = Actions.execute; + break; + case READ: + case OPTIONS: + action = Actions.read; + break; + case CREATE: + case WRITE: + action = Actions.write; + break; + case DELETE: + action = Actions.delete; + break; + default: + throw new KapuaRuntimeException(KapuaErrorCodes.OPERATION_NOT_SUPPORTED); } - authorizationService.checkPermission(permissionFactory.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, action, requestInput.getScopeId())); + AUTHORIZATION_SERVICE.checkPermission(PERMISSION_FACTORY.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, action, requestInput.getScopeId())); // // Prepare the request @@ -103,18 +104,7 @@ public GenericResponseMessage exec( // // Create event - DeviceEventService deviceEventService = locator.getService(DeviceEventService.class); - DeviceEventFactory deviceEventFactory = locator.getFactory(DeviceEventFactory.class); - - DeviceEventCreator deviceEventCreator = deviceEventFactory - .newCreator(requestInput.getScopeId(), requestInput.getDeviceId(), responseMessage.getReceivedOn(), requestInput.getChannel().getAppName().getValue()); - deviceEventCreator.setPosition(responseMessage.getPosition()); - deviceEventCreator.setSentOn(responseMessage.getSentOn()); - deviceEventCreator.setAction(genericRequestChannel.getMethod()); - deviceEventCreator.setResponseCode(responseMessage.getResponseCode()); - deviceEventCreator.setEventMessage(responseMessage.getPayload().toDisplayString()); - - KapuaSecurityUtils.doPrivileged(() -> deviceEventService.create(deviceEventCreator)); + createDeviceEvent(scopeId, deviceId, genericRequestMessage, responseMessage); return responseMessage; }