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/08/03 12:03:02 UTC
incubator-eagle git commit: [EAGLE-403] Initialize eagle jpm app
Repository: incubator-eagle
Updated Branches:
refs/heads/develop f2f07211d -> 037b97ad6
[EAGLE-403] Initialize eagle jpm app
Author: Hao Chen <ha...@apache.org>
Closes #294 from haoch/createEagleJPMApp.
Project: http://git-wip-us.apache.org/repos/asf/incubator-eagle/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-eagle/commit/037b97ad
Tree: http://git-wip-us.apache.org/repos/asf/incubator-eagle/tree/037b97ad
Diff: http://git-wip-us.apache.org/repos/asf/incubator-eagle/diff/037b97ad
Branch: refs/heads/develop
Commit: 037b97ad627148c81d53aa8444e599f0103020e5
Parents: f2f0721
Author: Hao Chen <ha...@apache.org>
Authored: Wed Aug 3 20:02:49 2016 +0800
Committer: Hao Chen <ha...@apache.org>
Committed: Wed Aug 3 20:02:49 2016 +0800
----------------------------------------------------------------------
.../app/service/ApplicationProviderLoader.java | 6 +-
.../impl/ApplicationProviderSPILoader.java | 1 -
eagle-jpm/eagle-jpm-app/pom.xml | 30 +++++
.../apache/eagle/app/jpm/JPMApplication.java | 56 ++++++++++
.../eagle/app/jpm/JPMApplicationProvider.java | 33 ++++++
.../resources/META-INF/apps/jpm/metadata.xml | 109 +++++++++++++++++++
...org.apache.eagle.app.spi.ApplicationProvider | 16 +++
.../src/main/webapp/app/apps/jpm/index.html | 6 +
.../eagle-jpm-app/src/main/webapp/package.json | 0
.../eagle/app/jpm/JPMApplicationTest.java | 71 ++++++++++++
eagle-jpm/pom.xml | 1 +
eagle-server/pom.xml | 8 +-
12 files changed, 334 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/037b97ad/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationProviderLoader.java
----------------------------------------------------------------------
diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationProviderLoader.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationProviderLoader.java
index 85f0709..0c895a3 100644
--- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationProviderLoader.java
+++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/service/ApplicationProviderLoader.java
@@ -56,7 +56,11 @@ public abstract class ApplicationProviderLoader {
}
public ApplicationProvider<?> getApplicationProviderByType(String type) {
- return providers.get(type);
+ if(providers.containsKey(type)) {
+ return providers.get(type);
+ }else{
+ throw new IllegalArgumentException("Unknown Application Type: "+type);
+ }
}
public void reset(){
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/037b97ad/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 3304286..762f024 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
@@ -44,7 +44,6 @@ public class ApplicationProviderSPILoader extends ApplicationProviderLoader{
}
LOG.info("Using {}: {}",APPLICATIONS_DIR_PROPS_KEY,this.appProviderExtDir);
-
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/037b97ad/eagle-jpm/eagle-jpm-app/pom.xml
----------------------------------------------------------------------
diff --git a/eagle-jpm/eagle-jpm-app/pom.xml b/eagle-jpm/eagle-jpm-app/pom.xml
new file mode 100644
index 0000000..095596f
--- /dev/null
+++ b/eagle-jpm/eagle-jpm-app/pom.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>eagle-jpm-parent</artifactId>
+ <groupId>org.apache.eagle</groupId>
+ <version>0.5.0-incubating-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>eagle-jpm-app</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.eagle</groupId>
+ <artifactId>eagle-app-base</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <resources>
+ <resource>
+ <directory>src/main/webapp/app</directory>
+ <targetPath>assets/</targetPath>
+ </resource>
+ <resource>
+ <directory>src/main/resources</directory>
+ </resource>
+ </resources>
+ </build>
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/037b97ad/eagle-jpm/eagle-jpm-app/src/main/java/org/apache/eagle/app/jpm/JPMApplication.java
----------------------------------------------------------------------
diff --git a/eagle-jpm/eagle-jpm-app/src/main/java/org/apache/eagle/app/jpm/JPMApplication.java b/eagle-jpm/eagle-jpm-app/src/main/java/org/apache/eagle/app/jpm/JPMApplication.java
new file mode 100644
index 0000000..7fecbf4
--- /dev/null
+++ b/eagle-jpm/eagle-jpm-app/src/main/java/org/apache/eagle/app/jpm/JPMApplication.java
@@ -0,0 +1,56 @@
+/*
+ * 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.jpm;
+
+import backtype.storm.spout.SpoutOutputCollector;
+import backtype.storm.task.TopologyContext;
+import backtype.storm.topology.OutputFieldsDeclarer;
+import backtype.storm.topology.TopologyBuilder;
+import backtype.storm.topology.base.BaseRichSpout;
+import backtype.storm.tuple.Fields;
+import org.apache.eagle.app.AbstractApplication;
+import org.apache.eagle.app.ApplicationContext;
+
+import java.util.Arrays;
+import java.util.Map;
+
+public class JPMApplication extends AbstractApplication {
+ protected void buildApp(TopologyBuilder builder, ApplicationContext context) {
+ builder.setSpout("metric_spout", new RandomEventSpout(), 4);
+ builder.setBolt("sink_1",context.getFlattenStreamSink("SAMPLE_STREAM_1")).fieldsGrouping("metric_spout",new Fields("metric"));
+ builder.setBolt("sink_2",context.getFlattenStreamSink("SAMPLE_STREAM_2")).fieldsGrouping("metric_spout",new Fields("metric"));
+ }
+
+ private class RandomEventSpout extends BaseRichSpout {
+ private SpoutOutputCollector _collector;
+ @Override
+ public void open(Map map, TopologyContext topologyContext, SpoutOutputCollector spoutOutputCollector) {
+ _collector = spoutOutputCollector;
+ }
+
+ @Override
+ public void nextTuple() {
+ _collector.emit(Arrays.asList("disk.usage",System.currentTimeMillis(),"host_1",56.7));
+ _collector.emit(Arrays.asList("cpu.usage",System.currentTimeMillis(),"host_2",99.8));
+ }
+
+ @Override
+ public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {
+ outputFieldsDeclarer.declare(new Fields("metric","timestamp","source","value"));
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/037b97ad/eagle-jpm/eagle-jpm-app/src/main/java/org/apache/eagle/app/jpm/JPMApplicationProvider.java
----------------------------------------------------------------------
diff --git a/eagle-jpm/eagle-jpm-app/src/main/java/org/apache/eagle/app/jpm/JPMApplicationProvider.java b/eagle-jpm/eagle-jpm-app/src/main/java/org/apache/eagle/app/jpm/JPMApplicationProvider.java
new file mode 100644
index 0000000..1da0c63
--- /dev/null
+++ b/eagle-jpm/eagle-jpm-app/src/main/java/org/apache/eagle/app/jpm/JPMApplicationProvider.java
@@ -0,0 +1,33 @@
+/**
+ * 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.jpm;
+
+import org.apache.eagle.app.spi.AbstractApplicationProvider;
+
+/**
+ * Define application provider programmatically
+ */
+public class JPMApplicationProvider extends AbstractApplicationProvider<JPMApplication> {
+ public JPMApplicationProvider() {
+ super("/META-INF/apps/jpm/metadata.xml");
+ }
+
+ @Override
+ public JPMApplication getApplication() {
+ return new JPMApplication();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/037b97ad/eagle-jpm/eagle-jpm-app/src/main/resources/META-INF/apps/jpm/metadata.xml
----------------------------------------------------------------------
diff --git a/eagle-jpm/eagle-jpm-app/src/main/resources/META-INF/apps/jpm/metadata.xml b/eagle-jpm/eagle-jpm-app/src/main/resources/META-INF/apps/jpm/metadata.xml
new file mode 100644
index 0000000..c2c77e2
--- /dev/null
+++ b/eagle-jpm/eagle-jpm-app/src/main/resources/META-INF/apps/jpm/metadata.xml
@@ -0,0 +1,109 @@
+<?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.
+ -->
+
+<application>
+ <type>JPM</type>
+ <name>Job Performance Monitoring Application</name>
+ <version>0.5.0-incubating</version>
+ <appClass>org.apache.eagle.app.jpm.JPMApplication</appClass>
+ <viewPath>/apps/jpm</viewPath>
+ <configuration>
+ <property>
+ <name>default</name>
+ <displayName>Message</displayName>
+ <value>Hello, example application!</value>
+ <description>Just an sample configuration property</description>
+ </property>
+ </configuration>
+ <streams>
+ <stream>
+ <streamId>SAMPLE_STREAM_1</streamId>
+ <description>Sample output stream #1</description>
+ <validate>true</validate>
+ <timeseries>true</timeseries>
+ <columns>
+ <column>
+ <name>metric</name>
+ <type>string</type>
+ </column>
+ <column>
+ <name>source</name>
+ <type>string</type>
+ </column>
+ <column>
+ <name>value</name>
+ <type>double</type>
+ <defaultValue>0.0</defaultValue>
+ </column>
+ </columns>
+ </stream>
+ <stream>
+ <streamId>SAMPLE_STREAM_2</streamId>
+ <description>Sample output stream #2</description>
+ <validate>true</validate>
+ <timeseries>true</timeseries>
+ <columns>
+ <column>
+ <name>metric</name>
+ <type>string</type>
+ </column>
+ <column>
+ <name>source</name>
+ <type>string</type>
+ </column>
+ <column>
+ <name>value</name>
+ <type>double</type>
+ <defaultValue>0.0</defaultValue>
+ </column>
+ </columns>
+ </stream>
+ </streams>
+ <docs>
+ <install>
+# Step 1: Create source kafka topic named "${site}_example_source_topic"
+
+./bin/kafka-topics.sh --create --topic example_source_topic --replication-factor 1 --replication 1
+
+# Step 2: Set up data collector to flow data into kafka topic in
+
+./bin/logstash -f log_collector.conf
+
+## `log_collector.conf` sample as following:
+
+input {
+
+}
+filter {
+
+}
+output{
+
+}
+
+# Step 3: start application
+
+# Step 4: monitor with featured portal or alert with policies
+ </install>
+ <uninstall>
+# Step 1: stop and uninstall application
+# Step 2: delete kafka topic named "${site}_example_source_topic"
+# Step 3: stop logstash
+ </uninstall>
+ </docs>
+</application>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/037b97ad/eagle-jpm/eagle-jpm-app/src/main/resources/META-INF/services/org.apache.eagle.app.spi.ApplicationProvider
----------------------------------------------------------------------
diff --git a/eagle-jpm/eagle-jpm-app/src/main/resources/META-INF/services/org.apache.eagle.app.spi.ApplicationProvider b/eagle-jpm/eagle-jpm-app/src/main/resources/META-INF/services/org.apache.eagle.app.spi.ApplicationProvider
new file mode 100644
index 0000000..2a876fd
--- /dev/null
+++ b/eagle-jpm/eagle-jpm-app/src/main/resources/META-INF/services/org.apache.eagle.app.spi.ApplicationProvider
@@ -0,0 +1,16 @@
+# 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.
+
+org.apache.eagle.app.jpm.JPMApplicationProvider
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/037b97ad/eagle-jpm/eagle-jpm-app/src/main/webapp/app/apps/jpm/index.html
----------------------------------------------------------------------
diff --git a/eagle-jpm/eagle-jpm-app/src/main/webapp/app/apps/jpm/index.html b/eagle-jpm/eagle-jpm-app/src/main/webapp/app/apps/jpm/index.html
new file mode 100644
index 0000000..c0e81f3
--- /dev/null
+++ b/eagle-jpm/eagle-jpm-app/src/main/webapp/app/apps/jpm/index.html
@@ -0,0 +1,6 @@
+<htm>
+ <body>
+ <h1>JPM Application!</h1>
+ <i><b>url</b>: /apps/jpm</i>
+ </body>
+</htm>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/037b97ad/eagle-jpm/eagle-jpm-app/src/main/webapp/package.json
----------------------------------------------------------------------
diff --git a/eagle-jpm/eagle-jpm-app/src/main/webapp/package.json b/eagle-jpm/eagle-jpm-app/src/main/webapp/package.json
new file mode 100644
index 0000000..e69de29
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/037b97ad/eagle-jpm/eagle-jpm-app/src/test/java/org/apache/eagle/app/jpm/JPMApplicationTest.java
----------------------------------------------------------------------
diff --git a/eagle-jpm/eagle-jpm-app/src/test/java/org/apache/eagle/app/jpm/JPMApplicationTest.java b/eagle-jpm/eagle-jpm-app/src/test/java/org/apache/eagle/app/jpm/JPMApplicationTest.java
new file mode 100644
index 0000000..a78bbae
--- /dev/null
+++ b/eagle-jpm/eagle-jpm-app/src/test/java/org/apache/eagle/app/jpm/JPMApplicationTest.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.jpm;
+
+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.AppUnitTestRunner;
+import org.apache.eagle.app.test.ApplicationSimulator;
+import org.apache.eagle.metadata.model.ApplicationEntity;
+import org.apache.eagle.metadata.model.SiteEntity;
+import org.apache.eagle.metadata.resource.SiteResource;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AppUnitTestRunner.class)
+public class JPMApplicationTest {
+ @Inject
+ private SiteResource siteResource;
+ @Inject private ApplicationResource applicationResource;
+
+ /**
+ * register site
+ * install app
+ * start app
+ * stop app
+ * uninstall app
+ *
+ * @throws InterruptedException
+ */
+ @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 JPMApplication");
+ siteResource.createSite(siteEntity);
+ Assert.assertNotNull(siteEntity.getUuid());
+
+ // Install application
+ ApplicationEntity applicationEntity = applicationResource.installApplication(new ApplicationOperations.InstallOperation("test_site","JPM_APP", ApplicationEntity.Mode.LOCAL)).getData();
+ // Start application
+ applicationResource.startApplication(new ApplicationOperations.StartOperation(applicationEntity.getUuid()));
+ // Stop application
+ applicationResource.stopApplication(new ApplicationOperations.StopOperation(applicationEntity.getUuid()));
+ // 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
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/037b97ad/eagle-jpm/pom.xml
----------------------------------------------------------------------
diff --git a/eagle-jpm/pom.xml b/eagle-jpm/pom.xml
index 05c3087..eada67f 100644
--- a/eagle-jpm/pom.xml
+++ b/eagle-jpm/pom.xml
@@ -38,6 +38,7 @@
<module>eagle-jpm-entity</module>
<module>eagle-hadoop-queue</module>
<module>eagle-jpm-util</module>
+ <module>eagle-jpm-app</module>
</modules>
<dependencies>
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/037b97ad/eagle-server/pom.xml
----------------------------------------------------------------------
diff --git a/eagle-server/pom.xml b/eagle-server/pom.xml
index f2aaa41..b2fb0d2 100644
--- a/eagle-server/pom.xml
+++ b/eagle-server/pom.xml
@@ -120,12 +120,18 @@
</dependency>
<dependency>
<groupId>org.apache.eagle</groupId>
+ <artifactId>eagle-common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.eagle</groupId>
<artifactId>eagle-app-example</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.eagle</groupId>
- <artifactId>eagle-common</artifactId>
+ <artifactId>eagle-jpm-app</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>