Search in sources :

Example 1 with JobEntryCopy

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

the class JobFileListenerTest method testProcessLinkedJobsWithNoFilename.

@Test
public void testProcessLinkedJobsWithNoFilename() {
    JobEntryJob jobJobExecutor = spy(new JobEntryJob());
    jobJobExecutor.setFileName(null);
    jobJobExecutor.setDirectory("/path/to");
    jobJobExecutor.setJobName("Job1");
    jobJobExecutor.setSpecificationMethod(ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME);
    JobEntryCopy jobEntry = mock(JobEntryCopy.class);
    when(jobEntry.getEntry()).thenReturn(jobJobExecutor);
    JobMeta parent = mock(JobMeta.class);
    when(parent.nrJobEntries()).thenReturn(1);
    when(parent.getJobEntry(0)).thenReturn(jobEntry);
    JobMeta result = jobFileListener.processLinkedJobs(parent);
    JobEntryCopy meta = result.getJobEntry(0);
    assertNotNull(meta);
    JobEntryJob resultExecMeta = (JobEntryJob) meta.getEntry();
    assertEquals(ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME, resultExecMeta.getSpecificationMethod());
    assertEquals(resultExecMeta.getDirectory(), "/path/to");
    assertEquals(resultExecMeta.getJobName(), "Job1");
}
Also used : JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) JobMeta(org.pentaho.di.job.JobMeta) JobEntryJob(org.pentaho.di.job.entries.job.JobEntryJob) Test(org.junit.Test)

Example 2 with JobEntryCopy

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

the class JobEntrySetVariables method setParentJob.

@Override
public void setParentJob(Job parentJob) {
    super.setParentJob(parentJob);
    // PDI-16387 Add a listener for recovering changed values of variables
    JobEntryListener jobListener = new JobEntryListener() {

        @Override
        public void beforeExecution(Job job, JobEntryCopy jobEntryCopy, JobEntryInterface jobEntryInterface) {
            for (String key : changedInitialVariables.keySet()) {
                setVariable(key, changedInitialVariables.get(key));
                parentJob.setVariable(key, changedInitialVariables.get(key));
            }
            changedInitialVariables.clear();
        }

        @Override
        public void afterExecution(Job job, JobEntryCopy jobEntryCopy, JobEntryInterface jobEntryInterface, Result result) {
        }
    };
    parentJob.addJobEntryListener(jobListener);
}
Also used : JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) JobEntryInterface(org.pentaho.di.job.entry.JobEntryInterface) JobEntryListener(org.pentaho.di.job.JobEntryListener) Job(org.pentaho.di.job.Job) Result(org.pentaho.di.core.Result)

Example 3 with JobEntryCopy

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

the class Spoon method refreshJobEntriesSubtree.

private void refreshJobEntriesSubtree(TreeItem tiJobName, JobMeta jobMeta, GUIResource guiResource) {
    TreeItem tiJobEntriesTitle = createTreeItem(tiJobName, STRING_JOB_ENTRIES, guiResource.getImageFolder());
    for (int i = 0; i < jobMeta.nrJobEntries(); i++) {
        JobEntryCopy jobEntry = jobMeta.getJobEntry(i);
        if (!filterMatch(jobEntry.getName()) && !filterMatch(jobEntry.getDescription())) {
            continue;
        }
        TreeItem tiJobEntry = ConstUI.findTreeItem(tiJobEntriesTitle, jobEntry.getName());
        if (tiJobEntry != null) {
            // only show it once
            continue;
        }
        // if (jobEntry.isShared())
        // tiStep.setFont(guiResource.getFontBold()); TODO:
        // allow job entries to be shared as well...
        Image icon;
        if (jobEntry.isStart()) {
            icon = GUIResource.getInstance().getImageStartMedium();
        } else if (jobEntry.isDummy()) {
            icon = GUIResource.getInstance().getImageDummyMedium();
        } else {
            String key = jobEntry.getEntry().getPluginId();
            icon = GUIResource.getInstance().getImagesJobentriesSmall().get(key);
        }
        createTreeItem(tiJobEntriesTitle, jobEntry.getName(), icon);
    }
}
Also used : JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) TreeItem(org.eclipse.swt.widgets.TreeItem) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Image(org.eclipse.swt.graphics.Image) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint)

Example 4 with JobEntryCopy

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

the class JobEntryAnalyzerTest method setUp.

/**
 * @throws Exception
 */
@Before
public void setUp() throws Exception {
    IMetaverseObjectFactory factory = MetaverseTestUtils.getMetaverseObjectFactory();
    when(mockBuilder.getMetaverseObjectFactory()).thenReturn(factory);
    JobEntryAnalyzer baseAnalyzer = new JobEntryAnalyzer() {

        @Override
        public Set<Class<? super JobEntryCopy>> getSupportedEntries() {
            return null;
        }

        @Override
        protected void customAnalyze(JobEntryInterface entry, IMetaverseNode rootNode) throws MetaverseAnalyzerException {
        // TODO Auto-generated method stub
        }
    };
    analyzer = spy(baseAnalyzer);
    analyzer.setMetaverseBuilder(mockBuilder);
    when(mockEntry.getEntry()).thenReturn(mockJobEntryInterface);
    when(mockJobEntryInterface.getPluginId()).thenReturn("Base job entry");
    when(mockJobEntryInterface.getParentJob()).thenReturn(mockJob);
    when(mockJob.getJobMeta()).thenReturn(mockJobMeta);
}
Also used : JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) JobEntryInterface(org.pentaho.di.job.entry.JobEntryInterface) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) IMetaverseObjectFactory(org.pentaho.metaverse.api.IMetaverseObjectFactory) AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) Before(org.junit.Before)

Example 5 with JobEntryCopy

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

the class JobAnalyzer method analyze.

@Override
public synchronized IMetaverseNode analyze(final IComponentDescriptor documentDescriptor, final AbstractMeta meta, final IMetaverseNode node, final String documentPath) throws MetaverseAnalyzerException {
    final JobMeta jobMeta = (JobMeta) meta;
    Job j = new Job(null, jobMeta);
    j.setInternalKettleVariables(jobMeta);
    // pull out the standard fields
    String description = jobMeta.getDescription();
    if (description != null) {
        node.setProperty(DictionaryConst.PROPERTY_DESCRIPTION, description);
    }
    String extendedDescription = jobMeta.getExtendedDescription();
    if (extendedDescription != null) {
        node.setProperty("extendedDescription", extendedDescription);
    }
    Date createdDate = jobMeta.getCreatedDate();
    if (createdDate != null) {
        node.setProperty(DictionaryConst.PROPERTY_CREATED, Long.toString(createdDate.getTime()));
    }
    String createdUser = jobMeta.getCreatedUser();
    if (createdUser != null) {
        node.setProperty(DictionaryConst.PROPERTY_CREATED_BY, createdUser);
    }
    Date lastModifiedDate = jobMeta.getModifiedDate();
    if (lastModifiedDate != null) {
        node.setProperty(DictionaryConst.PROPERTY_LAST_MODIFIED, Long.toString(lastModifiedDate.getTime()));
    }
    String lastModifiedUser = jobMeta.getModifiedUser();
    if (lastModifiedUser != null) {
        node.setProperty(DictionaryConst.PROPERTY_LAST_MODIFIED_BY, lastModifiedUser);
    }
    String version = jobMeta.getJobversion();
    if (version != null) {
        node.setProperty(DictionaryConst.PROPERTY_ARTIFACT_VERSION, version);
    }
    String status = Messages.getString("INFO.JobOrTrans.Status_" + Integer.toString(jobMeta.getJobstatus()));
    if (status != null && !status.startsWith("!")) {
        node.setProperty(DictionaryConst.PROPERTY_STATUS, status);
    }
    node.setProperty(DictionaryConst.PROPERTY_PATH, documentPath);
    // Process job parameters
    String[] parameters = jobMeta.listParameters();
    if (parameters != null) {
        for (String parameter : parameters) {
            try {
                // Determine parameter properties and add them to a map, then the map to the list
                String defaultParameterValue = jobMeta.getParameterDefault(parameter);
                String parameterValue = jobMeta.getParameterValue(parameter);
                String parameterDescription = jobMeta.getParameterDescription(parameter);
                PropertiesHolder paramProperties = new PropertiesHolder();
                paramProperties.setProperty("defaultValue", defaultParameterValue);
                paramProperties.setProperty("value", parameterValue);
                paramProperties.setProperty("description", parameterDescription);
                node.setProperty("parameter_" + parameter, paramProperties.toString());
            } catch (UnknownParamException upe) {
                // This shouldn't happen as we're using the list provided by the meta
                throw new MetaverseAnalyzerException(upe);
            }
        }
    }
    // handle the entries
    for (int i = 0; i < jobMeta.nrJobEntries(); i++) {
        JobEntryCopy entry = jobMeta.getJobEntry(i);
        try {
            if (entry != null) {
                entry.getEntry().setParentJob(j);
                IMetaverseNode jobEntryNode = null;
                JobEntryInterface jobEntryInterface = entry.getEntry();
                IComponentDescriptor entryDescriptor = new MetaverseComponentDescriptor(entry.getName(), DictionaryConst.NODE_TYPE_JOB_ENTRY, node, documentDescriptor.getContext());
                Set<IJobEntryAnalyzer> jobEntryAnalyzers = getJobEntryAnalyzers(jobEntryInterface);
                if (jobEntryAnalyzers != null && !jobEntryAnalyzers.isEmpty()) {
                    for (IJobEntryAnalyzer jobEntryAnalyzer : jobEntryAnalyzers) {
                        // change while the job is being analyzed
                        if (jobEntryAnalyzer instanceof IClonableJobEntryAnalyzer) {
                            jobEntryAnalyzer = ((IClonableJobEntryAnalyzer) jobEntryAnalyzer).cloneAnalyzer();
                            ((IClonableJobEntryAnalyzer) jobEntryAnalyzer).setDocumentAnalyzer(this);
                            ((IClonableJobEntryAnalyzer) jobEntryAnalyzer).setDocumentDescriptor(documentDescriptor);
                            ((IClonableJobEntryAnalyzer) jobEntryAnalyzer).setDocumentPath(documentPath);
                        } else {
                            log.debug(Messages.getString("WARNING.CannotCloneAnalyzer"), jobEntryAnalyzer);
                        }
                        jobEntryAnalyzer.setMetaverseBuilder(metaverseBuilder);
                        jobEntryNode = (IMetaverseNode) jobEntryAnalyzer.analyze(entryDescriptor, entry.getEntry());
                    }
                } else if (new AnnotatedClassFields(jobEntryInterface, jobEntryInterface.getParentJobMeta()).hasMetaverseAnnotations()) {
                    AnnotationDrivenJobAnalyzer annotationDrivenJobAnalyzer = new AnnotationDrivenJobAnalyzer(jobEntryInterface);
                    annotationDrivenJobAnalyzer.setMetaverseBuilder(metaverseBuilder);
                    annotationDrivenJobAnalyzer.setDocumentAnalyzer(this);
                    annotationDrivenJobAnalyzer.setDocumentDescriptor(documentDescriptor);
                    annotationDrivenJobAnalyzer.setDocumentPath(documentPath);
                    jobEntryNode = annotationDrivenJobAnalyzer.analyze(entryDescriptor, jobEntryInterface);
                } else {
                    GenericJobEntryMetaAnalyzer defaultJobEntryAnalyzer = new GenericJobEntryMetaAnalyzer();
                    defaultJobEntryAnalyzer.setMetaverseBuilder(metaverseBuilder);
                    jobEntryNode = defaultJobEntryAnalyzer.analyze(entryDescriptor, jobEntryInterface);
                }
                if (jobEntryNode != null) {
                    metaverseBuilder.addLink(node, DictionaryConst.LINK_CONTAINS, jobEntryNode);
                }
            }
        } catch (Exception mae) {
            // Don't throw an exception, just log and carry on
            log.warn(Messages.getString("ERROR.ErrorDuringAnalysis", entry.getName(), Const.NVL(mae.getLocalizedMessage(), "Unspecified")));
            log.debug(Messages.getString("ERROR.ErrorDuringAnalysisStackTrace"), mae);
        }
    }
    // Model the hops between steps
    int numHops = jobMeta.nrJobHops();
    for (int i = 0; i < numHops; i++) {
        JobHopMeta hop = jobMeta.getJobHop(i);
        JobEntryCopy fromEntry = hop.getFromEntry();
        JobEntryCopy toEntry = hop.getToEntry();
        INamespace childNs = new Namespace(node.getLogicalId());
        // process legitimate hops
        if (fromEntry != null && toEntry != null) {
            IMetaverseNode fromEntryNode = metaverseObjectFactory.createNodeObject(childNs, fromEntry.getName(), DictionaryConst.NODE_TYPE_JOB_ENTRY);
            IMetaverseNode toEntryNode = metaverseObjectFactory.createNodeObject(childNs, toEntry.getName(), DictionaryConst.NODE_TYPE_JOB_ENTRY);
            metaverseBuilder.addLink(fromEntryNode, DictionaryConst.LINK_HOPSTO, toEntryNode);
        }
    }
    metaverseBuilder.addNode(node);
    addParentLink(documentDescriptor, node);
    return node;
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) PropertiesHolder(org.pentaho.metaverse.api.PropertiesHolder) JobHopMeta(org.pentaho.di.job.JobHopMeta) MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException) JobEntryInterface(org.pentaho.di.job.entry.JobEntryInterface) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) IJobEntryAnalyzer(org.pentaho.metaverse.api.analyzer.kettle.jobentry.IJobEntryAnalyzer) Date(java.util.Date) AnnotatedClassFields(org.pentaho.metaverse.api.analyzer.kettle.annotations.AnnotatedClassFields) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException) MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException) INamespace(org.pentaho.metaverse.api.INamespace) Namespace(org.pentaho.metaverse.api.Namespace) MetaverseComponentDescriptor(org.pentaho.metaverse.api.MetaverseComponentDescriptor) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) INamespace(org.pentaho.metaverse.api.INamespace) IClonableJobEntryAnalyzer(org.pentaho.metaverse.api.analyzer.kettle.jobentry.IClonableJobEntryAnalyzer) UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException) GenericJobEntryMetaAnalyzer(org.pentaho.metaverse.analyzer.kettle.jobentry.GenericJobEntryMetaAnalyzer) Job(org.pentaho.di.job.Job) AnnotationDrivenJobAnalyzer(org.pentaho.metaverse.api.analyzer.kettle.annotations.AnnotationDrivenJobAnalyzer)

Aggregations

JobEntryCopy (org.pentaho.di.job.entry.JobEntryCopy)170 JobMeta (org.pentaho.di.job.JobMeta)53 Point (org.pentaho.di.core.gui.Point)52 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)51 Test (org.junit.Test)42 KettleException (org.pentaho.di.core.exception.KettleException)31 JobEntryInterface (org.pentaho.di.job.entry.JobEntryInterface)29 NotePadMeta (org.pentaho.di.core.NotePadMeta)24 JobHopMeta (org.pentaho.di.job.JobHopMeta)24 ArrayList (java.util.ArrayList)20 Job (org.pentaho.di.job.Job)19 JobEntryTrans (org.pentaho.di.job.entries.trans.JobEntryTrans)17 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)16 DataNode (org.pentaho.platform.api.repository2.unified.data.node.DataNode)15 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)15 MessageBox (org.eclipse.swt.widgets.MessageBox)13 AttributesInterface (org.pentaho.di.core.AttributesInterface)10 PluginInterface (org.pentaho.di.core.plugins.PluginInterface)10 Result (org.pentaho.di.core.Result)9 JobEntryJob (org.pentaho.di.job.entries.job.JobEntryJob)9