Search in sources :

Example 6 with SourceMappingMetadata

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;
}
Also used : SourceMappingMetadata(org.teiid.adminapi.impl.SourceMappingMetadata)

Example 7 with SourceMappingMetadata

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);
    }
}
Also used : SourceMappingMetadata(org.teiid.adminapi.impl.SourceMappingMetadata) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) InvalidServiceNameException(org.teiid.jboss.TeiidServiceNames.InvalidServiceNameException) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 8 with SourceMappingMetadata

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);
                    }
                }
            }
        }
    }
}
Also used : SourceMappingMetadata(org.teiid.adminapi.impl.SourceMappingMetadata) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) AdminProcessingException(org.teiid.adminapi.AdminProcessingException) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 9 with SourceMappingMetadata

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);
            }
        }
    }
}
Also used : SourceMappingMetadata(org.teiid.adminapi.impl.SourceMappingMetadata) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) AdminProcessingException(org.teiid.adminapi.AdminProcessingException) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 10 with SourceMappingMetadata

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");
}
Also used : SourceMappingMetadata(org.teiid.adminapi.impl.SourceMappingMetadata) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Aggregations

SourceMappingMetadata (org.teiid.adminapi.impl.SourceMappingMetadata)13 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)11 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)5 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)4 AdminProcessingException (org.teiid.adminapi.AdminProcessingException)3 ConnectorManager (org.teiid.dqp.internal.datamgr.ConnectorManager)3 ArrayList (java.util.ArrayList)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1 DataPolicy (org.teiid.adminapi.DataPolicy)1 DataPermission (org.teiid.adminapi.DataPolicy.DataPermission)1 Translator (org.teiid.adminapi.Translator)1 DataPolicyMetadata (org.teiid.adminapi.impl.DataPolicyMetadata)1 InvalidServiceNameException (org.teiid.jboss.TeiidServiceNames.InvalidServiceNameException)1 Permission (org.teiid.metadata.Grant.Permission)1 EmbeddedConfiguration (org.teiid.runtime.EmbeddedConfiguration)1 EmbeddedServer (org.teiid.runtime.EmbeddedServer)1 LoopbackExecutionFactory (org.teiid.translator.loopback.LoopbackExecutionFactory)1