Search in sources :

Example 1 with Backoff

use of org.springframework.retry.annotation.Backoff in project cwa-server by corona-warn-app.

the class S3ClientWrapper method getObjects.

@Override
@Retryable(value = SdkException.class, maxAttemptsExpression = "${services.distribution.objectstore.retry-attempts}", backoff = @Backoff(delayExpression = "${services.distribution.objectstore.retry-backoff}"))
public List<S3Object> getObjects(String bucket, String prefix) {
    logRetryStatus("object download");
    List<S3Object> allS3Objects = new ArrayList<>();
    String continuationToken = null;
    do {
        ListObjectsV2Request request = ListObjectsV2Request.builder().prefix(prefix).bucket(bucket).continuationToken(continuationToken).build();
        ListObjectsV2Response response = s3Client.listObjectsV2(request);
        response.contents().stream().map(s3Object -> buildS3Object(s3Object, bucket)).forEach(allS3Objects::add);
        continuationToken = TRUE.equals(response.isTruncated()) ? response.nextContinuationToken() : null;
    } while (continuationToken != null);
    return allS3Objects;
}
Also used : NotModifiedException(app.coronawarn.server.services.distribution.statistics.exceptions.NotModifiedException) LoggerFactory(org.slf4j.LoggerFactory) SdkException(software.amazon.awssdk.core.exception.SdkException) S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) Function(java.util.function.Function) ListObjectsV2Response(software.amazon.awssdk.services.s3.model.ListObjectsV2Response) GetObjectResponse(software.amazon.awssdk.services.s3.model.GetObjectResponse) ArrayList(java.util.ArrayList) DeleteObjectsResponse(software.amazon.awssdk.services.s3.model.DeleteObjectsResponse) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) GetObjectRequest(software.amazon.awssdk.services.s3.model.GetObjectRequest) PutObjectRequest(software.amazon.awssdk.services.s3.model.PutObjectRequest) ResponseInputStream(software.amazon.awssdk.core.ResponseInputStream) ObjectIdentifier(software.amazon.awssdk.services.s3.model.ObjectIdentifier) Retryable(org.springframework.retry.annotation.Retryable) Path(java.nio.file.Path) JsonFile(app.coronawarn.server.services.distribution.statistics.file.JsonFile) Logger(org.slf4j.Logger) Recover(org.springframework.retry.annotation.Recover) S3Client(software.amazon.awssdk.services.s3.S3Client) Collection(java.util.Collection) NoSuchBucketException(software.amazon.awssdk.services.s3.model.NoSuchBucketException) HeadObjectRequest(software.amazon.awssdk.services.s3.model.HeadObjectRequest) ListObjectsV2Request(software.amazon.awssdk.services.s3.model.ListObjectsV2Request) Collectors(java.util.stream.Collectors) Backoff(org.springframework.retry.annotation.Backoff) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) DeleteObjectsRequest(software.amazon.awssdk.services.s3.model.DeleteObjectsRequest) RetrySynchronizationManager(org.springframework.retry.support.RetrySynchronizationManager) RequestBody(software.amazon.awssdk.core.sync.RequestBody) Delete(software.amazon.awssdk.services.s3.model.Delete) TRUE(java.lang.Boolean.TRUE) ListObjectsV2Request(software.amazon.awssdk.services.s3.model.ListObjectsV2Request) ArrayList(java.util.ArrayList) ListObjectsV2Response(software.amazon.awssdk.services.s3.model.ListObjectsV2Response) Retryable(org.springframework.retry.annotation.Retryable)

Example 2 with Backoff

use of org.springframework.retry.annotation.Backoff in project cloudbreak by hortonworks.

the class AzureMetadataCollector method collect.

@Override
@Retryable(backoff = @Backoff(delay = 1000, multiplier = 2, maxDelay = 10000), maxAttempts = 5)
public List<CloudVmMetaDataStatus> collect(AuthenticatedContext authenticatedContext, List<CloudResource> resources, List<CloudInstance> vms, List<CloudInstance> knownInstances) {
    LOGGER.debug("Starting to collect vm metadata.");
    List<CloudVmMetaDataStatus> results = new ArrayList<>();
    String resourceGroup = azureUtils.getTemplateResource(resources).getName();
    AzureClient azureClient = authenticatedContext.getParameter(AzureClient.class);
    Map<String, InstanceTemplate> templateMap = getTemplateMap(vms, authenticatedContext);
    Map<String, VirtualMachine> virtualMachinesByName = azureVirtualMachineService.getVirtualMachinesByName(azureClient, resourceGroup, templateMap.keySet());
    azureVirtualMachineService.refreshInstanceViews(virtualMachinesByName);
    try {
        for (Entry<String, InstanceTemplate> instance : templateMap.entrySet()) {
            VirtualMachine vm = virtualMachinesByName.get(instance.getKey());
            // TODO: network interface is lazy, so we will fetch it for every instances
            if (vm != null) {
                NetworkInterface networkInterface = vm.getPrimaryNetworkInterface();
                String subnetId = networkInterface.primaryIPConfiguration().subnetName();
                Integer faultDomainCount = azureClient.getFaultDomainNumber(resourceGroup, vm.name());
                String publicIp = azureVmPublicIpProvider.getPublicIp(networkInterface);
                String instanceId = instance.getKey();
                String localityIndicator = Optional.ofNullable(faultDomainCount).map(domainCount -> getLocalityIndicator(domainCount, authenticatedContext.getCloudContext(), instance.getValue(), resourceGroup)).orElse(null);
                CloudInstanceMetaData md = new CloudInstanceMetaData(networkInterface.primaryPrivateIP(), publicIp, localityIndicator);
                InstanceTemplate template = templateMap.get(instanceId);
                if (template != null) {
                    Map<String, Object> params = new HashMap<>(1);
                    params.put(SUBNET_ID, subnetId);
                    params.put(CloudInstance.INSTANCE_NAME, vm.computerName());
                    CloudInstance cloudInstance = new CloudInstance(instanceId, template, null, subnetId, null, params);
                    CloudVmInstanceStatus status = new CloudVmInstanceStatus(cloudInstance, InstanceStatus.CREATED);
                    results.add(new CloudVmMetaDataStatus(status, md));
                }
            }
        }
    } catch (RuntimeException e) {
        LOGGER.debug("Failed to collect vm metadata due to an exception: ", e);
        throw new CloudConnectorException(e.getMessage(), e);
    }
    LOGGER.debug("Metadata collection finished with result {}", results);
    return results;
}
Also used : NetworkInterface(com.microsoft.azure.management.network.NetworkInterface) VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine) AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) AzureLoadBalancer(com.sequenceiq.cloudbreak.cloud.azure.loadbalancer.AzureLoadBalancer) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) ArrayList(java.util.ArrayList) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) Inject(javax.inject.Inject) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) SUBNET_ID(com.sequenceiq.cloudbreak.common.network.NetworkConstants.SUBNET_ID) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Service(org.springframework.stereotype.Service) Map(java.util.Map) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Retryable(org.springframework.retry.annotation.Retryable) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) InstanceStoreMetadata(com.sequenceiq.cloudbreak.cloud.model.InstanceStoreMetadata) Logger(org.slf4j.Logger) CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) MetadataCollector(com.sequenceiq.cloudbreak.cloud.MetadataCollector) Collectors(java.util.stream.Collectors) Backoff(org.springframework.retry.annotation.Backoff) List(java.util.List) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) Entry(java.util.Map.Entry) Optional(java.util.Optional) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) HashMap(java.util.HashMap) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) ArrayList(java.util.ArrayList) NetworkInterface(com.microsoft.azure.management.network.NetworkInterface) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) VirtualMachine(com.microsoft.azure.management.compute.VirtualMachine) Retryable(org.springframework.retry.annotation.Retryable)

Example 3 with Backoff

use of org.springframework.retry.annotation.Backoff in project cloudbreak by hortonworks.

the class CleanupService method revokeCerts.

@Retryable(value = RetryableFreeIpaClientException.class, maxAttemptsExpression = RetryableFreeIpaClientException.MAX_RETRIES_EXPRESSION, backoff = @Backoff(delayExpression = RetryableFreeIpaClientException.DELAY_EXPRESSION, multiplierExpression = RetryableFreeIpaClientException.MULTIPLIER_EXPRESSION))
public Pair<Set<String>, Map<String, String>> revokeCerts(Long stackId, Set<String> hosts) throws FreeIpaClientException {
    FreeIpaClient client = getFreeIpaClient(stackId);
    Set<String> certCleanupSuccess = new HashSet<>();
    Map<String, String> certCleanupFailed = new HashMap<>();
    Set<Cert> certs = client.findAllCert();
    certs.stream().filter(cert -> hosts.stream().anyMatch(host -> substringBefore(host, ".").equals(substringBefore(removeStart(cert.getSubject(), "CN="), ".")))).filter(cert -> !cert.isRevoked()).forEach(cert -> {
        try {
            client.revokeCert(cert.getSerialNumber());
            certCleanupSuccess.add(cert.getSubject());
        } catch (FreeIpaClientException e) {
            LOGGER.error("Couldn't revoke certificate: {}", cert, e);
            certCleanupFailed.put(cert.getSubject(), e.getMessage());
        }
    });
    return Pair.of(certCleanupSuccess, certCleanupFailed);
}
Also used : FreeIpaCleanupEvent(com.sequenceiq.freeipa.flow.freeipa.cleanup.FreeIpaCleanupEvent) DeleteException(com.sequenceiq.freeipa.kerberosmgmt.exception.DeleteException) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) OperationStatus(com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus) LdapConfigService(com.sequenceiq.freeipa.ldap.LdapConfigService) DnsZone(com.sequenceiq.freeipa.client.model.DnsZone) RetryableFreeIpaClientException(com.sequenceiq.freeipa.client.RetryableFreeIpaClientException) Operation(com.sequenceiq.freeipa.entity.Operation) Map(java.util.Map) Pair(org.springframework.data.util.Pair) StackService(com.sequenceiq.freeipa.service.stack.StackService) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) FreeIpaClientExceptionUtil(com.sequenceiq.freeipa.client.FreeIpaClientExceptionUtil) Set(java.util.Set) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) User(com.sequenceiq.freeipa.client.model.User) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) Collectors(java.util.stream.Collectors) Backoff(org.springframework.retry.annotation.Backoff) List(java.util.List) PollingService(com.sequenceiq.cloudbreak.polling.PollingService) KeytabCleanupService(com.sequenceiq.freeipa.kerberosmgmt.v1.KeytabCleanupService) Entry(java.util.Map.Entry) KerberosConfigService(com.sequenceiq.freeipa.kerberos.KerberosConfigService) Optional(java.util.Optional) HostRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.HostRequest) HashMap(java.util.HashMap) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) Service(org.springframework.stereotype.Service) OperationType(com.sequenceiq.freeipa.api.v1.operation.model.OperationType) CleanupEvent(com.sequenceiq.freeipa.flow.freeipa.cleanup.CleanupEvent) Retryable(org.springframework.retry.annotation.Retryable) Cert(com.sequenceiq.freeipa.client.model.Cert) Stack(com.sequenceiq.freeipa.entity.Stack) KeytabCacheService(com.sequenceiq.freeipa.kerberosmgmt.v1.KeytabCacheService) FreeIpaFlowManager(com.sequenceiq.freeipa.service.freeipa.flow.FreeIpaFlowManager) Logger(org.slf4j.Logger) DnsRecord(com.sequenceiq.freeipa.client.model.DnsRecord) OperationService(com.sequenceiq.freeipa.service.operation.OperationService) CleanupRequest(com.sequenceiq.freeipa.api.v1.freeipa.cleanup.CleanupRequest) Role(com.sequenceiq.freeipa.client.model.Role) FreeIpaClientFactory(com.sequenceiq.freeipa.service.freeipa.FreeIpaClientFactory) StringUtils.substringBefore(org.apache.commons.lang3.StringUtils.substringBefore) Collections(java.util.Collections) HostDeletionService(com.sequenceiq.freeipa.service.freeipa.host.HostDeletionService) StringUtils.removeStart(org.apache.commons.lang3.StringUtils.removeStart) OperationToOperationStatusConverter(com.sequenceiq.freeipa.converter.operation.OperationToOperationStatusConverter) HashMap(java.util.HashMap) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) RetryableFreeIpaClientException(com.sequenceiq.freeipa.client.RetryableFreeIpaClientException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Cert(com.sequenceiq.freeipa.client.model.Cert) HashSet(java.util.HashSet) Retryable(org.springframework.retry.annotation.Retryable)

Example 4 with Backoff

use of org.springframework.retry.annotation.Backoff in project cloudbreak by hortonworks.

the class SaltOrchestrator method tearDown.

@Retryable(backoff = @Backoff(delay = 1000, multiplier = 2, maxDelay = 10000), maxAttempts = 5)
@Override
public void tearDown(OrchestratorAware stack, List<GatewayConfig> allGatewayConfigs, Map<String, String> removeNodePrivateIPsByFQDN, Set<Node> remainingNodes, ExitCriteriaModel exitModel) throws CloudbreakOrchestratorException {
    LOGGER.debug("Tear down hosts: {},", removeNodePrivateIPsByFQDN);
    LOGGER.debug("Gateway config for tear down: {}", allGatewayConfigs);
    Set<String> remainingIps = remainingNodes.stream().map(Node::getPrivateIp).collect(Collectors.toSet());
    LOGGER.debug("Remaining IPs: {}", remainingIps);
    Set<String> minionsToStop = removeNodePrivateIPsByFQDN.values().stream().filter(not(remainingIps::contains)).collect(Collectors.toSet());
    LOGGER.debug("Minions to stop: {}", minionsToStop);
    GatewayConfig primaryGateway = saltService.getPrimaryGatewayConfig(allGatewayConfigs);
    Set<String> gatewayTargetIpAddresses = getGatewayPrivateIps(allGatewayConfigs);
    try (SaltConnector saltConnector = saltService.createSaltConnector(primaryGateway)) {
        SaltStates.stopMinions(saltConnector, minionsToStop);
        if (!CollectionUtils.isEmpty(remainingNodes)) {
            saveHostsPillar(stack, exitModel, gatewayTargetIpAddresses, saltConnector);
        }
    } catch (Exception e) {
        LOGGER.info("Error occurred during salt minion tear down", e);
        throw new CloudbreakOrchestratorFailedException(e.getMessage(), e);
    }
    List<GatewayConfig> liveGateways = allGatewayConfigs.stream().filter(gw -> remainingIps.contains(gw.getPrivateAddress())).collect(Collectors.toList());
    for (GatewayConfig gatewayConfig : liveGateways) {
        try (SaltConnector sc = saltService.createSaltConnector(gatewayConfig)) {
            sc.wheel("key.delete", removeNodePrivateIPsByFQDN.keySet(), Object.class);
            removeDeadSaltMinions(gatewayConfig);
        } catch (Exception e) {
            LOGGER.info("Error occurred during salt minion tear down", e);
            throw new CloudbreakOrchestratorFailedException(e.getMessage(), e);
        }
    }
}
Also used : GrainOperation(com.sequenceiq.cloudbreak.orchestrator.host.GrainOperation) FileReaderUtils.readFileFromClasspath(com.sequenceiq.cloudbreak.util.FileReaderUtils.readFileFromClasspath) SaltCommandRunner(com.sequenceiq.cloudbreak.orchestrator.salt.runner.SaltCommandRunner) Target(com.sequenceiq.cloudbreak.orchestrator.salt.client.target.Target) SaltBootstrap(com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltBootstrap) SaltJobIdTracker(com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltJobIdTracker) SyncAllRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.SyncAllRunner) LoggerFactory(org.slf4j.LoggerFactory) HostList(com.sequenceiq.cloudbreak.orchestrator.salt.client.target.HostList) SaltUploadWithPermission(com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltUploadWithPermission) HighStateRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.HighStateRunner) HighStateAllRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.HighStateAllRunner) StringUtils(org.apache.commons.lang3.StringUtils) PillarSave(com.sequenceiq.cloudbreak.orchestrator.salt.poller.PillarSave) BootstrapParams(com.sequenceiq.cloudbreak.orchestrator.model.BootstrapParams) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) HostAndRoleTarget(com.sequenceiq.cloudbreak.orchestrator.salt.client.target.HostAndRoleTarget) OrchestratorBootstrap(com.sequenceiq.cloudbreak.orchestrator.OrchestratorBootstrap) StateAllRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.StateAllRunner) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) CloudbreakOrchestratorTimeoutException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorTimeoutException) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) MineUpdateRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.MineUpdateRunner) ModifyGrainBase(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.ModifyGrainBase) SaltPillarProperties(com.sequenceiq.cloudbreak.orchestrator.model.SaltPillarProperties) Collection(java.util.Collection) Set(java.util.Set) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) Retry(com.sequenceiq.cloudbreak.service.Retry) RecipeExecutionPhase.convert(com.sequenceiq.cloudbreak.common.type.RecipeExecutionPhase.convert) Collectors(java.util.stream.Collectors) Backoff(org.springframework.retry.annotation.Backoff) TemporaryStorage(com.sequenceiq.cloudbreak.common.type.TemporaryStorage) GrainRemoveRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainRemoveRunner) StandardCharsets(java.nio.charset.StandardCharsets) Sets(com.google.common.collect.Sets) ParameterizedStateRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.ParameterizedStateRunner) SALT(com.sequenceiq.cloudbreak.common.type.OrchestratorConstants.SALT) List(java.util.List) MinionStatusSaltResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.MinionStatusSaltResponse) SaltStates(com.sequenceiq.cloudbreak.orchestrator.salt.states.SaltStates) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) CollectionUtils(org.springframework.util.CollectionUtils) Entry(java.util.Map.Entry) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Optional(java.util.Optional) NodeVolumes(com.sequenceiq.cloudbreak.common.orchestration.NodeVolumes) Predicate.not(java.util.function.Predicate.not) RecipeExecutionPhase(com.sequenceiq.cloudbreak.common.type.RecipeExecutionPhase) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) Joiner(com.google.common.base.Joiner) SaltUpload(com.sequenceiq.cloudbreak.orchestrator.salt.poller.SaltUpload) OrchestratorGrainRunnerParams(com.sequenceiq.cloudbreak.orchestrator.host.OrchestratorGrainRunnerParams) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) CompressUtil(com.sequenceiq.cloudbreak.util.CompressUtil) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) ArrayList(java.util.ArrayList) RecipeModel(com.sequenceiq.cloudbreak.orchestrator.model.RecipeModel) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) GrainAddRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.GrainAddRunner) OrchestratorStateRetryParams(com.sequenceiq.cloudbreak.orchestrator.host.OrchestratorStateRetryParams) CmAgentStopFlags(com.sequenceiq.cloudbreak.orchestrator.model.CmAgentStopFlags) KeytabModel(com.sequenceiq.cloudbreak.orchestrator.model.KeytabModel) OrchestratorStateParams(com.sequenceiq.cloudbreak.orchestrator.host.OrchestratorStateParams) Retryable(org.springframework.retry.annotation.Retryable) Glob(com.sequenceiq.cloudbreak.orchestrator.salt.client.target.Glob) ConcurrentParameterizedStateRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.ConcurrentParameterizedStateRunner) ExitCriteria(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteria) StateRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.checker.StateRunner) Logger(org.slf4j.Logger) PackageInfo(com.sequenceiq.cloudbreak.common.model.PackageInfo) OrchestratorAware(com.sequenceiq.cloudbreak.common.orchestration.OrchestratorAware) NodeReachabilityResult(com.sequenceiq.cloudbreak.orchestrator.model.NodeReachabilityResult) GrainUploader(com.sequenceiq.cloudbreak.orchestrator.salt.grain.GrainUploader) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) ExitCriteriaModel(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel) IOException(java.io.IOException) PRE_CLOUDERA_MANAGER_START(com.sequenceiq.cloudbreak.common.type.RecipeExecutionPhase.PRE_CLOUDERA_MANAGER_START) ExecutionException(java.util.concurrent.ExecutionException) GrainsJsonPropertyUtil(com.sequenceiq.cloudbreak.orchestrator.salt.utils.GrainsJsonPropertyUtil) HttpStatus(org.springframework.http.HttpStatus) Component(org.springframework.stereotype.Component) BaseSaltJobRunner(com.sequenceiq.cloudbreak.orchestrator.salt.poller.BaseSaltJobRunner) SaltRunner(com.sequenceiq.cloudbreak.orchestrator.salt.runner.SaltRunner) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Collections(java.util.Collections) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) SaltConfig(com.sequenceiq.cloudbreak.orchestrator.model.SaltConfig) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) SaltConnector(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltConnector) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) CloudbreakOrchestratorTimeoutException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorTimeoutException) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Retryable(org.springframework.retry.annotation.Retryable)

Example 5 with Backoff

use of org.springframework.retry.annotation.Backoff in project cloudbreak by hortonworks.

the class SaltConnector method members.

@Measure(SaltConnector.class)
@Retryable(value = ClusterProxyWebApplicationException.class, backoff = @Backoff(delay = 1000))
public Map<String, String> members(List<String> privateIps) throws CloudbreakOrchestratorFailedException {
    Map<String, List<String>> clients = singletonMap("clients", privateIps);
    Response response = postSignedJsonSaltRequest(BOOT_HOSTNAME_ENDPOINT, clients);
    GenericResponses responses = JaxRSUtil.response(response, GenericResponses.class);
    List<GenericResponse> failedResponses = responses.getResponses().stream().filter(genericResponse -> !ACCEPTED_STATUSES.contains(genericResponse.getStatusCode())).collect(Collectors.toList());
    if (!failedResponses.isEmpty()) {
        failedResponseErrorLog(failedResponses);
        String nodeErrors = failedResponses.stream().map(gr -> gr.getAddress() + ": " + gr.getErrorText()).collect(Collectors.joining(","));
        throw new CloudbreakOrchestratorFailedException("Hostname resolution failed for nodes: " + nodeErrors);
    }
    return responses.getResponses().stream().collect(Collectors.toMap(GenericResponse::getAddress, GenericResponse::getStatus));
}
Also used : GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) Response(javax.ws.rs.core.Response) FingerprintsResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.FingerprintsResponse) Arrays(java.util.Arrays) Target(com.sequenceiq.cloudbreak.orchestrator.salt.client.target.Target) LoggerFactory(org.slf4j.LoggerFactory) HttpStatus(org.apache.http.HttpStatus) JsonUtil(com.sequenceiq.cloudbreak.common.json.JsonUtil) Measure(com.sequenceiq.cloudbreak.aspect.Measure) MediaType(javax.ws.rs.core.MediaType) JaxRSUtil(com.sequenceiq.cloudbreak.util.JaxRSUtil) ByteArrayInputStream(java.io.ByteArrayInputStream) SaltErrorResolver(com.sequenceiq.cloudbreak.orchestrator.salt.SaltErrorResolver) Map(java.util.Map) SaltAction(com.sequenceiq.cloudbreak.orchestrator.salt.domain.SaltAction) GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) BOOT_HOSTNAME_ENDPOINT(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltEndpoint.BOOT_HOSTNAME_ENDPOINT) SetProxyTimeoutFeature(com.sequenceiq.cloudbreak.client.SetProxyTimeoutFeature) Collection(java.util.Collection) ClientTracingFeature(io.opentracing.contrib.jaxrs2.client.ClientTracingFeature) Invocation(javax.ws.rs.client.Invocation) Collectors(java.util.stream.Collectors) Entity(javax.ws.rs.client.Entity) Backoff(org.springframework.retry.annotation.Backoff) List(java.util.List) Response(javax.ws.rs.core.Response) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) StreamDataBodyPart(org.glassfish.jersey.media.multipart.file.StreamDataBodyPart) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Optional(java.util.Optional) MultiPart(org.glassfish.jersey.media.multipart.MultiPart) Form(javax.ws.rs.core.Form) Pillar(com.sequenceiq.cloudbreak.orchestrator.salt.domain.Pillar) Client(javax.ws.rs.client.Client) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) BOOT_FINGERPRINT_DISTRIBUTE(com.sequenceiq.cloudbreak.orchestrator.salt.client.SaltEndpoint.BOOT_FINGERPRINT_DISTRIBUTE) GenericResponses(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses) Collections.singletonMap(java.util.Collections.singletonMap) Retryable(org.springframework.retry.annotation.Retryable) AnonymizerUtil.anonymize(com.sequenceiq.cloudbreak.common.anonymizer.AnonymizerUtil.anonymize) FingerprintRequest(com.sequenceiq.cloudbreak.orchestrator.salt.domain.FingerprintRequest) Logger(org.slf4j.Logger) Tracer(io.opentracing.Tracer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) DisableProxyAuthFeature(com.sequenceiq.cloudbreak.client.DisableProxyAuthFeature) ClusterProxyWebApplicationException(com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyWebApplicationException) FingerprintsResponse(com.sequenceiq.cloudbreak.orchestrator.salt.domain.FingerprintsResponse) Closeable(java.io.Closeable) PkiUtil(com.sequenceiq.cloudbreak.certificate.PkiUtil) RestClientUtil(com.sequenceiq.cloudbreak.client.RestClientUtil) WebTarget(javax.ws.rs.client.WebTarget) HttpAuthenticationFeature(org.glassfish.jersey.client.authentication.HttpAuthenticationFeature) Collections(java.util.Collections) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) GenericResponse(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponse) List(java.util.List) GenericResponses(com.sequenceiq.cloudbreak.orchestrator.model.GenericResponses) Retryable(org.springframework.retry.annotation.Retryable) Measure(com.sequenceiq.cloudbreak.aspect.Measure)

Aggregations

Backoff (org.springframework.retry.annotation.Backoff)13 Retryable (org.springframework.retry.annotation.Retryable)11 List (java.util.List)10 Collectors (java.util.stream.Collectors)10 Logger (org.slf4j.Logger)9 LoggerFactory (org.slf4j.LoggerFactory)9 Map (java.util.Map)8 Optional (java.util.Optional)6 Set (java.util.Set)6 Inject (javax.inject.Inject)6 ArrayList (java.util.ArrayList)5 Collections (java.util.Collections)5 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 Service (org.springframework.stereotype.Service)5 Component (org.springframework.stereotype.Component)4 Collection (java.util.Collection)3 Entry (java.util.Map.Entry)3 Value (org.springframework.beans.factory.annotation.Value)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2