From 11dc413af0c51944627c684e27c292632ddf3ea0 Mon Sep 17 00:00:00 2001 From: heliang <3596006474@qq.com> Date: Sat, 22 Jun 2024 16:06:05 +0800 Subject: [PATCH] copy all the related classes to org.apache.dubbo.rpc.cluster.configurator.parser.model --- .../parser/model/ConditionMatch.java | 4 +- .../configurator/parser/model/ParamMatch.java | 2 +- .../parser/model/match/AddressMatch.java | 87 ++++++++++++ .../parser/model/match/BoolMatch.java | 36 +++++ .../parser/model/match/DoubleMatch.java | 60 ++++++++ .../parser/model/match/DoubleRangeMatch.java | 50 +++++++ .../model/match/DubboAttachmentMatch.java | 73 ++++++++++ .../parser/model/match/DubboMethodArg.java | 87 ++++++++++++ .../parser/model/match/DubboMethodMatch.java | 133 ++++++++++++++++++ .../parser/model/match/ListBoolMatch.java | 41 ++++++ .../parser/model/match/ListDoubleMatch.java | 41 ++++++ .../parser/model/match/ListStringMatch.java | 41 ++++++ .../parser/model/match/StringMatch.java | 105 ++++++++++++++ 13 files changed, 757 insertions(+), 3 deletions(-) create mode 100644 dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/AddressMatch.java create mode 100644 dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/BoolMatch.java create mode 100644 dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/DoubleMatch.java create mode 100644 dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/DoubleRangeMatch.java create mode 100644 dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/DubboAttachmentMatch.java create mode 100644 dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/DubboMethodArg.java create mode 100644 dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/DubboMethodMatch.java create mode 100644 dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/ListBoolMatch.java create mode 100644 dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/ListDoubleMatch.java create mode 100644 dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/ListStringMatch.java create mode 100644 dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/StringMatch.java diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/ConditionMatch.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/ConditionMatch.java index 853a6ae8df..21138b9558 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/ConditionMatch.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/ConditionMatch.java @@ -17,8 +17,8 @@ package org.apache.dubbo.rpc.cluster.configurator.parser.model; import org.apache.dubbo.common.URL; -import org.apache.dubbo.rpc.cluster.router.mesh.rule.virtualservice.match.AddressMatch; -import org.apache.dubbo.rpc.cluster.router.mesh.rule.virtualservice.match.ListStringMatch; +import org.apache.dubbo.rpc.cluster.configurator.parser.model.match.AddressMatch; +import org.apache.dubbo.rpc.cluster.configurator.parser.model.match.ListStringMatch; import java.util.List; diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/ParamMatch.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/ParamMatch.java index ad6dae436f..b3e447a1f6 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/ParamMatch.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/ParamMatch.java @@ -17,7 +17,7 @@ package org.apache.dubbo.rpc.cluster.configurator.parser.model; import org.apache.dubbo.common.URL; -import org.apache.dubbo.rpc.cluster.router.mesh.rule.virtualservice.match.StringMatch; +import org.apache.dubbo.rpc.cluster.configurator.parser.model.match.StringMatch; public class ParamMatch { private String key; diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/AddressMatch.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/AddressMatch.java new file mode 100644 index 0000000000..87ca1be1df --- /dev/null +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/AddressMatch.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.dubbo.rpc.cluster.configurator.parser.model.match; + +import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; +import org.apache.dubbo.common.logger.LoggerFactory; + +import java.net.UnknownHostException; + +import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE; +import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE; +import static org.apache.dubbo.common.constants.LoggerCodeConstants.CLUSTER_FAILED_EXEC_CONDITION_ROUTER; +import static org.apache.dubbo.common.utils.NetUtils.matchIpExpression; +import static org.apache.dubbo.common.utils.UrlUtils.isMatchGlobPattern; + +public class AddressMatch { + public static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(AddressMatch.class); + private String wildcard; + private String cird; + private String exact; + + public String getWildcard() { + return wildcard; + } + + public void setWildcard(String wildcard) { + this.wildcard = wildcard; + } + + public String getCird() { + return cird; + } + + public void setCird(String cird) { + this.cird = cird; + } + + public String getExact() { + return exact; + } + + public void setExact(String exact) { + this.exact = exact; + } + + public boolean isMatch(String input) { + if (getCird() != null && input != null) { + try { + return input.equals(getCird()) || matchIpExpression(getCird(), input); + } catch (UnknownHostException e) { + logger.error( + CLUSTER_FAILED_EXEC_CONDITION_ROUTER, + "Executing routing rule match expression error.", + "", + String.format( + "Error trying to match cird formatted address %s with input %s in AddressMatch.", + getCird(), input), + e); + } + } + if (getWildcard() != null && input != null) { + if (ANYHOST_VALUE.equals(getWildcard()) || ANY_VALUE.equals(getWildcard())) { + return true; + } + // FIXME + return isMatchGlobPattern(getWildcard(), input); + } + if (getExact() != null && input != null) { + return input.equals(getExact()); + } + return false; + } +} diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/BoolMatch.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/BoolMatch.java new file mode 100644 index 0000000000..5dc9d36af7 --- /dev/null +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/BoolMatch.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.dubbo.rpc.cluster.configurator.parser.model.match; + +public class BoolMatch { + private Boolean exact; + + public Boolean getExact() { + return exact; + } + + public void setExact(Boolean exact) { + this.exact = exact; + } + + public boolean isMatch(boolean input) { + if (exact != null) { + return input == exact; + } + return false; + } +} diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/DoubleMatch.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/DoubleMatch.java new file mode 100644 index 0000000000..16a906d833 --- /dev/null +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/DoubleMatch.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.dubbo.rpc.cluster.configurator.parser.model.match; + +public class DoubleMatch { + private Double exact; + private DoubleRangeMatch range; + private Double mod; + + public Double getExact() { + return exact; + } + + public void setExact(Double exact) { + this.exact = exact; + } + + public DoubleRangeMatch getRange() { + return range; + } + + public void setRange(DoubleRangeMatch range) { + this.range = range; + } + + public Double getMod() { + return mod; + } + + public void setMod(Double mod) { + this.mod = mod; + } + + public boolean isMatch(Double input) { + if (exact != null && mod == null) { + return input.equals(exact); + } else if (range != null) { + return range.isMatch(input); + } else if (exact != null) { + Double result = input % mod; + return result.equals(exact); + } + + return false; + } +} diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/DoubleRangeMatch.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/DoubleRangeMatch.java new file mode 100644 index 0000000000..8ac219a8d4 --- /dev/null +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/DoubleRangeMatch.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.dubbo.rpc.cluster.configurator.parser.model.match; + +public class DoubleRangeMatch { + private Double start; + private Double end; + + public Double getStart() { + return start; + } + + public void setStart(Double start) { + this.start = start; + } + + public Double getEnd() { + return end; + } + + public void setEnd(Double end) { + this.end = end; + } + + public boolean isMatch(Double input) { + if (start != null && end != null) { + return input.compareTo(start) >= 0 && input.compareTo(end) < 0; + } else if (start != null) { + return input.compareTo(start) >= 0; + } else if (end != null) { + return input.compareTo(end) < 0; + } else { + return false; + } + } +} diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/DubboAttachmentMatch.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/DubboAttachmentMatch.java new file mode 100644 index 0000000000..47c5f07db7 --- /dev/null +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/DubboAttachmentMatch.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.dubbo.rpc.cluster.configurator.parser.model.match; + +import org.apache.dubbo.rpc.Invocation; +import org.apache.dubbo.rpc.cluster.router.mesh.util.TracingContextProvider; + +import java.util.Map; +import java.util.Set; + +public class DubboAttachmentMatch { + private Map tracingContext; + private Map dubboContext; + + public Map getTracingContext() { + return tracingContext; + } + + public void setTracingContext(Map tracingContext) { + this.tracingContext = tracingContext; + } + + public Map getDubboContext() { + return dubboContext; + } + + public void setDubboContext(Map dubboContext) { + this.dubboContext = dubboContext; + } + + public boolean isMatch(Invocation invocation, Set contextProviders) { + // Match Dubbo Context + if (dubboContext != null) { + for (Map.Entry entry : dubboContext.entrySet()) { + String key = entry.getKey(); + if (!entry.getValue().isMatch(invocation.getAttachment(key))) { + return false; + } + } + } + + // Match Tracing Context + if (tracingContext != null) { + for (Map.Entry entry : tracingContext.entrySet()) { + String key = entry.getKey(); + boolean match = false; + for (TracingContextProvider contextProvider : contextProviders) { + if (entry.getValue().isMatch(contextProvider.getValue(invocation, key))) { + match = true; + } + } + if (!match) { + return false; + } + } + } + return true; + } +} diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/DubboMethodArg.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/DubboMethodArg.java new file mode 100644 index 0000000000..14a1b64b61 --- /dev/null +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/DubboMethodArg.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.dubbo.rpc.cluster.configurator.parser.model.match; + +public class DubboMethodArg { + private int index; + private String type; + private ListStringMatch str_value; + private ListDoubleMatch num_value; + private BoolMatch bool_value; + + public int getIndex() { + return index; + } + + public void setIndex(int index) { + this.index = index; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public ListStringMatch getStr_value() { + return str_value; + } + + public void setStr_value(ListStringMatch str_value) { + this.str_value = str_value; + } + + public ListDoubleMatch getNum_value() { + return num_value; + } + + public void setNum_value(ListDoubleMatch num_value) { + this.num_value = num_value; + } + + public BoolMatch getBool_value() { + return bool_value; + } + + public void setBool_value(BoolMatch bool_value) { + this.bool_value = bool_value; + } + + public boolean isMatch(Object input) { + + if (str_value != null) { + return input instanceof String && str_value.isMatch((String) input); + } else if (num_value != null) { + return num_value.isMatch(Double.valueOf(input.toString())); + } else if (bool_value != null) { + return input instanceof Boolean && bool_value.isMatch((Boolean) input); + } + return false; + } + + @Override + public String toString() { + return "DubboMethodArg{" + "index=" + + index + ", type='" + + type + '\'' + ", str_value=" + + str_value + ", num_value=" + + num_value + ", bool_value=" + + bool_value + '}'; + } +} diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/DubboMethodMatch.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/DubboMethodMatch.java new file mode 100644 index 0000000000..59b869e92f --- /dev/null +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/DubboMethodMatch.java @@ -0,0 +1,133 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.dubbo.rpc.cluster.configurator.parser.model.match; + +import org.apache.dubbo.rpc.Invocation; +import org.apache.dubbo.rpc.support.RpcUtils; + +import java.util.List; +import java.util.Map; + +public class DubboMethodMatch { + private StringMatch name_match; + private Integer argc; + private List args; + private List argp; + private Map headers; + + public StringMatch getName_match() { + return name_match; + } + + public void setName_match(StringMatch name_match) { + this.name_match = name_match; + } + + public Integer getArgc() { + return argc; + } + + public void setArgc(Integer argc) { + this.argc = argc; + } + + public List getArgs() { + return args; + } + + public void setArgs(List args) { + this.args = args; + } + + public List getArgp() { + return argp; + } + + public void setArgp(List argp) { + this.argp = argp; + } + + public Map getHeaders() { + return headers; + } + + public void setHeaders(Map headers) { + this.headers = headers; + } + + @Override + public String toString() { + return "DubboMethodMatch{" + "name_match=" + + name_match + ", argc=" + + argc + ", args=" + + args + ", argp=" + + argp + ", headers=" + + headers + '}'; + } + + public boolean isMatch(Invocation invocation) { + StringMatch nameMatch = getName_match(); + if (nameMatch != null && !nameMatch.isMatch(RpcUtils.getMethodName(invocation))) { + return false; + } + + Integer argc = getArgc(); + Object[] arguments = invocation.getArguments(); + if (argc != null + && ((argc != 0 && (arguments == null || arguments.length == 0)) || (argc != arguments.length))) { + return false; + } + + List argp = getArgp(); + Class[] parameterTypes = invocation.getParameterTypes(); + if (argp != null && argp.size() > 0) { + if (parameterTypes == null || parameterTypes.length == 0) { + return false; + } + if (argp.size() != parameterTypes.length) { + return false; + } + + for (int index = 0; index < argp.size(); index++) { + boolean match = argp.get(index).isMatch(parameterTypes[index].getName()) + || argp.get(index).isMatch(parameterTypes[index].getSimpleName()); + if (!match) { + return false; + } + } + } + + List args = getArgs(); + if (args != null && args.size() > 0) { + if (arguments == null || arguments.length == 0) { + return false; + } + + for (DubboMethodArg dubboMethodArg : args) { + int index = dubboMethodArg.getIndex(); + if (index >= arguments.length) { + throw new IndexOutOfBoundsException("DubboMethodArg index >= parameters.length"); + } + if (!dubboMethodArg.isMatch(arguments[index])) { + return false; + } + } + } + + return true; + } +} diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/ListBoolMatch.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/ListBoolMatch.java new file mode 100644 index 0000000000..6cc0709f93 --- /dev/null +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/ListBoolMatch.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.dubbo.rpc.cluster.configurator.parser.model.match; + +import java.util.List; + +public class ListBoolMatch { + private List oneof; + + public List getOneof() { + return oneof; + } + + public void setOneof(List oneof) { + this.oneof = oneof; + } + + public boolean isMatch(boolean input) { + + for (BoolMatch boolMatch : oneof) { + if (boolMatch.isMatch(input)) { + return true; + } + } + return false; + } +} diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/ListDoubleMatch.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/ListDoubleMatch.java new file mode 100644 index 0000000000..9391f2e3b5 --- /dev/null +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/ListDoubleMatch.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.dubbo.rpc.cluster.configurator.parser.model.match; + +import java.util.List; + +public class ListDoubleMatch { + private List oneof; + + public List getOneof() { + return oneof; + } + + public void setOneof(List oneof) { + this.oneof = oneof; + } + + public boolean isMatch(Double input) { + + for (DoubleMatch doubleMatch : oneof) { + if (doubleMatch.isMatch(input)) { + return true; + } + } + return false; + } +} diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/ListStringMatch.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/ListStringMatch.java new file mode 100644 index 0000000000..f6047f8a8d --- /dev/null +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/ListStringMatch.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.dubbo.rpc.cluster.configurator.parser.model.match; + +import java.util.List; + +public class ListStringMatch { + private List oneof; + + public List getOneof() { + return oneof; + } + + public void setOneof(List oneof) { + this.oneof = oneof; + } + + public boolean isMatch(String input) { + + for (StringMatch stringMatch : oneof) { + if (stringMatch.isMatch(input)) { + return true; + } + } + return false; + } +} diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/StringMatch.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/StringMatch.java new file mode 100644 index 0000000000..f75af959a9 --- /dev/null +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/parser/model/match/StringMatch.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.dubbo.rpc.cluster.configurator.parser.model.match; + +import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE; + +public class StringMatch { + private String exact; + private String prefix; + private String regex; + private String noempty; + private String empty; + private String wildcard; + + public String getExact() { + return exact; + } + + public void setExact(String exact) { + this.exact = exact; + } + + public String getPrefix() { + return prefix; + } + + public void setPrefix(String prefix) { + this.prefix = prefix; + } + + public String getRegex() { + return regex; + } + + public void setRegex(String regex) { + this.regex = regex; + } + + public String getNoempty() { + return noempty; + } + + public void setNoempty(String noempty) { + this.noempty = noempty; + } + + public String getEmpty() { + return empty; + } + + public void setEmpty(String empty) { + this.empty = empty; + } + + public String getWildcard() { + return wildcard; + } + + public void setWildcard(String wildcard) { + this.wildcard = wildcard; + } + + public boolean isMatch(String input) { + if (getExact() != null && input != null) { + return input.equals(getExact()); + } else if (getPrefix() != null && input != null) { + return input.startsWith(getPrefix()); + } else if (getRegex() != null && input != null) { + return input.matches(getRegex()); + } else if (getWildcard() != null && input != null) { + // only supports "*" + return input.equals(getWildcard()) || ANY_VALUE.equals(getWildcard()); + } else if (getEmpty() != null) { + return input == null || "".equals(input); + } else if (getNoempty() != null) { + return input != null && input.length() > 0; + } else { + return false; + } + } + + @Override + public String toString() { + return "StringMatch{" + "exact='" + + exact + '\'' + ", prefix='" + + prefix + '\'' + ", regex='" + + regex + '\'' + ", noempty='" + + noempty + '\'' + ", empty='" + + empty + '\'' + '}'; + } +}