use of com.alibaba.nacos.api.selector.Selector in project nacos by alibaba.
the class LabelSelectorTest method testParseSelector.
@Test
public void testParseSelector() throws NacosException {
Selector selector = selectorManager.parseSelector("label", "CONSUMER.label.A=PROVIDER.label.A &CONSUMER.label.B=PROVIDER.label.B");
Assert.assertTrue(selector instanceof LabelSelector);
LabelSelector labelSelector = (LabelSelector) selector;
Assert.assertEquals(2, labelSelector.getLabels().size());
Assert.assertTrue(labelSelector.getLabels().contains("A"));
Assert.assertTrue(labelSelector.getLabels().contains("B"));
}
use of com.alibaba.nacos.api.selector.Selector in project nacos by alibaba.
the class SelectorManagerTest method testParseSelector.
@Test
public void testParseSelector() throws NacosException {
Selector selector = selectorManager.parseSelector("mock", "key=value");
Assert.assertTrue(selector instanceof MockSelector);
Assert.assertEquals("mock", selector.getType());
}
use of com.alibaba.nacos.api.selector.Selector in project nacos by alibaba.
the class ServiceController method parseSelector.
private Selector parseSelector(String selectorJsonString) throws Exception {
if (StringUtils.isBlank(selectorJsonString)) {
return new NoneSelector();
}
JsonNode selectorJson = JacksonUtils.toObj(URLDecoder.decode(selectorJsonString, "UTF-8"));
String type = Optional.ofNullable(selectorJson.get("type")).orElseThrow(() -> new NacosException(NacosException.INVALID_PARAM, "not match any type of selector!")).asText();
String expression = Optional.ofNullable(selectorJson.get("expression")).map(JsonNode::asText).orElse(null);
Selector selector = selectorManager.parseSelector(type, expression);
if (Objects.isNull(selector)) {
throw new NacosException(NacosException.INVALID_PARAM, "not match any type of selector!");
}
return selector;
}
use of com.alibaba.nacos.api.selector.Selector in project nacos by alibaba.
the class ServiceControllerV2 method parseSelector.
private Selector parseSelector(String selectorJsonString) throws Exception {
if (StringUtils.isBlank(selectorJsonString)) {
return new NoneSelector();
}
JsonNode selectorJson = JacksonUtils.toObj(URLDecoder.decode(selectorJsonString, "UTF-8"));
String type = Optional.ofNullable(selectorJson.get("type")).orElseThrow(() -> new NacosException(NacosException.INVALID_PARAM, "not match any type of selector!")).asText();
String expression = Optional.ofNullable(selectorJson.get("expression")).map(JsonNode::asText).orElse(null);
Selector selector = selectorManager.parseSelector(type, expression);
if (Objects.isNull(selector)) {
throw new NacosException(NacosException.INVALID_PARAM, "not match any type of selector!");
}
return selector;
}
use of com.alibaba.nacos.api.selector.Selector in project nacos by alibaba.
the class UpgradeOpsController method parseSelector.
private Selector parseSelector(String selectorJsonString) throws Exception {
if (StringUtils.isBlank(selectorJsonString)) {
return new NoneSelector();
}
JsonNode selectorJson = JacksonUtils.toObj(URLDecoder.decode(selectorJsonString, "UTF-8"));
String type = Optional.ofNullable(selectorJson.get("type")).orElseThrow(() -> new NacosException(NacosException.INVALID_PARAM, "not match any type of selector!")).asText();
String expression = Optional.ofNullable(selectorJson.get("expression")).map(JsonNode::asText).orElse(null);
Selector selector = selectorManager.parseSelector(type, expression);
if (Objects.isNull(selector)) {
throw new NacosException(NacosException.INVALID_PARAM, "not match any type of selector!");
}
return selector;
}
Aggregations