Search in sources :

Example 21 with DatabaseStack

use of com.sequenceiq.cloudbreak.cloud.model.DatabaseStack in project cloudbreak by hortonworks.

the class GcpDatabaseServerTerminateServiceTest method testTerminateWhenDatabaseIsPresentedShouldDeleteDatabase.

@Test
public void testTerminateWhenDatabaseIsPresentedShouldDeleteDatabase() throws Exception {
    AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
    CloudCredential cloudCredential = mock(CloudCredential.class);
    DatabaseStack databaseStack = mock(DatabaseStack.class);
    DatabaseServer databaseServer = mock(DatabaseServer.class);
    PersistenceNotifier persistenceNotifier = mock(PersistenceNotifier.class);
    SQLAdmin sqlAdmin = mock(SQLAdmin.class);
    SQLAdmin.Instances sqlAdminInstances = mock(SQLAdmin.Instances.class);
    SQLAdmin.Instances.List sqlAdminInstancesList = mock(SQLAdmin.Instances.List.class);
    InstancesListResponse instancesListResponse = mock(InstancesListResponse.class);
    when(authenticatedContext.getCloudCredential()).thenReturn(cloudCredential);
    when(cloudCredential.getName()).thenReturn("credential");
    when(databaseStack.getDatabaseServer()).thenReturn(databaseServer);
    when(databaseServer.getServerId()).thenReturn("server-1");
    when(gcpSQLAdminFactory.buildSQLAdmin(any(CloudCredential.class), anyString())).thenReturn(sqlAdmin);
    when(gcpStackUtil.getProjectId(any(CloudCredential.class))).thenReturn("project-id");
    when(sqlAdmin.instances()).thenReturn(sqlAdminInstances);
    when(sqlAdminInstances.list(anyString())).thenReturn(sqlAdminInstancesList);
    when(sqlAdminInstancesList.execute()).thenReturn(instancesListResponse);
    DatabaseInstance databaseInstance = new DatabaseInstance();
    databaseInstance.setName("server-1");
    databaseInstance.setState("RUNNABLE");
    Settings settings = new Settings();
    settings.setActivationPolicy("ALWAYS");
    databaseInstance.setSettings(settings);
    when(instancesListResponse.getItems()).thenReturn(List.of(databaseInstance));
    SQLAdmin.Instances.Delete delete = mock(SQLAdmin.Instances.Delete.class);
    Operation operation = mock(Operation.class);
    when(sqlAdminInstances.delete(anyString(), anyString())).thenReturn(delete);
    when(delete.execute()).thenReturn(operation);
    when(delete.setPrettyPrint(anyBoolean())).thenReturn(delete);
    when(operation.getError()).thenReturn(null);
    when(authenticatedContext.getCloudContext()).thenReturn(cloudContext);
    when(cloudContext.getLocation()).thenReturn(location(region("region"), availabilityZone("az1")));
    doNothing().when(databasePollerService).terminateDatabasePoller(any(AuthenticatedContext.class), anyList());
    List<CloudResource> terminate = underTest.terminate(authenticatedContext, databaseStack, persistenceNotifier);
    Assert.assertEquals(1, terminate.size());
    Assert.assertEquals("server-1", terminate.get(0).getName());
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) DatabaseStack(com.sequenceiq.cloudbreak.cloud.model.DatabaseStack) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Operation(com.google.api.services.sqladmin.model.Operation) SQLAdmin(com.google.api.services.sqladmin.SQLAdmin) DatabaseInstance(com.google.api.services.sqladmin.model.DatabaseInstance) InstancesListResponse(com.google.api.services.sqladmin.model.InstancesListResponse) PersistenceNotifier(com.sequenceiq.cloudbreak.cloud.notification.PersistenceNotifier) DatabaseServer(com.sequenceiq.cloudbreak.cloud.model.DatabaseServer) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Settings(com.google.api.services.sqladmin.model.Settings) Test(org.junit.jupiter.api.Test)

Example 22 with DatabaseStack

use of com.sequenceiq.cloudbreak.cloud.model.DatabaseStack in project cloudbreak by hortonworks.

the class AwsRdsLaunchServiceTest method createDatabaseStack.

private DatabaseStack createDatabaseStack(boolean useSslEnforcement, boolean sslCertificateIdentifierDefined) {
    Subnet subnet = new Subnet(SUBNET_CIDR);
    Network network = new Network(subnet, List.of(NETWORK_CIDR), OutboundInternetTraffic.ENABLED);
    network.putParameter("subnetId", SUBNET_ID);
    network.putParameter("vpcCidr", NETWORK_CIDR);
    Security security = new Security(Collections.emptyList(), List.of(SECURITY_GROUP_ID));
    DatabaseServer databaseServer = DatabaseServer.builder().useSslEnforcement(useSslEnforcement).params(sslCertificateIdentifierDefined ? Map.of(DatabaseServer.SSL_CERTIFICATE_IDENTIFIER, SSL_CERTIFICATE_IDENTIFIER) : Map.of()).security(security).build();
    return new DatabaseStack(network, databaseServer, Collections.emptyMap(), null);
}
Also used : Network(com.sequenceiq.cloudbreak.cloud.model.Network) DatabaseStack(com.sequenceiq.cloudbreak.cloud.model.DatabaseStack) DatabaseServer(com.sequenceiq.cloudbreak.cloud.model.DatabaseServer) Subnet(com.sequenceiq.cloudbreak.cloud.model.Subnet) Security(com.sequenceiq.cloudbreak.cloud.model.Security)

Example 23 with DatabaseStack

use of com.sequenceiq.cloudbreak.cloud.model.DatabaseStack in project cloudbreak by hortonworks.

the class AzureDatabaseResourceServiceTest method shouldReturnDeletedResourceGroupWhenTerminateDatabaseServerAndMultipleResourceGroups.

@Test
void shouldReturnDeletedResourceGroupWhenTerminateDatabaseServerAndMultipleResourceGroups() {
    PersistenceNotifier persistenceNotifier = mock(PersistenceNotifier.class);
    DatabaseStack databaseStack = mock(DatabaseStack.class);
    when(azureResourceGroupMetadataProvider.getResourceGroupUsage(any(DatabaseStack.class))).thenReturn(ResourceGroupUsage.MULTIPLE);
    when(azureResourceGroupMetadataProvider.getResourceGroupName(cloudContext, databaseStack)).thenReturn(RESOURCE_GROUP_NAME);
    when(azureUtils.deleteResourceGroup(any(), anyString(), anyBoolean())).thenReturn(Optional.empty());
    List<CloudResource> cloudResources = List.of(CloudResource.builder().type(AZURE_DATABASE).reference("dbReference").name("dbName").status(CommonStatus.CREATED).params(Map.of()).build());
    List<CloudResourceStatus> resourceStatuses = victim.terminateDatabaseServer(ac, databaseStack, cloudResources, false, persistenceNotifier);
    assertEquals(1, resourceStatuses.size());
    assertEquals(AZURE_RESOURCE_GROUP, resourceStatuses.get(0).getCloudResource().getType());
    assertEquals(DELETED, resourceStatuses.get(0).getStatus());
    verify(azureUtils).deleteResourceGroup(any(), eq(RESOURCE_GROUP_NAME), eq(false));
    verify(azureUtils, never()).deleteDatabaseServer(any(), anyString(), anyBoolean());
    verify(persistenceNotifier).notifyDeletion(any(), any());
}
Also used : CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) PersistenceNotifier(com.sequenceiq.cloudbreak.cloud.notification.PersistenceNotifier) DatabaseStack(com.sequenceiq.cloudbreak.cloud.model.DatabaseStack) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Test(org.junit.jupiter.api.Test)

Example 24 with DatabaseStack

use of com.sequenceiq.cloudbreak.cloud.model.DatabaseStack in project cloudbreak by hortonworks.

the class GcpDatabaseServerCheckServiceTest method testCheckWhenDbInstanceIsRunnableAlwaysShouldReturnStarted.

@Test
public void testCheckWhenDbInstanceIsRunnableAlwaysShouldReturnStarted() throws IOException {
    AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
    CloudCredential cloudCredential = mock(CloudCredential.class);
    DatabaseStack databaseStack = mock(DatabaseStack.class);
    DatabaseServer databaseServer = mock(DatabaseServer.class);
    SQLAdmin sqlAdmin = mock(SQLAdmin.class);
    SQLAdmin.Instances sqlAdminInstances = mock(SQLAdmin.Instances.class);
    SQLAdmin.Instances.List sqlAdminInstancesList = mock(SQLAdmin.Instances.List.class);
    InstancesListResponse instancesListResponse = mock(InstancesListResponse.class);
    when(authenticatedContext.getCloudCredential()).thenReturn(cloudCredential);
    when(cloudCredential.getName()).thenReturn("credential");
    when(databaseStack.getDatabaseServer()).thenReturn(databaseServer);
    when(databaseServer.getServerId()).thenReturn("test");
    when(gcpSQLAdminFactory.buildSQLAdmin(any(CloudCredential.class), anyString())).thenReturn(sqlAdmin);
    when(gcpStackUtil.getProjectId(any(CloudCredential.class))).thenReturn("project-id");
    when(sqlAdmin.instances()).thenReturn(sqlAdminInstances);
    when(sqlAdminInstances.list(anyString())).thenReturn(sqlAdminInstancesList);
    when(sqlAdminInstancesList.execute()).thenReturn(instancesListResponse);
    when(instancesListResponse.isEmpty()).thenReturn(false);
    DatabaseInstance databaseInstance = new DatabaseInstance();
    databaseInstance.setName("test");
    databaseInstance.setState("RUNNABLE");
    Settings settings = new Settings();
    settings.setActivationPolicy("ALWAYS");
    databaseInstance.setSettings(settings);
    when(instancesListResponse.getItems()).thenReturn(List.of(databaseInstance));
    ExternalDatabaseStatus check = underTest.check(authenticatedContext, databaseStack);
    Assert.assertEquals(ExternalDatabaseStatus.STARTED, check);
}
Also used : InstancesListResponse(com.google.api.services.sqladmin.model.InstancesListResponse) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) DatabaseStack(com.sequenceiq.cloudbreak.cloud.model.DatabaseStack) DatabaseServer(com.sequenceiq.cloudbreak.cloud.model.DatabaseServer) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) SQLAdmin(com.google.api.services.sqladmin.SQLAdmin) DatabaseInstance(com.google.api.services.sqladmin.model.DatabaseInstance) Settings(com.google.api.services.sqladmin.model.Settings) ExternalDatabaseStatus(com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus) Test(org.junit.jupiter.api.Test)

Example 25 with DatabaseStack

use of com.sequenceiq.cloudbreak.cloud.model.DatabaseStack in project cloudbreak by hortonworks.

the class GcpDatabaseServerCheckServiceTest method testCheckWhenDbInstanceIsTESTShouldReturnDeleted.

@Test
public void testCheckWhenDbInstanceIsTESTShouldReturnDeleted() throws IOException {
    AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
    CloudCredential cloudCredential = mock(CloudCredential.class);
    DatabaseStack databaseStack = mock(DatabaseStack.class);
    DatabaseServer databaseServer = mock(DatabaseServer.class);
    SQLAdmin sqlAdmin = mock(SQLAdmin.class);
    SQLAdmin.Instances sqlAdminInstances = mock(SQLAdmin.Instances.class);
    SQLAdmin.Instances.List sqlAdminInstancesList = mock(SQLAdmin.Instances.List.class);
    InstancesListResponse instancesListResponse = mock(InstancesListResponse.class);
    when(authenticatedContext.getCloudCredential()).thenReturn(cloudCredential);
    when(cloudCredential.getName()).thenReturn("credential");
    when(databaseStack.getDatabaseServer()).thenReturn(databaseServer);
    when(databaseServer.getServerId()).thenReturn("test");
    when(gcpSQLAdminFactory.buildSQLAdmin(any(CloudCredential.class), anyString())).thenReturn(sqlAdmin);
    when(gcpStackUtil.getProjectId(any(CloudCredential.class))).thenReturn("project-id");
    when(sqlAdmin.instances()).thenReturn(sqlAdminInstances);
    when(sqlAdminInstances.list(anyString())).thenReturn(sqlAdminInstancesList);
    when(sqlAdminInstancesList.execute()).thenReturn(instancesListResponse);
    when(instancesListResponse.isEmpty()).thenReturn(false);
    DatabaseInstance databaseInstance = new DatabaseInstance();
    databaseInstance.setName("test");
    databaseInstance.setState("TEST");
    when(instancesListResponse.getItems()).thenReturn(List.of(databaseInstance));
    ExternalDatabaseStatus check = underTest.check(authenticatedContext, databaseStack);
    Assert.assertEquals(ExternalDatabaseStatus.UPDATE_IN_PROGRESS, check);
}
Also used : InstancesListResponse(com.google.api.services.sqladmin.model.InstancesListResponse) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) DatabaseStack(com.sequenceiq.cloudbreak.cloud.model.DatabaseStack) DatabaseServer(com.sequenceiq.cloudbreak.cloud.model.DatabaseServer) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) SQLAdmin(com.google.api.services.sqladmin.SQLAdmin) DatabaseInstance(com.google.api.services.sqladmin.model.DatabaseInstance) ExternalDatabaseStatus(com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus) Test(org.junit.jupiter.api.Test)

Aggregations

DatabaseStack (com.sequenceiq.cloudbreak.cloud.model.DatabaseStack)48 Test (org.junit.jupiter.api.Test)34 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)24 DatabaseServer (com.sequenceiq.cloudbreak.cloud.model.DatabaseServer)24 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)22 SQLAdmin (com.google.api.services.sqladmin.SQLAdmin)16 InstancesListResponse (com.google.api.services.sqladmin.model.InstancesListResponse)13 DatabaseInstance (com.google.api.services.sqladmin.model.DatabaseInstance)12 PersistenceNotifier (com.sequenceiq.cloudbreak.cloud.notification.PersistenceNotifier)12 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)11 DatabaseServer (com.sequenceiq.redbeams.domain.stack.DatabaseServer)11 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)11 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)10 Network (com.sequenceiq.cloudbreak.cloud.model.Network)9 ExternalDatabaseStatus (com.sequenceiq.cloudbreak.cloud.model.ExternalDatabaseStatus)8 Location (com.sequenceiq.cloudbreak.cloud.model.Location)8 Subnet (com.sequenceiq.cloudbreak.cloud.model.Subnet)8 Json (com.sequenceiq.cloudbreak.common.json.Json)8 DBStack (com.sequenceiq.redbeams.domain.stack.DBStack)7 Network (com.sequenceiq.redbeams.domain.stack.Network)7