Skip to content
This repository
Browse code

Allow async manager to block on destroys when preempting (could block…

… up to 30s)
  • Loading branch information...
commit d48ff79d7cbed40e8200582af1c477a0b38947e5 1 parent 5da43c1
Tim Freeman authored June 13, 2011
2  service/service/java/source/src/org/globus/workspace/async/AsyncRequestManagerImpl.java
@@ -824,7 +824,7 @@ protected void preempt(AsyncRequest request, int quantity) {
824 824
 
825 825
                 final String sourceStr = "via async-Manager-preempt, request " +
826 826
                 "id = '" + request.getId() + "'";
827  
-                String errorStr = home.destroyMultiple(preemptionList, sourceStr);
  827
+                String errorStr = home.destroyMultiple(preemptionList, sourceStr, true);
828 828
                 if(errorStr != null && errorStr.length() != 0){
829 829
                     failRequest("pre-empting", request, errorStr, null);
830 830
                 }
18  service/service/java/source/src/org/globus/workspace/service/WorkspaceHome.java
@@ -85,9 +85,6 @@ public void destroy(String id)
85 85
      * including if the workspace was not found, etc.  This does not cut out
86 86
      * early if there is any kind of problem.
87 87
      *
88  
-     * (note: implement with multiple threads because the remove procedure is
89  
-     * blocking)
90  
-     *
91 88
      * @param workspaces list of workspace IDs
92 89
      * @param sourceStr string for log msgs
93 90
      * @return string report on what happened
@@ -95,6 +92,21 @@ public void destroy(String id)
95 92
     public String destroyMultiple(int[] workspaces, String sourceStr);
96 93
 
97 94
 
  95
+    /**
  96
+     * Destroy a set of workspaces.  Return a list of errors separated by \n,
  97
+     * including if the workspace was not found, etc.  This does not cut out
  98
+     * early if there is any kind of problem.
  99
+     *
  100
+     * Allow parameter to set to block until work is complete (up to thirty seconds).
  101
+     *
  102
+     * @param workspaces list of workspace IDs
  103
+     * @param sourceStr string for log msgs
  104
+     * @param block set true if you want to block until complete (up to thirty seconds)
  105
+     * @return string report on what happened
  106
+     */
  107
+    public String destroyMultiple(int[] workspaces, String sourceStr, boolean block);
  108
+
  109
+
98 110
     // -------------------------------------------------------------------------
99 111
     // OTHER
100 112
     // -------------------------------------------------------------------------
27  service/service/java/source/src/org/globus/workspace/service/impls/DestroyFutureTask.java
@@ -30,19 +30,26 @@
30 30
 
31 31
     private final int id;
32 32
     private final WorkspaceHome home;
33  
-
  33
+    private final boolean blockForSuccess;
34 34
 
35 35
     // -------------------------------------------------------------------------
36  
-    // CONSTRUCTOR
  36
+    // CONSTRUCTORS
37 37
     // -------------------------------------------------------------------------
38 38
     
39 39
     public DestroyFutureTask(int vmid,
40 40
                              WorkspaceHome whome) {
  41
+        this(vmid, whome, false);
  42
+    }
  43
+
  44
+    public DestroyFutureTask(int vmid,
  45
+                             WorkspaceHome whome,
  46
+                             boolean blockForSuccess) {
41 47
         this.id = vmid;
42 48
         if (whome == null) {
43 49
             throw new IllegalArgumentException("whome may not be null");
44 50
         }
45 51
         this.home = whome;
  52
+        this.blockForSuccess = blockForSuccess;
46 53
     }
47 54
 
48 55
 
@@ -52,7 +59,7 @@ public DestroyFutureTask(int vmid,
52 59
     
53 60
     public Object call() throws Exception {
54 61
 
55  
-        final InstanceResource resource;
  62
+        InstanceResource resource;
56 63
         try {
57 64
             resource = this.home.find(this.id);
58 65
         } catch (DoesNotExistException e) {
@@ -68,6 +75,18 @@ public Object call() throws Exception {
68 75
 
69 76
         this.home.destroy(this.id);
70 77
 
71  
-        return null;
  78
+        if (!this.blockForSuccess) {
  79
+            return null;
  80
+        }
  81
+
  82
+        // There should also be a higher level timeout
  83
+        while (true) {
  84
+            try {
  85
+                Thread.sleep(1000);
  86
+                resource = this.home.find(this.id);
  87
+            } catch (Exception e) {
  88
+                return null;
  89
+            }
  90
+        }
72 91
     }
73 92
 }
27  service/service/java/source/src/org/globus/workspace/service/impls/WorkspaceHomeImpl.java
@@ -447,39 +447,30 @@ public void destroy(String id)
447 447
         }
448 448
     }
449 449
 
450  
-    /**
451  
-     * Destroy a set of workspaces.  Return a list of errors separated by \n,
452  
-     * including if the workspace was not found, etc.  This does not cut out
453  
-     * early if there is any kind of problem.
454  
-     *
455  
-     * Implemented with multiple threads because the remove procedure is
456  
-     * blocking.
457  
-     *
458  
-     * @param workspaces list of workspace IDs
459  
-     * @param sourceStr string for log msgs, or null
460  
-     * @return string report on what happened
461  
-     */
462  
-    public String destroyMultiple(int[] workspaces,
463  
-                                  String sourceStr) {
  450
+    public String destroyMultiple(int[] workspaces, String sourceStr) {
  451
+        return this.destroyMultiple(workspaces, sourceStr, false);
  452
+    }
  453
+
  454
+    public String destroyMultiple(int[] workspaces, String sourceStr, boolean block) {
464 455
 
465 456
         final FutureTask[] tasks = new FutureTask[workspaces.length];
466 457
         for (int i = 0; i < workspaces.length; i++) {
467 458
             tasks[i] = new FutureTask(
468  
-                            new DestroyFutureTask(workspaces[i], this));
  459
+                            new DestroyFutureTask(workspaces[i], this, block));
469 460
         }
470 461
 
471 462
         for (int i = 0; i < tasks.length; i++) {
472 463
             this.executor.submit(tasks[i]);
473 464
         }
474 465
 
475  
-        final StringBuffer buf = new StringBuffer(tasks.length * 256);
  466
+        final StringBuilder buf = new StringBuilder(tasks.length * 256);
476 467
 
477  
-        // Log any unexpected errors.  Wait two minutes (normal destroy time
  468
+        // Log any unexpected errors.  Wait thirty seconds (normal destroy time
478 469
         // should be a matter of seconds even if there is high congestion).
479 470
         // todo: make timeout configurable
480 471
         for (int i = 0; i < tasks.length; i++) {
481 472
             try {
482  
-                final String msg = (String) tasks[i].get(120L, TimeUnit.SECONDS);
  473
+                final String msg = (String) tasks[i].get(30L, TimeUnit.SECONDS);
483 474
                 if (msg != null) {
484 475
                     buf.append(msg);
485 476
                 }

0 notes on commit d48ff79

Please sign in to comment.
Something went wrong with that request. Please try again.