@Generated(value="by gapic-generator-java") public class ProjectsClient extends Object implements BackgroundResource
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
Project response = projectsClient.getProject(name);
}
Note: close() needs to be called on the ProjectsClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
The surface of this class includes several types of Java methods for each of the API's methods:
See the individual methods for example code.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.
This class can be customized by passing in a custom instance of ProjectsSettings to create(). For example:
To customize credentials:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
ProjectsSettings projectsSettings =
ProjectsSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
ProjectsClient projectsClient = ProjectsClient.create(projectsSettings);
To customize the endpoint:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
ProjectsSettings projectsSettings =
ProjectsSettings.newBuilder().setEndpoint(myEndpoint).build();
ProjectsClient projectsClient = ProjectsClient.create(projectsSettings);
To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over the wire:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
ProjectsSettings projectsSettings =
ProjectsSettings.newBuilder()
.setTransportChannelProvider(
ProjectsSettings.defaultHttpJsonTransportProviderBuilder().build())
.build();
ProjectsClient projectsClient = ProjectsClient.create(projectsSettings);
Please refer to the GitHub repository's samples for more quickstart code snippets.
Modifier and Type | Class and Description |
---|---|
static class |
ProjectsClient.ListProjectsFixedSizeCollection |
static class |
ProjectsClient.ListProjectsPage |
static class |
ProjectsClient.ListProjectsPagedResponse |
static class |
ProjectsClient.SearchProjectsFixedSizeCollection |
static class |
ProjectsClient.SearchProjectsPage |
static class |
ProjectsClient.SearchProjectsPagedResponse |
Modifier | Constructor and Description |
---|---|
protected |
ProjectsClient(ProjectsSettings settings)
Constructs an instance of ProjectsClient, using the given settings.
|
protected |
ProjectsClient(ProjectsStub stub) |
Modifier and Type | Method and Description |
---|---|
boolean |
awaitTermination(long duration,
TimeUnit unit) |
void |
close() |
static ProjectsClient |
create()
Constructs an instance of ProjectsClient with default settings.
|
static ProjectsClient |
create(ProjectsSettings settings)
Constructs an instance of ProjectsClient, using the given settings.
|
static ProjectsClient |
create(ProjectsStub stub)
Constructs an instance of ProjectsClient, using the given stub for making calls.
|
OperationFuture<Project,CreateProjectMetadata> |
createProjectAsync(CreateProjectRequest request)
Request that a new project be created.
|
OperationFuture<Project,CreateProjectMetadata> |
createProjectAsync(Project project)
Request that a new project be created.
|
UnaryCallable<CreateProjectRequest,Operation> |
createProjectCallable()
Request that a new project be created.
|
OperationCallable<CreateProjectRequest,Project,CreateProjectMetadata> |
createProjectOperationCallable()
Request that a new project be created.
|
OperationFuture<Project,DeleteProjectMetadata> |
deleteProjectAsync(DeleteProjectRequest request)
Marks the project identified by the specified `name` (for example, `projects/415104041262`) for
deletion.
|
OperationFuture<Project,DeleteProjectMetadata> |
deleteProjectAsync(ProjectName name)
Marks the project identified by the specified `name` (for example, `projects/415104041262`) for
deletion.
|
OperationFuture<Project,DeleteProjectMetadata> |
deleteProjectAsync(String name)
Marks the project identified by the specified `name` (for example, `projects/415104041262`) for
deletion.
|
UnaryCallable<DeleteProjectRequest,Operation> |
deleteProjectCallable()
Marks the project identified by the specified `name` (for example, `projects/415104041262`) for
deletion.
|
OperationCallable<DeleteProjectRequest,Project,DeleteProjectMetadata> |
deleteProjectOperationCallable()
Marks the project identified by the specified `name` (for example, `projects/415104041262`) for
deletion.
|
OperationsClient |
getHttpJsonOperationsClient()
Returns the OperationsClient that can be used to query the status of a long-running operation
returned by another API method call.
|
com.google.iam.v1.Policy |
getIamPolicy(com.google.iam.v1.GetIamPolicyRequest request)
Returns the IAM access control policy for the specified project.
|
com.google.iam.v1.Policy |
getIamPolicy(com.google.api.resourcenames.ResourceName resource)
Returns the IAM access control policy for the specified project.
|
com.google.iam.v1.Policy |
getIamPolicy(String resource)
Returns the IAM access control policy for the specified project.
|
UnaryCallable<com.google.iam.v1.GetIamPolicyRequest,com.google.iam.v1.Policy> |
getIamPolicyCallable()
Returns the IAM access control policy for the specified project.
|
OperationsClient |
getOperationsClient()
Returns the OperationsClient that can be used to query the status of a long-running operation
returned by another API method call.
|
Project |
getProject(GetProjectRequest request)
Retrieves the project identified by the specified `name` (for example,
`projects/415104041262`).
|
Project |
getProject(ProjectName name)
Retrieves the project identified by the specified `name` (for example,
`projects/415104041262`).
|
Project |
getProject(String name)
Retrieves the project identified by the specified `name` (for example,
`projects/415104041262`).
|
UnaryCallable<GetProjectRequest,Project> |
getProjectCallable()
Retrieves the project identified by the specified `name` (for example,
`projects/415104041262`).
|
ProjectsSettings |
getSettings() |
ProjectsStub |
getStub() |
boolean |
isShutdown() |
boolean |
isTerminated() |
ProjectsClient.ListProjectsPagedResponse |
listProjects(ListProjectsRequest request)
Lists projects that are direct children of the specified folder or organization resource.
|
ProjectsClient.ListProjectsPagedResponse |
listProjects(com.google.api.resourcenames.ResourceName parent)
Lists projects that are direct children of the specified folder or organization resource.
|
ProjectsClient.ListProjectsPagedResponse |
listProjects(String parent)
Lists projects that are direct children of the specified folder or organization resource.
|
UnaryCallable<ListProjectsRequest,ListProjectsResponse> |
listProjectsCallable()
Lists projects that are direct children of the specified folder or organization resource.
|
UnaryCallable<ListProjectsRequest,ProjectsClient.ListProjectsPagedResponse> |
listProjectsPagedCallable()
Lists projects that are direct children of the specified folder or organization resource.
|
OperationFuture<Project,MoveProjectMetadata> |
moveProjectAsync(MoveProjectRequest request)
Move a project to another place in your resource hierarchy, under a new resource parent.
|
OperationFuture<Project,MoveProjectMetadata> |
moveProjectAsync(ProjectName name,
com.google.api.resourcenames.ResourceName destinationParent)
Move a project to another place in your resource hierarchy, under a new resource parent.
|
OperationFuture<Project,MoveProjectMetadata> |
moveProjectAsync(ProjectName name,
String destinationParent)
Move a project to another place in your resource hierarchy, under a new resource parent.
|
OperationFuture<Project,MoveProjectMetadata> |
moveProjectAsync(String name,
com.google.api.resourcenames.ResourceName destinationParent)
Move a project to another place in your resource hierarchy, under a new resource parent.
|
OperationFuture<Project,MoveProjectMetadata> |
moveProjectAsync(String name,
String destinationParent)
Move a project to another place in your resource hierarchy, under a new resource parent.
|
UnaryCallable<MoveProjectRequest,Operation> |
moveProjectCallable()
Move a project to another place in your resource hierarchy, under a new resource parent.
|
OperationCallable<MoveProjectRequest,Project,MoveProjectMetadata> |
moveProjectOperationCallable()
Move a project to another place in your resource hierarchy, under a new resource parent.
|
ProjectsClient.SearchProjectsPagedResponse |
searchProjects(SearchProjectsRequest request)
Search for projects that the caller has both `resourcemanager.projects.get` permission on, and
also satisfy the specified query.
|
ProjectsClient.SearchProjectsPagedResponse |
searchProjects(String query)
Search for projects that the caller has both `resourcemanager.projects.get` permission on, and
also satisfy the specified query.
|
UnaryCallable<SearchProjectsRequest,SearchProjectsResponse> |
searchProjectsCallable()
Search for projects that the caller has both `resourcemanager.projects.get` permission on, and
also satisfy the specified query.
|
UnaryCallable<SearchProjectsRequest,ProjectsClient.SearchProjectsPagedResponse> |
searchProjectsPagedCallable()
Search for projects that the caller has both `resourcemanager.projects.get` permission on, and
also satisfy the specified query.
|
com.google.iam.v1.Policy |
setIamPolicy(com.google.api.resourcenames.ResourceName resource,
com.google.iam.v1.Policy policy)
Sets the IAM access control policy for the specified project.
|
com.google.iam.v1.Policy |
setIamPolicy(com.google.iam.v1.SetIamPolicyRequest request)
Sets the IAM access control policy for the specified project.
|
com.google.iam.v1.Policy |
setIamPolicy(String resource,
com.google.iam.v1.Policy policy)
Sets the IAM access control policy for the specified project.
|
UnaryCallable<com.google.iam.v1.SetIamPolicyRequest,com.google.iam.v1.Policy> |
setIamPolicyCallable()
Sets the IAM access control policy for the specified project.
|
void |
shutdown() |
void |
shutdownNow() |
com.google.iam.v1.TestIamPermissionsResponse |
testIamPermissions(com.google.api.resourcenames.ResourceName resource,
List<String> permissions)
Returns permissions that a caller has on the specified project.
|
com.google.iam.v1.TestIamPermissionsResponse |
testIamPermissions(String resource,
List<String> permissions)
Returns permissions that a caller has on the specified project.
|
com.google.iam.v1.TestIamPermissionsResponse |
testIamPermissions(com.google.iam.v1.TestIamPermissionsRequest request)
Returns permissions that a caller has on the specified project.
|
UnaryCallable<com.google.iam.v1.TestIamPermissionsRequest,com.google.iam.v1.TestIamPermissionsResponse> |
testIamPermissionsCallable()
Returns permissions that a caller has on the specified project.
|
OperationFuture<Project,UndeleteProjectMetadata> |
undeleteProjectAsync(ProjectName name)
Restores the project identified by the specified `name` (for example, `projects/415104041262`).
|
OperationFuture<Project,UndeleteProjectMetadata> |
undeleteProjectAsync(String name)
Restores the project identified by the specified `name` (for example, `projects/415104041262`).
|
OperationFuture<Project,UndeleteProjectMetadata> |
undeleteProjectAsync(UndeleteProjectRequest request)
Restores the project identified by the specified `name` (for example, `projects/415104041262`).
|
UnaryCallable<UndeleteProjectRequest,Operation> |
undeleteProjectCallable()
Restores the project identified by the specified `name` (for example, `projects/415104041262`).
|
OperationCallable<UndeleteProjectRequest,Project,UndeleteProjectMetadata> |
undeleteProjectOperationCallable()
Restores the project identified by the specified `name` (for example, `projects/415104041262`).
|
OperationFuture<Project,UpdateProjectMetadata> |
updateProjectAsync(Project project,
FieldMask updateMask)
Updates the `display_name` and labels of the project identified by the specified `name` (for
example, `projects/415104041262`).
|
OperationFuture<Project,UpdateProjectMetadata> |
updateProjectAsync(UpdateProjectRequest request)
Updates the `display_name` and labels of the project identified by the specified `name` (for
example, `projects/415104041262`).
|
UnaryCallable<UpdateProjectRequest,Operation> |
updateProjectCallable()
Updates the `display_name` and labels of the project identified by the specified `name` (for
example, `projects/415104041262`).
|
OperationCallable<UpdateProjectRequest,Project,UpdateProjectMetadata> |
updateProjectOperationCallable()
Updates the `display_name` and labels of the project identified by the specified `name` (for
example, `projects/415104041262`).
|
protected ProjectsClient(ProjectsSettings settings) throws IOException
IOException
protected ProjectsClient(ProjectsStub stub)
public static final ProjectsClient create() throws IOException
IOException
public static final ProjectsClient create(ProjectsSettings settings) throws IOException
IOException
public static final ProjectsClient create(ProjectsStub stub)
public final ProjectsSettings getSettings()
public ProjectsStub getStub()
public final OperationsClient getOperationsClient()
@BetaApi public final OperationsClient getHttpJsonOperationsClient()
public final Project getProject(ProjectName name)
The caller must have `resourcemanager.projects.get` permission for this project.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
Project response = projectsClient.getProject(name);
}
name
- Required. The name of the project (for example, `projects/415104041262`).ApiException
- if the remote call failspublic final Project getProject(String name)
The caller must have `resourcemanager.projects.get` permission for this project.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
String name = ProjectName.of("[PROJECT]").toString();
Project response = projectsClient.getProject(name);
}
name
- Required. The name of the project (for example, `projects/415104041262`).ApiException
- if the remote call failspublic final Project getProject(GetProjectRequest request)
The caller must have `resourcemanager.projects.get` permission for this project.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
GetProjectRequest request =
GetProjectRequest.newBuilder().setName(ProjectName.of("[PROJECT]").toString()).build();
Project response = projectsClient.getProject(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<GetProjectRequest,Project> getProjectCallable()
The caller must have `resourcemanager.projects.get` permission for this project.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
GetProjectRequest request =
GetProjectRequest.newBuilder().setName(ProjectName.of("[PROJECT]").toString()).build();
ApiFuture<Project> future = projectsClient.getProjectCallable().futureCall(request);
// Do something.
Project response = future.get();
}
public final ProjectsClient.ListProjectsPagedResponse listProjects(com.google.api.resourcenames.ResourceName parent)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
ResourceName parent = FolderName.of("[FOLDER]");
for (Project element : projectsClient.listProjects(parent).iterateAll()) {
// doThingsWith(element);
}
}
parent
- Required. The name of the parent resource to list projects under.
For example, setting this field to 'folders/1234' would list all projects directly under that folder.
ApiException
- if the remote call failspublic final ProjectsClient.ListProjectsPagedResponse listProjects(String parent)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
String parent = FolderName.of("[FOLDER]").toString();
for (Project element : projectsClient.listProjects(parent).iterateAll()) {
// doThingsWith(element);
}
}
parent
- Required. The name of the parent resource to list projects under.
For example, setting this field to 'folders/1234' would list all projects directly under that folder.
ApiException
- if the remote call failspublic final ProjectsClient.ListProjectsPagedResponse listProjects(ListProjectsRequest request)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
ListProjectsRequest request =
ListProjectsRequest.newBuilder()
.setParent(FolderName.of("[FOLDER]").toString())
.setPageToken("pageToken873572522")
.setPageSize(883849137)
.setShowDeleted(true)
.build();
for (Project element : projectsClient.listProjects(request).iterateAll()) {
// doThingsWith(element);
}
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<ListProjectsRequest,ProjectsClient.ListProjectsPagedResponse> listProjectsPagedCallable()
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
ListProjectsRequest request =
ListProjectsRequest.newBuilder()
.setParent(FolderName.of("[FOLDER]").toString())
.setPageToken("pageToken873572522")
.setPageSize(883849137)
.setShowDeleted(true)
.build();
ApiFuture<Project> future = projectsClient.listProjectsPagedCallable().futureCall(request);
// Do something.
for (Project element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
public final UnaryCallable<ListProjectsRequest,ListProjectsResponse> listProjectsCallable()
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
ListProjectsRequest request =
ListProjectsRequest.newBuilder()
.setParent(FolderName.of("[FOLDER]").toString())
.setPageToken("pageToken873572522")
.setPageSize(883849137)
.setShowDeleted(true)
.build();
while (true) {
ListProjectsResponse response = projectsClient.listProjectsCallable().call(request);
for (Project element : response.getProjectsList()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
public final ProjectsClient.SearchProjectsPagedResponse searchProjects(String query)
This method returns projects in an unspecified order.
This method is eventually consistent with project mutations; this means that a newly created project may not appear in the results or recent updates to an existing project may not be reflected in the results. To retrieve the latest state of a project, use the [GetProject][google.cloud.resourcemanager.v3.Projects.GetProject] method.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
String query = "query107944136";
for (Project element : projectsClient.searchProjects(query).iterateAll()) {
// doThingsWith(element);
}
}
query
- Optional. A query string for searching for projects that the caller has
`resourcemanager.projects.get` permission to. If multiple fields are included in the query,
the it will return results that match any of the fields. Some eligible fields are:
``` | Field | Description | |-------------------------|----------------------------------------------| | displayName, name | Filters by displayName. | | parent | Project's parent. (for example: folders/123, organizations/*) Prefer parent field over parent.type and parent.id. | | parent.type | Parent's type: `folder` or `organization`. | | parent.id | Parent's id number (for example: 123) | | id, projectId | Filters by projectId. | | state, lifecycleState | Filters by state. | | labels | Filters by label name or value. | | labels.<key> (where *key* is the name of a label) | Filters by label name. | ```
Search expressions are case insensitive.
Some examples queries:
``` | Query | Description | |------------------|-----------------------------------------------------| | name:how* | The project's name starts with "how". | | name:Howl | The project's name is `Howl` or `howl`. | | name:HOWL | Equivalent to above. | | NAME:howl | Equivalent to above. | | labels.color:* | The project has the label `color`. | | labels.color:red | The project's label `color` has the value `red`. | | labels.color:red labels.size:big | The project's label `color` has the value `red` and its label `size` has the value `big`. | ```
If no query is specified, the call will return projects for which the user has the `resourcemanager.projects.get` permission.
ApiException
- if the remote call failspublic final ProjectsClient.SearchProjectsPagedResponse searchProjects(SearchProjectsRequest request)
This method returns projects in an unspecified order.
This method is eventually consistent with project mutations; this means that a newly created project may not appear in the results or recent updates to an existing project may not be reflected in the results. To retrieve the latest state of a project, use the [GetProject][google.cloud.resourcemanager.v3.Projects.GetProject] method.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
SearchProjectsRequest request =
SearchProjectsRequest.newBuilder()
.setQuery("query107944136")
.setPageToken("pageToken873572522")
.setPageSize(883849137)
.build();
for (Project element : projectsClient.searchProjects(request).iterateAll()) {
// doThingsWith(element);
}
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<SearchProjectsRequest,ProjectsClient.SearchProjectsPagedResponse> searchProjectsPagedCallable()
This method returns projects in an unspecified order.
This method is eventually consistent with project mutations; this means that a newly created project may not appear in the results or recent updates to an existing project may not be reflected in the results. To retrieve the latest state of a project, use the [GetProject][google.cloud.resourcemanager.v3.Projects.GetProject] method.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
SearchProjectsRequest request =
SearchProjectsRequest.newBuilder()
.setQuery("query107944136")
.setPageToken("pageToken873572522")
.setPageSize(883849137)
.build();
ApiFuture<Project> future = projectsClient.searchProjectsPagedCallable().futureCall(request);
// Do something.
for (Project element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
public final UnaryCallable<SearchProjectsRequest,SearchProjectsResponse> searchProjectsCallable()
This method returns projects in an unspecified order.
This method is eventually consistent with project mutations; this means that a newly created project may not appear in the results or recent updates to an existing project may not be reflected in the results. To retrieve the latest state of a project, use the [GetProject][google.cloud.resourcemanager.v3.Projects.GetProject] method.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
SearchProjectsRequest request =
SearchProjectsRequest.newBuilder()
.setQuery("query107944136")
.setPageToken("pageToken873572522")
.setPageSize(883849137)
.build();
while (true) {
SearchProjectsResponse response = projectsClient.searchProjectsCallable().call(request);
for (Project element : response.getProjectsList()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
public final OperationFuture<Project,CreateProjectMetadata> createProjectAsync(Project project)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
Project project = Project.newBuilder().build();
Project response = projectsClient.createProjectAsync(project).get();
}
project
- Required. The Project to create.
Project ID is required. If the requested ID is unavailable, the request fails.
If the `parent` field is set, the `resourcemanager.projects.create` permission is checked on the parent resource. If no parent is set and the authorization credentials belong to an Organziation, the parent will be set to that Organization.
ApiException
- if the remote call failspublic final OperationFuture<Project,CreateProjectMetadata> createProjectAsync(CreateProjectRequest request)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
CreateProjectRequest request =
CreateProjectRequest.newBuilder().setProject(Project.newBuilder().build()).build();
Project response = projectsClient.createProjectAsync(request).get();
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final OperationCallable<CreateProjectRequest,Project,CreateProjectMetadata> createProjectOperationCallable()
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
CreateProjectRequest request =
CreateProjectRequest.newBuilder().setProject(Project.newBuilder().build()).build();
OperationFuture<Project, CreateProjectMetadata> future =
projectsClient.createProjectOperationCallable().futureCall(request);
// Do something.
Project response = future.get();
}
public final UnaryCallable<CreateProjectRequest,Operation> createProjectCallable()
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
CreateProjectRequest request =
CreateProjectRequest.newBuilder().setProject(Project.newBuilder().build()).build();
ApiFuture<Operation> future = projectsClient.createProjectCallable().futureCall(request);
// Do something.
Operation response = future.get();
}
public final OperationFuture<Project,UpdateProjectMetadata> updateProjectAsync(Project project, FieldMask updateMask)
The caller must have `resourcemanager.projects.update` permission for this project.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
Project project = Project.newBuilder().build();
FieldMask updateMask = FieldMask.newBuilder().build();
Project response = projectsClient.updateProjectAsync(project, updateMask).get();
}
project
- Required. The new definition of the project.updateMask
- Optional. An update mask to selectively update fields.ApiException
- if the remote call failspublic final OperationFuture<Project,UpdateProjectMetadata> updateProjectAsync(UpdateProjectRequest request)
The caller must have `resourcemanager.projects.update` permission for this project.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
UpdateProjectRequest request =
UpdateProjectRequest.newBuilder()
.setProject(Project.newBuilder().build())
.setUpdateMask(FieldMask.newBuilder().build())
.build();
Project response = projectsClient.updateProjectAsync(request).get();
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final OperationCallable<UpdateProjectRequest,Project,UpdateProjectMetadata> updateProjectOperationCallable()
The caller must have `resourcemanager.projects.update` permission for this project.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
UpdateProjectRequest request =
UpdateProjectRequest.newBuilder()
.setProject(Project.newBuilder().build())
.setUpdateMask(FieldMask.newBuilder().build())
.build();
OperationFuture<Project, UpdateProjectMetadata> future =
projectsClient.updateProjectOperationCallable().futureCall(request);
// Do something.
Project response = future.get();
}
public final UnaryCallable<UpdateProjectRequest,Operation> updateProjectCallable()
The caller must have `resourcemanager.projects.update` permission for this project.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
UpdateProjectRequest request =
UpdateProjectRequest.newBuilder()
.setProject(Project.newBuilder().build())
.setUpdateMask(FieldMask.newBuilder().build())
.build();
ApiFuture<Operation> future = projectsClient.updateProjectCallable().futureCall(request);
// Do something.
Operation response = future.get();
}
public final OperationFuture<Project,MoveProjectMetadata> moveProjectAsync(ProjectName name, com.google.api.resourcenames.ResourceName destinationParent)
Returns an operation which can be used to track the process of the project move workflow. Upon success, the `Operation.response` field will be populated with the moved project.
The caller must have `resourcemanager.projects.update` permission on the project and have `resourcemanager.projects.move` permission on the project's current and proposed new parent.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
ResourceName destinationParent = ProjectName.of("[PROJECT]");
Project response = projectsClient.moveProjectAsync(name, destinationParent).get();
}
name
- Required. The name of the project to move.destinationParent
- Required. The new parent to move the Project under.ApiException
- if the remote call failspublic final OperationFuture<Project,MoveProjectMetadata> moveProjectAsync(ProjectName name, String destinationParent)
Returns an operation which can be used to track the process of the project move workflow. Upon success, the `Operation.response` field will be populated with the moved project.
The caller must have `resourcemanager.projects.update` permission on the project and have `resourcemanager.projects.move` permission on the project's current and proposed new parent.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
String destinationParent = FolderName.of("[FOLDER]").toString();
Project response = projectsClient.moveProjectAsync(name, destinationParent).get();
}
name
- Required. The name of the project to move.destinationParent
- Required. The new parent to move the Project under.ApiException
- if the remote call failspublic final OperationFuture<Project,MoveProjectMetadata> moveProjectAsync(String name, com.google.api.resourcenames.ResourceName destinationParent)
Returns an operation which can be used to track the process of the project move workflow. Upon success, the `Operation.response` field will be populated with the moved project.
The caller must have `resourcemanager.projects.update` permission on the project and have `resourcemanager.projects.move` permission on the project's current and proposed new parent.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
String name = ProjectName.of("[PROJECT]").toString();
ResourceName destinationParent = ProjectName.of("[PROJECT]");
Project response = projectsClient.moveProjectAsync(name, destinationParent).get();
}
name
- Required. The name of the project to move.destinationParent
- Required. The new parent to move the Project under.ApiException
- if the remote call failspublic final OperationFuture<Project,MoveProjectMetadata> moveProjectAsync(String name, String destinationParent)
Returns an operation which can be used to track the process of the project move workflow. Upon success, the `Operation.response` field will be populated with the moved project.
The caller must have `resourcemanager.projects.update` permission on the project and have `resourcemanager.projects.move` permission on the project's current and proposed new parent.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
String name = ProjectName.of("[PROJECT]").toString();
String destinationParent = FolderName.of("[FOLDER]").toString();
Project response = projectsClient.moveProjectAsync(name, destinationParent).get();
}
name
- Required. The name of the project to move.destinationParent
- Required. The new parent to move the Project under.ApiException
- if the remote call failspublic final OperationFuture<Project,MoveProjectMetadata> moveProjectAsync(MoveProjectRequest request)
Returns an operation which can be used to track the process of the project move workflow. Upon success, the `Operation.response` field will be populated with the moved project.
The caller must have `resourcemanager.projects.update` permission on the project and have `resourcemanager.projects.move` permission on the project's current and proposed new parent.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
MoveProjectRequest request =
MoveProjectRequest.newBuilder()
.setName(ProjectName.of("[PROJECT]").toString())
.setDestinationParent(ProjectName.of("[PROJECT]").toString())
.build();
Project response = projectsClient.moveProjectAsync(request).get();
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final OperationCallable<MoveProjectRequest,Project,MoveProjectMetadata> moveProjectOperationCallable()
Returns an operation which can be used to track the process of the project move workflow. Upon success, the `Operation.response` field will be populated with the moved project.
The caller must have `resourcemanager.projects.update` permission on the project and have `resourcemanager.projects.move` permission on the project's current and proposed new parent.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
MoveProjectRequest request =
MoveProjectRequest.newBuilder()
.setName(ProjectName.of("[PROJECT]").toString())
.setDestinationParent(ProjectName.of("[PROJECT]").toString())
.build();
OperationFuture<Project, MoveProjectMetadata> future =
projectsClient.moveProjectOperationCallable().futureCall(request);
// Do something.
Project response = future.get();
}
public final UnaryCallable<MoveProjectRequest,Operation> moveProjectCallable()
Returns an operation which can be used to track the process of the project move workflow. Upon success, the `Operation.response` field will be populated with the moved project.
The caller must have `resourcemanager.projects.update` permission on the project and have `resourcemanager.projects.move` permission on the project's current and proposed new parent.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
MoveProjectRequest request =
MoveProjectRequest.newBuilder()
.setName(ProjectName.of("[PROJECT]").toString())
.setDestinationParent(ProjectName.of("[PROJECT]").toString())
.build();
ApiFuture<Operation> future = projectsClient.moveProjectCallable().futureCall(request);
// Do something.
Operation response = future.get();
}
public final OperationFuture<Project,DeleteProjectMetadata> deleteProjectAsync(ProjectName name)
This method will only affect the project if it has a lifecycle state of [ACTIVE][google.cloud.resourcemanager.v3.Project.State.ACTIVE].
This method changes the Project's lifecycle state from [ACTIVE][google.cloud.resourcemanager.v3.Project.State.ACTIVE] to [DELETE_REQUESTED][google.cloud.resourcemanager.v3.Project.State.DELETE_REQUESTED]. The deletion starts at an unspecified time, at which point the Project is no longer accessible.
Until the deletion completes, you can check the lifecycle state checked by retrieving the project with [GetProject] [google.cloud.resourcemanager.v3.Projects.GetProject], and the project remains visible to [ListProjects] [google.cloud.resourcemanager.v3.Projects.ListProjects]. However, you cannot update the project.
After the deletion completes, the project is not retrievable by the [GetProject] [google.cloud.resourcemanager.v3.Projects.GetProject], [ListProjects] [google.cloud.resourcemanager.v3.Projects.ListProjects], and [SearchProjects][google.cloud.resourcemanager.v3.Projects.SearchProjects] methods.
This method behaves idempotently, such that deleting a `DELETE_REQUESTED` project will not cause an error, but also won't do anything.
The caller must have `resourcemanager.projects.delete` permissions for this project.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
Project response = projectsClient.deleteProjectAsync(name).get();
}
name
- Required. The name of the Project (for example, `projects/415104041262`).ApiException
- if the remote call failspublic final OperationFuture<Project,DeleteProjectMetadata> deleteProjectAsync(String name)
This method will only affect the project if it has a lifecycle state of [ACTIVE][google.cloud.resourcemanager.v3.Project.State.ACTIVE].
This method changes the Project's lifecycle state from [ACTIVE][google.cloud.resourcemanager.v3.Project.State.ACTIVE] to [DELETE_REQUESTED][google.cloud.resourcemanager.v3.Project.State.DELETE_REQUESTED]. The deletion starts at an unspecified time, at which point the Project is no longer accessible.
Until the deletion completes, you can check the lifecycle state checked by retrieving the project with [GetProject] [google.cloud.resourcemanager.v3.Projects.GetProject], and the project remains visible to [ListProjects] [google.cloud.resourcemanager.v3.Projects.ListProjects]. However, you cannot update the project.
After the deletion completes, the project is not retrievable by the [GetProject] [google.cloud.resourcemanager.v3.Projects.GetProject], [ListProjects] [google.cloud.resourcemanager.v3.Projects.ListProjects], and [SearchProjects][google.cloud.resourcemanager.v3.Projects.SearchProjects] methods.
This method behaves idempotently, such that deleting a `DELETE_REQUESTED` project will not cause an error, but also won't do anything.
The caller must have `resourcemanager.projects.delete` permissions for this project.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
String name = ProjectName.of("[PROJECT]").toString();
Project response = projectsClient.deleteProjectAsync(name).get();
}
name
- Required. The name of the Project (for example, `projects/415104041262`).ApiException
- if the remote call failspublic final OperationFuture<Project,DeleteProjectMetadata> deleteProjectAsync(DeleteProjectRequest request)
This method will only affect the project if it has a lifecycle state of [ACTIVE][google.cloud.resourcemanager.v3.Project.State.ACTIVE].
This method changes the Project's lifecycle state from [ACTIVE][google.cloud.resourcemanager.v3.Project.State.ACTIVE] to [DELETE_REQUESTED][google.cloud.resourcemanager.v3.Project.State.DELETE_REQUESTED]. The deletion starts at an unspecified time, at which point the Project is no longer accessible.
Until the deletion completes, you can check the lifecycle state checked by retrieving the project with [GetProject] [google.cloud.resourcemanager.v3.Projects.GetProject], and the project remains visible to [ListProjects] [google.cloud.resourcemanager.v3.Projects.ListProjects]. However, you cannot update the project.
After the deletion completes, the project is not retrievable by the [GetProject] [google.cloud.resourcemanager.v3.Projects.GetProject], [ListProjects] [google.cloud.resourcemanager.v3.Projects.ListProjects], and [SearchProjects][google.cloud.resourcemanager.v3.Projects.SearchProjects] methods.
This method behaves idempotently, such that deleting a `DELETE_REQUESTED` project will not cause an error, but also won't do anything.
The caller must have `resourcemanager.projects.delete` permissions for this project.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
DeleteProjectRequest request =
DeleteProjectRequest.newBuilder().setName(ProjectName.of("[PROJECT]").toString()).build();
Project response = projectsClient.deleteProjectAsync(request).get();
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final OperationCallable<DeleteProjectRequest,Project,DeleteProjectMetadata> deleteProjectOperationCallable()
This method will only affect the project if it has a lifecycle state of [ACTIVE][google.cloud.resourcemanager.v3.Project.State.ACTIVE].
This method changes the Project's lifecycle state from [ACTIVE][google.cloud.resourcemanager.v3.Project.State.ACTIVE] to [DELETE_REQUESTED][google.cloud.resourcemanager.v3.Project.State.DELETE_REQUESTED]. The deletion starts at an unspecified time, at which point the Project is no longer accessible.
Until the deletion completes, you can check the lifecycle state checked by retrieving the project with [GetProject] [google.cloud.resourcemanager.v3.Projects.GetProject], and the project remains visible to [ListProjects] [google.cloud.resourcemanager.v3.Projects.ListProjects]. However, you cannot update the project.
After the deletion completes, the project is not retrievable by the [GetProject] [google.cloud.resourcemanager.v3.Projects.GetProject], [ListProjects] [google.cloud.resourcemanager.v3.Projects.ListProjects], and [SearchProjects][google.cloud.resourcemanager.v3.Projects.SearchProjects] methods.
This method behaves idempotently, such that deleting a `DELETE_REQUESTED` project will not cause an error, but also won't do anything.
The caller must have `resourcemanager.projects.delete` permissions for this project.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
DeleteProjectRequest request =
DeleteProjectRequest.newBuilder().setName(ProjectName.of("[PROJECT]").toString()).build();
OperationFuture<Project, DeleteProjectMetadata> future =
projectsClient.deleteProjectOperationCallable().futureCall(request);
// Do something.
Project response = future.get();
}
public final UnaryCallable<DeleteProjectRequest,Operation> deleteProjectCallable()
This method will only affect the project if it has a lifecycle state of [ACTIVE][google.cloud.resourcemanager.v3.Project.State.ACTIVE].
This method changes the Project's lifecycle state from [ACTIVE][google.cloud.resourcemanager.v3.Project.State.ACTIVE] to [DELETE_REQUESTED][google.cloud.resourcemanager.v3.Project.State.DELETE_REQUESTED]. The deletion starts at an unspecified time, at which point the Project is no longer accessible.
Until the deletion completes, you can check the lifecycle state checked by retrieving the project with [GetProject] [google.cloud.resourcemanager.v3.Projects.GetProject], and the project remains visible to [ListProjects] [google.cloud.resourcemanager.v3.Projects.ListProjects]. However, you cannot update the project.
After the deletion completes, the project is not retrievable by the [GetProject] [google.cloud.resourcemanager.v3.Projects.GetProject], [ListProjects] [google.cloud.resourcemanager.v3.Projects.ListProjects], and [SearchProjects][google.cloud.resourcemanager.v3.Projects.SearchProjects] methods.
This method behaves idempotently, such that deleting a `DELETE_REQUESTED` project will not cause an error, but also won't do anything.
The caller must have `resourcemanager.projects.delete` permissions for this project.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
DeleteProjectRequest request =
DeleteProjectRequest.newBuilder().setName(ProjectName.of("[PROJECT]").toString()).build();
ApiFuture<Operation> future = projectsClient.deleteProjectCallable().futureCall(request);
// Do something.
Operation response = future.get();
}
public final OperationFuture<Project,UndeleteProjectMetadata> undeleteProjectAsync(ProjectName name)
The caller must have `resourcemanager.projects.undelete` permission for this project.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
ProjectName name = ProjectName.of("[PROJECT]");
Project response = projectsClient.undeleteProjectAsync(name).get();
}
name
- Required. The name of the project (for example, `projects/415104041262`).
Required.
ApiException
- if the remote call failspublic final OperationFuture<Project,UndeleteProjectMetadata> undeleteProjectAsync(String name)
The caller must have `resourcemanager.projects.undelete` permission for this project.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
String name = ProjectName.of("[PROJECT]").toString();
Project response = projectsClient.undeleteProjectAsync(name).get();
}
name
- Required. The name of the project (for example, `projects/415104041262`).
Required.
ApiException
- if the remote call failspublic final OperationFuture<Project,UndeleteProjectMetadata> undeleteProjectAsync(UndeleteProjectRequest request)
The caller must have `resourcemanager.projects.undelete` permission for this project.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
UndeleteProjectRequest request =
UndeleteProjectRequest.newBuilder()
.setName(ProjectName.of("[PROJECT]").toString())
.build();
Project response = projectsClient.undeleteProjectAsync(request).get();
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final OperationCallable<UndeleteProjectRequest,Project,UndeleteProjectMetadata> undeleteProjectOperationCallable()
The caller must have `resourcemanager.projects.undelete` permission for this project.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
UndeleteProjectRequest request =
UndeleteProjectRequest.newBuilder()
.setName(ProjectName.of("[PROJECT]").toString())
.build();
OperationFuture<Project, UndeleteProjectMetadata> future =
projectsClient.undeleteProjectOperationCallable().futureCall(request);
// Do something.
Project response = future.get();
}
public final UnaryCallable<UndeleteProjectRequest,Operation> undeleteProjectCallable()
The caller must have `resourcemanager.projects.undelete` permission for this project.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
UndeleteProjectRequest request =
UndeleteProjectRequest.newBuilder()
.setName(ProjectName.of("[PROJECT]").toString())
.build();
ApiFuture<Operation> future = projectsClient.undeleteProjectCallable().futureCall(request);
// Do something.
Operation response = future.get();
}
public final com.google.iam.v1.Policy getIamPolicy(com.google.api.resourcenames.ResourceName resource)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
ResourceName resource = ProjectName.of("[PROJECT]");
Policy response = projectsClient.getIamPolicy(resource);
}
resource
- REQUIRED: The resource for which the policy is being requested. See the
operation documentation for the appropriate value for this field.ApiException
- if the remote call failspublic final com.google.iam.v1.Policy getIamPolicy(String resource)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
String resource = FolderName.of("[FOLDER]").toString();
Policy response = projectsClient.getIamPolicy(resource);
}
resource
- REQUIRED: The resource for which the policy is being requested. See the
operation documentation for the appropriate value for this field.ApiException
- if the remote call failspublic final com.google.iam.v1.Policy getIamPolicy(com.google.iam.v1.GetIamPolicyRequest request)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
GetIamPolicyRequest request =
GetIamPolicyRequest.newBuilder()
.setResource(ProjectName.of("[PROJECT]").toString())
.setOptions(GetPolicyOptions.newBuilder().build())
.build();
Policy response = projectsClient.getIamPolicy(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.iam.v1.GetIamPolicyRequest,com.google.iam.v1.Policy> getIamPolicyCallable()
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
GetIamPolicyRequest request =
GetIamPolicyRequest.newBuilder()
.setResource(ProjectName.of("[PROJECT]").toString())
.setOptions(GetPolicyOptions.newBuilder().build())
.build();
ApiFuture<Policy> future = projectsClient.getIamPolicyCallable().futureCall(request);
// Do something.
Policy response = future.get();
}
public final com.google.iam.v1.Policy setIamPolicy(com.google.api.resourcenames.ResourceName resource, com.google.iam.v1.Policy policy)
CAUTION: This method will replace the existing policy, and cannot be used to append additional IAM settings.
Note: Removing service accounts from policies or changing their roles can render services completely inoperable. It is important to understand how the service account is being used before removing or updating its roles.
The following constraints apply when using `setIamPolicy()`:
+ Project does not support `allUsers` and `allAuthenticatedUsers` as `members` in a `Binding` of a `Policy`.
+ The owner role can be granted to a `user`, `serviceAccount`, or a group that is part of an organization. For example, group@myownpersonaldomain.com could be added as an owner to a project in the myownpersonaldomain.com organization, but not the examplepetstore.com organization.
+ Service accounts can be made owners of a project directly without any restrictions. However, to be added as an owner, a user must be invited using the Cloud Platform console and must accept the invitation.
+ A user cannot be granted the owner role using `setIamPolicy()`. The user must be granted the owner role using the Cloud Platform Console and must explicitly accept the invitation.
+ Invitations to grant the owner role cannot be sent using `setIamPolicy()`; they must be sent only using the Cloud Platform Console.
+ Membership changes that leave the project without any owners that have accepted the Terms of Service (ToS) will be rejected.
+ If the project is not part of an organization, there must be at least one owner who has accepted the Terms of Service (ToS) agreement in the policy. Calling `setIamPolicy()` to remove the last ToS-accepted owner from the policy will fail. This restriction also applies to legacy projects that no longer have owners who have accepted the ToS. Edits to IAM policies will be rejected until the lack of a ToS-accepting owner is rectified.
+ Calling this method requires enabling the App Engine Admin API.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
ResourceName resource = ProjectName.of("[PROJECT]");
Policy policy = Policy.newBuilder().build();
Policy response = projectsClient.setIamPolicy(resource, policy);
}
resource
- REQUIRED: The resource for which the policy is being specified. See the
operation documentation for the appropriate value for this field.policy
- REQUIRED: The complete policy to be applied to the `resource`. The size of the
policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud
Platform services (such as Projects) might reject them.ApiException
- if the remote call failspublic final com.google.iam.v1.Policy setIamPolicy(String resource, com.google.iam.v1.Policy policy)
CAUTION: This method will replace the existing policy, and cannot be used to append additional IAM settings.
Note: Removing service accounts from policies or changing their roles can render services completely inoperable. It is important to understand how the service account is being used before removing or updating its roles.
The following constraints apply when using `setIamPolicy()`:
+ Project does not support `allUsers` and `allAuthenticatedUsers` as `members` in a `Binding` of a `Policy`.
+ The owner role can be granted to a `user`, `serviceAccount`, or a group that is part of an organization. For example, group@myownpersonaldomain.com could be added as an owner to a project in the myownpersonaldomain.com organization, but not the examplepetstore.com organization.
+ Service accounts can be made owners of a project directly without any restrictions. However, to be added as an owner, a user must be invited using the Cloud Platform console and must accept the invitation.
+ A user cannot be granted the owner role using `setIamPolicy()`. The user must be granted the owner role using the Cloud Platform Console and must explicitly accept the invitation.
+ Invitations to grant the owner role cannot be sent using `setIamPolicy()`; they must be sent only using the Cloud Platform Console.
+ Membership changes that leave the project without any owners that have accepted the Terms of Service (ToS) will be rejected.
+ If the project is not part of an organization, there must be at least one owner who has accepted the Terms of Service (ToS) agreement in the policy. Calling `setIamPolicy()` to remove the last ToS-accepted owner from the policy will fail. This restriction also applies to legacy projects that no longer have owners who have accepted the ToS. Edits to IAM policies will be rejected until the lack of a ToS-accepting owner is rectified.
+ Calling this method requires enabling the App Engine Admin API.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
String resource = FolderName.of("[FOLDER]").toString();
Policy policy = Policy.newBuilder().build();
Policy response = projectsClient.setIamPolicy(resource, policy);
}
resource
- REQUIRED: The resource for which the policy is being specified. See the
operation documentation for the appropriate value for this field.policy
- REQUIRED: The complete policy to be applied to the `resource`. The size of the
policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud
Platform services (such as Projects) might reject them.ApiException
- if the remote call failspublic final com.google.iam.v1.Policy setIamPolicy(com.google.iam.v1.SetIamPolicyRequest request)
CAUTION: This method will replace the existing policy, and cannot be used to append additional IAM settings.
Note: Removing service accounts from policies or changing their roles can render services completely inoperable. It is important to understand how the service account is being used before removing or updating its roles.
The following constraints apply when using `setIamPolicy()`:
+ Project does not support `allUsers` and `allAuthenticatedUsers` as `members` in a `Binding` of a `Policy`.
+ The owner role can be granted to a `user`, `serviceAccount`, or a group that is part of an organization. For example, group@myownpersonaldomain.com could be added as an owner to a project in the myownpersonaldomain.com organization, but not the examplepetstore.com organization.
+ Service accounts can be made owners of a project directly without any restrictions. However, to be added as an owner, a user must be invited using the Cloud Platform console and must accept the invitation.
+ A user cannot be granted the owner role using `setIamPolicy()`. The user must be granted the owner role using the Cloud Platform Console and must explicitly accept the invitation.
+ Invitations to grant the owner role cannot be sent using `setIamPolicy()`; they must be sent only using the Cloud Platform Console.
+ Membership changes that leave the project without any owners that have accepted the Terms of Service (ToS) will be rejected.
+ If the project is not part of an organization, there must be at least one owner who has accepted the Terms of Service (ToS) agreement in the policy. Calling `setIamPolicy()` to remove the last ToS-accepted owner from the policy will fail. This restriction also applies to legacy projects that no longer have owners who have accepted the ToS. Edits to IAM policies will be rejected until the lack of a ToS-accepting owner is rectified.
+ Calling this method requires enabling the App Engine Admin API.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
SetIamPolicyRequest request =
SetIamPolicyRequest.newBuilder()
.setResource(ProjectName.of("[PROJECT]").toString())
.setPolicy(Policy.newBuilder().build())
.setUpdateMask(FieldMask.newBuilder().build())
.build();
Policy response = projectsClient.setIamPolicy(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.iam.v1.SetIamPolicyRequest,com.google.iam.v1.Policy> setIamPolicyCallable()
CAUTION: This method will replace the existing policy, and cannot be used to append additional IAM settings.
Note: Removing service accounts from policies or changing their roles can render services completely inoperable. It is important to understand how the service account is being used before removing or updating its roles.
The following constraints apply when using `setIamPolicy()`:
+ Project does not support `allUsers` and `allAuthenticatedUsers` as `members` in a `Binding` of a `Policy`.
+ The owner role can be granted to a `user`, `serviceAccount`, or a group that is part of an organization. For example, group@myownpersonaldomain.com could be added as an owner to a project in the myownpersonaldomain.com organization, but not the examplepetstore.com organization.
+ Service accounts can be made owners of a project directly without any restrictions. However, to be added as an owner, a user must be invited using the Cloud Platform console and must accept the invitation.
+ A user cannot be granted the owner role using `setIamPolicy()`. The user must be granted the owner role using the Cloud Platform Console and must explicitly accept the invitation.
+ Invitations to grant the owner role cannot be sent using `setIamPolicy()`; they must be sent only using the Cloud Platform Console.
+ Membership changes that leave the project without any owners that have accepted the Terms of Service (ToS) will be rejected.
+ If the project is not part of an organization, there must be at least one owner who has accepted the Terms of Service (ToS) agreement in the policy. Calling `setIamPolicy()` to remove the last ToS-accepted owner from the policy will fail. This restriction also applies to legacy projects that no longer have owners who have accepted the ToS. Edits to IAM policies will be rejected until the lack of a ToS-accepting owner is rectified.
+ Calling this method requires enabling the App Engine Admin API.
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
SetIamPolicyRequest request =
SetIamPolicyRequest.newBuilder()
.setResource(ProjectName.of("[PROJECT]").toString())
.setPolicy(Policy.newBuilder().build())
.setUpdateMask(FieldMask.newBuilder().build())
.build();
ApiFuture<Policy> future = projectsClient.setIamPolicyCallable().futureCall(request);
// Do something.
Policy response = future.get();
}
public final com.google.iam.v1.TestIamPermissionsResponse testIamPermissions(com.google.api.resourcenames.ResourceName resource, List<String> permissions)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
ResourceName resource = ProjectName.of("[PROJECT]");
List<String> permissions = new ArrayList<>();
TestIamPermissionsResponse response =
projectsClient.testIamPermissions(resource, permissions);
}
resource
- REQUIRED: The resource for which the policy detail is being requested. See the
operation documentation for the appropriate value for this field.permissions
- The set of permissions to check for the `resource`. Permissions with
wildcards (such as '*' or 'storage.*') are not allowed. For more information see
[IAM Overview](https://cloud.google.com/iam/docs/overview#permissions).ApiException
- if the remote call failspublic final com.google.iam.v1.TestIamPermissionsResponse testIamPermissions(String resource, List<String> permissions)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
String resource = FolderName.of("[FOLDER]").toString();
List<String> permissions = new ArrayList<>();
TestIamPermissionsResponse response =
projectsClient.testIamPermissions(resource, permissions);
}
resource
- REQUIRED: The resource for which the policy detail is being requested. See the
operation documentation for the appropriate value for this field.permissions
- The set of permissions to check for the `resource`. Permissions with
wildcards (such as '*' or 'storage.*') are not allowed. For more information see
[IAM Overview](https://cloud.google.com/iam/docs/overview#permissions).ApiException
- if the remote call failspublic final com.google.iam.v1.TestIamPermissionsResponse testIamPermissions(com.google.iam.v1.TestIamPermissionsRequest request)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
TestIamPermissionsRequest request =
TestIamPermissionsRequest.newBuilder()
.setResource(ProjectName.of("[PROJECT]").toString())
.addAllPermissions(new ArrayList<String>())
.build();
TestIamPermissionsResponse response = projectsClient.testIamPermissions(request);
}
request
- The request object containing all of the parameters for the API call.ApiException
- if the remote call failspublic final UnaryCallable<com.google.iam.v1.TestIamPermissionsRequest,com.google.iam.v1.TestIamPermissionsResponse> testIamPermissionsCallable()
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ProjectsClient projectsClient = ProjectsClient.create()) {
TestIamPermissionsRequest request =
TestIamPermissionsRequest.newBuilder()
.setResource(ProjectName.of("[PROJECT]").toString())
.addAllPermissions(new ArrayList<String>())
.build();
ApiFuture<TestIamPermissionsResponse> future =
projectsClient.testIamPermissionsCallable().futureCall(request);
// Do something.
TestIamPermissionsResponse response = future.get();
}
public final void close()
close
in interface AutoCloseable
public void shutdown()
shutdown
in interface BackgroundResource
public boolean isShutdown()
isShutdown
in interface BackgroundResource
public boolean isTerminated()
isTerminated
in interface BackgroundResource
public void shutdownNow()
shutdownNow
in interface BackgroundResource
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException
awaitTermination
in interface BackgroundResource
InterruptedException
Copyright © 2022 Google LLC. All rights reserved.