Search in sources :

Example 1 with NoneSelector

use of com.alibaba.nacos.naming.selector.NoneSelector 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;
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) NacosException(com.alibaba.nacos.api.exception.NacosException) NoneSelector(com.alibaba.nacos.naming.selector.NoneSelector) Selector(com.alibaba.nacos.api.selector.Selector) NoneSelector(com.alibaba.nacos.naming.selector.NoneSelector)

Example 2 with NoneSelector

use of com.alibaba.nacos.naming.selector.NoneSelector 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;
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) NacosException(com.alibaba.nacos.api.exception.NacosException) NoneSelector(com.alibaba.nacos.naming.selector.NoneSelector) Selector(com.alibaba.nacos.api.selector.Selector) NoneSelector(com.alibaba.nacos.naming.selector.NoneSelector)

Example 3 with NoneSelector

use of com.alibaba.nacos.naming.selector.NoneSelector 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;
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) NacosException(com.alibaba.nacos.api.exception.NacosException) NoneSelector(com.alibaba.nacos.naming.selector.NoneSelector) Selector(com.alibaba.nacos.api.selector.Selector) NoneSelector(com.alibaba.nacos.naming.selector.NoneSelector)

Example 4 with NoneSelector

use of com.alibaba.nacos.naming.selector.NoneSelector in project nacos by alibaba.

the class ServiceMetadataTest method testGetSelector.

@Test
public void testGetSelector() {
    Selector selector = serviceMetadata.getSelector();
    Assert.assertNotNull(selector);
    boolean result = selector instanceof NoneSelector;
    Assert.assertTrue(result);
}
Also used : Selector(com.alibaba.nacos.api.selector.Selector) LabelSelector(com.alibaba.nacos.naming.selector.LabelSelector) NoneSelector(com.alibaba.nacos.naming.selector.NoneSelector) NoneSelector(com.alibaba.nacos.naming.selector.NoneSelector) Test(org.junit.Test)

Aggregations

Selector (com.alibaba.nacos.api.selector.Selector)4 NoneSelector (com.alibaba.nacos.naming.selector.NoneSelector)4 NacosException (com.alibaba.nacos.api.exception.NacosException)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 LabelSelector (com.alibaba.nacos.naming.selector.LabelSelector)1 Test (org.junit.Test)1