コード例 #1
0
        private async Task CheckLocalConfig(string agentName, CacheData cacheData)
        {
            string dataId = cacheData.DataId;
            string group  = cacheData.Group;
            string tenant = cacheData.Tenant;

            var path = FileLocalConfigInfoProcessor.GetFailoverFile(agentName, dataId, group, tenant);

            if (!cacheData.IsUseLocalConfig && path.Exists)
            {
                string content = await FileLocalConfigInfoProcessor.GetFailoverAsync(agentName, dataId, group, tenant);

                string md5 = HashUtil.GetMd5(content);
                cacheData.SetUseLocalConfigInfo(true);
                cacheData.SetLocalConfigInfoVersion(path.LastWriteTimeUtc.ToTimestamp());
                cacheData.SetContent(content);

                _logger?.LogWarning(
                    "[{0}] [failover-change] failover file created. dataId={1}, group={2}, tenant={3}, md5={4}, content={5}",
                    agentName, dataId, group, tenant, md5, ContentUtils.TruncateContent(content));

                return;
            }

            // If use local config info, then it doesn't notify business listener and notify after getting from server.
            if (cacheData.IsUseLocalConfig && !path.Exists)
            {
                cacheData.SetUseLocalConfigInfo(false);

                _logger?.LogWarning(
                    "[{0}] [failover-change] failover file deleted. dataId={1}, group={2}, tenant={3}",
                    agentName, dataId, group, tenant);
                return;
            }

            // When it changed.
            if (cacheData.IsUseLocalConfig &&
                path.Exists &&
                cacheData.GetLocalConfigInfoVersion() != path.LastWriteTimeUtc.ToTimestamp())
            {
                string content = await FileLocalConfigInfoProcessor.GetFailoverAsync(agentName, dataId, group, tenant);

                string md5 = HashUtil.GetMd5(content);
                cacheData.SetUseLocalConfigInfo(true);
                cacheData.SetLocalConfigInfoVersion(path.LastWriteTimeUtc.ToTimestamp());
                cacheData.SetContent(content);

                _logger?.LogWarning(
                    "[{0}] [failover-change] failover file created. dataId={1}, group={2}, tenant={3}, md5={4}, content={5}",
                    agentName, dataId, group, tenant, md5, ContentUtils.TruncateContent(content));
            }
        }
コード例 #2
0
        internal async Task AddTenantListenersWithContent(string dataId, string group, string content, List <IListener> listeners)
        {
            group = ParamUtils.Null2DefaultGroup(group);
            string    tenant = _agent.GetTenant();
            CacheData cache  = AddCacheDataIfAbsent(dataId, group, tenant);

            cache.SetContent(content);
            foreach (var listener in listeners)
            {
                cache.AddListener(listener);
            }

            // if current cache is already at listening status,do not notify.
            if (!cache.IsListenSuccess)
            {
                await _agent.NotifyListenConfigAsync();
            }
        }
コード例 #3
0
        private async Task RefreshContentAndCheck(CacheData cacheData, bool notify)
        {
            try
            {
                var ct = await GetServerConfig(cacheData.DataId, cacheData.Group, cacheData.Tenant, 3000L, notify);

                cacheData.SetContent(ct[0]);
                if (ct.Count > 1 && ct[1] != null)
                {
                    cacheData.Type = ct[1];
                }

                cacheData.CheckListenerMd5();
            }
            catch (Exception ex)
            {
                _logger?.LogError(ex, "refresh content and check md5 fail ,dataid={0},group={1},tenant={2} ", cacheData.DataId, cacheData.Group, cacheData.Tenant);
            }
        }
コード例 #4
0
        private async Task RefreshContentAndCheck(CacheData cacheData, bool notify)
        {
            try
            {
                var resp = await GetServerConfig(cacheData.DataId, cacheData.Group, cacheData.Tenant, 3000L, notify).ConfigureAwait(false);

                cacheData.SetContent(resp.GetContent());

                if (resp.GetConfigType().IsNotNullOrWhiteSpace())
                {
                    cacheData.Type = resp.GetConfigType();
                }

                cacheData.CheckListenerMd5();
            }
            catch (Exception ex)
            {
                _logger?.LogError(ex, "refresh content and check md5 fail ,dataid={0},group={1},tenant={2} ", cacheData.DataId, cacheData.Group, cacheData.Tenant);
            }
        }