From 891d064db3e86607130c0222c8754ce0c5b3d17a Mon Sep 17 00:00:00 2001 From: Marcus Leich Date: Thu, 19 Dec 2013 19:06:52 +0100 Subject: [PATCH 1/2] cleaned up dependencies --- meteor-scheduler-common/pom.xml | 7 ++++++ meteor-scheduler-server/pom.xml | 16 ++++++++++++++ pom.xml | 39 +++++++++------------------------ 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/meteor-scheduler-common/pom.xml b/meteor-scheduler-common/pom.xml index 3011586..0e4fdfe 100644 --- a/meteor-scheduler-common/pom.xml +++ b/meteor-scheduler-common/pom.xml @@ -11,5 +11,12 @@ meteor-scheduler-common + + + org.json + json + 20090211 + + \ No newline at end of file diff --git a/meteor-scheduler-server/pom.xml b/meteor-scheduler-server/pom.xml index 9527aee..7efb851 100644 --- a/meteor-scheduler-server/pom.xml +++ b/meteor-scheduler-server/pom.xml @@ -17,6 +17,22 @@ meteor-scheduler-common 0.4-SNAPSHOT + + eu.stratosphere + meteor-client + ${project.version} + + + eu.stratosphere + meteor-meteor + ${project.version} + + + eu.stratosphere + meteor-webfrontend + ${project.version} + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 8d520b9..19130fe 100644 --- a/pom.xml +++ b/pom.xml @@ -25,55 +25,36 @@ 0.4-SNAPSHOT - - eu.stratosphere - meteor-client - ${project.version} - - - eu.stratosphere - meteor-meteor - ${project.version} - - - eu.stratosphere - meteor-webfrontend - ${project.version} - com.rabbitmq amqp-client 3.1.3 - - org.apache.hadoop - hadoop-core - 0.20.205.0 - junit junit 4.10 + test - + + org.apache.hadoop + hadoop-core + 0.20.205.0 + + + From 3a5ca073e1e5e41c0ca30e0223b4c30eedf9ca54 Mon Sep 17 00:00:00 2001 From: Marcus Leich Date: Thu, 19 Dec 2013 19:07:35 +0100 Subject: [PATCH 2/2] improced connect/disconnect/reconnect handlind --- .../meteor/client/DOPAClient.java | 54 ++++++++++++++----- .../meteor/client/DOPAClientTest.java | 34 +++++++++--- 2 files changed, 70 insertions(+), 18 deletions(-) diff --git a/meteor-scheduler-client/src/main/java/eu/stratosphere/meteor/client/DOPAClient.java b/meteor-scheduler-client/src/main/java/eu/stratosphere/meteor/client/DOPAClient.java index a0037ea..ffa2611 100644 --- a/meteor-scheduler-client/src/main/java/eu/stratosphere/meteor/client/DOPAClient.java +++ b/meteor-scheduler-client/src/main/java/eu/stratosphere/meteor/client/DOPAClient.java @@ -89,36 +89,66 @@ public String getClientID(){ * Try to connect the client with the scheduler services. * If this failed for any reason you can try it again. * - * It do nothing if the client is still connected. + * It does nothing if the client is still connected. + * + * @return true if the client was successfully connected or the client was already connected, + * false if the client was not connected to the server */ - public void connect() { + public boolean connect() { // if the client is still connect if ( this.connectionFac != null ) { LOG.error( "The client is still connected. If you want to reconnect the client disconnect it first." ); - return; + return true; } // else try to connect it - try { this.connectionFac = new ClientConnectionFactory( this ); } - catch ( Exception exc ) { LOG.error( "Cannot connected to the scheduler services!", exc ); } + try { + this.connectionFac = new ClientConnectionFactory( this ); + return true; + } + catch ( Exception exc ) { + LOG.error( "Cannot connected to the scheduler services!", exc ); + } + return false; } /** - * Try to reconnect the client with the scheduler services. - * - * Nothing happened if this client is still connected. + * Tries to reconnect the client with the scheduler services. + * Does nothing if this client is still connected. + * Use this method if you want to reconnect to the scheduler but didn't properly disconnect before. + * This is especially useful if you client crashed and the scheduler assumes it is still connected. + * + * ¡Use this method with great care! + * We only support one active client instance per client ID. Reconnect only if you are sure the previous + * client instance that created the connection is not running anymore! + * + * * @return true if the client was successfully reconnected or the client was already connected, + * false if the client was not reconnected to the server */ - public void reconnect(){ + public boolean reconnect(){ // if the client is still connect if ( this.connectionFac != null ) { LOG.error( "The client is still connected. If you want to reconnect the client disconnect it first." ); - return; + return true; } // try to reconnect - try { this.connectionFac = new ClientConnectionFactory( this, true ); } - catch ( Exception exc ) { LOG.error("Cannot reconnect to the scheduler services!", exc); } + try { this.connectionFac = new ClientConnectionFactory( this, true ); + return true; + } + catch ( Exception exc ) { + LOG.error("Cannot reconnect to the scheduler services!", exc); + } + return false; } + + /** + * Check whether this client is connected to the server + * @return true if this client is connected to the server + */ + public boolean isConnected () { + return this.connectionFac != null; + } /** * Try to disconnect the client. diff --git a/meteor-scheduler-client/src/test/java/eu/stratosphere/meteor/client/DOPAClientTest.java b/meteor-scheduler-client/src/test/java/eu/stratosphere/meteor/client/DOPAClientTest.java index 9282256..b72c3e5 100644 --- a/meteor-scheduler-client/src/test/java/eu/stratosphere/meteor/client/DOPAClientTest.java +++ b/meteor-scheduler-client/src/test/java/eu/stratosphere/meteor/client/DOPAClientTest.java @@ -1,5 +1,7 @@ package eu.stratosphere.meteor.client; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import eu.stratosphere.meteor.common.DSCLJob; import eu.stratosphere.meteor.common.JobState; @@ -12,15 +14,33 @@ public class DOPAClientTest { @Test public void testConnectDisconnect () { DOPAClient client = DOPAClient.createNewClient("connectDisconnectID"); - client.connect(); + assertTrue(client.connect()); client.disconnect(); } + @Test + public void testReconnect () { + // connect first client + DOPAClient client = DOPAClient.createNewClient("testReconnectID"); + assertTrue("First client could not connect to scheduler", client.connect()); + // leave connection open + client = null; + + // connect second client with same ID + DOPAClient client2 = DOPAClient.createNewClient("testReconnectID"); + // connection should fail as the first client didn't disconnect properly + assertFalse("Second client did connect to server, connection was expected to fail!", client2.connect()); + // explicit reconnect should work + assertTrue("Reconnecting second client failed", client2.reconnect()); + // do proper disconnect + client2.disconnect(); + } + @Test public void testQuerySubmission () { DOPAClient client = DOPAClient.createNewClient("testID"); - client.connect(); + assertTrue("Could not connect client to scheduler", client.connect()); JobStateListener listener = new JobStateListener() { @Override public void stateChanged(DSCLJob job, JobState newStatus) { @@ -31,18 +51,20 @@ public void stateChanged(DSCLJob job, JobState newStatus) { DSCLJob job = client.createNewJob("PROVOKE SYNTAX ERROR", listener); long start = System.currentTimeMillis(); + boolean expectedErrorFlag = false; // wait for 10.000ms = 10 seconds while ( System.currentTimeMillis() - start < 10_000 ) { - if ( job.getStatus().equals(JobState.ERROR) )return; - + if ( job.getStatus().equals(JobState.ERROR) ) { + expectedErrorFlag = true; + } try {Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } - - fail("Job doesn't finished with an error in 10 seconds."); + client.disconnect(); + assertTrue("Job doesn't finished with an error in 10 seconds.", expectedErrorFlag); } }