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