use of com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent in project cloudbreak by hortonworks.
the class EnvironmentValidationHandler method goToFailedState.
private void goToFailedState(Event<EnvironmentValidationDto> environmentDtoEvent, String message) {
LOGGER.warn("Environment validation failed: {}", message);
EnvironmentDto environmentDto = environmentDtoEvent.getData().getEnvironmentDto();
EnvCreationFailureEvent failureEvent = new EnvCreationFailureEvent(environmentDto.getId(), environmentDto.getName(), new BadRequestException(message), environmentDto.getResourceCrn());
eventBus.notify(failureEvent.selector(), new Event<>(environmentDtoEvent.getHeaders(), failureEvent));
}
use of com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent in project cloudbreak by hortonworks.
the class NetworkCreationHandler method accept.
@Override
public void accept(Event<EnvironmentDto> environmentDtoEvent) {
EnvironmentDto environmentDto = environmentDtoEvent.getData();
try {
environmentService.findEnvironmentById(environmentDto.getId()).ifPresent(environment -> {
setChildEnvironmentNetworkIfItHasParentWithTheSameCloudProvider(environmentDto);
Map<String, CloudSubnet> subnetMetas = null;
Map<String, CloudSubnet> endpointGatewaySubnetMetas = null;
if (environmentDto.getNetwork() != null) {
LOGGER.debug("Environment ({}) dto has network, hence we're filling it's related subnet fields", environment.getName());
subnetMetas = cloudNetworkService.retrieveSubnetMetadata(environmentDto, environmentDto.getNetwork());
environmentDto.getNetwork().setSubnetMetas(subnetMetas);
endpointGatewaySubnetMetas = networkValidationService.getEndpointGatewaySubnetMetadata(environment, environmentDto);
environmentDto.getNetwork().setEndpointGatewaySubnetMetas(endpointGatewaySubnetMetas);
environmentResourceService.createAndSetNetwork(environment, environmentDto.getNetwork(), environment.getAccountId(), environmentDto.getNetwork().getSubnetMetas(), environmentDto.getNetwork().getEndpointGatewaySubnetMetas());
} else {
LOGGER.debug("Environment ({}) dto has no network!", environment.getName());
}
createCloudNetworkIfNeeded(environmentDto, environment);
createProviderSpecificNetworkResourcesIfNeeded(environmentDto, environment.getNetwork());
environmentService.save(environment);
});
initiateNextStep(environmentDtoEvent, environmentDto);
} catch (Exception e) {
EnvCreationFailureEvent failureEvent = new EnvCreationFailureEvent(environmentDto.getId(), environmentDto.getName(), e, environmentDto.getResourceCrn());
eventBus.notify(failureEvent.selector(), new Event<>(environmentDtoEvent.getHeaders(), failureEvent));
}
}
use of com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent in project cloudbreak by hortonworks.
the class PublicKeyCreationHandler method accept.
@Override
public void accept(Event<EnvironmentDto> environmentDtoEvent) {
LOGGER.debug("Accepting PublicKeyCreation event");
EnvironmentDto environmentDto = environmentDtoEvent.getData();
try {
environmentService.findEnvironmentById(environmentDto.getId()).ifPresent(environment -> {
if (environment.getAuthentication().isManagedKey()) {
boolean created = environmentResourceService.createAndUpdateSshKey(environment);
if (created) {
String publicKeyId = environment.getAuthentication().getPublicKeyId();
LOGGER.info("Update the environment and it's authentication with the created public SSH key id: '{}'", publicKeyId);
environmentService.save(environment);
} else {
LOGGER.info("The public key id could not be created for {}", environmentDto.getName());
}
} else {
LOGGER.debug("Environment {} requested no managed public key", environment.getName());
}
});
EnvCreationEvent envCreationEvent = getEnvCreateEvent(environmentDto);
eventSender().sendEvent(envCreationEvent, environmentDtoEvent.getHeaders());
} catch (Exception e) {
EnvCreationFailureEvent failedEvent = new EnvCreationFailureEvent(environmentDto.getId(), environmentDto.getName(), e, environmentDto.getResourceCrn());
Event<EnvCreationFailureEvent> ev = new Event<>(environmentDtoEvent.getHeaders(), failedEvent);
eventBus.notify(failedEvent.selector(), ev);
}
}
use of com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent in project cloudbreak by hortonworks.
the class EnvCreationActions method environmentValidationAction.
@Bean(name = "ENVIRONMENT_CREATION_VALIDATION_STATE")
public Action<?, ?> environmentValidationAction() {
return new AbstractEnvironmentCreationAction<>(EnvCreationEvent.class) {
@Override
protected void doExecute(CommonContext context, EnvCreationEvent payload, Map<Object, Object> variables) {
environmentService.findEnvironmentById(payload.getResourceId()).ifPresentOrElse(environment -> {
LOGGER.info("Validation of Environment has started. Current state is - ENVIRONMENT_CREATION_VALIDATION_STATE");
environment.setStatus(EnvironmentStatus.ENVIRONMENT_VALIDATION_IN_PROGRESS);
environment.setStatusReason(null);
environment = environmentService.save(environment);
EnvironmentDto environmentDto = environmentService.getEnvironmentDto(environment);
eventService.sendEventAndNotification(environmentDto, context.getFlowTriggerUserCrn(), ENVIRONMENT_VALIDATION_STARTED);
EnvironmentValidationDto environmentValidationDto = EnvironmentValidationDto.builder().withEnvironmentDto(environmentDto).withValidationType(ValidationType.ENVIRONMENT_CREATION).build();
sendEvent(context, VALIDATE_ENVIRONMENT_EVENT.selector(), environmentValidationDto);
}, () -> {
EnvCreationFailureEvent failureEvent = new EnvCreationFailureEvent(payload.getResourceId(), payload.getResourceName(), null, payload.getResourceCrn());
LOGGER.debug("Environment validation action went failed with EnvCreationFailureEvent was: {}", failureEvent);
eventService.sendEventAndNotificationForMissingEnv(payload, ENVIRONMENT_VALIDATION_FAILED, context.getFlowTriggerUserCrn());
LOGGER.warn("Failed to validate environment creation request! No environment found with id '{}'.", payload.getResourceId());
sendEvent(context, failureEvent);
});
}
};
}
use of com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent in project cloudbreak by hortonworks.
the class EnvCreationActions method resourceEncryptionInitializationAction.
@Bean(name = "ENVIRONMENT_RESOURCE_ENCRYPTION_INITIALIZATION_STARTED_STATE")
public Action<?, ?> resourceEncryptionInitializationAction() {
return new AbstractEnvironmentCreationAction<>(EnvCreationEvent.class) {
@Override
protected void doExecute(CommonContext context, EnvCreationEvent payload, Map<Object, Object> variables) {
environmentService.findEnvironmentById(payload.getResourceId()).ifPresentOrElse(environment -> {
LOGGER.info("Initialization of resource encryption has started." + " Current state is - ENVIRONMENT_RESOURCE_ENCRYPTION_INITIALIZATION_STARTED_STATE");
environment.setStatus(EnvironmentStatus.ENVIRONMENT_RESOURCE_ENCRYPTION_INITIALIZATION_IN_PROGRESS);
environment.setStatusReason(null);
environment = environmentService.save(environment);
EnvironmentDto environmentDto = environmentService.getEnvironmentDto(environment);
eventService.sendEventAndNotification(environmentDto, context.getFlowTriggerUserCrn(), ENVIRONMENT_RESOURCE_ENCRYPTION_INITIALIZATION_STARTED);
sendEvent(context, INITIALIZE_ENVIRONMENT_RESOURCE_ENCRYPTION_EVENT.selector(), environmentDto);
}, () -> {
EnvCreationFailureEvent failureEvent = new EnvCreationFailureEvent(payload.getResourceId(), payload.getResourceName(), null, payload.getResourceCrn());
LOGGER.debug("Environment encryption init action went failed with EnvCreationFailureEvent was: {}", failureEvent);
eventService.sendEventAndNotificationForMissingEnv(payload, ENVIRONMENT_RESOURCE_ENCRYPTION_INITIALIZATION_FAILED, context.getFlowTriggerUserCrn());
LOGGER.warn("Failed to create encryption resources for environment! No environment found with id '{}'.", payload.getResourceId());
sendEvent(context, failureEvent);
});
}
};
}
Aggregations