Search in sources :

Example 1 with OpenstackStorageClient

use of org.openstack.client.storage.OpenstackStorageClient 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 OpenstackStorageClient

use of org.openstack.client.storage.OpenstackStorageClient in project platformlayer by platformlayer.

the class OpenstackCasStore method findArtifact.

@Override
public CasStoreObject findArtifact(Md5Hash hash) {
    OpenstackStorageClient storageClient = getStorageClient();
    try {
        List<StorageObject> storageObjects = Lists.newArrayList(storageClient.listObjects(containerName, null, null));
        String findHash = hash.toHex();
        for (StorageObject storageObject : storageObjects) {
            String storageObjectHash = storageObject.getHash();
            if (storageObjectHash.equalsIgnoreCase(findHash)) {
                return new OpenstackCasObject(storageObject);
            }
        }
    } catch (OpenstackNotFoundException e) {
        log.debug("Not found (404) returned from Openstack");
        return null;
    }
    return null;
}
Also used : StorageObject(org.openstack.model.storage.StorageObject) OpenstackStorageClient(org.openstack.client.storage.OpenstackStorageClient) OpenstackNotFoundException(org.openstack.client.OpenstackNotFoundException)

Aggregations

OpenstackStorageClient (org.openstack.client.storage.OpenstackStorageClient)2 OpenstackNotFoundException (org.openstack.client.OpenstackNotFoundException)1 RequestBuilder (org.openstack.client.common.RequestBuilder)1 StorageObject (org.openstack.model.storage.StorageObject)1 Command (org.platformlayer.ops.Command)1 CurlRequest (org.platformlayer.ops.helpers.CurlRequest)1 ProcessExecution (org.platformlayer.ops.process.ProcessExecution)1