Search in sources :

Example 1 with KuraRequestPayload

use of org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestPayload in project kapua by eclipse.

the class TranslatorAppCommandKapuaKura method translate.

@Override
public KuraRequestMessage translate(CommandRequestMessage kapuaMessage) throws KapuaException {
    // 
    // Kura channel
    KapuaLocator locator = KapuaLocator.getInstance();
    AccountService accountService = locator.getService(AccountService.class);
    Account account = accountService.find(kapuaMessage.getScopeId());
    DeviceRegistryService deviceService = locator.getService(DeviceRegistryService.class);
    Device device = deviceService.find(kapuaMessage.getScopeId(), kapuaMessage.getDeviceId());
    KuraRequestChannel kuraRequestChannel = translate(kapuaMessage.getChannel());
    kuraRequestChannel.setScope(account.getName());
    kuraRequestChannel.setClientId(device.getClientId());
    // 
    // Kura payload
    KuraRequestPayload kuraPayload = translate(kapuaMessage.getPayload());
    // return Kura Message
    return new KuraRequestMessage(kuraRequestChannel, kapuaMessage.getReceivedOn(), kuraPayload);
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) Account(org.eclipse.kapua.service.account.Account) Device(org.eclipse.kapua.service.device.registry.Device) KuraRequestMessage(org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestMessage) DeviceRegistryService(org.eclipse.kapua.service.device.registry.DeviceRegistryService) KuraRequestChannel(org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestChannel) AccountService(org.eclipse.kapua.service.account.AccountService) KuraRequestPayload(org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestPayload)

Example 2 with KuraRequestPayload

use of org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestPayload in project kapua by eclipse.

the class TranslatorAppBundleKapuaKura method translate.

@Override
public KuraRequestMessage translate(BundleRequestMessage kapuaMessage) throws KapuaException {
    // 
    // Kura channel
    KapuaLocator locator = KapuaLocator.getInstance();
    AccountService accountService = locator.getService(AccountService.class);
    Account account = accountService.find(kapuaMessage.getScopeId());
    DeviceRegistryService deviceService = locator.getService(DeviceRegistryService.class);
    Device device = deviceService.find(kapuaMessage.getScopeId(), kapuaMessage.getDeviceId());
    KuraRequestChannel kuraRequestChannel = translate(kapuaMessage.getChannel());
    kuraRequestChannel.setScope(account.getName());
    kuraRequestChannel.setClientId(device.getClientId());
    // 
    // Kura payload
    KuraRequestPayload kuraPayload = translate(kapuaMessage.getPayload());
    // Return Kura Message
    return new KuraRequestMessage(kuraRequestChannel, kapuaMessage.getReceivedOn(), kuraPayload);
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) Account(org.eclipse.kapua.service.account.Account) Device(org.eclipse.kapua.service.device.registry.Device) KuraRequestMessage(org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestMessage) DeviceRegistryService(org.eclipse.kapua.service.device.registry.DeviceRegistryService) KuraRequestChannel(org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestChannel) AccountService(org.eclipse.kapua.service.account.AccountService) KuraRequestPayload(org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestPayload)

Example 3 with KuraRequestPayload

use of org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestPayload in project kapua by eclipse.

the class TranslatorAppCommandKapuaKura method translate.

private KuraRequestPayload translate(CommandRequestPayload kapuaPayload) throws KapuaException {
    KuraRequestPayload kuraRequestPayload = new KuraRequestPayload();
    // 
    // Payload translation
    Map<String, Object> metrics = kuraRequestPayload.getMetrics();
    metrics.put(propertiesDictionary.get(CommandAppProperties.APP_PROPERTY_CMD).getValue(), kapuaPayload.getCommand());
    metrics.put(propertiesDictionary.get(CommandAppProperties.APP_PROPERTY_ENVP).getValue(), kapuaPayload.getEnvironmentPairs());
    metrics.put(propertiesDictionary.get(CommandAppProperties.APP_PROPERTY_DIR).getValue(), kapuaPayload.getWorkingDir());
    metrics.put(propertiesDictionary.get(CommandAppProperties.APP_PROPERTY_STDIN).getValue(), kapuaPayload.getStdin());
    metrics.put(propertiesDictionary.get(CommandAppProperties.APP_PROPERTY_TOUT).getValue(), kapuaPayload.getTimeout());
    metrics.put(propertiesDictionary.get(CommandAppProperties.APP_PROPERTY_ASYNC).getValue(), kapuaPayload.isRunAsync());
    metrics.put(propertiesDictionary.get(CommandAppProperties.APP_PROPERTY_PASSWORD).getValue(), kapuaPayload.getPassword());
    // argument translation
    int i = 0;
    String[] arguments = kapuaPayload.getArguments();
    if (arguments != null) {
        for (String argument : arguments) {
            metrics.put(propertiesDictionary.get(CommandAppProperties.APP_PROPERTY_ARG).getValue() + i++, argument);
        }
    }
    // 
    // Body translation
    kuraRequestPayload.setBody(kapuaPayload.getBody());
    // Return Kura Payload
    return kuraRequestPayload;
}
Also used : KuraRequestPayload(org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestPayload)

Example 4 with KuraRequestPayload

use of org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestPayload in project kapua by eclipse.

the class TranslatorAppConfigurationKapuaKura method translate.

@Override
public KuraRequestMessage translate(ConfigurationRequestMessage kapuaMessage) throws KapuaException {
    // 
    // Kura channel
    KapuaLocator locator = KapuaLocator.getInstance();
    AccountService accountService = locator.getService(AccountService.class);
    Account account = accountService.find(kapuaMessage.getScopeId());
    DeviceRegistryService deviceService = locator.getService(DeviceRegistryService.class);
    Device device = deviceService.find(kapuaMessage.getScopeId(), kapuaMessage.getDeviceId());
    KuraRequestChannel kuraRequestChannel = translate(kapuaMessage.getChannel());
    kuraRequestChannel.setScope(account.getName());
    kuraRequestChannel.setClientId(device.getClientId());
    // 
    // Kura payload
    KuraRequestPayload kuraPayload = translate(kapuaMessage.getPayload());
    // Return Kura Message
    return new KuraRequestMessage(kuraRequestChannel, kapuaMessage.getReceivedOn(), kuraPayload);
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) Account(org.eclipse.kapua.service.account.Account) Device(org.eclipse.kapua.service.device.registry.Device) KuraRequestMessage(org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestMessage) DeviceRegistryService(org.eclipse.kapua.service.device.registry.DeviceRegistryService) KuraRequestChannel(org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestChannel) AccountService(org.eclipse.kapua.service.account.AccountService) KuraRequestPayload(org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestPayload)

Example 5 with KuraRequestPayload

use of org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestPayload in project kapua by eclipse.

the class TranslatorAppConfigurationKapuaKura method translate.

private KuraRequestPayload translate(ConfigurationRequestPayload kapuaPayload) throws KapuaException {
    KuraRequestPayload kuraRequestPayload = new KuraRequestPayload();
    if (kapuaPayload.getBody() != null) {
        DeviceConfiguration kapuaDeviceConfiguration;
        try {
            kapuaDeviceConfiguration = XmlUtil.unmarshal(new String(kapuaPayload.getBody()), DeviceConfigurationImpl.class);
        } catch (Exception e) {
            throw new TranslatorException(TranslatorErrorCodes.INVALID_PAYLOAD, e, kapuaPayload.getBody());
        }
        KuraDeviceConfiguration kuraDeviceConfiguration = translate(kapuaDeviceConfiguration);
        byte[] body;
        try {
            body = XmlUtil.marshal(kuraDeviceConfiguration).getBytes();
        } catch (Exception e) {
            throw new TranslatorException(TranslatorErrorCodes.INVALID_PAYLOAD, e, kapuaPayload.getBody());
        }
        kuraRequestPayload.setBody(body);
    }
    // Return Kura Payload
    return kuraRequestPayload;
}
Also used : KuraDeviceConfiguration(org.eclipse.kapua.service.device.call.kura.model.configuration.KuraDeviceConfiguration) TranslatorException(org.eclipse.kapua.translator.exception.TranslatorException) KuraDeviceConfiguration(org.eclipse.kapua.service.device.call.kura.model.configuration.KuraDeviceConfiguration) DeviceConfiguration(org.eclipse.kapua.service.device.management.configuration.DeviceConfiguration) DeviceConfigurationImpl(org.eclipse.kapua.service.device.management.configuration.internal.DeviceConfigurationImpl) TranslatorException(org.eclipse.kapua.translator.exception.TranslatorException) KapuaException(org.eclipse.kapua.KapuaException) KuraRequestPayload(org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestPayload)

Aggregations

KuraRequestPayload (org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestPayload)10 KuraRequestChannel (org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestChannel)7 KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)6 KuraRequestMessage (org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestMessage)6 Account (org.eclipse.kapua.service.account.Account)5 AccountService (org.eclipse.kapua.service.account.AccountService)5 Device (org.eclipse.kapua.service.device.registry.Device)5 DeviceRegistryService (org.eclipse.kapua.service.device.registry.DeviceRegistryService)5 Date (java.util.Date)2 KapuaException (org.eclipse.kapua.KapuaException)2 Random (java.util.Random)1 KapuaId (org.eclipse.kapua.model.id.KapuaId)1 DeviceCall (org.eclipse.kapua.service.device.call.DeviceCall)1 DeviceCallFactory (org.eclipse.kapua.service.device.call.DeviceCallFactory)1 KuraMqttDeviceCallException (org.eclipse.kapua.service.device.call.kura.exception.KuraMqttDeviceCallException)1 KuraDeviceConfiguration (org.eclipse.kapua.service.device.call.kura.model.configuration.KuraDeviceConfiguration)1 KuraResponseMessage (org.eclipse.kapua.service.device.call.message.app.response.kura.KuraResponseMessage)1 DeviceConfiguration (org.eclipse.kapua.service.device.management.configuration.DeviceConfiguration)1 DeviceConfigurationImpl (org.eclipse.kapua.service.device.management.configuration.internal.DeviceConfigurationImpl)1 Translator (org.eclipse.kapua.translator.Translator)1