Search in sources :

Example 1 with CommandEnvironment

use of org.platformlayer.ops.CommandEnvironment in project platformlayer by platformlayer.

the class JenkinsCasObject method copyTo0.

@Override
public void copyTo0(OpsTarget target, File remoteFilePath) throws OpsException {
    InetAddress host;
    try {
        host = InetAddress.getByName(uri.getHost());
    } catch (UnknownHostException e) {
        throw new OpsException("Unable to resolve host: " + uri, e);
    }
    if (InetAddressUtils.isPublic(host)) {
        CurlRequest curlRequest = new CurlRequest(uri);
        curlRequest.bareRequest = true;
        CommandEnvironment commandEnvironment = httpProxies.getHttpProxyEnvironment(target, Usage.General, uri);
        Command curlCommand = curlRequest.toCommand();
        curlCommand.addLiteral(">");
        curlCommand.addFile(remoteFilePath);
        curlCommand.setEnvironment(commandEnvironment);
        curlCommand.setTimeout(TimeSpan.FIVE_MINUTES);
        target.executeCommand(curlCommand);
    } else {
        log.warn("Address was not public: " + host + ", doing copy via ops system");
        File tempFile;
        try {
            tempFile = File.createTempFile("jenkins", "dat");
        } catch (IOException e) {
            throw new OpsException("Error creating temp file", e);
        }
        try {
            InputStream is = uri.toURL().openStream();
            try {
                IoUtils.copyStream(is, tempFile);
            } finally {
                Closeables.closeQuietly(is);
            }
            FileUpload.upload(target, remoteFilePath, tempFile);
        } catch (IOException e) {
            throw new OpsException("Error copying jenkins artifact", e);
        } finally {
            tempFile.delete();
        }
    }
}
Also used : OpsException(org.platformlayer.ops.OpsException) UnknownHostException(java.net.UnknownHostException) Command(org.platformlayer.ops.Command) InputStream(java.io.InputStream) CurlRequest(org.platformlayer.ops.helpers.CurlRequest) CommandEnvironment(org.platformlayer.ops.CommandEnvironment) IOException(java.io.IOException) InetAddress(java.net.InetAddress) File(java.io.File)

Example 2 with CommandEnvironment

use of org.platformlayer.ops.CommandEnvironment in project platformlayer by platformlayer.

the class SshPostgresTarget method execute.

public ProcessExecution execute(String sql, String maskedSql) throws OpsException {
    OpsTarget target = getOpsTarget();
    // We probably want psql -A -t -c "command"
    Command command = Command.build("psql");
    command.addQuoted("--username=", username);
    command.addQuoted("--host=", hostname);
    command.addArgument(Argument.buildQuoted("--command=", sql).setMasked("--command=" + Command.MASKED));
    CommandEnvironment env = new CommandEnvironment();
    env.put("PGPASSWORD", password.plaintext());
    command.setEnvironment(env);
    return target.executeCommand(command);
}
Also used : OpsTarget(org.platformlayer.ops.OpsTarget) Command(org.platformlayer.ops.Command) CommandEnvironment(org.platformlayer.ops.CommandEnvironment)

Example 3 with CommandEnvironment

use of org.platformlayer.ops.CommandEnvironment in project platformlayer by platformlayer.

the class AptPackageManager method clean.

public void clean(OpsTarget target) throws OpsException {
    CommandEnvironment commandEnvironment = buildEnvironmentWithProxy(target);
    Command command = Command.build("apt-get clean");
    target.executeCommand(command.setEnvironment(commandEnvironment).setTimeout(TimeSpan.TEN_MINUTES));
}
Also used : Command(org.platformlayer.ops.Command) CommandEnvironment(org.platformlayer.ops.CommandEnvironment)

Example 4 with CommandEnvironment

use of org.platformlayer.ops.CommandEnvironment in project platformlayer by platformlayer.

the class AptPackageManager method doDpkgConfigure.

private void doDpkgConfigure(OpsTarget target) throws OpsException {
    CommandEnvironment commandEnvironment = buildEnvironmentWithProxy(target);
    Command command = Command.build("dpkg --configure -a");
    command = command.setEnvironment(commandEnvironment).setTimeout(TimeSpan.TEN_MINUTES);
    target.executeCommand(command);
}
Also used : Command(org.platformlayer.ops.Command) CommandEnvironment(org.platformlayer.ops.CommandEnvironment)

Example 5 with CommandEnvironment

use of org.platformlayer.ops.CommandEnvironment in project platformlayer by platformlayer.

the class AptPackageManager method install.

public void install(OpsTarget target, Iterable<String> packageNames) throws OpsException {
    CommandEnvironment commandEnvironment = buildEnvironmentWithProxy(target);
    commandEnvironment.put("DEBIAN_FRONTEND", "noninteractive");
    log.info("Installing APT packages: " + Joiner.on(",").join(packageNames));
    Command command = Command.build("apt-get install --yes");
    for (String packageName : packageNames) {
        command.addQuoted(packageName);
    }
    target.executeCommand(command.setEnvironment(commandEnvironment).setTimeout(TimeSpan.TEN_MINUTES));
    flushCache(target);
}
Also used : Command(org.platformlayer.ops.Command) CommandEnvironment(org.platformlayer.ops.CommandEnvironment)

Aggregations

CommandEnvironment (org.platformlayer.ops.CommandEnvironment)12 Command (org.platformlayer.ops.Command)11 File (java.io.File)4 OpsException (org.platformlayer.ops.OpsException)3 OpsTarget (org.platformlayer.ops.OpsTarget)3 IOException (java.io.IOException)2 CurlRequest (org.platformlayer.ops.helpers.CurlRequest)2 Md5Hash (com.fathomdb.hash.Md5Hash)1 InputStream (java.io.InputStream)1 InetAddress (java.net.InetAddress)1 URISyntaxException (java.net.URISyntaxException)1 UnknownHostException (java.net.UnknownHostException)1 List (java.util.List)1 CasStoreMap (org.platformlayer.cas.CasStoreMap)1 CasStoreObject (org.platformlayer.cas.CasStoreObject)1 HostPolicy (org.platformlayer.core.model.HostPolicy)1 TagChanges (org.platformlayer.core.model.TagChanges)1 Tags (org.platformlayer.core.model.Tags)1 DiskImageRecipe (org.platformlayer.images.model.DiskImageRecipe)1 ChrootOpsTarget (org.platformlayer.ops.ChrootOpsTarget)1