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;
}
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:
* 
org.pentaho.di.core.exception.KettleException:
* 
Unable to find transformation 'dummy-trans.ktr' in directory
* :/home/admin

 at
* org.pentaho.di.www.ExecuteTransServlet.loadTransformation(ExecuteTransServlet.java:214)

* at org.pentaho.di.www.ExecuteTransServlet.doGet(ExecuteTransServlet.java:104)

* at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)

* at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)

* at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)

* at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390)

* at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)

* at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)

* at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)

* at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)

* at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)

* at org.mortbay.jetty.Server.handle(Server.java:326)

* at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:536)

* at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:915)

* at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:539)

* at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)

* at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:405)

* at org.mortbay.jetty.bio.SocketConnector$Connection.run(SocketConnector.java:228)

* at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

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