From 155135a70d54e68b96f85bad03d344be218292f5 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Wed, 26 Apr 2017 01:34:57 +0530 Subject: [PATCH 1/6] fixed few issues after testing analytics --- .../websocket/WebsocketEventAdapter.java | 39 ++++++++++++------- .../constants/WebsocketConstants.java | 3 ++ 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/WebsocketEventAdapter.java b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/WebsocketEventAdapter.java index edf39993a..ed50d9f21 100644 --- a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/WebsocketEventAdapter.java +++ b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/WebsocketEventAdapter.java @@ -425,23 +425,36 @@ public class WebsocketEventAdapter implements OutputEventAdapter { // fetch the different attribute values received as part of the current event. Set queryParams = queryParamValuePairs.keySet(); for (String aQueryParam : queryParams) { - if (!aQueryParam.equalsIgnoreCase(WebsocketConstants.TOKEN_PARAM)) { - try { - String queryValue = queryParamValuePairs.get(aQueryParam); - if (queryValue != null && !queryValue.trim().isEmpty()) { - JSONObject jsonObject = new JSONObject(jsonMessage); - String eventValue = jsonObject.getString(aQueryParam); - if (eventValue == null || !eventValue.equalsIgnoreCase(queryValue)) { - return false; + try { + + String queryValue = queryParamValuePairs.get(aQueryParam); + if (queryValue != null && !queryValue.trim().isEmpty()) { + JSONObject jsonObject = new JSONObject(jsonMessage); + JSONObject event = jsonObject.getJSONObject(WebsocketConstants.EVENT); + JSONObject data; + if (!event.isNull(WebsocketConstants.META_DATA)) { + data = event.getJSONObject(WebsocketConstants.META_DATA); + if (!data.isNull(aQueryParam)) { + String eventValue = data.get(aQueryParam).toString(); + if (eventValue == null || !eventValue.equalsIgnoreCase(queryValue)) { + return false; + } } + } - } catch (JSONException e) { - if (log.isDebugEnabled()) { - log.debug("Unable validate the stream filter properties for event : " + jsonMessage - + " ", e); + + if (!event.isNull(WebsocketConstants.PAYLOAD_DATA)) { + data = event.getJSONObject(WebsocketConstants.PAYLOAD_DATA); + if (!data.isNull(aQueryParam)) { + String eventValue = data.get(aQueryParam).toString(); + if (eventValue == null || !eventValue.equalsIgnoreCase(queryValue)) { + return false; + } + } } - return false; } + } catch (JSONException e) { + //do nothing - This exception is thrown when the event does not have query parameter. } } } diff --git a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/constants/WebsocketConstants.java b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/constants/WebsocketConstants.java index c5c3c01f2..743e51c21 100644 --- a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/constants/WebsocketConstants.java +++ b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/constants/WebsocketConstants.java @@ -34,4 +34,7 @@ public class WebsocketConstants { public static final String USERNAME = "username"; public static final String PASSWORD = "password"; public static final String TOKEN_PARAM = "token"; + public static final String META_DATA = "metaData"; + public static final String PAYLOAD_DATA = "payloadData"; + public static final String EVENT = "event"; } From b32bf11c91080b8d0e38f8cacddd0abf5b3fce0f Mon Sep 17 00:00:00 2001 From: ayyoob Date: Mon, 29 May 2017 01:01:26 +0530 Subject: [PATCH 2/6] fixed multi tenant issues after testing thrift endpoint with multitenant --- .../Geo-Receiver-WSO2Event-LocationStream.xml | 2 +- .../arduino_receiver/arduino_receiver.xml | 10 +- .../adapter/mqtt/MQTTEventAdapterFactory.java | 2 +- .../mqtt/util/MQTTEventAdapterConstants.java | 2 +- .../pom.xml | 134 ++++++++++++++ .../input/adapter/thrift/ThriftAdapter.java | 90 ++++++++++ .../thrift/ThriftEventAdapterFactory.java | 41 +++++ .../ThriftEventAdapterServiceComponent.java | 167 ++++++++++++++++++ .../ThriftEventAdapterServiceHolder.java | 99 +++++++++++ .../input/adapter/thrift/Resources.properties | 25 +++ .../endpoint/TenantSubscriptionEndpoint.java | 3 +- .../cdmf-transport-adapters/pom.xml | 1 + .../android_agent_event_receiver.xml | 2 +- .../android_sense_receiver-carbon.super.xml | 1 - .../receiver/android_sense_receiver.xml | 1 - .../raspberrypi_receiver-carbon.super.xml | 1 - .../receiver/raspberrypi_receiver.xml | 1 - ...virtualfirealarm_receiver-carbon.super.xml | 1 - .../receiver/virtualfirealarm_receiver.xml | 1 - .../pom.xml | 15 ++ pom.xml | 25 +++ 21 files changed, 608 insertions(+), 16 deletions(-) create mode 100644 components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/pom.xml create mode 100644 components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/src/main/java/org/wso2/carbon/device/mgt/input/adapter/thrift/ThriftAdapter.java create mode 100644 components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/src/main/java/org/wso2/carbon/device/mgt/input/adapter/thrift/ThriftEventAdapterFactory.java create mode 100644 components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/src/main/java/org/wso2/carbon/device/mgt/input/adapter/thrift/internal/ThriftEventAdapterServiceComponent.java create mode 100644 components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/src/main/java/org/wso2/carbon/device/mgt/input/adapter/thrift/internal/ThriftEventAdapterServiceHolder.java create mode 100644 components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/src/main/resources/org/wso2/carbon/device/mgt/input/adapter/thrift/Resources.properties diff --git a/components/analytics/iot-analytics/org.wso2.carbon.iot.geo.dashboard/src/main/resources/carbonapps/Geo-Dashboard-WSO2Event-Receiver_1.0.0/Geo-Receiver-WSO2Event-LocationStream.xml b/components/analytics/iot-analytics/org.wso2.carbon.iot.geo.dashboard/src/main/resources/carbonapps/Geo-Dashboard-WSO2Event-Receiver_1.0.0/Geo-Receiver-WSO2Event-LocationStream.xml index bce9c10d4..66ddcc2c4 100644 --- a/components/analytics/iot-analytics/org.wso2.carbon.iot.geo.dashboard/src/main/resources/carbonapps/Geo-Dashboard-WSO2Event-Receiver_1.0.0/Geo-Receiver-WSO2Event-LocationStream.xml +++ b/components/analytics/iot-analytics/org.wso2.carbon.iot.geo.dashboard/src/main/resources/carbonapps/Geo-Dashboard-WSO2Event-Receiver_1.0.0/Geo-Receiver-WSO2Event-LocationStream.xml @@ -19,7 +19,7 @@ - + false diff --git a/components/device-types/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.analytics/src/main/resources/carbonapps/Arduino/arduino_receiver/arduino_receiver.xml b/components/device-types/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.analytics/src/main/resources/carbonapps/Arduino/arduino_receiver/arduino_receiver.xml index b20bafc96..35263dc9c 100644 --- a/components/device-types/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.analytics/src/main/resources/carbonapps/Arduino/arduino_receiver/arduino_receiver.xml +++ b/components/device-types/arduino-plugin/org.wso2.carbon.device.mgt.iot.arduino.analytics/src/main/resources/carbonapps/Arduino/arduino_receiver/arduino_receiver.xml @@ -18,9 +18,9 @@ --> - - iot-http - - - + + false + + + diff --git a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/input/adapter/mqtt/MQTTEventAdapterFactory.java b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/input/adapter/mqtt/MQTTEventAdapterFactory.java index 0419d26eb..f5f93b17a 100644 --- a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/input/adapter/mqtt/MQTTEventAdapterFactory.java +++ b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/input/adapter/mqtt/MQTTEventAdapterFactory.java @@ -120,7 +120,7 @@ public class MQTTEventAdapterFactory extends InputEventAdapterFactory { // set clientId Property clientId = new Property(MQTTEventAdapterConstants.ADAPTER_CONF_CLIENTID); clientId.setDisplayName(resourceBundle.getString(MQTTEventAdapterConstants.ADAPTER_CONF_CLIENTID)); - clientId.setRequired(true); + clientId.setRequired(false); clientId.setHint(resourceBundle.getString(MQTTEventAdapterConstants.ADAPTER_CONF_CLIENTID_HINT)); propertyList.add(clientId); diff --git a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/input/adapter/mqtt/util/MQTTEventAdapterConstants.java b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/input/adapter/mqtt/util/MQTTEventAdapterConstants.java index 7d52fb53c..0a0b09e2a 100644 --- a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/input/adapter/mqtt/util/MQTTEventAdapterConstants.java +++ b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/input/adapter/mqtt/util/MQTTEventAdapterConstants.java @@ -46,7 +46,7 @@ public class MQTTEventAdapterConstants { public static final String ADAPTER_CONF_CLEAN_SESSION = "cleanSession"; public static final String ADAPTER_CONF_CLEAN_SESSION_HINT = "cleanSession.hint"; public static final String ADAPTER_CONF_KEEP_ALIVE = "keepAlive"; - public static final int ADAPTER_CONF_DEFAULT_KEEP_ALIVE = 60000; + public static final int ADAPTER_CONF_DEFAULT_KEEP_ALIVE = 20000; public static final int INITIAL_RECONNECTION_DURATION = 4000; public static final int RECONNECTION_PROGRESS_FACTOR = 2; diff --git a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/pom.xml b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/pom.xml new file mode 100644 index 000000000..6c1d4d94e --- /dev/null +++ b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/pom.xml @@ -0,0 +1,134 @@ + + + + + + org.wso2.carbon.devicemgt-plugins + cdmf-transport-adapters + 3.0.37-SNAPSHOT + ../../pom.xml + + + 4.0.0 + org.wso2.carbon.device.mgt.input.adapter.thrift + bundle + WSO2 Carbon - Event Input Thrift Adapter Module + org.wso2.carbon.event.input.adapter.thrift provides the back-end + functionality of input wso2event adapter + + http://wso2.org + + + + org.wso2.carbon.analytics-common + org.wso2.carbon.event.input.adapter.core + + + org.wso2.carbon.analytics-common + org.wso2.carbon.event.input.adapter.wso2event + + + org.wso2.carbon + org.wso2.carbon.logging + + + org.wso2.carbon + org.wso2.carbon.core + + + org.wso2.carbon.analytics-common + org.wso2.carbon.databridge.commons + + + org.wso2.carbon.analytics-common + org.wso2.carbon.databridge.commons.thrift + + + org.wso2.carbon.analytics-common + org.wso2.carbon.databridge.commons.binary + + + org.wso2.carbon.analytics-common + org.wso2.carbon.databridge.core + + + + + + + + org.apache.felix + maven-scr-plugin + + + generate-scr-descriptor + + scr + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + org.apache.felix + maven-bundle-plugin + true + + + ${project.artifactId} + ${project.artifactId} + + org.wso2.carbon.device.mgt.input.adapter.thrift.internal, + org.wso2.carbon.device.mgt.input.adapter.thrift.internal.*, + + + !org.wso2.carbon.device.mgt.input.adapter.thrift.internal, + !org.wso2.carbon.device.mgt.input.adapter.thrift.internal.*, + org.wso2.carbon.device.mgt.input.adapter.thrift.*, + + + org.wso2.carbon.event.input.adapter.core, + org.wso2.carbon.event.input.adapter.core.*, + !javax.xml.namespace, + javax.xml.namespace; version=0.0.0, + org.apache.commons.logging, + org.osgi.framework, + org.osgi.service.component, + org.wso2.carbon.context, + org.wso2.carbon.databridge.commons, + org.wso2.carbon.databridge.core, + org.wso2.carbon.event.input.adapter.wso2event, + org.apache.axis2.context, + org.wso2.carbon.core.multitenancy.utils, + org.wso2.carbon.utils + + + + + + + + + + + + diff --git a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/src/main/java/org/wso2/carbon/device/mgt/input/adapter/thrift/ThriftAdapter.java b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/src/main/java/org/wso2/carbon/device/mgt/input/adapter/thrift/ThriftAdapter.java new file mode 100644 index 000000000..5210f2030 --- /dev/null +++ b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/src/main/java/org/wso2/carbon/device/mgt/input/adapter/thrift/ThriftAdapter.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy + * of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.wso2.carbon.device.mgt.input.adapter.thrift; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.input.adapter.thrift.internal.ThriftEventAdapterServiceHolder; +import org.wso2.carbon.event.input.adapter.core.EventAdapterConstants; +import org.wso2.carbon.event.input.adapter.core.InputEventAdapter; +import org.wso2.carbon.event.input.adapter.core.InputEventAdapterConfiguration; +import org.wso2.carbon.event.input.adapter.core.InputEventAdapterListener; +import org.wso2.carbon.event.input.adapter.core.exception.InputEventAdapterException; +import org.wso2.carbon.event.input.adapter.core.exception.TestConnectionNotSupportedException; + +import java.util.Map; + +public final class ThriftAdapter implements InputEventAdapter { + + private static final Log log = LogFactory.getLog(ThriftAdapter.class); + private final InputEventAdapterConfiguration eventAdapterConfiguration; + private final Map globalProperties; + private InputEventAdapterListener eventAdaptorListener; + + public ThriftAdapter(InputEventAdapterConfiguration eventAdapterConfiguration, + Map globalProperties) { + this.eventAdapterConfiguration = eventAdapterConfiguration; + this.globalProperties = globalProperties; + } + + @Override + public void init(InputEventAdapterListener eventAdaptorListener) throws InputEventAdapterException { + this.eventAdaptorListener = eventAdaptorListener; + } + + @Override + public void testConnect() throws TestConnectionNotSupportedException { + throw new TestConnectionNotSupportedException("not-supported"); + } + + @Override + public void connect() { + String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true); + String streamId = eventAdapterConfiguration.getInputStreamIdOfWso2eventMessageFormat(); + ThriftEventAdapterServiceHolder.registerAdapterService(tenantDomain, streamId, this); + } + + @Override + public void disconnect() { + String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true); + String streamId = eventAdapterConfiguration.getInputStreamIdOfWso2eventMessageFormat(); + ThriftEventAdapterServiceHolder.unregisterAdapterService(tenantDomain, streamId, this); + } + + @Override + public void destroy() { + + } + + @Override + public boolean isEventDuplicatedInCluster() { + return Boolean.parseBoolean(eventAdapterConfiguration.getProperties().get( + EventAdapterConstants.EVENTS_DUPLICATED_IN_CLUSTER)); + } + + @Override + public boolean isPolling() { + return false; + } + + public String getEventAdapterName() { + return eventAdapterConfiguration.getName(); + } + + public InputEventAdapterListener getEventAdaptorListener() { + return eventAdaptorListener; + } +} diff --git a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/src/main/java/org/wso2/carbon/device/mgt/input/adapter/thrift/ThriftEventAdapterFactory.java b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/src/main/java/org/wso2/carbon/device/mgt/input/adapter/thrift/ThriftEventAdapterFactory.java new file mode 100644 index 000000000..b6a421718 --- /dev/null +++ b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/src/main/java/org/wso2/carbon/device/mgt/input/adapter/thrift/ThriftEventAdapterFactory.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy + * of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.wso2.carbon.device.mgt.input.adapter.thrift; + + +import org.wso2.carbon.event.input.adapter.core.InputEventAdapter; +import org.wso2.carbon.event.input.adapter.core.InputEventAdapterConfiguration; +import org.wso2.carbon.event.input.adapter.wso2event.WSO2EventEventAdapterFactory; + +import java.util.Map; + +/** + * The WSO2Event adapter factory class to create a WSO2Event input adapter + */ +public class ThriftEventAdapterFactory extends WSO2EventEventAdapterFactory { + private static final String ADAPTER_TYPE_THRIFT = "iot-event"; + + @Override + public String getType() { + return ADAPTER_TYPE_THRIFT; + } + + @Override + public InputEventAdapter createEventAdapter(InputEventAdapterConfiguration eventAdapterConfiguration, + Map globalProperties) { + return new ThriftAdapter(eventAdapterConfiguration, globalProperties); + } + +} diff --git a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/src/main/java/org/wso2/carbon/device/mgt/input/adapter/thrift/internal/ThriftEventAdapterServiceComponent.java b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/src/main/java/org/wso2/carbon/device/mgt/input/adapter/thrift/internal/ThriftEventAdapterServiceComponent.java new file mode 100644 index 000000000..ad18ff6d1 --- /dev/null +++ b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/src/main/java/org/wso2/carbon/device/mgt/input/adapter/thrift/internal/ThriftEventAdapterServiceComponent.java @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy + * of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.wso2.carbon.device.mgt.input.adapter.thrift.internal; + +import org.apache.axis2.context.ConfigurationContext; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.osgi.service.component.ComponentContext; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.core.multitenancy.utils.TenantAxisUtils; +import org.wso2.carbon.databridge.commons.Credentials; +import org.wso2.carbon.databridge.commons.Event; +import org.wso2.carbon.databridge.commons.StreamDefinition; +import org.wso2.carbon.databridge.core.AgentCallback; +import org.wso2.carbon.databridge.core.DataBridgeSubscriberService; +import org.wso2.carbon.device.mgt.input.adapter.thrift.ThriftAdapter; +import org.wso2.carbon.event.input.adapter.core.InputEventAdapterFactory; +import org.wso2.carbon.device.mgt.input.adapter.thrift.ThriftEventAdapterFactory; +import org.wso2.carbon.utils.ConfigurationContextService; +import org.wso2.carbon.utils.multitenancy.MultitenantConstants; + +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; + + +/** + * @scr.component name="input.wso2EventAdapterService.component" immediate="true" + * @scr.reference name="agentserverservice.service" + * interface="org.wso2.carbon.databridge.core.DataBridgeSubscriberService" cardinality="1..1" + * policy="dynamic" bind="setDataBridgeSubscriberService" unbind="unSetDataBridgeSubscriberService" + * @scr.reference name="config.context.service" + * interface="org.wso2.carbon.utils.ConfigurationContextService" + * cardinality="1..1" policy="dynamic" bind="setConfigurationContextService" + * unbind="unsetConfigurationContextService" + */ + + +public class ThriftEventAdapterServiceComponent { + + private static final Log log = LogFactory.getLog(ThriftEventAdapterServiceComponent.class); + + /** + * initialize the agent service here service here. + * + * @param context + */ + + + protected void activate(ComponentContext context) { + + try { + InputEventAdapterFactory wso2EventEventAdapterFactory = new ThriftEventAdapterFactory(); + context.getBundleContext().registerService(InputEventAdapterFactory.class.getName(), wso2EventEventAdapterFactory, null); + if (log.isDebugEnabled()) { + log.debug("Successfully deployed the input WSO2Event adapter service"); + } + } catch (RuntimeException e) { + log.error("Can not create the input WSO2Event adapter service ", e); + } + } + + protected void setDataBridgeSubscriberService( + DataBridgeSubscriberService dataBridgeSubscriberService) { + if (ThriftEventAdapterServiceHolder.getDataBridgeSubscriberService() == null) { + ThriftEventAdapterServiceHolder.registerDataBridgeSubscriberService(dataBridgeSubscriberService); + + dataBridgeSubscriberService.subscribe(new AgentCallback() { + @Override + public void definedStream(StreamDefinition streamDefinition, int i) { + + } + + @Override + public void removeStream(StreamDefinition streamDefinition, int i) { + + } + + @Override + public void receive(List events, Credentials credentials) { + try { + PrivilegedCarbonContext.startTenantFlow(); + String tenantDomain = getTenantDomain(events, credentials); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true); + if (!tenantDomain.equalsIgnoreCase(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { + TenantAxisUtils.getTenantConfigurationContext(tenantDomain, ThriftEventAdapterServiceHolder + .getConfigurationContext()); + } + for (Event event : events) { + ConcurrentHashMap adapters = ThriftEventAdapterServiceHolder + .getAdapterService(tenantDomain, event.getStreamId()); + if (adapters != null) { + event = getStrippedEvent(event, credentials); + for (ThriftAdapter adapter : adapters.values()) { + adapter.getEventAdaptorListener().onEvent(event); + } + } + if (log.isDebugEnabled()) { + log.debug("Event received in wso2Event Adapter - " + event); + } + } + } finally { + PrivilegedCarbonContext.endTenantFlow(); + } + } + }); + } + } + + protected void unSetDataBridgeSubscriberService( + DataBridgeSubscriberService dataBridgeSubscriberService) { + + } + + protected void setConfigurationContextService(ConfigurationContextService contextService) { + ConfigurationContext serverConfigContext = contextService.getServerConfigContext(); + ThriftEventAdapterServiceHolder.setConfigurationContext(serverConfigContext); + } + + protected void unsetConfigurationContextService(ConfigurationContextService contextService) { + ThriftEventAdapterServiceHolder.setConfigurationContext(null); + } + + private String getTenantDomain(List events, Credentials credentials) { + Object[] objects = events.get(0).getMetaData(); + String tenantDomain = credentials.getDomainName(); + if (objects != null && objects.length > 0) { + if (tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { + String[] splitValues = ((String) objects[0]).split("@@"); + if (splitValues.length > 1) { + tenantDomain = splitValues[0]; + } + } + } + return tenantDomain; + + } + + private Event getStrippedEvent (Event event, Credentials credentials) { + Object[] objects = event.getMetaData(); + String tenantDomain = credentials.getDomainName(); + if (objects != null && objects.length > 0) { + if (tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { + String[] splitValues = ((String) objects[0]).split("@"); + if (splitValues.length > 1) { + event.getMetaData()[0] = splitValues[1]; + } + } + } + return event; + + } + + + +} diff --git a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/src/main/java/org/wso2/carbon/device/mgt/input/adapter/thrift/internal/ThriftEventAdapterServiceHolder.java b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/src/main/java/org/wso2/carbon/device/mgt/input/adapter/thrift/internal/ThriftEventAdapterServiceHolder.java new file mode 100644 index 000000000..330ef86c6 --- /dev/null +++ b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/src/main/java/org/wso2/carbon/device/mgt/input/adapter/thrift/internal/ThriftEventAdapterServiceHolder.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy + * of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.wso2.carbon.device.mgt.input.adapter.thrift.internal; + +import org.apache.axis2.context.ConfigurationContext; +import org.wso2.carbon.databridge.core.DataBridgeSubscriberService; +import org.wso2.carbon.device.mgt.input.adapter.thrift.ThriftAdapter; + +import java.util.concurrent.ConcurrentHashMap; + +/** + * common place to hold some OSGI bundle references. + */ +public final class ThriftEventAdapterServiceHolder { + + private static DataBridgeSubscriberService dataBridgeSubscriberService; + private static ConfigurationContext configurationContext; + + private static ConcurrentHashMap>> + inputEventAdapterListenerMap = + new ConcurrentHashMap>>(); + + private ThriftEventAdapterServiceHolder() { + } + + public static void registerDataBridgeSubscriberService( + DataBridgeSubscriberService dataBridgeSubscriberService) { + ThriftEventAdapterServiceHolder.dataBridgeSubscriberService = dataBridgeSubscriberService; + } + + public static DataBridgeSubscriberService getDataBridgeSubscriberService() { + return dataBridgeSubscriberService; + } + + public static synchronized void registerAdapterService(String tenantDomain, String streamId, + ThriftAdapter thriftAdapter) { + + ConcurrentHashMap> + tenantSpecificInputEventAdapterListenerMap = inputEventAdapterListenerMap.get(tenantDomain); + + if (tenantSpecificInputEventAdapterListenerMap == null) { + tenantSpecificInputEventAdapterListenerMap = + new ConcurrentHashMap>(); + inputEventAdapterListenerMap.put(tenantDomain, tenantSpecificInputEventAdapterListenerMap); + } + ConcurrentHashMap streamSpecificInputEventAdapterListenerMap = + tenantSpecificInputEventAdapterListenerMap.get(streamId); + if (streamSpecificInputEventAdapterListenerMap == null) { + streamSpecificInputEventAdapterListenerMap = new ConcurrentHashMap(); + tenantSpecificInputEventAdapterListenerMap.put(streamId, streamSpecificInputEventAdapterListenerMap); + } + streamSpecificInputEventAdapterListenerMap.put(thriftAdapter.getEventAdapterName(), thriftAdapter); + + + } + + public static void unregisterAdapterService(String tenantDomain, String streamId, + ThriftAdapter thriftAdapter) { + ConcurrentHashMap> + tenantSpecificInputEventAdapterListenerMap = inputEventAdapterListenerMap.get(tenantDomain); + + if (tenantSpecificInputEventAdapterListenerMap != null) { + ConcurrentHashMap streamSpecificInputEventAdapterListenerMap = + tenantSpecificInputEventAdapterListenerMap.get(streamId); + if (streamSpecificInputEventAdapterListenerMap != null) { + streamSpecificInputEventAdapterListenerMap.remove(thriftAdapter.getEventAdapterName()); + } + } + } + + public static ConcurrentHashMap getAdapterService(String tenantDomain, String streamId) { + ConcurrentHashMap> + tenantSpecificInputEventAdapterListenerMap = inputEventAdapterListenerMap.get(tenantDomain); + if (tenantSpecificInputEventAdapterListenerMap != null) { + return tenantSpecificInputEventAdapterListenerMap.get(streamId); + } + return null; + } + + public static ConfigurationContext getConfigurationContext() { + return configurationContext; + } + + public static void setConfigurationContext(ConfigurationContext configurationContext) { + ThriftEventAdapterServiceHolder.configurationContext = configurationContext; + } +} diff --git a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/src/main/resources/org/wso2/carbon/device/mgt/input/adapter/thrift/Resources.properties b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/src/main/resources/org/wso2/carbon/device/mgt/input/adapter/thrift/Resources.properties new file mode 100644 index 000000000..576d9cc65 --- /dev/null +++ b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/src/main/resources/org/wso2/carbon/device/mgt/input/adapter/thrift/Resources.properties @@ -0,0 +1,25 @@ +# +# Copyright (c) 2005-2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +# +# WSO2 Inc. licenses this file to you under the Apache License, +# Version 2.0 (the "License"); you may not use this file except +# in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +stream=Stream Name +version=Stream Version +events.duplicated.in.cluster=Is events duplicated in cluster +events.duplicated.in.cluster.hint=This depends on how events are published to the server, 'true' only if multiple receiver URLs are defined in different receiver groups ({}). +wso2event.usage.tips_prefix=Following url formats are used to receive events
For load-balancing: use "," to separate values for multiple endpoints
   Eg: {tcp://<hostname>:<port>,tcp://<hostname>:<port>, ...}

For failover: use "|" to separate multiple endpoints
   Eg: {tcp://<hostname>:<port>|tcp://<hostname>:<port>| ...}

For more than one cluster: use "{}" to separate multiple clusters
   Eg: {tcp://<hostname>:<port>|tcp://<hostname>:<port>| ...},{tcp://<hostname>:<port>}

Ports available for Thrift protocol - TCP port: +wso2event.usage.tips_in_between= or SSL port: +wso2event.usage.tips_postfix=
Ports available for Binary protocol - TCP port: diff --git a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket.endpoint/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/endpoint/TenantSubscriptionEndpoint.java b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket.endpoint/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/endpoint/TenantSubscriptionEndpoint.java index 099200c46..2e8ec6192 100644 --- a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket.endpoint/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/endpoint/TenantSubscriptionEndpoint.java +++ b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.websocket.endpoint/src/main/java/org/wso2/carbon/device/mgt/output/adapter/websocket/endpoint/TenantSubscriptionEndpoint.java @@ -77,7 +77,8 @@ public class TenantSubscriptionEndpoint extends SubscriptionEndpoint { if (isAuthorized) { try { PrivilegedCarbonContext.startTenantFlow(); - PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tdomain, true); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(authenticationInfo.getTenantDomain() + , true); ServiceHolder.getInstance().getWebsocketOutputCallbackControllerService().subscribeWebsocket(streamName , version, session); } finally { diff --git a/components/extensions/cdmf-transport-adapters/pom.xml b/components/extensions/cdmf-transport-adapters/pom.xml index 18e368ce2..d5707972e 100644 --- a/components/extensions/cdmf-transport-adapters/pom.xml +++ b/components/extensions/cdmf-transport-adapters/pom.xml @@ -37,6 +37,7 @@ input/org.wso2.carbon.device.mgt.input.adapter.http input/org.wso2.carbon.device.mgt.input.adapter.mqtt input/org.wso2.carbon.device.mgt.input.adapter.xmpp + input/org.wso2.carbon.device.mgt.input.adapter.thrift output/org.wso2.carbon.device.mgt.output.adapter.mqtt output/org.wso2.carbon.device.mgt.output.adapter.xmpp output/org.wso2.carbon.device.mgt.output.adapter.websocket diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.analytics/src/main/resources/carbonapps/Android-Agent-Event-Receiver_1.0.0/android_agent_event_receiver.xml b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.analytics/src/main/resources/carbonapps/Android-Agent-Event-Receiver_1.0.0/android_agent_event_receiver.xml index 977e9a38c..7e4820744 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.analytics/src/main/resources/carbonapps/Android-Agent-Event-Receiver_1.0.0/android_agent_event_receiver.xml +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.analytics/src/main/resources/carbonapps/Android-Agent-Event-Receiver_1.0.0/android_agent_event_receiver.xml @@ -18,7 +18,7 @@ --> - + false diff --git a/features/device-types-feature/androidsense-plugin-feature/org.wso2.carbon.device.mgt.iot.androidsense.analytics.feature/src/main/resources/receiver/android_sense_receiver-carbon.super.xml b/features/device-types-feature/androidsense-plugin-feature/org.wso2.carbon.device.mgt.iot.androidsense.analytics.feature/src/main/resources/receiver/android_sense_receiver-carbon.super.xml index 727aea028..028b69a41 100644 --- a/features/device-types-feature/androidsense-plugin-feature/org.wso2.carbon.device.mgt.iot.androidsense.analytics.feature/src/main/resources/receiver/android_sense_receiver-carbon.super.xml +++ b/features/device-types-feature/androidsense-plugin-feature/org.wso2.carbon.device.mgt.iot.androidsense.analytics.feature/src/main/resources/receiver/android_sense_receiver-carbon.super.xml @@ -20,7 +20,6 @@ carbon.super/android_sense/+/data - android_sense_receiver-carbon.super diff --git a/features/device-types-feature/androidsense-plugin-feature/org.wso2.carbon.device.mgt.iot.androidsense.backend.feature/src/main/resources/receiver/android_sense_receiver.xml b/features/device-types-feature/androidsense-plugin-feature/org.wso2.carbon.device.mgt.iot.androidsense.backend.feature/src/main/resources/receiver/android_sense_receiver.xml index 3faeedaf0..d5bb810bc 100644 --- a/features/device-types-feature/androidsense-plugin-feature/org.wso2.carbon.device.mgt.iot.androidsense.backend.feature/src/main/resources/receiver/android_sense_receiver.xml +++ b/features/device-types-feature/androidsense-plugin-feature/org.wso2.carbon.device.mgt.iot.androidsense.backend.feature/src/main/resources/receiver/android_sense_receiver.xml @@ -20,7 +20,6 @@ ${tenant-domain}/android_sense/+/data - android_sense_receiver-${tenant-domain} diff --git a/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.analytics.feature/src/main/resources/receiver/raspberrypi_receiver-carbon.super.xml b/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.analytics.feature/src/main/resources/receiver/raspberrypi_receiver-carbon.super.xml index 0d8b2fd7a..11cc1d962 100644 --- a/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.analytics.feature/src/main/resources/receiver/raspberrypi_receiver-carbon.super.xml +++ b/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.analytics.feature/src/main/resources/receiver/raspberrypi_receiver-carbon.super.xml @@ -19,7 +19,6 @@ carbon.super/raspberrypi/+/temperature - raspberrypi_receiver-carbon.super diff --git a/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.backend.feature/src/main/resources/receiver/raspberrypi_receiver.xml b/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.backend.feature/src/main/resources/receiver/raspberrypi_receiver.xml index 331a954e8..aff61431d 100644 --- a/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.backend.feature/src/main/resources/receiver/raspberrypi_receiver.xml +++ b/features/device-types-feature/raspberrypi-plugin-feature/org.wso2.carbon.device.mgt.iot.raspberrypi.backend.feature/src/main/resources/receiver/raspberrypi_receiver.xml @@ -19,7 +19,6 @@ ${tenant-domain}/raspberrypi/+/temperature - raspberrypi_receiver-${tenant-domain} diff --git a/features/device-types-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics.feature/src/main/resources/receiver/virtualfirealarm_receiver-carbon.super.xml b/features/device-types-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics.feature/src/main/resources/receiver/virtualfirealarm_receiver-carbon.super.xml index efd5dde7b..21910b4b6 100644 --- a/features/device-types-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics.feature/src/main/resources/receiver/virtualfirealarm_receiver-carbon.super.xml +++ b/features/device-types-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics.feature/src/main/resources/receiver/virtualfirealarm_receiver-carbon.super.xml @@ -19,7 +19,6 @@ carbon.super/virtual_firealarm/+/temperature - virtualfirealarm_receiver-carbon.super diff --git a/features/device-types-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.backend.feature/src/main/resources/receiver/virtualfirealarm_receiver.xml b/features/device-types-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.backend.feature/src/main/resources/receiver/virtualfirealarm_receiver.xml index eea9bb117..98ee47d86 100644 --- a/features/device-types-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.backend.feature/src/main/resources/receiver/virtualfirealarm_receiver.xml +++ b/features/device-types-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.backend.feature/src/main/resources/receiver/virtualfirealarm_receiver.xml @@ -19,7 +19,6 @@ ${tenant-domain}/virtual_firealarm/+/temperature - virtualfirealarm_receiver-${tenant-domain} diff --git a/features/extensions-feature/org.wso2.carbon.device.mgt.adapter.feature/pom.xml b/features/extensions-feature/org.wso2.carbon.device.mgt.adapter.feature/pom.xml index 526334471..5e6165737 100644 --- a/features/extensions-feature/org.wso2.carbon.device.mgt.adapter.feature/pom.xml +++ b/features/extensions-feature/org.wso2.carbon.device.mgt.adapter.feature/pom.xml @@ -64,6 +64,14 @@ org.wso2.carbon.devicemgt-plugins org.wso2.carbon.device.mgt.input.adapter.xmpp + + org.wso2.carbon.devicemgt-plugins + org.wso2.carbon.device.mgt.input.adapter.thrift + + + org.wso2.carbon.analytics-common + org.wso2.carbon.event.input.adapter.wso2event + com.jayway.jsonpath json-path @@ -174,12 +182,19 @@ org.wso2.carbon.devicemgt-plugins:org.wso2.carbon.device.mgt.input.adapter.mqtt:${carbon.devicemgt.plugins.version} + + org.wso2.carbon.devicemgt-plugins:org.wso2.carbon.device.mgt.input.adapter.thrift:${carbon.devicemgt.plugins.version} + + + org.wso2.carbon.analytics-common:org.wso2.carbon.event.input.adapter.wso2event:${carbon.analytics.common.version} + org.wso2.carbon.devicemgt-plugins:org.wso2.carbon.device.mgt.input.adapter.xmpp:${carbon.devicemgt.plugins.version} org.wso2.carbon.devicemgt-plugins:org.wso2.carbon.device.mgt.output.adapter.websocket:${carbon.devicemgt.plugins.version} + org.eclipse.paho:org.eclipse.paho.client.mqttv3:${eclipse.paho.version} diff --git a/pom.xml b/pom.xml index 3c5d5b531..b3d7b36fd 100644 --- a/pom.xml +++ b/pom.xml @@ -355,6 +355,11 @@ org.wso2.carbon.event.output.adapter.core ${carbon.analytics.common.version} + + org.wso2.carbon.analytics-common + org.wso2.carbon.event.input.adapter.wso2event + ${carbon.analytics.common.version} + org.wso2.carbon.analytics-common org.wso2.carbon.event.input.adapter.core @@ -365,6 +370,21 @@ org.wso2.carbon.databridge.commons ${carbon.analytics.common.version} + + org.wso2.carbon.analytics-common + org.wso2.carbon.databridge.commons.thrift + ${carbon.analytics.common.version} + + + org.wso2.carbon.analytics-common + org.wso2.carbon.databridge.commons.binary + ${carbon.analytics.common.version} + + + org.wso2.carbon.analytics-common + org.wso2.carbon.databridge.core + ${carbon.analytics.common.version} + org.wso2.carbon.analytics org.wso2.carbon.analytics.api @@ -387,6 +407,11 @@ org.wso2.carbon.device.mgt.output.adapter.mqtt ${carbon.devicemgt.plugins.version} + + org.wso2.carbon.devicemgt-plugins + org.wso2.carbon.device.mgt.input.adapter.thrift + ${carbon.devicemgt.plugins.version} + org.wso2.carbon.devicemgt-plugins org.wso2.carbon.device.mgt.output.adapter.xmpp From 1b4de09d7b62ea3776fb673d95ffdc53cbcb0205 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Mon, 29 May 2017 12:11:31 +0530 Subject: [PATCH 3/6] added missing imports --- .../org.wso2.carbon.device.mgt.input.adapter.thrift/pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/pom.xml b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/pom.xml index 6c1d4d94e..a994c8d91 100644 --- a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/pom.xml +++ b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/pom.xml @@ -119,7 +119,8 @@ org.wso2.carbon.event.input.adapter.wso2event, org.apache.axis2.context, org.wso2.carbon.core.multitenancy.utils, - org.wso2.carbon.utils + org.wso2.carbon.utils, + org.wso2.carbon.utils.multitenancy From aaeac03cfbc4912ccfaabc4cb4f882089745f94f Mon Sep 17 00:00:00 2001 From: ayyoob Date: Tue, 30 May 2017 00:04:49 +0530 Subject: [PATCH 4/6] fixed issues in mqtt input adapter and thrift adapter after testing with multitenancy --- .../mgt/input/adapter/mqtt/util/MQTTAdapterListener.java | 6 ++++++ .../internal/ThriftEventAdapterServiceComponent.java | 2 +- .../authorization/DeviceAccessBasedMQTTAuthorizer.java | 8 +++----- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/input/adapter/mqtt/util/MQTTAdapterListener.java b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/input/adapter/mqtt/util/MQTTAdapterListener.java index 635012538..e6e9fe700 100644 --- a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/input/adapter/mqtt/util/MQTTAdapterListener.java +++ b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/input/adapter/mqtt/util/MQTTAdapterListener.java @@ -206,8 +206,14 @@ public class MQTTAdapterListener implements MqttCallback, Runnable { } try { mqttClient.subscribe(topic); + log.info("mqtt receiver subscribed to topic: " + topic); } catch (MqttException e) { log.error("Failed to subscribe to topic: " + topic + ", Retrying....."); + try { + mqttClient.disconnect(); + } catch (MqttException ex) { + // do nothing. + } return false; } return true; diff --git a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/src/main/java/org/wso2/carbon/device/mgt/input/adapter/thrift/internal/ThriftEventAdapterServiceComponent.java b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/src/main/java/org/wso2/carbon/device/mgt/input/adapter/thrift/internal/ThriftEventAdapterServiceComponent.java index ad18ff6d1..4d85851a2 100644 --- a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/src/main/java/org/wso2/carbon/device/mgt/input/adapter/thrift/internal/ThriftEventAdapterServiceComponent.java +++ b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/src/main/java/org/wso2/carbon/device/mgt/input/adapter/thrift/internal/ThriftEventAdapterServiceComponent.java @@ -137,7 +137,7 @@ public class ThriftEventAdapterServiceComponent { String tenantDomain = credentials.getDomainName(); if (objects != null && objects.length > 0) { if (tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { - String[] splitValues = ((String) objects[0]).split("@@"); + String[] splitValues = ((String) objects[0]).split("@"); if (splitValues.length > 1) { tenantDomain = splitValues[0]; } diff --git a/components/extensions/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/DeviceAccessBasedMQTTAuthorizer.java b/components/extensions/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/DeviceAccessBasedMQTTAuthorizer.java index e158c726e..568c567ec 100644 --- a/components/extensions/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/DeviceAccessBasedMQTTAuthorizer.java +++ b/components/extensions/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/DeviceAccessBasedMQTTAuthorizer.java @@ -72,7 +72,7 @@ public class DeviceAccessBasedMQTTAuthorizer implements IAuthorizer { private static final String UI_EXECUTE = "ui.execute"; private static Log log = LogFactory.getLog(DeviceAccessBasedMQTTAuthorizer.class); - AuthorizationConfigurationManager MQTTAuthorizationConfiguration; + private AuthorizationConfigurationManager MQTTAuthorizationConfiguration; private static final String CDMF_SERVER_BASE_CONTEXT = "/api/device-mgt/v1.0"; private static final String CACHE_MANAGER_NAME = "mqttAuthorizationCacheManager"; private static final String CACHE_NAME = "mqttAuthorizationCache"; @@ -173,17 +173,15 @@ public class DeviceAccessBasedMQTTAuthorizer implements IAuthorizer { } catch (FeignException e) { oAuthRequestInterceptor.resetApiApplicationKey(); if (e.getMessage().contains(GATEWAY_ERROR_CODE)) { - log.error("Failed to connect to the device authorization service."); + log.error("Failed to connect to the device authorization service.", e); } else { log.error(e.getMessage(), e); } - log.error(e.getMessage(), e); } + return false; } finally { PrivilegedCarbonContext.endTenantFlow(); } - - return false; } /** From 94d626ca3cd0dd10ed3a9f8079844bceacc78af3 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Tue, 30 May 2017 00:31:04 +0530 Subject: [PATCH 5/6] changed event definition --- .../Android-Agent-ExecutionPlan.siddhiql | 4 ++-- .../org.wso2.android.agent.Stream_1.0.0.json | 6 ++++-- .../android/services/impl/EventReceiverServiceImpl.java | 8 +++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.analytics/src/main/resources/carbonapps/Android-Agent-ExecutionPlan/Android-Agent-ExecutionPlan.siddhiql b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.analytics/src/main/resources/carbonapps/Android-Agent-ExecutionPlan/Android-Agent-ExecutionPlan.siddhiql index a7b469131..9b6e0eeb0 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.analytics/src/main/resources/carbonapps/Android-Agent-ExecutionPlan/Android-Agent-ExecutionPlan.siddhiql +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.analytics/src/main/resources/carbonapps/Android-Agent-ExecutionPlan/Android-Agent-ExecutionPlan.siddhiql @@ -9,12 +9,12 @@ @Plan:trace('false') @Import('org.wso2.android.agent.Stream:1.0.0') -define stream dataIn (deviceId string, payload string, type string); +define stream dataIn (meta_deviceId string, payload string, type string); @Export('org.wso2.geo.LocationStream:1.0.0') define stream dataOut (id string, timeStamp long, latitude double, longitude double, type string, speed float, heading float ); from dataIn[type == 'location'] -select deviceId as id, convert(json:getProperty(payload, 'timeStamp'), 'long') as timeStamp, convert(json:getProperty(payload, +select meta_deviceId as id, convert(json:getProperty(payload, 'timeStamp'), 'long') as timeStamp, convert(json:getProperty(payload, 'latitude'), 'double') as latitude, convert(json:getProperty(payload, 'longitude'), 'double') as longitude, 'android' as type, 0.0f as speed, 0.0f as heading insert into dataOut \ No newline at end of file diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.analytics/src/main/resources/carbonapps/org.wso2.android.agent.Stream_1.0.0/org.wso2.android.agent.Stream_1.0.0.json b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.analytics/src/main/resources/carbonapps/org.wso2.android.agent.Stream_1.0.0/org.wso2.android.agent.Stream_1.0.0.json index ed17c58f2..1c8f6b2b6 100755 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.analytics/src/main/resources/carbonapps/org.wso2.android.agent.Stream_1.0.0/org.wso2.android.agent.Stream_1.0.0.json +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.analytics/src/main/resources/carbonapps/org.wso2.android.agent.Stream_1.0.0/org.wso2.android.agent.Stream_1.0.0.json @@ -3,11 +3,13 @@ "version": "1.0.0", "nickName": "", "description": "Stream that receives various types of events from android agent", - "payloadData": [ + "metaData": [ { "name": "deviceId", "type": "STRING" - }, + } + ], + "payloadData": [ { "name": "payload", "type": "STRING" diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/EventReceiverServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/EventReceiverServiceImpl.java index a11c678d0..362289b2c 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/EventReceiverServiceImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/EventReceiverServiceImpl.java @@ -21,6 +21,7 @@ package org.wso2.carbon.mdm.services.android.services.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException; +import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException; import org.wso2.carbon.mdm.services.android.bean.DeviceState; import org.wso2.carbon.mdm.services.android.bean.ErrorResponse; @@ -31,6 +32,7 @@ import org.wso2.carbon.mdm.services.android.exception.UnexpectedServerErrorExcep import org.wso2.carbon.mdm.services.android.services.EventReceiverService; import org.wso2.carbon.mdm.services.android.util.AndroidAPIUtils; import org.wso2.carbon.mdm.services.android.util.Message; +import org.wso2.carbon.utils.multitenancy.MultitenantConstants; import javax.validation.Valid; import javax.validation.constraints.Size; @@ -51,12 +53,12 @@ public class EventReceiverServiceImpl implements EventReceiverService { log.debug("Invoking Android device even logging."); } Message message = new Message(); + Object metaData[] = {eventBeanWrapper.getDeviceIdentifier()}; - Object payload[] = {eventBeanWrapper.getDeviceIdentifier(), eventBeanWrapper.getPayload(), - eventBeanWrapper.getType()}; + Object payload[] = {eventBeanWrapper.getPayload(), eventBeanWrapper.getType()}; try { if (AndroidAPIUtils.getEventPublisherService().publishEvent( - EVENT_STREAM_DEFINITION, "1.0.0", new Object[0], new Object[0], payload)) { + EVENT_STREAM_DEFINITION, "1.0.0", metaData, new Object[0], payload)) { message.setResponseCode("Event is published successfully."); return Response.status(Response.Status.CREATED).entity(message).build(); } else { From ef274b0b3eb3884e85e98a0c648e067a74a49bde Mon Sep 17 00:00:00 2001 From: ayyoob Date: Tue, 30 May 2017 00:38:48 +0530 Subject: [PATCH 6/6] fixed formatting issue --- .../pom.xml | 153 +++++++++--------- 1 file changed, 77 insertions(+), 76 deletions(-) diff --git a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/pom.xml b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/pom.xml index a994c8d91..ad9d9789e 100644 --- a/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/pom.xml +++ b/components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.thrift/pom.xml @@ -16,7 +16,8 @@ ~ specific language governing permissions and limitations ~ under the License. --> - + org.wso2.carbon.devicemgt-plugins @@ -25,91 +26,91 @@ ../../pom.xml - 4.0.0 - org.wso2.carbon.device.mgt.input.adapter.thrift - bundle - WSO2 Carbon - Event Input Thrift Adapter Module - org.wso2.carbon.event.input.adapter.thrift provides the back-end + 4.0.0 + org.wso2.carbon.device.mgt.input.adapter.thrift + bundle + WSO2 Carbon - Event Input Thrift Adapter Module + org.wso2.carbon.event.input.adapter.thrift provides the back-end functionality of input wso2event adapter - http://wso2.org + http://wso2.org - - - org.wso2.carbon.analytics-common - org.wso2.carbon.event.input.adapter.core - + + + org.wso2.carbon.analytics-common + org.wso2.carbon.event.input.adapter.core + org.wso2.carbon.analytics-common org.wso2.carbon.event.input.adapter.wso2event - - org.wso2.carbon - org.wso2.carbon.logging - - - org.wso2.carbon - org.wso2.carbon.core - - - org.wso2.carbon.analytics-common - org.wso2.carbon.databridge.commons - - - org.wso2.carbon.analytics-common - org.wso2.carbon.databridge.commons.thrift - - - org.wso2.carbon.analytics-common - org.wso2.carbon.databridge.commons.binary - - - org.wso2.carbon.analytics-common - org.wso2.carbon.databridge.core - + + org.wso2.carbon + org.wso2.carbon.logging + + + org.wso2.carbon + org.wso2.carbon.core + + + org.wso2.carbon.analytics-common + org.wso2.carbon.databridge.commons + + + org.wso2.carbon.analytics-common + org.wso2.carbon.databridge.commons.thrift + + + org.wso2.carbon.analytics-common + org.wso2.carbon.databridge.commons.binary + + + org.wso2.carbon.analytics-common + org.wso2.carbon.databridge.core + - + - - - - org.apache.felix - maven-scr-plugin - - - generate-scr-descriptor - - scr - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - org.apache.felix - maven-bundle-plugin - true - - - ${project.artifactId} - ${project.artifactId} - + + + + org.apache.felix + maven-scr-plugin + + + generate-scr-descriptor + + scr + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + org.apache.felix + maven-bundle-plugin + true + + + ${project.artifactId} + ${project.artifactId} + org.wso2.carbon.device.mgt.input.adapter.thrift.internal, org.wso2.carbon.device.mgt.input.adapter.thrift.internal.*, - + !org.wso2.carbon.device.mgt.input.adapter.thrift.internal, !org.wso2.carbon.device.mgt.input.adapter.thrift.internal.*, org.wso2.carbon.device.mgt.input.adapter.thrift.*, - - org.wso2.carbon.event.input.adapter.core, - org.wso2.carbon.event.input.adapter.core.*, - !javax.xml.namespace, - javax.xml.namespace; version=0.0.0, + + org.wso2.carbon.event.input.adapter.core, + org.wso2.carbon.event.input.adapter.core.*, + !javax.xml.namespace, + javax.xml.namespace; version=0.0.0, org.apache.commons.logging, org.osgi.framework, org.osgi.service.component, @@ -121,12 +122,12 @@ org.wso2.carbon.core.multitenancy.utils, org.wso2.carbon.utils, org.wso2.carbon.utils.multitenancy - - - - - - + + + + + +