Search in sources :

Example 1 with DetailedEnvironmentResponse

use of com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse in project cloudbreak by hortonworks.

the class SdxReactorFlowManagerTest method testSdxBackupOnUpgradeAzureSupported.

@Test
void testSdxBackupOnUpgradeAzureSupported() {
    sdxCluster = getValidSdxCluster("7.2.2");
    sdxCluster.setRangerRazEnabled(false);
    DetailedEnvironmentResponse detailedEnvironmentResponse = new DetailedEnvironmentResponse();
    detailedEnvironmentResponse.setCloudPlatform("AZURE");
    when(environmentClientService.getByName(anyString())).thenReturn(detailedEnvironmentResponse);
    when(environmentClientService.getBackupLocation(ENV_CRN)).thenReturn(BACKUP_LOCATION);
    when(entitlementService.isDatalakeBackupOnUpgradeEnabled(any())).thenReturn(true);
    when(datalakeDrConfig.isConfigured()).thenReturn(true);
    sdxCluster.setCloudStorageFileSystemType(FileSystemType.ADLS_GEN_2);
    try {
        ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.triggerDatalakeRuntimeUpgradeFlow(sdxCluster, IMAGE_ID, SdxUpgradeReplaceVms.DISABLED, SKIP_BACKUP));
    } catch (Exception ignored) {
    }
    verify(reactor, times(1)).notify(eq(DatalakeUpgradeFlowChainStartEvent.DATALAKE_UPGRADE_FLOW_CHAIN_EVENT), any(Event.class));
}
Also used : DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) DatalakeUpgradeFlowChainStartEvent(com.sequenceiq.datalake.flow.datalake.upgrade.event.DatalakeUpgradeFlowChainStartEvent) Event(reactor.bus.Event) BaseFlowEvent(com.sequenceiq.flow.reactor.api.event.BaseFlowEvent) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Test(org.junit.jupiter.api.Test)

Example 2 with DetailedEnvironmentResponse

use of com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse in project cloudbreak by hortonworks.

the class SdxReactorFlowManagerTest method testSdxBackupOnUpgradeAwsSupported.

@Test
void testSdxBackupOnUpgradeAwsSupported() {
    sdxCluster = getValidSdxCluster("7.2.10");
    sdxCluster.setRangerRazEnabled(false);
    sdxCluster.setCloudStorageFileSystemType(FileSystemType.S3);
    DetailedEnvironmentResponse detailedEnvironmentResponse = new DetailedEnvironmentResponse();
    detailedEnvironmentResponse.setCloudPlatform("AWS");
    when(environmentClientService.getByName(anyString())).thenReturn(detailedEnvironmentResponse);
    when(environmentClientService.getBackupLocation(ENV_CRN)).thenReturn(BACKUP_LOCATION);
    when(entitlementService.isDatalakeBackupOnUpgradeEnabled(any())).thenReturn(true);
    when(datalakeDrConfig.isConfigured()).thenReturn(true);
    try {
        ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.triggerDatalakeRuntimeUpgradeFlow(sdxCluster, IMAGE_ID, SdxUpgradeReplaceVms.DISABLED, SKIP_BACKUP));
    } catch (Exception ignored) {
    }
    verify(reactor, times(1)).notify(eq(DatalakeUpgradeFlowChainStartEvent.DATALAKE_UPGRADE_FLOW_CHAIN_EVENT), any(Event.class));
    reset(reactor);
    sdxCluster = getValidSdxCluster("7.2.1");
    sdxCluster.setCloudStorageFileSystemType(FileSystemType.S3);
    try {
        ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.triggerDatalakeRuntimeUpgradeFlow(sdxCluster, IMAGE_ID, SdxUpgradeReplaceVms.DISABLED, SKIP_BACKUP));
    } catch (Exception ignored) {
    }
    verify(reactor, times(1)).notify(eq(DatalakeUpgradeFlowChainStartEvent.DATALAKE_UPGRADE_FLOW_CHAIN_EVENT), any(Event.class));
}
Also used : DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) DatalakeUpgradeFlowChainStartEvent(com.sequenceiq.datalake.flow.datalake.upgrade.event.DatalakeUpgradeFlowChainStartEvent) Event(reactor.bus.Event) BaseFlowEvent(com.sequenceiq.flow.reactor.api.event.BaseFlowEvent) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Test(org.junit.jupiter.api.Test)

Example 3 with DetailedEnvironmentResponse

use of com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse in project cloudbreak by hortonworks.

the class SdxReactorFlowManagerTest method testSdxBackupOnUpgradeForMockPlatformWithEmptyFileSystemType.

@Test
void testSdxBackupOnUpgradeForMockPlatformWithEmptyFileSystemType() {
    DetailedEnvironmentResponse detailedEnvironmentResponse = new DetailedEnvironmentResponse();
    detailedEnvironmentResponse.setCloudPlatform("MOCK");
    sdxCluster = getValidSdxCluster("7.2.9");
    sdxCluster.setRangerRazEnabled(false);
    sdxCluster.setCloudStorageFileSystemType(null);
    when(environmentClientService.getByName(anyString())).thenReturn(detailedEnvironmentResponse);
    when(environmentClientService.getBackupLocation(ENV_CRN)).thenReturn(BACKUP_LOCATION);
    when(entitlementService.isDatalakeBackupOnUpgradeEnabled(any())).thenReturn(true);
    when(datalakeDrConfig.isConfigured()).thenReturn(true);
    try {
        ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.triggerDatalakeRuntimeUpgradeFlow(sdxCluster, IMAGE_ID, SdxUpgradeReplaceVms.DISABLED, SKIP_BACKUP));
    } catch (Exception ignored) {
    }
    verify(reactor, times(1)).notify(eq(DatalakeUpgradeFlowChainStartEvent.DATALAKE_UPGRADE_FLOW_CHAIN_EVENT), any(Event.class));
}
Also used : DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) DatalakeUpgradeFlowChainStartEvent(com.sequenceiq.datalake.flow.datalake.upgrade.event.DatalakeUpgradeFlowChainStartEvent) Event(reactor.bus.Event) BaseFlowEvent(com.sequenceiq.flow.reactor.api.event.BaseFlowEvent) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Test(org.junit.jupiter.api.Test)

Example 4 with DetailedEnvironmentResponse

use of com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse in project cloudbreak by hortonworks.

the class StartExternalDatabaseHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<StartExternalDatabaseRequest> event) {
    LOGGER.debug("In StartExternalDatabaseHandler.doAccept");
    StartExternalDatabaseRequest request = event.getData();
    Stack stack = stackService.getById(request.getResourceId());
    DatabaseAvailabilityType externalDatabase = ObjectUtils.defaultIfNull(stack.getExternalDatabaseCreationType(), DatabaseAvailabilityType.NONE);
    LOGGER.debug("External database: {} for stack {}", externalDatabase.name(), stack.getName());
    LOGGER.debug("Getting environment CRN for stack {}", stack.getName());
    DetailedEnvironmentResponse environment = environmentClientService.getByCrn(stack.getEnvironmentCrn());
    Selectable result;
    try {
        if (StackType.WORKLOAD != stack.getType()) {
            LOGGER.debug("External database start in Cloudbreak service is required for WORKLOAD stacks only.");
            result = new StartExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STARTED_EVENT.event(), stack.getName(), null);
        } else if (externalDatabase.isEmbedded()) {
            LOGGER.info("External database for stack {} is not requested. Start is not possible.", stack.getName());
            result = new StartExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STARTED_EVENT.event(), stack.getName(), null);
        } else if (!externalDatabaseConfig.isExternalDatabasePauseSupportedFor(CloudPlatform.valueOf(environment.getCloudPlatform()))) {
            LOGGER.debug("External database pause is not supported for '{}' cloud platform.", environment.getCloudPlatform());
            result = new StartExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STARTED_EVENT.event(), stack.getName(), null);
        } else {
            LOGGER.debug("Updating stack {} status from {} to {}", stack.getName(), stack.getStatus().name(), DetailedStackStatus.EXTERNAL_DATABASE_START_IN_PROGRESS.name());
            stackUpdaterService.updateStatus(stack.getId(), DetailedStackStatus.EXTERNAL_DATABASE_START_IN_PROGRESS, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_START_COMMANCED, "External database start in progress");
            startService.startDatabase(stack.getCluster(), externalDatabase, environment);
            LOGGER.debug("Updating stack {} status from {} to {}", stack.getName(), stack.getStatus().name(), DetailedStackStatus.EXTERNAL_DATABASE_START_FINISHED.name());
            stackUpdaterService.updateStatus(stack.getId(), DetailedStackStatus.EXTERNAL_DATABASE_START_FINISHED, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_START_FINISHED, "External database start finished");
            result = new StartExternalDatabaseResult(stack.getId(), EXTERNAL_DATABASE_STARTED_EVENT.event(), stack.getName(), stack.getCluster().getDatabaseServerCrn());
        }
    } catch (UserBreakException e) {
        LOGGER.error("Database 'start' polling exited before timeout. Cause: ", e);
        result = startFailedEvent(stack, e);
    } catch (PollerStoppedException e) {
        LOGGER.error(String.format("Database 'start' poller stopped for stack: %s", stack.getName()), e);
        result = startFailedEvent(stack, e);
    } catch (PollerException e) {
        LOGGER.error(String.format("Database 'start' polling failed for stack: %s", stack.getName()), e);
        result = startFailedEvent(stack, e);
    }
    return result;
}
Also used : UserBreakException(com.dyngr.exception.UserBreakException) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) StartExternalDatabaseResult(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StartExternalDatabaseResult) PollerException(com.dyngr.exception.PollerException) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) StartExternalDatabaseRequest(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StartExternalDatabaseRequest) PollerStoppedException(com.dyngr.exception.PollerStoppedException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) DatabaseAvailabilityType(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.database.DatabaseAvailabilityType)

Example 5 with DetailedEnvironmentResponse

use of com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse in project cloudbreak by hortonworks.

the class StackCreationActions method getTlsInfoAction.

@Bean(name = "GET_TLS_INFO_STATE")
public Action<?, ?> getTlsInfoAction() {
    return new AbstractStackCreationAction<>(GetTlsInfoResult.class) {

        @Override
        protected void doExecute(StackCreationContext context, GetTlsInfoResult payload, Map<Object, Object> variables) {
            Stack stack = stackCreationService.saveTlsInfo(context, payload.getTlsInfo());
            StackCreationContext newContext = new StackCreationContext(context.getFlowParameters(), stack, context.getCloudContext(), context.getCloudCredential(), context.getCloudStack());
            sendEvent(newContext);
        }

        @Override
        protected Selectable createRequest(StackCreationContext context) {
            Stack stack = context.getStack();
            InstanceMetaData gatewayMetaData = stack.getPrimaryGatewayInstance();
            DetailedEnvironmentResponse environment = environmentClientService.getByCrnAsInternal(stack.getEnvironmentCrn());
            CloudInstance gatewayInstance = metadataConverter.convert(gatewayMetaData, environment, stack.getStackAuthentication());
            return new GetSSHFingerprintsRequest<GetSSHFingerprintsResult>(context.getCloudContext(), context.getCloudCredential(), gatewayInstance);
        }
    };
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) StackCreationContext(com.sequenceiq.cloudbreak.core.flow2.stack.start.StackCreationContext) GetSSHFingerprintsRequest(com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsRequest) GetTlsInfoResult(com.sequenceiq.cloudbreak.cloud.event.instance.GetTlsInfoResult) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Map(java.util.Map) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Bean(org.springframework.context.annotation.Bean)

Aggregations

DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)317 Test (org.junit.jupiter.api.Test)164 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)102 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)90 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)47 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)43 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)42 Test (org.junit.Test)37 LoadBalancer (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer)34 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)33 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)32 SubnetTest (com.sequenceiq.cloudbreak.core.network.SubnetTest)31 List (java.util.List)30 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)29 EnvironmentNetworkResponse (com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse)27 Set (java.util.Set)26 InstanceGroupV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request)25 ArrayList (java.util.ArrayList)25 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)24 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)24