Search in sources :

Example 16 with Transaction

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

the class ConfigServiceLocator method updateConfigServices.

private synchronized void updateConfigServices() {
    String url = assembleMetaServiceUrl();
    HttpRequest request = new HttpRequest(url);
    int maxRetries = 2;
    Throwable exception = null;
    for (int i = 0; i < maxRetries; i++) {
        Transaction transaction = Tracer.newTransaction("Apollo.MetaService", "getConfigService");
        transaction.addData("Url", url);
        try {
            HttpResponse<List<ServiceDTO>> response = m_httpClient.doGet(request, m_responseType);
            transaction.setStatus(Transaction.SUCCESS);
            List<ServiceDTO> services = response.getBody();
            if (services == null || services.isEmpty()) {
                logConfigService("Empty response!");
                continue;
            }
            setConfigServices(services);
            return;
        } catch (Throwable ex) {
            Tracer.logEvent("ApolloConfigException", ExceptionUtil.getDetailMessage(ex));
            transaction.setStatus(ex);
            exception = ex;
        } finally {
            transaction.complete();
        }
        try {
            m_configUtil.getOnErrorRetryIntervalTimeUnit().sleep(m_configUtil.getOnErrorRetryInterval());
        } catch (InterruptedException ex) {
        // ignore
        }
    }
    throw new ApolloConfigException(String.format("Get config services failed from %s", url), exception);
}
Also used : HttpRequest(com.ctrip.framework.apollo.util.http.HttpRequest) Transaction(com.ctrip.framework.apollo.tracer.spi.Transaction) ServiceDTO(com.ctrip.framework.apollo.core.dto.ServiceDTO) List(java.util.List) ApolloConfigException(com.ctrip.framework.apollo.exceptions.ApolloConfigException)

Example 17 with Transaction

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

the class AccessKeyServiceWithCache method rebuildAccessKeyCache.

private void rebuildAccessKeyCache() {
    Transaction transaction = Tracer.newTransaction("Apollo.AccessKeyServiceWithCache", "rebuildCache");
    try {
        deleteAccessKeyCache();
        transaction.setStatus(Transaction.SUCCESS);
    } catch (Throwable ex) {
        transaction.setStatus(ex);
        logger.error("Rebuild cache failed", ex);
    } finally {
        transaction.complete();
    }
}
Also used : Transaction(com.ctrip.framework.apollo.tracer.spi.Transaction)

Example 18 with Transaction

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

the class ReleaseMessageScanner method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    databaseScanInterval = bizConfig.releaseMessageScanIntervalInMilli();
    maxIdScanned = loadLargestMessageId();
    executorService.scheduleWithFixedDelay(() -> {
        Transaction transaction = Tracer.newTransaction("Apollo.ReleaseMessageScanner", "scanMessage");
        try {
            scanMissingMessages();
            scanMessages();
            transaction.setStatus(Transaction.SUCCESS);
        } catch (Throwable ex) {
            transaction.setStatus(ex);
            logger.error("Scan and send message failed", ex);
        } finally {
            transaction.complete();
        }
    }, databaseScanInterval, databaseScanInterval, TimeUnit.MILLISECONDS);
}
Also used : Transaction(com.ctrip.framework.apollo.tracer.spi.Transaction)

Example 19 with Transaction

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

the class DatabaseMessageSender method sendMessage.

@Override
@Transactional
public void sendMessage(String message, String channel) {
    logger.info("Sending message {} to channel {}", message, channel);
    if (!Objects.equals(channel, Topics.APOLLO_RELEASE_TOPIC)) {
        logger.warn("Channel {} not supported by DatabaseMessageSender!", channel);
        return;
    }
    Tracer.logEvent("Apollo.AdminService.ReleaseMessage", message);
    Transaction transaction = Tracer.newTransaction("Apollo.AdminService", "sendMessage");
    try {
        ReleaseMessage newMessage = releaseMessageRepository.save(new ReleaseMessage(message));
        toClean.offer(newMessage.getId());
        transaction.setStatus(Transaction.SUCCESS);
    } catch (Throwable ex) {
        logger.error("Sending message to database failed", 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) Transactional(org.springframework.transaction.annotation.Transactional)

Example 20 with Transaction

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

the class LocalFileConfigRepository method sync.

@Override
protected void sync() {
    // sync with upstream immediately
    boolean syncFromUpstreamResultSuccess = trySyncFromUpstream();
    if (syncFromUpstreamResultSuccess) {
        return;
    }
    Transaction transaction = Tracer.newTransaction("Apollo.ConfigService", "syncLocalConfig");
    Throwable exception = null;
    try {
        transaction.addData("Basedir", m_baseDir.getAbsolutePath());
        m_fileProperties = this.loadFromLocalCacheFile(m_baseDir, m_namespace);
        m_sourceType = ConfigSourceType.LOCAL;
        transaction.setStatus(Transaction.SUCCESS);
    } catch (Throwable ex) {
        Tracer.logEvent("ApolloConfigException", ExceptionUtil.getDetailMessage(ex));
        transaction.setStatus(ex);
        exception = ex;
    // ignore
    } finally {
        transaction.complete();
    }
    if (m_fileProperties == null) {
        m_sourceType = ConfigSourceType.NONE;
        throw new ApolloConfigException("Load config from local config failed!", exception);
    }
}
Also used : Transaction(com.ctrip.framework.apollo.tracer.spi.Transaction) ApolloConfigException(com.ctrip.framework.apollo.exceptions.ApolloConfigException)

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