Search in sources :

Example 6 with EnvironmentLoadBalancerDto

use of com.sequenceiq.environment.environment.dto.EnvironmentLoadBalancerDto 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);
        }
    };
}
Also used : EnvironmentLoadBalancerDto(com.sequenceiq.environment.environment.dto.EnvironmentLoadBalancerDto) EnvironmentStatus(com.sequenceiq.environment.environment.EnvironmentStatus) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CommonContext(com.sequenceiq.flow.core.CommonContext) LoadBalancerUpdateEvent(com.sequenceiq.environment.environment.flow.loadbalancer.event.LoadBalancerUpdateEvent) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 7 with EnvironmentLoadBalancerDto

use of com.sequenceiq.environment.environment.dto.EnvironmentLoadBalancerDto 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);
        }
    };
}
Also used : EnvironmentLoadBalancerDto(com.sequenceiq.environment.environment.dto.EnvironmentLoadBalancerDto) EnvironmentStatus(com.sequenceiq.environment.environment.EnvironmentStatus) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CommonContext(com.sequenceiq.flow.core.CommonContext) LoadBalancerUpdateEvent(com.sequenceiq.environment.environment.flow.loadbalancer.event.LoadBalancerUpdateEvent) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 8 with EnvironmentLoadBalancerDto

use of com.sequenceiq.environment.environment.dto.EnvironmentLoadBalancerDto 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());
    }
}
Also used : LoadBalancerUpdateStateSelectors(com.sequenceiq.environment.environment.flow.loadbalancer.event.LoadBalancerUpdateStateSelectors) Environment(com.sequenceiq.environment.environment.domain.Environment) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) EventSender(com.sequenceiq.flow.reactor.api.event.EventSender) Logger(org.slf4j.Logger) LoadBalancerUpdateFailedEvent(com.sequenceiq.environment.environment.flow.loadbalancer.event.LoadBalancerUpdateFailedEvent) LoggerFactory(org.slf4j.LoggerFactory) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) EnvironmentService(com.sequenceiq.environment.environment.service.EnvironmentService) NetworkMetadataValidationService(com.sequenceiq.environment.environment.service.network.NetworkMetadataValidationService) LoadBalancerUpdateEvent(com.sequenceiq.environment.environment.flow.loadbalancer.event.LoadBalancerUpdateEvent) NetworkService(com.sequenceiq.environment.network.NetworkService) EnvironmentLoadBalancerDto(com.sequenceiq.environment.environment.dto.EnvironmentLoadBalancerDto) Component(org.springframework.stereotype.Component) Collectors.toMap(java.util.stream.Collectors.toMap) Event(reactor.bus.Event) NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) EventSenderAwareHandler(com.sequenceiq.flow.reactor.api.handler.EventSenderAwareHandler) PublicEndpointAccessGateway(com.sequenceiq.common.api.type.PublicEndpointAccessGateway) LoadBalancerUpdateHandlerSelectors(com.sequenceiq.environment.environment.flow.loadbalancer.event.LoadBalancerUpdateHandlerSelectors) Objects.requireNonNull(java.util.Objects.requireNonNull) Map(java.util.Map) EnvironmentStatus(com.sequenceiq.environment.environment.EnvironmentStatus) EnvironmentLoadBalancerDto(com.sequenceiq.environment.environment.dto.EnvironmentLoadBalancerDto) NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) LoadBalancerUpdateFailedEvent(com.sequenceiq.environment.environment.flow.loadbalancer.event.LoadBalancerUpdateFailedEvent) Environment(com.sequenceiq.environment.environment.domain.Environment) LoadBalancerUpdateEvent(com.sequenceiq.environment.environment.flow.loadbalancer.event.LoadBalancerUpdateEvent) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)

Example 9 with EnvironmentLoadBalancerDto

use of com.sequenceiq.environment.environment.dto.EnvironmentLoadBalancerDto 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());
    }
}
Also used : EnvironmentLoadBalancerDto(com.sequenceiq.environment.environment.dto.EnvironmentLoadBalancerDto) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) LoadBalancerUpdateFailedEvent(com.sequenceiq.environment.environment.flow.loadbalancer.event.LoadBalancerUpdateFailedEvent) LoadBalancerUpdateEvent(com.sequenceiq.environment.environment.flow.loadbalancer.event.LoadBalancerUpdateEvent)

Example 10 with EnvironmentLoadBalancerDto

use of com.sequenceiq.environment.environment.dto.EnvironmentLoadBalancerDto in project cloudbreak by hortonworks.

the class EnvironmentController method updateEnvironmentLoadBalancersByCrn.

@Override
@CheckPermissionByResourceCrn(action = AuthorizationResourceAction.EDIT_ENVIRONMENT)
public FlowIdentifier updateEnvironmentLoadBalancersByCrn(@ValidCrn(resource = CrnResourceDescriptor.ENVIRONMENT) @ResourceCrn @TenantAwareParam String crn, @NotNull EnvironmentLoadBalancerUpdateRequest request) {
    String accountId = ThreadBasedUserCrnProvider.getAccountId();
    EnvironmentDto environmentDto = environmentService.getByCrnAndAccountId(crn, accountId);
    EnvironmentLoadBalancerDto environmentLoadBalancerDto = environmentApiConverter.initLoadBalancerDto(request);
    return environmentLoadBalancerService.updateLoadBalancerInEnvironmentAndStacks(environmentDto, environmentLoadBalancerDto);
}
Also used : EnvironmentLoadBalancerDto(com.sequenceiq.environment.environment.dto.EnvironmentLoadBalancerDto) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CheckPermissionByResourceCrn(com.sequenceiq.authorization.annotation.CheckPermissionByResourceCrn)

Aggregations

EnvironmentLoadBalancerDto (com.sequenceiq.environment.environment.dto.EnvironmentLoadBalancerDto)11 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)10 Test (org.junit.jupiter.api.Test)5 LoadBalancerUpdateEvent (com.sequenceiq.environment.environment.flow.loadbalancer.event.LoadBalancerUpdateEvent)4 EnvironmentStatus (com.sequenceiq.environment.environment.EnvironmentStatus)3 Environment (com.sequenceiq.environment.environment.domain.Environment)3 Map (java.util.Map)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 ResourceEvent (com.sequenceiq.cloudbreak.event.ResourceEvent)2 LoadBalancerUpdateFailedEvent (com.sequenceiq.environment.environment.flow.loadbalancer.event.LoadBalancerUpdateFailedEvent)2 CommonContext (com.sequenceiq.flow.core.CommonContext)2 Bean (org.springframework.context.annotation.Bean)2 CheckPermissionByResourceCrn (com.sequenceiq.authorization.annotation.CheckPermissionByResourceCrn)1 CheckPermissionByResourceName (com.sequenceiq.authorization.annotation.CheckPermissionByResourceName)1 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)1 PublicEndpointAccessGateway (com.sequenceiq.common.api.type.PublicEndpointAccessGateway)1 EnvironmentLoadBalancerUpdateRequest (com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentLoadBalancerUpdateRequest)1 LoadBalancerUpdateHandlerSelectors (com.sequenceiq.environment.environment.flow.loadbalancer.event.LoadBalancerUpdateHandlerSelectors)1