Search in sources :

Example 46 with Environment

use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.

the class EnvironmentStatusCheckerJob method executeTracedJob.

@Override
protected void executeTracedJob(JobExecutionContext context) throws JobExecutionException {
    Long envId = getLocalIdAsLong();
    Optional<Environment> environmentOpt = environmentService.findEnvironmentById(envId);
    if (environmentOpt.isPresent()) {
        Environment environment = environmentOpt.get();
        if (flowLogService.isOtherFlowRunning(envId)) {
            LOGGER.info("EnvironmentStatusCheckerJob cannot run, because flow is running for environment: {}", environment.getName());
        } else {
            syncAnEnv(environment);
        }
    } else {
        environmentJobService.unschedule(envId);
        LOGGER.warn("EnvironmentStatusCheckerJob cannot run, because environment is not found with id: {}. This env is unscheduled now", envId);
    }
}
Also used : Environment(com.sequenceiq.environment.environment.domain.Environment)

Example 47 with Environment

use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.

the class NetworkCreationHandlerTest method testWithEndpointGatewayAndEnvironmentSubnets.

@Test
public void testWithEndpointGatewayAndEnvironmentSubnets() {
    EnvironmentDto environmentDto = createEnvironmentDto();
    Event<EnvironmentDto> environmentDtoEvent = Event.wrap(environmentDto);
    AwsNetwork network = createNetwork();
    Environment environment = createEnvironment(network);
    Optional<Environment> environmentOptional = Optional.of(environment);
    Map<String, CloudSubnet> subnets = createDefaultPrivateSubnets();
    subnets.putAll(createDefaultPublicSubnets());
    when(environmentService.findEnvironmentById(any())).thenReturn(environmentOptional);
    when(cloudNetworkService.retrieveSubnetMetadata(any(EnvironmentDto.class), any())).thenReturn(subnets);
    when(networkMetadataValidationService.getEndpointGatewaySubnetMetadata(any(), any())).thenReturn(Map.of());
    when(environmentResourceService.createAndSetNetwork(any(), any(), any(), any(), any())).thenReturn(network);
    // Testing that underTest.accept() does not throw a BadRequestException
    ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.accept(environmentDtoEvent));
    assertEquals(0, environmentDto.getNetwork().getEndpointGatewaySubnetMetas().size());
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) Environment(com.sequenceiq.environment.environment.domain.Environment) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) NetworkTest(com.sequenceiq.environment.environment.service.network.NetworkTest) Test(org.junit.jupiter.api.Test)

Example 48 with Environment

use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.

the class NetworkCreationHandlerTest method testHandleValidationFailure.

@Test
public void testHandleValidationFailure() {
    EnvironmentDto environmentDto = createEnvironmentDto();
    Event<EnvironmentDto> environmentDtoEvent = Event.wrap(environmentDto);
    AwsNetwork network = createNetwork();
    Environment environment = createEnvironment(network);
    Optional<Environment> environmentOptional = Optional.of(environment);
    Map<String, CloudSubnet> subnets = createDefaultPrivateSubnets();
    when(environmentService.findEnvironmentById(any())).thenReturn(environmentOptional);
    when(cloudNetworkService.retrieveSubnetMetadata(any(EnvironmentDto.class), any())).thenReturn(subnets);
    when(networkMetadataValidationService.getEndpointGatewaySubnetMetadata(any(), any())).thenThrow(new BadRequestException("failure"));
    when(environmentResourceService.createAndSetNetwork(any(), any(), any(), any(), any())).thenReturn(network);
    ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.accept(environmentDtoEvent));
    ArgumentCaptor<Event<EnvCreationFailureEvent>> eventCaptor = ArgumentCaptor.forClass(Event.class);
    verify(eventBus, times(1)).notify(any(Object.class), eventCaptor.capture());
    Event<EnvCreationFailureEvent> value = eventCaptor.getValue();
    assertTrue(value.getData().getException() instanceof BadRequestException);
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) EnvCreationFailureEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Environment(com.sequenceiq.environment.environment.domain.Environment) BadRequestException(javax.ws.rs.BadRequestException) Event(reactor.bus.Event) EnvCreationFailureEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent) NetworkTest(com.sequenceiq.environment.environment.service.network.NetworkTest) Test(org.junit.jupiter.api.Test)

Example 49 with Environment

use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.

the class PublicKeyCreationHandlerTest method acceptTestEnvironmentShouldNotBeUpdatedWhenAuthenticationDoesNotContainManagedKey.

@Test
void acceptTestEnvironmentShouldNotBeUpdatedWhenAuthenticationDoesNotContainManagedKey() {
    doAnswer(i -> null).when(eventSender).sendEvent(baseNamedFlowEvent.capture(), any(Headers.class));
    EnvironmentAuthentication authentication = new EnvironmentAuthentication();
    authentication.setManagedKey(false);
    Environment environment = new Environment();
    environment.setAuthentication(authentication);
    when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenReturn(Optional.of(environment));
    underTest.accept(environmentDtoEvent);
    verify(eventSender).sendEvent(baseNamedFlowEvent.capture(), headersArgumentCaptor.capture());
    verify(environmentResourceService, never()).createAndUpdateSshKey(environment);
    verify(environmentService, never()).save(any());
    verifyEnvCreationEvent();
}
Also used : EnvironmentAuthentication(com.sequenceiq.environment.environment.domain.EnvironmentAuthentication) Headers(reactor.bus.Event.Headers) Environment(com.sequenceiq.environment.environment.domain.Environment) Test(org.junit.jupiter.api.Test)

Example 50 with Environment

use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.

the class ResourceEncryptionInitializationHandlerTest method acceptTestEnvironmentShouldNotBeUpdatedWhenCloudPlatformIsNotAzure.

@Test
void acceptTestEnvironmentShouldNotBeUpdatedWhenCloudPlatformIsNotAzure() {
    doAnswer(i -> null).when(eventSender).sendEvent(baseNamedFlowEventCaptor.capture(), any(Headers.class));
    Environment environment = new Environment();
    eventDto.setCloudPlatform("Dummy-cloud");
    when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenReturn(Optional.of(environment));
    underTest.accept(environmentDtoEvent);
    verify(eventSender).sendEvent(baseNamedFlowEventCaptor.capture(), headersArgumentCaptor.capture());
    verify(environmentService, never()).save(any(Environment.class));
    verifyEnvCreationEvent();
}
Also used : Headers(reactor.bus.Event.Headers) Environment(com.sequenceiq.environment.environment.domain.Environment) Test(org.junit.jupiter.api.Test)

Aggregations

Environment (com.sequenceiq.environment.environment.domain.Environment)187 Test (org.junit.jupiter.api.Test)145 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)48 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)42 EnvironmentEditDto (com.sequenceiq.environment.environment.dto.EnvironmentEditDto)29 Credential (com.sequenceiq.environment.credential.domain.Credential)26 EnvironmentAuthentication (com.sequenceiq.environment.environment.domain.EnvironmentAuthentication)24 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)23 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)21 ParametersDto (com.sequenceiq.environment.parameter.dto.ParametersDto)16 AwsNetwork (com.sequenceiq.environment.network.dao.domain.AwsNetwork)15 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)14 ExtendedPollingResult (com.sequenceiq.cloudbreak.polling.ExtendedPollingResult)13 SecurityAccessDto (com.sequenceiq.environment.environment.dto.SecurityAccessDto)12 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)11 AwsParametersDto (com.sequenceiq.environment.parameter.dto.AwsParametersDto)11 AzureResourceEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto)11 Headers (reactor.bus.Event.Headers)11 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)10 AuthenticationDto (com.sequenceiq.environment.environment.dto.AuthenticationDto)10