Search in sources :

Example 76 with Repository

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

the class DIRepositoryLocatorTest method testGetRootUri.

@Test
public void testGetRootUri() throws Exception {
    Repository mockRepo = mock(Repository.class);
    when(spyLocator.getRepository()).thenReturn(mockRepo);
    when(mockRepo.getRepositoryMeta()).thenReturn(mock(RepositoryMeta.class));
    // This one won't get far due to no getRepositoryLocation() method
    spyLocator.getRootUri();
    GetRepositoryLocationMethodProvider getRepositoryLocationMethodProvider = new GetRepositoryLocationMethodProvider(null);
    when(mockRepo.getRepositoryMeta()).thenReturn(getRepositoryLocationMethodProvider);
    // This one won't get too far due to no RepositoryLocation being determined
    spyLocator.getRootUri();
    getRepositoryLocationMethodProvider = new GetRepositoryLocationMethodProvider(new Object());
    when(mockRepo.getRepositoryMeta()).thenReturn(getRepositoryLocationMethodProvider);
    // This one won't go all the way through due to no getUrl() method defined
    spyLocator.getRootUri();
    getRepositoryLocationMethodProvider = new GetRepositoryLocationMethodProvider(new RepositoryLocationTestClass());
    when(mockRepo.getRepositoryMeta()).thenReturn(getRepositoryLocationMethodProvider);
    spyLocator.getRootUri();
}
Also used : KettleFileRepositoryMeta(org.pentaho.di.repository.filerep.KettleFileRepositoryMeta) RepositoryMeta(org.pentaho.di.repository.RepositoryMeta) KettleFileRepository(org.pentaho.di.repository.filerep.KettleFileRepository) Repository(org.pentaho.di.repository.Repository) Test(org.junit.Test)

Example 77 with Repository

use of org.pentaho.di.repository.Repository in project pdi-platform-plugin by pentaho.

the class PdiAction method connectToRepository.

/**
 * Connects to the PDI repository
 *
 * @param logWriter
 * @return
 * @throws KettleException
 * @throws KettleSecurityException
 * @throws ActionExecutionException
 */
protected Repository connectToRepository(final LogWriter logWriter) throws KettleSecurityException, KettleException, ActionExecutionException {
    if (log.isDebugEnabled()) {
        // $NON-NLS-1$
        log.debug(Messages.getInstance().getString("Kettle.DEBUG_META_REPOSITORY"));
    }
    RepositoriesMeta repositoriesMeta = new RepositoriesMeta();
    if (log.isDebugEnabled()) {
        // $NON-NLS-1$
        log.debug(Messages.getInstance().getString("Kettle.DEBUG_POPULATING_META"));
    }
    boolean singleDiServerInstance = // $NON-NLS-1$ //$NON-NLS-2$
    "true".equals(PentahoSystem.getSystemSetting(SINGLE_DI_SERVER_INSTANCE, "true"));
    try {
        if (singleDiServerInstance) {
            if (log.isDebugEnabled()) {
                // $NON-NLS-1$
                log.debug("singleDiServerInstance=true, loading default repository");
            }
            // only load a default enterprise repository. If this option is set, then you cannot load
            // transformations or jobs from anywhere but the local server.
            String repositoriesXml = // $NON-NLS-1$
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?><repositories>" + // $NON-NLS-1$
            "<repository><id>PentahoEnterpriseRepository</id>" + "<name>" + SINGLE_DI_SERVER_INSTANCE + // $NON-NLS-1$ //$NON-NLS-2$
            "</name>" + "<description>" + SINGLE_DI_SERVER_INSTANCE + // $NON-NLS-1$ //$NON-NLS-2$
            "</description>" + "<repository_location_url>" + PentahoSystem.getApplicationContext().getFullyQualifiedServerURL() + // $NON-NLS-1$ //$NON-NLS-2$
            "</repository_location_url>" + // $NON-NLS-1$
            "<version_comment_mandatory>N</version_comment_mandatory>" + // $NON-NLS-1$
            "</repository>" + // $NON-NLS-1$
            "</repositories>";
            ByteArrayInputStream sbis = new ByteArrayInputStream(repositoriesXml.getBytes("UTF8"));
            repositoriesMeta.readDataFromInputStream(sbis);
        } else {
            // TODO: add support for specified repositories.xml files...
            // Read from the default $HOME/.kettle/repositories.xml file.
            repositoriesMeta.readData();
        }
    } catch (Exception e) {
        throw new ActionExecutionException(Messages.getInstance().getErrorString("Kettle.ERROR_0018_META_REPOSITORY_NOT_POPULATED"), // $NON-NLS-1$
        e);
    }
    if (log.isDebugEnabled()) {
        // $NON-NLS-1$
        log.debug(Messages.getInstance().getString("Kettle.DEBUG_FINDING_REPOSITORY"));
    }
    // Find the specified repository.
    RepositoryMeta repositoryMeta = null;
    try {
        if (singleDiServerInstance) {
            repositoryMeta = repositoriesMeta.findRepository(SINGLE_DI_SERVER_INSTANCE);
        } else {
            repositoryMeta = repositoriesMeta.findRepository(repositoryName);
        }
    } catch (Exception e) {
        throw new ActionExecutionException(Messages.getInstance().getErrorString("Kettle.ERROR_0004_REPOSITORY_NOT_FOUND", repositoryName), // $NON-NLS-1$
        e);
    }
    if (repositoryMeta == null) {
        if (log.isDebugEnabled()) {
            log.debug(pdiUserAppender.getBuffer().toString());
        }
        throw new ActionExecutionException(Messages.getInstance().getErrorString("Kettle.ERROR_0004_REPOSITORY_NOT_FOUND", // $NON-NLS-1$
        repositoryName));
    }
    if (log.isDebugEnabled()) {
        // $NON-NLS-1$
        log.debug(Messages.getInstance().getString("Kettle.DEBUG_GETTING_REPOSITORY"));
    }
    Repository repository = null;
    try {
        repository = PluginRegistry.getInstance().loadClass(RepositoryPluginType.class, repositoryMeta.getId(), Repository.class);
        repository.init(repositoryMeta);
    } catch (Exception e) {
        throw new ActionExecutionException(Messages.getInstance().getErrorString("Kettle.ERROR_0016_COULD_NOT_GET_REPOSITORY_INSTANCE"), // $NON-NLS-1$
        e);
    }
    // OK, now try the username and password
    if (log.isDebugEnabled()) {
        // $NON-NLS-1$
        log.debug(Messages.getInstance().getString("Kettle.DEBUG_CONNECTING"));
    }
    // Two scenarios here: internal to server or external to server. If internal, you are already authenticated. If
    // external, you must provide a username and additionally specify that the IP address of the machine running this
    // code is trusted.
    repository.connect(PentahoSessionHolder.getSession().getName(), "password");
    // OK, the repository is open and ready to use.
    if (log.isDebugEnabled()) {
        // $NON-NLS-1$
        log.debug(Messages.getInstance().getString("Kettle.DEBUG_FINDING_DIRECTORY"));
    }
    return repository;
}
Also used : RepositoryMeta(org.pentaho.di.repository.RepositoryMeta) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Repository(org.pentaho.di.repository.Repository) ByteArrayInputStream(java.io.ByteArrayInputStream) RepositoryPluginType(org.pentaho.di.core.plugins.RepositoryPluginType) RepositoriesMeta(org.pentaho.di.repository.RepositoriesMeta) ActionExecutionException(org.pentaho.platform.api.engine.ActionExecutionException) ActionExecutionException(org.pentaho.platform.api.engine.ActionExecutionException) ActionValidationException(org.pentaho.platform.api.engine.ActionValidationException) UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException) FileNotFoundException(java.io.FileNotFoundException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) KettleException(org.pentaho.di.core.exception.KettleException) KettleSecurityException(org.pentaho.di.core.exception.KettleSecurityException)

Example 78 with Repository

use of org.pentaho.di.repository.Repository in project pdi-platform-plugin by pentaho.

the class PdiAction method execute.

/**
 * Execute the specified transformation in the chosen repository.
 */
public void execute() throws Exception {
    // Reset the flag
    transPrepExecutionFailure = false;
    IAuthorizationPolicy authorizationPolicy = PentahoSystem.get(IAuthorizationPolicy.class, PentahoSessionHolder.getSession());
    if (!authorizationPolicy.isAllowed(RepositoryExecuteAction.NAME)) {
        throw new IllegalStateException(org.pentaho.platform.plugin.kettle.messages.Messages.getInstance().getErrorString(// $NON-NLS-1$
        "PdiAction.ERROR_0010_NO_PERMISSION_TO_EXECUTE"));
    }
    if (log.isDebugEnabled()) {
        // $NON-NLS-1$
        log.debug(Messages.getInstance().getString("Kettle.DEBUG_START"));
    }
    validate();
    TransMeta transMeta = null;
    JobMeta jobMeta = null;
    // $NON-NLS-1$
    LogWriter logWriter = LogWriter.getInstance("Kettle-pentaho", false);
    // initialize environment variables
    KettleSystemListener.environmentInit(PentahoSessionHolder.getSession());
    pdiUserAppender = KettleLogStore.getAppender();
    Repository repository = connectToRepository(logWriter);
    LoggingBufferAppender loggingBufferAppender = new LoggingBufferAppender(pdiUserAppender);
    logWriter.addAppender(loggingBufferAppender);
    try {
        if (transformation != null) {
            // to populate available databases, etc in "standard" kettle fashion
            try {
                transMeta = createTransMetaJCR(repository);
            } catch (Throwable t) {
            // ignored
            }
            if (transMeta == null) {
                transMeta = createTransMeta(repository, logWriter);
            }
            if (transMeta == null) {
                throw new IllegalStateException(org.pentaho.platform.plugin.kettle.messages.Messages.getInstance().getErrorString(// $NON-NLS-1$
                "PdiAction.ERROR_0004_FAILED_TRANSMETA_CREATION"));
            }
            executeTransformation(transMeta, logWriter);
        } else if (job != null) {
            // to populate available databases, etc in "standard" kettle fashion
            try {
                jobMeta = createJobMetaJCR(repository);
            } catch (Throwable t) {
            // ignored
            }
            if (jobMeta == null) {
                jobMeta = createJobMeta(repository, logWriter);
            }
            if (jobMeta == null) {
                throw new IllegalStateException(org.pentaho.platform.plugin.kettle.messages.Messages.getInstance().getErrorString(// $NON-NLS-1$
                "PdiAction.ERROR_0005_FAILED_JOBMETA_CREATION"));
            }
            executeJob(jobMeta, repository, logWriter);
        }
    } finally {
        logWriter.removeAppender(loggingBufferAppender);
        if (repository != null) {
            if (log.isDebugEnabled()) {
                // $NON-NLS-1$
                log.debug(Messages.getInstance().getString("Kettle.DEBUG_DISCONNECTING"));
            }
            repository.disconnect();
        }
    }
    XMLHandlerCache.getInstance().clear();
}
Also used : IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) JobMeta(org.pentaho.di.job.JobMeta) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Repository(org.pentaho.di.repository.Repository) LogWriter(org.pentaho.di.core.logging.LogWriter) TransMeta(org.pentaho.di.trans.TransMeta)

Example 79 with Repository

use of org.pentaho.di.repository.Repository in project pdi-dataservice-server-plugin by pentaho.

the class DeleteRepositoryObjectExtensionPointPlugin method callExtensionPoint.

@Override
public void callExtensionPoint(LogChannelInterface log, Object object) throws KettleException {
    RepositoryExtension repositoryExtension = (RepositoryExtension) object;
    UIRepositoryObject repositoryObject = repositoryExtension.getRepositoryObject();
    // if a directory get all transformations recursively
    if (repositoryObject instanceof UIRepositoryDirectory) {
        List<UIRepositoryObject> transformationList = new ArrayList<UIRepositoryObject>();
        getAllTransformations((UIRepositoryDirectory) repositoryObject, transformationList);
        for (UIRepositoryObject uiRepositoryObject : transformationList) {
            Repository repository = uiRepositoryObject.getRepository();
            metaStoreUtil.clearReferences(repository.loadTransformation(uiRepositoryObject.getObjectId(), null));
        }
    } else if (repositoryObject.getRepositoryElementType().equals(RepositoryObjectType.TRANSFORMATION)) {
        Repository repository = repositoryObject.getRepository();
        metaStoreUtil.clearReferences(repository.loadTransformation(repositoryObject.getObjectId(), null));
    }
}
Also used : UIRepositoryObject(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject) UIRepositoryDirectory(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryDirectory) Repository(org.pentaho.di.repository.Repository) RepositoryExtension(org.pentaho.di.ui.repository.RepositoryExtension) ArrayList(java.util.ArrayList)

Example 80 with Repository

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

the class DIRepositoryLocator method getContents.

@Override
protected Object getContents(RepositoryFile file) throws Exception {
    Object object = null;
    ObjectId objectId;
    Repository repo = getRepository();
    if (repo instanceof KettleFileRepository) {
        objectId = new StringObjectId(file.getPath());
    } else {
        objectId = new StringObjectId(file.getId().toString());
    }
    String extension = FilenameUtils.getExtension(file.getName());
    if ("ktr".equals(extension)) {
        object = repo.loadTransformation(objectId, null);
    } else if ("kjb".equals(extension)) {
        object = repo.loadJob(objectId, null);
    }
    return object;
}
Also used : Repository(org.pentaho.di.repository.Repository) KettleFileRepository(org.pentaho.di.repository.filerep.KettleFileRepository) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) ObjectId(org.pentaho.di.repository.ObjectId) StringObjectId(org.pentaho.di.repository.StringObjectId) StringObjectId(org.pentaho.di.repository.StringObjectId) KettleFileRepository(org.pentaho.di.repository.filerep.KettleFileRepository)

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