Search in sources :

Example 1 with Retryable

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;
}
Also used : ServiceInstance(org.springframework.cloud.client.ServiceInstance) Retryable(org.springframework.retry.annotation.Retryable)

Example 2 with Retryable

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);
    }
}
Also used : AzureRoleDefinitionListResponse(com.sequenceiq.cloudbreak.cloud.azure.AzureRoleDefinitionListResponse) Response(javax.ws.rs.core.Response) ClientBuilder(javax.ws.rs.client.ClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) JsonObject(com.google.gson.JsonObject) WebTarget(javax.ws.rs.client.WebTarget) IOException(java.io.IOException) Client(javax.ws.rs.client.Client) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Retryable(org.springframework.retry.annotation.Retryable)

Example 3 with Retryable

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);
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) ServicePrincipalInner(com.microsoft.azure.management.graphrbac.implementation.ServicePrincipalInner) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Retryable(org.springframework.retry.annotation.Retryable)

Example 4 with Retryable

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);
}
Also used : lombok.val(lombok.val) ArrayList(java.util.ArrayList) Retryable(org.springframework.retry.annotation.Retryable)

Example 5 with Retryable

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();
    }
}
Also used : SystemEvent(com.icthh.xm.ms.entity.domain.kafka.SystemEvent) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Retryable(org.springframework.retry.annotation.Retryable)

Aggregations

Retryable (org.springframework.retry.annotation.Retryable)10 IOException (java.io.IOException)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ArrayList (java.util.ArrayList)2 Response (javax.ws.rs.core.Response)2 lombok.val (lombok.val)2 CompositePropertySource (org.springframework.core.env.CompositePropertySource)2 ClientConfiguration (com.amazonaws.ClientConfiguration)1 GetValue (com.ecwid.consul.v1.kv.model.GetValue)1 JavaTimeModule (com.fasterxml.jackson.datatype.jsr310.JavaTimeModule)1 JsonObject (com.google.gson.JsonObject)1 SystemEvent (com.icthh.xm.ms.entity.domain.kafka.SystemEvent)1 ServicePrincipalInner (com.microsoft.azure.management.graphrbac.implementation.ServicePrincipalInner)1 Response (com.qiniu.http.Response)1 AzureRoleDefinitionListResponse (com.sequenceiq.cloudbreak.cloud.azure.AzureRoleDefinitionListResponse)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Client (javax.ws.rs.client.Client)1 ClientBuilder (javax.ws.rs.client.ClientBuilder)1 Builder (javax.ws.rs.client.Invocation.Builder)1