Search in sources :

Example 81 with Stack

use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.

the class CleanupFreeIpaHandler method accept.

@Override
public void accept(Event<CleanupFreeIpaEvent> cleanupFreeIpaEvent) {
    CleanupFreeIpaEvent event = cleanupFreeIpaEvent.getData();
    try {
        LOGGER.debug("Handle cleanup request for hosts: {} and IPs: {}", event.getHostNames(), event.getIps());
        Stack stack = stackService.get(event.getResourceId());
        if (event.isRecover()) {
            LOGGER.debug("Invoke cleanup on recover");
            freeIpaCleanupService.cleanupOnRecover(stack, event.getHostNames(), event.getIps());
        } else {
            LOGGER.debug("Invoke cleanup on scale");
            freeIpaCleanupService.cleanupOnScale(stack, event.getHostNames(), event.getIps());
        }
        LOGGER.debug("Cleanup finished for hosts: {} and IPs: {}", event.getHostNames(), event.getIps());
    } catch (Exception e) {
        LOGGER.error("FreeIPA cleanup failed for hosts {} and IPs: {}", event.getHostNames(), event.getIps(), e);
    } finally {
        CleanupFreeIpaEvent response = new CleanupFreeIpaEvent(CLEANUP_FREEIPA_FINISHED_EVENT.event(), event.getResourceId(), event.getHostNames(), event.getIps(), event.isRecover());
        Event<StackEvent> responseEvent = new Event<>(cleanupFreeIpaEvent.getHeaders(), response);
        eventBus.notify(CLEANUP_FREEIPA_FINISHED_EVENT.event(), responseEvent);
    }
}
Also used : CleanupFreeIpaEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.CleanupFreeIpaEvent) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) CleanupFreeIpaEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.CleanupFreeIpaEvent) Event(reactor.bus.Event) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 82 with Stack

use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.

the class RegisterPublicDnsHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<RegisterPublicDnsRequest> event) {
    RegisterPublicDnsRequest request = event.getData();
    Stack stack = request.getStack();
    if (gatewayPublicEndpointManagementService.isCertRenewalTriggerable(stack)) {
        try {
            LOGGER.debug("Fetching instance group and instance metadata for stack.");
            InstanceGroup instanceGroup = instanceGroupService.getPrimaryGatewayInstanceGroupByStackId(stack.getId());
            List<InstanceMetaData> instanceMetaData = instanceMetaDataService.findAliveInstancesInInstanceGroup(instanceGroup.getId());
            if (!instanceMetaData.isEmpty()) {
                stack.getInstanceGroups().stream().filter(ig -> ig.getId().equals(instanceGroup.getId())).forEach(ig -> ig.setInstanceMetaData(Set.copyOf(instanceMetaData)));
                LOGGER.debug("Registering load balancer public DNS entry");
                boolean success = clusterPublicEndpointManagementService.provisionLoadBalancer(stack);
                if (!success) {
                    throw new CloudbreakException("Public DNS registration resulted in failed state. Please consult DNS registration logs.");
                }
                LOGGER.debug("Load balancer public DNS registration was successful");
                return new RegisterPublicDnsSuccess(stack);
            } else {
                throw new CloudbreakException("Unable to find instance metadata for primary instance group. Certificates cannot " + "be updated.");
            }
        } catch (Exception e) {
            LOGGER.warn("Failed to register load balancer public DNS entries.", e);
            return new RegisterPublicDnsFailure(request.getResourceId(), e);
        }
    } else {
        LOGGER.info("Certificates and DNS are not managed by PEM for stack {}. Skipping public DNS registration.", stack.getName());
        return new RegisterPublicDnsSuccess(stack);
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) Logger(org.slf4j.Logger) RegisterPublicDnsRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.RegisterPublicDnsRequest) LoggerFactory(org.slf4j.LoggerFactory) EventSelectorUtil(com.sequenceiq.flow.event.EventSelectorUtil) Set(java.util.Set) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) RegisterPublicDnsSuccess(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.RegisterPublicDnsSuccess) InstanceGroupService(com.sequenceiq.cloudbreak.service.stack.InstanceGroupService) ClusterPublicEndpointManagementService(com.sequenceiq.cloudbreak.service.publicendpoint.ClusterPublicEndpointManagementService) GatewayPublicEndpointManagementService(com.sequenceiq.cloudbreak.service.publicendpoint.GatewayPublicEndpointManagementService) Inject(javax.inject.Inject) List(java.util.List) Component(org.springframework.stereotype.Component) ExceptionCatcherEventHandler(com.sequenceiq.flow.reactor.api.handler.ExceptionCatcherEventHandler) Event(reactor.bus.Event) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) RegisterPublicDnsFailure(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.RegisterPublicDnsFailure) RegisterPublicDnsRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.RegisterPublicDnsRequest) RegisterPublicDnsSuccess(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.RegisterPublicDnsSuccess) RegisterPublicDnsFailure(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.RegisterPublicDnsFailure) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)

Example 83 with Stack

use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.

the class UpdateServiceConfigHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<UpdateServiceConfigRequest> event) {
    UpdateServiceConfigRequest request = event.getData();
    Stack stack = request.getStack();
    requireNonNull(stack);
    requireNonNull(stack.getCluster());
    try {
        LOGGER.debug("Gathering entries for Hue knox_proxyhosts property.");
        Set<String> proxyhosts = new HashSet<>();
        if (StringUtils.isNotEmpty(stack.getPrimaryGatewayInstance().getDiscoveryFQDN())) {
            proxyhosts.add(stack.getPrimaryGatewayInstance().getDiscoveryFQDN());
        }
        if (StringUtils.isNotEmpty(stack.getPrimaryGatewayInstance().getDiscoveryFQDN())) {
            proxyhosts.add(stack.getCluster().getFqdn());
        }
        String loadBalancerFqdn = loadBalancerConfigService.getLoadBalancerUserFacingFQDN(stack.getId());
        if (StringUtils.isNotEmpty(loadBalancerFqdn)) {
            proxyhosts.add(loadBalancerFqdn);
        }
        LOGGER.debug("Hue knox_proxyhosts setting will be updated to {}", proxyhosts);
        ClusterApi clusterApi = clusterApiConnectors.getConnector(stackService.getByIdWithListsInTransaction(event.getData().getResourceId()));
        clusterApi.clusterModificationService().updateServiceConfigAndRestartService(HUE_SERVICE, HUE_KNOX_PROXYHOSTS, String.join(",", proxyhosts));
        LOGGER.debug("Updating CM frontend URL with load balancer DNS");
        clusterHostServiceRunner.updateClusterConfigs(stack, stack.getCluster());
        LOGGER.debug("Service config update was successful");
        return new UpdateServiceConfigSuccess(stack);
    } catch (Exception e) {
        LOGGER.warn("Error updating HUE and CM service configuration.", e);
        return new UpdateServiceConfigFailure(request.getResourceId(), e);
    }
}
Also used : UpdateServiceConfigRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.UpdateServiceConfigRequest) UpdateServiceConfigFailure(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.UpdateServiceConfigFailure) UpdateServiceConfigSuccess(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.UpdateServiceConfigSuccess) ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) HashSet(java.util.HashSet)

Example 84 with Stack

use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.

the class UpdateDomainDnsResolverHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<UpdateDomainDnsResolverRequest> updateDomainDnsResolverRequestHandlerEvent) {
    UpdateDomainDnsResolverRequest event = updateDomainDnsResolverRequestHandlerEvent.getData();
    try {
        Stack stack = stackService.getByIdWithLists(event.getResourceId());
        DnsResolverType actualDnsResolverType = targetedUpscaleSupportService.getActualDnsResolverType(stack);
        if (!actualDnsResolverType.equals(stack.getDomainDnsResolver())) {
            LOGGER.debug("New value of domainDnsResolver field for stack {} is {}", stack.getResourceCrn(), actualDnsResolverType);
            stack.setDomainDnsResolver(actualDnsResolverType);
            stackService.save(stack);
            LOGGER.debug("domainDnsResolver field of stack {} has been successfully updated!", stack.getResourceCrn());
        } else {
            LOGGER.debug("Currently set and actual domainDnsResolverType is the same, not need for update, value {}", actualDnsResolverType);
        }
    } catch (Exception e) {
        LOGGER.debug("We couldn't update domainDnsResolver field of stack, so we move on with current value of the field.", e);
    }
    return new UpdateDomainDnsResolverResult(event.getResourceId());
}
Also used : UpdateDomainDnsResolverRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverRequest) DnsResolverType(com.sequenceiq.cloudbreak.domain.stack.DnsResolverType) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) UpdateDomainDnsResolverResult(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverResult)

Example 85 with Stack

use of com.sequenceiq.cloudbreak.domain.stack.Stack in project cloudbreak by hortonworks.

the class CreateCloudLoadBalancersHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<CreateCloudLoadBalancersRequest> event) {
    CreateCloudLoadBalancersRequest request = event.getData();
    CloudContext cloudContext = request.getCloudContext();
    try {
        LOGGER.info("Updating cloud stack with load balancer network information");
        CloudStack origCloudStack = request.getCloudStack();
        Stack stack = request.getStack();
        CloudStack updatedCloudStack = new CloudStack(origCloudStack.getGroups(), cloudStackConverter.buildNetwork(stack), origCloudStack.getImage(), origCloudStack.getParameters(), origCloudStack.getTags(), origCloudStack.getTemplate(), origCloudStack.getInstanceAuthentication(), origCloudStack.getLoginUserName(), origCloudStack.getPublicKey(), origCloudStack.getFileSystem().orElse(null), origCloudStack.getLoadBalancers());
        CloudConnector<Object> connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
        AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
        LOGGER.debug("Initiating cloud load balancer creation");
        List<CloudResourceStatus> resourceStatus = connector.resources().launchLoadBalancers(ac, updatedCloudStack, persistenceNotifier);
        LOGGER.debug("Waiting for cloud load balancers to be fully created");
        List<CloudResource> resources = ResourceLists.transform(resourceStatus);
        PollTask<ResourcesStatePollerResult> task = statusCheckFactory.newPollResourcesStateTask(ac, resources, true);
        ResourcesStatePollerResult statePollerResult = ResourcesStatePollerResults.build(cloudContext, resourceStatus);
        if (!task.completed(statePollerResult)) {
            syncPollingScheduler.schedule(task);
        }
        if (resourceStatus.stream().anyMatch(CloudResourceStatus::isFailed)) {
            Set<String> names = resourceStatus.stream().filter(CloudResourceStatus::isFailed).map(r -> r.getCloudResource().getName()).collect(Collectors.toSet());
            throw new CloudbreakException("Creation failed for load balancers: " + names);
        }
        Set<String> types = updatedCloudStack.getLoadBalancers().stream().map(CloudLoadBalancer::getType).map(LoadBalancerType::toString).collect(Collectors.toSet());
        LOGGER.info("Cloud load balancer creation for load balancer types {} successful", types);
        return new CreateCloudLoadBalancersSuccess(stack);
    } catch (Exception e) {
        LOGGER.warn("Failed to created cloud load balance resources.", e);
        return new CreateCloudLoadBalancersFailure(request.getResourceId(), e);
    }
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) ResourcesStatePollerResult(com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ResourceLists(com.sequenceiq.cloudbreak.cloud.transform.ResourceLists) LoggerFactory(org.slf4j.LoggerFactory) StackToCloudStackConverter(com.sequenceiq.cloudbreak.converter.spi.StackToCloudStackConverter) EventSelectorUtil(com.sequenceiq.flow.event.EventSelectorUtil) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) Inject(javax.inject.Inject) ExceptionCatcherEventHandler(com.sequenceiq.flow.reactor.api.handler.ExceptionCatcherEventHandler) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Event(reactor.bus.Event) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) PollTask(com.sequenceiq.cloudbreak.cloud.task.PollTask) CreateCloudLoadBalancersSuccess(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.CreateCloudLoadBalancersSuccess) Logger(org.slf4j.Logger) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) PollTaskFactory(com.sequenceiq.cloudbreak.cloud.task.PollTaskFactory) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) ResourcesStatePollerResults(com.sequenceiq.cloudbreak.cloud.transform.ResourcesStatePollerResults) Set(java.util.Set) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) PersistenceNotifier(com.sequenceiq.cloudbreak.cloud.notification.PersistenceNotifier) CreateCloudLoadBalancersFailure(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.CreateCloudLoadBalancersFailure) Collectors(java.util.stream.Collectors) CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) List(java.util.List) Component(org.springframework.stereotype.Component) CloudPlatformConnectors(com.sequenceiq.cloudbreak.cloud.init.CloudPlatformConnectors) SyncPollingScheduler(com.sequenceiq.cloudbreak.cloud.scheduler.SyncPollingScheduler) CreateCloudLoadBalancersRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.CreateCloudLoadBalancersRequest) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CreateCloudLoadBalancersRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.CreateCloudLoadBalancersRequest) CreateCloudLoadBalancersFailure(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.CreateCloudLoadBalancersFailure) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) CreateCloudLoadBalancersSuccess(com.sequenceiq.cloudbreak.reactor.api.event.stack.loadbalancer.CreateCloudLoadBalancersSuccess) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ResourcesStatePollerResult(com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult)

Aggregations

Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1041 Test (org.junit.jupiter.api.Test)326 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)255 Test (org.junit.Test)208 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)158 Map (java.util.Map)114 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)113 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)112 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)111 List (java.util.List)101 Set (java.util.Set)101 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)100 Collectors (java.util.stream.Collectors)84 Optional (java.util.Optional)83 HashSet (java.util.HashSet)82 Inject (javax.inject.Inject)80 Logger (org.slf4j.Logger)78 LoggerFactory (org.slf4j.LoggerFactory)78 DetailedStackStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus)69 StackStatus (com.sequenceiq.cloudbreak.domain.stack.StackStatus)67