Search in sources :

Example 1 with INCServiceContext

use of org.apache.hyracks.api.application.INCServiceContext in project asterixdb by apache.

the class NCQueryServiceServlet method executeStatement.

@Override
protected void executeStatement(String statementsText, SessionOutput sessionOutput, IStatementExecutor.ResultDelivery delivery, IStatementExecutor.Stats stats, RequestParameters param, String handleUrl, long[] outExecStartEnd) throws Exception {
    // Running on NC -> send 'execute' message to CC
    INCServiceContext ncCtx = (INCServiceContext) serviceCtx;
    INCMessageBroker ncMb = (INCMessageBroker) ncCtx.getMessageBroker();
    IStatementExecutor.ResultDelivery ccDelivery = delivery == IStatementExecutor.ResultDelivery.IMMEDIATE ? IStatementExecutor.ResultDelivery.DEFERRED : delivery;
    ExecuteStatementResponseMessage responseMsg;
    MessageFuture responseFuture = ncMb.registerMessageFuture();
    try {
        ExecuteStatementRequestMessage requestMsg = new ExecuteStatementRequestMessage(ncCtx.getNodeId(), responseFuture.getFutureId(), queryLanguage, statementsText, sessionOutput.config(), ccDelivery, param.clientContextID, handleUrl);
        outExecStartEnd[0] = System.nanoTime();
        ncMb.sendMessageToCC(requestMsg);
        responseMsg = (ExecuteStatementResponseMessage) responseFuture.get(ExecuteStatementResponseMessage.DEFAULT_TIMEOUT_MILLIS, java.util.concurrent.TimeUnit.MILLISECONDS);
        outExecStartEnd[1] = System.nanoTime();
    } finally {
        ncMb.deregisterMessageFuture(responseFuture.getFutureId());
    }
    Throwable err = responseMsg.getError();
    if (err != null) {
        if (err instanceof Error) {
            throw (Error) err;
        } else if (err instanceof Exception) {
            throw (Exception) err;
        } else {
            throw new Exception(err.toString(), err);
        }
    }
    IStatementExecutor.ResultMetadata resultMetadata = responseMsg.getMetadata();
    if (delivery == IStatementExecutor.ResultDelivery.IMMEDIATE && !resultMetadata.getResultSets().isEmpty()) {
        for (Triple<JobId, ResultSetId, ARecordType> rsmd : resultMetadata.getResultSets()) {
            ResultReader resultReader = new ResultReader(getHyracksDataset(), rsmd.getLeft(), rsmd.getMiddle());
            ResultUtil.printResults(appCtx, resultReader, sessionOutput, stats, rsmd.getRight());
        }
    } else {
        sessionOutput.out().append(responseMsg.getResult());
    }
}
Also used : ResultReader(org.apache.asterix.app.result.ResultReader) ExecuteStatementResponseMessage(org.apache.asterix.app.message.ExecuteStatementResponseMessage) INCMessageBroker(org.apache.asterix.common.messaging.api.INCMessageBroker) ExecuteStatementRequestMessage(org.apache.asterix.app.message.ExecuteStatementRequestMessage) IStatementExecutor(org.apache.asterix.translator.IStatementExecutor) INCServiceContext(org.apache.hyracks.api.application.INCServiceContext) ResultSetId(org.apache.hyracks.api.dataset.ResultSetId) MessageFuture(org.apache.asterix.common.messaging.api.MessageFuture) ARecordType(org.apache.asterix.om.types.ARecordType) JobId(org.apache.hyracks.api.job.JobId)

Example 2 with INCServiceContext

use of org.apache.hyracks.api.application.INCServiceContext in project asterixdb by apache.

the class GenericAdapterFactory method createAdapter.

/**
     * Runs on each node controller (after serialization-deserialization)
     */
@Override
public synchronized IDataSourceAdapter createAdapter(IHyracksTaskContext ctx, int partition) throws HyracksDataException {
    INCServiceContext serviceCtx = ctx.getJobletContext().getServiceContext();
    INcApplicationContext appCtx = (INcApplicationContext) serviceCtx.getApplicationContext();
    try {
        restoreExternalObjects(serviceCtx, appCtx.getLibraryManager());
    } catch (Exception e) {
        LOGGER.log(Level.INFO, "Failure restoring external objects", e);
        throw HyracksDataException.create(e);
    }
    if (isFeed) {
        if (feedLogManager == null) {
            feedLogManager = FeedUtils.getFeedLogManager(ctx, partition, feedLogFileSplits);
        }
        feedLogManager.touch();
    }
    IDataFlowController controller = DataflowControllerProvider.getDataflowController(recordType, ctx, partition, dataSourceFactory, dataParserFactory, configuration, indexingOp, isFeed, feedLogManager);
    if (isFeed) {
        return new FeedAdapter((AbstractFeedDataFlowController) controller);
    } else {
        return new GenericAdapter(controller);
    }
}
Also used : INcApplicationContext(org.apache.asterix.common.api.INcApplicationContext) INCServiceContext(org.apache.hyracks.api.application.INCServiceContext) GenericAdapter(org.apache.asterix.external.dataset.adapter.GenericAdapter) FeedAdapter(org.apache.asterix.external.dataset.adapter.FeedAdapter) IDataFlowController(org.apache.asterix.external.api.IDataFlowController) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)

Example 3 with INCServiceContext

use of org.apache.hyracks.api.application.INCServiceContext in project asterixdb by apache.

the class TestUtils method create.

public static IHyracksTaskContext create(int frameSize) {
    try {
        IOManager ioManager = createIoManager();
        INCServiceContext serviceCtx = new TestNCServiceContext(ioManager, null);
        TestJobletContext jobletCtx = new TestJobletContext(frameSize, serviceCtx, new JobId(0));
        TaskAttemptId tid = new TaskAttemptId(new TaskId(new ActivityId(new OperatorDescriptorId(0), 0), 0), 0);
        IHyracksTaskContext taskCtx = new TestTaskContext(jobletCtx, tid);
        return taskCtx;
    } catch (HyracksException e) {
        throw new RuntimeException(e);
    }
}
Also used : OperatorDescriptorId(org.apache.hyracks.api.dataflow.OperatorDescriptorId) TaskId(org.apache.hyracks.api.dataflow.TaskId) IOManager(org.apache.hyracks.control.nc.io.IOManager) TaskAttemptId(org.apache.hyracks.api.dataflow.TaskAttemptId) ActivityId(org.apache.hyracks.api.dataflow.ActivityId) HyracksException(org.apache.hyracks.api.exceptions.HyracksException) INCServiceContext(org.apache.hyracks.api.application.INCServiceContext) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) JobId(org.apache.hyracks.api.job.JobId)

Aggregations

INCServiceContext (org.apache.hyracks.api.application.INCServiceContext)3 JobId (org.apache.hyracks.api.job.JobId)2 ExecuteStatementRequestMessage (org.apache.asterix.app.message.ExecuteStatementRequestMessage)1 ExecuteStatementResponseMessage (org.apache.asterix.app.message.ExecuteStatementResponseMessage)1 ResultReader (org.apache.asterix.app.result.ResultReader)1 INcApplicationContext (org.apache.asterix.common.api.INcApplicationContext)1 INCMessageBroker (org.apache.asterix.common.messaging.api.INCMessageBroker)1 MessageFuture (org.apache.asterix.common.messaging.api.MessageFuture)1 IDataFlowController (org.apache.asterix.external.api.IDataFlowController)1 FeedAdapter (org.apache.asterix.external.dataset.adapter.FeedAdapter)1 GenericAdapter (org.apache.asterix.external.dataset.adapter.GenericAdapter)1 ARecordType (org.apache.asterix.om.types.ARecordType)1 IStatementExecutor (org.apache.asterix.translator.IStatementExecutor)1 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)1 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)1 ActivityId (org.apache.hyracks.api.dataflow.ActivityId)1 OperatorDescriptorId (org.apache.hyracks.api.dataflow.OperatorDescriptorId)1 TaskAttemptId (org.apache.hyracks.api.dataflow.TaskAttemptId)1 TaskId (org.apache.hyracks.api.dataflow.TaskId)1 ResultSetId (org.apache.hyracks.api.dataset.ResultSetId)1