Search in sources :

Example 1 with LocalDataChangeEvent

use of com.alibaba.nacos.config.server.model.event.LocalDataChangeEvent in project nacos by alibaba.

the class ConfigCacheService method removeTag.

/**
 * Delete tag config file, and delete cache.
 *
 * @param dataId dataId string value.
 * @param group  group string value.
 * @param tenant tenant string value.
 * @param tag    tag string value.
 * @return remove success or not.
 */
public static boolean removeTag(String dataId, String group, String tenant, String tag) {
    final String groupKey = GroupKey2.getKey(dataId, group, tenant);
    final int lockResult = tryWriteLock(groupKey);
    // If data is non-existent.
    if (0 == lockResult) {
        DUMP_LOG.info("[remove-ok] {} not exist.", groupKey);
        return true;
    }
    // try to lock failed
    if (lockResult < 0) {
        DUMP_LOG.warn("[remove-error] write lock failed. {}", groupKey);
        return false;
    }
    try {
        if (!PropertyUtil.isDirectRead()) {
            DiskUtil.removeConfigInfo4Tag(dataId, group, tenant, tag);
        }
        CacheItem ci = CACHE.get(groupKey);
        ci.tagMd5.remove(tag);
        ci.tagLastModifiedTs.remove(tag);
        NotifyCenter.publishEvent(new LocalDataChangeEvent(groupKey, false, null, tag));
        return true;
    } finally {
        releaseWriteLock(groupKey);
    }
}
Also used : LocalDataChangeEvent(com.alibaba.nacos.config.server.model.event.LocalDataChangeEvent) CacheItem(com.alibaba.nacos.config.server.model.CacheItem)

Example 2 with LocalDataChangeEvent

use of com.alibaba.nacos.config.server.model.event.LocalDataChangeEvent in project nacos by alibaba.

the class ConfigCacheService method updateMd5.

/**
 * Update md5 value.
 *
 * @param groupKey       groupKey string value.
 * @param md5            md5 string value.
 * @param lastModifiedTs lastModifiedTs long value.
 */
public static void updateMd5(String groupKey, String md5, long lastModifiedTs, String encryptedDataKey) {
    CacheItem cache = makeSure(groupKey, encryptedDataKey, false);
    if (cache.md5 == null || !cache.md5.equals(md5)) {
        cache.md5 = md5;
        cache.lastModifiedTs = lastModifiedTs;
        NotifyCenter.publishEvent(new LocalDataChangeEvent(groupKey));
    }
}
Also used : LocalDataChangeEvent(com.alibaba.nacos.config.server.model.event.LocalDataChangeEvent) CacheItem(com.alibaba.nacos.config.server.model.CacheItem)

Example 3 with LocalDataChangeEvent

use of com.alibaba.nacos.config.server.model.event.LocalDataChangeEvent in project nacos by alibaba.

the class RpcConfigChangeNotifierTest method testOnEvent.

@Test
public void testOnEvent() {
    final String groupKey = GroupKey2.getKey("nacos.internal.tps.control_rule_1", "nacos", "tenant");
    final String limitGroupKey = GroupKey2.getKey("nacos.internal.tps.nacos.internal.connection.limit.rule", "nacos", "tenant");
    List<String> betaIps = new ArrayList<>();
    betaIps.add("1.1.1.1");
    rpcConfigChangeNotifier.onEvent(new LocalDataChangeEvent(groupKey, true, betaIps));
    rpcConfigChangeNotifier.onEvent(new LocalDataChangeEvent(limitGroupKey));
}
Also used : ArrayList(java.util.ArrayList) LocalDataChangeEvent(com.alibaba.nacos.config.server.model.event.LocalDataChangeEvent) Test(org.junit.Test)

Example 4 with LocalDataChangeEvent

use of com.alibaba.nacos.config.server.model.event.LocalDataChangeEvent in project nacos by alibaba.

the class InternalConfigChangeNotifierTest method testOnEvent.

@Test
public void testOnEvent() {
    final String groupKey = GroupKey2.getKey("nacos.internal.tps.control_rule_1", "nacos", "tenant");
    final String limitGroupKey = GroupKey2.getKey("nacos.internal.tps.nacos.internal.connection.limit.rule", "nacos", "tenant");
    NotifyCenter.registerSubscriber(new Subscriber() {

        @Override
        public void onEvent(Event event) {
            ConnectionLimitRuleChangeEvent connectionLimitRuleChangeEvent = (ConnectionLimitRuleChangeEvent) event;
            Assert.assertEquals("content", connectionLimitRuleChangeEvent.getLimitRule());
        }

        @Override
        public Class<? extends Event> subscribeType() {
            return ConnectionLimitRuleChangeEvent.class;
        }
    });
    NotifyCenter.registerSubscriber(new Subscriber() {

        @Override
        public void onEvent(Event event) {
            TpsControlRuleChangeEvent tpsControlRuleChangeEvent = (TpsControlRuleChangeEvent) event;
            Assert.assertEquals("content", tpsControlRuleChangeEvent.getRuleContent());
        }

        @Override
        public Class<? extends Event> subscribeType() {
            return TpsControlRuleChangeEvent.class;
        }
    });
    internalConfigChangeNotifier.onEvent(new LocalDataChangeEvent(groupKey));
    internalConfigChangeNotifier.onEvent(new LocalDataChangeEvent(limitGroupKey));
    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : TpsControlRuleChangeEvent(com.alibaba.nacos.core.remote.control.TpsControlRuleChangeEvent) Subscriber(com.alibaba.nacos.common.notify.listener.Subscriber) ConnectionLimitRuleChangeEvent(com.alibaba.nacos.core.remote.event.ConnectionLimitRuleChangeEvent) TpsControlRuleChangeEvent(com.alibaba.nacos.core.remote.control.TpsControlRuleChangeEvent) ConnectionLimitRuleChangeEvent(com.alibaba.nacos.core.remote.event.ConnectionLimitRuleChangeEvent) LocalDataChangeEvent(com.alibaba.nacos.config.server.model.event.LocalDataChangeEvent) Event(com.alibaba.nacos.common.notify.Event) LocalDataChangeEvent(com.alibaba.nacos.config.server.model.event.LocalDataChangeEvent) Test(org.junit.Test)

Example 5 with LocalDataChangeEvent

use of com.alibaba.nacos.config.server.model.event.LocalDataChangeEvent in project nacos by alibaba.

the class ConfigCacheService method removeBeta.

/**
 * Delete beta config file, and delete cache.
 *
 * @param dataId dataId string value.
 * @param group  group string value.
 * @param tenant tenant string value.
 * @return remove success or not.
 */
public static boolean removeBeta(String dataId, String group, String tenant) {
    final String groupKey = GroupKey2.getKey(dataId, group, tenant);
    final int lockResult = tryWriteLock(groupKey);
    // If data is non-existent.
    if (0 == lockResult) {
        DUMP_LOG.info("[remove-ok] {} not exist.", groupKey);
        return true;
    }
    // try to lock failed
    if (lockResult < 0) {
        DUMP_LOG.warn("[remove-error] write lock failed. {}", groupKey);
        return false;
    }
    try {
        if (!PropertyUtil.isDirectRead()) {
            DiskUtil.removeConfigInfo4Beta(dataId, group, tenant);
        }
        NotifyCenter.publishEvent(new LocalDataChangeEvent(groupKey, true, CACHE.get(groupKey).getIps4Beta()));
        CACHE.get(groupKey).setBeta(false);
        CACHE.get(groupKey).setIps4Beta(null);
        CACHE.get(groupKey).setMd54Beta(Constants.NULL);
        return true;
    } finally {
        releaseWriteLock(groupKey);
    }
}
Also used : LocalDataChangeEvent(com.alibaba.nacos.config.server.model.event.LocalDataChangeEvent)

Aggregations

LocalDataChangeEvent (com.alibaba.nacos.config.server.model.event.LocalDataChangeEvent)8 CacheItem (com.alibaba.nacos.config.server.model.CacheItem)4 Test (org.junit.Test)2 Event (com.alibaba.nacos.common.notify.Event)1 Subscriber (com.alibaba.nacos.common.notify.listener.Subscriber)1 TpsControlRuleChangeEvent (com.alibaba.nacos.core.remote.control.TpsControlRuleChangeEvent)1 ConnectionLimitRuleChangeEvent (com.alibaba.nacos.core.remote.event.ConnectionLimitRuleChangeEvent)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1