Skip to content

Commit

Permalink
Simple Web Socket Client and Server Implementation Added
Browse files Browse the repository at this point in the history
  • Loading branch information
nisarg64 committed Oct 26, 2015
1 parent 8ef5beb commit f7b9131
Show file tree
Hide file tree
Showing 37 changed files with 214 additions and 65 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -21,3 +21,4 @@ pass.txt
ambari-agent/src/test/python/ambari_agent/dummy_files/current-stack
velocity.log*
ambari-metrics/ambari-metrics-host-monitoring/src/main/python/psutil/build/
*versionsBackup
4 changes: 2 additions & 2 deletions ambari-admin/pom.xml
Expand Up @@ -19,15 +19,15 @@
<parent>
<groupId>org.apache.ambari</groupId>
<artifactId>ambari-project</artifactId>
<version>2.0.0.0-SNAPSHOT</version>
<version>2.2.0.0.0</version>
<relativePath>../ambari-project</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.ambari</groupId>
<artifactId>ambari-admin</artifactId>
<packaging>jar</packaging>
<name>Ambari Admin View</name>
<version>2.0.0.0-SNAPSHOT</version>
<version>2.2.0.0.0</version>
<description>Admin control panel</description>
<build>
<plugins>
Expand Down
4 changes: 2 additions & 2 deletions ambari-agent/pom.xml
Expand Up @@ -19,14 +19,14 @@
<parent>
<groupId>org.apache.ambari</groupId>
<artifactId>ambari-project</artifactId>
<version>2.0.0.0-SNAPSHOT</version>
<version>2.2.0.0.0</version>
<relativePath>../ambari-project</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.ambari</groupId>
<artifactId>ambari-agent</artifactId>
<packaging>pom</packaging>
<version>2.0.0.0-SNAPSHOT</version>
<version>2.2.0.0.0</version>
<name>Ambari Agent</name>
<description>Ambari Agent</description>
<properties>
Expand Down
4 changes: 2 additions & 2 deletions ambari-client/groovy-client/pom.xml
Expand Up @@ -12,14 +12,14 @@
<parent>
<artifactId>ambari-client</artifactId>
<groupId>org.apache.ambari</groupId>
<version>2.0.0.0-SNAPSHOT</version>
<version>2.2.0.0.0</version>
<relativePath>../../ambari-client/</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.ambari</groupId>
<artifactId>groovy-client</artifactId>
<packaging>jar</packaging>
<version>2.0.0.0-SNAPSHOT</version>
<version>2.2.0.0.0</version>
<name>Ambari Groovy Client</name>
<description>Ambari Groovy client</description>
<properties>
Expand Down
4 changes: 2 additions & 2 deletions ambari-client/pom.xml
Expand Up @@ -20,14 +20,14 @@
<parent>
<groupId>org.apache.ambari</groupId>
<artifactId>ambari-project</artifactId>
<version>2.0.0.0-SNAPSHOT</version>
<version>2.2.0.0.0</version>
<relativePath>../ambari-project</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.ambari</groupId>
<artifactId>ambari-client</artifactId>
<packaging>pom</packaging>
<version>2.0.0.0-SNAPSHOT</version>
<version>2.2.0.0.0</version>
<name>Ambari Client</name>
<description>Ambari client</description>
<modules>
Expand Down
4 changes: 2 additions & 2 deletions ambari-client/python-client/pom.xml
Expand Up @@ -19,14 +19,14 @@
<parent>
<groupId>org.apache.ambari</groupId>
<artifactId>ambari-client</artifactId>
<version>2.0.0.0-SNAPSHOT</version>
<version>2.2.0.0.0</version>
<relativePath>../../ambari-client</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.ambari</groupId>
<artifactId>python-client</artifactId>
<packaging>pom</packaging>
<version>2.0.0.0-SNAPSHOT</version>
<version>2.2.0.0.0</version>
<name>Ambari Python Client</name>
<description>Ambari Python client</description>
<properties>
Expand Down
4 changes: 2 additions & 2 deletions ambari-metrics/ambari-metrics-assembly/pom.xml
Expand Up @@ -23,13 +23,13 @@
<parent>
<artifactId>ambari-metrics</artifactId>
<groupId>org.apache.ambari</groupId>
<version>2.0.0.0-SNAPSHOT</version>
<version>2.2.0.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ambari-metrics-assembly</artifactId>
<name>Ambari Metrics Assembly</name>
<packaging>pom</packaging>
<version>2.0.0.0-SNAPSHOT</version>
<version>2.2.0.0.0</version>
<description>Ambari Metrics</description>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion ambari-metrics/ambari-metrics-common/pom.xml
Expand Up @@ -21,7 +21,7 @@
<parent>
<artifactId>ambari-metrics</artifactId>
<groupId>org.apache.ambari</groupId>
<version>2.0.0.0-SNAPSHOT</version>
<version>2.2.0.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ambari-metrics-common</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions ambari-metrics/ambari-metrics-flume-sink/pom.xml
Expand Up @@ -22,11 +22,11 @@ limitations under the License.
<parent>
<artifactId>ambari-metrics</artifactId>
<groupId>org.apache.ambari</groupId>
<version>2.0.0.0-SNAPSHOT</version>
<version>2.2.0.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ambari-metrics-flume-sink</artifactId>
<version>2.0.0.0-SNAPSHOT</version>
<version>2.2.0.0.0</version>
<name>Ambari Metrics Flume Sink</name>
<packaging>jar</packaging>
<build>
Expand Down
4 changes: 2 additions & 2 deletions ambari-metrics/ambari-metrics-hadoop-sink/pom.xml
Expand Up @@ -22,11 +22,11 @@ limitations under the License.
<parent>
<artifactId>ambari-metrics</artifactId>
<groupId>org.apache.ambari</groupId>
<version>2.0.0.0-SNAPSHOT</version>
<version>2.2.0.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ambari-metrics-hadoop-sink</artifactId>
<version>2.0.0.0-SNAPSHOT</version>
<version>2.2.0.0.0</version>
<name>Ambari Metrics Hadoop Sink</name>
<packaging>jar</packaging>
<properties>
Expand Down
4 changes: 2 additions & 2 deletions ambari-metrics/ambari-metrics-host-monitoring/pom.xml
Expand Up @@ -22,11 +22,11 @@
<parent>
<artifactId>ambari-metrics</artifactId>
<groupId>org.apache.ambari</groupId>
<version>2.0.0.0-SNAPSHOT</version>
<version>2.2.0.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<version>2.0.0.0-SNAPSHOT</version>
<version>2.2.0.0.0</version>
<artifactId>ambari-metrics-host-monitoring</artifactId>
<name>Ambari Metrics Monitor</name>
<properties>
Expand Down
4 changes: 2 additions & 2 deletions ambari-metrics/ambari-metrics-kafka-sink/pom.xml
Expand Up @@ -22,11 +22,11 @@ limitations under the License.
<parent>
<artifactId>ambari-metrics</artifactId>
<groupId>org.apache.ambari</groupId>
<version>2.0.0.0-SNAPSHOT</version>
<version>2.2.0.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ambari-metrics-kafka-sink</artifactId>
<version>2.0.0.0-SNAPSHOT</version>
<version>2.2.0.0.0</version>
<name>Ambari Metrics Kafka Sink</name>
<packaging>jar</packaging>
<build>
Expand Down
4 changes: 2 additions & 2 deletions ambari-metrics/ambari-metrics-storm-sink/pom.xml
Expand Up @@ -22,11 +22,11 @@ limitations under the License.
<parent>
<artifactId>ambari-metrics</artifactId>
<groupId>org.apache.ambari</groupId>
<version>2.0.0.0-SNAPSHOT</version>
<version>2.2.0.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ambari-metrics-storm-sink</artifactId>
<version>2.0.0.0-SNAPSHOT</version>
<version>2.2.0.0.0</version>
<name>Ambari Metrics Storm Sink</name>
<packaging>jar</packaging>

Expand Down
6 changes: 3 additions & 3 deletions ambari-metrics/ambari-metrics-timelineservice/pom.xml
Expand Up @@ -22,11 +22,11 @@
<parent>
<artifactId>ambari-metrics</artifactId>
<groupId>org.apache.ambari</groupId>
<version>2.0.0.0-SNAPSHOT</version>
<version>2.2.0.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ambari-metrics-timelineservice</artifactId>
<version>2.0.0.0-SNAPSHOT</version>
<version>2.2.0.0.0</version>
<name>Ambari Metrics Collector</name>
<packaging>jar</packaging>

Expand Down Expand Up @@ -274,7 +274,7 @@
<dependency>
<groupId>org.apache.ambari</groupId>
<artifactId>ambari-metrics-common</artifactId>
<version>2.0.0.0-SNAPSHOT</version>
<version>2.2.0.0.0</version>
</dependency>

<dependency>
Expand Down
2 changes: 1 addition & 1 deletion ambari-metrics/pom.xml
Expand Up @@ -19,7 +19,7 @@
<groupId>org.apache.ambari</groupId>
<modelVersion>4.0.0</modelVersion>
<artifactId>ambari-metrics</artifactId>
<version>2.0.0.0-SNAPSHOT</version>
<version>2.2.0.0.0</version>
<packaging>pom</packaging>
<modules>
<module>ambari-metrics-common</module>
Expand Down
4 changes: 2 additions & 2 deletions ambari-project/pom.xml
Expand Up @@ -18,11 +18,11 @@
<parent>
<groupId>org.apache.ambari</groupId>
<artifactId>ambari</artifactId>
<version>2.0.0.0-SNAPSHOT</version>
<version>2.2.0.0.0</version>
</parent>
<groupId>org.apache.ambari</groupId>
<artifactId>ambari-project</artifactId>
<version>2.0.0.0-SNAPSHOT</version>
<version>2.2.0.0.0</version>
<description>Apache Ambari Project POM</description>
<name>Apache Ambari Project POM</name>
<packaging>pom</packaging>
Expand Down
23 changes: 20 additions & 3 deletions ambari-server/pom.xml
Expand Up @@ -12,15 +12,15 @@
<parent>
<groupId>org.apache.ambari</groupId>
<artifactId>ambari-project</artifactId>
<version>2.0.0.0-SNAPSHOT</version>
<version>2.2.0.0.0</version>
<relativePath>../ambari-project</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.ambari</groupId>
<artifactId>ambari-server</artifactId>
<packaging>${packagingFormat}</packaging>
<name>Ambari Server</name>
<version>2.0.0.0-SNAPSHOT</version>
<version>2.2.0.0.0</version>
<description>Ambari Server</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand All @@ -47,6 +47,7 @@
<stacksSrcLocation>target/classes/stacks/${stack.distribution}</stacksSrcLocation>
<tarballResourcesFolder>src/main/resources</tarballResourcesFolder>
<skipPythonTests>false</skipPythonTests>
<jetty.version>9.2.11.v20150529</jetty.version>
</properties>
<build>
<plugins>
Expand Down Expand Up @@ -1157,7 +1158,7 @@
<group>root</group>
<filemode>755</filemode>
</mapper>
</data>
</data>
<data>
<src>
${project.basedir}/../ambari-common/src/main/python/ambari_commons
Expand Down Expand Up @@ -1325,6 +1326,11 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
</plugin>
</plugins>
<resources>
<resource>
Expand Down Expand Up @@ -2011,6 +2017,17 @@
<artifactId>ehcache</artifactId>
<version>2.10.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>javax-websocket-server-impl</artifactId>
<version>${jetty.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>javax-websocket-client-impl</artifactId>
<version>${jetty.version}</version>
</dependency>
</dependencies>

<pluginRepositories>
Expand Down
Expand Up @@ -21,6 +21,8 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -107,6 +109,10 @@
import com.google.inject.Injector;
import com.google.inject.Singleton;

import javax.websocket.ContainerProvider;
import javax.websocket.DeploymentException;
import javax.websocket.WebSocketContainer;


/**
* This class handles the heartbeats coming from the agent, passes on the information
Expand Down Expand Up @@ -330,6 +336,8 @@ protected void processHostStatus(HeartBeat heartbeat, String hostname) throws Am

Host host = clusterFsm.getHost(hostname);
HealthStatus healthStatus = host.getHealthStatus().getHealthStatus();
boolean persistExists = false;


if (!healthStatus.equals(HostHealthStatus.HealthStatus.UNKNOWN)) {

Expand Down Expand Up @@ -414,15 +422,31 @@ protected void processHostStatus(HeartBeat heartbeat, String hostname) throws Am

host.setStatus(healthStatus.name());
host.persist();
persistExists = true;
}

//If host doesn't belong to any cluster
if ((clusterFsm.getClustersForHost(host.getHostName())).size() == 0) {
healthStatus = HealthStatus.HEALTHY;
host.setStatus(healthStatus.name());
host.persist();
persistExists = true;
}
}
if(persistExists){
try {
String dest = "ws://localhost:8080/";
WebSocketClient socket = new WebSocketClient();
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
container.connectToServer(socket, new URI(dest));

socket.getLatch().await();
socket.sendMessage("Hello World");
Thread.sleep(10000l);
} catch (Throwable t) {
t.printStackTrace();
}
}
}

protected void processCommandReports(
Expand Down

0 comments on commit f7b9131

Please sign in to comment.