Skip to content

Commit d240f95

Browse files
author
Ajay Kannan
committed
Create packages for resource manager and outline spi layer.
1 parent 33bfb1e commit d240f95

File tree

9 files changed

+470
-0
lines changed

9 files changed

+470
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
Google Cloud Java Client for Resource Manager
2+
=============================================
3+
4+
Java idiomatic client for [Google Cloud Resource Manager] (https://cloud.google.com/resource-manager/).
5+
6+
[![Build Status](https://travis-ci.org/GoogleCloudPlatform/gcloud-java.svg?branch=master)](https://travis-ci.org/GoogleCloudPlatform/gcloud-java)
7+
[![Coverage Status](https://coveralls.io/repos/GoogleCloudPlatform/gcloud-java/badge.svg?branch=master)](https://coveralls.io/r/GoogleCloudPlatform/gcloud-java?branch=master)
8+
9+
<!-- TODO(ajaykannan): add in the maven shield once the artifact is pushed to maven -->
10+
11+
- [Homepage] (https://googlecloudplatform.github.io/gcloud-java/)
12+
13+
<!-- TODO(ajaykannan): add in a link to javadocs once the site has been generated with resource manager docs included -->
14+
15+
> Note: This client is a work-in-progress, and may occasionally
16+
> make backwards-incompatible changes.
17+
18+
Quickstart
19+
----------
20+
This library is currently under development and will be available soon!
21+
<!--TODO(ajaykannan): add in pom.xml snippet once gcloud-java-resource-manager becomes available on maven -->
22+
23+
<!-- TODO(ajaykannan): once the API becomes usable, make an example application
24+
Example Application
25+
-------------------- -->
26+
27+
Authentication
28+
--------------
29+
30+
See the [Authentication](https://github.com/GoogleCloudPlatform/gcloud-java#authentication) section in the base directory's README.
31+
32+
About Google Cloud Resource Manager
33+
-----------------------------------
34+
35+
Google [Cloud Resource Manager][cloud-resourcemanager] provides a programmatic way to manage your Google Cloud Platform projects. Google Cloud Resource Manager is currently in beta and may occasionally make backwards incompatible changes.
36+
37+
Be sure to activate the Google Cloud Resource Manager API on the Developer's Console to use Resource Manager from your project.
38+
39+
See the ``gcloud-java`` API [Resource Manager documentation][resourcemanager-api] to learn how to interact
40+
with the Cloud Resource Manager using this client Library.
41+
42+
<!-- TODO(ajaykannan): add code snippet -->
43+
44+
Java Versions
45+
-------------
46+
47+
Java 7 or above is required for using this client.
48+
49+
<!-- TODO(ajaykannan): add this in once the RemoteGCRMHelper class is functional -->
50+
51+
Versioning
52+
----------
53+
54+
This library follows [Semantic Versioning] (http://semver.org/).
55+
56+
It is currently in major version zero (``0.y.z``), which means that anything
57+
may change at any time and the public API should not be considered
58+
stable.
59+
60+
Contributing
61+
------------
62+
63+
Contributions to this library are always welcome and highly encouraged.
64+
65+
See [CONTRIBUTING] for more information on how to get started.
66+
67+
License
68+
-------
69+
70+
Apache 2.0 - See [LICENSE] for more information.
71+
72+
73+
[CONTRIBUTING]:https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/CONTRIBUTING.md
74+
[LICENSE]: https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/LICENSE
75+
[TESTING]: https://github.com/GoogleCloudPlatform/gcloud-java/blob/master/TESTING.md#testing-code-that-uses-resource-manager
76+
[cloud-platform]: https://cloud.google.com/
77+
[cloud-resourcemanager]: https://cloud.google.com/resource-manager/docs
78+
[resourcemanager-api]: http://googlecloudplatform.github.io/gcloud-java/apidocs/index.html?com/google/gcloud/resourcemanager/package-summary.html
79+

gcloud-java-resource-manager/pom.xml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0"?>
2+
<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/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.google.gcloud</groupId>
5+
<artifactId>gcloud-java-resource-manager</artifactId>
6+
<packaging>jar</packaging>
7+
<name>GCloud Java resource manager</name>
8+
<description>
9+
Java idiomatic client for Google Cloud Resource Manager.
10+
</description>
11+
<parent>
12+
<groupId>com.google.gcloud</groupId>
13+
<artifactId>gcloud-java-pom</artifactId>
14+
<version>0.0.11-SNAPSHOT</version>
15+
</parent>
16+
<properties>
17+
<site.installationModule>gcloud-java-resource-manager</site.installationModule>
18+
</properties>
19+
<dependencies>
20+
<dependency>
21+
<groupId>${project.groupId}</groupId>
22+
<artifactId>gcloud-java-core</artifactId>
23+
<version>${project.version}</version>
24+
</dependency>
25+
<dependency>
26+
<groupId>com.google.apis</groupId>
27+
<artifactId>google-api-services-cloudresourcemanager</artifactId>
28+
<version>v1beta1-rev6-1.19.0</version>
29+
<scope>compile</scope>
30+
</dependency>
31+
<dependency>
32+
<groupId>junit</groupId>
33+
<artifactId>junit</artifactId>
34+
<version>4.12</version>
35+
<scope>test</scope>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.easymock</groupId>
39+
<artifactId>easymock</artifactId>
40+
<version>3.3</version>
41+
<scope>test</scope>
42+
</dependency>
43+
</dependencies>
44+
</project>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2015 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.gcloud.resourcemanager;
18+
19+
import com.google.gcloud.Service;
20+
21+
/**
22+
* An interface for Google Cloud Resource Manager.
23+
*
24+
* @see <a href="https://cloud.google.com/resource-manager/">Google Cloud Resource Manager</a>
25+
*/
26+
public interface ResourceManager extends Service<ResourceManagerOptions> {
27+
28+
public static final String DEFAULT_CONTENT_TYPE = "application/octet-stream";
29+
30+
// TODO(ajaykannan): Fix me! Add in missing methods.
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright 2015 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.gcloud.resourcemanager;
18+
19+
import com.google.gcloud.RetryHelper;
20+
import com.google.gcloud.RetryHelper.RetryHelperException;
21+
import com.google.gcloud.RetryHelper.RetryInterruptedException;
22+
23+
/**
24+
* Resource Manager service exception.
25+
*
26+
* @see <a href="https://cloud.google.com/resource-manager/v1/errors/core_errors">Google Cloud
27+
* Resource Manager error codes</a>
28+
*/
29+
public class ResourceManagerException extends RuntimeException {
30+
31+
private static final long serialVersionUID = 6841689911565501705L;
32+
private static final int UNKNOWN_CODE = -1;
33+
34+
private final int code;
35+
private final boolean retryable;
36+
37+
public ResourceManagerException(int code, String message, boolean retryable) {
38+
super(message);
39+
this.code = code;
40+
this.retryable = retryable;
41+
}
42+
43+
/**
44+
* Returns the code associated with this exception.
45+
*/
46+
public int code() {
47+
return code;
48+
}
49+
50+
public boolean retryable() {
51+
return retryable;
52+
}
53+
54+
/**
55+
* Translate RetryHelperException to the ResourceManagerException that caused the error. This
56+
* method will always throw an exception.
57+
*
58+
* @throws ResourceManagerException when {@code ex} was caused by a {@code
59+
* ResourceManagerException}
60+
* @throws RetryInterruptedException when {@code ex} is a {@code RetryInterruptedException}
61+
*/
62+
static ResourceManagerException translateAndThrow(RetryHelperException ex) {
63+
if (ex.getCause() instanceof ResourceManagerException) {
64+
throw (ResourceManagerException) ex.getCause();
65+
}
66+
if (ex instanceof RetryHelper.RetryInterruptedException) {
67+
RetryHelper.RetryInterruptedException.propagate();
68+
}
69+
throw new ResourceManagerException(UNKNOWN_CODE, ex.getMessage(), false);
70+
}
71+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright 2015 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.gcloud.resourcemanager;
18+
19+
import com.google.gcloud.ServiceFactory;
20+
21+
/**
22+
* An interface for ResourceManager factories.
23+
*/
24+
public interface ResourceManagerFactory
25+
extends ServiceFactory<ResourceManager, ResourceManagerOptions> {}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Copyright 2015 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.gcloud.resourcemanager;
18+
19+
import com.google.common.collect.ImmutableSet;
20+
import com.google.gcloud.ServiceOptions;
21+
import com.google.gcloud.spi.ResourceManagerRpc;
22+
import com.google.gcloud.spi.ResourceManagerRpcFactory;
23+
24+
import java.util.Set;
25+
26+
public class ResourceManagerOptions
27+
extends ServiceOptions<ResourceManager, ResourceManagerRpc, ResourceManagerOptions> {
28+
29+
private static final long serialVersionUID = 538303101192527452L;
30+
private static final String GCRM_SCOPE = "https://www.googleapis.com/auth/cloud-platform";
31+
private static final Set<String> SCOPES = ImmutableSet.of(GCRM_SCOPE);
32+
33+
public static class DefaultResourceManagerFactory implements ResourceManagerFactory {
34+
private static final ResourceManagerFactory INSTANCE = new DefaultResourceManagerFactory();
35+
36+
@Override
37+
public ResourceManager create(ResourceManagerOptions options) {
38+
// return new ResourceManagerImpl(options);
39+
return null; // TODO(ajaykannan): Fix me!
40+
}
41+
}
42+
43+
public static class DefaultResourceManagerRpcFactory implements ResourceManagerRpcFactory {
44+
private static final ResourceManagerRpcFactory INSTANCE =
45+
new DefaultResourceManagerRpcFactory();
46+
47+
@Override
48+
public ResourceManagerRpc create(ResourceManagerOptions options) {
49+
// return new DefaultResourceManagerRpc(options);
50+
return null; // TODO(ajaykannan): Fix me!
51+
}
52+
}
53+
54+
public static class Builder extends ServiceOptions.Builder<ResourceManager, ResourceManagerRpc,
55+
ResourceManagerOptions, Builder> {
56+
57+
private Builder() {}
58+
59+
private Builder(ResourceManagerOptions options) {
60+
super(options);
61+
}
62+
63+
@Override
64+
public ResourceManagerOptions build() {
65+
return new ResourceManagerOptions(this);
66+
}
67+
}
68+
69+
private ResourceManagerOptions(Builder builder) {
70+
super(ResourceManagerFactory.class, ResourceManagerRpcFactory.class, builder);
71+
}
72+
73+
@Override
74+
protected ResourceManagerFactory defaultServiceFactory() {
75+
return DefaultResourceManagerFactory.INSTANCE;
76+
}
77+
78+
@Override
79+
protected ResourceManagerRpcFactory defaultRpcFactory() {
80+
return DefaultResourceManagerRpcFactory.INSTANCE;
81+
}
82+
83+
@Override
84+
protected Set<String> scopes() {
85+
return SCOPES;
86+
}
87+
88+
@Override
89+
public boolean equals(Object obj) {
90+
return obj instanceof ResourceManagerOptions && baseEquals((ResourceManagerOptions) obj);
91+
}
92+
93+
@Override
94+
public Builder toBuilder() {
95+
return new Builder(this);
96+
}
97+
98+
public static Builder builder() {
99+
return new Builder();
100+
}
101+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2015 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* A client to Google Cloud Resource Manager.
19+
* //TODO(ajaykannan): add code example
20+
* @see <a href="https://cloud.google.com/resource-manager/">Google Cloud Resource Manager</a>
21+
*/
22+
23+
package com.google.gcloud.resourcemanager;

0 commit comments

Comments
 (0)