Search in sources :

Example 46 with VDBMetaData

use of org.teiid.adminapi.impl.VDBMetaData in project teiid by teiid.

the class VDBRepository method getLiveVDB.

/**
 * A live vdb may be loading or active
 * @param vdbName
 * @return
 */
public VDBMetaData getLiveVDB(String vdbName) {
    VDBMetaData result = null;
    VDBKey key = new VDBKey(vdbName, null);
    if (!key.isAtMost()) {
        CompositeVDB v = this.vdbRepo.get(key);
        if (v != null) {
            return v.getVDB();
        }
        return null;
    }
    for (Map.Entry<VDBKey, CompositeVDB> entry : this.vdbRepo.tailMap(key).entrySet()) {
        if (!key.acceptsVerion(entry.getKey())) {
            break;
        }
        VDBMetaData vdb = entry.getValue().getVDB();
        switch(vdb.getConnectionType()) {
            case ANY:
                result = vdb;
                break;
            case BY_VERSION:
            case NONE:
                if (result == null || result.getConnectionType() == ConnectionType.NONE) {
                    result = vdb;
                }
                break;
        }
    }
    return result;
}
Also used : VDBKey(org.teiid.vdb.runtime.VDBKey) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) NavigableMap(java.util.NavigableMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap)

Example 47 with VDBMetaData

use of org.teiid.adminapi.impl.VDBMetaData in project teiid by teiid.

the class VDBStatusChecker method dataSourceRemoved.

/**
 * @param dataSourceName
 * @param vdbKey which cannot be null
 */
public void dataSourceRemoved(String dataSourceName, VDBKey vdbKey) {
    dataSourceName = stripContext(dataSourceName);
    CompositeVDB cvdb = getVDBRepository().getCompositeVDB(vdbKey);
    if (cvdb == null) {
        return;
    }
    VDBMetaData vdb = cvdb.getVDB();
    if (vdb.getStatus() == Status.FAILED) {
        return;
    }
    synchronized (vdb) {
        ConnectorManagerRepository cmr = vdb.getAttachment(ConnectorManagerRepository.class);
        for (ModelMetaData model : vdb.getModelMetaDatas().values()) {
            String sourceName = getSourceName(dataSourceName, model);
            if (sourceName == null) {
                continue;
            }
            Severity severity = Severity.WARNING;
            ConnectorManager cm = cmr.getConnectorManager(sourceName);
            if (cm.getExecutionFactory().isSourceRequired() && vdb.getStatus() == Status.ACTIVE) {
                severity = Severity.ERROR;
            }
            String msg = RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40012, vdb.getName(), vdb.getVersion(), dataSourceName);
            model.addRuntimeMessage(severity, msg);
            LogManager.logInfo(LogConstants.CTX_RUNTIME, msg);
        }
    }
}
Also used : ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) Severity(org.teiid.adminapi.impl.ModelMetaData.Message.Severity) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 48 with VDBMetaData

use of org.teiid.adminapi.impl.VDBMetaData in project teiid by teiid.

the class MaterializationManager method beforeRemove.

@Override
public void beforeRemove(String name, CompositeVDB cvdb) {
    if (cvdb == null) {
        return;
    }
    final VDBMetaData vdb = cvdb.getVDB();
    // cancel any matview load pending tasks
    Collection<Future<?>> tasks = cvdb.clearTasks();
    if (tasks != null && !tasks.isEmpty()) {
        for (Future<?> f : tasks) {
            f.cancel(true);
        }
    }
    // If VDB is being undeployed, run the shutdown triggers
    if (!shutdownListener.isShutdownInProgress()) {
        doMaterializationActions(vdb, new MaterializationAction() {

            @Override
            public void process(Table table) {
                if (table.getMaterializedTable() == null) {
                    return;
                }
                String remove = table.getProperty(MaterializationMetadataRepository.ON_VDB_DROP_SCRIPT, false);
                if (remove != null) {
                    try {
                        executeQuery(vdb, remove);
                    } catch (SQLException e) {
                        LogManager.logWarning(LogConstants.CTX_MATVIEWS, e, e.getMessage());
                    }
                }
            }
        });
    }
}
Also used : Table(org.teiid.metadata.Table) SQLException(java.sql.SQLException) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) ScheduledFuture(java.util.concurrent.ScheduledFuture) Future(java.util.concurrent.Future) ResultsFuture(org.teiid.client.util.ResultsFuture)

Example 49 with VDBMetaData

use of org.teiid.adminapi.impl.VDBMetaData in project teiid by teiid.

the class MaterializationManager method finishedDeployment.

@Override
public void finishedDeployment(String name, final CompositeVDB cvdb) {
    // execute start triggers
    final VDBMetaData vdb = cvdb.getVDB();
    if (vdb.getStatus() != Status.ACTIVE) {
        return;
    }
    doMaterializationActions(vdb, new MaterializationAction() {

        @Override
        public void process(final Table table) {
            if (table.getMaterializedTable() == null) {
                String ttlStr = table.getProperty(MaterializationMetadataRepository.MATVIEW_TTL, false);
                if (ttlStr != null) {
                    long ttl = Long.parseLong(ttlStr);
                    if (ttl > 0) {
                        // TODO: make the interval based upon the state as with the external, but
                        // for now just refresh on schedule
                        Future<?> f = getScheduledExecutorService().scheduleAtFixedRate(new Runnable() {

                            @Override
                            public void run() {
                                boolean invalidate = TempTableDataManager.shouldInvalidate(vdb);
                                try {
                                    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
                                    executeAsynchQuery(vdb, "call SYSADMIN.refreshMatView('" + table.getFullName().replaceAll("'", "''") + "', " + invalidate + ")");
                                } catch (SQLException e) {
                                    LogManager.logWarning(LogConstants.CTX_MATVIEWS, e, e.getMessage());
                                }
                            }
                        }, 0, ttl, TimeUnit.MILLISECONDS);
                        cvdb.addTask(f);
                        return;
                    }
                }
                // just a one time load
                try {
                    // we use a count so that the load can cascade
                    // $NON-NLS-1$
                    executeAsynchQuery(vdb, "select count(*) from " + table.getSQLString());
                } catch (SQLException e) {
                    LogManager.logWarning(LogConstants.CTX_MATVIEWS, e, e.getMessage());
                }
                return;
            }
            // reset any jobs started by this node that did not complete
            // $NON-NLS-1$
            String nodeName = System.getProperty("jboss.node.name");
            resetPendingJob(vdb, table, nodeName);
            String start = table.getProperty(MaterializationMetadataRepository.ON_VDB_START_SCRIPT, false);
            if (start != null) {
                try {
                    executeQuery(vdb, start);
                } catch (SQLException e) {
                    LogManager.logWarning(LogConstants.CTX_MATVIEWS, e, e.getMessage());
                }
            }
            long ttl = 0;
            String ttlStr = table.getProperty(MaterializationMetadataRepository.MATVIEW_TTL, false);
            if (ttlStr == null) {
                ttlStr = String.valueOf(Long.MAX_VALUE);
            }
            if (ttlStr != null) {
                ttl = Long.parseLong(ttlStr);
                if (ttl > 0) {
                    scheduleSnapshotJob(cvdb, table, ttl, 0L, false);
                }
            }
            String stalenessString = table.getProperty(MaterializationMetadataRepository.MATVIEW_MAX_STALENESS_PCT, false);
            if (stalenessString != null) {
                // run first time like, SNAPSHOT
                if (ttl <= 0) {
                    scheduleSnapshotJob(cvdb, table, 0L, 0L, true);
                }
                // schedule a check every minute
                scheduleSnapshotJob(cvdb, table, WAITTIME, WAITTIME, true);
            }
        }
    });
}
Also used : Table(org.teiid.metadata.Table) SQLException(java.sql.SQLException) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) ScheduledFuture(java.util.concurrent.ScheduledFuture) Future(java.util.concurrent.Future) ResultsFuture(org.teiid.client.util.ResultsFuture)

Example 50 with VDBMetaData

use of org.teiid.adminapi.impl.VDBMetaData in project teiid by teiid.

the class MaterializationManager method nodeDropped.

@Override
public void nodeDropped(String nodeName) {
    for (VDBMetaData vdb : getVDBRepository().getVDBs()) {
        TransformationMetadata metadata = vdb.getAttachment(TransformationMetadata.class);
        if (metadata == null) {
            continue;
        }
        for (ModelMetaData model : vdb.getModelMetaDatas().values()) {
            if (vdb.getImportedModels().contains(model.getName())) {
                continue;
            }
            MetadataStore store = metadata.getMetadataStore();
            Schema schema = store.getSchema(model.getName());
            for (Table t : schema.getTables().values()) {
                if (t.isVirtual() && t.isMaterialized() && t.getMaterializedTable() != null) {
                    String allow = t.getProperty(MaterializationMetadataRepository.ALLOW_MATVIEW_MANAGEMENT, false);
                    if (allow == null || !Boolean.valueOf(allow)) {
                        continue;
                    }
                    // reset the pending job if there is one.
                    int update = resetPendingJob(vdb, t, nodeName);
                    if (update > 0) {
                        String ttlStr = t.getProperty(MaterializationMetadataRepository.MATVIEW_TTL, false);
                        if (ttlStr == null) {
                            ttlStr = String.valueOf(Long.MAX_VALUE);
                        }
                        if (ttlStr != null) {
                            long ttl = Long.parseLong(ttlStr);
                            if (ttl > 0) {
                                // run the job
                                CompositeVDB cvdb = getVDBRepository().getCompositeVDB(new VDBKey(vdb.getName(), vdb.getVersion()));
                                scheduleSnapshotJob(cvdb, t, ttl, 0L, true);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Table(org.teiid.metadata.Table) VDBKey(org.teiid.vdb.runtime.VDBKey) CompositeVDB(org.teiid.deployers.CompositeVDB) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) Schema(org.teiid.metadata.Schema) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Aggregations

VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)121 Test (org.junit.Test)48 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)36 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)16 MetadataStore (org.teiid.metadata.MetadataStore)15 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)14 VDBRepository (org.teiid.deployers.VDBRepository)12 ArrayList (java.util.ArrayList)10 IOException (java.io.IOException)9 ConnectorManager (org.teiid.dqp.internal.datamgr.ConnectorManager)9 Properties (java.util.Properties)8 XMLStreamException (javax.xml.stream.XMLStreamException)8 VDBImportMetadata (org.teiid.adminapi.impl.VDBImportMetadata)8 DataPolicyMetadata (org.teiid.adminapi.impl.DataPolicyMetadata)7 TeiidComponentException (org.teiid.core.TeiidComponentException)7 VDBKey (org.teiid.vdb.runtime.VDBKey)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 VDBTranslatorMetaData (org.teiid.adminapi.impl.VDBTranslatorMetaData)6 Schema (org.teiid.metadata.Schema)6 SessionMetadata (org.teiid.adminapi.impl.SessionMetadata)5