Search in sources :

Example 11 with DownscaleFailureEvent

use of com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleFailureEvent in project cloudbreak by hortonworks.

the class RemoveServersResponseToDownscaleFailureEventConverter method convert.

@Override
public DownscaleFailureEvent convert(Object payload) {
    RemoveServersResponse removeServersResponse = (RemoveServersResponse) payload;
    DownscaleFailureEvent event = new DownscaleFailureEvent(removeServersResponse.getResourceId(), "Server removal", Set.of(), Map.of(), new Exception("Payload failed: " + payload));
    return event;
}
Also used : RemoveServersResponse(com.sequenceiq.freeipa.flow.freeipa.downscale.event.removeserver.RemoveServersResponse) DownscaleFailureEvent(com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleFailureEvent)

Example 12 with DownscaleFailureEvent

use of com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleFailureEvent in project cloudbreak by hortonworks.

the class CollectAdditionalHostnamesHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<CollectAdditionalHostnamesRequest> event) {
    CollectAdditionalHostnamesRequest request = event.getData();
    Selectable result;
    try {
        Long stackId = request.getResourceId();
        Set<String> fqdns = getHostnamesFromFreeIpaServers(stackId);
        result = new CollectAdditionalHostnamesResponse(request.getResourceId(), fqdns);
    } catch (Exception e) {
        LOGGER.error("Collecting additional hostnames failed", e);
        result = new DownscaleFailureEvent(DOWNSCALE_COLLECT_ADDITIONAL_HOSTNAMES_FAILED_EVENT.event(), request.getResourceId(), "Downscale Collect Additional Hostnames", Set.of(), Map.of(), e);
    }
    return result;
}
Also used : Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) CollectAdditionalHostnamesRequest(com.sequenceiq.freeipa.flow.freeipa.downscale.event.collecthostnames.CollectAdditionalHostnamesRequest) CollectAdditionalHostnamesResponse(com.sequenceiq.freeipa.flow.freeipa.downscale.event.collecthostnames.CollectAdditionalHostnamesResponse) DownscaleFailureEvent(com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleFailureEvent) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException)

Example 13 with DownscaleFailureEvent

use of com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleFailureEvent in project cloudbreak by hortonworks.

the class RemoveHostsHandler method accept.

@Override
public void accept(Event<RemoveHostsFromOrchestrationRequest> removeHostsRequestEvent) {
    RemoveHostsFromOrchestrationRequest request = removeHostsRequestEvent.getData();
    Set<String> hostNames = request.getHosts();
    Selectable result;
    try {
        if (!hostNames.isEmpty()) {
            Stack stack = stackService.getByIdWithListsInTransaction(request.getResourceId());
            PollingResult orchestratorRemovalPollingResult = removeHostsFromOrchestrator(stack, new ArrayList<>(hostNames));
            if (!orchestratorRemovalPollingResult.isSuccess()) {
                LOGGER.warn("Can not remove hosts from orchestrator: {}", hostNames);
            }
            // rebootstrap to update the minion's multi-master configuration
            List<String> remainingInstanceIds = stack.getNotDeletedInstanceMetaDataList().stream().filter(metadata -> Objects.nonNull(metadata.getDiscoveryFQDN())).filter(metadata -> !hostNames.contains(metadata.getDiscoveryFQDN())).map(InstanceMetaData::getInstanceId).collect(Collectors.toList());
            bootstrapService.bootstrap(stack.getId(), remainingInstanceIds);
        }
        result = new RemoveHostsFromOrchestrationSuccess(request.getResourceId());
    } catch (Exception e) {
        LOGGER.error("Failed to remove hosts from orchestration", e);
        result = new DownscaleFailureEvent(REMOVE_HOSTS_FROM_ORCHESTRATION_FAILED_EVENT.event(), request.getResourceId(), "Removing host from orchestration", Set.of(), Map.of(), e);
    }
    eventBus.notify(result.selector(), new Event<>(removeHostsRequestEvent.getHeaders(), result));
}
Also used : CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) LoggerFactory(org.slf4j.LoggerFactory) EventSelectorUtil(com.sequenceiq.flow.event.EventSelectorUtil) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) RemoveHostsFromOrchestrationSuccess(com.sequenceiq.freeipa.flow.freeipa.downscale.event.removehosts.RemoveHostsFromOrchestrationSuccess) Event(reactor.bus.Event) SUCCESS(com.sequenceiq.cloudbreak.polling.PollingResult.SUCCESS) Map(java.util.Map) StackService(com.sequenceiq.freeipa.service.stack.StackService) EventHandler(com.sequenceiq.flow.reactor.api.handler.EventHandler) StackBasedExitCriteriaModel(com.sequenceiq.freeipa.orchestrator.StackBasedExitCriteriaModel) REMOVE_HOSTS_FROM_ORCHESTRATION_FAILED_EVENT(com.sequenceiq.freeipa.flow.freeipa.downscale.DownscaleFlowEvent.REMOVE_HOSTS_FROM_ORCHESTRATION_FAILED_EVENT) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Stack(com.sequenceiq.freeipa.entity.Stack) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) RemoveHostsFromOrchestrationRequest(com.sequenceiq.freeipa.flow.freeipa.downscale.event.removehosts.RemoveHostsFromOrchestrationRequest) Logger(org.slf4j.Logger) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) Set(java.util.Set) EventBus(reactor.bus.EventBus) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) Component(org.springframework.stereotype.Component) GatewayConfigService(com.sequenceiq.freeipa.service.GatewayConfigService) DownscaleFailureEvent(com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleFailureEvent) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) PollingResult(com.sequenceiq.cloudbreak.polling.PollingResult) BootstrapService(com.sequenceiq.freeipa.service.BootstrapService) RemoveHostsFromOrchestrationSuccess(com.sequenceiq.freeipa.flow.freeipa.downscale.event.removehosts.RemoveHostsFromOrchestrationSuccess) DownscaleFailureEvent(com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleFailureEvent) RemoveHostsFromOrchestrationRequest(com.sequenceiq.freeipa.flow.freeipa.downscale.event.removehosts.RemoveHostsFromOrchestrationRequest) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) Stack(com.sequenceiq.freeipa.entity.Stack) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) PollingResult(com.sequenceiq.cloudbreak.polling.PollingResult)

Example 14 with DownscaleFailureEvent

use of com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleFailureEvent in project cloudbreak by hortonworks.

the class UpdateDnsSoaRecordsHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<UpdateDnsSoaRecordsRequest> event) {
    UpdateDnsSoaRecordsRequest request = event.getData();
    Selectable result;
    try {
        Long stackId = request.getResourceId();
        Set<String> fqdns = request.getHosts().stream().map(hostname -> StringUtils.appendIfMissing(hostname, ".")).collect(Collectors.toSet());
        updateSoaRecords(stackId, fqdns);
        result = new UpdateDnsSoaRecordsResponse(request.getResourceId());
    } catch (Exception e) {
        LOGGER.error("Downscale updating DNS SOA records failed", e);
        result = new DownscaleFailureEvent(DOWNSCALE_UPDATE_DNS_SOA_RECORDS_FAILED_EVENT.event(), request.getResourceId(), "Downscale Update DNS SOA Records", Set.of(), Map.of(), e);
    }
    return result;
}
Also used : DOWNSCALE_UPDATE_DNS_SOA_RECORDS_FAILED_EVENT(com.sequenceiq.freeipa.flow.freeipa.downscale.DownscaleFlowEvent.DOWNSCALE_UPDATE_DNS_SOA_RECORDS_FAILED_EVENT) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) EventSelectorUtil(com.sequenceiq.flow.event.EventSelectorUtil) IpaServer(com.sequenceiq.freeipa.client.model.IpaServer) Set(java.util.Set) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) UpdateDnsSoaRecordsResponse(com.sequenceiq.freeipa.flow.freeipa.downscale.event.dnssoarecords.UpdateDnsSoaRecordsResponse) UpdateDnsSoaRecordsRequest(com.sequenceiq.freeipa.flow.freeipa.downscale.event.dnssoarecords.UpdateDnsSoaRecordsRequest) Objects(java.util.Objects) Inject(javax.inject.Inject) DnsZone(com.sequenceiq.freeipa.client.model.DnsZone) Component(org.springframework.stereotype.Component) ExceptionCatcherEventHandler(com.sequenceiq.flow.reactor.api.handler.ExceptionCatcherEventHandler) DownscaleFailureEvent(com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleFailureEvent) Event(reactor.bus.Event) Map(java.util.Map) FreeIpaClientFactory(com.sequenceiq.freeipa.service.freeipa.FreeIpaClientFactory) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) UpdateDnsSoaRecordsRequest(com.sequenceiq.freeipa.flow.freeipa.downscale.event.dnssoarecords.UpdateDnsSoaRecordsRequest) DownscaleFailureEvent(com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleFailureEvent) UpdateDnsSoaRecordsResponse(com.sequenceiq.freeipa.flow.freeipa.downscale.event.dnssoarecords.UpdateDnsSoaRecordsResponse) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException)

Aggregations

DownscaleFailureEvent (com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleFailureEvent)14 Stack (com.sequenceiq.freeipa.entity.Stack)5 Map (java.util.Map)5 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)3 StackContext (com.sequenceiq.freeipa.flow.stack.StackContext)3 Bean (org.springframework.context.annotation.Bean)3 EventSelectorUtil (com.sequenceiq.flow.event.EventSelectorUtil)2 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)2 StackEvent (com.sequenceiq.freeipa.flow.stack.StackEvent)2 Objects (java.util.Objects)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 ClientErrorException (javax.ws.rs.ClientErrorException)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Component (org.springframework.stereotype.Component)2 Event (reactor.bus.Event)2 DownscaleStackCollectResourcesResult (com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackCollectResourcesResult)1 DownscaleStackResult (com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackResult)1