Search in sources :

Example 76 with VDBMetaData

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

the class VDBMetadataFactory method getVDBMetadata.

public static TransformationMetadata getVDBMetadata(String vdbName, URL vdbURL, URL udfFile) throws IOException {
    TransformationMetadata vdbmetadata = VDB_CACHE.get(vdbURL);
    if (vdbmetadata != null) {
        return vdbmetadata;
    }
    try {
        IndexVDB imf = loadMetadata(vdbName, vdbURL);
        Resource r = imf.resources.getEntriesPlusVisibilities().get("/META-INF/vdb.xml");
        VDBMetaData vdb = null;
        if (r != null) {
            vdb = VDBMetadataParser.unmarshell(r.openStream());
        }
        Collection<FunctionMethod> methods = null;
        Collection<FunctionTree> trees = null;
        if (udfFile != null) {
            String schema = FileUtils.getFilenameWithoutExtension(udfFile.getPath());
            methods = FunctionMetadataReader.loadFunctionMethods(udfFile.openStream());
            trees = Arrays.asList(new FunctionTree(schema, new UDFSource(methods), true));
        }
        SystemFunctionManager sfm = SystemMetadata.getInstance().getSystemFunctionManager();
        vdbmetadata = new TransformationMetadata(vdb, new CompositeMetadataStore(Arrays.asList(SystemMetadata.getInstance().getSystemStore(), imf.store)), imf.resources.getEntriesPlusVisibilities(), sfm.getSystemFunctions(), trees);
        VDB_CACHE.put(vdbURL, vdbmetadata);
        return vdbmetadata;
    } catch (XMLStreamException e) {
        throw new IOException(e);
    }
}
Also used : UDFSource(org.teiid.query.function.UDFSource) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) FunctionTree(org.teiid.query.function.FunctionTree) SystemFunctionManager(org.teiid.query.function.SystemFunctionManager) Resource(org.teiid.query.metadata.VDBResources.Resource) IOException(java.io.IOException) CompositeMetadataStore(org.teiid.query.metadata.CompositeMetadataStore) XMLStreamException(javax.xml.stream.XMLStreamException) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) FunctionMethod(org.teiid.metadata.FunctionMethod)

Example 77 with VDBMetaData

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

the class EngineStatistics method checkVDB.

static VDBMetaData checkVDB(OperationContext context, String vdbName, String vdbVersion) throws OperationFailedException {
    ServiceController<?> sc = context.getServiceRegistry(false).getRequiredService(TeiidServiceNames.VDB_REPO);
    VDBRepository repo = VDBRepository.class.cast(sc.getValue());
    VDBMetaData vdb = repo.getLiveVDB(vdbName, vdbVersion);
    if (vdb == null) {
        throw new OperationFailedException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50102, vdbName, vdbVersion));
    }
    Status status = vdb.getStatus();
    if (status != VDB.Status.ACTIVE) {
        throw new OperationFailedException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50096, vdbName, vdbVersion));
    }
    return vdb;
}
Also used : Status(org.teiid.adminapi.VDB.Status) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) OperationFailedException(org.jboss.as.controller.OperationFailedException) VDBRepository(org.teiid.deployers.VDBRepository)

Example 78 with VDBMetaData

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

the class OlingoBridge method getHandler.

public ODataHttpHandler getHandler(String baseUri, Client client, String schemaName) throws ServletException {
    if (this.handlers.get(schemaName) == null) {
        org.teiid.metadata.Schema teiidSchema = client.getMetadataStore().getSchema(schemaName);
        if (teiidSchema == null || !isVisible(client.getVDB(), teiidSchema)) {
            throw new ServletException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16022));
        }
        try {
            OData odata = OData4Impl.newInstance();
            VDBMetaData vdb = client.getVDB();
            CsdlSchema schema = ODataSchemaBuilder.buildMetadata(vdb.getFullName(), teiidSchema);
            TeiidEdmProvider edmProvider = new TeiidEdmProvider(baseUri, schema, client.getProperty(Client.INVALID_CHARACTER_REPLACEMENT));
            ServiceMetadata metadata = odata.createServiceMetadata(edmProvider, edmProvider.getReferences());
            ODataHttpHandler handler = odata.createHandler(metadata);
            handler.register(new TeiidServiceHandler(schemaName));
            this.handlers.put(schemaName, handler);
        } catch (XMLStreamException e) {
            throw new ServletException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16054));
        } catch (ODataException e) {
            throw new ServletException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16054));
        }
    }
    return this.handlers.get(schemaName);
}
Also used : OData(org.apache.olingo.server.api.OData) CsdlSchema(org.apache.olingo.commons.api.edm.provider.CsdlSchema) ODataHttpHandler(org.apache.olingo.server.api.ODataHttpHandler) ServletException(javax.servlet.ServletException) ODataException(org.apache.olingo.commons.api.ex.ODataException) XMLStreamException(javax.xml.stream.XMLStreamException) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) ServiceMetadata(org.apache.olingo.server.api.ServiceMetadata)

Example 79 with VDBMetaData

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

the class VDBRepository method finishDeployment.

public void finishDeployment(String name, String version) {
    VDBKey key = new VDBKey(name, version);
    CompositeVDB v = this.vdbRepo.get(key);
    if (v == null) {
        return;
    }
    VDBMetaData metadataAwareVDB = v.getVDB();
    if (v.getOriginalVDB().getStatus() == Status.FAILED) {
        if (v.getOriginalVDB() != metadataAwareVDB && metadataAwareVDB.getStatus() == Status.LOADING) {
            metadataAwareVDB.setStatus(Status.FAILED);
        }
        return;
    }
    synchronized (metadataAwareVDB) {
        try {
            try {
                v.metadataLoadFinished(allowEnv);
            } catch (MetadataException e) {
                // $NON-NLS-1$
                LogManager.logWarning(LogConstants.CTX_RUNTIME, e, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40073, name, version, e.getMessage()));
                if (!metadataAwareVDB.isPreview()) {
                    ValidatorReport report = new ValidatorReport();
                    report.addItem(new ValidatorFailure(e.getMessage()));
                    if (!processMetadataValidatorReport(key, report)) {
                        metadataAwareVDB.setStatus(Status.FAILED);
                        notifyFinished(name, version, v);
                        return;
                    }
                }
            }
            MetadataStore store = metadataAwareVDB.removeAttachment(MetadataStore.class);
            ValidatorReport report = new MetadataValidator(store.getDatatypes(), QueryParser.getQueryParser()).validate(metadataAwareVDB, store);
            if (report.hasItems()) {
                LogManager.logWarning(LogConstants.CTX_RUNTIME, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40073, name, version, report.getItems().iterator().next()));
                if (!metadataAwareVDB.isPreview() && !processMetadataValidatorReport(key, report)) {
                    metadataAwareVDB.setStatus(Status.FAILED);
                    notifyFinished(name, version, v);
                    return;
                }
            }
            validateDataSources(metadataAwareVDB);
            metadataAwareVDB.setStatus(Status.ACTIVE);
            // for  replication of events, temp tables and mat views
            GlobalTableStore gts = CompositeGlobalTableStore.createInstance(v, this.bufferManager, this.objectReplictor);
            metadataAwareVDB.addAttchment(GlobalTableStore.class, gts);
            if (this.databaseStore != null) {
                metadataAwareVDB.addAttchment(DatabaseStore.class, this.databaseStore);
            }
            notifyFinished(name, version, v);
        } finally {
            if (metadataAwareVDB.getStatus() != Status.ACTIVE && metadataAwareVDB.getStatus() != Status.FAILED) {
                // guard against an unexpected exception - probably bad validation logic
                metadataAwareVDB.setStatus(Status.FAILED);
                notifyFinished(name, version, v);
            }
        }
    }
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) VDBKey(org.teiid.vdb.runtime.VDBKey) ValidatorFailure(org.teiid.query.validator.ValidatorFailure) GlobalTableStore(org.teiid.query.tempdata.GlobalTableStore) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) FunctionMetadataValidator(org.teiid.query.function.metadata.FunctionMetadataValidator) MetadataValidator(org.teiid.query.metadata.MetadataValidator) MetadataException(org.teiid.metadata.MetadataException) ValidatorReport(org.teiid.query.validator.ValidatorReport)

Example 80 with VDBMetaData

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

the class VDBStatusChecker method updateSource.

/**
 * @return true if the datasource is new to the vdb
 * @throws AdminProcessingException
 */
public boolean updateSource(String vdbName, String vdbVersion, SourceMappingMetadata mapping, boolean replace) throws AdminProcessingException {
    String dsName = stripContext(mapping.getConnectionJndiName());
    VDBMetaData vdb = getVDBRepository().getLiveVDB(vdbName, vdbVersion);
    if (vdb == null || vdb.getStatus() == Status.FAILED) {
        return false;
    }
    synchronized (vdb) {
        ConnectorManagerRepository cmr = vdb.getAttachment(ConnectorManagerRepository.class);
        ConnectorManager existing = cmr.getConnectorManager(mapping.getName());
        try {
            cmr.createConnectorManager(vdb, cmr.getProvider(), mapping, replace);
        } catch (TeiidException e) {
            throw new AdminProcessingException(RuntimePlugin.Event.TEIID40033, e);
        }
        if (mapping.getConnectionJndiName() != null && (existing == null || !dsName.equals(existing.getConnectionName()))) {
            List<Runnable> runnables = new ArrayList<Runnable>();
            resourceAdded(dsName, runnables, vdb);
            return true;
        }
        return false;
    }
}
Also used : ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) ArrayList(java.util.ArrayList) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) AdminProcessingException(org.teiid.adminapi.AdminProcessingException) TeiidException(org.teiid.core.TeiidException)

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