Search in sources :

Example 1 with IApplicationContext

use of org.apache.asterix.common.api.IApplicationContext in project asterixdb by apache.

the class GenericAdapterFactory method configure.

@Override
public void configure(IServiceContext serviceContext, Map<String, String> configuration) throws HyracksDataException, AlgebricksException {
    this.configuration = configuration;
    IApplicationContext appCtx = (IApplicationContext) serviceContext.getApplicationContext();
    ExternalDataUtils.validateDataSourceParameters(configuration);
    dataSourceFactory = DatasourceFactoryProvider.getExternalDataSourceFactory(appCtx.getLibraryManager(), configuration);
    if (dataSourceFactory.isIndexible() && (files != null)) {
        ((IIndexibleExternalDataSource) dataSourceFactory).setSnapshot(files, indexingOp);
    }
    dataSourceFactory.configure(serviceContext, configuration);
    ExternalDataUtils.validateDataParserParameters(configuration);
    dataParserFactory = ParserFactoryProvider.getDataParserFactory(appCtx.getLibraryManager(), configuration);
    dataParserFactory.setRecordType(recordType);
    dataParserFactory.setMetaType(metaType);
    dataParserFactory.configure(configuration);
    ExternalDataCompatibilityUtils.validateCompatibility(dataSourceFactory, dataParserFactory);
    configureFeedLogManager();
    nullifyExternalObjects();
}
Also used : IIndexibleExternalDataSource(org.apache.asterix.external.api.IIndexibleExternalDataSource) IApplicationContext(org.apache.asterix.common.api.IApplicationContext)

Example 2 with IApplicationContext

use of org.apache.asterix.common.api.IApplicationContext in project asterixdb by apache.

the class LookupAdapterFactory method configure.

public void configure(IServiceContext serviceContext, Map<String, String> configuration) throws HyracksDataException, AlgebricksException {
    this.configuration = configuration;
    IApplicationContext appCtx = (IApplicationContext) serviceContext.getApplicationContext();
    readerFactory = LookupReaderFactoryProvider.getLookupReaderFactory(serviceContext, configuration);
    dataParserFactory = (IRecordDataParserFactory<T>) ParserFactoryProvider.getDataParserFactory(appCtx.getLibraryManager(), configuration);
    dataParserFactory.setRecordType(recordType);
    readerFactory.configure(serviceContext, configuration);
    dataParserFactory.configure(configuration);
}
Also used : IApplicationContext(org.apache.asterix.common.api.IApplicationContext)

Example 3 with IApplicationContext

use of org.apache.asterix.common.api.IApplicationContext in project asterixdb by apache.

the class ReplicationCheckpointManager method getDeadReplicasMinFirstLSN.

private long getDeadReplicasMinFirstLSN(Set<String> deadReplicaIds) {
    final IReplicaResourcesManager remoteResourcesManager = txnSubsystem.getAsterixAppRuntimeContextProvider().getAppContext().getReplicaResourcesManager();
    final IApplicationContext propertiesProvider = txnSubsystem.getAsterixAppRuntimeContextProvider().getAppContext();
    final MetadataProperties metadataProperties = propertiesProvider.getMetadataProperties();
    final PersistentLocalResourceRepository localResourceRepository = (PersistentLocalResourceRepository) txnSubsystem.getAsterixAppRuntimeContextProvider().getLocalResourceRepository();
    // Get partitions of the dead replicas that are not active on this node
    final Set<Integer> deadReplicasPartitions = new HashSet<>();
    for (String deadReplicaId : deadReplicaIds) {
        final ClusterPartition[] nodePartitons = metadataProperties.getNodePartitions().get(deadReplicaId);
        for (ClusterPartition partition : nodePartitons) {
            if (!localResourceRepository.getActivePartitions().contains(partition.getPartitionId())) {
                deadReplicasPartitions.add(partition.getPartitionId());
            }
        }
    }
    return remoteResourcesManager.getPartitionsMinLSN(deadReplicasPartitions);
}
Also used : PersistentLocalResourceRepository(org.apache.asterix.transaction.management.resource.PersistentLocalResourceRepository) IReplicaResourcesManager(org.apache.asterix.common.replication.IReplicaResourcesManager) IApplicationContext(org.apache.asterix.common.api.IApplicationContext) MetadataProperties(org.apache.asterix.common.config.MetadataProperties) HashSet(java.util.HashSet) ClusterPartition(org.apache.asterix.common.cluster.ClusterPartition)

Example 4 with IApplicationContext

use of org.apache.asterix.common.api.IApplicationContext in project asterixdb by apache.

the class TestTypedAdapterFactory method createAdapter.

@Override
public IDataSourceAdapter createAdapter(IHyracksTaskContext ctx, int partition) throws HyracksDataException {
    final String nodeId = ctx.getJobletContext().getServiceContext().getNodeId();
    final ITupleParserFactory tupleParserFactory = new ITupleParserFactory() {

        private static final long serialVersionUID = 1L;

        @Override
        public ITupleParser createTupleParser(IHyracksTaskContext ctx) throws HyracksDataException {
            ADMDataParser parser;
            ITupleForwarder forwarder;
            ArrayTupleBuilder tb;
            IApplicationContext appCtx = (IApplicationContext) ctx.getJobletContext().getServiceContext().getApplicationContext();
            ClusterPartition nodePartition = appCtx.getMetadataProperties().getNodePartitions().get(nodeId)[0];
            parser = new ADMDataParser(outputType, true);
            forwarder = DataflowUtils.getTupleForwarder(configuration, FeedUtils.getFeedLogManager(ctx, FeedUtils.splitsForAdapter(ExternalDataUtils.getDataverse(configuration), ExternalDataUtils.getFeedName(configuration), nodeId, nodePartition)));
            tb = new ArrayTupleBuilder(1);
            return new ITupleParser() {

                @Override
                public void parse(InputStream in, IFrameWriter writer) throws HyracksDataException {
                    try {
                        parser.setInputStream(in);
                        forwarder.initialize(ctx, writer);
                        while (true) {
                            tb.reset();
                            if (!parser.parse(tb.getDataOutput())) {
                                break;
                            }
                            tb.addFieldEndOffset();
                            forwarder.addTuple(tb);
                        }
                        forwarder.close();
                    } catch (Exception e) {
                        throw new HyracksDataException(e);
                    }
                }
            };
        }
    };
    try {
        return new TestTypedAdapter(tupleParserFactory, outputType, ctx, configuration, partition);
    } catch (IOException e) {
        throw new HyracksDataException(e);
    }
}
Also used : IFrameWriter(org.apache.hyracks.api.comm.IFrameWriter) ITupleParser(org.apache.hyracks.dataflow.std.file.ITupleParser) InputStream(java.io.InputStream) ArrayTupleBuilder(org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder) IApplicationContext(org.apache.asterix.common.api.IApplicationContext) IOException(java.io.IOException) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IOException(java.io.IOException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) ADMDataParser(org.apache.asterix.external.parser.ADMDataParser) ITupleForwarder(org.apache.asterix.external.api.ITupleForwarder) ITupleParserFactory(org.apache.hyracks.dataflow.std.file.ITupleParserFactory) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) ClusterPartition(org.apache.asterix.common.cluster.ClusterPartition)

Example 5 with IApplicationContext

use of org.apache.asterix.common.api.IApplicationContext in project asterixdb by apache.

the class RSSRecordReaderFactory method getPartitionConstraint.

@Override
public AlgebricksAbsolutePartitionConstraint getPartitionConstraint() throws AlgebricksException {
    int count = urls.size();
    clusterLocations = IExternalDataSourceFactory.getPartitionConstraints((IApplicationContext) serviceContext.getApplicationContext(), clusterLocations, count);
    return clusterLocations;
}
Also used : IApplicationContext(org.apache.asterix.common.api.IApplicationContext) AlgebricksAbsolutePartitionConstraint(org.apache.hyracks.algebricks.common.constraints.AlgebricksAbsolutePartitionConstraint)

Aggregations

IApplicationContext (org.apache.asterix.common.api.IApplicationContext)5 ClusterPartition (org.apache.asterix.common.cluster.ClusterPartition)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HashSet (java.util.HashSet)1 MetadataProperties (org.apache.asterix.common.config.MetadataProperties)1 IReplicaResourcesManager (org.apache.asterix.common.replication.IReplicaResourcesManager)1 IIndexibleExternalDataSource (org.apache.asterix.external.api.IIndexibleExternalDataSource)1 ITupleForwarder (org.apache.asterix.external.api.ITupleForwarder)1 ADMDataParser (org.apache.asterix.external.parser.ADMDataParser)1 PersistentLocalResourceRepository (org.apache.asterix.transaction.management.resource.PersistentLocalResourceRepository)1 AlgebricksAbsolutePartitionConstraint (org.apache.hyracks.algebricks.common.constraints.AlgebricksAbsolutePartitionConstraint)1 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)1 IFrameWriter (org.apache.hyracks.api.comm.IFrameWriter)1 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)1 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)1 ArrayTupleBuilder (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder)1 ITupleParser (org.apache.hyracks.dataflow.std.file.ITupleParser)1 ITupleParserFactory (org.apache.hyracks.dataflow.std.file.ITupleParserFactory)1