use of org.talend.daikon.exception.TalendRuntimeException in project tdq-studio-se by Talend.
the class AnalysisExecutor method needChangeCatalog.
/**
* return true if the connection need to set the catalog, otherwise return false.
* <p>
* The list of databases which don't need to change the catalog:
* <p>
* Odbc Mssql
* <p>
* Odbc Oracle
* <p>
* Odbc Progress
* <p>
* Odbc Teradata
* <p>
* Exasol
* <p>
* Hive
* <p>
* Mysql: because there will generate the sql statement with fully qualified name before the table name,so no need to change
* the catalog of the connection here
* <p>
*
* @return need to change the catalog or not
*/
protected boolean needChangeCatalog(java.sql.Connection connection) {
boolean result = true;
try {
DatabaseMetaData metadata = ExtractMetaDataUtils.getInstance().getConnectionMetadata(connection);
result = !(ConnectionUtils.isOdbcMssql(connection) || ConnectionUtils.isOdbcOracle(connection) || ConnectionUtils.isOdbcProgress(connection) || ConnectionUtils.isOdbcTeradata(connection) || org.talend.utils.sql.ConnectionUtils.isExasol(metadata) || ExtractMetaDataUtils.getInstance().isHiveConnection(connection) || ConnectionUtils.isMysql(connection));
} catch (TalendRuntimeException e) {
traceError(e.getMessage());
result = Boolean.FALSE;
} catch (SQLException e) {
traceError(e.getMessage());
result = Boolean.FALSE;
}
return result;
}
use of org.talend.daikon.exception.TalendRuntimeException in project components by Talend.
the class SimpleFileIOOutputErrorTest method testUnauthorizedAccess.
/**
* Basic unit test using all default values (except for the path) on an in-memory DFS cluster.
*/
@Test
public void testUnauthorizedAccess() throws IOException, URISyntaxException {
Path parent = new Path(mini.newFolder().toString());
String fileSpec = mini.getLocalFs().getUri().resolve(new Path(parent, "output.csv").toUri()).toString();
// Ensure that the parent is unwritable.
FileUtil.chmod(parent.toUri().toString(), "000", true);
// Requesting a wrong execution engine causes an exception.
thrown.expect(TalendRuntimeException.class);
thrown.expect(hasProperty("code", is(SimpleFileIOErrorCode.OUTPUT_NOT_AUTHORIZED)));
thrown.expectMessage("Can not write to " + fileSpec + ". Please check user permissions or existence of base directory.");
// Now try using the component.
try {
// Configure the component.
SimpleFileIOOutputProperties props = SimpleFileIOOutputRuntimeTest.createOutputComponentProperties();
props.getDatasetProperties().path.setValue(fileSpec);
// Create the runtime.
SimpleFileIOOutputRuntime runtime = new SimpleFileIOOutputRuntime();
runtime.initialize(null, props);
// Use the runtime in a direct pipeline to test.
final Pipeline p = beam.createPipeline();
PCollection<IndexedRecord> input = //
p.apply(//
Create.of(//
ConvertToIndexedRecord.convertToAvro(new String[] { "1", "one" }), //
ConvertToIndexedRecord.convertToAvro(new String[] { "2", "two" })));
input.apply(runtime);
// And run the test.
p.run().waitUntilFinish();
} catch (Pipeline.PipelineExecutionException e) {
if (e.getCause() instanceof TalendRuntimeException)
throw (TalendRuntimeException) e.getCause();
throw e;
}
// Check the expected values.
mini.assertReadFile(mini.getLocalFs(), fileSpec, "1;one", "2;two");
}
use of org.talend.daikon.exception.TalendRuntimeException in project components by Talend.
the class SimpleFileIOOutputRuntimeTest method testTryToOverwrite.
/**
* Basic unit test using all default values (except for the path) on an in-memory DFS cluster.
*/
@Test
public void testTryToOverwrite() throws IOException, URISyntaxException {
Path parent = new Path(mini.newFolder().toString());
Path dst = new Path(parent, "output");
String fileSpec = mini.getLocalFs().getUri().resolve(dst.toUri()).toString();
// Write something to the file before trying to run.
try (OutputStream out = mini.getLocalFs().create(new Path(dst, "part-00000"))) {
out.write(0);
}
// Now try using the component.
try {
// Configure the component.
SimpleFileIOOutputProperties props = SimpleFileIOOutputRuntimeTest.createOutputComponentProperties();
props.getDatasetProperties().path.setValue(fileSpec);
props.overwrite.setValue(true);
// Create the runtime.
SimpleFileIOOutputRuntime runtime = new SimpleFileIOOutputRuntime();
runtime.initialize(null, props);
// Use the runtime in a direct pipeline to test.
final Pipeline p = beam.createPipeline();
PCollection<IndexedRecord> input = //
p.apply(//
Create.of(//
ConvertToIndexedRecord.convertToAvro(new String[] { "1", "one" }), //
ConvertToIndexedRecord.convertToAvro(new String[] { "2", "two" })));
input.apply(runtime);
// And run the test.
runtime.runAtDriver(null);
p.run().waitUntilFinish();
} catch (Pipeline.PipelineExecutionException e) {
if (e.getCause() instanceof TalendRuntimeException)
throw (TalendRuntimeException) e.getCause();
throw e;
}
// Check the expected values, which should be overwritten.
mini.assertReadFile(mini.getLocalFs(), fileSpec, "1;one", "2;two");
}
use of org.talend.daikon.exception.TalendRuntimeException in project components by Talend.
the class SimpleFileIODatasetRuntime method getSample.
@Override
public void getSample(int limit, Consumer<IndexedRecord> consumer) {
// Create an input runtime based on the properties.
SimpleFileIOInputRuntime inputRuntime = new SimpleFileIOInputRuntime();
SimpleFileIOInputProperties inputProperties = new SimpleFileIOInputProperties(null);
inputProperties.limit.setValue(limit);
inputProperties.init();
inputProperties.setDatasetProperties(properties);
inputRuntime.initialize(null, inputProperties);
// Create a pipeline using the input component to get records.
DirectOptions options = BeamLocalRunnerOption.getOptions();
final Pipeline p = Pipeline.create(options);
try (DirectConsumerCollector<IndexedRecord> collector = DirectConsumerCollector.of(consumer)) {
// Collect a sample of the input records.
//
p.apply(inputRuntime).apply(//
Sample.<IndexedRecord>any(limit)).apply(collector);
try {
p.run().waitUntilFinish();
} catch (Pipeline.PipelineExecutionException e) {
if (e.getCause() instanceof TalendRuntimeException)
throw (TalendRuntimeException) e.getCause();
throw e;
}
}
}
use of org.talend.daikon.exception.TalendRuntimeException in project components by Talend.
the class JmsOutputPTransformRuntime method expand.
@Override
public PDone expand(PCollection<Object> objectPCollection) {
// TODO remove this method from PCollection<Object> to PCollection<IndexedRecord>, as the incoming type always PCollection<IndexedRecord>
PCollection<IndexedRecord> indexedCollection = objectPCollection.apply("ExtractIndexedRecord", ParDo.of(new DoFn<Object, IndexedRecord>() {
IndexedRecordConverter converter;
@DoFn.ProcessElement
public void processElement(ProcessContext c) throws Exception {
if (c.element() == null) {
return;
}
if (converter == null) {
converter = new AvroRegistry().createIndexedRecordConverter(c.element().getClass());
}
c.output((IndexedRecord) converter.convertToAvro(c.element()));
}
}));
indexedCollection.setCoder(LazyAvroCoder.of());
PCollection<String> jmsCollection = indexedCollection.apply("IndexedRecordToJmsRecord", ParDo.of(new DoFn<IndexedRecord, String>() {
@DoFn.ProcessElement
public void processElement(ProcessContext c) throws Exception {
c.output(c.element().get(0).toString());
}
}));
datastoreRuntime = new JmsDatastoreRuntime();
datastoreRuntime.initialize(null, properties.datasetRef.getReference().getDatastoreProperties());
if (messageType.equals(JmsMessageType.QUEUE)) {
return jmsCollection.apply(JmsIO.write().withConnectionFactory(datastoreRuntime.getConnectionFactory()).withQueue(properties.datasetRef.getReference().queueTopicName.getValue()));
} else if (messageType.equals(JmsMessageType.TOPIC)) {
return jmsCollection.apply(JmsIO.write().withConnectionFactory(datastoreRuntime.getConnectionFactory()).withTopic(properties.datasetRef.getReference().queueTopicName.getValue()));
} else {
throw new TalendRuntimeException(CommonErrorCodes.UNEXPECTED_ARGUMENT);
}
}
Aggregations