Search in sources :

Example 1 with UnknownParamException

use of org.pentaho.di.core.parameters.UnknownParamException 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)

Example 2 with UnknownParamException

use of org.pentaho.di.core.parameters.UnknownParamException in project pentaho-kettle by pentaho.

the class AbstractMeta method activateParameters.

/*
   * (non-Javadoc)
   *
   * @see org.pentaho.di.core.parameters.NamedParams#activateParameters()
   */
@Override
public void activateParameters() {
    String[] keys = listParameters();
    for (String key : keys) {
        String value;
        try {
            value = getParameterValue(key);
        } catch (UnknownParamException e) {
            value = "";
        }
        String defValue;
        try {
            defValue = getParameterDefault(key);
        } catch (UnknownParamException e) {
            defValue = "";
        }
        if (Utils.isEmpty(value)) {
            setVariable(key, Const.NVL(defValue, ""));
        } else {
            setVariable(key, value);
        }
    }
}
Also used : UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString)

Example 3 with UnknownParamException

use of org.pentaho.di.core.parameters.UnknownParamException in project pentaho-kettle by pentaho.

the class JobMeta method getXML.

/*
   * (non-Javadoc)
   *
   * @see org.pentaho.di.core.xml.XMLInterface#getXML()
   */
public String getXML() {
    // Clear the embedded named clusters.  We will be repopulating from steps that used named clusters
    getNamedClusterEmbedManager().clear();
    Props props = null;
    if (Props.isInitialized()) {
        props = Props.getInstance();
    }
    StringBuilder retval = new StringBuilder(500);
    retval.append(XMLHandler.openTag(XML_TAG)).append(Const.CR);
    retval.append("  ").append(XMLHandler.addTagValue("name", getName()));
    retval.append("  ").append(XMLHandler.addTagValue("description", description));
    retval.append("  ").append(XMLHandler.addTagValue("extended_description", extendedDescription));
    retval.append("  ").append(XMLHandler.addTagValue("job_version", jobVersion));
    if (jobStatus >= 0) {
        retval.append("  ").append(XMLHandler.addTagValue("job_status", jobStatus));
    }
    retval.append("  ").append(XMLHandler.addTagValue("directory", (directory != null ? directory.getPath() : RepositoryDirectory.DIRECTORY_SEPARATOR)));
    retval.append("  ").append(XMLHandler.addTagValue("created_user", createdUser));
    retval.append("  ").append(XMLHandler.addTagValue("created_date", XMLHandler.date2string(createdDate)));
    retval.append("  ").append(XMLHandler.addTagValue("modified_user", modifiedUser));
    retval.append("  ").append(XMLHandler.addTagValue("modified_date", XMLHandler.date2string(modifiedDate)));
    retval.append("    ").append(XMLHandler.openTag(XML_TAG_PARAMETERS)).append(Const.CR);
    String[] parameters = listParameters();
    for (int idx = 0; idx < parameters.length; idx++) {
        retval.append("      ").append(XMLHandler.openTag("parameter")).append(Const.CR);
        retval.append("        ").append(XMLHandler.addTagValue("name", parameters[idx]));
        try {
            retval.append("        ").append(XMLHandler.addTagValue("default_value", getParameterDefault(parameters[idx])));
            retval.append("        ").append(XMLHandler.addTagValue("description", getParameterDescription(parameters[idx])));
        } catch (UnknownParamException e) {
        // skip the default value and/or description. This exception should never happen because we use listParameters()
        // above.
        }
        retval.append("      ").append(XMLHandler.closeTag("parameter")).append(Const.CR);
    }
    retval.append("    ").append(XMLHandler.closeTag(XML_TAG_PARAMETERS)).append(Const.CR);
    Set<DatabaseMeta> usedDatabaseMetas = getUsedDatabaseMetas();
    // Save the database connections...
    for (int i = 0; i < nrDatabases(); i++) {
        DatabaseMeta dbMeta = getDatabase(i);
        if (props != null && props.areOnlyUsedConnectionsSavedToXML()) {
            if (usedDatabaseMetas.contains(dbMeta)) {
                retval.append(dbMeta.getXML());
            }
        } else {
            retval.append(dbMeta.getXML());
        }
    }
    // The slave servers...
    // 
    retval.append("    ").append(XMLHandler.openTag(XML_TAG_SLAVESERVERS)).append(Const.CR);
    for (int i = 0; i < slaveServers.size(); i++) {
        SlaveServer slaveServer = slaveServers.get(i);
        retval.append(slaveServer.getXML());
    }
    retval.append("    ").append(XMLHandler.closeTag(XML_TAG_SLAVESERVERS)).append(Const.CR);
    // 
    for (LogTableInterface logTable : getLogTables()) {
        retval.append(logTable.getXML());
    }
    retval.append("   ").append(XMLHandler.addTagValue("pass_batchid", batchIdPassed));
    retval.append("   ").append(XMLHandler.addTagValue("shared_objects_file", sharedObjectsFile));
    retval.append("  ").append(XMLHandler.openTag("entries")).append(Const.CR);
    for (int i = 0; i < nrJobEntries(); i++) {
        JobEntryCopy jge = getJobEntry(i);
        jge.getEntry().setRepository(repository);
        retval.append(jge.getXML());
    }
    retval.append("  ").append(XMLHandler.closeTag("entries")).append(Const.CR);
    retval.append("  ").append(XMLHandler.openTag("hops")).append(Const.CR);
    for (JobHopMeta hi : jobhops) {
        // Look at all the hops
        retval.append(hi.getXML());
    }
    retval.append("  ").append(XMLHandler.closeTag("hops")).append(Const.CR);
    retval.append("  ").append(XMLHandler.openTag("notepads")).append(Const.CR);
    for (int i = 0; i < nrNotes(); i++) {
        NotePadMeta ni = getNote(i);
        retval.append(ni.getXML());
    }
    retval.append("  ").append(XMLHandler.closeTag("notepads")).append(Const.CR);
    // Also store the attribute groups
    // 
    retval.append(AttributesUtil.getAttributesXml(attributesMap));
    retval.append(XMLHandler.closeTag(XML_TAG)).append(Const.CR);
    return XMLFormatter.format(retval.toString());
}
Also used : Props(org.pentaho.di.core.Props) SlaveServer(org.pentaho.di.cluster.SlaveServer) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) LogTableInterface(org.pentaho.di.core.logging.LogTableInterface) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException) NotePadMeta(org.pentaho.di.core.NotePadMeta)

Example 4 with UnknownParamException

use of org.pentaho.di.core.parameters.UnknownParamException in project pentaho-platform by pentaho.

the class KettleComponent method executeAction.

/**
 * Execute the specified transformation in the chosen repository.
 */
@SuppressWarnings("unchecked")
@Override
public boolean executeAction() {
    if (ComponentBase.debug) {
        // $NON-NLS-1$
        debug(Messages.getInstance().getString("Kettle.DEBUG_START"));
    }
    TransMeta transMeta = null;
    JobMeta jobMeta = null;
    // Build lists of parameters, variables and command line arguments
    Map<String, String> argumentMap = new HashMap<String, String>();
    Map<String, String> variableMap = new HashMap<String, String>();
    Map<String, String> parameterMap = new HashMap<String, String>();
    for (Node n : (List<Node>) getComponentDefinition().selectNodes(PARAMETER_MAP_CMD_ARG)) {
        argumentMap.put(n.selectSingleNode("name").getText(), // $NON-NLS-1$ //$NON-NLS-2$
        applyInputsToFormat(getInputStringValue(n.selectSingleNode("mapping").getText())));
    }
    for (Node n : (List<Node>) getComponentDefinition().selectNodes(PARAMETER_MAP_VARIABLE)) {
        variableMap.put(n.selectSingleNode("name").getText(), // $NON-NLS-1$ //$NON-NLS-2$
        applyInputsToFormat(getInputStringValue(n.selectSingleNode("mapping").getText())));
    }
    for (Node n : (List<Node>) getComponentDefinition().selectNodes(PARAMETER_MAP_PARAMETER)) {
        parameterMap.put(n.selectSingleNode("name").getText(), // $NON-NLS-1$ //$NON-NLS-2$
        applyInputsToFormat(getInputStringValue(n.selectSingleNode("mapping").getText())));
    }
    String[] arguments = null;
    // arguments (This supports the legacy method)
    if (argumentMap.size() <= 0 && variableMap.size() <= 0 && parameterMap.size() <= 0) {
        // this use is now considered obsolete, as we prefer the
        // action-sequence inputs since they
        // now maintain order
        boolean running = true;
        int index = 1;
        ArrayList<String> argumentList = new ArrayList<String>();
        while (running) {
            if (isDefinedInput("parameter" + index)) {
                // $NON-NLS-1$
                String value = null;
                // $NON-NLS-1$
                String inputName = getInputStringValue("parameter" + index);
                // see if we have an input with this name
                if (isDefinedInput(inputName)) {
                    value = getInputStringValue(inputName);
                }
                argumentList.add(value);
            } else {
                running = false;
            }
            index++;
        }
        // this is the preferred way to provide inputs to the
        // KetteComponent, the order of inputs is now preserved
        Iterator<?> inputNamesIter = getInputNames().iterator();
        while (inputNamesIter.hasNext()) {
            String name = (String) inputNamesIter.next();
            argumentList.add(getInputStringValue(name));
        }
        arguments = (String[]) argumentList.toArray(new String[argumentList.size()]);
    } else {
        // Extract arguments from argumentMap (Throw an error if the
        // sequential ordering is broken)
        arguments = new String[argumentMap.size()];
        for (int i = 0; i < argumentMap.size(); i++) {
            // Mapping
            arguments[i] = argumentMap.get(Integer.toString(i + 1));
            // UI
            if (arguments[i] == null) {
                // $NON-NLS-1$
                error(Messages.getInstance().getErrorString("Kettle.ERROR_0030_INVALID_ARGUMENT_MAPPING"));
            }
        }
    }
    // initialize environment variables
    try {
        KettleSystemListener.environmentInit(getSession());
    } catch (KettleException ke) {
        error(ke.getMessage(), ke);
    }
    String solutionPath = "solution:";
    Repository repository = connectToRepository();
    boolean result = false;
    try {
        if (isDefinedInput(KettleComponent.DIRECTORY)) {
            String directoryName = getInputStringValue(KettleComponent.DIRECTORY);
            if (repository == null) {
                return false;
            }
            if (isDefinedInput(KettleComponent.TRANSFORMATION)) {
                String transformationName = getInputStringValue(KettleComponent.TRANSFORMATION);
                transMeta = loadTransformFromRepository(directoryName, transformationName, repository);
                if (transMeta != null) {
                    try {
                        for (String key : parameterMap.keySet()) {
                            transMeta.setParameterValue(key, parameterMap.get(key));
                        }
                        for (String key : variableMap.keySet()) {
                            transMeta.setVariable(key, variableMap.get(key));
                        }
                    } catch (UnknownParamException e) {
                        error(e.getMessage());
                    }
                    transMeta.setArguments(arguments);
                } else {
                    return false;
                }
            } else if (isDefinedInput(KettleComponent.JOB)) {
                String jobName = getInputStringValue(KettleComponent.JOB);
                jobMeta = loadJobFromRepository(directoryName, jobName, repository);
                if (jobMeta != null) {
                    try {
                        for (String key : parameterMap.keySet()) {
                            jobMeta.setParameterValue(key, parameterMap.get(key));
                        }
                        for (String key : variableMap.keySet()) {
                            jobMeta.setVariable(key, variableMap.get(key));
                        }
                    } catch (UnknownParamException e) {
                        error(e.getMessage());
                    }
                    jobMeta.setArguments(arguments);
                } else {
                    return false;
                }
            }
        } else if (isDefinedResource(KettleComponent.TRANSFORMFILE)) {
            IActionSequenceResource transformResource = getResource(KettleComponent.TRANSFORMFILE);
            String fileAddress = getActualFileName(transformResource);
            try {
                if (fileAddress != null) {
                    // We have an actual loadable
                    // filesystem and file
                    transMeta = new TransMeta(fileAddress, repository, true);
                    transMeta.setFilename(fileAddress);
                } else if (repository != null && repository.isConnected()) {
                    fileAddress = transformResource.getAddress();
                    // load transformation resource from kettle/settings.xml configured repository
                    transMeta = loadTransformFromRepository(FilenameUtils.getPathNoEndSeparator(fileAddress), FilenameUtils.getBaseName(fileAddress), repository);
                } else {
                    String jobXmlStr = getResourceAsString(getResource(KettleComponent.TRANSFORMFILE));
                    // $NON-NLS-1$
                    jobXmlStr = jobXmlStr.replaceAll("\\$\\{pentaho.solutionpath\\}", solutionPath);
                    // $NON-NLS-1$
                    jobXmlStr = jobXmlStr.replaceAll("\\%\\%pentaho.solutionpath\\%\\%", solutionPath);
                    org.w3c.dom.Document doc = XmlW3CHelper.getDomFromString(jobXmlStr);
                    // create a tranformation from the document
                    transMeta = new TransMeta(doc.getFirstChild(), repository);
                }
            } catch (Exception e) {
                error(Messages.getInstance().getErrorString("Kettle.ERROR_0015_BAD_RESOURCE", KettleComponent.TRANSFORMFILE, fileAddress), // $NON-NLS-1$
                e);
                return false;
            }
            // Don't forget to set the parameters here as well...
            try {
                for (String key : parameterMap.keySet()) {
                    transMeta.setParameterValue(key, parameterMap.get(key));
                }
                for (String key : variableMap.keySet()) {
                    transMeta.setVariable(key, variableMap.get(key));
                }
            } catch (UnknownParamException e) {
                error(e.getMessage());
            }
            transMeta.setArguments(arguments);
            /*
         * We do not need to concatenate the solutionPath info as the fileAddress has the complete location of the file
         * from start to end. This is to resolve BISERVER-502.
         */
            transMeta.setFilename(fileAddress);
        } else if (isDefinedResource(KettleComponent.JOBFILE)) {
            // $NON-NLS-1$
            String fileAddress = "";
            try {
                fileAddress = getResource(KettleComponent.JOBFILE).getAddress();
                if (repository != null && repository.isConnected()) {
                    solutionPath = StringUtils.EMPTY;
                    // load job resource from kettle/settings.xml configured repository
                    jobMeta = loadJobFromRepository(FilenameUtils.getPathNoEndSeparator(fileAddress), FilenameUtils.getBaseName(fileAddress), repository);
                } else {
                    String jobXmlStr = getResourceAsString(getResource(KettleComponent.JOBFILE));
                    // String jobXmlStr =
                    // XmlW3CHelper.getContentFromSolutionResource(fileAddress);
                    // $NON-NLS-1$
                    jobXmlStr = jobXmlStr.replaceAll("\\$\\{pentaho.solutionpath\\}", solutionPath);
                    // $NON-NLS-1$
                    jobXmlStr = jobXmlStr.replaceAll("\\%\\%pentaho.solutionpath\\%\\%", solutionPath);
                    org.w3c.dom.Document doc = XmlW3CHelper.getDomFromString(jobXmlStr);
                    if (doc == null) {
                        error(Messages.getInstance().getErrorString("Kettle.ERROR_0015_BAD_RESOURCE", KettleComponent.JOBFILE, // $NON-NLS-1$
                        fileAddress));
                        debug(getKettleLog(true));
                        return false;
                    }
                    // create a job from the document
                    try {
                        repository = connectToRepository();
                        // if we get a valid repository its great, if not try it
                        // without
                        jobMeta = new JobMeta(solutionPath + fileAddress, repository);
                    } catch (Exception e) {
                        // $NON-NLS-1$
                        error(Messages.getInstance().getString("Kettle.ERROR_0023_NO_META"), e);
                    } finally {
                        if (repository != null) {
                            if (ComponentBase.debug) {
                                // $NON-NLS-1$
                                debug(Messages.getInstance().getString("Kettle.DEBUG_DISCONNECTING"));
                            }
                            repository.disconnect();
                        }
                    }
                }
            } catch (Exception e) {
                error(Messages.getInstance().getErrorString("Kettle.ERROR_0015_BAD_RESOURCE", KettleComponent.JOBFILE, fileAddress), // $NON-NLS-1$
                e);
                return false;
            }
            if (jobMeta == null) {
                error(Messages.getInstance().getErrorString("Kettle.ERROR_0015_BAD_RESOURCE", KettleComponent.JOBFILE, // $NON-NLS-1$
                fileAddress));
                debug(getKettleLog(true));
                return false;
            } else {
                try {
                    for (String key : parameterMap.keySet()) {
                        jobMeta.setParameterValue(key, parameterMap.get(key));
                    }
                    for (String key : variableMap.keySet()) {
                        jobMeta.setVariable(key, variableMap.get(key));
                    }
                } catch (UnknownParamException e) {
                    error(e.getMessage());
                }
                jobMeta.setArguments(arguments);
                jobMeta.setFilename(solutionPath + fileAddress);
            }
        }
        if (transMeta != null) {
            result = executeTransformation(transMeta);
        }
        if (jobMeta != null) {
            result = executeJob(jobMeta, repository);
        }
    } finally {
        if (repository != null) {
            if (ComponentBase.debug) {
                // $NON-NLS-1$
                debug(Messages.getInstance().getString("Kettle.DEBUG_DISCONNECTING"));
            }
            try {
                repository.disconnect();
            } catch (Exception ignored) {
            // ignore
            }
        }
        if (transMeta != null) {
            try {
                cleanLogChannel(transMeta);
                transMeta.clear();
            } catch (Exception ignored) {
            // ignore
            }
            transMeta = null;
        }
        if (jobMeta != null) {
            try {
                cleanLogChannel(jobMeta);
                jobMeta.clear();
            } catch (Exception ignored) {
            // ignored
            }
            // Can't do anything about an exception here.
            jobMeta = null;
        }
    }
    if (isDefinedOutput(EXECUTION_LOG_OUTPUT)) {
        setOutputValue(EXECUTION_LOG_OUTPUT, executionLog);
    }
    if (isDefinedOutput(EXECUTION_STATUS_OUTPUT)) {
        setOutputValue(EXECUTION_STATUS_OUTPUT, executionStatus);
    }
    XMLHandlerCache.getInstance().clear();
    return result;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) JobMeta(org.pentaho.di.job.JobMeta) HashMap(java.util.HashMap) Node(org.dom4j.Node) TransMeta(org.pentaho.di.trans.TransMeta) ArrayList(java.util.ArrayList) KettleException(org.pentaho.di.core.exception.KettleException) UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) IActionSequenceResource(org.pentaho.platform.api.engine.IActionSequenceResource) Repository(org.pentaho.di.repository.Repository) UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with UnknownParamException

use of org.pentaho.di.core.parameters.UnknownParamException in project pentaho-metaverse by pentaho.

the class AbstractMetaJsonSerializer method serializeParameters.

protected void serializeParameters(T meta, JsonGenerator json) throws IOException {
    json.writeArrayFieldStart(JSON_PROPERTY_PARAMETERS);
    String[] parameters = meta.listParameters();
    if (parameters != null) {
        for (String param : parameters) {
            try {
                ParamInfo paramInfo = new ParamInfo(param, null, meta.getParameterDefault(param), meta.getParameterDescription(param));
                json.writeObject(paramInfo);
            } catch (UnknownParamException e) {
                LOGGER.warn(Messages.getString("WARNING.Serialization.Trans.Param", param), e);
            }
        }
    }
    json.writeEndArray();
}
Also used : UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException) ParamInfo(org.pentaho.metaverse.impl.model.ParamInfo)

Aggregations

UnknownParamException (org.pentaho.di.core.parameters.UnknownParamException)17 KettleException (org.pentaho.di.core.exception.KettleException)7 Date (java.util.Date)5 ArrayList (java.util.ArrayList)4 ExecutionException (java.util.concurrent.ExecutionException)4 JobMeta (org.pentaho.di.job.JobMeta)4 TransMeta (org.pentaho.di.trans.TransMeta)4 IOException (java.io.IOException)3 TableItem (org.eclipse.swt.widgets.TableItem)3 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)3 Job (org.pentaho.di.job.Job)3 Repository (org.pentaho.di.repository.Repository)3 IParamInfo (org.pentaho.metaverse.api.model.IParamInfo)3 ParamInfo (org.pentaho.metaverse.impl.model.ParamInfo)3 Timestamp (java.sql.Timestamp)2 KettleClientEnvironment (org.pentaho.di.core.KettleClientEnvironment)2 Result (org.pentaho.di.core.Result)2 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)2 KettleStepException (org.pentaho.di.core.exception.KettleStepException)2 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)2