Search in sources :

Example 1 with RuntimeInfo

use of org.talend.daikon.runtime.RuntimeInfo in project tdi-studio-se by Talend.

the class Component method getModulesNeeded.

@Override
public List<ModuleNeeded> getModulesNeeded(INode node) {
    List<ModuleNeeded> componentImportNeedsList = new ArrayList<>();
    ConnectorTopology topology = null;
    if (node != null) {
        boolean hasInput = !NodeUtil.getIncomingConnections(node, IConnectionCategory.DATA).isEmpty();
        boolean hasOutput = !NodeUtil.getOutgoingConnections(node, IConnectionCategory.DATA).isEmpty();
        if (hasInput && hasOutput) {
            topology = ConnectorTopology.INCOMING_AND_OUTGOING;
        } else if (hasInput) {
            topology = ConnectorTopology.INCOMING;
        } else if (hasOutput) {
            topology = ConnectorTopology.OUTGOING;
        } else {
            topology = ConnectorTopology.NONE;
        }
    } else {
        Set<ConnectorTopology> topologies = componentDefinition.getSupportedConnectorTopologies();
        if (!topologies.isEmpty()) {
            topology = topologies.iterator().next();
        }
    }
    RuntimeInfo runtimeInfo = null;
    try {
        runtimeInfo = componentDefinition.getRuntimeInfo(ExecutionEngine.DI, node == null ? null : node.getComponentProperties(), topology);
    } catch (Exception e) {
        if (node == null) {
        // not handled, must because the runtime info must have a node configuration (properties are null)
        } else {
            ExceptionHandler.process(e);
        }
    }
    if (runtimeInfo != null) {
        if (runtimeInfo instanceof JarRuntimeInfo) {
            JarRuntimeInfo currentRuntimeInfo = (JarRuntimeInfo) runtimeInfo;
            JarRuntimeInfo localRuntimeInfo = new JarRuntimeInfo(//$NON-NLS-1$
            currentRuntimeInfo.getJarUrl().toString().replace(//$NON-NLS-1$
            "mvn:", //$NON-NLS-1$ //$NON-NLS-2$
            "mvn:" + MavenConstants.LOCAL_RESOLUTION_URL + "!"), currentRuntimeInfo.getDepTxtPath(), currentRuntimeInfo.getRuntimeClassName());
            runtimeInfo = localRuntimeInfo;
        }
        final Bundle bundle = FrameworkUtil.getBundle(componentDefinition.getClass());
        for (URL mvnUri : runtimeInfo.getMavenUrlDependencies()) {
            //$NON-NLS-1$
            ModuleNeeded moduleNeeded = new ModuleNeeded(getName(), "", true, mvnUri.toString());
            componentImportNeedsList.add(moduleNeeded);
            if (bundle != null) {
                // update module location
                try {
                    final MavenArtifact artifact = MavenUrlHelper.parseMvnUrl(moduleNeeded.getMavenUri());
                    final String moduleFileName = artifact.getFileName();
                    final File bundleFile = BundleFileUtil.getBundleFile(bundle, moduleFileName);
                    if (bundleFile != null && bundleFile.exists()) {
                        // FIXME, better install the embed jars from bundle directly in this way.
                        moduleNeeded.setModuleLocaion(ExtensionModuleManager.URIPATH_PREFIX + bundle.getSymbolicName() + '/' + moduleFileName);
                    }
                } catch (IOException e) {
                    ExceptionHandler.process(e);
                }
            }
        }
    }
    ModuleNeeded moduleNeeded = new ModuleNeeded(getName(), "", true, "mvn:org.talend.libraries/slf4j-log4j12-1.7.2/6.0.0");
    componentImportNeedsList.add(moduleNeeded);
    moduleNeeded = new ModuleNeeded(getName(), "", true, "mvn:org.talend.libraries/talend-codegen-utils/0.17.0-SNAPSHOT");
    componentImportNeedsList.add(moduleNeeded);
    return componentImportNeedsList;
}
Also used : JarRuntimeInfo(org.talend.components.api.component.runtime.JarRuntimeInfo) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) JarRuntimeInfo(org.talend.components.api.component.runtime.JarRuntimeInfo) IOException(java.io.IOException) BusinessException(org.talend.commons.exception.BusinessException) IOException(java.io.IOException) URL(java.net.URL) ModuleNeeded(org.talend.core.model.general.ModuleNeeded) MavenArtifact(org.talend.core.runtime.maven.MavenArtifact) File(java.io.File) ConnectorTopology(org.talend.components.api.component.ConnectorTopology)

Example 2 with RuntimeInfo

use of org.talend.daikon.runtime.RuntimeInfo in project components by Talend.

the class TFilterRowDefinitionTest method testGetRuntime.

/**
 * Check {@link TFilterRowDefinition#getRuntime()} returns instance of {@link JiraSource}
 */
@Test
public void testGetRuntime() {
    TFilterRowDefinition definition = new TFilterRowDefinition();
    RuntimeInfo runtimeInfo = definition.getRuntimeInfo(ExecutionEngine.DI, null, ConnectorTopology.INCOMING_AND_OUTGOING);
    SandboxedInstance sandboxedInstance = RuntimeUtil.createRuntimeClass(runtimeInfo, definition.getClass().getClassLoader());
    Sink source = (Sink) sandboxedInstance.getInstance();
    assertThat(source, is(instanceOf(TFilterRowSink.class)));
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) Sink(org.talend.components.api.component.runtime.Sink) TFilterRowSink(org.talend.components.filterrow.runtime.TFilterRowSink) Test(org.junit.Test)

Example 3 with RuntimeInfo

use of org.talend.daikon.runtime.RuntimeInfo in project components by Talend.

the class MarkLogicOutputDefinitionTest method testGetRuntimeInfo.

@Test
public void testGetRuntimeInfo() {
    RuntimeInfo runtimeInfo = definition.getRuntimeInfo(ExecutionEngine.DI, null, ConnectorTopology.INCOMING);
    assertEquals("org.talend.components.marklogic.runtime.MarkLogicSink", runtimeInfo.getRuntimeClassName());
}
Also used : RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) Test(org.junit.Test)

Example 4 with RuntimeInfo

use of org.talend.daikon.runtime.RuntimeInfo in project components by Talend.

the class MarkLogicBulkLoadDefinitionTest method testGetRuntimeInfo.

@Test
public void testGetRuntimeInfo() {
    RuntimeInfo runtimeInfo = bulkLoadDefinition.getRuntimeInfo(ExecutionEngine.DI, null, ConnectorTopology.NONE);
    assertEquals("org.talend.components.marklogic.runtime.bulkload.MarkLogicBulkLoad", runtimeInfo.getRuntimeClassName());
}
Also used : RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) Test(org.junit.Test)

Example 5 with RuntimeInfo

use of org.talend.daikon.runtime.RuntimeInfo in project components by Talend.

the class SalesforceSourceOrSinkTestIT method testIsolatedClassLoader.

@Test
public void testIsolatedClassLoader() {
    ClassLoader classLoader = SalesforceDefinition.class.getClassLoader();
    RuntimeInfo runtimeInfo = SalesforceDefinition.getCommonRuntimeInfo(SalesforceSourceOrSink.class.getCanonicalName());
    try (SandboxedInstance sandboxedInstance = RuntimeUtil.createRuntimeClassWithCurrentJVMProperties(runtimeInfo, classLoader)) {
        sandboxedInstance.getInstance();
        System.setProperty("key", "value");
    }
    Assert.assertNull("The system property should not exist, but not", System.getProperty("key"));
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) Test(org.junit.Test)

Aggregations

RuntimeInfo (org.talend.daikon.runtime.RuntimeInfo)131 Test (org.junit.Test)120 SandboxedInstance (org.talend.daikon.sandbox.SandboxedInstance)27 Ignore (org.junit.Ignore)21 JarRuntimeInfo (org.talend.components.api.component.runtime.JarRuntimeInfo)17 ArrayList (java.util.ArrayList)13 AllSetting (org.talend.components.jdbc.runtime.setting.AllSetting)11 IndexedRecord (org.apache.avro.generic.IndexedRecord)8 ExecutionEngine (org.talend.components.api.component.runtime.ExecutionEngine)8 DatasetRuntime (org.talend.components.common.dataset.runtime.DatasetRuntime)7 URL (java.net.URL)6 Schema (org.apache.avro.Schema)6 ComponentException (org.talend.components.api.exception.ComponentException)5 ValidationResult (org.talend.daikon.properties.ValidationResult)5 File (java.io.File)3 NamedThing (org.talend.daikon.NamedThing)3 SimpleNamedThing (org.talend.daikon.SimpleNamedThing)3 TalendRuntimeException (org.talend.daikon.exception.TalendRuntimeException)3 FileWriter (java.io.FileWriter)2 GenericRecord (org.apache.avro.generic.GenericRecord)2