From 2e984294ac28c6f2ede290c38164c5d536ccaf4a Mon Sep 17 00:00:00 2001 From: ChrisC Date: Tue, 31 Jan 2017 13:57:24 +0100 Subject: Initial OpenECOMP MSO OpenStack SDK lib commit Change-Id: Ieaacb2b2c0dcc469669880e73f0cda9fa59a6c5a Signed-off-by: ChrisC --- .../java/com/woorea/openstack/swift/Swift.java | 33 +++++ .../openstack/swift/api/AccountResource.java | 22 ++++ .../openstack/swift/api/ContainerResource.java | 143 +++++++++++++++++++++ .../openstack/swift/api/ContainersResource.java | 74 +++++++++++ 4 files changed, 272 insertions(+) create mode 100644 swift-client/src/main/java/com/woorea/openstack/swift/Swift.java create mode 100644 swift-client/src/main/java/com/woorea/openstack/swift/api/AccountResource.java create mode 100644 swift-client/src/main/java/com/woorea/openstack/swift/api/ContainerResource.java create mode 100644 swift-client/src/main/java/com/woorea/openstack/swift/api/ContainersResource.java (limited to 'swift-client/src/main/java') diff --git a/swift-client/src/main/java/com/woorea/openstack/swift/Swift.java b/swift-client/src/main/java/com/woorea/openstack/swift/Swift.java new file mode 100644 index 0000000..0629853 --- /dev/null +++ b/swift-client/src/main/java/com/woorea/openstack/swift/Swift.java @@ -0,0 +1,33 @@ +package com.woorea.openstack.swift; + + +import com.woorea.openstack.base.client.OpenStackClient; +import com.woorea.openstack.base.client.OpenStackClientConnector; +import com.woorea.openstack.swift.api.AccountResource; +import com.woorea.openstack.swift.api.ContainersResource; + +public class Swift extends OpenStackClient { + + private final AccountResource ACCOUNT; + + private final ContainersResource CONTAINERS; + + public Swift(String endpoint, OpenStackClientConnector connector) { + super(endpoint, connector); + CONTAINERS = new ContainersResource(this); + ACCOUNT = new AccountResource(this); + } + + public Swift(String endpoint) { + this(endpoint, null); + } + + public ContainersResource containers() { + return CONTAINERS; + } + + public AccountResource account() { + return ACCOUNT; + } + +} diff --git a/swift-client/src/main/java/com/woorea/openstack/swift/api/AccountResource.java b/swift-client/src/main/java/com/woorea/openstack/swift/api/AccountResource.java new file mode 100644 index 0000000..f98fbf9 --- /dev/null +++ b/swift-client/src/main/java/com/woorea/openstack/swift/api/AccountResource.java @@ -0,0 +1,22 @@ +package com.woorea.openstack.swift.api; + +import com.woorea.openstack.base.client.OpenStackClient; +import com.woorea.openstack.base.client.OpenStackRequest; + +public class AccountResource { + + private final OpenStackClient CLIENT; + + public AccountResource(OpenStackClient client) { + CLIENT = client; + } + + public class ShowAccount extends OpenStackRequest { + + public ShowAccount() { +// return target.request(MediaType.APPLICATION_JSON).head(); + } + + } + +} diff --git a/swift-client/src/main/java/com/woorea/openstack/swift/api/ContainerResource.java b/swift-client/src/main/java/com/woorea/openstack/swift/api/ContainerResource.java new file mode 100644 index 0000000..c55babe --- /dev/null +++ b/swift-client/src/main/java/com/woorea/openstack/swift/api/ContainerResource.java @@ -0,0 +1,143 @@ +package com.woorea.openstack.swift.api; + +import java.util.Map; + + +import com.woorea.openstack.base.client.OpenStackClient; +import com.woorea.openstack.base.client.OpenStackRequest; +import com.woorea.openstack.base.client.OpenStackResponse; +import com.woorea.openstack.swift.model.ObjectDownload; +import com.woorea.openstack.swift.model.ObjectForUpload; + +public class ContainerResource { + + private final OpenStackClient CLIENT; + + private String container; + + public ContainerResource(OpenStackClient client, String container) { + CLIENT = client; + this.container = container; + } + + public List list() { + return new List(container, null); + } + + public CreateDirectory createDirectory(String path) { + return new CreateDirectory(container, path); + } + + public Show show(String path) { + return new Show(container, path); + } + + public Upload upload(ObjectForUpload objectForUpload) { + return new Upload(objectForUpload); + } + + public Download download(String path) { + return new Download(container, path); + } + + public Delete delete(String path) { + return new Delete(container, path); + } + + public class List extends OpenStackRequest> { + + private String containerName; + + private Map filters; + + public List(String containerName, Map filters) { + this.containerName = containerName; + this.filters = filters; + //returnType(new TypeToken>(){}); +// target = target.path(containerName); +// for(String filter : new String[]{"prefix","delimiter","path","marker"}) { +// if(filters.get(filter) != null) { +// target = target.queryParam(filter, filters.get(filter)); +// } +// } +// return target.request(MediaType.APPLICATION_JSON).get(new GenericType>(){}); + } + + } + + public class CreateDirectory extends OpenStackRequest { + + private String container; + + private String path; + + public CreateDirectory(String container, String path) { + this.container = container; + this.path = path; +// endpoint.path(container).path(path).request().put(Entity.entity(new byte[1],"application/directory")); + } + + } + + public class Show extends OpenStackRequest { + + private String containerName; + + private String objectName; + + public Show(String containerName, String objectName) { + this.containerName = containerName; + this.objectName = objectName; +// return target.path(containerName).path(objectName).request(MediaType.APPLICATION_JSON).head(); + } + + } + + public class Upload extends OpenStackRequest { + + private ObjectForUpload objectForUpload; + + public Upload(ObjectForUpload objectForUpload) { + this.objectForUpload = objectForUpload; +// Invocation.Builder invocationBuilder = target.path(objectForUpload.getContainer()).path(objectForUpload.getName()).request(MediaType.APPLICATION_JSON); +// for(String key : objectForUpload.getProperties().keySet()) { +// invocationBuilder.header("x-object-meta-" + key, objectForUpload.getProperties().get(key)); +// } +// return invocationBuilder.put(Entity.entity(objectForUpload.getInputStream(), MediaType.APPLICATION_OCTET_STREAM), Response.class); + } + + } + + public class Download extends OpenStackRequest { + + private String containerName; + + private String objectName; + + public Download(String containerName, String objectName) { + this.containerName = containerName; + this.objectName = objectName; +// Response response = target.path(containerName).path(objectName).request(MediaType.APPLICATION_JSON).get(); +// ObjectDownload objectDownload = new ObjectDownload(); +// objectDownload.setInputStream((InputStream) response.getEntity()); +// return objectDownload; + } + + } + + + public class Delete extends OpenStackRequest { + + private String containerName; + + private String objectName; + + public Delete(String containerName, String objectName) { + this.containerName = containerName; + this.objectName = objectName; + //return target.path(containerName).path(objectName).request(MediaType.APPLICATION_JSON).delete(); + } + + } + +} diff --git a/swift-client/src/main/java/com/woorea/openstack/swift/api/ContainersResource.java b/swift-client/src/main/java/com/woorea/openstack/swift/api/ContainersResource.java new file mode 100644 index 0000000..aedcc3f --- /dev/null +++ b/swift-client/src/main/java/com/woorea/openstack/swift/api/ContainersResource.java @@ -0,0 +1,74 @@ +package com.woorea.openstack.swift.api; + + +import com.woorea.openstack.base.client.OpenStackClient; +import com.woorea.openstack.base.client.OpenStackRequest; +import com.woorea.openstack.swift.model.Container; + +public class ContainersResource { + + private final OpenStackClient CLIENT; + + public ContainersResource(OpenStackClient client) { + CLIENT = client; + } + + public List list() { + return new List(); + } + + public Create create(String name) { + return new Create(name); + } + + public Show show(String name) { + return new Show(name); + } + + public Delete delete(String name) { + return new Delete(name); + } + + public ContainerResource container(String name) { + return new ContainerResource(CLIENT, name); + } + + public class List extends OpenStackRequest> { + + public List() { + //return target.request(MediaType.APPLICATION_JSON).get(new GenericType>(){}); + } + + } + + + public class Create extends OpenStackRequest { + + public Create(String containerName) { + //return target.path(containerName).request().method("PUT",Entity.text("*")); + } + + } + + public class Show extends OpenStackRequest { + + private String containerName; + + public Show(String containerName) { +// return target.path(containerName).request(MediaType.APPLICATION_JSON).head(); + } + + } + + public class Delete extends OpenStackRequest { + + private String containerName; + + public Delete(String containerName) { + this.containerName = containerName; + //return target.path(containerName).request(MediaType.APPLICATION_JSON).delete(); + } + + } + +} -- cgit 1.2.3-korg