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