Search in sources :

Example 1 with DatasourceAdapter

use of org.apache.asterix.metadata.entities.DatasourceAdapter in project asterixdb by apache.

the class MetadataManagerUtil method getAdapter.

public static DatasourceAdapter getAdapter(MetadataTransactionContext mdTxnCtx, String dataverseName, String adapterName) throws MetadataException {
    DatasourceAdapter adapter;
    // search in default namespace (built-in adapter)
    adapter = MetadataManager.INSTANCE.getAdapter(mdTxnCtx, MetadataConstants.METADATA_DATAVERSE_NAME, adapterName);
    // search in dataverse (user-defined adapter)
    if (adapter == null) {
        adapter = MetadataManager.INSTANCE.getAdapter(mdTxnCtx, dataverseName, adapterName);
    }
    return adapter;
}
Also used : DatasourceAdapter(org.apache.asterix.metadata.entities.DatasourceAdapter)

Example 2 with DatasourceAdapter

use of org.apache.asterix.metadata.entities.DatasourceAdapter in project asterixdb by apache.

the class MetadataBootstrap method insertInitialAdapters.

private static void insertInitialAdapters(MetadataTransactionContext mdTxnCtx) throws MetadataException {
    String[] builtInAdapterClassNames = new String[] { GenericAdapterFactory.class.getName() };
    DatasourceAdapter adapter;
    for (String adapterClassName : builtInAdapterClassNames) {
        adapter = getAdapter(adapterClassName);
        MetadataManager.INSTANCE.addAdapter(mdTxnCtx, adapter);
    }
    if (LOGGER.isLoggable(Level.INFO)) {
        LOGGER.info("Finished inserting built-in adapters.");
    }
}
Also used : DatasourceAdapter(org.apache.asterix.metadata.entities.DatasourceAdapter)

Example 3 with DatasourceAdapter

use of org.apache.asterix.metadata.entities.DatasourceAdapter in project asterixdb by apache.

the class FeedMetadataUtil method validateFeed.

public static void validateFeed(Feed feed, MetadataTransactionContext mdTxnCtx, ICcApplicationContext appCtx) throws AsterixException {
    try {
        String adapterName = feed.getAdapterName();
        Map<String, String> configuration = feed.getAdapterConfiguration();
        ARecordType adapterOutputType = getOutputType(feed, configuration, ExternalDataConstants.KEY_TYPE_NAME);
        ARecordType metaType = getOutputType(feed, configuration, ExternalDataConstants.KEY_META_TYPE_NAME);
        ExternalDataUtils.prepareFeed(configuration, feed.getDataverseName(), feed.getFeedName());
        // Get adapter from metadata dataset <Metadata dataverse>
        DatasourceAdapter adapterEntity = MetadataManager.INSTANCE.getAdapter(mdTxnCtx, MetadataConstants.METADATA_DATAVERSE_NAME, adapterName);
        // Get adapter from metadata dataset <The feed dataverse>
        if (adapterEntity == null) {
            adapterEntity = MetadataManager.INSTANCE.getAdapter(mdTxnCtx, feed.getDataverseName(), adapterName);
        }
        AdapterType adapterType;
        IAdapterFactory adapterFactory;
        if (adapterEntity != null) {
            adapterType = adapterEntity.getType();
            String adapterFactoryClassname = adapterEntity.getClassname();
            switch(adapterType) {
                case INTERNAL:
                    adapterFactory = (IAdapterFactory) Class.forName(adapterFactoryClassname).newInstance();
                    break;
                case EXTERNAL:
                    String[] anameComponents = adapterName.split("#");
                    String libraryName = anameComponents[0];
                    ClassLoader cl = appCtx.getLibraryManager().getLibraryClassLoader(feed.getDataverseName(), libraryName);
                    adapterFactory = (IAdapterFactory) cl.loadClass(adapterFactoryClassname).newInstance();
                    break;
                default:
                    throw new AsterixException("Unknown Adapter type " + adapterType);
            }
            adapterFactory.setOutputType(adapterOutputType);
            adapterFactory.setMetaType(metaType);
            adapterFactory.configure(appCtx.getServiceContext(), configuration);
        } else {
            AdapterFactoryProvider.getAdapterFactory(appCtx.getServiceContext(), adapterName, configuration, adapterOutputType, metaType);
        }
        if (metaType == null && configuration.containsKey(ExternalDataConstants.KEY_META_TYPE_NAME)) {
            metaType = getOutputType(feed, configuration, ExternalDataConstants.KEY_META_TYPE_NAME);
            if (metaType == null) {
                throw new AsterixException("Unknown specified feed meta output data type " + configuration.get(ExternalDataConstants.KEY_META_TYPE_NAME));
            }
        }
        if (adapterOutputType == null) {
            if (!configuration.containsKey(ExternalDataConstants.KEY_TYPE_NAME)) {
                throw new AsterixException("Unspecified feed output data type");
            }
            adapterOutputType = getOutputType(feed, configuration, ExternalDataConstants.KEY_TYPE_NAME);
            if (adapterOutputType == null) {
                throw new AsterixException("Unknown specified feed output data type " + configuration.get(ExternalDataConstants.KEY_TYPE_NAME));
            }
        }
    } catch (Exception e) {
        throw new AsterixException("Invalid feed parameters. Exception Message:" + e.getMessage(), e);
    }
}
Also used : DatasourceAdapter(org.apache.asterix.metadata.entities.DatasourceAdapter) AsterixException(org.apache.asterix.common.exceptions.AsterixException) AdapterType(org.apache.asterix.external.api.IDataSourceAdapter.AdapterType) IAdapterFactory(org.apache.asterix.external.api.IAdapterFactory) ARecordType(org.apache.asterix.om.types.ARecordType) AsterixException(org.apache.asterix.common.exceptions.AsterixException) ACIDException(org.apache.asterix.common.exceptions.ACIDException) MetadataException(org.apache.asterix.metadata.MetadataException) CompilationException(org.apache.asterix.common.exceptions.CompilationException) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) RemoteException(java.rmi.RemoteException)

Example 4 with DatasourceAdapter

use of org.apache.asterix.metadata.entities.DatasourceAdapter in project asterixdb by apache.

the class ExternalLibraryUtils method uninstallLibrary.

/**
     * Remove the library from metadata completely.
     * TODO Currently, external libraries only include functions and adapters. we need to extend this to include:
     * 1. external data source
     * 2. data parser
     *
     * @param dataverse
     * @param libraryName
     * @return true if the library was found and removed, false otherwise
     * @throws AsterixException
     * @throws RemoteException
     * @throws ACIDException
     */
protected static boolean uninstallLibrary(String dataverse, String libraryName) throws AsterixException, RemoteException, ACIDException {
    MetadataTransactionContext mdTxnCtx = null;
    try {
        // begin transaction
        mdTxnCtx = MetadataManager.INSTANCE.beginTransaction();
        // make sure dataverse exists
        Dataverse dv = MetadataManager.INSTANCE.getDataverse(mdTxnCtx, dataverse);
        if (dv == null) {
            return false;
        }
        // make sure library exists
        Library library = MetadataManager.INSTANCE.getLibrary(mdTxnCtx, dataverse, libraryName);
        if (library == null) {
            return false;
        }
        // get dataverse functions
        List<Function> functions = MetadataManager.INSTANCE.getDataverseFunctions(mdTxnCtx, dataverse);
        for (Function function : functions) {
            // does function belong to library?
            if (function.getName().startsWith(libraryName + "#")) {
                // drop the function
                MetadataManager.INSTANCE.dropFunction(mdTxnCtx, new FunctionSignature(dataverse, function.getName(), function.getArity()));
            }
        }
        // get the dataverse adapters
        List<DatasourceAdapter> adapters = MetadataManager.INSTANCE.getDataverseAdapters(mdTxnCtx, dataverse);
        for (DatasourceAdapter adapter : adapters) {
            // belong to the library?
            if (adapter.getAdapterIdentifier().getName().startsWith(libraryName + "#")) {
                // remove adapter <! we didn't check if there are feeds which use this adapter>
                MetadataManager.INSTANCE.dropAdapter(mdTxnCtx, dataverse, adapter.getAdapterIdentifier().getName());
            }
        }
        // drop the library itself
        MetadataManager.INSTANCE.dropLibrary(mdTxnCtx, dataverse, libraryName);
        MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
    } catch (Exception e) {
        MetadataManager.INSTANCE.abortTransaction(mdTxnCtx);
        throw new AsterixException(e);
    }
    return true;
}
Also used : Function(org.apache.asterix.metadata.entities.Function) LibraryFunction(org.apache.asterix.external.library.LibraryFunction) DatasourceAdapter(org.apache.asterix.metadata.entities.DatasourceAdapter) AsterixException(org.apache.asterix.common.exceptions.AsterixException) MetadataTransactionContext(org.apache.asterix.metadata.MetadataTransactionContext) Library(org.apache.asterix.metadata.entities.Library) ExternalLibrary(org.apache.asterix.external.library.ExternalLibrary) Dataverse(org.apache.asterix.metadata.entities.Dataverse) FunctionSignature(org.apache.asterix.common.functions.FunctionSignature) AsterixException(org.apache.asterix.common.exceptions.AsterixException) ACIDException(org.apache.asterix.common.exceptions.ACIDException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException)

Example 5 with DatasourceAdapter

use of org.apache.asterix.metadata.entities.DatasourceAdapter in project asterixdb by apache.

the class MetadataNode method dropAdapter.

@Override
public void dropAdapter(JobId jobId, String dataverseName, String adapterName) throws MetadataException, RemoteException {
    DatasourceAdapter adapter = getAdapter(jobId, dataverseName, adapterName);
    if (adapter == null) {
        throw new MetadataException("Cannot drop adapter '" + adapter + "' because it doesn't exist.");
    }
    try {
        // Delete entry from the 'Adapter' dataset.
        ITupleReference searchKey = createTuple(dataverseName, adapterName);
        // Searches the index for the tuple to be deleted. Acquires an S
        // lock on the 'Adapter' dataset.
        ITupleReference datasetTuple = getTupleToBeDeleted(jobId, MetadataPrimaryIndexes.DATASOURCE_ADAPTER_DATASET, searchKey);
        deleteTupleFromIndex(jobId, MetadataPrimaryIndexes.DATASOURCE_ADAPTER_DATASET, datasetTuple);
    // TODO: Change this to be a BTree specific exception, e.g.,
    // BTreeKeyDoesNotExistException.
    } catch (HyracksDataException e) {
        if (e.getComponent().equals(ErrorCode.HYRACKS) && e.getErrorCode() == ErrorCode.UPDATE_OR_DELETE_NON_EXISTENT_KEY) {
            throw new MetadataException("Cannot drop adapter '" + adapterName + " since it doesn't exist", e);
        } else {
            throw new MetadataException(e);
        }
    } catch (ACIDException e) {
        throw new MetadataException(e);
    }
}
Also used : DatasourceAdapter(org.apache.asterix.metadata.entities.DatasourceAdapter) ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Aggregations

DatasourceAdapter (org.apache.asterix.metadata.entities.DatasourceAdapter)14 ACIDException (org.apache.asterix.common.exceptions.ACIDException)6 RemoteException (java.rmi.RemoteException)4 AsterixException (org.apache.asterix.common.exceptions.AsterixException)4 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)4 ITupleReference (org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)4 ArrayList (java.util.ArrayList)3 AdapterIdentifier (org.apache.asterix.external.dataset.adapter.AdapterIdentifier)3 Function (org.apache.asterix.metadata.entities.Function)3 IOException (java.io.IOException)2 CompilationException (org.apache.asterix.common.exceptions.CompilationException)2 FunctionSignature (org.apache.asterix.common.functions.FunctionSignature)2 IAdapterFactory (org.apache.asterix.external.api.IAdapterFactory)2 IDataSourceAdapter (org.apache.asterix.external.api.IDataSourceAdapter)2 AdapterType (org.apache.asterix.external.api.IDataSourceAdapter.AdapterType)2 ExternalLibrary (org.apache.asterix.external.library.ExternalLibrary)2 LibraryFunction (org.apache.asterix.external.library.LibraryFunction)2 MetadataException (org.apache.asterix.metadata.MetadataException)2 MetadataTransactionContext (org.apache.asterix.metadata.MetadataTransactionContext)2 Dataverse (org.apache.asterix.metadata.entities.Dataverse)2