use of com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto in project cloudbreak by hortonworks.
the class DataHubClusterDeletionHandlerTest method setUp.
@BeforeEach
void setUp() {
EnvironmentDto eventDto = EnvironmentDto.builder().withId(ENV_ID).withResourceCrn(RESOURCE_CRN).withName(ENV_NAME).build();
EnvironmentDeletionDto build = EnvironmentDeletionDto.builder().withId(ENV_ID).withForceDelete(false).withEnvironmentDto(eventDto).build();
when(environmentDtoEvent.getData()).thenReturn(build);
when(environmentDtoEvent.getHeaders()).thenReturn(headers);
doAnswer(i -> null).when(eventSender).sendEvent(baseNamedFlowEvent.capture(), any(Event.Headers.class));
}
use of com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto in project cloudbreak by hortonworks.
the class S3GuardTableDeleteHandler method accept.
@Override
public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) {
EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData();
EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto();
EnvDeleteEvent envDeleteEvent = getEnvDeleteEvent(environmentDeletionDto);
try {
environmentService.findEnvironmentById(environmentDto.getId()).ifPresent(environment -> {
BaseParameters environmentParameters = environment.getParameters();
if (environmentParameters instanceof AwsParameters) {
AwsParameters awsParameters = (AwsParameters) environmentParameters;
deleteS3GuardTable(environment, awsParameters);
} else {
LOGGER.info("Environment parameters determine a non-AWS environment. DynamoDB table deletion is not necessary.");
}
});
eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders());
} catch (Exception e) {
exceptionProcessor.handle(new HandlerFailureConjoiner(e, environmentDtoEvent, envDeleteEvent), LOGGER, eventSender(), selector());
}
}
use of com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto in project cloudbreak by hortonworks.
the class FreeIpaDeletionHandler method accept.
@Override
public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) {
EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData();
EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto();
Environment environment = environmentService.findEnvironmentById(environmentDto.getId()).orElse(null);
try {
if (shouldRemoveFreeIpa(environment)) {
if (Objects.nonNull(environment.getParentEnvironment())) {
detachChildEnvironmentFromFreeIpa(environment);
} else {
deleteFreeIpa(environment, environmentDeletionDto.isForceDelete());
}
}
eventSender().sendEvent(getNextStepObject(environmentDeletionDto), environmentDtoEvent.getHeaders());
} catch (Exception e) {
EnvDeleteFailedEvent failedEvent = EnvDeleteFailedEvent.builder().withEnvironmentID(environmentDto.getId()).withException(e).withResourceCrn(environmentDto.getResourceCrn()).withResourceName(environmentDto.getName()).build();
eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders());
}
}
use of com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto in project cloudbreak by hortonworks.
the class EnvironmentUMSResourceDeleteHandler method accept.
@Override
public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) {
EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData();
EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto();
String environmentCrn = null;
try {
environmentCrn = environmentDto.getResourceCrn();
AtomicReference<String> resourceCrn = new AtomicReference<>(null);
environmentService.findEnvironmentById(environmentDto.getId()).ifPresent(environment -> {
resourceCrn.set(environment.getResourceCrn());
});
if (StringUtils.isBlank(environmentCrn)) {
environmentCrn = resourceCrn.get();
}
virtualGroupService.cleanupVirtualGroups(Crn.fromString(environmentCrn).getAccountId(), environmentCrn);
ownerAssignmentService.notifyResourceDeleted(environmentCrn, MDCUtils.getRequestId());
} catch (Exception e) {
LOGGER.warn("UMS delete event failed (this event is not critical)", e);
}
EnvDeleteEvent envDeleteEvent = EnvDeleteEvent.builder().withResourceId(environmentDto.getResourceId()).withResourceName(environmentDto.getName()).withResourceCrn(environmentCrn).withForceDelete(environmentDeletionDto.isForceDelete()).withSelector(FINISH_ENV_DELETE_EVENT.selector()).build();
eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders());
}
use of com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto in project cloudbreak by hortonworks.
the class NetworkDeleteHandler method accept.
@Override
public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) {
EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData();
EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto();
EnvDeleteEvent envDeleteEvent = EnvDeleteEvent.builder().withResourceId(environmentDto.getResourceId()).withResourceName(environmentDto.getName()).withResourceCrn(environmentDto.getResourceCrn()).withForceDelete(environmentDeletionDto.isForceDelete()).withSelector(START_IDBROKER_MAPPINGS_DELETE_EVENT.selector()).build();
try {
environmentService.findEnvironmentById(environmentDto.getId()).ifPresent(environment -> {
BaseNetwork network = environment.getNetwork();
if (network != null) {
RegistrationType registrationType = network.getRegistrationType();
if (RegistrationType.CREATE_NEW == registrationType) {
environmentNetworkService.deleteNetwork(environmentDtoConverter.environmentToDto(environment));
}
network.setName(environment.getResourceCrn() + "_network_DELETED_@_" + System.currentTimeMillis());
environmentService.save(environment);
}
});
eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders());
} catch (Exception e) {
exceptionProcessor.handle(new HandlerFailureConjoiner(e, environmentDtoEvent, envDeleteEvent), LOGGER, eventSender(), selector());
}
}
Aggregations