Package com.dp.nebula.wormhole.common.interfaces

Examples of com.dp.nebula.wormhole.common.interfaces.IParam


      }
      for(int j = 0; j < concurrency; j++){
        if(sqlArray[j] == null) {
          continue;
        }
        IParam paramSplitted = param.clone();
        paramSplitted.putValue(ParamKey.sql, sqlArray[j].toString());
        paramList.add(paramSplitted);
      }
    }
    return paramList;
  }
View Full Code Here


  @Override
  public List<IParam> split() {
    List<IParam> paramList = new ArrayList<IParam>() ;
    if(!needSplit) {
      IParam paramNoSplitted = param.clone();
      if(sql.isEmpty()&&!tableName.isEmpty()&&!columns.isEmpty()){
        String noSplitSql = "";
        if(!where.isEmpty()) {
          noSplitSql = String.format(SQL_WITH_WHERE_PATTEN, columns, tableName, where);
        } else {
          noSplitSql = String.format(SQL_WITHOUT_WHERE_PATTEN, columns, tableName);
        }
        paramNoSplitted.putValue(ParamKey.sql, noSplitSql);
      }
      paramList.add(paramNoSplitted);
      return paramList;
    }
    if(autoIncKey.isEmpty()){
      return candidateSplitter.split();
    }
    logger.info("Mysql reader start to split");
    try {
      conn = DBSource.getConnection(MysqlReader.class, ip, port, dbname);
    } catch (Exception e) {
      throw new WormholeException(e, JobStatus.READ_CONNECTION_FAILED.getStatus() + MysqlReader.ERROR_CODE_ADD);
    }
    String rangeSql = "";
    if(!where.isEmpty()) {
      rangeSql = String.format(RANGE_SQL_WITH_WHERE_PATTERN, autoIncKey,autoIncKey,tableName,where);
    } else {
      rangeSql = String.format(RANGE_SQL_WITHOUT_WHERE_PATTERN, autoIncKey,autoIncKey,tableName);
    }
    long min=0,max=0;
   
    try {
      logger.debug("RangeSql: " + rangeSql);
      ResultSet rs = DBUtils.query(conn, rangeSql);
      rs.next();
      min = rs.getInt(1);
      max = rs.getInt(2);
      rs.close();
    } catch (Exception e) {
      logger.error(e.getMessage(),e);
      throw new WormholeException(e,JobStatus.READ_FAILED.getStatus()+MysqlReader.ERROR_CODE_ADD);
    }
    long start = min - 1;
    long end = min - 1 + blockSize;
    StringBuilder []sqlArray = new StringBuilder[concurrency];
    for(long i = 0; i <= (max-min)/blockSize; i++){
      String sqlSplitted = null;
      if(!where.isEmpty()) {
        sqlSplitted = String.format(SPLIT_SQL_WITH_WHERE_PATTEN, columns, tableName, where, autoIncKey, start, autoIncKey,end);
      } else {
        sqlSplitted = String.format(SPLIT_SQL_WITHOUT_WHERE_PATTEN, columns, tableName, autoIncKey, start, autoIncKey,end);
      }
      int index = (int) (i%concurrency);
      if(sqlArray[index] == null){
        sqlArray[index] new StringBuilder();
      }
      sqlArray[index].append(sqlSplitted).append(";") ;
      start += blockSize;
      end += blockSize;
      if(end > max) {
        end = max;
      }
    }
    for(int j = 0; j < concurrency; j++){
      if(sqlArray[j] == null) {
        continue;
      }
      IParam paramSplitted = param.clone();
      paramSplitted.putValue(ParamKey.sql, sqlArray[j].toString());
      paramList.add(paramSplitted);
    }
    logger.info("Mysql reader is splitted successfully");
    return paramList;
  }
View Full Code Here

   
    JobPluginConf readerConf =  jobConf.getReaderConf();
    List<JobPluginConf> writerConf = jobConf.getWriterConfs();
   
    assertEquals("hivereader", readerConf.getPluginName());
    IParam readerPluginParam = readerConf.getPluginParam();
    assertNotNull(readerPluginParam);
    assertTrue(readerPluginParam instanceof IParam);
   
    assertNotNull(writerConf);
    assertEquals(1, writerConf.size());
View Full Code Here

    }
  }

  @Test
  public void testLoadEngineConfig() {
    IParam engineConf = ParseXMLUtil.loadEngineConfig();
    assertNotNull(engineConf);
    assertNotNull(engineConf.getValue("storageClassName"));
  }
View Full Code Here

          sb.append(",");
        }
      }
      target = sb.toString();

      IParam readerPluginParam = pluginReg
          .get(readerConf.getPluginName());
      s_logger.info("Start Reader Threads");
      ReaderManager readerManager = ReaderManager.getInstance(
          storageManager, monitorManager);
      readerManager.run(readerConf, readerPluginParam);
View Full Code Here

    else {
      s_logger.error("Usage: ./wormhole.sh job.xml .");
      System.exit(JobStatus.FAILED.getStatus());
    }
    JobConf jobConf = null;
    IParam engineConf = null;
    Map<String, IParam> pluginConfs = null;
    try {
      // read configurations from XML for engine & plugins
      jobConf = ParseXMLUtil.loadJobConf(jobDescriptionXML);
      engineConf = ParseXMLUtil.loadEngineConfig();
View Full Code Here

    params.put(key, value);
  }
 
  public IParam clone(){
    Map<String,String> map  = new HashMap<String,String>();
    IParam result = new DefaultParam(map);
    for(String key : params.keySet()){
      map.put(key, params.get(key));
    }
    return result;
  }
View Full Code Here

      try {
        Configuration conf = DFSUtils.getConf(sourceDir, null);
        fs = DFSUtils.createFileSystem(new URI(sourceDir), conf);
        FileStatus[] files = fs.listStatus(new Path(sourceDir));
        for (FileStatus fileStatus : files) {
          IParam p = param.clone();
          p.putValue(ParamKey.dataDir, fileStatus.getPath()
              .toString());
          result.add(p);
        }
      } catch (Exception e) {
        throw new WormholeException(e,
View Full Code Here

    if(autoIncKey.isEmpty() || tableName.isEmpty()){
      logger.warn("AutoIncKey or tableName is empty, sqlserverReader  cannot split!");
      needSplit = false;
    }
    if(!needSplit) {
      IParam paramNoSplitted = param.clone();
      if(!tableName.isEmpty()){
        String noSplitSql = "";
        if(!where.isEmpty()) {
          noSplitSql = String.format(SQL_WITH_WHERE_PATTEN, columns, tableName, where);
        } else {
          noSplitSql = String.format(SQL_WITHOUT_WHERE_PATTEN, columns, tableName);
        }
        paramNoSplitted.putValue(ParamKey.sql, noSplitSql);
      }
      paramList.add(paramNoSplitted);
      return paramList;
    }
   
    logger.info("Sqlserver reader start to split");

    String rangeSql = "";
    if(!where.isEmpty()) {
      rangeSql = String.format(RANGE_SQL_WITH_WHERE_PATTERN, autoIncKey,autoIncKey,tableName,where);
    } else {
      rangeSql = String.format(RANGE_SQL_WITHOUT_WHERE_PATTERN, autoIncKey,autoIncKey,tableName);
    }
    long min=0,max=0;
   
    try {
      logger.debug(rangeSql);
      ResultSet rs = DBUtils.query(conn, rangeSql);
      rs.next();
      min = rs.getInt(1);
      max = rs.getInt(2);
      rs.close();
    } catch (Exception e) {
      logger.error(e.getMessage(),e);
      throw new WormholeException(e,JobStatus.READ_FAILED.getStatus()+SqlserverReader.ERROR_CODE_ADD);
    }
    long start = min - 1;
    long end = min - 1 + blockSize;
    StringBuilder []sqlArray = new StringBuilder[concurrency];
    for(long i = 0; i <= (max-min)/blockSize; i++){
      String sqlSplitted = null;
      if(!where.isEmpty()) {
        sqlSplitted = String.format(SPLIT_SQL_WITH_WHERE_PATTEN, columns, tableName, where, autoIncKey, start, autoIncKey,end);
      } else {
        sqlSplitted = String.format(SPLIT_SQL_WITHOUT_WHERE_PATTEN, columns, tableName, autoIncKey, start, autoIncKey,end);
      }
      int index = (int) (i%concurrency);
      if(sqlArray[index] == null){
        sqlArray[index] new StringBuilder();
      }
      sqlArray[index].append(sqlSplitted).append(";") ;
      start += blockSize;
      end += blockSize;
      if(end > max) {
        end = max;
      }
    }
    for(int j = 0; j < concurrency; j++){
      if(sqlArray[j] == null) {
        continue;
      }
      IParam paramSplitted = param.clone();
      paramSplitted.putValue(ParamKey.sql, sqlArray[j].toString());
      paramList.add(paramSplitted);
    }
    logger.info("sqlServer reader is splitted successfully");
    return paramList;
  }
View Full Code Here

            if (lsEntry.getAttrs().isDir()) {
              continue;
            }

            IParam oParams = param.clone();
           
            String dir = oneDir;
            String absolutePath = null;
            if (containsWildcardCharacter){
              dir = oneDir.substring(0, oneDir.lastIndexOf('/'));
              absolutePath = dir + "/"
              + lsEntry.getFilename();
            }else {
              if (!isDirectory){
                absolutePath = dir;
              }else{
                absolutePath = dir + "/" + lsEntry.getFilename();
              }
            }
           
            LOGGER.info(ParamKey.dir + " split filename:"
                + absolutePath + "\tfile length:"
                + lsEntry.getAttrs().getSize());

            oParams.putValue(ParamKey.dir, absolutePath);
            paramsList.add(oParams);
           
          }
        }
        c.disconnect();
View Full Code Here

TOP

Related Classes of com.dp.nebula.wormhole.common.interfaces.IParam

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.