Search in sources :

Example 36 with RepositoryDirectory

use of org.pentaho.di.repository.RepositoryDirectory in project pentaho-kettle by pentaho.

the class AbstractMeta method clear.

public void clear() {
    setName(null);
    setFilename(null);
    notes = new ArrayList<NotePadMeta>();
    databases = new ArrayList<DatabaseMeta>();
    slaveServers = new ArrayList<SlaveServer>();
    channelLogTable = ChannelLogTable.getDefault(this, this);
    attributesMap = new HashMap<String, Map<String, String>>();
    max_undo = Const.MAX_UNDO;
    clearUndo();
    clearChanged();
    setChanged(false);
    channelLogTable = ChannelLogTable.getDefault(this, this);
    createdUser = "-";
    createdDate = new Date();
    modifiedUser = "-";
    modifiedDate = new Date();
    directory = new RepositoryDirectory();
    description = null;
    extendedDescription = null;
}
Also used : RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) NotePadMeta(org.pentaho.di.core.NotePadMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) SlaveServer(org.pentaho.di.cluster.SlaveServer) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Map(java.util.Map) HashMap(java.util.HashMap) Date(java.util.Date)

Example 37 with RepositoryDirectory

use of org.pentaho.di.repository.RepositoryDirectory in project pentaho-kettle by pentaho.

the class JobMeta method loadXML.

/**
 * Load a block of XML from an DOM node.
 *
 * @param jobnode                       The node to load from
 * @param fname                         The filename
 * @param rep                           The reference to a repository to load additional information from
 * @param metaStore                     the MetaStore to use
 * @param ignoreRepositorySharedObjects Do not load shared objects, handled separately
 * @param prompter                      The prompter to use in case a shared object gets overwritten
 * @throws KettleXMLException
 */
public void loadXML(Node jobnode, String fname, Repository rep, IMetaStore metaStore, boolean ignoreRepositorySharedObjects, OverwritePrompter prompter) throws KettleXMLException {
    Props props = null;
    if (Props.isInitialized()) {
        props = Props.getInstance();
    }
    try {
        // clear the jobs;
        clear();
        // Set the filename here so it can be used in variables for ALL aspects of the job FIX: PDI-8890
        if (null == rep) {
            setFilename(fname);
        } else {
            // Set the repository here so it can be used in variables for ALL aspects of the job FIX: PDI-16441
            setRepository(rep);
        }
        // 
        // get job info:
        // 
        setName(XMLHandler.getTagValue(jobnode, "name"));
        // 
        if (rep != null) {
            String directoryPath = XMLHandler.getTagValue(jobnode, "directory");
            if (directoryPath != null) {
                directory = rep.findDirectory(directoryPath);
                if (directory == null) {
                    // not found
                    // The root as default
                    directory = new RepositoryDirectory();
                }
            }
        }
        // description
        description = XMLHandler.getTagValue(jobnode, "description");
        // extended description
        extendedDescription = XMLHandler.getTagValue(jobnode, "extended_description");
        // job version
        jobVersion = XMLHandler.getTagValue(jobnode, "job_version");
        // job status
        jobStatus = Const.toInt(XMLHandler.getTagValue(jobnode, "job_status"), -1);
        // Created user/date
        createdUser = XMLHandler.getTagValue(jobnode, "created_user");
        String createDate = XMLHandler.getTagValue(jobnode, "created_date");
        if (createDate != null) {
            createdDate = XMLHandler.stringToDate(createDate);
        }
        // Changed user/date
        modifiedUser = XMLHandler.getTagValue(jobnode, "modified_user");
        String modDate = XMLHandler.getTagValue(jobnode, "modified_date");
        if (modDate != null) {
            modifiedDate = XMLHandler.stringToDate(modDate);
        }
        // Read objects from the shared XML file & the repository
        try {
            sharedObjectsFile = XMLHandler.getTagValue(jobnode, "shared_objects_file");
            if (rep == null || ignoreRepositorySharedObjects) {
                sharedObjects = readSharedObjects();
            } else {
                sharedObjects = rep.readJobMetaSharedObjects(this);
            }
        } catch (Exception e) {
            LogChannel.GENERAL.logError(BaseMessages.getString(PKG, "JobMeta.ErrorReadingSharedObjects.Message", e.toString()));
            LogChannel.GENERAL.logError(Const.getStackTracker(e));
        }
        // Load the database connections, slave servers, cluster schemas & partition schemas into this object.
        // 
        importFromMetaStore();
        // Read the named parameters.
        Node paramsNode = XMLHandler.getSubNode(jobnode, XML_TAG_PARAMETERS);
        int nrParams = XMLHandler.countNodes(paramsNode, "parameter");
        for (int i = 0; i < nrParams; i++) {
            Node paramNode = XMLHandler.getSubNodeByNr(paramsNode, "parameter", i);
            String paramName = XMLHandler.getTagValue(paramNode, "name");
            String defValue = XMLHandler.getTagValue(paramNode, "default_value");
            String descr = XMLHandler.getTagValue(paramNode, "description");
            addParameterDefinition(paramName, defValue, descr);
        }
        // 
        // Read the database connections
        // 
        int nr = XMLHandler.countNodes(jobnode, "connection");
        Set<String> privateDatabases = new HashSet<String>(nr);
        for (int i = 0; i < nr; i++) {
            Node dbnode = XMLHandler.getSubNodeByNr(jobnode, "connection", i);
            DatabaseMeta dbcon = new DatabaseMeta(dbnode);
            dbcon.shareVariablesWith(this);
            if (!dbcon.isShared()) {
                privateDatabases.add(dbcon.getName());
            }
            DatabaseMeta exist = findDatabase(dbcon.getName());
            if (exist == null) {
                addDatabase(dbcon);
            } else {
                if (!exist.isShared()) {
                    // skip shared connections
                    if (shouldOverwrite(prompter, props, BaseMessages.getString(PKG, "JobMeta.Dialog.ConnectionExistsOverWrite.Message", dbcon.getName()), BaseMessages.getString(PKG, "JobMeta.Dialog.ConnectionExistsOverWrite.DontShowAnyMoreMessage"))) {
                        int idx = indexOfDatabase(exist);
                        removeDatabase(idx);
                        addDatabase(idx, dbcon);
                    }
                }
            }
        }
        setPrivateDatabases(privateDatabases);
        // Read the slave servers...
        // 
        Node slaveServersNode = XMLHandler.getSubNode(jobnode, XML_TAG_SLAVESERVERS);
        int nrSlaveServers = XMLHandler.countNodes(slaveServersNode, SlaveServer.XML_TAG);
        for (int i = 0; i < nrSlaveServers; i++) {
            Node slaveServerNode = XMLHandler.getSubNodeByNr(slaveServersNode, SlaveServer.XML_TAG, i);
            SlaveServer slaveServer = new SlaveServer(slaveServerNode);
            slaveServer.shareVariablesWith(this);
            // Check if the object exists and if it's a shared object.
            // If so, then we will keep the shared version, not this one.
            // The stored XML is only for backup purposes.
            SlaveServer check = findSlaveServer(slaveServer.getName());
            if (check != null) {
                if (!check.isShared()) {
                    // we don't overwrite shared objects.
                    if (shouldOverwrite(prompter, props, BaseMessages.getString(PKG, "JobMeta.Dialog.SlaveServerExistsOverWrite.Message", slaveServer.getName()), BaseMessages.getString(PKG, "JobMeta.Dialog.ConnectionExistsOverWrite.DontShowAnyMoreMessage"))) {
                        addOrReplaceSlaveServer(slaveServer);
                    }
                }
            } else {
                slaveServers.add(slaveServer);
            }
        }
        /*
       * Get the log database connection & log table
       */
        // Backward compatibility...
        // 
        Node jobLogNode = XMLHandler.getSubNode(jobnode, JobLogTable.XML_TAG);
        if (jobLogNode == null) {
            // Load the XML
            // 
            jobLogTable.setConnectionName(XMLHandler.getTagValue(jobnode, "logconnection"));
            jobLogTable.setTableName(XMLHandler.getTagValue(jobnode, "logtable"));
            jobLogTable.setBatchIdUsed("Y".equalsIgnoreCase(XMLHandler.getTagValue(jobnode, "use_batchid")));
            jobLogTable.setLogFieldUsed("Y".equalsIgnoreCase(XMLHandler.getTagValue(jobnode, "use_logfield")));
            jobLogTable.findField(JobLogTable.ID.CHANNEL_ID).setEnabled(false);
            jobLogTable.findField(JobLogTable.ID.LINES_REJECTED).setEnabled(false);
        } else {
            jobLogTable.loadXML(jobLogNode, databases, null);
        }
        Node channelLogTableNode = XMLHandler.getSubNode(jobnode, ChannelLogTable.XML_TAG);
        if (channelLogTableNode != null) {
            channelLogTable.loadXML(channelLogTableNode, databases, null);
        }
        jobEntryLogTable.loadXML(jobnode, databases, null);
        for (LogTableInterface extraLogTable : extraLogTables) {
            extraLogTable.loadXML(jobnode, databases, null);
        }
        batchIdPassed = "Y".equalsIgnoreCase(XMLHandler.getTagValue(jobnode, "pass_batchid"));
        /*
       * read the job entries...
       */
        Node entriesnode = XMLHandler.getSubNode(jobnode, "entries");
        int tr = XMLHandler.countNodes(entriesnode, "entry");
        for (int i = 0; i < tr; i++) {
            Node entrynode = XMLHandler.getSubNodeByNr(entriesnode, "entry", i);
            // System.out.println("Reading entry:\n"+entrynode);
            JobEntryCopy je = new JobEntryCopy(entrynode, databases, slaveServers, rep, metaStore);
            if (je.isSpecial() && je.isMissing()) {
                addMissingEntry((MissingEntry) je.getEntry());
            }
            JobEntryCopy prev = findJobEntry(je.getName(), 0, true);
            if (prev != null) {
                // 
                if (je.getNr() == 0) {
                    // Replace previous version with this one: remove it first
                    // 
                    int idx = indexOfJobEntry(prev);
                    removeJobEntry(idx);
                } else if (je.getNr() > 0) {
                    // Use previously defined JobEntry info!
                    // 
                    je.setEntry(prev.getEntry());
                    // See if entry already exists...
                    prev = findJobEntry(je.getName(), je.getNr(), true);
                    if (prev != null) {
                        // remove the old one!
                        // 
                        int idx = indexOfJobEntry(prev);
                        removeJobEntry(idx);
                    }
                }
            }
            // Add the JobEntryCopy...
            addJobEntry(je);
        }
        Node hopsnode = XMLHandler.getSubNode(jobnode, "hops");
        int ho = XMLHandler.countNodes(hopsnode, "hop");
        for (int i = 0; i < ho; i++) {
            Node hopnode = XMLHandler.getSubNodeByNr(hopsnode, "hop", i);
            JobHopMeta hi = new JobHopMeta(hopnode, this);
            jobhops.add(hi);
        }
        // Read the notes...
        Node notepadsnode = XMLHandler.getSubNode(jobnode, "notepads");
        int nrnotes = XMLHandler.countNodes(notepadsnode, "notepad");
        for (int i = 0; i < nrnotes; i++) {
            Node notepadnode = XMLHandler.getSubNodeByNr(notepadsnode, "notepad", i);
            NotePadMeta ni = new NotePadMeta(notepadnode);
            notes.add(ni);
        }
        // Load the attribute groups map
        // 
        attributesMap = AttributesUtil.loadAttributes(XMLHandler.getSubNode(jobnode, AttributesUtil.XML_TAG));
        ExtensionPointHandler.callExtensionPoint(LogChannel.GENERAL, KettleExtensionPoint.JobMetaLoaded.id, this);
        clearChanged();
    } catch (Exception e) {
        throw new KettleXMLException(BaseMessages.getString(PKG, "JobMeta.Exception.UnableToLoadJobFromXMLNode"), e);
    } finally {
        setInternalKettleVariables();
    }
}
Also used : RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) Node(org.w3c.dom.Node) Props(org.pentaho.di.core.Props) SlaveServer(org.pentaho.di.cluster.SlaveServer) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException) LookupReferencesException(org.pentaho.di.core.exception.LookupReferencesException) FileSystemException(org.apache.commons.vfs2.FileSystemException) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) IdNotFoundException(org.pentaho.di.core.exception.IdNotFoundException) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) LogTableInterface(org.pentaho.di.core.logging.LogTableInterface) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) NotePadMeta(org.pentaho.di.core.NotePadMeta) HashSet(java.util.HashSet)

Example 38 with RepositoryDirectory

use of org.pentaho.di.repository.RepositoryDirectory in project pentaho-kettle by pentaho.

the class TransMetaTest method testLoadXml.

@Test
public void testLoadXml() throws KettleException {
    String directory = "/home/admin";
    Node jobNode = Mockito.mock(Node.class);
    NodeList nodeList = new NodeList() {

        ArrayList<Node> nodes = new ArrayList<>();

        {
            Node nodeInfo = Mockito.mock(Node.class);
            Mockito.when(nodeInfo.getNodeName()).thenReturn(TransMeta.XML_TAG_INFO);
            Mockito.when(nodeInfo.getChildNodes()).thenReturn(this);
            Node nodeDirectory = Mockito.mock(Node.class);
            Mockito.when(nodeDirectory.getNodeName()).thenReturn("directory");
            Node child = Mockito.mock(Node.class);
            Mockito.when(nodeDirectory.getFirstChild()).thenReturn(child);
            Mockito.when(child.getNodeValue()).thenReturn(directory);
            nodes.add(nodeDirectory);
            nodes.add(nodeInfo);
        }

        @Override
        public Node item(int index) {
            return nodes.get(index);
        }

        @Override
        public int getLength() {
            return nodes.size();
        }
    };
    Mockito.when(jobNode.getChildNodes()).thenReturn(nodeList);
    Repository rep = Mockito.mock(Repository.class);
    RepositoryDirectory repDirectory = new RepositoryDirectory(new RepositoryDirectory(new RepositoryDirectory(), "home"), "admin");
    Mockito.when(rep.findDirectory(Mockito.eq(directory))).thenReturn(repDirectory);
    TransMeta meta = new TransMeta();
    VariableSpace variableSpace = Mockito.mock(VariableSpace.class);
    Mockito.when(variableSpace.listVariables()).thenReturn(new String[0]);
    meta.loadXML(jobNode, null, Mockito.mock(IMetaStore.class), rep, false, variableSpace, Mockito.mock(OverwritePrompter.class));
    meta.setInternalKettleVariables(null);
    assertEquals(repDirectory.getPath(), meta.getVariable(Const.INTERNAL_VARIABLE_TRANSFORMATION_REPOSITORY_DIRECTORY));
}
Also used : Repository(org.pentaho.di.repository.Repository) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) VariableSpace(org.pentaho.di.core.variables.VariableSpace) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) OverwritePrompter(org.pentaho.di.core.gui.OverwritePrompter) IMetaStore(org.pentaho.metastore.api.IMetaStore) Test(org.junit.Test)

Example 39 with RepositoryDirectory

use of org.pentaho.di.repository.RepositoryDirectory in project pentaho-kettle by pentaho.

the class GetRepositoryNamesTest method prepareFileRepository.

private static void prepareFileRepository() throws IOException, KettleException {
    baseDirName = Files.createTempDirectory("GetRepositoryNamesIT");
    RepositoryMeta repoMeta = new KettleFileRepositoryMeta(UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), baseDirName.toString());
    repo = new KettleFileRepository();
    repo.init(repoMeta);
    repo.connect(null, null);
    // Populate
    RepositoryDirectoryInterface rootDir = repo.findDirectory("/");
    RepositoryDirectoryInterface subdir1 = new RepositoryDirectory(rootDir, "subdir1");
    repo.saveRepositoryDirectory(subdir1);
    TransMeta transMeta1 = new TransMeta();
    transMeta1.setName("Trans1");
    transMeta1.setRepositoryDirectory(subdir1);
    repo.save(transMeta1, null, null);
    JobMeta jobMeta1 = new JobMeta();
    jobMeta1.setName("Job1");
    jobMeta1.setRepositoryDirectory(subdir1);
    repo.save(jobMeta1, null, null);
    RepositoryDirectoryInterface subdir2 = new RepositoryDirectory(subdir1, "subdir2");
    repo.saveRepositoryDirectory(subdir2);
    TransMeta transMeta2 = new TransMeta();
    transMeta2.setName("Trans2");
    transMeta2.setRepositoryDirectory(subdir2);
    repo.save(transMeta2, null, null);
    JobMeta jobMeta2 = new JobMeta();
    jobMeta2.setName("Job2");
    jobMeta2.setRepositoryDirectory(subdir2);
    repo.save(jobMeta2, null, null);
}
Also used : KettleFileRepositoryMeta(org.pentaho.di.repository.filerep.KettleFileRepositoryMeta) RepositoryMeta(org.pentaho.di.repository.RepositoryMeta) RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) JobMeta(org.pentaho.di.job.JobMeta) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) TransMeta(org.pentaho.di.trans.TransMeta) KettleFileRepositoryMeta(org.pentaho.di.repository.filerep.KettleFileRepositoryMeta) KettleFileRepository(org.pentaho.di.repository.filerep.KettleFileRepository)

Example 40 with RepositoryDirectory

use of org.pentaho.di.repository.RepositoryDirectory in project pentaho-kettle by pentaho.

the class GetRepositoryNamesTest method prepareExtendedRepository.

@SuppressWarnings("deprecation")
private static void prepareExtendedRepository() throws KettleException {
    repoExtended = mock(RepositoryExtended.class);
    when(repoExtended.loadRepositoryDirectoryTree(anyString(), anyString(), anyInt(), anyBoolean(), anyBoolean(), anyBoolean())).then(new Answer<RepositoryDirectoryInterface>() {

        @Override
        public RepositoryDirectoryInterface answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            RepositoryDirectoryInterface root = new RepositoryDirectory();
            root.setName("/");
            RepositoryDirectoryInterface subdir1 = new RepositoryDirectory(root, "subdir1");
            RepositoryDirectoryInterface subdir2 = new RepositoryDirectory(subdir1, "subdir2");
            RepositoryElementMetaInterface trans1 = new RepositoryObject(null, "Trans1", subdir1, "user", null, RepositoryObjectType.TRANSFORMATION, "", false);
            RepositoryElementMetaInterface trans2 = new RepositoryObject(null, "Trans2", subdir2, "user", null, RepositoryObjectType.TRANSFORMATION, "", false);
            RepositoryElementMetaInterface job1 = new RepositoryObject(null, "Job1", subdir1, "user", null, RepositoryObjectType.JOB, "", false);
            RepositoryElementMetaInterface job2 = new RepositoryObject(null, "Job2", subdir2, "user", null, RepositoryObjectType.JOB, "", false);
            List<RepositoryElementMetaInterface> list1 = new ArrayList<RepositoryElementMetaInterface>();
            List<RepositoryElementMetaInterface> list2 = new ArrayList<RepositoryElementMetaInterface>();
            if (((String) args[1]).contains("ktr")) {
                list1.add(trans1);
                list2.add(trans2);
            }
            if (((String) args[1]).contains("kjb")) {
                list1.add(job1);
                list2.add(job2);
            }
            subdir1.setRepositoryObjects(list1);
            subdir2.setRepositoryObjects(list2);
            if (((Integer) args[2]) == -1) {
                subdir1.addSubdirectory(subdir2);
                root.addSubdirectory(subdir1);
            }
            String actualPath = ((String) args[0]);
            if (actualPath.equals("/")) {
                return root;
            } else if (actualPath.equals(subdir1.getPath())) {
                return subdir1;
            } else if (actualPath.equals(subdir2.getPath())) {
                return subdir2;
            } else {
                return null;
            }
        }
    });
    IUser user = Mockito.mock(IUser.class);
    Mockito.when(user.isAdmin()).thenReturn(true);
    Mockito.when(repoExtended.getUserInfo()).thenReturn(user);
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) RepositoryObject(org.pentaho.di.repository.RepositoryObject) Mockito.anyString(org.mockito.Mockito.anyString) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IUser(org.pentaho.di.repository.IUser) RepositoryExtended(org.pentaho.di.repository.RepositoryExtended) ArrayList(java.util.ArrayList) List(java.util.List) RepositoryElementMetaInterface(org.pentaho.di.repository.RepositoryElementMetaInterface)

Aggregations

RepositoryDirectory (org.pentaho.di.repository.RepositoryDirectory)57 KettleException (org.pentaho.di.core.exception.KettleException)23 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)15 Test (org.junit.Test)14 TransMeta (org.pentaho.di.trans.TransMeta)11 LongObjectId (org.pentaho.di.repository.LongObjectId)10 ObjectId (org.pentaho.di.repository.ObjectId)9 KettleFileException (org.pentaho.di.core.exception.KettleFileException)8 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)8 Repository (org.pentaho.di.repository.Repository)8 RepositoryElementMetaInterface (org.pentaho.di.repository.RepositoryElementMetaInterface)8 ArrayList (java.util.ArrayList)7 StringObjectId (org.pentaho.di.repository.StringObjectId)7 FileSystemException (org.apache.commons.vfs2.FileSystemException)6 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)6 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)6 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)6 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)5 JobMeta (org.pentaho.di.job.JobMeta)5 TreeItem (org.eclipse.swt.widgets.TreeItem)4