Search in sources :

Example 21 with KapuaId

use of org.eclipse.kapua.model.id.KapuaId in project kapua by eclipse.

the class DeviceLifeCycleServiceImpl method missing.

@Override
public void missing(KapuaId connectionId, KapuaMissingMessage message) throws KapuaException {
    KapuaPayload payload = message.getPayload();
    KapuaId scopeId = message.getScopeId();
    KapuaId deviceId = message.getDeviceId();
    // 
    // Device update
    KapuaLocator locator = KapuaLocator.getInstance();
    DeviceRegistryService deviceRegistryService = locator.getService(DeviceRegistryService.class);
    Device device = deviceRegistryService.find(scopeId, deviceId);
    // 
    // Event create
    DeviceEventService deviceEventService = locator.getService(DeviceEventService.class);
    DeviceEventFactory deviceEventFactory = locator.getFactory(DeviceEventFactory.class);
    DeviceEventCreator deviceEventCreator = deviceEventFactory.newCreator(scopeId, device.getId(), message.getReceivedOn(), "MISSING");
    deviceEventCreator.setEventMessage(payload.toDisplayString());
    // TODO check this change
    deviceEventCreator.setResponseCode(KapuaResponseCode.ACCEPTED);
    deviceEventCreator.setSentOn(message.getReceivedOn());
    KapuaPosition position = message.getPosition();
    if (position != null) {
        deviceEventCreator.setPosition(position);
    }
    deviceEventService.create(deviceEventCreator);
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) KapuaPosition(org.eclipse.kapua.message.KapuaPosition) Device(org.eclipse.kapua.service.device.registry.Device) KapuaPayload(org.eclipse.kapua.message.KapuaPayload) DeviceRegistryService(org.eclipse.kapua.service.device.registry.DeviceRegistryService) DeviceEventService(org.eclipse.kapua.service.device.registry.event.DeviceEventService) DeviceEventFactory(org.eclipse.kapua.service.device.registry.event.DeviceEventFactory) DeviceEventCreator(org.eclipse.kapua.service.device.registry.event.DeviceEventCreator) KapuaId(org.eclipse.kapua.model.id.KapuaId)

Example 22 with KapuaId

use of org.eclipse.kapua.model.id.KapuaId in project kapua by eclipse.

the class IdGeneratorServiceImplTest method testIdGeneration.

@Test
public void testIdGeneration() throws Exception {
    KapuaLocator locator = KapuaLocator.getInstance();
    IdGeneratorService idGeneratorService = locator.getService(IdGeneratorService.class);
    KapuaId id = idGeneratorService.generate();
    assertNotNull(id);
    assertNotNull(id.getShortId());
    assertTrue(!id.getShortId().isEmpty());
    assertNotNull(id.getId());
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) KapuaId(org.eclipse.kapua.model.id.KapuaId) IdGeneratorService(org.eclipse.kapua.service.generator.id.IdGeneratorService) Test(org.junit.Test)

Example 23 with KapuaId

use of org.eclipse.kapua.model.id.KapuaId in project kapua by eclipse.

the class IdGeneratorServiceImplTest method testBulkIdGeneration.

@Test
public void testBulkIdGeneration() throws Exception {
    KapuaLocator locator = KapuaLocator.getInstance();
    IdGeneratorService idGeneratorService = locator.getService(IdGeneratorService.class);
    Set<KapuaId> generatedIds = new HashSet<>();
    for (int i = 0; i < 1000; i++) {
        KapuaId id = idGeneratorService.generate();
        assertFalse(generatedIds.contains(id));
        generatedIds.add(id);
    }
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) KapuaId(org.eclipse.kapua.model.id.KapuaId) IdGeneratorService(org.eclipse.kapua.service.generator.id.IdGeneratorService) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 24 with KapuaId

use of org.eclipse.kapua.model.id.KapuaId in project kapua by eclipse.

the class IdGeneratorServiceImplTest method testIdGeneration.

@Test
public void testIdGeneration() throws Exception {
    KapuaLocator locator = KapuaLocator.getInstance();
    IdGeneratorService idGeneratorService = locator.getService(IdGeneratorService.class);
    KapuaId id = idGeneratorService.generate();
    assertNotNull(id);
    assertNotNull(id.getShortId());
    assertTrue(!id.getShortId().isEmpty());
    assertNotNull(id.getId());
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) KapuaId(org.eclipse.kapua.model.id.KapuaId) IdGeneratorService(org.eclipse.kapua.service.generator.id.IdGeneratorService) Test(org.junit.Test)

Example 25 with KapuaId

use of org.eclipse.kapua.model.id.KapuaId in project kapua by eclipse.

the class DevicePackageManagementServiceImpl method downloadExec.

@Override
public void downloadExec(KapuaId scopeId, KapuaId deviceId, DevicePackageDownloadRequest packageDownloadRequest, Long timeout) throws KapuaException {
    // 
    // Argument Validation
    ArgumentValidator.notNull(scopeId, "scopeId");
    ArgumentValidator.notNull(deviceId, "deviceId");
    ArgumentValidator.notNull(packageDownloadRequest, "packageDownloadRequest");
    // 
    // Check Access
    KapuaLocator locator = KapuaLocator.getInstance();
    AuthorizationService authorizationService = locator.getService(AuthorizationService.class);
    PermissionFactory permissionFactory = locator.getFactory(PermissionFactory.class);
    authorizationService.checkPermission(permissionFactory.newPermission(DeviceManagementDomain.DEVICE_MANAGEMENT, Actions.write, scopeId));
    // 
    // Generate requestId
    IdGeneratorService idGeneratorService = locator.getService(IdGeneratorService.class);
    KapuaId operationId = idGeneratorService.generate();
    // 
    // Prepare the request
    PackageRequestChannel packageRequestChannel = new PackageRequestChannel();
    packageRequestChannel.setAppName(PackageAppProperties.APP_NAME);
    packageRequestChannel.setVersion(PackageAppProperties.APP_VERSION);
    packageRequestChannel.setMethod(KapuaMethod.EXECUTE);
    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.isInstall());
    packageRequestPayload.setReboot(packageDownloadRequest.isReboot());
    packageRequestPayload.setRebootDelay(packageDownloadRequest.getRebootDelay());
    PackageRequestMessage packageRequestMessage = new PackageRequestMessage();
    packageRequestMessage.setScopeId(scopeId);
    packageRequestMessage.setDeviceId(deviceId);
    packageRequestMessage.setCapturedOn(new Date());
    packageRequestMessage.setPayload(packageRequestPayload);
    packageRequestMessage.setChannel(packageRequestChannel);
    // 
    // Do exec
    @SuppressWarnings({ "rawtypes", "unchecked" }) DeviceCallExecutor deviceApplicationCall = new DeviceCallExecutor(packageRequestMessage, timeout);
    PackageResponseMessage responseMessage = (PackageResponseMessage) deviceApplicationCall.send();
    // 
    // Create event
    DeviceEventService deviceEventService = locator.getService(DeviceEventService.class);
    DeviceEventFactory deviceEventFactory = locator.getFactory(DeviceEventFactory.class);
    DeviceEventCreator deviceEventCreator = deviceEventFactory.newCreator(scopeId, deviceId, responseMessage.getReceivedOn(), PackageAppProperties.APP_NAME.getValue());
    deviceEventCreator.setPosition(responseMessage.getPosition());
    deviceEventCreator.setSentOn(responseMessage.getSentOn());
    deviceEventCreator.setAction(KapuaMethod.EXECUTE);
    deviceEventCreator.setResponseCode(responseMessage.getResponseCode());
    deviceEventCreator.setEventMessage(responseMessage.getPayload().toDisplayString());
    deviceEventService.create(deviceEventCreator);
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) PackageResponseMessage(org.eclipse.kapua.service.device.management.packages.message.internal.PackageResponseMessage) PermissionFactory(org.eclipse.kapua.service.authorization.permission.PermissionFactory) DeviceEventFactory(org.eclipse.kapua.service.device.registry.event.DeviceEventFactory) IdGeneratorService(org.eclipse.kapua.service.generator.id.IdGeneratorService) Date(java.util.Date) PackageRequestChannel(org.eclipse.kapua.service.device.management.packages.message.internal.PackageRequestChannel) DeviceCallExecutor(org.eclipse.kapua.service.device.management.commons.call.DeviceCallExecutor) AuthorizationService(org.eclipse.kapua.service.authorization.AuthorizationService) PackageRequestMessage(org.eclipse.kapua.service.device.management.packages.message.internal.PackageRequestMessage) DeviceEventService(org.eclipse.kapua.service.device.registry.event.DeviceEventService) DeviceEventCreator(org.eclipse.kapua.service.device.registry.event.DeviceEventCreator) KapuaId(org.eclipse.kapua.model.id.KapuaId) PackageRequestPayload(org.eclipse.kapua.service.device.management.packages.message.internal.PackageRequestPayload)

Aggregations

KapuaId (org.eclipse.kapua.model.id.KapuaId)75 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)54 Account (org.eclipse.kapua.service.account.Account)14 AccountService (org.eclipse.kapua.service.account.AccountService)14 ArrayList (java.util.ArrayList)13 Date (java.util.Date)11 Device (org.eclipse.kapua.service.device.registry.Device)11 Test (org.junit.Test)11 DeviceRegistryService (org.eclipse.kapua.service.device.registry.DeviceRegistryService)10 BaseListLoadResult (com.extjs.gxt.ui.client.data.BaseListLoadResult)9 DeviceEventFactory (org.eclipse.kapua.service.device.registry.event.DeviceEventFactory)9 DeviceEventService (org.eclipse.kapua.service.device.registry.event.DeviceEventService)9 PermissionFactory (org.eclipse.kapua.service.authorization.permission.PermissionFactory)8 IdGeneratorService (org.eclipse.kapua.service.generator.id.IdGeneratorService)8 GwtAccount (org.eclipse.kapua.app.console.shared.model.GwtAccount)7 GwtAccountService (org.eclipse.kapua.app.console.shared.service.GwtAccountService)7 KapuaEid (org.eclipse.kapua.commons.model.id.KapuaEid)7 DeviceEventCreator (org.eclipse.kapua.service.device.registry.event.DeviceEventCreator)7 User (org.eclipse.kapua.service.user.User)7 GwtDevice (org.eclipse.kapua.app.console.shared.model.GwtDevice)6