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;
}
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);
}
};
}
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;
}
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));
}
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);
}
Aggregations