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;
}
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);
}
}
}
}
}
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;
}
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();
}
}
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);
}
}
}
Aggregations