-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Project, ProjectInfo, Policy, and ResourceId classes added. #374
Merged
aozarov
merged 10 commits into
googleapis:resource-manager
from
ajkannan:project-objects
Nov 30, 2015
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
573f88c
Project, ProjectInfo, Policy, and ResourceId classes added.
8efaa54
Fix style, simplify equals methods, fix tests, and add Project javadocs
9e48ecf
Add documentation and make resource ID type string
01f8b6c
Remove Policy and add docs
9f7fc1a
Added docs, removed policy-related methods from spi layer, fixed list…
0ec9f50
Remove parent and resource ID, add fields options
4107bbe
Add exception handling, add back resource ID, and other cleanup
d67f94b
Add list/get options serialization tests + other small fixes
3408d7a
Add page size and page token options
55c60b1
fix paging docs
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
gcloud-java-resourcemanager/src/main/java/com/google/gcloud/resourcemanager/Option.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright 2015 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed 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 com.google.gcloud.resourcemanager; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
import com.google.common.base.MoreObjects; | ||
import com.google.gcloud.spi.ResourceManagerRpc; | ||
|
||
import java.io.Serializable; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Base class for Resource Manager operation options | ||
*/ | ||
class Option implements Serializable { | ||
|
||
private static final long serialVersionUID = 2655177550880762967L; | ||
|
||
private final ResourceManagerRpc.Option rpcOption; | ||
private final Object value; | ||
|
||
Option(ResourceManagerRpc.Option rpcOption, Object value) { | ||
this.rpcOption = checkNotNull(rpcOption); | ||
this.value = value; | ||
} | ||
|
||
ResourceManagerRpc.Option rpcOption() { | ||
return rpcOption; | ||
} | ||
|
||
Object value() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (!(obj instanceof Option)) { | ||
return false; | ||
} | ||
Option other = (Option) obj; | ||
return Objects.equals(rpcOption, other.rpcOption) | ||
&& Objects.equals(value, other.value); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(rpcOption, value); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return MoreObjects.toStringHelper(this) | ||
.add("name", rpcOption.value()) | ||
.add("value", value) | ||
.toString(); | ||
} | ||
} |
134 changes: 134 additions & 0 deletions
134
gcloud-java-resourcemanager/src/main/java/com/google/gcloud/resourcemanager/Project.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/* | ||
* Copyright 2015 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed 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 com.google.gcloud.resourcemanager; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
/** | ||
* A Google Cloud Resource Manager project object. | ||
* | ||
* A Project is a high-level Google Cloud Platform entity. It is a container for ACLs, APIs, | ||
* AppEngine Apps, VMs, and other Google Cloud Platform resources. This class' member variables are | ||
* immutable. Methods that change or update the underlying Project information return a new Project | ||
* instance. | ||
*/ | ||
public class Project { | ||
|
||
private final ResourceManager resourceManager; | ||
private final ProjectInfo info; | ||
|
||
/** | ||
* Constructs a Project object that contains the ProjectInfo given. | ||
*/ | ||
public Project(ResourceManager resourceManager, ProjectInfo projectInfo) { | ||
this.resourceManager = checkNotNull(resourceManager); | ||
this.info = checkNotNull(projectInfo); | ||
} | ||
|
||
/** | ||
* Constructs a Project object that contains project information loaded from the server. | ||
* | ||
* @return Project object containing the project's metadata | ||
* @throws ResourceManagerException upon failure | ||
*/ | ||
public static Project load(ResourceManager resourceManager, String projectId) { | ||
ProjectInfo projectInfo = resourceManager.get(projectId); | ||
return new Project(resourceManager, projectInfo); | ||
} | ||
|
||
/** | ||
* Returns the {@link ProjectInfo} object associated with this Project. | ||
*/ | ||
public ProjectInfo info() { | ||
return info; | ||
} | ||
|
||
/** | ||
* Returns the {@link ResourceManager} service object associated with this Project. | ||
*/ | ||
public ResourceManager resourceManager() { | ||
return resourceManager; | ||
} | ||
|
||
/** | ||
* Returns a Project object with updated project information. | ||
* | ||
* @return Project object containing the project's updated metadata | ||
* @throws ResourceManagerException upon failure | ||
*/ | ||
public Project reload() { | ||
This comment was marked as spam.
Sorry, something went wrong. |
||
return Project.load(resourceManager, info.projectId()); | ||
} | ||
|
||
/** | ||
* Marks the project identified by the specified project ID for deletion. | ||
* | ||
* This method will only affect the project if the following criteria are met: | ||
* <ul> | ||
* <li>The project does not have a billing account associated with it. | ||
* <li>The project has a lifecycle state of {@link ProjectInfo.State#ACTIVE}. | ||
* </ul> | ||
* This method changes the project's lifecycle state from {@link ProjectInfo.State#ACTIVE} to | ||
* {@link ProjectInfo.State#DELETE_REQUESTED}. The deletion starts at an unspecified time, at | ||
* which point the lifecycle state changes to {@link ProjectInfo.State#DELETE_IN_PROGRESS}. Until | ||
* the deletion completes, you can check the lifecycle state checked by retrieving the project | ||
* with {@link ResourceManager#get}, and the project remains visible to | ||
* {@link ResourceManager#list}. However, you cannot update the project. After the deletion | ||
* completes, the project is not retrievable by the {@link ResourceManager#get} and | ||
* {@link ResourceManager#list} methods. The caller must have modify permissions for this project. | ||
* | ||
* @see <a | ||
* href="https://cloud.google.com/resource-manager/reference/rest/v1beta1/projects/delete">Cloud | ||
* Resource Manager delete</a> | ||
* @throws ResourceManagerException upon failure | ||
*/ | ||
public void delete() { | ||
resourceManager.delete(info.projectId()); | ||
} | ||
|
||
/** | ||
* Restores the project identified by the specified project ID. | ||
* | ||
* You can only use this method for a project that has a lifecycle state of | ||
* {@link ProjectInfo.State#DELETE_REQUESTED}. After deletion starts, as indicated by a lifecycle | ||
* state of {@link ProjectInfo.State#DELETE_IN_PROGRESS}, the project cannot be restored. The | ||
* caller must have modify permissions for this project. | ||
* | ||
* @see <a | ||
* href="https://cloud.google.com/resource-manager/reference/rest/v1beta1/projects/undelete">Cloud | ||
* Resource Manager undelete</a> | ||
* @throws ResourceManagerException upon failure (including when the project can't be restored) | ||
*/ | ||
public void undelete() { | ||
resourceManager.undelete(info.projectId()); | ||
} | ||
|
||
/** | ||
* Replaces the attributes of the project. | ||
* | ||
* The caller must have modify permissions for this project. | ||
* | ||
* @see <a | ||
* href="https://cloud.google.com/resource-manager/reference/rest/v1beta1/projects/update">Cloud | ||
* Resource Manager update</a> | ||
* @return the ProjectInfo representing the new project metadata | ||
* @throws ResourceManagerException upon failure | ||
*/ | ||
public Project replace(ProjectInfo projectInfo) { | ||
return new Project(resourceManager, resourceManager.replace(checkNotNull(projectInfo))); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.