use of org.pentaho.di.repository.RepositoryMeta in project pentaho-platform by pentaho.
the class RepositorySyncWebService method sync.
public RepositorySyncStatus sync(String repositoryId, String repositoryUrl) throws RepositorySyncException {
boolean singleDiServerInstance = // $NON-NLS-1$ //$NON-NLS-2$
"true".equals(PentahoSystem.getSystemSetting(SINGLE_DI_SERVER_INSTANCE, "true"));
if (singleDiServerInstance) {
return RepositorySyncStatus.SINGLE_DI_SERVER_INSTANCE;
}
RepositoriesMeta repositoriesMeta = new RepositoriesMeta();
try {
repositoriesMeta.readData();
} catch (Exception e) {
// $NON-NLS-1$
log.error(Messages.getInstance().getString("RepositorySyncWebService.UNABLE_TO_READ_DATA"), e);
throw new RepositorySyncException(Messages.getInstance().getString("RepositorySyncWebService.UNABLE_TO_READ_DATA"), // $NON-NLS-1$
e);
}
RepositoryMeta repositoryMeta = repositoriesMeta.findRepository(repositoryId);
if (repositoryMeta == null) {
try {
repositoryMeta = getRepositoryMeta(repositoryId, repositoryUrl);
if (repositoryMeta == null) {
// $NON-NLS-1$
log.error(Messages.getInstance().getString("RepositorySyncWebService.UNABLE_TO_LOAD_PLUGIN"));
throw new RepositorySyncException(Messages.getInstance().getString(// $NON-NLS-1$
"RepositorySyncWebService.UNABLE_TO_LOAD_PLUGIN"));
}
repositoriesMeta.addRepository(repositoryMeta);
repositoriesMeta.writeData();
return RepositorySyncStatus.REGISTERED;
} catch (KettleException e) {
log.error(Messages.getInstance().getString("RepositorySyncWebService.UNABLE_TO_REGISTER_REPOSITORY", repositoryId), // $NON-NLS-1$
e);
throw new RepositorySyncException(Messages.getInstance().getString("RepositorySyncWebService.UNABLE_TO_REGISTER_REPOSITORY", repositoryId), // $NON-NLS-1$
e);
}
} else {
String xml = repositoryMeta.getXML();
Element node;
try {
node = XMLParserFactoryProducer.createSecureDocBuilderFactory().newDocumentBuilder().parse(new StringBufferInputStream(xml)).getDocumentElement();
} catch (Exception e) {
node = null;
}
if (node != null) {
// $NON-NLS-1$
NodeList list = node.getElementsByTagName("repository_location_url");
if (list != null && list.getLength() == 1) {
String url = list.item(0).getTextContent();
if (url.equals(repositoryUrl)) {
// now test base URL
String fullyQualifiedServerUrl = null;
if (PentahoSystem.getApplicationContext().getFullyQualifiedServerURL() != null) {
fullyQualifiedServerUrl = PentahoSystem.getApplicationContext().getFullyQualifiedServerURL();
if (url.endsWith("/")) {
// $NON-NLS-1$
url = url.substring(0, url.length() - 2);
}
if (fullyQualifiedServerUrl.endsWith("/")) {
// $NON-NLS-1$
fullyQualifiedServerUrl = fullyQualifiedServerUrl.substring(0, fullyQualifiedServerUrl.length() - 2);
}
if (url.startsWith(fullyQualifiedServerUrl)) {
return RepositorySyncStatus.ALREADY_REGISTERED;
}
}
log.error(Messages.getInstance().getString("RepositorySyncWebService.FULLY_QUALIFIED_SERVER_URL_SYNC_PROBLEM", fullyQualifiedServerUrl, // $NON-NLS-1$
url));
throw new RepositorySyncException(Messages.getInstance().getString("RepositorySyncWebService.FULLY_QUALIFIED_SERVER_URL_SYNC_PROBLEM", fullyQualifiedServerUrl, // $NON-NLS-1$
url));
} else {
log.error(Messages.getInstance().getString("RepositorySyncWebService.REPOSITORY_URL_SYNC_PROBLEM", repositoryId, url, // $NON-NLS-1$
repositoryUrl));
throw new RepositorySyncException(Messages.getInstance().getString("RepositorySyncWebService.REPOSITORY_URL_SYNC_PROBLEM", repositoryId, url, // $NON-NLS-1$
repositoryUrl));
}
}
}
log.error(Messages.getInstance().getString("RepositorySyncWebService.REPOSITORY_URL_XML_PARSING_PROBLEM", repositoryId, // $NON-NLS-1$
xml));
throw new RepositorySyncException(Messages.getInstance().getString("RepositorySyncWebService.REPOSITORY_URL_XML_PARSING_PROBLEM_CLIENT_MESSAGE", // $NON-NLS-1$
repositoryId));
}
}
use of org.pentaho.di.repository.RepositoryMeta in project pdi-platform-plugin by pentaho.
the class EngineMetaLoader method dumpRepositoryNames.
private void dumpRepositoryNames() {
try {
RepositoriesMeta repositoriesMeta = new RepositoriesMeta();
// Read from the default $HOME/.kettle/repositories.xml file.
repositoriesMeta.readData();
for (int i = 0; i < repositoriesMeta.nrRepositories(); i++) {
RepositoryMeta repoMeta = repositoriesMeta.getRepository(i);
// $NON-NLS-1$//$NON-NLS-2$
log.debug("Found repo: " + repoMeta.getName() + " type: " + repoMeta.getClass().getName());
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.pentaho.di.repository.RepositoryMeta 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.RepositoryMeta in project pentaho-kettle by pentaho.
the class ExecuteTransServlet method openRepository.
private Repository openRepository(String repositoryName, String user, String pass) throws KettleException {
if (Utils.isEmpty(repositoryName)) {
return null;
}
RepositoriesMeta repositoriesMeta = new RepositoriesMeta();
repositoriesMeta.readData();
RepositoryMeta repositoryMeta = repositoriesMeta.findRepository(repositoryName);
if (repositoryMeta == null) {
throw new KettleException("Unable to find repository: " + repositoryName);
}
PluginRegistry registry = PluginRegistry.getInstance();
Repository repository = registry.loadClass(RepositoryPluginType.class, repositoryMeta, Repository.class);
repository.init(repositoryMeta);
repository.connect(user, pass);
return repository;
}
use of org.pentaho.di.repository.RepositoryMeta in project pentaho-kettle by pentaho.
the class Kitchen method main.
public static void main(String[] a) throws Exception {
final ExecutorService executor = ExecutorUtil.getExecutor();
final RepositoryPluginType repositoryPluginType = RepositoryPluginType.getInstance();
final Future<Map.Entry<KettlePluginException, Future<KettleException>>> repositoryRegisterFuture = executor.submit(new Callable<Map.Entry<KettlePluginException, Future<KettleException>>>() {
@Override
public Map.Entry<KettlePluginException, Future<KettleException>> call() throws Exception {
PluginRegistry.addPluginType(repositoryPluginType);
try {
KettleClientEnvironment.getInstance().setClient(KettleClientEnvironment.ClientType.KITCHEN);
KettleClientEnvironment.init();
} catch (KettlePluginException e) {
return new AbstractMap.SimpleImmutableEntry<KettlePluginException, Future<KettleException>>(e, null);
}
Future<KettleException> kettleEnvironmentInitFuture = executor.submit(new Callable<KettleException>() {
@Override
public KettleException call() throws Exception {
try {
KettleClientEnvironment.getInstance().setClient(KettleClientEnvironment.ClientType.KITCHEN);
KettleEnvironment.init();
} catch (KettleException e) {
return e;
}
return null;
}
});
return new AbstractMap.SimpleImmutableEntry<KettlePluginException, Future<KettleException>>(null, kettleEnvironmentInitFuture);
}
});
List<String> args = new ArrayList<String>();
for (int i = 0; i < a.length; i++) {
if (a[i].length() > 0) {
args.add(a[i]);
}
}
DelegatingMetaStore metaStore = new DelegatingMetaStore();
metaStore.addMetaStore(MetaStoreConst.openLocalPentahoMetaStore());
metaStore.setActiveMetaStoreName(metaStore.getName());
RepositoryMeta repositoryMeta = null;
Job job = null;
StringBuilder optionRepname, optionUsername, optionTrustUser, optionPassword, optionJobname, optionDirname, initialDir;
StringBuilder optionFilename, optionLoglevel, optionLogfile, optionLogfileOld, optionListdir;
StringBuilder optionListjobs, optionListrep, optionNorep, optionVersion, optionListParam, optionExport;
NamedParams optionParams = new NamedParamsDefault();
NamedParams customOptions = new NamedParamsDefault();
CommandLineOption maxLogLinesOption = new CommandLineOption("maxloglines", BaseMessages.getString(PKG, "Kitchen.CmdLine.MaxLogLines"), new StringBuilder());
CommandLineOption maxLogTimeoutOption = new CommandLineOption("maxlogtimeout", BaseMessages.getString(PKG, "Kitchen.CmdLine.MaxLogTimeout"), new StringBuilder());
CommandLineOption[] options = new CommandLineOption[] { new CommandLineOption("rep", BaseMessages.getString(PKG, "Kitchen.CmdLine.RepName"), optionRepname = new StringBuilder()), new CommandLineOption("user", BaseMessages.getString(PKG, "Kitchen.CmdLine.RepUsername"), optionUsername = new StringBuilder()), new CommandLineOption("trustuser", BaseMessages.getString(PKG, "Kitchen.ComdLine.RepUsername"), optionTrustUser = new StringBuilder()), new CommandLineOption("pass", BaseMessages.getString(PKG, "Kitchen.CmdLine.RepPassword"), optionPassword = new StringBuilder()), new CommandLineOption("job", BaseMessages.getString(PKG, "Kitchen.CmdLine.RepJobName"), optionJobname = new StringBuilder()), new CommandLineOption("dir", BaseMessages.getString(PKG, "Kitchen.CmdLine.RepDir"), optionDirname = new StringBuilder()), new CommandLineOption("file", BaseMessages.getString(PKG, "Kitchen.CmdLine.XMLJob"), optionFilename = new StringBuilder()), new CommandLineOption("level", BaseMessages.getString(PKG, "Kitchen.CmdLine.LogLevel"), optionLoglevel = new StringBuilder()), new CommandLineOption("logfile", BaseMessages.getString(PKG, "Kitchen.CmdLine.LogFile"), optionLogfile = new StringBuilder()), new CommandLineOption("log", BaseMessages.getString(PKG, "Kitchen.CmdLine.LogFileOld"), optionLogfileOld = new StringBuilder(), false, true), new CommandLineOption("listdir", BaseMessages.getString(PKG, "Kitchen.CmdLine.ListDir"), optionListdir = new StringBuilder(), true, false), new CommandLineOption("listjobs", BaseMessages.getString(PKG, "Kitchen.CmdLine.ListJobsDir"), optionListjobs = new StringBuilder(), true, false), new CommandLineOption("listrep", BaseMessages.getString(PKG, "Kitchen.CmdLine.ListAvailableReps"), optionListrep = new StringBuilder(), true, false), new CommandLineOption("norep", BaseMessages.getString(PKG, "Kitchen.CmdLine.NoRep"), optionNorep = new StringBuilder(), true, false), new CommandLineOption("version", BaseMessages.getString(PKG, "Kitchen.CmdLine.Version"), optionVersion = new StringBuilder(), true, false), new CommandLineOption("param", BaseMessages.getString(PKG, "Kitchen.ComdLine.Param"), optionParams, false), new CommandLineOption("listparam", BaseMessages.getString(PKG, "Kitchen.ComdLine.ListParam"), optionListParam = new StringBuilder(), true, false), new CommandLineOption("export", BaseMessages.getString(PKG, "Kitchen.ComdLine.Export"), optionExport = new StringBuilder(), true, false), new CommandLineOption("initialDir", null, initialDir = new StringBuilder(), false, true), new CommandLineOption("custom", BaseMessages.getString(PKG, "Kitchen.ComdLine.Custom"), customOptions, false), maxLogLinesOption, maxLogTimeoutOption };
if (args.size() == 2) {
// 2 internal hidden argument (flag and value)
CommandLineOption.printUsage(options);
exitJVM(9);
}
LogChannelInterface log = new LogChannel(STRING_KITCHEN);
CommandLineOption.parseArguments(args, options, log);
configureLogging(maxLogLinesOption, maxLogTimeoutOption);
String kettleRepname = Const.getEnvironmentVariable("KETTLE_REPOSITORY", null);
String kettleUsername = Const.getEnvironmentVariable("KETTLE_USER", null);
String kettlePassword = Const.getEnvironmentVariable("KETTLE_PASSWORD", null);
if (!Utils.isEmpty(kettleRepname)) {
optionRepname = new StringBuilder(kettleRepname);
}
if (!Utils.isEmpty(kettleUsername)) {
optionUsername = new StringBuilder(kettleUsername);
}
if (!Utils.isEmpty(kettlePassword)) {
optionPassword = new StringBuilder(kettlePassword);
}
if (Utils.isEmpty(optionLogfile) && !Utils.isEmpty(optionLogfileOld)) {
// if the old style of logging name is filled in, and the new one is not
// overwrite the new by the old
optionLogfile = optionLogfileOld;
}
Map.Entry<KettlePluginException, Future<KettleException>> repositoryRegisterResults = repositoryRegisterFuture.get();
// It's a singleton map with one key-value pair (a Pair collection)
KettlePluginException repositoryRegisterException = repositoryRegisterResults.getKey();
if (repositoryRegisterException != null) {
throw repositoryRegisterException;
}
Future<KettleException> kettleInitFuture = repositoryRegisterResults.getValue();
if (!Utils.isEmpty(optionLogfile)) {
fileAppender = new FileLoggingEventListener(optionLogfile.toString(), true);
KettleLogStore.getAppender().addLoggingEventListener(fileAppender);
} else {
fileAppender = null;
}
if (!Utils.isEmpty(optionLoglevel)) {
log.setLogLevel(LogLevel.getLogLevelForCode(optionLoglevel.toString()));
log.logMinimal(BaseMessages.getString(PKG, "Kitchen.Log.LogLevel", log.getLogLevel().getDescription()));
}
// Start the action...
//
int returnCode = CommandExecutorCodes.Kitchen.SUCCESS.getCode();
try {
if (getCommandExecutor() == null) {
// init
setCommandExecutor(new KitchenCommandExecutor(PKG, log, kettleInitFuture));
}
if (!Utils.isEmpty(optionVersion)) {
getCommandExecutor().printVersion();
if (a.length == 1) {
exitJVM(CommandExecutorCodes.Pan.KETTLE_VERSION_PRINT.getCode());
}
}
returnCode = getCommandExecutor().execute(optionRepname.toString(), optionNorep.toString(), optionUsername.toString(), optionTrustUser.toString(), optionPassword.toString(), optionDirname.toString(), optionFilename.toString(), optionJobname.toString(), optionListjobs.toString(), optionListdir.toString(), optionExport.toString(), initialDir.toString(), optionListrep.toString(), optionListParam.toString(), optionParams, customOptions, args.toArray(new String[args.size()]));
} catch (Throwable t) {
t.printStackTrace();
returnCode = CommandExecutorCodes.Pan.UNEXPECTED_ERROR.getCode();
} finally {
if (fileAppender != null) {
fileAppender.close();
KettleLogStore.getAppender().removeLoggingEventListener(fileAppender);
}
}
exitJVM(returnCode);
}
Aggregations