Search in sources :

Example 1 with Function

use of com.actiontech.dble.config.loader.zkprocess.entity.rule.function.Function in project dble by actiontech.

the class RulesxmlTozkLoader method readMapFileAddFunction.

/**
 * readMapFileAddFunction
 *
 * @param functionList
 * @Created 2016/9/18
 */
private void readMapFileAddFunction(List<Function> functionList) {
    List<Property> tempData = new ArrayList<>();
    for (Function function : functionList) {
        List<Property> proList = function.getProperty();
        if (null != proList && !proList.isEmpty()) {
            for (Property property : proList) {
                // if mapfile,read and save to json
                if (ParseParamEnum.ZK_PATH_RULE_MAPFILE_NAME.getKey().equals(property.getName())) {
                    Property mapFilePro = new Property();
                    mapFilePro.setName(property.getValue());
                    try {
                        mapFilePro.setValue(ConfFileRWUtils.readFile(property.getValue()));
                        tempData.add(mapFilePro);
                    } catch (IOException e) {
                        LOGGER.warn(AlarmCode.CORE_ZK_WARN + "RulesxmlTozkLoader readMapFile IOException", e);
                    }
                }
            }
            proList.addAll(tempData);
            tempData.clear();
        }
    }
}
Also used : Function(com.actiontech.dble.config.loader.zkprocess.entity.rule.function.Function) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Property(com.actiontech.dble.config.loader.zkprocess.entity.Property)

Example 2 with Function

use of com.actiontech.dble.config.loader.zkprocess.entity.rule.function.Function in project dble by actiontech.

the class UXmlRuleLoader method writeMapFileAddFunction.

/**
 * writeMapFileAddFunction
 *
 * @param functionList
 * @Created 2016/9/18
 */
private void writeMapFileAddFunction(List<Function> functionList) {
    List<Property> tempData = new ArrayList<>();
    List<Property> writeData = new ArrayList<>();
    for (Function function : functionList) {
        List<Property> proList = function.getProperty();
        if (null != proList && !proList.isEmpty()) {
            for (Property property : proList) {
                if (ParseParamEnum.ZK_PATH_RULE_MAPFILE_NAME.getKey().equals(property.getName())) {
                    tempData.add(property);
                }
            }
            if (!tempData.isEmpty()) {
                for (Property property : tempData) {
                    for (Property prozkdownload : proList) {
                        if (property.getValue().equals(prozkdownload.getName())) {
                            writeData.add(prozkdownload);
                        }
                    }
                }
            }
            if (!writeData.isEmpty()) {
                for (Property writeMsg : writeData) {
                    try {
                        ConfFileRWUtils.writeFile(writeMsg.getName(), writeMsg.getValue());
                    } catch (IOException e) {
                        LOGGER.warn(AlarmCode.CORE_ZK_WARN + "RuleszkToxmlLoader write File IOException", e);
                    }
                }
            }
            proList.removeAll(writeData);
            tempData.clear();
            writeData.clear();
        }
    }
}
Also used : Function(com.actiontech.dble.config.loader.zkprocess.entity.rule.function.Function) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Property(com.actiontech.dble.config.loader.zkprocess.entity.Property)

Example 3 with Function

use of com.actiontech.dble.config.loader.zkprocess.entity.rule.function.Function in project dble by actiontech.

the class UXmlRuleLoader method notifyProcess.

@Override
public void notifyProcess(UKvBean configValue) throws Exception {
    UKvBean lock = ClusterUcoreSender.getKey(UcorePathUtil.getConfChangeLockPath());
    if (UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_CFG_MYID).equals(lock.getValue())) {
        return;
    }
    Rules rule = new Rules();
    // the config Value in ucore is an all in one json config of the schema.xml
    JSONObject jsonObj = JSONObject.parseObject(configValue.getValue());
    List<Function> functions = parseJsonFunctionService.parseJsonToBean(jsonObj.getJSONArray(UcorePathUtil.FUNCTION).toJSONString());
    rule.setFunction(functions);
    List<TableRule> tableRules = parseJsonTableRuleService.parseJsonToBean(jsonObj.getJSONArray(UcorePathUtil.TABLE_RULE).toJSONString());
    rule.setTableRule(tableRules);
    String path = ResourceUtil.getResourcePathFromRoot(UcorePathUtil.UCORE_LOCAL_WRITE_PATH);
    path = new File(path).getPath() + File.separator;
    path += WRITEPATH;
    LOGGER.info("SchemasLoader notifyProcess ucore to object writePath :" + path);
    writeMapFileAddFunction(functions);
    this.parseRulesXMl.parseToXmlWrite(rule, path, "rule");
    LOGGER.info("SchemasLoader notifyProcess ucore to object zk schema      write :" + path + " is success");
}
Also used : TableRule(com.actiontech.dble.config.loader.zkprocess.entity.rule.tablerule.TableRule) Function(com.actiontech.dble.config.loader.zkprocess.entity.rule.function.Function) JSONObject(com.alibaba.fastjson.JSONObject) UKvBean(com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean) Rules(com.actiontech.dble.config.loader.zkprocess.entity.Rules) File(java.io.File)

Example 4 with Function

use of com.actiontech.dble.config.loader.zkprocess.entity.rule.function.Function in project dble by actiontech.

the class RuleszkToxmlLoader method zktoRulesBean.

/**
 * zktoRulesBean
 *
 * @param zkDirectory
 * @return
 * @Created 2016/9/17
 */
private Rules zktoRulesBean(DirectoryInf zkDirectory) {
    Rules rules = new Rules();
    // tablerule
    DataInf rulesZkData = this.getZkData(zkDirectory, KVPathUtil.TABLE_RULE);
    List<TableRule> tableRuleData = parseJsonTableRuleService.parseJsonToBean(rulesZkData.getDataValue());
    rules.setTableRule(tableRuleData);
    // function
    DataInf functionZkData = this.getZkData(zkDirectory, KVPathUtil.FUNCTION);
    List<Function> functionList = parseJsonFunctionService.parseJsonToBean(functionZkData.getDataValue());
    rules.setFunction(functionList);
    return rules;
}
Also used : TableRule(com.actiontech.dble.config.loader.zkprocess.entity.rule.tablerule.TableRule) Function(com.actiontech.dble.config.loader.zkprocess.entity.rule.function.Function) DataInf(com.actiontech.dble.config.loader.zkprocess.zookeeper.DataInf) Rules(com.actiontech.dble.config.loader.zkprocess.entity.Rules)

Example 5 with Function

use of com.actiontech.dble.config.loader.zkprocess.entity.rule.function.Function in project dble by actiontech.

the class UXmlRuleLoader method readMapFileAddFunction.

/**
 * readMapFileAddFunction
 *
 * @param functionList
 * @Created 2016/9/18
 */
private void readMapFileAddFunction(List<Function> functionList) {
    List<Property> tempData = new ArrayList<>();
    for (Function function : functionList) {
        List<Property> proList = function.getProperty();
        if (null != proList && !proList.isEmpty()) {
            for (Property property : proList) {
                // if mapfile,read and save to json
                if (ParseParamEnum.ZK_PATH_RULE_MAPFILE_NAME.getKey().equals(property.getName())) {
                    Property mapFilePro = new Property();
                    mapFilePro.setName(property.getValue());
                    try {
                        mapFilePro.setValue(ConfFileRWUtils.readFile(property.getValue()));
                        tempData.add(mapFilePro);
                    } catch (IOException e) {
                        LOGGER.warn(AlarmCode.CORE_ZK_WARN + "RulesxmlTozkLoader readMapFile IOException", e);
                    }
                }
            }
            proList.addAll(tempData);
            tempData.clear();
        }
    }
}
Also used : Function(com.actiontech.dble.config.loader.zkprocess.entity.rule.function.Function) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Property(com.actiontech.dble.config.loader.zkprocess.entity.Property)

Aggregations

Function (com.actiontech.dble.config.loader.zkprocess.entity.rule.function.Function)6 Property (com.actiontech.dble.config.loader.zkprocess.entity.Property)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Rules (com.actiontech.dble.config.loader.zkprocess.entity.Rules)2 TableRule (com.actiontech.dble.config.loader.zkprocess.entity.rule.tablerule.TableRule)2 UKvBean (com.actiontech.dble.config.loader.ucoreprocess.bean.UKvBean)1 DataInf (com.actiontech.dble.config.loader.zkprocess.zookeeper.DataInf)1 JSONObject (com.alibaba.fastjson.JSONObject)1 File (java.io.File)1