Package com.alibaba.otter.shared.etl.model

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


        if (fileInfos == null || fileInfos.length == 0) {
            return new ArrayList<FileData>();
        } else {
            List<FileData> fileDatas = new ArrayList<FileData>();
            for (FileInfo fileInfo : fileInfos) {
                FileData fileData = new FileData();
                fileData.setPairId(pairId); // 记录一下具体映射规则的id
                fileData.setTableId(eventData.getTableId());
                fileData.setEventType(eventData.getEventType());
                fileData.setLastModifiedTime(fileInfo.getLastModifiedTime());
                fileData.setNameSpace(fileInfo.getNamespace());
                fileData.setPath(fileInfo.getPath());
                fileData.setSize(fileInfo.getSize());
                fileDatas.add(fileData);
            }
            return fileDatas;
        }
    }
View Full Code Here


            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;
View Full Code Here

    protected List<FileData> buildFileDatas(String namespace, EventType eventType, int start, int count, boolean create)
                                                                                                                        throws IOException {
        List<FileData> files = new ArrayList<FileData>();

        for (int i = start; i < count; i++) {
            FileData fileData = new FileData();
            fileData.setNameSpace(namespace); // namespace is null means file is
                                              // local file
            fileData.setEventType(eventType);
            fileData.setPairId(i % NUMBER_OF_FILE_DATA_COPIES);
            fileData.setPath(ROOT_DIR.getAbsolutePath() + "/target/" + eventType.getValue() + i);

            String parentPath = ROOT_DIR.getPath();
            if (namespace != null) {
                parentPath = parentPath + "/" + namespace;
            }
            File file = new File(parentPath, fileData.getPath());
            if (!file.exists() && create) {
                FileUtils.touch(file);
            }

            fileData.setSize(file.exists() ? file.length() : 0);
            fileData.setLastModifiedTime(file.exists() ? file.lastModified() : Calendar.getInstance().getTimeInMillis());
            fileData.setTableId(TABLE_ID);

            files.add(fileData);
        }

        return files;
View Full Code Here

        List<FileData> result = new ArrayList<FileData>();
        String target = tmp + File.separator + OTTERLOAD + "_loaded/";
        for (int i = 0; i < count; i++) {
            String filepath = tmp + File.separator + OTTERLOAD + target;
            File local = new File(filepath, prefix + "_" + i + ".jpg");
            FileData localFileData = new FileData();
            localFileData.setPairId(i);
            localFileData.setTableId(i);
            localFileData.setPath(target + local.getName());
            localFileData.setLastModifiedTime(new Date().getTime());
            try {
                byte[] data = getBlock((i + 1) * 1024);
                localFileData.setSize(data.length);
                NioUtils.write(data, local);
            } catch (IOException e) {
                want.fail();
            }
            result.add(localFileData);
View Full Code Here

        identity.setProcessId(100L);

        FileBatch fileBatch = new FileBatch();
        fileBatch.setIdentity(identity);
        File localFile = new File("/tmp", "httpPipeTest.jpg");
        FileData localFileData = new FileData();
        localFileData.setTableId(1L);
        localFileData.setPairId(1L);
        localFileData.setPath(localFile.getPath());
        fileBatch.getFiles().add(localFileData);

        Map<Class, BatchObject> batchs = otterTransformFactory.transform(fileBatch);
        FileBatch result = (FileBatch) batchs.get(FileData.class);
        want.number(result.getFiles().size()).isEqualTo(1);
View Full Code Here

        identity.setProcessId(100L);

        FileBatch fileBatch = new FileBatch();
        fileBatch.setIdentity(identity);
        File localFile = new File(tmp, "httpPipeTest.jpg");
        FileData localFileData = new FileData();
        localFileData.setEventType(EventType.INSERT);
        localFileData.setPath(localFile.getPath());
        fileBatch.getFiles().add(localFileData);
        try {
            byte[] data = getBlock(10 * 1024);
            NioUtils.write(data, localFile);
            HttpPipeKey key = attachmentHttpPipe.put(fileBatch);
View Full Code Here

        identity.setProcessId(100L);

        FileBatch fileBatch = new FileBatch();
        fileBatch.setIdentity(identity);
        File localFile = new File(tmp, "httpPipeTest.jpg");
        FileData localFileData = new FileData();
        localFileData.setPath(localFile.getPath());
        localFileData.setEventType(EventType.INSERT);
        localFileData.setLastModifiedTime(new Date().getTime());
        localFileData.setSize(100L);
        localFileData.setTableId(1L);
        fileBatch.getFiles().add(localFileData);

        RowBatch rowBatch = new RowBatch();
        rowBatch.setIdentity(identity);
        EventData eventData = new EventData();
View Full Code Here

    private List<FileData> generatorLocalFileData(String prefix, int count) {
        List<FileData> result = new ArrayList<FileData>();
        for (int i = 0; i < count; i++) {
            String filepath = tmp + File.separator + OTTERLOAD + File.separator;
            File local = new File(filepath, prefix + "_" + i + ".jpg");
            FileData localFileData = new FileData();
            localFileData.setEventType(EventType.UPDATE);
            localFileData.setPairId(i);
            localFileData.setTableId(i);
            localFileData.setNameSpace(null);
            localFileData.setPath(local.getPath());
            try {
                byte[] data = getBlock((i + 1) * 1024);
                localFileData.setSize(data.length);
                NioUtils.write(data, local);
                localFileData.setLastModifiedTime(local.lastModified());
            } catch (IOException e) {
                want.fail();
            }
            result.add(localFileData);
        }
View Full Code Here

        File file = new File("/tmp/otter/test");
        Collection<File> allFiles = FileUtils.listFiles(file, new String[] { "jpg" }, true);

        List<FileData> fileDatas = new ArrayList<FileData>();
        for (File files : allFiles) {
            FileData data = new FileData();
            // data.setPath("wsproduct_repository/product_sku/76/84/32/84/768432847_10.summ.jpg");
            data.setPath(StringUtils.substringAfter(files.getAbsolutePath(), "/tmp/otter/test"));
            fileDatas.add(data);
        }

        File archiveFile = new File("/tmp/otter/test.gzip");
        if (archiveFile.exists()) {
View Full Code Here

                            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

TOP

Related Classes of com.alibaba.otter.shared.etl.model.FileData

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.