use of org.platformlayer.ops.helpers.CurlRequest in project platformlayer by platformlayer.
the class SolrCoreHelpers method execute.
private CurlResult execute(String action) throws OpsException {
String url = "http://127.0.0.1:8080/solr/admin/cores?core=" + coreKey;
url += "&action=" + action;
CurlRequest request = new CurlRequest(url);
CurlResult result = request.executeRequest(target);
log.info("result: " + result);
return result;
}
use of org.platformlayer.ops.helpers.CurlRequest in project platformlayer by platformlayer.
the class DirectOpenstackDownload method download.
public void download(OpsTarget target, File targetPath, OpenstackCredentials credentials, String containerName, String objectPath) throws OpsException {
RemoteCurlOpenstackSession session = new RemoteCurlOpenstackSession(target);
session.authenticate(credentials, false);
OpenstackStorageClient storageClient = session.getStorageClient();
RequestBuilder request = storageClient.root().containers().id(containerName).objects().id(objectPath).buildDownloadRequest();
CurlRequest curlRequest = session.toCurlRequest(request);
curlRequest.bareRequest = true;
Command curlCommand = curlRequest.toCommand();
curlCommand.addLiteral(">");
curlCommand.addFile(targetPath);
ProcessExecution execution = target.executeCommand(curlCommand);
// CurlResult curlResult = curlRequest.parseResponse(execution);
//
// int httpResult = curlResult.getHttpResult();
// switch (httpResult) {
// case 200:
// break;
// case 201:
// break;
// default:
// throw new OpsException("Unexpected result code while downloading file: " + httpResult + " Result=" +
// curlResult);
// }
}
use of org.platformlayer.ops.helpers.CurlRequest 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.helpers.CurlRequest in project platformlayer by platformlayer.
the class DownloadFileByHash method uploadFile.
@Override
protected void uploadFile(OpsTarget target, File remoteFilePath) throws IOException, OpsException {
target.mkdir(remoteFilePath.getParentFile());
Md5Hash resolved = getResolved(target);
CasStoreObject casObject;
CasStoreMap casStoreMap = cas.getCasStoreMap(target);
try {
casObject = casStoreMap.findArtifact(new OpsCasTarget(target), resolved);
} catch (Exception e) {
throw new OpsException("Error while resolving artifact:" + getHumanName(), e);
}
if (url != null && casObject == null) {
target.mkdir(remoteFilePath.getParentFile());
CurlRequest curlRequest = new CurlRequest(url);
curlRequest.bareRequest = true;
CommandEnvironment commandEnvironment = httpProxies.getHttpProxyEnvironment(target, Usage.General, url);
Command curlCommand = curlRequest.toCommand();
curlCommand.addLiteral(">");
curlCommand.addFile(remoteFilePath);
curlCommand.setEnvironment(commandEnvironment);
curlCommand.setTimeout(TimeSpan.FIVE_MINUTES);
// TODO: Can we cache into CAS instead??
log.info("Not found in CAS system; downloading directly: " + url);
target.executeCommand(curlCommand);
} else {
if (casObject == null) {
throw new OpsException("Unable to find artifact: " + getHumanName());
}
log.info("Doing a CAS copy from " + casObject + " to target");
cas.copyObject(casStoreMap, casObject, new OpsCasTarget(target), remoteFilePath, true);
}
}
use of org.platformlayer.ops.helpers.CurlRequest in project platformlayer by platformlayer.
the class ShellBackupClient method uploadStream.
public void uploadStream(Backup request, Command dataSourceCommand) throws OpsException {
ObjectProperties openstackProperties = new ObjectProperties();
if (request.objectName == null) {
throw new IllegalArgumentException("objectName is required");
}
String objectPath = context.toPath(request.objectName);
openstackProperties.setName(objectPath);
for (Map.Entry<String, String> entry : request.objectProperties.entrySet()) {
String key = entry.getKey();
openstackProperties.getCustomProperties().put(key, entry.getValue());
}
log.info("Uploading to " + getContainerName() + "/" + objectPath);
RequestBuilder requestBuilder = getStorageClient(request.target).root().containers().id(getContainerName()).objects().buildPutRequest(openstackProperties);
CurlRequest curlRequest = ((RemoteCurlOpenstackRequest) requestBuilder).toCurlRequest();
curlRequest.bodyFromStdin = true;
Command curlCommand = curlRequest.toCommand();
Command pipedCommand = dataSourceCommand.pipeTo(curlCommand);
ProcessExecution execution = request.target.executeCommand(pipedCommand);
CurlResult curlResult = curlRequest.parseResponse(execution);
int httpResult = curlResult.getHttpResult();
switch(httpResult) {
case 200:
break;
case 201:
break;
default:
throw new OpsException("Unexpected result code while uploading backup: " + httpResult + " Result=" + curlResult);
}
}
Aggregations