Search in sources :

Example 21 with JobEntryInterface

use of org.pentaho.di.job.entry.JobEntryInterface in project pentaho-metaverse by pentaho.

the class JobMetaJsonSerializer method serializeSteps.

@Override
protected void serializeSteps(JobMeta meta, JsonGenerator json) throws IOException {
    json.writeArrayFieldStart(JSON_PROPERTY_STEPS);
    int numberOfEntries = meta.nrJobEntries();
    for (int i = 0; i < numberOfEntries; i++) {
        JobEntryCopy jobEntry = meta.getJobEntry(i);
        LineageRepository repo = getLineageRepository();
        ObjectId jobId = meta.getObjectId() == null ? new StringObjectId(meta.getName()) : meta.getObjectId();
        ObjectId entryId = jobEntry.getObjectId() == null ? new StringObjectId(jobEntry.getName()) : jobEntry.getObjectId();
        JobEntryInterface jobEntryInterface = jobEntry.getEntry();
        JobEntryBase jobEntryBase = getJobEntryBase(jobEntryInterface);
        Job job = new Job(null, meta);
        jobEntryBase.setParentJob(job);
        jobEntryInterface.setObjectId(entryId);
        try {
            jobEntryInterface.saveRep(repo, null, jobId);
        } catch (KettleException e) {
            LOGGER.warn(Messages.getString("INFO.Serialization.Trans.Step", jobEntry.getName()), e);
        }
        json.writeObject(jobEntryBase);
    }
    json.writeEndArray();
}
Also used : JobEntryBase(org.pentaho.di.job.entry.JobEntryBase) KettleException(org.pentaho.di.core.exception.KettleException) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) JobEntryInterface(org.pentaho.di.job.entry.JobEntryInterface) ObjectId(org.pentaho.di.repository.ObjectId) StringObjectId(org.pentaho.di.repository.StringObjectId) LineageRepository(org.pentaho.metaverse.impl.model.kettle.LineageRepository) Job(org.pentaho.di.job.Job) StringObjectId(org.pentaho.di.repository.StringObjectId)

Example 22 with JobEntryInterface

use of org.pentaho.di.job.entry.JobEntryInterface in project pentaho-metaverse by pentaho.

the class JobMetaJsonSerializerTest method testSerializeSteps.

@Test
public void testSerializeSteps() throws Exception {
    when(meta.nrJobEntries()).thenReturn(2);
    JobEntryCopy jobEntryCopy = mock(JobEntryCopy.class);
    JobEntryInterface jobEntryInterface = new JobEntrySuccess("name", "description");
    when(meta.getJobEntry(anyInt())).thenReturn(jobEntryCopy);
    when(meta.getName()).thenReturn("JobMeta");
    when(jobEntryCopy.getName()).thenReturn("JobEntry");
    when(jobEntryCopy.getEntry()).thenReturn(jobEntryInterface);
    serializer.serializeSteps(meta, json);
    verify(json, times(2)).writeObject(jobEntryInterface);
}
Also used : JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) JobEntryInterface(org.pentaho.di.job.entry.JobEntryInterface) JobEntrySuccess(org.pentaho.di.job.entries.success.JobEntrySuccess) Test(org.junit.Test)

Example 23 with JobEntryInterface

use of org.pentaho.di.job.entry.JobEntryInterface 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 24 with JobEntryInterface

use of org.pentaho.di.job.entry.JobEntryInterface in project pentaho-metaverse by pentaho.

the class JobEntryExternalResourceConsumerListenerTest method testCallJobEntryExtensionPoint.

@Test
public void testCallJobEntryExtensionPoint() throws Exception {
    JobEntryExternalResourceConsumerListener jobEntryExtensionPoint = new JobEntryExternalResourceConsumerListener();
    jobEntryExtensionPoint.setJobEntryExternalResourceConsumerProvider(MetaverseTestUtils.getJobEntryExternalResourceConsumerProvider());
    JobExecutionExtension jobExec = mock(JobExecutionExtension.class);
    JobEntryBase jobEntryBase = mock(JobEntryBase.class, withSettings().extraInterfaces(JobEntryInterface.class));
    JobEntryInterface jobEntryInterface = (JobEntryInterface) jobEntryBase;
    JobEntryCopy jobEntryCopy = mock(JobEntryCopy.class);
    when(jobEntryCopy.getEntry()).thenReturn(jobEntryInterface);
    jobExec.jobEntryCopy = jobEntryCopy;
    jobEntryExtensionPoint.callExtensionPoint(null, jobExec);
    // Adda consumer
    Map<Class<? extends JobEntryBase>, Set<IJobEntryExternalResourceConsumer>> jobEntryConsumerMap = new JobEntryExternalResourceConsumerProvider().getJobEntryConsumerMap();
    Set<IJobEntryExternalResourceConsumer> consumers = new HashSet<IJobEntryExternalResourceConsumer>();
    jobEntryConsumerMap.put(jobEntryBase.getClass(), consumers);
    jobEntryExtensionPoint.callExtensionPoint(null, jobExec);
    IJobEntryExternalResourceConsumer consumer = mock(IJobEntryExternalResourceConsumer.class);
    when(consumer.getResourcesFromMeta(Mockito.any())).thenReturn(Collections.emptyList());
    consumers.add(consumer);
    Job mockJob = mock(Job.class);
    when(jobEntryInterface.getParentJob()).thenReturn(mockJob);
    jobExec.job = mockJob;
    jobEntryExtensionPoint.callExtensionPoint(null, jobExec);
    when(consumer.isDataDriven(Mockito.any())).thenReturn(Boolean.TRUE);
    jobEntryExtensionPoint.callExtensionPoint(null, jobExec);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) JobEntryInterface(org.pentaho.di.job.entry.JobEntryInterface) JobExecutionExtension(org.pentaho.di.job.JobExecutionExtension) JobEntryBase(org.pentaho.di.job.entry.JobEntryBase) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) JobEntryExternalResourceConsumerProvider(org.pentaho.metaverse.analyzer.kettle.jobentry.JobEntryExternalResourceConsumerProvider) IJobEntryExternalResourceConsumer(org.pentaho.metaverse.api.analyzer.kettle.jobentry.IJobEntryExternalResourceConsumer) Job(org.pentaho.di.job.Job) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 25 with JobEntryInterface

use of org.pentaho.di.job.entry.JobEntryInterface in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryJobEntryDelegate method saveJobEntryCopy.

public void saveJobEntryCopy(JobEntryCopy copy, ObjectId id_job, KettleDatabaseRepositoryMetaStore metaStore) throws KettleException {
    try {
        JobEntryInterface entry = copy.getEntry();
        /*
       * --1-- Save the JobEntryCopy details... --2-- If we don't find a id_jobentry, save the jobentry (meaning: only
       * once)
       */
        // See if an entry with the same name is already available...
        ObjectId id_jobentry = getJobEntryID(copy.getName(), id_job);
        if (id_jobentry == null) {
            insertJobEntry(id_job, (JobEntryBase) entry);
            // THIS IS THE PLUGIN/JOB-ENTRY BEING SAVED!
            // 
            entry.saveRep(repository, metaStore, id_job);
            compatibleEntrySaveRep(entry, repository, id_job);
            // 
            if (entry instanceof JobEntryBase) {
                saveAttributesMap(id_job, copy.getObjectId(), ((JobEntryBase) entry).getAttributesMap());
            }
            id_jobentry = entry.getObjectId();
        }
        // OK, the entry is saved.
        // Get the entry type...
        // 
        ObjectId id_jobentry_type = getJobEntryTypeID(entry.getPluginId());
        // Oops, not found: update the repository!
        if (id_jobentry_type == null) {
            repository.updateJobEntryTypes();
            // Try again!
            id_jobentry_type = getJobEntryTypeID(entry.getPluginId());
        }
        // Save the entry copy..
        // 
        copy.setObjectId(insertJobEntryCopy(id_job, id_jobentry, id_jobentry_type, copy.getNr(), copy.getLocation().x, copy.getLocation().y, copy.isDrawn(), copy.isLaunchingInParallel()));
    } catch (KettleDatabaseException dbe) {
        throw new KettleException("Unable to save job entry copy to the repository, id_job=" + id_job, dbe);
    }
}
Also used : JobEntryBase(org.pentaho.di.job.entry.JobEntryBase) KettleException(org.pentaho.di.core.exception.KettleException) JobEntryInterface(org.pentaho.di.job.entry.JobEntryInterface) LongObjectId(org.pentaho.di.repository.LongObjectId) ObjectId(org.pentaho.di.repository.ObjectId) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException)

Aggregations

JobEntryInterface (org.pentaho.di.job.entry.JobEntryInterface)43 JobEntryCopy (org.pentaho.di.job.entry.JobEntryCopy)27 Test (org.junit.Test)15 KettleException (org.pentaho.di.core.exception.KettleException)12 JobMeta (org.pentaho.di.job.JobMeta)9 StepMetaInterface (org.pentaho.di.trans.step.StepMetaInterface)8 ArrayList (java.util.ArrayList)7 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)7 Job (org.pentaho.di.job.Job)7 Result (org.pentaho.di.core.Result)5 Point (org.pentaho.di.core.gui.Point)5 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)5 JobEntryBase (org.pentaho.di.job.entry.JobEntryBase)5 NotePadMeta (org.pentaho.di.core.NotePadMeta)4 JobHopMeta (org.pentaho.di.job.JobHopMeta)4 JobEntryDialogInterface (org.pentaho.di.job.entry.JobEntryDialogInterface)4 ObjectId (org.pentaho.di.repository.ObjectId)4 Date (java.util.Date)3 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)3 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)3