forked from kiritbasu/datacollector
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduces Whole File Data Format along with Data parser and Data Generator. Whole File Data Parser: The Whole file Data Parser creates a record for each file with a FileRef Field and a metadata field for each file, so each record parsed is one for single file Whole file Data Generator: The Whole File Data Generator uses the record created by the Whole File Data Parser which contains information about the file and the File Stream Ref for creating a stream for reading, the generator treats one record as a whole file and transfer it in one shot (internally buffering and writing). Any errors during this operation will have to restarted from scratch, this indicates file transfer will not have a feature of resumability. Error handling using different generator format: Most of the existing data generator formats (TEXT, BINARY, DELIMITED) use getValueAs function which will by default fail during fileRef conversion. For Avro, Protobuf there is an augumented which will make sure the conversion fails. Metrics: The target will produce two metrics to keep track of the file transfer progress. 1) File Tranfer rate (bytes/sec) 2) Remaining bytes to be transferred. This patch also edits the existing sources to add this as a dummy group as the data format value is not in the list for supported data format chooser values. Upgrade: Given that all are new configurations introduced with default values, there is not an upgrade impact. Checksum Verification: The target when it reads the file also calculates the checksum and compare it with the checksum (if provided) in the file metadata of the record If the source system does not support checksum verification the record will be an error record. If the source system automatically verifies the checksum on file open the verifyChecksum configuration is ignored. If the source system provides the checksum in the file metadata and does not automatically verify the checksum, the target when it reads the file compares thc checksum during the stream close call. This patch also edits the existing sources to add this as a dummy group as the data format value is not in the list for supported data format chooser values. Change-Id: I2b667f76f93fd80c4b01893183297134a58f9e41 Reviewed-on: https://review.streamsets.net/3722 Tested-by: StreamSets CI <streamsets-ci-spam@streamsets.com> Reviewed-by: Alejandro Abdelnur <tucu@streamsets.com>
- Loading branch information
1 parent
1881b93
commit d6fac73
Showing
56 changed files
with
2,176 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
commonlib/src/main/java/com/streamsets/pipeline/lib/generator/wholefile/Errors.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* Copyright 2016 StreamSets Inc. | ||
* | ||
* Licensed under the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.streamsets.pipeline.lib.generator.wholefile; | ||
|
||
import com.streamsets.pipeline.api.ErrorCode; | ||
|
||
public enum Errors implements ErrorCode { | ||
WHOLE_FILE_GENERATOR_ERROR_0("Record does not contain the mandatory field {} for Whole File Format."), | ||
; | ||
|
||
private final String msg; | ||
|
||
Errors(String msg) { | ||
this.msg = msg; | ||
} | ||
|
||
@Override | ||
public String getCode() { | ||
return name(); | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return msg; | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
...src/main/java/com/streamsets/pipeline/lib/generator/wholefile/WholeFileDataGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/** | ||
* Copyright 2016 StreamSets Inc. | ||
* | ||
* Licensed under the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.streamsets.pipeline.lib.generator.wholefile; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.streamsets.pipeline.api.FileRef; | ||
import com.streamsets.pipeline.api.Record; | ||
import com.streamsets.pipeline.api.Stage; | ||
import com.streamsets.pipeline.lib.generator.DataGenerator; | ||
import com.streamsets.pipeline.lib.generator.DataGeneratorException; | ||
import org.apache.commons.io.IOUtils; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.nio.ByteBuffer; | ||
import java.nio.channels.Channels; | ||
import java.nio.channels.ReadableByteChannel; | ||
import java.nio.channels.WritableByteChannel; | ||
import java.util.List; | ||
|
||
public class WholeFileDataGenerator implements DataGenerator { | ||
private static final String FILE_REF = "/fileRef"; | ||
private static final String FILE_INFO = "/fileInfo"; | ||
private static final List<String> MANDATORY_FIELD_PATHS = ImmutableList.of(FILE_REF, FILE_INFO); | ||
private final Stage.Context context; | ||
private final OutputStream outputStream; | ||
|
||
WholeFileDataGenerator( | ||
Stage.Context context, | ||
OutputStream os | ||
) throws IOException { | ||
this.context = context; | ||
this.outputStream = os; | ||
} | ||
|
||
private void validateRecord(Record record) throws DataGeneratorException { | ||
for (String fieldPath : MANDATORY_FIELD_PATHS) { | ||
if (!record.has(fieldPath)) { | ||
throw new DataGeneratorException(Errors.WHOLE_FILE_GENERATOR_ERROR_0, fieldPath); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void write(Record record) throws IOException, DataGeneratorException { | ||
validateRecord(record); | ||
FileRef fileRef = record.get(FILE_REF).getValueAsFileRef(); | ||
int bufferSize = fileRef.getBufferSize(); | ||
boolean canUseDirectByteBuffer = fileRef.getSupportedStreamClasses().contains(ReadableByteChannel.class); | ||
if (canUseDirectByteBuffer) { | ||
WritableByteChannel writableByteChannel = Channels.newChannel(outputStream); | ||
try (ReadableByteChannel readableByteChannel = fileRef.createInputStream(context, ReadableByteChannel.class)){ | ||
ByteBuffer buffer = ByteBuffer.allocateDirect(bufferSize); | ||
while ((readableByteChannel.read(buffer)) > 0) { | ||
//Flip to use the buffer from 0 to position. | ||
buffer.flip(); | ||
while (buffer.hasRemaining()) { | ||
writableByteChannel.write(buffer); | ||
} | ||
//Compact the buffer for reuse. | ||
buffer.clear(); | ||
} | ||
} | ||
} else { | ||
byte[] b = new byte[bufferSize]; | ||
try (InputStream stream = fileRef.createInputStream(context, InputStream.class)) { | ||
IOUtils.copyLarge(stream, outputStream, b); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void flush() throws IOException { | ||
outputStream.flush(); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
outputStream.close(); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...n/java/com/streamsets/pipeline/lib/generator/wholefile/WholeFileDataGeneratorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* Copyright 2016 StreamSets Inc. | ||
* | ||
* Licensed under the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.streamsets.pipeline.lib.generator.wholefile; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.google.common.collect.ImmutableSet; | ||
import com.streamsets.pipeline.lib.generator.DataGenerator; | ||
import com.streamsets.pipeline.lib.generator.DataGeneratorFactory; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public class WholeFileDataGeneratorFactory extends DataGeneratorFactory { | ||
public static final Map<String, Object> CONFIGS = ImmutableMap.of(); | ||
public static final Set<Class<? extends Enum>> MODES = ImmutableSet.of(); | ||
|
||
public WholeFileDataGeneratorFactory(Settings settings) { | ||
super(settings); | ||
} | ||
|
||
@Override | ||
public DataGenerator getGenerator(OutputStream os) throws IOException { | ||
return new WholeFileDataGenerator(getSettings().getContext(), os); | ||
} | ||
} |
Oops, something went wrong.