Search in sources :

Example 16 with SharedObjectInterface

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();
    }
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) AbstractMeta(org.pentaho.di.base.AbstractMeta) SharedObjectInterface(org.pentaho.di.shared.SharedObjectInterface) List(java.util.List) SlaveServer(org.pentaho.di.cluster.SlaveServer) Document(org.w3c.dom.Document)

Example 17 with SharedObjectInterface

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;
}
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 18 with SharedObjectInterface

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);
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) StringObjectId(org.pentaho.di.repository.StringObjectId) ObjectId(org.pentaho.di.repository.ObjectId) PartitionSchema(org.pentaho.di.partition.PartitionSchema) ArrayList(java.util.ArrayList) SlaveServer(org.pentaho.di.cluster.SlaveServer) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) RepositoryElementInterface(org.pentaho.di.repository.RepositoryElementInterface) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) SharedObjectInterface(org.pentaho.di.shared.SharedObjectInterface)

Aggregations

SharedObjectInterface (org.pentaho.di.shared.SharedObjectInterface)18 List (java.util.List)7 RepositoryObjectType (org.pentaho.di.repository.RepositoryObjectType)7 ArrayList (java.util.ArrayList)6 KettleException (org.pentaho.di.core.exception.KettleException)6 Test (org.junit.Test)5 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)5 SlaveServer (org.pentaho.di.cluster.SlaveServer)4 PartitionSchema (org.pentaho.di.partition.PartitionSchema)4 KettleFileException (org.pentaho.di.core.exception.KettleFileException)3 SharedObjects (org.pentaho.di.shared.SharedObjects)3 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)3 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)2 ClusterSchema (org.pentaho.di.cluster.ClusterSchema)2 IdNotFoundException (org.pentaho.di.core.exception.IdNotFoundException)2 KettleSecurityException (org.pentaho.di.core.exception.KettleSecurityException)2 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)2 ObjectId (org.pentaho.di.repository.ObjectId)2 RepositoryElementInterface (org.pentaho.di.repository.RepositoryElementInterface)2 StringObjectId (org.pentaho.di.repository.StringObjectId)2