Search in sources :

Example 91 with Repository

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

the class ExecuteTransServlet method openRepository.

private Repository openRepository(String repositoryName, String user, String pass) throws KettleException {
    if (Utils.isEmpty(repositoryName)) {
        return null;
    }
    RepositoriesMeta repositoriesMeta = new RepositoriesMeta();
    repositoriesMeta.readData();
    RepositoryMeta repositoryMeta = repositoriesMeta.findRepository(repositoryName);
    if (repositoryMeta == null) {
        throw new KettleException("Unable to find repository: " + repositoryName);
    }
    PluginRegistry registry = PluginRegistry.getInstance();
    Repository repository = registry.loadClass(RepositoryPluginType.class, repositoryMeta, Repository.class);
    repository.init(repositoryMeta);
    repository.connect(user, pass);
    return repository;
}
Also used : RepositoryMeta(org.pentaho.di.repository.RepositoryMeta) KettleException(org.pentaho.di.core.exception.KettleException) Repository(org.pentaho.di.repository.Repository) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) RepositoriesMeta(org.pentaho.di.repository.RepositoriesMeta)

Example 92 with Repository

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

the class ExecuteTransServlet method doGet.

/**
 * <div id="mindtouch">
 *    <h1>/kettle/executeTrans</h1>
 *    <a name="GET"></a>
 *    <h2>GET</h2>
 *    <p>Executes transformation from the specified repository.
 *  Connects to the repository provided as a parameter, loads the transformation from it and executes it.
 *  Empty response is returned or response contains output of an error happened during the transformation execution.
 *  Response contains <code>ERROR</code> result if error happened during transformation execution.</p>
 *
 *    <p><b>Example Request:</b><br />
 *    <pre function="syntax.xml">
 *    GET /kettle/executeTrans/?rep=my_repository&user=my_user&pass=my_password&trans=my_trans&level=INFO
 *    </pre>
 *
 *    </p>
 *    <h3>Parameters</h3>
 *    <table class="pentaho-table">
 *    <tbody>
 *    <tr>
 *      <th>name</th>
 *      <th>description</th>
 *      <th>type</th>
 *    </tr>
 *    <tr>
 *    <td>rep</td>
 *    <td>Repository id to connect to.</td>
 *    <td>query</td>
 *    </tr>
 *    <tr>
 *    <td>user</td>
 *    <td>User name to be used to connect to repository.</td>
 *    <td>query</td>
 *    </tr>
 *    <tr>
 *    <td>pass</td>
 *    <td>User password to be used to connect to repository.</td>
 *    <td>query</td>
 *    </tr>
 *    <tr>
 *    <td>trans</td>
 *    <td>Transfromation name to be loaded and executed.</td>
 *    <td>query</td>
 *    </tr>
 *    <tr>
 *    <td>level</td>
 *    <td>Logging level to be used for transformation execution (i.e. Debug).</td>
 *    <td>query</td>
 *    </tr>
 *    <tr>
 *    <td>*any name*</td>
 *    <td>All the other parameters will be sent to the transformation for using as variables.
 *  When necessary you can add custom parameters to the request.
 *  They will be used to set the transformation variables values..</td>
 *    <td>query</td>
 *    </tr>
 *    </tbody>
 *    </table>
 *
 *  <h3>Response Body</h3>
 *
 *  <table class="pentaho-table">
 *    <tbody>
 *      <tr>
 *        <td align="right">element:</td>
 *        <td>(custom)</td>
 *      </tr>
 *      <tr>
 *        <td align="right">media types:</td>
 *        <td>application/xml</td>
 *      </tr>
 *    </tbody>
 *  </table>
 *    <p>Response contains error output of the transformation executed or nothing
 *  if the execution was successful.</p>
 *
 *    <p><b>Example Error Response:</b></p>
 *    <pre function="syntax.xml">
 *  <webresult>
 *    <result>ERROR</result>
 *    <message>Unexpected error executing the transformation&#x3a;
 *    &#xd;&#xa;org.pentaho.di.core.exception.KettleException&#x3a;
 *    &#xd;&#xa;Unable to find transformation &#x27;dummy-trans.ktr&#x27; in directory
 *    &#x3a;&#x2f;home&#x2f;admin&#xd;&#xa;&#xd;&#xa; at
 *    org.pentaho.di.www.ExecuteTransServlet.loadTransformation&#x28;ExecuteTransServlet.java&#x3a;214&#x29;&#xd;&#xa;
 *    at org.pentaho.di.www.ExecuteTransServlet.doGet&#x28;ExecuteTransServlet.java&#x3a;104&#x29;&#xd;&#xa;
 *    at javax.servlet.http.HttpServlet.service&#x28;HttpServlet.java&#x3a;707&#x29;&#xd;&#xa;
 *    at javax.servlet.http.HttpServlet.service&#x28;HttpServlet.java&#x3a;820&#x29;&#xd;&#xa;
 *    at org.mortbay.jetty.servlet.ServletHolder.handle&#x28;ServletHolder.java&#x3a;511&#x29;&#xd;&#xa;
 *    at org.mortbay.jetty.servlet.ServletHandler.handle&#x28;ServletHandler.java&#x3a;390&#x29;&#xd;&#xa;
 *    at org.mortbay.jetty.servlet.SessionHandler.handle&#x28;SessionHandler.java&#x3a;182&#x29;&#xd;&#xa;
 *    at org.mortbay.jetty.handler.ContextHandler.handle&#x28;ContextHandler.java&#x3a;765&#x29;&#xd;&#xa;
 *    at org.mortbay.jetty.handler.ContextHandlerCollection.handle&#x28;ContextHandlerCollection.java&#x3a;230&#x29;&#xd;&#xa;
 *    at org.mortbay.jetty.handler.HandlerCollection.handle&#x28;HandlerCollection.java&#x3a;114&#x29;&#xd;&#xa;
 *    at org.mortbay.jetty.handler.HandlerWrapper.handle&#x28;HandlerWrapper.java&#x3a;152&#x29;&#xd;&#xa;
 *    at org.mortbay.jetty.Server.handle&#x28;Server.java&#x3a;326&#x29;&#xd;&#xa;
 *    at org.mortbay.jetty.HttpConnection.handleRequest&#x28;HttpConnection.java&#x3a;536&#x29;&#xd;&#xa;
 *    at org.mortbay.jetty.HttpConnection&#x24;RequestHandler.headerComplete&#x28;HttpConnection.java&#x3a;915&#x29;&#xd;&#xa;
 *    at org.mortbay.jetty.HttpParser.parseNext&#x28;HttpParser.java&#x3a;539&#x29;&#xd;&#xa;
 *    at org.mortbay.jetty.HttpParser.parseAvailable&#x28;HttpParser.java&#x3a;212&#x29;&#xd;&#xa;
 *    at org.mortbay.jetty.HttpConnection.handle&#x28;HttpConnection.java&#x3a;405&#x29;&#xd;&#xa;
 *    at org.mortbay.jetty.bio.SocketConnector&#x24;Connection.run&#x28;SocketConnector.java&#x3a;228&#x29;&#xd;&#xa;
 *    at org.mortbay.thread.QueuedThreadPool&#x24;PoolThread.run&#x28;QueuedThreadPool.java&#x3a;582&#x29;&#xd;&#xa;
 *    </message>
 *    <id/>
 *  </webresult>
 *    </pre>
 *
 *    <h3>Status Codes</h3>
 *    <table class="pentaho-table">
 *  <tbody>
 *    <tr>
 *      <th>code</th>
 *      <th>description</th>
 *    </tr>
 *    <tr>
 *      <td>200</td>
 *      <td>Request was processed.</td>
 *    </tr>
 *    <tr>
 *      <td>500</td>
 *      <td>Internal server error occurs during request processing.</td>
 *    </tr>
 *  </tbody>
 *</table>
 *</div>
 */
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    if (isJettyMode() && !request.getContextPath().startsWith(CONTEXT_PATH)) {
        return;
    }
    if (log.isDebug()) {
        logDebug(BaseMessages.getString(PKG, "ExecuteTransServlet.Log.ExecuteTransRequested"));
    }
    // Options taken from PAN
    // 
    String[] knownOptions = new String[] { "rep", "user", "pass", "trans", "level" };
    String repOption = request.getParameter("rep");
    String userOption = request.getParameter("user");
    String passOption = Encr.decryptPasswordOptionallyEncrypted(request.getParameter("pass"));
    String transOption = request.getParameter("trans");
    String levelOption = request.getParameter("level");
    response.setStatus(HttpServletResponse.SC_OK);
    String encoding = System.getProperty("KETTLE_DEFAULT_SERVLET_ENCODING", null);
    if (encoding != null && !Utils.isEmpty(encoding.trim())) {
        response.setCharacterEncoding(encoding);
        response.setContentType("text/html; charset=" + encoding);
    }
    PrintWriter out = response.getWriter();
    try {
        final Repository repository = openRepository(repOption, userOption, passOption);
        final TransMeta transMeta = loadTransformation(repository, transOption);
        // Set the servlet parameters as variables in the transformation
        // 
        String[] parameters = transMeta.listParameters();
        Enumeration<?> parameterNames = request.getParameterNames();
        while (parameterNames.hasMoreElements()) {
            String parameter = (String) parameterNames.nextElement();
            String[] values = request.getParameterValues(parameter);
            // 
            if (Const.indexOfString(parameter, knownOptions) < 0) {
                // 
                if (Const.indexOfString(parameter, parameters) < 0) {
                    transMeta.setVariable(parameter, values[0]);
                } else {
                    transMeta.setParameterValue(parameter, values[0]);
                }
            }
        }
        TransExecutionConfiguration transExecutionConfiguration = new TransExecutionConfiguration();
        LogLevel logLevel = LogLevel.getLogLevelForCode(levelOption);
        transExecutionConfiguration.setLogLevel(logLevel);
        TransConfiguration transConfiguration = new TransConfiguration(transMeta, transExecutionConfiguration);
        String carteObjectId = UUID.randomUUID().toString();
        SimpleLoggingObject servletLoggingObject = new SimpleLoggingObject(CONTEXT_PATH, LoggingObjectType.CARTE, null);
        servletLoggingObject.setContainerObjectId(carteObjectId);
        servletLoggingObject.setLogLevel(logLevel);
        // Create the transformation and store in the list...
        // 
        final Trans trans = new Trans(transMeta, servletLoggingObject);
        trans.setRepository(repository);
        trans.setSocketRepository(getSocketRepository());
        getTransformationMap().addTransformation(transMeta.getName(), carteObjectId, trans, transConfiguration);
        trans.setContainerObjectId(carteObjectId);
        if (repository != null) {
            // The repository connection is open: make sure we disconnect from the repository once we
            // are done with this transformation.
            // 
            trans.addTransListener(new TransAdapter() {

                public void transFinished(Trans trans) {
                    repository.disconnect();
                }
            });
        }
        // Pass the servlet print writer to the transformation...
        // 
        trans.setServletPrintWriter(out);
        trans.setServletReponse(response);
        trans.setServletRequest(request);
        try {
            // Execute the transformation...
            // 
            executeTrans(trans);
            out.flush();
        } catch (Exception executionException) {
            String logging = KettleLogStore.getAppender().getBuffer(trans.getLogChannelId(), false).toString();
            throw new KettleException("Error executing transformation: " + logging, executionException);
        }
    } catch (Exception ex) {
        out.println(new WebResult(WebResult.STRING_ERROR, BaseMessages.getString(PKG, "ExecuteTransServlet.Error.UnexpectedError", Const.CR + Const.getStackTracker(ex))));
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) TransMeta(org.pentaho.di.trans.TransMeta) SimpleLoggingObject(org.pentaho.di.core.logging.SimpleLoggingObject) TransConfiguration(org.pentaho.di.trans.TransConfiguration) LogLevel(org.pentaho.di.core.logging.LogLevel) TransAdapter(org.pentaho.di.trans.TransAdapter) ServletException(javax.servlet.ServletException) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException) TransExecutionConfiguration(org.pentaho.di.trans.TransExecutionConfiguration) Repository(org.pentaho.di.repository.Repository) Trans(org.pentaho.di.trans.Trans) PrintWriter(java.io.PrintWriter)

Example 93 with Repository

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

the class SlaveServerConfig method openRepository.

private void openRepository(String repositoryId) throws KettleException {
    try {
        RepositoriesMeta repositoriesMeta = new RepositoriesMeta();
        repositoriesMeta.readData();
        repositoryMeta = repositoriesMeta.findRepository(repositoryId);
        if (repositoryMeta == null) {
            throw new KettleException("Unable to find repository: " + repositoryId);
        }
        PluginRegistry registry = PluginRegistry.getInstance();
        repository = registry.loadClass(RepositoryPluginType.class, repositoryMeta, Repository.class);
        repository.init(repositoryMeta);
        repository.connect(repositoryUsername, repositoryPassword);
        // 
        if (repository.getMetaStore() != null) {
            metaStore.addMetaStore(0, repository.getMetaStore());
            metaStore.setActiveMetaStoreName(repository.getMetaStore().getName());
        }
        LogChannel.GENERAL.logBasic("Connected to repository '" + repository.getName() + "'");
    } catch (Exception e) {
        throw new KettleException("Unable to open repository connection", e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) Repository(org.pentaho.di.repository.Repository) RepositoryPluginType(org.pentaho.di.core.plugins.RepositoryPluginType) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) RepositoriesMeta(org.pentaho.di.repository.RepositoriesMeta) KettleException(org.pentaho.di.core.exception.KettleException) SocketException(java.net.SocketException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException)

Example 94 with Repository

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

the class JobResource method addJob.

@PUT
@Path("/add")
@Produces({ MediaType.APPLICATION_JSON })
public JobStatus addJob(String xml) {
    // Parse the XML, create a job configuration
    // 
    // System.out.println(xml);
    // 
    JobConfiguration jobConfiguration;
    try {
        jobConfiguration = JobConfiguration.fromXML(xml.toString());
        JobMeta jobMeta = jobConfiguration.getJobMeta();
        JobExecutionConfiguration jobExecutionConfiguration = jobConfiguration.getJobExecutionConfiguration();
        jobMeta.setLogLevel(jobExecutionConfiguration.getLogLevel());
        jobMeta.injectVariables(jobExecutionConfiguration.getVariables());
        // If there was a repository, we know about it at this point in time.
        // 
        final Repository repository = jobConfiguration.getJobExecutionConfiguration().getRepository();
        String carteObjectId = UUID.randomUUID().toString();
        SimpleLoggingObject servletLoggingObject = new SimpleLoggingObject(getClass().getName(), LoggingObjectType.CARTE, null);
        servletLoggingObject.setContainerObjectId(carteObjectId);
        servletLoggingObject.setLogLevel(jobExecutionConfiguration.getLogLevel());
        // Create the transformation and store in the list...
        // 
        final Job job = new Job(repository, jobMeta, servletLoggingObject);
        // Setting variables
        // 
        job.initializeVariablesFrom(null);
        job.getJobMeta().setInternalKettleVariables(job);
        job.injectVariables(jobConfiguration.getJobExecutionConfiguration().getVariables());
        job.setArguments(jobExecutionConfiguration.getArgumentStrings());
        // Also copy the parameters over...
        // 
        job.copyParametersFrom(jobMeta);
        job.clearParameters();
        String[] parameterNames = job.listParameters();
        for (int idx = 0; idx < parameterNames.length; idx++) {
            // Grab the parameter value set in the job entry
            // 
            String thisValue = jobExecutionConfiguration.getParams().get(parameterNames[idx]);
            if (!Utils.isEmpty(thisValue)) {
                // Set the value as specified by the user in the job entry
                // 
                jobMeta.setParameterValue(parameterNames[idx], thisValue);
            }
        }
        jobMeta.activateParameters();
        job.setSocketRepository(CarteSingleton.getInstance().getSocketRepository());
        CarteSingleton.getInstance().getJobMap().addJob(job.getJobname(), carteObjectId, job, jobConfiguration);
        // 
        if (repository != null) {
            job.addJobListener(new JobAdapter() {

                public void jobFinished(Job job) {
                    repository.disconnect();
                }
            });
        }
        return getJobStatus(carteObjectId);
    } catch (KettleException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) JobMeta(org.pentaho.di.job.JobMeta) Repository(org.pentaho.di.repository.Repository) SimpleLoggingObject(org.pentaho.di.core.logging.SimpleLoggingObject) Job(org.pentaho.di.job.Job) JobExecutionConfiguration(org.pentaho.di.job.JobExecutionConfiguration) JobAdapter(org.pentaho.di.job.JobAdapter) JobConfiguration(org.pentaho.di.job.JobConfiguration) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 95 with Repository

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

the class GetRepositoryNames method getRepositoryObjects.

@SuppressWarnings("deprecation")
private List<RepositoryElementMetaInterface> getRepositoryObjects() throws KettleException {
    try {
        // The repository is available in the parent transformation metadata
        // 
        Repository repository = getTransMeta().getRepository();
        // Now populate the list...
        // 
        List<RepositoryElementMetaInterface> list = new ArrayList<RepositoryElementMetaInterface>();
        if (repository instanceof RepositoryExtended) {
            RepositoryExtended extendedRep = (RepositoryExtended) repository;
            for (int i = 0; i < meta.getDirectory().length; i++) {
                String directoryPath = environmentSubstitute(meta.getDirectory()[i]);
                String filter = null;
                // by default we look for current level
                int depth = 0;
                if (meta.getObjectTypeSelection().areTransformationsSelected()) {
                    filter = "*.ktr";
                }
                if (meta.getObjectTypeSelection().areJobsSelected()) {
                    // if we have selected the job and transformation than we have applied filter with both condition
                    filter = Utils.isEmpty(filter) ? "*.kjb" : filter + "|*.kjb";
                }
                // should include unlimited subfolder
                if (meta.getIncludeSubFolders()[i]) {
                    depth = -1;
                }
                RepositoryDirectoryInterface directory = extendedRep.loadRepositoryDirectoryTree(directoryPath, filter, depth, BooleanUtils.isTrue(repository.getUserInfo().isAdmin()), false, false);
                list.addAll(getRepositoryObjects(directory, environmentSubstitute(meta.getNameMask()[i]), environmentSubstitute(meta.getExcludeNameMask()[i])));
            }
        } else {
            // Get the repository directory tree.
            // 
            RepositoryDirectoryInterface tree = repository.loadRepositoryDirectoryTree();
            // 
            for (int i = 0; i < meta.getDirectory().length; i++) {
                RepositoryDirectoryInterface dir = tree.findDirectory(environmentSubstitute(meta.getDirectory()[i]));
                if (dir != null) {
                    List<RepositoryElementMetaInterface> objects = getRepositoryObjects(repository, dir, meta.getIncludeSubFolders()[i], environmentSubstitute(meta.getNameMask()[i]), environmentSubstitute(meta.getExcludeNameMask()[i]));
                    list.addAll(objects);
                }
            }
        }
        return list;
    } catch (Exception e) {
        throw new KettleException("Unable to get the list of repository objects from the repository", e);
    }
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleException(org.pentaho.di.core.exception.KettleException) Repository(org.pentaho.di.repository.Repository) ArrayList(java.util.ArrayList) RepositoryExtended(org.pentaho.di.repository.RepositoryExtended) KettleException(org.pentaho.di.core.exception.KettleException) RepositoryElementMetaInterface(org.pentaho.di.repository.RepositoryElementMetaInterface)

Aggregations

Repository (org.pentaho.di.repository.Repository)143 Test (org.junit.Test)69 KettleException (org.pentaho.di.core.exception.KettleException)54 TransMeta (org.pentaho.di.trans.TransMeta)39 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)21 IMetaStore (org.pentaho.metastore.api.IMetaStore)20 RepositoryMeta (org.pentaho.di.repository.RepositoryMeta)19 JobMeta (org.pentaho.di.job.JobMeta)18 ObjectId (org.pentaho.di.repository.ObjectId)14 StepMeta (org.pentaho.di.trans.step.StepMeta)14 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)14 StringObjectId (org.pentaho.di.repository.StringObjectId)13 Variables (org.pentaho.di.core.variables.Variables)12 ArrayList (java.util.ArrayList)11 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)11 SimpleLoggingObject (org.pentaho.di.core.logging.SimpleLoggingObject)11 VariableSpace (org.pentaho.di.core.variables.VariableSpace)11 RepositoriesMeta (org.pentaho.di.repository.RepositoriesMeta)11 RepositoryPluginType (org.pentaho.di.core.plugins.RepositoryPluginType)10 IOException (java.io.IOException)9