Skip to content

Commit

Permalink
alibaba#187 Fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
nkorange committed Dec 14, 2018
1 parent a631ec3 commit 7a64ce2
Show file tree
Hide file tree
Showing 13 changed files with 230 additions and 119 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 1999-2018 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.api.selector;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 1999-2018 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.api.selector;

/**
* The selector to filter resource with flexible expression.
*
* @author <a href="mailto:[email protected]">nkorange</a>
*/
public class ExpressionSelector extends AbstractSelector {

/**
* Label expression of this selector.
*/
private String expression;

public ExpressionSelector() {
this.setType(SelectorType.label.name());
}

public String getExpression() {
return expression;
}

public void setExpression(String expression) {
this.expression = expression;
}
}
15 changes: 15 additions & 0 deletions api/src/main/java/com/alibaba/nacos/api/selector/SelectorType.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 1999-2018 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.api.selector;

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.nacos.api.cmdb.pojo.Label;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.pojo.ListView;
import com.alibaba.nacos.api.selector.AbstractSelector;
import com.alibaba.nacos.api.selector.SelectorType;
import com.alibaba.nacos.api.selector.label.LabelSelector;
import com.alibaba.nacos.api.selector.ExpressionSelector;
import com.alibaba.nacos.client.naming.utils.*;
import com.alibaba.nacos.common.util.UuidUtils;

Expand Down Expand Up @@ -223,8 +222,8 @@ public ListView<String> getServiceList(int pageNo, int pageSize, AbstractSelecto
case none:
break;
case label:
LabelSelector labelSelector = (LabelSelector) selector;
params.put("selector", JSON.toJSONString(labelSelector));
ExpressionSelector expressionSelector = (ExpressionSelector) selector;
params.put("selector", JSON.toJSONString(expressionSelector));
break;
default:
break;
Expand Down
8 changes: 4 additions & 4 deletions client/src/test/java/com/alibaba/nacos/client/NamingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.pojo.ListView;
import com.alibaba.nacos.api.selector.label.LabelSelector;
import com.alibaba.nacos.api.selector.ExpressionSelector;
import org.junit.Ignore;
import org.junit.Test;

Expand Down Expand Up @@ -48,9 +48,9 @@ public void testServiceList() throws Exception {

namingService.registerInstance("dungu.test.1", instance);

LabelSelector labelSelector = new LabelSelector();
labelSelector.setExpression("INSTANCE.metadata.registerSource = 'dubbo'");
ListView<String> serviceList = namingService.getServicesOfServer(1, 10, labelSelector);
ExpressionSelector expressionSelector = new ExpressionSelector();
expressionSelector.setExpression("INSTANCE.metadata.registerSource = 'dubbo'");
ListView<String> serviceList = namingService.getServicesOfServer(1, 10, expressionSelector);

Thread.sleep(1000000000L);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 1999-2018 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.cmdb.controllers;

import com.alibaba.nacos.cmdb.core.SwitchAndOptions;
Expand Down
15 changes: 15 additions & 0 deletions common/src/main/java/com/alibaba/nacos/common/util/WebUtils.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 1999-2018 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.common.util;

import org.apache.commons.lang3.StringUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ public JSONObject list(HttpServletRequest request) throws Exception {
default:
break;
}
break;
default:
break;
}
}

Expand Down Expand Up @@ -282,11 +285,6 @@ private Selector parseSelector(String selectorJsonString) throws NacosException
case label:
String expression = selectorJson.getString("expression");
Set<String> labels = LabelSelector.parseExpression(expression);

if (labels.isEmpty()) {
throw new NacosException(NacosException.INVALID_PARAM, "expression parse failed:" + expression);
}

LabelSelector labelSelector = new LabelSelector();
labelSelector.setExpression(expression);
labelSelector.setLabels(labels);
Expand Down
Loading

0 comments on commit 7a64ce2

Please sign in to comment.