Search in sources :

Example 41 with Repository

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) KettleException(org.pentaho.di.core.exception.KettleException) Repository(org.pentaho.di.repository.Repository) StringWriter(java.io.StringWriter) ObjectId(org.pentaho.di.repository.ObjectId) HttpServletResponse(javax.servlet.http.HttpServletResponse) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 42 with Repository

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;
}
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) TransAdapter(org.pentaho.di.trans.TransAdapter) TransExecutionConfiguration(org.pentaho.di.trans.TransExecutionConfiguration) Repository(org.pentaho.di.repository.Repository) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Map(java.util.Map) Trans(org.pentaho.di.trans.Trans) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 43 with Repository

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);
}
Also used : Repository(org.pentaho.di.repository.Repository) ObjectId(org.pentaho.di.repository.ObjectId) StepWithMappingMeta(org.pentaho.di.trans.StepWithMappingMeta)

Example 44 with Repository

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"));
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) Repository(org.pentaho.di.repository.Repository) Transformation(org.pentaho.di.engine.api.model.Transformation) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) HashMap(java.util.HashMap) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 45 with Repository

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());
}
Also used : Repository(org.pentaho.di.repository.Repository) Database(org.pentaho.di.core.database.Database) Test(org.junit.Test)

Aggregations

Repository (org.pentaho.di.repository.Repository)194 Test (org.junit.Test)110 KettleException (org.pentaho.di.core.exception.KettleException)66 TransMeta (org.pentaho.di.trans.TransMeta)48 ObjectId (org.pentaho.di.repository.ObjectId)36 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)31 IMetaStore (org.pentaho.metastore.api.IMetaStore)29 JobMeta (org.pentaho.di.job.JobMeta)27 StringObjectId (org.pentaho.di.repository.StringObjectId)26 RepositoryMeta (org.pentaho.di.repository.RepositoryMeta)24 ArrayList (java.util.ArrayList)20 StepMeta (org.pentaho.di.trans.step.StepMeta)20 VariableSpace (org.pentaho.di.core.variables.VariableSpace)18 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)18 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)17 PrintWriter (java.io.PrintWriter)15 Variables (org.pentaho.di.core.variables.Variables)15 IOException (java.io.IOException)14 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)14 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)13