Search in sources :

Example 36 with InstanceMetaData

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

the class ClusterCommonService method getHostNamesAsIniString.

/**
 * Get cluster host details (ips + cluster name) - ini format
 *
 * @param stack     stack object that is used to fill the cluster details ini
 * @param loginUser ssh username that will be used as a default user in the inventory
 * @return Ini file content in string
 */
public String getHostNamesAsIniString(Stack stack, String loginUser) {
    Cluster cluster = stack.getCluster();
    String clusterName = cluster.getName();
    String serverHost = cluster.getClusterManagerIp();
    List<InstanceMetaData> agentHostsSet = instanceMetaDataService.getAllInstanceMetadataByStackId(stack.getId()).stream().filter(i -> i.getInstanceStatus() != InstanceStatus.TERMINATED).collect(Collectors.toList());
    if (agentHostsSet.isEmpty()) {
        throw new NotFoundException(String.format("Not found any agent hosts (yet) for cluster '%s'", cluster.getId()));
    }
    String agentHosts = agentHostsSet.stream().map(InstanceMetaData::getPublicIpWrapper).collect(Collectors.joining("\n"));
    List<String> hostGroupHostsStrings = agentHostsSet.stream().collect(Collectors.groupingBy(InstanceMetaData::getInstanceGroupName)).entrySet().stream().map(s -> addSectionWithBody(s.getKey(), s.getValue().stream().map(InstanceMetaData::getPublicIpWrapper).collect(Collectors.joining("\n")))).collect(Collectors.toList());
    return String.join("\n", addSectionWithBody("cluster", "name=" + clusterName), addSectionWithBody("server", serverHost), String.join("\n", hostGroupHostsStrings), addSectionWithBody("agent", agentHosts), addSectionWithBody("all:vars", String.join("\n", String.format("ansible_ssh_user=%s", loginUser), "ansible_ssh_common_args='-o StrictHostKeyChecking=no'", "ansible_become=yes")));
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) AttachRecipeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recipe.AttachRecipeV4Response) LoggerFactory(org.slf4j.LoggerFactory) UserNamePasswordV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UserNamePasswordV4Request) ClusterService(com.sequenceiq.cloudbreak.service.cluster.ClusterService) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException) InstanceGroupService(com.sequenceiq.cloudbreak.service.stack.InstanceGroupService) HostGroupDecorator(com.sequenceiq.cloudbreak.service.decorator.HostGroupDecorator) CloudbreakEventService(com.sequenceiq.cloudbreak.structuredevent.event.CloudbreakEventService) CmTemplateValidator(com.sequenceiq.cloudbreak.cmtemplate.CmTemplateValidator) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) UpdateClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UpdateClusterV4Request) CertificatesRotationV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.CertificatesRotationV4Request) UpdateRecipesV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recipe.UpdateRecipesV4Response) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) Set(java.util.Set) Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) CertificatesRotationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.CertificatesRotationV4Response) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) Collectors(java.util.stream.Collectors) List(java.util.List) AttachRecipeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.recipe.AttachRecipeV4Request) ClusterOperationService(com.sequenceiq.cloudbreak.service.cluster.flow.ClusterOperationService) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) EnvironmentStatus(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentStatus) UpdateRecipeService(com.sequenceiq.cloudbreak.service.recipe.UpdateRecipeService) HostGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupV4Request) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) UpdateNodeCountValidator(com.sequenceiq.cloudbreak.service.stack.flow.UpdateNodeCountValidator) HostGroupV4RequestToHostGroupConverter(com.sequenceiq.cloudbreak.converter.v4.stacks.updates.HostGroupV4RequestToHostGroupConverter) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) HostGroupService(com.sequenceiq.cloudbreak.service.hostgroup.HostGroupService) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Service(org.springframework.stereotype.Service) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) ClusterComponentConfigProvider(com.sequenceiq.cloudbreak.cluster.service.ClusterComponentConfigProvider) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Logger(org.slf4j.Logger) MaintenanceModeStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.MaintenanceModeStatus) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) UpdateRecipesV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.recipe.UpdateRecipesV4Request) NameOrCrn(com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn) DetachRecipeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recipe.DetachRecipeV4Response) MAINTENANCE_MODE_ENABLED(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.MAINTENANCE_MODE_ENABLED) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) DetachRecipeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.recipe.DetachRecipeV4Request) BlueprintService(com.sequenceiq.cloudbreak.service.blueprint.BlueprintService) EnvironmentService(com.sequenceiq.cloudbreak.service.environment.EnvironmentService) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException)

Example 37 with InstanceMetaData

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

the class ClusterOperationService method updateAutoRecoverableNodes.

private void updateAutoRecoverableNodes(Cluster cluster, Map<String, List<String>> autoRecoveryNodesMap, Map<String, InstanceMetaData> autoRecoveryHostMetadata) throws TransactionExecutionException {
    if (!autoRecoveryNodesMap.isEmpty()) {
        flowManager.triggerClusterRepairFlow(cluster.getStack().getId(), autoRecoveryNodesMap, false);
        Map<String, Optional<String>> hostNamesWithReason = autoRecoveryHostMetadata.keySet().stream().collect(Collectors.toMap(host -> host, host -> Optional.empty()));
        Set<InstanceStatus> expectedStates = Set.of(SERVICES_HEALTHY);
        InstanceStatus newState = InstanceStatus.WAITING_FOR_REPAIR;
        ResourceEvent clusterEvent = CLUSTER_AUTORECOVERY_REQUESTED_CLUSTER_EVENT;
        ResourceEvent hostEvent = CLUSTER_AUTORECOVERY_REQUESTED_HOST_EVENT;
        updateChangedHosts(cluster, hostNamesWithReason, expectedStates, newState, clusterEvent, Optional.of(hostEvent));
    }
}
Also used : ComponentType(com.sequenceiq.cloudbreak.common.type.ComponentType) SERVICES_RUNNING(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_RUNNING) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) Resource(com.sequenceiq.cloudbreak.domain.Resource) AVAILABLE(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.AVAILABLE) HostGroupAdjustmentV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupAdjustmentV4Request) SERVICES_UNHEALTHY(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_UNHEALTHY) LoggerFactory(org.slf4j.LoggerFactory) UserNamePasswordV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UserNamePasswordV4Request) Math.abs(java.lang.Math.abs) Measure(com.sequenceiq.cloudbreak.aspect.Measure) ClusterService(com.sequenceiq.cloudbreak.service.cluster.ClusterService) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException) StringUtils(org.apache.commons.lang3.StringUtils) StatusRequest(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.StatusRequest) CloudbreakMessagesService(com.sequenceiq.cloudbreak.message.CloudbreakMessagesService) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) CloudbreakEventService(com.sequenceiq.cloudbreak.structuredevent.event.CloudbreakEventService) Map(java.util.Map) CLUSTER_AUTORECOVERY_REQUESTED_CLUSTER_EVENT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_AUTORECOVERY_REQUESTED_CLUSTER_EVENT) StackUpdater(com.sequenceiq.cloudbreak.service.StackUpdater) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) EnumSet(java.util.EnumSet) RecoveryMode(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.RecoveryMode) CLUSTER_RECOVERED_NODES_REPORTED_CLUSTER_EVENT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_RECOVERED_NODES_REPORTED_CLUSTER_EVENT) CertificatesRotationV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.CertificatesRotationV4Request) ResourceAttributeUtil(com.sequenceiq.cloudbreak.cluster.util.ResourceAttributeUtil) SERVICES_HEALTHY(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.SERVICES_HEALTHY) FileSystemConfigService(com.sequenceiq.cloudbreak.service.filesystem.FileSystemConfigService) Collection(java.util.Collection) CLUSTER_STOP_IGNORED(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_STOP_IGNORED) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) Set(java.util.Set) Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Collectors(java.util.stream.Collectors) ClouderaManagerRepo(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo) Sets(com.google.common.collect.Sets) List(java.util.List) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) Optional(java.util.Optional) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) CLUSTER_FAILED_NODES_REPORTED_HOST_EVENT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_FAILED_NODES_REPORTED_HOST_EVENT) START_IN_PROGRESS(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.START_IN_PROGRESS) CMRepositoryVersionUtil(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil) ReactorFlowManager(com.sequenceiq.cloudbreak.core.flow2.service.ReactorFlowManager) HashMap(java.util.HashMap) HostGroupService(com.sequenceiq.cloudbreak.service.hostgroup.HostGroupService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ResourceService(com.sequenceiq.cloudbreak.service.resource.ResourceService) StackStopRestrictionService(com.sequenceiq.cloudbreak.service.stack.StackStopRestrictionService) Service(org.springframework.stereotype.Service) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) FAILED(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.FAILED) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) ResourceType(com.sequenceiq.common.api.type.ResourceType) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) DECOMMISSION_FAILED(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.DECOMMISSION_FAILED) Logger(org.slf4j.Logger) Benchmark.measure(com.sequenceiq.cloudbreak.util.Benchmark.measure) BlueprintValidator(com.sequenceiq.cloudbreak.template.validation.BlueprintValidator) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) IOException(java.io.IOException) CLUSTER_AUTORECOVERY_REQUESTED_HOST_EVENT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_AUTORECOVERY_REQUESTED_HOST_EVENT) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) CLUSTER_FAILED_NODES_REPORTED_CLUSTER_EVENT(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_FAILED_NODES_REPORTED_CLUSTER_EVENT) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) ClusterComponent(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent) NotAllowedStatusUpdate(com.sequenceiq.cloudbreak.util.NotAllowedStatusUpdate) User(com.sequenceiq.cloudbreak.workspace.model.User) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CLUSTER_START_IGNORED(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_START_IGNORED) BlueprintService(com.sequenceiq.cloudbreak.service.blueprint.BlueprintService) UsageLoggingUtil(com.sequenceiq.cloudbreak.util.UsageLoggingUtil) BlueprintValidatorFactory(com.sequenceiq.cloudbreak.service.blueprint.BlueprintValidatorFactory) STOPPED(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.STOPPED) Collections(java.util.Collections) StopRestrictionReason(com.sequenceiq.cloudbreak.domain.StopRestrictionReason) Optional(java.util.Optional) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent)

Example 38 with InstanceMetaData

use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData 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 39 with InstanceMetaData

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

the class ClusterService method updateInstancesToRunning.

public void updateInstancesToRunning(Long stackId, Set<Node> reachableNodes) {
    try {
        transactionService.required(() -> {
            List<InstanceMetaData> createdInstances = instanceMetaDataService.findNotTerminatedForStack(stackId).stream().filter(InstanceMetaData::isCreated).collect(Collectors.toList());
            for (InstanceMetaData instanceMetaData : createdInstances) {
                if (reachableNodes.stream().anyMatch(node -> node.getHostname().equals(instanceMetaData.getDiscoveryFQDN()))) {
                    instanceMetaData.setInstanceStatus(SERVICES_RUNNING);
                    instanceMetaDataService.save(instanceMetaData);
                }
            }
        });
    } catch (TransactionExecutionException e) {
        throw new TransactionRuntimeExecutionException(e);
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)

Example 40 with InstanceMetaData

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

the class ClusterService method updateClusterManagerHostStatus.

private InstanceMetaData updateClusterManagerHostStatus(Set<InstanceMetaData> notTerminatedInstanceMetaDatas) {
    InstanceMetaData cmInstance = notTerminatedInstanceMetaDatas.stream().filter(InstanceMetaData::getClusterManagerServer).findFirst().orElseThrow(() -> new CloudbreakServiceException("Cluster manager inaccessible, and the corresponding instance metadata not found."));
    cmInstance.setInstanceStatus(SERVICES_UNHEALTHY);
    cmInstance.setStatusReason("Cluster manager inaccessible.");
    instanceMetaDataService.save(cmInstance);
    return cmInstance;
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)

Aggregations

InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)415 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)165 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)152 Test (org.junit.jupiter.api.Test)143 Map (java.util.Map)92 HashSet (java.util.HashSet)90 Set (java.util.Set)86 List (java.util.List)84 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)77 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)73 Collectors (java.util.stream.Collectors)71 ArrayList (java.util.ArrayList)62 Test (org.junit.Test)60 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)57 Optional (java.util.Optional)52 StackService (com.sequenceiq.cloudbreak.service.stack.StackService)48 Inject (javax.inject.Inject)47 Logger (org.slf4j.Logger)47 LoggerFactory (org.slf4j.LoggerFactory)47 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)45