@Override public void run(ResourceManager resourceManager, String... args) { String projectId = args[0]; System.out.printf("Going to delete project \"%s\". Are you sure [y/N]: ", projectId); Scanner scanner = new Scanner(System.in); if (scanner.nextLine().toLowerCase().equals("y")) { resourceManager.delete(projectId); System.out.printf("Successfully deleted project %s.%n", projectId); } else { System.out.printf("Will not delete project %s.%n", projectId); } scanner.close(); }
/** * 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()); }
@Test public void testDelete() { initializeExpectedProject(1); expect(resourceManager.getOptions()).andReturn(mockOptions); resourceManager.delete(PROJECT_INFO.getProjectId()); replay(resourceManager); initializeProject(); project.delete(); }
@Test public void testDelete() { RESOURCE_MANAGER.create(COMPLETE_PROJECT); RESOURCE_MANAGER.delete(COMPLETE_PROJECT.getProjectId()); assertEquals( ProjectInfo.State.DELETE_REQUESTED, RESOURCE_MANAGER.get(COMPLETE_PROJECT.getProjectId()).getState()); try { RESOURCE_MANAGER.delete("some-nonexistant-project-id"); fail("Should fail because the project doesn't exist."); } catch (ResourceManagerException e) { assertEquals(403, e.getCode()); assertTrue(e.getMessage().contains("not found.")); } }
@Test public void testUndelete() { RESOURCE_MANAGER.create(COMPLETE_PROJECT); RESOURCE_MANAGER.delete(COMPLETE_PROJECT.getProjectId()); assertEquals( ProjectInfo.State.DELETE_REQUESTED, RESOURCE_MANAGER.get(COMPLETE_PROJECT.getProjectId()).getState()); RESOURCE_MANAGER.undelete(COMPLETE_PROJECT.getProjectId()); ProjectInfo revivedProject = RESOURCE_MANAGER.get(COMPLETE_PROJECT.getProjectId()); compareReadWriteFields(COMPLETE_PROJECT, revivedProject); assertEquals(ProjectInfo.State.ACTIVE, revivedProject.getState()); try { RESOURCE_MANAGER.undelete("invalid-project-id"); fail("Should fail because the project doesn't exist."); } catch (ResourceManagerException e) { assertEquals(403, e.getCode()); assertTrue(e.getMessage().contains("the project was not found")); } }
/** * 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(projectId()); }