Search in sources :

Example 36 with IExternalResourceInfo

use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.

the class AbstractStepMetaJsonSerializer method writeExternalResources.

protected void writeExternalResources(T meta, JsonGenerator json, SerializerProvider serializerProvider) throws IOException, JsonGenerationException {
    Set<Class<?>> metaClassSet = new HashSet<Class<?>>(1);
    metaClassSet.add(meta.getClass());
    IStepExternalResourceConsumerProvider stepExternalResourceConsumerProvider = getStepExternalResourceConsumerProvider();
    List<IStepExternalResourceConsumer> resourceConsumers = null;
    if (stepExternalResourceConsumerProvider != null) {
        resourceConsumers = stepExternalResourceConsumerProvider.getExternalResourceConsumers(metaClassSet);
    }
    json.writeArrayFieldStart(JSON_PROPERTY_EXTERNAL_RESOURCES);
    if (resourceConsumers != null) {
        for (IStepExternalResourceConsumer resourceConsumer : resourceConsumers) {
            Collection<IExternalResourceInfo> infos = resourceConsumer.getResourcesFromMeta(meta);
            for (IExternalResourceInfo info : infos) {
                json.writeObject(info);
            }
        }
    }
    json.writeEndArray();
}
Also used : IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) IStepExternalResourceConsumerProvider(org.pentaho.metaverse.api.analyzer.kettle.step.IStepExternalResourceConsumerProvider) IStepExternalResourceConsumer(org.pentaho.metaverse.api.analyzer.kettle.step.IStepExternalResourceConsumer) HashSet(java.util.HashSet)

Example 37 with IExternalResourceInfo

use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.

the class TransMetaJsonDeserializer method deserializeConnections.

protected void deserializeConnections(TransMeta transMeta, JsonNode node, ObjectMapper mapper) {
    ArrayNode connectionsArrayNode = (ArrayNode) node.get(TransMetaJsonSerializer.JSON_PROPERTY_CONNECTIONS);
    IExternalResourceInfo conn = null;
    for (int i = 0; i < connectionsArrayNode.size(); i++) {
        JsonNode connNode = connectionsArrayNode.get(i);
        String className = connNode.get(IInfo.JSON_PROPERTY_CLASS).asText();
        try {
            Class clazz = this.getClass().getClassLoader().loadClass(className);
            conn = (IExternalResourceInfo) clazz.newInstance();
            conn = mapper.readValue(connNode.toString(), conn.getClass());
            DatabaseMeta dbMeta = null;
            if (conn instanceof JdbcResourceInfo) {
                JdbcResourceInfo db = (JdbcResourceInfo) conn;
                dbMeta = new DatabaseMeta(db.getName(), db.getPluginId(), DatabaseMeta.getAccessTypeDesc(DatabaseMeta.TYPE_ACCESS_NATIVE), db.getServer(), db.getDatabaseName(), String.valueOf(db.getPort()), db.getUsername(), db.getPassword());
            } else if (conn instanceof JndiResourceInfo) {
                JndiResourceInfo db = (JndiResourceInfo) conn;
                dbMeta = new DatabaseMeta(db.getName(), db.getPluginId(), DatabaseMeta.getAccessTypeDesc(DatabaseMeta.TYPE_ACCESS_JNDI), null, null, null, null, null);
            }
            transMeta.addDatabase(dbMeta);
        } catch (Exception e) {
            LOGGER.warn(Messages.getString("WARNING.Deserialization.Trans.Connections", conn.getName(), transMeta.getName()), e);
        }
    }
}
Also used : IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) JdbcResourceInfo(org.pentaho.metaverse.api.model.JdbcResourceInfo) JsonNode(com.fasterxml.jackson.databind.JsonNode) JndiResourceInfo(org.pentaho.metaverse.api.model.JndiResourceInfo) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) KettleException(org.pentaho.di.core.exception.KettleException) DuplicateParamException(org.pentaho.di.core.parameters.DuplicateParamException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException)

Example 38 with IExternalResourceInfo

use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.

the class JobEntryExternalResourceConsumerListener method addExternalResources.

protected void addExternalResources(Collection<IExternalResourceInfo> resources, JobEntryInterface jobEntry) {
    if (resources != null) {
        // Add the resources to the execution profile
        IExecutionProfile executionProfile = JobLineageHolderMap.getInstance().getLineageHolder(jobEntry.getParentJob()).getExecutionProfile();
        if (executionProfile != null) {
            String jobEntryName = jobEntry.getName();
            Map<String, List<IExternalResourceInfo>> resourceMap = executionProfile.getExecutionData().getExternalResources();
            List<IExternalResourceInfo> externalResources = resourceMap.get(jobEntryName);
            if (externalResources == null) {
                externalResources = new LinkedList<IExternalResourceInfo>();
            }
            externalResources.addAll(resources);
            resourceMap.put(jobEntryName, externalResources);
        }
    }
}
Also used : IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) IExecutionProfile(org.pentaho.metaverse.api.model.IExecutionProfile) List(java.util.List) LinkedList(java.util.LinkedList)

Example 39 with IExternalResourceInfo

use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.

the class JobEntryExternalResourceConsumerListener method callExtensionPoint.

/**
 * This method is called by the Kettle code when a job entry is about to start
 *
 * @param log    the logging channel to log debugging information to
 * @param object The subject object that is passed to the plugin code
 * @throws org.pentaho.di.core.exception.KettleException In case the plugin decides that an error has occurred
 *                                                       and the parent process should stop.
 */
@Override
public void callExtensionPoint(LogChannelInterface log, Object object) throws KettleException {
    if (jobEntryConsumerProvider == null) {
        jobEntryConsumerProvider = (IJobEntryExternalResourceConsumerProvider) MetaverseBeanUtil.getInstance().get("IJobEntryExternalResourceConsumerProvider");
    }
    JobExecutionExtension jobExec = (JobExecutionExtension) object;
    JobEntryCopy jobEntryCopy = jobExec.jobEntryCopy;
    if (jobEntryCopy != null) {
        JobEntryInterface meta = jobEntryCopy.getEntry();
        if (meta != null) {
            Class<?> metaClass = meta.getClass();
            if (JobEntryBase.class.isAssignableFrom(metaClass)) {
                if (jobEntryConsumerProvider != null) {
                    // Put the class into a collection and get the consumers that can process this class
                    Set<Class<?>> metaClassSet = new HashSet<Class<?>>(1);
                    metaClassSet.add(metaClass);
                    List<IJobEntryExternalResourceConsumer> jobEntryConsumers = jobEntryConsumerProvider.getExternalResourceConsumers(metaClassSet);
                    if (jobEntryConsumers != null) {
                        for (IJobEntryExternalResourceConsumer jobEntryConsumer : jobEntryConsumers) {
                            // We might know enough at this point, so call the consumer
                            Collection<IExternalResourceInfo> resources = jobEntryConsumer.getResourcesFromMeta(meta);
                            addExternalResources(resources, meta);
                            // Add a JobEntryListener to collect external resource info after a job entry has finished
                            if (jobExec.job != null && jobEntryConsumer.isDataDriven(meta)) {
                                // Add the consumer as a resource listener, this is done to override the default impl
                                if (jobEntryConsumer instanceof JobEntryExternalResourceListener) {
                                    jobExec.job.addJobEntryListener((JobEntryExternalResourceListener) jobEntryConsumer);
                                } else {
                                    jobExec.job.addJobEntryListener(new JobEntryExternalResourceListener());
                                }
                            }
                        }
                    } else {
                        // Add a JobEntryListener to collect external resource info after a job entry has finished
                        if (jobExec.job != null) {
                            jobExec.job.addJobEntryListener(new JobEntryExternalResourceListener());
                        }
                    }
                }
            }
        }
    }
}
Also used : JobExecutionExtension(org.pentaho.di.job.JobExecutionExtension) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) JobEntryInterface(org.pentaho.di.job.entry.JobEntryInterface) IJobEntryExternalResourceConsumer(org.pentaho.metaverse.api.analyzer.kettle.jobentry.IJobEntryExternalResourceConsumer) HashSet(java.util.HashSet)

Example 40 with IExternalResourceInfo

use of org.pentaho.metaverse.api.model.IExternalResourceInfo in project pentaho-metaverse by pentaho.

the class StepExternalResourceConsumerListener method callExtensionPoint.

/**
 * This method is called by the Kettle code when a step is about to start
 *
 * @param log    the logging channel to log debugging information to
 * @param object The subject object that is passed to the plugin code
 * @throws org.pentaho.di.core.exception.KettleException In case the plugin decides that an error has occurred
 *                                                       and the parent process should stop.
 */
@Override
public void callExtensionPoint(LogChannelInterface log, Object object) throws KettleException {
    if (stepConsumerProvider == null) {
        stepConsumerProvider = (IStepExternalResourceConsumerProvider) MetaverseBeanUtil.getInstance().get("IStepExternalResourceConsumerProvider");
    }
    StepMetaDataCombi stepCombi = (StepMetaDataCombi) object;
    if (stepCombi != null) {
        StepMetaInterface meta = stepCombi.meta;
        StepInterface step = stepCombi.step;
        if (meta != null) {
            Class<?> metaClass = meta.getClass();
            if (BaseStepMeta.class.isAssignableFrom(metaClass)) {
                if (stepConsumerProvider != null) {
                    // Put the class into a collection and get the consumers that can process this class
                    Set<Class<?>> metaClassSet = new HashSet<Class<?>>(1);
                    metaClassSet.add(metaClass);
                    List<IStepExternalResourceConsumer> stepConsumers = stepConsumerProvider.getExternalResourceConsumers(metaClassSet);
                    if (stepConsumers != null) {
                        for (IStepExternalResourceConsumer stepConsumer : stepConsumers) {
                            // We might know enough at this point, so call the consumer
                            Collection<IExternalResourceInfo> resources = stepConsumer.getResourcesFromMeta(meta);
                            addExternalResources(resources, step);
                            // Add a RowListener if the step is data-driven
                            if (stepConsumer.isDataDriven(meta)) {
                                stepCombi.step.addRowListener(new StepExternalConsumerRowListener(stepConsumer, step));
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : StepInterface(org.pentaho.di.trans.step.StepInterface) IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) StepMetaDataCombi(org.pentaho.di.trans.step.StepMetaDataCombi) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) IStepExternalResourceConsumer(org.pentaho.metaverse.api.analyzer.kettle.step.IStepExternalResourceConsumer) HashSet(java.util.HashSet)

Aggregations

IExternalResourceInfo (org.pentaho.metaverse.api.model.IExternalResourceInfo)64 Test (org.junit.Test)38 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)16 StepMeta (org.pentaho.di.trans.step.StepMeta)16 LinkedList (java.util.LinkedList)12 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)12 HashSet (java.util.HashSet)10 KettleException (org.pentaho.di.core.exception.KettleException)10 ArrayList (java.util.ArrayList)8 VariableSpace (org.pentaho.di.core.variables.VariableSpace)8 FileObject (org.apache.commons.vfs2.FileObject)7 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)5 IExecutionProfile (org.pentaho.metaverse.api.model.IExecutionProfile)5 List (java.util.List)4 IAnalysisContext (org.pentaho.metaverse.api.IAnalysisContext)4 IStepExternalResourceConsumer (org.pentaho.metaverse.api.analyzer.kettle.step.IStepExternalResourceConsumer)3 WebServiceResourceInfo (org.pentaho.metaverse.api.model.WebServiceResourceInfo)3 Before (org.junit.Before)2 Matchers.anyString (org.mockito.Matchers.anyString)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2