use of org.pentaho.di.shared.SharedObjectInterface in project pentaho-kettle by pentaho.
the class PurRepository_SharedObjects_Links_IT method testReadSharedObjects.
@SuppressWarnings("unchecked")
private void testReadSharedObjects(GenericMeta gMeta) throws Exception {
PurRepository pur = (PurRepository) repository;
RepositoryDirectoryInterface rootDir = initRepo();
SlaveServer slave1 = createSlaveServer("slave1");
SlaveServer slave2 = createSlaveServer("slave2");
pur.save(slave1, VERSION_COMMENT_V1, null);
pur.save(slave2, VERSION_COMMENT_V1, null);
AbstractMeta meta = gMeta.createFilled();
meta.getSlaveServers().add(slave1);
meta.getSlaveServers().add(slave2);
rootDir.findDirectory(DIR_TRANSFORMATIONS);
pur.save(meta, VERSION_COMMENT_V1, null);
String xmlText = meta.getXML();
try {
// import transformation from file
meta = gMeta.createEmpty();
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(IOUtils.toInputStream(xmlText));
gMeta.loadFromXml(doc.getParentNode());
List<SharedObjectInterface> sharedObjects = (List<SharedObjectInterface>) pur.loadAndCacheSharedObjects(false).get(RepositoryObjectType.SLAVE_SERVER);
for (int i = 0; i < meta.getSlaveServers().size(); i++) {
for (int j = 0; j < sharedObjects.size(); j++) {
SlaveServer s1 = meta.getSlaveServers().get(i);
SlaveServer s2 = (SlaveServer) sharedObjects.get(j);
if (s1 == s2) {
fail("Trans/job has direct links on slave servers from cache");
}
}
}
} finally {
pur.deleteSlave(slave1.getObjectId());
pur.deleteSlave(slave2.getObjectId());
pur.clearSharedObjectCache();
}
}
use of org.pentaho.di.shared.SharedObjectInterface 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.shared.SharedObjectInterface in project pentaho-kettle by pentaho.
the class PurRepository method updateSharedObjectCache.
/**
* Do not call this method directly. Instead call updateSharedObjectCache or removeFromSharedObjectCache.
*/
private void updateSharedObjectCache(final RepositoryElementInterface element, final RepositoryObjectType type, final ObjectId id) throws KettleException {
if (element != null && (element.getObjectId() == null || element.getObjectId().getId() == null)) {
throw new IllegalArgumentException(element.getName() + " has a null id");
}
loadAndCacheSharedObjects(false);
boolean remove = element == null;
ObjectId idToFind = element != null ? element.getObjectId() : id;
RepositoryObjectType typeToUpdate = element != null ? element.getRepositoryElementType() : type;
RepositoryElementInterface elementToUpdate = null;
List<? extends SharedObjectInterface> origSharedObjects = null;
switch(typeToUpdate) {
case DATABASE:
origSharedObjects = sharedObjectsByType.get(RepositoryObjectType.DATABASE);
if (!remove) {
elementToUpdate = (RepositoryElementInterface) ((DatabaseMeta) element).clone();
}
break;
case SLAVE_SERVER:
origSharedObjects = sharedObjectsByType.get(RepositoryObjectType.SLAVE_SERVER);
if (!remove) {
elementToUpdate = (RepositoryElementInterface) ((SlaveServer) element).clone();
}
break;
case CLUSTER_SCHEMA:
origSharedObjects = sharedObjectsByType.get(RepositoryObjectType.CLUSTER_SCHEMA);
if (!remove) {
elementToUpdate = ((ClusterSchema) element).clone();
}
break;
case PARTITION_SCHEMA:
origSharedObjects = sharedObjectsByType.get(RepositoryObjectType.PARTITION_SCHEMA);
if (!remove) {
elementToUpdate = (RepositoryElementInterface) ((PartitionSchema) element).clone();
}
break;
default:
throw new KettleException("unknown type [" + typeToUpdate + "]");
}
List<SharedObjectInterface> newSharedObjects = new ArrayList<SharedObjectInterface>(origSharedObjects);
// if there's a match on id, replace the element
boolean found = false;
for (int i = 0; i < origSharedObjects.size(); i++) {
RepositoryElementInterface repositoryElementInterface = (RepositoryElementInterface) origSharedObjects.get(i);
if (repositoryElementInterface == null) {
continue;
}
ObjectId objectId = repositoryElementInterface.getObjectId();
if (objectId != null && objectId.equals(idToFind)) {
if (remove) {
newSharedObjects.remove(i);
} else {
// because some clones don't clone the ID!!!
elementToUpdate.setObjectId(idToFind);
newSharedObjects.set(i, (SharedObjectInterface) elementToUpdate);
}
found = true;
}
}
// otherwise, add it
if (!remove && !found) {
// because some clones don't clone the ID!!!
elementToUpdate.setObjectId(idToFind);
newSharedObjects.add((SharedObjectInterface) elementToUpdate);
}
sharedObjectsByType.put(typeToUpdate, newSharedObjects);
}
Aggregations