// Path: src/main/java/com/indeed/proctor/webapp/db/Environment.java
// public enum Environment {
//     WORKING("trunk", 0),
//     QA("qa", 1),
//     PRODUCTION("production", 2);
// 
//     private final String name;
//     private final int precedence;
//     private Environment(final String name, final int precedence) {
//         this.name = name;
//         this.precedence = precedence;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public int getPrecedence() {
//         return precedence;
//     }
// 
//     private static final Map<String, Environment> LOOKUP = Maps.uniqueIndex(ImmutableList.copyOf(Environment.values()), Functions.toStringFunction());
//     public static Environment fromName(String name) {
//         if(name == null) {
//             return null;
//         } else {
//             return LOOKUP.get(name.toLowerCase());
//         }
//     }
// 
//     @Override
//     public String toString() {
//         return this.getName();
//     }
// }
// 
// Path: src/main/java/com/indeed/proctor/webapp/util/ThreadPoolExecutorVarExports.java
// public class ThreadPoolExecutorVarExports {
//     public ThreadPoolExecutor executor;
// 
//     public ThreadPoolExecutorVarExports(final ThreadPoolExecutor executor) {
//         this.executor = executor;
//     }
// 
//     @Export(name = "total-task-count")
//     public long getTaskCount() {
//         return executor.getTaskCount();
//     }
// 
//     @Export(name = "completed-task-count")
//     public long getCompletedTaskCount() {
//         return executor.getCompletedTaskCount();
//     }
// 
//     @Export(name = "active-threads")
//     public long getActiveCount() {
//         return executor.getActiveCount();
//     }
// 
//     @Export(name = "pool-size")
//     public long getPoolSize() {
//         return executor.getPoolSize();
//     }
// 
//     @Export(name = "max-pool-size")
//     public long getMaximumPoolSize() {
//         return executor.getMaximumPoolSize();
//     }
// 
//     @Export(name = "queue-remaining-capacity")
//     public int getQueueRemainingCapacity() {
//         return executor.getQueue().remainingCapacity();
//     }
// 
//     @Export(name = "core-pool-size")
//     public long getCorePoolSize() {
//         return executor.getCorePoolSize();
//     }
// 
//     @Export(name = "keep-alive-time")
//     public String getKeepAliveTime() {
//         return executor.getKeepAliveTime(TimeUnit.SECONDS) + " seconds";
//     }
// 
//     @Export(name = "queue-size")
//     public int getQueueSize() {
//         return executor.getQueue().size();
//     }
// 
//     @Export(name = "shutdown")
//     public boolean isShutdown() {
//         return executor.isShutdown();
//     }
// }


import com.google.common.base.CharMatcher;
import com.google.common.base.Strings;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.indeed.proctor.common.model.TestDefinition;
import com.indeed.proctor.common.model.TestMatrixDefinition;
import com.indeed.proctor.store.GitProctorUtils;
import com.indeed.proctor.store.Revision;
import com.indeed.proctor.store.StoreException;
import com.indeed.proctor.webapp.db.Environment;
import com.indeed.proctor.store.ProctorStore;
import com.indeed.proctor.webapp.util.ThreadPoolExecutorVarExports;
import com.indeed.util.varexport.VarExporter;
import org.apache.log4j.Logger;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
package com.indeed.proctor.common;



/**
 * @author parker
 */
public class ProctorPromoter {
    private static final Logger LOGGER = Logger.getLogger(ProctorPromoter.class);
    private static final String UNKNOWN_VERSION = EnvironmentVersion.UNKNOWN_VERSION;

    final ProctorStore trunk;
    final ProctorStore qa;
    final ProctorStore production;
    private ExecutorService executor;

    private final Cache<String, EnvironmentVersion> environmentVersions = CacheBuilder.newBuilder()
        .maximumSize(2048)
        .expireAfterWrite(30, TimeUnit.SECONDS)
        .softValues()
        .build();

    public ProctorPromoter(final ProctorStore trunk,
                           final ProctorStore qa,
                           final ProctorStore production,
                           final ExecutorService executor) {
        this.trunk = trunk;
        this.qa = qa;
        this.production = production;

        if (executor instanceof ThreadPoolExecutor) {
            final VarExporter exporter = VarExporter.forNamespace(getClass().getSimpleName());
// Path: src/main/java/com/indeed/proctor/webapp/db/Environment.java
// public enum Environment {
//     WORKING("trunk", 0),
//     QA("qa", 1),
//     PRODUCTION("production", 2);
// 
//     private final String name;
//     private final int precedence;
//     private Environment(final String name, final int precedence) {
//         this.name = name;
//         this.precedence = precedence;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public int getPrecedence() {
//         return precedence;
//     }
// 
//     private static final Map<String, Environment> LOOKUP = Maps.uniqueIndex(ImmutableList.copyOf(Environment.values()), Functions.toStringFunction());
//     public static Environment fromName(String name) {
//         if(name == null) {
//             return null;
//         } else {
//             return LOOKUP.get(name.toLowerCase());
//         }
//     }
// 
//     @Override
//     public String toString() {
//         return this.getName();
//     }
// }
// 
// Path: src/main/java/com/indeed/proctor/webapp/util/ThreadPoolExecutorVarExports.java
// public class ThreadPoolExecutorVarExports {
//     public ThreadPoolExecutor executor;
// 
//     public ThreadPoolExecutorVarExports(final ThreadPoolExecutor executor) {
//         this.executor = executor;
//     }
// 
//     @Export(name = "total-task-count")
//     public long getTaskCount() {
//         return executor.getTaskCount();
//     }
// 
//     @Export(name = "completed-task-count")
//     public long getCompletedTaskCount() {
//         return executor.getCompletedTaskCount();
//     }
// 
//     @Export(name = "active-threads")
//     public long getActiveCount() {
//         return executor.getActiveCount();
//     }
// 
//     @Export(name = "pool-size")
//     public long getPoolSize() {
//         return executor.getPoolSize();
//     }
// 
//     @Export(name = "max-pool-size")
//     public long getMaximumPoolSize() {
//         return executor.getMaximumPoolSize();
//     }
// 
//     @Export(name = "queue-remaining-capacity")
//     public int getQueueRemainingCapacity() {
//         return executor.getQueue().remainingCapacity();
//     }
// 
//     @Export(name = "core-pool-size")
//     public long getCorePoolSize() {
//         return executor.getCorePoolSize();
//     }
// 
//     @Export(name = "keep-alive-time")
//     public String getKeepAliveTime() {
//         return executor.getKeepAliveTime(TimeUnit.SECONDS) + " seconds";
//     }
// 
//     @Export(name = "queue-size")
//     public int getQueueSize() {
//         return executor.getQueue().size();
//     }
// 
//     @Export(name = "shutdown")
//     public boolean isShutdown() {
//         return executor.isShutdown();
//     }
// }


// Path: src/main/java/com/indeed/proctor/common/ProctorPromoter.java
import com.google.common.base.CharMatcher;
import com.google.common.base.Strings;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.indeed.proctor.common.model.TestDefinition;
import com.indeed.proctor.common.model.TestMatrixDefinition;
import com.indeed.proctor.store.GitProctorUtils;
import com.indeed.proctor.store.Revision;
import com.indeed.proctor.store.StoreException;
import com.indeed.proctor.webapp.db.Environment;
import com.indeed.proctor.store.ProctorStore;
import com.indeed.proctor.webapp.util.ThreadPoolExecutorVarExports;
import com.indeed.util.varexport.VarExporter;
import org.apache.log4j.Logger;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

package com.indeed.proctor.common;



/**
 * @author parker
 */
public class ProctorPromoter {
    private static final Logger LOGGER = Logger.getLogger(ProctorPromoter.class);
    private static final String UNKNOWN_VERSION = EnvironmentVersion.UNKNOWN_VERSION;

    final ProctorStore trunk;
    final ProctorStore qa;
    final ProctorStore production;
    private ExecutorService executor;

    private final Cache<String, EnvironmentVersion> environmentVersions = CacheBuilder.newBuilder()
        .maximumSize(2048)
        .expireAfterWrite(30, TimeUnit.SECONDS)
        .softValues()
        .build();

    public ProctorPromoter(final ProctorStore trunk,
                           final ProctorStore qa,
                           final ProctorStore production,
                           final ExecutorService executor) {
        this.trunk = trunk;
        this.qa = qa;
        this.production = production;

        if (executor instanceof ThreadPoolExecutor) {
            final VarExporter exporter = VarExporter.forNamespace(getClass().getSimpleName());
            exporter.export(new ThreadPoolExecutorVarExports((ThreadPoolExecutor) executor), "ProctorPromoter-pool-");