Examples of FileBatch


Examples of com.alibaba.otter.shared.etl.model.FileBatch

        Identity identity = new Identity();
        identity.setChannelId(100L);
        identity.setPipelineId(100L);
        identity.setProcessId(100L);

        FileBatch fileBatch = new FileBatch();
        fileBatch.setIdentity(identity);

        fileBatch.getFiles().addAll(generatorLocalFileData("fileLoad", 10));
        FileBatch result = fileBatchConflictDetectService.detect(fileBatch, 1L);
        want.number(result.getFiles().size()).isEqualTo(0);

        NioUtils.delete(new File(tmp + File.separator + OTTERLOAD));
    }
View Full Code Here

Examples of com.alibaba.otter.shared.etl.model.FileBatch

        identity.setProcessId(100L);

        RowBatch rowBatch = new RowBatch();
        rowBatch.setIdentity(identity);

        FileBatch fileBatch = new FileBatch();
        fileBatch.setIdentity(identity);

        final DbBatch dbBatch = new DbBatch();
        dbBatch.setRowBatch(rowBatch);
        dbBatch.setFileBatch(fileBatch);
        final CountDownLatch latch = new CountDownLatch(1);
View Full Code Here

Examples of com.alibaba.otter.shared.etl.model.FileBatch

    /**
     * 具体冲突检测的行为
     */
    private FileBatch onFileConflictDetect(FileConflictDetectEvent event) {
        final FileBatch fileBatch = event.getFileBatch();
        if (CollectionUtils.isEmpty(fileBatch.getFiles())) {
            return fileBatch;
        }

        ExecutorTemplate executorTemplate = executorTemplateGetter.get();
        try {
            MDC.put(OtterConstants.splitPipelineLoadLogFileKey, String.valueOf(fileBatch.getIdentity().getPipelineId()));
            executorTemplate.start();
            // 重新设置下poolSize
            Pipeline pipeline = configClientService.findPipeline(fileBatch.getIdentity().getPipelineId());
            executorTemplate.adjustPoolSize(pipeline.getParameters().getFileLoadPoolSize());
            // 启动
            final List<FileData> result = Collections.synchronizedList(new ArrayList<FileData>());
            final List<FileData> filter = Collections.synchronizedList(new ArrayList<FileData>());
            for (final FileData source : fileBatch.getFiles()) {
                EventType type = source.getEventType();
                if (type.isDelete()) {
                    result.add(source);
                } else {
                    executorTemplate.submit(new Runnable() {

                        public void run() {
                            MDC.put(OtterConstants.splitPipelineLoadLogFileKey,
                                    String.valueOf(fileBatch.getIdentity().getPipelineId()));
                            // 处理更新类型
                            String namespace = source.getNameSpace();
                            String path = source.getPath();
                            FileData target = null;

                            int count = 0;
                            while (count++ < retry) {// 进行重试处理
                                try {
                                    if (true == StringUtils.isBlank(namespace)) {
                                        // local file
                                        java.io.File targetFile = new java.io.File(path);
                                        if (true == targetFile.exists()) {
                                            // modified time cost
                                            long lastModified = targetFile.lastModified();
                                            long size = targetFile.length();
                                            // 更新数据
                                            target = new FileData();
                                            target.setLastModifiedTime(lastModified);
                                            target.setSize(size);
                                        }
                                    } else {
                                        // remote file
                                        throw new RuntimeException(source + " is not support!");
                                    }

                                    break; // 不出异常就跳出
                                } catch (Exception ex) {
                                    target = null;
                                }
                            }

                            boolean shouldSync = false;
                            if (target != null) {
                                if (true == accept(target, source)) {
                                    shouldSync = true;
                                }
                            } else {
                                shouldSync = true;
                            }

                            if (true == shouldSync) {
                                result.add(source);
                            } else {
                                filter.add(source);
                            }
                        }
                    });
                }
            }
            // 等待所有都处理完成
            executorTemplate.waitForResult();

            if (pipeline.getParameters().getDumpEvent() && logger.isInfoEnabled()) {
                logger.info(FileloadDumper.dumpFilterFileDatas(fileBatch.getIdentity(), fileBatch.getFiles().size(),
                                                               result.size(), filter));
            }

            // 构造返回结果
            FileBatch target = new FileBatch();
            target.setIdentity(fileBatch.getIdentity());
            target.setFiles(result);
            return target;
        } finally {
            if (executorTemplate != null) {
                executorTemplateGetter.release(executorTemplate);
            }
View Full Code Here

Examples of com.alibaba.otter.shared.etl.model.FileBatch

                            otterExtractorFactory.extract(dbBatch);// 重新装配一下数据
                            if (dbBatch.getFileBatch() != null
                                && !CollectionUtils.isEmpty(dbBatch.getFileBatch().getFiles())
                                && pipeline.getParameters().getFileDetect()) { // 判断一下是否有文件同步,并且需要进行文件对比
                                // 对比一下中美图片是否有变化
                                FileBatch fileBatch = fileBatchConflictDetectService.detect(dbBatch.getFileBatch(),
                                                                                            nextNodeId);
                                dbBatch.setFileBatch(fileBatch);
                            }

                            List<PipeKey> pipeKeys = rowDataPipeDelegate.put(dbBatch, nextNodeId);
View Full Code Here

Examples of com.alibaba.otter.shared.etl.model.FileBatch

    private int                    retry  = 3;
    private ExecutorTemplateGetter executorTemplateGetter;

    public void extract(DbBatch dbBatch) throws ExtractException {
        List<FileData> fileDatas = doFileExtract(dbBatch.getRowBatch());
        FileBatch fileBatch = new FileBatch();
        fileBatch.setFiles(fileDatas);
        Identity identity = new Identity();
        identity.setChannelId(dbBatch.getRowBatch().getIdentity().getChannelId());
        identity.setPipelineId(dbBatch.getRowBatch().getIdentity().getPipelineId());
        identity.setProcessId(dbBatch.getRowBatch().getIdentity().getProcessId());
        fileBatch.setIdentity(identity);
        dbBatch.setFileBatch(fileBatch);
    }
View Full Code Here

Examples of com.alibaba.otter.shared.etl.model.FileBatch

    private ConfigClientService configClientService;
    private LoadInterceptor     dbInterceptor;

    public List<LoadContext> load(DbBatch data) {
        final RowBatch rowBatch = data.getRowBatch();
        final FileBatch fileBatch = data.getFileBatch();
        boolean existFileBatch = (rowBatch != null && !CollectionUtils.isEmpty(fileBatch.getFiles()) && data.getRoot() != null);
        boolean existRowBatch = (rowBatch != null && !CollectionUtils.isEmpty(rowBatch.getDatas()));

        int count = 0;
        List<RowBatch> rowBatchs = null;
        if (existRowBatch) {
View Full Code Here

Examples of com.alibaba.otter.shared.etl.model.FileBatch

        if (EventData.class.equals(clazz)) {
            RowBatch rowbatch = new RowBatch();
            rowbatch.setIdentity(identity);
            return rowbatch;
        } else if (FileData.class.equals(clazz)) {
            FileBatch fileBatch = new FileBatch();
            fileBatch.setIdentity(identity);
            return fileBatch;
        } else {
            throw new TransformException("no support Data[" + clazz.getName() + "]");
        }
    }
View Full Code Here

Examples of com.alibaba.otter.shared.etl.model.FileBatch

            }
            rowBatchBuilder.addRows(rowDataBuilder.build());// 添加一条rowData记录
        }

        // 处理下FileBatch
        FileBatch fileBatch = dbBatch.getFileBatch();
        BatchProto.FileBatch.Builder fileBatchBuilder = null;
        fileBatchBuilder = BatchProto.FileBatch.newBuilder();
        fileBatchBuilder.setIdentity(build(fileBatch.getIdentity()));
        // 构造对应的proto对象
        for (FileData fileData : fileBatch.getFiles()) {
            BatchProto.FileData.Builder fileDataBuilder = BatchProto.FileData.newBuilder();
            fileDataBuilder.setPairId(fileData.getPairId());
            fileDataBuilder.setTableId(fileData.getTableId());
            if (fileData.getNameSpace() != null) {
                fileDataBuilder.setNamespace(fileData.getNameSpace());
View Full Code Here

Examples of com.alibaba.otter.shared.etl.model.FileBatch

            input.read(lengthBytes);
            length = ByteUtils.bytes2int(lengthBytes);
            BatchProto.FileBatch filebatchProto = BatchProto.FileBatch.parseFrom(new LimitedInputStream(input, length));
            // 构造原始的model对象
            FileBatch fileBatch = new FileBatch();
            fileBatch.setIdentity(build(filebatchProto.getIdentity()));
            for (BatchProto.FileData fileDataProto : filebatchProto.getFilesList()) {
                FileData fileData = new FileData();
                fileData.setPairId(fileDataProto.getPairId());
                fileData.setTableId(fileDataProto.getTableId());
                fileData.setEventType(EventType.valuesOf(fileDataProto.getEventType()));
                fileData.setLastModifiedTime(fileDataProto.getLastModifiedTime());
                fileData.setNameSpace(fileDataProto.getNamespace());
                fileData.setPath(fileDataProto.getPath());
                fileData.setSize(fileDataProto.getSize());
                // 添加到filebatch中
                fileBatch.getFiles().add(fileData);
            }
            dbBatch.setFileBatch(fileBatch);
            return dbBatch;
        } catch (IOException e) {
            throw new PipeException("deserial_error", e);
View Full Code Here

Examples of com.alibaba.otter.shared.etl.model.FileBatch

            rowDataBuilder.setWithoutSchema(eventData.isWithoutSchema());
            rowBatchBuilder.addRows(rowDataBuilder.build());// 添加一条rowData记录
        }

        // 处理下FileBatch
        FileBatch fileBatch = dbBatch.getFileBatch();
        BatchProto.FileBatch.Builder fileBatchBuilder = null;
        fileBatchBuilder = BatchProto.FileBatch.newBuilder();
        fileBatchBuilder.setIdentity(build(fileBatch.getIdentity()));
        // 构造对应的proto对象
        for (FileData fileData : fileBatch.getFiles()) {
            BatchProto.FileData.Builder fileDataBuilder = BatchProto.FileData.newBuilder();
            fileDataBuilder.setPairId(fileData.getPairId());
            fileDataBuilder.setTableId(fileData.getTableId());
            if (fileData.getNameSpace() != null) {
                fileDataBuilder.setNamespace(fileData.getNameSpace());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.