Search in sources :

Example 56 with Project

use of com.google.api.services.cloudresourcemanager.v3.model.Project in project blackduck-common by blackducksoftware.

the class Bdio2Factory method createAndLinkComponentsFromGraph.

private Pair<List<Project>, List<Component>> createAndLinkComponentsFromGraph(DependencyGraph dependencyGraph, @Nullable SubProjectFunction linkProjectDependency, DependencyFunction linkComponentDependency, Set<Dependency> dependencies, Map<ExternalId, Project> existingSubprojects, Map<ExternalId, Component> existingComponents) {
    List<Project> addedSubprojects = new ArrayList<>();
    List<Component> addedComponents = new ArrayList<>();
    for (Dependency dependency : dependencies) {
        if (dependency instanceof ProjectDependency) {
            if (linkProjectDependency == null) {
                // Subprojects cannot be dependencies of components
                // TODO is there a better way to handle this?
                // passing subProjectFunction: component::dependency on line 124 might look better (but be more nonsensical?)
                String subprojectExternalId = dependency.getExternalId().toString();
                logger.warn("Sipping subproject {}. Failed to add the subproject to the graph because subprojects cannot be dependencies of components. Please contact Synopsys support.", subprojectExternalId);
                continue;
            // Jake's maybe better way for now? Exposed a few issues with graph building. See IDETECT-3243
            // throw new UnsupportedOperationException("Subprojects cannot be dependencies of components. The graph was incorrectly built.");
            }
            Project subproject = projectFromDependency(dependency);
            linkProjectDependency.subProject(new Project(subproject.id()).subproject(subproject));
            if (!existingSubprojects.containsKey(dependency.getExternalId())) {
                addedSubprojects.add(subproject);
                existingSubprojects.put(dependency.getExternalId(), subproject);
                Pair<List<Project>, List<Component>> children = createAndLinkComponentsFromGraph(dependencyGraph, subproject::subproject, subproject::dependency, dependencyGraph.getChildrenForParent(dependency), existingSubprojects, existingComponents);
                addedSubprojects.addAll(children.getLeft());
                addedComponents.addAll(children.getRight());
            }
        } else {
            Component component = componentFromDependency(dependency);
            linkComponentDependency.dependency(new com.blackducksoftware.bdio2.model.Dependency().dependsOn(component));
            if (!existingComponents.containsKey(dependency.getExternalId())) {
                addedComponents.add(component);
                existingComponents.put(dependency.getExternalId(), component);
                Pair<List<Project>, List<Component>> children = createAndLinkComponentsFromGraph(dependencyGraph, null, component::dependency, dependencyGraph.getChildrenForParent(dependency), existingSubprojects, existingComponents);
                addedSubprojects.addAll(children.getLeft());
                addedComponents.addAll(children.getRight());
            }
        }
    }
    return Pair.of(addedSubprojects, addedComponents);
}
Also used : ArrayList(java.util.ArrayList) ProjectDependency(com.synopsys.integration.bdio.model.dependency.ProjectDependency) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency) ProjectDependency(com.synopsys.integration.bdio.model.dependency.ProjectDependency) Project(com.blackducksoftware.bdio2.model.Project) ProductList(com.blackducksoftware.common.value.ProductList) ArrayList(java.util.ArrayList) List(java.util.List) Component(com.blackducksoftware.bdio2.model.Component)

Example 57 with Project

use of com.google.api.services.cloudresourcemanager.v3.model.Project in project terra-workspace-manager by DataBiosphere.

the class CreateGcpContextFlightTest method assertPolicyGroupsSynced.

/**
 * Asserts that Sam groups are granted their appropriate IAM roles on a GCP project.
 */
private void assertPolicyGroupsSynced(UUID workspaceId, Project project) throws Exception {
    Map<WsmIamRole, String> roleToSamGroup = Arrays.stream(WsmIamRole.values()).filter(role -> !role.equals(WsmIamRole.MANAGER)).collect(Collectors.toMap(Function.identity(), role -> "group:" + SamRethrow.onInterrupted(() -> mockSamService.syncWorkspacePolicy(workspaceId, role, userAccessUtils.defaultUserAuthRequest()), "syncWorkspacePolicy")));
    Policy currentPolicy = crl.getCloudResourceManagerCow().projects().getIamPolicy(project.getProjectId(), new GetIamPolicyRequest()).execute();
    for (WsmIamRole role : WsmIamRole.values()) {
        // Don't check MANAGER role, which isn't synced to GCP.
        if (role.equals(WsmIamRole.MANAGER)) {
            continue;
        }
        assertRoleBindingInPolicy(role, roleToSamGroup.get(role), currentPolicy, project.getProjectId());
    }
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) WsmIamRole(bio.terra.workspace.service.iam.model.WsmIamRole) SamService(bio.terra.workspace.service.iam.SamService) Autowired(org.springframework.beans.factory.annotation.Autowired) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) CloudSyncRoleMapping(bio.terra.workspace.service.workspace.CloudSyncRoleMapping) Role(com.google.api.services.iam.v1.model.Role) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) GetIamPolicyRequest(com.google.api.services.cloudresourcemanager.v3.model.GetIamPolicyRequest) FlightState(bio.terra.stairway.FlightState) Duration(java.time.Duration) Map(java.util.Map) SpendUnauthorizedException(bio.terra.workspace.service.spendprofile.exceptions.SpendUnauthorizedException) CustomGcpIamRoleMapping(bio.terra.workspace.service.resource.controlled.cloud.gcp.CustomGcpIamRoleMapping) JobService(bio.terra.workspace.service.job.JobService) MockBean(org.springframework.boot.test.mock.mockito.MockBean) UserAccessUtils(bio.terra.workspace.connected.UserAccessUtils) NoBillingAccountException(bio.terra.workspace.service.workspace.exceptions.NoBillingAccountException) StairwayTestUtils(bio.terra.workspace.common.StairwayTestUtils) Binding(com.google.api.services.cloudresourcemanager.v3.model.Binding) UUID(java.util.UUID) SpendProfileId(bio.terra.workspace.service.spendprofile.SpendProfileId) Collectors(java.util.stream.Collectors) WorkspaceConnectedTestUtils(bio.terra.workspace.connected.WorkspaceConnectedTestUtils) CustomGcpIamRole(bio.terra.workspace.service.resource.controlled.cloud.gcp.CustomGcpIamRole) Test(org.junit.jupiter.api.Test) List(java.util.List) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) StepStatus(bio.terra.stairway.StepStatus) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) JobMapKeys(bio.terra.workspace.service.job.JobMapKeys) WorkspaceService(bio.terra.workspace.service.workspace.WorkspaceService) Policy(com.google.api.services.cloudresourcemanager.v3.model.Policy) Project(com.google.api.services.cloudresourcemanager.v3.model.Project) HashMap(java.util.HashMap) Function(java.util.function.Function) SamResource(bio.terra.workspace.service.iam.model.SamConstants.SamResource) SamRethrow(bio.terra.workspace.service.iam.SamRethrow) DisabledIfEnvironmentVariable(org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) FlightDebugInfo(bio.terra.stairway.FlightDebugInfo) CrlService(bio.terra.workspace.service.crl.CrlService) Nullable(javax.annotation.Nullable) SamSpendProfileAction(bio.terra.workspace.service.iam.model.SamConstants.SamSpendProfileAction) MissingSpendProfileException(bio.terra.workspace.service.workspace.exceptions.MissingSpendProfileException) FlightMap(bio.terra.stairway.FlightMap) Workspace(bio.terra.workspace.service.workspace.model.Workspace) IOException(java.io.IOException) BaseConnectedTest(bio.terra.workspace.common.BaseConnectedTest) SpendConnectedTestUtils(bio.terra.workspace.service.spendprofile.SpendConnectedTestUtils) WorkspaceStage(bio.terra.workspace.service.workspace.model.WorkspaceStage) Mockito(org.mockito.Mockito) FlightStatus(bio.terra.stairway.FlightStatus) Collections(java.util.Collections) Policy(com.google.api.services.cloudresourcemanager.v3.model.Policy) GetIamPolicyRequest(com.google.api.services.cloudresourcemanager.v3.model.GetIamPolicyRequest) WsmIamRole(bio.terra.workspace.service.iam.model.WsmIamRole)

Example 58 with Project

use of com.google.api.services.cloudresourcemanager.v3.model.Project in project terra-workspace-manager by DataBiosphere.

the class CreateGcpContextFlightTest method errorRevertsChanges.

@Test
@DisabledIfEnvironmentVariable(named = "TEST_ENV", matches = BUFFER_SERVICE_DISABLED_ENVS_REG_EX)
void errorRevertsChanges() throws Exception {
    UUID workspaceId = createWorkspace(spendUtils.defaultSpendId());
    AuthenticatedUserRequest userRequest = userAccessUtils.defaultUserAuthRequest();
    assertTrue(testUtils.getAuthorizedGcpCloudContext(workspaceId, userRequest).isEmpty());
    // Submit a flight class that always errors.
    Map<String, StepStatus> retrySteps = getStepNameToStepStatusMap();
    FlightDebugInfo debugInfo = FlightDebugInfo.newBuilder().undoStepFailures(retrySteps).lastStepFailure(true).build();
    FlightState flightState = StairwayTestUtils.blockUntilFlightCompletes(jobService.getStairway(), CreateGcpContextFlight.class, createInputParameters(workspaceId, userRequest), STAIRWAY_FLIGHT_TIMEOUT, debugInfo);
    assertEquals(FlightStatus.ERROR, flightState.getFlightStatus());
    assertTrue(testUtils.getAuthorizedGcpCloudContext(workspaceId, userRequest).isEmpty());
    String projectId = flightState.getResultMap().get().get(WorkspaceFlightMapKeys.GCP_PROJECT_ID, String.class);
    // The Project should exist, but requested to be deleted.
    Project project = crl.getCloudResourceManagerCow().projects().get(projectId).execute();
    assertEquals(projectId, project.getProjectId());
    assertEquals("DELETE_REQUESTED", project.getState());
}
Also used : FlightState(bio.terra.stairway.FlightState) Project(com.google.api.services.cloudresourcemanager.v3.model.Project) FlightDebugInfo(bio.terra.stairway.FlightDebugInfo) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) StepStatus(bio.terra.stairway.StepStatus) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test) BaseConnectedTest(bio.terra.workspace.common.BaseConnectedTest) DisabledIfEnvironmentVariable(org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable)

Aggregations

Project (com.google.api.services.cloudresourcemanager.v3.model.Project)38 Test (org.junit.jupiter.api.Test)30 BaseIntegrationTest (bio.terra.buffer.common.BaseIntegrationTest)15 Pool (bio.terra.buffer.common.Pool)15 ResourceId (bio.terra.buffer.common.ResourceId)15 IntegrationUtils.preparePool (bio.terra.buffer.integration.IntegrationUtils.preparePool)15 FlightManager (bio.terra.buffer.service.resource.FlightManager)15 IOException (java.io.IOException)13 Binding (com.google.api.services.cloudresourcemanager.v3.model.Binding)10 StepStatus (bio.terra.stairway.StepStatus)9 ArrayList (java.util.ArrayList)9 BaseConnectedTest (bio.terra.workspace.common.BaseConnectedTest)8 List (java.util.List)8 DisabledIfEnvironmentVariable (org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable)8 FlightDebugInfo (bio.terra.stairway.FlightDebugInfo)7 FlightState (bio.terra.stairway.FlightState)7 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)7 GetIamPolicyRequest (com.google.api.services.cloudresourcemanager.v3.model.GetIamPolicyRequest)7 FlightMap (bio.terra.stairway.FlightMap)6 Project (com.blackducksoftware.bdio2.model.Project)6