Example usage for org.apache.commons.configuration BaseConfiguration getString

List of usage examples for org.apache.commons.configuration BaseConfiguration getString

Introduction

In this page you can find the example usage for org.apache.commons.configuration BaseConfiguration getString.

Prototype

public String getString(String key) 

Source Link

Usage

From source file:uk.ac.sanger.cgp.wwdocker.Config.java

public static Map<String, String> getEnvs(BaseConfiguration config) {
    Map<String, String> envs = new HashMap();
    for (String env : optionalEnvs) {
        String value = config.getString(env);
        if (value != null) {
            envs.put(env, value);/*from   ww  w.  j  a va 2  s . c om*/
        }
    }
    return envs;
}

From source file:uk.ac.sanger.cgp.wwdocker.daemon.PrimaryDaemon.java

private void hostSet(BaseConfiguration config, Map<String, String> hosts) {
    // first remove the killed off hosts
    List toRemove = new ArrayList();
    for (Map.Entry<String, String> e : hosts.entrySet()) {
        if (e.getValue().equals("DELETE")) {
            toRemove.add(e.getKey());//  w w w  .j  ava2  s .  c  om
        }
    }
    hosts.keySet().removeAll(toRemove);

    // add the new hosts
    BaseConfiguration workerConf = Config.loadWorkers(config.getString("workerCfg"));
    String[] rawHosts = workerConf.getStringArray("hosts");
    if (rawHosts.length == 1 && rawHosts[0].equals(new String())) {
        rawHosts = new String[0];
    }
    Set<String> tmp = new LinkedHashSet<>();
    for (String h : rawHosts) {
        if (!hosts.containsKey(h)) {
            hosts.put(h, "TO_PROVISION");
        }
        tmp.add(h);
    }

    // identify which hosts need to be killed
    for (Map.Entry<String, String> e : hosts.entrySet()) {
        if (!tmp.contains(e.getKey())) {
            hosts.replace(e.getKey(), "KILL");
        }
    }
}

From source file:uk.ac.sanger.cgp.wwdocker.daemon.PrimaryDaemon.java

private void addWorkToPend(Workflow workManager, BaseConfiguration config)
        throws IOException, InterruptedException, TimeoutException {
    // send all work into the wwd_PEND queue, data can be added during execution, this ensures duplicates don't occur
    List<File> iniFiles = Utils.getWorkInis(config);
    if (iniFiles.isEmpty()) {
        return;//from   w  w  w .  j av  a2  s .  c om
    }

    // get all of the existing iniFiles so we can generate a uniq list
    String qPrefix = config.getString("qPrefix");
    List<String> existing = messaging.getMessageStrings(qPrefix.concat(".PEND"), 500);
    Map<String, WorkflowIni> allInis = new HashMap();
    for (String m : existing) {
        WorkflowIni iniFile = (WorkflowIni) Utils.jsonToObject(m, WorkflowIni.class);
        allInis.put(iniFile.getIniFile().getName(), iniFile);
    }
    for (File iniFile : iniFiles) {
        if (!allInis.containsKey(iniFile.getName())) {
            WorkflowIni newIni = new WorkflowIni(iniFile);
            newIni.setLogSearchCmd(workManager.getFindLogsCmds());
            allInis.put(iniFile.getName(), newIni);
        }
    }

    Iterator itr = allInis.values().iterator();
    while (itr.hasNext()) {
        messaging.sendMessage(qPrefix.concat(".PEND"), (WorkflowIni) itr.next());
    }

    workManager.iniUpdate(iniFiles, config, HostStatus.PEND);
}

From source file:uk.ac.sanger.cgp.wwdocker.daemon.PrimaryDaemon.java

private void killAll(BaseConfiguration config, Map<String, String> hosts, File thisJar, File thisConf)
        throws IOException, InterruptedException, TimeoutException {
    WorkerState killState = new WorkerState(thisJar, thisConf);
    killState.setChangeStatusTo(HostStatus.KILL);
    String killJson = Utils.objectToJson(killState);
    String qPrefix = config.getString("qPrefix");
    for (Map.Entry<String, String> e : hosts.entrySet()) {
        messaging.sendMessage(qPrefix.concat(".").concat(e.getKey()), killJson);
    }//w  ww.j  a  va2s  .c om
    logger.fatal("All hosts shutting down as requested... exiting");
    System.exit(0);
}

From source file:uk.ac.sanger.cgp.wwdocker.daemon.PrimaryDaemon.java

private void cleanHostQueues(BaseConfiguration config, Map<String, String> hosts)
        throws IOException, InterruptedException {
    String qPrefix = config.getString("qPrefix");
    for (Map.Entry<String, String> e : hosts.entrySet()) {
        messaging.getMessageStrings(qPrefix.concat(".").concat(e.getKey()), 50);
    }//from   w  ww  .  j  a va2  s. c o  m
}

From source file:uk.ac.sanger.cgp.wwdocker.factories.WorkflowFactory.java

public Workflow getWorkflow(BaseConfiguration config) {
    String workflowFile = config.getString("workflow");
    int startPos = workflowFile.lastIndexOf(WORKFLOW_PREFIX) + WORKFLOW_PREFIX.length();
    logger.trace(workflowFile);/* w  w w  .j  a va 2s.  c o m*/
    int endPos = workflowFile.indexOf("_", startPos);
    String workflow = workflowFile.substring(startPos, endPos);
    logger.trace("Got workflow: " + workflow);

    switch (workflow) {
    case "Test":
        logger.trace("Creating a TestWorkflow manager");
        return new TestWorkflow(config);
    case "SangerPancancerCgpCnIndelSnvStr":
        logger.trace("Creating a SangerWorkflow manager");
        return new SangerWorkflow(config);
    case "DEWrapperWorkflow":
        logger.trace("Creating a DEWorkflow manager");
        return new DEWorkflow(config);
    default:
        throw new RuntimeException("Workflow filename doesn't decode to a known workflow type:" + workflow);
    }
}

From source file:uk.ac.sanger.cgp.wwdocker.interfaces.Workflow.java

default String iniPathByState(BaseConfiguration config, String iniFile, HostStatus hs) {
    File tmp = new File(iniFile);
    String statePath = config.getString("wfl_inis");
    if (!statePath.endsWith("/")) {
        statePath = statePath.concat("/");
    }/*from   ww  w.  jav a2  s  .co m*/
    return statePath.concat(hs.name()).concat("/").concat(tmp.getName());
}

From source file:uk.ac.sanger.cgp.wwdocker.interfaces.Workflow.java

default void iniUpdate(List<File> inisFrom, BaseConfiguration config, HostStatus hs) {
    String iniBaseTo = config.getString("wfl_inis");
    if (!iniBaseTo.endsWith("/")) {
        iniBaseTo = iniBaseTo.concat("/");
    }/*from   ww w. j  a va2 s . c  om*/
    iniBaseTo = iniBaseTo.concat(hs.name()).concat("/");
    File dirCreate = new File(iniBaseTo);
    if (!dirCreate.exists()) {
        if (!dirCreate.mkdirs()) {
            throw new RuntimeException("Failed to create full path: " + dirCreate.getAbsolutePath());
        }
    }
    for (File iniFrom : inisFrom) {
        File iniTo = new File(iniBaseTo.concat(iniFrom.getName()));
        try {
            Files.move(iniFrom.toPath(), iniTo.toPath(), StandardCopyOption.REPLACE_EXISTING);
        } catch (IOException e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
}

From source file:uk.ac.sanger.cgp.wwdocker.workflow.DEWorkflow.java

@Override
public String baseDockerCommand(BaseConfiguration config, String extras) {
    //File workflow = Paths.get(config.getString("workflowDir"), config.getString("workflow").replaceAll(".*/", "").replaceAll("\\.zip$", "")).toFile();

    // probably want to clean the data store before we write the ini file
    //docker run --rm -h master -v /cgp/datastore:/datastore -v /cgp/workflows/Workflow_Bundle_SangerPancancerCgpCnIndelSnvStr_1.0.5.1_SeqWare_1.1.0-alpha.5:/workflow -i seqware/seqware_whitestar_pancancer rm -rf /datastore/

    String command = "docker run --rm -h master";
    // this is an oddity of the DKFZ version to ensure that paths are handled correctly in the inner docker call
    command = command.concat(" -v ").concat(config.getString("datastoreDir")).concat(":")
            .concat(config.getString("datastoreDir"));
    command = command.concat(" -v ").concat(config.getString("workflowDir")).concat(":/workflow");
    if (extras != null) {
        command = command.concat(extras);
    }//from   ww w.  j a va2  s  .c  o  m
    command = command.concat(" ").concat(seqwareWhiteStarImage(config));
    return command;
}

From source file:uk.ac.sanger.cgp.wwdocker.workflow.DEWorkflow.java

@Override
public int runDocker(BaseConfiguration config, File iniFile) {
    /*//from   w w w .jav  a2  s .  co  m
     * docker run --rm -h master -t
     * -v /cgp/datastore:/datastore
     * -v /cgp/Workflow_Bundle_SangerPancancerCgpCnIndelSnvStr_1.0.5.1_SeqWare_1.1.0-alpha.5:/workflow
     * -i seqware/seqware_whitestar_pancancer
     * seqware bundle launch
     * --no-metadata
     * --engine whitestar-parallel
     * --dir /workflow
     * --ini /datastore/testRun.ini
     */

    String extras = " -v /var/run/docker.sock:/var/run/docker.sock";
    extras = extras.concat(" -v ").concat(config.getString("datastoreDir")).concat("/")
            .concat(iniFile.getName()).concat(":/workflow.ini");
    // don't add the pem key here, just standardise in the ini file template

    String command = baseDockerCommand(config, extras);
    command = command.concat(" bash -c \"sed -i 's|/datastore|" + config.getString("datastoreDir")
            + "|g' /home/seqware/.seqware/settings ;");
    command = command
            .concat(" sed -i 's|OOZIE_RETRY_MAX=.*|OOZIE_RETRY_MAX=0|' /home/seqware/.seqware/settings ;");
    command = command.concat(" seqware bundle launch --no-metadata --engine whitestar");
    command = command.concat(" --dir /workflow/")
            .concat(config.getString("workflow").replaceAll(".*/", "").replaceAll("\\.zip$", ""));
    command = command.concat(" --ini /workflow.ini");
    command = command.concat("\""); // close quotes on bash command

    // this may need to be more itelligent than just the exit code
    return execCommand(command, Config.getEnvs(config), true);
}