Search in sources :

Example 1 with RemoteCurlOpenstackRequest

use of org.platformlayer.service.cloud.openstack.ops.RemoteCurlOpenstackSession.RemoteCurlOpenstackRequest 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

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