Search in sources :

Example 6 with ClusterApi

use of com.sequenceiq.cloudbreak.cluster.api.ClusterApi 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 7 with ClusterApi

use of com.sequenceiq.cloudbreak.cluster.api.ClusterApi in project cloudbreak by hortonworks.

the class ClusterUpgradeHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<ClusterUpgradeRequest> event) {
    LOGGER.debug("Accepting Cluster upgrade event..");
    ClusterUpgradeRequest request = event.getData();
    Long stackId = request.getResourceId();
    Selectable result;
    try {
        Stack stack = stackService.getByIdWithClusterInTransaction(stackId);
        Optional<String> remoteDataContext = getRemoteDataContext(stack);
        ClusterApi connector = clusterApiConnectors.getConnector(stack);
        Set<ClusterComponent> components = parcelService.getParcelComponentsByBlueprint(stack);
        connector.upgradeClusterRuntime(components, request.isPatchUpgrade(), remoteDataContext);
        ParcelOperationStatus parcelOperationStatus = parcelService.removeUnusedParcelComponents(stack, components);
        if (parcelOperationStatus.getFailed().isEmpty()) {
            result = new ClusterUpgradeSuccess(request.getResourceId());
        } else {
            LOGGER.info("There are failed parcel removals: {}", parcelOperationStatus);
            CloudbreakException exception = new CloudbreakException(format("Failed to remove the following parcels: %s", parcelOperationStatus.getFailed()));
            result = new ClusterUpgradeFailedEvent(request.getResourceId(), exception, DetailedStackStatus.CLUSTER_UPGRADE_FAILED);
        }
    } catch (Exception e) {
        LOGGER.error("Cluster upgrade event failed", e);
        result = new ClusterUpgradeFailedEvent(request.getResourceId(), e, DetailedStackStatus.CLUSTER_UPGRADE_FAILED);
    }
    return result;
}
Also used : ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) ClusterComponent(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent) ClusterUpgradeRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeRequest) ClusterUpgradeFailedEvent(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeFailedEvent) ClusterUpgradeSuccess(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeSuccess) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) ParcelOperationStatus(com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException)

Example 8 with ClusterApi

use of com.sequenceiq.cloudbreak.cluster.api.ClusterApi in project cloudbreak by hortonworks.

the class ClusterService method updateClusterMetadata.

public Cluster updateClusterMetadata(Long stackId) {
    Stack stack = stackService.getById(stackId);
    ClusterApi connector = clusterApiConnectors.getConnector(stack);
    if (!connector.clusterStatusService().isClusterManagerRunning()) {
        Set<InstanceMetaData> notTerminatedInstanceMetaDatas = instanceMetaDataService.findNotTerminatedAndNotZombieForStack(stackId);
        InstanceMetaData cmInstance = updateClusterManagerHostStatus(notTerminatedInstanceMetaDatas);
        eventService.fireCloudbreakEvent(stack.getId(), AVAILABLE.name(), CLUSTER_HOST_STATUS_UPDATED, Arrays.asList(cmInstance.getDiscoveryFQDN(), cmInstance.getInstanceStatus().name()));
        return stack.getCluster();
    } else {
        ExtendedHostStatuses extendedHostStatuses = connector.clusterStatusService().getExtendedHostStatuses(runtimeVersionService.getRuntimeVersion(stack.getCluster().getId()));
        updateClusterCertExpirationState(stack.getCluster(), extendedHostStatuses.isAnyCertExpiring());
        try {
            return transactionService.required(() -> {
                Set<InstanceMetaData> notTerminatedInstanceMetaDatas = instanceMetaDataService.findNotTerminatedAndNotZombieForStack(stackId);
                List<InstanceMetaData> updatedInstanceMetaData = updateInstanceStatuses(notTerminatedInstanceMetaDatas, extendedHostStatuses);
                instanceMetaDataService.saveAll(updatedInstanceMetaData);
                fireHostStatusUpdateNotification(stack, updatedInstanceMetaData);
                return stack.getCluster();
            });
        } catch (TransactionExecutionException e) {
            throw new TransactionRuntimeExecutionException(e);
        }
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ExtendedHostStatuses(com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses) ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)

Example 9 with ClusterApi

use of com.sequenceiq.cloudbreak.cluster.api.ClusterApi in project cloudbreak by hortonworks.

the class VmStatusCheckerConclusionStep method checkCMForInstanceStatuses.

private Conclusion checkCMForInstanceStatuses(ClusterApi connector, Set<InstanceMetaData> runningInstances, Long clusterId) {
    ExtendedHostStatuses extendedHostStatuses = connector.clusterStatusService().getExtendedHostStatuses(runtimeVersionService.getRuntimeVersion(clusterId));
    Map<HostName, Set<HealthCheck>> hostStatuses = extendedHostStatuses.getHostsHealth();
    Map<String, String> unhealthyHosts = hostStatuses.keySet().stream().filter(hostName -> !extendedHostStatuses.isHostHealthy(hostName)).collect(Collectors.toMap(StringType::value, extendedHostStatuses::statusReasonForHost));
    Set<String> noReportHosts = runningInstances.stream().map(InstanceMetaData::getDiscoveryFQDN).filter(Objects::nonNull).filter(discoveryFQDN -> !hostStatuses.containsKey(hostName(discoveryFQDN))).collect(toSet());
    if (!unhealthyHosts.isEmpty() || !noReportHosts.isEmpty()) {
        String conclusion = String.format("Unhealthy and/or unknown VMs found based on CM status. Unhealthy VMs: %s, unknown VMs: %s. " + "Please check the instances on your cloud provider for further details.", unhealthyHosts, noReportHosts);
        String details = String.format("Unhealthy and/or unknown VMs found based on CM status. Unhealthy VMs: %s, unknown VMs: %s", unhealthyHosts, noReportHosts);
        LOGGER.warn(details);
        return failed(conclusion, details);
    } else {
        return succeeded();
    }
}
Also used : ExtendedHostStatuses(com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) HealthCheck(com.sequenceiq.cloudbreak.common.type.HealthCheck) ExtendedHostStatuses(com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses) LoggerFactory(org.slf4j.LoggerFactory) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) Inject(javax.inject.Inject) InstanceMetaDataToCloudInstanceConverter(com.sequenceiq.cloudbreak.converter.spi.InstanceMetaDataToCloudInstanceConverter) Map(java.util.Map) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) StackInstanceStatusChecker(com.sequenceiq.cloudbreak.service.stack.StackInstanceStatusChecker) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) Collectors.toSet(java.util.stream.Collectors.toSet) Logger(org.slf4j.Logger) RuntimeVersionService(com.sequenceiq.cloudbreak.service.stack.RuntimeVersionService) Set(java.util.Set) StringType(com.sequenceiq.cloudbreak.cloud.model.generic.StringType) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) HostName.hostName(com.sequenceiq.cloudbreak.cloud.model.HostName.hostName) List(java.util.List) Component(org.springframework.stereotype.Component) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) InstanceSyncState(com.sequenceiq.cloudbreak.service.stack.flow.InstanceSyncState) HostName(com.sequenceiq.cloudbreak.cloud.model.HostName) ClusterApiConnectors(com.sequenceiq.cloudbreak.service.cluster.ClusterApiConnectors) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) Collectors.toSet(java.util.stream.Collectors.toSet) Set(java.util.Set) Objects(java.util.Objects) HostName(com.sequenceiq.cloudbreak.cloud.model.HostName)

Example 10 with ClusterApi

use of com.sequenceiq.cloudbreak.cluster.api.ClusterApi in project cloudbreak by hortonworks.

the class VmStatusCheckerConclusionStep method check.

@Override
public Conclusion check(Long resourceId) {
    Stack stack = stackService.getById(resourceId);
    ClusterApi connector = clusterApiConnectors.getConnector(stack);
    Set<InstanceMetaData> runningInstances = instanceMetaDataService.findNotTerminatedAndNotZombieForStack(stack.getId());
    if (isClusterManagerRunning(stack, connector)) {
        return checkCMForInstanceStatuses(connector, runningInstances, stack.getCluster().getId());
    } else {
        return checkProviderForInstanceStatuses(stack, runningInstances);
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Aggregations

ClusterApi (com.sequenceiq.cloudbreak.cluster.api.ClusterApi)27 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)20 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)9 Set (java.util.Set)7 ExtendedHostStatuses (com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses)6 ParcelOperationStatus (com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus)5 ClusterApiConnectors (com.sequenceiq.cloudbreak.service.cluster.ClusterApiConnectors)5 ClusterStatusService (com.sequenceiq.cloudbreak.cluster.api.ClusterStatusService)4 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)4 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)4 InstanceMetaDataService (com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService)4 StackService (com.sequenceiq.cloudbreak.service.stack.StackService)4 Collectors (java.util.stream.Collectors)4 Inject (javax.inject.Inject)4 Test (org.junit.jupiter.api.Test)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 Service (org.springframework.stereotype.Service)4 InstanceStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus)3 HostName (com.sequenceiq.cloudbreak.cloud.model.HostName)3