Search in sources :

Example 6 with SharedObjectInterface

use of org.pentaho.di.shared.SharedObjectInterface in project pentaho-kettle by pentaho.

the class KettleFileRepository method save.

public void save(RepositoryElementInterface repositoryElement, String versionComment, ProgressMonitorListener monitor, ObjectId parentId, boolean used) throws KettleException {
    try {
        if (!(repositoryElement instanceof XMLInterface) && !(repositoryElement instanceof SharedObjectInterface)) {
            throw new KettleException("Class [" + repositoryElement.getClass().getName() + "] needs to implement the XML Interface in order to save it to disk");
        }
        if (!Utils.isEmpty(versionComment)) {
            insertLogEntry("Save repository element : " + repositoryElement.toString() + " : " + versionComment);
        }
        ObjectId objectId = new StringObjectId(calcObjectId(repositoryElement));
        FileObject fileObject = getFileObject(repositoryElement);
        String xml = ((XMLInterface) repositoryElement).getXML();
        OutputStream os = KettleVFS.getOutputStream(fileObject, false);
        os.write(xml.getBytes(Const.XML_ENCODING));
        os.close();
        if (repositoryElement instanceof ChangedFlagInterface) {
            ((ChangedFlagInterface) repositoryElement).clearChanged();
        }
        // 
        if (repositoryElement.getObjectId() != null && !repositoryElement.getObjectId().equals(objectId)) {
            delObject(repositoryElement.getObjectId());
        }
        repositoryElement.setObjectId(objectId);
        // 
        if (repositoryElement instanceof TransMeta) {
            ((TransMeta) repositoryElement).saveMetaStoreObjects(this, metaStore);
        }
        if (repositoryElement instanceof JobMeta) {
            ((JobMeta) repositoryElement).saveMetaStoreObjects(this, metaStore);
        }
    } catch (Exception e) {
        throw new KettleException("Unable to save repository element [" + repositoryElement + "] to XML file : " + calcFilename(repositoryElement), e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) JobMeta(org.pentaho.di.job.JobMeta) StringObjectId(org.pentaho.di.repository.StringObjectId) ObjectId(org.pentaho.di.repository.ObjectId) ChangedFlagInterface(org.pentaho.di.core.changed.ChangedFlagInterface) OutputStream(java.io.OutputStream) TransMeta(org.pentaho.di.trans.TransMeta) SharedObjectInterface(org.pentaho.di.shared.SharedObjectInterface) FileObject(org.apache.commons.vfs2.FileObject) XMLInterface(org.pentaho.di.core.xml.XMLInterface) StringObjectId(org.pentaho.di.repository.StringObjectId) KettleFileException(org.pentaho.di.core.exception.KettleFileException) FileSystemException(org.apache.commons.vfs2.FileSystemException) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException)

Example 7 with SharedObjectInterface

use of org.pentaho.di.shared.SharedObjectInterface 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 8 with SharedObjectInterface

use of org.pentaho.di.shared.SharedObjectInterface in project pentaho-kettle by pentaho.

the class PurRepository_SharedObjects_IT method testLoadSharedObjects.

private void testLoadSharedObjects(RepositoryElementInterface sharedObject) throws Exception {
    purRepository.save(sharedObject, null, null);
    Map<RepositoryObjectType, List<? extends SharedObjectInterface>> map = map();
    purRepository.readSharedObjects(map, sharedObject.getRepositoryElementType());
    List<? extends SharedObjectInterface> objects = map.get(sharedObject.getRepositoryElementType());
    assertNotNull(objects);
    assertEquals(1, objects.size());
    SharedObjectInterface object = objects.get(0);
    assertEquals(sharedObject, object);
}
Also used : RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) List(java.util.List) SharedObjectInterface(org.pentaho.di.shared.SharedObjectInterface)

Example 9 with SharedObjectInterface

use of org.pentaho.di.shared.SharedObjectInterface in project pentaho-kettle by pentaho.

the class PurRepositoryIT method testNewNonAmbiguousNaming.

@Test
public void testNewNonAmbiguousNaming() throws Exception {
    PurRepository repo = (PurRepository) repository;
    System.setProperty("KETTLE_COMPATIBILITY_PUR_OLD_NAMING_MODE", "N");
    // $NON-NLS-1$
    PartitionSchema partSchema1 = createPartitionSchema("find.me");
    // $NON-NLS-1$
    PartitionSchema partSchema2 = createPartitionSchema("find|me");
    repository.save(partSchema1, VERSION_COMMENT_V1, null);
    repository.save(partSchema2, VERSION_COMMENT_V1, null);
    Map<RepositoryObjectType, List<? extends SharedObjectInterface>> sharedObjectsByType = new HashMap<RepositoryObjectType, List<? extends SharedObjectInterface>>();
    repo.readSharedObjects(sharedObjectsByType, RepositoryObjectType.PARTITION_SCHEMA);
    List<PartitionSchema> partitionSchemas = (List<PartitionSchema>) sharedObjectsByType.get(RepositoryObjectType.PARTITION_SCHEMA);
    assertEquals(2, partitionSchemas.size());
    System.setProperty("KETTLE_COMPATIBILITY_PUR_OLD_NAMING_MODE", "Y");
    // $NON-NLS-1$
    PartitionSchema partSchema3 = createPartitionSchema("another.one");
    // $NON-NLS-1$
    PartitionSchema partSchema4 = createPartitionSchema("another|one");
    repository.save(partSchema3, VERSION_COMMENT_V1, null);
    repository.save(partSchema4, VERSION_COMMENT_V1, null);
    sharedObjectsByType = new HashMap<RepositoryObjectType, List<? extends SharedObjectInterface>>();
    repo.readSharedObjects(sharedObjectsByType, RepositoryObjectType.PARTITION_SCHEMA);
    partitionSchemas = (List<PartitionSchema>) sharedObjectsByType.get(RepositoryObjectType.PARTITION_SCHEMA);
    assertEquals(3, partitionSchemas.size());
}
Also used : PartitionSchema(org.pentaho.di.partition.PartitionSchema) HashMap(java.util.HashMap) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) ArrayList(java.util.ArrayList) AbstractList(java.util.AbstractList) List(java.util.List) SharedObjectInterface(org.pentaho.di.shared.SharedObjectInterface) Test(org.junit.Test)

Example 10 with SharedObjectInterface

use of org.pentaho.di.shared.SharedObjectInterface in project pentaho-kettle by pentaho.

the class PurRepository method readSharedObjects.

/**
 * Read shared objects of the types provided from the repository. Every {@link SharedObjectInterface} that is read
 * will be fully loaded as if it has been loaded through {@link #loadDatabaseMeta(ObjectId, String)},
 * {@link #loadClusterSchema(ObjectId, List, String)}, etc.
 * <p>
 * This method was introduced to reduce the number of server calls for loading shared objects to a constant number:
 * {@code 2 + n, where n is the number of types requested}.
 * </p>
 *
 * @param sharedObjectsByType
 *          Map of type to shared objects. Each map entry will contain a non-null {@link List} of
 *          {@link RepositoryObjectType}s for every type provided. Only entries for types provided will be altered.
 * @param types
 *          Types of repository objects to read from the repository
 * @throws KettleException
 */
protected void readSharedObjects(Map<RepositoryObjectType, List<? extends SharedObjectInterface>> sharedObjectsByType, RepositoryObjectType... types) throws KettleException {
    // Overview:
    // 1) We will fetch RepositoryFile, NodeRepositoryFileData, and VersionSummary for all types provided.
    // 2) We assume that unless an exception is thrown every RepositoryFile returned by getFilesByType(..) have a
    // matching NodeRepositoryFileData and VersionSummary.
    // 3) With all files, node data, and versions in hand we will iterate over them, merging them back into usable
    // shared objects
    List<RepositoryFile> allFiles = new ArrayList<RepositoryFile>();
    // Since type is not preserved in the RepositoryFile we fetch files by type so we don't rely on parsing the name to
    // determine type afterward
    // Map must be ordered or we can't match up files with data and version summary
    LinkedHashMap<RepositoryObjectType, List<RepositoryFile>> filesByType = getFilesByType(allFiles, types);
    try {
        List<NodeRepositoryFileData> data = pur.getDataForReadInBatch(allFiles, NodeRepositoryFileData.class);
        List<VersionSummary> versions = pur.getVersionSummaryInBatch(allFiles);
        // Only need one iterator for all data and versions. We will work through them as we process the files by type, in
        // order.
        Iterator<NodeRepositoryFileData> dataIter = data.iterator();
        Iterator<VersionSummary> versionsIter = versions.iterator();
        // Assemble into completely loaded SharedObjectInterfaces by type
        for (Entry<RepositoryObjectType, List<RepositoryFile>> entry : filesByType.entrySet()) {
            SharedObjectAssembler<?> assembler = sharedObjectAssemblerMap.get(entry.getKey());
            if (assembler == null) {
                throw new UnsupportedOperationException(// $NON-NLS-1$
                String.format("Cannot assemble shared object of type [%s]", entry.getKey()));
            }
            // For all files of this type, assemble them from the pieces of data pulled from the repository
            Iterator<RepositoryFile> filesIter = entry.getValue().iterator();
            List<SharedObjectInterface> sharedObjects = new ArrayList<SharedObjectInterface>(entry.getValue().size());
            // (no need to check for next on all iterators)
            while (filesIter.hasNext()) {
                RepositoryFile file = filesIter.next();
                NodeRepositoryFileData repoData = dataIter.next();
                VersionSummary version = versionsIter.next();
                // TODO: inexistent db types can cause exceptions assembling; prevent total failure
                try {
                    sharedObjects.add(assembler.assemble(file, repoData, version));
                } catch (Exception ex) {
                    // TODO i18n
                    getLog().logError("Unable to load shared objects", ex);
                }
            }
            sharedObjectsByType.put(entry.getKey(), sharedObjects);
        }
    } catch (Exception ex) {
        // $NON-NLS-1$
        throw new KettleException("Unable to load shared objects", ex);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ArrayList(java.util.ArrayList) MetaStoreNamespaceExistsException(org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) UnifiedRepositoryCreateFileException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryCreateFileException) UnifiedRepositoryUpdateFileException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryUpdateFileException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) KettleException(org.pentaho.di.core.exception.KettleException) IdNotFoundException(org.pentaho.di.core.exception.IdNotFoundException) KettleSecurityException(org.pentaho.di.core.exception.KettleSecurityException) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType) VersionSummary(org.pentaho.platform.api.repository2.unified.VersionSummary) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) List(java.util.List) ArrayList(java.util.ArrayList) 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