use of com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response in project cloudbreak by hortonworks.
the class DatabaseCriteriaResolverTest method setUp.
@BeforeEach
void setUp() {
database = new DatabaseServerV4Response();
cluster = new Cluster();
}
use of com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response in project cloudbreak by hortonworks.
the class ExternalDatabaseServiceTest method provisionDatabase.
@ParameterizedTest
@EnumSource(DatabaseAvailabilityType.class)
void provisionDatabase(DatabaseAvailabilityType availabilty) throws JsonProcessingException {
Assumptions.assumeTrue(!availabilty.isEmbedded());
DatabaseServerStatusV4Response createResponse = new DatabaseServerStatusV4Response();
createResponse.setResourceCrn(RDBMS_CRN);
Cluster cluster = spy(new Cluster());
Stack stack = new Stack();
stack.setResourceCrn(CLUSTER_CRN);
cluster.setStack(stack);
when(redbeamsClient.getByClusterCrn(nullable(String.class), nullable(String.class))).thenReturn(null);
when(redbeamsClient.create(any())).thenReturn(createResponse);
when(databaseObtainerService.obtainAttemptResult(eq(cluster), eq(DatabaseOperation.CREATION), eq(RDBMS_CRN), eq(true))).thenReturn(AttemptResults.finishWith(new DatabaseServerV4Response()));
underTest.provisionDatabase(cluster, availabilty, environmentResponse);
ArgumentCaptor<DatabaseServerParameter> serverParameterCaptor = ArgumentCaptor.forClass(DatabaseServerParameter.class);
verify(redbeamsClient).getByClusterCrn(ENV_CRN, CLUSTER_CRN);
verify(redbeamsClient).create(any(AllocateDatabaseServerV4Request.class));
verify(cluster).setDatabaseServerCrn(RDBMS_CRN);
verify(dbServerParameterDecorator).setParameters(any(), serverParameterCaptor.capture());
verify(clusterRepository).save(cluster);
DatabaseServerParameter paramValue = serverParameterCaptor.getValue();
assertThat(paramValue.isHighlyAvailable()).isEqualTo(availabilty == DatabaseAvailabilityType.HA);
}
use of com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response in project cloudbreak by hortonworks.
the class ExternalDatabaseServiceTest method stopDatabase.
@Test
void stopDatabase() throws JsonProcessingException {
Cluster cluster = spy(new Cluster());
cluster.setDatabaseServerCrn(RDBMS_CRN);
DatabaseServerV4Response deleteResponse = new DatabaseServerV4Response();
deleteResponse.setCrn(RDBMS_CRN);
when(databaseObtainerService.obtainAttemptResult(eq(cluster), eq(DatabaseOperation.STOP), eq(RDBMS_CRN), eq(false))).thenReturn(AttemptResults.finishWith(new DatabaseServerV4Response()));
underTest.stopDatabase(cluster, DatabaseAvailabilityType.HA, environmentResponse);
verify(redbeamsClient).stopByCrn(RDBMS_CRN);
}
use of com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response in project cloudbreak by hortonworks.
the class ExternalDatabaseServiceTest method provisionDatabaseWhenAlreadyExists.
@Test
void provisionDatabaseWhenAlreadyExists() throws JsonProcessingException {
Cluster cluster = spy(new Cluster());
Stack stack = new Stack();
stack.setResourceCrn(CLUSTER_CRN);
cluster.setStack(stack);
DatabaseServerV4Response dbServerResponse = new DatabaseServerV4Response();
dbServerResponse.setCrn(RDBMS_CRN);
when(redbeamsClient.getByClusterCrn(nullable(String.class), nullable(String.class))).thenReturn(dbServerResponse);
when(databaseObtainerService.obtainAttemptResult(eq(cluster), eq(DatabaseOperation.CREATION), eq(RDBMS_CRN), eq(true))).thenReturn(AttemptResults.finishWith(new DatabaseServerV4Response()));
underTest.provisionDatabase(cluster, DatabaseAvailabilityType.NON_HA, environmentResponse);
verify(redbeamsClient).getByClusterCrn(ENV_CRN, CLUSTER_CRN);
verify(redbeamsClient, never()).create(any(AllocateDatabaseServerV4Request.class));
verify(dbServerParameterDecorator, never()).setParameters(any(), any());
verify(cluster).setDatabaseServerCrn(RDBMS_CRN);
verify(clusterRepository).save(cluster);
}
use of com.sequenceiq.redbeams.api.endpoint.v4.databaseserver.responses.DatabaseServerV4Response in project cloudbreak by hortonworks.
the class DatabaseService method getDatabaseStatus.
private DatabaseServerStatusV4Response getDatabaseStatus(String databaseCrn) {
DatabaseServerV4Response response = ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> databaseServerV4Endpoint.getByCrn(databaseCrn));
DatabaseServerStatusV4Response statusResponse = new DatabaseServerStatusV4Response();
statusResponse.setEnvironmentCrn(response.getEnvironmentCrn());
statusResponse.setName(response.getName());
statusResponse.setResourceCrn(response.getCrn());
statusResponse.setStatus(response.getStatus());
statusResponse.setStatusReason(response.getStatusReason());
return statusResponse;
}
Aggregations