Search in sources :

Example 21 with TalendRuntimeException

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;
}
Also used : TalendRuntimeException(org.talend.daikon.exception.TalendRuntimeException) SQLException(java.sql.SQLException) DatabaseMetaData(java.sql.DatabaseMetaData)

Example 22 with TalendRuntimeException

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");
}
Also used : Path(org.apache.hadoop.fs.Path) TalendRuntimeException(org.talend.daikon.exception.TalendRuntimeException) SimpleFileIOOutputProperties(org.talend.components.simplefileio.output.SimpleFileIOOutputProperties) ConvertToIndexedRecord(org.talend.components.adapter.beam.transform.ConvertToIndexedRecord) IndexedRecord(org.apache.avro.generic.IndexedRecord) Pipeline(org.apache.beam.sdk.Pipeline) Test(org.junit.Test)

Example 23 with TalendRuntimeException

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");
}
Also used : Path(org.apache.hadoop.fs.Path) TalendRuntimeException(org.talend.daikon.exception.TalendRuntimeException) SimpleFileIOOutputProperties(org.talend.components.simplefileio.output.SimpleFileIOOutputProperties) ConvertToIndexedRecord(org.talend.components.adapter.beam.transform.ConvertToIndexedRecord) IndexedRecord(org.apache.avro.generic.IndexedRecord) OutputStream(java.io.OutputStream) Pipeline(org.apache.beam.sdk.Pipeline) Test(org.junit.Test)

Example 24 with TalendRuntimeException

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;
        }
    }
}
Also used : TalendRuntimeException(org.talend.daikon.exception.TalendRuntimeException) IndexedRecord(org.apache.avro.generic.IndexedRecord) SimpleFileIOInputProperties(org.talend.components.simplefileio.input.SimpleFileIOInputProperties) DirectOptions(org.apache.beam.runners.direct.DirectOptions) Pipeline(org.apache.beam.sdk.Pipeline)

Example 25 with TalendRuntimeException

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);
    }
}
Also used : TalendRuntimeException(org.talend.daikon.exception.TalendRuntimeException) DoFn(org.apache.beam.sdk.transforms.DoFn) AvroRegistry(org.talend.daikon.avro.AvroRegistry) IndexedRecord(org.apache.avro.generic.IndexedRecord) IndexedRecordConverter(org.talend.daikon.avro.converter.IndexedRecordConverter)

Aggregations

TalendRuntimeException (org.talend.daikon.exception.TalendRuntimeException)28 IndexedRecord (org.apache.avro.generic.IndexedRecord)10 IOException (java.io.IOException)8 Test (org.junit.Test)7 Pipeline (org.apache.beam.sdk.Pipeline)6 Schema (org.apache.avro.Schema)5 Path (org.apache.hadoop.fs.Path)5 ConvertToIndexedRecord (org.talend.components.adapter.beam.transform.ConvertToIndexedRecord)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 SimpleFileIOOutputProperties (org.talend.components.simplefileio.output.SimpleFileIOOutputProperties)4 BufferedWriter (java.io.BufferedWriter)3 OutputStream (java.io.OutputStream)3 OutputStreamWriter (java.io.OutputStreamWriter)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 DateTimeException (java.time.DateTimeException)2 LocalDateTime (java.time.LocalDateTime)2 GenericRecord (org.apache.avro.generic.GenericRecord)2 StringUtils (org.apache.commons.lang.StringUtils)2 SandboxedInstance (org.talend.daikon.sandbox.SandboxedInstance)2