Search in sources :

Example 1 with RequestBuilder

use of org.openstack.client.common.RequestBuilder 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 2 with RequestBuilder

use of org.openstack.client.common.RequestBuilder 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

RequestBuilder (org.openstack.client.common.RequestBuilder)2 Command (org.platformlayer.ops.Command)2 CurlRequest (org.platformlayer.ops.helpers.CurlRequest)2 ProcessExecution (org.platformlayer.ops.process.ProcessExecution)2 Map (java.util.Map)1 OpenstackStorageClient (org.openstack.client.storage.OpenstackStorageClient)1 ObjectProperties (org.openstack.model.storage.ObjectProperties)1 OpsException (org.platformlayer.ops.OpsException)1 CurlResult (org.platformlayer.ops.helpers.CurlResult)1 RemoteCurlOpenstackRequest (org.platformlayer.service.cloud.openstack.ops.RemoteCurlOpenstackSession.RemoteCurlOpenstackRequest)1