Search in sources :

Example 1 with DBStackStatus

use of com.sequenceiq.redbeams.domain.stack.DBStackStatus in project cloudbreak by hortonworks.

the class DBStackStatusUpdaterTest method testUpdateStatusSkippedWhenDeleteCompleted.

@Test
public void testUpdateStatusSkippedWhenDeleteCompleted() {
    dbStack.setDBStackStatus(new DBStackStatus(dbStack, DetailedDBStackStatus.DELETE_COMPLETED, now));
    underTest.updateStatus(1L, DetailedDBStackStatus.PROVISIONED, "because").get();
    verify(dbStackService, never()).save(dbStack);
    verify(redbeamsInMemoryStateStoreUpdaterService, never()).update(anyLong(), any());
}
Also used : DetailedDBStackStatus(com.sequenceiq.redbeams.api.model.common.DetailedDBStackStatus) DBStackStatus(com.sequenceiq.redbeams.domain.stack.DBStackStatus) Test(org.junit.Test)

Example 2 with DBStackStatus

use of com.sequenceiq.redbeams.domain.stack.DBStackStatus in project cloudbreak by hortonworks.

the class AllocateDatabaseServerV4RequestToDBStackConverter method convert.

public DBStack convert(AllocateDatabaseServerV4Request source, String ownerCrnString) {
    Crn ownerCrn = Crn.safeFromString(ownerCrnString);
    CrnUser user = crnUserDetailsService.loadUserByUsername(ownerCrnString);
    DetailedEnvironmentResponse environment = environmentService.getByCrn(source.getEnvironmentCrn());
    DBStack dbStack = new DBStack();
    dbStack.setOwnerCrn(ownerCrn);
    dbStack.setUserName(user.getEmail());
    CloudPlatform cloudPlatform = updateCloudPlatformAndRelatedFields(source, dbStack, environment.getCloudPlatform());
    dbStack.setName(source.getName() != null ? source.getName() : generateDatabaseServerStackName(environment.getName()));
    dbStack.setEnvironmentId(source.getEnvironmentCrn());
    setRegion(dbStack, environment);
    if (source.getDatabaseServer() != null) {
        dbStack.setDatabaseServer(buildDatabaseServer(source.getDatabaseServer(), cloudPlatform, ownerCrn, environment.getSecurityAccess()));
    }
    Map<String, Object> asMap = providerParameterCalculator.get(source).asMap();
    if (asMap != null) {
        Map<String, String> parameter = new HashMap<>();
        asMap.forEach((key, value) -> parameter.put(key, value.toString()));
        dbStack.setParameters(parameter);
    }
    dbStack.setNetwork(buildNetwork(source.getNetwork(), environment, cloudPlatform, dbStack));
    Instant now = clock.getCurrentInstant();
    dbStack.setDBStackStatus(new DBStackStatus(dbStack, DetailedDBStackStatus.PROVISION_REQUESTED, now.toEpochMilli()));
    dbStack.setResourceCrn(crnService.createCrn(dbStack).toString());
    dbStack.setTags(getTags(dbStack, source, environment));
    dbStack.setSslConfig(getSslConfig(source, dbStack));
    return dbStack;
}
Also used : CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) HashMap(java.util.HashMap) Instant(java.time.Instant) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) CrnUser(com.sequenceiq.cloudbreak.auth.CrnUser) DetailedDBStackStatus(com.sequenceiq.redbeams.api.model.common.DetailedDBStackStatus) DBStackStatus(com.sequenceiq.redbeams.domain.stack.DBStackStatus) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn)

Example 3 with DBStackStatus

use of com.sequenceiq.redbeams.domain.stack.DBStackStatus in project cloudbreak by hortonworks.

the class DatabaseServerConfigToDatabaseServerV4ResponseConverterTest method initDBStackStatus.

private void initDBStackStatus(DBStack dbStack) {
    DBStackStatus dbStackStatus = new DBStackStatus();
    dbStackStatus.setStatus(Status.CREATE_IN_PROGRESS);
    dbStackStatus.setStatusReason(STATUS_REASON);
    dbStack.setDBStackStatus(dbStackStatus);
}
Also used : DBStackStatus(com.sequenceiq.redbeams.domain.stack.DBStackStatus)

Example 4 with DBStackStatus

use of com.sequenceiq.redbeams.domain.stack.DBStackStatus in project cloudbreak by hortonworks.

the class DBStackStatusUpdater method updateStatus.

public Optional<DBStack> updateStatus(Long dbStackId, DetailedDBStackStatus detailedStatus, String statusReason) {
    return dbStackService.findById(dbStackId).map(dbStack -> {
        if (dbStack.getStatus() != Status.DELETE_COMPLETED) {
            Status status = detailedStatus.getStatus();
            DBStackStatus updatedStatus = new DBStackStatus(dbStack, status, statusReason, detailedStatus, clock.getCurrentTimeMillis());
            // The next line is a workaround to get the @OneToOne @MapsId relationship between DBStack and DBStackStatus working
            // see https://hibernate.atlassian.net/browse/HHH-12436
            // It might be removable once Spring Boot bumps up to Hibernate 5.4
            updatedStatus.setId(dbStackId);
            dbStack.setDBStackStatus(updatedStatus);
            dbStack = dbStackService.save(dbStack);
            redbeamsInMemoryStateStoreUpdaterService.update(dbStackId, updatedStatus.getStatus());
        }
        return dbStack;
    });
}
Also used : DetailedDBStackStatus(com.sequenceiq.redbeams.api.model.common.DetailedDBStackStatus) DBStackStatus(com.sequenceiq.redbeams.domain.stack.DBStackStatus) Status(com.sequenceiq.redbeams.api.model.common.Status) DetailedDBStackStatus(com.sequenceiq.redbeams.api.model.common.DetailedDBStackStatus) DBStackStatus(com.sequenceiq.redbeams.domain.stack.DBStackStatus)

Example 5 with DBStackStatus

use of com.sequenceiq.redbeams.domain.stack.DBStackStatus in project cloudbreak by hortonworks.

the class DBStackStatusUpdaterTest method testUpdateStatus.

@Test
public void testUpdateStatus() {
    dbStack.setDBStackStatus(new DBStackStatus(dbStack, DetailedDBStackStatus.CREATING_INFRASTRUCTURE, now));
    DBStack savedStack = underTest.updateStatus(1L, DetailedDBStackStatus.PROVISIONED, "because").get();
    verify(dbStackService).save(dbStack);
    verify(redbeamsInMemoryStateStoreUpdaterService).update(1L, Status.AVAILABLE);
    DBStackStatus dbStackStatus = savedStack.getDbStackStatus();
    assertEquals(dbStack, dbStackStatus.getDBStack());
    assertEquals(DetailedDBStackStatus.PROVISIONED.getStatus(), dbStackStatus.getStatus());
    assertEquals("because", dbStackStatus.getStatusReason());
    assertEquals(DetailedDBStackStatus.PROVISIONED, dbStackStatus.getDetailedDBStackStatus());
    assertEquals(now, dbStackStatus.getCreated().longValue());
}
Also used : DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) DetailedDBStackStatus(com.sequenceiq.redbeams.api.model.common.DetailedDBStackStatus) DBStackStatus(com.sequenceiq.redbeams.domain.stack.DBStackStatus) Test(org.junit.Test)

Aggregations

DBStackStatus (com.sequenceiq.redbeams.domain.stack.DBStackStatus)6 DetailedDBStackStatus (com.sequenceiq.redbeams.api.model.common.DetailedDBStackStatus)5 DBStack (com.sequenceiq.redbeams.domain.stack.DBStack)3 Test (org.junit.Test)2 CrnUser (com.sequenceiq.cloudbreak.auth.CrnUser)1 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)1 CloudPlatform (com.sequenceiq.cloudbreak.common.mappable.CloudPlatform)1 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)1 Status (com.sequenceiq.redbeams.api.model.common.Status)1 DatabaseServerConfig (com.sequenceiq.redbeams.domain.DatabaseServerConfig)1 Instant (java.time.Instant)1 HashMap (java.util.HashMap)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1