Search in sources :

Example 1 with DeviceCallFactory

use of org.eclipse.kapua.service.device.call.DeviceCallFactory in project kapua by eclipse.

the class DeviceCallExecutor method send.

@SuppressWarnings({ "unchecked" })
public RS send() throws KapuaException {
    // 
    // Get the correct device call
    KapuaLocator locator = KapuaLocator.getInstance();
    DeviceCallFactory kapuaDeviceCallFactory = locator.getFactory(DeviceCallFactory.class);
    DeviceCall<DeviceRequestMessage, DeviceResponseMessage> deviceCall = kapuaDeviceCallFactory.newDeviceCall();
    Translator tKapuaToClient = Translator.getTranslatorFor(requestMessage.getRequestClass(), deviceCall.getBaseMessageClass());
    DeviceResponseMessage responseMessage;
    timeout = timeout == null ? DeviceManagementSetting.getInstance().getLong(DeviceManagementSettingKey.REQUEST_TIMEOUT) : timeout;
    DeviceRequestMessage deviceRequestMessage = (DeviceRequestMessage) tKapuaToClient.translate(requestMessage);
    switch(requestMessage.getChannel().getMethod()) {
        case CREATE:
            {
                responseMessage = deviceCall.create(deviceRequestMessage, timeout);
            }
            break;
        case READ:
            {
                responseMessage = deviceCall.read(deviceRequestMessage, timeout);
            }
            break;
        case OPTIONS:
            {
                responseMessage = deviceCall.options(deviceRequestMessage, timeout);
            }
            break;
        case DELETE:
            {
                responseMessage = deviceCall.delete(deviceRequestMessage, timeout);
            }
            break;
        case EXECUTE:
            {
                responseMessage = deviceCall.execute(deviceRequestMessage, timeout);
            }
            break;
        case WRITE:
            {
                responseMessage = deviceCall.write(deviceRequestMessage, timeout);
            }
            break;
        default:
            throw new DeviceManagementException(DeviceManagementErrorCodes.REQUEST_BAD_METHOD, null, requestMessage.getChannel().getMethod());
    }
    Translator tClientToKapua = Translator.getTranslatorFor(deviceCall.getBaseMessageClass(), requestMessage.getResponseClass());
    return (RS) tClientToKapua.translate(responseMessage);
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) DeviceManagementException(org.eclipse.kapua.service.device.management.commons.exception.DeviceManagementException) DeviceResponseMessage(org.eclipse.kapua.service.device.call.message.app.response.DeviceResponseMessage) Translator(org.eclipse.kapua.translator.Translator) DeviceRequestMessage(org.eclipse.kapua.service.device.call.message.app.request.DeviceRequestMessage) DeviceCallFactory(org.eclipse.kapua.service.device.call.DeviceCallFactory)

Example 2 with DeviceCallFactory

use of org.eclipse.kapua.service.device.call.DeviceCallFactory in project kapua by eclipse.

the class KuraCallTest method testKuraCall.

// Disabling this test until we have build fixed. Then we should register DeviceCallFactory to service locator
// and enable the test again.
@Ignore
@SuppressWarnings("unchecked")
@Test
public void testKuraCall() throws Exception {
    KapuaLocator locator = KapuaLocator.getInstance();
    DeviceCallFactory deviceCallFactory = locator.getFactory(DeviceCallFactory.class);
    DeviceCall deviceCall = deviceCallFactory.newDeviceCall();
    KuraRequestChannel requestChannel = new KuraRequestChannel("$EDC", "kapua-sys", "00:60:0C:82:52:34");
    requestChannel.setAppId("CMD-V1");
    requestChannel.setMethod(KuraMethod.EXEC);
    requestChannel.setResources(new String[] { "command" });
    KuraRequestPayload requestPayload = new KuraRequestPayload();
    // requestPayload.metrics().put(Kurame, value)
    requestPayload.getMetrics().put(CommandMetrics.APP_METRIC_CMD.getValue(), "ifconfig");
    KuraRequestMessage requestMessage = new KuraRequestMessage(requestChannel, new Date(), requestPayload);
    deviceCall.execute(requestMessage, 120000L);
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) KuraRequestMessage(org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestMessage) KuraRequestChannel(org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestChannel) DeviceCall(org.eclipse.kapua.service.device.call.DeviceCall) DeviceCallFactory(org.eclipse.kapua.service.device.call.DeviceCallFactory) Date(java.util.Date) KuraRequestPayload(org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestPayload) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)2 DeviceCallFactory (org.eclipse.kapua.service.device.call.DeviceCallFactory)2 Date (java.util.Date)1 DeviceCall (org.eclipse.kapua.service.device.call.DeviceCall)1 DeviceRequestMessage (org.eclipse.kapua.service.device.call.message.app.request.DeviceRequestMessage)1 KuraRequestChannel (org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestChannel)1 KuraRequestMessage (org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestMessage)1 KuraRequestPayload (org.eclipse.kapua.service.device.call.message.app.request.kura.KuraRequestPayload)1 DeviceResponseMessage (org.eclipse.kapua.service.device.call.message.app.response.DeviceResponseMessage)1 DeviceManagementException (org.eclipse.kapua.service.device.management.commons.exception.DeviceManagementException)1 Translator (org.eclipse.kapua.translator.Translator)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1