Search in sources :

Example 1 with CloudbreakRuntimeException

use of com.sequenceiq.cloudbreak.service.CloudbreakRuntimeException in project cloudbreak by hortonworks.

the class HostMetadataSetup method updateWithHostData.

private void updateWithHostData(Stack stack, Collection<InstanceMetaData> metadataToUpdate) {
    try {
        LOGGER.info("Update metadatas: {}", metadataToUpdate);
        List<String> privateIps = metadataToUpdate.stream().filter(instanceMetaData -> InstanceStatus.CREATED.equals(instanceMetaData.getInstanceStatus())).map(InstanceMetaData::getPrivateIp).collect(Collectors.toList());
        if (!privateIps.isEmpty()) {
            GatewayConfig gatewayConfig = gatewayConfigService.getPrimaryGatewayConfig(stack);
            Map<String, String> members = hostOrchestrator.getMembers(gatewayConfig, privateIps);
            LOGGER.info("Received host names from hosts: {}, original targets: {}", members.values(), privateIps);
            for (InstanceMetaData instanceMetaData : metadataToUpdate) {
                String privateIp = instanceMetaData.getPrivateIp();
                String fqdnFromTheCluster = members.get(privateIp);
                String discoveryFQDN = instanceMetaData.getDiscoveryFQDN();
                if (Strings.isNullOrEmpty(discoveryFQDN) || !discoveryFQDN.equals(fqdnFromTheCluster)) {
                    instanceMetaData.setDiscoveryFQDN(fqdnFromTheCluster);
                    LOGGER.info("Discovery FQDN has been updated for instance: {} original: {}, fqdn: {}", instanceMetaData.getInstanceId(), fqdnFromTheCluster, discoveryFQDN);
                } else {
                    LOGGER.debug("There is no need to update the FQDN for node, private ip: '{}' with FQDN: '{}'", privateIp, discoveryFQDN);
                }
            }
        } else {
            LOGGER.info("There is no hosts to update");
        }
    } catch (Exception e) {
        throw new CloudbreakRuntimeException(e);
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CloudbreakRuntimeException(com.sequenceiq.cloudbreak.service.CloudbreakRuntimeException) CloudbreakRuntimeException(com.sequenceiq.cloudbreak.service.CloudbreakRuntimeException) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 2 with CloudbreakRuntimeException

use of com.sequenceiq.cloudbreak.service.CloudbreakRuntimeException 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 3 with CloudbreakRuntimeException

use of com.sequenceiq.cloudbreak.service.CloudbreakRuntimeException in project cloudbreak by hortonworks.

the class MeteringAzureMetadataPatchService method isAffected.

@Override
public boolean isAffected(Stack stack) {
    try {
        boolean affected = false;
        if (StackType.WORKLOAD.equals(stack.getType()) && CloudPlatform.AZURE.equalsIgnoreCase(stack.getCloudPlatform())) {
            try {
                final Long dateBeforeTimestamp = dateStringToTimestampForImage(meteringAzureMetadataPatchConfig.getDateBefore());
                Optional<StatedImage> statedImageOpt = stackImageService.getStatedImageInternal(stack);
                if (statedImageOpt.isEmpty() || statedImageOpt.get().getImage() == null || statedImageOpt.get().getImage().getCreated() < dateBeforeTimestamp) {
                    affected = true;
                }
            } catch (Exception e) {
                String errorMessage = String.format("Cannot determine stack with crn %s is affected by azure metadata issue", stack.getResourceCrn());
                LOGGER.debug(errorMessage, e);
                throw new ExistingStackPatchApplyException(errorMessage, e);
            }
        }
        return affected;
    } catch (Exception e) {
        LOGGER.warn("Error during obtaining image / catalog for stack " + stack.getResourceCrn(), e);
        throw new CloudbreakRuntimeException("Error during obtaining image / catalog for stack " + stack.getResourceCrn(), e);
    }
}
Also used : CloudbreakRuntimeException(com.sequenceiq.cloudbreak.service.CloudbreakRuntimeException) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) CloudbreakRuntimeException(com.sequenceiq.cloudbreak.service.CloudbreakRuntimeException) IOException(java.io.IOException) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)

Example 4 with CloudbreakRuntimeException

use of com.sequenceiq.cloudbreak.service.CloudbreakRuntimeException in project cloudbreak by hortonworks.

the class StackDownscaleService method startStackDownscale.

public void startStackDownscale(StackScalingFlowContext context, StackDownscaleTriggerEvent stackDownscaleTriggerEvent) {
    LOGGER.debug("Downscaling of stack {}", context.getStack().getId());
    stackUpdater.updateStackStatus(context.getStack().getId(), DetailedStackStatus.DOWNSCALE_IN_PROGRESS);
    Set<Long> privateIds = null;
    if (stackDownscaleTriggerEvent.getHostGroupsWithPrivateIds() != null) {
        privateIds = stackDownscaleTriggerEvent.getHostGroupsWithPrivateIds().values().stream().flatMap(Collection::stream).collect(Collectors.toSet());
    }
    String msgParam;
    if (CollectionUtils.isNotEmpty(privateIds)) {
        Stack stack = stackService.getByIdWithListsInTransaction(context.getStack().getId());
        List<String> instanceIdList = stackService.getInstanceIdsForPrivateIds(stack.getInstanceMetaDataAsList(), privateIds);
        msgParam = String.join(",", instanceIdList);
    } else if (stackDownscaleTriggerEvent.getHostGroupsWithAdjustment() != null) {
        Integer adjustmentSize = stackDownscaleTriggerEvent.getHostGroupsWithAdjustment().values().stream().reduce(0, Integer::sum);
        msgParam = String.valueOf(adjustmentSize);
    } else {
        throw new CloudbreakRuntimeException("No adjustment was defined");
    }
    flowMessageService.fireEventAndLog(context.getStack().getId(), UPDATE_IN_PROGRESS.name(), STACK_DOWNSCALE_INSTANCES, msgParam);
}
Also used : CloudbreakRuntimeException(com.sequenceiq.cloudbreak.service.CloudbreakRuntimeException) Collection(java.util.Collection) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 5 with CloudbreakRuntimeException

use of com.sequenceiq.cloudbreak.service.CloudbreakRuntimeException in project cloudbreak by hortonworks.

the class UnboundRestartPatchService method isAffected.

@Override
public boolean isAffected(Stack stack) {
    try {
        boolean affected = false;
        if (AFFECTED_STACK_VERSION.equals(stack.getStackVersion())) {
            Image image = stackImageService.getCurrentImage(stack);
            affected = AFFECTED_IMAGE_IDS.contains(image.getImageId());
            LOGGER.debug("Stack {} with version {} and image {} is {} by unbound service restart bug", stack.getResourceCrn(), stack.getStackVersion(), image.getImageId(), affected ? "affected" : "not affected");
        } else {
            LOGGER.debug("Stack {} with version {} is not affected by unbound service restart bug", stack.getResourceCrn(), stack.getStackVersion());
        }
        return affected;
    } catch (CloudbreakImageNotFoundException e) {
        LOGGER.warn("Image not found for stack " + stack.getResourceCrn(), e);
        throw new CloudbreakRuntimeException("Image not found for stack " + stack.getResourceCrn(), e);
    }
}
Also used : CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) CloudbreakRuntimeException(com.sequenceiq.cloudbreak.service.CloudbreakRuntimeException) Image(com.sequenceiq.cloudbreak.cloud.model.Image)

Aggregations

CloudbreakRuntimeException (com.sequenceiq.cloudbreak.service.CloudbreakRuntimeException)10 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)4 Image (com.sequenceiq.cloudbreak.cloud.model.Image)3 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)3 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)3 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)3 TransactionService (com.sequenceiq.cloudbreak.common.service.TransactionService)2 StatedImage (com.sequenceiq.cloudbreak.service.image.StatedImage)2 Collection (java.util.Collection)2 Strings (com.google.common.base.Strings)1 InstanceStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus)1 CloudbreakImageCatalogV3 (com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3)1 Node (com.sequenceiq.cloudbreak.common.orchestration.Node)1 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)1 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)1 StackView (com.sequenceiq.cloudbreak.domain.view.StackView)1 CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)1 HostOrchestrator (com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator)1 SaltConfig (com.sequenceiq.cloudbreak.orchestrator.model.SaltConfig)1 ExitCriteriaModel (com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel)1