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

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


                            if (!CollectionUtils.isEmpty(eventData)) {
                                startTime = eventData.get(0).getExecuteTime();
                            }

                            Channel channel = configClientService.findChannelByPipelineId(pipelineId);
                            RowBatch rowBatch = new RowBatch();
                            // 构造唯一标识
                            Identity identity = new Identity();
                            identity.setChannelId(channel.getId());
                            identity.setPipelineId(pipelineId);
                            identity.setProcessId(etlEventData.getProcessId());
                            rowBatch.setIdentity(identity);
                            // 进行数据合并
                            for (EventData data : eventData) {
                                rowBatch.merge(data);
                            }

                            long nextNodeId = etlEventData.getNextNid();
                            List<PipeKey> pipeKeys = rowDataPipeDelegate.put(new DbBatch(rowBatch), nextNodeId);
                            etlEventData.setDesc(pipeKeys);
View Full Code Here


    }

    // ======================== help method ===================
    // 保存对应的dbBatch
    private HttpPipeKey saveDbBatch(DbBatch dbBatch) {
        RowBatch rowBatch = dbBatch.getRowBatch();
        // 转化为proto对象
        BatchProto.RowBatch.Builder rowBatchBuilder = BatchProto.RowBatch.newBuilder();
        rowBatchBuilder.setIdentity(build(rowBatch.getIdentity()));
        // 处理具体的字段rowData
        for (EventData eventData : rowBatch.getDatas()) {
            BatchProto.RowData.Builder rowDataBuilder = BatchProto.RowData.newBuilder();
            rowDataBuilder.setPairId(eventData.getPairId());
            rowDataBuilder.setTableId(eventData.getTableId());
            if (eventData.getSchemaName() != null) {
                rowDataBuilder.setSchemaName(eventData.getSchemaName());
            }
            rowDataBuilder.setTableName(eventData.getTableName());
            rowDataBuilder.setEventType(eventData.getEventType().getValue());
            rowDataBuilder.setExecuteTime(eventData.getExecuteTime());
            // add by ljh at 2012-10-31
            if (eventData.getSyncMode() != null) {
                rowDataBuilder.setSyncMode(eventData.getSyncMode().getValue());
            }
            if (eventData.getSyncConsistency() != null) {
                rowDataBuilder.setSyncConsistency(eventData.getSyncConsistency().getValue());
            }

            // 构造key column
            for (EventColumn keyColumn : eventData.getKeys()) {
                rowDataBuilder.addKeys(buildColumn(keyColumn));
            }
            // 构造old key column
            if (CollectionUtils.isEmpty(eventData.getOldKeys()) == false) {
                for (EventColumn keyColumn : eventData.getOldKeys()) {
                    rowDataBuilder.addOldKeys(buildColumn(keyColumn));
                }
            }

            // 构造其他 column
            for (EventColumn column : eventData.getColumns()) {
                rowDataBuilder.addColumns(buildColumn(column));
            }

            rowDataBuilder.setRemedy(eventData.isRemedy());
            rowDataBuilder.setSize(eventData.getSize());
            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());
            }
            if (fileData.getPath() != null) {
                fileDataBuilder.setPath(fileData.getPath());
            }
            fileDataBuilder.setEventType(fileData.getEventType().getValue());
            fileDataBuilder.setSize(fileData.getSize());
            fileDataBuilder.setLastModifiedTime(fileData.getLastModifiedTime());

            fileBatchBuilder.addFiles(fileDataBuilder.build());// 添加一条fileData记录
        }
        // 处理构造对应的文件url
        String filename = buildFileName(rowBatch.getIdentity(), ClassUtils.getShortClassName(dbBatch.getClass()));
        // 写入数据
        File file = new File(htdocsDir, filename);
        OutputStream output = null;
        try {
            output = new BufferedOutputStream(new FileOutputStream(file));
            com.alibaba.otter.node.etl.model.protobuf.BatchProto.RowBatch rowBatchProto = rowBatchBuilder.build();
            output.write(ByteUtils.int2bytes(rowBatchProto.getSerializedSize()));//输出大小
            rowBatchProto.writeTo(output);//输出row batch

            com.alibaba.otter.node.etl.model.protobuf.BatchProto.FileBatch fileBatchProto = fileBatchBuilder.build();
            output.write(ByteUtils.int2bytes(fileBatchProto.getSerializedSize()));//输出大小
            fileBatchProto.writeTo(output); //输出file batch
            output.flush();
        } catch (IOException e) {
            throw new PipeException("write_byte_error", e);
        } finally {
            IOUtils.closeQuietly(output);
        }

        HttpPipeKey key = new HttpPipeKey();
        key.setUrl(remoteUrlBuilder.getUrl(rowBatch.getIdentity().getPipelineId(), filename));
        key.setDataType(PipeDataType.DB_BATCH);
        key.setIdentity(rowBatch.getIdentity());
        Pipeline pipeline = configClientService.findPipeline(rowBatch.getIdentity().getPipelineId());
        if (pipeline.getParameters().getUseFileEncrypt()) {
            // 加密处理
            EncryptedData encryptedData = encryptFile(file);
            key.setKey(encryptedData.getKey());
            key.setCrc(encryptedData.getCrc());
View Full Code Here

            byte[] lengthBytes = new byte[4];
            input.read(lengthBytes);
            int length = ByteUtils.bytes2int(lengthBytes);
            BatchProto.RowBatch rowbatchProto = BatchProto.RowBatch.parseFrom(new LimitedInputStream(input, length));
            // 构造原始的model对象
            RowBatch rowBatch = new RowBatch();
            rowBatch.setIdentity(build(rowbatchProto.getIdentity()));
            for (BatchProto.RowData rowDataProto : rowbatchProto.getRowsList()) {
                EventData eventData = new EventData();
                eventData.setPairId(rowDataProto.getPairId());
                eventData.setTableId(rowDataProto.getTableId());
                eventData.setTableName(rowDataProto.getTableName());
                eventData.setSchemaName(rowDataProto.getSchemaName());
                eventData.setEventType(EventType.valuesOf(rowDataProto.getEventType()));
                eventData.setExecuteTime(rowDataProto.getExecuteTime());
                // add by ljh at 2012-10-31
                if (StringUtils.isNotEmpty(rowDataProto.getSyncMode())) {
                    eventData.setSyncMode(SyncMode.valuesOf(rowDataProto.getSyncMode()));
                }
                if (StringUtils.isNotEmpty(rowDataProto.getSyncConsistency())) {
                    eventData.setSyncConsistency(SyncConsistency.valuesOf(rowDataProto.getSyncConsistency()));
                }
                // 处理主键
                List<EventColumn> keys = new ArrayList<EventColumn>();
                for (BatchProto.Column columnProto : rowDataProto.getKeysList()) {
                    keys.add(buildColumn(columnProto));
                }
                eventData.setKeys(keys);
                // 处理old主键
                if (CollectionUtils.isEmpty(rowDataProto.getOldKeysList()) == false) {
                    List<EventColumn> oldKeys = new ArrayList<EventColumn>();
                    for (BatchProto.Column columnProto : rowDataProto.getOldKeysList()) {
                        oldKeys.add(buildColumn(columnProto));
                    }
                    eventData.setOldKeys(oldKeys);
                }
                // 处理具体的column value
                List<EventColumn> columns = new ArrayList<EventColumn>();
                for (BatchProto.Column columnProto : rowDataProto.getColumnsList()) {
                    columns.add(buildColumn(columnProto));
                }
                eventData.setColumns(columns);

                eventData.setRemedy(rowDataProto.getRemedy());
                eventData.setSize(rowDataProto.getSize());
                // 添加到总记录
                rowBatch.merge(eventData);
            }
            dbBatch.setRowBatch(rowBatch);

            input.read(lengthBytes);
            length = ByteUtils.bytes2int(lengthBytes);
View Full Code Here

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

        RowBatch rowBatch = new RowBatch();
        rowBatch.setIdentity(identity);
        List<EventData> eventDatas = generatorEventDataForOracle(0, 20, EventType.INSERT);
        for (EventData eventData : eventDatas) {
            rowBatch.merge(eventData);
        }
        eventDatas = generatorEventDataForOracle(10, 10, EventType.INSERT);
        for (EventData eventData : eventDatas) {
            rowBatch.merge(eventData);
        }
        eventDatas = generatorEventDataForOracle(19, 1, EventType.DELETE);
        for (EventData eventData : eventDatas) {
            rowBatch.merge(eventData);
        }

        WeightController controller = new WeightController(1);
        dbLoadAction.load(rowBatch, controller);
    }
View Full Code Here

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

        RowBatch rowBatch = new RowBatch();
        rowBatch.setIdentity(identity);
        List<EventData> eventDatas = generatorEventDataForMysql(0, 20, EventType.INSERT);
        for (EventData eventData : eventDatas) {
            rowBatch.merge(eventData);
        }
        eventDatas = generatorEventDataForMysql(10, 10, EventType.INSERT);
        for (EventData eventData : eventDatas) {
            rowBatch.merge(eventData);
        }
        eventDatas = generatorEventDataForMysql(19, 1, EventType.DELETE);
        for (EventData eventData : eventDatas) {
            rowBatch.merge(eventData);
        }

        WeightController controller = new WeightController(1);
        dbLoadAction.load(rowBatch, controller);
    }
View Full Code Here

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

        RowBatch rowBatch = new RowBatch();
        rowBatch.setIdentity(identity);
        EventData eventData = new EventData();
        eventData.setTableId(1L);
        eventData.setSchemaName("srf");
        eventData.setTableName("columns");
        eventData.setEventType(EventType.UPDATE);
        eventData.setExecuteTime(100L);

        eventData.getKeys().add(buildColumn("id", Types.INTEGER, "1", true, false));
        eventData.getKeys().add(buildColumn("name", Types.VARCHAR, "ljh", true, false));

        eventData.getColumns().add(buildColumn("alias_name", Types.CHAR, "hello", false, false));
        eventData.getColumns().add(buildColumn("amount", Types.DECIMAL, "100.01", false, false));
        eventData.getColumns().add(buildColumn("text_b", Types.BLOB, "[116,101,120,116,95,98]", false, false));
        eventData.getColumns().add(buildColumn("text_c", Types.CLOB, "text_c", false, false));
        eventData.getColumns().add(buildColumn("curr_date", Types.DATE, "2011-01-01", false, false));
        eventData.getColumns().add(buildColumn("gmt_create", Types.TIMESTAMP, "2011-01-01 11:11:11", false, false));
        eventData.getColumns().add(buildColumn("gmt_modify", Types.TIMESTAMP, "2011-01-01 11:11:11", false, false));

        rowBatch.merge(eventData);

        Map<Class, BatchObject> batchs = otterTransformFactory.transform(rowBatch);
        RowBatch result = (RowBatch) batchs.get(EventData.class);
        want.number(result.getDatas().size()).isEqualTo(1);
    }
View Full Code Here

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

        RowBatch rowBatch = new RowBatch();
        rowBatch.setIdentity(identity);
        EventData eventData = new EventData();
        eventData.setTableId(1L);
        eventData.setSchemaName("srf");
        eventData.setTableName("columns");
        eventData.setEventType(EventType.UPDATE);
        eventData.setExecuteTime(100L);

        eventData.getKeys().add(buildColumn("id", Types.NUMERIC, "1", true, false));
        eventData.getKeys().add(buildColumn("name", Types.VARCHAR, "ljh", true, false));

        eventData.getColumns().add(buildColumn("alias_name", Types.CHAR, "hello", false, false));
        eventData.getColumns().add(buildColumn("amount", Types.NUMERIC, "100.01", false, false));
        eventData.getColumns().add(buildColumn("text_b", Types.BLOB, "[116,101,120,116,95,98]", false, false));
        eventData.getColumns().add(buildColumn("text_c", Types.CLOB, "text_c", false, false));
        eventData.getColumns().add(buildColumn("curr_date", Types.DATE, "2011-01-01", false, false));
        eventData.getColumns().add(buildColumn("gmt_create", Types.DATE, "2011-01-01 11:11:11", false, false));
        eventData.getColumns().add(buildColumn("gmt_modify", Types.DATE, "2011-01-01 11:11:11", false, false));

        rowBatch.merge(eventData);

        Map<Class, BatchObject> batchs = otterTransformFactory.transform(rowBatch);
        RowBatch result = (RowBatch) batchs.get(EventData.class);
        want.number(result.getDatas().size()).isEqualTo(1);
    }
View Full Code Here

        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();
        eventData.setTableId(1L);
        eventData.setSchemaName("otter");
        eventData.setTableName("test");
        eventData.setEventType(EventType.INSERT);
        eventData.setExecuteTime(100L);

        EventColumn primaryKey = new EventColumn();
        primaryKey.setColumnName("id");
        primaryKey.setColumnType(1);
        primaryKey.setColumnValue("1");
        primaryKey.setKey(true);
        primaryKey.setNull(false);
        eventData.getKeys().add(primaryKey);

        EventColumn column = new EventColumn();
        column.setColumnName("name");
        column.setColumnType(1);
        column.setColumnValue("test");
        column.setKey(false);
        column.setNull(false);
        eventData.getColumns().add(column);

        rowBatch.merge(eventData);

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

        } catch (Exception e) {
            want.fail();
        }

        DbBatch source = new DbBatch();
        RowBatch rowBatch = new RowBatch();
        Identity identity = new Identity();
        identity.setChannelId(100L);
        identity.setPipelineId(100L);
        identity.setProcessId(100L);
        rowBatch.setIdentity(identity);
        source.setRowBatch(rowBatch);

        MemoryPipeKey key = pipe.put(source);
        DbBatch target = pipe.get(key);
        want.bool(source == target).is(true);// 引用为同一个
View Full Code Here

        } catch (Exception e) {
            want.fail();
        }

        DbBatch source = new DbBatch();
        RowBatch rowBatch = new RowBatch();
        Identity identity = new Identity();
        identity.setChannelId(100L);
        identity.setPipelineId(100L);
        identity.setProcessId(100L);
        rowBatch.setIdentity(identity);
        source.setRowBatch(rowBatch);

        MemoryPipeKey key = pipe.put(source);
        try {
            Thread.sleep(1500L);
View Full Code Here

TOP

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

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.