/** * Fetches the project's latest information. Returns {@code null} if the project does not exist. * * @return Project containing the project's updated metadata or {@code null} if not found * @throws ResourceManagerException upon failure */ public Project reload() { return resourceManager.get(getProjectId()); }
/** * Sets the IAM access control policy for this project. Replaces any existing policy. It is * recommended that you use the read-modify-write pattern. See code samples and important details * of replacing policies in the documentation for {@link ResourceManager#replacePolicy}. * * @return the newly set IAM policy for this project * @throws ResourceManagerException upon failure * @see <a href= * "https://cloud.google.com/resource-manager/reference/rest/v1beta1/projects/setIamPolicy"> * Resource Manager setIamPolicy</a> */ public Policy replacePolicy(Policy newPolicy) { return resourceManager.replacePolicy(getProjectId(), newPolicy); }
/** * Returns the IAM access control policy for this project. Returns {@code null} if the resource * does not exist or if you do not have adequate permission to view the project or get the policy. * * @return the IAM policy for the project * @throws ResourceManagerException upon failure * @see <a href= * "https://cloud.google.com/resource-manager/reference/rest/v1beta1/projects/getIamPolicy"> * Resource Manager getIamPolicy</a> */ public Policy getPolicy() { return resourceManager.getPolicy(getProjectId()); }
/** * Restores the project identified by the specified project ID. * * <p>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. * * @throws ResourceManagerException upon failure (including when the project can't be restored) * @see <a href= * "https://cloud.google.com/resource-manager/reference/rest/v1beta1/projects/undelete">Cloud * Resource Manager undelete</a> */ public void undelete() { resourceManager.undelete(getProjectId()); }
/** * Returns the permissions that a caller has on this project. You typically don't call this method * if you're using Google Cloud Platform directly to manage permissions. This method is intended * for integration with your proprietary software, such as a customized graphical user interface. * For example, the Cloud Platform Console tests IAM permissions internally to determine which UI * should be available to the logged-in user. Each service that supports IAM lists the possible * permissions; see the <i>Supported Cloud Platform services</i> page below for links to these * lists. * * @return a list of booleans representing whether the caller has the permissions specified (in * the order of the given permissions) * @throws ResourceManagerException upon failure * @see <a href= * "https://cloud.google.com/resource-manager/reference/rest/v1beta1/projects/testIamPermissions"> * Resource Manager testIamPermissions</a> * @see <a href= "https://cloud.google.com/iam/#supported_cloud_platform_services">Supported Cloud * Platform Services</a> */ List<Boolean> testPermissions(List<String> permissions) { return resourceManager.testPermissions(getProjectId(), permissions); }
/** * Marks the project identified by the specified project ID for deletion. * * <p>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. * * @throws ResourceManagerException upon failure * @see <a href= * "https://cloud.google.com/resource-manager/reference/rest/v1beta1/projects/delete">Cloud * Resource Manager delete</a> */ public void delete() { resourceManager.delete(getProjectId()); }
public static void main(String... args) { // Create Resource Manager service object // By default, credentials are inferred from the runtime environment. ResourceManager resourceManager = ResourceManagerOptions.getDefaultInstance().getService(); // Get a project from the server Project project = resourceManager.get("some-project-id"); // Use an existing project's ID // Update a project if (project != null) { Project newProject = project.toBuilder().addLabel("launch-status", "in-development").build().replace(); System.out.println( "Updated the labels of project " + newProject.getProjectId() + " to be " + newProject.getLabels()); } // List all the projects you have permission to view. System.out.println("Projects I can view:"); for (Project currentProject : resourceManager.list().iterateAll()) { System.out.println(currentProject.getProjectId()); } } }
public static void main(String... args) { // Create Resource Manager service object. // By default, credentials are inferred from the runtime environment. ResourceManager resourceManager = ResourceManagerOptions.getDefaultInstance().getService(); String projectId = "my-globally-unique-project-id"; // Change to a unique project ID. // Get a project from the server. Project project = resourceManager.get(projectId); if (project == null) { // Create a project. project = resourceManager.create(ProjectInfo.newBuilder(projectId).build()); } System.out.println("Got project " + project.getProjectId() + " from the server."); } }
private void clearProjects() { for (Project project : RESOURCE_MANAGER.list().getValues()) { RESOURCE_MANAGER_HELPER.removeProject(project.getProjectId()); } }
@Test public void testList() { Page<Project> projects = RESOURCE_MANAGER.list(); assertFalse(projects.getValues().iterator().hasNext()); RESOURCE_MANAGER.create(PARTIAL_PROJECT); RESOURCE_MANAGER.create(COMPLETE_PROJECT); for (Project p : RESOURCE_MANAGER.list().getValues()) { if (p.getProjectId().equals(PARTIAL_PROJECT.getProjectId())) { compareReadWriteFields(PARTIAL_PROJECT, p); } else if (p.getProjectId().equals(COMPLETE_PROJECT.getProjectId())) { compareReadWriteFields(COMPLETE_PROJECT, p); } else { fail("Some unexpected project returned by list."); } assertSame(RESOURCE_MANAGER, p.getResourceManager()); } }
@Test public void testListFieldOptions() { RESOURCE_MANAGER.create(COMPLETE_PROJECT); Page<Project> projects = RESOURCE_MANAGER.list(LIST_FIELDS); Project returnedProject = projects.iterateAll().iterator().next(); assertEquals(COMPLETE_PROJECT.getProjectId(), returnedProject.getProjectId()); assertEquals(COMPLETE_PROJECT.getName(), returnedProject.getName()); assertEquals(COMPLETE_PROJECT.getLabels(), returnedProject.getLabels()); assertNull(returnedProject.getParent()); assertNull(returnedProject.getProjectNumber()); assertNull(returnedProject.getState()); assertNull(returnedProject.getCreateTimeMillis()); assertSame(RESOURCE_MANAGER, returnedProject.getResourceManager()); }
Iterator<Project> iterator = projects.getValues().iterator(); Project returnedProject = iterator.next(); assertEquals(COMPLETE_PROJECT.getProjectId(), returnedProject.getProjectId()); assertEquals(COMPLETE_PROJECT.getName(), returnedProject.getName()); assertEquals(COMPLETE_PROJECT.getLabels(), returnedProject.getLabels()); iterator = projects.getValues().iterator(); returnedProject = iterator.next(); assertEquals(PARTIAL_PROJECT.getProjectId(), returnedProject.getProjectId()); assertEquals(PARTIAL_PROJECT.getName(), returnedProject.getName()); assertEquals(PARTIAL_PROJECT.getLabels(), returnedProject.getLabels());
@Test public void testGetWithOptions() { Project originalProject = RESOURCE_MANAGER.create(COMPLETE_PROJECT); Project returnedProject = RESOURCE_MANAGER.get(COMPLETE_PROJECT.getProjectId(), GET_FIELDS); assertFalse(COMPLETE_PROJECT.equals(returnedProject)); assertEquals(COMPLETE_PROJECT.getProjectId(), returnedProject.getProjectId()); assertEquals(COMPLETE_PROJECT.getName(), returnedProject.getName()); assertEquals(originalProject.getCreateTimeMillis(), returnedProject.getCreateTimeMillis()); assertNull(returnedProject.getParent()); assertNull(returnedProject.getProjectNumber()); assertNull(returnedProject.getState()); assertTrue(returnedProject.getLabels().isEmpty()); assertEquals(RESOURCE_MANAGER, originalProject.getResourceManager()); assertEquals(RESOURCE_MANAGER, returnedProject.getResourceManager()); }
.setState(STATE) .build(); assertEquals(PROJECT_ID, project.getProjectId()); assertEquals(NAME, project.getName()); assertEquals(LABELS, project.getLabels()); .setParent(parent) .build(); assertEquals(PROJECT_ID, project.getProjectId()); assertEquals(NAME, project.getName()); assertEquals(ImmutableMap.of("k3", "v3"), project.getLabels());