Search in sources :

Example 1 with ZkDataImpl

use of com.actiontech.dble.config.loader.zkprocess.zookeeper.process.ZkDataImpl in project dble by actiontech.

the class ConfigStatusListener method notifyProcess.

@Override
public boolean notifyProcess() throws Exception {
    if (DbleServer.getInstance().getFrontProcessors() != null) {
        DirectoryInf statusDirectory = new ZkDirectoryImpl(currZkPath, null);
        this.getTreeDirectory(currZkPath, KVPathUtil.CONF_STATUS, statusDirectory);
        ZkDataImpl zkData = (ZkDataImpl) statusDirectory.getSubordinateInfo().get(0);
        ConfStatus status = new ConfStatus(zkData.getValue());
        if (status.getFrom().equals(ZkConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID))) {
            // self node
            return true;
        }
        LOGGER.info("ConfigStatusListener notifyProcess zk to object  :" + status);
        if (status.getStatus() == ConfStatus.Status.ROLLBACK) {
            try {
                RollbackConfig.rollback();
                ZKUtils.createTempNode(KVPathUtil.getConfStatusPath(), ZkConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), SUCCESS.getBytes(StandardCharsets.UTF_8));
            } catch (Exception e) {
                String errorinfo = e.getMessage() == null ? e.toString() : e.getMessage();
                ZKUtils.createTempNode(KVPathUtil.getConfStatusPath(), ZkConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), errorinfo.getBytes(StandardCharsets.UTF_8));
            }
            return true;
        }
        for (NotifyService service : childService) {
            try {
                service.notifyProcess();
            } catch (Exception e) {
                LOGGER.warn(AlarmCode.CORE_ZK_WARN + "ConfigStatusListener notify  error :" + service + " ,Exception info:", e);
            }
        }
        try {
            if (status.getStatus() == ConfStatus.Status.RELOAD_ALL) {
                ReloadConfig.reloadAll(Integer.parseInt(status.getParams()));
            } else {
                ReloadConfig.reload();
            }
            ZKUtils.createTempNode(KVPathUtil.getConfStatusPath(), ZkConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), SUCCESS.getBytes(StandardCharsets.UTF_8));
        } catch (Exception e) {
            String errorinfo = e.getMessage() == null ? e.toString() : e.getMessage();
            ZKUtils.createTempNode(KVPathUtil.getConfStatusPath(), ZkConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID), errorinfo.getBytes(StandardCharsets.UTF_8));
        }
    }
    return true;
}
Also used : ConfStatus(com.actiontech.dble.config.loader.zkprocess.zookeeper.process.ConfStatus) DirectoryInf(com.actiontech.dble.config.loader.zkprocess.zookeeper.DirectoryInf) ZkDirectoryImpl(com.actiontech.dble.config.loader.zkprocess.zookeeper.process.ZkDirectoryImpl) NotifyService(com.actiontech.dble.config.loader.zkprocess.comm.NotifyService) ZkDataImpl(com.actiontech.dble.config.loader.zkprocess.zookeeper.process.ZkDataImpl)

Example 2 with ZkDataImpl

use of com.actiontech.dble.config.loader.zkprocess.zookeeper.process.ZkDataImpl in project dble by actiontech.

the class EcacheszkToxmlLoader method zktoEhcacheWrite.

/**
 * zktoEhcacheWrite
 *
 * @param zkDirectory
 * @return
 * @Created 2016/9/17
 */
private void zktoEhcacheWrite(ZkDirectoryImpl zkDirectory) {
    DataInf ehcacheZkDirectory = this.getZkData(zkDirectory, KVPathUtil.EHCACHE_NAME);
    Ehcache ehcache = parseJsonEhcacheService.parseJsonToBean(ehcacheZkDirectory.getDataValue());
    String outputPath = ResourceUtil.getResourcePathFromRoot(ZookeeperPath.ZK_LOCAL_WRITE_PATH.getKey());
    outputPath = new File(outputPath).getPath() + File.separator;
    outputPath += KVPathUtil.EHCACHE_NAME;
    parseEcacheXMl.parseToXmlWrite(ehcache, outputPath, null);
    this.zookeeperListen.addWatch(KVPathUtil.getEhcacheNamePath(), this);
    DataInf cacheserZkDirectory = this.getZkData(zkDirectory, KVPathUtil.CACHESERVER_NAME);
    if (null != cacheserZkDirectory) {
        ZkDataImpl cacheData = (ZkDataImpl) cacheserZkDirectory;
        try {
            ConfFileRWUtils.writeFile(cacheData.getName(), cacheData.getValue());
        } catch (IOException e) {
            LOGGER.warn(AlarmCode.CORE_ZK_WARN + "EcacheszkToxmlLoader wirteMapFile IOException", e);
        }
        this.zookeeperListen.addWatch(KVPathUtil.getCacheServerNamePath(), this);
    }
}
Also used : Ehcache(com.actiontech.dble.config.loader.zkprocess.entity.cache.Ehcache) DataInf(com.actiontech.dble.config.loader.zkprocess.zookeeper.DataInf) IOException(java.io.IOException) File(java.io.File) ZkDataImpl(com.actiontech.dble.config.loader.zkprocess.zookeeper.process.ZkDataImpl)

Example 3 with ZkDataImpl

use of com.actiontech.dble.config.loader.zkprocess.zookeeper.process.ZkDataImpl in project dble by actiontech.

the class SequenceTopropertiesLoader method sequenceZkToProperties.

/**
 * sequenceZkToProperties
 *
 * @param name schema
 * @throws Exception
 */
private void sequenceZkToProperties(String name, DirectoryInf seqDirectory) throws Exception {
    ZkDirectoryImpl zkDirectory = (ZkDirectoryImpl) this.getZkDirectory(seqDirectory, KVPathUtil.SEQUENCE_COMMON);
    if (null != zkDirectory) {
        String writeFile = name + PROPERTIES_SUFFIX;
        ZkDataImpl commData = (ZkDataImpl) this.getZkData(zkDirectory, writeFile);
        if (commData != null) {
            ConfFileRWUtils.writeFile(commData.getName(), commData.getValue());
        }
        String sequenceWatchPath = KVPathUtil.getSequencesCommonPath() + writeFile;
        this.zookeeperListen.addWatch(sequenceWatchPath, this);
        LOGGER.info("SequenceTozkLoader notifyProcess " + name + " to local properties success");
    }
}
Also used : ZkDirectoryImpl(com.actiontech.dble.config.loader.zkprocess.zookeeper.process.ZkDirectoryImpl) ZkDataImpl(com.actiontech.dble.config.loader.zkprocess.zookeeper.process.ZkDataImpl)

Example 4 with ZkDataImpl

use of com.actiontech.dble.config.loader.zkprocess.zookeeper.process.ZkDataImpl in project dble by actiontech.

the class BinlogPauseStatusListener method notifyProcess.

@Override
public boolean notifyProcess() throws Exception {
    DirectoryInf statusDirectory = new ZkDirectoryImpl(currZkPath, null);
    this.getTreeDirectory(currZkPath, KVPathUtil.BINLOG_PAUSE_STATUS, statusDirectory);
    ZkDataImpl zkDdata = (ZkDataImpl) statusDirectory.getSubordinateInfo().get(0);
    String strPauseInfo = zkDdata.getDataValue();
    LOGGER.info("BinlogPauseStatusListener notifyProcess zk to object  :" + strPauseInfo);
    BinlogPause pauseInfo = new BinlogPause(strPauseInfo);
    String myID = ZkConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID);
    if (pauseInfo.getFrom().equals(myID)) {
        // self node
        return true;
    }
    String instancePath = ZKPaths.makePath(KVPathUtil.getBinlogPauseInstance(), myID);
    if (pauseInfo.getStatus() == BinlogPause.BinlogPauseStatus.ON) {
        DbleServer.getInstance().getBackupLocked().compareAndSet(false, true);
        boolean isPaused = ShowBinlogStatus.waitAllSession();
        if (!isPaused) {
            cleanResource(instancePath);
        }
        try {
            ZKUtils.createTempNode(KVPathUtil.getBinlogPauseInstance(), myID, String.valueOf(isPaused).getBytes(StandardCharsets.UTF_8));
        } catch (Exception e) {
            cleanResource(instancePath);
            LOGGER.warn(AlarmCode.CORE_ZK_WARN + "create binlogPause instance failed", e);
        }
    } else if (pauseInfo.getStatus() == BinlogPause.BinlogPauseStatus.OFF) {
        cleanResource(instancePath);
    }
    return true;
}
Also used : BinlogPause(com.actiontech.dble.config.loader.zkprocess.zookeeper.process.BinlogPause) DirectoryInf(com.actiontech.dble.config.loader.zkprocess.zookeeper.DirectoryInf) ZkDirectoryImpl(com.actiontech.dble.config.loader.zkprocess.zookeeper.process.ZkDirectoryImpl) ZkDataImpl(com.actiontech.dble.config.loader.zkprocess.zookeeper.process.ZkDataImpl)

Aggregations

ZkDataImpl (com.actiontech.dble.config.loader.zkprocess.zookeeper.process.ZkDataImpl)4 ZkDirectoryImpl (com.actiontech.dble.config.loader.zkprocess.zookeeper.process.ZkDirectoryImpl)3 DirectoryInf (com.actiontech.dble.config.loader.zkprocess.zookeeper.DirectoryInf)2 NotifyService (com.actiontech.dble.config.loader.zkprocess.comm.NotifyService)1 Ehcache (com.actiontech.dble.config.loader.zkprocess.entity.cache.Ehcache)1 DataInf (com.actiontech.dble.config.loader.zkprocess.zookeeper.DataInf)1 BinlogPause (com.actiontech.dble.config.loader.zkprocess.zookeeper.process.BinlogPause)1 ConfStatus (com.actiontech.dble.config.loader.zkprocess.zookeeper.process.ConfStatus)1 File (java.io.File)1 IOException (java.io.IOException)1