Skip to content
Browse files

Clean up a few Async persistance things

  • Loading branch information...
1 parent 51314ad commit ed37db2514b07ded713d3e1b773d3aa875fcd7e2 @oldpatricka oldpatricka committed Jun 22, 2011
View
2 service/service/java/source/src/org/globus/workspace/async/AsyncRequestManagerImpl.java
@@ -907,8 +907,8 @@ protected void allocate(AsyncRequest request, Integer quantity) {
chargeRatio);
for (InstanceResource resource : createdVMs) {
request.addAllocatedVM(resource.getID());
- this.asyncRequestMap.addOrReplace(request);
}
+ this.asyncRequestMap.addOrReplace(request);
} catch (Exception e) {
failRequest("allocating", request, e.getMessage(), e);
return;
View
30 service/service/java/source/src/org/globus/workspace/persistence/PersistenceAdapterImpl.java
@@ -37,7 +37,6 @@
import org.globus.workspace.Lager;
import org.globus.workspace.WorkspaceConstants;
import org.globus.workspace.async.AsyncRequest;
-import org.globus.workspace.async.AsyncRequestMap;
import org.globus.workspace.creation.IdempotentInstance;
import org.globus.workspace.creation.IdempotentReservation;
import org.globus.workspace.creation.defaults.IdempotentInstanceImpl;
@@ -57,10 +56,8 @@
import org.nimbustools.api.repr.CannotTranslateException;
import org.nimbustools.api.repr.ReprFactory;
import org.nimbustools.api.repr.SpotPriceEntry;
-import org.nimbustools.api.repr.vm.NIC;
import org.nimbustools.api.services.rm.DoesNotExistException;
import org.nimbustools.api.services.rm.ManageException;
-import org.springframework.scheduling.annotation.Async;
public class PersistenceAdapterImpl implements WorkspaceConstants,
PersistenceAdapterConstants,
@@ -3238,39 +3235,34 @@ public void addAsyncRequest(AsyncRequest asyncRequest)
AsyncRequest oldAsyncRequest = getAsyncRequest(asyncRequest.getId());
+
if (oldAsyncRequest != null) {
logger.debug("Updating old request " + oldAsyncRequest.getId());
- pstmt = AsyncRequestMapPersistenceUtil.getUpdateAsyncRequest(asyncRequest, this.repr, c);
- pstmt.executeUpdate();
- pstmt.close();
-
-
// We will later need to persist modified versions of our persisted VMs,
// so we need to remove all of our earlier copies
- pstmts = AsyncRequestMapPersistenceUtil.getRemoveAsyncVMs(asyncRequest, c);
+ pstmts = AsyncRequestMapPersistenceUtil.getRemoveAsyncBindings(oldAsyncRequest, c);
for (PreparedStatement p : pstmts) {
p.executeUpdate();
}
+ AsyncRequestMapPersistenceUtil.removeAllocatedVMs(oldAsyncRequest, c);
+ AsyncRequestMapPersistenceUtil.removeFinishedVMs(oldAsyncRequest, c);
+ AsyncRequestMapPersistenceUtil.removeToBePreempted(oldAsyncRequest, c);
- pstmt = AsyncRequestMapPersistenceUtil.getDeleteAsyncRequestVMs(asyncRequest, c);
+
+ pstmt = AsyncRequestMapPersistenceUtil.getUpdateAsyncRequest(asyncRequest, this.repr, c);
pstmt.executeUpdate();
- AsyncRequestMapPersistenceUtil.removeAllocatedVMs(asyncRequest, c);
- AsyncRequestMapPersistenceUtil.removeFinishedVMs(asyncRequest, c);
- AsyncRequestMapPersistenceUtil.removeToBePreempted(asyncRequest, c);
- AsyncRequestMapPersistenceUtil.putAllocatedVMs(asyncRequest, c);
- AsyncRequestMapPersistenceUtil.putFinishedVMs(asyncRequest, c);
- AsyncRequestMapPersistenceUtil.putToBePreempted(asyncRequest, c);
+ c.commit();
}
else {
logger.debug("Persisting request: " + asyncRequest.getId());
pstmt = AsyncRequestMapPersistenceUtil.getInsertAsyncRequest(asyncRequest, this.repr, c);
pstmt.executeUpdate();
- AsyncRequestMapPersistenceUtil.putAllocatedVMs(asyncRequest, c);
- AsyncRequestMapPersistenceUtil.putFinishedVMs(asyncRequest, c);
- AsyncRequestMapPersistenceUtil.putToBePreempted(asyncRequest, c);
}
+ AsyncRequestMapPersistenceUtil.putAllocatedVMs(asyncRequest, c);
+ AsyncRequestMapPersistenceUtil.putFinishedVMs(asyncRequest, c);
+ AsyncRequestMapPersistenceUtil.putToBePreempted(asyncRequest, c);
AsyncRequestMapPersistenceUtil.putAsyncRequestBindings(asyncRequest, c);
c.commit();
View
9 ...ava/source/src/org/globus/workspace/persistence/impls/AsyncRequestMapPersistenceUtil.java
@@ -257,13 +257,6 @@ public static PreparedStatement getAllAsyncRequests(Connection c)
return pstmt;
}
- public static PreparedStatement getDeleteAsyncRequestVMs(AsyncRequest asyncRequest, Connection c)
- throws SQLException {
-
- final PreparedStatement pstmt = c.prepareStatement(SQL_DELETE_ASYNC_REQUESTS_VMS);
- pstmt.setString(1, asyncRequest.getId());
- return pstmt;
- }
public static AsyncRequest rsToAsyncRequest(ResultSet rs, ReprFactory repr, Connection c)
throws SQLException, CannotTranslateException {
@@ -580,7 +573,7 @@ public static PreparedStatement getInsertAsyncRequestVM(String id, int vmid, Con
return pstmt;
}
- public static PreparedStatement[] getRemoveAsyncVMs(AsyncRequest asyncRequest, Connection c) throws SQLException {
+ public static PreparedStatement[] getRemoveAsyncBindings(AsyncRequest asyncRequest, Connection c) throws SQLException {
PreparedStatement[] pstmts = new PreparedStatement[4];
View
15 ...ests/suites/basic/src/org/globus/workspace/testing/suites/basic/AsyncRequestMapSuite.java
@@ -19,6 +19,7 @@
import org.apache.commons.dbcp.BasicDataSource;
import org.globus.workspace.async.AsyncRequest;
import org.globus.workspace.async.AsyncRequestMap;
+import org.globus.workspace.async.AsyncRequestStatus;
import org.globus.workspace.persistence.DataConvert;
import org.globus.workspace.persistence.PersistenceAdapter;
import org.globus.workspace.service.binding.vm.VirtualMachine;
@@ -136,6 +137,7 @@ public void persistOne() throws Exception {
AsyncRequest testRequest = new AsyncRequest(testID, testSpotinstances, testMaxBid, testIsPersistent, testCaller, testGroupID, testBindings, context, testNICs, testSshKeyName, testCreationTime);
testRequest.addAllocatedVM(testAllocatedVM);
asyncRequestMap.addOrReplace(testRequest);
+ logger.debug("Status: " + testRequest.getStatus());
allRequests = asyncRequestMap.getAll();
assert(allRequests != null);
@@ -156,5 +158,18 @@ public void persistOne() throws Exception {
assertEquals(testVM.getID(), gotRequest.getBindings()[0].getID());
assertEquals(testNICs[0].getIpAddress(), gotRequest.getRequestedNics()[0].getIpAddress());
assertEquals(testAllocatedVM, gotRequest.getAllocatedVMs()[0]);
+ assertEquals(AsyncRequestStatus.OPEN, gotRequest.getStatus());
+
+ gotRequest.setStatus(AsyncRequestStatus.ACTIVE);
+ asyncRequestMap.addOrReplace(gotRequest);
+
+ AsyncRequest updatedRequest = asyncRequestMap.getByID(testID);
+ assertEquals(AsyncRequestStatus.ACTIVE, updatedRequest.getStatus());
+ assertEquals(testAllocatedVM, updatedRequest.getAllocatedVMs()[0]);
+
+ asyncRequestMap.addOrReplace(updatedRequest);
+ AsyncRequest updatedRequest1 = asyncRequestMap.getByID(testID);
+ assertEquals(testAllocatedVM, updatedRequest1.getAllocatedVMs()[0]);
+
}
}

0 comments on commit ed37db2

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