You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@eagle.apache.org by ha...@apache.org on 2016/11/30 01:38:25 UTC
[1/5] incubator-eagle git commit: [EAGLE-806] Integrate Metric
Process and Persistence with Application Framework
Repository: incubator-eagle
Updated Branches:
refs/heads/master ff2253754 -> 10572c296
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-topology-check/eagle-topology-entity/src/main/java/org/apache/eagle/topology/entity/HdfsServiceTopologyAPIEntity.java
----------------------------------------------------------------------
diff --git a/eagle-topology-check/eagle-topology-entity/src/main/java/org/apache/eagle/topology/entity/HdfsServiceTopologyAPIEntity.java b/eagle-topology-check/eagle-topology-entity/src/main/java/org/apache/eagle/topology/entity/HdfsServiceTopologyAPIEntity.java
index d5ee41e..f39d056 100644
--- a/eagle-topology-check/eagle-topology-entity/src/main/java/org/apache/eagle/topology/entity/HdfsServiceTopologyAPIEntity.java
+++ b/eagle-topology-check/eagle-topology-entity/src/main/java/org/apache/eagle/topology/entity/HdfsServiceTopologyAPIEntity.java
@@ -1,123 +1,123 @@
-/*
- * 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.eagle.topology.entity;
-
-import org.apache.eagle.log.entity.meta.*;
-import org.apache.eagle.topology.TopologyConstants;
-import org.codehaus.jackson.map.annotate.JsonSerialize;
-
-@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
-@Table("hadoop_topology")
-@ColumnFamily("f")
-@Prefix("hdfsservicestatus")
-@Service(TopologyConstants.HDFS_INSTANCE_SERVICE_NAME)
-@TimeSeries(false)
-public class HdfsServiceTopologyAPIEntity extends TopologyBaseAPIEntity {
- @Column("a")
- private String status;
- @Column("b")
- private String configuredCapacityTB;
- @Column("c")
- private String usedCapacityTB;
- @Column("d")
- private String numBlocks;
- @Column("e")
- private String numFailedVolumes;
- @Column("f")
- private long writtenTxidDiff;
- @Column("g")
- private long lastUpdateTime;
- @Column("h")
- private String version;
-
- public long getLastUpdateTime() {
- return lastUpdateTime;
- }
-
- public void setLastUpdateTime(long lastUpdateTime) {
- this.lastUpdateTime = lastUpdateTime;
- valueChanged("lastUpdateTime");
- }
-
- public String getNumFailedVolumes() {
- return numFailedVolumes;
- }
-
- public void setNumFailedVolumes(String numFailedVolumes) {
- this.numFailedVolumes = numFailedVolumes;
- valueChanged("numFailedVolumes");
- }
-
- public String getNumBlocks() {
- return numBlocks;
- }
-
- public void setNumBlocks(String numBlocks) {
- this.numBlocks = numBlocks;
- valueChanged("numBlocks");
- }
-
- public String getStatus() {
- return status;
- }
-
- public void setStatus(String status) {
- this.status = status;
- valueChanged("status");
- }
-
- public String getConfiguredCapacityTB() {
- return configuredCapacityTB;
- }
-
- public void setConfiguredCapacityTB(String configuredCapacityTB) {
- this.configuredCapacityTB = configuredCapacityTB;
- valueChanged("configuredCapacityTB");
- }
-
- public String getUsedCapacityTB() {
- return usedCapacityTB;
- }
-
- public void setUsedCapacityTB(String usedCapacityTB) {
- this.usedCapacityTB = usedCapacityTB;
- valueChanged("usedCapacityTB");
- }
-
- public long getWrittenTxidDiff() {
- return writtenTxidDiff;
- }
-
- public void setWrittenTxidDiff(long writtenTxidDiff) {
- this.writtenTxidDiff = writtenTxidDiff;
- valueChanged("writtenTxidDiff");
- }
-
- public String getVersion() {
- return version;
- }
-
- public void setVersion(String version) {
- this.version = version;
- valueChanged("version");
- }
-
-
-}
-
+/*
+ * 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.eagle.topology.entity;
+
+import org.apache.eagle.log.entity.meta.*;
+import org.apache.eagle.topology.TopologyConstants;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+
+@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+@Table("hadoop_topology")
+@ColumnFamily("f")
+@Prefix("hdfsservicestatus")
+@Service(TopologyConstants.HDFS_INSTANCE_SERVICE_NAME)
+@TimeSeries(false)
+public class HdfsServiceTopologyAPIEntity extends TopologyBaseAPIEntity {
+ @Column("a")
+ private String status;
+ @Column("b")
+ private String configuredCapacityTB;
+ @Column("c")
+ private String usedCapacityTB;
+ @Column("d")
+ private String numBlocks;
+ @Column("e")
+ private String numFailedVolumes;
+ @Column("f")
+ private long writtenTxidDiff;
+ @Column("g")
+ private long lastUpdateTime;
+ @Column("h")
+ private String version;
+
+ public long getLastUpdateTime() {
+ return lastUpdateTime;
+ }
+
+ public void setLastUpdateTime(long lastUpdateTime) {
+ this.lastUpdateTime = lastUpdateTime;
+ valueChanged("lastUpdateTime");
+ }
+
+ public String getNumFailedVolumes() {
+ return numFailedVolumes;
+ }
+
+ public void setNumFailedVolumes(String numFailedVolumes) {
+ this.numFailedVolumes = numFailedVolumes;
+ valueChanged("numFailedVolumes");
+ }
+
+ public String getNumBlocks() {
+ return numBlocks;
+ }
+
+ public void setNumBlocks(String numBlocks) {
+ this.numBlocks = numBlocks;
+ valueChanged("numBlocks");
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ valueChanged("status");
+ }
+
+ public String getConfiguredCapacityTB() {
+ return configuredCapacityTB;
+ }
+
+ public void setConfiguredCapacityTB(String configuredCapacityTB) {
+ this.configuredCapacityTB = configuredCapacityTB;
+ valueChanged("configuredCapacityTB");
+ }
+
+ public String getUsedCapacityTB() {
+ return usedCapacityTB;
+ }
+
+ public void setUsedCapacityTB(String usedCapacityTB) {
+ this.usedCapacityTB = usedCapacityTB;
+ valueChanged("usedCapacityTB");
+ }
+
+ public long getWrittenTxidDiff() {
+ return writtenTxidDiff;
+ }
+
+ public void setWrittenTxidDiff(long writtenTxidDiff) {
+ this.writtenTxidDiff = writtenTxidDiff;
+ valueChanged("writtenTxidDiff");
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ valueChanged("version");
+ }
+
+
+}
+
[2/5] incubator-eagle git commit: [EAGLE-806] Integrate Metric
Process and Persistence with Application Framework
Posted by ha...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/extractor/hbase/HbaseTopologyEntityParser.java
----------------------------------------------------------------------
diff --git a/eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/extractor/hbase/HbaseTopologyEntityParser.java b/eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/extractor/hbase/HbaseTopologyEntityParser.java
index f3eac23..94b3727 100644
--- a/eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/extractor/hbase/HbaseTopologyEntityParser.java
+++ b/eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/extractor/hbase/HbaseTopologyEntityParser.java
@@ -1,165 +1,165 @@
-/*
- * 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.eagle.topology.extractor.hbase;
-
-import org.apache.eagle.app.utils.HadoopSecurityUtil;
-import org.apache.eagle.topology.TopologyCheckAppConfig;
-import org.apache.eagle.topology.TopologyConstants;
-import org.apache.eagle.topology.extractor.TopologyEntityParserResult;
-import org.apache.eagle.topology.entity.HBaseServiceTopologyAPIEntity;
-import org.apache.eagle.topology.extractor.TopologyEntityParser;
-import org.apache.eagle.topology.resolver.TopologyRackResolver;
-import org.apache.eagle.topology.utils.EntityBuilderHelper;
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.ClusterStatus;
-import org.apache.hadoop.hbase.HBaseConfiguration;
-import org.apache.hadoop.hbase.ServerLoad;
-import org.apache.hadoop.hbase.ServerName;
-import org.apache.hadoop.hbase.client.HBaseAdmin;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.apache.eagle.topology.TopologyConstants.*;
-
-public class HbaseTopologyEntityParser implements TopologyEntityParser {
-
- private Configuration hBaseConfiguration;
- private String site;
- private Boolean kerberosEnable = false;
- private TopologyRackResolver rackResolver;
-
- public HbaseTopologyEntityParser(String site, TopologyCheckAppConfig.HBaseConfig hBaseConfig, TopologyRackResolver resolver) {
- this.site = site;
- this.rackResolver = resolver;
- this.hBaseConfiguration = HBaseConfiguration.create();
- this.hBaseConfiguration.set("hbase.zookeeper.quorum", hBaseConfig.zkQuorum);
- this.hBaseConfiguration.set("hbase.zookeeper.property.clientPort", hBaseConfig.zkClientPort);
- this.hBaseConfiguration.set("zookeeper.znode.parent", hBaseConfig.zkRoot);
- this.hBaseConfiguration.set("hbase.client.retries.number", hBaseConfig.zkRetryTimes);
- // kerberos authentication
- if (hBaseConfig.eaglePrincipal != null && hBaseConfig.eagleKeytab != null
- && !hBaseConfig.eaglePrincipal.isEmpty() && !hBaseConfig.eagleKeytab.isEmpty()) {
- this.hBaseConfiguration.set(HadoopSecurityUtil.EAGLE_PRINCIPAL_KEY, hBaseConfig.eaglePrincipal);
- this.hBaseConfiguration.set(HadoopSecurityUtil.EAGLE_KEYTAB_FILE_KEY, hBaseConfig.eagleKeytab);
- this.kerberosEnable = true;
- this.hBaseConfiguration.set("hbase.security.authentication", "kerberos");
- this.hBaseConfiguration.set("hbase.master.kerberos.principal", hBaseConfig.hbaseMasterPrincipal);
- }
- }
-
- private HBaseAdmin getHBaseAdmin() throws IOException {
- if (this.kerberosEnable) {
- HadoopSecurityUtil.login(hBaseConfiguration);
- }
- return new HBaseAdmin(this.hBaseConfiguration);
- }
-
- @Override
- public TopologyEntityParserResult parse(long timestamp) throws IOException {
- long deadServers = 0;
- long liveServers = 0;
- TopologyEntityParserResult result = new TopologyEntityParserResult();
- HBaseAdmin admin = null;
- try {
- admin = getHBaseAdmin();
- ClusterStatus status = admin.getClusterStatus();
- deadServers = status.getDeadServers();
- liveServers = status.getServersSize();
- result.setVersion(HadoopVersion.V2);
- for (ServerName liveServer : status.getServers()) {
- ServerLoad load = status.getLoad(liveServer);
- result.getSlaveNodes().add(parseServer(liveServer, load, TopologyConstants.REGIONSERVER_ROLE, TopologyConstants.REGIONSERVER_LIVE_STATUS, timestamp));
- }
- for (ServerName deadServer : status.getDeadServerNames()) {
- ServerLoad load = status.getLoad(deadServer);
- result.getSlaveNodes().add(parseServer(deadServer, load, TopologyConstants.REGIONSERVER_ROLE, TopologyConstants.REGIONSERVER_DEAD_STATUS, timestamp));
- }
- ServerName master = status.getMaster();
- if (master != null) {
- ServerLoad load = status.getLoad(master);
- result.getMasterNodes().add(parseServer(master, load, TopologyConstants.HMASTER_ROLE, TopologyConstants.HMASTER_ACTIVE_STATUS, timestamp));
- }
- for (ServerName backupMaster : status.getBackupMasters()) {
- ServerLoad load = status.getLoad(backupMaster);
- result.getMasterNodes().add(parseServer(backupMaster, load, TopologyConstants.HMASTER_ROLE, TopologyConstants.HMASTER_STANDBY_STATUS, timestamp));
- }
- double liveRatio = liveServers * 1d / (liveServers + deadServers);
- result.getMetrics().add(EntityBuilderHelper.generateMetric(TopologyConstants.REGIONSERVER_ROLE, liveRatio, site, timestamp));
- result.getMetrics().add(EntityBuilderHelper.generateMetric(TopologyConstants.HMASTER_ROLE, 1d, site, timestamp));
- return result;
- } catch (RuntimeException e) {
- e.printStackTrace();
- } finally {
- if (admin != null) {
- try {
- admin.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- return result;
- }
-
- private HBaseServiceTopologyAPIEntity parseServer(ServerName serverName, ServerLoad serverLoad, String role, String status, long timestamp) {
- if (serverName == null) {
- return null;
- }
- HBaseServiceTopologyAPIEntity entity = createEntity(role, serverName.getHostname(), timestamp);
- parseServerLoad(entity, serverLoad);
- entity.setStatus(status);
- return entity;
- }
-
- private void parseServerLoad(HBaseServiceTopologyAPIEntity entity, ServerLoad load) {
- if (load == null) {
- return;
- }
- entity.setMaxHeapMB(load.getMaxHeapMB());
- entity.setUsedHeapMB(load.getUsedHeapMB());
- entity.setNumRegions(load.getNumberOfRegions());
- entity.setNumRequests(load.getNumberOfRequests());
- }
-
- private HBaseServiceTopologyAPIEntity createEntity(String roleType, String hostname, long timestamp) {
- HBaseServiceTopologyAPIEntity entity = new HBaseServiceTopologyAPIEntity();
- Map<String, String> tags = new HashMap<String, String>();
- entity.setTags(tags);
- tags.put(SITE_TAG, site);
- tags.put(ROLE_TAG, roleType);
- tags.put(HOSTNAME_TAG, hostname);
- String rack = rackResolver.resolve(hostname);
- tags.put(RACK_TAG, rack);
- entity.setLastUpdateTime(timestamp);
- entity.setTimestamp(timestamp);
- return entity;
- }
-
- @Override
- public TopologyConstants.TopologyType getTopologyType() {
- return TopologyType.HBASE;
- }
-
- @Override
- public TopologyConstants.HadoopVersion getHadoopVersion() {
- return HadoopVersion.V2;
- }
-}
+/*
+ * 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.eagle.topology.extractor.hbase;
+
+import org.apache.eagle.app.utils.HadoopSecurityUtil;
+import org.apache.eagle.topology.TopologyCheckAppConfig;
+import org.apache.eagle.topology.TopologyConstants;
+import org.apache.eagle.topology.extractor.TopologyEntityParserResult;
+import org.apache.eagle.topology.entity.HBaseServiceTopologyAPIEntity;
+import org.apache.eagle.topology.extractor.TopologyEntityParser;
+import org.apache.eagle.topology.resolver.TopologyRackResolver;
+import org.apache.eagle.topology.utils.EntityBuilderHelper;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.ClusterStatus;
+import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.ServerLoad;
+import org.apache.hadoop.hbase.ServerName;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.apache.eagle.topology.TopologyConstants.*;
+
+public class HbaseTopologyEntityParser implements TopologyEntityParser {
+
+ private Configuration hBaseConfiguration;
+ private String site;
+ private Boolean kerberosEnable = false;
+ private TopologyRackResolver rackResolver;
+
+ public HbaseTopologyEntityParser(String site, TopologyCheckAppConfig.HBaseConfig hBaseConfig, TopologyRackResolver resolver) {
+ this.site = site;
+ this.rackResolver = resolver;
+ this.hBaseConfiguration = HBaseConfiguration.create();
+ this.hBaseConfiguration.set("hbase.zookeeper.quorum", hBaseConfig.zkQuorum);
+ this.hBaseConfiguration.set("hbase.zookeeper.property.clientPort", hBaseConfig.zkClientPort);
+ this.hBaseConfiguration.set("zookeeper.znode.parent", hBaseConfig.zkRoot);
+ this.hBaseConfiguration.set("hbase.client.retries.number", hBaseConfig.zkRetryTimes);
+ // kerberos authentication
+ if (hBaseConfig.eaglePrincipal != null && hBaseConfig.eagleKeytab != null
+ && !hBaseConfig.eaglePrincipal.isEmpty() && !hBaseConfig.eagleKeytab.isEmpty()) {
+ this.hBaseConfiguration.set(HadoopSecurityUtil.EAGLE_PRINCIPAL_KEY, hBaseConfig.eaglePrincipal);
+ this.hBaseConfiguration.set(HadoopSecurityUtil.EAGLE_KEYTAB_FILE_KEY, hBaseConfig.eagleKeytab);
+ this.kerberosEnable = true;
+ this.hBaseConfiguration.set("hbase.security.authentication", "kerberos");
+ this.hBaseConfiguration.set("hbase.master.kerberos.principal", hBaseConfig.hbaseMasterPrincipal);
+ }
+ }
+
+ private HBaseAdmin getHBaseAdmin() throws IOException {
+ if (this.kerberosEnable) {
+ HadoopSecurityUtil.login(hBaseConfiguration);
+ }
+ return new HBaseAdmin(this.hBaseConfiguration);
+ }
+
+ @Override
+ public TopologyEntityParserResult parse(long timestamp) throws IOException {
+ long deadServers = 0;
+ long liveServers = 0;
+ TopologyEntityParserResult result = new TopologyEntityParserResult();
+ HBaseAdmin admin = null;
+ try {
+ admin = getHBaseAdmin();
+ ClusterStatus status = admin.getClusterStatus();
+ deadServers = status.getDeadServers();
+ liveServers = status.getServersSize();
+ result.setVersion(HadoopVersion.V2);
+ for (ServerName liveServer : status.getServers()) {
+ ServerLoad load = status.getLoad(liveServer);
+ result.getSlaveNodes().add(parseServer(liveServer, load, TopologyConstants.REGIONSERVER_ROLE, TopologyConstants.REGIONSERVER_LIVE_STATUS, timestamp));
+ }
+ for (ServerName deadServer : status.getDeadServerNames()) {
+ ServerLoad load = status.getLoad(deadServer);
+ result.getSlaveNodes().add(parseServer(deadServer, load, TopologyConstants.REGIONSERVER_ROLE, TopologyConstants.REGIONSERVER_DEAD_STATUS, timestamp));
+ }
+ ServerName master = status.getMaster();
+ if (master != null) {
+ ServerLoad load = status.getLoad(master);
+ result.getMasterNodes().add(parseServer(master, load, TopologyConstants.HMASTER_ROLE, TopologyConstants.HMASTER_ACTIVE_STATUS, timestamp));
+ }
+ for (ServerName backupMaster : status.getBackupMasters()) {
+ ServerLoad load = status.getLoad(backupMaster);
+ result.getMasterNodes().add(parseServer(backupMaster, load, TopologyConstants.HMASTER_ROLE, TopologyConstants.HMASTER_STANDBY_STATUS, timestamp));
+ }
+ double liveRatio = liveServers * 1d / (liveServers + deadServers);
+ result.getMetrics().add(EntityBuilderHelper.generateMetric(TopologyConstants.REGIONSERVER_ROLE, liveRatio, site, timestamp));
+ result.getMetrics().add(EntityBuilderHelper.generateMetric(TopologyConstants.HMASTER_ROLE, 1d, site, timestamp));
+ return result;
+ } catch (RuntimeException e) {
+ e.printStackTrace();
+ } finally {
+ if (admin != null) {
+ try {
+ admin.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ return result;
+ }
+
+ private HBaseServiceTopologyAPIEntity parseServer(ServerName serverName, ServerLoad serverLoad, String role, String status, long timestamp) {
+ if (serverName == null) {
+ return null;
+ }
+ HBaseServiceTopologyAPIEntity entity = createEntity(role, serverName.getHostname(), timestamp);
+ parseServerLoad(entity, serverLoad);
+ entity.setStatus(status);
+ return entity;
+ }
+
+ private void parseServerLoad(HBaseServiceTopologyAPIEntity entity, ServerLoad load) {
+ if (load == null) {
+ return;
+ }
+ entity.setMaxHeapMB(load.getMaxHeapMB());
+ entity.setUsedHeapMB(load.getUsedHeapMB());
+ entity.setNumRegions(load.getNumberOfRegions());
+ entity.setNumRequests(load.getNumberOfRequests());
+ }
+
+ private HBaseServiceTopologyAPIEntity createEntity(String roleType, String hostname, long timestamp) {
+ HBaseServiceTopologyAPIEntity entity = new HBaseServiceTopologyAPIEntity();
+ Map<String, String> tags = new HashMap<String, String>();
+ entity.setTags(tags);
+ tags.put(SITE_TAG, site);
+ tags.put(ROLE_TAG, roleType);
+ tags.put(HOSTNAME_TAG, hostname);
+ String rack = rackResolver.resolve(hostname);
+ tags.put(RACK_TAG, rack);
+ entity.setLastUpdateTime(timestamp);
+ entity.setTimestamp(timestamp);
+ return entity;
+ }
+
+ @Override
+ public TopologyConstants.TopologyType getTopologyType() {
+ return TopologyType.HBASE;
+ }
+
+ @Override
+ public TopologyConstants.HadoopVersion getHadoopVersion() {
+ return HadoopVersion.V2;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/extractor/hdfs/HdfsTopologyEntityParser.java
----------------------------------------------------------------------
diff --git a/eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/extractor/hdfs/HdfsTopologyEntityParser.java b/eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/extractor/hdfs/HdfsTopologyEntityParser.java
index 3cb55e9..79277a4 100644
--- a/eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/extractor/hdfs/HdfsTopologyEntityParser.java
+++ b/eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/extractor/hdfs/HdfsTopologyEntityParser.java
@@ -1,290 +1,289 @@
-/*
- * 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.eagle.topology.extractor.hdfs;
-
-import org.apache.eagle.app.utils.PathResolverHelper;
-import org.apache.eagle.topology.TopologyCheckAppConfig;
-import org.apache.eagle.topology.TopologyConstants;
-import org.apache.eagle.topology.extractor.TopologyEntityParserResult;
-import org.apache.eagle.topology.entity.HdfsServiceTopologyAPIEntity;
-import org.apache.eagle.topology.extractor.TopologyEntityParser;
-import org.apache.eagle.topology.resolver.TopologyRackResolver;
-import org.apache.eagle.topology.utils.*;
-
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.json.JSONTokener;
-import org.slf4j.Logger;
-
-import java.io.IOException;
-import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import static org.apache.eagle.topology.TopologyConstants.*;
-import static org.apache.eagle.topology.TopologyConstants.RACK_TAG;
-
-public class HdfsTopologyEntityParser implements TopologyEntityParser {
-
- private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(HdfsTopologyEntityParser.class);
- private String[] namenodeUrls;
- private String site;
- private TopologyRackResolver rackResolver;
-
- private static final String JMX_URL = "/jmx?anonymous=true";
- private static final String JMX_FS_NAME_SYSTEM_BEAN_NAME = "Hadoop:service=NameNode,name=FSNamesystem";
- private static final String JMX_NAMENODE_INFO = "Hadoop:service=NameNode,name=NameNodeInfo";
-
- private static final String HA_STATE = "tag.HAState";
- private static final String HA_NAME = "tag.Hostname";
- private static final String CAPACITY_TOTAL_GB = "CapacityTotalGB";
- private static final String CAPACITY_USED_GB = "CapacityUsedGB";
- private static final String BLOCKS_TOTAL = "BlocksTotal";
- private static final String LIVE_NODES = "LiveNodes";
- private static final String DEAD_NODES = "DeadNodes";
-
- private static final String JN_STATUS = "NameJournalStatus";
- private static final String JN_TRANSACTION_INFO = "JournalTransactionInfo";
- private static final String LAST_TX_ID = "LastAppliedOrWrittenTxId";
-
- private static final String DATA_NODE_NUM_BLOCKS = "numBlocks";
- private static final String DATA_NODE_USED_SPACE = "usedSpace";
- private static final String DATA_NODE_CAPACITY = "capacity";
- private static final String DATA_NODE_ADMIN_STATE = "adminState";
- private static final String DATA_NODE_FAILED_VOLUMN = "volfails";
- private static final String DATA_NODE_VERSION = "version";
- private static final String NAME_NODE_VERSION = "Version";
-
- private static final String DATA_NODE_DECOMMISSIONED = "Decommissioned";
- private static final String DATA_NODE_DECOMMISSIONED_STATE = "decommissioned";
-
- private static final String STATUS_PATTERN = "([\\d\\.]+):\\d+\\s+\\([\\D]+(\\d+)\\)";
- private static final String QJM_PATTERN = "([\\d\\.]+):\\d+";
-
- private static final double TB = 1024 * 1024 * 1024 * 1024;
-
- public HdfsTopologyEntityParser(String site, TopologyCheckAppConfig.HdfsConfig hdfsConfig, TopologyRackResolver rackResolver) {
- this.namenodeUrls = hdfsConfig.namenodeUrls;
- this.site = site;
- this.rackResolver = rackResolver;
- }
-
- @Override
- public TopologyEntityParserResult parse(long timestamp) throws IOException {
- final TopologyEntityParserResult result = new TopologyEntityParserResult();
- result.setVersion(TopologyConstants.HadoopVersion.V2);
- int numNamenode = 0;
- for (String url : namenodeUrls) {
- try {
- final HdfsServiceTopologyAPIEntity namenodeEntity = createNamenodeEntity(url, timestamp);
- result.getMasterNodes().add(namenodeEntity);
- numNamenode++;
- if (namenodeEntity.getStatus().equalsIgnoreCase(NAME_NODE_ACTIVE_STATUS)) {
- String namenodeVersion = createSlaveNodeEntities(url, timestamp, result);
- namenodeEntity.setVersion(namenodeVersion);
- }
- } catch (RuntimeException ex) {
- ex.printStackTrace();
- } catch (IOException e) {
- LOG.warn("Catch an IOException with url: {}", url);
- }
- }
- double value = numNamenode * 1d / namenodeUrls.length;
- result.getMetrics().add(EntityBuilderHelper.generateMetric(TopologyConstants.NAME_NODE_ROLE, value, site, timestamp));
- return result;
- }
-
- private HdfsServiceTopologyAPIEntity createNamenodeEntity(String url, long updateTime) throws JSONException, IOException {
- final String urlString = buildFSNamesystemURL(url);
- final Map<String, JMXBean> jmxBeanMap = JMXQueryHelper.query(urlString);
- final JMXBean bean = jmxBeanMap.get(JMX_FS_NAME_SYSTEM_BEAN_NAME);
-
- if (bean == null || bean.getPropertyMap() == null) {
- throw new ServiceNotResponseException("Invalid JMX format, FSNamesystem bean is null!");
- }
-
- final String hostname = (String) bean.getPropertyMap().get(HA_NAME);
- HdfsServiceTopologyAPIEntity result = createHdfsServiceEntity(TopologyConstants.NAME_NODE_ROLE, hostname, updateTime);
- final String state = (String) bean.getPropertyMap().get(HA_STATE);
- result.setStatus(state);
- final Double configuredCapacityGB = (Double) bean.getPropertyMap().get(CAPACITY_TOTAL_GB);
- result.setConfiguredCapacityTB(Double.toString(configuredCapacityGB / 1024));
- final Double capacityUsedGB = (Double) bean.getPropertyMap().get(CAPACITY_USED_GB);
- result.setUsedCapacityTB(Double.toString(capacityUsedGB / 1024));
- final Integer blocksTotal = (Integer) bean.getPropertyMap().get(BLOCKS_TOTAL);
- result.setNumBlocks(Integer.toString(blocksTotal));
- return result;
- }
-
- private String createSlaveNodeEntities(String url, long updateTime, TopologyEntityParserResult result) throws IOException {
- final String urlString = buildNamenodeInfo(url);
- final Map<String, JMXBean> jmxBeanMap = JMXQueryHelper.query(urlString);
- final JMXBean bean = jmxBeanMap.get(JMX_NAMENODE_INFO);
- if (bean == null || bean.getPropertyMap() == null) {
- throw new ServiceNotResponseException("Invalid JMX format, NameNodeInfo bean is null!");
- }
- createAllDataNodeEntities(bean, updateTime, result);
- createAllJournalNodeEntities(bean, updateTime, result);
- return (String) bean.getPropertyMap().get(NAME_NODE_VERSION);
- }
-
- private void createAllJournalNodeEntities(JMXBean bean, long updateTime, TopologyEntityParserResult result) throws UnknownHostException {
- if (bean.getPropertyMap().get(JN_TRANSACTION_INFO) == null || bean.getPropertyMap().get(JN_STATUS) == null) {
- return;
- }
- String jnInfoString = (String) bean.getPropertyMap().get(JN_TRANSACTION_INFO);
- JSONObject jsonObject = new JSONObject(jnInfoString);
- long lastTxId = Long.parseLong(jsonObject.getString(LAST_TX_ID));
-
- String journalnodeString = (String) bean.getPropertyMap().get(JN_STATUS);
- JSONArray jsonArray = new JSONArray(journalnodeString);
- JSONObject jsonMap = (JSONObject) jsonArray.get(0);
-
- Map<String, HdfsServiceTopologyAPIEntity> journalNodesMap = new HashMap<>();
- String manager = jsonMap.getString("manager");
- Pattern qjm = Pattern.compile(QJM_PATTERN);
- Matcher jpmMatcher = qjm.matcher(manager);
- while (jpmMatcher.find()) {
- String ip = jpmMatcher.group(1);
- String hostname = EntityBuilderHelper.resolveHostByIp(ip);
- HdfsServiceTopologyAPIEntity entity = createHdfsServiceEntity(TopologyConstants.JOURNAL_NODE_ROLE, hostname, updateTime);
- entity.setStatus(TopologyConstants.DATA_NODE_DEAD_STATUS);
- journalNodesMap.put(ip, entity);
- }
- if (journalNodesMap.isEmpty()) {
- LOG.warn("Fail to find journal node info in JMX");
- return;
- }
-
- String stream = jsonMap.getString("stream");
- Pattern status = Pattern.compile(STATUS_PATTERN);
- Matcher statusMatcher = status.matcher(stream);
- long numLiveJournalNodes = 0;
- while (statusMatcher.find()) {
- numLiveJournalNodes++;
- String ip = statusMatcher.group(1);
- if (journalNodesMap.containsKey(ip)) {
- long txid = Long.parseLong(statusMatcher.group(2));
- journalNodesMap.get(ip).setWrittenTxidDiff(lastTxId - txid);
- journalNodesMap.get(ip).setStatus(TopologyConstants.DATA_NODE_LIVE_STATUS);
- }
- }
- result.getMasterNodes().addAll(journalNodesMap.values());
-
- double value = numLiveJournalNodes * 1d / journalNodesMap.size();
- result.getMetrics().add(EntityBuilderHelper.generateMetric(TopologyConstants.JOURNAL_NODE_ROLE, value, site, updateTime));
- }
-
- private void createAllDataNodeEntities(JMXBean bean, long updateTime, TopologyEntityParserResult result) throws JSONException, IOException {
- int numLiveNodes = 0;
- int numLiveDecommNodes = 0;
- int numDeadNodes = 0;
- int numDeadDecommNodes = 0;
-
- String deadNodesStrings = (String) bean.getPropertyMap().get(DEAD_NODES);
- JSONTokener tokener = new JSONTokener(deadNodesStrings);
- JSONObject jsonNodesObject = new JSONObject(tokener);
- final JSONArray deadNodes = jsonNodesObject.names();
- for (int i = 0; deadNodes != null && i < deadNodes.length(); ++i) {
- final String hostname = deadNodes.getString(i);
- final JSONObject deadNode = jsonNodesObject.getJSONObject(hostname);
- HdfsServiceTopologyAPIEntity entity = createHdfsServiceEntity(TopologyConstants.DATA_NODE_ROLE, EntityBuilderHelper.getValidHostName(hostname), updateTime);
- if (deadNode.getBoolean(DATA_NODE_DECOMMISSIONED_STATE)) {
- ++numDeadDecommNodes;
- entity.setStatus(TopologyConstants.DATA_NODE_DEAD_DECOMMISSIONED_STATUS);
- } else {
- entity.setStatus(TopologyConstants.DATA_NODE_DEAD_STATUS);
- }
- ++numDeadNodes;
- result.getSlaveNodes().add(entity);
- }
- LOG.info("Dead nodes " + numDeadNodes + ", dead but decommissioned nodes: " + numDeadDecommNodes);
-
- String liveNodesStrings = (String) bean.getPropertyMap().get(LIVE_NODES);
- tokener = new JSONTokener(liveNodesStrings);
- jsonNodesObject = new JSONObject(tokener);
- final JSONArray liveNodes = jsonNodesObject.names();
- for (int i = 0; liveNodes != null && i < liveNodes.length(); ++i) {
- final String hostname = liveNodes.getString(i);
- final JSONObject liveNode = jsonNodesObject.getJSONObject(hostname);
-
- HdfsServiceTopologyAPIEntity entity = createHdfsServiceEntity(TopologyConstants.DATA_NODE_ROLE, EntityBuilderHelper.getValidHostName(hostname), updateTime);
- final Number configuredCapacity = (Number) liveNode.get(DATA_NODE_CAPACITY);
- entity.setConfiguredCapacityTB(Double.toString(configuredCapacity.doubleValue() / TB));
- final Number capacityUsed = (Number) liveNode.get(DATA_NODE_USED_SPACE);
- entity.setUsedCapacityTB(Double.toString(capacityUsed.doubleValue() / TB));
- final Number blocksTotal = (Number) liveNode.get(DATA_NODE_NUM_BLOCKS);
- entity.setNumBlocks(Double.toString(blocksTotal.doubleValue()));
- if (liveNode.has(DATA_NODE_FAILED_VOLUMN)) {
- final Number volFails = (Number) liveNode.get(DATA_NODE_FAILED_VOLUMN);
- entity.setNumFailedVolumes(Double.toString(volFails.doubleValue()));
- }
- final String adminState = liveNode.getString(DATA_NODE_ADMIN_STATE);
- if (DATA_NODE_DECOMMISSIONED.equalsIgnoreCase(adminState)) {
- ++numLiveDecommNodes;
- entity.setStatus(TopologyConstants.DATA_NODE_LIVE_DECOMMISSIONED_STATUS);
- } else {
- entity.setStatus(TopologyConstants.DATA_NODE_LIVE_STATUS);
- }
- entity.setVersion(String.valueOf(liveNode.get(DATA_NODE_VERSION)));
- numLiveNodes++;
- result.getSlaveNodes().add(entity);
- }
- LOG.info("Live nodes " + numLiveNodes + ", live but decommissioned nodes: " + numLiveDecommNodes);
-
- double value = numLiveNodes * 1.0d / result.getSlaveNodes().size();
- result.getMetrics().add(EntityBuilderHelper.generateMetric(TopologyConstants.DATA_NODE_ROLE, value, site, updateTime));
- }
-
- private HdfsServiceTopologyAPIEntity createHdfsServiceEntity(String roleType, String hostname, long updateTime) {
- HdfsServiceTopologyAPIEntity entity = new HdfsServiceTopologyAPIEntity();
- entity.setTimestamp(updateTime);
- entity.setLastUpdateTime(updateTime);
- Map<String, String> tags = new HashMap<String, String>();
- entity.setTags(tags);
- tags.put(SITE_TAG, site);
- tags.put(ROLE_TAG, roleType);
- tags.put(HOSTNAME_TAG, hostname);
- String rack = rackResolver.resolve(hostname);
- tags.put(RACK_TAG, rack);
- return entity;
- }
-
- private String buildFSNamesystemURL(String url) {
- return PathResolverHelper.buildUrlPath(url, JMX_URL + "&qry=" + JMX_FS_NAME_SYSTEM_BEAN_NAME);
- }
-
- private String buildNamenodeInfo(String url) {
- return PathResolverHelper.buildUrlPath(url, JMX_URL + "&qry=" + JMX_NAMENODE_INFO);
- }
-
- @Override
- public TopologyConstants.TopologyType getTopologyType() {
- return TopologyConstants.TopologyType.HDFS;
- }
-
- @Override
- public TopologyConstants.HadoopVersion getHadoopVersion() {
- return TopologyConstants.HadoopVersion.V2;
- }
-}
+/*
+ * 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.eagle.topology.extractor.hdfs;
+
+import org.apache.eagle.app.utils.PathResolverHelper;
+import org.apache.eagle.topology.TopologyCheckAppConfig;
+import org.apache.eagle.topology.TopologyConstants;
+import org.apache.eagle.topology.extractor.TopologyEntityParserResult;
+import org.apache.eagle.topology.entity.HdfsServiceTopologyAPIEntity;
+import org.apache.eagle.topology.extractor.TopologyEntityParser;
+import org.apache.eagle.topology.resolver.TopologyRackResolver;
+import org.apache.eagle.topology.utils.*;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.json.JSONTokener;
+import org.slf4j.Logger;
+
+import java.io.IOException;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import static org.apache.eagle.topology.TopologyConstants.*;
+import static org.apache.eagle.topology.TopologyConstants.RACK_TAG;
+
+public class HdfsTopologyEntityParser implements TopologyEntityParser {
+
+ private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(HdfsTopologyEntityParser.class);
+ private String[] namenodeUrls;
+ private String site;
+ private TopologyRackResolver rackResolver;
+
+ private static final String JMX_URL = "/jmx?anonymous=true";
+ private static final String JMX_FS_NAME_SYSTEM_BEAN_NAME = "Hadoop:service=NameNode,name=FSNamesystem";
+ private static final String JMX_NAMENODE_INFO = "Hadoop:service=NameNode,name=NameNodeInfo";
+
+ private static final String HA_STATE = "tag.HAState";
+ private static final String HA_NAME = "tag.Hostname";
+ private static final String CAPACITY_TOTAL_GB = "CapacityTotalGB";
+ private static final String CAPACITY_USED_GB = "CapacityUsedGB";
+ private static final String BLOCKS_TOTAL = "BlocksTotal";
+ private static final String LIVE_NODES = "LiveNodes";
+ private static final String DEAD_NODES = "DeadNodes";
+
+ private static final String JN_STATUS = "NameJournalStatus";
+ private static final String JN_TRANSACTION_INFO = "JournalTransactionInfo";
+ private static final String LAST_TX_ID = "LastAppliedOrWrittenTxId";
+
+ private static final String DATA_NODE_NUM_BLOCKS = "numBlocks";
+ private static final String DATA_NODE_USED_SPACE = "usedSpace";
+ private static final String DATA_NODE_CAPACITY = "capacity";
+ private static final String DATA_NODE_ADMIN_STATE = "adminState";
+ private static final String DATA_NODE_FAILED_VOLUMN = "volfails";
+ private static final String DATA_NODE_VERSION = "version";
+ private static final String NAME_NODE_VERSION = "Version";
+
+ private static final String DATA_NODE_DECOMMISSIONED = "Decommissioned";
+ private static final String DATA_NODE_DECOMMISSIONED_STATE = "decommissioned";
+
+ private static final String STATUS_PATTERN = "([\\d\\.]+):\\d+\\s+\\([\\D]+(\\d+)\\)";
+ private static final String QJM_PATTERN = "([\\d\\.]+):\\d+";
+
+ private static final double TB = 1024 * 1024 * 1024 * 1024;
+
+ public HdfsTopologyEntityParser(String site, TopologyCheckAppConfig.HdfsConfig hdfsConfig, TopologyRackResolver rackResolver) {
+ this.namenodeUrls = hdfsConfig.namenodeUrls;
+ this.site = site;
+ this.rackResolver = rackResolver;
+ }
+
+ @Override
+ public TopologyEntityParserResult parse(long timestamp) throws IOException {
+ final TopologyEntityParserResult result = new TopologyEntityParserResult();
+ result.setVersion(TopologyConstants.HadoopVersion.V2);
+ int numNamenode = 0;
+ for (String url : namenodeUrls) {
+ try {
+ final HdfsServiceTopologyAPIEntity namenodeEntity = createNamenodeEntity(url, timestamp);
+ result.getMasterNodes().add(namenodeEntity);
+ numNamenode++;
+ if (namenodeEntity.getStatus().equalsIgnoreCase(NAME_NODE_ACTIVE_STATUS)) {
+ String namenodeVersion = createSlaveNodeEntities(url, timestamp, result);
+ namenodeEntity.setVersion(namenodeVersion);
+ }
+ } catch (RuntimeException ex) {
+ ex.printStackTrace();
+ } catch (IOException e) {
+ LOG.warn("Catch an IOException with url: {}", url);
+ }
+ }
+ double value = numNamenode * 1d / namenodeUrls.length;
+ result.getMetrics().add(EntityBuilderHelper.generateMetric(TopologyConstants.NAME_NODE_ROLE, value, site, timestamp));
+ return result;
+ }
+
+ private HdfsServiceTopologyAPIEntity createNamenodeEntity(String url, long updateTime) throws JSONException, IOException {
+ final String urlString = buildFSNamesystemURL(url);
+ final Map<String, JMXBean> jmxBeanMap = JMXQueryHelper.query(urlString);
+ final JMXBean bean = jmxBeanMap.get(JMX_FS_NAME_SYSTEM_BEAN_NAME);
+
+ if (bean == null || bean.getPropertyMap() == null) {
+ throw new ServiceNotResponseException("Invalid JMX format, FSNamesystem bean is null!");
+ }
+
+ final String hostname = (String) bean.getPropertyMap().get(HA_NAME);
+ HdfsServiceTopologyAPIEntity result = createHdfsServiceEntity(TopologyConstants.NAME_NODE_ROLE, hostname, updateTime);
+ final String state = (String) bean.getPropertyMap().get(HA_STATE);
+ result.setStatus(state);
+ final Double configuredCapacityGB = (Double) bean.getPropertyMap().get(CAPACITY_TOTAL_GB);
+ result.setConfiguredCapacityTB(Double.toString(configuredCapacityGB / 1024));
+ final Double capacityUsedGB = (Double) bean.getPropertyMap().get(CAPACITY_USED_GB);
+ result.setUsedCapacityTB(Double.toString(capacityUsedGB / 1024));
+ final Integer blocksTotal = (Integer) bean.getPropertyMap().get(BLOCKS_TOTAL);
+ result.setNumBlocks(Integer.toString(blocksTotal));
+ return result;
+ }
+
+ private String createSlaveNodeEntities(String url, long updateTime, TopologyEntityParserResult result) throws IOException {
+ final String urlString = buildNamenodeInfo(url);
+ final Map<String, JMXBean> jmxBeanMap = JMXQueryHelper.query(urlString);
+ final JMXBean bean = jmxBeanMap.get(JMX_NAMENODE_INFO);
+ if (bean == null || bean.getPropertyMap() == null) {
+ throw new ServiceNotResponseException("Invalid JMX format, NameNodeInfo bean is null!");
+ }
+ createAllDataNodeEntities(bean, updateTime, result);
+ createAllJournalNodeEntities(bean, updateTime, result);
+ return (String) bean.getPropertyMap().get(NAME_NODE_VERSION);
+ }
+
+ private void createAllJournalNodeEntities(JMXBean bean, long updateTime, TopologyEntityParserResult result) throws UnknownHostException {
+ if (bean.getPropertyMap().get(JN_TRANSACTION_INFO) == null || bean.getPropertyMap().get(JN_STATUS) == null) {
+ return;
+ }
+ String jnInfoString = (String) bean.getPropertyMap().get(JN_TRANSACTION_INFO);
+ JSONObject jsonObject = new JSONObject(jnInfoString);
+ long lastTxId = Long.parseLong(jsonObject.getString(LAST_TX_ID));
+
+ String journalnodeString = (String) bean.getPropertyMap().get(JN_STATUS);
+ JSONArray jsonArray = new JSONArray(journalnodeString);
+ JSONObject jsonMap = (JSONObject) jsonArray.get(0);
+
+ Map<String, HdfsServiceTopologyAPIEntity> journalNodesMap = new HashMap<>();
+ String manager = jsonMap.getString("manager");
+ Pattern qjm = Pattern.compile(QJM_PATTERN);
+ Matcher jpmMatcher = qjm.matcher(manager);
+ while (jpmMatcher.find()) {
+ String ip = jpmMatcher.group(1);
+ String hostname = EntityBuilderHelper.resolveHostByIp(ip);
+ HdfsServiceTopologyAPIEntity entity = createHdfsServiceEntity(TopologyConstants.JOURNAL_NODE_ROLE, hostname, updateTime);
+ entity.setStatus(TopologyConstants.DATA_NODE_DEAD_STATUS);
+ journalNodesMap.put(ip, entity);
+ }
+ if (journalNodesMap.isEmpty()) {
+ LOG.warn("Fail to find journal node info in JMX");
+ return;
+ }
+
+ String stream = jsonMap.getString("stream");
+ Pattern status = Pattern.compile(STATUS_PATTERN);
+ Matcher statusMatcher = status.matcher(stream);
+ long numLiveJournalNodes = 0;
+ while (statusMatcher.find()) {
+ numLiveJournalNodes++;
+ String ip = statusMatcher.group(1);
+ if (journalNodesMap.containsKey(ip)) {
+ long txid = Long.parseLong(statusMatcher.group(2));
+ journalNodesMap.get(ip).setWrittenTxidDiff(lastTxId - txid);
+ journalNodesMap.get(ip).setStatus(TopologyConstants.DATA_NODE_LIVE_STATUS);
+ }
+ }
+ result.getMasterNodes().addAll(journalNodesMap.values());
+
+ double value = numLiveJournalNodes * 1d / journalNodesMap.size();
+ result.getMetrics().add(EntityBuilderHelper.generateMetric(TopologyConstants.JOURNAL_NODE_ROLE, value, site, updateTime));
+ }
+
+ private void createAllDataNodeEntities(JMXBean bean, long updateTime, TopologyEntityParserResult result) throws JSONException, IOException {
+ int numLiveNodes = 0;
+ int numLiveDecommNodes = 0;
+ int numDeadNodes = 0;
+ int numDeadDecommNodes = 0;
+
+ String deadNodesStrings = (String) bean.getPropertyMap().get(DEAD_NODES);
+ JSONTokener tokener = new JSONTokener(deadNodesStrings);
+ JSONObject jsonNodesObject = new JSONObject(tokener);
+ final JSONArray deadNodes = jsonNodesObject.names();
+ for (int i = 0; deadNodes != null && i < deadNodes.length(); ++i) {
+ final String hostname = deadNodes.getString(i);
+ final JSONObject deadNode = jsonNodesObject.getJSONObject(hostname);
+ HdfsServiceTopologyAPIEntity entity = createHdfsServiceEntity(TopologyConstants.DATA_NODE_ROLE, EntityBuilderHelper.getValidHostName(hostname), updateTime);
+ if (deadNode.getBoolean(DATA_NODE_DECOMMISSIONED_STATE)) {
+ ++numDeadDecommNodes;
+ entity.setStatus(TopologyConstants.DATA_NODE_DEAD_DECOMMISSIONED_STATUS);
+ } else {
+ entity.setStatus(TopologyConstants.DATA_NODE_DEAD_STATUS);
+ }
+ ++numDeadNodes;
+ result.getSlaveNodes().add(entity);
+ }
+ LOG.info("Dead nodes " + numDeadNodes + ", dead but decommissioned nodes: " + numDeadDecommNodes);
+
+ String liveNodesStrings = (String) bean.getPropertyMap().get(LIVE_NODES);
+ tokener = new JSONTokener(liveNodesStrings);
+ jsonNodesObject = new JSONObject(tokener);
+ final JSONArray liveNodes = jsonNodesObject.names();
+ for (int i = 0; liveNodes != null && i < liveNodes.length(); ++i) {
+ final String hostname = liveNodes.getString(i);
+ final JSONObject liveNode = jsonNodesObject.getJSONObject(hostname);
+
+ HdfsServiceTopologyAPIEntity entity = createHdfsServiceEntity(TopologyConstants.DATA_NODE_ROLE, EntityBuilderHelper.getValidHostName(hostname), updateTime);
+ final Number configuredCapacity = (Number) liveNode.get(DATA_NODE_CAPACITY);
+ entity.setConfiguredCapacityTB(Double.toString(configuredCapacity.doubleValue() / TB));
+ final Number capacityUsed = (Number) liveNode.get(DATA_NODE_USED_SPACE);
+ entity.setUsedCapacityTB(Double.toString(capacityUsed.doubleValue() / TB));
+ final Number blocksTotal = (Number) liveNode.get(DATA_NODE_NUM_BLOCKS);
+ entity.setNumBlocks(Double.toString(blocksTotal.doubleValue()));
+ if (liveNode.has(DATA_NODE_FAILED_VOLUMN)) {
+ final Number volFails = (Number) liveNode.get(DATA_NODE_FAILED_VOLUMN);
+ entity.setNumFailedVolumes(Double.toString(volFails.doubleValue()));
+ }
+ final String adminState = liveNode.getString(DATA_NODE_ADMIN_STATE);
+ if (DATA_NODE_DECOMMISSIONED.equalsIgnoreCase(adminState)) {
+ ++numLiveDecommNodes;
+ entity.setStatus(TopologyConstants.DATA_NODE_LIVE_DECOMMISSIONED_STATUS);
+ } else {
+ entity.setStatus(TopologyConstants.DATA_NODE_LIVE_STATUS);
+ }
+ entity.setVersion(String.valueOf(liveNode.get(DATA_NODE_VERSION)));
+ numLiveNodes++;
+ result.getSlaveNodes().add(entity);
+ }
+ LOG.info("Live nodes " + numLiveNodes + ", live but decommissioned nodes: " + numLiveDecommNodes);
+
+ double value = numLiveNodes * 1.0d / result.getSlaveNodes().size();
+ result.getMetrics().add(EntityBuilderHelper.generateMetric(TopologyConstants.DATA_NODE_ROLE, value, site, updateTime));
+ }
+
+ private HdfsServiceTopologyAPIEntity createHdfsServiceEntity(String roleType, String hostname, long updateTime) {
+ HdfsServiceTopologyAPIEntity entity = new HdfsServiceTopologyAPIEntity();
+ entity.setTimestamp(updateTime);
+ entity.setLastUpdateTime(updateTime);
+ Map<String, String> tags = new HashMap<String, String>();
+ entity.setTags(tags);
+ tags.put(SITE_TAG, site);
+ tags.put(ROLE_TAG, roleType);
+ tags.put(HOSTNAME_TAG, hostname);
+ String rack = rackResolver.resolve(hostname);
+ tags.put(RACK_TAG, rack);
+ return entity;
+ }
+
+ private String buildFSNamesystemURL(String url) {
+ return PathResolverHelper.buildUrlPath(url, JMX_URL + "&qry=" + JMX_FS_NAME_SYSTEM_BEAN_NAME);
+ }
+
+ private String buildNamenodeInfo(String url) {
+ return PathResolverHelper.buildUrlPath(url, JMX_URL + "&qry=" + JMX_NAMENODE_INFO);
+ }
+
+ @Override
+ public TopologyConstants.TopologyType getTopologyType() {
+ return TopologyConstants.TopologyType.HDFS;
+ }
+
+ @Override
+ public TopologyConstants.HadoopVersion getHadoopVersion() {
+ return TopologyConstants.HadoopVersion.V2;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/extractor/mr/MRTopologyEntityParser.java
----------------------------------------------------------------------
diff --git a/eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/extractor/mr/MRTopologyEntityParser.java b/eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/extractor/mr/MRTopologyEntityParser.java
index 52148b7..447686c 100644
--- a/eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/extractor/mr/MRTopologyEntityParser.java
+++ b/eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/extractor/mr/MRTopologyEntityParser.java
@@ -1,219 +1,219 @@
-/*
- * 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.eagle.topology.extractor.mr;
-
-import org.apache.eagle.app.utils.AppConstants;
-import org.apache.eagle.app.utils.PathResolverHelper;
-import org.apache.eagle.app.utils.connection.InputStreamUtils;
-import org.apache.eagle.topology.TopologyCheckAppConfig;
-import org.apache.eagle.topology.TopologyConstants;
-import org.apache.eagle.topology.extractor.TopologyEntityParserResult;
-import org.apache.eagle.topology.entity.MRServiceTopologyAPIEntity;
-import org.apache.eagle.topology.extractor.TopologyEntityParser;
-import org.apache.eagle.topology.resolver.TopologyRackResolver;
-import org.apache.eagle.topology.utils.EntityBuilderHelper;
-import org.apache.eagle.topology.utils.ServiceNotResponseException;
-import org.codehaus.jackson.JsonParser;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.ConnectException;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.regex.Matcher;
-
-import static org.apache.eagle.topology.TopologyConstants.*;
-
-public class MRTopologyEntityParser implements TopologyEntityParser {
-
- private String[] rmUrls;
- private String historyServerUrl;
- private String site;
- private TopologyRackResolver rackResolver;
-
- private static final String YARN_NODES_URL = "/ws/v1/cluster/nodes?anonymous=true";
- private static final String YARN_HISTORY_SERVER_URL = "/ws/v1/history/info";
-
- private static final Logger LOGGER = LoggerFactory.getLogger(MRTopologyEntityParser.class);
- private static final ObjectMapper OBJ_MAPPER = new ObjectMapper();
-
- static {
- OBJ_MAPPER.configure(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS, true);
- }
-
- public MRTopologyEntityParser(String site, TopologyCheckAppConfig.MRConfig config, TopologyRackResolver rackResolver) {
- this.site = site;
- this.rmUrls = config.rmUrls;
- this.historyServerUrl = config.historyServerUrl;
- this.rackResolver = rackResolver;
- }
-
- @Override
- public TopologyConstants.HadoopVersion getHadoopVersion() {
- return TopologyConstants.HadoopVersion.V2;
- }
-
- @Override
- public TopologyConstants.TopologyType getTopologyType() {
- return TopologyConstants.TopologyType.MR;
- }
-
- @Override
- public TopologyEntityParserResult parse(long timestamp) {
- final TopologyEntityParserResult result = new TopologyEntityParserResult();
- result.setVersion(TopologyConstants.HadoopVersion.V2);
-
- for (String url : rmUrls) {
- try {
- doParse(PathResolverHelper.buildUrlPath(url, YARN_NODES_URL), timestamp, result);
- } catch (ServiceNotResponseException ex) {
- LOGGER.warn("Catch a ServiceNotResponseException with url: {}", url);
- // reSelect url
- }
- }
-
- double value = result.getMasterNodes().isEmpty() ? 0 : result.getMasterNodes().size() * 1d / rmUrls.length;
- result.getMetrics().add(EntityBuilderHelper.generateMetric(TopologyConstants.RESOURCE_MANAGER_ROLE, value, site, timestamp));
-
- doCheckHistoryServer(timestamp, result);
- return result;
- }
-
- private void doCheckHistoryServer(long updateTime, TopologyEntityParserResult result) {
- if (historyServerUrl == null || historyServerUrl.isEmpty()) {
- return;
- }
- String hsUrl = PathResolverHelper.buildUrlPath(historyServerUrl, YARN_HISTORY_SERVER_URL);
- double liveCount = 1;
- try {
- InputStreamUtils.getInputStream(hsUrl, null, AppConstants.CompressionType.NONE);
- } catch (ConnectException e) {
- liveCount = 0;
- } catch (Exception e) {
- e.printStackTrace();
- return;
- }
- result.getMetrics().add(EntityBuilderHelper.generateMetric(TopologyConstants.HISTORY_SERVER_ROLE, liveCount, site, updateTime));
- }
-
- private InputStream getInputStream(String url, AppConstants.CompressionType type) throws ServiceNotResponseException {
- InputStream is = null;
- try {
- is = InputStreamUtils.getInputStream(url, null, type);
- } catch (ConnectException e) {
- throw new ServiceNotResponseException(e);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return is;
- }
-
- private void doParse(String url, long timestamp, TopologyEntityParserResult result) throws ServiceNotResponseException {
-
- InputStream is = null;
- try {
- LOGGER.info("Going to query URL: " + url);
- is = InputStreamUtils.getInputStream(url, null, AppConstants.CompressionType.NONE);
- YarnNodeInfoWrapper nodeWrapper = OBJ_MAPPER.readValue(is, YarnNodeInfoWrapper.class);
- if (nodeWrapper.getNodes() == null || nodeWrapper.getNodes().getNode() == null) {
- throw new ServiceNotResponseException("Invalid result of URL: " + url);
- }
- int runningNodeCount = 0;
- int lostNodeCount = 0;
- int unhealthyNodeCount = 0;
- final List<YarnNodeInfo> list = nodeWrapper.getNodes().getNode();
- for (YarnNodeInfo info : list) {
- final MRServiceTopologyAPIEntity nodeManagerEntity = createEntity(NODE_MANAGER_ROLE, info.getNodeHostName(), timestamp);
- if (info.getHealthReport() != null && (!info.getHealthReport().isEmpty())) {
- nodeManagerEntity.setHealthReport(info.getHealthReport());
- }
- // TODO: Need to remove the manually mapping RUNNING -> running, LOST - > lost, UNHEALTHY -> unhealthy
- if (info.getState() != null) {
- final String state = info.getState().toLowerCase();
- nodeManagerEntity.setStatus(state);
- if (state.equals(TopologyConstants.NODE_MANAGER_RUNNING_STATUS)) {
- ++runningNodeCount;
- } else if (state.equals(TopologyConstants.NODE_MANAGER_LOST_STATUS)) {
- ++lostNodeCount;
- } else if (state.equals(TopologyConstants.NODE_MANAGER_UNHEALTHY_STATUS)) {
- ++unhealthyNodeCount;
- }
- }
- result.getSlaveNodes().add(nodeManagerEntity);
- }
- LOGGER.info("Running NMs: " + runningNodeCount + ", lost NMs: " + lostNodeCount + ", unhealthy NMs: " + unhealthyNodeCount);
- final MRServiceTopologyAPIEntity resourceManagerEntity = createEntity(TopologyConstants.RESOURCE_MANAGER_ROLE, extractMasterHost(url), timestamp);
- resourceManagerEntity.setStatus(TopologyConstants.RESOURCE_MANAGER_ACTIVE_STATUS);
- result.getMasterNodes().add(resourceManagerEntity);
- double value = runningNodeCount * 1d / list.size();
- result.getMetrics().add(EntityBuilderHelper.generateMetric(TopologyConstants.NODE_MANAGER_ROLE, value, site, timestamp));
- } catch (RuntimeException e) {
- e.printStackTrace();
- } catch (IOException e) {
- throw new ServiceNotResponseException(e);
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- if (is != null) {
- try {
- is.close();
- } catch (IOException e) {
- e.printStackTrace();
- // Do nothing
- }
- }
- }
- }
-
- private String extractMasterHost(String url) {
- Matcher matcher = TopologyConstants.HTTP_HOST_MATCH_PATTERN.matcher(url);
- if (matcher.find()) {
- return matcher.group(1);
- }
- return url;
- }
-
- private String extractRack(YarnNodeInfo info) {
- if (info.getRack() == null) {
- return null;
- }
- String value = info.getRack();
- value = value.substring(value.lastIndexOf('/') + 1);
- return value;
- }
-
- private MRServiceTopologyAPIEntity createEntity(String roleType, String hostname, long updateTime) {
- MRServiceTopologyAPIEntity entity = new MRServiceTopologyAPIEntity();
- entity.setTimestamp(updateTime);
- entity.setLastUpdateTime(updateTime);
- Map<String, String> tags = new HashMap<String, String>();
- entity.setTags(tags);
- tags.put(SITE_TAG, site);
- tags.put(ROLE_TAG, roleType);
- tags.put(HOSTNAME_TAG, hostname);
- String rack = rackResolver.resolve(hostname);
- tags.put(RACK_TAG, rack);
- return entity;
- }
-
-}
+/*
+ * 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.eagle.topology.extractor.mr;
+
+import org.apache.eagle.app.utils.AppConstants;
+import org.apache.eagle.app.utils.PathResolverHelper;
+import org.apache.eagle.app.utils.connection.InputStreamUtils;
+import org.apache.eagle.topology.TopologyCheckAppConfig;
+import org.apache.eagle.topology.TopologyConstants;
+import org.apache.eagle.topology.extractor.TopologyEntityParserResult;
+import org.apache.eagle.topology.entity.MRServiceTopologyAPIEntity;
+import org.apache.eagle.topology.extractor.TopologyEntityParser;
+import org.apache.eagle.topology.resolver.TopologyRackResolver;
+import org.apache.eagle.topology.utils.EntityBuilderHelper;
+import org.apache.eagle.topology.utils.ServiceNotResponseException;
+import org.codehaus.jackson.JsonParser;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.ConnectException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+
+import static org.apache.eagle.topology.TopologyConstants.*;
+
+public class MRTopologyEntityParser implements TopologyEntityParser {
+
+ private String[] rmUrls;
+ private String historyServerUrl;
+ private String site;
+ private TopologyRackResolver rackResolver;
+
+ private static final String YARN_NODES_URL = "/ws/v1/cluster/nodes?anonymous=true";
+ private static final String YARN_HISTORY_SERVER_URL = "/ws/v1/history/info";
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(MRTopologyEntityParser.class);
+ private static final ObjectMapper OBJ_MAPPER = new ObjectMapper();
+
+ static {
+ OBJ_MAPPER.configure(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS, true);
+ }
+
+ public MRTopologyEntityParser(String site, TopologyCheckAppConfig.MRConfig config, TopologyRackResolver rackResolver) {
+ this.site = site;
+ this.rmUrls = config.rmUrls;
+ this.historyServerUrl = config.historyServerUrl;
+ this.rackResolver = rackResolver;
+ }
+
+ @Override
+ public TopologyConstants.HadoopVersion getHadoopVersion() {
+ return TopologyConstants.HadoopVersion.V2;
+ }
+
+ @Override
+ public TopologyConstants.TopologyType getTopologyType() {
+ return TopologyConstants.TopologyType.MR;
+ }
+
+ @Override
+ public TopologyEntityParserResult parse(long timestamp) {
+ final TopologyEntityParserResult result = new TopologyEntityParserResult();
+ result.setVersion(TopologyConstants.HadoopVersion.V2);
+
+ for (String url : rmUrls) {
+ try {
+ doParse(PathResolverHelper.buildUrlPath(url, YARN_NODES_URL), timestamp, result);
+ } catch (ServiceNotResponseException ex) {
+ LOGGER.warn("Catch a ServiceNotResponseException with url: {}", url);
+ // reSelect url
+ }
+ }
+
+ double value = result.getMasterNodes().isEmpty() ? 0 : result.getMasterNodes().size() * 1d / rmUrls.length;
+ result.getMetrics().add(EntityBuilderHelper.generateMetric(TopologyConstants.RESOURCE_MANAGER_ROLE, value, site, timestamp));
+
+ doCheckHistoryServer(timestamp, result);
+ return result;
+ }
+
+ private void doCheckHistoryServer(long updateTime, TopologyEntityParserResult result) {
+ if (historyServerUrl == null || historyServerUrl.isEmpty()) {
+ return;
+ }
+ String hsUrl = PathResolverHelper.buildUrlPath(historyServerUrl, YARN_HISTORY_SERVER_URL);
+ double liveCount = 1;
+ try {
+ InputStreamUtils.getInputStream(hsUrl, null, AppConstants.CompressionType.NONE);
+ } catch (ConnectException e) {
+ liveCount = 0;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return;
+ }
+ result.getMetrics().add(EntityBuilderHelper.generateMetric(TopologyConstants.HISTORY_SERVER_ROLE, liveCount, site, updateTime));
+ }
+
+ private InputStream getInputStream(String url, AppConstants.CompressionType type) throws ServiceNotResponseException {
+ InputStream is = null;
+ try {
+ is = InputStreamUtils.getInputStream(url, null, type);
+ } catch (ConnectException e) {
+ throw new ServiceNotResponseException(e);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return is;
+ }
+
+ private void doParse(String url, long timestamp, TopologyEntityParserResult result) throws ServiceNotResponseException {
+
+ InputStream is = null;
+ try {
+ LOGGER.info("Going to query URL: " + url);
+ is = InputStreamUtils.getInputStream(url, null, AppConstants.CompressionType.NONE);
+ YarnNodeInfoWrapper nodeWrapper = OBJ_MAPPER.readValue(is, YarnNodeInfoWrapper.class);
+ if (nodeWrapper.getNodes() == null || nodeWrapper.getNodes().getNode() == null) {
+ throw new ServiceNotResponseException("Invalid result of URL: " + url);
+ }
+ int runningNodeCount = 0;
+ int lostNodeCount = 0;
+ int unhealthyNodeCount = 0;
+ final List<YarnNodeInfo> list = nodeWrapper.getNodes().getNode();
+ for (YarnNodeInfo info : list) {
+ final MRServiceTopologyAPIEntity nodeManagerEntity = createEntity(NODE_MANAGER_ROLE, info.getNodeHostName(), timestamp);
+ if (info.getHealthReport() != null && (!info.getHealthReport().isEmpty())) {
+ nodeManagerEntity.setHealthReport(info.getHealthReport());
+ }
+ // TODO: Need to remove the manually mapping RUNNING -> running, LOST - > lost, UNHEALTHY -> unhealthy
+ if (info.getState() != null) {
+ final String state = info.getState().toLowerCase();
+ nodeManagerEntity.setStatus(state);
+ if (state.equals(TopologyConstants.NODE_MANAGER_RUNNING_STATUS)) {
+ ++runningNodeCount;
+ } else if (state.equals(TopologyConstants.NODE_MANAGER_LOST_STATUS)) {
+ ++lostNodeCount;
+ } else if (state.equals(TopologyConstants.NODE_MANAGER_UNHEALTHY_STATUS)) {
+ ++unhealthyNodeCount;
+ }
+ }
+ result.getSlaveNodes().add(nodeManagerEntity);
+ }
+ LOGGER.info("Running NMs: " + runningNodeCount + ", lost NMs: " + lostNodeCount + ", unhealthy NMs: " + unhealthyNodeCount);
+ final MRServiceTopologyAPIEntity resourceManagerEntity = createEntity(TopologyConstants.RESOURCE_MANAGER_ROLE, extractMasterHost(url), timestamp);
+ resourceManagerEntity.setStatus(TopologyConstants.RESOURCE_MANAGER_ACTIVE_STATUS);
+ result.getMasterNodes().add(resourceManagerEntity);
+ double value = runningNodeCount * 1d / list.size();
+ result.getMetrics().add(EntityBuilderHelper.generateMetric(TopologyConstants.NODE_MANAGER_ROLE, value, site, timestamp));
+ } catch (RuntimeException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ throw new ServiceNotResponseException(e);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ // Do nothing
+ }
+ }
+ }
+ }
+
+ private String extractMasterHost(String url) {
+ Matcher matcher = TopologyConstants.HTTP_HOST_MATCH_PATTERN.matcher(url);
+ if (matcher.find()) {
+ return matcher.group(1);
+ }
+ return url;
+ }
+
+ private String extractRack(YarnNodeInfo info) {
+ if (info.getRack() == null) {
+ return null;
+ }
+ String value = info.getRack();
+ value = value.substring(value.lastIndexOf('/') + 1);
+ return value;
+ }
+
+ private MRServiceTopologyAPIEntity createEntity(String roleType, String hostname, long updateTime) {
+ MRServiceTopologyAPIEntity entity = new MRServiceTopologyAPIEntity();
+ entity.setTimestamp(updateTime);
+ entity.setLastUpdateTime(updateTime);
+ Map<String, String> tags = new HashMap<String, String>();
+ entity.setTags(tags);
+ tags.put(SITE_TAG, site);
+ tags.put(ROLE_TAG, roleType);
+ tags.put(HOSTNAME_TAG, hostname);
+ String rack = rackResolver.resolve(hostname);
+ tags.put(RACK_TAG, rack);
+ return entity;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/storm/TopologyDataPersistBolt.java
----------------------------------------------------------------------
diff --git a/eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/storm/TopologyDataPersistBolt.java b/eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/storm/TopologyDataPersistBolt.java
index afd3518..11d907b 100644
--- a/eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/storm/TopologyDataPersistBolt.java
+++ b/eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/storm/TopologyDataPersistBolt.java
@@ -1,200 +1,200 @@
-/*
- * 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.eagle.topology.storm;
-
-import static org.apache.eagle.topology.TopologyConstants.HOSTNAME_TAG;
-import static org.apache.eagle.topology.TopologyConstants.RACK_TAG;
-import static org.apache.eagle.topology.TopologyConstants.ROLE_TAG;
-import static org.apache.eagle.topology.TopologyConstants.SITE_TAG;
-
-import backtype.storm.task.OutputCollector;
-import backtype.storm.task.TopologyContext;
-import backtype.storm.topology.OutputFieldsDeclarer;
-import backtype.storm.topology.base.BaseRichBolt;
-import backtype.storm.tuple.Fields;
-import backtype.storm.tuple.Tuple;
-import backtype.storm.tuple.Values;
-
-
-import org.apache.eagle.log.base.taggedlog.TaggedLogAPIEntity;
-import org.apache.eagle.log.entity.GenericServiceAPIResponseEntity;
-import org.apache.eagle.service.client.EagleServiceClientException;
-import org.apache.eagle.service.client.EagleServiceConnector;
-import org.apache.eagle.service.client.IEagleServiceClient;
-import org.apache.eagle.service.client.impl.EagleServiceClientImpl;
-import org.apache.eagle.topology.TopologyCheckAppConfig;
-import org.apache.eagle.topology.TopologyConstants;
-import org.apache.eagle.topology.extractor.TopologyEntityParserResult;
-import org.apache.eagle.topology.entity.HBaseServiceTopologyAPIEntity;
-import org.apache.eagle.topology.entity.HdfsServiceTopologyAPIEntity;
-import org.apache.eagle.topology.entity.HealthCheckParseAPIEntity;
-import org.apache.eagle.topology.entity.MRServiceTopologyAPIEntity;
-import org.apache.eagle.topology.entity.TopologyBaseAPIEntity;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.util.*;
-
-public class TopologyDataPersistBolt extends BaseRichBolt {
-
- private TopologyCheckAppConfig config;
- private IEagleServiceClient client;
- private OutputCollector collector;
-
- private static final Logger LOG = LoggerFactory.getLogger(TopologyDataPersistBolt.class);
-
- public TopologyDataPersistBolt(TopologyCheckAppConfig config) {
- this.config = config;
- }
-
- @Override
- public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
- this.client = new EagleServiceClientImpl(new EagleServiceConnector(this.config.getConfig().getString("service.host"), this.config.getConfig().getInt("service.port"),
- this.config.getConfig().getString("service.username"), this.config.getConfig().getString("service.password")));
- this.collector = collector;
- }
-
- @Override
- public void execute(Tuple input) {
- if (input == null) {
- return;
- }
- String serviceName = input.getStringByField(TopologyConstants.SERVICE_NAME_FIELD);
- TopologyEntityParserResult result = (TopologyEntityParserResult) input.getValueByField(TopologyConstants.TOPOLOGY_DATA_FIELD);
- Set<String> availableHostnames = new HashSet<String>();
- List<TopologyBaseAPIEntity> entitiesForDeletion = new ArrayList<>();
- List<TopologyBaseAPIEntity> entitiesToWrite = new ArrayList<>();
-
- filterEntitiesToWrite(entitiesToWrite, availableHostnames, result.getMasterNodes());
- filterEntitiesToWrite(entitiesToWrite, availableHostnames, result.getSlaveNodes());
-
- String query = String.format("%s[@site=\"%s\"]{*}", serviceName, this.config.dataExtractorConfig.site);
- try {
- GenericServiceAPIResponseEntity<TopologyBaseAPIEntity> response = client.search().query(query).pageSize(Integer.MAX_VALUE).send();
- if (response.isSuccess() && response.getObj() != null) {
- for (TopologyBaseAPIEntity entity : response.getObj()) {
- if (availableHostnames != null && availableHostnames.size() > 0 && !availableHostnames.contains(generateKey(entity))) {
- entitiesForDeletion.add(entity);
- }
- }
- }
- deleteEntities(entitiesForDeletion, serviceName);
- writeEntities(entitiesToWrite, serviceName);
- writeEntities(result.getMetrics(), serviceName);
- emitToKafkaBolt(result);
- this.collector.ack(input);
- } catch (Exception e) {
- LOG.error(e.getMessage(), e);
- this.collector.fail(input);
- }
- }
-
- private void filterEntitiesToWrite(List<TopologyBaseAPIEntity> entitiesToWrite, Set<String> availableHostnames, List<TopologyBaseAPIEntity> entities) {
- for (TopologyBaseAPIEntity entity : entities) {
- availableHostnames.add(generateKey(entity));
- entitiesToWrite.add(entity);
- }
- }
-
- @Override
- public void declareOutputFields(OutputFieldsDeclarer declarer) {
- declarer.declare(new Fields("f1"));
- }
-
- private void deleteEntities(List<TopologyBaseAPIEntity> entities, String serviceName) {
- try {
- GenericServiceAPIResponseEntity response = client.delete(entities);
- if (!response.isSuccess()) {
- LOG.error("Got exception from eagle service: " + response.getException());
- } else {
- LOG.info("Successfully delete {} entities for {}", entities.size(), serviceName);
- }
- } catch (EagleServiceClientException e) {
- LOG.error(e.getMessage(), e);
- } catch (IOException e) {
- LOG.error(e.getMessage(), e);
- }
- entities.clear();
- }
-
- private void writeEntities(List<? extends TaggedLogAPIEntity> entities, String serviceName) {
- try {
- GenericServiceAPIResponseEntity response = client.create(entities);
- if (!response.isSuccess()) {
- LOG.error("Got exception from eagle service: " + response.getException());
- } else {
- LOG.info("Successfully wrote {} entities for {}", entities.size(), serviceName);
- }
- } catch (Exception e) {
- LOG.error("cannot create entities successfully", e);
- }
- entities.clear();
- }
-
- private String generateKey(TopologyBaseAPIEntity entity) {
- return String.format("%s-%s-%s-%s", entity.getTags().get(TopologyConstants.SITE_TAG),
- entity.getTags().get(TopologyConstants.RACK_TAG), entity.getTags().get(TopologyConstants.HOSTNAME_TAG),
- entity.getTags().get(TopologyConstants.ROLE_TAG));
- }
-
- private void emitToKafkaBolt(TopologyEntityParserResult result) {
-
- List<HealthCheckParseAPIEntity> healthCheckParseAPIList = new ArrayList<HealthCheckParseAPIEntity>();
-
- setNodeInfo(result.getMasterNodes(), healthCheckParseAPIList);
-
- setNodeInfo(result.getSlaveNodes(), healthCheckParseAPIList);
-
- for (HealthCheckParseAPIEntity healthCheckAPIEntity : healthCheckParseAPIList) {
- this.collector.emit(new Values(healthCheckAPIEntity));
- }
-
- }
-
- private void setNodeInfo(List<TopologyBaseAPIEntity> topologyBaseAPIList, List<HealthCheckParseAPIEntity> healthCheckParseAPIList) {
- HealthCheckParseAPIEntity healthCheckAPIEntity = null;
- for (Iterator<TopologyBaseAPIEntity> iterator = topologyBaseAPIList.iterator(); iterator.hasNext(); ) {
-
- healthCheckAPIEntity = new HealthCheckParseAPIEntity();
- TopologyBaseAPIEntity topologyBaseAPIEntity = iterator.next();
-
- if (topologyBaseAPIEntity instanceof HBaseServiceTopologyAPIEntity) {
-
- healthCheckAPIEntity.setStatus(((HBaseServiceTopologyAPIEntity) topologyBaseAPIEntity).getStatus());
-
- }
- if (topologyBaseAPIEntity instanceof HdfsServiceTopologyAPIEntity) {
-
- healthCheckAPIEntity.setStatus(((HdfsServiceTopologyAPIEntity) topologyBaseAPIEntity).getStatus());
- }
-
- if (topologyBaseAPIEntity instanceof MRServiceTopologyAPIEntity) {
-
- healthCheckAPIEntity.setStatus(((MRServiceTopologyAPIEntity) topologyBaseAPIEntity).getStatus());
- }
-
- healthCheckAPIEntity.setTimeStamp(topologyBaseAPIEntity.getTimestamp());
- healthCheckAPIEntity.setHost(topologyBaseAPIEntity.getTags().get(HOSTNAME_TAG));
- healthCheckAPIEntity.setRole(topologyBaseAPIEntity.getTags().get(ROLE_TAG));
- healthCheckAPIEntity.setSite(topologyBaseAPIEntity.getTags().get(SITE_TAG));
- healthCheckParseAPIList.add(healthCheckAPIEntity);
- }
- }
-}
+/*
+ * 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.eagle.topology.storm;
+
+import static org.apache.eagle.topology.TopologyConstants.HOSTNAME_TAG;
+import static org.apache.eagle.topology.TopologyConstants.RACK_TAG;
+import static org.apache.eagle.topology.TopologyConstants.ROLE_TAG;
+import static org.apache.eagle.topology.TopologyConstants.SITE_TAG;
+
+import backtype.storm.task.OutputCollector;
+import backtype.storm.task.TopologyContext;
+import backtype.storm.topology.OutputFieldsDeclarer;
+import backtype.storm.topology.base.BaseRichBolt;
+import backtype.storm.tuple.Fields;
+import backtype.storm.tuple.Tuple;
+import backtype.storm.tuple.Values;
+
+
+import org.apache.eagle.log.base.taggedlog.TaggedLogAPIEntity;
+import org.apache.eagle.log.entity.GenericServiceAPIResponseEntity;
+import org.apache.eagle.service.client.EagleServiceClientException;
+import org.apache.eagle.service.client.EagleServiceConnector;
+import org.apache.eagle.service.client.IEagleServiceClient;
+import org.apache.eagle.service.client.impl.EagleServiceClientImpl;
+import org.apache.eagle.topology.TopologyCheckAppConfig;
+import org.apache.eagle.topology.TopologyConstants;
+import org.apache.eagle.topology.extractor.TopologyEntityParserResult;
+import org.apache.eagle.topology.entity.HBaseServiceTopologyAPIEntity;
+import org.apache.eagle.topology.entity.HdfsServiceTopologyAPIEntity;
+import org.apache.eagle.topology.entity.HealthCheckParseAPIEntity;
+import org.apache.eagle.topology.entity.MRServiceTopologyAPIEntity;
+import org.apache.eagle.topology.entity.TopologyBaseAPIEntity;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.*;
+
+public class TopologyDataPersistBolt extends BaseRichBolt {
+
+ private TopologyCheckAppConfig config;
+ private IEagleServiceClient client;
+ private OutputCollector collector;
+
+ private static final Logger LOG = LoggerFactory.getLogger(TopologyDataPersistBolt.class);
+
+ public TopologyDataPersistBolt(TopologyCheckAppConfig config) {
+ this.config = config;
+ }
+
+ @Override
+ public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
+ this.client = new EagleServiceClientImpl(new EagleServiceConnector(this.config.getConfig().getString("service.host"), this.config.getConfig().getInt("service.port"),
+ this.config.getConfig().getString("service.username"), this.config.getConfig().getString("service.password")));
+ this.collector = collector;
+ }
+
+ @Override
+ public void execute(Tuple input) {
+ if (input == null) {
+ return;
+ }
+ String serviceName = input.getStringByField(TopologyConstants.SERVICE_NAME_FIELD);
+ TopologyEntityParserResult result = (TopologyEntityParserResult) input.getValueByField(TopologyConstants.TOPOLOGY_DATA_FIELD);
+ Set<String> availableHostnames = new HashSet<String>();
+ List<TopologyBaseAPIEntity> entitiesForDeletion = new ArrayList<>();
+ List<TopologyBaseAPIEntity> entitiesToWrite = new ArrayList<>();
+
+ filterEntitiesToWrite(entitiesToWrite, availableHostnames, result.getMasterNodes());
+ filterEntitiesToWrite(entitiesToWrite, availableHostnames, result.getSlaveNodes());
+
+ String query = String.format("%s[@site=\"%s\"]{*}", serviceName, this.config.dataExtractorConfig.site);
+ try {
+ GenericServiceAPIResponseEntity<TopologyBaseAPIEntity> response = client.search().query(query).pageSize(Integer.MAX_VALUE).send();
+ if (response.isSuccess() && response.getObj() != null) {
+ for (TopologyBaseAPIEntity entity : response.getObj()) {
+ if (availableHostnames != null && availableHostnames.size() > 0 && !availableHostnames.contains(generateKey(entity))) {
+ entitiesForDeletion.add(entity);
+ }
+ }
+ }
+ deleteEntities(entitiesForDeletion, serviceName);
+ writeEntities(entitiesToWrite, serviceName);
+ writeEntities(result.getMetrics(), serviceName);
+ emitToKafkaBolt(result);
+ this.collector.ack(input);
+ } catch (Exception e) {
+ LOG.error(e.getMessage(), e);
+ this.collector.fail(input);
+ }
+ }
+
+ private void filterEntitiesToWrite(List<TopologyBaseAPIEntity> entitiesToWrite, Set<String> availableHostnames, List<TopologyBaseAPIEntity> entities) {
+ for (TopologyBaseAPIEntity entity : entities) {
+ availableHostnames.add(generateKey(entity));
+ entitiesToWrite.add(entity);
+ }
+ }
+
+ @Override
+ public void declareOutputFields(OutputFieldsDeclarer declarer) {
+ declarer.declare(new Fields("f1"));
+ }
+
+ private void deleteEntities(List<TopologyBaseAPIEntity> entities, String serviceName) {
+ try {
+ GenericServiceAPIResponseEntity response = client.delete(entities);
+ if (!response.isSuccess()) {
+ LOG.error("Got exception from eagle service: " + response.getException());
+ } else {
+ LOG.info("Successfully delete {} entities for {}", entities.size(), serviceName);
+ }
+ } catch (EagleServiceClientException e) {
+ LOG.error(e.getMessage(), e);
+ } catch (IOException e) {
+ LOG.error(e.getMessage(), e);
+ }
+ entities.clear();
+ }
+
+ private void writeEntities(List<? extends TaggedLogAPIEntity> entities, String serviceName) {
+ try {
+ GenericServiceAPIResponseEntity response = client.create(entities);
+ if (!response.isSuccess()) {
+ LOG.error("Got exception from eagle service: " + response.getException());
+ } else {
+ LOG.info("Successfully wrote {} entities for {}", entities.size(), serviceName);
+ }
+ } catch (Exception e) {
+ LOG.error("cannot create entities successfully", e);
+ }
+ entities.clear();
+ }
+
+ private String generateKey(TopologyBaseAPIEntity entity) {
+ return String.format("%s-%s-%s-%s", entity.getTags().get(TopologyConstants.SITE_TAG),
+ entity.getTags().get(TopologyConstants.RACK_TAG), entity.getTags().get(TopologyConstants.HOSTNAME_TAG),
+ entity.getTags().get(TopologyConstants.ROLE_TAG));
+ }
+
+ private void emitToKafkaBolt(TopologyEntityParserResult result) {
+
+ List<HealthCheckParseAPIEntity> healthCheckParseAPIList = new ArrayList<HealthCheckParseAPIEntity>();
+
+ setNodeInfo(result.getMasterNodes(), healthCheckParseAPIList);
+
+ setNodeInfo(result.getSlaveNodes(), healthCheckParseAPIList);
+
+ for (HealthCheckParseAPIEntity healthCheckAPIEntity : healthCheckParseAPIList) {
+ this.collector.emit(new Values(healthCheckAPIEntity));
+ }
+
+ }
+
+ private void setNodeInfo(List<TopologyBaseAPIEntity> topologyBaseAPIList, List<HealthCheckParseAPIEntity> healthCheckParseAPIList) {
+ HealthCheckParseAPIEntity healthCheckAPIEntity = null;
+ for (Iterator<TopologyBaseAPIEntity> iterator = topologyBaseAPIList.iterator(); iterator.hasNext(); ) {
+
+ healthCheckAPIEntity = new HealthCheckParseAPIEntity();
+ TopologyBaseAPIEntity topologyBaseAPIEntity = iterator.next();
+
+ if (topologyBaseAPIEntity instanceof HBaseServiceTopologyAPIEntity) {
+
+ healthCheckAPIEntity.setStatus(((HBaseServiceTopologyAPIEntity) topologyBaseAPIEntity).getStatus());
+
+ }
+ if (topologyBaseAPIEntity instanceof HdfsServiceTopologyAPIEntity) {
+
+ healthCheckAPIEntity.setStatus(((HdfsServiceTopologyAPIEntity) topologyBaseAPIEntity).getStatus());
+ }
+
+ if (topologyBaseAPIEntity instanceof MRServiceTopologyAPIEntity) {
+
+ healthCheckAPIEntity.setStatus(((MRServiceTopologyAPIEntity) topologyBaseAPIEntity).getStatus());
+ }
+
+ healthCheckAPIEntity.setTimeStamp(topologyBaseAPIEntity.getTimestamp());
+ healthCheckAPIEntity.setHost(topologyBaseAPIEntity.getTags().get(HOSTNAME_TAG));
+ healthCheckAPIEntity.setRole(topologyBaseAPIEntity.getTags().get(ROLE_TAG));
+ healthCheckAPIEntity.setSite(topologyBaseAPIEntity.getTags().get(SITE_TAG));
+ healthCheckParseAPIList.add(healthCheckAPIEntity);
+ }
+ }
+}
[3/5] incubator-eagle git commit: [EAGLE-806] Integrate Metric
Process and Persistence with Application Framework
Posted by ha...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/provider/JDBCDataSourceProvider.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/provider/JDBCDataSourceProvider.java b/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/provider/JDBCDataSourceProvider.java
index 7495ef5..40f08c1 100644
--- a/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/provider/JDBCDataSourceProvider.java
+++ b/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/provider/JDBCDataSourceProvider.java
@@ -45,7 +45,7 @@ public class JDBCDataSourceProvider implements Provider<DataSource> {
@Override
public void run() {
try {
- LOGGER.info("Shutting down data source");
+ LOGGER.info("Shutting down data fromStream");
datasource.close();
} catch (SQLException e) {
LOGGER.error("SQLException: {}", e.getMessage(), e);
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/service/ApplicationEntityServiceJDBCImpl.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/service/ApplicationEntityServiceJDBCImpl.java b/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/service/ApplicationEntityServiceJDBCImpl.java
index 6ddf3c6..02bf1cc 100644
--- a/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/service/ApplicationEntityServiceJDBCImpl.java
+++ b/eagle-core/eagle-metadata/eagle-metadata-jdbc/src/main/java/org/apache/eagle/metadata/store/jdbc/service/ApplicationEntityServiceJDBCImpl.java
@@ -210,10 +210,10 @@ public class ApplicationEntityServiceJDBCImpl implements ApplicationEntityServic
ExecutionRuntime runtime = ExecutionRuntimeManager.getInstance().getRuntime(
applicationProviderService.getApplicationProviderByType(entity.getDescriptor().getType()).getApplication().getEnvironmentType(), config);
StreamSinkConfig streamSinkConfig = runtime.environment()
- .streamSink().getSinkConfig(StreamIdConversions.parseStreamTypeId(copied.getSiteId(), copied.getStreamId()), effectiveConfig);
+ .stream().getSinkConfig(StreamIdConversions.parseStreamTypeId(copied.getSiteId(), copied.getStreamId()), effectiveConfig);
StreamDesc streamDesc = new StreamDesc();
streamDesc.setSchema(copied);
- streamDesc.setSink(streamSinkConfig);
+ streamDesc.setSinkConfig(streamSinkConfig);
streamDesc.setStreamId(copied.getStreamId());
streamDesc.getSchema().setDataSource(entity.getAppId());
return streamDesc;
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/EagleServiceConnector.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/EagleServiceConnector.java b/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/EagleServiceConnector.java
index d06a3e4..fa59e8a 100644
--- a/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/EagleServiceConnector.java
+++ b/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/EagleServiceConnector.java
@@ -25,7 +25,8 @@ import java.io.Serializable;
/**
* Some common codes to enable DAO through eagle service including service host/post, credential population etc.
*/
-public class EagleServiceConnector implements Serializable{
+@Deprecated
+public class EagleServiceConnector implements Serializable {
private final String eagleServiceHost;
private final Integer eagleServicePort;
private String username;
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/impl/EagleServiceClientImpl.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/impl/EagleServiceClientImpl.java b/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/impl/EagleServiceClientImpl.java
index 912f1f7..f0b6283 100644
--- a/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/impl/EagleServiceClientImpl.java
+++ b/eagle-core/eagle-query/eagle-client-base/src/main/java/org/apache/eagle/service/client/impl/EagleServiceClientImpl.java
@@ -16,6 +16,7 @@
*/
package org.apache.eagle.service.client.impl;
+import com.typesafe.config.Config;
import org.apache.eagle.log.base.taggedlog.TaggedLogAPIEntity;
import org.apache.eagle.log.entity.GenericServiceAPIResponseEntity;
import org.apache.eagle.service.client.EagleServiceClientException;
@@ -33,14 +34,24 @@ import java.util.Map;
public class EagleServiceClientImpl extends EagleServiceBaseClient {
private final static Logger LOG = LoggerFactory.getLogger(EagleServiceClientImpl.class);
- public EagleServiceClientImpl(String host, int port){
+ public EagleServiceClientImpl(String host, int port) {
super(host, port);
}
- public EagleServiceClientImpl(EagleServiceConnector connector){
+ @Deprecated
+ public EagleServiceClientImpl(EagleServiceConnector connector) {
this(connector.getEagleServiceHost(), connector.getEagleServicePort(), connector.getUsername(), connector.getPassword());
}
+ public EagleServiceClientImpl (Config config) {
+ super(
+ config.hasPath("service.host") ? config.getString("service.host") : "localhost",
+ config.hasPath("service.port") ? config.getInt("service.port") : 9090,
+ config.hasPath("service.username") ? config.getString("service.username") : null,
+ config.hasPath("service.password") ? config.getString("service.password") : null
+ );
+ }
+
public EagleServiceClientImpl(String host, int port, String username, String password){
super(host, port, username, password);
}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-examples/eagle-app-example/src/main/java/org/apache/eagle/app/example/ExampleStormApplication.java
----------------------------------------------------------------------
diff --git a/eagle-examples/eagle-app-example/src/main/java/org/apache/eagle/app/example/ExampleStormApplication.java b/eagle-examples/eagle-app-example/src/main/java/org/apache/eagle/app/example/ExampleStormApplication.java
index c78cd3c..f1f4e58 100644
--- a/eagle-examples/eagle-app-example/src/main/java/org/apache/eagle/app/example/ExampleStormApplication.java
+++ b/eagle-examples/eagle-app-example/src/main/java/org/apache/eagle/app/example/ExampleStormApplication.java
@@ -57,7 +57,7 @@ public class ExampleStormApplication extends StormApplication{
@Override
public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {
- outputFieldsDeclarer.declare(new Fields("metric","timestamp","source","value"));
+ outputFieldsDeclarer.declare(new Fields("metric","timestamp","fromStream","value"));
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-examples/eagle-app-example/src/test/resources/application.conf
----------------------------------------------------------------------
diff --git a/eagle-examples/eagle-app-example/src/test/resources/application.conf b/eagle-examples/eagle-app-example/src/test/resources/application.conf
index de9be89..0c9ba51 100644
--- a/eagle-examples/eagle-app-example/src/test/resources/application.conf
+++ b/eagle-examples/eagle-app-example/src/test/resources/application.conf
@@ -44,7 +44,7 @@
},
"application": {
"sink": {
- "type": "org.apache.eagle.app.sink.KafkaStreamSink",
+ "type": "org.apache.eagle.app.messaging.KafkaStreamSink",
"config": {
"kafkaBrokerHost": "",
"kafkaZkConnection": ""
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-gc/src/main/java/org/apache/eagle/gc/GCLogApplication.java
----------------------------------------------------------------------
diff --git a/eagle-gc/src/main/java/org/apache/eagle/gc/GCLogApplication.java b/eagle-gc/src/main/java/org/apache/eagle/gc/GCLogApplication.java
index a3052d8..1453c3e 100644
--- a/eagle-gc/src/main/java/org/apache/eagle/gc/GCLogApplication.java
+++ b/eagle-gc/src/main/java/org/apache/eagle/gc/GCLogApplication.java
@@ -29,7 +29,7 @@ import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import org.apache.eagle.app.StormApplication;
import org.apache.eagle.app.environment.impl.StormEnvironment;
-import org.apache.eagle.app.sink.StormStreamSink;
+import org.apache.eagle.app.messaging.StormStreamSink;
import org.apache.eagle.dataproc.impl.storm.kafka.KafkaSpoutProvider;
import org.apache.eagle.gc.executor.GCLogAnalyzerBolt;
import org.apache.eagle.gc.executor.GCMetricGeneratorBolt;
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-hadoop-metric/pom.xml
----------------------------------------------------------------------
diff --git a/eagle-hadoop-metric/pom.xml b/eagle-hadoop-metric/pom.xml
index ad1521f..a3d1cb0 100644
--- a/eagle-hadoop-metric/pom.xml
+++ b/eagle-hadoop-metric/pom.xml
@@ -31,6 +31,20 @@
<groupId>org.apache.eagle</groupId>
<artifactId>eagle-app-base</artifactId>
<version>${project.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-core</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.ow2.asm</groupId>
+ <artifactId>asm</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
</dependencies>
-</project>
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-hadoop-metric/src/main/java/org/apache/eagle/metric/HadoopMetricMonitorApp.java
----------------------------------------------------------------------
diff --git a/eagle-hadoop-metric/src/main/java/org/apache/eagle/metric/HadoopMetricMonitorApp.java b/eagle-hadoop-metric/src/main/java/org/apache/eagle/metric/HadoopMetricMonitorApp.java
new file mode 100644
index 0000000..7f5e21b
--- /dev/null
+++ b/eagle-hadoop-metric/src/main/java/org/apache/eagle/metric/HadoopMetricMonitorApp.java
@@ -0,0 +1,38 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.eagle.metric;
+
+import backtype.storm.generated.StormTopology;
+import com.typesafe.config.Config;
+import org.apache.eagle.app.StormApplication;
+import org.apache.eagle.app.environment.builder.CEPFunction;
+import org.apache.eagle.app.environment.impl.StormEnvironment;
+import org.apache.eagle.app.environment.builder.MetricDefinition;
+
+public class HadoopMetricMonitorApp extends StormApplication {
+ @Override
+ public StormTopology execute(Config config, StormEnvironment environment) {
+ return environment.newApp(config)
+ .fromStream("HADOOP_JMX_METRIC_STREAM")
+ .saveAsMetric(MetricDefinition
+ .namedByField("metric")
+ .eventTimeByField("timestamp")
+ .dimensionFields("host","component","site")
+ .valueField("value"))
+ .toTopology();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-hadoop-metric/src/main/java/org/apache/eagle/metric/HadoopMetricMonitorAppProdiver.java
----------------------------------------------------------------------
diff --git a/eagle-hadoop-metric/src/main/java/org/apache/eagle/metric/HadoopMetricMonitorAppProdiver.java b/eagle-hadoop-metric/src/main/java/org/apache/eagle/metric/HadoopMetricMonitorAppProdiver.java
index e6ebde1..dc7ea97 100644
--- a/eagle-hadoop-metric/src/main/java/org/apache/eagle/metric/HadoopMetricMonitorAppProdiver.java
+++ b/eagle-hadoop-metric/src/main/java/org/apache/eagle/metric/HadoopMetricMonitorAppProdiver.java
@@ -16,8 +16,14 @@
*/
package org.apache.eagle.metric;
-import org.apache.eagle.app.StaticApplicationProvider;
+import org.apache.eagle.app.spi.AbstractApplicationProvider;
-public class HadoopMetricMonitorAppProdiver extends StaticApplicationProvider {
- // Metadata: META-INF/providers/org.apache.eagle.metric.HadoopMetricMonitorAppProdiver.xml
+/**
+ * Metadata: META-INF/providers/org.apache.eagle.metric.HadoopMetricMonitorAppProdiver.xml.
+ */
+public class HadoopMetricMonitorAppProdiver extends AbstractApplicationProvider<HadoopMetricMonitorApp> {
+ @Override
+ public HadoopMetricMonitorApp getApplication() {
+ return new HadoopMetricMonitorApp();
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-hadoop-metric/src/main/resources/META-INF/providers/org.apache.eagle.metric.HadoopMetricMonitorAppProdiver.xml
----------------------------------------------------------------------
diff --git a/eagle-hadoop-metric/src/main/resources/META-INF/providers/org.apache.eagle.metric.HadoopMetricMonitorAppProdiver.xml b/eagle-hadoop-metric/src/main/resources/META-INF/providers/org.apache.eagle.metric.HadoopMetricMonitorAppProdiver.xml
index 752c0cb..07270a5 100644
--- a/eagle-hadoop-metric/src/main/resources/META-INF/providers/org.apache.eagle.metric.HadoopMetricMonitorAppProdiver.xml
+++ b/eagle-hadoop-metric/src/main/resources/META-INF/providers/org.apache.eagle.metric.HadoopMetricMonitorAppProdiver.xml
@@ -21,7 +21,7 @@
<name>Hadoop JMX Metric Monitor</name>
<version>0.5.0-incubating</version>
<configuration>
- <!-- data source configurations -->
+ <!-- data fromStream configurations -->
<property>
<name>dataSinkConfig.HADOOP_JMX_METRIC_STREAM.topic</name>
<displayName>JMX Metric Kafka Topic</displayName>
@@ -41,8 +41,6 @@
<stream>
<streamId>HADOOP_JMX_METRIC_STREAM</streamId>
<description>Hadoop JMX Metric Stream including name node, resource manager, etc.</description>
- <validate>true</validate>
- <timeseries>true</timeseries>
<columns>
<column>
<name>host</name>
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-hadoop-metric/src/main/test/java/org/apache/eagle/metric/HadoopMetricMonitorAppProdiverTest.java
----------------------------------------------------------------------
diff --git a/eagle-hadoop-metric/src/main/test/java/org/apache/eagle/metric/HadoopMetricMonitorAppProdiverTest.java b/eagle-hadoop-metric/src/main/test/java/org/apache/eagle/metric/HadoopMetricMonitorAppProdiverTest.java
deleted file mode 100644
index ee0b3c0..0000000
--- a/eagle-hadoop-metric/src/main/test/java/org/apache/eagle/metric/HadoopMetricMonitorAppProdiverTest.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * 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.eagle.metric;
-
-
-import com.google.inject.Inject;
-import org.apache.eagle.app.resource.ApplicationResource;
-import org.apache.eagle.app.service.ApplicationOperations;
-import org.apache.eagle.app.test.ApplicationSimulator;
-import org.apache.eagle.app.test.ApplicationTestBase;
-import org.apache.eagle.metadata.model.ApplicationEntity;
-import org.apache.eagle.metadata.model.SiteEntity;
-import org.apache.eagle.metadata.resource.SiteResource;
-import org.apache.eagle.metadata.service.ApplicationStatusUpdateService;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public class HadoopMetricMonitorAppProdiverTest extends ApplicationTestBase {
-
- @Inject
- private SiteResource siteResource;
- @Inject
- private ApplicationResource applicationResource;
- @Inject
- private ApplicationSimulator simulator;
- @Inject
- ApplicationStatusUpdateService statusUpdateService;
-
- @Test
- public void testApplicationLifecycle() throws InterruptedException {
- // Create local site
- SiteEntity siteEntity = new SiteEntity();
- siteEntity.setSiteId("test_site");
- siteEntity.setSiteName("Test Site");
- siteEntity.setDescription("Test Site for HADOOP_JMX_METRIC_MONITOR");
- siteResource.createSite(siteEntity);
- Assert.assertNotNull(siteEntity.getUuid());
-
- ApplicationOperations.InstallOperation installOperation = new ApplicationOperations.InstallOperation("test_site", "HADOOP_JMX_METRIC_MONITOR", ApplicationEntity.Mode.LOCAL);
- installOperation.setConfiguration(getConf());
- // Install application
- ApplicationEntity applicationEntity = applicationResource.installApplication(installOperation).getData();
- // Uninstall application
- applicationResource.uninstallApplication(new ApplicationOperations.UninstallOperation(applicationEntity.getUuid()));
- try {
- applicationResource.getApplicationEntityByUUID(applicationEntity.getUuid());
- Assert.fail("Application instance (UUID: " + applicationEntity.getUuid() + ") should have been uninstalled");
- } catch (Exception ex) {
- // Expected exception
- }
- }
-
- private Map<String, Object> getConf() {
- Map<String, Object> conf = new HashMap<>();
- conf.put("dataSinkConfig.topic", "testTopic");
- conf.put("dataSinkConfig.brokerList", "broker");
- conf.put("dataSinkConfig.serializerClass", "serializerClass");
- conf.put("dataSinkConfig.keySerializerClass", "keySerializerClass");
- conf.put("dataSinkConfig.producerType", "async");
- conf.put("dataSinkConfig.numBatchMessages", 4096);
- conf.put("dataSinkConfig.maxQueueBufferMs", 5000);
- conf.put("dataSinkConfig.requestRequiredAcks", 0);
- conf.put("spoutNum", 2);
- conf.put("mode", "LOCAL");
- return conf;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-hadoop-metric/src/test/java/org/apache/eagle/metric/HadoopMetricMonitorAppDebug.java
----------------------------------------------------------------------
diff --git a/eagle-hadoop-metric/src/test/java/org/apache/eagle/metric/HadoopMetricMonitorAppDebug.java b/eagle-hadoop-metric/src/test/java/org/apache/eagle/metric/HadoopMetricMonitorAppDebug.java
new file mode 100644
index 0000000..03ba4ee
--- /dev/null
+++ b/eagle-hadoop-metric/src/test/java/org/apache/eagle/metric/HadoopMetricMonitorAppDebug.java
@@ -0,0 +1,23 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.eagle.metric;
+
+public class HadoopMetricMonitorAppDebug {
+ public static void main(String[] args) {
+ new HadoopMetricMonitorApp().run(args);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-hadoop-metric/src/test/java/org/apache/eagle/metric/HadoopMetricMonitorAppProviderTest.java
----------------------------------------------------------------------
diff --git a/eagle-hadoop-metric/src/test/java/org/apache/eagle/metric/HadoopMetricMonitorAppProviderTest.java b/eagle-hadoop-metric/src/test/java/org/apache/eagle/metric/HadoopMetricMonitorAppProviderTest.java
new file mode 100644
index 0000000..eb343d9
--- /dev/null
+++ b/eagle-hadoop-metric/src/test/java/org/apache/eagle/metric/HadoopMetricMonitorAppProviderTest.java
@@ -0,0 +1,84 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.eagle.metric;
+
+
+import com.google.inject.Inject;
+import org.apache.eagle.app.resource.ApplicationResource;
+import org.apache.eagle.app.service.ApplicationOperations;
+import org.apache.eagle.app.test.ApplicationSimulator;
+import org.apache.eagle.app.test.ApplicationTestBase;
+import org.apache.eagle.metadata.model.ApplicationEntity;
+import org.apache.eagle.metadata.model.SiteEntity;
+import org.apache.eagle.metadata.resource.SiteResource;
+import org.apache.eagle.metadata.service.ApplicationStatusUpdateService;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class HadoopMetricMonitorAppProviderTest extends ApplicationTestBase {
+
+ @Inject
+ private SiteResource siteResource;
+ @Inject
+ private ApplicationResource applicationResource;
+ @Inject
+ private ApplicationSimulator simulator;
+ @Inject
+ ApplicationStatusUpdateService statusUpdateService;
+
+ @Test
+ public void testApplicationLifecycle() throws InterruptedException {
+ // Create local site
+ SiteEntity siteEntity = new SiteEntity();
+ siteEntity.setSiteId("test_site");
+ siteEntity.setSiteName("Test Site");
+ siteEntity.setDescription("Test Site for HADOOP_JMX_METRIC_MONITOR");
+ siteResource.createSite(siteEntity);
+ Assert.assertNotNull(siteEntity.getUuid());
+
+ ApplicationOperations.InstallOperation installOperation = new ApplicationOperations.InstallOperation("test_site", "HADOOP_JMX_METRIC_MONITOR", ApplicationEntity.Mode.LOCAL);
+ installOperation.setConfiguration(getConf());
+ // Install application
+ ApplicationEntity applicationEntity = applicationResource.installApplication(installOperation).getData();
+ // Uninstall application
+ applicationResource.uninstallApplication(new ApplicationOperations.UninstallOperation(applicationEntity.getUuid()));
+ try {
+ applicationResource.getApplicationEntityByUUID(applicationEntity.getUuid());
+ Assert.fail("Application instance (UUID: " + applicationEntity.getUuid() + ") should have been uninstalled");
+ } catch (Exception ex) {
+ // Expected exception
+ }
+ }
+
+ private Map<String, Object> getConf() {
+ Map<String, Object> conf = new HashMap<>();
+ conf.put("dataSinkConfig.topic", "testTopic");
+ conf.put("dataSinkConfig.brokerList", "broker");
+ conf.put("dataSinkConfig.serializerClass", "serializerClass");
+ conf.put("dataSinkConfig.keySerializerClass", "keySerializerClass");
+ conf.put("dataSinkConfig.producerType", "async");
+ conf.put("dataSinkConfig.numBatchMessages", 4096);
+ conf.put("dataSinkConfig.maxQueueBufferMs", 5000);
+ conf.put("dataSinkConfig.requestRequiredAcks", 0);
+ conf.put("spoutNum", 2);
+ conf.put("mode", "LOCAL");
+ return conf;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-hadoop-metric/src/test/java/org/apache/eagle/metric/SendSampleDataToKafka.java
----------------------------------------------------------------------
diff --git a/eagle-hadoop-metric/src/test/java/org/apache/eagle/metric/SendSampleDataToKafka.java b/eagle-hadoop-metric/src/test/java/org/apache/eagle/metric/SendSampleDataToKafka.java
new file mode 100644
index 0000000..67b94f8
--- /dev/null
+++ b/eagle-hadoop-metric/src/test/java/org/apache/eagle/metric/SendSampleDataToKafka.java
@@ -0,0 +1,55 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.eagle.metric;
+
+import com.google.common.base.Preconditions;
+import com.typesafe.config.ConfigFactory;
+import kafka.producer.KeyedMessage;
+import kafka.producer.ProducerConfig;
+import org.apache.commons.io.IOUtils;
+import org.apache.eagle.app.messaging.KafkaStreamProvider;
+import org.apache.eagle.app.messaging.KafkaStreamSinkConfig;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URISyntaxException;
+import java.util.Properties;
+
+public class SendSampleDataToKafka {
+ public static void main(String[] args) throws URISyntaxException, IOException {
+ KafkaStreamSinkConfig config = new KafkaStreamProvider().getSinkConfig("HADOOP_JMX_METRIC_STREAM",ConfigFactory.load());
+ Properties properties = new Properties();
+ properties.put("metadata.broker.list", config.getBrokerList());
+ properties.put("serializer.class", config.getSerializerClass());
+ properties.put("key.serializer.class", config.getKeySerializerClass());
+ // new added properties for async producer
+ properties.put("producer.type", config.getProducerType());
+ properties.put("batch.num.messages", config.getNumBatchMessages());
+ properties.put("request.required.acks", config.getRequestRequiredAcks());
+ properties.put("queue.buffering.max.ms", config.getMaxQueueBufferMs());
+ ProducerConfig producerConfig = new ProducerConfig(properties);
+ kafka.javaapi.producer.Producer producer = new kafka.javaapi.producer.Producer(producerConfig);
+ try {
+ InputStream is = SendSampleDataToKafka.class.getResourceAsStream("hadoop_jmx_metric_sample.json");
+ Preconditions.checkNotNull(is, "hadoop_jmx_metric_sample.json");
+ String value = IOUtils.toString(is);
+ producer.send(new KeyedMessage(config.getTopicId(), value));
+ } finally {
+ producer.close();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-hadoop-metric/src/test/resources/application.conf
----------------------------------------------------------------------
diff --git a/eagle-hadoop-metric/src/test/resources/application.conf b/eagle-hadoop-metric/src/test/resources/application.conf
new file mode 100644
index 0000000..8ff6016
--- /dev/null
+++ b/eagle-hadoop-metric/src/test/resources/application.conf
@@ -0,0 +1,49 @@
+# 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.
+
+
+
+
+{
+ service {
+ env = "testing"
+ host = "localhost"
+ port = 9090
+ username = "admin"
+ password = "secret"
+ readTimeOutSeconds = 60
+ context = "/rest"
+ timezone = "UTC"
+ }
+
+ "appId" : "HadoopJmxAppForTest",
+ "mode" : "LOCAL",
+ "siteId" : "testsite",
+ "dataSourceConfig": {
+ "topic" : "hadoop_jmx_metric",
+ "zkConnection" : "localhost:2181",
+ "txZkServers" : "localhost:2181"
+ }
+ "dataSinkConfig": {
+ "topic" : "hadoop_jmx_metric",
+ "brokerList" : "localhost:6667",
+ "serializerClass" : "kafka.serializer.StringEncoder",
+ "keySerializerClass" : "kafka.serializer.StringEncoder"
+ "producerType" : "async",
+ "numBatchMessages" : "4096",
+ "maxQueueBufferMs" : "5000",
+ "requestRequiredAcks" : "0"
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-hadoop-metric/src/test/resources/hadoop_jmx_metric_sample.json
----------------------------------------------------------------------
diff --git a/eagle-hadoop-metric/src/test/resources/hadoop_jmx_metric_sample.json b/eagle-hadoop-metric/src/test/resources/hadoop_jmx_metric_sample.json
new file mode 100644
index 0000000..f0f62f2
--- /dev/null
+++ b/eagle-hadoop-metric/src/test/resources/hadoop_jmx_metric_sample.json
@@ -0,0 +1,8 @@
+{
+ "host":"localhost",
+ "timestamp": 1480319107,
+ "metric": "hadoop.cpu.usage",
+ "component": "namenode",
+ "site": "test",
+ "value": 0.96
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-jpm/eagle-hadoop-queue/src/main/java/org/apache/eagle/hadoop/queue/HadoopQueueRunningApplicationHealthCheck.java
----------------------------------------------------------------------
diff --git a/eagle-jpm/eagle-hadoop-queue/src/main/java/org/apache/eagle/hadoop/queue/HadoopQueueRunningApplicationHealthCheck.java b/eagle-jpm/eagle-hadoop-queue/src/main/java/org/apache/eagle/hadoop/queue/HadoopQueueRunningApplicationHealthCheck.java
index 6a7535c..6471dfc 100644
--- a/eagle-jpm/eagle-hadoop-queue/src/main/java/org/apache/eagle/hadoop/queue/HadoopQueueRunningApplicationHealthCheck.java
+++ b/eagle-jpm/eagle-hadoop-queue/src/main/java/org/apache/eagle/hadoop/queue/HadoopQueueRunningApplicationHealthCheck.java
@@ -1,102 +1,102 @@
-/*
- * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.eagle.hadoop.queue;
-
-import com.typesafe.config.Config;
-import org.apache.commons.lang.exception.ExceptionUtils;
-import org.apache.eagle.app.service.impl.ApplicationHealthCheckBase;
-import org.apache.eagle.hadoop.queue.common.HadoopClusterConstants;
-import org.apache.eagle.jpm.util.Constants;
-import org.apache.eagle.log.entity.GenericServiceAPIResponseEntity;
-import org.apache.eagle.metadata.model.ApplicationEntity;
-import org.apache.eagle.service.client.IEagleServiceClient;
-import org.apache.eagle.service.client.impl.EagleServiceClientImpl;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.List;
-import java.util.Map;
-
-public class HadoopQueueRunningApplicationHealthCheck extends ApplicationHealthCheckBase {
- private static final Logger LOG = LoggerFactory.getLogger(HadoopQueueRunningApplicationHealthCheck.class);
- private static final long DEFAULT_MAX_DELAY_TIME = 10 * 60 * 1000L;
-
- private HadoopQueueRunningAppConfig hadoopQueueRunningAppConfig;
-
- public HadoopQueueRunningApplicationHealthCheck(Config config) {
- super(config);
- this.hadoopQueueRunningAppConfig = new HadoopQueueRunningAppConfig(config);
- }
-
- @Override
- public Result check() {
- HadoopQueueRunningAppConfig.EagleProps eagleServiceConfig = this.hadoopQueueRunningAppConfig.eagleProps;
- IEagleServiceClient client = new EagleServiceClientImpl(
- eagleServiceConfig.eagleService.host,
- eagleServiceConfig.eagleService.port,
- eagleServiceConfig.eagleService.username,
- eagleServiceConfig.eagleService.password);
-
- client.getJerseyClient().setReadTimeout(60000);
-
- String message = "";
- try {
- ApplicationEntity.Status status = getApplicationStatus();
- if (!status.toString().equals(ApplicationEntity.Status.RUNNING.toString())) {
- message += String.format("Application is not RUNNING, status is %s. ", status.toString());
- }
-
-
- String query = String.format("%s[@site=\"%s\"]<@site>{max(timestamp)}",
- Constants.GENERIC_METRIC_SERVICE,
- hadoopQueueRunningAppConfig.eagleProps.site);
-
- GenericServiceAPIResponseEntity response = client
- .search(query)
- .metricName(HadoopClusterConstants.MetricName.HADOOP_CLUSTER_ALLOCATED_MEMORY)
- .startTime(System.currentTimeMillis() - 24 * 60 * 60000L)
- .endTime(System.currentTimeMillis())
- .pageSize(10)
- .send();
- List<Map<List<String>, List<Double>>> results = response.getObj();
- long currentProcessTimeStamp = results.get(0).get("value").get(0).longValue();
- long currentTimeStamp = System.currentTimeMillis();
- long maxDelayTime = DEFAULT_MAX_DELAY_TIME;
- if (hadoopQueueRunningAppConfig.getConfig().hasPath(MAX_DELAY_TIME_KEY)) {
- maxDelayTime = hadoopQueueRunningAppConfig.getConfig().getLong(MAX_DELAY_TIME_KEY);
- }
-
- if (!message.isEmpty() || currentTimeStamp - currentProcessTimeStamp > maxDelayTime) {
- message += String.format("Current process time is %sms, delay %s minutes.",
- currentProcessTimeStamp, (currentTimeStamp - currentProcessTimeStamp) * 1.0 / 60000L);
- return Result.unhealthy(message);
- } else {
- return Result.healthy();
- }
- } catch (Exception e) {
- return Result.unhealthy(printMessages(message, "An exception was caught when fetch application current process time: ", ExceptionUtils.getStackTrace(e)));
- } finally {
- client.getJerseyClient().destroy();
- try {
- client.close();
- } catch (Exception e) {
- LOG.warn("{}", e);
- }
- }
- }
-}
+/*
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.eagle.hadoop.queue;
+
+import com.typesafe.config.Config;
+import org.apache.commons.lang.exception.ExceptionUtils;
+import org.apache.eagle.app.service.impl.ApplicationHealthCheckBase;
+import org.apache.eagle.hadoop.queue.common.HadoopClusterConstants;
+import org.apache.eagle.jpm.util.Constants;
+import org.apache.eagle.log.entity.GenericServiceAPIResponseEntity;
+import org.apache.eagle.metadata.model.ApplicationEntity;
+import org.apache.eagle.service.client.IEagleServiceClient;
+import org.apache.eagle.service.client.impl.EagleServiceClientImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.Map;
+
+public class HadoopQueueRunningApplicationHealthCheck extends ApplicationHealthCheckBase {
+ private static final Logger LOG = LoggerFactory.getLogger(HadoopQueueRunningApplicationHealthCheck.class);
+ private static final long DEFAULT_MAX_DELAY_TIME = 10 * 60 * 1000L;
+
+ private HadoopQueueRunningAppConfig hadoopQueueRunningAppConfig;
+
+ public HadoopQueueRunningApplicationHealthCheck(Config config) {
+ super(config);
+ this.hadoopQueueRunningAppConfig = new HadoopQueueRunningAppConfig(config);
+ }
+
+ @Override
+ public Result check() {
+ HadoopQueueRunningAppConfig.EagleProps eagleServiceConfig = this.hadoopQueueRunningAppConfig.eagleProps;
+ IEagleServiceClient client = new EagleServiceClientImpl(
+ eagleServiceConfig.eagleService.host,
+ eagleServiceConfig.eagleService.port,
+ eagleServiceConfig.eagleService.username,
+ eagleServiceConfig.eagleService.password);
+
+ client.getJerseyClient().setReadTimeout(60000);
+
+ String message = "";
+ try {
+ ApplicationEntity.Status status = getApplicationStatus();
+ if (!status.toString().equals(ApplicationEntity.Status.RUNNING.toString())) {
+ message += String.format("Application is not RUNNING, status is %s. ", status.toString());
+ }
+
+
+ String query = String.format("%s[@site=\"%s\"]<@site>{max(timestamp)}",
+ Constants.GENERIC_METRIC_SERVICE,
+ hadoopQueueRunningAppConfig.eagleProps.site);
+
+ GenericServiceAPIResponseEntity response = client
+ .search(query)
+ .metricName(HadoopClusterConstants.MetricName.HADOOP_CLUSTER_ALLOCATED_MEMORY)
+ .startTime(System.currentTimeMillis() - 24 * 60 * 60000L)
+ .endTime(System.currentTimeMillis())
+ .pageSize(10)
+ .send();
+ List<Map<List<String>, List<Double>>> results = response.getObj();
+ long currentProcessTimeStamp = results.get(0).get("value").get(0).longValue();
+ long currentTimeStamp = System.currentTimeMillis();
+ long maxDelayTime = DEFAULT_MAX_DELAY_TIME;
+ if (hadoopQueueRunningAppConfig.getConfig().hasPath(MAX_DELAY_TIME_KEY)) {
+ maxDelayTime = hadoopQueueRunningAppConfig.getConfig().getLong(MAX_DELAY_TIME_KEY);
+ }
+
+ if (!message.isEmpty() || currentTimeStamp - currentProcessTimeStamp > maxDelayTime) {
+ message += String.format("Current process time is %sms, delay %s minutes.",
+ currentProcessTimeStamp, (currentTimeStamp - currentProcessTimeStamp) * 1.0 / 60000L);
+ return Result.unhealthy(message);
+ } else {
+ return Result.healthy();
+ }
+ } catch (Exception e) {
+ return Result.unhealthy(printMessages(message, "An exception was caught when fetch application current process time: ", ExceptionUtils.getStackTrace(e)));
+ } finally {
+ client.getJerseyClient().destroy();
+ try {
+ client.close();
+ } catch (Exception e) {
+ LOG.warn("{}", e);
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-jpm/eagle-jpm-aggregation/src/main/java/org/apache/eagle/jpm/aggregation/storm/AggregationSpout.java
----------------------------------------------------------------------
diff --git a/eagle-jpm/eagle-jpm-aggregation/src/main/java/org/apache/eagle/jpm/aggregation/storm/AggregationSpout.java b/eagle-jpm/eagle-jpm-aggregation/src/main/java/org/apache/eagle/jpm/aggregation/storm/AggregationSpout.java
index f19c366..e145cf3 100644
--- a/eagle-jpm/eagle-jpm-aggregation/src/main/java/org/apache/eagle/jpm/aggregation/storm/AggregationSpout.java
+++ b/eagle-jpm/eagle-jpm-aggregation/src/main/java/org/apache/eagle/jpm/aggregation/storm/AggregationSpout.java
@@ -76,7 +76,7 @@ public class AggregationSpout extends BaseRichSpout {
//1, get last updateTime;
lastUpdateTime = AggregationTimeManager.instance().readLastFinishTime();
if (lastUpdateTime == 0L) {
- //init state, just set to currentTime - 18 hours
+ //prepare state, just set to currentTime - 18 hours
lastUpdateTime = (currentJobTime - (MAX_SAFE_TIME + MAX_WAIT_TIME)) / 3600000 * 3600000;
}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-jpm/eagle-jpm-mr-history/src/main/java/org/apache/eagle/jpm/mr/history/MRHistoryJobApplication.java
----------------------------------------------------------------------
diff --git a/eagle-jpm/eagle-jpm-mr-history/src/main/java/org/apache/eagle/jpm/mr/history/MRHistoryJobApplication.java b/eagle-jpm/eagle-jpm-mr-history/src/main/java/org/apache/eagle/jpm/mr/history/MRHistoryJobApplication.java
index 907ccdb..66906f0 100644
--- a/eagle-jpm/eagle-jpm-mr-history/src/main/java/org/apache/eagle/jpm/mr/history/MRHistoryJobApplication.java
+++ b/eagle-jpm/eagle-jpm-mr-history/src/main/java/org/apache/eagle/jpm/mr/history/MRHistoryJobApplication.java
@@ -17,10 +17,9 @@
package org.apache.eagle.jpm.mr.history;
import backtype.storm.topology.BoltDeclarer;
-import com.codahale.metrics.health.HealthCheck;
import org.apache.eagle.app.StormApplication;
import org.apache.eagle.app.environment.impl.StormEnvironment;
-import org.apache.eagle.app.sink.StormStreamSink;
+import org.apache.eagle.app.messaging.StormStreamSink;
import org.apache.eagle.jpm.mr.history.crawler.JobHistoryContentFilter;
import org.apache.eagle.jpm.mr.history.crawler.JobHistoryContentFilterBuilder;
import org.apache.eagle.jpm.mr.history.storm.JobHistorySpout;
@@ -37,11 +36,11 @@ import java.util.regex.Pattern;
public class MRHistoryJobApplication extends StormApplication {
@Override
public StormTopology execute(Config config, StormEnvironment environment) {
- //1. trigger init conf
+ //1. trigger prepare conf
MRHistoryJobConfig appConfig = MRHistoryJobConfig.newInstance(config);
com.typesafe.config.Config jhfAppConf = appConfig.getConfig();
- //2. init JobHistoryContentFilter
+ //2. prepare JobHistoryContentFilter
final JobHistoryContentFilterBuilder builder = JobHistoryContentFilterBuilder.newBuilder().acceptJobFile().acceptJobConfFile();
String[] confKeyPatternsSplit = jhfAppConf.getString("MRConfigureKeys.jobConfigKey").split(",");
List<String> confKeyPatterns = new ArrayList<>(confKeyPatternsSplit.length);
@@ -60,7 +59,7 @@ public class MRHistoryJobApplication extends StormApplication {
builder.includeJobKeyPatterns(Pattern.compile(key));
}
JobHistoryContentFilter filter = builder.build();
- //3. init topology
+ //3. prepare topology
TopologyBuilder topologyBuilder = new TopologyBuilder();
String spoutName = "mrHistoryJobSpout";
int tasks = jhfAppConf.getInt("stormConfig.mrHistoryJobSpoutTasks");
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-jpm/eagle-jpm-mr-running/src/main/java/org/apache/eagle/jpm/mr/running/MRRunningJobApplication.java
----------------------------------------------------------------------
diff --git a/eagle-jpm/eagle-jpm-mr-running/src/main/java/org/apache/eagle/jpm/mr/running/MRRunningJobApplication.java b/eagle-jpm/eagle-jpm-mr-running/src/main/java/org/apache/eagle/jpm/mr/running/MRRunningJobApplication.java
index e5c7c87..de0d846 100644
--- a/eagle-jpm/eagle-jpm-mr-running/src/main/java/org/apache/eagle/jpm/mr/running/MRRunningJobApplication.java
+++ b/eagle-jpm/eagle-jpm-mr-running/src/main/java/org/apache/eagle/jpm/mr/running/MRRunningJobApplication.java
@@ -32,7 +32,7 @@ import java.util.List;
public class MRRunningJobApplication extends StormApplication {
@Override
public StormTopology execute(Config config, StormEnvironment environment) {
- //1. trigger init conf
+ //1. trigger prepare conf
MRRunningJobConfig mrRunningJobConfig = MRRunningJobConfig.newInstance(config);
String[] confKeyPatternsSplit = mrRunningJobConfig.getConfig().getString("MRConfigureKeys.jobConfigKey").split(",");
@@ -46,7 +46,7 @@ public class MRRunningJobApplication extends StormApplication {
confKeyKeys.add(Constants.JobConfiguration.SCOOBI_JOB);
confKeyKeys.add(0, mrRunningJobConfig.getConfig().getString("MRConfigureKeys.jobNameKey"));
- //2. init topology
+ //2. prepare topology
TopologyBuilder topologyBuilder = new TopologyBuilder();
String spoutName = "mrRunningJobFetchSpout";
String boltName = "mrRunningJobParseBolt";
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-jpm/eagle-jpm-mr-running/src/test/resources/mrconf_30784.xml
----------------------------------------------------------------------
diff --git a/eagle-jpm/eagle-jpm-mr-running/src/test/resources/mrconf_30784.xml b/eagle-jpm/eagle-jpm-mr-running/src/test/resources/mrconf_30784.xml
index 66da734..1b7b8ed 100644
--- a/eagle-jpm/eagle-jpm-mr-running/src/test/resources/mrconf_30784.xml
+++ b/eagle-jpm/eagle-jpm-mr-running/src/test/resources/mrconf_30784.xml
@@ -1,4 +1,4 @@
-\ufeff<!--
+<!--
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.
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-jpm/eagle-jpm-spark-history/src/main/java/org/apache/eagle/jpm/spark/history/SparkHistoryJobApplicationHealthCheck.java
----------------------------------------------------------------------
diff --git a/eagle-jpm/eagle-jpm-spark-history/src/main/java/org/apache/eagle/jpm/spark/history/SparkHistoryJobApplicationHealthCheck.java b/eagle-jpm/eagle-jpm-spark-history/src/main/java/org/apache/eagle/jpm/spark/history/SparkHistoryJobApplicationHealthCheck.java
index d6f5031..fdfcaad 100644
--- a/eagle-jpm/eagle-jpm-spark-history/src/main/java/org/apache/eagle/jpm/spark/history/SparkHistoryJobApplicationHealthCheck.java
+++ b/eagle-jpm/eagle-jpm-spark-history/src/main/java/org/apache/eagle/jpm/spark/history/SparkHistoryJobApplicationHealthCheck.java
@@ -1,99 +1,99 @@
-/*
- * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.eagle.jpm.spark.history;
-
-import com.typesafe.config.Config;
-import org.apache.commons.lang.exception.ExceptionUtils;
-import org.apache.eagle.app.service.impl.ApplicationHealthCheckBase;
-import org.apache.eagle.jpm.util.Constants;
-import org.apache.eagle.log.entity.GenericServiceAPIResponseEntity;
-import org.apache.eagle.metadata.model.ApplicationEntity;
-import org.apache.eagle.service.client.IEagleServiceClient;
-import org.apache.eagle.service.client.impl.EagleServiceClientImpl;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.List;
-import java.util.Map;
-
-public class SparkHistoryJobApplicationHealthCheck extends ApplicationHealthCheckBase {
- private static final Logger LOG = LoggerFactory.getLogger(SparkHistoryJobApplicationHealthCheck.class);
-
- private SparkHistoryJobAppConfig sparkHistoryJobAppConfig;
-
- public SparkHistoryJobApplicationHealthCheck(Config config) {
- super(config);
- this.sparkHistoryJobAppConfig = SparkHistoryJobAppConfig.newInstance(config);
- }
-
- @Override
- public Result check() {
- SparkHistoryJobAppConfig.EagleInfo eagleServiceConfig = sparkHistoryJobAppConfig.eagleInfo;
- IEagleServiceClient client = new EagleServiceClientImpl(
- eagleServiceConfig.host,
- eagleServiceConfig.port,
- eagleServiceConfig.username,
- eagleServiceConfig.password);
-
- client.getJerseyClient().setReadTimeout(eagleServiceConfig.timeout * 1000);
-
- String message = "";
- try {
- ApplicationEntity.Status status = getApplicationStatus();
- if (!status.toString().equals(ApplicationEntity.Status.RUNNING.toString())) {
- message += String.format("Application is not RUNNING, status is %s. ", status.toString());
- }
-
- String query = String.format("%s[@site=\"%s\"]<@site>{max(endTime)}",
- Constants.SPARK_APP_SERVICE_ENDPOINT_NAME,
- sparkHistoryJobAppConfig.stormConfig.siteId);
-
- GenericServiceAPIResponseEntity response = client
- .search(query)
- .startTime(System.currentTimeMillis() - 12 * 60 * 60000L)
- .endTime(System.currentTimeMillis())
- .pageSize(10)
- .send();
-
- List<Map<List<String>, List<Double>>> results = response.getObj();
- long currentProcessTimeStamp = results.get(0).get("value").get(0).longValue();
- long currentTimeStamp = System.currentTimeMillis();
- long maxDelayTime = DEFAULT_MAX_DELAY_TIME;
- if (sparkHistoryJobAppConfig.getConfig().hasPath(MAX_DELAY_TIME_KEY)) {
- maxDelayTime = sparkHistoryJobAppConfig.getConfig().getLong(MAX_DELAY_TIME_KEY);
- }
-
- if (!message.isEmpty() || currentTimeStamp - currentProcessTimeStamp > maxDelayTime * 3) {
- message += String.format("Current process time is %sms, delay %s hours.",
- currentProcessTimeStamp, (currentTimeStamp - currentProcessTimeStamp) * 1.0 / 60000L / 60);
- return Result.unhealthy(message);
- } else {
- return Result.healthy();
- }
- } catch (Exception e) {
- return Result.unhealthy(printMessages(message, "An exception was caught when fetch application current process time: ", ExceptionUtils.getStackTrace(e)));
- } finally {
- client.getJerseyClient().destroy();
- try {
- client.close();
- } catch (Exception e) {
- LOG.warn("{}", e);
- }
- }
- }
-}
+/*
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.eagle.jpm.spark.history;
+
+import com.typesafe.config.Config;
+import org.apache.commons.lang.exception.ExceptionUtils;
+import org.apache.eagle.app.service.impl.ApplicationHealthCheckBase;
+import org.apache.eagle.jpm.util.Constants;
+import org.apache.eagle.log.entity.GenericServiceAPIResponseEntity;
+import org.apache.eagle.metadata.model.ApplicationEntity;
+import org.apache.eagle.service.client.IEagleServiceClient;
+import org.apache.eagle.service.client.impl.EagleServiceClientImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.Map;
+
+public class SparkHistoryJobApplicationHealthCheck extends ApplicationHealthCheckBase {
+ private static final Logger LOG = LoggerFactory.getLogger(SparkHistoryJobApplicationHealthCheck.class);
+
+ private SparkHistoryJobAppConfig sparkHistoryJobAppConfig;
+
+ public SparkHistoryJobApplicationHealthCheck(Config config) {
+ super(config);
+ this.sparkHistoryJobAppConfig = SparkHistoryJobAppConfig.newInstance(config);
+ }
+
+ @Override
+ public Result check() {
+ SparkHistoryJobAppConfig.EagleInfo eagleServiceConfig = sparkHistoryJobAppConfig.eagleInfo;
+ IEagleServiceClient client = new EagleServiceClientImpl(
+ eagleServiceConfig.host,
+ eagleServiceConfig.port,
+ eagleServiceConfig.username,
+ eagleServiceConfig.password);
+
+ client.getJerseyClient().setReadTimeout(eagleServiceConfig.timeout * 1000);
+
+ String message = "";
+ try {
+ ApplicationEntity.Status status = getApplicationStatus();
+ if (!status.toString().equals(ApplicationEntity.Status.RUNNING.toString())) {
+ message += String.format("Application is not RUNNING, status is %s. ", status.toString());
+ }
+
+ String query = String.format("%s[@site=\"%s\"]<@site>{max(endTime)}",
+ Constants.SPARK_APP_SERVICE_ENDPOINT_NAME,
+ sparkHistoryJobAppConfig.stormConfig.siteId);
+
+ GenericServiceAPIResponseEntity response = client
+ .search(query)
+ .startTime(System.currentTimeMillis() - 12 * 60 * 60000L)
+ .endTime(System.currentTimeMillis())
+ .pageSize(10)
+ .send();
+
+ List<Map<List<String>, List<Double>>> results = response.getObj();
+ long currentProcessTimeStamp = results.get(0).get("value").get(0).longValue();
+ long currentTimeStamp = System.currentTimeMillis();
+ long maxDelayTime = DEFAULT_MAX_DELAY_TIME;
+ if (sparkHistoryJobAppConfig.getConfig().hasPath(MAX_DELAY_TIME_KEY)) {
+ maxDelayTime = sparkHistoryJobAppConfig.getConfig().getLong(MAX_DELAY_TIME_KEY);
+ }
+
+ if (!message.isEmpty() || currentTimeStamp - currentProcessTimeStamp > maxDelayTime * 3) {
+ message += String.format("Current process time is %sms, delay %s hours.",
+ currentProcessTimeStamp, (currentTimeStamp - currentProcessTimeStamp) * 1.0 / 60000L / 60);
+ return Result.unhealthy(message);
+ } else {
+ return Result.healthy();
+ }
+ } catch (Exception e) {
+ return Result.unhealthy(printMessages(message, "An exception was caught when fetch application current process time: ", ExceptionUtils.getStackTrace(e)));
+ } finally {
+ client.getJerseyClient().destroy();
+ try {
+ client.close();
+ } catch (Exception e) {
+ LOG.warn("{}", e);
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-jpm/eagle-jpm-spark-running/src/main/java/org/apache/eagle/jpm/spark/running/SparkRunningJobApp.java
----------------------------------------------------------------------
diff --git a/eagle-jpm/eagle-jpm-spark-running/src/main/java/org/apache/eagle/jpm/spark/running/SparkRunningJobApp.java b/eagle-jpm/eagle-jpm-spark-running/src/main/java/org/apache/eagle/jpm/spark/running/SparkRunningJobApp.java
index 209481a..0e1aacd 100644
--- a/eagle-jpm/eagle-jpm-spark-running/src/main/java/org/apache/eagle/jpm/spark/running/SparkRunningJobApp.java
+++ b/eagle-jpm/eagle-jpm-spark-running/src/main/java/org/apache/eagle/jpm/spark/running/SparkRunningJobApp.java
@@ -29,10 +29,10 @@ import com.typesafe.config.Config;
public class SparkRunningJobApp extends StormApplication {
@Override
public StormTopology execute(Config config, StormEnvironment environment) {
- //1. trigger init conf
+ //1. trigger prepare conf
SparkRunningJobAppConfig sparkRunningJobAppConfig = SparkRunningJobAppConfig.newInstance(config);
- //2. init topology
+ //2. prepare topology
TopologyBuilder topologyBuilder = new TopologyBuilder();
final String spoutName = SparkRunningJobAppConfig.JOB_FETCH_SPOUT_NAME;
final String boltName = SparkRunningJobAppConfig.JOB_PARSE_BOLT_NAME;
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-security/eagle-security-hbase-auditlog/src/main/java/org/apache/eagle/security/hbase/HBaseAuditLogApplication.java
----------------------------------------------------------------------
diff --git a/eagle-security/eagle-security-hbase-auditlog/src/main/java/org/apache/eagle/security/hbase/HBaseAuditLogApplication.java b/eagle-security/eagle-security-hbase-auditlog/src/main/java/org/apache/eagle/security/hbase/HBaseAuditLogApplication.java
index c5c0388..11a22e5 100644
--- a/eagle-security/eagle-security-hbase-auditlog/src/main/java/org/apache/eagle/security/hbase/HBaseAuditLogApplication.java
+++ b/eagle-security/eagle-security-hbase-auditlog/src/main/java/org/apache/eagle/security/hbase/HBaseAuditLogApplication.java
@@ -25,7 +25,7 @@ import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import org.apache.eagle.app.StormApplication;
import org.apache.eagle.app.environment.impl.StormEnvironment;
-import org.apache.eagle.app.sink.StormStreamSink;
+import org.apache.eagle.app.messaging.StormStreamSink;
import org.apache.eagle.dataproc.impl.storm.kafka.KafkaSpoutProvider;
import storm.kafka.StringScheme;
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-security/eagle-security-hdfs-auditlog/src/main/java/org/apache/eagle/security/auditlog/AbstractHdfsAuditLogApplication.java
----------------------------------------------------------------------
diff --git a/eagle-security/eagle-security-hdfs-auditlog/src/main/java/org/apache/eagle/security/auditlog/AbstractHdfsAuditLogApplication.java b/eagle-security/eagle-security-hdfs-auditlog/src/main/java/org/apache/eagle/security/auditlog/AbstractHdfsAuditLogApplication.java
index a1daf89..6d7022b 100644
--- a/eagle-security/eagle-security-hdfs-auditlog/src/main/java/org/apache/eagle/security/auditlog/AbstractHdfsAuditLogApplication.java
+++ b/eagle-security/eagle-security-hdfs-auditlog/src/main/java/org/apache/eagle/security/auditlog/AbstractHdfsAuditLogApplication.java
@@ -24,18 +24,16 @@ import backtype.storm.topology.BoltDeclarer;
import backtype.storm.topology.IRichSpout;
import backtype.storm.topology.TopologyBuilder;
import backtype.storm.topology.base.BaseRichBolt;
-import backtype.storm.tuple.Fields;
import com.typesafe.config.Config;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.eagle.app.StormApplication;
import org.apache.eagle.app.environment.impl.StormEnvironment;
-import org.apache.eagle.app.sink.StormStreamSink;
+import org.apache.eagle.app.messaging.StormStreamSink;
import org.apache.eagle.common.config.EagleConfigConstants;
import org.apache.eagle.dataproc.impl.storm.partition.*;
import org.apache.eagle.security.partition.DataDistributionDaoImpl;
import org.apache.eagle.security.partition.GreedyPartitionAlgorithm;
import org.apache.eagle.dataproc.impl.storm.kafka.KafkaSpoutProvider;
-import storm.kafka.StringScheme;
/**
* Since 8/10/16.
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-security/eagle-security-hive/src/main/java/org/apache/eagle/security/hive/HiveQueryMonitoringApplication.java
----------------------------------------------------------------------
diff --git a/eagle-security/eagle-security-hive/src/main/java/org/apache/eagle/security/hive/HiveQueryMonitoringApplication.java b/eagle-security/eagle-security-hive/src/main/java/org/apache/eagle/security/hive/HiveQueryMonitoringApplication.java
index 7a4509b..4df4a5b 100644
--- a/eagle-security/eagle-security-hive/src/main/java/org/apache/eagle/security/hive/HiveQueryMonitoringApplication.java
+++ b/eagle-security/eagle-security-hive/src/main/java/org/apache/eagle/security/hive/HiveQueryMonitoringApplication.java
@@ -26,7 +26,7 @@ import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import org.apache.eagle.app.StormApplication;
import org.apache.eagle.app.environment.impl.StormEnvironment;
-import org.apache.eagle.app.sink.StormStreamSink;
+import org.apache.eagle.app.messaging.StormStreamSink;
import org.apache.eagle.security.hive.jobrunning.HiveJobRunningSourcedStormSpoutProvider;
import org.apache.eagle.security.hive.jobrunning.HiveQueryParserBolt;
import org.apache.eagle.security.hive.jobrunning.JobFilterBolt;
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-security/eagle-security-oozie-auditlog/src/main/java/org/apache/eagle/security/oozie/parse/OozieAuditLogApplication.java
----------------------------------------------------------------------
diff --git a/eagle-security/eagle-security-oozie-auditlog/src/main/java/org/apache/eagle/security/oozie/parse/OozieAuditLogApplication.java b/eagle-security/eagle-security-oozie-auditlog/src/main/java/org/apache/eagle/security/oozie/parse/OozieAuditLogApplication.java
index c1c3033..32dcc30 100644
--- a/eagle-security/eagle-security-oozie-auditlog/src/main/java/org/apache/eagle/security/oozie/parse/OozieAuditLogApplication.java
+++ b/eagle-security/eagle-security-oozie-auditlog/src/main/java/org/apache/eagle/security/oozie/parse/OozieAuditLogApplication.java
@@ -19,7 +19,7 @@ package org.apache.eagle.security.oozie.parse;
import org.apache.eagle.app.StormApplication;
import org.apache.eagle.app.environment.impl.StormEnvironment;
-import org.apache.eagle.app.sink.StormStreamSink;
+import org.apache.eagle.app.messaging.StormStreamSink;
import org.apache.eagle.dataproc.impl.storm.kafka.KafkaSpoutProvider;
import org.apache.eagle.security.oozie.parse.sensitivity.OozieResourceSensitivityDataJoinBolt;
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-server-assembly/src/main/conf/eagle.conf
----------------------------------------------------------------------
diff --git a/eagle-server-assembly/src/main/conf/eagle.conf b/eagle-server-assembly/src/main/conf/eagle.conf
index 5f6c240..705ef6f 100644
--- a/eagle-server-assembly/src/main/conf/eagle.conf
+++ b/eagle-server-assembly/src/main/conf/eagle.conf
@@ -83,8 +83,8 @@ metadata {
# Eagle Application Configuration
# ---------------------------------------------
application {
- sink {
- type = org.apache.eagle.app.sink.KafkaStreamSink
+ stream {
+ provider = org.apache.eagle.app.messaging.KafkaStreamProvider
}
storm {
nimbusHost = "server.eagle.apache.org"
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-server/src/main/resources/application.conf
----------------------------------------------------------------------
diff --git a/eagle-server/src/main/resources/application.conf b/eagle-server/src/main/resources/application.conf
index ce68550..20f5b2e 100644
--- a/eagle-server/src/main/resources/application.conf
+++ b/eagle-server/src/main/resources/application.conf
@@ -85,8 +85,8 @@ metadata {
# Eagle Application Configuration
# ---------------------------------------------
application {
- sink {
- type = org.apache.eagle.app.sink.KafkaStreamSink
+ stream {
+ provider = org.apache.eagle.app.messaging.KafkaStreamProvider
}
storm {
nimbusHost = "server.eagle.apache.org"
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/TopologyCheckApp.java
----------------------------------------------------------------------
diff --git a/eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/TopologyCheckApp.java b/eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/TopologyCheckApp.java
index 93a06f8..ba5914b 100644
--- a/eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/TopologyCheckApp.java
+++ b/eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/TopologyCheckApp.java
@@ -23,7 +23,7 @@ import backtype.storm.topology.TopologyBuilder;
import com.typesafe.config.Config;
import org.apache.eagle.app.StormApplication;
import org.apache.eagle.app.environment.impl.StormEnvironment;
-import org.apache.eagle.app.sink.StormStreamSink;
+import org.apache.eagle.app.messaging.StormStreamSink;
import org.apache.eagle.topology.storm.HealthCheckParseBolt;
import org.apache.eagle.topology.storm.TopologyCheckAppSpout;
import org.apache.eagle.topology.storm.TopologyDataPersistBolt;
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/TopologyCheckApplicationHealthCheck.java
----------------------------------------------------------------------
diff --git a/eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/TopologyCheckApplicationHealthCheck.java b/eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/TopologyCheckApplicationHealthCheck.java
index 7860cb5..bf5e695 100644
--- a/eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/TopologyCheckApplicationHealthCheck.java
+++ b/eagle-topology-check/eagle-topology-app/src/main/java/org/apache/eagle/topology/TopologyCheckApplicationHealthCheck.java
@@ -1,109 +1,109 @@
-/*
- * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.eagle.topology;
-
-import com.typesafe.config.Config;
-import org.apache.commons.lang.exception.ExceptionUtils;
-import org.apache.eagle.app.service.impl.ApplicationHealthCheckBase;
-import org.apache.eagle.log.entity.GenericServiceAPIResponseEntity;
-import org.apache.eagle.metadata.model.ApplicationEntity;
-import org.apache.eagle.service.client.IEagleServiceClient;
-import org.apache.eagle.service.client.impl.EagleServiceClientImpl;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.List;
-import java.util.Map;
-
-public class TopologyCheckApplicationHealthCheck extends ApplicationHealthCheckBase {
- private static final Logger LOG = LoggerFactory.getLogger(TopologyCheckApplicationHealthCheck.class);
- private static final long DEFAULT_MAX_DELAY_TIME = 10 * 60 * 1000L;
-
- private TopologyCheckAppConfig topologyCheckAppConfig;
-
- public TopologyCheckApplicationHealthCheck(Config config) {
- super(config);
- topologyCheckAppConfig = TopologyCheckAppConfig.newInstance(config);
- }
-
- @Override
- public Result check() {
- //FIXME, this application owner please add eagle server config to Class TopologyCheckAppConfig
- IEagleServiceClient client = new EagleServiceClientImpl(
- topologyCheckAppConfig.getConfig().getString("service.host"),
- topologyCheckAppConfig.getConfig().getInt("service.port"),
- topologyCheckAppConfig.getConfig().getString("service.username"),
- topologyCheckAppConfig.getConfig().getString("service.password"));
-
- client.getJerseyClient().setReadTimeout(topologyCheckAppConfig.getConfig().getInt("service.readTimeOutSeconds") * 1000);
-
- String message = "";
- try {
- ApplicationEntity.Status status = getApplicationStatus();
- if (!status.toString().equals(ApplicationEntity.Status.RUNNING.toString())) {
- message += String.format("Application is not RUNNING, status is %s. ", status.toString());
- }
-
- long currentProcessTimeStamp = Math.min(
- Math.min(
- getServiceLatestUpdateTime(TopologyConstants.HBASE_INSTANCE_SERVICE_NAME, client),
- getServiceLatestUpdateTime(TopologyConstants.HDFS_INSTANCE_SERVICE_NAME, client)
- ), getServiceLatestUpdateTime(TopologyConstants.MR_INSTANCE_SERVICE_NAME, client));
- long currentTimeStamp = System.currentTimeMillis();
- long maxDelayTime = DEFAULT_MAX_DELAY_TIME;
- if (topologyCheckAppConfig.getConfig().hasPath(MAX_DELAY_TIME_KEY)) {
- maxDelayTime = topologyCheckAppConfig.getConfig().getLong(MAX_DELAY_TIME_KEY);
- }
-
- if (!message.isEmpty() || currentTimeStamp - currentProcessTimeStamp > maxDelayTime) {
- message += String.format("Current process time is %sms, delay %s minutes.",
- currentProcessTimeStamp, (currentTimeStamp - currentProcessTimeStamp) * 1.0 / 60000L);
- return Result.unhealthy(message);
- } else {
- return Result.healthy();
- }
- } catch (Exception e) {
- return Result.unhealthy(printMessages(message, "An exception was caught when fetch application current process time: ", ExceptionUtils.getStackTrace(e)));
- } finally {
- client.getJerseyClient().destroy();
- try {
- client.close();
- } catch (Exception e) {
- LOG.warn("{}", e);
- }
- }
- }
-
- private long getServiceLatestUpdateTime(String serviceName, IEagleServiceClient client) throws Exception {
- String query = String.format("%s[@site=\"%s\"]<@site>{max(lastUpdateTime)}",
- serviceName,
- topologyCheckAppConfig.dataExtractorConfig.site);
-
- GenericServiceAPIResponseEntity response = client
- .search(query)
- .pageSize(10)
- .send();
-
- List<Map<List<String>, List<Double>>> results = response.getObj();
- if (results.size() == 0) {
- return Long.MAX_VALUE;
- }
- long currentProcessTimeStamp = results.get(0).get("value").get(0).longValue();
- return currentProcessTimeStamp;
- }
-}
+/*
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.eagle.topology;
+
+import com.typesafe.config.Config;
+import org.apache.commons.lang.exception.ExceptionUtils;
+import org.apache.eagle.app.service.impl.ApplicationHealthCheckBase;
+import org.apache.eagle.log.entity.GenericServiceAPIResponseEntity;
+import org.apache.eagle.metadata.model.ApplicationEntity;
+import org.apache.eagle.service.client.IEagleServiceClient;
+import org.apache.eagle.service.client.impl.EagleServiceClientImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.Map;
+
+public class TopologyCheckApplicationHealthCheck extends ApplicationHealthCheckBase {
+ private static final Logger LOG = LoggerFactory.getLogger(TopologyCheckApplicationHealthCheck.class);
+ private static final long DEFAULT_MAX_DELAY_TIME = 10 * 60 * 1000L;
+
+ private TopologyCheckAppConfig topologyCheckAppConfig;
+
+ public TopologyCheckApplicationHealthCheck(Config config) {
+ super(config);
+ topologyCheckAppConfig = TopologyCheckAppConfig.newInstance(config);
+ }
+
+ @Override
+ public Result check() {
+ //FIXME, this application owner please add eagle server config to Class TopologyCheckAppConfig
+ IEagleServiceClient client = new EagleServiceClientImpl(
+ topologyCheckAppConfig.getConfig().getString("service.host"),
+ topologyCheckAppConfig.getConfig().getInt("service.port"),
+ topologyCheckAppConfig.getConfig().getString("service.username"),
+ topologyCheckAppConfig.getConfig().getString("service.password"));
+
+ client.getJerseyClient().setReadTimeout(topologyCheckAppConfig.getConfig().getInt("service.readTimeOutSeconds") * 1000);
+
+ String message = "";
+ try {
+ ApplicationEntity.Status status = getApplicationStatus();
+ if (!status.toString().equals(ApplicationEntity.Status.RUNNING.toString())) {
+ message += String.format("Application is not RUNNING, status is %s. ", status.toString());
+ }
+
+ long currentProcessTimeStamp = Math.min(
+ Math.min(
+ getServiceLatestUpdateTime(TopologyConstants.HBASE_INSTANCE_SERVICE_NAME, client),
+ getServiceLatestUpdateTime(TopologyConstants.HDFS_INSTANCE_SERVICE_NAME, client)
+ ), getServiceLatestUpdateTime(TopologyConstants.MR_INSTANCE_SERVICE_NAME, client));
+ long currentTimeStamp = System.currentTimeMillis();
+ long maxDelayTime = DEFAULT_MAX_DELAY_TIME;
+ if (topologyCheckAppConfig.getConfig().hasPath(MAX_DELAY_TIME_KEY)) {
+ maxDelayTime = topologyCheckAppConfig.getConfig().getLong(MAX_DELAY_TIME_KEY);
+ }
+
+ if (!message.isEmpty() || currentTimeStamp - currentProcessTimeStamp > maxDelayTime) {
+ message += String.format("Current process time is %sms, delay %s minutes.",
+ currentProcessTimeStamp, (currentTimeStamp - currentProcessTimeStamp) * 1.0 / 60000L);
+ return Result.unhealthy(message);
+ } else {
+ return Result.healthy();
+ }
+ } catch (Exception e) {
+ return Result.unhealthy(printMessages(message, "An exception was caught when fetch application current process time: ", ExceptionUtils.getStackTrace(e)));
+ } finally {
+ client.getJerseyClient().destroy();
+ try {
+ client.close();
+ } catch (Exception e) {
+ LOG.warn("{}", e);
+ }
+ }
+ }
+
+ private long getServiceLatestUpdateTime(String serviceName, IEagleServiceClient client) throws Exception {
+ String query = String.format("%s[@site=\"%s\"]<@site>{max(lastUpdateTime)}",
+ serviceName,
+ topologyCheckAppConfig.dataExtractorConfig.site);
+
+ GenericServiceAPIResponseEntity response = client
+ .search(query)
+ .pageSize(10)
+ .send();
+
+ List<Map<List<String>, List<Double>>> results = response.getObj();
+ if (results.size() == 0) {
+ return Long.MAX_VALUE;
+ }
+ long currentProcessTimeStamp = results.get(0).get("value").get(0).longValue();
+ return currentProcessTimeStamp;
+ }
+}
[5/5] incubator-eagle git commit: [EAGLE-806] Integrate Metric
Process and Persistence with Application Framework
Posted by ha...@apache.org.
[EAGLE-806] Integrate Metric Process and Persistence with Application Framework
Integrate Stream Source and Metric Persistence with Application Framework
- Provide API to easily ingest, process, aggregate and persist metric
- Integrate stream source
- Integrate metric definition and metric persistence.
- Implement basic plug-able aggregation abstraction for later usage.
- Provide `CEPFunction` as default `TransformFunction` based on `SiddhiCEP`
Author: Hao Chen <ha...@apache.org>
Closes #692 from haoch/streamSourceAndPersist.
Project: http://git-wip-us.apache.org/repos/asf/incubator-eagle/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-eagle/commit/10572c29
Tree: http://git-wip-us.apache.org/repos/asf/incubator-eagle/tree/10572c29
Diff: http://git-wip-us.apache.org/repos/asf/incubator-eagle/diff/10572c29
Branch: refs/heads/master
Commit: 10572c296f58532897cdea4f80132d1420890679
Parents: ff22537
Author: Hao Chen <ha...@apache.org>
Authored: Wed Nov 30 09:38:11 2016 +0800
Committer: Hao Chen <ha...@apache.org>
Committed: Wed Nov 30 09:38:11 2016 +0800
----------------------------------------------------------------------
.../alert/engine/coordinator/StreamColumn.java | 408 ++++++-------
.../engine/coordinator/StreamDefinition.java | 288 ++++-----
eagle-core/eagle-app/eagle-app-base/pom.xml | 11 +
.../app/environment/AbstractEnvironment.java | 30 +-
.../eagle/app/environment/Environment.java | 6 +-
.../environment/builder/AggregateFunction.java | 67 +++
.../environment/builder/ApplicationBuilder.java | 122 ++++
.../app/environment/builder/CEPFunction.java | 92 +++
.../app/environment/builder/Collector.java | 23 +
.../app/environment/builder/MaxFunction.java | 48 ++
.../environment/builder/MetricDefinition.java | 165 ++++++
.../builder/StormOutputCollector.java | 36 ++
.../environment/builder/TransformFunction.java | 30 +
.../builder/TransformFunctionBolt.java | 66 +++
.../app/environment/impl/StormEnvironment.java | 34 +-
.../app/messaging/DefaultStreamSinkConfig.java | 42 ++
.../eagle/app/messaging/FlattenEventMapper.java | 60 ++
.../apache/eagle/app/messaging/JsonSchema.java | 66 +++
.../app/messaging/KafkaStreamProvider.java | 130 +++++
.../eagle/app/messaging/KafkaStreamSink.java | 97 ++++
.../app/messaging/KafkaStreamSinkConfig.java | 115 ++++
.../eagle/app/messaging/KafkaStreamSource.java | 162 ++++++
.../app/messaging/KafkaStreamSourceConfig.java | 153 +++++
.../app/messaging/MetricStreamPersist.java | 152 +++++
.../eagle/app/messaging/StormStreamSink.java | 71 +++
.../eagle/app/messaging/StormStreamSource.java | 25 +
.../eagle/app/messaging/StreamEventMapper.java | 35 ++
.../eagle/app/messaging/StreamProvider.java | 50 ++
.../apache/eagle/app/messaging/StreamSink.java | 24 +
.../eagle/app/messaging/StreamSource.java | 23 +
.../eagle/app/service/ApplicationAction.java | 24 +-
.../impl/ApplicationProviderSPILoader.java | 2 +-
.../eagle/app/sink/DefaultStreamSinkConfig.java | 42 --
.../eagle/app/sink/FlattenEventMapper.java | 60 --
.../apache/eagle/app/sink/KafkaStreamSink.java | 144 -----
.../eagle/app/sink/KafkaStreamSinkConfig.java | 109 ----
.../eagle/app/sink/LoggingStreamSink.java | 55 --
.../apache/eagle/app/sink/StormStreamSink.java | 93 ---
.../eagle/app/sink/StreamEventMapper.java | 35 --
.../org/apache/eagle/app/sink/StreamSink.java | 24 -
.../eagle/app/sink/StreamSinkProvider.java | 42 --
.../eagle/app/spi/ApplicationProvider.java | 2 +-
.../eagle/app/utils/StreamConvertHelper.java | 51 ++
.../apache/eagle/app/TestStormApplication.java | 5 +-
.../app/environment/StaticEnvironmentTest.java | 2 +-
.../eagle/app/storm/MockStormApplication.java | 2 +-
.../eagle/app/stream/CEPFunctionTest.java | 50 ++
.../src/test/resources/application.conf | 5 +-
.../org/apache/eagle/common/utils/Tuple2.java | 42 ++
.../apache/eagle/metadata/model/StreamDesc.java | 21 +-
.../metadata/model/StreamSourceConfig.java | 27 +
.../src/test/resources/application-test.xml | 17 +
.../jdbc/provider/JDBCDataSourceProvider.java | 2 +-
.../ApplicationEntityServiceJDBCImpl.java | 4 +-
.../service/client/EagleServiceConnector.java | 3 +-
.../client/impl/EagleServiceClientImpl.java | 15 +-
.../app/example/ExampleStormApplication.java | 2 +-
.../src/test/resources/application.conf | 2 +-
.../org/apache/eagle/gc/GCLogApplication.java | 2 +-
eagle-hadoop-metric/pom.xml | 16 +-
.../eagle/metric/HadoopMetricMonitorApp.java | 38 ++
.../metric/HadoopMetricMonitorAppProdiver.java | 12 +-
...le.metric.HadoopMetricMonitorAppProdiver.xml | 4 +-
.../HadoopMetricMonitorAppProdiverTest.java | 84 ---
.../metric/HadoopMetricMonitorAppDebug.java | 23 +
.../HadoopMetricMonitorAppProviderTest.java | 84 +++
.../eagle/metric/SendSampleDataToKafka.java | 55 ++
.../src/test/resources/application.conf | 49 ++
.../resources/hadoop_jmx_metric_sample.json | 8 +
...adoopQueueRunningApplicationHealthCheck.java | 204 +++----
.../jpm/aggregation/storm/AggregationSpout.java | 2 +-
.../jpm/mr/history/MRHistoryJobApplication.java | 9 +-
.../jpm/mr/running/MRRunningJobApplication.java | 4 +-
.../src/test/resources/mrconf_30784.xml | 2 +-
.../SparkHistoryJobApplicationHealthCheck.java | 198 +++----
.../jpm/spark/running/SparkRunningJobApp.java | 4 +-
.../hbase/HBaseAuditLogApplication.java | 2 +-
.../AbstractHdfsAuditLogApplication.java | 4 +-
.../hive/HiveQueryMonitoringApplication.java | 2 +-
.../oozie/parse/OozieAuditLogApplication.java | 2 +-
eagle-server-assembly/src/main/conf/eagle.conf | 4 +-
.../src/main/resources/application.conf | 4 +-
.../apache/eagle/topology/TopologyCheckApp.java | 2 +-
.../TopologyCheckApplicationHealthCheck.java | 218 +++----
.../hbase/HbaseTopologyEntityParser.java | 330 +++++------
.../hdfs/HdfsTopologyEntityParser.java | 579 +++++++++----------
.../extractor/mr/MRTopologyEntityParser.java | 438 +++++++-------
.../topology/storm/TopologyDataPersistBolt.java | 400 ++++++-------
.../entity/HdfsServiceTopologyAPIEntity.java | 246 ++++----
89 files changed, 4118 insertions(+), 2424 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/engine/coordinator/StreamColumn.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/engine/coordinator/StreamColumn.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/engine/coordinator/StreamColumn.java
index 4628043..9705efc 100644
--- a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/engine/coordinator/StreamColumn.java
+++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/engine/coordinator/StreamColumn.java
@@ -1,205 +1,205 @@
-/*
- * 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.eagle.alert.engine.coordinator;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-import java.io.IOException;
-import java.io.Serializable;
-import java.util.HashMap;
-import javax.xml.bind.annotation.adapters.XmlAdapter;
-import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
-
-public class StreamColumn implements Serializable {
-
- private static final long serialVersionUID = -5457861313624389106L;
- private String name;
- private Type type;
- private Object defaultValue;
- private boolean required;
- private String description;
- private String nodataExpression;
-
- public String toString() {
- return String.format("StreamColumn=name[%s], type=[%s], defaultValue=[%s], required=[%s], nodataExpression=[%s]",
- name, type, defaultValue, required, nodataExpression);
- }
-
- public String getNodataExpression() {
- return nodataExpression;
- }
-
- public void setNodataExpression(String nodataExpression) {
- this.nodataExpression = nodataExpression;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- @XmlJavaTypeAdapter(StreamColumnTypeAdapter.class)
- public Type getType() {
- return type;
- }
-
- public void setType(Type type) {
- this.type = type;
- }
-
- @XmlJavaTypeAdapter(value = DefaultValueAdapter.class)
- public Object getDefaultValue() {
- return defaultValue;
- }
-
- private void ensureDefaultValueType() {
- if (this.getDefaultValue() != null && (this.getDefaultValue() instanceof String) && this.getType() != Type.STRING) {
- switch (this.getType()) {
- case INT:
- this.setDefaultValue(Integer.valueOf((String) this.getDefaultValue()));
- break;
- case LONG:
- this.setDefaultValue(Long.valueOf((String) this.getDefaultValue()));
- break;
- case FLOAT:
- this.setDefaultValue(Float.valueOf((String) this.getDefaultValue()));
- break;
- case DOUBLE:
- this.setDefaultValue(Double.valueOf((String) this.getDefaultValue()));
- break;
- case BOOL:
- this.setDefaultValue(Boolean.valueOf((String) this.getDefaultValue()));
- break;
- case OBJECT:
- try {
- this.setDefaultValue(new ObjectMapper().readValue((String) this.getDefaultValue(), HashMap.class));
- } catch (IOException e) {
- throw new IllegalArgumentException(e);
- }
- break;
- default:
- throw new IllegalArgumentException("Illegal type: " + this.getType());
- }
- }
- }
-
- public void setDefaultValue(Object defaultValue) {
- this.defaultValue = defaultValue;
- ensureDefaultValueType();
- }
-
- public boolean isRequired() {
- return required;
- }
-
- public void setRequired(boolean required) {
- this.required = required;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public enum Type implements Serializable {
- STRING("string"), INT("int"), LONG("long"), FLOAT("float"), DOUBLE("double"), BOOL("bool"), OBJECT("object");
-
- private final String name;
-
- Type(String name) {
- this.name = name;
- }
-
- @Override
- public String toString() {
- return name;
- }
-
- @com.fasterxml.jackson.annotation.JsonCreator
- public static Type getEnumFromValue(String value) {
- for (Type testEnum : values()) {
- if (testEnum.name.equalsIgnoreCase(value)) {
- return testEnum;
- }
- }
- throw new IllegalArgumentException();
- }
- }
-
- public static class StreamColumnTypeAdapter extends XmlAdapter<String, Type> {
-
- @Override
- public Type unmarshal(String v) throws Exception {
- return Type.getEnumFromValue(v);
- }
-
- @Override
- public String marshal(Type v) throws Exception {
- return v.name;
- }
- }
-
- public static class DefaultValueAdapter extends XmlAdapter<String, Object> {
- @Override
- public Object unmarshal(String v) throws Exception {
- return v;
- }
-
- @Override
- public String marshal(Object v) throws Exception {
- return v.toString();
- }
- }
-
- public static class Builder {
- private StreamColumn column;
-
- public Builder() {
- column = new StreamColumn();
- }
-
- public Builder name(String name) {
- column.setName(name);
- return this;
- }
-
- public Builder type(Type type) {
- column.setType(type);
- return this;
- }
-
- public Builder defaultValue(Object defaultValue) {
- column.setDefaultValue(defaultValue);
- return this;
- }
-
- public Builder required(boolean required) {
- column.setRequired(required);
- return this;
- }
-
- public StreamColumn build() {
- return column;
- }
- }
+/*
+ * 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.eagle.alert.engine.coordinator;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.HashMap;
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
+public class StreamColumn implements Serializable {
+
+ private static final long serialVersionUID = -5457861313624389106L;
+ private String name;
+ private Type type;
+ private Object defaultValue;
+ private boolean required;
+ private String description;
+ private String nodataExpression;
+
+ public String toString() {
+ return String.format("StreamColumn=name[%s], type=[%s], defaultValue=[%s], required=[%s], nodataExpression=[%s]",
+ name, type, defaultValue, required, nodataExpression);
+ }
+
+ public String getNodataExpression() {
+ return nodataExpression;
+ }
+
+ public void setNodataExpression(String nodataExpression) {
+ this.nodataExpression = nodataExpression;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @XmlJavaTypeAdapter(StreamColumnTypeAdapter.class)
+ public Type getType() {
+ return type;
+ }
+
+ public void setType(Type type) {
+ this.type = type;
+ }
+
+ @XmlJavaTypeAdapter(value = DefaultValueAdapter.class)
+ public Object getDefaultValue() {
+ return defaultValue;
+ }
+
+ private void ensureDefaultValueType() {
+ if (this.getDefaultValue() != null && (this.getDefaultValue() instanceof String) && this.getType() != Type.STRING) {
+ switch (this.getType()) {
+ case INT:
+ this.setDefaultValue(Integer.valueOf((String) this.getDefaultValue()));
+ break;
+ case LONG:
+ this.setDefaultValue(Long.valueOf((String) this.getDefaultValue()));
+ break;
+ case FLOAT:
+ this.setDefaultValue(Float.valueOf((String) this.getDefaultValue()));
+ break;
+ case DOUBLE:
+ this.setDefaultValue(Double.valueOf((String) this.getDefaultValue()));
+ break;
+ case BOOL:
+ this.setDefaultValue(Boolean.valueOf((String) this.getDefaultValue()));
+ break;
+ case OBJECT:
+ try {
+ this.setDefaultValue(new ObjectMapper().readValue((String) this.getDefaultValue(), HashMap.class));
+ } catch (IOException e) {
+ throw new IllegalArgumentException(e);
+ }
+ break;
+ default:
+ throw new IllegalArgumentException("Illegal type: " + this.getType());
+ }
+ }
+ }
+
+ public void setDefaultValue(Object defaultValue) {
+ this.defaultValue = defaultValue;
+ ensureDefaultValueType();
+ }
+
+ public boolean isRequired() {
+ return required;
+ }
+
+ public void setRequired(boolean required) {
+ this.required = required;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public enum Type implements Serializable {
+ STRING("string"), INT("int"), LONG("long"), FLOAT("float"), DOUBLE("double"), BOOL("bool"), OBJECT("object");
+
+ private final String name;
+
+ Type(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+
+ @com.fasterxml.jackson.annotation.JsonCreator
+ public static Type getEnumFromValue(String value) {
+ for (Type testEnum : values()) {
+ if (testEnum.name.equalsIgnoreCase(value)) {
+ return testEnum;
+ }
+ }
+ throw new IllegalArgumentException();
+ }
+ }
+
+ public static class StreamColumnTypeAdapter extends XmlAdapter<String, Type> {
+
+ @Override
+ public Type unmarshal(String v) throws Exception {
+ return Type.getEnumFromValue(v);
+ }
+
+ @Override
+ public String marshal(Type v) throws Exception {
+ return v.name;
+ }
+ }
+
+ public static class DefaultValueAdapter extends XmlAdapter<String, Object> {
+ @Override
+ public Object unmarshal(String v) throws Exception {
+ return v;
+ }
+
+ @Override
+ public String marshal(Object v) throws Exception {
+ return v.toString();
+ }
+ }
+
+ public static class Builder {
+ private StreamColumn column;
+
+ public Builder() {
+ column = new StreamColumn();
+ }
+
+ public Builder name(String name) {
+ column.setName(name);
+ return this;
+ }
+
+ public Builder type(Type type) {
+ column.setType(type);
+ return this;
+ }
+
+ public Builder defaultValue(Object defaultValue) {
+ column.setDefaultValue(defaultValue);
+ return this;
+ }
+
+ public Builder required(boolean required) {
+ column.setRequired(required);
+ return this;
+ }
+
+ public StreamColumn build() {
+ return column;
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/engine/coordinator/StreamDefinition.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/engine/coordinator/StreamDefinition.java b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/engine/coordinator/StreamDefinition.java
index e0789f9..1be36f3 100644
--- a/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/engine/coordinator/StreamDefinition.java
+++ b/eagle-core/eagle-alert-parent/eagle-alert/alert-common/src/main/java/org/apache/eagle/alert/engine/coordinator/StreamDefinition.java
@@ -1,145 +1,145 @@
-/*
- * 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.eagle.alert.engine.coordinator;
-
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlElementWrapper;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * This is actually a data source schema.
- *
- * @since Apr 5, 2016
- */
-public class StreamDefinition implements Serializable {
- private static final long serialVersionUID = 2352202882328931825L;
-
- // Stream unique ID
- private String streamId;
-
- // Stream description
- private String description;
-
- // Is validateable or not
- private boolean validate;
-
- // Is timeseries-based stream or not
- private boolean timeseries;
-
- // TODO: Decouple dataSource and siteId from stream definition
-
- // Stream data source ID
- private String dataSource;
-
- // Tenant (Site) ID
- private String siteId;
-
- private List<StreamColumn> columns = new ArrayList<>();
-
- public String toString() {
- return String.format("StreamDefinition[streamId=%s, dataSource=%s, description=%s, validate=%s, timeseries=%s, columns=%s",
- streamId,
- dataSource,
- description,
- validate,
- timeseries,
- columns);
- }
-
- public String getStreamId() {
- return streamId;
- }
-
- public void setStreamId(String streamId) {
- this.streamId = streamId;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public boolean isValidate() {
- return validate;
- }
-
- public void setValidate(boolean validate) {
- this.validate = validate;
- }
-
- public boolean isTimeseries() {
- return timeseries;
- }
-
- public void setTimeseries(boolean timeseries) {
- this.timeseries = timeseries;
- }
-
- @XmlElementWrapper(name = "columns")
- @XmlElement(name = "column")
- public List<StreamColumn> getColumns() {
- return columns;
- }
-
- public void setColumns(List<StreamColumn> columns) {
- this.columns = columns;
- }
-
- public String getDataSource() {
- return dataSource;
- }
-
- public void setDataSource(String dataSource) {
- this.dataSource = dataSource;
- }
-
- public int getColumnIndex(String column) {
- int i = 0;
- for (StreamColumn col : this.getColumns()) {
- if (col.getName().equals(column)) {
- return i;
- }
- i++;
- }
- return -1;
- }
-
- public String getSiteId() {
- return siteId;
- }
-
- public void setSiteId(String siteId) {
- this.siteId = siteId;
- }
-
- public StreamDefinition copy() {
- StreamDefinition copied = new StreamDefinition();
- copied.setColumns(this.getColumns());
- copied.setDataSource(this.getDataSource());
- copied.setDescription(this.getDescription());
- copied.setSiteId(this.getSiteId());
- copied.setStreamId(this.getStreamId());
- copied.setTimeseries(this.isTimeseries());
- copied.setValidate(this.isValidate());
- return copied;
- }
+/*
+ * 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.eagle.alert.engine.coordinator;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * This is actually a data source schema.
+ *
+ * @since Apr 5, 2016
+ */
+public class StreamDefinition implements Serializable {
+ private static final long serialVersionUID = 2352202882328931825L;
+
+ // Stream unique ID
+ private String streamId;
+
+ // Stream description
+ private String description;
+
+ // Is validateable or not
+ private boolean validate;
+
+ // Is timeseries-based stream or not
+ private boolean timeseries;
+
+ // TODO: Decouple dataSource and siteId from stream definition
+
+ // Stream data source ID
+ private String dataSource;
+
+ // Tenant (Site) ID
+ private String siteId;
+
+ private List<StreamColumn> columns = new ArrayList<>();
+
+ public String toString() {
+ return String.format("StreamDefinition[streamId=%s, dataSource=%s, description=%s, validate=%s, timeseries=%s, columns=%s",
+ streamId,
+ dataSource,
+ description,
+ validate,
+ timeseries,
+ columns);
+ }
+
+ public String getStreamId() {
+ return streamId;
+ }
+
+ public void setStreamId(String streamId) {
+ this.streamId = streamId;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public boolean isValidate() {
+ return validate;
+ }
+
+ public void setValidate(boolean validate) {
+ this.validate = validate;
+ }
+
+ public boolean isTimeseries() {
+ return timeseries;
+ }
+
+ public void setTimeseries(boolean timeseries) {
+ this.timeseries = timeseries;
+ }
+
+ @XmlElementWrapper(name = "columns")
+ @XmlElement(name = "column")
+ public List<StreamColumn> getColumns() {
+ return columns;
+ }
+
+ public void setColumns(List<StreamColumn> columns) {
+ this.columns = columns;
+ }
+
+ public String getDataSource() {
+ return dataSource;
+ }
+
+ public void setDataSource(String dataSource) {
+ this.dataSource = dataSource;
+ }
+
+ public int getColumnIndex(String column) {
+ int i = 0;
+ for (StreamColumn col : this.getColumns()) {
+ if (col.getName().equals(column)) {
+ return i;
+ }
+ i++;
+ }
+ return -1;
+ }
+
+ public String getSiteId() {
+ return siteId;
+ }
+
+ public void setSiteId(String siteId) {
+ this.siteId = siteId;
+ }
+
+ public StreamDefinition copy() {
+ StreamDefinition copied = new StreamDefinition();
+ copied.setColumns(this.getColumns());
+ copied.setDataSource(this.getDataSource());
+ copied.setDescription(this.getDescription());
+ copied.setSiteId(this.getSiteId());
+ copied.setStreamId(this.getStreamId());
+ copied.setTimeseries(this.isTimeseries());
+ copied.setValidate(this.isValidate());
+ return copied;
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/pom.xml
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/pom.xml b/eagle-core/eagle-app/eagle-app-base/pom.xml
index a5e295e..21fdfae 100644
--- a/eagle-core/eagle-app/eagle-app-base/pom.xml
+++ b/eagle-core/eagle-app/eagle-app-base/pom.xml
@@ -114,6 +114,17 @@
</exclusions>
</dependency>
<dependency>
+ <groupId>org.apache.eagle</groupId>
+ <artifactId>eagle-client-base</artifactId>
+ <version>${project.version}</version>
+ <exclusions>
+ <exclusion>
+ <artifactId>xercesImpl</artifactId>
+ <groupId>xerces</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/AbstractEnvironment.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/AbstractEnvironment.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/AbstractEnvironment.java
index 02c130a..5032aa6 100644
--- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/AbstractEnvironment.java
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/AbstractEnvironment.java
@@ -16,8 +16,7 @@
*/
package org.apache.eagle.app.environment;
-import org.apache.eagle.app.sink.KafkaStreamSink;
-import org.apache.eagle.app.sink.StreamSinkProvider;
+import org.apache.eagle.app.messaging.*;
import com.typesafe.config.Config;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.slf4j.Logger;
@@ -26,25 +25,25 @@ import org.slf4j.LoggerFactory;
public abstract class AbstractEnvironment implements Environment {
private final Config config;
- private final StreamSinkProvider sinkProvider;
- private static final String APPLICATIONS_SINK_TYPE_PROPS_KEY = "application.sink.provider";
- private static final String DEFAULT_APPLICATIONS_SINK_TYPE = KafkaStreamSink.Provider.class.getName();
+ private final StreamProvider streamProvider;
+ private static final String APPLICATIONS_MESSAGING_TYPE_PROPS_KEY = "application.stream.provider";
+ private static final String DEFAULT_APPLICATIONS_MESSAGING_TYPE = KafkaStreamProvider.class.getName();
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractEnvironment.class);
public AbstractEnvironment(Config config) {
this.config = config;
- this.sinkProvider = loadStreamSinkProvider();
+ this.streamProvider = loadStreamProvider();
}
- private StreamSinkProvider loadStreamSinkProvider() {
- String sinkProviderClassName = config.hasPath(APPLICATIONS_SINK_TYPE_PROPS_KEY)
- ? config.getString(APPLICATIONS_SINK_TYPE_PROPS_KEY) : DEFAULT_APPLICATIONS_SINK_TYPE;
+ private StreamProvider loadStreamProvider() {
+ String sinkProviderClassName = config.hasPath(APPLICATIONS_MESSAGING_TYPE_PROPS_KEY)
+ ? config.getString(APPLICATIONS_MESSAGING_TYPE_PROPS_KEY) : DEFAULT_APPLICATIONS_MESSAGING_TYPE;
try {
Class<?> sinkProviderClass = Class.forName(sinkProviderClassName);
- if (!StreamSinkProvider.class.isAssignableFrom(sinkProviderClass)) {
- throw new IllegalStateException(sinkProviderClassName + "is not assignable from " + StreamSinkProvider.class.getCanonicalName());
+ if (!StreamProvider.class.isAssignableFrom(sinkProviderClass)) {
+ throw new IllegalStateException(sinkProviderClassName + "is not assignable from " + StreamProvider.class.getCanonicalName());
}
- StreamSinkProvider instance = (StreamSinkProvider) sinkProviderClass.newInstance();
+ StreamProvider instance = (StreamProvider) sinkProviderClass.newInstance();
LOGGER.info("Loaded {}", instance);
return instance;
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
@@ -60,12 +59,13 @@ public abstract class AbstractEnvironment implements Environment {
.append(this.config()).build();
}
- public StreamSinkProvider streamSink() {
- return sinkProvider;
+ public StreamProvider stream() {
+ return streamProvider;
}
+
@Override
public Config config() {
return config;
}
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/Environment.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/Environment.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/Environment.java
index 29e90d9..db87693 100644
--- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/Environment.java
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/Environment.java
@@ -16,7 +16,7 @@
*/
package org.apache.eagle.app.environment;
-import org.apache.eagle.app.sink.StreamSinkProvider;
+import org.apache.eagle.app.messaging.StreamProvider;
import com.typesafe.config.Config;
import java.io.Serializable;
@@ -31,7 +31,7 @@ public interface Environment extends Serializable {
/**
* TODO Only useful for Storm/Spark Exeuctable Application instead of static web application.
*
- * @return StreamSinkProvider.
+ * @return StreamProvider.
*/
- StreamSinkProvider streamSink();
+ StreamProvider stream();
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/AggregateFunction.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/AggregateFunction.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/AggregateFunction.java
new file mode 100644
index 0000000..836300c
--- /dev/null
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/AggregateFunction.java
@@ -0,0 +1,67 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.eagle.app.environment.builder;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+public abstract class AggregateFunction implements TransformFunction {
+ private String aggFieldName;
+ private String resultFieldName;
+ private List<String> groupByFieldNames;
+ private long windowLengthMs;
+
+ public List<String> getGroupByFieldNames() {
+ return groupByFieldNames;
+ }
+
+ public void setGroupByFieldNames(List<String> groupByFieldNames) {
+ this.groupByFieldNames = groupByFieldNames;
+ }
+
+ public String getResultFieldName() {
+ return resultFieldName;
+ }
+
+ public void setResultFieldName(String resultFieldName) {
+ this.resultFieldName = resultFieldName;
+ }
+
+ public String getAggFieldName() {
+ return aggFieldName;
+ }
+
+ public void setAggFieldName(String aggFieldName) {
+ this.aggFieldName = aggFieldName;
+ }
+
+ public AggregateFunction asField(String resultFieldName) {
+ this.setResultFieldName(resultFieldName);
+ return this;
+ }
+
+ public AggregateFunction groupBy(String... groupByFieldNames) {
+ this.setGroupByFieldNames(Arrays.asList(groupByFieldNames));
+ return this;
+ }
+
+ public AggregateFunction windowBy(long windowLength, TimeUnit timeUnit) {
+ this.windowLengthMs = timeUnit.toMillis(windowLength);
+ return this;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/ApplicationBuilder.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/ApplicationBuilder.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/ApplicationBuilder.java
new file mode 100644
index 0000000..83f00db
--- /dev/null
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/ApplicationBuilder.java
@@ -0,0 +1,122 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.eagle.app.environment.builder;
+
+
+import backtype.storm.generated.StormTopology;
+import backtype.storm.topology.TopologyBuilder;
+import com.google.common.base.Preconditions;
+import com.typesafe.config.Config;
+import org.apache.eagle.app.environment.impl.StormEnvironment;
+import org.apache.eagle.app.messaging.MetricStreamPersist;
+import org.apache.eagle.app.messaging.StormStreamSource;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Storm Application Builder DSL.
+ */
+public class ApplicationBuilder {
+ private final StormEnvironment environment;
+ private final Config appConfig;
+ private final TopologyBuilder topologyBuilder;
+ private final AtomicInteger identifier;
+
+ public ApplicationBuilder(Config appConfig, StormEnvironment environment) {
+ this.appConfig = appConfig;
+ this.environment = environment;
+ this.identifier = new AtomicInteger(0);
+ this.topologyBuilder = new TopologyBuilder();
+ }
+
+ public class BuilderContext {
+ public StormTopology toTopology() {
+ return topologyBuilder.createTopology();
+ }
+ }
+
+ public abstract class InitializedStream extends BuilderContext {
+ private String id;
+
+ InitializedStream(String id) {
+ Preconditions.checkNotNull(id);
+ this.id = id;
+ }
+
+ String getId() {
+ return this.id;
+ }
+
+ /**
+ * Persist source data stream as metric.
+ */
+ public BuilderContext saveAsMetric(MetricDefinition metricDefinition) {
+ topologyBuilder.setBolt(generateId("MetricPersist"), new MetricStreamPersist(metricDefinition, appConfig)).shuffleGrouping(getId());
+ return this;
+ }
+
+ public TransformedStream transformBy(TransformFunction function) {
+ String componentId = generateId(function.getName());
+ topologyBuilder.setBolt(componentId, new TransformFunctionBolt(function)).shuffleGrouping(getId());
+ return new TransformedStream(componentId);
+ }
+ }
+
+ public class SourcedStream extends InitializedStream {
+ private final Config appConfig;
+ private final StormStreamSource streamSource;
+
+ private SourcedStream(SourcedStream withSourcedStream) {
+ this(withSourcedStream.getId(), withSourcedStream.appConfig, withSourcedStream.streamSource);
+ }
+
+ private SourcedStream(String componentId, Config appConfig, StormStreamSource streamSource) {
+ super(componentId);
+ this.appConfig = appConfig;
+ this.streamSource = streamSource;
+ topologyBuilder.setSpout(componentId, streamSource);
+ }
+ }
+
+ public class TransformedStream extends InitializedStream {
+ public TransformedStream(String id) {
+ super(id);
+ throw new IllegalStateException("TODO: Not implemented yet");
+ }
+ }
+
+ public TopologyBuilder getTopologyBuilder() {
+ return this.topologyBuilder;
+ }
+
+ public StormTopology createTopology() {
+ return topologyBuilder.createTopology();
+ }
+
+
+ public SourcedStream fromStream(String streamId) {
+ return new SourcedStream(generateId("SourcedStream-" + streamId), this.appConfig, environment.getStreamSource(streamId, this.appConfig));
+ }
+
+ public SourcedStream fromStream(SourcedStream sourcedStream) {
+ return new SourcedStream(sourcedStream);
+ }
+
+ private String generateId(String prefix) {
+ return String.format("%s_%s", prefix, this.identifier.getAndIncrement());
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/CEPFunction.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/CEPFunction.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/CEPFunction.java
new file mode 100644
index 0000000..dd3b214
--- /dev/null
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/CEPFunction.java
@@ -0,0 +1,92 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.eagle.app.environment.builder;
+
+import java.util.Map;
+
+/**
+ * TODO: Not implemented yet.
+ */
+public class CEPFunction implements TransformFunction {
+
+ private final CEPDefinition cepDefinition;
+ private Collector collector;
+
+ public CEPFunction(CEPDefinition cepDefinition) {
+ this.cepDefinition = cepDefinition;
+ }
+
+ public CEPFunction(String siddhiQuery, String inputStreamId, String outputStreamId) {
+ this.cepDefinition = new CEPDefinition(siddhiQuery,inputStreamId, outputStreamId);
+ }
+
+ @Override
+ public String getName() {
+ return "CEPFunction";
+ }
+
+ @Override
+ public void open(Collector collector) {
+ throw new IllegalStateException("TODO: Not implemented yet");
+ }
+
+ @Override
+ public void transform(Map event) {
+ throw new IllegalStateException("TODO: Not implemented yet");
+ }
+
+ @Override
+ public void close() {
+ throw new IllegalStateException("TODO: Not implemented yet");
+ }
+
+ public static class CEPDefinition {
+ private String inputStreamId;
+ private String outputStreamId;
+ private String siddhiQuery;
+
+ public CEPDefinition(String siddhiQuery, String inputStreamId, String outputStreamId) {
+ this.siddhiQuery = siddhiQuery;
+ this.inputStreamId = inputStreamId;
+ this.outputStreamId = outputStreamId;
+ }
+
+ public String getSiddhiQuery() {
+ return siddhiQuery;
+ }
+
+ public void setSiddhiQuery(String siddhiQuery) {
+ this.siddhiQuery = siddhiQuery;
+ }
+
+ public String getOutputStreamId() {
+ return outputStreamId;
+ }
+
+ public void setOutputStreamId(String outputStreamId) {
+ this.outputStreamId = outputStreamId;
+ }
+
+ public String getInputStreamId() {
+ return inputStreamId;
+ }
+
+ public void setInputStreamId(String inputStreamId) {
+ this.inputStreamId = inputStreamId;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/Collector.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/Collector.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/Collector.java
new file mode 100644
index 0000000..f86d101
--- /dev/null
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/Collector.java
@@ -0,0 +1,23 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.eagle.app.environment.builder;
+
+import java.util.Map;
+
+public interface Collector {
+ void collect(Object key, Map event);
+}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/MaxFunction.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/MaxFunction.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/MaxFunction.java
new file mode 100644
index 0000000..04c5bf9
--- /dev/null
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/MaxFunction.java
@@ -0,0 +1,48 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.eagle.app.environment.builder;
+
+import java.util.Map;
+
+public class MaxFunction extends AggregateFunction {
+ @Override
+ public String getName() {
+ return "MAX";
+ }
+
+ @Override
+ public void open(Collector collector) {
+ throw new IllegalStateException("TODO: Not implemented yet.");
+ }
+
+ @Override
+ public void transform(Map event) {
+ throw new IllegalStateException("TODO: Not implemented yet.");
+ }
+
+ @Override
+ public void close() {
+
+ throw new IllegalStateException("TODO: Not implemented yet.");
+ }
+
+ public static MaxFunction maxOf(String aggFieldName) {
+ MaxFunction function = new MaxFunction();
+ function.setAggFieldName(aggFieldName);
+ return function;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/MetricDefinition.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/MetricDefinition.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/MetricDefinition.java
new file mode 100644
index 0000000..62a81b0
--- /dev/null
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/MetricDefinition.java
@@ -0,0 +1,165 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.eagle.app.environment.builder;
+
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+public class MetricDefinition implements Serializable {
+
+ /**
+ * Support simple and complex name format, by default using "metric" field.
+ */
+ private NameSelector nameSelector = new FieldNameSelector("metric");
+
+ /**
+ * Support event/system time, by default using system time.
+ */
+ private TimestampSelector timestampSelector = new SystemTimestampSelector();
+
+ /**
+ * Metric dimension field name.
+ */
+ private List<String> dimensionFields;
+
+ /**
+ * Metric value field name.
+ */
+ private String valueField = "value";
+
+ public NameSelector getNameSelector() {
+ return nameSelector;
+ }
+
+ public void setNameSelector(NameSelector nameSelector) {
+ this.nameSelector = nameSelector;
+ }
+
+ public String getValueField() {
+ return valueField;
+ }
+
+ public void setValueField(String valueField) {
+ this.valueField = valueField;
+ }
+
+ public List<String> getDimensionFields() {
+ return dimensionFields;
+ }
+
+ public void setDimensionFields(List<String> dimensionFields) {
+ this.dimensionFields = dimensionFields;
+ }
+
+ public TimestampSelector getTimestampSelector() {
+ return timestampSelector;
+ }
+
+ public void setTimestampSelector(TimestampSelector timestampSelector) {
+ this.timestampSelector = timestampSelector;
+ }
+
+
+ @FunctionalInterface
+ public interface NameSelector extends Serializable {
+ String getMetricName(Map event);
+ }
+
+ @FunctionalInterface
+ public interface TimestampSelector extends Serializable {
+ Long getTimestamp(Map event);
+ }
+
+ public static MetricDefinition namedBy(NameSelector nameSelector) {
+ MetricDefinition metricDefinition = new MetricDefinition();
+ metricDefinition.setNameSelector(nameSelector);
+ return metricDefinition;
+ }
+
+ public static MetricDefinition namedByField(String nameField) {
+ MetricDefinition metricDefinition = new MetricDefinition();
+ metricDefinition.setNameSelector(new FieldNameSelector(nameField));
+ return metricDefinition;
+ }
+
+ public MetricDefinition eventTimeByField(String timestampField) {
+ this.setTimestampSelector(new EventTimestampSelector(timestampField));
+ return this;
+ }
+
+ public MetricDefinition dimensionFields(String... dimensionFields) {
+ this.setDimensionFields(Arrays.asList(dimensionFields));
+ return this;
+ }
+
+ public MetricDefinition valueField(String valueField) {
+ this.setValueField(valueField);
+ return this;
+ }
+
+ public class EventTimestampSelector implements TimestampSelector {
+ private final String timestampField;
+
+ EventTimestampSelector(String timestampField) {
+ this.timestampField = timestampField;
+ }
+
+ @Override
+ public Long getTimestamp(Map event) {
+ if (event.containsKey(timestampField)) {
+ Object timestampValue = event.get(timestampField);
+ if (timestampValue instanceof Integer) {
+ return Long.valueOf((Integer) timestampValue);
+ }
+ if (timestampValue instanceof String) {
+ return Long.valueOf((String) timestampValue);
+ } else {
+ return (Long) timestampValue;
+ }
+ } else {
+ throw new IllegalArgumentException("Timestamp field '" + timestampField + "' not exists");
+ }
+ }
+ }
+
+ public static class SystemTimestampSelector implements TimestampSelector {
+ @Override
+ public Long getTimestamp(Map event) {
+ return System.currentTimeMillis();
+ }
+ }
+
+ public static class FieldNameSelector implements NameSelector {
+ private final String fieldName;
+
+ FieldNameSelector(String fieldName) {
+ this.fieldName = fieldName;
+ }
+
+ @Override
+ public String getMetricName(Map event) {
+ if (event.containsKey(fieldName)) {
+ return (String) event.get(fieldName);
+ } else {
+ throw new IllegalArgumentException("Metric name field '" + fieldName + "' not exists: " + event);
+ }
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/StormOutputCollector.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/StormOutputCollector.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/StormOutputCollector.java
new file mode 100644
index 0000000..9135cc8
--- /dev/null
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/StormOutputCollector.java
@@ -0,0 +1,36 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.eagle.app.environment.builder;
+
+import backtype.storm.task.OutputCollector;
+
+import java.util.Arrays;
+
+import java.util.Map;
+
+public class StormOutputCollector implements Collector {
+ private final OutputCollector delegate;
+
+ StormOutputCollector(OutputCollector delegate) {
+ this.delegate = delegate;
+ }
+
+ @Override
+ public void collect(Object key, Map event) {
+ delegate.emit(Arrays.asList(key, event));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/TransformFunction.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/TransformFunction.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/TransformFunction.java
new file mode 100644
index 0000000..11974ff
--- /dev/null
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/TransformFunction.java
@@ -0,0 +1,30 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.eagle.app.environment.builder;
+
+import java.io.Serializable;
+import java.util.Map;
+
+public interface TransformFunction extends Serializable {
+ String getName();
+
+ void open(Collector collector);
+
+ void transform(Map event);
+
+ void close();
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/TransformFunctionBolt.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/TransformFunctionBolt.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/TransformFunctionBolt.java
new file mode 100644
index 0000000..dbc7239
--- /dev/null
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/builder/TransformFunctionBolt.java
@@ -0,0 +1,66 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.eagle.app.environment.builder;
+
+import backtype.storm.task.OutputCollector;
+import backtype.storm.task.TopologyContext;
+import backtype.storm.topology.OutputFieldsDeclarer;
+import backtype.storm.topology.base.BaseRichBolt;
+import backtype.storm.tuple.Fields;
+import backtype.storm.tuple.Tuple;
+import org.apache.eagle.app.utils.StreamConvertHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+
+public class TransformFunctionBolt extends BaseRichBolt {
+ private static final Logger LOG = LoggerFactory.getLogger(TransformFunctionBolt.class);
+ private final TransformFunction function;
+ private OutputCollector collector;
+
+ public TransformFunctionBolt(TransformFunction function) {
+ this.function = function;
+ }
+
+ @Override
+ public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
+ this.function.open(new StormOutputCollector(collector));
+ this.collector = collector;
+ }
+
+ @Override
+ public void execute(Tuple input) {
+ try {
+ this.function.transform(StreamConvertHelper.tupleToEvent(input).f1());
+ this.collector.ack(input);
+ } catch (Throwable throwable) {
+ LOG.error("Transform error: {}", input, throwable);
+ this.collector.reportError(throwable);
+ }
+ }
+
+ @Override
+ public void declareOutputFields(OutputFieldsDeclarer declarer) {
+ declarer.declare(new Fields("f1","f2"));
+ }
+
+ @Override
+ public void cleanup() {
+ this.function.close();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/impl/StormEnvironment.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/impl/StormEnvironment.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/impl/StormEnvironment.java
index 18675a6..ae52cd0 100644
--- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/impl/StormEnvironment.java
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/environment/impl/StormEnvironment.java
@@ -17,8 +17,13 @@
package org.apache.eagle.app.environment.impl;
import org.apache.eagle.app.environment.AbstractEnvironment;
-import org.apache.eagle.app.sink.StormStreamSink;
+import org.apache.eagle.app.environment.builder.ApplicationBuilder;
+import org.apache.eagle.app.environment.builder.MetricDefinition;
+import org.apache.eagle.app.environment.builder.TransformFunction;
+import org.apache.eagle.app.environment.builder.TransformFunctionBolt;
+import org.apache.eagle.app.messaging.*;
import com.typesafe.config.Config;
+import org.apache.eagle.metadata.model.StreamSourceConfig;
/**
* Storm Execution Environment Context.
@@ -28,7 +33,30 @@ public class StormEnvironment extends AbstractEnvironment {
super(envConfig);
}
+ // ----------------------------------
+ // Classic Storm Topology Builder API
+ // ----------------------------------
public StormStreamSink getStreamSink(String streamId, Config config) {
- return ((StormStreamSink) streamSink().getSink(streamId,config));
+ return ((StormStreamSink) stream().getSink(streamId,config));
}
-}
+
+ public StormStreamSource getStreamSource(String streamId, Config config) {
+ return (StormStreamSource) stream().getSource(streamId,config);
+ }
+
+ public MetricStreamPersist getMetricPersist(MetricDefinition metricDefinition, Config config) {
+ return new MetricStreamPersist(metricDefinition, config);
+ }
+
+ public TransformFunctionBolt getTransformer(TransformFunction function) {
+ return new TransformFunctionBolt(function);
+ }
+
+ // ----------------------------------
+ // Fluent Storm App Builder API
+ // ----------------------------------
+
+ public ApplicationBuilder newApp(Config appConfig) {
+ return new ApplicationBuilder(appConfig, this);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/DefaultStreamSinkConfig.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/DefaultStreamSinkConfig.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/DefaultStreamSinkConfig.java
new file mode 100644
index 0000000..d1cecc9
--- /dev/null
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/DefaultStreamSinkConfig.java
@@ -0,0 +1,42 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.eagle.app.messaging;
+
+import org.apache.eagle.metadata.model.StreamSinkConfig;
+
+public class DefaultStreamSinkConfig implements StreamSinkConfig {
+ private final Class<?> streamPersistClass;
+ private static final String NONE_STORAGE_TYPE = "NONE";
+
+ public DefaultStreamSinkConfig(Class<?> streamPersistClass) {
+ this.streamPersistClass = streamPersistClass;
+ }
+
+ @Override
+ public String getType() {
+ return NONE_STORAGE_TYPE;
+ }
+
+ public Class<?> getSinkType() {
+ return streamPersistClass;
+ }
+
+ @Override
+ public Class<? extends StreamSinkConfig> getConfigType() {
+ return DefaultStreamSinkConfig.class;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/FlattenEventMapper.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/FlattenEventMapper.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/FlattenEventMapper.java
new file mode 100644
index 0000000..c8fe1b5
--- /dev/null
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/FlattenEventMapper.java
@@ -0,0 +1,60 @@
+/*
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.eagle.app.messaging;
+
+import org.apache.eagle.alert.engine.model.StreamEvent;
+import backtype.storm.tuple.Tuple;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collections;
+import java.util.List;
+
+public class FlattenEventMapper implements StreamEventMapper {
+ private final String streamId;
+ private static final String TIMESTAMP_FIELD = "timestamp";
+ private static final Logger LOGGER = LoggerFactory.getLogger(FlattenEventMapper.class);
+
+ public FlattenEventMapper(String streamId) {
+ this.streamId = streamId;
+ }
+
+ @Override
+ public List<StreamEvent> map(Tuple tuple) throws Exception {
+ long timestamp;
+ if (tuple.getFields().contains(TIMESTAMP_FIELD)) {
+ try {
+ timestamp = tuple.getLongByField("timestamp");
+ } catch (Exception ex) {
+ // if timestamp is not null
+ LOGGER.error(ex.getMessage(), ex);
+ timestamp = 0;
+ }
+ } else {
+ timestamp = System.currentTimeMillis();
+ }
+ Object[] values = new Object[tuple.getFields().size()];
+ for (int i = 0; i < tuple.getFields().size(); i++) {
+ values[i] = tuple.getValue(i);
+ }
+ StreamEvent event = new StreamEvent();
+ event.setTimestamp(timestamp);
+ event.setStreamId(streamId);
+ event.setData(values);
+ return Collections.singletonList(event);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/JsonSchema.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/JsonSchema.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/JsonSchema.java
new file mode 100644
index 0000000..987ed0b
--- /dev/null
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/JsonSchema.java
@@ -0,0 +1,66 @@
+/*
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.eagle.app.messaging;
+
+import backtype.storm.spout.Scheme;
+import backtype.storm.tuple.Fields;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.slf4j.Logger;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * General Json Schema.
+ * Different from org.apache.eagle.alert.engine.scheme.JsonScheme which is just to multi-topic cases.
+ *
+ * @see org.apache.eagle.alert.engine.scheme.JsonScheme
+ */
+public class JsonSchema implements Scheme {
+ private static final long serialVersionUID = -8352896475656975577L;
+ private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(JsonSchema.class);
+ private static final ObjectMapper mapper = new ObjectMapper();
+
+ @Override
+ public Fields getOutputFields() {
+ return new Fields("f1","f2");
+ }
+
+ @Override
+ @SuppressWarnings("rawtypes")
+ public List<Object> deserialize(byte[] ser) {
+ try {
+ if (ser != null) {
+ Map map = mapper.readValue(ser, Map.class);
+ return Arrays.asList(map.hashCode(), map);
+ } else {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Content is null, ignore");
+ }
+ }
+ } catch (IOException e) {
+ try {
+ LOG.error("Failed to deserialize as JSON: {}", new String(ser, "UTF-8"), e);
+ } catch (Exception ex) {
+ LOG.error(ex.getMessage(), ex);
+ }
+ }
+ return null;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/KafkaStreamProvider.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/KafkaStreamProvider.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/KafkaStreamProvider.java
new file mode 100644
index 0000000..13080a1
--- /dev/null
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/KafkaStreamProvider.java
@@ -0,0 +1,130 @@
+/*
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.eagle.app.messaging;
+
+import backtype.storm.spout.Scheme;
+import com.typesafe.config.Config;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class KafkaStreamProvider implements StreamProvider<KafkaStreamSink, KafkaStreamSinkConfig,KafkaStreamSource,KafkaStreamSourceConfig> {
+ private static final Logger LOG = LoggerFactory.getLogger(KafkaStreamProvider.class);
+ private static final String DEFAULT_SHARED_SINK_TOPIC_CONF_KEY = "dataSinkConfig.topic";
+ private static final String DEFAULT_SHARED_SOURCE_TOPIC_CONF_KEY = "dataSourceConfig.topic";
+
+ private String getSinkTopicName(String streamId, Config config) {
+ String streamSpecificTopicConfigKey = String.format("dataSinkConfig.%s.topic",streamId);
+ if (config.hasPath(streamSpecificTopicConfigKey)) {
+ return config.getString(streamSpecificTopicConfigKey);
+ } else if (config.hasPath(DEFAULT_SHARED_SINK_TOPIC_CONF_KEY)) {
+ LOG.warn("Using default shared sink topic {}: {}", DEFAULT_SHARED_SINK_TOPIC_CONF_KEY, config.getString(DEFAULT_SHARED_SINK_TOPIC_CONF_KEY));
+ return config.getString(DEFAULT_SHARED_SINK_TOPIC_CONF_KEY);
+ } else {
+ LOG.error("Neither stream specific topic: {} nor default shared topic: {} found in config", streamSpecificTopicConfigKey, DEFAULT_SHARED_SINK_TOPIC_CONF_KEY);
+ throw new IllegalArgumentException("Neither stream specific topic: "
+ + streamSpecificTopicConfigKey + " nor default shared topic: " + DEFAULT_SHARED_SINK_TOPIC_CONF_KEY + " found in config");
+ }
+ }
+
+ private String getSourceTopicName(String streamId, Config config) {
+ String streamSpecificTopicConfigKey = String.format("dataSourceConfig.%s.topic",streamId);;
+ if (config.hasPath(streamSpecificTopicConfigKey)) {
+ return config.getString(streamSpecificTopicConfigKey);
+ } else if (config.hasPath(DEFAULT_SHARED_SOURCE_TOPIC_CONF_KEY)) {
+ LOG.warn("Using default shared source topic {}: {}", DEFAULT_SHARED_SOURCE_TOPIC_CONF_KEY, config.getString(DEFAULT_SHARED_SOURCE_TOPIC_CONF_KEY));
+ return config.getString(DEFAULT_SHARED_SOURCE_TOPIC_CONF_KEY);
+ } else {
+ LOG.debug("Neither stream specific topic: {} nor default shared topic: {} found in config, try sink config instead", streamSpecificTopicConfigKey, DEFAULT_SHARED_SINK_TOPIC_CONF_KEY);
+ return getSinkTopicName(streamId,config);
+ }
+ }
+
+ @Override
+ public KafkaStreamSinkConfig getSinkConfig(String streamId, Config config) {
+ KafkaStreamSinkConfig sinkConfig = new KafkaStreamSinkConfig();
+ sinkConfig.setTopicId(getSinkTopicName(streamId,config));
+ sinkConfig.setBrokerList(config.getString("dataSinkConfig.brokerList"));
+ sinkConfig.setSerializerClass(config.hasPath("dataSinkConfig.serializerClass")
+ ? config.getString("dataSinkConfig.serializerClass") : "kafka.serializer.StringEncoder");
+ sinkConfig.setKeySerializerClass(config.hasPath("dataSinkConfig.keySerializerClass")
+ ? config.getString("dataSinkConfig.keySerializerClass") : "kafka.serializer.StringEncoder");
+
+ // new added properties for async producer
+ sinkConfig.setNumBatchMessages(config.hasPath("dataSinkConfig.numBatchMessages")
+ ? config.getString("dataSinkConfig.numBatchMessages") : "1024");
+ sinkConfig.setProducerType(config.hasPath("dataSinkConfig.producerType")
+ ? config.getString("dataSinkConfig.producerType") : "async");
+ sinkConfig.setMaxQueueBufferMs(config.hasPath("dataSinkConfig.maxQueueBufferMs")
+ ? config.getString("dataSinkConfig.maxQueueBufferMs") : "3000");
+ sinkConfig.setRequestRequiredAcks(config.hasPath("dataSinkConfig.requestRequiredAcks")
+ ? config.getString("dataSinkConfig.requestRequiredAcks") : "1");
+
+ return sinkConfig;
+ }
+
+ @Override
+ public KafkaStreamSink getSink() {
+ return new KafkaStreamSink();
+ }
+
+ @Override
+ public KafkaStreamSourceConfig getSourceConfig(String streamId, Config config) {
+ KafkaStreamSourceConfig sourceConfig = new KafkaStreamSourceConfig();
+
+ sourceConfig.setTopicId(getSourceTopicName(streamId,config));
+ sourceConfig.setBrokerZkQuorum(config.getString("dataSourceConfig.zkConnection"));
+
+ if (config.hasPath("dataSourceConfig.fetchSize")) {
+ sourceConfig.setFetchSize(config.getInt("dataSourceConfig.fetchSize"));
+ }
+ if (config.hasPath("dataSourceConfig.transactionZKRoot")) {
+ sourceConfig.setTransactionZKRoot(config.getString("dataSourceConfig.transactionZKRoot"));
+ }
+ if (config.hasPath("dataSourceConfig.consumerGroupId")) {
+ sourceConfig.setConsumerGroupId(config.getString("dataSourceConfig.consumerGroupId"));
+ }
+ if (config.hasPath("dataSourceConfig.brokerZkPath")) {
+ sourceConfig.setBrokerZkPath(config.getString("dataSourceConfig.brokerZkPath"));
+ }
+ if (config.hasPath("dataSourceConfig.txZkServers")) {
+ sourceConfig.setTransactionZkServers(config.getString("dataSourceConfig.txZkServers"));
+ }
+ if (config.hasPath("dataSourceConfig.transactionStateUpdateMS")) {
+ sourceConfig.setTransactionStateUpdateMS(config.getLong("dataSourceConfig.transactionStateUpdateMS"));
+ }
+ if (config.hasPath("dataSourceConfig.startOffsetTime")) {
+ sourceConfig.setStartOffsetTime(config.getInt("dataSourceConfig.startOffsetTime"));
+ }
+ if (config.hasPath("dataSourceConfig.forceFromStart")) {
+ sourceConfig.setForceFromStart(config.getBoolean("dataSourceConfig.forceFromStart"));
+ }
+ if (config.hasPath("dataSourceConfig.schemeCls")) {
+ try {
+ sourceConfig.setSchemaClass((Class<? extends Scheme>) Class.forName(config.getString("dataSourceConfig.schemeCls")));
+ } catch (ClassNotFoundException e) {
+ LOG.error("Class not found error, dataSourceConfig.schemeCls = {}",config.getString("dataSourceConfig.schemeCls"),e);
+ }
+ }
+ return sourceConfig;
+ }
+
+ @Override
+ public KafkaStreamSource getSource() {
+ return new KafkaStreamSource();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/KafkaStreamSink.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/KafkaStreamSink.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/KafkaStreamSink.java
new file mode 100644
index 0000000..696d79f
--- /dev/null
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/KafkaStreamSink.java
@@ -0,0 +1,97 @@
+/*
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.eagle.app.messaging;
+
+import backtype.storm.task.OutputCollector;
+import backtype.storm.task.TopologyContext;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import kafka.javaapi.producer.Producer;
+import kafka.producer.KeyedMessage;
+import kafka.producer.ProducerConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+import java.util.Properties;
+
+public class KafkaStreamSink extends StormStreamSink<KafkaStreamSinkConfig> {
+ private static final Logger LOG = LoggerFactory.getLogger(KafkaStreamSink.class);
+ private String topicId;
+ private Producer producer;
+ private KafkaStreamSinkConfig config;
+
+ @Override
+ public void init(String streamId, KafkaStreamSinkConfig config) {
+ super.init(streamId, config);
+ this.topicId = config.getTopicId();
+ this.config = config;
+ }
+
+ @Override
+ public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
+ super.prepare(stormConf, context, collector);
+ Properties properties = new Properties();
+ properties.put("metadata.broker.list", config.getBrokerList());
+ properties.put("serializer.class", config.getSerializerClass());
+ properties.put("key.serializer.class", config.getKeySerializerClass());
+ // new added properties for async producer
+ properties.put("producer.type", config.getProducerType());
+ properties.put("batch.num.messages", config.getNumBatchMessages());
+ properties.put("request.required.acks", config.getRequestRequiredAcks());
+ properties.put("queue.buffering.max.ms", config.getMaxQueueBufferMs());
+ ProducerConfig producerConfig = new ProducerConfig(properties);
+ producer = new Producer(producerConfig);
+ }
+
+ @Override
+ protected void execute(Object key, Map event, OutputCollector collector) throws Exception {
+ try {
+ String output = new ObjectMapper().writeValueAsString(event);
+ // partition key may cause data skew
+ //producer.send(new KeyedMessage(this.topicId, key, output));
+ producer.send(new KeyedMessage(this.topicId, output));
+ } catch (Exception ex) {
+ LOG.error(ex.getMessage(), ex);
+ throw ex;
+ }
+ }
+
+ @Override
+ public void afterInstall() {
+ ensureTopicCreated();
+ }
+
+ private void ensureTopicCreated() {
+ LOG.info("TODO: ensure kafka topic {} created", this.topicId);
+ }
+
+ private void ensureTopicDeleted() {
+ LOG.info("TODO: ensure kafka topic {} deleted", this.topicId);
+ }
+
+ @Override
+ public void cleanup() {
+ if (this.producer != null) {
+ this.producer.close();
+ }
+ }
+
+ @Override
+ public void afterUninstall() {
+ ensureTopicDeleted();
+ }
+}
\ No newline at end of file
[4/5] incubator-eagle git commit: [EAGLE-806] Integrate Metric
Process and Persistence with Application Framework
Posted by ha...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/KafkaStreamSinkConfig.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/KafkaStreamSinkConfig.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/KafkaStreamSinkConfig.java
new file mode 100644
index 0000000..4a72709
--- /dev/null
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/KafkaStreamSinkConfig.java
@@ -0,0 +1,115 @@
+/*
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.eagle.app.messaging;
+
+import org.apache.eagle.metadata.model.StreamSinkConfig;
+
+/**
+ * FIXME Rename to KafkaStreamMessagingConfig.
+ */
+public class KafkaStreamSinkConfig implements StreamSinkConfig {
+ // Write Config
+ private String topicId;
+ private String brokerList;
+ private String serializerClass;
+ private String keySerializerClass;
+ private String numBatchMessages;
+ private String maxQueueBufferMs;
+ private String producerType;
+ private String requestRequiredAcks;
+
+ public String getTopicId() {
+ return topicId;
+ }
+
+ public void setTopicId(String topicId) {
+ this.topicId = topicId;
+ }
+
+ public String getBrokerList() {
+ return brokerList;
+ }
+
+ public void setBrokerList(String brokerList) {
+ this.brokerList = brokerList;
+ }
+
+ public String getSerializerClass() {
+ return serializerClass;
+ }
+
+ public void setSerializerClass(String serializerClass) {
+ this.serializerClass = serializerClass;
+ }
+
+ public String getKeySerializerClass() {
+ return keySerializerClass;
+ }
+
+ public void setKeySerializerClass(String keySerializerClass) {
+ this.keySerializerClass = keySerializerClass;
+ }
+
+ public String getNumBatchMessages() {
+ return numBatchMessages;
+ }
+
+ public void setNumBatchMessages(String numBatchMessages) {
+ this.numBatchMessages = numBatchMessages;
+ }
+
+ public String getMaxQueueBufferMs() {
+ return maxQueueBufferMs;
+ }
+
+ public void setMaxQueueBufferMs(String maxQueueBufferMs) {
+ this.maxQueueBufferMs = maxQueueBufferMs;
+ }
+
+ public String getProducerType() {
+ return producerType;
+ }
+
+ public void setProducerType(String producerType) {
+ this.producerType = producerType;
+ }
+
+ public String getRequestRequiredAcks() {
+ return requestRequiredAcks;
+ }
+
+ public void setRequestRequiredAcks(String requestRequiredAcks) {
+ this.requestRequiredAcks = requestRequiredAcks;
+ }
+
+ @Override
+ public String getType() {
+ return "KAFKA";
+ }
+
+ @Override
+ public Class<?> getSinkType() {
+ return KafkaStreamSink.class;
+ }
+
+ @Override
+ public Class<? extends StreamSinkConfig> getConfigType() {
+ return KafkaStreamSinkConfig.class;
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/KafkaStreamSource.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/KafkaStreamSource.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/KafkaStreamSource.java
new file mode 100644
index 0000000..9edf644
--- /dev/null
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/KafkaStreamSource.java
@@ -0,0 +1,162 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.eagle.app.messaging;
+
+import backtype.storm.spout.Scheme;
+import backtype.storm.spout.SchemeAsMultiScheme;
+import backtype.storm.spout.SpoutOutputCollector;
+import backtype.storm.task.TopologyContext;
+import backtype.storm.topology.OutputFieldsDeclarer;
+import com.google.common.base.Preconditions;
+import org.apache.eagle.alert.engine.spout.SchemeBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import storm.kafka.*;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class KafkaStreamSource extends StormStreamSource<KafkaStreamSourceConfig> {
+ private static final Logger LOG = LoggerFactory.getLogger(KafkaStreamSource.class);
+ private KafkaSpout spout;
+
+ @Override
+ public void init(String streamId, KafkaStreamSourceConfig config) {
+ this.spout = createKafkaSpout(config);
+ }
+
+ @Override
+ public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
+ this.spout.open(conf, context, collector);
+ }
+
+ @Override
+ public void nextTuple() {
+ this.spout.nextTuple();
+ }
+
+ @Override
+ public void declareOutputFields(OutputFieldsDeclarer declarer) {
+ this.spout.declareOutputFields(declarer);
+ }
+
+ @Override
+ public void close() {
+ this.spout.close();
+ }
+
+ @Override
+ public void activate() {
+ this.spout.activate();
+ }
+
+ @Override
+ public void deactivate() {
+ this.spout.deactivate();
+ }
+
+ @Override
+ public void ack(Object msgId) {
+ this.spout.ack(msgId);
+ }
+
+ @Override
+ public void fail(Object msgId) {
+ this.spout.fail(msgId);
+ }
+
+ @Override
+ public Map<String, Object> getComponentConfiguration() {
+ return this.spout.getComponentConfiguration();
+ }
+
+ // ----------------
+ // Helper Methods
+ // ----------------
+
+ private static KafkaSpout createKafkaSpout(KafkaStreamSourceConfig config) {
+
+ // the following is for fetching data from one topic
+ // Kafka topic
+ String topic = config.getTopicId();
+ // Kafka broker zk connection
+ String zkConnString = config.getBrokerZkQuorum();
+ // Kafka fetch size
+ int fetchSize = config.getFetchSize();
+ LOG.info(String.format("Use topic : %s, zkQuorum : %s , fetchSize : %d", topic, zkConnString, fetchSize));
+
+ /*
+ the following is for recording offset for processing the data
+ the zk path to store current offset is comprised of the following
+ offset zkPath = zkRoot + "/" + topic + "/" + consumerGroupId + "/" + partition_Id
+
+ consumerGroupId is for differentiating different consumers which consume the same topic
+ */
+ // transaction zkRoot
+ String zkRoot = config.getTransactionZKRoot();
+ // Kafka consumer group id
+ String groupId = config.getConsumerGroupId();
+ String brokerZkPath = config.getBrokerZkPath();
+
+ BrokerHosts hosts;
+ if (brokerZkPath == null) {
+ hosts = new ZkHosts(zkConnString);
+ } else {
+ hosts = new ZkHosts(zkConnString, brokerZkPath);
+ }
+
+ SpoutConfig spoutConfig = new SpoutConfig(hosts,
+ topic,
+ zkRoot + "/" + topic,
+ groupId);
+
+ // transaction zkServers to store kafka consumer offset. Default to use storm zookeeper
+ if (config.getTransactionZkServers() != null) {
+ String[] txZkServers = config.getTransactionZkServers().split(",");
+ spoutConfig.zkServers = Arrays.asList(txZkServers).stream().map(server -> server.split(":")[0]).collect(Collectors.toList());
+ spoutConfig.zkPort = Integer.parseInt(txZkServers[0].split(":")[1]);
+ LOG.info("txZkServers:" + spoutConfig.zkServers + ", zkPort:" + spoutConfig.zkPort);
+ }
+
+ // transaction update interval
+ spoutConfig.stateUpdateIntervalMs = config.getTransactionStateUpdateMS();
+ // Kafka fetch size
+ spoutConfig.fetchSizeBytes = fetchSize;
+ spoutConfig.startOffsetTime = kafka.api.OffsetRequest.LatestTime();
+
+ // "startOffsetTime" is for test usage, prod should not use this
+ if (config.getStartOffsetTime() >= 0) {
+ spoutConfig.startOffsetTime = config.getStartOffsetTime();
+ }
+ // "forceFromStart" is for test usage, prod should not use this
+ if (config.isForceFromStart()) {
+ spoutConfig.startOffsetTime = kafka.api.OffsetRequest.EarliestTime();
+ }
+
+ Preconditions.checkNotNull(config.getSchemaClass(), "schemaClass is null");
+ try {
+ Scheme s = config.getSchemaClass().newInstance();
+ spoutConfig.scheme = new SchemeAsMultiScheme(s);
+ } catch (Exception ex) {
+ LOG.error("Error instantiating scheme object");
+ throw new IllegalStateException(ex);
+ }
+ return new KafkaSpout(spoutConfig);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/KafkaStreamSourceConfig.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/KafkaStreamSourceConfig.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/KafkaStreamSourceConfig.java
new file mode 100644
index 0000000..5a9c162
--- /dev/null
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/KafkaStreamSourceConfig.java
@@ -0,0 +1,153 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.eagle.app.messaging;
+
+import org.apache.eagle.metadata.model.StreamSourceConfig;
+
+public class KafkaStreamSourceConfig implements StreamSourceConfig {
+
+ private static final String DEFAULT_CONFIG_PREFIX = "dataSourceConfig";
+ private static final String DEFAULT_CONSUMER_GROUP_ID = "eagleKafkaSource";
+ private static final String DEFAULT_TRANSACTION_ZK_ROOT = "/consumers";
+ private static final Class<? extends backtype.storm.spout.Scheme> DEFAULT_KAFKA_SCHEMA = JsonSchema.class;
+
+ // Read Config
+ private String topicId;
+ private String brokerZkQuorum;
+ private String brokerZkBasePath;
+ private String transactionZkServers;
+
+ private int fetchSize = 1048576;
+ private String transactionZKRoot = DEFAULT_TRANSACTION_ZK_ROOT;
+ private String consumerGroupId = DEFAULT_CONSUMER_GROUP_ID;
+ private String brokerZkPath = null;
+ private long transactionStateUpdateMS = 2000;
+ private int startOffsetTime = -1;
+ private boolean forceFromStart = false;
+ private Class<? extends backtype.storm.spout.Scheme> schemaClass = DEFAULT_KAFKA_SCHEMA;
+
+ public String getBrokerZkQuorum() {
+ return brokerZkQuorum;
+ }
+
+ public void setBrokerZkQuorum(String brokerZkQuorum) {
+ this.brokerZkQuorum = brokerZkQuorum;
+ }
+
+ public String getBrokerZkBasePath() {
+ return brokerZkBasePath;
+ }
+
+ public void setBrokerZkBasePath(String brokerZkBasePath) {
+ this.brokerZkBasePath = brokerZkBasePath;
+ }
+
+ public int getFetchSize() {
+ return fetchSize;
+ }
+
+ public void setFetchSize(int fetchSize) {
+ this.fetchSize = fetchSize;
+ }
+
+ public String getTransactionZKRoot() {
+ return transactionZKRoot;
+ }
+
+ public void setTransactionZKRoot(String transactionZKRoot) {
+ this.transactionZKRoot = transactionZKRoot;
+ }
+
+ public String getConsumerGroupId() {
+ return consumerGroupId;
+ }
+
+ public void setConsumerGroupId(String consumerGroupId) {
+ this.consumerGroupId = consumerGroupId;
+ }
+
+ public String getBrokerZkPath() {
+ return brokerZkPath;
+ }
+
+ public void setBrokerZkPath(String brokerZkPath) {
+ this.brokerZkPath = brokerZkPath;
+ }
+
+ public String getTransactionZkServers() {
+ return transactionZkServers;
+ }
+
+ public void setTransactionZkServers(String transactionZkServers) {
+ this.transactionZkServers = transactionZkServers;
+ }
+
+ public long getTransactionStateUpdateMS() {
+ return transactionStateUpdateMS;
+ }
+
+ public void setTransactionStateUpdateMS(long transactionStateUpdateMS) {
+ this.transactionStateUpdateMS = transactionStateUpdateMS;
+ }
+
+ public int getStartOffsetTime() {
+ return startOffsetTime;
+ }
+
+ public void setStartOffsetTime(int startOffsetTime) {
+ this.startOffsetTime = startOffsetTime;
+ }
+
+ public boolean isForceFromStart() {
+ return forceFromStart;
+ }
+
+ public void setForceFromStart(boolean forceFromStart) {
+ this.forceFromStart = forceFromStart;
+ }
+
+ public Class<? extends backtype.storm.spout.Scheme> getSchemaClass() {
+ return schemaClass;
+ }
+
+ public void setSchemaClass(Class<? extends backtype.storm.spout.Scheme> schemaClass) {
+ this.schemaClass = schemaClass;
+ }
+
+ @Override
+ public String getType() {
+ return "KAFKA";
+ }
+
+ @Override
+ public Class<?> getSourceType() {
+ return KafkaStreamSource.class;
+ }
+
+ @Override
+ public Class<? extends StreamSourceConfig> getConfigType() {
+ return StreamSourceConfig.class;
+ }
+
+ public String getTopicId() {
+ return topicId;
+ }
+
+ public void setTopicId(String topicId) {
+ this.topicId = topicId;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/MetricStreamPersist.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/MetricStreamPersist.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/MetricStreamPersist.java
new file mode 100644
index 0000000..32b168b
--- /dev/null
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/MetricStreamPersist.java
@@ -0,0 +1,152 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.eagle.app.messaging;
+
+import backtype.storm.task.OutputCollector;
+import backtype.storm.task.TopologyContext;
+import backtype.storm.topology.OutputFieldsDeclarer;
+import backtype.storm.topology.base.BaseRichBolt;
+import backtype.storm.tuple.Fields;
+import backtype.storm.tuple.Tuple;
+import com.google.common.base.Preconditions;
+import com.typesafe.config.Config;
+import org.apache.eagle.app.environment.builder.MetricDefinition;
+import org.apache.eagle.app.utils.StreamConvertHelper;
+import org.apache.eagle.log.entity.GenericMetricEntity;
+import org.apache.eagle.log.entity.GenericServiceAPIResponseEntity;
+import org.apache.eagle.service.client.IEagleServiceClient;
+import org.apache.eagle.service.client.impl.BatchSender;
+import org.apache.eagle.service.client.impl.EagleServiceClientImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+public class MetricStreamPersist extends BaseRichBolt {
+ private static final Logger LOG = LoggerFactory.getLogger(MetricStreamPersist.class);
+
+ private final Config config;
+ private final MetricMapper mapper;
+ private final int batchSize;
+ private IEagleServiceClient client;
+ private OutputCollector collector;
+ private BatchSender batchSender;
+
+ public MetricStreamPersist(MetricDefinition metricDefinition, Config config) {
+ this.config = config;
+ this.mapper = new StructuredMetricMapper(metricDefinition);
+ this.batchSize = config.hasPath("service.batchSize") ? config.getInt("service.batchSize") : 1;
+ }
+
+ public MetricStreamPersist(MetricMapper mapper, Config config) {
+ this.config = config;
+ this.mapper = mapper;
+ this.batchSize = config.hasPath("service.batchSize") ? config.getInt("service.batchSize") : 1;
+ }
+
+ @Override
+ public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
+ this.client = new EagleServiceClientImpl(config);
+ if (this.batchSize > 0) {
+ this.batchSender = client.batch(this.batchSize);
+ }
+ this.collector = collector;
+ }
+
+ @Override
+ public void execute(Tuple input) {
+ try {
+ GenericMetricEntity metricEntity = this.mapper.map(StreamConvertHelper.tupleToEvent(input).f1());
+ if (batchSize <= 1) {
+ GenericServiceAPIResponseEntity<String> response = this.client.create(Collections.singletonList(metricEntity));
+ if (!response.isSuccess()) {
+ LOG.error("Service side error: {}", response.getException());
+ collector.reportError(new IllegalStateException(response.getException()));
+ } else {
+ collector.ack(input);
+ }
+ } else {
+ this.batchSender.send(metricEntity);
+ collector.ack(input);
+ }
+ } catch (Exception ex) {
+ LOG.error(ex.getMessage(), ex);
+ collector.reportError(ex);
+ }
+ }
+
+ @Override
+ public void declareOutputFields(OutputFieldsDeclarer declarer) {
+ declarer.declare(new Fields("f1"));
+ }
+
+ @Override
+ public void cleanup() {
+ try {
+ this.client.close();
+ } catch (IOException e) {
+ LOG.error("Close client error: {}", e.getMessage(), e);
+ } finally {
+ super.cleanup();
+ }
+ }
+
+ @FunctionalInterface
+ public interface MetricMapper extends Serializable {
+ GenericMetricEntity map(Map event);
+ }
+
+ public class StructuredMetricMapper implements MetricMapper {
+ private final MetricDefinition metricDefinition;
+
+ private StructuredMetricMapper(MetricDefinition metricDefinition) {
+ this.metricDefinition = metricDefinition;
+ }
+
+ @Override
+ public GenericMetricEntity map(Map event) {
+ String metricName = metricDefinition.getNameSelector().getMetricName(event);
+ Preconditions.checkNotNull(metricName,"Metric name is null");
+ Long timestamp = metricDefinition.getTimestampSelector().getTimestamp(event);
+ Preconditions.checkNotNull(timestamp, "Timestamp is null");
+ Map<String,String> tags = new HashMap<>();
+ for (String dimensionField: metricDefinition.getDimensionFields()) {
+ Preconditions.checkNotNull(dimensionField,"Dimension field name is null");
+ tags.put(dimensionField, (String) event.get(dimensionField));
+ }
+
+ double[] values;
+ if (event.containsKey(metricDefinition.getValueField())) {
+ values = new double[] {(double) event.get(metricDefinition.getValueField())};
+ } else {
+ LOG.warn("Event has no value field '{}': {}, use 0 by default", metricDefinition.getValueField(), event);
+ values = new double[]{0};
+ }
+
+ GenericMetricEntity entity = new GenericMetricEntity();
+ entity.setPrefix(metricName);
+ entity.setTimestamp(timestamp);
+ entity.setTags(tags);
+ entity.setValue(values);
+ return entity;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/StormStreamSink.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/StormStreamSink.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/StormStreamSink.java
new file mode 100644
index 0000000..ef6c8d6
--- /dev/null
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/StormStreamSink.java
@@ -0,0 +1,71 @@
+/*
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.eagle.app.messaging;
+
+import backtype.storm.task.OutputCollector;
+import backtype.storm.topology.base.BaseRichBolt;
+import org.apache.eagle.app.utils.StreamConvertHelper;
+import org.apache.eagle.common.utils.Tuple2;
+import org.apache.eagle.metadata.model.StreamSinkConfig;
+import backtype.storm.task.TopologyContext;
+import backtype.storm.topology.OutputFieldsDeclarer;
+import backtype.storm.tuple.Tuple;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+
+public abstract class StormStreamSink<K extends StreamSinkConfig> extends BaseRichBolt implements StreamSink<K> {
+ private static final Logger LOG = LoggerFactory.getLogger(StormStreamSink.class);
+ private String streamId;
+ private OutputCollector collector;
+
+ @Override
+ public void init(String streamId, K config) {
+ this.streamId = streamId;
+ }
+
+ @Override
+ public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
+ this.collector = collector;
+ }
+
+ /**
+ * Implicitly hides the Tuple protocol inside code as Tuple[Key,Map].
+ */
+ @Override
+ public void execute(Tuple input) {
+ try {
+ Tuple2<Object,Map> keyValue = StreamConvertHelper.tupleToEvent(input);
+ execute(keyValue.f0(), keyValue.f1(), collector);
+ collector.ack(input);
+ } catch (Exception ex) {
+ LOG.error(ex.getMessage(), ex);
+ collector.reportError(ex);
+ }
+ }
+
+ protected abstract void execute(Object key, Map event, OutputCollector collector) throws Exception;
+
+ @Override
+ public void declareOutputFields(OutputFieldsDeclarer declarer) {
+ }
+
+ public String getStreamId() {
+ return streamId;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/StormStreamSource.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/StormStreamSource.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/StormStreamSource.java
new file mode 100644
index 0000000..b31de46
--- /dev/null
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/StormStreamSource.java
@@ -0,0 +1,25 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.eagle.app.messaging;
+
+import backtype.storm.topology.base.BaseRichSpout;
+import org.apache.eagle.metadata.model.StreamSinkConfig;
+import org.apache.eagle.metadata.model.StreamSourceConfig;
+
+public abstract class StormStreamSource<T extends StreamSourceConfig> extends BaseRichSpout implements StreamSource<T> {
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/StreamEventMapper.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/StreamEventMapper.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/StreamEventMapper.java
new file mode 100644
index 0000000..42ea36e
--- /dev/null
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/StreamEventMapper.java
@@ -0,0 +1,35 @@
+/*
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.eagle.app.messaging;
+
+import org.apache.eagle.alert.engine.model.StreamEvent;
+import backtype.storm.tuple.Tuple;
+
+import java.io.Serializable;
+import java.util.List;
+
+@FunctionalInterface
+public interface StreamEventMapper extends Serializable {
+ /**
+ * Map from storm tuple to Stream Event.
+ *
+ * @param tuple
+ * @return
+ * @throws Exception
+ */
+ List<StreamEvent> map(Tuple tuple) throws Exception;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/StreamProvider.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/StreamProvider.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/StreamProvider.java
new file mode 100644
index 0000000..0dbc1a7
--- /dev/null
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/StreamProvider.java
@@ -0,0 +1,50 @@
+/*
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.eagle.app.messaging;
+
+import com.typesafe.config.Config;
+import org.apache.eagle.metadata.model.StreamSinkConfig;
+import org.apache.eagle.metadata.model.StreamSourceConfig;
+
+import java.lang.reflect.ParameterizedType;
+
+/**
+ * Stream Messaging Bus.
+ */
+public interface StreamProvider<W extends StreamSink<C>, C extends StreamSinkConfig,
+ R extends StreamSource<F>, F extends StreamSourceConfig> {
+
+ C getSinkConfig(String streamId, Config config);
+
+ W getSink();
+
+ default W getSink(String streamId, Config config) {
+ W s = getSink();
+ s.init(streamId, getSinkConfig(streamId, config));
+ return s;
+ }
+
+ F getSourceConfig(String streamId, Config config);
+
+ R getSource();
+
+ default R getSource(String streamId, Config config) {
+ R i = getSource();
+ i.init(streamId, getSourceConfig(streamId, config));
+ return i;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/StreamSink.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/StreamSink.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/StreamSink.java
new file mode 100644
index 0000000..7ba4a9a
--- /dev/null
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/StreamSink.java
@@ -0,0 +1,24 @@
+/*
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.eagle.app.messaging;
+
+import org.apache.eagle.app.ApplicationLifecycle;
+import org.apache.eagle.metadata.model.StreamSinkConfig;
+
+public interface StreamSink<T extends StreamSinkConfig> extends ApplicationLifecycle {
+ void init(String streamId,T config);
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/StreamSource.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/StreamSource.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/StreamSource.java
new file mode 100644
index 0000000..af3965f
--- /dev/null
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/messaging/StreamSource.java
@@ -0,0 +1,23 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.eagle.app.messaging;
+
+import org.apache.eagle.metadata.model.StreamSourceConfig;
+
+public interface StreamSource<T extends StreamSourceConfig> {
+ void init(String streamId, T config);
+}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationAction.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationAction.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationAction.java
index bd0adfe..25b5978 100644
--- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationAction.java
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationAction.java
@@ -29,8 +29,9 @@ import org.apache.eagle.alert.metric.MetricConfigs;
import org.apache.eagle.app.Application;
import org.apache.eagle.app.environment.ExecutionRuntime;
import org.apache.eagle.app.environment.ExecutionRuntimeManager;
-import org.apache.eagle.app.sink.KafkaStreamSinkConfig;
+import org.apache.eagle.app.messaging.KafkaStreamSinkConfig;
import org.apache.eagle.metadata.model.ApplicationEntity;
+import org.apache.eagle.metadata.model.StreamSourceConfig;
import org.apache.eagle.metadata.utils.StreamIdConversions;
import org.apache.eagle.metadata.model.StreamDesc;
import org.apache.eagle.metadata.model.StreamSinkConfig;
@@ -101,21 +102,32 @@ public class ApplicationAction implements Serializable {
copied.setSiteId(metadata.getSite().getSiteId());
copied.setStreamId(StreamIdConversions.formatSiteStreamId(metadata.getSite().getSiteId(), copied.getStreamId()));
StreamSinkConfig streamSinkConfig = this.runtime.environment()
- .streamSink().getSinkConfig(StreamIdConversions.parseStreamTypeId(copied.getSiteId(), copied.getStreamId()), this.effectiveConfig);
+ .stream().getSinkConfig(StreamIdConversions.parseStreamTypeId(copied.getSiteId(), copied.getStreamId()), this.effectiveConfig);
+
+ StreamSourceConfig streamSourceConfig = null;
+
+ try {
+ streamSourceConfig = this.runtime.environment()
+ .stream().getSourceConfig(StreamIdConversions.parseStreamTypeId(copied.getSiteId(), copied.getStreamId()), this.effectiveConfig);
+ } catch (Throwable throwable) {
+ // Ignore source config if not set.
+ }
+
StreamDesc streamDesc = new StreamDesc();
streamDesc.setSchema(copied);
- streamDesc.setSink(streamSinkConfig);
+ streamDesc.setSinkConfig(streamSinkConfig);
+ streamDesc.setSourceConfig(streamSourceConfig);
streamDesc.setStreamId(copied.getStreamId());
+
return streamDesc;
})).collect(Collectors.toList());
metadata.setStreams(streamDescToInstall);
- // TODO: Decouple converting from StreamSink to Alert DataSource
// iterate each stream descriptor and create alert datasource for each
for (StreamDesc streamDesc : streamDescToInstall) {
// only take care of Kafka sink
- if (streamDesc.getSink() instanceof KafkaStreamSinkConfig) {
- KafkaStreamSinkConfig kafkaCfg = (KafkaStreamSinkConfig) streamDesc.getSink();
+ if (streamDesc.getSinkConfig() instanceof KafkaStreamSinkConfig) {
+ KafkaStreamSinkConfig kafkaCfg = (KafkaStreamSinkConfig) streamDesc.getSinkConfig();
Kafka2TupleMetadata datasource = new Kafka2TupleMetadata();
datasource.setType("KAFKA");
datasource.setName(metadata.getAppId());
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationProviderSPILoader.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationProviderSPILoader.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationProviderSPILoader.java
index cbbd438..aa62251 100644
--- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationProviderSPILoader.java
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/impl/ApplicationProviderSPILoader.java
@@ -31,7 +31,7 @@ import java.util.ServiceLoader;
import java.util.function.Function;
/**
- * Load Application Provider with SPI, by default from current class loader.
+ * Load Application KafkaStreamMessaging with SPI, by default from current class loader.
*/
public class ApplicationProviderSPILoader extends ApplicationProviderLoader {
private final String appProviderExtDir;
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/DefaultStreamSinkConfig.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/DefaultStreamSinkConfig.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/DefaultStreamSinkConfig.java
deleted file mode 100644
index b3d984e..0000000
--- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/DefaultStreamSinkConfig.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.eagle.app.sink;
-
-import org.apache.eagle.metadata.model.StreamSinkConfig;
-
-public class DefaultStreamSinkConfig implements StreamSinkConfig {
- private final Class<?> streamPersistClass;
- private static final String NONE_STORAGE_TYPE = "NONE";
-
- public DefaultStreamSinkConfig(Class<?> streamPersistClass) {
- this.streamPersistClass = streamPersistClass;
- }
-
- @Override
- public String getType() {
- return NONE_STORAGE_TYPE;
- }
-
- public Class<?> getSinkType() {
- return streamPersistClass;
- }
-
- @Override
- public Class<? extends StreamSinkConfig> getConfigType() {
- return DefaultStreamSinkConfig.class;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/FlattenEventMapper.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/FlattenEventMapper.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/FlattenEventMapper.java
deleted file mode 100644
index 3649d72..0000000
--- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/FlattenEventMapper.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.eagle.app.sink;
-
-import org.apache.eagle.alert.engine.model.StreamEvent;
-import backtype.storm.tuple.Tuple;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Collections;
-import java.util.List;
-
-public class FlattenEventMapper implements StreamEventMapper {
- private final String streamId;
- private static final String TIMESTAMP_FIELD = "timestamp";
- private static final Logger LOGGER = LoggerFactory.getLogger(FlattenEventMapper.class);
-
- public FlattenEventMapper(String streamId) {
- this.streamId = streamId;
- }
-
- @Override
- public List<StreamEvent> map(Tuple tuple) throws Exception {
- long timestamp;
- if (tuple.getFields().contains(TIMESTAMP_FIELD)) {
- try {
- timestamp = tuple.getLongByField("timestamp");
- } catch (Exception ex) {
- // if timestamp is not null
- LOGGER.error(ex.getMessage(), ex);
- timestamp = 0;
- }
- } else {
- timestamp = System.currentTimeMillis();
- }
- Object[] values = new Object[tuple.getFields().size()];
- for (int i = 0; i < tuple.getFields().size(); i++) {
- values[i] = tuple.getValue(i);
- }
- StreamEvent event = new StreamEvent();
- event.setTimestamp(timestamp);
- event.setStreamId(streamId);
- event.setData(values);
- return Collections.singletonList(event);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/KafkaStreamSink.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/KafkaStreamSink.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/KafkaStreamSink.java
deleted file mode 100644
index 12acb81..0000000
--- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/KafkaStreamSink.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.eagle.app.sink;
-
-import backtype.storm.task.OutputCollector;
-import backtype.storm.task.TopologyContext;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.typesafe.config.Config;
-import kafka.javaapi.producer.Producer;
-import kafka.producer.KeyedMessage;
-import kafka.producer.ProducerConfig;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Map;
-import java.util.Properties;
-
-public class KafkaStreamSink extends StormStreamSink<KafkaStreamSinkConfig> {
- private static final Logger LOG = LoggerFactory.getLogger(KafkaStreamSink.class);
- private String topicId;
- private Producer producer;
- private KafkaStreamSinkConfig config;
-
- @Override
- public void init(String streamId, KafkaStreamSinkConfig config) {
- super.init(streamId, config);
- this.topicId = config.getTopicId();
- this.config = config;
- }
-
- @Override
- public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
- super.prepare(stormConf, context, collector);
- Properties properties = new Properties();
- properties.put("metadata.broker.list", config.getBrokerList());
- properties.put("serializer.class", config.getSerializerClass());
- properties.put("key.serializer.class", config.getKeySerializerClass());
- // new added properties for async producer
- properties.put("producer.type", config.getProducerType());
- properties.put("batch.num.messages", config.getNumBatchMessages());
- properties.put("request.required.acks", config.getRequestRequiredAcks());
- properties.put("queue.buffering.max.ms", config.getMaxQueueBufferMs());
- ProducerConfig producerConfig = new ProducerConfig(properties);
- producer = new Producer(producerConfig);
- }
-
- @Override
- protected void execute(Object key, Map event, OutputCollector collector) throws Exception {
- try {
- String output = new ObjectMapper().writeValueAsString(event);
- // partition key may cause data skew
- //producer.send(new KeyedMessage(this.topicId, key, output));
- producer.send(new KeyedMessage(this.topicId, output));
- } catch (Exception ex) {
- LOG.error(ex.getMessage(), ex);
- throw ex;
- }
- }
-
- @Override
- public void afterInstall() {
- ensureTopicCreated();
- }
-
- private void ensureTopicCreated() {
- LOG.info("TODO: ensure kafka topic {} created", this.topicId);
- }
-
- private void ensureTopicDeleted() {
- LOG.info("TODO: ensure kafka topic {} deleted", this.topicId);
- }
-
- @Override
- public void cleanup() {
- if (this.producer != null) {
- this.producer.close();
- }
- }
-
- @Override
- public void afterUninstall() {
- ensureTopicDeleted();
- }
-
- public static class Provider implements StreamSinkProvider<KafkaStreamSink, KafkaStreamSinkConfig> {
- private static final Logger LOG = LoggerFactory.getLogger(Provider.class);
- private static final String DEAULT_SHARED_TOPIC_CONF_KEY = "dataSinkConfig.topic";
-
- private String getStreamSpecificTopicConfigKey(String streamId) {
- return String.format("dataSinkConfig.%s.topic",streamId);
- }
-
- @Override
- public KafkaStreamSinkConfig getSinkConfig(String streamId, Config config) {
- KafkaStreamSinkConfig desc = new KafkaStreamSinkConfig();
- String streamSpecificTopicConfigKey = getStreamSpecificTopicConfigKey(streamId);
- if (config.hasPath(streamSpecificTopicConfigKey)) {
- desc.setTopicId(config.getString(streamSpecificTopicConfigKey));
- } else if (config.hasPath(DEAULT_SHARED_TOPIC_CONF_KEY)) {
- desc.setTopicId(config.getString(DEAULT_SHARED_TOPIC_CONF_KEY));
- LOG.warn("Using default shared topic {}: {}", DEAULT_SHARED_TOPIC_CONF_KEY, desc.getTopicId());
- } else {
- LOG.error("Neither stream specific topic: {} nor default shared topic: {} found in config", streamSpecificTopicConfigKey, DEAULT_SHARED_TOPIC_CONF_KEY);
- throw new IllegalArgumentException("Neither stream specific topic: "
- + streamSpecificTopicConfigKey + " nor default shared topic: " + DEAULT_SHARED_TOPIC_CONF_KEY + " found in config");
- }
- desc.setBrokerList(config.getString("dataSinkConfig.brokerList"));
- desc.setSerializerClass(config.hasPath("dataSinkConfig.serializerClass")
- ? config.getString("dataSinkConfig.serializerClass") : "kafka.serializer.StringEncoder");
- desc.setKeySerializerClass(config.hasPath("dataSinkConfig.keySerializerClass")
- ? config.getString("dataSinkConfig.keySerializerClass") : "kafka.serializer.StringEncoder");
-
- // new added properties for async producer
- desc.setNumBatchMessages(config.hasPath("dataSinkConfig.numBatchMessages")
- ? config.getString("dataSinkConfig.numBatchMessages") : "1024");
- desc.setProducerType(config.hasPath("dataSinkConfig.producerType")
- ? config.getString("dataSinkConfig.producerType") : "async");
- desc.setMaxQueueBufferMs(config.hasPath("dataSinkConfig.maxQueueBufferMs")
- ? config.getString("dataSinkConfig.maxQueueBufferMs") : "3000");
- desc.setRequestRequiredAcks(config.hasPath("dataSinkConfig.requestRequiredAcks")
- ? config.getString("dataSinkConfig.requestRequiredAcks") : "1");
- return desc;
- }
-
- @Override
- public KafkaStreamSink getSink() {
- return new KafkaStreamSink();
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/KafkaStreamSinkConfig.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/KafkaStreamSinkConfig.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/KafkaStreamSinkConfig.java
deleted file mode 100644
index d5479df..0000000
--- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/KafkaStreamSinkConfig.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.eagle.app.sink;
-
-import org.apache.eagle.metadata.model.StreamSinkConfig;
-
-public class KafkaStreamSinkConfig implements StreamSinkConfig {
- private String topicId;
- private String brokerList;
- private String serializerClass;
- private String keySerializerClass;
- private String numBatchMessages;
- private String maxQueueBufferMs;
- private String producerType;
- private String requestRequiredAcks;
-
- public String getTopicId() {
- return topicId;
- }
-
- public void setTopicId(String topicId) {
- this.topicId = topicId;
- }
-
- public String getBrokerList() {
- return brokerList;
- }
-
- public void setBrokerList(String brokerList) {
- this.brokerList = brokerList;
- }
-
- public String getSerializerClass() {
- return serializerClass;
- }
-
- public void setSerializerClass(String serializerClass) {
- this.serializerClass = serializerClass;
- }
-
- public String getKeySerializerClass() {
- return keySerializerClass;
- }
-
- public void setKeySerializerClass(String keySerializerClass) {
- this.keySerializerClass = keySerializerClass;
- }
-
- public String getNumBatchMessages() {
- return numBatchMessages;
- }
-
- public void setNumBatchMessages(String numBatchMessages) {
- this.numBatchMessages = numBatchMessages;
- }
-
- public String getMaxQueueBufferMs() {
- return maxQueueBufferMs;
- }
-
- public void setMaxQueueBufferMs(String maxQueueBufferMs) {
- this.maxQueueBufferMs = maxQueueBufferMs;
- }
-
- public String getProducerType() {
- return producerType;
- }
-
- public void setProducerType(String producerType) {
- this.producerType = producerType;
- }
-
- public String getRequestRequiredAcks() {
- return requestRequiredAcks;
- }
-
- public void setRequestRequiredAcks(String requestRequiredAcks) {
- this.requestRequiredAcks = requestRequiredAcks;
- }
-
- @Override
- public String getType() {
- return "KAFKA";
- }
-
- @Override
- public Class<?> getSinkType() {
- return KafkaStreamSink.class;
- }
-
- @Override
- public Class<? extends StreamSinkConfig> getConfigType() {
- return KafkaStreamSinkConfig.class;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/LoggingStreamSink.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/LoggingStreamSink.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/LoggingStreamSink.java
deleted file mode 100644
index 3a02caf..0000000
--- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/LoggingStreamSink.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.eagle.app.sink;
-
-import backtype.storm.task.OutputCollector;
-import com.typesafe.config.Config;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Map;
-
-public class LoggingStreamSink extends StormStreamSink<DefaultStreamSinkConfig> {
- private static final Logger LOGGER = LoggerFactory.getLogger(KafkaStreamSink.class);
-
- @Override
- public void afterInstall() {
- LOGGER.info("Executing afterInstall callback, do nothing");
- }
-
- @Override
- public void afterUninstall() {
- LOGGER.info("Executing afterUninstall callback, do nothing");
- }
-
- @Override
- protected void execute(Object key, Map event, OutputCollector collector) throws Exception {
- LOGGER.info("Receiving {}", event);
- }
-
- public static class Provider implements StreamSinkProvider<LoggingStreamSink, DefaultStreamSinkConfig> {
- @Override
- public DefaultStreamSinkConfig getSinkConfig(String streamId, Config config) {
- return new DefaultStreamSinkConfig(LoggingStreamSink.class);
- }
-
- @Override
- public LoggingStreamSink getSink() {
- return new LoggingStreamSink();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/StormStreamSink.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/StormStreamSink.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/StormStreamSink.java
deleted file mode 100644
index ad40772..0000000
--- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/StormStreamSink.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.eagle.app.sink;
-
-import backtype.storm.task.OutputCollector;
-import backtype.storm.topology.base.BaseRichBolt;
-import org.apache.eagle.metadata.model.StreamSinkConfig;
-import backtype.storm.task.TopologyContext;
-import backtype.storm.topology.BasicOutputCollector;
-import backtype.storm.topology.OutputFieldsDeclarer;
-import backtype.storm.topology.base.BaseBasicBolt;
-import backtype.storm.tuple.Tuple;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public abstract class StormStreamSink<K extends StreamSinkConfig> extends BaseRichBolt implements StreamSink<K> {
- private static final Logger LOG = LoggerFactory.getLogger(StormStreamSink.class);
- private String streamId;
- private OutputCollector collector;
-
- @Override
- public void init(String streamId, K config) {
- this.streamId = streamId;
- }
-
- @Override
- public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
- this.collector = collector;
- }
-
- /**
- * Implicitly hides the Tuple protocol inside code as Tuple[Key,Map].
- */
- @Override
- public void execute(Tuple input) {
- try {
- Map event = null;
- Object key = input.getValue(0);
- if (input.size() < 2) {
- event = tupleAsMap(input);
- } else {
- Object value = input.getValue(1);
- if (value != null) {
- if (value instanceof Map) {
- event = (Map) input.getValue(1);
- } else {
- event = tupleAsMap(input);
- }
- }
- }
- execute(key, event, collector);
- collector.ack(input);
- } catch (Exception ex) {
- LOG.error(ex.getMessage(), ex);
- collector.reportError(ex);
- }
- }
-
- protected abstract void execute(Object key, Map event, OutputCollector collector) throws Exception;
-
- private Map tupleAsMap(Tuple tuple) {
- Map values = new HashMap<>();
- for (String field : tuple.getFields()) {
- values.put(field, tuple.getValueByField(field));
- }
- return values;
- }
-
- @Override
- public void declareOutputFields(OutputFieldsDeclarer declarer) {
- }
-
- public String getStreamId() {
- return streamId;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/StreamEventMapper.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/StreamEventMapper.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/StreamEventMapper.java
deleted file mode 100644
index 710e4d2..0000000
--- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/StreamEventMapper.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.eagle.app.sink;
-
-import org.apache.eagle.alert.engine.model.StreamEvent;
-import backtype.storm.tuple.Tuple;
-
-import java.io.Serializable;
-import java.util.List;
-
-@FunctionalInterface
-public interface StreamEventMapper extends Serializable {
- /**
- * Map from storm tuple to Stream Event.
- *
- * @param tuple
- * @return
- * @throws Exception
- */
- List<StreamEvent> map(Tuple tuple) throws Exception;
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/StreamSink.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/StreamSink.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/StreamSink.java
deleted file mode 100644
index ee2790c..0000000
--- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/StreamSink.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.eagle.app.sink;
-
-import org.apache.eagle.app.ApplicationLifecycle;
-import org.apache.eagle.metadata.model.StreamSinkConfig;
-
-public interface StreamSink<T extends StreamSinkConfig> extends ApplicationLifecycle {
- void init(String streamId,T config);
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/StreamSinkProvider.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/StreamSinkProvider.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/StreamSinkProvider.java
deleted file mode 100644
index 0425fa6..0000000
--- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/sink/StreamSinkProvider.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
- * 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.eagle.app.sink;
-
-import org.apache.eagle.metadata.model.StreamSinkConfig;
-import com.typesafe.config.Config;
-
-import java.lang.reflect.ParameterizedType;
-
-public interface StreamSinkProvider<S extends StreamSink<D>, D extends StreamSinkConfig> {
- D getSinkConfig(String streamId, Config config);
-
- S getSink();
-
- default S getSink(String streamId, Config config) {
- S s = getSink();
- s.init(streamId, getSinkConfig(streamId, config));
- return s;
- }
-
- default Class<? extends S> getSinkType() {
- return (Class<S>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
- }
-
- default Class<? extends D> getSinkConfigType() {
- return (Class<D>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[1];
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/spi/ApplicationProvider.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/spi/ApplicationProvider.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/spi/ApplicationProvider.java
index 143e026..361b4c6 100644
--- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/spi/ApplicationProvider.java
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/spi/ApplicationProvider.java
@@ -28,7 +28,7 @@ import java.lang.reflect.ParameterizedType;
import java.util.Optional;
/**
- * Application Service Provider Interface.
+ * Application Service KafkaStreamMessaging Interface.
*
* @param <T> Application Type.
*/
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/utils/StreamConvertHelper.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/utils/StreamConvertHelper.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/utils/StreamConvertHelper.java
new file mode 100644
index 0000000..c25a93b
--- /dev/null
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/utils/StreamConvertHelper.java
@@ -0,0 +1,51 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.eagle.app.utils;
+
+import backtype.storm.tuple.Tuple;
+import org.apache.eagle.common.utils.Tuple2;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class StreamConvertHelper {
+ private static Map tupleToMap(Tuple tuple) {
+ Map values = new HashMap<>();
+ for (String field : tuple.getFields()) {
+ values.put(field, tuple.getValueByField(field));
+ }
+ return values;
+ }
+
+ public static Tuple2<Object,Map> tupleToEvent(Tuple input) {
+ Map event = null;
+ Object key = input.getValue(0);
+ if (input.size() < 2) {
+ event = StreamConvertHelper.tupleToMap(input);
+ } else {
+ Object value = input.getValue(1);
+ if (value != null) {
+ if (value instanceof Map) {
+ event = (Map) input.getValue(1);
+ } else {
+ event = StreamConvertHelper.tupleToMap(input);
+ }
+ }
+ }
+ return new Tuple2<>(key, event);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/TestStormApplication.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/TestStormApplication.java b/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/TestStormApplication.java
index a47e30a..7977650 100644
--- a/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/TestStormApplication.java
+++ b/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/TestStormApplication.java
@@ -23,13 +23,10 @@ import backtype.storm.topology.OutputFieldsDeclarer;
import backtype.storm.topology.TopologyBuilder;
import backtype.storm.topology.base.BaseRichSpout;
import backtype.storm.tuple.Fields;
-import com.google.inject.AbstractModule;
import com.google.inject.Inject;
import com.typesafe.config.Config;
import org.apache.eagle.app.environment.impl.StormEnvironment;
-import org.apache.eagle.common.module.ModuleRegistry;
import org.apache.eagle.app.spi.AbstractApplicationProvider;
-import org.apache.eagle.metadata.service.memory.MemoryMetadataStore;
import org.junit.Ignore;
import java.util.Arrays;
@@ -61,7 +58,7 @@ public class TestStormApplication extends StormApplication{
@Override
public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {
- outputFieldsDeclarer.declare(new Fields("metric","timestamp","source","value"));
+ outputFieldsDeclarer.declare(new Fields("metric","timestamp","fromStream","value"));
}
}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/environment/StaticEnvironmentTest.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/environment/StaticEnvironmentTest.java b/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/environment/StaticEnvironmentTest.java
index de64e6a..906bf66 100644
--- a/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/environment/StaticEnvironmentTest.java
+++ b/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/environment/StaticEnvironmentTest.java
@@ -34,6 +34,6 @@ public class StaticEnvironmentTest {
*/
@Test
public void testStreamSinkSupport(){
- environment.streamSink();
+ environment.stream();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/storm/MockStormApplication.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/storm/MockStormApplication.java b/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/storm/MockStormApplication.java
index 5733531..eda9383 100644
--- a/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/storm/MockStormApplication.java
+++ b/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/storm/MockStormApplication.java
@@ -54,7 +54,7 @@ public class MockStormApplication extends StormApplication {
}
@Override
public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {
- outputFieldsDeclarer.declare(new Fields("metric","timestamp","source","value"));
+ outputFieldsDeclarer.declare(new Fields("metric","timestamp","fromStream","value"));
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/stream/CEPFunctionTest.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/stream/CEPFunctionTest.java b/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/stream/CEPFunctionTest.java
new file mode 100644
index 0000000..b1a4193
--- /dev/null
+++ b/eagle-core/eagle-app/eagle-app-base/src/test/java/org/apache/eagle/app/stream/CEPFunctionTest.java
@@ -0,0 +1,50 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.eagle.app.stream;
+
+import org.apache.eagle.app.environment.builder.CEPFunction;
+import org.apache.eagle.app.environment.builder.Collector;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class CEPFunctionTest {
+ @Test @Ignore("TODO: Not implement yet")
+ public void testSiddhiFunction() {
+ CEPFunction function = new CEPFunction(
+ "define stream inputStream (name string, value double);\n "
+ + "from inputStream#window.timeBatch( 1 min ) \n" +
+ "select name, avg(value) as avgValue\n" +
+ "group by name \n" +
+ "insert into outputStream ",
+ "inputStream","outputStream");
+ Collector collector = new Collector() {
+ @Override
+ public void collect(Object key, Map event) {
+
+ }
+ };
+ function.open(collector);
+ function.transform(new HashMap<String,Object>() {{
+ put("name","cpu.usage");
+ put("value", 0.98);
+ }});
+ function.close();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-app/eagle-app-base/src/test/resources/application.conf
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/test/resources/application.conf b/eagle-core/eagle-app/eagle-app-base/src/test/resources/application.conf
index 4dbf0c4..377eed1 100644
--- a/eagle-core/eagle-app/eagle-app-base/src/test/resources/application.conf
+++ b/eagle-core/eagle-app/eagle-app-base/src/test/resources/application.conf
@@ -43,9 +43,8 @@
"store": "org.apache.eagle.metadata.service.memory.MemoryMetadataStore"
},
"application":{
- "sink":{
- "type": "org.apache.eagle.app.sink.KafkaStreamSink"
- "boostrap.server":"localhost:9092"
+ "stream": {
+ "provider": "org.apache.eagle.app.messaging.KafkaStreamProvider"
}
"provider":{
"loader": "org.apache.eagle.app.service.impl.ApplicationProviderSPILoader"
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/utils/Tuple2.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/utils/Tuple2.java b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/utils/Tuple2.java
new file mode 100644
index 0000000..ac3dc7c
--- /dev/null
+++ b/eagle-core/eagle-common/src/main/java/org/apache/eagle/common/utils/Tuple2.java
@@ -0,0 +1,42 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.eagle.common.utils;
+
+import java.io.Serializable;
+
+public class Tuple2<F1, F2> implements Serializable {
+ private final F1 f1;
+ private final F2 f2;
+
+ public Tuple2(F1 f1, F2 f2) {
+ this.f1 = f1;
+ this.f2 = f2;
+ }
+
+ public F2 f1() {
+ return f2;
+ }
+
+ public F1 f0() {
+ return f1;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("(%s,%s)", this.f1, this.f2);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/model/StreamDesc.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/model/StreamDesc.java b/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/model/StreamDesc.java
index 47d16fd..a183351 100644
--- a/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/model/StreamDesc.java
+++ b/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/model/StreamDesc.java
@@ -19,10 +19,13 @@ package org.apache.eagle.metadata.model;
import org.apache.eagle.alert.engine.coordinator.StreamDefinition;
import org.apache.eagle.metadata.utils.StreamIdConversions;
+import javax.xml.transform.stream.StreamSource;
+
public class StreamDesc {
private String streamId;
private StreamDefinition schema;
- private StreamSinkConfig sink;
+ private StreamSinkConfig sinkConfig;
+ private StreamSourceConfig sourceConfig;
public String getStreamId() {
return streamId;
@@ -40,11 +43,19 @@ public class StreamDesc {
this.schema = streamSchema;
}
- public StreamSinkConfig getSink() {
- return sink;
+ public StreamSinkConfig getSinkConfig() {
+ return sinkConfig;
+ }
+
+ public void setSinkConfig(StreamSinkConfig sinkDesc) {
+ this.sinkConfig = sinkDesc;
+ }
+
+ public StreamSourceConfig getSourceConfig() {
+ return sourceConfig;
}
- public void setSink(StreamSinkConfig sinkDesc) {
- this.sink = sinkDesc;
+ public void setSourceConfig(StreamSourceConfig sourceConfig) {
+ this.sourceConfig = sourceConfig;
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/model/StreamSourceConfig.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/model/StreamSourceConfig.java b/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/model/StreamSourceConfig.java
new file mode 100644
index 0000000..4034221
--- /dev/null
+++ b/eagle-core/eagle-metadata/eagle-metadata-base/src/main/java/org/apache/eagle/metadata/model/StreamSourceConfig.java
@@ -0,0 +1,27 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.eagle.metadata.model;
+
+import java.io.Serializable;
+
+public interface StreamSourceConfig extends Serializable {
+ String getType();
+
+ Class<?> getSourceType();
+
+ Class<? extends StreamSourceConfig> getConfigType();
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/10572c29/eagle-core/eagle-metadata/eagle-metadata-base/src/test/resources/application-test.xml
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-metadata/eagle-metadata-base/src/test/resources/application-test.xml b/eagle-core/eagle-metadata/eagle-metadata-base/src/test/resources/application-test.xml
index 82e84ed..d408c5e 100644
--- a/eagle-core/eagle-metadata/eagle-metadata-base/src/test/resources/application-test.xml
+++ b/eagle-core/eagle-metadata/eagle-metadata-base/src/test/resources/application-test.xml
@@ -1,3 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
<configuration>
<property>
<name>testkey1</name>