use of org.pentaho.di.repository.Repository in project pentaho-kettle by pentaho.
the class RunJobServletTest method doGetUnexpectedErrorTest.
@Test
public void doGetUnexpectedErrorTest() throws Exception {
HttpServletRequest mockHttpServletRequest = mock(HttpServletRequest.class);
HttpServletResponse mockHttpServletResponse = mock(HttpServletResponse.class);
TransformationMap transformationMap = mock(TransformationMap.class);
SlaveServerConfig slaveServerConfig = mock(SlaveServerConfig.class);
Repository repository = mock(Repository.class);
RepositoryDirectoryInterface repDirInterface = mock(RepositoryDirectoryInterface.class);
ObjectId objId = mock(ObjectId.class);
Whitebox.setInternalState(runJobServlet, "transformationMap", transformationMap);
KettleLogStore.init();
StringWriter out = new StringWriter();
PrintWriter printWriter = new PrintWriter(out);
when(mockHttpServletRequest.getParameter("job")).thenReturn("dummyJob");
when(mockHttpServletRequest.getParameter("level")).thenReturn("SomethingInvalid");
when(mockHttpServletResponse.getWriter()).thenReturn(printWriter);
when(transformationMap.getSlaveServerConfig()).thenReturn(slaveServerConfig);
when(slaveServerConfig.getRepository()).thenReturn(repository);
when(repository.isConnected()).thenReturn(true);
when(repository.loadRepositoryDirectoryTree()).thenReturn(repDirInterface);
when(repDirInterface.findDirectory(anyString())).thenReturn(repDirInterface);
when(repository.getJobId("dummyJob", repDirInterface)).thenReturn(objId);
when(repository.loadJob(objId, null)).thenThrow(new KettleException(""));
runJobServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
verify(mockHttpServletResponse).setStatus(HttpServletResponse.SC_OK);
verify(mockHttpServletResponse).setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
use of org.pentaho.di.repository.Repository in project pentaho-kettle by pentaho.
the class TransformationResource method addTransformation.
@PUT
@Path("/add")
@Produces({ MediaType.APPLICATION_JSON })
public TransformationStatus addTransformation(String xml) {
TransConfiguration transConfiguration;
try {
transConfiguration = TransConfiguration.fromXML(xml.toString());
TransMeta transMeta = transConfiguration.getTransMeta();
TransExecutionConfiguration transExecutionConfiguration = transConfiguration.getTransExecutionConfiguration();
transMeta.setLogLevel(transExecutionConfiguration.getLogLevel());
LogChannelInterface log = CarteSingleton.getInstance().getLog();
if (log.isDetailed()) {
log.logDetailed("Logging level set to " + log.getLogLevel().getDescription());
}
transMeta.injectVariables(transExecutionConfiguration.getVariables());
// Also copy the parameters over...
//
Map<String, String> params = transExecutionConfiguration.getParams();
for (Map.Entry<String, String> entry : params.entrySet()) {
transMeta.setParameterValue(entry.getKey(), entry.getValue());
}
// If there was a repository, we know about it at this point in time.
//
TransExecutionConfiguration executionConfiguration = transConfiguration.getTransExecutionConfiguration();
final Repository repository = transConfiguration.getTransExecutionConfiguration().getRepository();
String carteObjectId = UUID.randomUUID().toString();
SimpleLoggingObject servletLoggingObject = new SimpleLoggingObject(getClass().getName(), LoggingObjectType.CARTE, null);
servletLoggingObject.setContainerObjectId(carteObjectId);
servletLoggingObject.setLogLevel(executionConfiguration.getLogLevel());
// Create the transformation and store in the list...
//
final Trans trans = new Trans(transMeta, servletLoggingObject);
trans.setRepository(repository);
trans.setSocketRepository(CarteSingleton.getInstance().getSocketRepository());
CarteSingleton.getInstance().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() {
@Override
public void transFinished(Trans trans) {
repository.disconnect();
}
});
}
return getTransformationStatus(carteObjectId);
} catch (KettleException e) {
e.printStackTrace();
}
return null;
}
use of org.pentaho.di.repository.Repository in project pentaho-kettle by pentaho.
the class MappingParametersTest method prepareMappingParametesActions.
private void prepareMappingParametesActions(boolean override) throws KettleException {
MappingMeta meta = new MappingMeta();
meta.setSpecificationMethod(ObjectLocationSpecificationMethod.REPOSITORY_BY_REFERENCE);
Repository rep = Mockito.mock(Repository.class);
Mockito.when(step.getTransMeta().getRepository()).thenReturn(rep);
Mockito.when(rep.loadTransformation(Mockito.any(ObjectId.class), Mockito.anyString())).thenReturn(transMeta);
MappingParameters mapPar = new MappingParameters();
mapPar.setInheritingAllVariables(override);
meta.setMappingParameters(mapPar);
MappingData data = new MappingData();
step.init(meta, data);
}
use of org.pentaho.di.repository.Repository in project pentaho-kettle by pentaho.
the class TransMetaConverterTest method testIncludesSubTransformationsFromRepository.
@Test
public void testIncludesSubTransformationsFromRepository() throws Exception {
TransMeta parentTransMeta = new TransMeta(getClass().getResource("trans-meta-converter-parent.ktr").getPath());
Repository repository = mock(Repository.class);
TransMeta transMeta = new TransMeta();
RepositoryDirectoryInterface repositoryDirectory = new RepositoryDirectory(null, "public");
String directory = getClass().getResource("").toString().replace(File.separator, "/");
when(repository.findDirectory("public")).thenReturn(repositoryDirectory);
when(repository.loadTransformation("trans-meta-converter-sub.ktr", repositoryDirectory, null, true, null)).thenReturn(transMeta);
parentTransMeta.setRepository(repository);
parentTransMeta.setRepositoryDirectory(repositoryDirectory);
parentTransMeta.setVariable("Internal.Entry.Current.Directory", "public");
Transformation transformation = TransMetaConverter.convert(parentTransMeta);
@SuppressWarnings({ "unchecked", "ConstantConditions" }) HashMap<String, Transformation> config = (HashMap<String, Transformation>) transformation.getConfig(TransMetaConverter.SUB_TRANSFORMATIONS_KEY).get();
assertEquals(1, config.size());
assertNotNull(config.get("public/trans-meta-converter-sub.ktr"));
}
use of org.pentaho.di.repository.Repository in project pentaho-kettle by pentaho.
the class BaseStepMetaCloningTest method testClone.
@Test
public void testClone() throws Exception {
final Database db1 = mock(Database.class);
final Database db2 = mock(Database.class);
final Repository repository = mock(Repository.class);
final StepMeta stepMeta = mock(StepMeta.class);
BaseStepMeta meta = new BaseStepMeta();
meta.setChanged(true);
meta.databases = new Database[] { db1, db2 };
StepIOMetaInterface ioMeta = new StepIOMeta(true, false, false, false, false, false);
meta.setStepIOMeta(ioMeta);
meta.repository = repository;
meta.parentStepMeta = stepMeta;
BaseStepMeta clone = (BaseStepMeta) meta.clone();
assertTrue(clone.hasChanged());
// is it OK ?
assertTrue(clone.databases == meta.databases);
assertArrayEquals(meta.databases, clone.databases);
assertEquals(meta.repository, clone.repository);
assertEquals(meta.parentStepMeta, clone.parentStepMeta);
StepIOMetaInterface cloneIOMeta = clone.getStepIOMeta();
assertNotNull(cloneIOMeta);
assertEquals(ioMeta.isInputAcceptor(), cloneIOMeta.isInputAcceptor());
assertEquals(ioMeta.isInputDynamic(), cloneIOMeta.isInputDynamic());
assertEquals(ioMeta.isInputOptional(), cloneIOMeta.isInputOptional());
assertEquals(ioMeta.isOutputDynamic(), cloneIOMeta.isOutputDynamic());
assertEquals(ioMeta.isOutputProducer(), cloneIOMeta.isOutputProducer());
assertEquals(ioMeta.isSortedDataRequired(), cloneIOMeta.isSortedDataRequired());
assertNotNull(cloneIOMeta.getInfoStreams());
assertEquals(0, cloneIOMeta.getInfoStreams().size());
}
Aggregations