use of org.springframework.retry.annotation.Retryable in project paascloud-master by paascloud.
the class OptQiniuOssServiceImpl method deleteFile.
@Override
@Retryable(value = Exception.class, backoff = @Backoff(delay = 5000, multiplier = 2))
public void deleteFile(String fileName, String bucketName) throws QiniuException {
log.info("deleteFile - 删除OSS文件. fileName={}, bucketName={}", fileName, bucketName);
Preconditions.checkArgument(StringUtils.isNotEmpty(fileName), ErrorCodeEnum.OPC10040010.msg());
Preconditions.checkArgument(StringUtils.isNotEmpty(bucketName), "存储空间不能为空");
Response response = bucketManager.delete(bucketName, fileName);
log.info("deleteFile - 删除OSS文件. [OK] response={}", response);
}
use of org.springframework.retry.annotation.Retryable in project spring-cloud-consul by spring-cloud.
the class ConsulPropertySourceLocator method locate.
@Override
@Retryable(interceptor = "consulRetryInterceptor")
public PropertySource<?> locate(Environment environment) {
if (environment instanceof ConfigurableEnvironment) {
ConfigurableEnvironment env = (ConfigurableEnvironment) environment;
String appName = properties.getName();
if (appName == null) {
appName = env.getProperty("spring.application.name");
}
List<String> profiles = Arrays.asList(env.getActiveProfiles());
String prefix = this.properties.getPrefix();
List<String> suffixes = new ArrayList<>();
if (this.properties.getFormat() != FILES) {
suffixes.add("/");
} else {
suffixes.add(".yml");
suffixes.add(".yaml");
suffixes.add(".properties");
}
String defaultContext = getContext(prefix, this.properties.getDefaultContext());
for (String suffix : suffixes) {
this.contexts.add(defaultContext + suffix);
}
for (String suffix : suffixes) {
addProfiles(this.contexts, defaultContext, profiles, suffix);
}
String baseContext = getContext(prefix, appName);
for (String suffix : suffixes) {
this.contexts.add(baseContext + suffix);
}
for (String suffix : suffixes) {
addProfiles(this.contexts, baseContext, profiles, suffix);
}
Collections.reverse(this.contexts);
CompositePropertySource composite = new CompositePropertySource("consul");
for (String propertySourceContext : this.contexts) {
try {
ConsulPropertySource propertySource = null;
if (this.properties.getFormat() == FILES) {
Response<GetValue> response = this.consul.getKVValue(propertySourceContext, this.properties.getAclToken());
addIndex(propertySourceContext, response.getConsulIndex());
if (response.getValue() != null) {
ConsulFilesPropertySource filesPropertySource = new ConsulFilesPropertySource(propertySourceContext, this.consul, this.properties);
filesPropertySource.init(response.getValue());
propertySource = filesPropertySource;
}
} else {
propertySource = create(propertySourceContext, contextIndex);
}
if (propertySource != null) {
composite.addPropertySource(propertySource);
}
} catch (Exception e) {
if (this.properties.isFailFast()) {
log.error("Fail fast is set and there was an error reading configuration from consul.");
ReflectionUtils.rethrowRuntimeException(e);
} else {
log.warn("Unable to load consul config from " + propertySourceContext, e);
}
}
}
return composite;
}
return null;
}
use of org.springframework.retry.annotation.Retryable in project spring-cloud-config by spring-cloud.
the class ConfigServicePropertySourceLocator method locate.
@Override
@Retryable(interceptor = "configServerRetryInterceptor")
public org.springframework.core.env.PropertySource<?> locate(org.springframework.core.env.Environment environment) {
ConfigClientProperties properties = this.defaultProperties.override(environment);
CompositePropertySource composite = new CompositePropertySource("configService");
RestTemplate restTemplate = this.restTemplate == null ? getSecureRestTemplate(properties) : this.restTemplate;
Exception error = null;
String errorBody = null;
logger.info("Fetching config from server at: " + properties.getRawUri());
try {
String[] labels = new String[] { "" };
if (StringUtils.hasText(properties.getLabel())) {
labels = StringUtils.commaDelimitedListToStringArray(properties.getLabel());
}
String state = ConfigClientStateHolder.getState();
// Try all the labels until one works
for (String label : labels) {
Environment result = getRemoteEnvironment(restTemplate, properties, label.trim(), state);
if (result != null) {
log(result);
if (result.getPropertySources() != null) {
// result.getPropertySources() can be null if using xml
for (PropertySource source : result.getPropertySources()) {
@SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) source.getSource();
composite.addPropertySource(new MapPropertySource(source.getName(), map));
}
}
if (StringUtils.hasText(result.getState()) || StringUtils.hasText(result.getVersion())) {
HashMap<String, Object> map = new HashMap<>();
putValue(map, "config.client.state", result.getState());
putValue(map, "config.client.version", result.getVersion());
composite.addFirstPropertySource(new MapPropertySource("configClient", map));
}
return composite;
}
}
} catch (HttpServerErrorException e) {
error = e;
if (MediaType.APPLICATION_JSON.includes(e.getResponseHeaders().getContentType())) {
errorBody = e.getResponseBodyAsString();
}
} catch (Exception e) {
error = e;
}
if (properties.isFailFast()) {
throw new IllegalStateException("Could not locate PropertySource and the fail fast property is set, failing", error);
}
logger.warn("Could not locate PropertySource: " + (errorBody == null ? error == null ? "label not found" : error.getMessage() : errorBody));
return null;
}
use of org.springframework.retry.annotation.Retryable in project herd by FINRAOS.
the class CredStashHelper method getCredentialFromCredStash.
/**
* Gets a password from the credstash.
*
* @param credStashEncryptionContext the encryption context
* @param credentialName the credential name
*
* @return the password
* @throws CredStashGetCredentialFailedException if CredStash fails to get a credential
*/
@Retryable(maxAttempts = 3, value = CredStashGetCredentialFailedException.class, backoff = @Backoff(delay = 5000, multiplier = 2))
public String getCredentialFromCredStash(String credStashEncryptionContext, String credentialName) throws CredStashGetCredentialFailedException {
// Get the credstash table name and credential names for the keystore and truststore.
String credStashAwsRegion = configurationHelper.getProperty(ConfigurationValue.CREDSTASH_AWS_REGION_NAME);
String credStashTableName = configurationHelper.getProperty(ConfigurationValue.CREDSTASH_TABLE_NAME);
// Log configuration values and input parameters.
LOGGER.info("credStashAwsRegion={} credStashTableName={} credStashEncryptionContext={} credentialName={}", credStashAwsRegion, credStashTableName, credStashEncryptionContext, credentialName);
// Get the AWS client configuration.
ClientConfiguration clientConfiguration = awsHelper.getClientConfiguration(awsHelper.getAwsParamsDto());
// Get the keystore and truststore passwords from Credstash.
CredStash credstash = credStashFactory.getCredStash(credStashAwsRegion, credStashTableName, clientConfiguration);
// Try to obtain the credentials from cred stash.
String password = null;
String errorMessage = null;
try {
// Convert the JSON config file version of the encryption context to a Java Map class.
@SuppressWarnings("unchecked") Map<String, String> credstashEncryptionContextMap = jsonHelper.unmarshallJsonToObject(Map.class, credStashEncryptionContext);
// Get the keystore and truststore passwords from credstash.
password = credstash.getCredential(credentialName, credstashEncryptionContextMap);
} catch (Exception exception) {
LOGGER.error("Caught exception when attempting to get a credential value from CredStash.", exception);
errorMessage = exception.getMessage();
}
// as credentials from cred stash, then throw a CredStashGetCredentialFailedException.
if (StringUtils.isEmpty(password)) {
throw new CredStashGetCredentialFailedException(String.format("Failed to obtain the keystore or truststore credential from credstash.%s " + "credStashAwsRegion=%s credStashTableName=%s credStashEncryptionContext=%s credentialName=%s", StringUtils.isNotBlank(errorMessage) ? " Reason: " + errorMessage : "", credStashAwsRegion, credStashTableName, credStashEncryptionContext, credentialName));
}
// Return the keystore and truststore passwords in a map.
return password;
}
use of org.springframework.retry.annotation.Retryable in project cas by apereo.
the class AccepttoMultifactorValidateUserDeviceRegistrationAction method verifyUserDeviceIsPaired.
/**
* Verify user device is paired.
*
* @return true/false
*/
@Retryable(value = AccepttoUserDeviceRegistrationException.class, maxAttempts = 2, backoff = @Backoff(delay = 1000, maxDelay = 3000))
public boolean verifyUserDeviceIsPaired() {
val acceptto = casProperties.getAuthn().getMfa().getAcceptto();
val authentication = WebUtils.getInProgressAuthentication();
if (!AccepttoApiUtils.isUserDevicePaired(authentication, acceptto)) {
val email = AccepttoApiUtils.getUserEmail(authentication, acceptto);
throw new AccepttoUserDeviceRegistrationException("Could not locate registered device for " + email);
}
return true;
}
Aggregations