use of com.sequenceiq.environment.environment.flow.loadbalancer.event.LoadBalancerUpdateEvent in project cloudbreak by hortonworks.
the class EnvironmentReactorFlowManager method triggerLoadBalancerUpdateFlow.
public FlowIdentifier triggerLoadBalancerUpdateFlow(EnvironmentDto environmentDto, Long envId, String envName, String envCrn, PublicEndpointAccessGateway endpointAccessGateway, Set<String> subnetIds, String userCrn) {
LOGGER.info("Load balancer update flow triggered.");
if (PublicEndpointAccessGateway.ENABLED.equals(endpointAccessGateway)) {
if (subnetIds != null && !subnetIds.isEmpty()) {
LOGGER.debug("Adding Endpoint Gateway with subnet ids {}", subnetIds);
} else {
LOGGER.debug("Adding Endpoint Gateway using environment subnets.");
}
}
LoadBalancerUpdateEvent loadBalancerUpdateEvent = LoadBalancerUpdateEvent.LoadBalancerUpdateEventBuilder.aLoadBalancerUpdateEvent().withAccepted(new Promise<>()).withSelector(LoadBalancerUpdateStateSelectors.LOAD_BALANCER_UPDATE_START_EVENT.selector()).withResourceId(envId).withResourceName(envName).withResourceCrn(envCrn).withEnvironmentDto(environmentDto).withPublicEndpointAccessGateway(endpointAccessGateway).withSubnetIds(subnetIds).build();
return eventSender.sendEvent(loadBalancerUpdateEvent, new Event.Headers(getFlowTriggerUsercrn(userCrn)));
}
use of com.sequenceiq.environment.environment.flow.loadbalancer.event.LoadBalancerUpdateEvent in project cloudbreak by hortonworks.
the class LoadBalancerUpdateActions method stackLoadBalancerUpdate.
@Bean(name = "STACK_UPDATE_STATE")
public Action<?, ?> stackLoadBalancerUpdate() {
return new AbstractLoadBalancerUpdateAction<>(LoadBalancerUpdateEvent.class) {
@Override
protected void doExecute(CommonContext context, LoadBalancerUpdateEvent payload, Map<Object, Object> variables) {
EnvironmentStatus environmentStatus = EnvironmentStatus.LOAD_BALANCER_STACK_UPDATE_STARTED;
ResourceEvent resourceEvent = ResourceEvent.ENVIRONMENT_LOAD_BALANCER_STACK_UPDATE_STARTED;
LoadBalancerUpdateState loadBalancerUpdateState = LoadBalancerUpdateState.STACK_UPDATE_STATE;
EnvironmentDto envDto = environmentStatusUpdateService.updateEnvironmentStatusAndNotify(context, payload, environmentStatus, resourceEvent, loadBalancerUpdateState);
EnvironmentLoadBalancerDto environmentLoadBalancerDto = EnvironmentLoadBalancerDto.builder().withId(envDto.getId()).withEnvironmentDto(payload.getEnvironmentDto()).withEndpointAccessGateway(payload.getEndpointAccessGateway()).withEndpointGatewaySubnetIds(payload.getSubnetIds()).build();
sendEvent(context, LoadBalancerUpdateHandlerSelectors.STACK_UPDATE_HANDLER_EVENT.selector(), environmentLoadBalancerDto);
}
};
}
use of com.sequenceiq.environment.environment.flow.loadbalancer.event.LoadBalancerUpdateEvent in project cloudbreak by hortonworks.
the class LoadBalancerUpdateActions method environmentLoadBalancerUpdate.
@Bean(name = "ENVIRONMENT_UPDATE_STATE")
public Action<?, ?> environmentLoadBalancerUpdate() {
return new AbstractLoadBalancerUpdateAction<>(LoadBalancerUpdateEvent.class) {
@Override
protected void doExecute(CommonContext context, LoadBalancerUpdateEvent payload, Map<Object, Object> variables) {
EnvironmentStatus environmentStatus = EnvironmentStatus.LOAD_BALANCER_ENV_UPDATE_STARTED;
ResourceEvent resourceEvent = ResourceEvent.ENVIRONMENT_LOAD_BALANCER_ENV_UPDATE_STARTED;
LoadBalancerUpdateState loadBalancerUpdateState = LoadBalancerUpdateState.ENVIRONMENT_UPDATE_STATE;
EnvironmentDto envDto = environmentStatusUpdateService.updateEnvironmentStatusAndNotify(context, payload, environmentStatus, resourceEvent, loadBalancerUpdateState);
EnvironmentLoadBalancerDto environmentLoadBalancerDto = EnvironmentLoadBalancerDto.builder().withId(envDto.getId()).withEnvironmentDto(payload.getEnvironmentDto()).withEndpointAccessGateway(payload.getEndpointAccessGateway()).withEndpointGatewaySubnetIds(payload.getSubnetIds()).build();
sendEvent(context, LoadBalancerUpdateHandlerSelectors.ENVIRONMENT_UPDATE_HANDLER_EVENT.selector(), environmentLoadBalancerDto);
}
};
}
use of com.sequenceiq.environment.environment.flow.loadbalancer.event.LoadBalancerUpdateEvent in project cloudbreak by hortonworks.
the class LoadBalancerEnvUpdateHandler method accept.
@Override
public void accept(Event<EnvironmentLoadBalancerDto> envLoadBalancerDtoEvent) {
EnvironmentLoadBalancerDto environmentLoadBalancerDto = envLoadBalancerDtoEvent.getData();
EnvironmentDto environmentDto = environmentLoadBalancerDto.getEnvironmentDto();
requireNonNull(environmentDto);
requireNonNull(environmentDto.getNetwork());
try {
Environment environment = environmentService.findEnvironmentByIdOrThrow(environmentDto.getResourceId());
requireNonNull(environment);
requireNonNull(environment.getNetwork());
LOGGER.debug("Starting endpoint gateway update for environment {}", environmentDto.getResourceCrn());
NetworkDto networkDto = environmentDto.getNetwork();
if (PublicEndpointAccessGateway.ENABLED.equals(environmentLoadBalancerDto.getEndpointAccessGateway())) {
LOGGER.debug("Enabling endpoint gateway on environment network.");
networkDto.setPublicEndpointAccessGateway(PublicEndpointAccessGateway.ENABLED);
Map<String, CloudSubnet> tempSubnetMetas = environmentLoadBalancerDto.getEndpointGatewaySubnetIds().stream().collect(toMap(id -> id, id -> new CloudSubnet(id, null)));
networkDto.setEndpointGatewaySubnetMetas(tempSubnetMetas);
LOGGER.debug("Fetching metadata for endpoint gateway subnets.");
Map<String, CloudSubnet> endpointGatewaySubnetMetas = networkValidationService.getEndpointGatewaySubnetMetadata(environment, environmentDto);
LOGGER.debug("Updating environment network settings.");
environment.getNetwork().setPublicEndpointAccessGateway(PublicEndpointAccessGateway.ENABLED);
environment.getNetwork().setEndpointGatewaySubnetMetas(endpointGatewaySubnetMetas);
LOGGER.debug("Persisting updated network to database.");
networkService.save(environment.getNetwork());
}
LOGGER.debug("Environment network load balancer update complete.");
LoadBalancerUpdateEvent loadBalancerUpdateEvent = LoadBalancerUpdateEvent.LoadBalancerUpdateEventBuilder.aLoadBalancerUpdateEvent().withSelector(LoadBalancerUpdateStateSelectors.LOAD_BALANCER_STACK_UPDATE_EVENT.selector()).withResourceId(environment.getId()).withResourceName(environment.getResourceName()).withResourceCrn(environment.getResourceCrn()).withEnvironmentDto(environmentDto).withEnvironment(environment).withPublicEndpointAccessGateway(environmentLoadBalancerDto.getEndpointAccessGateway()).withSubnetIds(environmentLoadBalancerDto.getEndpointGatewaySubnetIds()).build();
eventSender().sendEvent(loadBalancerUpdateEvent, envLoadBalancerDtoEvent.getHeaders());
} catch (Exception e) {
LOGGER.error("Caught exception while updating environment state with laod balancers.", e);
LoadBalancerUpdateFailedEvent failedEvent = new LoadBalancerUpdateFailedEvent(environmentDto, e, EnvironmentStatus.LOAD_BALANCER_ENV_UPDATE_FAILED);
eventSender().sendEvent(failedEvent, envLoadBalancerDtoEvent.getHeaders());
}
}
use of com.sequenceiq.environment.environment.flow.loadbalancer.event.LoadBalancerUpdateEvent in project cloudbreak by hortonworks.
the class LoadBalancerStackUpdateHandler method accept.
@Override
public void accept(Event<EnvironmentLoadBalancerDto> envLoadBalancerDtoEvent) {
EnvironmentLoadBalancerDto environmentLoadBalancerDto = envLoadBalancerDtoEvent.getData();
EnvironmentDto environmentDto = environmentLoadBalancerDto.getEnvironmentDto();
try {
LOGGER.debug("Initating stack load balancer update");
loadBalancerPollerService.updateStackWithLoadBalancer(environmentDto.getId(), environmentDto.getResourceCrn(), environmentDto.getName(), environmentLoadBalancerDto.getEndpointAccessGateway());
LOGGER.debug("Stack load balancer update complete.");
LoadBalancerUpdateEvent loadBalancerUpdateEvent = LoadBalancerUpdateEvent.LoadBalancerUpdateEventBuilder.aLoadBalancerUpdateEvent().withSelector(LoadBalancerUpdateStateSelectors.FINISH_LOAD_BALANCER_UPDATE_EVENT.selector()).withResourceId(environmentDto.getResourceId()).withResourceName(environmentDto.getName()).withResourceCrn(environmentDto.getResourceCrn()).withEnvironmentDto(environmentDto).withPublicEndpointAccessGateway(environmentLoadBalancerDto.getEndpointAccessGateway()).withSubnetIds(environmentLoadBalancerDto.getEndpointGatewaySubnetIds()).build();
eventSender().sendEvent(loadBalancerUpdateEvent, envLoadBalancerDtoEvent.getHeaders());
} catch (Exception e) {
LoadBalancerUpdateFailedEvent failedEvent = new LoadBalancerUpdateFailedEvent(environmentDto, e, EnvironmentStatus.LOAD_BALANCER_STACK_UPDATE_FAILED);
eventSender().sendEvent(failedEvent, envLoadBalancerDtoEvent.getHeaders());
}
}
Aggregations