Search in sources :

Example 26 with PartitionSchema

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();
    }
}
Also used : RepositoryExplorer(org.pentaho.di.ui.repository.repositoryexplorer.RepositoryExplorer) KettleException(org.pentaho.di.core.exception.KettleException) PartitionSchema(org.pentaho.di.partition.PartitionSchema) ObjectId(org.pentaho.di.repository.ObjectId) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) UIPartition(org.pentaho.di.ui.repository.repositoryexplorer.model.UIPartition) PartitionSchemaDialog(org.pentaho.di.ui.partition.dialog.PartitionSchemaDialog) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 27 with PartitionSchema

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));
    }
}
Also used : RepositoryElementInterface(org.pentaho.di.repository.RepositoryElementInterface) PartitionSchema(org.pentaho.di.partition.PartitionSchema) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) List(java.util.List) SharedObjectInterface(org.pentaho.di.shared.SharedObjectInterface) SlaveServer(org.pentaho.di.cluster.SlaveServer) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) ClusterSchema(org.pentaho.di.cluster.ClusterSchema) Test(org.junit.Test)

Example 28 with PartitionSchema

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);
            }
        }
    }
}
Also used : PartitionSchema(org.pentaho.di.partition.PartitionSchema) TransMeta(org.pentaho.di.trans.TransMeta) ArrayList(java.util.ArrayList) SlaveServer(org.pentaho.di.cluster.SlaveServer) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) ClusterSchema(org.pentaho.di.cluster.ClusterSchema)

Example 29 with PartitionSchema

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();
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) PartitionSchema(org.pentaho.di.partition.PartitionSchema) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) PartitionSchemaDialog(org.pentaho.di.ui.partition.dialog.PartitionSchemaDialog)

Example 30 with PartitionSchema

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;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) PartitionSchema(org.pentaho.di.partition.PartitionSchema)

Aggregations

PartitionSchema (org.pentaho.di.partition.PartitionSchema)74 KettleException (org.pentaho.di.core.exception.KettleException)26 TransMeta (org.pentaho.di.trans.TransMeta)19 StepMeta (org.pentaho.di.trans.step.StepMeta)19 ClusterSchema (org.pentaho.di.cluster.ClusterSchema)18 SlaveServer (org.pentaho.di.cluster.SlaveServer)18 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)17 StepPartitioningMeta (org.pentaho.di.trans.step.StepPartitioningMeta)17 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)15 ObjectId (org.pentaho.di.repository.ObjectId)14 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)10 List (java.util.List)8 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)8 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)6 StringObjectId (org.pentaho.di.repository.StringObjectId)6 PartitionSchemaDialog (org.pentaho.di.ui.partition.dialog.PartitionSchemaDialog)6 MessageBox (org.eclipse.swt.widgets.MessageBox)5 Point (org.pentaho.di.core.gui.Point)5 IOException (java.io.IOException)4