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);
}
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());
}
}
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());
}
Aggregations