Java Code Examples for com.alibaba.csp.sentinel.util.AssertUtil#assertNotBlank()

The following examples show how to use com.alibaba.csp.sentinel.util.AssertUtil#assertNotBlank() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileInJarReadableDataSource.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 6 votes vote down vote up
public FileInJarReadableDataSource(String jarName, String fileInJarName, Converter<String, T> configParser,
                                   int bufSize, Charset charset) throws IOException {
    super(configParser);
    AssertUtil.assertNotBlank(jarName, "jarName cannot be blank");
    AssertUtil.assertNotBlank(fileInJarName, "fileInJarName cannot be blank");
    if (bufSize <= 0 || bufSize > MAX_SIZE) {
        throw new IllegalArgumentException("bufSize must between (0, " + MAX_SIZE + "], but " + bufSize + " get");
    }
    AssertUtil.notNull(charset, "charset can't be null");
    this.buf = new byte[bufSize];
    this.charset = charset;
    this.jarName = jarName;
    this.fileInJarName = fileInJarName;
    initializeJar();
    firstLoad();
}
 
Example 2
Source File: ConnectionManager.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 5 votes vote down vote up
public static ConnectionGroup getOrCreateGroup(String namespace) {
    AssertUtil.assertNotBlank(namespace, "namespace should not be empty");
    ConnectionGroup group = CONN_MAP.get(namespace);
    if (group == null) {
        synchronized (CREATE_LOCK) {
            if ((group = CONN_MAP.get(namespace)) == null) {
                group = new ConnectionGroup(namespace);
                CONN_MAP.put(namespace, group);
            }
        }
    }
    return group;
}
 
Example 3
Source File: ContextConfig.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 5 votes vote down vote up
public ContextConfig(String contextName, String origin) {
    AssertUtil.assertNotBlank(contextName, "contextName cannot be blank");
    this.contextName = contextName;
    if (StringUtil.isBlank(origin)) {
        origin = "";
    }
    this.origin = origin;
}
 
Example 4
Source File: ConnectionManager.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
public static void removeConnection(String namespace, String address) {
    AssertUtil.assertNotBlank(namespace, "namespace should not be empty");
    AssertUtil.assertNotBlank(address, "address should not be empty");
    ConnectionGroup group = CONN_MAP.get(namespace);
    if (group == null) {
        return;
    }
    group.removeConnection(address);
    NAMESPACE_MAP.remove(address);
    RecordLog.info("[ConnectionManager] Client <{}> disconnected and removed from namespace <{}>", address, namespace);
}
 
Example 5
Source File: ClusterAssignServiceImpl.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 5 votes vote down vote up
@Override
public ClusterAppAssignResultVO applyAssignToApp(String app, List<ClusterAppAssignMap> clusterMap,
                                                 Set<String> remainingSet) {
    AssertUtil.assertNotBlank(app, "app cannot be blank");
    AssertUtil.notNull(clusterMap, "clusterMap cannot be null");
    Set<String> failedServerSet = new HashSet<>();
    Set<String> failedClientSet = new HashSet<>();

    // Assign server and apply config.
    clusterMap.stream()
        .filter(Objects::nonNull)
        .filter(ClusterAppAssignMap::getBelongToApp)
        .map(e -> {
            String ip = e.getIp();
            int commandPort = parsePort(e);
            CompletableFuture<Void> f = modifyMode(ip, commandPort, ClusterStateManager.CLUSTER_SERVER)
                .thenCompose(v -> applyServerConfigChange(app, ip, commandPort, e));
            return Tuple2.of(e.getMachineId(), f);
        })
        .forEach(t -> handleFutureSync(t, failedServerSet));

    // Assign client of servers and apply config.
    clusterMap.parallelStream()
        .filter(Objects::nonNull)
        .forEach(e -> applyAllClientConfigChange(app, e, failedClientSet));

    // Unbind remaining (unassigned) machines.
    applyAllRemainingMachineSet(app, remainingSet, failedClientSet);

    return new ClusterAppAssignResultVO()
        .setFailedClientSet(failedClientSet)
        .setFailedServerSet(failedServerSet);
}
 
Example 6
Source File: ClusterAssignServiceImpl.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 5 votes vote down vote up
@Override
public ClusterAppAssignResultVO unbindClusterServer(String app, String machineId) {
    AssertUtil.assertNotBlank(app, "app cannot be blank");
    AssertUtil.assertNotBlank(machineId, "machineId cannot be blank");

    if (isMachineInApp(machineId)) {
        return handleUnbindClusterServerNotInApp(app, machineId);
    }
    Set<String> failedSet = new HashSet<>();
    try {
        ClusterGroupEntity entity = clusterConfigService.getClusterUniversalStateForAppMachine(app, machineId)
            .get(10, TimeUnit.SECONDS);
        Set<String> toModifySet = new HashSet<>();
        toModifySet.add(machineId);
        if (entity.getClientSet() != null) {
            toModifySet.addAll(entity.getClientSet());
        }
        // Modify mode to NOT-STARTED for all chosen token servers and associated token clients.
        modifyToNonStarted(toModifySet, failedSet);
    } catch (Exception ex) {
        Throwable e = ex instanceof ExecutionException ? ex.getCause() : ex;
        LOGGER.error("Failed to unbind machine <{}>", machineId, e);
        failedSet.add(machineId);
    }
    return new ClusterAppAssignResultVO()
        .setFailedClientSet(failedSet)
        .setFailedServerSet(new HashSet<>());
}
 
Example 7
Source File: SimpleMachineDiscovery.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 5 votes vote down vote up
@Override
public boolean removeMachine(String app, String ip, int port) {
    AssertUtil.assertNotBlank(app, "app name cannot be blank");
    AppInfo appInfo = apps.get(app);
    if (appInfo != null) {
        return appInfo.removeMachine(ip, port);
    }
    return false;
}
 
Example 8
Source File: AbstractApiMatcher.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
public AbstractApiMatcher(ApiDefinition apiDefinition) {
    AssertUtil.notNull(apiDefinition, "apiDefinition cannot be null");
    AssertUtil.assertNotBlank(apiDefinition.getApiName(), "apiName cannot be empty");
    this.apiName = apiDefinition.getApiName();
    this.apiDefinition = apiDefinition;

    try {
        initializeMatchers();
    } catch (Exception ex) {
        RecordLog.warn("[GatewayApiMatcher] Failed to initialize internal matchers", ex);
    }
}
 
Example 9
Source File: ConnectionManager.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 5 votes vote down vote up
public static ConnectionGroup addConnection(String namespace, String address) {
    AssertUtil.assertNotBlank(namespace, "namespace should not be empty");
    AssertUtil.assertNotBlank(address, "address should not be empty");
    ConnectionGroup group = getOrCreateGroup(namespace);
    group.addConnection(address);
    NAMESPACE_MAP.put(address, namespace);
    RecordLog.info("[ConnectionManager] Client <{0}> registered with namespace <{1}>", address, namespace);
    return group;
}
 
Example 10
Source File: ConnectionManager.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
public static ConnectionGroup getOrCreateGroup(String namespace) {
    AssertUtil.assertNotBlank(namespace, "namespace should not be empty");
    ConnectionGroup group = CONN_MAP.get(namespace);
    if (group == null) {
        synchronized (CREATE_LOCK) {
            if ((group = CONN_MAP.get(namespace)) == null) {
                group = new ConnectionGroup(namespace);
                CONN_MAP.put(namespace, group);
            }
        }
    }
    return group;
}
 
Example 11
Source File: ConnectionManager.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 5 votes vote down vote up
public static void removeConnection(String address) {
    AssertUtil.assertNotBlank(address, "address should not be empty");
    String namespace = NAMESPACE_MAP.get(address);
    if (namespace != null) {
        ConnectionGroup group = CONN_MAP.get(namespace);
        if (group == null) {
            return;
        }
        group.removeConnection(address);
        RecordLog.info("[ConnectionManager] Client <{0}> disconnected and removed from namespace <{1}>", address, namespace);
    }
    NAMESPACE_MAP.remove(address);
}
 
Example 12
Source File: ConnectionManager.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 4 votes vote down vote up
public static ConnectionGroup getOrCreateConnectionGroup(String namespace) {
    AssertUtil.assertNotBlank(namespace, "namespace should not be empty");
    ConnectionGroup group = getOrCreateGroup(namespace);
    return group;
}
 
Example 13
Source File: AbstractSentinelInterceptor.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
public AbstractSentinelInterceptor(BaseWebMvcConfig config) {
    AssertUtil.notNull(config, "BaseWebMvcConfig should not be null");
    AssertUtil.assertNotBlank(config.getRequestAttributeName(), "requestAttributeName should not be blank");
    this.baseWebMvcConfig = config;
}
 
Example 14
Source File: ConnectionManager.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
public static ConnectionGroup getConnectionGroup(String namespace) {
    AssertUtil.assertNotBlank(namespace, "namespace should not be empty");
    ConnectionGroup group = CONN_MAP.get(namespace);
    return group;
}
 
Example 15
Source File: NettyTransportClient.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
public NettyTransportClient(String host, int port) {
    AssertUtil.assertNotBlank(host, "remote host cannot be blank");
    AssertUtil.isTrue(port > 0, "port should be positive");
    this.host = host;
    this.port = port;
}
 
Example 16
Source File: SimpleMachineDiscovery.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
@Override
public void removeApp(String app) {
    AssertUtil.assertNotBlank(app, "app name cannot be blank");
    apps.remove(app);
}
 
Example 17
Source File: NettyTransportClient.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 4 votes vote down vote up
public NettyTransportClient(String host, int port) {
    AssertUtil.assertNotBlank(host, "remote host cannot be blank");
    AssertUtil.isTrue(port > 0, "port should be positive");
    this.host = host;
    this.port = port;
}
 
Example 18
Source File: RedirectBlockRequestHandler.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 4 votes vote down vote up
public RedirectBlockRequestHandler(String url) {
    AssertUtil.assertNotBlank(url, "url cannot be blank");
    this.uri = URI.create(url);
}
 
Example 19
Source File: RegexRoutePathMatcher.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
public RegexRoutePathMatcher(String pattern) {
    AssertUtil.assertNotBlank(pattern, "pattern cannot be blank");
    this.pattern = pattern;
    this.regex = Pattern.compile(pattern);
}
 
Example 20
Source File: RegexRoutePathMatcher.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
public RegexRoutePathMatcher(String pattern) {
    AssertUtil.assertNotBlank(pattern, "pattern cannot be blank");
    this.pattern = pattern;
    this.regex = Pattern.compile(pattern);
}