Search in sources :

Example 41 with Project

use of com.blackducksoftware.bdio2.model.Project in project terra-resource-buffer by DataBiosphere.

the class CreateProjectFlightIntegrationTest method testCreateGoogleProject_blockedRegions.

@Test
public void testCreateGoogleProject_blockedRegions() throws Exception {
    List<String> blockedRegions = ImmutableList.of("europe-west2", "us-west4");
    FlightManager manager = new FlightManager(bufferDao, flightSubmissionFactoryImpl, stairwayComponent, transactionTemplate);
    Pool pool = preparePool(bufferDao, newBasicGcpConfig().network(new bio.terra.buffer.generated.model.Network().blockedRegions(blockedRegions)));
    String flightId = manager.submitCreationFlight(pool).get();
    ResourceId resourceId = extractResourceIdFromFlightState(blockUntilFlightComplete(stairwayComponent, flightId));
    Project project = assertProjectExists(resourceId);
    assertNoSubnetsInBlockedRegions(project, blockedRegions);
}
Also used : Project(com.google.api.services.cloudresourcemanager.v3.model.Project) ResourceId(bio.terra.buffer.common.ResourceId) Pool(bio.terra.buffer.common.Pool) IntegrationUtils.preparePool(bio.terra.buffer.integration.IntegrationUtils.preparePool) bio.terra.buffer.generated.model(bio.terra.buffer.generated.model) FlightManager(bio.terra.buffer.service.resource.FlightManager) Test(org.junit.jupiter.api.Test) BaseIntegrationTest(bio.terra.buffer.common.BaseIntegrationTest)

Example 42 with Project

use of com.blackducksoftware.bdio2.model.Project in project terra-resource-buffer by DataBiosphere.

the class CreateProjectFlightIntegrationTest method testCreateGoogleProject_multipleSteps.

@Test
public void testCreateGoogleProject_multipleSteps() throws Exception {
    // Verify flight is able to finish with multiple same steps exists.
    FlightManager manager = new FlightManager(bufferDao, new StubSubmissionFlightFactory(MultiInstanceStepFlight.class), stairwayComponent, transactionTemplate);
    Pool pool = preparePool(bufferDao, newFullGcpConfig());
    String flightId = manager.submitCreationFlight(pool).get();
    ResourceId resourceId = extractResourceIdFromFlightState(blockUntilFlightComplete(stairwayComponent, flightId));
    Project project = assertProjectExists(resourceId);
    assertIamBindingsContains(project, IAM_BINDINGS);
    assertNetworkExists(project);
    assertSubnetsExist(project, NetworkMonitoring.ENABLED);
    assertRouteExists(project);
    assertDnsExists(project);
}
Also used : Project(com.google.api.services.cloudresourcemanager.v3.model.Project) ResourceId(bio.terra.buffer.common.ResourceId) Pool(bio.terra.buffer.common.Pool) IntegrationUtils.preparePool(bio.terra.buffer.integration.IntegrationUtils.preparePool) FlightManager(bio.terra.buffer.service.resource.FlightManager) StubSubmissionFlightFactory(bio.terra.buffer.integration.IntegrationUtils.StubSubmissionFlightFactory) Test(org.junit.jupiter.api.Test) BaseIntegrationTest(bio.terra.buffer.common.BaseIntegrationTest)

Example 43 with Project

use of com.blackducksoftware.bdio2.model.Project in project terra-resource-buffer by DataBiosphere.

the class CreateProjectFlightIntegrationTest method assertDnsExists.

private void assertDnsExists(Project project) throws Exception {
    String projectId = project.getProjectId();
    ManagedZone managedZone = dnsCow.managedZones().get(projectId, MANAGED_ZONE_NAME).execute();
    Map<String, ResourceRecordSet> resourceRecordSets = dnsCow.resourceRecordSets().list(project.getProjectId(), MANAGED_ZONE_NAME).execute().getRrsets().stream().collect(Collectors.toMap(ResourceRecordSet::getType, r -> r));
    ResourceRecordSet aRecordSet = resourceRecordSets.get(RESTRICT_API_A_RECORD.getType());
    ResourceRecordSet cnameRecordSet = resourceRecordSets.get(RESTRICT_API_CNAME_RECORD.getType());
    assertEquals(MANAGED_ZONE_TEMPLATE.getName(), managedZone.getName());
    assertEquals(MANAGED_ZONE_TEMPLATE.getVisibility(), managedZone.getVisibility().toLowerCase());
    assertEquals(MANAGED_ZONE_TEMPLATE.getDescription(), managedZone.getDescription());
    assertResourceRecordSetMatch(RESTRICT_API_A_RECORD, aRecordSet);
    assertResourceRecordSetMatch(RESTRICT_API_CNAME_RECORD, cnameRecordSet);
}
Also used : ResourceRecordSet(com.google.api.services.dns.model.ResourceRecordSet) LEONARDO_ALLOW_INTERNAL_RULE_NAME_LABEL_KEY(bio.terra.buffer.service.resource.flight.CreateProjectStep.LEONARDO_ALLOW_INTERNAL_RULE_NAME_LABEL_KEY) RESTRICT_API_CNAME_RECORD(bio.terra.buffer.service.resource.flight.CreateResourceRecordSetStep.RESTRICT_API_CNAME_RECORD) LEONARDO_SSL_FOR_DEFAULT_NETWORK_RULE_NAME(bio.terra.buffer.service.resource.flight.CreateFirewallRuleStep.LEONARDO_SSL_FOR_DEFAULT_NETWORK_RULE_NAME) ROUTE_NAME(bio.terra.buffer.service.resource.flight.CreateRouteStep.ROUTE_NAME) RetryRule(bio.terra.stairway.RetryRule) Autowired(org.springframework.beans.factory.annotation.Autowired) Network(com.google.api.services.compute.model.Network) Route(com.google.api.services.compute.model.Route) LEONARDO_SSL_FOR_VPC_NETWORK_RULE_NAME(bio.terra.buffer.service.resource.flight.CreateFirewallRuleStep.LEONARDO_SSL_FOR_VPC_NETWORK_RULE_NAME) Disabled(org.junit.jupiter.api.Disabled) ResourceId(bio.terra.buffer.common.ResourceId) BigDecimal(java.math.BigDecimal) CreateSubnetsStep.getSubnetLogConfig(bio.terra.buffer.service.resource.flight.CreateSubnetsStep.getSubnetLogConfig) DENY_EGRESS_LEONARDO_WORKER_RULE_NAME(bio.terra.buffer.service.resource.flight.CreateFirewallRuleStep.DENY_EGRESS_LEONARDO_WORKER_RULE_NAME) Map(java.util.Map) GoogleUtils.resourceExists(bio.terra.buffer.service.resource.flight.GoogleUtils.resourceExists) IntegrationUtils.blockUntilFlightComplete(bio.terra.buffer.integration.IntegrationUtils.blockUntilFlightComplete) TEST_CONFIG_NAME(bio.terra.buffer.integration.IntegrationUtils.TEST_CONFIG_NAME) ServiceAccountName(bio.terra.cloudres.google.iam.ServiceAccountName) StorageCow(bio.terra.cloudres.google.storage.StorageCow) ResourceRecordSet(com.google.api.services.dns.model.ResourceRecordSet) ALLOW_INTERNAL_VPC_NETWORK(bio.terra.buffer.service.resource.flight.CreateFirewallRuleStep.ALLOW_INTERNAL_VPC_NETWORK) GCR_CNAME_RECORD(bio.terra.buffer.service.resource.flight.CreateResourceRecordSetStep.GCR_CNAME_RECORD) BucketInfo(com.google.cloud.storage.BucketInfo) StubSubmissionFlightFactory(bio.terra.buffer.integration.IntegrationUtils.StubSubmissionFlightFactory) ALLOW_EGRESS_INTERNAL(bio.terra.buffer.service.resource.flight.CreateFirewallRuleStep.ALLOW_EGRESS_INTERNAL) SUB_NETWORK_LABEL_KEY(bio.terra.buffer.service.resource.flight.CreateProjectStep.SUB_NETWORK_LABEL_KEY) NETWORK_NAME(bio.terra.buffer.service.resource.flight.GoogleUtils.NETWORK_NAME) Pool(bio.terra.buffer.common.Pool) GKE_SA_NAME(bio.terra.buffer.service.resource.flight.CreateGkeDefaultSAStep.GKE_SA_NAME) Flight(bio.terra.stairway.Flight) CreateProjectStep.createValidLabelValue(bio.terra.buffer.service.resource.flight.CreateProjectStep.createValidLabelValue) Service(com.google.api.services.serviceusage.v1beta1.model.Service) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) StepStatus(bio.terra.stairway.StepStatus) ALLOW_EGRESS_INTERNAL_RULE_NAME(bio.terra.buffer.service.resource.flight.CreateFirewallRuleStep.ALLOW_EGRESS_INTERNAL_RULE_NAME) FlightContext(bio.terra.stairway.FlightContext) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) FlightSubmissionFactoryImpl(bio.terra.buffer.service.resource.FlightSubmissionFactoryImpl) ServiceAccount(com.google.api.services.iam.v1.model.ServiceAccount) Policy(com.google.cloud.Policy) ListConsumerOverridesResponse(com.google.api.services.serviceusage.v1beta1.model.ListConsumerOverridesResponse) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) IntegrationUtils.newBasicGcpConfig(bio.terra.buffer.integration.IntegrationUtils.newBasicGcpConfig) Project(com.google.api.services.cloudresourcemanager.v3.model.Project) ArrayList(java.util.ArrayList) REGION_TO_IP_RANGE(bio.terra.buffer.service.resource.flight.CreateSubnetsStep.REGION_TO_IP_RANGE) GoogleUtils.projectIdToName(bio.terra.buffer.service.resource.flight.GoogleUtils.projectIdToName) GenerateProjectIdStep(bio.terra.buffer.service.resource.flight.GenerateProjectIdStep) Firewall(com.google.api.services.compute.model.Firewall) GCR_MANAGED_ZONE_NAME(bio.terra.buffer.service.resource.flight.GoogleUtils.GCR_MANAGED_ZONE_NAME) IntegrationUtils.preparePool(bio.terra.buffer.integration.IntegrationUtils.preparePool) GKE_SA_ROLES(bio.terra.buffer.service.resource.flight.CreateGkeDefaultSAStep.GKE_SA_ROLES) LEONARDO_ALLOW_HTTPS_FIREWALL_RULE_NAME_LABEL_KEY(bio.terra.buffer.service.resource.flight.CreateProjectStep.LEONARDO_ALLOW_HTTPS_FIREWALL_RULE_NAME_LABEL_KEY) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) GoogleApiServiceusageV1Service(com.google.api.services.serviceusage.v1beta1.model.GoogleApiServiceusageV1Service) Resource(bio.terra.buffer.common.Resource) ALLOW_INGRESS_LEONARDO_SSL_DEFAULT(bio.terra.buffer.service.resource.flight.CreateFirewallRuleStep.ALLOW_INGRESS_LEONARDO_SSL_DEFAULT) Subnetwork(com.google.api.services.compute.model.Subnetwork) FlightMap(bio.terra.stairway.FlightMap) GoogleProjectCreationFlight(bio.terra.buffer.service.resource.flight.GoogleProjectCreationFlight) CloudResourceManagerCow(bio.terra.cloudres.google.cloudresourcemanager.CloudResourceManagerCow) IOException(java.io.IOException) GcpProjectIdGenerator(bio.terra.buffer.service.resource.projectid.GcpProjectIdGenerator) ALLOW_INTERNAL_DEFAULT_NETWORK(bio.terra.buffer.service.resource.flight.CreateFirewallRuleStep.ALLOW_INTERNAL_DEFAULT_NETWORK) FinishResourceCreationStep(bio.terra.buffer.service.resource.flight.FinishResourceCreationStep) CloudBillingClientCow(bio.terra.cloudres.google.billing.CloudBillingClientCow) DEFAULT_FIREWALL_NAMES(bio.terra.buffer.service.resource.flight.DeleteDefaultFirewallRulesStep.DEFAULT_FIREWALL_NAMES) SUBNETWORK_NAME(bio.terra.buffer.service.resource.flight.GoogleUtils.SUBNETWORK_NAME) DnsCow(bio.terra.cloudres.google.dns.DnsCow) DirtiesContext(org.springframework.test.annotation.DirtiesContext) RESTRICTED_GOOGLE_IP_ADDRESS(bio.terra.buffer.service.resource.flight.GoogleUtils.RESTRICTED_GOOGLE_IP_ADDRESS) MANAGED_ZONE_TEMPLATE(bio.terra.buffer.service.resource.flight.CreateDnsZoneStep.MANAGED_ZONE_TEMPLATE) ALLOW_EGRESS_LEONARDO(bio.terra.buffer.service.resource.flight.CreateFirewallRuleStep.ALLOW_EGRESS_LEONARDO) StorageOptions(com.google.cloud.storage.StorageOptions) IntegrationUtils.newFullGcpConfig(bio.terra.buffer.integration.IntegrationUtils.newFullGcpConfig) NETWORK_LABEL_KEY(bio.terra.buffer.service.resource.flight.CreateProjectStep.NETWORK_LABEL_KEY) DEFAULT_NETWORK_NAME(bio.terra.buffer.service.resource.flight.GoogleUtils.DEFAULT_NETWORK_NAME) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ResourceState(bio.terra.buffer.common.ResourceState) GetIamPolicyRequest(com.google.api.services.cloudresourcemanager.v3.model.GetIamPolicyRequest) ErrorStep(bio.terra.buffer.service.resource.flight.ErrorStep) RESTRICT_API_A_RECORD(bio.terra.buffer.service.resource.flight.CreateResourceRecordSetStep.RESTRICT_API_A_RECORD) IamCow(bio.terra.cloudres.google.iam.IamCow) IntegrationUtils.extractResourceIdFromFlightState(bio.terra.buffer.integration.IntegrationUtils.extractResourceIdFromFlightState) Binding(com.google.api.services.cloudresourcemanager.v3.model.Binding) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) GCR_MANAGED_ZONE_TEMPLATE(bio.terra.buffer.service.resource.flight.CreateDnsZoneStep.GCR_MANAGED_ZONE_TEMPLATE) List(java.util.List) STORAGE_LOGS_IDENTITY(bio.terra.buffer.service.resource.flight.CreateStorageLogBucketStep.STORAGE_LOGS_IDENTITY) SubnetworkList(com.google.api.services.compute.model.SubnetworkList) GCR_A_RECORD(bio.terra.buffer.service.resource.flight.CreateResourceRecordSetStep.GCR_A_RECORD) CloudComputeCow(bio.terra.cloudres.google.compute.CloudComputeCow) ManagedZone(com.google.api.services.dns.model.ManagedZone) DENY_EGRESS(bio.terra.buffer.service.resource.flight.CreateFirewallRuleStep.DENY_EGRESS) DENY_EGRESS_LEONARDO_WORKER(bio.terra.buffer.service.resource.flight.CreateFirewallRuleStep.DENY_EGRESS_LEONARDO_WORKER) CreateProjectStep(bio.terra.buffer.service.resource.flight.CreateProjectStep) ALLOW_INGRESS_LEONARDO_SSL_NETWORK(bio.terra.buffer.service.resource.flight.CreateFirewallRuleStep.ALLOW_INGRESS_LEONARDO_SSL_NETWORK) ALLOW_INTERNAL_FOR_DEFAULT_NETWORK_RULE_NAME(bio.terra.buffer.service.resource.flight.CreateFirewallRuleStep.ALLOW_INTERNAL_FOR_DEFAULT_NETWORK_RULE_NAME) StairwayComponent(bio.terra.common.stairway.StairwayComponent) BufferDao(bio.terra.buffer.db.BufferDao) BaseIntegrationTest(bio.terra.buffer.common.BaseIntegrationTest) DENY_EGRESS_RULE_NAME(bio.terra.buffer.service.resource.flight.CreateFirewallRuleStep.DENY_EGRESS_RULE_NAME) StepResult(bio.terra.stairway.StepResult) QuotaOverride(com.google.api.services.serviceusage.v1beta1.model.QuotaOverride) Step(bio.terra.stairway.Step) ImmutableList(com.google.common.collect.ImmutableList) CONFIG_NAME_LABEL_KEY(bio.terra.buffer.service.resource.flight.CreateProjectStep.CONFIG_NAME_LABEL_KEY) FlightManager(bio.terra.buffer.service.resource.FlightManager) ServiceUsageCow(bio.terra.cloudres.google.serviceusage.ServiceUsageCow) DEFAULT_GATEWAY(bio.terra.buffer.service.resource.flight.CreateRouteStep.DEFAULT_GATEWAY) IntegrationUtils.pollUntilResourcesMatch(bio.terra.buffer.integration.IntegrationUtils.pollUntilResourcesMatch) UndoCreatingDbEntityStep(bio.terra.buffer.service.resource.flight.UndoCreatingDbEntityStep) ClientConfig(bio.terra.cloudres.common.ClientConfig) StorageRoles(com.google.cloud.storage.StorageRoles) Matchers(org.hamcrest.Matchers) ALLOW_EGRESS_PRIVATE_ACCESS_RULE_NAME(bio.terra.buffer.service.resource.flight.CreateFirewallRuleStep.ALLOW_EGRESS_PRIVATE_ACCESS_RULE_NAME) ApplicationContext(org.springframework.context.ApplicationContext) MANAGED_ZONE_NAME(bio.terra.buffer.service.resource.flight.GoogleUtils.MANAGED_ZONE_NAME) LatchStep(bio.terra.buffer.service.resource.flight.LatchStep) IAM_BINDINGS(bio.terra.buffer.integration.IntegrationUtils.IAM_BINDINGS) AssertResourceCreatingStep(bio.terra.buffer.service.resource.flight.AssertResourceCreatingStep) AutoConfigureMockMvc(org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc) ALLOW_EGRESS_LEONARDO_RULE_NAME(bio.terra.buffer.service.resource.flight.CreateFirewallRuleStep.ALLOW_EGRESS_LEONARDO_RULE_NAME) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) FlightStatus(bio.terra.stairway.FlightStatus) bio.terra.buffer.generated.model(bio.terra.buffer.generated.model) ALLOW_INTERNAL_FOR_VPC_NETWORK_RULE_NAME(bio.terra.buffer.service.resource.flight.CreateFirewallRuleStep.ALLOW_INTERNAL_FOR_VPC_NETWORK_RULE_NAME) RESOURCE_CONFIG(bio.terra.buffer.service.resource.FlightMapKeys.RESOURCE_CONFIG) ALLOW_EGRESS_PRIVATE_ACCESS(bio.terra.buffer.service.resource.flight.CreateFirewallRuleStep.ALLOW_EGRESS_PRIVATE_ACCESS) ManagedZone(com.google.api.services.dns.model.ManagedZone)

Example 44 with Project

use of com.blackducksoftware.bdio2.model.Project in project terra-resource-buffer by DataBiosphere.

the class CreateProjectFlightIntegrationTest method testCreateGoogleProject_enablePrivateGoogleAccessAndFlowLog.

@Test
public void testCreateGoogleProject_enablePrivateGoogleAccessAndFlowLog() throws Exception {
    FlightManager manager = new FlightManager(bufferDao, flightSubmissionFactoryImpl, stairwayComponent, transactionTemplate);
    Pool pool = preparePool(bufferDao, newBasicGcpConfig().network(new bio.terra.buffer.generated.model.Network().enableNetworkMonitoring(true).enablePrivateGoogleAccess(true)));
    String flightId = manager.submitCreationFlight(pool).get();
    ResourceId resourceId = extractResourceIdFromFlightState(blockUntilFlightComplete(stairwayComponent, flightId));
    Project project = assertProjectExists(resourceId);
    assertNetworkExists(project);
    assertSubnetsExist(project, NetworkMonitoring.ENABLED);
    assertRouteExists(project);
    assertDnsExists(project);
    assertDefaultVpcNotExists(project);
}
Also used : Project(com.google.api.services.cloudresourcemanager.v3.model.Project) ResourceId(bio.terra.buffer.common.ResourceId) Network(com.google.api.services.compute.model.Network) Pool(bio.terra.buffer.common.Pool) IntegrationUtils.preparePool(bio.terra.buffer.integration.IntegrationUtils.preparePool) FlightManager(bio.terra.buffer.service.resource.FlightManager) Test(org.junit.jupiter.api.Test) BaseIntegrationTest(bio.terra.buffer.common.BaseIntegrationTest)

Example 45 with Project

use of com.blackducksoftware.bdio2.model.Project in project terra-resource-buffer by DataBiosphere.

the class CreateProjectFlightIntegrationTest method assertProjectExists.

private Project assertProjectExists(ResourceId resourceId) throws Exception {
    Resource resource = bufferDao.retrieveResource(resourceId).get();
    Project project = rmCow.projects().get(resource.cloudResourceUid().getGoogleProjectUid().getProjectId()).execute();
    assertEquals("ACTIVE", project.getState());
    assertThat(project.getLabels().entrySet(), Matchers.hasItems(Map.entry(NETWORK_LABEL_KEY, NETWORK_NAME), Map.entry(SUB_NETWORK_LABEL_KEY, SUBNETWORK_NAME), Map.entry(LEONARDO_ALLOW_HTTPS_FIREWALL_RULE_NAME_LABEL_KEY, LEONARDO_SSL_FOR_VPC_NETWORK_RULE_NAME), Map.entry(LEONARDO_ALLOW_INTERNAL_RULE_NAME_LABEL_KEY, ALLOW_INTERNAL_FOR_VPC_NETWORK_RULE_NAME), Map.entry(CONFIG_NAME_LABEL_KEY, TEST_CONFIG_NAME)));
    return project;
}
Also used : Project(com.google.api.services.cloudresourcemanager.v3.model.Project) Resource(bio.terra.buffer.common.Resource)

Aggregations

Project (com.google.api.services.cloudresourcemanager.v3.model.Project)38 Test (org.junit.jupiter.api.Test)32 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 StepStatus (bio.terra.stairway.StepStatus)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 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 Project (com.blackducksoftware.bdio2.model.Project)6 UUID (java.util.UUID)6 Resource (bio.terra.buffer.common.Resource)5 bio.terra.buffer.generated.model (bio.terra.buffer.generated.model)5