Search in sources :

Example 11 with Transaction

use of com.ctrip.framework.apollo.tracer.spi.Transaction in project apollo by ctripcorp.

the class ConfigServiceWithCache method initialize.

@PostConstruct
void initialize() {
    configCache = CacheBuilder.newBuilder().expireAfterAccess(DEFAULT_EXPIRED_AFTER_ACCESS_IN_MINUTES, TimeUnit.MINUTES).build(new CacheLoader<String, ConfigCacheEntry>() {

        @Override
        public ConfigCacheEntry load(String key) throws Exception {
            List<String> namespaceInfo = STRING_SPLITTER.splitToList(key);
            if (namespaceInfo.size() != 3) {
                Tracer.logError(new IllegalArgumentException(String.format("Invalid cache load key %s", key)));
                return nullConfigCacheEntry;
            }
            Transaction transaction = Tracer.newTransaction(TRACER_EVENT_CACHE_LOAD, key);
            try {
                ReleaseMessage latestReleaseMessage = releaseMessageService.findLatestReleaseMessageForMessages(Lists.newArrayList(key));
                Release latestRelease = releaseService.findLatestActiveRelease(namespaceInfo.get(0), namespaceInfo.get(1), namespaceInfo.get(2));
                transaction.setStatus(Transaction.SUCCESS);
                long notificationId = latestReleaseMessage == null ? ConfigConsts.NOTIFICATION_ID_PLACEHOLDER : latestReleaseMessage.getId();
                if (notificationId == ConfigConsts.NOTIFICATION_ID_PLACEHOLDER && latestRelease == null) {
                    return nullConfigCacheEntry;
                }
                return new ConfigCacheEntry(notificationId, latestRelease);
            } catch (Throwable ex) {
                transaction.setStatus(ex);
                throw ex;
            } finally {
                transaction.complete();
            }
        }
    });
    configIdCache = CacheBuilder.newBuilder().expireAfterAccess(DEFAULT_EXPIRED_AFTER_ACCESS_IN_MINUTES, TimeUnit.MINUTES).build(new CacheLoader<Long, Optional<Release>>() {

        @Override
        public Optional<Release> load(Long key) throws Exception {
            Transaction transaction = Tracer.newTransaction(TRACER_EVENT_CACHE_LOAD_ID, String.valueOf(key));
            try {
                Release release = releaseService.findActiveOne(key);
                transaction.setStatus(Transaction.SUCCESS);
                return Optional.ofNullable(release);
            } catch (Throwable ex) {
                transaction.setStatus(ex);
                throw ex;
            } finally {
                transaction.complete();
            }
        }
    });
}
Also used : Transaction(com.ctrip.framework.apollo.tracer.spi.Transaction) ReleaseMessage(com.ctrip.framework.apollo.biz.entity.ReleaseMessage) CacheLoader(com.google.common.cache.CacheLoader) Release(com.ctrip.framework.apollo.biz.entity.Release) PostConstruct(javax.annotation.PostConstruct)

Example 12 with Transaction

use of com.ctrip.framework.apollo.tracer.spi.Transaction in project apollo by ctripcorp.

the class AccessKeyServiceWithCache method scanNewAndUpdatedAccessKeys.

private void scanNewAndUpdatedAccessKeys() {
    Transaction transaction = Tracer.newTransaction("Apollo.AccessKeyServiceWithCache", "scanNewAndUpdatedAccessKeys");
    try {
        loadNewAndUpdatedAccessKeys();
        transaction.setStatus(Transaction.SUCCESS);
    } catch (Throwable ex) {
        transaction.setStatus(ex);
        logger.error("Load new/updated app access keys failed", ex);
    } finally {
        transaction.complete();
    }
}
Also used : Transaction(com.ctrip.framework.apollo.tracer.spi.Transaction)

Example 13 with Transaction

use of com.ctrip.framework.apollo.tracer.spi.Transaction in project apollo by ctripcorp.

the class ReleaseMessageServiceWithCache method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    populateDataBaseInterval();
    // block the startup process until load finished
    // this should happen before ReleaseMessageScanner due to autowire
    loadReleaseMessages(0);
    executorService.submit(() -> {
        while (doScan.get() && !Thread.currentThread().isInterrupted()) {
            Transaction transaction = Tracer.newTransaction("Apollo.ReleaseMessageServiceWithCache", "scanNewReleaseMessages");
            try {
                loadReleaseMessages(maxIdScanned);
                transaction.setStatus(Transaction.SUCCESS);
            } catch (Throwable ex) {
                transaction.setStatus(ex);
                logger.error("Scan new release messages failed", ex);
            } finally {
                transaction.complete();
            }
            try {
                scanIntervalTimeUnit.sleep(scanInterval);
            } catch (InterruptedException e) {
            // ignore
            }
        }
    });
}
Also used : Transaction(com.ctrip.framework.apollo.tracer.spi.Transaction)

Example 14 with Transaction

use of com.ctrip.framework.apollo.tracer.spi.Transaction in project apollo by ctripcorp.

the class RepositoryAspect method invokeWithCatTransaction.

@Around("anyRepositoryMethod()")
public Object invokeWithCatTransaction(ProceedingJoinPoint joinPoint) throws Throwable {
    String name = joinPoint.getSignature().getDeclaringType().getSimpleName() + "." + joinPoint.getSignature().getName();
    Transaction catTransaction = Tracer.newTransaction("SQL", name);
    try {
        Object result = joinPoint.proceed();
        catTransaction.setStatus(Transaction.SUCCESS);
        return result;
    } catch (Throwable ex) {
        catTransaction.setStatus(ex);
        throw ex;
    } finally {
        catTransaction.complete();
    }
}
Also used : Transaction(com.ctrip.framework.apollo.tracer.spi.Transaction) Around(org.aspectj.lang.annotation.Around)

Example 15 with Transaction

use of com.ctrip.framework.apollo.tracer.spi.Transaction in project apollo by ctripcorp.

the class RetryableRestTemplate method exchangeGet.

private <T> ResponseEntity<T> exchangeGet(Env env, String path, ParameterizedTypeReference<T> reference, Object... uriVariables) {
    if (path.startsWith("/")) {
        path = path.substring(1);
    }
    String uri = uriTemplateHandler.expand(path, uriVariables).getPath();
    Transaction ct = Tracer.newTransaction("AdminAPI", uri);
    ct.addData("Env", env);
    List<ServiceDTO> services = getAdminServices(env, ct);
    HttpEntity<Void> entity = new HttpEntity<>(assembleExtraHeaders(env));
    for (ServiceDTO serviceDTO : services) {
        try {
            ResponseEntity<T> result = restTemplate.exchange(parseHost(serviceDTO) + path, HttpMethod.GET, entity, reference, uriVariables);
            ct.setStatus(Transaction.SUCCESS);
            ct.complete();
            return result;
        } catch (Throwable t) {
            logger.error("Http request failed, uri: {}, method: {}", uri, HttpMethod.GET, t);
            Tracer.logError(t);
            if (canRetry(t, HttpMethod.GET)) {
                Tracer.logEvent(TracerEventType.API_RETRY, uri);
            } else {
                // biz exception rethrow
                ct.setStatus(t);
                ct.complete();
                throw t;
            }
        }
    }
    // all admin server down
    ServiceException e = new ServiceException(String.format("Admin servers are unresponsive. meta server address: %s, admin servers: %s", portalMetaDomainService.getDomain(env), services));
    ct.setStatus(e);
    ct.complete();
    throw e;
}
Also used : Transaction(com.ctrip.framework.apollo.tracer.spi.Transaction) HttpEntity(org.springframework.http.HttpEntity) ServiceException(com.ctrip.framework.apollo.common.exception.ServiceException) ServiceDTO(com.ctrip.framework.apollo.core.dto.ServiceDTO)

Aggregations

Transaction (com.ctrip.framework.apollo.tracer.spi.Transaction)26 ServiceDTO (com.ctrip.framework.apollo.core.dto.ServiceDTO)5 ApolloConfigException (com.ctrip.framework.apollo.exceptions.ApolloConfigException)5 HttpRequest (com.ctrip.framework.apollo.util.http.HttpRequest)3 List (java.util.List)3 ReleaseMessage (com.ctrip.framework.apollo.biz.entity.ReleaseMessage)2 ServiceException (com.ctrip.framework.apollo.common.exception.ServiceException)2 ApolloConfig (com.ctrip.framework.apollo.core.dto.ApolloConfig)2 NullTransaction (com.ctrip.framework.apollo.tracer.internals.NullTransaction)2 IOException (java.io.IOException)2 Test (org.junit.Test)2 ConfigChangeListener (com.ctrip.framework.apollo.ConfigChangeListener)1 ConfigFileChangeListener (com.ctrip.framework.apollo.ConfigFileChangeListener)1 Release (com.ctrip.framework.apollo.biz.entity.Release)1 ApolloConfigStatusCodeException (com.ctrip.framework.apollo.exceptions.ApolloConfigStatusCodeException)1 MessageProducer (com.ctrip.framework.apollo.tracer.spi.MessageProducer)1 HttpResponse (com.ctrip.framework.apollo.util.http.HttpResponse)1 CacheLoader (com.google.common.cache.CacheLoader)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1