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;
}
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);
}
}
}
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());
}
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;
}
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();
}
Aggregations