package org.apache.hadoop.tools.posum.common.util;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.tools.posum.scheduler.portfolio.DataOrientedPolicy;
import org.apache.hadoop.tools.posum.scheduler.portfolio.EDLSPriorityPolicy;
import org.apache.hadoop.tools.posum.scheduler.portfolio.EDLSSharePolicy;
import org.apache.hadoop.tools.posum.scheduler.portfolio.FifoPolicy;
import org.apache.hadoop.tools.posum.scheduler.portfolio.LocalityFirstPolicy;
import org.apache.hadoop.tools.posum.scheduler.portfolio.PluginPolicy;
import org.apache.hadoop.tools.posum.scheduler.portfolio.ShortestRTFirstPolicy;

import java.util.HashMap;

public class PolicyPortfolio extends HashMap<String, Class<? extends PluginPolicy>> {

  public enum StandardPolicy {
    FIFO(FifoPolicy.class),
    EDLS_SH(EDLSSharePolicy.class),
    EDLS_PR(EDLSPriorityPolicy.class),
    LOCF(LocalityFirstPolicy.class);//,
    //SRTF(ShortestRTFirstPolicy.class);

    Class<? extends PluginPolicy> implClass;

    StandardPolicy(Class<? extends PluginPolicy> implClass) {
      this.implClass = implClass;
    }
  }

  private String defaultPolicyName;

  public PolicyPortfolio() {

  }

  public PolicyPortfolio(Configuration conf) {
    super(StandardPolicy.values().length);
    String policyMap = conf.get(PosumConfiguration.SCHEDULER_POLICY_MAP);
    if (policyMap != null) {
      try {
        for (String entry : policyMap.split(",")) {
          String[] entryParts = entry.split("=");
          if (entryParts.length != 2) {
            Class<? extends PluginPolicy> implClass =
              conf.getClass(entryParts[1], null, PluginPolicy.class);
            if (implClass != null)
              put(entryParts[0], implClass);
            else
              throw new PosumException("Invalid policy class " + entryParts[1]);
          }
        }
      } catch (Exception e) {
        throw new PosumException("Could not parse policy map");
      }
    } else {
      for (StandardPolicy policy : StandardPolicy.values()) {
        put(policy.name(), policy.implClass);
      }
    }
    defaultPolicyName = conf.get(PosumConfiguration.DEFAULT_POLICY, PosumConfiguration.DEFAULT_POLICY_DEFAULT);
    if (get(defaultPolicyName) == null) {
      throw new PosumException("Invalid policy portfolio configuration. No default policy implementation");
    }
  }

  public String getDefaultPolicyName() {
    return defaultPolicyName;
  }
}

@@ -67,110 +67,118 @@
 che.
-hadoop.conf.Configuration;%0Aimport org.apache.hadoop.tools.posum.scheduler.portfolio.DataOrientedPolicy
+commons.logging.Log;%0Aimport org.apache.commons.logging.LogFactory;%0Aimport org.apache.hadoop.conf.Configuration
 ;%0Aim
@@ -737,16 +737,88 @@
 licy%3E%3E %7B
+%0A  private static Log logger = LogFactory.getLog(PolicyPortfolio.class);
 %0A%0A  publ
@@ -1596,18 +1596,16 @@
 th != 2)
- %7B
 %0A       
@@ -1613,281 +1613,118 @@
     
-Class%3C? extends PluginPolicy%3E implClass =%0A              conf.getClass(entryParts%5B1%5D, null, PluginPolicy.class);%0A            if (implClass != null)%0A              put(entryParts%5B0%5D, implClass);%0A            else%0A              throw new PosumException(%22Invalid policy class %22 +
+throw new PosumException(%22Invalid policy entry %22 + entry);%0A          put(entryParts%5B0%5D, resolveImplClass(conf,
  ent
@@ -1738,22 +1738,11 @@
 %5B1%5D)
+)
 ;%0A
-          %7D%0A
     
@@ -2242,24 +2242,24 @@
 entation%22);%0A
-
     %7D%0A  %7D%0A%0A 
@@ -2253,24 +2253,379 @@
 %0A    %7D%0A  %7D%0A%0A
+  private Class%3C? extends PluginPolicy%3E resolveImplClass(Configuration conf, String name) throws ClassNotFoundException %7B%0A    Class%3C?%3E theClass = conf.getClassByName(name);%0A    if (!PluginPolicy.class.isAssignableFrom(theClass))%0A      throw new PosumException(theClass + %22 is not a PluginPolicy%22);%0A    return theClass.asSubclass(PluginPolicy.class);%0A  %7D%0A%0A
   public Str

fix for explicit policy map