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;
}
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);
}
}
}
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());
}
}
}
});
}
}
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);
}
}
});
}
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);
}
}
}
}
}
}
}
}
Aggregations