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