You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2013/12/19 08:50:53 UTC

git commit: Adding missing files from previous commit

Updated Branches:
  refs/heads/master 880c346a1 -> 10231d5a5


Adding missing files from previous commit


Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/10231d5a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/10231d5a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/10231d5a

Branch: refs/heads/master
Commit: 10231d5a59fefb0946419cda0e9cb3e6bb57414e
Parents: 880c346
Author: Imesh Gunaratne <im...@apache.org>
Authored: Thu Dec 19 13:20:35 2013 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Thu Dec 19 13:20:35 2013 +0530

----------------------------------------------------------------------
 .../publisher/StatisticsPublisher.java          |  45 ++++++++
 .../publisher/WSO2CEPStatisticsPublisher.java   | 106 +++++++++++++++++++
 2 files changed, 151 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/10231d5a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/StatisticsPublisher.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/StatisticsPublisher.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/StatisticsPublisher.java
new file mode 100644
index 0000000..cac973f
--- /dev/null
+++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/StatisticsPublisher.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF 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.
+ */
+
+package org.apache.stratos.common.statistics.publisher;
+
+/**
+ *  Statistics publisher interface.
+ */
+public interface StatisticsPublisher {
+
+    /**
+     * Set statistics publisher enabled or disabled.
+     *
+     * @param enabled
+     */
+    void setEnabled(boolean enabled);
+
+    /**
+     * Return enabled state of the statistics publisher.
+     */
+    boolean isEnabled();
+
+    /**
+     * Payload to be published.
+     *
+     * @param payload An array of parameter values.
+     */
+    void publish(Object[] payload);
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/10231d5a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/WSO2CEPStatisticsPublisher.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/WSO2CEPStatisticsPublisher.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/WSO2CEPStatisticsPublisher.java
new file mode 100644
index 0000000..153c511
--- /dev/null
+++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/WSO2CEPStatisticsPublisher.java
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF 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.
+ */
+
+package org.apache.stratos.common.statistics.publisher;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.databridge.agent.thrift.Agent;
+import org.wso2.carbon.databridge.agent.thrift.AsyncDataPublisher;
+import org.wso2.carbon.databridge.agent.thrift.conf.AgentConfiguration;
+import org.wso2.carbon.databridge.agent.thrift.exception.AgentException;
+import org.wso2.carbon.databridge.commons.Event;
+import org.wso2.carbon.databridge.commons.StreamDefinition;
+
+import java.util.HashMap;
+
+/**
+ * WSO2 CEP statistics publisher.
+ */
+public class WSO2CEPStatisticsPublisher implements StatisticsPublisher {
+    private static final Log log = LogFactory.getLog(WSO2CEPStatisticsPublisher.class);
+
+    private StreamDefinition streamDefinition;
+    private AsyncDataPublisher asyncDataPublisher;
+    private String ip;
+    private String port;
+    private String username;
+    private String password;
+    private boolean enabled = false;
+
+    public WSO2CEPStatisticsPublisher(StreamDefinition streamDefinition) {
+        this.streamDefinition = streamDefinition;
+        this.ip = System.getProperty("thrift.receiver.ip");
+        this.port = System.getProperty("thrift.receiver.port");
+        this.username = "admin";
+        this.password = "admin";
+        String enabledStr = System.getProperty("load.balancer.cep.stats.publisher.enabled");
+        if (StringUtils.isNotBlank(enabledStr)) {
+            enabled = Boolean.getBoolean(enabledStr);
+            if (enabled) {
+                init();
+            }
+        }
+    }
+
+    private void init() {
+        AgentConfiguration agentConfiguration = new AgentConfiguration();
+        Agent agent = new Agent(agentConfiguration);
+
+        // Initialize asynchronous data publisher
+        asyncDataPublisher = new AsyncDataPublisher("tcp://" + ip + ":" + port + "", username, password, agent);
+        asyncDataPublisher.addStreamDefinition(streamDefinition);
+    }
+
+    @Override
+    public void setEnabled(boolean enabled) {
+        this.enabled = enabled;
+        if (this.enabled) {
+            init();
+        }
+    }
+
+    @Override
+    public boolean isEnabled() {
+        return enabled;
+    }
+
+    @Override
+    public void publish(Object[] payload) {
+        if (!isEnabled()) {
+            throw new RuntimeException("Statistics publisher is not enabled");
+        }
+
+        Event event = new Event();
+        event.setPayloadData(payload);
+        event.setArbitraryDataMap(new HashMap<String, String>());
+
+        try {
+            if (log.isDebugEnabled()) {
+                log.debug(String.format("Publishing cep event: [stream] %s [version] %s", streamDefinition.getName(), streamDefinition.getVersion()));
+            }
+            asyncDataPublisher.publish(streamDefinition.getName(), streamDefinition.getVersion(), event);
+        } catch (AgentException e) {
+            if (log.isErrorEnabled()) {
+                log.error(String.format("Could not publish cep event: [stream] %s [version] %s", streamDefinition.getName(), streamDefinition.getVersion()), e);
+            }
+        }
+    }
+}