Search in sources :

Example 1 with CurlRequest

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;
}
Also used : CurlResult(org.platformlayer.ops.helpers.CurlResult) CurlRequest(org.platformlayer.ops.helpers.CurlRequest)

Example 2 with CurlRequest

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);
// }
}
Also used : RequestBuilder(org.openstack.client.common.RequestBuilder) Command(org.platformlayer.ops.Command) ProcessExecution(org.platformlayer.ops.process.ProcessExecution) OpenstackStorageClient(org.openstack.client.storage.OpenstackStorageClient) CurlRequest(org.platformlayer.ops.helpers.CurlRequest)

Example 3 with CurlRequest

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();
        }
    }
}
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 4 with CurlRequest

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);
    }
}
Also used : CasStoreMap(org.platformlayer.cas.CasStoreMap) OpsException(org.platformlayer.ops.OpsException) CasStoreObject(org.platformlayer.cas.CasStoreObject) Command(org.platformlayer.ops.Command) CurlRequest(org.platformlayer.ops.helpers.CurlRequest) CommandEnvironment(org.platformlayer.ops.CommandEnvironment) Md5Hash(com.fathomdb.hash.Md5Hash) OpsCasTarget(org.platformlayer.ops.cas.OpsCasTarget) URISyntaxException(java.net.URISyntaxException) OpsException(org.platformlayer.ops.OpsException) IOException(java.io.IOException)

Example 5 with CurlRequest

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);
    }
}
Also used : OpsException(org.platformlayer.ops.OpsException) RequestBuilder(org.openstack.client.common.RequestBuilder) CurlRequest(org.platformlayer.ops.helpers.CurlRequest) RemoteCurlOpenstackRequest(org.platformlayer.service.cloud.openstack.ops.RemoteCurlOpenstackSession.RemoteCurlOpenstackRequest) ObjectProperties(org.openstack.model.storage.ObjectProperties) CurlResult(org.platformlayer.ops.helpers.CurlResult) Command(org.platformlayer.ops.Command) ProcessExecution(org.platformlayer.ops.process.ProcessExecution) Map(java.util.Map)

Aggregations

CurlRequest (org.platformlayer.ops.helpers.CurlRequest)6 Command (org.platformlayer.ops.Command)4 OpsException (org.platformlayer.ops.OpsException)4 CurlResult (org.platformlayer.ops.helpers.CurlResult)3 IOException (java.io.IOException)2 RequestBuilder (org.openstack.client.common.RequestBuilder)2 CommandEnvironment (org.platformlayer.ops.CommandEnvironment)2 ProcessExecution (org.platformlayer.ops.process.ProcessExecution)2 TimeSpan (com.fathomdb.TimeSpan)1 Md5Hash (com.fathomdb.hash.Md5Hash)1 File (java.io.File)1 InputStream (java.io.InputStream)1 InetAddress (java.net.InetAddress)1 URISyntaxException (java.net.URISyntaxException)1 UnknownHostException (java.net.UnknownHostException)1 Map (java.util.Map)1 OpenstackStorageClient (org.openstack.client.storage.OpenstackStorageClient)1 ObjectProperties (org.openstack.model.storage.ObjectProperties)1 CasStoreMap (org.platformlayer.cas.CasStoreMap)1 CasStoreObject (org.platformlayer.cas.CasStoreObject)1