X11DatasetHandler.java 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package com.primeton.damp.core.dataset;
  2. import com.primeton.damp.config.DataShardConfig;
  3. import com.primeton.damp.fileclient.*;
  4. import lombok.extern.slf4j.Slf4j;
  5. import org.apache.commons.lang.StringUtils;
  6. import org.apache.hadoop.fs.FileSystem;
  7. import org.springframework.beans.factory.FactoryBean;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.stereotype.Component;
  10. import java.util.Properties;
  11. /**
  12. * <pre>
  13. *
  14. * Created by zhaopx.
  15. * User: zhaopx
  16. * Date: 2021/3/31
  17. * Time: 13:17
  18. *
  19. * </pre>
  20. *
  21. * @author zhaopx
  22. */
  23. @Component
  24. @Slf4j
  25. public class X11DatasetHandler implements FactoryBean<X11ClientHandler> {
  26. /**
  27. * DataShard 配置
  28. */
  29. @Autowired
  30. DataShardConfig dataShardConfig;
  31. @Autowired
  32. FileSystem fs;
  33. @Override
  34. public X11ClientHandler getObject() throws Exception {
  35. if(StringUtils.isBlank(dataShardConfig.getType()) || "local".equalsIgnoreCase(dataShardConfig.getType())) {
  36. return new LocalFsClientHandler(dataShardConfig.getBasePath());
  37. } else if("hdfs".equalsIgnoreCase(dataShardConfig.getType())) {
  38. return new HdfsClientHandler(fs);
  39. } else if("sftp".equalsIgnoreCase(dataShardConfig.getType())) {
  40. return new SftpClientHandler((String) dataShardConfig.getSftp().get("host"),
  41. (Integer) dataShardConfig.getSftp().get("port"),
  42. (String) dataShardConfig.getSftp().get("username"),
  43. (String) dataShardConfig.getSftp().get("password"),
  44. new Properties());
  45. } else if("ftp".equalsIgnoreCase(dataShardConfig.getType())) {
  46. return new FtpClientHandler((String) dataShardConfig.getFtp().get("host"),
  47. (Integer) dataShardConfig.getFtp().get("port"),
  48. (String) dataShardConfig.getFtp().get("username"),
  49. (String) dataShardConfig.getFtp().get("password"),
  50. new Properties());
  51. } else {
  52. throw new IllegalArgumentException("Illegal config datashard.type: " + dataShardConfig.getType());
  53. }
  54. }
  55. @Override
  56. public Class<?> getObjectType() {
  57. return X11ClientHandler.class;
  58. }
  59. }