use of org.pentaho.di.partition.PartitionSchema in project pentaho-kettle by pentaho.
the class PartitionsController method editPartition.
public void editPartition() {
String partitionSchemaName = "";
try {
Collection<UIPartition> partitions = partitionsTable.getSelectedItems();
if (partitions != null && !partitions.isEmpty()) {
// Grab the first item in the list & send it to the partition schema dialog
PartitionSchema partitionSchema = ((UIPartition) partitions.toArray()[0]).getPartitionSchema();
partitionSchemaName = partitionSchema.getName();
// Make sure the partition already exists
ObjectId partitionId = repository.getPartitionSchemaID(partitionSchema.getName());
if (partitionId == null) {
MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Partition.DoesNotExists.Message", partitionSchemaName));
mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Partition.Edit.Title"));
mb.open();
} else {
PartitionSchemaDialog partitionDialog = new PartitionSchemaDialog(shell, partitionSchema, repository.readDatabases(), variableSpace);
if (partitionDialog.open()) {
if (partitionSchema.getName() != null && !partitionSchema.getName().equals("")) {
repository.insertLogEntry(BaseMessages.getString(RepositoryExplorer.class, "PartitionsController.Message.UpdatingPartition", partitionSchema.getName()));
repository.save(partitionSchema, Const.VERSION_COMMENT_EDIT_VERSION, null);
if (mainController != null && mainController.getSharedObjectSyncUtil() != null) {
mainController.getSharedObjectSyncUtil().synchronizePartitionSchemas(partitionSchema, partitionSchemaName);
}
} else {
MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Partition.Edit.InvalidName.Message"));
mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Partition.Edit.Title"));
mb.open();
}
}
}
} else {
MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Partition.NoItemSelected.Message"));
mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Partition.Edit.Title"));
mb.open();
}
} catch (KettleException e) {
if (mainController == null || !mainController.handleLostRepository(e)) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryExplorerDialog.Partition.Edit.Title"), BaseMessages.getString(PKG, "RepositoryExplorerDialog.Partition.Edit.UnexpectedError.Message") + partitionSchemaName + "]", e);
}
} finally {
refreshPartitions();
}
}
use of org.pentaho.di.partition.PartitionSchema in project pentaho-kettle by pentaho.
the class PurRepository_SharedObjects_IT method loadAllShared.
@Test
public void loadAllShared() throws Exception {
ClusterSchema cluster = cluster();
DatabaseMeta database = database();
SlaveServer slaveServer = slaveServer();
PartitionSchema partition = partition();
purRepository.save(cluster, null, null);
purRepository.save(database, null, null);
purRepository.save(slaveServer, null, null);
purRepository.save(partition, null, null);
Map<RepositoryObjectType, List<? extends SharedObjectInterface>> map = map();
purRepository.readSharedObjects(map, RepositoryObjectType.CLUSTER_SCHEMA, RepositoryObjectType.DATABASE, RepositoryObjectType.SLAVE_SERVER, RepositoryObjectType.PARTITION_SCHEMA);
RepositoryElementInterface[] saved = new RepositoryElementInterface[] { cluster, database, slaveServer, partition };
assertEquals(saved.length, map.size());
for (RepositoryElementInterface sharedObject : saved) {
List<? extends SharedObjectInterface> list = map.get(sharedObject.getRepositoryElementType());
assertEquals(1, list.size());
assertEquals(sharedObject, list.get(0));
}
}
use of org.pentaho.di.partition.PartitionSchema in project pentaho-kettle by pentaho.
the class StreamToTransNodeConverter method saveSharedObjects.
private void saveSharedObjects(final Repository repo, final RepositoryElementInterface element) throws KettleException {
TransMeta transMeta = (TransMeta) element;
// First store the databases and other depending objects in the transformation.
List<String> databaseNames = Arrays.asList(repo.getDatabaseNames(true));
int dbIndex = 0;
boolean updateMeta = Boolean.FALSE;
List<Integer> transMetaDatabasesToUpdate = new ArrayList<Integer>();
synchronized (repo) {
for (DatabaseMeta databaseMeta : transMeta.getDatabases()) {
if (!databaseNames.contains(databaseMeta.getName())) {
if (databaseMeta.getObjectId() == null || !StringUtils.isEmpty(databaseMeta.getHostname())) {
repo.save(databaseMeta, null, null);
}
} else if (databaseMeta.getObjectId() == null) {
// add this to the list to update object Ids later
transMetaDatabasesToUpdate.add(dbIndex);
updateMeta = Boolean.TRUE;
}
dbIndex++;
}
if (updateMeta) {
// make sure to update object ids in the transmeta db collection
for (Integer databaseMetaIndex : transMetaDatabasesToUpdate) {
transMeta.getDatabase(databaseMetaIndex).setObjectId(repo.getDatabaseID(transMeta.getDatabase(databaseMetaIndex).getName()));
}
}
//
for (SlaveServer slaveServer : transMeta.getSlaveServers()) {
if (slaveServer.hasChanged() || slaveServer.getObjectId() == null) {
repo.save(slaveServer, null, null);
}
}
//
for (ClusterSchema clusterSchema : transMeta.getClusterSchemas()) {
if (clusterSchema.hasChanged() || clusterSchema.getObjectId() == null) {
repo.save(clusterSchema, null, null);
}
}
//
for (PartitionSchema partitionSchema : transMeta.getPartitionSchemas()) {
if (partitionSchema.hasChanged() || partitionSchema.getObjectId() == null) {
repo.save(partitionSchema, null, null);
}
}
}
}
use of org.pentaho.di.partition.PartitionSchema in project pentaho-kettle by pentaho.
the class SpoonPartitionsDelegate method newPartitioningSchema.
public void newPartitioningSchema(TransMeta transMeta) {
PartitionSchema partitionSchema = new PartitionSchema();
PartitionSchemaDialog dialog = new PartitionSchemaDialog(spoon.getShell(), partitionSchema, transMeta.getPartitionSchemas(), transMeta.getDatabases(), transMeta);
if (dialog.open()) {
List<PartitionSchema> partitions = transMeta.getPartitionSchemas();
if (isDuplicate(partitions, partitionSchema)) {
new ErrorDialog(spoon.getShell(), getMessage("Spoon.Dialog.ErrorSavingPartition.Title"), getMessage("Spoon.Dialog.ErrorSavingPartition.Message", partitionSchema.getName()), new KettleException(getMessage("Spoon.Dialog.ErrorSavingPartition.NotUnique")));
return;
}
partitions.add(partitionSchema);
if (spoon.rep != null) {
try {
if (!spoon.rep.getSecurityProvider().isReadOnly()) {
spoon.rep.save(partitionSchema, Const.VERSION_COMMENT_INITIAL_VERSION, null);
if (sharedObjectSyncUtil != null) {
sharedObjectSyncUtil.reloadTransformationRepositoryObjects(false);
}
} else {
throw new KettleException(BaseMessages.getString(PKG, "Spoon.Dialog.Exception.ReadOnlyRepositoryUser"));
}
} catch (KettleException e) {
showSaveErrorDialog(partitionSchema, e);
}
}
refreshTree();
}
}
use of org.pentaho.di.partition.PartitionSchema in project pentaho-kettle by pentaho.
the class PartitionSettings method getDefaultSelectedSchemaIndex.
public int getDefaultSelectedSchemaIndex() {
List<String> schemaNames;
try {
schemaNames = schemasProvider.getPartitionSchemasNames(transMeta);
} catch (KettleException e) {
schemaNames = Collections.emptyList();
}
PartitionSchema partitioningSchema = stepMeta.getStepPartitioningMeta().getPartitionSchema();
int defaultSelectedSchemaIndex = 0;
if (partitioningSchema != null && partitioningSchema.getName() != null && !schemaNames.isEmpty()) {
defaultSelectedSchemaIndex = Const.indexOfString(partitioningSchema.getName(), schemaNames);
}
return defaultSelectedSchemaIndex != -1 ? defaultSelectedSchemaIndex : 0;
}
Aggregations