Search in sources :

Example 1 with DevicePackageFactory

use of org.eclipse.kapua.service.device.management.packages.DevicePackageFactory in project kapua by eclipse.

the class TranslatorAppPackageKuraKapua method translate.

private void translate(PackageResponsePayload packageResponsePayload, String charEncoding, KuraDeploymentPackages kuraDeploymentPackages) throws KapuaException {
    try {
        KuraDeploymentPackage[] deploymentPackageArray = kuraDeploymentPackages.getDeploymentPackages();
        if (deploymentPackageArray != null) {
            KapuaLocator locator = KapuaLocator.getInstance();
            DevicePackageFactory deviceDeploymentFactory = locator.getFactory(DevicePackageFactory.class);
            DevicePackages deviceDeploymentPackages = deviceDeploymentFactory.newDeviceDeploymentPackages();
            for (KuraDeploymentPackage deploymentPackage : deploymentPackageArray) {
                DevicePackage deviceDeploymentPackage = deviceDeploymentFactory.newDeviceDeploymentPackage();
                deviceDeploymentPackage.setName(deploymentPackage.getName());
                deviceDeploymentPackage.setVersion(deploymentPackage.getVersion());
                DevicePackageBundleInfos devicePackageBundleInfos = deviceDeploymentPackage.getBundleInfos();
                KuraBundleInfo[] bundleInfoArray = deploymentPackage.getBundleInfos();
                for (KuraBundleInfo bundleInfo : bundleInfoArray) {
                    DevicePackageBundleInfo devicePackageBundleInfo = deviceDeploymentFactory.newDevicePackageBundleInfo();
                    devicePackageBundleInfo.setName(bundleInfo.getName());
                    devicePackageBundleInfo.setVersion(bundleInfo.getVersion());
                    // Add the new DevicePackageBundleInfo object to the corresponding list
                    devicePackageBundleInfos.getBundlesInfos().add(devicePackageBundleInfo);
                }
                // Add the new DeviceDeploymentPackage object to the corresponding list
                deviceDeploymentPackages.getPackages().add(deviceDeploymentPackage);
            }
            StringWriter sw = new StringWriter();
            XmlUtil.marshal(deviceDeploymentPackages, sw);
            byte[] requestBody = sw.toString().getBytes(charEncoding);
            packageResponsePayload.setBody(requestBody);
        }
    } catch (Exception e) {
        throw new TranslatorException(TranslatorErrorCodes.INVALID_BODY, e, kuraDeploymentPackages);
    }
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) DevicePackageBundleInfo(org.eclipse.kapua.service.device.management.packages.model.DevicePackageBundleInfo) DevicePackage(org.eclipse.kapua.service.device.management.packages.model.DevicePackage) KuraBundleInfo(org.eclipse.kapua.service.device.call.kura.model.deploy.KuraBundleInfo) TranslatorException(org.eclipse.kapua.translator.exception.TranslatorException) KapuaException(org.eclipse.kapua.KapuaException) DevicePackages(org.eclipse.kapua.service.device.management.packages.model.DevicePackages) DevicePackageFactory(org.eclipse.kapua.service.device.management.packages.DevicePackageFactory) StringWriter(java.io.StringWriter) DevicePackageBundleInfos(org.eclipse.kapua.service.device.management.packages.model.DevicePackageBundleInfos) TranslatorException(org.eclipse.kapua.translator.exception.TranslatorException) KuraDeploymentPackage(org.eclipse.kapua.service.device.call.kura.model.deploy.KuraDeploymentPackage)

Example 2 with DevicePackageFactory

use of org.eclipse.kapua.service.device.management.packages.DevicePackageFactory in project kapua by eclipse.

the class GwtDeviceManagementServiceImpl method uninstallPackage.

@Override
public void uninstallPackage(GwtXSRFToken xsrfToken, GwtPackageUninstallRequest gwtPackageUninstallRequest) throws GwtKapuaException {
    // 
    // Check token
    checkXSRFToken(xsrfToken);
    // Do install
    try {
        KapuaId scopeId = KapuaEid.parseShortId(gwtPackageUninstallRequest.getScopeId());
        KapuaId deviceId = KapuaEid.parseShortId(gwtPackageUninstallRequest.getDeviceId());
        KapuaLocator locator = KapuaLocator.getInstance();
        DevicePackageFactory devicePackageFactory = locator.getFactory(DevicePackageFactory.class);
        DevicePackageUninstallRequest packageUninstallRequest = devicePackageFactory.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);
    } catch (Throwable t) {
        KapuaExceptionHandler.handle(t);
    }
}
Also used : DevicePackageManagementService(org.eclipse.kapua.service.device.management.packages.DevicePackageManagementService) KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) DevicePackageFactory(org.eclipse.kapua.service.device.management.packages.DevicePackageFactory) DevicePackageUninstallRequest(org.eclipse.kapua.service.device.management.packages.model.uninstall.DevicePackageUninstallRequest) KapuaId(org.eclipse.kapua.model.id.KapuaId)

Example 3 with DevicePackageFactory

use of org.eclipse.kapua.service.device.management.packages.DevicePackageFactory in project kapua by eclipse.

the class GwtDeviceManagementServiceImpl method installPackage.

@Override
public void installPackage(GwtXSRFToken xsrfToken, GwtPackageInstallRequest gwtPackageInstallRequest) throws GwtKapuaException {
    // 
    // Check token
    checkXSRFToken(xsrfToken);
    // Do install
    try {
        KapuaId scopeId = KapuaEid.parseShortId(gwtPackageInstallRequest.getScopeId());
        KapuaId deviceId = KapuaEid.parseShortId(gwtPackageInstallRequest.getDeviceId());
        KapuaLocator locator = KapuaLocator.getInstance();
        DevicePackageFactory devicePackageFactory = locator.getFactory(DevicePackageFactory.class);
        DevicePackageDownloadRequest packageDownloadRequest = devicePackageFactory.newPackageDownloadRequest();
        packageDownloadRequest.setURI(new URI(gwtPackageInstallRequest.getPackageURI()));
        packageDownloadRequest.setName(gwtPackageInstallRequest.getPackageName());
        packageDownloadRequest.setVersion(gwtPackageInstallRequest.getPackageVersion());
        // Always install
        packageDownloadRequest.setInstall(true);
        packageDownloadRequest.setReboot(gwtPackageInstallRequest.isReboot());
        packageDownloadRequest.setRebootDelay(gwtPackageInstallRequest.getRebootDelay());
        DevicePackageManagementService packageManagementService = locator.getService(DevicePackageManagementService.class);
        packageManagementService.downloadExec(scopeId, deviceId, packageDownloadRequest, null);
    } catch (Throwable t) {
        KapuaExceptionHandler.handle(t);
    }
}
Also used : DevicePackageManagementService(org.eclipse.kapua.service.device.management.packages.DevicePackageManagementService) KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) DevicePackageFactory(org.eclipse.kapua.service.device.management.packages.DevicePackageFactory) DevicePackageDownloadRequest(org.eclipse.kapua.service.device.management.packages.model.download.DevicePackageDownloadRequest) KapuaId(org.eclipse.kapua.model.id.KapuaId) URI(java.net.URI)

Aggregations

KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)3 DevicePackageFactory (org.eclipse.kapua.service.device.management.packages.DevicePackageFactory)3 KapuaId (org.eclipse.kapua.model.id.KapuaId)2 DevicePackageManagementService (org.eclipse.kapua.service.device.management.packages.DevicePackageManagementService)2 StringWriter (java.io.StringWriter)1 URI (java.net.URI)1 KapuaException (org.eclipse.kapua.KapuaException)1 KuraBundleInfo (org.eclipse.kapua.service.device.call.kura.model.deploy.KuraBundleInfo)1 KuraDeploymentPackage (org.eclipse.kapua.service.device.call.kura.model.deploy.KuraDeploymentPackage)1 DevicePackage (org.eclipse.kapua.service.device.management.packages.model.DevicePackage)1 DevicePackageBundleInfo (org.eclipse.kapua.service.device.management.packages.model.DevicePackageBundleInfo)1 DevicePackageBundleInfos (org.eclipse.kapua.service.device.management.packages.model.DevicePackageBundleInfos)1 DevicePackages (org.eclipse.kapua.service.device.management.packages.model.DevicePackages)1 DevicePackageDownloadRequest (org.eclipse.kapua.service.device.management.packages.model.download.DevicePackageDownloadRequest)1 DevicePackageUninstallRequest (org.eclipse.kapua.service.device.management.packages.model.uninstall.DevicePackageUninstallRequest)1 TranslatorException (org.eclipse.kapua.translator.exception.TranslatorException)1