[Swift-commit] r4810 - trunk/src/org/griphyn/vdl/karajan
hategan at ci.uchicago.edu
hategan at ci.uchicago.edu
Thu Jul 7 20:10:05 CDT 2011
Author: hategan
Date: 2011-07-07 20:10:05 -0500 (Thu, 07 Jul 2011)
New Revision: 4810
Modified:
trunk/src/org/griphyn/vdl/karajan/HangChecker.java
trunk/src/org/griphyn/vdl/karajan/Loader.java
trunk/src/org/griphyn/vdl/karajan/Monitor.java
trunk/src/org/griphyn/vdl/karajan/Pair.java
trunk/src/org/griphyn/vdl/karajan/ScalabilityTest.java
trunk/src/org/griphyn/vdl/karajan/TCCache.java
trunk/src/org/griphyn/vdl/karajan/VDL2ErrorTranslator.java
trunk/src/org/griphyn/vdl/karajan/VDSAdaptiveScheduler.java
trunk/src/org/griphyn/vdl/karajan/WaitingThreadsMonitor.java
Log:
more cleanups/generics
Modified: trunk/src/org/griphyn/vdl/karajan/HangChecker.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/HangChecker.java 2011-07-08 00:16:04 UTC (rev 4809)
+++ trunk/src/org/griphyn/vdl/karajan/HangChecker.java 2011-07-08 01:10:05 UTC (rev 4810)
@@ -20,7 +20,6 @@
import org.globus.cog.karajan.workflow.ExecutionException;
import org.globus.cog.karajan.workflow.events.EventBus;
import org.globus.cog.karajan.workflow.nodes.grid.SchedulerNode;
-import org.griphyn.vdl.karajan.lib.VDLFunction;
public class HangChecker extends TimerTask {
public static final Logger logger = Logger.getLogger(HangChecker.class);
Modified: trunk/src/org/griphyn/vdl/karajan/Loader.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/Loader.java 2011-07-08 00:16:04 UTC (rev 4809)
+++ trunk/src/org/griphyn/vdl/karajan/Loader.java 2011-07-08 01:10:05 UTC (rev 4810)
@@ -18,7 +18,6 @@
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Enumeration;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -191,7 +190,7 @@
stack.setGlobal("swift.home", System.getProperty("swift.home"));
stack.setGlobal("PATH_SEPARATOR", File.separator);
- List arguments = ap.getArguments();
+ List<String> arguments = ap.getArguments();
if (ap.hasValue(ARG_RESUME)) {
arguments.add("-rlog:resume=" + ap.getStringValue(ARG_RESUME));
}
@@ -409,11 +408,9 @@
private static void addCommandLineProperties(VDL2Config config,
ArgumentParser ap) {
- Map desc = VDL2ConfigProperties.getPropertyDescriptions();
- Iterator i = desc.entrySet().iterator();
- while (i.hasNext()) {
- Map.Entry e = (Map.Entry) i.next();
- String name = (String) e.getKey();
+ Map<String, PropInfo> desc = VDL2ConfigProperties.getPropertyDescriptions();
+ for (Map.Entry<String, PropInfo> e : desc.entrySet()) {
+ String name = e.getKey();
if (ap.isPresent(name)) {
String value = ap.getStringValue(name);
logger.debug("setting: " + name + " to: " + value);
@@ -494,12 +491,10 @@
"reports warnings only");
- Map desc = VDL2ConfigProperties.getPropertyDescriptions();
- Iterator i = desc.entrySet().iterator();
- while (i.hasNext()) {
- Map.Entry e = (Map.Entry) i.next();
- PropInfo pi = (PropInfo) e.getValue();
- ap.addOption((String) e.getKey(), pi.desc, pi.validValues,
+ Map<String, PropInfo> desc = VDL2ConfigProperties.getPropertyDescriptions();
+ for (Map.Entry<String, PropInfo> e : desc.entrySet()) {
+ PropInfo pi = e.getValue();
+ ap.addOption(e.getKey(), pi.desc, pi.validValues,
ArgumentParser.OPTIONAL);
}
return ap;
@@ -567,6 +562,8 @@
}
}
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
protected static Appender getAppender(Class cls) {
Logger root = Logger.getRootLogger();
Enumeration e = root.getAllAppenders();
Modified: trunk/src/org/griphyn/vdl/karajan/Monitor.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/Monitor.java 2011-07-08 00:16:04 UTC (rev 4809)
+++ trunk/src/org/griphyn/vdl/karajan/Monitor.java 2011-07-08 01:10:05 UTC (rev 4810)
@@ -51,7 +51,8 @@
private JPanel buttons, display;
private JTable t;
private JButton futures, waiting, tasks;
- private List wr, wt;
+ private List<Future> wr;
+ private List<VariableStack> wt;
private int crtdisp;
public Monitor() {
@@ -93,12 +94,12 @@
t.removeMouseListener(this);
}
crtdisp = VARS;
- ArrayList al = new ArrayList();
- wr = new ArrayList();
+ ArrayList<List<Object>> al = new ArrayList<List<Object>>();
+ wr = new ArrayList<Future>();
Map<DSHandle, Future> map = FutureTracker.get().getMap();
synchronized (map) {
for (Map.Entry<DSHandle, Future> en : map.entrySet()) {
- List entry = new ArrayList();
+ List<Object> entry = new ArrayList<Object>();
Future f = en.getValue();
DSHandle handle = en.getKey();
String value = "-";
@@ -164,12 +165,10 @@
t.removeMouseListener(this);
}
crtdisp = THREADS;
- ArrayList al = new ArrayList();
- wt = new ArrayList();
- Collection c = WaitingThreadsMonitor.getAllThreads();
- Iterator i = c.iterator();
- while (i.hasNext()) {
- VariableStack stack = (VariableStack) i.next();
+ ArrayList<String> al = new ArrayList<String>();
+ wt = new ArrayList<VariableStack>();
+ Collection<VariableStack> c = WaitingThreadsMonitor.getAllThreads();
+ for (VariableStack stack : c) {
try {
al.add(String.valueOf(ThreadingContext.get(stack)));
}
@@ -229,10 +228,8 @@
public static void dumpThreads(PrintStream pw) {
pw.println("\nWaiting threads:");
- Collection c = WaitingThreadsMonitor.getAllThreads();
- Iterator i = c.iterator();
- while (i.hasNext()) {
- VariableStack stack = (VariableStack) i.next();
+ Collection<VariableStack> c = WaitingThreadsMonitor.getAllThreads();
+ for (VariableStack stack : c) {
try {
pw.println(String.valueOf(ThreadingContext.get(stack)));
}
@@ -244,16 +241,14 @@
}
public class VariableModel extends AbstractTableModel {
- private List l;
+ private List<Object[]> l;
- public VariableModel(List lp) {
- l = new ArrayList();
- Iterator i = lp.iterator();
+ public VariableModel(List<List<Object>> lp) {
+ l = new ArrayList<Object[]>();
+ Iterator<List<Object>> i = lp.iterator();
while (i.hasNext()) {
- List s = (List) i.next();
- Iterator j = s.iterator();
- Object[] e = new Object[6];
- e = s.toArray();
+ List<Object> s = i.next();
+ Object[] e = s.toArray();
l.add(e);
}
}
@@ -268,7 +263,7 @@
public Object getValueAt(int rowIndex, int columnIndex) {
if (columnIndex < 6) {
- return ((Object[]) l.get(rowIndex))[columnIndex];
+ return l.get(rowIndex)[columnIndex];
}
else {
EventTargetPair[] l = Monitor.this.getListeners(rowIndex);
@@ -313,9 +308,9 @@
}
public static class ThreadModel extends AbstractTableModel {
- private List l;
+ private List<String> l;
- public ThreadModel(List lp) {
+ public ThreadModel(List<String> lp) {
l = lp;
}
Modified: trunk/src/org/griphyn/vdl/karajan/Pair.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/Pair.java 2011-07-08 00:16:04 UTC (rev 4809)
+++ trunk/src/org/griphyn/vdl/karajan/Pair.java 2011-07-08 01:10:05 UTC (rev 4810)
@@ -5,7 +5,7 @@
import java.util.AbstractList;
-public class Pair extends AbstractList {
+public class Pair extends AbstractList<Object> {
private Object[] elements = new Object[2];
public Pair(Object o1, Object o2) {
Modified: trunk/src/org/griphyn/vdl/karajan/ScalabilityTest.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/ScalabilityTest.java 2011-07-08 00:16:04 UTC (rev 4809)
+++ trunk/src/org/griphyn/vdl/karajan/ScalabilityTest.java 2011-07-08 01:10:05 UTC (rev 4810)
@@ -42,7 +42,7 @@
ElementTree tree = Loader.load("scalability.k");
ExecutionContext ec = new ExecutionContext(tree);
ec.setStdout(new Stdout());
- List l = new LinkedList();
+ List<String> l = new LinkedList<String>();
l.add(args[1]);
l.add(args[2]);
ec.setArguments(l);
Modified: trunk/src/org/griphyn/vdl/karajan/TCCache.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/TCCache.java 2011-07-08 00:16:04 UTC (rev 4809)
+++ trunk/src/org/griphyn/vdl/karajan/TCCache.java 2011-07-08 01:10:05 UTC (rev 4810)
@@ -7,24 +7,25 @@
import java.util.List;
import java.util.Map;
+import org.globus.swift.catalog.TCEntry;
import org.globus.swift.catalog.TransformationCatalog;
import org.globus.swift.catalog.types.TCType;
import org.griphyn.vdl.util.FQN;
public class TCCache {
private TransformationCatalog tc;
- private Map<Entry, List> cache;
+ private Map<Entry, List<TCEntry>> cache;
private Entry entry;
public TCCache(TransformationCatalog tc) {
this.tc = tc;
- cache = new HashMap<Entry, List>();
+ cache = new HashMap<Entry, List<TCEntry>>();
entry = new Entry();
}
- public synchronized List getTCEntries(FQN tr, String host, TCType tctype) throws Exception {
+ public synchronized List<TCEntry> getTCEntries(FQN tr, String host, TCType tctype) throws Exception {
entry.set(tr, host, tctype);
- List l = cache.get(entry);
+ List<TCEntry> l = cache.get(entry);
if (l == null && !cache.containsKey(entry)) {
l = tc.getTCEntries(tr.getNamespace(), tr.getName(), tr.getVersion(), host, tctype);
cache.put(new Entry(tr, host, tctype), l);
Modified: trunk/src/org/griphyn/vdl/karajan/VDL2ErrorTranslator.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/VDL2ErrorTranslator.java 2011-07-08 00:16:04 UTC (rev 4809)
+++ trunk/src/org/griphyn/vdl/karajan/VDL2ErrorTranslator.java 2011-07-08 01:10:05 UTC (rev 4810)
@@ -14,7 +14,6 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -38,11 +37,11 @@
return translator;
}
- private List entries;
+ private List<Entry> entries;
public void load() {
try {
- entries = new ArrayList();
+ entries = new ArrayList<Entry>();
InputStream is = VDL2ErrorTranslator.class.getClassLoader().getResourceAsStream(
"error.properties");
if (is == null) {
@@ -80,9 +79,7 @@
}
public String translate(String org) {
- Iterator i = entries.iterator();
- while (i.hasNext()) {
- Entry e = (Entry) i.next();
+ for (Entry e : entries) {
Matcher m = e.pattern.matcher(org);
if (m.matches()) {
return replace(m, e.replacement);
@@ -91,18 +88,17 @@
return null;
}
- private String replace(Matcher m, ArrayList replacement) {
- Iterator i = replacement.iterator();
+ private String replace(Matcher m, List<Replacement> replacement) {
StringBuffer sb = new StringBuffer();
- while (i.hasNext()) {
- sb.append(((Replacement) i.next()).get(m));
+ for (Replacement r : replacement) {
+ sb.append(r.get(m));
}
return sb.toString();
}
public static class Entry {
public Pattern pattern;
- public ArrayList replacement;
+ public ArrayList<Replacement> replacement;
public Entry(Pattern pattern, String replacement) {
this.pattern = pattern;
@@ -110,7 +106,7 @@
}
private void buildReplacement(String r) {
- replacement = new ArrayList();
+ replacement = new ArrayList<Replacement>();
int last = 0;
int index = 0;
while (true) {
Modified: trunk/src/org/griphyn/vdl/karajan/VDSAdaptiveScheduler.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/VDSAdaptiveScheduler.java 2011-07-08 00:16:04 UTC (rev 4809)
+++ trunk/src/org/griphyn/vdl/karajan/VDSAdaptiveScheduler.java 2011-07-08 01:10:05 UTC (rev 4810)
@@ -14,9 +14,11 @@
import org.apache.log4j.Logger;
import org.globus.cog.abstraction.impl.common.IdentityImpl;
import org.globus.cog.abstraction.impl.common.StatusEvent;
+import org.globus.cog.abstraction.impl.common.StatusImpl;
import org.globus.cog.abstraction.impl.common.task.JobSpecificationImpl;
import org.globus.cog.abstraction.impl.common.task.TaskImpl;
import org.globus.cog.abstraction.interfaces.JobSpecification;
+import org.globus.cog.abstraction.interfaces.Status;
import org.globus.cog.abstraction.interfaces.Task;
import org.globus.cog.karajan.scheduler.AbstractScheduler;
import org.globus.cog.karajan.scheduler.ResourceConstraintChecker;
@@ -25,12 +27,10 @@
import org.globus.cog.karajan.util.BoundContact;
import org.globus.cog.karajan.util.Contact;
import org.globus.cog.karajan.util.TypeUtil;
-import org.griphyn.vdl.util.FQN;
-
-import org.globus.cog.abstraction.impl.common.StatusImpl;
-import org.globus.cog.abstraction.interfaces.Status;
+import org.globus.swift.catalog.TCEntry;
import org.globus.swift.catalog.transformation.File;
import org.globus.swift.catalog.types.TCType;
+import org.griphyn.vdl.util.FQN;
public class VDSAdaptiveScheduler extends WeightedHostScoreScheduler {
@@ -39,16 +39,16 @@
private static Timer timer;
private TCCache tc;
- private LinkedList dq;
+ private LinkedList<Object[]> dq;
private int clusteringQueueDelay = 1;
private int minClusterTime = 60;
- private Map tasks;
+ private Map<Task, List<Object[]>> tasks;
private boolean clusteringEnabled;
private int clusterId;
public VDSAdaptiveScheduler() {
- dq = new LinkedList();
- tasks = new HashMap();
+ dq = new LinkedList<Object[]>();
+ tasks = new HashMap<Task, List<Object[]>>();
}
public static final String PROP_TC_FILE = "transformationCatalogFile";
@@ -163,15 +163,15 @@
synchronized (dq) {
while (!dq.isEmpty()) {
int clusterTime = 0;
- LinkedList cluster = new LinkedList();
- Map env = new HashMap();
- Map attrs = new HashMap();
+ LinkedList<Object[]> cluster = new LinkedList<Object[]>();
+ Map<String, String> env = new HashMap<String, String>();
+ Map<String, Object> attrs = new HashMap<String, Object>();
Object constraints = null;
String dir = null;
- Iterator dqi = dq.iterator();
+ Iterator<Object[]> dqi = dq.iterator();
while (clusterTime < minClusterTime && dqi.hasNext()) {
- Object[] h = (Object[]) dqi.next();
+ Object[] h = dqi.next();
Task task = (Task) h[0];
JobSpecification js = (JobSpecification) task.getSpecification();
@@ -212,7 +212,7 @@
continue;
}
else if (cluster.size() == 1) {
- Object[] h = (Object[]) cluster.removeFirst();
+ Object[] h = cluster.removeFirst();
super.enqueue((Task) h[0], h[1]);
}
else if (cluster.size() > 1) {
@@ -235,19 +235,15 @@
logger.info("Creating cluster " + t.getIdentity() + " with size " + cluster.size());
}
- Iterator i = cluster.iterator();
- while (i.hasNext()) {
- Object[] h = (Object[]) i.next();
+ for (Object[] h : cluster) {
Task st = (Task) h[0];
if (logger.isInfoEnabled()) {
logger.info("Task " + st.getIdentity() + " clustered in " + t.getIdentity());
}
JobSpecification sjs = (JobSpecification) st.getSpecification();
js.addArgument(sjs.getExecutable());
- List args = sjs.getArgumentsAsList();
- Iterator j = args.iterator();
- while (j.hasNext()) {
- String arg = (String) j.next();
+ List<String> args = sjs.getArgumentsAsList();
+ for (String arg : args) {
if (arg.equals("|")) {
arg = "||";
}
@@ -255,17 +251,13 @@
}
js.addArgument("|");
}
-
- i = env.entrySet().iterator();
- while (i.hasNext()) {
- Map.Entry e = (Map.Entry) i.next();
- js.addEnvironmentVariable((String) e.getKey(), (String) e.getValue());
+
+ for (Map.Entry<String, String> e : env.entrySet()) {
+ js.addEnvironmentVariable(e.getKey(), e.getValue());
}
- i = attrs.entrySet().iterator();
- while (i.hasNext()) {
- Map.Entry e = (Map.Entry) i.next();
- js.setAttribute((String) e.getKey(), (String) e.getValue());
+ for (Map.Entry<String, Object> e : attrs.entrySet()) {
+ js.setAttribute(e.getKey(), e.getValue());
}
synchronized (tasks) {
@@ -277,14 +269,12 @@
}
}
- private boolean detectConflict(JobSpecification js, Map env, Map attrs) {
+ private boolean detectConflict(JobSpecification js, Map<String, String> env, Map<String, Object> attrs) {
return detectEnvironmentConflict(js, env) || detectAttributeConflict(js, attrs);
}
- private boolean detectEnvironmentConflict(JobSpecification js, Map env) {
- Iterator i = js.getEnvironmentVariableNames().iterator();
- while (i.hasNext()) {
- String envName = (String) i.next();
+ private boolean detectEnvironmentConflict(JobSpecification js, Map<String, String> env) {
+ for (String envName : js.getEnvironmentVariableNames()) {
Object value = env.get(envName);
if (value != null && !value.equals(js.getEnvironmentVariable(envName))) {
return true;
@@ -293,10 +283,8 @@
return false;
}
- private boolean detectAttributeConflict(JobSpecification js, Map attrs) {
- Iterator ia = js.getAttributeNames().iterator();
- while (ia.hasNext()) {
- String attrName = (String) ia.next();
+ private boolean detectAttributeConflict(JobSpecification js, Map<String, Object> attrs) {
+ for (String attrName : js.getAttributeNames()) {
if (attrName.equals("maxwalltime")) {
continue;
}
@@ -308,25 +296,22 @@
return false;
}
- private void merge(JobSpecification js, Map env, Map attrs) {
+ private void merge(JobSpecification js, Map<String, String> env, Map<String, Object> attrs) {
mergeEnvironment(js, env);
mergeAttributes(js, attrs);
}
- private void mergeEnvironment(JobSpecification js, Map env) {
- Iterator i = js.getEnvironmentVariableNames().iterator();
- while (i.hasNext()) {
- String envName = (String) i.next();
+ private void mergeEnvironment(JobSpecification js, Map<String, String> env) {
+ for (String envName : js.getEnvironmentVariableNames()) {
env.put(envName, js.getEnvironmentVariable(envName));
}
}
- private void mergeAttributes(JobSpecification js, Map attrs) {
- Iterator i = js.getAttributeNames().iterator();
- while (i.hasNext()) {
- String attrName = (String) i.next();
- if (attrName.equals("maxwalltime"))
+ private void mergeAttributes(JobSpecification js, Map<String, Object> attrs) {
+ for (String attrName : js.getAttributeNames()) {
+ if (attrName.equals("maxwalltime")) {
continue;
+ }
attrs.put(attrName, js.getAttribute(attrName));
}
}
@@ -378,14 +363,12 @@
if (logger.isDebugEnabled()) {
logger.debug("Failing task " + t.getIdentity());
}
- LinkedList cluster = null;
+ List<Object[]> cluster = null;
synchronized (tasks) {
- cluster = (LinkedList) tasks.get(t);
+ cluster = tasks.get(t);
}
if (cluster != null) {
- Iterator i = cluster.iterator();
- while (i.hasNext()) {
- Object[] h = (Object[]) i.next();
+ for (Object[] h : cluster) {
super.failTask((Task) h[0], message, e);
}
}
@@ -401,9 +384,9 @@
if (logger.isDebugEnabled()) {
logger.debug("Got task status change for " + t.getIdentity());
}
- LinkedList cluster = null;
+ List<Object[]> cluster = null;
synchronized (tasks) {
- cluster = (LinkedList) tasks.get(t);
+ cluster = tasks.get(t);
}
if (cluster == null) {
@@ -418,9 +401,7 @@
if(clusterMemberStatus.getStatusCode() == Status.FAILED) {
clusterMemberStatus = new StatusImpl(Status.COMPLETED);
}
- Iterator i = cluster.iterator();
- while (i.hasNext()) {
- Object[] h = (Object[]) i.next();
+ for (Object[] h : cluster) {
Task ct = (Task) h[0];
StatusEvent nse = new StatusEvent(ct, clusterMemberStatus);
ct.setStatus(clusterMemberStatus);
@@ -452,7 +433,7 @@
if (isPresent("trfqn", tc)) {
FQN tr = (FQN) tc.getConstraint("trfqn");
try {
- List l = this.tc.getTCEntries(tr, resource.getHost(), TCType.INSTALLED);
+ List<TCEntry> l = this.tc.getTCEntries(tr, resource.getHost(), TCType.INSTALLED);
if (l == null || l.isEmpty()) {
return false;
}
Modified: trunk/src/org/griphyn/vdl/karajan/WaitingThreadsMonitor.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/WaitingThreadsMonitor.java 2011-07-08 00:16:04 UTC (rev 4809)
+++ trunk/src/org/griphyn/vdl/karajan/WaitingThreadsMonitor.java 2011-07-08 01:10:05 UTC (rev 4810)
@@ -11,7 +11,7 @@
import org.globus.cog.karajan.stack.VariableStack;
public class WaitingThreadsMonitor {
- private static Set threads;
+ private static Set<VariableStack> threads;
public synchronized static void addThread(VariableStack stack) {
if (stack != null) {
@@ -19,9 +19,9 @@
}
}
- private static synchronized Set getThreads() {
+ private static synchronized Set<VariableStack> getThreads() {
if (threads == null) {
- threads = new HashSet();
+ threads = new HashSet<VariableStack>();
}
return threads;
}
@@ -30,12 +30,12 @@
getThreads().remove(stack);
}
- public synchronized static Collection getAllThreads() {
+ public synchronized static Collection<VariableStack> getAllThreads() {
if (threads == null) {
- return Collections.EMPTY_SET;
+ return Collections.emptySet();
}
else {
- return new HashSet(threads);
+ return new HashSet<VariableStack>(threads);
}
}
}
More information about the Swift-commit
mailing list