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();
}
}
}
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);
}
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));
}
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);
}
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);
}
Aggregations