Search in sources :

Example 1 with VDBKey

use of org.teiid.vdb.runtime.VDBKey in project teiid by teiid.

the class DatabaseStore method databaseSwitched.

/*public void databaseDropped(String dbName, String version) {
        assertInEditMode();
        Database db = this.databases.get(new VDBKey(dbName,version));
        if (db == null) {
            throw new MetadataException(QueryPlugin.Event.TEIID31231,
                    QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31231, dbName, version));                        
        }

        assertGrant(Grant.Permission.Privilege.DROP, Database.ResourceType.DATABASE, db);
        
        // remove locally
        this.databases.remove(new VDBKey(dbName, version));
        if (this.currentDatabase != null && this.currentDatabase.getName().equalsIgnoreCase(dbName)) {
            this.currentDatabase = null;
        }
    }*/
public void databaseSwitched(String dbName, String version) {
    if (!assertInEditMode(Mode.DATABASE_STRUCTURE)) {
        return;
    }
    Database db = this.databases.get(new VDBKey(dbName, version));
    if (db == null) {
        throw new MetadataException(QueryPlugin.Event.TEIID31231, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31231, dbName, version));
    }
    if (currentDatabase != null && !this.currentDatabase.equals(db)) {
        throw new MetadataException(QueryPlugin.Event.TEIID31242, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31242));
    }
    this.currentDatabase = db;
}
Also used : VDBKey(org.teiid.vdb.runtime.VDBKey)

Example 2 with VDBKey

use of org.teiid.vdb.runtime.VDBKey in project teiid by teiid.

the class ODataFilter method internalDoFilter.

public void internalDoFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException, TeiidProcessingException {
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    String proxyURI = this.proxyBaseURI;
    if (proxyURI != null) {
        httpRequest = new ProxyHttpServletRequest(httpRequest, proxyURI);
    }
    VDBKey key = null;
    String vdbName = null;
    String version = null;
    String modelName = null;
    String uri = ((HttpServletRequest) request).getRequestURI().toString();
    String fullURL = ((HttpServletRequest) request).getRequestURL().toString();
    if (uri.startsWith("/odata4/static/") || uri.startsWith("/odata4/keycloak/")) {
        // $NON-NLS-1$ //$NON-NLS-2$
        chain.doFilter(httpRequest, response);
        return;
    }
    String contextPath = httpRequest.getContextPath();
    String baseURI = fullURL.substring(0, fullURL.indexOf(contextPath));
    int endIdx = uri.indexOf('/', contextPath.length() + 1);
    int beginIdx = contextPath.length() + 1;
    if (contextPath.equals("/odata4")) {
        // $NON-NLS-1$
        if (endIdx == -1) {
            throw new TeiidProcessingException(ODataPlugin.Event.TEIID16020, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16020));
        }
        // $NON-NLS-1$
        baseURI = baseURI + "/odata4";
        vdbName = uri.substring(beginIdx, endIdx);
        int modelIdx = uri.indexOf('/', endIdx + 1);
        if (modelIdx == -1) {
            modelName = uri.substring(endIdx + 1).trim();
            if (modelName.isEmpty()) {
                throw new TeiidProcessingException(ODataPlugin.Event.TEIID16019, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16019));
            }
        } else {
            modelName = uri.substring(endIdx + 1, modelIdx);
        }
        // $NON-NLS-1$ //$NON-NLS-2$
        contextPath = contextPath + "/" + vdbName + "/" + modelName;
        vdbName = vdbName.trim();
        if (vdbName.isEmpty()) {
            throw new TeiidProcessingException(ODataPlugin.Event.TEIID16008, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16008));
        }
    } else {
        if (this.initProperties.getProperty("vdb-name") == null) {
            // $NON-NLS-1$
            throw new TeiidProcessingException(ODataPlugin.Event.TEIID16018, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16018));
        }
        // $NON-NLS-1$
        vdbName = this.initProperties.getProperty("vdb-name");
        // $NON-NLS-1$
        version = this.initProperties.getProperty("vdb-version");
        if (endIdx == -1) {
            modelName = uri.substring(beginIdx).trim();
            if (modelName.isEmpty()) {
                throw new TeiidProcessingException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16021));
            }
        } else {
            modelName = uri.substring(beginIdx, endIdx);
        }
        // $NON-NLS-1$
        contextPath = contextPath + "/" + modelName;
    }
    ContextAwareHttpSerlvetRequest contextAwareRequest = new ContextAwareHttpSerlvetRequest(httpRequest);
    contextAwareRequest.setContextPath(contextPath);
    httpRequest = contextAwareRequest;
    key = new VDBKey(vdbName, version);
    if (key.isAtMost()) {
        if (key.getVersion() != null) {
            throw new TeiidProcessingException(ODataPlugin.Event.TEIID16044, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16044, key));
        }
        // $NON-NLS-1$ //legacy behavior, default to version 1
        key = new VDBKey(vdbName, "1");
    }
    SoftReference<OlingoBridge> ref = this.contextMap.get(key);
    OlingoBridge context = null;
    if (ref != null) {
        context = ref.get();
    }
    if (context == null) {
        context = new OlingoBridge();
        ref = new SoftReference<OlingoBridge>(context);
        this.contextMap.put(key, ref);
    }
    Client client = buildClient(key.getName(), key.getVersion(), this.initProperties);
    try {
        Connection connection = client.open();
        registerVDBListener(client, connection);
        ODataHttpHandler handler = context.getHandler(baseURI, client, modelName);
        httpRequest.setAttribute(ODataHttpHandler.class.getName(), handler);
        httpRequest.setAttribute(Client.class.getName(), client);
        chain.doFilter(httpRequest, response);
    } catch (SQLException e) {
        throw new TeiidProcessingException(e);
    } finally {
        try {
            client.close();
        } catch (SQLException e) {
        // ignore
        }
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) LocalServerConnection(org.teiid.transport.LocalServerConnection) OlingoBridge(org.teiid.olingo.service.OlingoBridge) ODataHttpHandler(org.apache.olingo.server.api.ODataHttpHandler) TeiidProcessingException(org.teiid.core.TeiidProcessingException) HttpServletRequest(javax.servlet.http.HttpServletRequest) VDBKey(org.teiid.vdb.runtime.VDBKey) Client(org.teiid.odata.api.Client) LocalClient(org.teiid.olingo.service.LocalClient)

Example 3 with VDBKey

use of org.teiid.vdb.runtime.VDBKey in project teiid by teiid.

the class VDBDeployer method deploy.

public void deploy(final DeploymentPhaseContext context) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
    if (!TeiidAttachments.isVDBDeployment(deploymentUnit)) {
        return;
    }
    final VDBMetaData deployment = deploymentUnit.getAttachment(TeiidAttachments.VDB_METADATA);
    VDBMetaData other = this.vdbRepository.getVDB(deployment.getName(), deployment.getVersion());
    if (other != null) {
        String deploymentName = other.getPropertyValue(TranslatorUtil.DEPLOYMENT_NAME);
        throw new DeploymentUnitProcessingException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50106, deployment, deploymentName));
    }
    deployment.addProperty(TranslatorUtil.DEPLOYMENT_NAME, deploymentUnit.getName());
    // check to see if there is old vdb already deployed.
    final ServiceController<?> controller = context.getServiceRegistry().getService(TeiidServiceNames.vdbServiceName(deployment.getName(), deployment.getVersion()));
    if (controller != null) {
        LogManager.logInfo(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50019, deployment));
        controller.setMode(ServiceController.Mode.REMOVE);
    }
    boolean preview = deployment.isPreview();
    if (!preview && deployment.hasErrors()) {
        throw new DeploymentUnitProcessingException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50074, deployment));
    }
    // make sure the translator defined exists in configuration; otherwise add as error
    for (ModelMetaData model : deployment.getModelMetaDatas().values()) {
        if (!model.isSource() || model.getSourceNames().isEmpty()) {
            continue;
        }
        for (String source : model.getSourceNames()) {
            String translatorName = model.getSourceTranslatorName(source);
            if (deployment.isOverideTranslator(translatorName)) {
                VDBTranslatorMetaData parent = deployment.getTranslator(translatorName);
                translatorName = parent.getType();
            }
            Translator translator = this.translatorRepository.getTranslatorMetaData(translatorName);
            if (translator == null) {
                String msg = IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50077, translatorName, deployment.getName(), deployment.getVersion());
                LogManager.logWarning(LogConstants.CTX_RUNTIME, msg);
            }
        }
    }
    // add VDB module's classloader as an attachment
    ModuleClassLoader classLoader = deploymentUnit.getAttachment(Attachments.MODULE).getClassLoader();
    deployment.addAttchment(ClassLoader.class, classLoader);
    deployment.addAttchment(ScriptEngineManager.class, new ScriptEngineManager(classLoader));
    try {
        EmbeddedServer.createPreParser(deployment);
    } catch (TeiidException e1) {
        throw new DeploymentUnitProcessingException(e1);
    }
    UDFMetaData udf = deploymentUnit.removeAttachment(TeiidAttachments.UDF_METADATA);
    if (udf == null) {
        udf = new UDFMetaData();
    }
    udf.setFunctionClassLoader(classLoader);
    deployment.addAttchment(UDFMetaData.class, udf);
    VirtualFile file = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();
    VDBResources resources;
    try {
        resources = new VDBResources(file, deployment);
    } catch (IOException e) {
        throw new DeploymentUnitProcessingException(IntegrationPlugin.Event.TEIID50017.name(), e);
    }
    this.vdbRepository.addPendingDeployment(deployment);
    // build a VDB service
    final VDBService vdb = new VDBService(deployment, resources, shutdownListener);
    // $NON-NLS-1$
    vdb.addMetadataRepository("index", new IndexMetadataRepository());
    final ServiceBuilder<RuntimeVDB> vdbService = context.getServiceTarget().addService(TeiidServiceNames.vdbServiceName(deployment.getName(), deployment.getVersion()), vdb);
    // add dependencies to data-sources
    dataSourceDependencies(deployment, context.getServiceTarget());
    for (VDBImport vdbImport : deployment.getVDBImports()) {
        VDBKey vdbKey = new VDBKey(vdbImport.getName(), vdbImport.getVersion());
        if (vdbKey.isAtMost()) {
            // TODO: could allow partial versions here if we canonicalize
            throw new DeploymentUnitProcessingException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40144, deployment, vdbKey));
        }
        LogManager.logInfo(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50115, deployment, vdbKey));
        vdbService.addDependency(TeiidServiceNames.vdbFinishedServiceName(vdbImport.getName(), vdbKey.getVersion()));
    }
    // adding the translator services is redundant, however if one is removed then it is an issue.
    for (Model model : deployment.getModels()) {
        List<String> sourceNames = model.getSourceNames();
        for (String sourceName : sourceNames) {
            String translatorName = model.getSourceTranslatorName(sourceName);
            if (deployment.isOverideTranslator(translatorName)) {
                VDBTranslatorMetaData translator = deployment.getTranslator(translatorName);
                translatorName = translator.getType();
            }
            vdbService.addDependency(TeiidServiceNames.translatorServiceName(translatorName));
        }
    }
    ServiceName vdbSwitchServiceName = TeiidServiceNames.vdbSwitchServiceName(deployment.getName(), deployment.getVersion());
    vdbService.addDependency(TeiidServiceNames.VDB_REPO, VDBRepository.class, vdb.vdbRepositoryInjector);
    vdbService.addDependency(TeiidServiceNames.TRANSLATOR_REPO, TranslatorRepository.class, vdb.translatorRepositoryInjector);
    vdbService.addDependency(TeiidServiceNames.THREAD_POOL_SERVICE, Executor.class, vdb.executorInjector);
    vdbService.addDependency(TeiidServiceNames.OBJECT_SERIALIZER, ObjectSerializer.class, vdb.serializerInjector);
    vdbService.addDependency(TeiidServiceNames.VDB_STATUS_CHECKER, VDBStatusChecker.class, vdb.vdbStatusCheckInjector);
    vdbService.addDependency(vdbSwitchServiceName, CountDownLatch.class, new InjectedValue<CountDownLatch>());
    // VDB restart switch, control the vdbservice by adding removing the switch service. If you
    // remove the service by setting status remove, there is no way start it back up if vdbservice used alone
    installVDBSwitchService(context.getServiceTarget(), vdbSwitchServiceName);
    vdbService.addListener(new AbstractServiceListener<Object>() {

        @Override
        public void transition(final ServiceController controller, final ServiceController.Transition transition) {
            if (transition.equals(ServiceController.Transition.DOWN_to_WAITING)) {
                RuntimeVDB runtimeVDB = RuntimeVDB.class.cast(controller.getValue());
                if (runtimeVDB != null && runtimeVDB.isRestartInProgress()) {
                    ServiceName vdbSwitchServiceName = TeiidServiceNames.vdbSwitchServiceName(deployment.getName(), deployment.getVersion());
                    ServiceController<?> switchSvc = controller.getServiceContainer().getService(vdbSwitchServiceName);
                    if (switchSvc != null) {
                        CountDownLatch latch = CountDownLatch.class.cast(switchSvc.getValue());
                        try {
                            latch.await(5, TimeUnit.SECONDS);
                        } catch (InterruptedException e) {
                        // todo:log it?
                        }
                    }
                    installVDBSwitchService(controller.getServiceContainer(), vdbSwitchServiceName);
                }
            }
        }
    });
    vdbService.setInitialMode(Mode.PASSIVE).install();
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) VirtualFile(org.jboss.vfs.VirtualFile) ScriptEngineManager(javax.script.ScriptEngineManager) IndexMetadataRepository(org.teiid.metadata.index.IndexMetadataRepository) Translator(org.teiid.adminapi.Translator) RuntimeVDB(org.teiid.deployers.RuntimeVDB) ModuleClassLoader(org.jboss.modules.ModuleClassLoader) UDFMetaData(org.teiid.deployers.UDFMetaData) VDBResources(org.teiid.query.metadata.VDBResources) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) TeiidException(org.teiid.core.TeiidException) VDBKey(org.teiid.vdb.runtime.VDBKey) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) VDBImport(org.teiid.adminapi.VDBImport) Model(org.teiid.adminapi.Model) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) VDBTranslatorMetaData(org.teiid.adminapi.impl.VDBTranslatorMetaData)

Example 4 with VDBKey

use of org.teiid.vdb.runtime.VDBKey in project teiid by teiid.

the class VDBDeployer method dataSourceDependencies.

private void dataSourceDependencies(VDBMetaData deployment, ServiceTarget serviceTarget) {
    final VDBKey vdbKey = new VDBKey(deployment.getName(), deployment.getVersion());
    Set<String> dataSources = new HashSet<String>();
    for (ModelMetaData model : deployment.getModelMetaDatas().values()) {
        for (String sourceName : model.getSourceNames()) {
            // Need to make the data source service as dependency; otherwise dynamic vdbs will not work correctly.
            String dsName = model.getSourceConnectionJndiName(sourceName);
            if (dsName == null) {
                continue;
            }
            if (!dataSources.add(VDBStatusChecker.stripContext(dsName))) {
                // already listening
                continue;
            }
            addDataSourceListener(serviceTarget, vdbKey, dsName);
        }
    }
}
Also used : VDBKey(org.teiid.vdb.runtime.VDBKey) HashSet(java.util.HashSet) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 5 with VDBKey

use of org.teiid.vdb.runtime.VDBKey in project teiid by teiid.

the class TestJBossSecurityHelper method validateSession.

public void validateSession(boolean securityEnabled) throws Exception {
    final ArrayList<String> domains = new ArrayList<String>();
    domains.add("somedomain");
    AuthenticationManager authManager = Mockito.mock(AuthenticationManager.class);
    Mockito.stub(authManager.isValid(new SimplePrincipal("steve"), "pass1", new Subject())).toReturn(true);
    final SecurityDomainContext securityContext = new SecurityDomainContext(authManager, null, null, null, null, null);
    SessionServiceImpl jss = new SessionServiceImpl() {

        @Override
        protected VDBMetaData getActiveVDB(String vdbName, String vdbVersion) throws SessionServiceException {
            return Mockito.mock(VDBMetaData.class);
        }
    };
    jss.setSecurityHelper(buildSecurityHelper("somedomain", securityContext));
    jss.setSecurityDomain("somedomain");
    try {
        jss.validateSession(String.valueOf(1));
        // $NON-NLS-1$
        fail("exception expected");
    } catch (InvalidSessionException e) {
    }
    // $NON-NLS-1$ //$NON-NLS-2$
    SessionMetadata info = jss.createSession("x", "1", AuthenticationType.USERPASSWORD, "steve", new Credentials("pass1".toCharArray()), "foo", new Properties());
    if (securityEnabled) {
        Mockito.verify(authManager).isValid(new SimplePrincipal("steve"), "pass1", new Subject());
    }
    String id1 = info.getSessionId();
    jss.validateSession(id1);
    assertEquals(1, jss.getActiveSessionsCount());
    // $NON-NLS-1$
    assertEquals(0, jss.getSessionsLoggedInToVDB(new VDBKey("a", 1)).size());
    jss.closeSession(id1);
    try {
        jss.validateSession(id1);
        // $NON-NLS-1$
        fail("exception expected");
    } catch (InvalidSessionException e) {
    }
    try {
        jss.closeSession(id1);
        // $NON-NLS-1$
        fail("exception expected");
    } catch (InvalidSessionException e) {
    }
}
Also used : InvalidSessionException(org.teiid.client.security.InvalidSessionException) SessionServiceImpl(org.teiid.services.SessionServiceImpl) SessionMetadata(org.teiid.adminapi.impl.SessionMetadata) ArrayList(java.util.ArrayList) Properties(java.util.Properties) Subject(javax.security.auth.Subject) SecurityDomainContext(org.jboss.as.security.plugins.SecurityDomainContext) AuthenticationManager(org.jboss.security.AuthenticationManager) VDBKey(org.teiid.vdb.runtime.VDBKey) SimplePrincipal(org.jboss.security.SimplePrincipal) Credentials(org.teiid.security.Credentials)

Aggregations

VDBKey (org.teiid.vdb.runtime.VDBKey)18 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)7 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)5 MetadataStore (org.teiid.metadata.MetadataStore)5 Schema (org.teiid.metadata.Schema)3 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Properties (java.util.Properties)2 Test (org.junit.Test)2 VDBImport (org.teiid.adminapi.VDBImport)2 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 HashSet (java.util.HashSet)1 NavigableMap (java.util.NavigableMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)1