Search in sources :

Example 51 with InstanceMetaData

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

the class HostMetadataSetup method setupNewHostMetadata.

public void setupNewHostMetadata(Long stackId, Collection<String> newAddresses) {
    try {
        transactionService.required(() -> {
            LOGGER.info("Extending host metadata: {}", newAddresses);
            Stack stack = stackService.getByIdWithListsInTransaction(stackId);
            Set<InstanceMetaData> newInstanceMetadata = instanceMetaDataService.getNotDeletedAndNotZombieInstanceMetadataByStackId(stackId).stream().filter(instanceMetaData -> newAddresses.contains(instanceMetaData.getPrivateIp())).collect(Collectors.toSet());
            updateWithHostData(stack, newInstanceMetadata);
            instanceMetaDataService.saveAll(newInstanceMetadata);
        });
    } catch (TransactionExecutionException e) {
        throw new CloudbreakRuntimeException(e.getCause());
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) Logger(org.slf4j.Logger) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) CloudbreakRuntimeException(com.sequenceiq.cloudbreak.service.CloudbreakRuntimeException) Set(java.util.Set) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) GatewayConfigService(com.sequenceiq.cloudbreak.service.GatewayConfigService) List(java.util.List) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Service(org.springframework.stereotype.Service) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) Map(java.util.Map) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) CloudbreakRuntimeException(com.sequenceiq.cloudbreak.service.CloudbreakRuntimeException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 52 with InstanceMetaData

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

the class MetadataSetupService method cleanupRequestedInstancesIfNotInList.

public void cleanupRequestedInstancesIfNotInList(Long stackId, Set<String> instanceGroups, Set<Long> privateIds) {
    LOGGER.info("Cleanup the requested instances if private id not in {}", privateIds);
    for (String instanceGroupName : instanceGroups) {
        Optional<InstanceGroup> instanceGroup = instanceGroupService.findOneByStackIdAndGroupName(stackId, instanceGroupName);
        instanceGroup.ifPresent(ig -> {
            List<InstanceMetaData> requestedInstanceMetaDatas = instanceMetaDataService.findAllByInstanceGroupAndInstanceStatus(ig, InstanceStatus.REQUESTED);
            LOGGER.info("Instances in requested state: {}", requestedInstanceMetaDatas);
            List<InstanceMetaData> removableInstanceMetaDatas = requestedInstanceMetaDatas.stream().filter(instanceMetaData -> !privateIds.contains(instanceMetaData.getPrivateId())).collect(Collectors.toList());
            LOGGER.info("Cleanup the following instances: {}", requestedInstanceMetaDatas);
            for (InstanceMetaData removableInstanceMetaData : removableInstanceMetaDatas) {
                removableInstanceMetaData.setTerminationDate(clock.getCurrentTimeMillis());
                removableInstanceMetaData.setInstanceStatus(InstanceStatus.TERMINATED);
            }
            instanceMetaDataService.saveAll(removableInstanceMetaDatas);
        });
    }
}
Also used : CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) LoggerFactory(org.slf4j.LoggerFactory) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException) InstanceGroupService(com.sequenceiq.cloudbreak.service.stack.InstanceGroupService) ImageService(com.sequenceiq.cloudbreak.service.image.ImageService) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) CloudbreakEventService(com.sequenceiq.cloudbreak.structuredevent.event.CloudbreakEventService) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) Map(java.util.Map) TargetGroupPersistenceService(com.sequenceiq.cloudbreak.service.stack.TargetGroupPersistenceService) UPDATE_FAILED(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.UPDATE_FAILED) LoadBalancerPersistenceService(com.sequenceiq.cloudbreak.service.stack.LoadBalancerPersistenceService) InstanceMetadataType(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceMetadataType) Collection(java.util.Collection) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) Set(java.util.Set) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Json(com.sequenceiq.cloudbreak.common.json.Json) List(java.util.List) STARTED(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus.STARTED) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) Optional(java.util.Optional) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) InstanceLifeCycle(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceLifeCycle) Clock(com.sequenceiq.cloudbreak.common.service.Clock) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) LoadBalancerConfigService(com.sequenceiq.cloudbreak.service.LoadBalancerConfigService) TargetGroup(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup) Image(com.sequenceiq.cloudbreak.cloud.model.Image) Function(java.util.function.Function) StackStatusService(com.sequenceiq.cloudbreak.service.stackstatus.StackStatusService) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) Inject(javax.inject.Inject) Service(org.springframework.stereotype.Service) LoadBalancerConfigConverter(com.sequenceiq.cloudbreak.service.LoadBalancerConfigConverter) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) TERMINATED(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus.TERMINATED) Logger(org.slf4j.Logger) CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) STACK_INSTANCE_METADATA_RESTORED(com.sequenceiq.cloudbreak.event.ResourceEvent.STACK_INSTANCE_METADATA_RESTORED) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) StackType(com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) StackIdView(com.sequenceiq.cloudbreak.domain.projection.StackIdView) CREATED(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus.CREATED) StringUtils(org.springframework.util.StringUtils) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)

Example 53 with InstanceMetaData

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

the class MountDisks method mountDisks.

private void mountDisks(Stack stack, Set<Node> nodesWithDiskData, Set<Node> allNodes) throws CloudbreakException {
    Cluster cluster = stack.getCluster();
    try {
        List<GatewayConfig> gatewayConfigs = gatewayConfigService.getAllGatewayConfigs(stack);
        ExitCriteriaModel exitCriteriaModel = clusterDeletionBasedModel(stack.getId(), cluster.getId());
        Map<String, Map<String, String>> mountInfo;
        if (isCbVersionPostOptimisation(stack)) {
            mountInfo = hostOrchestrator.formatAndMountDisksOnNodes(stack, gatewayConfigs, nodesWithDiskData, allNodes, exitCriteriaModel, stack.getPlatformVariant());
        } else {
            mountInfo = hostOrchestrator.formatAndMountDisksOnNodesLegacy(gatewayConfigs, nodesWithDiskData, allNodes, exitCriteriaModel, stack.getPlatformVariant());
        }
        mountInfo.forEach((hostname, value) -> {
            Optional<String> instanceIdOptional = stack.getInstanceMetaDataAsList().stream().filter(instanceMetaData -> hostname.equals(instanceMetaData.getDiscoveryFQDN())).filter(instanceMetaData -> InstanceStatus.CREATED.equals(instanceMetaData.getInstanceStatus())).map(InstanceMetaData::getInstanceId).findFirst();
            if (instanceIdOptional.isPresent()) {
                String uuids = value.getOrDefault("uuids", "");
                String fstab = value.getOrDefault("fstab", "");
                if (!StringUtils.isEmpty(uuids) && !StringUtils.isEmpty(fstab)) {
                    persistUuidAndFstab(stack, instanceIdOptional.get(), hostname, uuids, fstab);
                }
            }
        });
    } catch (CloudbreakOrchestratorFailedException e) {
        LOGGER.error("Failed to mount disks", e);
        throw new CloudbreakSecuritySetupException(e);
    }
}
Also used : ExitCriteriaModel(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) LoggerFactory(org.slf4j.LoggerFactory) ComponentConfigProviderService(com.sequenceiq.cloudbreak.service.ComponentConfigProviderService) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ResourceService(com.sequenceiq.cloudbreak.service.resource.ResourceService) Service(org.springframework.stereotype.Service) Map(java.util.Map) CloudbreakSecuritySetupException(com.sequenceiq.cloudbreak.core.CloudbreakSecuritySetupException) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) ClusterDeletionBasedExitCriteriaModel.clusterDeletionBasedModel(com.sequenceiq.cloudbreak.core.bootstrap.service.ClusterDeletionBasedExitCriteriaModel.clusterDeletionBasedModel) Logger(org.slf4j.Logger) CloudbreakDetails(com.sequenceiq.cloudbreak.cloud.model.CloudbreakDetails) ResourceAttributeUtil(com.sequenceiq.cloudbreak.cluster.util.ResourceAttributeUtil) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) Set(java.util.Set) ExitCriteriaModel(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel) VersionComparator(com.sequenceiq.cloudbreak.util.VersionComparator) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Collectors(java.util.stream.Collectors) GatewayConfigService(com.sequenceiq.cloudbreak.service.GatewayConfigService) List(java.util.List) StackUtil(com.sequenceiq.cloudbreak.util.StackUtil) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Optional(java.util.Optional) StringUtils.substringBefore(org.apache.commons.lang3.StringUtils.substringBefore) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) StringUtils(org.springframework.util.StringUtils) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) CloudbreakSecuritySetupException(com.sequenceiq.cloudbreak.core.CloudbreakSecuritySetupException) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Map(java.util.Map) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 54 with InstanceMetaData

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

the class StackOperationService method removeInstance.

public FlowIdentifier removeInstance(Stack stack, String instanceId, boolean forced) {
    InstanceMetaData metaData = updateNodeCountValidator.validateInstanceForDownscale(instanceId, stack);
    String instanceGroupName = metaData.getInstanceGroupName();
    int scalingAdjustment = -1;
    updateNodeCountValidator.validateServiceRoles(stack, instanceGroupName, scalingAdjustment);
    if (!forced) {
        updateNodeCountValidator.validateScalabilityOfInstanceGroup(stack, instanceGroupName, scalingAdjustment);
        updateNodeCountValidator.validateScalingAdjustment(instanceGroupName, scalingAdjustment, stack);
    }
    return flowManager.triggerStackRemoveInstance(stack.getId(), instanceGroupName, metaData.getPrivateId(), forced);
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)

Example 55 with InstanceMetaData

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

the class TerminationService method terminateMetaDataInstances.

private void terminateMetaDataInstances(Stack stack) {
    List<InstanceMetaData> instanceMetaDatas = new ArrayList<>();
    Set<InstanceMetaData> notDeletedInstanceMetadataSet = instanceMetaDataService.getNotDeletedInstanceMetadataByStackId(stack.getId());
    for (InstanceMetaData metaData : notDeletedInstanceMetadataSet) {
        metaData.setTerminationDate(clock.getCurrentTimeMillis());
        metaData.setInstanceStatus(InstanceStatus.TERMINATED);
        instanceMetaDatas.add(metaData);
    }
    instanceMetaDataService.saveAll(instanceMetaDatas);
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ArrayList(java.util.ArrayList)

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