use of org.pentaho.di.core.logging.LogChannelInterface in project pdi-dataservice-server-plugin by pentaho.
the class AutoParameterGenerationService method apply.
@Override
public List<PushDownOptimizationMeta> apply(DataServiceMeta dataServiceMeta) {
TransMeta transMeta = dataServiceMeta.getServiceTrans();
LogChannelInterface logChannel = transMeta.getLogChannel() != null ? transMeta.getLogChannel() : LogChannel.GENERAL;
try {
String stepName = dataServiceMeta.getStepname();
List<String> fields = Arrays.asList(transMeta.getStepFields(stepName).getFieldNames());
Map<String, Set<List<StepFieldOperations>>> operationPaths = lineageClient.getOperationPaths(transMeta, stepName, fields);
SourceLineageMap sourceLineageMap = SourceLineageMap.create(operationPaths).filterKeys(stepSupported(transMeta)).filterKeys(not(in(parametrizedSteps(dataServiceMeta)))).filter(fieldUnchanged());
return generateOptimizationList(sourceLineageMap);
} catch (Throwable e) {
logChannel.logError("Unable to run Auto-Optimization", e);
return Collections.emptyList();
}
}
use of org.pentaho.di.core.logging.LogChannelInterface in project pentaho-kettle by pentaho.
the class JobEntryWriteToLog method evaluate.
/**
* Output message to job log.
*/
public boolean evaluate(Result result) {
LogChannelInterface logChannel = createLogChannel();
String message = getRealLogMessage();
// Filter out empty messages and those that are not visible with the job's log level
if (Utils.isEmpty(message) || !getEntryLogLevel().isVisible(logChannel.getLogLevel())) {
return true;
}
try {
switch(getEntryLogLevel()) {
case ERROR:
logChannel.logError(message + Const.CR);
break;
case MINIMAL:
logChannel.logMinimal(message + Const.CR);
break;
case BASIC:
logChannel.logBasic(message + Const.CR);
break;
case DETAILED:
logChannel.logDetailed(message + Const.CR);
break;
case DEBUG:
logChannel.logDebug(message + Const.CR);
break;
case ROWLEVEL:
logChannel.logRowlevel(message + Const.CR);
break;
default:
// NOTHING
break;
}
return true;
} catch (Exception e) {
result.setNrErrors(1);
log.logError(BaseMessages.getString(PKG, "WriteToLog.Error.Label"), BaseMessages.getString(PKG, "WriteToLog.Error.Description") + " : " + e.toString());
return false;
}
}
use of org.pentaho.di.core.logging.LogChannelInterface in project pentaho-kettle by pentaho.
the class Kitchen method main.
public static void main(String[] a) throws Exception {
final ExecutorService executor = ExecutorUtil.getExecutor();
final RepositoryPluginType repositoryPluginType = RepositoryPluginType.getInstance();
Locale.setDefault(LanguageChoice.getInstance().getDefaultLocale());
final Future<Map.Entry<KettlePluginException, Future<KettleException>>> repositoryRegisterFuture = executor.submit(new Callable<Map.Entry<KettlePluginException, Future<KettleException>>>() {
@Override
public Map.Entry<KettlePluginException, Future<KettleException>> call() throws Exception {
PluginRegistry.addPluginType(repositoryPluginType);
try {
KettleClientEnvironment.getInstance().setClient(KettleClientEnvironment.ClientType.KITCHEN);
KettleClientEnvironment.init();
} catch (KettlePluginException e) {
return new AbstractMap.SimpleImmutableEntry<KettlePluginException, Future<KettleException>>(e, null);
}
Future<KettleException> kettleEnvironmentInitFuture = executor.submit(new Callable<KettleException>() {
@Override
public KettleException call() throws Exception {
try {
KettleClientEnvironment.getInstance().setClient(KettleClientEnvironment.ClientType.KITCHEN);
KettleEnvironment.init();
} catch (KettleException e) {
return e;
}
return null;
}
});
return new AbstractMap.SimpleImmutableEntry<KettlePluginException, Future<KettleException>>(null, kettleEnvironmentInitFuture);
}
});
List<String> args = new ArrayList<String>();
for (int i = 0; i < a.length; i++) {
if (a[i].length() > 0) {
args.add(a[i]);
}
}
DelegatingMetaStore metaStore = new DelegatingMetaStore();
metaStore.addMetaStore(MetaStoreConst.openLocalPentahoMetaStore());
metaStore.setActiveMetaStoreName(metaStore.getName());
StringBuilder optionRepname, optionUsername, optionTrustUser, optionPassword, optionJobname, optionDirname, initialDir;
StringBuilder optionFilename, optionLoglevel, optionLogfile, optionLogfileOld, optionListdir;
StringBuilder optionListjobs, optionListrep, optionNorep, optionVersion, optionListParam, optionExport, optionBase64Zip, optionUuid;
NamedParams optionParams = new NamedParamsDefault();
NamedParams customOptions = new NamedParamsDefault();
CommandLineOption maxLogLinesOption = new CommandLineOption("maxloglines", BaseMessages.getString(PKG, "Kitchen.CmdLine.MaxLogLines"), new StringBuilder());
CommandLineOption maxLogTimeoutOption = new CommandLineOption("maxlogtimeout", BaseMessages.getString(PKG, "Kitchen.CmdLine.MaxLogTimeout"), new StringBuilder());
CommandLineOption[] options = new CommandLineOption[] { new CommandLineOption("rep", BaseMessages.getString(PKG, "Kitchen.CmdLine.RepName"), optionRepname = new StringBuilder()), new CommandLineOption("user", BaseMessages.getString(PKG, "Kitchen.CmdLine.RepUsername"), optionUsername = new StringBuilder()), new CommandLineOption("trustuser", BaseMessages.getString(PKG, "Kitchen.ComdLine.RepUsername"), optionTrustUser = new StringBuilder()), new CommandLineOption("pass", BaseMessages.getString(PKG, "Kitchen.CmdLine.RepPassword"), optionPassword = new StringBuilder()), new CommandLineOption("job", BaseMessages.getString(PKG, "Kitchen.CmdLine.RepJobName"), optionJobname = new StringBuilder()), new CommandLineOption("dir", BaseMessages.getString(PKG, "Kitchen.CmdLine.RepDir"), optionDirname = new StringBuilder()), new CommandLineOption("file", BaseMessages.getString(PKG, "Kitchen.CmdLine.XMLJob"), optionFilename = new StringBuilder()), new CommandLineOption("level", BaseMessages.getString(PKG, "Kitchen.CmdLine.LogLevel"), optionLoglevel = new StringBuilder()), new CommandLineOption("logfile", BaseMessages.getString(PKG, "Kitchen.CmdLine.LogFile"), optionLogfile = new StringBuilder()), new CommandLineOption("log", BaseMessages.getString(PKG, "Kitchen.CmdLine.LogFileOld"), optionLogfileOld = new StringBuilder(), false, true), new CommandLineOption("listdir", BaseMessages.getString(PKG, "Kitchen.CmdLine.ListDir"), optionListdir = new StringBuilder(), true, false), new CommandLineOption("listjobs", BaseMessages.getString(PKG, "Kitchen.CmdLine.ListJobsDir"), optionListjobs = new StringBuilder(), true, false), new CommandLineOption("listrep", BaseMessages.getString(PKG, "Kitchen.CmdLine.ListAvailableReps"), optionListrep = new StringBuilder(), true, false), new CommandLineOption("norep", BaseMessages.getString(PKG, "Kitchen.CmdLine.NoRep"), optionNorep = new StringBuilder(), true, false), new CommandLineOption("version", BaseMessages.getString(PKG, "Kitchen.CmdLine.Version"), optionVersion = new StringBuilder(), true, false), new CommandLineOption("param", BaseMessages.getString(PKG, "Kitchen.ComdLine.Param"), optionParams, false), new CommandLineOption("listparam", BaseMessages.getString(PKG, "Kitchen.ComdLine.ListParam"), optionListParam = new StringBuilder(), true, false), new CommandLineOption("export", BaseMessages.getString(PKG, "Kitchen.ComdLine.Export"), optionExport = new StringBuilder(), true, false), new CommandLineOption("initialDir", null, initialDir = new StringBuilder(), false, true), new CommandLineOption("zip", "Base64Zip", optionBase64Zip = new StringBuilder(), false, true), new CommandLineOption("uuid", "UUID", optionUuid = new StringBuilder(), false, true), new CommandLineOption("custom", BaseMessages.getString(PKG, "Kitchen.ComdLine.Custom"), customOptions, false), maxLogLinesOption, maxLogTimeoutOption };
if (args.size() == 2) {
// 2 internal hidden argument (flag and value)
CommandLineOption.printUsage(options);
exitJVM(9);
}
LogChannelInterface log = new LogChannel(STRING_KITCHEN);
CommandLineOption.parseArguments(args, options, log);
configureLogging(maxLogLinesOption, maxLogTimeoutOption);
String kettleRepname = Const.getEnvironmentVariable("KETTLE_REPOSITORY", null);
String kettleUsername = Const.getEnvironmentVariable("KETTLE_USER", null);
String kettlePassword = Const.getEnvironmentVariable("KETTLE_PASSWORD", null);
if (!Utils.isEmpty(kettleRepname)) {
optionRepname = new StringBuilder(kettleRepname);
}
if (!Utils.isEmpty(kettleUsername)) {
optionUsername = new StringBuilder(kettleUsername);
}
if (!Utils.isEmpty(kettlePassword)) {
optionPassword = new StringBuilder(kettlePassword);
}
if (Utils.isEmpty(optionLogfile) && !Utils.isEmpty(optionLogfileOld)) {
// if the old style of logging name is filled in, and the new one is not
// overwrite the new by the old
optionLogfile = optionLogfileOld;
}
Map.Entry<KettlePluginException, Future<KettleException>> repositoryRegisterResults = repositoryRegisterFuture.get();
// It's a singleton map with one key-value pair (a Pair collection)
KettlePluginException repositoryRegisterException = repositoryRegisterResults.getKey();
if (repositoryRegisterException != null) {
throw repositoryRegisterException;
}
Future<KettleException> kettleInitFuture = repositoryRegisterResults.getValue();
if (!Utils.isEmpty(optionLogfile)) {
fileAppender = new FileLoggingEventListener(optionLogfile.toString(), true);
KettleLogStore.getAppender().addLoggingEventListener(fileAppender);
} else {
fileAppender = null;
}
if (!Utils.isEmpty(optionLoglevel)) {
log.setLogLevel(LogLevel.getLogLevelForCode(optionLoglevel.toString()));
log.logMinimal(BaseMessages.getString(PKG, "Kitchen.Log.LogLevel", log.getLogLevel().getDescription()));
}
// Start the action...
//
Result result = new Result();
try {
if (getCommandExecutor() == null) {
// init
setCommandExecutor(new KitchenCommandExecutor(PKG, log, kettleInitFuture));
}
if (!Utils.isEmpty(optionVersion)) {
getCommandExecutor().printVersion();
if (a.length == 1) {
exitJVM(CommandExecutorCodes.Pan.KETTLE_VERSION_PRINT.getCode());
}
}
Params.Builder builder = optionUuid.length() > 0 ? new Params.Builder(optionUuid.toString()) : new Params.Builder();
Params jobParams = (builder).blockRepoConns(optionNorep.toString()).repoName(optionRepname.toString()).repoUsername(optionUsername.toString()).trustRepoUser(optionTrustUser.toString()).repoPassword(optionPassword.toString()).inputDir(optionDirname.toString()).inputFile(optionJobname.toString()).listRepoFiles(optionListjobs.toString()).listRepoDirs(optionListdir.toString()).exportRepo(optionExport.toString()).localFile(optionFilename.toString()).localJarFile("").localInitialDir(initialDir.toString()).listRepos(optionListrep.toString()).listFileParams(optionListParam.toString()).logLevel("").maxLogLines("").maxLogTimeout("").logFile("").oldLogFile("").version("").resultSetStepName("").resultSetCopyNumber("").base64Zip(optionBase64Zip.toString()).namedParams(optionParams).customNamedParams(customOptions).build();
result = getCommandExecutor().execute(jobParams, args.toArray(new String[args.size()]));
} catch (Throwable t) {
t.printStackTrace();
result.setExitStatus(CommandExecutorCodes.Pan.UNEXPECTED_ERROR.getCode());
} finally {
if (fileAppender != null) {
fileAppender.close();
KettleLogStore.getAppender().removeLoggingEventListener(fileAppender);
}
}
exitJVM(result.getExitStatus());
}
use of org.pentaho.di.core.logging.LogChannelInterface in project pentaho-kettle by pentaho.
the class MetaFileLoaderImplTest method setupTransExecutorMeta.
private void setupTransExecutorMeta() throws Exception {
TransExecutorMeta transExecutorMeta = new TransExecutorMeta();
baseStepMeta = transExecutorMeta;
TransMeta parentTransMeta = spy(new TransMeta());
LogChannelInterface logger = mock(LogChannelInterface.class);
metaFileCache = new MetaFileCacheImpl(logger);
parentTransMeta.setMetaFileCache(metaFileCache);
when(parentTransMeta.getNamedClusterEmbedManager()).thenReturn(namedClusterEmbedManager);
StepMeta stepMeta = new StepMeta();
stepMeta.setParentTransMeta(parentTransMeta);
transExecutorMeta.setParentStepMeta(stepMeta);
keyPath = getClass().getResource(TRANS_FILE).getPath();
transExecutorMeta.setFileName(keyPath);
Job job = new Job();
space = job;
targetMetaName = TRANS_FILE;
transExecutorMeta.setTransName(targetMetaName);
transExecutorMeta.setTransObjectId(null);
// repo stuff
keyPath = convertToRepoKeyPath(keyPath);
transExecutorMeta.setDirectoryPath(keyPath.substring(0, keyPath.lastIndexOf("/")));
transExecutorMeta.setTransObjectId(null);
RepositoryDirectoryInterface rdi = mock(RepositoryDirectoryInterface.class);
when(repository.findDirectory(transExecutorMeta.getDirectoryPath())).thenReturn(rdi);
when(repository.loadRepositoryDirectoryTree()).thenReturn(rdi);
TransMeta transMeta = new TransMeta();
transMeta.setName(stripExtension(TRANS_FILE));
when(repository.loadTransformation(TRANS_FILE, rdi, null, true, null)).thenReturn(transMeta);
}
use of org.pentaho.di.core.logging.LogChannelInterface in project pentaho-kettle by pentaho.
the class TextFileInputTest method convertLineToRowTest.
/**
* PDI-14390 Text file input throws NPE if skipping error rows and passing through incoming fieds
*
* @throws Exception
*/
@Test
public void convertLineToRowTest() throws Exception {
LogChannelInterface log = Mockito.mock(LogChannelInterface.class);
TextFileLine textFileLine = Mockito.mock(TextFileLine.class);
textFileLine.setLine("testData1;testData2;testData3");
InputFileMetaInterface info = Mockito.mock(InputFileMetaInterface.class);
TextFileInputField[] textFileInputFields = { new TextFileInputField(), new TextFileInputField(), new TextFileInputField() };
Mockito.doReturn(textFileInputFields).when(info).getInputFields();
Mockito.doReturn("CSV").when(info).getFileType();
Mockito.doReturn("/").when(info).getEscapeCharacter();
Mockito.doReturn(true).when(info).isErrorIgnored();
Mockito.doReturn(true).when(info).isErrorLineSkipped();
RowMetaInterface outputRowMeta = Mockito.mock(RowMetaInterface.class);
Mockito.doReturn(15).when(outputRowMeta).size();
ValueMetaInterface valueMetaWithError = Mockito.mock(ValueMetaInterface.class);
Mockito.doThrow(new KettleValueException("Error converting")).when(valueMetaWithError).convertDataFromString(Mockito.anyString(), Mockito.any(ValueMetaInterface.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyInt());
Mockito.doReturn(valueMetaWithError).when(outputRowMeta).getValueMeta(Mockito.anyInt());
// it should run without NPE
TextFileInput.convertLineToRow(log, textFileLine, info, new Object[3], 1, outputRowMeta, Mockito.mock(RowMetaInterface.class), null, 1L, ";", null, "/", Mockito.mock(FileErrorHandler.class), false, false, false, false, false, false, false, false, null, null, false, new Date(), null, null, null, 1L);
}
Aggregations