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;
}
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;
}
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);
}
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);
}
}
}
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));
}
Aggregations