From 058213dd20487544753ef7f6143c80a8db933a76 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Tue, 24 Apr 2012 17:38:39 -0700 Subject: [PATCH] Issue 188: base impl of cdmi --- labs/cdmi/pom.xml | 135 ++++++++++++++ .../jclouds/snia/cdmi/v1/CDMIApiMetadata.java | 93 ++++++++++ .../jclouds/snia/cdmi/v1/CDMIAsyncClient.java | 53 ++++++ .../org/jclouds/snia/cdmi/v1/CDMIClient.java | 57 ++++++ .../org/jclouds/snia/cdmi/v1/ObjectTypes.java | 31 ++++ .../snia/cdmi/v1/config/CDMIProperties.java | 28 +++ .../cdmi/v1/config/CDMIRestClientModule.java | 63 +++++++ .../snia/cdmi/v1/domain/CDMIObject.java | 165 ++++++++++++++++++ .../snia/cdmi/v1/domain/Container.java | 134 ++++++++++++++ .../v1/features/ContainerAsyncClient.java | 60 +++++++ .../cdmi/v1/features/ContainerClient.java | 38 ++++ .../cdmi/v1/features/DataAsyncClient.java | 39 +++++ .../snia/cdmi/v1/features/DataClient.java | 35 ++++ .../cdmi/v1/features/DomainAsyncClient.java | 40 +++++ .../snia/cdmi/v1/features/DomainClient.java | 36 ++++ .../BasicAuthenticationAndTenantId.java | 62 +++++++ .../v1/filters/StripExtraAcceptHeader.java | 43 +++++ .../cdmi/v1/handlers/CDMIErrorHandler.java | 82 +++++++++ .../v1/options/ListContainersOptions.java | 78 +++++++++ .../services/org.jclouds.apis.ApiMetadata | 1 + .../snia/cdmi/v1/CDMIApiMetadataTest.java | 38 ++++ .../snia/cdmi/v1/CDMIErrorHandlerTest.java | 120 +++++++++++++ .../features/ContainerClientExpectTest.java | 66 +++++++ .../v1/features/ContainerClientLiveTest.java | 48 +++++ .../v1/features/DataClientExpectTest.java | 30 ++++ .../cdmi/v1/features/DataClientLiveTest.java | 30 ++++ .../v1/features/DomainClientExpectTest.java | 30 ++++ .../v1/features/DomainClientLiveTest.java | 30 ++++ .../BaseCDMIAsyncClientExpectTest.java | 39 +++++ .../v1/internal/BaseCDMIClientExpectTest.java | 30 ++++ .../v1/internal/BaseCDMIClientLiveTest.java | 64 +++++++ .../cdmi/v1/internal/BaseCDMIExpectTest.java | 36 ++++ .../v1/options/ListContainersOptionsTest.java | 96 ++++++++++ .../cdmi/v1/parse/ParseContainerTest.java | 58 ++++++ labs/cdmi/src/test/resources/container.json | 17 ++ labs/cdmi/src/test/resources/logback.xml | 51 ++++++ labs/pom.xml | 1 + 37 files changed, 2057 insertions(+) create mode 100644 labs/cdmi/pom.xml create mode 100644 labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/CDMIApiMetadata.java create mode 100644 labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/CDMIAsyncClient.java create mode 100644 labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/CDMIClient.java create mode 100644 labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/ObjectTypes.java create mode 100644 labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/config/CDMIProperties.java create mode 100644 labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/config/CDMIRestClientModule.java create mode 100644 labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/domain/CDMIObject.java create mode 100644 labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/domain/Container.java create mode 100644 labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/ContainerAsyncClient.java create mode 100644 labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/ContainerClient.java create mode 100644 labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DataAsyncClient.java create mode 100644 labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DataClient.java create mode 100644 labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DomainAsyncClient.java create mode 100644 labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DomainClient.java create mode 100644 labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/filters/BasicAuthenticationAndTenantId.java create mode 100644 labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/filters/StripExtraAcceptHeader.java create mode 100644 labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/handlers/CDMIErrorHandler.java create mode 100644 labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/options/ListContainersOptions.java create mode 100644 labs/cdmi/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata create mode 100644 labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/CDMIApiMetadataTest.java create mode 100644 labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/CDMIErrorHandlerTest.java create mode 100644 labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/ContainerClientExpectTest.java create mode 100644 labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/ContainerClientLiveTest.java create mode 100644 labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/DataClientExpectTest.java create mode 100644 labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/DataClientLiveTest.java create mode 100644 labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/DomainClientExpectTest.java create mode 100644 labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/DomainClientLiveTest.java create mode 100644 labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/internal/BaseCDMIAsyncClientExpectTest.java create mode 100644 labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/internal/BaseCDMIClientExpectTest.java create mode 100644 labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/internal/BaseCDMIClientLiveTest.java create mode 100644 labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/internal/BaseCDMIExpectTest.java create mode 100644 labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/options/ListContainersOptionsTest.java create mode 100644 labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/parse/ParseContainerTest.java create mode 100644 labs/cdmi/src/test/resources/container.json create mode 100644 labs/cdmi/src/test/resources/logback.xml diff --git a/labs/cdmi/pom.xml b/labs/cdmi/pom.xml new file mode 100644 index 0000000000..5a2a5293e3 --- /dev/null +++ b/labs/cdmi/pom.xml @@ -0,0 +1,135 @@ + + + + 4.0.0 + + org.jclouds + jclouds-project + 1.5.0-SNAPSHOT + ../../project/pom.xml + + org.jclouds.labs + cdmi + jcloud cdmi api + jclouds components to access an implementation of SNIA CDMI + bundle + + + http://localhost:8080 + 1.0.1 + + tenantId:IDENTITY + FIXME_CREDENTIALS + FIXME_HTTPURL + FIXME_HTTPMD5 + + + + + org.jclouds + jclouds-blobstore + ${project.version} + + + org.jclouds + jclouds-core + ${project.version} + test-jar + test + + + org.jclouds + jclouds-blobstore + ${project.version} + test-jar + test + + + org.jclouds.driver + jclouds-slf4j + ${project.version} + test + + + ch.qos.logback + logback-classic + 1.0.0 + test + + + + + + live + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration + integration-test + + test + + + + ${test.cdmi.endpoint} + ${test.cdmi.api-version} + ${test.cdmi.build-version} + ${test.cdmi.identity} + ${test.cdmi.credential} + ${jclouds.blobstore.httpstream.url} + ${jclouds.blobstore.httpstream.md5} + + + + + + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + ${project.artifactId} + org.jclouds.snia.cdmi.v1*;version="${project.version}" + + org.jclouds.blobstore.internal;version="${project.version}", + org.jclouds.rest.internal;version="${project.version}", + org.jclouds*;version="${project.version}", + * + + + + + + + + diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/CDMIApiMetadata.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/CDMIApiMetadata.java new file mode 100644 index 0000000000..a01b8c47ca --- /dev/null +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/CDMIApiMetadata.java @@ -0,0 +1,93 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.snia.cdmi.v1; + +import java.net.URI; +import java.util.Properties; + +import org.jclouds.apis.ApiMetadata; +import org.jclouds.rest.RestContext; +import org.jclouds.rest.internal.BaseRestApiMetadata; +import org.jclouds.snia.cdmi.v1.config.CDMIRestClientModule; + +import com.google.common.collect.ImmutableSet; +import com.google.common.reflect.TypeToken; +import com.google.inject.Module; + +/** + * Implementation of {@link ApiMetadata} for CDMI 1.0.1 API + * + * @author Adrian Cole + */ +public class CDMIApiMetadata extends BaseRestApiMetadata { + + /** The serialVersionUID */ + private static final long serialVersionUID = 6725672099385580694L; + + public static final TypeToken> CONTEXT_TOKEN = new TypeToken>() { + private static final long serialVersionUID = -5070937833892503232L; + }; + + @Override + public Builder toBuilder() { + return new Builder().fromApiMetadata(this); + } + + public CDMIApiMetadata() { + this(new Builder()); + } + + protected CDMIApiMetadata(Builder builder) { + super(builder); + } + + public static Properties defaultProperties() { + Properties properties = BaseRestApiMetadata.defaultProperties(); + return properties; + } + + public static class Builder extends BaseRestApiMetadata.Builder { + + protected Builder() { + super(CDMIClient.class, CDMIAsyncClient.class); + id("cdmi") + .name("SNIA CDMI API") + .identityName("tenantId:user") + .credentialName("password") + .documentation(URI.create("http://www.snia.org/cdmi")) + .version("1.0.1") + .defaultEndpoint("http://localhost:8080") + .defaultProperties(CDMIApiMetadata.defaultProperties()) + .defaultModules(ImmutableSet.> of(CDMIRestClientModule.class)); + } + + @Override + public CDMIApiMetadata build() { + return new CDMIApiMetadata(this); + } + + @Override + public Builder fromApiMetadata(ApiMetadata in) { + super.fromApiMetadata(in); + return this; + } + + } + +} diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/CDMIAsyncClient.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/CDMIAsyncClient.java new file mode 100644 index 0000000000..e8c80e56b8 --- /dev/null +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/CDMIAsyncClient.java @@ -0,0 +1,53 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.snia.cdmi.v1; + +import org.jclouds.rest.annotations.Delegate; +import org.jclouds.snia.cdmi.v1.features.ContainerAsyncClient; +import org.jclouds.snia.cdmi.v1.features.DataAsyncClient; +import org.jclouds.snia.cdmi.v1.features.DomainAsyncClient; + +/** + * Provides asynchronous access to CDMI via their REST API. + *

+ * + * @see CDMIClient + * @see api doc + * @author Adrian Cole + */ +public interface CDMIAsyncClient { + + /** + * Provides asynchronous access to Domain Object Resource Operations. + */ + @Delegate + DomainAsyncClient getDomainClient(); + + /** + * Provides asynchronous access to Container Object Resource Operations. + */ + @Delegate + ContainerAsyncClient getContainerClient(); + + /** + * Provides asynchronous access to Data Object Resource Operations. + */ + @Delegate + DataAsyncClient getDataClient(); +} diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/CDMIClient.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/CDMIClient.java new file mode 100644 index 0000000000..3f1d369e67 --- /dev/null +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/CDMIClient.java @@ -0,0 +1,57 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.snia.cdmi.v1; + +import java.util.concurrent.TimeUnit; + +import org.jclouds.concurrent.Timeout; +import org.jclouds.rest.annotations.Delegate; +import org.jclouds.snia.cdmi.v1.features.ContainerClient; +import org.jclouds.snia.cdmi.v1.features.DataClient; +import org.jclouds.snia.cdmi.v1.features.DomainClient; + +/** + * Provides synchronous access to CDMI. + *

+ * + * @see CDMIAsyncClient + * @see api doc + * @author Adrian Cole + */ +@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) +public interface CDMIClient { + + /** + * Provides synchronous access to Domain Object Resource Operations. + */ + @Delegate + DomainClient getDomainClient(); + + /** + * Provides synchronous access to Container Object Resource Operations. + */ + @Delegate + ContainerClient getContainerClient(); + + /** + * Provides synchronous access to Data Object Resource Operations. + */ + @Delegate + DataClient getDataClient(); +} diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/ObjectTypes.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/ObjectTypes.java new file mode 100644 index 0000000000..e387eb9af2 --- /dev/null +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/ObjectTypes.java @@ -0,0 +1,31 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.snia.cdmi.v1; + + +/** + * Object Types used in CDMI. + * + * @see javax.ws.rs.core.MediaType; + */ +public interface ObjectTypes { + + public static final String CONTAINER = "application/cdmi-container"; + +} \ No newline at end of file diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/config/CDMIProperties.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/config/CDMIProperties.java new file mode 100644 index 0000000000..77beee510e --- /dev/null +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/config/CDMIProperties.java @@ -0,0 +1,28 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.snia.cdmi.v1.config; + +/** + * Configuration properties and constants used in SNIA CDMI connections. + * + * @author Adrian Cole + */ +public class CDMIProperties { + +} diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/config/CDMIRestClientModule.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/config/CDMIRestClientModule.java new file mode 100644 index 0000000000..cfe0250965 --- /dev/null +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/config/CDMIRestClientModule.java @@ -0,0 +1,63 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.snia.cdmi.v1.config; + +import java.util.Map; + +import org.jclouds.http.HttpErrorHandler; +import org.jclouds.http.annotation.ClientError; +import org.jclouds.http.annotation.Redirection; +import org.jclouds.http.annotation.ServerError; +import org.jclouds.rest.ConfiguresRestClient; +import org.jclouds.rest.config.RestClientModule; +import org.jclouds.snia.cdmi.v1.CDMIAsyncClient; +import org.jclouds.snia.cdmi.v1.CDMIClient; +import org.jclouds.snia.cdmi.v1.features.ContainerAsyncClient; +import org.jclouds.snia.cdmi.v1.features.ContainerClient; +import org.jclouds.snia.cdmi.v1.features.DataAsyncClient; +import org.jclouds.snia.cdmi.v1.features.DataClient; +import org.jclouds.snia.cdmi.v1.features.DomainAsyncClient; +import org.jclouds.snia.cdmi.v1.features.DomainClient; +import org.jclouds.snia.cdmi.v1.handlers.CDMIErrorHandler; + +import com.google.common.collect.ImmutableMap; + +/** + * Configures the CDMI connection. + * + * @author Adrian Cole + */ +@ConfiguresRestClient +public class CDMIRestClientModule extends RestClientModule { + + public static final Map, Class> DELEGATE_MAP = ImmutableMap., Class> builder().put( + DomainClient.class, DomainAsyncClient.class).put(ContainerClient.class, ContainerAsyncClient.class).put( + DataClient.class, DataAsyncClient.class).build(); + + public CDMIRestClientModule() { + super(DELEGATE_MAP); + } + + @Override + protected void bindErrorHandlers() { + bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(CDMIErrorHandler.class); + bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(CDMIErrorHandler.class); + bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(CDMIErrorHandler.class); + } +} diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/domain/CDMIObject.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/domain/CDMIObject.java new file mode 100644 index 0000000000..59508653ed --- /dev/null +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/domain/CDMIObject.java @@ -0,0 +1,165 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.snia.cdmi.v1.domain; + +import static com.google.common.base.Objects.equal; +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.javax.annotation.Nullable; + +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; + +/** + * The base type for all objects in the CDMI model. + * + * @author Adrian Cole + */ +public class CDMIObject { + + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return builder().fromCDMIObject(this); + } + + private static class ConcreteBuilder extends Builder { + } + + public static abstract class Builder> { + private String objectID; + private String objectType; + private String objectName; + + @SuppressWarnings("unchecked") + protected B self() { + return (B) this; + } + + /** + * @see CDMIObject#getObjectID() + */ + public B objectID(String objectID) { + this.objectID = objectID; + return self(); + } + + /** + * @see CDMIObject#getObjectType() + */ + public B objectType(String objectType) { + this.objectType = objectType; + return self(); + } + + /** + * @see CDMIObject#getObjectName() + */ + public B objectName(String objectName) { + this.objectName = objectName; + return self(); + } + + public CDMIObject build() { + return new CDMIObject(this); + } + + protected B fromCDMIObject(CDMIObject in) { + return objectID(in.getObjectID()).objectType(in.getObjectType()).objectName(in.getObjectName()); + } + } + + private final String objectID; + private final String objectType; + private final String objectName; + + protected CDMIObject(Builder builder) { + this.objectID = checkNotNull(builder.objectID, "objectID"); + this.objectType = checkNotNull(builder.objectType, "objectType"); + this.objectName = builder.objectName; + } + + /** + * Object ID of the object
+ * Every object stored within a CDMI-compliant system shall have a globally unique object + * identifier (ID) assigned at creation time. The CDMI object ID is a string with requirements + * for how it is generated and how it obtains its uniqueness. Each offering that implements CDMI + * is able to produce these identifiers without conflicting with other offerings. + */ + public String getObjectID() { + return objectID; + } + + /** + * + * type of the object + */ + public String getObjectType() { + return objectType; + } + + /** + * For objects in a container, the objectName field shall be returned. For objects not in a + * container (objects that are only accessible by ID), the objectName field shall not be + * returned. + * + * Name of the object + */ + @Nullable + public String getObjectName() { + return objectName; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + CDMIObject that = CDMIObject.class.cast(o); + return equal(this.objectID, that.objectID) && equal(this.objectName, that.objectName) + && equal(this.objectType, that.objectType); + } + + public boolean clone(Object o) { + if (this == o) + return false; + if (o == null || getClass() != o.getClass()) + return false; + CDMIObject that = CDMIObject.class.cast(o); + return equal(this.objectType, that.objectType); + } + + @Override + public int hashCode() { + return Objects.hashCode(objectID, objectName, objectType); + } + + @Override + public String toString() { + return string().toString(); + } + + protected ToStringHelper string() { + return Objects.toStringHelper("").add("objectID", objectID).add("objectName", objectName).add("objectType", + objectType); + } +} diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/domain/Container.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/domain/Container.java new file mode 100644 index 0000000000..f0d1affb08 --- /dev/null +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/domain/Container.java @@ -0,0 +1,134 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.snia.cdmi.v1.domain; + +import static com.google.common.base.Objects.equal; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Map; +import java.util.Set; + +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Maps; + +/** + * + * @author Adrian Cole + */ +public class Container extends CDMIObject { + + public static Builder builder() { + return new ConcreteBuilder(); + } + + @Override + public Builder toBuilder() { + return builder().fromContainer(this); + } + + public static class Builder> extends CDMIObject.Builder { + + private Set children = ImmutableSet.of(); + private Map metadata = Maps.newHashMap(); + + /** + * @see Container#getChildren() + */ + public B children(String... children) { + return children(ImmutableSet.copyOf(checkNotNull(children, "children"))); + } + + /** + * @see Container#getChildren() + */ + public B children(Set children) { + this.children = ImmutableSet.copyOf(checkNotNull(children, "children")); + return self(); + } + + /** + * @see Container#getMetadata() + */ + public B metadata(Map metadata) { + this.metadata = ImmutableMap.copyOf(checkNotNull(metadata, "metadata")); + return self(); + } + + @Override + public Container build() { + return new Container(this); + } + + public B fromContainer(Container in) { + return fromCDMIObject(in).children(in.getChildren()).metadata(in.getMetadata()); + } + } + + private static class ConcreteBuilder extends Builder { + } + + private final Set children; + private final Map metadata; + + protected Container(Builder builder) { + super(builder); + this.children = ImmutableSet.copyOf(checkNotNull(builder.children, "children")); + this.metadata = ImmutableMap.copyOf(checkNotNull(builder.metadata, "metadata")); + } + + /** + * Names of the children objects in the container object. Child container objects end with "/". + */ + public Set getChildren() { + return children; + } + + /** + * Metadata for the container object. This field includes any user and data system metadata + * specified in the request body metadata field, along with storage system metadata generated by + * the cloud storage system. + */ + public Map getMetadata() { + return metadata; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Container that = Container.class.cast(o); + return super.equals(that) && equal(this.children, that.children) && equal(this.metadata, that.metadata); + } + + @Override + public int hashCode() { + return Objects.hashCode(super.hashCode(), children, metadata); + } + + @Override + public ToStringHelper string() { + return super.string().add("children", children).add("metadata", metadata); + } + +} diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/ContainerAsyncClient.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/ContainerAsyncClient.java new file mode 100644 index 0000000000..1bbf7257f8 --- /dev/null +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/ContainerAsyncClient.java @@ -0,0 +1,60 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.snia.cdmi.v1.features; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.MediaType; + +import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.Headers; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.SkipEncoding; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.snia.cdmi.v1.ObjectTypes; +import org.jclouds.snia.cdmi.v1.domain.Container; +import org.jclouds.snia.cdmi.v1.filters.BasicAuthenticationAndTenantId; +import org.jclouds.snia.cdmi.v1.filters.StripExtraAcceptHeader; + +import com.google.common.util.concurrent.ListenableFuture; + +/** + * Container Object Resource Operations + * + * @see ContainerClient + * @author Adrian Cole + * @see api doc + */ +@SkipEncoding( { '/', '=' }) +@RequestFilters( { BasicAuthenticationAndTenantId.class, StripExtraAcceptHeader.class }) +@Headers(keys="X-CDMI-Specification-Version", values = "{jclouds.api-version}") +public interface ContainerAsyncClient { + + /** + * @see ContainerClient#listContainers() + */ + @GET + @Consumes( { ObjectTypes.CONTAINER, MediaType.APPLICATION_JSON }) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + @Path("/{containerName}/") + ListenableFuture getContainer(@PathParam("containerName") String containerName); + +} diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/ContainerClient.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/ContainerClient.java new file mode 100644 index 0000000000..76df5c73d8 --- /dev/null +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/ContainerClient.java @@ -0,0 +1,38 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.snia.cdmi.v1.features; + +import java.util.concurrent.TimeUnit; + +import org.jclouds.concurrent.Timeout; +import org.jclouds.snia.cdmi.v1.domain.Container; + +/** + * Container Object Resource Operations + * + * @see ContainerAsyncClient + * @author Adrian Cole + * @see api doc + */ +@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) +public interface ContainerClient { + + Container getContainer(String containerName); + +} diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DataAsyncClient.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DataAsyncClient.java new file mode 100644 index 0000000000..5fc289bbf0 --- /dev/null +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DataAsyncClient.java @@ -0,0 +1,39 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.snia.cdmi.v1.features; + +import org.jclouds.rest.annotations.Headers; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.SkipEncoding; +import org.jclouds.snia.cdmi.v1.filters.BasicAuthenticationAndTenantId; +import org.jclouds.snia.cdmi.v1.filters.StripExtraAcceptHeader; + +/** + * Data Object Resource Operations + * + * @see DataClient + * @author Adrian Cole + * @see api doc + */ +@SkipEncoding( { '/', '=' }) +@RequestFilters( { BasicAuthenticationAndTenantId.class, StripExtraAcceptHeader.class }) +@Headers(keys="X-CDMI-Specification-Version", values = "{jclouds.api-version}") +public interface DataAsyncClient { + +} diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DataClient.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DataClient.java new file mode 100644 index 0000000000..f6dea31e45 --- /dev/null +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DataClient.java @@ -0,0 +1,35 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.snia.cdmi.v1.features; + +import java.util.concurrent.TimeUnit; + +import org.jclouds.concurrent.Timeout; + +/** + * Data Object Resource Operations + * + * @see DataAsyncClient + * @author Adrian Cole + * @see api doc + */ +@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) +public interface DataClient { + +} diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DomainAsyncClient.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DomainAsyncClient.java new file mode 100644 index 0000000000..db00154a4a --- /dev/null +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DomainAsyncClient.java @@ -0,0 +1,40 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.snia.cdmi.v1.features; + +import org.jclouds.rest.annotations.Headers; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.SkipEncoding; +import org.jclouds.snia.cdmi.v1.filters.BasicAuthenticationAndTenantId; +import org.jclouds.snia.cdmi.v1.filters.StripExtraAcceptHeader; + +/** + * Domain Object Resource Operations + * + * @see DomainClient + * @author Adrian Cole + * @see api doc + */ +@SkipEncoding( { '/', '=' }) +@RequestFilters( { BasicAuthenticationAndTenantId.class, StripExtraAcceptHeader.class }) +@Headers(keys="X-CDMI-Specification-Version", values = "{jclouds.api-version}") +public interface DomainAsyncClient { + + +} diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DomainClient.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DomainClient.java new file mode 100644 index 0000000000..c0488895bc --- /dev/null +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/features/DomainClient.java @@ -0,0 +1,36 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.snia.cdmi.v1.features; + +import java.util.concurrent.TimeUnit; + +import org.jclouds.concurrent.Timeout; + +/** + * Domain Object Resource Operations + * + * @see DomainAsyncClient + * @author Adrian Cole + * @see api doc + */ +@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) +public interface DomainClient { + + +} diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/filters/BasicAuthenticationAndTenantId.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/filters/BasicAuthenticationAndTenantId.java new file mode 100644 index 0000000000..fff38e56dd --- /dev/null +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/filters/BasicAuthenticationAndTenantId.java @@ -0,0 +1,62 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.snia.cdmi.v1.filters; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.crypto.Crypto; +import org.jclouds.http.HttpException; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpRequestFilter; +import org.jclouds.http.filters.BasicAuthentication; +import org.jclouds.http.utils.ModifyRequest; +import org.jclouds.rest.AuthorizationException; +import org.jclouds.rest.annotations.Credential; +import org.jclouds.rest.annotations.Identity; + +/** + * Uses Basic Authentication to sign the request, and adds the {@code TID} header. + * + * @see + * @author Adrian Cole + * + */ +@Singleton +public class BasicAuthenticationAndTenantId implements HttpRequestFilter { + private final String tenantId; + private final BasicAuthentication basicAuthentication; + + @Inject + public BasicAuthenticationAndTenantId(@Identity String tenantIdAndUsername, @Credential String password, + Crypto crypto) { + if (tenantIdAndUsername.indexOf(':') == -1) { + throw new AuthorizationException(String.format("Identity %s does not match format tenantId:username", + tenantIdAndUsername), null); + } + this.tenantId = tenantIdAndUsername.substring(0, tenantIdAndUsername.indexOf(':')); + String username = tenantIdAndUsername.substring(tenantIdAndUsername.indexOf(':') + 1); + this.basicAuthentication = new BasicAuthentication(username, password, crypto); + } + + @Override + public HttpRequest filter(HttpRequest request) throws HttpException { + return basicAuthentication.filter(ModifyRequest.replaceHeader(request, "TID", tenantId)); + } +} \ No newline at end of file diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/filters/StripExtraAcceptHeader.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/filters/StripExtraAcceptHeader.java new file mode 100644 index 0000000000..3130533c9e --- /dev/null +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/filters/StripExtraAcceptHeader.java @@ -0,0 +1,43 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.snia.cdmi.v1.filters; + +import javax.inject.Singleton; + +import org.jclouds.http.HttpException; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpRequestFilter; +import org.jclouds.http.utils.ModifyRequest; + +/** + * current CDMI spec doesn't indicate the form of the response. It would be nice, if it could take 2 + * {@code Accept} headers. Until then, let's strip off the mediaType header, which we use to ensure + * responses are parsed with json. + * + * @author Adrian Cole + * + */ +@Singleton +public class StripExtraAcceptHeader implements HttpRequestFilter { + + @Override + public HttpRequest filter(HttpRequest request) throws HttpException { + return ModifyRequest.replaceHeader(request, "Accept", request.getFirstHeaderOrNull("Accept")); + } +} \ No newline at end of file diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/handlers/CDMIErrorHandler.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/handlers/CDMIErrorHandler.java new file mode 100644 index 0000000000..30f51c0758 --- /dev/null +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/handlers/CDMIErrorHandler.java @@ -0,0 +1,82 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.snia.cdmi.v1.handlers; + +import static org.jclouds.http.HttpUtils.closeClientButKeepContentStream; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.inject.Singleton; + +import org.jclouds.blobstore.ContainerNotFoundException; +import org.jclouds.blobstore.KeyNotFoundException; +import org.jclouds.http.HttpCommand; +import org.jclouds.http.HttpErrorHandler; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.HttpResponseException; +import org.jclouds.rest.AuthorizationException; + +/** + * This will parse and set an appropriate exception on the command data. + * + * @author Adrian Cole + * + */ +// TODO: is there error spec someplace? let's type errors, etc. +@Singleton +public class CDMIErrorHandler implements HttpErrorHandler { + public static final String PREFIX = "^/v[0-9][^/]*/[a-zA-Z]+_[^/]+/"; + public static final Pattern CONTAINER_PATH = Pattern.compile(PREFIX + "([^/]+)$"); + public static final Pattern CONTAINER_KEY_PATH = Pattern.compile(PREFIX + "([^/]+)/(.*)"); + + public void handleError(HttpCommand command, HttpResponse response) { + // it is important to always read fully and close streams + byte[] data = closeClientButKeepContentStream(response); + String message = data != null ? new String(data) : null; + + Exception exception = message != null ? new HttpResponseException(command, response, message) + : new HttpResponseException(command, response); + message = message != null ? message : String.format("%s -> %s", command.getCurrentRequest().getRequestLine(), + response.getStatusLine()); + switch (response.getStatusCode()) { + case 401: + exception = new AuthorizationException(exception.getMessage(), exception); + break; + case 404: + if (!command.getCurrentRequest().getMethod().equals("DELETE")) { + String path = command.getCurrentRequest().getEndpoint().getPath(); + Matcher matcher = CONTAINER_PATH.matcher(path); + Exception oldException = exception; + if (matcher.find()) { + exception = new ContainerNotFoundException(matcher.group(1), message); + exception.initCause(oldException); + } else { + matcher = CONTAINER_KEY_PATH.matcher(path); + if (matcher.find()) { + exception = new KeyNotFoundException(matcher.group(1), matcher.group(2), message); + exception.initCause(oldException); + } + } + } + break; + } + command.setException(exception); + } +} diff --git a/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/options/ListContainersOptions.java b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/options/ListContainersOptions.java new file mode 100644 index 0000000000..efa468f48e --- /dev/null +++ b/labs/cdmi/src/main/java/org/jclouds/snia/cdmi/v1/options/ListContainersOptions.java @@ -0,0 +1,78 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.snia.cdmi.v1.options; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; + +import org.jclouds.http.options.BaseHttpRequestOptions; + +/** + * Contains options supported in the REST API for the GET container operation.

+ */ +public class ListContainersOptions extends BaseHttpRequestOptions { + public static final ListContainersOptions NONE = new ListContainersOptions(); + + /** + * Given a string value x, return data names greater in value than the specified marker. + */ + public ListContainersOptions marker(String marker) { + queryParameters.put("marker", checkNotNull(marker, "marker")); + return this; + } + + public String getMarker() { + return getFirstQueryOrNull("marker"); + } + + /** + * For an integer value n, limits the number of results to n values. + */ + public ListContainersOptions limit(int limit) { + checkState(limit >= 0, "limit must be >= 0"); + checkState(limit <= 10000, "limit must be <= 10000"); + queryParameters.put("limit", Integer.toString(limit)); + return this; + } + + public int getLimit() { + String val = getFirstQueryOrNull("limit"); + return val != null ? new Integer(val) : 10000; + } + + public static class Builder { + + /** + * @see ListContainersOptions#marker(String) + */ + public static ListContainersOptions marker(String marker) { + ListContainersOptions options = new ListContainersOptions(); + return options.marker(marker); + } + + /** + * @see ListContainersOptions#limit(int) + */ + public static ListContainersOptions limit(int limit) { + ListContainersOptions options = new ListContainersOptions(); + return options.limit(limit); + } + + } +} diff --git a/labs/cdmi/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata b/labs/cdmi/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata new file mode 100644 index 0000000000..19b5767f88 --- /dev/null +++ b/labs/cdmi/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata @@ -0,0 +1 @@ +org.jclouds.snia.cdmi.v1.CDMIApiMetadata diff --git a/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/CDMIApiMetadataTest.java b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/CDMIApiMetadataTest.java new file mode 100644 index 0000000000..3a967e51ad --- /dev/null +++ b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/CDMIApiMetadataTest.java @@ -0,0 +1,38 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.snia.cdmi.v1; + +import org.jclouds.View; +import org.jclouds.apis.internal.BaseApiMetadataTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.common.reflect.TypeToken; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "CDMIApiMetadataTest") +// public class CDMIApiMetadataTest extends BaseBlobStoreApiMetadataTest { +public class CDMIApiMetadataTest extends BaseApiMetadataTest { + public CDMIApiMetadataTest() { + super(new CDMIApiMetadata(), ImmutableSet.> of()); + } +} diff --git a/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/CDMIErrorHandlerTest.java b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/CDMIErrorHandlerTest.java new file mode 100644 index 0000000000..1d114a0502 --- /dev/null +++ b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/CDMIErrorHandlerTest.java @@ -0,0 +1,120 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.snia.cdmi.v1; + +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.reportMatcher; +import static org.easymock.EasyMock.verify; + +import java.net.URI; + +import org.easymock.IArgumentMatcher; +import org.jclouds.blobstore.ContainerNotFoundException; +import org.jclouds.blobstore.KeyNotFoundException; +import org.jclouds.http.HttpCommand; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.io.Payloads; +import org.jclouds.snia.cdmi.v1.handlers.CDMIErrorHandler; +import org.jclouds.util.Strings2; +import org.testng.annotations.Test; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "CDMIErrorHandlerTest") +public class CDMIErrorHandlerTest { + + @Test + public void test404SetsKeyNotFoundExceptionMosso() { + assertCodeMakes("HEAD", URI + .create("http://host/v1/MossoCloudFS_7064cdb1d49d4dcba3c899ac33e8409d/adriancole-blobstore1/key"), 404, + "Not Found", "", KeyNotFoundException.class); + } + + @Test + public void test404SetsKeyNotFoundExceptionCDMI() { + assertCodeMakes("HEAD", URI + .create("http://67.202.39.175:8080/v1/AUTH_7064cdb1d49d4dcba3c899ac33e8409d/adriancole-blobstore1/key"), + 404, "Not Found", "", KeyNotFoundException.class); + } + + @Test + public void test404SetsContainerNotFoundExceptionMosso() { + assertCodeMakes("HEAD", URI + .create("http://host/v1/MossoCloudFS_7064cdb1d49d4dcba3c899ac33e8409d/adriancole-blobstore1"), 404, + "Not Found", "", ContainerNotFoundException.class); + } + + @Test + public void test404SetsContainerNotFoundExceptionCDMI() { + assertCodeMakes("HEAD", URI + .create("http://67.202.39.175:8080/v1/AUTH_7064cdb1d49d4dcba3c899ac33e8409d/adriancole-blobstore1"), + 404, "Not Found", "", ContainerNotFoundException.class); + } + + private void assertCodeMakes(String method, URI uri, int statusCode, String message, String content, + Class expected) { + assertCodeMakes(method, uri, statusCode, message, "text/plain", content, expected); + } + + private void assertCodeMakes(String method, URI uri, int statusCode, String message, String contentType, + String content, Class expected) { + + CDMIErrorHandler function = new CDMIErrorHandler(); + + HttpCommand command = createMock(HttpCommand.class); + HttpRequest request = new HttpRequest(method, uri); + HttpResponse response = new HttpResponse(statusCode, message, Payloads.newInputStreamPayload(Strings2 + .toInputStream(content))); + response.getPayload().getContentMetadata().setContentType(contentType); + + expect(command.getCurrentRequest()).andReturn(request).atLeastOnce(); + command.setException(classEq(expected)); + + replay(command); + + function.handleError(command, response); + + verify(command); + } + + public static Exception classEq(final Class in) { + reportMatcher(new IArgumentMatcher() { + + @Override + public void appendTo(StringBuffer buffer) { + buffer.append("classEq("); + buffer.append(in); + buffer.append(")"); + } + + @Override + public boolean matches(Object arg) { + return arg.getClass() == in; + } + + }); + return null; + } + +} diff --git a/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/ContainerClientExpectTest.java b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/ContainerClientExpectTest.java new file mode 100644 index 0000000000..95d8899c83 --- /dev/null +++ b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/ContainerClientExpectTest.java @@ -0,0 +1,66 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.snia.cdmi.v1.features; + +import static org.testng.Assert.assertEquals; + +import java.net.URI; + +import org.jclouds.crypto.CryptoStreams; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.snia.cdmi.v1.CDMIClient; +import org.jclouds.snia.cdmi.v1.internal.BaseCDMIClientExpectTest; +import org.jclouds.snia.cdmi.v1.parse.ParseContainerTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMultimap; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "ContainerAsyncClientTest") +public class ContainerClientExpectTest extends BaseCDMIClientExpectTest { + + public void testGetContainerWhenResponseIs2xx() throws Exception { + + HttpRequest getContainer = HttpRequest + .builder() + .method("GET") + .endpoint(URI.create("http://localhost:8080/MyContainer/")) + .headers(ImmutableMultimap. builder() + .put("X-CDMI-Specification-Version", "1.0.1") + .put("Accept", "application/cdmi-container") + .put("TID", "tenantId") + .put("Authorization", "Basic " + CryptoStreams.base64("username:password".getBytes())) + .build()) + .build(); + + HttpResponse getContainerResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResource("/container.json")).build(); + + CDMIClient clientWhenContainersExist = requestSendsResponse(getContainer, getContainerResponse); + + assertEquals( + clientWhenContainersExist.getContainerClient().getContainer("MyContainer"), + new ParseContainerTest().expected()); + } + +} diff --git a/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/ContainerClientLiveTest.java b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/ContainerClientLiveTest.java new file mode 100644 index 0000000000..1ee33f40f8 --- /dev/null +++ b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/ContainerClientLiveTest.java @@ -0,0 +1,48 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.snia.cdmi.v1.features; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +import org.jclouds.snia.cdmi.v1.ObjectTypes; +import org.jclouds.snia.cdmi.v1.domain.Container; +import org.jclouds.snia.cdmi.v1.internal.BaseCDMIClientLiveTest; +import org.testng.annotations.Test; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "live", testName = "ContainerClientLiveTest") +public class ContainerClientLiveTest extends BaseCDMIClientLiveTest { + + @Test + public void testGetContainer() throws Exception { + ContainerClient client = cdmiContext.getApi().getContainerClient(); + Container container = client.getContainer("TODO: figure out how to list containers"); + assertNotNull(container); + assertEquals(container.getObjectType(), ObjectTypes.CONTAINER); + assertNotNull(container.getObjectID()); + assertNotNull(container.getObjectName()); + assertNotNull(container.getChildren()); + assertNotNull(container.getMetadata()); + } + +} diff --git a/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/DataClientExpectTest.java b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/DataClientExpectTest.java new file mode 100644 index 0000000000..8ca2a21af2 --- /dev/null +++ b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/DataClientExpectTest.java @@ -0,0 +1,30 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.snia.cdmi.v1.features; + +import org.jclouds.snia.cdmi.v1.internal.BaseCDMIClientExpectTest; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "DataAsyncClientTest") +public class DataClientExpectTest extends BaseCDMIClientExpectTest { + +} diff --git a/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/DataClientLiveTest.java b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/DataClientLiveTest.java new file mode 100644 index 0000000000..0d1a07fc3c --- /dev/null +++ b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/DataClientLiveTest.java @@ -0,0 +1,30 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.snia.cdmi.v1.features; + +import org.jclouds.snia.cdmi.v1.internal.BaseCDMIClientLiveTest; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(groups = "live", testName = "DataClientLiveTest") +public class DataClientLiveTest extends BaseCDMIClientLiveTest { + +} diff --git a/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/DomainClientExpectTest.java b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/DomainClientExpectTest.java new file mode 100644 index 0000000000..368f99fb06 --- /dev/null +++ b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/DomainClientExpectTest.java @@ -0,0 +1,30 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unles required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either expres or implied. See the License for the + * specific language governing permisions and limitations + * under the License. + */ +package org.jclouds.snia.cdmi.v1.features; + +import org.jclouds.snia.cdmi.v1.internal.BaseCDMIClientExpectTest; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "DomainClientExpectTest") +public class DomainClientExpectTest extends BaseCDMIClientExpectTest { + +} diff --git a/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/DomainClientLiveTest.java b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/DomainClientLiveTest.java new file mode 100644 index 0000000000..6d21f4d66f --- /dev/null +++ b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/features/DomainClientLiveTest.java @@ -0,0 +1,30 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.snia.cdmi.v1.features; + +import org.jclouds.snia.cdmi.v1.internal.BaseCDMIClientLiveTest; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(groups = "live", testName = "ContainerClientLiveTest") +public class DomainClientLiveTest extends BaseCDMIClientLiveTest { + +} diff --git a/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/internal/BaseCDMIAsyncClientExpectTest.java b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/internal/BaseCDMIAsyncClientExpectTest.java new file mode 100644 index 0000000000..46ca56bc76 --- /dev/null +++ b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/internal/BaseCDMIAsyncClientExpectTest.java @@ -0,0 +1,39 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.snia.cdmi.v1.internal; + +import java.util.Properties; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.snia.cdmi.v1.CDMIAsyncClient; + +import com.google.common.base.Function; +import com.google.inject.Module; + +/** + * Base class for writing KeyStone Rest Client Expect tests + * + * @author Adrian Cole + */ +public class BaseCDMIAsyncClientExpectTest extends BaseCDMIExpectTest { + public CDMIAsyncClient createClient(Function fn, Module module, Properties props) { + return createInjector(fn, module, props).getInstance(CDMIAsyncClient.class); + } +} diff --git a/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/internal/BaseCDMIClientExpectTest.java b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/internal/BaseCDMIClientExpectTest.java new file mode 100644 index 0000000000..2e6871e9dc --- /dev/null +++ b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/internal/BaseCDMIClientExpectTest.java @@ -0,0 +1,30 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.snia.cdmi.v1.internal; + +import org.jclouds.snia.cdmi.v1.CDMIClient; + +/** + * Base class for writing KeyStone Rest Client Expect tests + * + * @author Adrian Cole + */ +public class BaseCDMIClientExpectTest extends BaseCDMIExpectTest { + +} diff --git a/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/internal/BaseCDMIClientLiveTest.java b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/internal/BaseCDMIClientLiveTest.java new file mode 100644 index 0000000000..0958b6e73b --- /dev/null +++ b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/internal/BaseCDMIClientLiveTest.java @@ -0,0 +1,64 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.snia.cdmi.v1.internal; + +import org.jclouds.apis.BaseContextLiveTest; +import org.jclouds.rest.RestContext; +import org.jclouds.snia.cdmi.v1.CDMIApiMetadata; +import org.jclouds.snia.cdmi.v1.CDMIAsyncClient; +import org.jclouds.snia.cdmi.v1.CDMIClient; +import org.testng.annotations.AfterGroups; +import org.testng.annotations.BeforeGroups; +import org.testng.annotations.Test; + +import com.google.common.reflect.TypeToken; + +/** + * Tests behavior of {@code CDMIClient} + * + * @author Adrian Cole + */ +@Test(groups = "live") +public class BaseCDMIClientLiveTest extends BaseContextLiveTest> { + + public BaseCDMIClientLiveTest() { + provider = "cdmi"; + } + + protected RestContext cdmiContext; + + @BeforeGroups(groups = { "integration", "live" }) + @Override + public void setupContext() { + super.setupContext(); + cdmiContext = context; + } + + @AfterGroups(groups = "live") + protected void tearDown() { + if (cdmiContext != null) + cdmiContext.close(); + } + + @Override + protected TypeToken> contextType() { + return CDMIApiMetadata.CONTEXT_TOKEN; + } + +} diff --git a/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/internal/BaseCDMIExpectTest.java b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/internal/BaseCDMIExpectTest.java new file mode 100644 index 0000000000..84457451ec --- /dev/null +++ b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/internal/BaseCDMIExpectTest.java @@ -0,0 +1,36 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.snia.cdmi.v1.internal; + +import org.jclouds.rest.internal.BaseRestClientExpectTest; + +/** + * Base class for writing CDMI Expect tests + * + * @author Adrian Cole + */ +public class BaseCDMIExpectTest extends BaseRestClientExpectTest { + + public BaseCDMIExpectTest() { + provider = "cdmi"; + // now, createContext arg will need tenant prefix + identity = "tenantId:username"; + credential = "password"; + } +} diff --git a/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/options/ListContainersOptionsTest.java b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/options/ListContainersOptionsTest.java new file mode 100644 index 0000000000..7753483dda --- /dev/null +++ b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/options/ListContainersOptionsTest.java @@ -0,0 +1,96 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.snia.cdmi.v1.options; + +import static org.jclouds.snia.cdmi.v1.options.ListContainersOptions.Builder.limit; +import static org.jclouds.snia.cdmi.v1.options.ListContainersOptions.Builder.marker; +import static org.testng.Assert.assertEquals; + +import java.util.Collections; + +import org.jclouds.http.options.HttpRequestOptions; +import org.testng.annotations.Test; + +/** + * Tests possible uses of ListContainerOptions and ListContainerOptions.Builder.* + * + * @author Adrian Cole + */ +@Test(testName = "ListContainersOptionsTest") +public class ListContainersOptionsTest { + + @Test + public void testAssignability() { + assert HttpRequestOptions.class.isAssignableFrom(ListContainersOptions.class); + assert !String.class.isAssignableFrom(ListContainersOptions.class); + } + @Test + public void testNoOptionsQueryString() { + HttpRequestOptions options = new ListContainersOptions(); + assertEquals(options.buildQueryParameters().size(), 0); + } + + @Test + public void testMarker() { + ListContainersOptions options = new ListContainersOptions(); + options.marker("test"); + assertEquals(options.buildQueryParameters().get("marker"), Collections.singletonList("test")); + } + + @Test + public void testNullMarker() { + ListContainersOptions options = new ListContainersOptions(); + assertEquals(options.buildQueryParameters().get("marker"), Collections.EMPTY_LIST); + } + + @Test + public void testMarkerStatic() { + ListContainersOptions options = marker("test"); + assertEquals(options.buildQueryParameters().get("marker"), Collections.singletonList("test")); + } + + @Test(expectedExceptions = NullPointerException.class) + public void testMarkerNPE() { + marker(null); + } + + @Test + public void testLimit() { + ListContainersOptions options = new ListContainersOptions(); + options.limit(1000); + assertEquals(options.buildQueryParameters().get("limit"), Collections.singletonList("1000")); + } + + @Test + public void testNullLimit() { + ListContainersOptions options = new ListContainersOptions(); + assertEquals(options.buildQueryParameters().get("limit"), Collections.EMPTY_LIST); + } + + @Test + public void testLimitStatic() { + ListContainersOptions options = limit(1000); + assertEquals(options.buildQueryParameters().get("limit"), Collections.singletonList("1000")); + } + + @Test(expectedExceptions = IllegalStateException.class) + public void testLimitNegative() { + limit(-1); + } +} diff --git a/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/parse/ParseContainerTest.java b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/parse/ParseContainerTest.java new file mode 100644 index 0000000000..14fea2114b --- /dev/null +++ b/labs/cdmi/src/test/java/org/jclouds/snia/cdmi/v1/parse/ParseContainerTest.java @@ -0,0 +1,58 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.snia.cdmi.v1.parse; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.json.BaseItemParserTest; +import org.jclouds.snia.cdmi.v1.domain.Container; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "ParseContainerTest") +public class ParseContainerTest extends BaseItemParserTest { + + @Override + public String resource() { + return "/container.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public Container expected() { + return Container.builder() + .objectType("application/cdmi-container") + .objectID("00007E7F00102E230ED82694DAA975D2") + .objectName("MyContainer/") + .metadata(ImmutableMap.builder() + .put("cdmi_size", "83") + .build()) + .children(ImmutableSet.builder() + .add("MyDataObject.txt") + .build()) + .build(); + } +} diff --git a/labs/cdmi/src/test/resources/container.json b/labs/cdmi/src/test/resources/container.json new file mode 100644 index 0000000000..601a54d529 --- /dev/null +++ b/labs/cdmi/src/test/resources/container.json @@ -0,0 +1,17 @@ +{ + "objectType" : "application/cdmi-container", + "objectID" : "00007E7F00102E230ED82694DAA975D2", + "objectName" : "MyContainer/", + "parentURI" : "/", + "parentID" : "00007E7F0010128E42D87EE34F5A6560", + "domainURI" : "/cdmi_domains/MyDomain/", + "capabilitiesURI" : "/cdmi_capabilities/container/", + "completionStatus" : "Complete", + "metadata" : { + "cdmi_size" : "83" + }, + "childrenrange" : "0-0", + "children" : [ + "MyDataObject.txt" + ] +} \ No newline at end of file diff --git a/labs/cdmi/src/test/resources/logback.xml b/labs/cdmi/src/test/resources/logback.xml new file mode 100644 index 0000000000..bd89efb8c0 --- /dev/null +++ b/labs/cdmi/src/test/resources/logback.xml @@ -0,0 +1,51 @@ + + + + target/test-data/jclouds.log + + + %d %-5p [%c] [%thread] %m%n + + + + + target/test-data/jclouds-wire.log + + + %d %-5p [%c] [%thread] %m%n + + + + + target/test-data/jclouds-blobstore.log + + + %d %-5p [%c] [%thread] %m%n + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/labs/pom.xml b/labs/pom.xml index a6d3e22750..8b18e076f1 100644 --- a/labs/pom.xml +++ b/labs/pom.xml @@ -43,5 +43,6 @@ carrenza-vcloud-director openstack-swift jenkins + cdmi