Skip to content

Commit

Permalink
Develop config query chain of responsibility.
Browse files Browse the repository at this point in the history
	modified:   config/src/main/java/com/alibaba/nacos/config/server/controller/ConfigController.java
	modified:   config/src/main/java/com/alibaba/nacos/config/server/controller/ConfigServletInner.java
	modified:   config/src/main/java/com/alibaba/nacos/config/server/controller/v2/ConfigControllerV2.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/enums/ApiVersionEnum.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/model/ConfigQueryChainRequest.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/model/ConfigQueryChainResponse.java
	modified:   config/src/main/java/com/alibaba/nacos/config/server/remote/ConfigQueryRequestHandler.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/ConfigQueryChainService.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/ConfigQueryHandlerChain.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/ConfigQueryHandlerChainBuilder.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/DefaultConfigQueryHandlerChainBuilder.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/handler/AbstractConfigQueryHandler.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/handler/ConfigChainEntryHandler.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/handler/ConfigQueryHandler.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/handler/FormalHandler.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/handler/GrayRuleMatchHandler.java

	modified:   config/src/main/java/com/alibaba/nacos/config/server/controller/ConfigController.java
	modified:   config/src/main/java/com/alibaba/nacos/config/server/controller/ConfigServletInner.java
	modified:   config/src/main/java/com/alibaba/nacos/config/server/controller/v2/ConfigControllerV2.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/enums/ApiVersionEnum.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/model/ConfigQueryChainRequest.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/model/ConfigQueryChainResponse.java
	modified:   config/src/main/java/com/alibaba/nacos/config/server/remote/ConfigQueryRequestHandler.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/ConfigQueryChainService.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/ConfigQueryHandlerChain.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/ConfigQueryHandlerChainBuilder.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/DefaultConfigQueryHandlerChainBuilder.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/handler/AbstractConfigQueryHandler.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/handler/ConfigChainEntryHandler.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/handler/ConfigQueryHandler.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/handler/FormalHandler.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/handler/GrayRuleMatchHandler.java
	new file:   config/src/main/java/com/alibaba/nacos/config/server/remote/query/handler/TagNotFoundHandler.java
	new file:   config/src/main/resources/META-INF/services/com.alibaba.nacos.config.server.remote.query.ConfigQueryHandlerChainBuilder
	modified:   config/src/test/java/com/alibaba/nacos/config/server/controller/ConfigServletInnerTest.java
	modified:   config/src/test/java/com/alibaba/nacos/config/server/controller/v2/ConfigControllerV2Test.java
	modified:   config/src/test/java/com/alibaba/nacos/config/server/remote/ConfigQueryRequestHandlerTest.java
  • Loading branch information
KiteSoar committed Nov 25, 2024
1 parent 2a0dafa commit c8d964d
Show file tree
Hide file tree
Showing 21 changed files with 1,206 additions and 274 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.alibaba.nacos.config.server.constant.Constants;
import com.alibaba.nacos.config.server.constant.ParametersField;
import com.alibaba.nacos.config.server.controller.parameters.SameNamespaceCloneConfigBean;
import com.alibaba.nacos.config.server.enums.ApiVersionEnum;
import com.alibaba.nacos.config.server.model.ConfigAdvanceInfo;
import com.alibaba.nacos.config.server.model.ConfigAllInfo;
import com.alibaba.nacos.config.server.model.ConfigInfo;
Expand Down Expand Up @@ -244,7 +245,7 @@ public void getConfig(HttpServletRequest request, HttpServletResponse response,

final String clientIp = RequestUtil.getRemoteIp(request);
String isNotify = request.getHeader("notify");
inner.doGetConfig(request, response, dataId, group, tenant, tag, isNotify, clientIp);
inner.doGetConfig(request, response, dataId, group, tenant, tag, isNotify, clientIp, ApiVersionEnum.V1);
}

/**
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.config.server.constant.Constants;
import com.alibaba.nacos.config.server.controller.ConfigServletInner;
import com.alibaba.nacos.config.server.enums.ApiVersionEnum;
import com.alibaba.nacos.config.server.model.ConfigInfo;
import com.alibaba.nacos.config.server.model.ConfigRequestInfo;
import com.alibaba.nacos.config.server.paramcheck.ConfigBlurSearchHttpParamExtractor;
Expand Down Expand Up @@ -105,7 +106,7 @@ public void getConfig(HttpServletRequest request, HttpServletResponse response,
ParamUtils.checkParamV2(tag);
final String clientIp = RequestUtil.getRemoteIp(request);
String isNotify = request.getHeader("notify");
inner.doGetConfig(request, response, dataId, group, namespaceId, tag, isNotify, clientIp, true);
inner.doGetConfig(request, response, dataId, group, namespaceId, tag, isNotify, clientIp, ApiVersionEnum.V2);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 1999-$toady.year Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.nacos.config.server.enums;

/**
* Config Api Version enum.
* @author Nacos
*/
public enum ApiVersionEnum {

V1("v1"),

V2("v2");

private final String version;

ApiVersionEnum(String version) {
this.version = version;
}

public String getVersion() {
return version;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Copyright 1999-$toady.year Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.nacos.config.server.model;

import java.util.Map;
import java.util.Objects;

/**
* ConfigQueryChainRequest.
* @author Nacos
*/
public class ConfigQueryChainRequest {

private String dataId;

private String group;

private String tenant;

private String tag;

private Map<String, String> appLabels;

public String getDataId() {
return dataId;
}

public void setDataId(String dataId) {
this.dataId = dataId;
}

public String getGroup() {
return group;
}

public void setGroup(String group) {
this.group = group;
}

public String getTenant() {
return tenant;
}

public void setTenant(String tenant) {
this.tenant = tenant;
}

public String getTag() {
return tag;
}

public void setTag(String tag) {
this.tag = tag;
}

public Map<String, String> getAppLabels() {
return appLabels;
}

public void setAppLabels(Map<String, String> appLabels) {
this.appLabels = appLabels;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ConfigQueryChainRequest that = (ConfigQueryChainRequest) o;
return Objects.equals(dataId, that.dataId)
&& Objects.equals(group, that.group)
&& Objects.equals(tenant, that.tenant)
&& Objects.equals(tag, that.tag)
&& Objects.equals(appLabels, that.appLabels);
}

@Override
public int hashCode() {
return Objects.hash(dataId, group, tenant, tag, appLabels);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* Copyright 1999-$toady.year Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.nacos.config.server.model;

import java.util.Objects;

/**
* ConfigQueryChainResponse.
* @author Nacos
*/
public class ConfigQueryChainResponse {

private String content;

private String contentType;

private String encryptedDataKey;

private String md5;

private long lastModified;

private ConfigCacheGray matchedGray;

private ConfigQueryStatus status;

public enum ConfigQueryStatus {
BETA,
TAG,
TAG_NOT_FOUND,
FORMAL,
CONFIG_QUERY_CONFLICT,
CONFIG_NOT_FOUND,
}

public String getContent() {
return content;
}

public void setContent(String content) {
this.content = content;
}

public String getContentType() {
return contentType;
}

public void setContentType(String contentType) {
this.contentType = contentType;
}

public String getEncryptedDataKey() {
return encryptedDataKey;
}

public void setEncryptedDataKey(String encryptedDataKey) {
this.encryptedDataKey = encryptedDataKey;
}

public String getMd5() {
return md5;
}

public void setMd5(String md5) {
this.md5 = md5;
}

public long getLastModified() {
return lastModified;
}

public void setLastModified(long lastModified) {
this.lastModified = lastModified;
}

public ConfigCacheGray getMatchedGray() {
return matchedGray;
}

public void setMatchedGray(ConfigCacheGray matchedGray) {
this.matchedGray = matchedGray;
}

public ConfigQueryStatus getStatus() {
return status;
}

public void setStatus(ConfigQueryStatus status) {
this.status = status;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ConfigQueryChainResponse that = (ConfigQueryChainResponse) o;
return lastModified == that.lastModified
&& Objects.equals(content, that.content)
&& Objects.equals(contentType, that.contentType)
&& Objects.equals(encryptedDataKey, that.encryptedDataKey)
&& Objects.equals(md5, that.md5)
&& Objects.equals(matchedGray, that.matchedGray)
&& status == that.status;
}

@Override
public int hashCode() {
return Objects.hash(content, contentType, encryptedDataKey, md5, lastModified, matchedGray, status);
}
}
Loading

0 comments on commit c8d964d

Please sign in to comment.