aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kevi...@apache.org
Subject [8/9] git commit: Returning custom response code in case of lock conflict
Date Thu, 05 Dec 2013 19:58:20 GMT
Returning custom response code in case of lock conflict


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

Branch: refs/heads/master
Commit: b4da3c3fc7ad5d3d0d9b7ccf1ce2c051420c85a9
Parents: 24c9906
Author: Maxim Khutornenko <mkhutornenko@twitter.com>
Authored: Thu Dec 5 11:23:43 2013 -0800
Committer: Maxim Khutornenko <mkhutornenko@twitter.com>
Committed: Thu Dec 5 11:23:43 2013 -0800

----------------------------------------------------------------------
 .../thrift/SchedulerThriftInterface.java        | 28 +++++++++++---------
 .../thrift/com/twitter/aurora/gen/api.thrift    |  3 ++-
 .../thrift/SchedulerThriftInterfaceTest.java    | 15 ++++++-----
 3 files changed, 26 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/b4da3c3f/src/main/java/com/twitter/aurora/scheduler/thrift/SchedulerThriftInterface.java
----------------------------------------------------------------------
diff --git a/src/main/java/com/twitter/aurora/scheduler/thrift/SchedulerThriftInterface.java
b/src/main/java/com/twitter/aurora/scheduler/thrift/SchedulerThriftInterface.java
index b8ba3f2..503ac44 100644
--- a/src/main/java/com/twitter/aurora/scheduler/thrift/SchedulerThriftInterface.java
+++ b/src/main/java/com/twitter/aurora/scheduler/thrift/SchedulerThriftInterface.java
@@ -126,6 +126,7 @@ import static com.twitter.aurora.auth.SessionValidator.SessionContext;
 import static com.twitter.aurora.gen.ResponseCode.AUTH_FAILED;
 import static com.twitter.aurora.gen.ResponseCode.ERROR;
 import static com.twitter.aurora.gen.ResponseCode.INVALID_REQUEST;
+import static com.twitter.aurora.gen.ResponseCode.LOCK_ERROR;
 import static com.twitter.aurora.gen.ResponseCode.OK;
 import static com.twitter.aurora.gen.apiConstants.CURRENT_API_VERSION;
 import static com.twitter.common.base.MorePreconditions.checkNotBlank;
@@ -246,7 +247,9 @@ class SchedulerThriftInterface implements AuroraAdmin.Iface {
       response.setResponseCode(OK)
           .setMessage(String.format("%d new tasks pending for job %s",
               sanitized.getJobConfig().getInstanceCount(), JobKeys.toPath(job)));
-    } catch (LockException | TaskDescriptionException | ScheduleException e) {
+    } catch (LockException e) {
+      response.setResponseCode(LOCK_ERROR).setMessage(e.getMessage());
+    } catch (TaskDescriptionException | ScheduleException e) {
       response.setResponseCode(INVALID_REQUEST).setMessage(e.getMessage());
     }
 
@@ -286,10 +289,8 @@ class SchedulerThriftInterface implements AuroraAdmin.Iface {
       return response.setResponseCode(OK).setMessage("Replaced template for: " + jobKey);
 
     } catch (LockException e) {
-      return response.setResponseCode(INVALID_REQUEST).setMessage(e.getMessage());
-    } catch (TaskDescriptionException e) {
-      return response.setResponseCode(INVALID_REQUEST).setMessage(e.getMessage());
-    } catch (ScheduleException e) {
+      return response.setResponseCode(LOCK_ERROR).setMessage(e.getMessage());
+    } catch (TaskDescriptionException | ScheduleException e) {
       return response.setResponseCode(INVALID_REQUEST).setMessage(e.getMessage());
     }
   }
@@ -490,10 +491,9 @@ class SchedulerThriftInterface implements AuroraAdmin.Iface {
       validateLockForTasks(Optional.fromNullable(mutablelock).transform(ILock.FROM_BUILDER),
tasks);
       schedulerCore.killTasks(Query.arbitrary(query), context.get().getIdentity());
     } catch (LockException e) {
-      return response.setResponseCode(INVALID_REQUEST).setMessage(e.getMessage());
+      return response.setResponseCode(LOCK_ERROR).setMessage(e.getMessage());
     } catch (ScheduleException e) {
-      response.setResponseCode(INVALID_REQUEST).setMessage(e.getMessage());
-      return response;
+      return response.setResponseCode(INVALID_REQUEST).setMessage(e.getMessage());
     }
 
     // TODO(William Farner): Move this into the client.
@@ -549,7 +549,9 @@ class SchedulerThriftInterface implements AuroraAdmin.Iface {
           Optional.fromNullable(mutableLock).transform(ILock.FROM_BUILDER));
       schedulerCore.restartShards(jobKey, shardIds, context.getIdentity());
       response.setResponseCode(OK).setMessage("Shards are restarting.");
-    } catch (LockException | ScheduleException e) {
+    } catch (LockException e) {
+      response.setResponseCode(ResponseCode.LOCK_ERROR).setMessage(e.getMessage());
+    } catch (ScheduleException e) {
       response.setResponseCode(ResponseCode.INVALID_REQUEST).setMessage(e.getMessage());
     }
 
@@ -894,7 +896,9 @@ class SchedulerThriftInterface implements AuroraAdmin.Iface {
       return resp.setResponseCode(OK).setMessage("Successfully added instances.");
     } catch (AuthFailedException e) {
       return resp.setResponseCode(AUTH_FAILED).setMessage(e.getMessage());
-    } catch (TaskDescriptionException | LockException | ScheduleException e) {
+    } catch (LockException e) {
+      return resp.setResponseCode(LOCK_ERROR).setMessage(e.getMessage());
+    } catch (TaskDescriptionException | ScheduleException e) {
       return resp.setResponseCode(INVALID_REQUEST).setMessage(e.getMessage());
     }
   }
@@ -930,7 +934,7 @@ class SchedulerThriftInterface implements AuroraAdmin.Iface {
     } catch (AuthFailedException e) {
       return response.setResponseCode(AUTH_FAILED).setMessage(e.getMessage());
     } catch (LockException e) {
-      return response.setResponseCode(ResponseCode.INVALID_REQUEST).setMessage(e.getMessage());
+      return response.setResponseCode(ResponseCode.LOCK_ERROR).setMessage(e.getMessage());
     }
   }
 
@@ -956,7 +960,7 @@ class SchedulerThriftInterface implements AuroraAdmin.Iface {
     } catch (AuthFailedException e) {
       return response.setResponseCode(AUTH_FAILED).setMessage(e.getMessage());
     } catch (LockException e) {
-      return response.setResponseCode(ResponseCode.INVALID_REQUEST).setMessage(e.getMessage());
+      return response.setResponseCode(ResponseCode.LOCK_ERROR).setMessage(e.getMessage());
     }
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/b4da3c3f/src/main/thrift/com/twitter/aurora/gen/api.thrift
----------------------------------------------------------------------
diff --git a/src/main/thrift/com/twitter/aurora/gen/api.thrift b/src/main/thrift/com/twitter/aurora/gen/api.thrift
index 1ce4041..9b3680b 100644
--- a/src/main/thrift/com/twitter/aurora/gen/api.thrift
+++ b/src/main/thrift/com/twitter/aurora/gen/api.thrift
@@ -21,7 +21,8 @@ enum ResponseCode {
   OK              = 1,
   ERROR           = 2,
   WARNING         = 3,
-  AUTH_FAILED     = 4
+  AUTH_FAILED     = 4,
+  LOCK_ERROR      = 5  // Raised when a Lock-protected operation failed due to lock validation.
 }
 
 struct APIVersion {

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/b4da3c3f/src/test/java/com/twitter/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/com/twitter/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
b/src/test/java/com/twitter/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
index 30d3947..1e1e7b5 100644
--- a/src/test/java/com/twitter/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
+++ b/src/test/java/com/twitter/aurora/scheduler/thrift/SchedulerThriftInterfaceTest.java
@@ -106,6 +106,7 @@ import static com.twitter.aurora.gen.MaintenanceMode.SCHEDULED;
 import static com.twitter.aurora.gen.ResponseCode.AUTH_FAILED;
 import static com.twitter.aurora.gen.ResponseCode.ERROR;
 import static com.twitter.aurora.gen.ResponseCode.INVALID_REQUEST;
+import static com.twitter.aurora.gen.ResponseCode.LOCK_ERROR;
 import static com.twitter.aurora.gen.ResponseCode.OK;
 import static com.twitter.aurora.gen.ResponseCode.WARNING;
 import static com.twitter.aurora.gen.apiConstants.DEFAULT_ENVIRONMENT;
@@ -239,7 +240,7 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
     control.replay();
 
     Response response = thrift.createJob(job.newBuilder(), LOCK.newBuilder(), SESSION);
-    assertEquals(ResponseCode.INVALID_REQUEST, response.getResponseCode());
+    assertEquals(ResponseCode.LOCK_ERROR, response.getResponseCode());
   }
 
   @Test
@@ -364,7 +365,7 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
     control.replay();
 
     Response response = thrift.killTasks(query.get(), LOCK.newBuilder(), SESSION);
-    assertEquals(ResponseCode.INVALID_REQUEST, response.getResponseCode());
+    assertEquals(ResponseCode.LOCK_ERROR, response.getResponseCode());
   }
 
   @Test
@@ -520,7 +521,7 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
     control.replay();
 
     Response resp = thrift.restartShards(JOB_KEY.newBuilder(), shards, LOCK.newBuilder(),
SESSION);
-    assertEquals(ResponseCode.INVALID_REQUEST, resp.getResponseCode());
+    assertEquals(ResponseCode.LOCK_ERROR, resp.getResponseCode());
   }
 
   @Test
@@ -664,7 +665,7 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
     control.replay();
 
     assertEquals(
-        INVALID_REQUEST,
+        LOCK_ERROR,
         thrift.replaceCronTemplate(CRON_JOB, LOCK.newBuilder(), SESSION).getResponseCode());
   }
 
@@ -1146,7 +1147,7 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
     control.replay();
 
     Response response = thrift.addInstances(config, LOCK.newBuilder(), SESSION);
-    assertEquals(ResponseCode.INVALID_REQUEST, response.getResponseCode());
+    assertEquals(ResponseCode.LOCK_ERROR, response.getResponseCode());
   }
 
   @Test
@@ -1221,7 +1222,7 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
     control.replay();
 
     Response response = thrift.acquireLock(LOCK_KEY.newBuilder(), SESSION);
-    assertEquals(ResponseCode.INVALID_REQUEST, response.getResponseCode());
+    assertEquals(ResponseCode.LOCK_ERROR, response.getResponseCode());
   }
 
   @Test
@@ -1265,7 +1266,7 @@ public class SchedulerThriftInterfaceTest extends EasyMockTest {
     control.replay();
 
     Response response = thrift.releaseLock(LOCK.newBuilder(), CHECKED, SESSION);
-    assertEquals(ResponseCode.INVALID_REQUEST, response.getResponseCode());
+    assertEquals(ResponseCode.LOCK_ERROR, response.getResponseCode());
   }
 
   private static JobConfiguration makeJob() {


Mime
View raw message