Permalink
Browse files

-Added getResourcePoolEntryImproved which is an improved version of g…

…etResourcepoolEntry that moves some processing down to SQL

-Related modifications
(cherry picked from commit 3189e9bce71b9ce3883700a50ed9b57eba1bfd8c)
  • Loading branch information...
1 parent e4b37fd commit 47d74c8471149b2898baa4aba2300bf19ffb6195 @pauloricardomg pauloricardomg committed with timf Jun 3, 2010
@@ -165,13 +165,17 @@ resourcepool VARCHAR(128) NOT NULL PRIMARY KEY,
file_time BIGINT NOT NULL
);
+-- using REAL for memory attributs to allow
+-- real division operations in ORDER BY statements
+
CREATE TABLE resourcepool_entries
(
resourcepool VARCHAR(128) NOT NULL,
hostname VARCHAR(128) NOT NULL,
associations VARCHAR(512) NOT NULL,
-maximum_memory INT,
-available_memory INT
+maximum_memory REAL,
+available_memory REAL,
+PRIMARY KEY(resourcepool, hostname)
);
--
@@ -16,17 +16,18 @@
package org.globus.workspace.persistence;
+import java.util.Calendar;
+import java.util.Hashtable;
+import java.util.List;
+
import org.globus.workspace.network.AssociationEntry;
import org.globus.workspace.scheduler.defaults.ResourcepoolEntry;
-import org.globus.workspace.service.InstanceResource;
-import org.globus.workspace.service.GroupResource;
import org.globus.workspace.service.CoschedResource;
+import org.globus.workspace.service.GroupResource;
+import org.globus.workspace.service.InstanceResource;
import org.globus.workspace.service.binding.vm.CustomizationNeed;
import org.nimbustools.api.services.rm.DoesNotExistException;
-import java.util.Calendar;
-import java.util.Hashtable;
-
/**
* TODO: each module implementation needs to encapsulate its own persistence,
* the persistence package will go away entirely
@@ -153,8 +154,7 @@ public void replaceResourcepools(Hashtable resourcepools)
throws WorkspaceDatabaseException;
- public void replaceResourcepoolEntry(String name,
- ResourcepoolEntry entry)
+ public void replaceResourcepoolEntry(ResourcepoolEntry entry)
throws WorkspaceDatabaseException;
@@ -189,5 +189,11 @@ public void updatePropagationCounter(int n)
public void updateCursorPosition(long currentPosition)
throws WorkspaceDatabaseException;
+
+ //SQL processing
+
+ public List<ResourcepoolEntry> getAvailableEntriesSortedByFreeMemoryPercentage(int requestedMem)
+
+ throws WorkspaceDatabaseException;
}
@@ -177,6 +177,9 @@
public static final String SQL_SELECT_ALL_VMS_BY_OWNER =
"SELECT id FROM resources WHERE creator_dn=?";
+
+ public static final String SQL_SELECT_AVAILABLE_ENTRIES =
+ "SELECT * FROM resourcepool_entries WHERE available_memory >= ? ORDER BY (available_memory/maximum_memory) ASC";
public static final String[] PREPARED_STATEMENTS = {
SQL_SELECT_RESOURCES,
@@ -221,5 +224,6 @@
SQL_JOIN_SELECT_RESOURCE_POOL_MEMORY,
SQL_SELECT_ALL_VMS_IN_GROUP,
SQL_SELECT_ALL_VMS_IN_ENSEMBLE,
- SQL_SELECT_ALL_VMS_BY_OWNER};
+ SQL_SELECT_ALL_VMS_BY_OWNER,
+ SQL_SELECT_AVAILABLE_ENTRIES};
}
@@ -16,10 +16,23 @@
package org.globus.workspace.persistence;
+import java.io.IOException;
+import java.sql.Blob;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Hashtable;
+import java.util.List;
+
+import javax.sql.DataSource;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.nimbustools.api.services.rm.DoesNotExistException;
-import org.nimbustools.api.services.rm.ManageException;
import org.globus.workspace.Lager;
import org.globus.workspace.WorkspaceConstants;
import org.globus.workspace.network.Association;
@@ -30,25 +43,14 @@
import org.globus.workspace.persistence.impls.VirtualMachinePersistenceUtil;
import org.globus.workspace.scheduler.defaults.Resourcepool;
import org.globus.workspace.scheduler.defaults.ResourcepoolEntry;
-import org.globus.workspace.service.InstanceResource;
import org.globus.workspace.service.CoschedResource;
import org.globus.workspace.service.GroupResource;
+import org.globus.workspace.service.InstanceResource;
import org.globus.workspace.service.binding.vm.CustomizationNeed;
import org.globus.workspace.service.binding.vm.VirtualMachine;
import org.globus.workspace.service.binding.vm.VirtualMachinePartition;
-
-import javax.sql.DataSource;
-import java.io.IOException;
-import java.sql.Blob;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.sql.Types;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Hashtable;
+import org.nimbustools.api.services.rm.DoesNotExistException;
+import org.nimbustools.api.services.rm.ManageException;
public class PersistenceAdapterImpl implements WorkspaceConstants,
PersistenceAdapterConstants,
@@ -1879,7 +1881,7 @@ public void replaceResourcepools(Hashtable pools)
* @param name name
* @param entry pool entry
*/
- public void replaceResourcepoolEntry(String name, ResourcepoolEntry entry)
+ public void replaceResourcepoolEntry(ResourcepoolEntry entry)
throws WorkspaceDatabaseException {
if (this.dbTrace) {
@@ -1891,12 +1893,13 @@ public void replaceResourcepoolEntry(String name, ResourcepoolEntry entry)
try {
c = getConnection();
pstmt = ResourcepoolPersistenceUtil.
- updateAvailableMemory(name, entry, c);
+ updateAvailableMemory(entry.getResourcePool(), entry, c);
final int updated = pstmt.executeUpdate();
- if (updated == 0) {
+ if(updated == 1){
+ this.resourcepools = null; //clean cache
+ } else {
throw new WorkspaceDatabaseException("expected row update");
}
-
} catch(SQLException e) {
logger.error("",e);
throw new WorkspaceDatabaseException(e);
@@ -1972,7 +1975,8 @@ public synchronized Hashtable currentResourcepools(boolean cachedIsFine)
continue;
}
ResourcepoolEntry entry =
- new ResourcepoolEntry(hostname,
+ new ResourcepoolEntry(name,
+ hostname,
rs2.getInt(4),
rs2.getInt(5),
assocs);
@@ -1990,10 +1994,11 @@ public synchronized Hashtable currentResourcepools(boolean cachedIsFine)
} while (rs.next());
- rs = null;
- rs2 = null;
- pstmt = null;
- pstmt2 = null;
+ // rs = null;
+ // rs2 = null;
+ // pstmt = null;
+ // pstmt2 = null;
+ // is that needed? (in finally they're closed)
this.resourcepools = pools;
@@ -2285,5 +2290,72 @@ private int readCounter(int n, String prepd)
}
}
}
+
+ @Override
+ public List<ResourcepoolEntry> getAvailableEntriesSortedByFreeMemoryPercentage(int requestedMem) throws WorkspaceDatabaseException{
+
+ Connection c = null;
+ PreparedStatement pstmt = null;
+ ResultSet rs = null;
+
+ ArrayList<ResourcepoolEntry> entries = new ArrayList<ResourcepoolEntry>();
+
+ try {
+ c = getConnection();
+ pstmt = c.prepareStatement(SQL_SELECT_AVAILABLE_ENTRIES);
+ pstmt.setInt(1, requestedMem);
+ rs = pstmt.executeQuery();
+
+ if (rs == null || !rs.next()) {
+ if (lager.traceLog) {
+ logger.debug("no available resource pool entries");
+ }
+ } else do {
+ // rs was next'd above already
+ String name = rs.getString(1);
+ String hostname = rs.getString(2);
+ String assocs = rs.getString(3);
+
+ if (hostname == null) {
+ logger.error("hostname cannot be null for resource pool entry");
+ continue;
+ }
+
+ if (assocs == null) {
+ logger.error("assocs cannot be null for resource pool entry");
+ continue;
+ }
+
+ ResourcepoolEntry entry =
+ new ResourcepoolEntry(name,
+ hostname,
+ rs.getInt(4),
+ rs.getInt(5),
+ assocs);
+ entries.add(entry);
+
+ } while (rs.next());
+
+ return entries;
+
+ } catch(SQLException e) {
+ logger.error("",e);
+ throw new WorkspaceDatabaseException(e);
+ } finally {
+ try {
+ if (pstmt != null) {
+ pstmt.close();
+ }
+ if (rs != null) {
+ rs.close();
+ }
+ if (c != null) {
+ returnConnection(c);
+ }
+ } catch (SQLException sql) {
+ logger.error("SQLException in finally cleanup", sql);
+ }
+ }
+ }
}
@@ -304,9 +304,8 @@ public synchronized Reservation reserveCoscheduledSpace(
for (int i = 0; i < vmids.length; i++) {
- // no distinction between resource pools yet, use "any" (null)
try {
- nodes[i] = ResourcepoolUtil.getResourcepoolEntry(memory,
+ nodes[i] = ResourcepoolUtil.getResourcePoolEntryImproved(memory,
assocs,
this.db,
this.lager,
@@ -18,13 +18,15 @@
public class ResourcepoolEntry {
+ private String resourcePool;
private String hostname;
private int memMax = -1; // in MBytes
private int memCurrent = -1; // in MBytes
private String supportedAssociations;
- public ResourcepoolEntry(String hostname, int memMax,
+ public ResourcepoolEntry(String resourcePool, String hostname, int memMax,
int memCurrent, String sa) {
+ this.resourcePool = resourcePool;
this.hostname = hostname;
this.memMax = memMax;
this.memCurrent = memCurrent;
@@ -91,8 +93,17 @@ public String toString() {
"hostname='" + this.hostname + '\'' +
", memMax=" + this.memMax +
", memCurrent=" + this.memCurrent +
- ", supportedNetworks='" + this.supportedAssociations + '\'' +
+ ", supportedNetworks='" + this.supportedAssociations +
+ ", percentEmpty= " + this.percentEmpty() + '\'' +
'}';
}
+ public void setResourcePool(String resourcePool) {
+ this.resourcePool = resourcePool;
+ }
+
+ public String getResourcePool() {
+ return resourcePool;
+ }
+
}
Oops, something went wrong.

0 comments on commit 47d74c8

Please sign in to comment.