use of org.springframework.retry.annotation.Retryable in project spring-cloud-config by spring-cloud.
the class ConfigServerInstanceProvider method getConfigServerInstance.
@Retryable(interceptor = "configServerRetryInterceptor")
public ServiceInstance getConfigServerInstance(String serviceId) {
logger.debug("Locating configserver (" + serviceId + ") via discovery");
List<ServiceInstance> instances = this.client.getInstances(serviceId);
if (instances.isEmpty()) {
throw new IllegalStateException("No instances found of configserver (" + serviceId + ")");
}
ServiceInstance instance = instances.get(0);
logger.debug("Located configserver (" + serviceId + ") via discovery: " + instance);
return instance;
}
use of org.springframework.retry.annotation.Retryable in project cloudbreak by hortonworks.
the class AzureRoleManager method assignRole.
@Retryable(value = InteractiveLoginException.class, maxAttempts = 15, backoff = @Backoff(delay = 1000))
public void assignRole(String accessToken, String subscriptionId, String roleDefinitionId, String principalObjectId) throws InteractiveLoginException {
Client client = ClientBuilder.newClient();
WebTarget resource = client.target(AZURE_MANAGEMENT);
Builder request = resource.path("subscriptions/" + subscriptionId + "/providers/Microsoft.Authorization/roleAssignments/" + UUID.randomUUID()).queryParam("api-version", "2015-07-01").request();
request.accept(MediaType.APPLICATION_JSON);
request.header("Authorization", "Bearer " + accessToken);
JsonObject properties = new JsonObject();
properties.addProperty("roleDefinitionId", roleDefinitionId);
properties.addProperty("principalId", principalObjectId);
JsonObject jsonObject = new JsonObject();
jsonObject.add("properties", properties);
Response response = request.put(Entity.entity(jsonObject.toString(), MediaType.APPLICATION_JSON));
if (response.getStatusInfo().getFamily() != Family.SUCCESSFUL) {
String errorResponse = response.readEntity(String.class);
LOGGER.error("Assign role request error - status code: {} - error message: {}", response.getStatus(), errorResponse);
if (response.getStatusInfo().getStatusCode() == Status.FORBIDDEN.getStatusCode()) {
throw new InteractiveLoginException("You don't have enough permissions to assign roles, please contact with your administrator");
} else {
try {
String errorMessage = new ObjectMapper().readTree(errorResponse).get("error").get("message").asText();
throw new InteractiveLoginException("Failed to assing role: " + errorMessage);
} catch (IOException e) {
throw new InteractiveLoginException("Failed to assing role (status " + response.getStatus() + "): " + errorResponse);
}
}
} else {
LOGGER.info("Role assigned successfully. subscriptionId '{}', roleDefinitionId {}, principalObjectId {}", subscriptionId, roleDefinitionId, principalObjectId);
}
}
use of org.springframework.retry.annotation.Retryable in project cloudbreak by hortonworks.
the class PrincipalCreator method createServicePrincipal.
@Retryable(value = InteractiveLoginException.class, maxAttempts = 15, backoff = @Backoff(delay = 1000))
public ServicePrincipalInner createServicePrincipal(String accessToken, String appId, String tenantId) throws InteractiveLoginException {
Response response = createServicePrincipalWithGraph(accessToken, appId, tenantId);
if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
String principal = response.readEntity(String.class);
try {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
ServicePrincipalInner sp = objectMapper.readValue(principal, ServicePrincipalInner.class);
String objectId = sp.objectId();
LOGGER.info("Service principal created with objectId: " + objectId);
return sp;
} catch (IOException e) {
throw new IllegalStateException(e);
}
} else {
String errorResponse = response.readEntity(String.class);
LOGGER.error("create service principal failed: " + errorResponse);
try {
String errorMessage = new ObjectMapper().readTree(errorResponse).get("odata.error").get("message").get("value").asText();
throw new InteractiveLoginException("Service principal creation error: " + errorMessage);
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
}
use of org.springframework.retry.annotation.Retryable in project cas by apereo.
the class SamlIdPMetadataResolver method resolve.
@Override
@Retryable(value = ResolverException.class, maxAttempts = 3, backoff = @Backoff(delay = 1000, maxDelay = 5000))
public Iterable<EntityDescriptor> resolve(final CriteriaSet criteria) throws ResolverException {
val filteringCriteria = determineFilteringCriteria(criteria);
for (val filter : filteringCriteria) {
val cacheKey = getMetadataCacheKey(filter, criteria);
LOGGER.debug("Cache key for SAML IdP metadata is [{}]", cacheKey);
var entities = metadataCache.getIfPresent(cacheKey);
if (entities != null) {
return entities;
}
entities = resolveMetadata(criteria, filter);
if (entities != null && Iterables.size(entities) > 0) {
metadataCache.put(cacheKey, entities);
return entities;
}
}
return new ArrayList<>(0);
}
use of org.springframework.retry.annotation.Retryable in project xm-ms-entity by xm-online.
the class SystemQueueConsumer method consumeEvent.
/**
* Consume system event message.
*
* @param message the system event message
*/
@Retryable(maxAttemptsExpression = "${application.retry.max-attempts}", backoff = @Backoff(delayExpression = "${application.retry.delay}", multiplierExpression = "${application.retry.multiplier}"))
public void consumeEvent(ConsumerRecord<String, String> message) {
MdcUtils.putRid();
try {
log.info("Consume event from topic [{}]", message.topic());
ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.registerModule(new JavaTimeModule());
try {
SystemEvent event = mapper.readValue(message.value(), SystemEvent.class);
log.info("Process event from topic [{}], {}", message.topic(), event);
if (StringUtils.isBlank(event.getTenantKey())) {
log.info("Event ignored due to tenantKey is empty {}", event);
return;
}
init(event.getTenantKey(), event.getUserLogin());
systemConsumerService.acceptSystemEvent(event);
} catch (IOException e) {
log.error("System queue message has incorrect format: '{}'", message.value(), e);
}
} finally {
destroy();
}
}
Aggregations