use of org.pentaho.di.repository.Repository in project pentaho-metaverse by pentaho.
the class TransExecutorStepAnalyzerTest method testCustomAnalyze_repoFile.
@Test
public void testCustomAnalyze_repoFile() throws Exception {
when(meta.getDirectoryPath()).thenReturn("/home/admin");
when(meta.getTransName()).thenReturn("my");
Repository repo = mock(Repository.class);
RepositoryDirectoryInterface repoDir = mock(RepositoryDirectoryInterface.class);
when(repo.findDirectory(anyString())).thenReturn(repoDir);
when(repo.loadTransformation(anyString(), eq(repoDir), any(ProgressMonitorListener.class), anyBoolean(), anyString())).thenReturn(childTransMeta);
when(parentTransMeta.getRepository()).thenReturn(repo);
doReturn(childTransMeta).when(spyAnalyzer).getSubTransMeta(anyString());
when(childTransMeta.getPathAndName()).thenReturn("/home/admin/my");
when(childTransMeta.getDefaultExtension()).thenReturn("ktr");
when(meta.getSpecificationMethod()).thenReturn(ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME);
// don't bother running the connectX methods, we'll test those later
doNothing().when(spyAnalyzer).connectToSubTransInputFields(eq(meta), any(TransMeta.class), any(IMetaverseNode.class), any(IComponentDescriptor.class));
doNothing().when(spyAnalyzer).connectToSubTransOutputFields(eq(meta), any(TransMeta.class), any(IMetaverseNode.class), any(IComponentDescriptor.class));
spyAnalyzer.customAnalyze(meta, node);
verify(node).setProperty(eq(TransExecutorStepAnalyzer.TRANSFORMATION_TO_EXECUTE), Mockito.contains("/home/admin/my.ktr"));
// we should have one link created that "executes" the sub transformation
verify(builder, times(1)).addLink(eq(node), eq(DictionaryConst.LINK_EXECUTES), any(IMetaverseNode.class));
}
use of org.pentaho.di.repository.Repository in project pentaho-metaverse by pentaho.
the class TransExecutorStepAnalyzerTest method testCustomAnalyze_repoRef_ErrorFindingRepoObject.
@Test(expected = MetaverseAnalyzerException.class)
public void testCustomAnalyze_repoRef_ErrorFindingRepoObject() throws Exception {
// we should get an exception if the sub transformation isn't found in the repo
when(meta.getTransObjectId()).thenReturn(mock(ObjectId.class));
Repository repo = mock(Repository.class);
when(parentTransMeta.getRepository()).thenReturn(repo);
when(repo.loadTransformation(any(ObjectId.class), anyString())).thenThrow(new KettleException());
when(meta.getSpecificationMethod()).thenReturn(ObjectLocationSpecificationMethod.REPOSITORY_BY_REFERENCE);
spyAnalyzer.customAnalyze(meta, node);
}
use of org.pentaho.di.repository.Repository in project pentaho-metaverse by pentaho.
the class TransExecutorStepAnalyzerTest method testCustomAnalyze_repoRepo_NoRepo.
@Test(expected = MetaverseAnalyzerException.class)
public void testCustomAnalyze_repoRepo_NoRepo() throws Exception {
// we should get an exception if the sub transformation isn't found on the filesystem
when(meta.getTransObjectId()).thenReturn(mock(ObjectId.class));
Repository repo = null;
when(parentTransMeta.getRepository()).thenReturn(repo);
when(meta.getSpecificationMethod()).thenReturn(ObjectLocationSpecificationMethod.REPOSITORY_BY_REFERENCE);
spyAnalyzer.customAnalyze(meta, node);
}
use of org.pentaho.di.repository.Repository in project pentaho-kettle by pentaho.
the class BaseJobServlet method createJob.
protected Job createJob(JobConfiguration jobConfiguration) throws UnknownParamException {
JobExecutionConfiguration jobExecutionConfiguration = jobConfiguration.getJobExecutionConfiguration();
JobMeta jobMeta = jobConfiguration.getJobMeta();
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 = getServletLogging(carteObjectId, 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().setMetaStore(jobMap.getSlaveServerConfig().getMetaStore());
job.getJobMeta().setInternalKettleVariables(job);
job.injectVariables(jobConfiguration.getJobExecutionConfiguration().getVariables());
job.setArguments(jobExecutionConfiguration.getArgumentStrings());
job.setSocketRepository(getSocketRepository());
copyJobParameters(job, jobExecutionConfiguration.getParams());
// Check if there is a starting point specified.
String startCopyName = jobExecutionConfiguration.getStartCopyName();
if (startCopyName != null && !startCopyName.isEmpty()) {
int startCopyNr = jobExecutionConfiguration.getStartCopyNr();
JobEntryCopy startJobEntryCopy = jobMeta.findJobEntry(startCopyName, startCopyNr, false);
job.setStartJobEntryCopy(startJobEntryCopy);
}
// Note: the plugin (Job and Trans) job entries need to call the delegation listeners in the parent job.
if (jobExecutionConfiguration.isExpandingRemoteJob()) {
job.addDelegationListener(new CarteDelegationHandler(getTransformationMap(), getJobMap()));
}
// Make sure to disconnect from the repository when the job finishes.
if (repository != null) {
job.addJobListener(new JobAdapter() {
public void jobFinished(Job job) {
repository.disconnect();
}
});
}
getJobMap().addJob(job.getJobname(), carteObjectId, job, jobConfiguration);
final Long passedBatchId = jobExecutionConfiguration.getPassedBatchId();
if (passedBatchId != null) {
job.setPassedBatchId(passedBatchId);
}
return job;
}
use of org.pentaho.di.repository.Repository in project pentaho-kettle by pentaho.
the class ExecuteJobServlet method doGet.
/**
* <div id="mindtouch">
* <h1>/kettle/executeJob</h1>
* <a name="GET"></a>
* <h2>GET</h2>
* <p>Executes job from the specified repository.
* Connects to the repository provided as a parameter, loads the job from it and executes it.
* Empty response is returned or response contains output of an error happened during the job execution.
* Response contains <code>ERROR</code> result if error happened during job execution.</p>
*
* <p><b>Example Request:</b><br />
* <pre function="syntax.xml">
* GET /kettle/executeJob/?rep=my_repository&user=my_user&pass=my_password&job=my_job&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>job</td>
* <td>Job name to be loaded and executed.</td>
* <td>query</td>
* </tr>
* <tr>
* <td>level</td>
* <td>Logging level to be used for job execution (i.e. Debug).</td>
* <td>query</td>
* </tr>
* <tr>
* <td>*any name*</td>
* <td>All the other parameters will be sent to the job for using as variables.
* When necessary you can add custom parameters to the request.
* They will be used to set the job 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 job executed or Carte object Id
* if the execution was successful.</p>
*
* <p><b>Example Error Response:</b></p>
* <pre function="syntax.xml">
* <webresult>
* <result>OK</result>
* <message>Job started</message>
* <id>74d96aa6-f29a-4bac-a26a-06a8c8f107e5</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, "ExecuteJobServlet.Log.ExecuteJobRequested"));
}
// Options taken from PAN
//
String[] knownOptions = new String[] { "rep", "user", "pass", "job", "level" };
String repOption = request.getParameter("rep");
String userOption = request.getParameter("user");
String passOption = Encr.decryptPasswordOptionallyEncrypted(request.getParameter("pass"));
String jobOption = request.getParameter("job");
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 JobMeta jobMeta = loadJob(repository, jobOption);
// Set the servlet parameters as variables in the job
//
String[] parameters = jobMeta.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) {
jobMeta.setVariable(parameter, values[0]);
} else {
jobMeta.setParameterValue(parameter, values[0]);
}
}
}
JobExecutionConfiguration jobExecutionConfiguration = new JobExecutionConfiguration();
LogLevel logLevel = LogLevel.getLogLevelForCode(levelOption);
jobExecutionConfiguration.setLogLevel(logLevel);
JobConfiguration jobConfiguration = new JobConfiguration(jobMeta, jobExecutionConfiguration);
String carteObjectId = UUID.randomUUID().toString();
SimpleLoggingObject servletLoggingObject = new SimpleLoggingObject(CONTEXT_PATH, LoggingObjectType.CARTE, null);
servletLoggingObject.setContainerObjectId(carteObjectId);
servletLoggingObject.setLogLevel(logLevel);
// Create the job and store in the list...
//
final Job job = new Job(repository, jobMeta, servletLoggingObject);
job.setRepository(repository);
job.setSocketRepository(getSocketRepository());
getJobMap().addJob(jobMeta.getName(), carteObjectId, job, jobConfiguration);
job.setContainerObjectId(carteObjectId);
if (repository != null) {
// The repository connection is open: make sure we disconnect from the repository once we
// are done with this job.
//
job.addJobListener(new JobAdapter() {
public void jobFinished(Job job) {
repository.disconnect();
}
});
}
try {
runJob(job);
WebResult webResult = new WebResult(WebResult.STRING_OK, "Job started", carteObjectId);
out.println(webResult.getXML());
out.flush();
} catch (Exception executionException) {
String logging = KettleLogStore.getAppender().getBuffer(job.getLogChannelId(), false).toString();
throw new KettleException("Error executing job: " + logging, executionException);
}
} catch (Exception ex) {
out.println(new WebResult(WebResult.STRING_ERROR, BaseMessages.getString(PKG, "ExecuteJobServlet.Error.UnexpectedError", Const.CR + Const.getStackTracker(ex))));
}
}
Aggregations