Java Code Examples for com.alibaba.csp.sentinel.util.AssertUtil#notEmpty()
The following examples show how to use
com.alibaba.csp.sentinel.util.AssertUtil#notEmpty() .
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: SentinelApiClient.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 6 votes |
public boolean modifyApis(String app, String ip, int port, List<ApiDefinitionEntity> apis) { if (apis == null) { return true; } try { AssertUtil.notEmpty(app, "Bad app name"); AssertUtil.notEmpty(ip, "Bad machine IP"); AssertUtil.isTrue(port > 0, "Bad machine port"); String data = JSON.toJSONString( apis.stream().map(r -> r.toApiDefinition()).collect(Collectors.toList())); Map<String, String> params = new HashMap<>(2); params.put("data", data); String result = executeCommand(app, ip, port, MODIFY_GATEWAY_API_PATH, params, true).get(); logger.info("Modify gateway apis: {}", result); return true; } catch (Exception e) { logger.warn("Error when modifying gateway apis", e); return false; } }
Example 2
Source File: ClusterParamFlowRuleManager.java From Sentinel with Apache License 2.0 | 6 votes |
/** * Listen to the {@link SentinelProperty} for cluster {@link ParamFlowRule}s. * The property is the source of cluster {@link ParamFlowRule}s for a specific namespace. * * @param namespace namespace to register */ public static void register2Property(String namespace) { AssertUtil.notEmpty(namespace, "namespace cannot be empty"); if (propertySupplier == null) { RecordLog.warn( "[ClusterParamFlowRuleManager] Cluster param rule property supplier is absent, cannot register " + "property"); return; } SentinelProperty<List<ParamFlowRule>> property = propertySupplier.apply(namespace); if (property == null) { RecordLog.warn( "[ClusterParamFlowRuleManager] Wrong created property from cluster param rule property supplier, " + "ignoring"); return; } synchronized (UPDATE_LOCK) { RecordLog.info("[ClusterParamFlowRuleManager] Registering new property to cluster param rule manager" + " for namespace <{}>", namespace); registerPropertyInternal(namespace, property); } }
Example 3
Source File: ClusterFlowRuleManager.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 6 votes |
/** * Listen to the {@link SentinelProperty} for cluster {@link FlowRule}s. * The property is the source of cluster {@link FlowRule}s for a specific namespace. * * @param namespace namespace to register */ public static void register2Property(String namespace) { AssertUtil.notEmpty(namespace, "namespace cannot be empty"); if (propertySupplier == null) { RecordLog.warn( "[ClusterFlowRuleManager] Cluster flow property supplier is absent, cannot register property"); return; } SentinelProperty<List<FlowRule>> property = propertySupplier.apply(namespace); if (property == null) { RecordLog.warn( "[ClusterFlowRuleManager] Wrong created property from cluster flow property supplier, ignoring"); return; } synchronized (UPDATE_LOCK) { RecordLog.info("[ClusterFlowRuleManager] Registering new property to cluster flow rule manager" + " for namespace <{0}>", namespace); registerPropertyInternal(namespace, property); } }
Example 4
Source File: ConnectionGroup.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 6 votes |
public ConnectionGroup addConnection(String address) { AssertUtil.notEmpty(address, "address cannot be empty"); String[] ip = address.split(":"); String host; if (ip != null && ip.length >= 1) { host = ip[0]; } else { host = address; } boolean newAdded = connectionSet.add(new ConnectionDescriptor().setAddress(address).setHost(host)); if (newAdded) { connectedCount.incrementAndGet(); } return this; }
Example 5
Source File: ClusterServerConfigManager.java From Sentinel with Apache License 2.0 | 5 votes |
/** * Get sample count of provided namespace. * * @param namespace valid namespace * @return the sample count of namespace; if the namespace does not have customized value, use the global value */ public static int getSampleCount(String namespace) { AssertUtil.notEmpty(namespace, "namespace cannot be empty"); ServerFlowConfig config = NAMESPACE_CONF.get(namespace); if (config != null) { return config.getSampleCount(); } return sampleCount; }
Example 6
Source File: RedisConnectionConfig.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 5 votes |
/** * Set Sentinel host. Creates a new builder. * * @param host the host name * @return New builder with Sentinel host/port. */ public static RedisConnectionConfig.Builder redisSentinel(String host) { AssertUtil.notEmpty(host, "Host must not be empty"); RedisConnectionConfig.Builder builder = RedisConnectionConfig.builder(); return builder.withRedisSentinel(host); }
Example 7
Source File: ClusterParamFlowRuleManager.java From Sentinel with Apache License 2.0 | 5 votes |
public static void removeProperty(String namespace) { AssertUtil.notEmpty(namespace, "namespace cannot be empty"); synchronized (UPDATE_LOCK) { NamespaceFlowProperty<ParamFlowRule> property = PROPERTY_MAP.get(namespace); if (property != null) { property.getProperty().removeListener(property.getListener()); PROPERTY_MAP.remove(namespace); } RecordLog.info("[ClusterParamFlowRuleManager] Removing property from cluster flow rule manager" + " for namespace <{}>", namespace); } }
Example 8
Source File: ClusterServerConfigManager.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 5 votes |
public static double getMaxOccupyRatio(String namespace) { AssertUtil.notEmpty(namespace, "namespace cannot be empty"); ServerFlowConfig config = NAMESPACE_CONF.get(namespace); if (config != null) { return config.getMaxOccupyRatio(); } return maxOccupyRatio; }
Example 9
Source File: ResourceWrapper.java From Sentinel with Apache License 2.0 | 5 votes |
public ResourceWrapper(String name, EntryType entryType, int resourceType) { AssertUtil.notEmpty(name, "resource name cannot be empty"); AssertUtil.notNull(entryType, "entryType cannot be null"); this.name = name; this.entryType = entryType; this.resourceType = resourceType; }
Example 10
Source File: ClusterParamFlowRuleManager.java From Sentinel with Apache License 2.0 | 5 votes |
public static void registerPropertyIfAbsent(String namespace) { AssertUtil.notEmpty(namespace, "namespace cannot be empty"); if (!PROPERTY_MAP.containsKey(namespace)) { synchronized (UPDATE_LOCK) { if (!PROPERTY_MAP.containsKey(namespace)) { register2Property(namespace); } } } }
Example 11
Source File: ClusterFlowRuleManager.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 5 votes |
/** * Load flow rules for a specific namespace. The former rules of the namespace will be replaced. * * @param namespace a valid namespace * @param rules rule list */ public static void loadRules(String namespace, List<FlowRule> rules) { AssertUtil.notEmpty(namespace, "namespace cannot be empty"); NamespaceFlowProperty<FlowRule> property = PROPERTY_MAP.get(namespace); if (property != null) { property.getProperty().updateValue(rules); } }
Example 12
Source File: RedisDataSource.java From Sentinel with Apache License 2.0 | 5 votes |
/** * Constructor of {@code RedisDataSource}. * * @param connectionConfig Redis connection config * @param ruleKey data key in Redis * @param channel channel to subscribe in Redis * @param parser customized data parser, cannot be empty */ public RedisDataSource(RedisConnectionConfig connectionConfig, String ruleKey, String channel, Converter<String, T> parser) { super(parser); AssertUtil.notNull(connectionConfig, "Redis connection config can not be null"); AssertUtil.notEmpty(ruleKey, "Redis ruleKey can not be empty"); AssertUtil.notEmpty(channel, "Redis subscribe channel can not be empty"); this.redisClient = getRedisClient(connectionConfig); this.ruleKey = ruleKey; loadInitialConfig(); subscribeFromChannel(channel); }
Example 13
Source File: SentinelApiClient.java From Sentinel with Apache License 2.0 | 5 votes |
@Nullable private <T> CompletableFuture<List<T>> fetchItemsAsync(String ip, int port, String api, String type, Class<T> ruleType) { AssertUtil.notEmpty(ip, "Bad machine IP"); AssertUtil.isTrue(port > 0, "Bad machine port"); Map<String, String> params = null; if (StringUtil.isNotEmpty(type)) { params = new HashMap<>(1); params.put("type", type); } return executeCommand(ip, port, api, params, false) .thenApply(json -> JSON.parseArray(json, ruleType)); }
Example 14
Source File: RedisConnectionConfig.java From Sentinel with Apache License 2.0 | 5 votes |
/** * Set Sentinel host. Creates a new builder. * * @param host the host name * @return New builder with Sentinel host/port. */ public static RedisConnectionConfig.Builder redisSentinel(String host) { AssertUtil.notEmpty(host, "Host must not be empty"); RedisConnectionConfig.Builder builder = RedisConnectionConfig.builder(); return builder.withRedisSentinel(host); }
Example 15
Source File: ConsulDataSource.java From Sentinel with Apache License 2.0 | 5 votes |
/** * Constructor of {@code ConsulDataSource}. * * @param parser customized data parser, cannot be empty * @param host consul agent host * @param port consul agent port * @param ruleKey data key in Consul * @param watchTimeout request for querying data will be blocked until new data or timeout. The unit is second (s) */ public ConsulDataSource(String host, int port, String ruleKey, int watchTimeout, Converter<String, T> parser) { super(parser); AssertUtil.notNull(host, "Consul host can not be null"); AssertUtil.notEmpty(ruleKey, "Consul ruleKey can not be empty"); AssertUtil.isTrue(watchTimeout >= 0, "watchTimeout should not be negative"); this.client = new ConsulClient(host, port); this.address = host + ":" + port; this.ruleKey = ruleKey; this.watchTimeout = watchTimeout; loadInitialConfig(); startKVWatcher(); }
Example 16
Source File: ClusterParamFlowRuleManager.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 5 votes |
public static void registerPropertyIfAbsent(String namespace) { AssertUtil.notEmpty(namespace, "namespace cannot be empty"); if (!PROPERTY_MAP.containsKey(namespace)) { synchronized (UPDATE_LOCK) { if (!PROPERTY_MAP.containsKey(namespace)) { register2Property(namespace); } } } }
Example 17
Source File: ConnectionGroup.java From Sentinel with Apache License 2.0 | 4 votes |
public ConnectionGroup(String namespace) { AssertUtil.notEmpty(namespace, "namespace cannot be empty"); this.namespace = namespace; }
Example 18
Source File: ClusterNode.java From Sentinel with Apache License 2.0 | 4 votes |
public ClusterNode(String name, int resourceType) { AssertUtil.notEmpty(name, "name cannot be empty"); this.name = name; this.resourceType = resourceType; }
Example 19
Source File: ConnectionManager.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 2 votes |
/** * Get connected count for specific namespace. * * @param namespace namespace to check * @return connected count for specific namespace */ public static int getConnectedCount(String namespace) { AssertUtil.notEmpty(namespace, "namespace should not be empty"); ConnectionGroup group = CONN_MAP.get(namespace); return group == null ? 0 : group.getConnectedCount(); }
Example 20
Source File: ClusterServerConfigManager.java From Sentinel-Dashboard-Nacos with Apache License 2.0 | 2 votes |
/** * Load server flow config for a specific namespace. * * @param namespace a valid namespace * @param config valid flow config for the namespace */ public static void loadFlowConfig(String namespace, ServerFlowConfig config) { AssertUtil.notEmpty(namespace, "namespace cannot be empty"); // TODO: Support namespace-scope server flow config. globalFlowProperty.updateValue(config); }