protected override async Task <ConfigResponse> QueryConfig(string dataId, string group, string tenant, long readTimeous, bool notify) { try { var request = new ConfigQueryRequest(dataId, group, tenant); request.PutHeader("notify", notify.ToString()); var response = (ConfigQueryResponse) await RequestProxy(GetOneRunningClient(), request).ConfigureAwait(false); ConfigResponse configResponse = new ConfigResponse(); if (response.IsSuccess()) { await FileLocalConfigInfoProcessor.SaveSnapshotAsync(this.GetName(), dataId, group, tenant, response.Content).ConfigureAwait(false); configResponse.SetContent(response.Content); configResponse.SetConfigType(response.ContentType.IsNotNullOrWhiteSpace() ? response.ContentType : "text"); string encryptedDataKey = response.EncryptedDataKey; await FileLocalConfigInfoProcessor.SaveEncryptDataKeySnapshot(this.GetName(), dataId, group, tenant, encryptedDataKey).ConfigureAwait(false); configResponse.SetEncryptedDataKey(encryptedDataKey); return(configResponse); } else if (response.ErrorCode.Equals(ConfigQueryResponse.CONFIG_NOT_FOUND)) { await FileLocalConfigInfoProcessor.SaveSnapshotAsync(this.GetName(), dataId, group, tenant, null).ConfigureAwait(false); await FileLocalConfigInfoProcessor.SaveEncryptDataKeySnapshot(this.GetName(), dataId, group, tenant, null).ConfigureAwait(false); return(configResponse); } else if (response.ErrorCode.Equals(ConfigQueryResponse.CONFIG_QUERY_CONFLICT)) { _logger?.LogError( "[{0}] [sub-server-error] get server config being modified concurrently, dataId={1}, group={2}, tenant={3}", GetName(), dataId, group, tenant); throw new NacosException(NacosException.CONFLICT, $"data being modified, dataId={dataId},group={group},tenant={tenant}"); } else { _logger?.LogError( "[{0}] [sub-server-error] dataId={1}, group={2}, tenant={3}, code={4}", GetName(), dataId, group, tenant, response.ToJsonString()); throw new NacosException(response.ErrorCode, $"http error, code={response.ErrorCode}, dataId={dataId},group={group},tenant={tenant}"); } } catch (Exception ex) { _logger?.LogError(ex, "[{0}] [sub-server-error] dataId={1}, group={2}, tenant={3}, code={4} ", GetName(), dataId, group, tenant, ex.Message); throw; } }
private void SafeNotifyListener(string dataId, string group, string content, string type, string md5, string encryptedDataKey, ManagerListenerWrap wrap) { var listener = wrap.Listener; ConfigResponse cr = new ConfigResponse(); cr.SetDataId(dataId); cr.SetGroup(group); cr.SetContent(content); cr.SetEncryptedDataKey(encryptedDataKey); ConfigFilterChainManager.DoFilter(null, cr); // after filter, such as decrypted value string contentTmp = cr.GetContent(); wrap.LastContent = content; wrap.LastCallMd5 = md5; // should pass the value after filter listener.ReceiveConfigInfo(contentTmp); }
private async Task <string> GetConfigInner(string tenant, string dataId, string group, long timeoutMs) { group = ParamUtils.Null2DefaultGroup(group); ParamUtils.CheckKeyParam(dataId, group); ConfigResponse cr = new ConfigResponse(); cr.SetDataId(dataId); cr.SetTenant(tenant); cr.SetGroup(group); string encryptedDataKey = string.Empty; // 优先使用本地配置 string content = await FileLocalConfigInfoProcessor.GetFailoverAsync(_worker.GetAgentName(), dataId, group, tenant).ConfigureAwait(false); if (content != null) { _logger?.LogWarning( "[{0}] [get-config] get failover ok, dataId={1}, group={2}, tenant={3}, config={4}", _worker.GetAgentName(), dataId, group, tenant, ContentUtils.TruncateContent(content)); cr.SetContent(content); await FileLocalConfigInfoProcessor.GetEncryptDataKeyFailover(_worker.GetAgentName(), dataId, group, tenant).ConfigureAwait(false); encryptedDataKey = string.Empty; cr.SetEncryptedDataKey(encryptedDataKey); _configFilterChainManager.DoFilter(null, cr); content = cr.GetContent(); return(content); } try { ConfigResponse response = await _worker.GetServerConfig(dataId, group, tenant, timeoutMs, false).ConfigureAwait(false); cr.SetContent(response.GetContent()); cr.SetEncryptedDataKey(response.GetEncryptedDataKey()); _configFilterChainManager.DoFilter(null, cr); content = cr.GetContent(); return(content); } catch (NacosException ioe) { if (NacosException.NO_RIGHT == ioe.ErrorCode) { throw; } _logger?.LogWarning( "[{0}] [get-config] get from server error, dataId={1}, group={2}, tenant={3}, msg={4}", _worker.GetAgentName(), dataId, group, tenant, ioe.ErrorMsg); } _logger?.LogWarning( "[{0}] [get-config] get snapshot ok, dataId={1}, group={2}, tenant={3}, config={4}", _worker.GetAgentName(), dataId, group, tenant, ContentUtils.TruncateContent(content)); content = await FileLocalConfigInfoProcessor.GetSnapshotAync(_worker.GetAgentName(), dataId, group, tenant).ConfigureAwait(false); cr.SetContent(content); encryptedDataKey = await FileLocalConfigInfoProcessor.GetEncryptDataKeyFailover(_worker.GetAgentName(), dataId, group, tenant).ConfigureAwait(false); cr.SetEncryptedDataKey(encryptedDataKey); _configFilterChainManager.DoFilter(null, cr); content = cr.GetContent(); return(content); }
protected override async Task <ConfigResponse> QueryConfig(string dataId, string group, string tenant, long readTimeous, bool notify) { try { var request = new ConfigQueryRequest(dataId, group, tenant); request.PutHeader(ConfigConstants.NOTIFY_HEADER, notify.ToString()); var rpcClient = GetOneRunningClient(); if (notify) { var key = GroupKey.GetKeyTenant(dataId, group, tenant); if (_cacheMap.TryGetValue(key, out var cacheData)) { rpcClient = EnsureRpcClient(cacheData.TaskId.ToString()); } } var response = (ConfigQueryResponse) await RequestProxy(rpcClient, request).ConfigureAwait(false); ConfigResponse configResponse = new ConfigResponse(); if (response.IsSuccess()) { await FileLocalConfigInfoProcessor.SaveSnapshotAsync(this.GetName(), dataId, group, tenant, response.Content).ConfigureAwait(false); configResponse.SetContent(response.Content); configResponse.SetConfigType(response.ContentType.IsNotNullOrWhiteSpace() ? response.ContentType : "text"); // in nacos 2.0.2 still do not return the EncryptedDataKey // so this always be null at this time!!! string encryptedDataKey = response.EncryptedDataKey; await FileLocalConfigInfoProcessor.SaveEncryptDataKeySnapshot(this.GetName(), dataId, group, tenant, encryptedDataKey).ConfigureAwait(false); configResponse.SetEncryptedDataKey(encryptedDataKey); return(configResponse); } else if (response.ErrorCode.Equals(ConfigQueryResponse.CONFIG_NOT_FOUND)) { await FileLocalConfigInfoProcessor.SaveSnapshotAsync(this.GetName(), dataId, group, tenant, null).ConfigureAwait(false); await FileLocalConfigInfoProcessor.SaveEncryptDataKeySnapshot(this.GetName(), dataId, group, tenant, null).ConfigureAwait(false); return(configResponse); } else if (response.ErrorCode.Equals(ConfigQueryResponse.CONFIG_QUERY_CONFLICT)) { _logger?.LogError( "[{0}] [sub-server-error] get server config being modified concurrently, dataId={1}, group={2}, tenant={3}", GetName(), dataId, group, tenant); throw new NacosException(NacosException.CONFLICT, $"data being modified, dataId={dataId},group={group},tenant={tenant}"); } else { _logger?.LogError( "[{0}] [sub-server-error] dataId={1}, group={2}, tenant={3}, code={4}", GetName(), dataId, group, tenant, response.ToJsonString()); throw new NacosException(response.ErrorCode, $"http error, code={response.ErrorCode}, dataId={dataId},group={group},tenant={tenant}"); } } catch (Exception ex) { _logger?.LogError(ex, "[{0}] [sub-server-error] dataId={1}, group={2}, tenant={3}, code={4} ", GetName(), dataId, group, tenant, ex.Message); throw; } }