Search in sources :

Example 46 with ClusterSchema

use of org.pentaho.di.cluster.ClusterSchema in project pentaho-kettle by pentaho.

the class PurRepository method deepCopy.

private Map<RepositoryObjectType, List<? extends SharedObjectInterface>> deepCopy(Map<RepositoryObjectType, List<? extends SharedObjectInterface>> orig) throws KettleException {
    Map<RepositoryObjectType, List<? extends SharedObjectInterface>> copy = new EnumMap<RepositoryObjectType, List<? extends SharedObjectInterface>>(RepositoryObjectType.class);
    for (Entry<RepositoryObjectType, List<? extends SharedObjectInterface>> entry : orig.entrySet()) {
        RepositoryObjectType type = entry.getKey();
        List<? extends SharedObjectInterface> value = entry.getValue();
        List<SharedObjectInterface> newValue = new ArrayList<SharedObjectInterface>(value.size());
        for (SharedObjectInterface obj : value) {
            SharedObjectInterface newValueItem;
            if (obj instanceof DatabaseMeta) {
                DatabaseMeta databaseMeta = (DatabaseMeta) ((DatabaseMeta) obj).clone();
                databaseMeta.setObjectId(((DatabaseMeta) obj).getObjectId());
                databaseMeta.clearChanged();
                newValueItem = databaseMeta;
            } else if (obj instanceof SlaveServer) {
                SlaveServer slaveServer = (SlaveServer) ((SlaveServer) obj).clone();
                slaveServer.setObjectId(((SlaveServer) obj).getObjectId());
                slaveServer.clearChanged();
                newValueItem = slaveServer;
            } else if (obj instanceof PartitionSchema) {
                PartitionSchema partitionSchema = (PartitionSchema) ((PartitionSchema) obj).clone();
                partitionSchema.setObjectId(((PartitionSchema) obj).getObjectId());
                partitionSchema.clearChanged();
                newValueItem = partitionSchema;
            } else if (obj instanceof ClusterSchema) {
                ClusterSchema clusterSchema = ((ClusterSchema) obj).clone();
                clusterSchema.setObjectId(((ClusterSchema) obj).getObjectId());
                clusterSchema.clearChanged();
                newValueItem = clusterSchema;
            } else {
                throw new KettleException("unknown shared object class");
            }
            newValue.add(newValueItem);
        }
        copy.put(type, newValue);
    }
    return copy;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) PartitionSchema(org.pentaho.di.partition.PartitionSchema) ArrayList(java.util.ArrayList) SlaveServer(org.pentaho.di.cluster.SlaveServer) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) List(java.util.List) ArrayList(java.util.ArrayList) SharedObjectInterface(org.pentaho.di.shared.SharedObjectInterface) EnumMap(java.util.EnumMap) ClusterSchema(org.pentaho.di.cluster.ClusterSchema)

Example 47 with ClusterSchema

use of org.pentaho.di.cluster.ClusterSchema in project pentaho-kettle by pentaho.

the class TransDelegate method readClusters.

/**
 * Add clusters in the repository to this transformation if they are not yet present.
 *
 * @param TransMeta
 *          The transformation to load into.
 * @param overWriteShared
 *          if an object with the same name exists, overwrite
 */
protected void readClusters(TransMeta transMeta, boolean overWriteShared, List<ClusterSchema> clusterSchemas) {
    for (ClusterSchema clusterSchema : clusterSchemas) {
        if (overWriteShared || transMeta.findClusterSchema(clusterSchema.getName()) == null) {
            if (!Utils.isEmpty(clusterSchema.getName())) {
                clusterSchema.shareVariablesWith(transMeta);
                transMeta.addOrReplaceClusterSchema(clusterSchema);
                if (!overWriteShared) {
                    clusterSchema.setChanged(false);
                }
            }
        }
    }
}
Also used : ClusterSchema(org.pentaho.di.cluster.ClusterSchema)

Example 48 with ClusterSchema

use of org.pentaho.di.cluster.ClusterSchema in project pentaho-kettle by pentaho.

the class StepMetaTest method createTestMeta.

private static StepMeta createTestMeta() throws Exception {
    StepMetaInterface stepMetaInterface = mock(AbstractStepMeta.class);
    when(stepMetaInterface.clone()).thenReturn(stepMetaInterface);
    StepMeta meta = new StepMeta(STEP_ID, "stepname", stepMetaInterface);
    meta.setSelected(true);
    meta.setDistributes(false);
    meta.setCopiesString("2");
    meta.setLocation(1, 2);
    meta.setDraw(true);
    meta.setDescription("description");
    meta.setTerminator(true);
    meta.setClusterSchemaName("clusterSchemaName");
    boolean shouldDistribute = rand.nextBoolean();
    meta.setDistributes(shouldDistribute);
    if (shouldDistribute) {
        meta.setRowDistribution(selectRowDistribution());
    }
    Map<String, Map<String, String>> attributes = new HashMap<String, Map<String, String>>();
    Map<String, String> map1 = new HashMap<String, String>();
    map1.put("1", "1");
    Map<String, String> map2 = new HashMap<String, String>();
    map2.put("2", "2");
    attributes.put("qwerty", map1);
    attributes.put("asdfg", map2);
    meta.setAttributesMap(attributes);
    meta.setStepPartitioningMeta(createStepPartitioningMeta("stepMethod", "stepSchema"));
    meta.setTargetStepPartitioningMeta(createStepPartitioningMeta("targetMethod", "targetSchema"));
    meta.setClusterSchema(new ClusterSchema("cluster_schema", Collections.<SlaveServer>emptyList()));
    return meta;
}
Also used : HashMap(java.util.HashMap) SlaveServer(org.pentaho.di.cluster.SlaveServer) AbstractStepMeta(org.pentaho.di.core.util.AbstractStepMeta) HashMap(java.util.HashMap) Map(java.util.Map) ClusterSchema(org.pentaho.di.cluster.ClusterSchema)

Example 49 with ClusterSchema

use of org.pentaho.di.cluster.ClusterSchema in project pentaho-kettle by pentaho.

the class ClustersController method removeCluster.

public void removeCluster() {
    String clusterSchemaName = "";
    try {
        Collection<UICluster> clusters = clustersTable.getSelectedItems();
        if (clusters != null && !clusters.isEmpty()) {
            for (Object obj : clusters) {
                if (obj != null && obj instanceof UICluster) {
                    UICluster cluster = (UICluster) obj;
                    ClusterSchema clusterSchema = cluster.getClusterSchema();
                    clusterSchemaName = clusterSchema.getName();
                    // Make sure the cluster to delete exists in the repository
                    ObjectId clusterId = repository.getClusterID(clusterSchema.getName());
                    if (clusterId == null) {
                        MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
                        mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Cluster.DoesNotExists.Message", clusterSchema.getName()));
                        mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Cluster.Delete.Title"));
                        mb.open();
                    } else {
                        repository.deleteClusterSchema(clusterId);
                        if (mainController != null && mainController.getSharedObjectSyncUtil() != null) {
                            mainController.getSharedObjectSyncUtil().deleteClusterSchema(clusterSchema);
                        }
                    }
                }
            }
        } else {
            MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
            mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Cluster.NoItemSelected.Message"));
            mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Cluster.Delete.Title"));
            mb.open();
        }
    } catch (KettleException e) {
        if (mainController == null || !mainController.handleLostRepository(e)) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryExplorerDialog.Cluster.Delete.Title"), BaseMessages.getString(PKG, "RepositoryExplorerDialog.Cluster.Delete.UnexpectedError.Message") + clusterSchemaName + "]", e);
        }
    } finally {
        refreshClusters();
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) UICluster(org.pentaho.di.ui.repository.repositoryexplorer.model.UICluster) ObjectId(org.pentaho.di.repository.ObjectId) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) ClusterSchema(org.pentaho.di.cluster.ClusterSchema) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 50 with ClusterSchema

use of org.pentaho.di.cluster.ClusterSchema in project pentaho-kettle by pentaho.

the class ClustersController method editCluster.

public void editCluster() {
    String clusterSchemaName = "";
    try {
        Collection<UICluster> clusters = clustersTable.getSelectedItems();
        if (clusters != null && !clusters.isEmpty()) {
            // Grab the first item in the list & send it to the cluster schema dialog
            ClusterSchema clusterSchema = ((UICluster) clusters.toArray()[0]).getClusterSchema();
            clusterSchemaName = clusterSchema.getName();
            // Make sure the cluster already exists
            ObjectId clusterId = repository.getClusterID(clusterSchema.getName());
            if (clusterId == null) {
                MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
                mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Cluster.DoesNotExists.Message", clusterSchemaName));
                mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Cluster.Edit.Title"));
                mb.open();
            } else {
                ClusterSchemaDialog csd = new ClusterSchemaDialog(shell, clusterSchema, repository.getSlaveServers());
                if (csd.open()) {
                    if (clusterSchema.getName() != null && !clusterSchema.getName().equals("")) {
                        repository.insertLogEntry(BaseMessages.getString(PKG, "ClusterController.Message.UpdatingCluster", clusterSchema.getName()));
                        repository.save(clusterSchema, Const.VERSION_COMMENT_EDIT_VERSION, null);
                        if (mainController != null && mainController.getSharedObjectSyncUtil() != null) {
                            mainController.getSharedObjectSyncUtil().synchronizeClusterSchemas(clusterSchema, clusterSchemaName);
                        }
                    } else {
                        MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
                        mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Cluster.Edit.InvalidName.Message"));
                        mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Cluster.Edit.Title"));
                        mb.open();
                    }
                }
            }
        } else {
            MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
            mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Cluster.NoItemSelected.Message"));
            mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Cluster.Edit.Title"));
            mb.open();
        }
        refreshClusters();
    } catch (KettleException e) {
        if (mainController == null || !mainController.handleLostRepository(e)) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryExplorerDialog.Cluster.Edit.Title"), BaseMessages.getString(PKG, "RepositoryExplorerDialog.Cluster.Edit.UnexpectedError.Message") + clusterSchemaName + "]", e);
        }
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) UICluster(org.pentaho.di.ui.repository.repositoryexplorer.model.UICluster) ObjectId(org.pentaho.di.repository.ObjectId) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) ClusterSchema(org.pentaho.di.cluster.ClusterSchema) MessageBox(org.eclipse.swt.widgets.MessageBox) ClusterSchemaDialog(org.pentaho.di.ui.cluster.dialog.ClusterSchemaDialog)

Aggregations

ClusterSchema (org.pentaho.di.cluster.ClusterSchema)52 SlaveServer (org.pentaho.di.cluster.SlaveServer)23 KettleException (org.pentaho.di.core.exception.KettleException)19 PartitionSchema (org.pentaho.di.partition.PartitionSchema)19 TransMeta (org.pentaho.di.trans.TransMeta)16 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)15 StepMeta (org.pentaho.di.trans.step.StepMeta)15 ObjectId (org.pentaho.di.repository.ObjectId)11 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)7 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)7 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)7 NotePadMeta (org.pentaho.di.core.NotePadMeta)6 TransHopMeta (org.pentaho.di.trans.TransHopMeta)6 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)5 Point (org.pentaho.di.core.gui.Point)5 ClusterSchemaDialog (org.pentaho.di.ui.cluster.dialog.ClusterSchemaDialog)5 List (java.util.List)4 MessageBox (org.eclipse.swt.widgets.MessageBox)4 JobMeta (org.pentaho.di.job.JobMeta)4