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 content = await FileLocalConfigInfoProcessor.GetFailoverAsync(_worker.GetAgentName(), dataId, group, tenant); 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); _configFilterChainManager.DoFilter(null, cr); content = cr.GetContent(); return(content); } try { List <string> ct = await _worker.GetServerConfig(dataId, group, tenant, timeoutMs, false); cr.SetContent(ct[0]); _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); cr.SetContent(content); _configFilterChainManager.DoFilter(null, cr); content = cr.GetContent(); return(content); }
protected override async Task <bool> RemoveConfig(string dataId, string group, string tenant, string tag) { group = ParamUtils.Null2DefaultGroup(group); ParamUtils.CheckKeyParam(dataId, group); string url = Constants.CONFIG_CONTROLLER_PATH; var parameters = new Dictionary <string, string>(4) { ["dataId"] = dataId, ["group"] = group }; if (tenant.IsNotNullOrWhiteSpace()) { parameters["tenant"] = tenant; } if (tag.IsNotNullOrWhiteSpace()) { parameters["tag"] = tag; } HttpResponseMessage result = null; try { result = await HttpDelete(url, null, parameters, "", POST_TIMEOUT); } catch (Exception ex) { _logger?.LogWarning( ex, "[remove] error,, dataId={1}, group={2}, tenant={3}", dataId, group, tenant); return(false); } if (result.StatusCode == System.Net.HttpStatusCode.OK) { _logger?.LogInformation( "[{0}] [remove] ok, dataId={1}, group={2}, tenant={3}", _agent.GetName(), dataId, group, tenant); return(true); } else if (result.StatusCode == System.Net.HttpStatusCode.Forbidden) { _logger?.LogWarning( "[{0}] [remove] error,, dataId={1}, group={2}, tenant={3}, code={4}, msg={5}", _agent.GetName(), dataId, group, tenant, (int)result.StatusCode, result.StatusCode.ToString()); throw new NacosException((int)result.StatusCode, result.StatusCode.ToString()); } else { _logger?.LogWarning( "[{0}] [remove] error,, dataId={1}, group={2}, tenant={3}, code={4}, msg={5}", _agent.GetName(), dataId, group, tenant, (int)result.StatusCode, result.StatusCode.ToString()); return(false); } }
private async Task <bool> RemoveConfigInner(string tenant, string dataId, string group, string tag) { group = ParamUtils.Null2DefaultGroup(group); ParamUtils.CheckKeyParam(dataId, group); return(await _worker.RemoveConfig(dataId, group, tenant, tag).ConfigureAwait(false)); }