Search in sources :

Example 1 with PreparedString

use of alma.acs.commandcenter.util.PreparedString in project ACS by ACS-Community.

the class ToolManager method generateCommand.

public static String generateCommand(Tool tool, RunModel runModel, Map<String, Object> input) throws Exception {
    String ret;
    String[] pieces = collectInsertions(tool, runModel, input);
    PreparedString prep = new PreparedString(tool.getCommand());
    String command = prep.toString(pieces);
    //		VariableString vari = new VariableString(command, false);
    //		ret = vari.toString(getVariables());
    ret = command;
    return ret;
}
Also used : PreparedString(alma.acs.commandcenter.util.PreparedString) PreparedString(alma.acs.commandcenter.util.PreparedString)

Example 2 with PreparedString

use of alma.acs.commandcenter.util.PreparedString in project ACS by ACS-Community.

the class Executor method remoteNative.

/**
    * @return false - if this failed gracefully
    * @throws Throwable - if this failed severely
    */
private static boolean remoteNative(String username, final String password, final String command, String endMark, NativeCommand.Listener listener, String host) throws Throwable {
    localOutProcFlow.reset(null);
    if (listener == null) {
        // normalization: use a do-nothing implementation
        listener = new NativeCommand.ListenerAdapter();
    }
    // --- set up task
    // ssh-command can be changed at any time through a system property if necessary
    // msc (2006-04-28): added "-X" for X-forwarding, as done for OMC in Socorro in Jan'06
    String sshPatternDefault = "ssh -X -t -l ? ? /bin/bash --login -c \"?\"";
    String sshPattern = System.getProperty(SYSPROP_COMMAND_NATIVE_SSH, sshPatternDefault);
    PreparedString prep = new PreparedString(sshPattern);
    String sshCommand = prep.toString(new String[] { username, host, command });
    /*String sshCommand = "ssh -t -l "+username+" "+host+" /bin/bash --login -c \""+command+"\"";*/
    boolean foreground = true;
    long maxExecutionTime = -1;
    // make a regular expression
    endMark = ".*" + endMark + ".*";
    NativeCommand task = new NativeCommand(sshCommand, foreground, maxExecutionTime, endMark);
    remoteNativeTasks.add(task);
    task.addListener(listener);
    task.addListener(new NativeCommand.ListenerAdapter() {

        @Override
        public void statusChanged(NativeCommand task, String oldStatus) {
            if (task.getStatus() == NativeCommand.RUNNING) {
                localOutProcFlow.success(LocalOutProcFlow.RUN);
            }
        }
    });
    // --- run task
    // the current thread will block if "foreground" is true
    task.run();
    // --- examine results
    Throwable latestExc = task.getLatestException();
    // if we get here and the process-status is still RUNNING,
    // it simply means the expected output has occurred but the
    // process itself is still running
    log.info("Process invoked. Process is now: " + task.getStatus() + ". Exitcode: " + (task.getExitValue() != null ? task.getExitValue().toString() : "none (yet)") + ". Command was '" + command + "'");
    if (latestExc != null) {
        log.fine("During process invocation (at least) one error occurred: " + latestExc);
        remoteFlow.failure(latestExc);
        throw latestExc;
    } else {
        localOutProcFlow.success(LocalOutProcFlow.COMPLETE);
        return true;
    }
}
Also used : PreparedString(alma.acs.commandcenter.util.PreparedString) PreparedString(alma.acs.commandcenter.util.PreparedString)

Aggregations

PreparedString (alma.acs.commandcenter.util.PreparedString)2