Repository: jclouds-labs-openstack Updated Branches: refs/heads/master d86884356 -> 6af7f8987
Initial OpenStack Heat skeleton with ResourceApi listTypes() method Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/repo Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/commit/6af7f898 Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/tree/6af7f898 Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/diff/6af7f898 Branch: refs/heads/master Commit: 6af7f898708d19afd81e7ffcfa29e1fc9967b72c Parents: d868843 Author: Jeremy Daggett <[email protected]> Authored: Mon Sep 1 23:49:14 2014 -0700 Committer: Jeremy Daggett <[email protected]> Committed: Thu Sep 11 08:13:54 2014 -0700 ---------------------------------------------------------------------- openstack-heat/README.md | 14 ++ openstack-heat/pom.xml | 145 ++++++++++++ .../org/jclouds/openstack/heat/v1/HeatApi.java | 45 ++++ .../openstack/heat/v1/HeatApiMetadata.java | 90 ++++++++ .../heat/v1/config/HeatHttpApiModule.java | 45 ++++ .../openstack/heat/v1/features/ResourceApi.java | 48 ++++ .../heat/v1/handlers/HeatErrorHandler.java | 52 +++++ .../services/org.jclouds.apis.ApiMetadata | 18 ++ .../openstack/heat/v1/HeatApiMetadataTest.java | 34 +++ .../heat/v1/features/ResourceApiLiveTest.java | 40 ++++ .../heat/v1/features/ResourceApiMockTest.java | 92 ++++++++ .../heat/v1/internal/BaseHeatApiLiveTest.java | 44 ++++ .../heat/v1/internal/BaseHeatApiMockTest.java | 39 ++++ openstack-heat/src/test/resources/access.json | 228 +++++++++++++++++++ openstack-heat/src/test/resources/logback.xml | 58 +++++ .../resources/resource_type_list_response.json | 24 ++ pom.xml | 1 + 17 files changed, 1017 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/6af7f898/openstack-heat/README.md ---------------------------------------------------------------------- diff --git a/openstack-heat/README.md b/openstack-heat/README.md new file mode 100644 index 0000000..c7bca21 --- /dev/null +++ b/openstack-heat/README.md @@ -0,0 +1,14 @@ +#OpenStack Heat +================ + +OpenStack Heat is a template-driven engine that allows application developers to describe and automate the deployment of infrastructure. The flexible template language can specify compute, storage and networking configurations as well as detailed post-deployment activity to automate the full provisioning of infrastructure as well as services and applications. + +##Running Live Tests +=== +To run the Heat live tests, execute the following command with your credentials and authentication endpoint: + + $ mvn clean install -Plive -Dtest.openstack-heat.identity=<username> -Dtest.openstack-heat.credential=<password> -Dtest.openstack-heat.endpoint=<keystone-auth-url> + +##Production ready? +=== +No. The OpenStack Heat API is a beta API and is subject to change during it's development. APIs have `@Beta` annotations where applicable. http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/6af7f898/openstack-heat/pom.xml ---------------------------------------------------------------------- diff --git a/openstack-heat/pom.xml b/openstack-heat/pom.xml new file mode 100644 index 0000000..6338e95 --- /dev/null +++ b/openstack-heat/pom.xml @@ -0,0 +1,145 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF 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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.jclouds</groupId> + <artifactId>jclouds-project</artifactId> + <version>2.0.0-SNAPSHOT</version> + <relativePath /> + </parent> + + <!-- TODO: when out of labs, switch to org.jclouds.api --> + <groupId>org.apache.jclouds.labs</groupId> + <artifactId>openstack-heat</artifactId> + <version>2.0.0-SNAPSHOT</version> + <name>Apache jclouds :: OpenStack :: Heat API</name> + <description>jclouds components to access an implementation of OpenStack Heat</description> + <packaging>bundle</packaging> + + <properties> + <!-- keystone endpoint --> + <test.openstack-heat.endpoint>http://localhost:5000/v2.0/</test.openstack-heat.endpoint> + <test.openstack-heat.api-version>1</test.openstack-heat.api-version> + <test.openstack-heat.build-version /> + <test.openstack-heat.identity>FIXME_IDENTITY</test.openstack-heat.identity> + <test.openstack-heat.credential>FIXME_CREDENTIALS</test.openstack-heat.credential> + <test.jclouds.keystone.credential-type>passwordCredentials</test.jclouds.keystone.credential-type> + <jclouds.osgi.export>org.jclouds.openstack.heat.v1*;version="${project.version}"</jclouds.osgi.export> + <jclouds.osgi.import>org.jclouds*;version="${project.version}",*</jclouds.osgi.import> + </properties> + + <repositories> + <repository> + <id>apache-snapshots</id> + <url>https://repository.apache.org/content/repositories/snapshots</url> + <releases> + <enabled>false</enabled> + </releases> + <snapshots> + <enabled>true</enabled> + </snapshots> + </repository> + </repositories> + + <dependencies> + <dependency> + <groupId>org.apache.jclouds.api</groupId> + <artifactId>openstack-keystone</artifactId> + <version>${project.parent.version}</version> + </dependency> + <dependency> + <groupId>org.apache.jclouds</groupId> + <artifactId>jclouds-core</artifactId> + <version>${project.parent.version}</version> + <type>test-jar</type> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.jclouds.api</groupId> + <artifactId>openstack-keystone</artifactId> + <version>${project.parent.version}</version> + <type>test-jar</type> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.jclouds.driver</groupId> + <artifactId>jclouds-slf4j</artifactId> + <version>${project.parent.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>ch.qos.logback</groupId> + <artifactId>logback-classic</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.squareup.okhttp</groupId> + <artifactId>mockwebserver</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <version>1.6.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-guava</artifactId> + <version>1.2.0</version> + <scope>test</scope> + </dependency> + </dependencies> + + <profiles> + <profile> + <id>live</id> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <executions> + <execution> + <id>integration</id> + <phase>integration-test</phase> + <goals> + <goal>test</goal> + </goals> + <configuration> + <systemPropertyVariables> + <test.openstack-heat.endpoint>${test.openstack-heat.endpoint}</test.openstack-heat.endpoint> + <test.openstack-heat.api-version>${test.openstack-heat.api-version}</test.openstack-heat.api-version> + <test.openstack-heat.build-version>${test.openstack-heat.build-version}</test.openstack-heat.build-version> + <test.openstack-heat.identity>${test.openstack-heat.identity}</test.openstack-heat.identity> + <test.openstack-heat.credential>${test.openstack-heat.credential}</test.openstack-heat.credential> + <test.jclouds.keystone.credential-type>${test.jclouds.keystone.credential-type}</test.jclouds.keystone.credential-type> + </systemPropertyVariables> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + </profiles> + +</project> http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/6af7f898/openstack-heat/src/main/java/org/jclouds/openstack/heat/v1/HeatApi.java ---------------------------------------------------------------------- diff --git a/openstack-heat/src/main/java/org/jclouds/openstack/heat/v1/HeatApi.java b/openstack-heat/src/main/java/org/jclouds/openstack/heat/v1/HeatApi.java new file mode 100644 index 0000000..e1f9e25 --- /dev/null +++ b/openstack-heat/src/main/java/org/jclouds/openstack/heat/v1/HeatApi.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.openstack.heat.v1; + +import java.io.Closeable; +import java.util.Set; + +import org.jclouds.location.Region; +import org.jclouds.location.functions.RegionToEndpoint; +import org.jclouds.openstack.heat.v1.features.ResourceApi; +import org.jclouds.rest.annotations.Delegate; +import org.jclouds.rest.annotations.EndpointParam; + +import com.google.inject.Provides; + +/** + * Provides access to the OpenStack Orchestration (Heat) API. + * + */ +public interface HeatApi extends Closeable { + + @Provides + @Region + Set<String> getConfiguredRegions(); + + /** + * Provides access to Resource features. + */ + @Delegate + ResourceApi getResourceApi(@EndpointParam(parser = RegionToEndpoint.class) String region); +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/6af7f898/openstack-heat/src/main/java/org/jclouds/openstack/heat/v1/HeatApiMetadata.java ---------------------------------------------------------------------- diff --git a/openstack-heat/src/main/java/org/jclouds/openstack/heat/v1/HeatApiMetadata.java b/openstack-heat/src/main/java/org/jclouds/openstack/heat/v1/HeatApiMetadata.java new file mode 100644 index 0000000..f8f6d77 --- /dev/null +++ b/openstack-heat/src/main/java/org/jclouds/openstack/heat/v1/HeatApiMetadata.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.openstack.heat.v1; + +import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE; +import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.SERVICE_TYPE; + +import java.net.URI; +import java.util.Properties; + +import org.jclouds.apis.ApiMetadata; +import org.jclouds.openstack.heat.v1.config.HeatHttpApiModule; +import org.jclouds.openstack.keystone.v2_0.config.AuthenticationApiModule; +import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes; +import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule; +import org.jclouds.openstack.keystone.v2_0.config.KeystoneAuthenticationModule.RegionModule; +import org.jclouds.rest.internal.BaseHttpApiMetadata; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Module; + +/** + * Implementation of {@link ApiMetadata} for the Heat API. + */ +public class HeatApiMetadata extends BaseHttpApiMetadata<HeatApi> { + + @Override + public Builder toBuilder() { + return new Builder().fromApiMetadata(this); + } + + public HeatApiMetadata() { + this(new Builder()); + } + + protected HeatApiMetadata(Builder builder) { + super(builder); + } + + public static Properties defaultProperties() { + Properties properties = BaseHttpApiMetadata.defaultProperties(); + properties.setProperty(SERVICE_TYPE, "orchestration"); + properties.setProperty(CREDENTIAL_TYPE, CredentialTypes.PASSWORD_CREDENTIALS); + return properties; + } + + public static class Builder extends BaseHttpApiMetadata.Builder<HeatApi, Builder> { + + protected Builder() { + id("openstack-heat") + .name("OpenStack Heat API") + .identityName("${tenantName}:${userName} or ${userName}, if your keystone supports a default tenant") + .credentialName("${password}") + .documentation(URI.create("https://wiki.openstack.org/wiki/Heat")) + .version("1") + .endpointName("Keystone base url ending in /v2.0/") + .defaultEndpoint("http://localhost:5000/v2.0/") + .defaultProperties(HeatApiMetadata.defaultProperties()) + .defaultModules(ImmutableSet.<Class<? extends Module>>builder() + .add(AuthenticationApiModule.class) + .add(KeystoneAuthenticationModule.class) + .add(RegionModule.class) + .add(HeatHttpApiModule.class).build()); + } + + @Override + public HeatApiMetadata build() { + return new HeatApiMetadata(this); + } + + @Override + protected Builder self() { + return this; + } + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/6af7f898/openstack-heat/src/main/java/org/jclouds/openstack/heat/v1/config/HeatHttpApiModule.java ---------------------------------------------------------------------- diff --git a/openstack-heat/src/main/java/org/jclouds/openstack/heat/v1/config/HeatHttpApiModule.java b/openstack-heat/src/main/java/org/jclouds/openstack/heat/v1/config/HeatHttpApiModule.java new file mode 100644 index 0000000..c381ea1 --- /dev/null +++ b/openstack-heat/src/main/java/org/jclouds/openstack/heat/v1/config/HeatHttpApiModule.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.openstack.heat.v1.config; + +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.json.config.GsonModule.DateAdapter; +import org.jclouds.json.config.GsonModule.Iso8601DateAdapter; +import org.jclouds.openstack.heat.v1.HeatApi; +import org.jclouds.openstack.heat.v1.handlers.HeatErrorHandler; +import org.jclouds.rest.ConfiguresHttpApi; +import org.jclouds.rest.config.HttpApiModule; + +@ConfiguresHttpApi +public class HeatHttpApiModule extends HttpApiModule<HeatApi> { + + @Override + protected void configure() { + bind(DateAdapter.class).to(Iso8601DateAdapter.class); + super.configure(); + } + + @Override + protected void bindErrorHandlers() { + bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(HeatErrorHandler.class); + bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(HeatErrorHandler.class); + bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(HeatErrorHandler.class); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/6af7f898/openstack-heat/src/main/java/org/jclouds/openstack/heat/v1/features/ResourceApi.java ---------------------------------------------------------------------- diff --git a/openstack-heat/src/main/java/org/jclouds/openstack/heat/v1/features/ResourceApi.java b/openstack-heat/src/main/java/org/jclouds/openstack/heat/v1/features/ResourceApi.java new file mode 100644 index 0000000..a1391b3 --- /dev/null +++ b/openstack-heat/src/main/java/org/jclouds/openstack/heat/v1/features/ResourceApi.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.openstack.heat.v1.features; + +import java.util.List; + +import javax.inject.Named; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.core.MediaType; + +import org.jclouds.Fallbacks.EmptyListOnNotFoundOr404; +import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; +import org.jclouds.rest.annotations.Fallback; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.SelectJson; + + +/** + * Provides access to Resource features. + * + */ +@RequestFilters(AuthenticateRequest.class) +@Consumes(MediaType.APPLICATION_JSON) +public interface ResourceApi { + + @Named("resource:listTypes") + @GET + @SelectJson("resource_types") + @Path("/resource_types") + @Fallback(EmptyListOnNotFoundOr404.class) + List<String> listTypes(); +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/6af7f898/openstack-heat/src/main/java/org/jclouds/openstack/heat/v1/handlers/HeatErrorHandler.java ---------------------------------------------------------------------- diff --git a/openstack-heat/src/main/java/org/jclouds/openstack/heat/v1/handlers/HeatErrorHandler.java b/openstack-heat/src/main/java/org/jclouds/openstack/heat/v1/handlers/HeatErrorHandler.java new file mode 100644 index 0000000..1ef2e05 --- /dev/null +++ b/openstack-heat/src/main/java/org/jclouds/openstack/heat/v1/handlers/HeatErrorHandler.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.openstack.heat.v1.handlers; + +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; + +import static org.jclouds.http.HttpUtils.closeClientButKeepContentStream; + +public class HeatErrorHandler implements HttpErrorHandler { + + public void handleError(HttpCommand command, HttpResponse response) { + // it is important to always read fully and close streams + byte[] data = closeClientButKeepContentStream(response); + Exception exception; + + if (data == null) { + exception = new HttpResponseException(command, response); + } + else { + exception = new HttpResponseException(command, response, new String(data)); + } + + switch (response.getStatusCode()) { + case 401: + exception = new AuthorizationException(exception.getMessage(), exception); + break; + case 409: + exception = new IllegalStateException(exception.getMessage(), exception); + break; + } + + command.setException(exception); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/6af7f898/openstack-heat/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata ---------------------------------------------------------------------- diff --git a/openstack-heat/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata b/openstack-heat/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata new file mode 100644 index 0000000..2c1c816 --- /dev/null +++ b/openstack-heat/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata @@ -0,0 +1,18 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF 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. +# + +org.jclouds.openstack.heat.v1.HeatApiMetadata http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/6af7f898/openstack-heat/src/test/java/org/jclouds/openstack/heat/v1/HeatApiMetadataTest.java ---------------------------------------------------------------------- diff --git a/openstack-heat/src/test/java/org/jclouds/openstack/heat/v1/HeatApiMetadataTest.java b/openstack-heat/src/test/java/org/jclouds/openstack/heat/v1/HeatApiMetadataTest.java new file mode 100644 index 0000000..fe1720b --- /dev/null +++ b/openstack-heat/src/test/java/org/jclouds/openstack/heat/v1/HeatApiMetadataTest.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.openstack.heat.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; + +/** + * Tests the Heat {@link ApiMetadata}. + */ +@Test(groups = "unit", testName = "HeatApiMetadataTest") +public class HeatApiMetadataTest extends BaseApiMetadataTest { + public HeatApiMetadataTest() { + super(new HeatApiMetadata(), ImmutableSet.<TypeToken<? extends View>> of()); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/6af7f898/openstack-heat/src/test/java/org/jclouds/openstack/heat/v1/features/ResourceApiLiveTest.java ---------------------------------------------------------------------- diff --git a/openstack-heat/src/test/java/org/jclouds/openstack/heat/v1/features/ResourceApiLiveTest.java b/openstack-heat/src/test/java/org/jclouds/openstack/heat/v1/features/ResourceApiLiveTest.java new file mode 100644 index 0000000..d4967a8 --- /dev/null +++ b/openstack-heat/src/test/java/org/jclouds/openstack/heat/v1/features/ResourceApiLiveTest.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.openstack.heat.v1.features; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.List; + +import org.jclouds.openstack.heat.v1.internal.BaseHeatApiLiveTest; +import org.testng.annotations.Test; + +/** + * Tests parsing and Guice wiring of ResourceApi + */ +@Test(groups = "live", testName = "ResourceApiLiveTest") +public class ResourceApiLiveTest extends BaseHeatApiLiveTest { + + public void testListTypes() { + for (String region : filterRegions(api.getConfiguredRegions())) { + ResourceApi resourceApi = api.getResourceApi(region); + + List<String> resourceTypes = resourceApi.listTypes(); + assertThat(resourceTypes).isNotNull(); + } + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/6af7f898/openstack-heat/src/test/java/org/jclouds/openstack/heat/v1/features/ResourceApiMockTest.java ---------------------------------------------------------------------- diff --git a/openstack-heat/src/test/java/org/jclouds/openstack/heat/v1/features/ResourceApiMockTest.java b/openstack-heat/src/test/java/org/jclouds/openstack/heat/v1/features/ResourceApiMockTest.java new file mode 100644 index 0000000..47e4c52 --- /dev/null +++ b/openstack-heat/src/test/java/org/jclouds/openstack/heat/v1/features/ResourceApiMockTest.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.openstack.heat.v1.features; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.List; + +import org.jclouds.openstack.heat.v1.HeatApi; +import org.jclouds.openstack.heat.v1.internal.BaseHeatApiMockTest; +import org.testng.annotations.Test; + +import com.squareup.okhttp.mockwebserver.MockResponse; +import com.squareup.okhttp.mockwebserver.MockWebServer; + +/** + * Tests annotation parsing of {@code ResourceApi} + */ +@Test(groups = "unit", testName = "ResourceApiMockTest") +public class ResourceApiMockTest extends BaseHeatApiMockTest { + + public void testListTypes() throws Exception { + MockWebServer server = mockOpenStackServer(); + server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); + server.enqueue(addCommonHeaders( + new MockResponse().setResponseCode(200).setBody(stringFromResource("/resource_type_list_response.json")))); + + try { + HeatApi heatApi = api(server.getUrl("/").toString(), "openstack-heat", overrides); + ResourceApi api = heatApi.getResourceApi("RegionOne"); + + List<String> resourceTypes = api.listTypes(); + + /* + * Check request + */ + assertThat(server.getRequestCount()).isEqualTo(2); + assertAuthentication(server); + assertRequest(server.takeRequest(), "GET", BASE_URI + "/resource_types"); + + /* + * Check response + */ + assertThat(resourceTypes).isNotEmpty(); + assertThat(resourceTypes.size()).isEqualTo(20); + + } finally { + server.shutdown(); + } + } + + public void testListTypesIsEmpty() throws Exception { + MockWebServer server = mockOpenStackServer(); + server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json")))); + server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(404))); + + try { + HeatApi heatApi = api(server.getUrl("/").toString(), "openstack-heat", overrides); + ResourceApi api = heatApi.getResourceApi("RegionOne"); + + List<String> resourceTypes = api.listTypes(); + + /* + * Check request + */ + assertThat(server.getRequestCount()).isEqualTo(2); + assertAuthentication(server); + assertRequest(server.takeRequest(), "GET", BASE_URI + "/resource_types"); + + /* + * Check response + */ + assertThat(resourceTypes).isEmpty(); + } finally { + server.shutdown(); + } + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/6af7f898/openstack-heat/src/test/java/org/jclouds/openstack/heat/v1/internal/BaseHeatApiLiveTest.java ---------------------------------------------------------------------- diff --git a/openstack-heat/src/test/java/org/jclouds/openstack/heat/v1/internal/BaseHeatApiLiveTest.java b/openstack-heat/src/test/java/org/jclouds/openstack/heat/v1/internal/BaseHeatApiLiveTest.java new file mode 100644 index 0000000..1887024 --- /dev/null +++ b/openstack-heat/src/test/java/org/jclouds/openstack/heat/v1/internal/BaseHeatApiLiveTest.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.openstack.heat.v1.internal; + +import java.util.Properties; + +import org.jclouds.apis.BaseApiLiveTest; +import org.jclouds.openstack.heat.v1.HeatApi; +import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties; +import org.testng.annotations.Test; + +/** + * Tests behavior of {@link HeatApi}. + * + */ +@Test(groups = "live") +public class BaseHeatApiLiveTest extends BaseApiLiveTest<HeatApi> { + + public BaseHeatApiLiveTest() { + provider = "openstack-heat"; + } + + @Override + protected Properties setupProperties() { + Properties props = super.setupProperties(); + setIfTestSystemPropertyPresent(props, KeystoneProperties.CREDENTIAL_TYPE); + return props; + } + +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/6af7f898/openstack-heat/src/test/java/org/jclouds/openstack/heat/v1/internal/BaseHeatApiMockTest.java ---------------------------------------------------------------------- diff --git a/openstack-heat/src/test/java/org/jclouds/openstack/heat/v1/internal/BaseHeatApiMockTest.java b/openstack-heat/src/test/java/org/jclouds/openstack/heat/v1/internal/BaseHeatApiMockTest.java new file mode 100644 index 0000000..ebca4a5 --- /dev/null +++ b/openstack-heat/src/test/java/org/jclouds/openstack/heat/v1/internal/BaseHeatApiMockTest.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.openstack.heat.v1.internal; + +import java.util.Properties; + +import org.jclouds.openstack.heat.v1.HeatApi; +import org.jclouds.openstack.v2_0.internal.BaseOpenStackMockTest; + +/** + * Base class for writing Heat Mock tests + * + */ +public class BaseHeatApiMockTest extends BaseOpenStackMockTest<HeatApi> { + protected Properties overrides; + + protected static String BASE_URI = "/v1/da0d12be20394afb851716e10a49e4a7"; + + /** + * Base Mock Test + */ + public BaseHeatApiMockTest() { + overrides = new Properties(); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/6af7f898/openstack-heat/src/test/resources/access.json ---------------------------------------------------------------------- diff --git a/openstack-heat/src/test/resources/access.json b/openstack-heat/src/test/resources/access.json new file mode 100644 index 0000000..fab1645 --- /dev/null +++ b/openstack-heat/src/test/resources/access.json @@ -0,0 +1,228 @@ +{ + "access": { + "metadata": { + "roles": [ + "9fe2ff9ee4384b1894a90878d3e92bab", + "b926cb0f4e2642678735f86c2b06205e", + "33484487e73d4da0918a19b9c7e1f8ae", + "f2e54c2105fb49e29479af047115cebc" + ], + "is_admin": 0 + }, + "user": { + "name": "joe", + "roles": [ + { + "name": "_member_" + }, + { + "name": "anotherrole" + }, + { + "name": "heat_stack_owner" + }, + { + "name": "Member" + } + ], + "id": "8fbf8e68d36e4ac7bcf912a26213bd49", + "roles_links": [], + "username": "joe" + }, + "serviceCatalog": [ + { + "name": "nova", + "type": "compute", + "endpoints_links": [], + "endpoints": [ + { + "publicURL": "URL/v2/da0d12be20394afb851716e10a49e4a7", + "id": "2122bcaa704343c19ad2578410d4961d", + "internalURL": "URL/v2/da0d12be20394afb851716e10a49e4a7", + "region": "RegionOne", + "adminURL": "URL/v2/da0d12be20394afb851716e10a49e4a7" + } + ] + }, + { + "name": "neutron", + "type": "network", + "endpoints_links": [], + "endpoints": [ + { + "publicURL": "URL/", + "id": "65a4d3f13cfb49a6a57a04e205cc2158", + "internalURL": "URL/", + "region": "RegionOne", + "adminURL": "URL/" + } + ] + }, + { + "name": "cinderv2", + "type": "volumev2", + "endpoints_links": [], + "endpoints": [ + { + "publicURL": "URL/v2/da0d12be20394afb851716e10a49e4a7", + "id": "31fe4d92eac44044b05be21c6f44cebc", + "internalURL": "URL/v2/da0d12be20394afb851716e10a49e4a7", + "region": "RegionOne", + "adminURL": "URL/v2/da0d12be20394afb851716e10a49e4a7" + } + ] + }, + { + "name": "trove", + "type": "database", + "endpoints_links": [], + "endpoints": [ + { + "publicURL": "URL/v1.0/da0d12be20394afb851716e10a49e4a7", + "id": "06b7a7dbd25c4a01819c879700a9712a", + "internalURL": "URL/v1.0/da0d12be20394afb851716e10a49e4a7", + "region": "RegionOne", + "adminURL": "URL/v1.0/da0d12be20394afb851716e10a49e4a7" + } + ] + }, + { + "name": "s3", + "type": "s3", + "endpoints_links": [], + "endpoints": [ + { + "publicURL": "URL", + "id": "93b0b67091324e8ba01b62ee0584994c", + "internalURL": "URL", + "region": "RegionOne", + "adminURL": "URL" + } + ] + }, + { + "name": "glance", + "type": "image", + "endpoints_links": [], + "endpoints": [ + { + "publicURL": "URL", + "id": "a542e91bcfa046bfa1bf2397356d1414", + "internalURL": "URL", + "region": "RegionOne", + "adminURL": "URL" + } + ] + }, + { + "name": "novav3", + "type": "computev3", + "endpoints_links": [], + "endpoints": [ + { + "publicURL": "URL/v3", + "id": "9c3e8abb576d483db93bcef70c67bc1d", + "internalURL": "URL/v3", + "region": "RegionOne", + "adminURL": "URL/v3" + } + ] + }, + { + "name": "heat", + "type": "cloudformation", + "endpoints_links": [], + "endpoints": [ + { + "publicURL": "URL/v1", + "id": "6f4ca5ca9698425b85c300b3fc176c39", + "internalURL": "URL/v1", + "region": "RegionOne", + "adminURL": "URL/v1" + } + ] + }, + { + "name": "cinder", + "type": "volume", + "endpoints_links": [], + "endpoints": [ + { + "publicURL": "URL/v1/da0d12be20394afb851716e10a49e4a7", + "id": "037039c676694a35aa28d34fce09e51d", + "internalURL": "URL/v1/da0d12be20394afb851716e10a49e4a7", + "region": "RegionOne", + "adminURL": "URL/v1/da0d12be20394afb851716e10a49e4a7" + } + ] + }, + { + "name": "ec2", + "type": "ec2", + "endpoints_links": [], + "endpoints": [ + { + "publicURL": "URL/services/Cloud", + "id": "1d242631bccb4ff4ba7a395dbcb51648", + "internalURL": "URL/services/Cloud", + "region": "RegionOne", + "adminURL": "URL/services/Admin" + } + ] + }, + { + "name": "heat", + "type": "orchestration", + "endpoints_links": [], + "endpoints": [ + { + "publicURL": "URL/v1/da0d12be20394afb851716e10a49e4a7", + "id": "199d00075e4a40308a6ad2aa8980d0cd", + "internalURL": "URL/v1/da0d12be20394afb851716e10a49e4a7", + "region": "RegionOne", + "adminURL": "URL/v1/da0d12be20394afb851716e10a49e4a7" + } + ] + }, + { + "name": "swift", + "type": "object-store", + "endpoints_links": [], + "endpoints": [ + { + "publicURL": "URL/v1/AUTH_da0d12be20394afb851716e10a49e4a7", + "id": "26b2cb1efb044193b847fc3f2fb12e82", + "internalURL": "URL/v1/AUTH_da0d12be20394afb851716e10a49e4a7", + "region": "RegionOne", + "adminURL": "URL" + } + ] + }, + { + "name": "keystone", + "type": "identity", + "endpoints_links": [], + "endpoints": [ + { + "publicURL": "URL/v2.0", + "id": "1bbfe80b50df4c4a84040aa782e42140", + "internalURL": "URL/v2.0", + "region": "RegionOne", + "adminURL": "URL/v2.0" + } + ] + } + ], + "token": { + "tenant": { + "name": "jclouds", + "id": "da0d12be20394afb851716e10a49e4a7", + "enabled": true, + "description": null + }, + "id": "TOKEN", + "expires": "2014-04-28T22:48:24Z", + "issued_at": "2014-04-28T21:48:24.972896" + } + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/6af7f898/openstack-heat/src/test/resources/logback.xml ---------------------------------------------------------------------- diff --git a/openstack-heat/src/test/resources/logback.xml b/openstack-heat/src/test/resources/logback.xml new file mode 100644 index 0000000..6cb2617 --- /dev/null +++ b/openstack-heat/src/test/resources/logback.xml @@ -0,0 +1,58 @@ +<?xml version="1.0"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF 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. + +--> +<configuration scan="false"> + <appender name="FILE" class="ch.qos.logback.core.FileAppender"> + <file>target/test-data/jclouds.log</file> + + <encoder> + <Pattern>%d %-5p [%c] [%thread] %m%n</Pattern> + </encoder> + </appender> + + <appender name="WIREFILE" class="ch.qos.logback.core.FileAppender"> + <file>target/test-data/jclouds-wire.log</file> + + <encoder> + <Pattern>%d %-5p [%c] [%thread] %m%n</Pattern> + </encoder> + </appender> + + <root> + <level value="warn" /> + </root> + + <logger name="org.jclouds"> + <level value="DEBUG" /> + <appender-ref ref="FILE" /> + </logger> + +<!-- + <logger name="jclouds.wire"> + <level value="DEBUG" /> + <appender-ref ref="WIREFILE" /> + </logger> +--> + + <logger name="jclouds.headers"> + <level value="DEBUG" /> + <appender-ref ref="WIREFILE" /> + </logger> + +</configuration> http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/6af7f898/openstack-heat/src/test/resources/resource_type_list_response.json ---------------------------------------------------------------------- diff --git a/openstack-heat/src/test/resources/resource_type_list_response.json b/openstack-heat/src/test/resources/resource_type_list_response.json new file mode 100644 index 0000000..20c5674 --- /dev/null +++ b/openstack-heat/src/test/resources/resource_type_list_response.json @@ -0,0 +1,24 @@ +{ + "resource_types": [ + "AWS::EC2::Instance", + "OS::Cinder::Volume", + "Rackspace::Cloud::DNS", + "Rackspace::AutoScale::ScalingPolicy", + "OS::Nova::Server", + "Rackspace::AutoScale::WebHook", + "OS::Cinder::VolumeAttachment", + "Rackspace::AutoScale::Group", + "Rackspace::Cloud::ChefSolo", + "OS::Heat::RandomString", + "OS::Heat::ResourceGroup", + "OS::Swift::Container", + "Rackspace::Cloud::Server", + "OS::Heat::ChefSolo", + "Rackspace::Cloud::LoadBalancer", + "Rackspace::Cloud::WinServer", + "OS::Nova::KeyPair", + "Rackspace::Cloud::Network", + "AWS::ElasticLoadBalancing::LoadBalancer", + "OS::Trove::Instance" + ] +} http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/6af7f898/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index d2769e5..8bf414e 100644 --- a/pom.xml +++ b/pom.xml @@ -55,6 +55,7 @@ <modules> <module>openstack-glance</module> + <module>openstack-heat</module> <module>openstack-neutron</module> <module>openstack-swift</module> <module>openstack-marconi</module>
