use of org.pentaho.di.repository.RepositoryMeta in project pentaho-kettle by pentaho.
the class KitchenCommandExecutor method execute.
public int execute(String repoName, String noRepo, String username, String trustUser, String password, String dirName, String filename, String jobName, String listJobs, String listDirs, String exportRepo, String initialDir, String listRepos, String listParams, NamedParams params, NamedParams customParams, String[] arguments) throws Throwable {
getLog().logMinimal(BaseMessages.getString(getPkgClazz(), "Kitchen.Log.Starting"));
Date start = Calendar.getInstance().getTime();
logDebug("Kitchen.Log.AllocateNewJob");
Job job = null;
// In case we use a repository...
Repository repository = null;
try {
if (getMetaStore() == null) {
setMetaStore(createDefaultMetastore());
}
// Read kettle job specified on command-line?
if (!Utils.isEmpty(repoName) || !Utils.isEmpty(filename)) {
logDebug("Kitchen.Log.ParsingCommandLine");
if (!Utils.isEmpty(repoName) && !YES.equalsIgnoreCase(noRepo)) {
/**
* if set, _trust_user_ needs to be considered. See pur-plugin's:
*
* @link https://github.com/pentaho/pentaho-kettle/blob/8.0.0.0-R/plugins/pur/core/src/main/java/org/pentaho/di/repository/pur/PurRepositoryConnector.java#L97-L101
* @link https://github.com/pentaho/pentaho-kettle/blob/8.0.0.0-R/plugins/pur/core/src/main/java/org/pentaho/di/repository/pur/WebServiceManager.java#L130-L133
*/
if (YES.equalsIgnoreCase(trustUser)) {
System.setProperty("pentaho.repository.client.attemptTrust", YES);
}
// In case we use a repository...
// some commands are to load a Trans from the repo; others are merely to print some repo-related information
RepositoryMeta repositoryMeta = loadRepositoryConnection(repoName, "Kitchen.Log.LoadingRep", "Kitchen.Error.NoRepDefinied", "Kitchen.Log.FindingRep");
repository = establishRepositoryConnection(repositoryMeta, username, password, RepositoryOperation.EXECUTE_JOB);
job = executeRepositoryBasedCommand(repository, repositoryMeta, dirName, jobName, listJobs, listDirs);
}
// Try to load if from file anyway.
if (!Utils.isEmpty(filename) && job == null) {
// Try to load the job from file, even if it failed to load from the repository
job = executeFilesystemBasedCommand(initialDir, filename);
}
} else if (YES.equalsIgnoreCase(listRepos)) {
// list the repositories placed at repositories.xml
printRepositories(loadRepositoryInfo("Kitchen.Log.ListRep", "Kitchen.Error.NoRepDefinied"));
}
} catch (KettleException e) {
job = null;
if (repository != null) {
repository.disconnect();
}
System.out.println(BaseMessages.getString(getPkgClazz(), "Kitchen.Error.StopProcess", e.getMessage()));
}
if (job == null) {
if (!YES.equalsIgnoreCase(listJobs) && !YES.equalsIgnoreCase(listDirs) && !YES.equalsIgnoreCase(listRepos)) {
System.out.println(BaseMessages.getString(getPkgClazz(), "Kitchen.Error.canNotLoadJob"));
}
return CommandExecutorCodes.Kitchen.COULD_NOT_LOAD_JOB.getCode();
}
if (!Utils.isEmpty(exportRepo)) {
try {
// Export the resources linked to the currently loaded file...
TopLevelResource topLevelResource = ResourceUtil.serializeResourceExportInterface(exportRepo, job.getJobMeta(), job, repository, getMetaStore());
String launchFile = topLevelResource.getResourceName();
String message = ResourceUtil.getExplanation(exportRepo, launchFile, job.getJobMeta());
System.out.println();
System.out.println(message);
// Setting the list parameters option will make kitchen exit below in the parameters section
listParams = YES;
} catch (Exception e) {
System.out.println(Const.getStackTracker(e));
return CommandExecutorCodes.Kitchen.UNEXPECTED_ERROR.getCode();
}
}
Result result = null;
int returnCode = CommandExecutorCodes.Kitchen.SUCCESS.getCode();
try {
// Set the command line arguments on the job ...
job.setArguments(arguments != null ? arguments : null);
job.initializeVariablesFrom(null);
job.setLogLevel(getLog().getLogLevel());
job.getJobMeta().setInternalKettleVariables(job);
job.setRepository(repository);
job.getJobMeta().setRepository(repository);
job.getJobMeta().setMetaStore(getMetaStore());
// Map the command line named parameters to the actual named parameters. Skip for
// the moment any extra command line parameter not known in the job.
String[] jobParams = job.getJobMeta().listParameters();
for (String param : jobParams) {
String value = params.getParameterValue(param);
if (value != null) {
job.getJobMeta().setParameterValue(param, value);
}
}
job.copyParametersFrom(job.getJobMeta());
// Put the parameters over the already defined variable space. Parameters get priority.
job.activateParameters();
// Set custom options in the job extension map as Strings
for (String optionName : customParams.listParameters()) {
String optionValue = customParams.getParameterValue(optionName);
if (optionName != null && optionValue != null) {
job.getExtensionDataMap().put(optionName, optionValue);
}
}
// List the parameters defined in this job, then simply exit...
if (YES.equalsIgnoreCase(listParams)) {
printJobParameters(job);
// same as the other list options
return CommandExecutorCodes.Kitchen.COULD_NOT_LOAD_JOB.getCode();
}
job.start();
job.waitUntilFinished();
// Execute the selected job.
result = job.getResult();
} finally {
if (repository != null) {
repository.disconnect();
}
if (YES.equalsIgnoreCase(trustUser)) {
// we set it, now we sanitize it
System.clearProperty("pentaho.repository.client.attemptTrust");
}
}
getLog().logMinimal(BaseMessages.getString(getPkgClazz(), "Kitchen.Log.Finished"));
if (result != null && result.getNrErrors() != 0) {
getLog().logError(BaseMessages.getString(getPkgClazz(), "Kitchen.Error.FinishedWithErrors"));
returnCode = CommandExecutorCodes.Kitchen.ERRORS_DURING_PROCESSING.getCode();
}
Date stop = Calendar.getInstance().getTime();
calculateAndPrintElapsedTime(start, stop, "Kitchen.Log.StartStop", "Kitchen.Log.ProcessEndAfter", "Kitchen.Log.ProcessEndAfterLong", "Kitchen.Log.ProcessEndAfterLonger", "Kitchen.Log.ProcessEndAfterLongest");
return returnCode;
}
use of org.pentaho.di.repository.RepositoryMeta in project pentaho-kettle by pentaho.
the class RepositoryConnectControllerTest method testEditConnectedRepositoryIncomaptible.
@Test
public void testEditConnectedRepositoryIncomaptible() throws Exception {
RepositoryMeta before = new TestRepositoryMeta(ID, "name1", PLUGIN_DESCRIPTION, "inner1");
RepositoryMeta edited = new TestRepositoryMeta(ID, "name2", PLUGIN_DESCRIPTION, "something completely different");
when(pluginRegistry.loadClass(RepositoryPluginType.class, ID, Repository.class)).thenReturn(repository);
when(pluginRegistry.loadClass(RepositoryPluginType.class, ID, RepositoryMeta.class)).thenReturn(edited);
when(repositoriesMeta.nrRepositories()).thenReturn(1);
when(repositoriesMeta.getRepository(0)).thenReturn(before);
controller.setConnectedRepository(before.clone());
controller.setCurrentRepository(before);
controller.updateRepository(ID, new HashMap<>());
assertNotEquals(edited, controller.getConnectedRepository());
}
use of org.pentaho.di.repository.RepositoryMeta in project pentaho-kettle by pentaho.
the class RepositoryConnectController method isCompatibleRepositoryEdit.
private boolean isCompatibleRepositoryEdit(RepositoryMeta repositoryMeta) {
if (repositoryMeta != null && repositoriesMeta.indexOfRepository(currentRepository) >= 0 && connectedRepository != null && repositoryEquals(connectedRepository, currentRepository)) {
// only name / description / default changed ?
RepositoryMeta clone = repositoryMeta.clone();
clone.setName(connectedRepository.getName());
clone.setDescription(connectedRepository.getDescription());
clone.setDefault(connectedRepository.isDefault());
return repositoryEquals(connectedRepository, clone);
}
return false;
}
use of org.pentaho.di.repository.RepositoryMeta in project pentaho-platform by pentaho.
the class DIServerConfig method getRepositoryMeta.
private RepositoryMeta getRepositoryMeta() throws KettleException, ParserConfigurationException {
if (repositoryMeta == null) {
// Load Repository Meta
RepositoryMeta repositoryMeta = pluginRegistry.loadClass(RepositoryPluginType.class, PUR_REPOSITORY_PLUGIN_ID, RepositoryMeta.class);
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = docBuilder.newDocument();
Element repnode = document.createElement(RepositoryMeta.XML_TAG);
Element id = document.createElement("id");
id.setTextContent(PUR_REPOSITORY_PLUGIN_ID);
repnode.appendChild(id);
Element name = document.createElement("name");
name.setTextContent(SINGLE_DI_SERVER_INSTANCE);
repnode.appendChild(name);
Element description = document.createElement("description");
description.setTextContent(SINGLE_DI_SERVER_INSTANCE);
repnode.appendChild(description);
Element location = document.createElement("repository_location_url");
location.setTextContent(PentahoSystem.getApplicationContext().getFullyQualifiedServerURL());
repnode.appendChild(location);
repositoryMeta.loadXML(repnode, Collections.<DatabaseMeta>emptyList());
this.repositoryMeta = repositoryMeta;
}
return repositoryMeta;
}
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));
}
}
Aggregations