Search in sources :

Example 1 with PradarSwitchEvent

use of com.pamirs.pradar.event.PradarSwitchEvent in project LinkAgent by shulieTech.

the class ZookeeperRegister method init.

@Override
public void init(RegisterOptions registerOptions) {
    if (registerOptions == null) {
        throw new NullPointerException("RegisterOptions is null");
    }
    this.basePath = registerOptions.getRegisterBasePath();
    this.appName = registerOptions.getAppName();
    this.md5 = registerOptions.getMd5();
    this.simulatorConfig = registerOptions.getSimulatorConfig();
    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("[pradar-register] prepare to init register zookeeper node. {}", Pradar.AGENT_ID_CONTAIN_USER_INFO);
    }
    String registerBasePath = null;
    if (StringUtils.endsWith(basePath, "/")) {
        registerBasePath = this.basePath + appName;
    } else {
        registerBasePath = this.basePath + '/' + appName;
    }
    try {
        ZkClientSpec zkClientSpec = new ZkClientSpec();
        zkClientSpec.setZkServers(registerOptions.getZkServers());
        zkClientSpec.setConnectionTimeoutMillis(registerOptions.getConnectionTimeoutMillis());
        zkClientSpec.setSessionTimeoutMillis(registerOptions.getSessionTimeoutMillis());
        zkClientSpec.setThreadName("heartbeat");
        this.zkClient = NetflixCuratorZkClientFactory.getInstance().create(zkClientSpec);
    } catch (PradarException e) {
        LOGGER.error("[pradar-register] ZookeeperRegister init error.", e);
        throw e;
    } catch (Throwable e) {
        LOGGER.error("[pradar-register] ZookeeperRegister init error.", e);
        throw new PradarException(e);
    }
    String client = Pradar.AGENT_ID_CONTAIN_USER_INFO;
    try {
        this.zkClient.ensureDirectoryExists(registerBasePath);
    } catch (Throwable e) {
        LOGGER.error("[register] ensureDirectoryExists err:{}", registerBasePath, e);
    }
    this.heartbeatPath = registerBasePath + '/' + client;
    try {
        if (this.zkClient.exists(this.heartbeatPath)) {
            this.zkClient.deleteQuietly(this.heartbeatPath);
        }
    } catch (Throwable e) {
    }
    cleanExpiredNodes(registerBasePath);
    this.heartbeatNode = this.zkClient.createHeartbeatNode(this.heartbeatPath);
    PradarSwitcher.registerListener(new PradarSwitcher.PradarSwitcherListener() {

        @Override
        public void onListen(Event event) {
            if (event instanceof PradarSwitchEvent || event instanceof ErrorEvent) {
                refresh();
            }
        }
    });
    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("[pradar-register] init register zookeeper node successful. {}", Pradar.AGENT_ID_CONTAIN_USER_INFO);
    }
}
Also used : PradarException(com.pamirs.pradar.exception.PradarException) ZkClientSpec(com.shulie.instrument.module.register.zk.impl.ZkClientSpec) ErrorEvent(com.pamirs.pradar.event.ErrorEvent) ErrorEvent(com.pamirs.pradar.event.ErrorEvent) Event(com.pamirs.pradar.event.Event) PradarSwitchEvent(com.pamirs.pradar.event.PradarSwitchEvent) PradarSwitchEvent(com.pamirs.pradar.event.PradarSwitchEvent)

Example 2 with PradarSwitchEvent

use of com.pamirs.pradar.event.PradarSwitchEvent in project LinkAgent by shulieTech.

the class PradarSwitcher method turnConfigSwitcherOn.

public static void turnConfigSwitcherOn(String configName) {
    configSwitchers.get(configName);
    Boolean oldValue = configSwitchers.put(configName, Boolean.TRUE);
    if (oldValue != null && !oldValue) {
        for (PradarSwitcherListener listener : listeners) {
            listener.onListen(new PradarSwitchEvent(isClusterTestEnabled(), getClusterTestUnableReason()));
        }
    }
}
Also used : PradarSwitchEvent(com.pamirs.pradar.event.PradarSwitchEvent) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 3 with PradarSwitchEvent

use of com.pamirs.pradar.event.PradarSwitchEvent in project LinkAgent by shulieTech.

the class PradarSwitcher method turnConfigSwitcherOff.

public static void turnConfigSwitcherOff(String configName) {
    Boolean oldValue = configSwitchers.get(configName);
    configSwitchers.put(configName, Boolean.FALSE);
    if (oldValue == null || oldValue) {
        for (PradarSwitcherListener listener : listeners) {
            listener.onListen(new PradarSwitchEvent(isClusterTestEnabled(), getClusterTestUnableReason()));
        }
    }
}
Also used : PradarSwitchEvent(com.pamirs.pradar.event.PradarSwitchEvent) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 4 with PradarSwitchEvent

use of com.pamirs.pradar.event.PradarSwitchEvent in project LinkAgent by shulieTech.

the class PradarSwitcher method invalid.

public static synchronized void invalid() {
    boolean before = isClusterTestEnabled();
    LOGGER.info("Cluster Tester is force closed....");
    isValid = false;
    boolean after = isClusterTestEnabled();
    if (before != after) {
        for (PradarSwitcherListener listener : listeners) {
            listener.onListen(new PradarSwitchEvent(after, "Cluster Tester is force closed...."));
        }
    }
}
Also used : PradarSwitchEvent(com.pamirs.pradar.event.PradarSwitchEvent)

Example 5 with PradarSwitchEvent

use of com.pamirs.pradar.event.PradarSwitchEvent in project LinkAgent by shulieTech.

the class PradarSwitcher method clusterTestPrepare.

/**
 * 设置压测环境没有准备完成
 */
public static void clusterTestPrepare() {
    /**
     * 只要有一次 ready 则不会再 prepare
     */
    if (isClusterTestReady) {
        return;
    }
    boolean before = isClusterTestEnabled();
    isClusterTestReady = false;
    boolean after = isClusterTestEnabled();
    if (before != after) {
        for (PradarSwitcherListener listener : listeners) {
            listener.onListen(new PradarSwitchEvent(after, getClusterTestUnableReason()));
        }
    }
}
Also used : PradarSwitchEvent(com.pamirs.pradar.event.PradarSwitchEvent)

Aggregations

PradarSwitchEvent (com.pamirs.pradar.event.PradarSwitchEvent)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 ErrorEvent (com.pamirs.pradar.event.ErrorEvent)1 Event (com.pamirs.pradar.event.Event)1 PradarException (com.pamirs.pradar.exception.PradarException)1 ZkClientSpec (com.shulie.instrument.module.register.zk.impl.ZkClientSpec)1