use of org.teiid.adminapi.impl.SourceMappingMetadata in project teiid by teiid.
the class VDBStatusChecker method getSourceName.
private String getSourceName(String factoryName, ModelMetaData model) {
for (SourceMappingMetadata source : model.getSources().values()) {
String jndiName = source.getConnectionJndiName();
if (jndiName == null) {
continue;
}
jndiName = stripContext(jndiName);
if (factoryName.equals(jndiName)) {
return source.getName();
}
}
return null;
}
use of org.teiid.adminapi.impl.SourceMappingMetadata in project teiid by teiid.
the class VDBDeployer method undeploy.
@Override
public void undeploy(final DeploymentUnit deploymentUnit) {
if (!TeiidAttachments.isVDBDeployment(deploymentUnit)) {
return;
}
final VDBMetaData deployment = deploymentUnit.getAttachment(TeiidAttachments.VDB_METADATA);
if (!this.shutdownListener.isShutdownInProgress()) {
final VDBMetaData vdb = deploymentUnit.getAttachment(TeiidAttachments.VDB_METADATA);
ServiceController<?> sc = deploymentUnit.getServiceRegistry().getService(TeiidServiceNames.OBJECT_SERIALIZER);
if (sc != null) {
ObjectSerializer serilalizer = ObjectSerializer.class.cast(sc.getValue());
serilalizer.removeAttachments(vdb);
// $NON-NLS-1$ //$NON-NLS-2$
LogManager.logTrace(LogConstants.CTX_RUNTIME, "VDB " + vdb.getName() + " metadata removed");
}
}
this.vdbRepository.removeVDB(deployment.getName(), deployment.getVersion());
ServiceController<?> switchSvc = deploymentUnit.getServiceRegistry().getService(TeiidServiceNames.vdbSwitchServiceName(deployment.getName(), deployment.getVersion()));
if (switchSvc != null) {
switchSvc.setMode(ServiceController.Mode.REMOVE);
}
for (ModelMetaData model : deployment.getModelMetaDatas().values()) {
for (SourceMappingMetadata smm : model.getSources().values()) {
String dsName = smm.getConnectionJndiName();
if (dsName == null) {
continue;
}
ServiceController<?> dsService;
try {
dsService = deploymentUnit.getServiceRegistry().getService(TeiidServiceNames.dsListenerServiceName(deployment.getName(), deployment.getVersion(), dsName));
} catch (InvalidServiceNameException e) {
continue;
}
if (dsService != null) {
dsService.setMode(ServiceController.Mode.REMOVE);
}
}
}
final ServiceController<?> controller = deploymentUnit.getServiceRegistry().getService(TeiidServiceNames.vdbServiceName(deployment.getName(), deployment.getVersion()));
if (controller != null) {
controller.setMode(ServiceController.Mode.REMOVE);
}
}
use of org.teiid.adminapi.impl.SourceMappingMetadata in project teiid by teiid.
the class RuntimeVDB method updateSource.
public ReplaceResult updateSource(String sourceName, String translatorName, String dsName) throws AdminProcessingException {
synchronized (this.vdb) {
ConnectorManagerRepository cmr = vdb.getAttachment(ConnectorManagerRepository.class);
ConnectorManager cr = cmr.getConnectorManager(sourceName);
if (cr == null) {
throw new AdminProcessingException(RuntimePlugin.Event.TEIID40091, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40091, sourceName, this.vdb.getName(), this.vdb.getVersion()));
}
String previousTranslatorName = cr.getTranslatorName();
String previousDsName = cr.getConnectionName();
// modify all source elements in all models
for (ModelMetaData m : this.vdb.getModelMetaDatas().values()) {
SourceMappingMetadata mapping = m.getSourceMapping(sourceName);
if (mapping != null) {
mapping.setTranslatorName(translatorName);
mapping.setConnectionJndiName(dsName);
}
}
boolean success = false;
try {
this.listener.dataSourceChanged(null, sourceName, translatorName, dsName);
ReplaceResult rr = new ReplaceResult();
if (dsName != null) {
rr.isNew = !dsExists(dsName, cmr);
}
boolean replaced = getVDBStatusChecker().dataSourceReplaced(vdb.getName(), vdb.getVersion(), null, sourceName, translatorName, dsName);
if (replaced && previousDsName != null && !dsExists(previousDsName, cmr)) {
rr.removedDs = previousDsName;
}
success = true;
return rr;
} finally {
if (!success) {
for (ModelMetaData m : this.vdb.getModelMetaDatas().values()) {
SourceMappingMetadata mapping = m.getSourceMapping(sourceName);
if (mapping != null) {
mapping.setTranslatorName(previousTranslatorName);
mapping.setConnectionJndiName(previousDsName);
}
}
}
}
}
}
use of org.teiid.adminapi.impl.SourceMappingMetadata in project teiid by teiid.
the class RuntimeVDB method addSource.
public ReplaceResult addSource(String modelName, String sourceName, String translatorName, String dsName) throws AdminProcessingException {
synchronized (this.vdb) {
ModelMetaData model = this.vdb.getModel(modelName);
if (model == null) {
throw new AdminProcessingException(RuntimePlugin.Event.TEIID40090, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40090, modelName, this.vdb.getName(), this.vdb.getVersion()));
}
if (!model.isSupportsMultiSourceBindings()) {
throw new AdminProcessingException(RuntimePlugin.Event.TEIID40108, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40108, modelName, this.vdb.getName(), this.vdb.getVersion()));
}
SourceMappingMetadata source = model.getSourceMapping(sourceName);
if (source != null) {
throw new AdminProcessingException(RuntimePlugin.Event.TEIID40107, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40107, sourceName, modelName, this.vdb.getName(), this.vdb.getVersion()));
}
boolean success = false;
try {
SourceMappingMetadata mapping = new SourceMappingMetadata(sourceName, translatorName, dsName);
boolean updated = getVDBStatusChecker().updateSource(vdb.getName(), vdb.getVersion(), mapping, false);
model.addSourceMapping(mapping);
this.listener.dataSourceChanged(modelName, sourceName, translatorName, dsName);
ReplaceResult rr = new ReplaceResult();
if (dsName != null && updated) {
ConnectorManagerRepository cmr = vdb.getAttachment(ConnectorManagerRepository.class);
rr.isNew = !dsExists(dsName, cmr);
}
success = true;
return rr;
} finally {
if (!success) {
model.getSources().remove(sourceName);
}
}
}
}
use of org.teiid.adminapi.impl.SourceMappingMetadata in project teiid by teiid.
the class TestEmbeddedServerAdmin method testSource.
@Test
public void testSource() throws AdminException {
admin.addSource("AdminAPITestVDB", 1, "TestModel", "text-connector-test", "file", "java:/test-file");
for (VDB vdb : admin.getVDBs()) {
VDBMetaData vdbMetaData = (VDBMetaData) vdb;
for (ModelMetaData m : vdbMetaData.getModelMetaDatas().values()) {
SourceMappingMetadata mapping = m.getSourceMapping("text-connector-test");
if (mapping != null) {
assertEquals(mapping.getConnectionJndiName(), "java:/test-file");
assertEquals(mapping.getTranslatorName(), "file");
}
}
}
admin.updateSource("AdminAPITestVDB", 1, "text-connector-test", "mysql", "java:/test-jdbc");
for (VDB vdb : admin.getVDBs()) {
VDBMetaData vdbMetaData = (VDBMetaData) vdb;
for (ModelMetaData m : vdbMetaData.getModelMetaDatas().values()) {
SourceMappingMetadata mapping = m.getSourceMapping("text-connector-test");
if (mapping != null) {
assertEquals(mapping.getConnectionJndiName(), "java:/test-jdbc");
assertEquals(mapping.getTranslatorName(), "mysql");
}
}
}
admin.removeSource("AdminAPITestVDB", 1, "TestModel", "text-connector-test");
}
Aggregations