拖拽控件User Defined Java Class
import java.io.File; import java.text.SimpleDateFormat; import java.util.*; import org.pentaho.di.core.exception.KettleException; import org.pentaho.di.core.plugins.PluginRegistry; import org.pentaho.di.core.plugins.RepositoryPluginType; import org.pentaho.di.job.Job; import org.pentaho.di.job.JobMeta; import org.pentaho.di.repository.RepositoriesMeta; import org.pentaho.di.repository.Repository; import org.pentaho.di.repository.RepositoryDirectoryInterface; import org.pentaho.di.repository.RepositoryElementMetaInterface; import org.pentaho.di.repository.RepositoryMeta; import org.pentaho.di.trans.Trans; import org.pentaho.di.trans.TransMeta; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.aliyun.openservices.oss.OSSClient; import com.aliyun.openservices.oss.model.GetObjectRequest; import com.aliyun.openservices.oss.model.OSSObjectSummary; import com.aliyun.openservices.oss.model.ObjectListing; private int accessIdIndex; private int accessKeyIndex; private int bucketNameIndex; private int prefixIndex; public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException { Object[] r=getRow(); if (r==null) { setOutputDone(); return false; } if (first) { accessIdIndex = getInputRowMeta().indexOfValue(getParameter("ACCESS_ID")); if (accessIdIndex<0) { throw new KettleException("accessId field not found in the input row, check parameter 'accessId'!"); } accessKeyIndex = getInputRowMeta().indexOfValue(getParameter("ACCESS_KEY")); if (accessKeyIndex<0) { throw new KettleException("accessKey field not found in the input row, check parameter 'accessKey'!"); } bucketNameIndex = getInputRowMeta().indexOfValue(getParameter("BUCKET_NAME")); if (bucketNameIndex<0) { throw new KettleException("bucketName field not found in the input row, check parameter 'bucketName'!"); } prefixIndex = getInputRowMeta().indexOfValue(getParameter("PREFIX")); if (prefixIndex<0) { throw new KettleException("prefix field not found in the input row, check parameter 'prefix'!"); } first=false; } Object[] outputRowData = RowDataUtil.resizeArray(r, data.outputRowMeta.size()); int outputIndex = getInputRowMeta().size(); String accessId = getInputRowMeta().getString(r, accessIdIndex); String accessKey = getInputRowMeta().getString(r, accessKeyIndex); String bucketName = getInputRowMeta().getString(r, bucketNameIndex); String prefix = getInputRowMeta().getString(r, prefixIndex); downAliyunLog(accessId, accessKey, bucketName, prefix); putRow(data.outputRowMeta, outputRowData); return true; } public void downAliyunLog(String accessId, String accessKey, String bucketName, String prefix) { OSSClient client = new OSSClient(accessId, accessKey); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DAY_OF_YEAR, -1); String date = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime()); ObjectListing ol = client.listObjects(bucketName, prefix + date); List yesterdayList = ol.getObjectSummaries(); date = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); ol = client.listObjects(bucketName, prefix + date); List todayList = ol.getObjectSummaries(); List list = new ArrayList(); list.addAll(yesterdayList); list.addAll(todayList); File downloadPath = new File(System.getProperty("LOG_FOLDER")); if(!downloadPath.exists()) downloadPath.mkdirs(); File downloadPathBak = new File(System.getProperty("DOWN_LOG_FOLDER")); if(!downloadPathBak.exists()) downloadPathBak.mkdirs(); List file = Arrays.asList(downloadPath.list()); List fileBak = Arrays.asList(downloadPathBak.list()); for (int i = 0; i < list.size(); i++) { OSSObjectSummary ossObjectSummary = (OSSObjectSummary) list.get(i); if(!file.contains(ossObjectSummary.getKey()) && !fileBak.contains(ossObjectSummary.getKey())) client.getObject(new GetObjectRequest(bucketName, ossObjectSummary.getKey()), new File(downloadPath, ossObjectSummary.getKey())); } System.out.println(list.size()); }
相关推荐
使用kettle批量下载文件的示例代码,一个主作业,一个下载作业,一个转换,这里可以从数据库里获取数据。
百度云进行下载 Kettle是一款国外开源的ETL工具,纯java编写,可以在Windows、Linux、Unix上运行,数据抽取高效稳定。 Kettle 中文名称叫水壶,该项目的主程序员MATT 希望把各种数据放到一个壶里,然后以一种指定的...
kettle是一个国外的,开源免费的数据库转储工具,能将多个数据可的数据信息进行简单有效的联动。(mysql导入到oracle,oracle导入MySQL,定时任务等等)图形化可视化操作简单快捷
kettle下载文件!!!经典例子!!
使用kettle批量下载文件的示例代码,详细内容可以查看博客对应的文章。
2020使用最新kettle批量下载文件,绝对物有所值。
使用Pentaho kettle 批量下载文件 的示例代码 包含三个文件,按执行顺序依次为:main.kjb、filelist.ktr、download.kjb。 压缩包中有2个版本的源码。 一个源码是从“txt文件”中读入URL路径,下载文件; 一个源码是...
springboot 集成kettle核心包依赖文件配置信息pom.xml
Kettle8.0清洗交易所DBF文件数据 Kettle8.0清洗交易所DBF文件数据 Kettle8.0清洗交易所DBF文件数据
pentaho kettle PDI 9.2下载
kettle 9.0 spoon9.0下载连接
使用Kettle获取MySQL日志文件名称
kettle9.0百度网盘下载链接
kettle批量解析多个xml文件,适合于批量数据导入,生产环境直接测试,肯定没有问题
此Demo为KETTLE-从ftp上下载txt文件插入到数据库中的原文件 需要的可下载参考 其中数据库信息需自己填写 包括字段什么的
NULL 博文链接:https://qq85609655.iteye.com/blog/2173882
pentaho kettle PDI 9.2下载
一个简单的例子,使用kettle将文本文件导入到数据库