Search in sources :

Example 31 with RepositoryMeta

use of org.pentaho.di.repository.RepositoryMeta in project pentaho-kettle by pentaho.

the class PanCommandExecutor method printRepositories.

protected void printRepositories(RepositoriesMeta repositoriesMeta) {
    if (repositoriesMeta != null) {
        logDebug("Pan.Log.GettingListReps");
        for (int i = 0; i < repositoriesMeta.nrRepositories(); i++) {
            RepositoryMeta repInfo = repositoriesMeta.getRepository(i);
            System.out.println(BaseMessages.getString(getPkgClazz(), "Pan.Log.RepNameDesc", "" + (i + 1), repInfo.getName(), repInfo.getDescription()));
        }
    }
}
Also used : RepositoryMeta(org.pentaho.di.repository.RepositoryMeta)

Example 32 with RepositoryMeta

use of org.pentaho.di.repository.RepositoryMeta in project pentaho-kettle by pentaho.

the class PanCommandExecutor method execute.

public int execute(String repoName, String noRepo, String username, String trustUser, String password, String dirName, String filename, String jarFile, String transName, String listTrans, String listDirs, String exportRepo, String initialDir, String listRepos, String safemode, String metrics, String listParams, NamedParams params, String[] arguments) throws Throwable {
    getLog().logMinimal(BaseMessages.getString(getPkgClazz(), "Pan.Log.StartingToRun"));
    // capture execution start time
    Date start = Calendar.getInstance().getTime();
    logDebug("Pan.Log.AllocatteNewTrans");
    Trans trans = null;
    // In case we use a repository...
    Repository repository = null;
    try {
        if (getMetaStore() == null) {
            setMetaStore(createDefaultMetastore());
        }
        logDebug("Pan.Log.StartingToLookOptions");
        // Read kettle transformation specified
        if (!Utils.isEmpty(repoName) || !Utils.isEmpty(filename) || !Utils.isEmpty(jarFile)) {
            logDebug("Pan.Log.ParsingCommandline");
            if (!Utils.isEmpty(repoName) && !YES.equalsIgnoreCase(noRepo)) {
                /**
                 * if set, _trust_user_ needs to be considered. See pur-plugin's:
                 *
                 * @link https://github.com/pentaho/pentaho-kettle/blob/8.0.0.0-R/plugins/pur/core/src/main/java/org/pentaho/di/repository/pur/PurRepositoryConnector.java#L97-L101
                 * @link https://github.com/pentaho/pentaho-kettle/blob/8.0.0.0-R/plugins/pur/core/src/main/java/org/pentaho/di/repository/pur/WebServiceManager.java#L130-L133
                 */
                if (YES.equalsIgnoreCase(trustUser)) {
                    System.setProperty("pentaho.repository.client.attemptTrust", YES);
                }
                // In case we use a repository...
                // some commands are to load a Trans from the repo; others are merely to print some repo-related information
                RepositoryMeta repositoryMeta = loadRepositoryConnection(repoName, "Pan.Log.LoadingAvailableRep", "Pan.Error.NoRepsDefined", "Pan.Log.FindingRep");
                repository = establishRepositoryConnection(repositoryMeta, username, password, RepositoryOperation.EXECUTE_TRANSFORMATION);
                trans = executeRepositoryBasedCommand(repository, repositoryMeta, dirName, transName, listTrans, listDirs, exportRepo);
            }
            // You could implement some fail-over mechanism this way.
            if (trans == null) {
                trans = executeFilesystemBasedCommand(initialDir, filename, jarFile);
            }
        }
        if (YES.equalsIgnoreCase(listRepos)) {
            // list the repositories placed at repositories.xml
            printRepositories(loadRepositoryInfo("Pan.Log.LoadingAvailableRep", "Pan.Error.NoRepsDefined"));
        }
    } catch (Exception e) {
        trans = null;
        System.out.println(BaseMessages.getString(getPkgClazz(), "Pan.Error.ProcessStopError", e.getMessage()));
        e.printStackTrace();
        if (repository != null) {
            repository.disconnect();
        }
        return CommandExecutorCodes.Pan.ERRORS_DURING_PROCESSING.getCode();
    }
    if (trans == null) {
        if (!YES.equalsIgnoreCase(listTrans) && !YES.equalsIgnoreCase(listDirs) && !YES.equalsIgnoreCase(listRepos) && Utils.isEmpty(exportRepo)) {
            System.out.println(BaseMessages.getString(getPkgClazz(), "Pan.Error.CanNotLoadTrans"));
            return CommandExecutorCodes.Pan.COULD_NOT_LOAD_TRANS.getCode();
        } else {
            return CommandExecutorCodes.Pan.SUCCESS.getCode();
        }
    }
    try {
        trans.setLogLevel(getLog().getLogLevel());
        configureParameters(trans, params, trans.getTransMeta());
        // run in safe mode if requested
        trans.setSafeModeEnabled(YES.equalsIgnoreCase(safemode));
        // enable kettle metric gathering if requested
        trans.setGatheringMetrics(YES.equalsIgnoreCase(metrics));
        // List the parameters defined in this transformation, and then simply exit
        if (YES.equalsIgnoreCase(listParams)) {
            printTransformationParameters(trans);
            // same as the other list options
            return CommandExecutorCodes.Pan.COULD_NOT_LOAD_TRANS.getCode();
        }
        // allocate & run the required sub-threads
        try {
            trans.execute(arguments);
        } catch (KettleException ke) {
            logDebug(ke.getLocalizedMessage());
            System.out.println(BaseMessages.getString(getPkgClazz(), "Pan.Error.UnablePrepareInitTrans"));
            return CommandExecutorCodes.Pan.UNABLE_TO_PREP_INIT_TRANS.getCode();
        }
        // Give the transformation up to 10 seconds to finish execution
        waitUntilFinished(trans, 100);
        if (trans.isRunning()) {
            getLog().logError(BaseMessages.getString(getPkgClazz(), "Pan.Log.NotStopping"));
        }
        getLog().logMinimal(BaseMessages.getString(getPkgClazz(), "Pan.Log.Finished"));
        // capture execution stop time
        Date stop = Calendar.getInstance().getTime();
        int completionTimeSeconds = calculateAndPrintElapsedTime(start, stop, "Pan.Log.StartStop", "Pan.Log.ProcessingEndAfter", "Pan.Log.ProcessingEndAfterLong", "Pan.Log.ProcessingEndAfterLonger", "Pan.Log.ProcessingEndAfterLongest");
        if (trans.getResult().getNrErrors() == 0) {
            trans.printStats(completionTimeSeconds);
            return CommandExecutorCodes.Pan.SUCCESS.getCode();
        } else {
            String transJVMExitCode = trans.getVariable(Const.KETTLE_TRANS_PAN_JVM_EXIT_CODE);
            // If the trans has a return code to return to the OS, then we exit with that
            if (!Utils.isEmpty(transJVMExitCode)) {
                try {
                    return Integer.parseInt(transJVMExitCode);
                } catch (NumberFormatException nfe) {
                    getLog().logError(BaseMessages.getString(getPkgClazz(), "Pan.Error.TransJVMExitCodeInvalid", Const.KETTLE_TRANS_PAN_JVM_EXIT_CODE, transJVMExitCode));
                    getLog().logError(BaseMessages.getString(getPkgClazz(), "Pan.Log.JVMExitCode", "1"));
                    return CommandExecutorCodes.Pan.ERRORS_DURING_PROCESSING.getCode();
                }
            } else {
                // the trans does not have a return code.
                return CommandExecutorCodes.Pan.ERRORS_DURING_PROCESSING.getCode();
            }
        }
    } catch (KettleException ke) {
        System.out.println(BaseMessages.getString(getPkgClazz(), "Pan.Log.ErrorOccurred", "" + ke.getMessage()));
        getLog().logError(BaseMessages.getString(getPkgClazz(), "Pan.Log.UnexpectedErrorOccurred", "" + ke.getMessage()));
        return CommandExecutorCodes.Pan.UNEXPECTED_ERROR.getCode();
    } finally {
        if (repository != null) {
            repository.disconnect();
        }
        if (YES.equalsIgnoreCase(trustUser)) {
            // we set it, now we sanitize it
            System.clearProperty("pentaho.repository.client.attemptTrust");
        }
    }
}
Also used : RepositoryMeta(org.pentaho.di.repository.RepositoryMeta) KettleException(org.pentaho.di.core.exception.KettleException) Repository(org.pentaho.di.repository.Repository) Trans(org.pentaho.di.trans.Trans) Date(java.util.Date) KettleException(org.pentaho.di.core.exception.KettleException) UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException)

Example 33 with RepositoryMeta

use of org.pentaho.di.repository.RepositoryMeta in project pentaho-kettle by pentaho.

the class JobExecutionConfiguration method connectRepository.

public Repository connectRepository(RepositoriesMeta repositoriesMeta, String repositoryName, String username, String password) throws KettleException {
    RepositoryMeta repositoryMeta = repositoriesMeta.findRepository(repositoryName);
    if (repositoryMeta == null) {
        log.logBasic("I couldn't find the repository with name '" + repositoryName + "'");
        return null;
    }
    Repository rep = PluginRegistry.getInstance().loadClass(RepositoryPluginType.class, repositoryMeta, Repository.class);
    rep.init(repositoryMeta);
    try {
        rep.connect(username, password);
        log.logBasic("Connected to " + repositoryName + " as " + username);
        setRepository(rep);
        return rep;
    } catch (Exception e) {
        log.logBasic("Unable to connect to the repository with name '" + repositoryName + "'");
        return null;
    }
}
Also used : RepositoryMeta(org.pentaho.di.repository.RepositoryMeta) Repository(org.pentaho.di.repository.Repository) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException)

Example 34 with RepositoryMeta

use of org.pentaho.di.repository.RepositoryMeta in project pentaho-kettle by pentaho.

the class GetRepositoryNamesTest method prepareFileRepository.

private static void prepareFileRepository() throws IOException, KettleException {
    baseDirName = Files.createTempDirectory("GetRepositoryNamesIT");
    RepositoryMeta repoMeta = new KettleFileRepositoryMeta(UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), baseDirName.toString());
    repo = new KettleFileRepository();
    repo.init(repoMeta);
    repo.connect(null, null);
    // Populate
    RepositoryDirectoryInterface rootDir = repo.findDirectory("/");
    RepositoryDirectoryInterface subdir1 = new RepositoryDirectory(rootDir, "subdir1");
    repo.saveRepositoryDirectory(subdir1);
    TransMeta transMeta1 = new TransMeta();
    transMeta1.setName("Trans1");
    transMeta1.setRepositoryDirectory(subdir1);
    repo.save(transMeta1, null, null);
    JobMeta jobMeta1 = new JobMeta();
    jobMeta1.setName("Job1");
    jobMeta1.setRepositoryDirectory(subdir1);
    repo.save(jobMeta1, null, null);
    RepositoryDirectoryInterface subdir2 = new RepositoryDirectory(subdir1, "subdir2");
    repo.saveRepositoryDirectory(subdir2);
    TransMeta transMeta2 = new TransMeta();
    transMeta2.setName("Trans2");
    transMeta2.setRepositoryDirectory(subdir2);
    repo.save(transMeta2, null, null);
    JobMeta jobMeta2 = new JobMeta();
    jobMeta2.setName("Job2");
    jobMeta2.setRepositoryDirectory(subdir2);
    repo.save(jobMeta2, null, null);
}
Also used : KettleFileRepositoryMeta(org.pentaho.di.repository.filerep.KettleFileRepositoryMeta) RepositoryMeta(org.pentaho.di.repository.RepositoryMeta) RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) JobMeta(org.pentaho.di.job.JobMeta) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) TransMeta(org.pentaho.di.trans.TransMeta) KettleFileRepositoryMeta(org.pentaho.di.repository.filerep.KettleFileRepositoryMeta) KettleFileRepository(org.pentaho.di.repository.filerep.KettleFileRepository)

Example 35 with RepositoryMeta

use of org.pentaho.di.repository.RepositoryMeta in project pentaho-kettle by pentaho.

the class JobEntryConnectedToRepositoryDialog method getListRepositories.

/**
 * Get a list of repositories defined in this system, allow the user to select from it.
 */
private void getListRepositories() {
    RepositoriesMeta reps_info = null;
    try {
        reps_info = new RepositoriesMeta();
        try {
            reps_info.readData();
            int nrRepositories = reps_info.nrRepositories();
            if (nrRepositories == 0) {
                displayMsg(BaseMessages.getString(PKG, "System.Dialog.Error.Title"), BaseMessages.getString(PKG, "JobEntryConnectedToRepositoryDialog.Error.NoRep.DialogMessage"), true);
            } else {
                String[] available = new String[nrRepositories];
                for (int i = 0; i < nrRepositories; i++) {
                    RepositoryMeta ri = reps_info.getRepository(i);
                    available[i] = ri.getName();
                }
                String[] source = new String[1];
                source[0] = wRepName.getText();
                int[] idxSource = Const.indexsOfStrings(source, available);
                EnterSelectionDialog dialog = new EnterSelectionDialog(shell, available, BaseMessages.getString(PKG, "JobEntryConnectedToRepositoryDialog.SelectRepository.Title"), BaseMessages.getString(PKG, "JobEntryConnectedToRepositoryDialog.SelectRepository.Message"));
                dialog.setMulti(false);
                dialog.setAvoidQuickSearch();
                dialog.setSelectedNrs(idxSource);
                if (dialog.open() != null) {
                    int[] idx = dialog.getSelectionIndeces();
                    wRepName.setText(available[idx[0]]);
                }
            }
        } catch (Exception e) {
            displayMsg(BaseMessages.getString(PKG, "JobEntryConnectedToRepositoryDialog.Error.NoRepsDefined"), BaseMessages.getString(PKG, "JobEntryConnectedToRepositoryDialog.Error.NoRepsDefinedMsg"), true);
        }
    } catch (Exception e) {
        displayMsg(BaseMessages.getString(PKG, "System.Dialog.Error.Title"), BaseMessages.getString(PKG, "JobEntryConnectedToRepositoryDialog.ErrorGettingRepositories.DialogMessage") + Const.CR + ":" + e.getMessage(), true);
    } finally {
        reps_info.clear();
    }
}
Also used : RepositoryMeta(org.pentaho.di.repository.RepositoryMeta) RepositoriesMeta(org.pentaho.di.repository.RepositoriesMeta) EnterSelectionDialog(org.pentaho.di.ui.core.dialog.EnterSelectionDialog)

Aggregations

RepositoryMeta (org.pentaho.di.repository.RepositoryMeta)44 KettleException (org.pentaho.di.core.exception.KettleException)27 Repository (org.pentaho.di.repository.Repository)16 RepositoriesMeta (org.pentaho.di.repository.RepositoriesMeta)14 RepositoryPluginType (org.pentaho.di.core.plugins.RepositoryPluginType)10 Test (org.junit.Test)4 KettleSecurityException (org.pentaho.di.core.exception.KettleSecurityException)4 UnknownParamException (org.pentaho.di.core.parameters.UnknownParamException)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 Map (java.util.Map)3 PluginInterface (org.pentaho.di.core.plugins.PluginInterface)3 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)3 RepositoryDialog (org.pentaho.di.ui.repo.dialog.RepositoryDialog)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 StringBufferInputStream (java.io.StringBufferInputStream)2 HashMap (java.util.HashMap)2 ExecutionException (java.util.concurrent.ExecutionException)2