Search in sources :

Example 86 with Environment

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

the class EnvClustersDeleteActions method commonUpdateEnvironmentAndNotify.

private EnvironmentDeletionDto commonUpdateEnvironmentAndNotify(CommonContext context, EnvDeleteEvent payload, EnvironmentStatus environmentStatus, ResourceEvent resourceEvent, EnvClustersDeleteState envClustersDeleteState, String logDeleteState) {
    environmentService.findEnvironmentById(payload.getResourceId()).ifPresentOrElse(environment -> {
        environment.setStatus(environmentStatus);
        environment.setStatusReason(null);
        Environment env = environmentService.save(environment);
        EnvironmentDto environmentDto = environmentService.getEnvironmentDto(env);
        eventService.sendEventAndNotification(environmentDto, context.getFlowTriggerUserCrn(), resourceEvent);
    }, () -> LOGGER.error("Cannot delete {} because the environment does not exist: {}. " + "But the flow will continue, how can this happen?", logDeleteState, payload.getResourceId()));
    EnvironmentDto envDto = new EnvironmentDto();
    envDto.setId(payload.getResourceId());
    envDto.setResourceCrn(payload.getResourceCrn());
    envDto.setName(payload.getResourceName());
    LOGGER.info("Flow entered into {}", envClustersDeleteState.name());
    EnvironmentDeletionDto environmentDeletionDto = EnvironmentDeletionDto.builder().withEnvironmentDto(envDto).withForceDelete(payload.isForceDelete()).withId(payload.getResourceId()).build();
    return environmentDeletionDto;
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) Environment(com.sequenceiq.environment.environment.domain.Environment) EnvironmentDeletionDto(com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto)

Example 87 with Environment

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

the class EnvCreationActions method finishedAction.

@Bean(name = "ENV_CREATION_FINISHED_STATE")
public Action<?, ?> finishedAction() {
    return new AbstractEnvironmentCreationAction<>(EnvCreationEvent.class) {

        @Override
        protected void doExecute(CommonContext context, EnvCreationEvent payload, Map<Object, Object> variables) {
            LOGGER.debug("Finished to create environment with payload {}", payload);
            environmentService.findEnvironmentById(payload.getResourceId()).ifPresentOrElse(environment -> {
                environment.setStatus(EnvironmentStatus.AVAILABLE);
                environment.setStatusReason(null);
                Environment result = environmentService.save(environment);
                environmentJobService.schedule(result.getId());
                EnvironmentDto environmentDto = environmentService.getEnvironmentDto(result);
                metricService.incrementMetricCounter(MetricType.ENV_CREATION_FINISHED, environmentDto);
                eventService.sendEventAndNotification(environmentDto, context.getFlowTriggerUserCrn(), ENVIRONMENT_CREATION_FINISHED);
            }, () -> LOGGER.error("Cannot finish the creation of env, because the environment does not exist: {}. " + "But the flow will continue, how can this happen?", payload.getResourceId()));
            LOGGER.info("Flow entered into ENV_CREATION_FINISHED_STATE");
            sendEvent(context, FINALIZE_ENV_CREATION_EVENT.event(), payload);
        }
    };
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CommonContext(com.sequenceiq.flow.core.CommonContext) Environment(com.sequenceiq.environment.environment.domain.Environment) EnvCreationEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 88 with Environment

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

the class EnvironmentDtoConverter method creationDtoToEnvironment.

public Environment creationDtoToEnvironment(EnvironmentCreationDto creationDto) {
    Environment environment = new Environment();
    environment.setAccountId(creationDto.getAccountId());
    environment.setCreator(creationDto.getCreator());
    environment.setName(creationDto.getName());
    environment.setOriginalName(creationDto.getName());
    environment.setArchived(false);
    environment.setCloudPlatform(creationDto.getCloudPlatform());
    environment.setDescription(creationDto.getDescription());
    LocationDto location = creationDto.getLocation();
    environment.setLatitude(location.getLatitude());
    environment.setLongitude(location.getLongitude());
    environment.setLocation(location.getName());
    environment.setTelemetry(creationDto.getTelemetry());
    environment.setBackup(creationDto.getBackup());
    environment.setLocationDisplayName(location.getDisplayName());
    environment.setStatus(EnvironmentStatus.CREATION_INITIATED);
    environment.setStatusReason(null);
    environment.setCreateFreeIpa(creationDto.getFreeIpaCreation().getCreate());
    environment.setFreeIpaInstanceCountByGroup(creationDto.getFreeIpaCreation().getInstanceCountByGroup());
    environment.setFreeIpaInstanceType(creationDto.getFreeIpaCreation().getInstanceType());
    environment.setFreeIpaImageCatalog(creationDto.getFreeIpaCreation().getImageCatalog());
    environment.setFreeIpaEnableMultiAz(creationDto.getFreeIpaCreation().isEnableMultiAz());
    environment.setDeletionType(NONE);
    environment.setFreeIpaImageId(creationDto.getFreeIpaCreation().getImageId());
    environment.setAdminGroupName(creationDto.getAdminGroupName());
    environment.setCreated(System.currentTimeMillis());
    environment.setTags(getTags(creationDto));
    environment.setExperimentalFeaturesJson(creationDto.getExperimentalFeatures());
    setLocation(creationDto, environment, location);
    return environment;
}
Also used : Environment(com.sequenceiq.environment.environment.domain.Environment)

Example 89 with Environment

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

the class NetworkServiceTest method testSaveNetworkIfNewNetwork.

@Test
public void testSaveNetworkIfNewNetwork() {
    NetworkDto networkDto = mock(NetworkDto.class);
    EnvironmentNetworkConverter environmentNetworkConverter = mock(EnvironmentNetworkConverter.class);
    Network network = mock(Network.class);
    Credential credential = mock(Credential.class);
    BaseNetwork baseNetwork = new AwsNetwork();
    baseNetwork.setRegistrationType(RegistrationType.CREATE_NEW);
    Environment environment = new Environment();
    environment.setCloudPlatform("AWS");
    environment.setCredential(credential);
    when(environmentNetworkConverterMap.get(any(CloudPlatform.class))).thenReturn(environmentNetworkConverter);
    when(environmentNetworkConverter.convert(environment, networkDto, Map.of(), Map.of())).thenReturn(baseNetwork);
    when(networkRepository.save(baseNetwork)).thenReturn(baseNetwork);
    BaseNetwork result = underTest.saveNetwork(environment, networkDto, "accountId", Map.of(), Map.of());
    Assertions.assertNull(result.getNetworkCidr());
    verify(environmentNetworkService, times(0)).getNetworkCidr(eq(network), anyString(), eq(credential));
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) Credential(com.sequenceiq.environment.credential.domain.Credential) BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork) AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) GcpNetwork(com.sequenceiq.environment.network.dao.domain.GcpNetwork) BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork) AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) Environment(com.sequenceiq.environment.environment.domain.Environment) EnvironmentNetworkConverter(com.sequenceiq.environment.network.v1.converter.EnvironmentNetworkConverter) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 90 with Environment

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

the class NetworkServiceTest method testRefreshMetadataFromAwsCloudProviderMustUseSubnetId.

@Test
public void testRefreshMetadataFromAwsCloudProviderMustUseSubnetId() {
    NetworkDto networkDto = mock(NetworkDto.class);
    AuthenticationDto authenticationDto = mock(AuthenticationDto.class);
    EnvironmentTelemetry environmentTelemetry = mock(EnvironmentTelemetry.class);
    EnvironmentBackup environmentBackup = mock(EnvironmentBackup.class);
    SecurityAccessDto securityAccessDto = mock(SecurityAccessDto.class);
    ParametersDto parametersDto = mock(ParametersDto.class);
    EnvironmentNetworkConverter environmentNetworkConverter = mock(EnvironmentNetworkConverter.class);
    Network network = mock(Network.class);
    Credential credential = mock(Credential.class);
    BaseNetwork baseNetwork = new GcpNetwork();
    baseNetwork.setRegistrationType(RegistrationType.EXISTING);
    Environment environment = new Environment();
    environment.setCloudPlatform("AWS");
    environment.setCredential(credential);
    EnvironmentEditDto environmentEditDto = new EnvironmentEditDto("description", "accountId", networkDto, authenticationDto, environmentTelemetry, environmentBackup, securityAccessDto, Tunnel.CCMV2, IdBrokerMappingSource.MOCK, CloudStorageValidation.ENABLED, "adminGroupName", parametersDto);
    when(environmentNetworkConverterMap.get(any(CloudPlatform.class))).thenReturn(environmentNetworkConverter);
    when(environmentNetworkConverter.convertToDto(baseNetwork)).thenReturn(networkDto);
    when(cloudNetworkService.retrieveSubnetMetadata(any(Environment.class), any(NetworkDto.class))).thenReturn(Map.of("s1", cloudSubnet("s1", "subnet1")));
    when(cloudNetworkService.retrieveEndpointGatewaySubnetMetadata(any(Environment.class), any(NetworkDto.class))).thenReturn(Map.of("s1", cloudSubnet("s1", "subnet1")));
    when(environmentNetworkConverter.convertToNetwork(any(BaseNetwork.class))).thenReturn(network);
    when(environmentNetworkService.getNetworkCidr(any(Network.class), anyString(), any(Credential.class))).thenReturn(new NetworkCidr("10.0.0.0", new ArrayList<>()));
    BaseNetwork result = underTest.refreshMetadataFromCloudProvider(baseNetwork, environmentEditDto, environment);
    Assertions.assertEquals(result.getSubnetMetas().keySet().stream().findFirst().get(), "s1");
    Assertions.assertEquals(result.getSubnetMetas().keySet().size(), 1);
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) EnvironmentTelemetry(com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry) Credential(com.sequenceiq.environment.credential.domain.Credential) BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork) EnvironmentBackup(com.sequenceiq.environment.environment.dto.EnvironmentBackup) GcpNetwork(com.sequenceiq.environment.network.dao.domain.GcpNetwork) ArrayList(java.util.ArrayList) EnvironmentEditDto(com.sequenceiq.environment.environment.dto.EnvironmentEditDto) EnvironmentNetworkConverter(com.sequenceiq.environment.network.v1.converter.EnvironmentNetworkConverter) NetworkCidr(com.sequenceiq.cloudbreak.cloud.network.NetworkCidr) AuthenticationDto(com.sequenceiq.environment.environment.dto.AuthenticationDto) AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) GcpNetwork(com.sequenceiq.environment.network.dao.domain.GcpNetwork) BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork) Environment(com.sequenceiq.environment.environment.domain.Environment) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) SecurityAccessDto(com.sequenceiq.environment.environment.dto.SecurityAccessDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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