com.alibaba.datax.common.util.Configuration.from()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(114)

本文整理了Java中com.alibaba.datax.common.util.Configuration.from()方法的一些代码示例,展示了Configuration.from()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Configuration.from()方法的具体详情如下:
包路径:com.alibaba.datax.common.util.Configuration
类名称:Configuration
方法名:from

Configuration.from介绍

[英]从包括json的File对象加载Configuration
[中]从包括json的文件对象加载配置

代码示例

代码示例来源:origin: ECNU-1X/DataX-Masking

/**
 * 初始化空白的Configuration
 */
public static Configuration newDefault() {
  return Configuration.from("{}");
}

代码示例来源:origin: ECNU-1X/DataX-Masking

private static Configuration loadTransFormerConfig(String transformerPath) {
  return Configuration.from(new File(transformerPath + File.separator + "transformer.json"));
}

代码示例来源:origin: ECNU-1X/DataX-Masking

private static Configuration parseCoreConfig(final String path) {
  return Configuration.from(new File(path));
}

代码示例来源:origin: ECNU-1X/DataX-Masking

/**
 * 从包括json的InputStream对象加载Configuration
 */
public static Configuration from(InputStream is) {
  try {
    return Configuration.from(IOUtils.toString(is));
  } catch (IOException e) {
    throw DataXException.asDataXException(CommonErrorCode.CONFIG_ERROR,
        String.format("请检查您的配置文件. 您提供的配置文件读取失败,错误原因: %s. 请检查您的配置文件的权限设置.", e));
  }
}

代码示例来源:origin: ECNU-1X/DataX-Masking

/**
 * 从Map对象加载Configuration
 */
public static Configuration from(final Map<String, Object> object) {
  return Configuration.from(Configuration.toJSONString(object));
}

代码示例来源:origin: ECNU-1X/DataX-Masking

/**
 * 从List对象加载Configuration
 */
public static Configuration from(final List<Object> object) {
  return Configuration.from(Configuration.toJSONString(object));
}

代码示例来源:origin: ECNU-1X/DataX-Masking

/**
 * 根据用户提供的json path,寻址包含Configuration的List,如果对象不存在,返回默认null
 */
public List<Configuration> getListConfiguration(final String path) {
  List<Object> lists = getList(path);
  if (lists == null) {
    return null;
  }
  List<Configuration> result = new ArrayList<Configuration>();
  for (final Object object : lists) {
    result.add(Configuration.from(Configuration.toJSONString(object)));
  }
  return result;
}

代码示例来源:origin: ECNU-1X/DataX-Masking

/**
 * 从包括json的File对象加载Configuration
 */
public static Configuration from(File file) {
  try {
    return Configuration.from(IOUtils
        .toString(new FileInputStream(file)));
  } catch (FileNotFoundException e) {
    throw DataXException.asDataXException(CommonErrorCode.CONFIG_ERROR,
        String.format("配置信息错误,您提供的配置文件[%s]不存在. 请检查您的配置文件.", file.getAbsolutePath()));
  } catch (IOException e) {
    throw DataXException.asDataXException(
        CommonErrorCode.CONFIG_ERROR,
        String.format("配置信息错误. 您提供配置文件[%s]读取失败,错误原因: %s. 请检查您的配置文件的权限设置.",
            file.getAbsolutePath(), e));
  }
}

代码示例来源:origin: ECNU-1X/DataX-Masking

/**
 * 根据用户提供的json path,寻址包含Configuration的Map,如果对象不存在,返回默认null
 */
@SuppressWarnings("unchecked")
public Map<String, Configuration> getMapConfiguration(final String path) {
  Map<String, Object> map = this.get(path, Map.class);
  if (null == map) {
    return null;
  }
  Map<String, Configuration> result = new HashMap<String, Configuration>();
  for (final String key : map.keySet()) {
    result.put(key, Configuration.from(Configuration.toJSONString(map
        .get(key))));
  }
  return result;
}

代码示例来源:origin: ECNU-1X/DataX-Masking

public static void loadDriverClass(String pluginType, String pluginName) {
    try {
      String pluginJsonPath = StringUtils.join(
          new String[] { System.getProperty("datax.home"), "plugin",
              pluginType,
              String.format("%s%s", pluginName, pluginType),
              "plugin.json" }, File.separator);
      Configuration configuration = Configuration.from(new File(
          pluginJsonPath));
      List<String> drivers = configuration.getList("drivers",
          String.class);
      for (String driver : drivers) {
        Class.forName(driver);
      }
    } catch (ClassNotFoundException e) {
      throw DataXException.asDataXException(DBUtilErrorCode.CONF_ERROR,
          "数据库驱动加载错误, 请确认libs目录有驱动jar包且plugin.json中drivers配置驱动类正确!",
          e);
    }
  }
}

代码示例来源:origin: ECNU-1X/DataX-Masking

public static Configuration parseJobConfig(final String path) {
  String jobContent = getJobContent(path);
  Configuration config = Configuration.from(jobContent);
  return SecretUtil.decryptSecretKey(config);
}

代码示例来源:origin: ECNU-1X/DataX-Masking

/**
 * 用户指定部分path,获取Configuration的子集
 * <p/>
 * <br>
 * 如果path获取的路径或者对象不存在,返回null
 */
public Configuration getConfiguration(final String path) {
  Object object = this.get(path);
  if (null == object) {
    return null;
  }
  return Configuration.from(Configuration.toJSONString(object));
}

代码示例来源:origin: ECNU-1X/DataX-Masking

String value = mapEntry.get("value").toString();
Configuration eachColumnConfig = Configuration.from(recordJson);

代码示例来源:origin: ECNU-1X/DataX-Masking

/**
 * 拷贝当前Configuration,注意,这里使用了深拷贝,避免冲突
 */
public Configuration clone() {
  Configuration config = Configuration
      .from(Configuration.toJSONString(this.getInternal()));
  config.addSecretKeyPath(this.secretKeyPathSet);
  return config;
}

代码示例来源:origin: ECNU-1X/DataX-Masking

public static void preCheckPrePareSQL(Configuration originalConfig, DataBaseType type) {
  List<Object> conns = originalConfig.getList(Constant.CONN_MARK, Object.class);
  Configuration connConf = Configuration.from(conns.get(0).toString());
  String table = connConf.getList(Key.TABLE, String.class).get(0);
  List<String> preSqls = originalConfig.getList(Key.PRE_SQL,
      String.class);
  List<String> renderedPreSqls = WriterUtil.renderPreOrPostSqls(
      preSqls, table);
  if (null != renderedPreSqls && !renderedPreSqls.isEmpty()) {
    LOG.info("Begin to preCheck preSqls:[{}].",
        StringUtils.join(renderedPreSqls, ";"));
    for(String sql : renderedPreSqls) {
      try{
        DBUtil.sqlValid(sql, type);
      }catch(ParserException e) {
        throw RdbmsException.asPreSQLParserException(type,e,sql);
      }
    }
  }
}

代码示例来源:origin: ECNU-1X/DataX-Masking

private Record buildOneRecord(RecordSender recordSender,
      List<String> columns) {
    if (null == recordSender) {
      throw new IllegalArgumentException(
          "参数[recordSender]不能为空.");
    }
    if (null == columns || columns.isEmpty()) {
      throw new IllegalArgumentException(
          "参数[column]不能为空.");
    }
    Record record = recordSender.createRecord();
    try {
      for (String eachColumn : columns) {
        Configuration eachColumnConfig = Configuration.from(eachColumn);
        record.addColumn(this.buildOneColumn(eachColumnConfig));
      }
    } catch (Exception e) {
      throw DataXException.asDataXException(StreamReaderErrorCode.ILLEGAL_VALUE,
          "构造一个record失败.", e);
    }
    return record;
  }
}

代码示例来源:origin: ECNU-1X/DataX-Masking

public static void preCheckPostSQL(Configuration originalConfig, DataBaseType type) {
  List<Object> conns = originalConfig.getList(Constant.CONN_MARK, Object.class);
  Configuration connConf = Configuration.from(conns.get(0).toString());
  String table = connConf.getList(Key.TABLE, String.class).get(0);
  List<String> postSqls = originalConfig.getList(Key.POST_SQL,
      String.class);
  List<String> renderedPostSqls = WriterUtil.renderPreOrPostSqls(
      postSqls, table);
  if (null != renderedPostSqls && !renderedPostSqls.isEmpty()) {
    LOG.info("Begin to preCheck postSqls:[{}].",
        StringUtils.join(renderedPostSqls, ";"));
    for(String sql : renderedPostSqls) {
      try{
        DBUtil.sqlValid(sql, type);
      }catch(ParserException e){
        throw RdbmsException.asPostSQLParserException(type,e,sql);
      }
    }
  }
}

代码示例来源:origin: ECNU-1X/DataX-Masking

public static Configuration parseOnePluginConfig(final String path,
                         final String type,
                         Set<String> pluginSet, List<String> wantPluginNames) {
  String filePath = path + File.separator + "plugin.json";
  Configuration configuration = Configuration.from(new File(filePath));
  String pluginPath = configuration.getString("path");
  String pluginName = configuration.getString("name");
  if(!pluginSet.contains(pluginName)) {
    pluginSet.add(pluginName);
  } else {
    throw DataXException.asDataXException(FrameworkErrorCode.PLUGIN_INIT_ERROR, "插件加载失败,存在重复插件:" + filePath);
  }
  //不是想要的插件,返回null
  if (wantPluginNames != null && wantPluginNames.size() > 0 && !wantPluginNames.contains(pluginName)) {
    return null;
  }
  boolean isDefaultPath = StringUtils.isBlank(pluginPath);
  if (isDefaultPath) {
    configuration.set("path", path);
  }
  Configuration result = Configuration.newDefault();
  result.set(
      String.format("plugin.%s.%s", type, pluginName),
      configuration.getInternal());
  return result;
}

代码示例来源:origin: ECNU-1X/DataX-Masking

Configuration connConf = Configuration.from(connections.get(i).toString());

代码示例来源:origin: ECNU-1X/DataX-Masking

public void privilegeValid(Configuration originalConfig, DataBaseType dataBaseType) {
  /*检查insert 跟delete权限*/
  String username = originalConfig.getString(Key.USERNAME);
  String password = originalConfig.getString(Key.PASSWORD);
  List<Object> connections = originalConfig.getList(Constant.CONN_MARK,
      Object.class);
  for (int i = 0, len = connections.size(); i < len; i++) {
    Configuration connConf = Configuration.from(connections.get(i).toString());
    String jdbcUrl = connConf.getString(Key.JDBC_URL);
    List<String> expandedTables = connConf.getList(Key.TABLE, String.class);
    boolean hasInsertPri = DBUtil.checkInsertPrivilege(dataBaseType, jdbcUrl, username, password, expandedTables);
    if (!hasInsertPri) {
      throw RdbmsException.asInsertPriException(dataBaseType, originalConfig.getString(Key.USERNAME), jdbcUrl);
    }
    if (DBUtil.needCheckDeletePrivilege(originalConfig)) {
      boolean hasDeletePri = DBUtil.checkDeletePrivilege(dataBaseType, jdbcUrl, username, password, expandedTables);
      if (!hasDeletePri) {
        throw RdbmsException.asDeletePriException(dataBaseType, originalConfig.getString(Key.USERNAME), jdbcUrl);
      }
    }
  }
}

相关文章