Search in sources :

Example 1 with ICcApplicationContext

use of org.apache.asterix.common.dataflow.ICcApplicationContext in project asterixdb by apache.

the class SocketServerInputStreamFactory method configure.

@Override
public void configure(IServiceContext serviceCtx, Map<String, String> configuration) throws AsterixException, CompilationException {
    try {
        sockets = new ArrayList<>();
        String modeValue = configuration.get(ExternalDataConstants.KEY_MODE);
        if (modeValue != null) {
            mode = Mode.valueOf(modeValue.trim().toUpperCase());
        }
        String socketsValue = configuration.get(ExternalDataConstants.KEY_SOCKETS);
        if (socketsValue == null) {
            throw new CompilationException(ErrorCode.FEED_METADATA_SOCKET_ADAPTOR_SOCKET_NOT_PROPERLY_CONFIGURED);
        }
        Map<InetAddress, Set<String>> ncMap;
        ncMap = RuntimeUtils.getNodeControllerMap((ICcApplicationContext) serviceCtx.getApplicationContext());
        List<String> ncs = RuntimeUtils.getAllNodeControllers((ICcApplicationContext) serviceCtx.getApplicationContext());
        String[] socketsArray = socketsValue.split(",");
        Random random = new Random();
        for (String socket : socketsArray) {
            String[] socketTokens = socket.split(":");
            String host = socketTokens[0].trim();
            int port = Integer.parseInt(socketTokens[1].trim());
            Pair<String, Integer> p = null;
            switch(mode) {
                case IP:
                    Set<String> ncsOnIp = ncMap.get(InetAddress.getByName(host));
                    if ((ncsOnIp == null) || ncsOnIp.isEmpty()) {
                        throw new CompilationException(ErrorCode.FEED_METADATA_SOCKET_ADAPTOR_SOCKET_INVALID_HOST_NC, "host", host, StringUtils.join(ncMap.keySet(), ", "));
                    }
                    String[] ncArray = ncsOnIp.toArray(new String[] {});
                    String nc = ncArray[random.nextInt(ncArray.length)];
                    p = new Pair<>(nc, port);
                    break;
                case NC:
                    p = new Pair<>(host, port);
                    if (!ncs.contains(host)) {
                        throw new CompilationException(ErrorCode.FEED_METADATA_SOCKET_ADAPTOR_SOCKET_INVALID_HOST_NC, "NC", host, StringUtils.join(ncs, ", "));
                    }
                    break;
            }
            sockets.add(p);
        }
    } catch (CompilationException e) {
        throw e;
    } catch (HyracksDataException | UnknownHostException e) {
        throw new AsterixException(e);
    } catch (Exception e) {
        throw new CompilationException(ErrorCode.FEED_METADATA_SOCKET_ADAPTOR_SOCKET_NOT_PROPERLY_CONFIGURED);
    }
}
Also used : CompilationException(org.apache.asterix.common.exceptions.CompilationException) ICcApplicationContext(org.apache.asterix.common.dataflow.ICcApplicationContext) Set(java.util.Set) UnknownHostException(java.net.UnknownHostException) AlgebricksAbsolutePartitionConstraint(org.apache.hyracks.algebricks.common.constraints.AlgebricksAbsolutePartitionConstraint) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) AsterixException(org.apache.asterix.common.exceptions.AsterixException) CompilationException(org.apache.asterix.common.exceptions.CompilationException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) AsterixException(org.apache.asterix.common.exceptions.AsterixException) Random(java.util.Random) InetAddress(java.net.InetAddress)

Example 2 with ICcApplicationContext

use of org.apache.asterix.common.dataflow.ICcApplicationContext in project asterixdb by apache.

the class QueryLogicalExpressionJobGen method createScalarFunctionEvaluatorFactory.

private IScalarEvaluatorFactory createScalarFunctionEvaluatorFactory(AbstractFunctionCallExpression expr, IVariableTypeEnvironment env, IOperatorSchema[] inputSchemas, JobGenContext context) throws AlgebricksException {
    IScalarEvaluatorFactory[] args = codegenArguments(expr, env, inputSchemas, context);
    IFunctionDescriptor fd = null;
    if (!(expr.getFunctionInfo() instanceof IExternalFunctionInfo)) {
        IDataFormat format = FormatUtils.getDefaultFormat();
        fd = format.resolveFunction(expr, env);
    } else {
        ICcApplicationContext appCtx = (ICcApplicationContext) context.getAppContext();
        fd = ExternalFunctionDescriptorProvider.getExternalFunctionDescriptor((IExternalFunctionInfo) expr.getFunctionInfo(), appCtx);
    }
    return fd.createEvaluatorFactory(args);
}
Also used : IFunctionDescriptor(org.apache.asterix.om.functions.IFunctionDescriptor) ICcApplicationContext(org.apache.asterix.common.dataflow.ICcApplicationContext) IDataFormat(org.apache.asterix.formats.base.IDataFormat) IExternalFunctionInfo(org.apache.asterix.om.functions.IExternalFunctionInfo) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)

Example 3 with ICcApplicationContext

use of org.apache.asterix.common.dataflow.ICcApplicationContext in project asterixdb by apache.

the class CCMessageBroker method receivedMessage.

@Override
public void receivedMessage(IMessage message, String nodeId) throws Exception {
    ICcAddressedMessage msg = (ICcAddressedMessage) message;
    if (LOGGER.isLoggable(Level.INFO)) {
        LOGGER.info("Received message: " + msg);
    }
    ICcApplicationContext appCtx = (ICcApplicationContext) ccs.getApplicationContext();
    msg.handle(appCtx);
}
Also used : ICcApplicationContext(org.apache.asterix.common.dataflow.ICcApplicationContext) ICcAddressedMessage(org.apache.asterix.common.messaging.api.ICcAddressedMessage)

Example 4 with ICcApplicationContext

use of org.apache.asterix.common.dataflow.ICcApplicationContext in project asterixdb by apache.

the class AutoFaultToleranceStrategy method prepareFailbackPlan.

private synchronized void prepareFailbackPlan(String failingBackNodeId) {
    NodeFailbackPlan plan = NodeFailbackPlan.createPlan(failingBackNodeId);
    pendingProcessingFailbackPlans.add(plan);
    planId2FailbackPlanMap.put(plan.getPlanId(), plan);
    //get all partitions this node requires to resync
    ICcApplicationContext appCtx = (ICcApplicationContext) serviceCtx.getApplicationContext();
    ReplicationProperties replicationProperties = appCtx.getReplicationProperties();
    Set<String> nodeReplicas = replicationProperties.getNodeReplicasIds(failingBackNodeId);
    clusterManager.getClusterPartitons();
    for (String replicaId : nodeReplicas) {
        ClusterPartition[] nodePartitions = clusterManager.getNodePartitions(replicaId);
        for (ClusterPartition partition : nodePartitions) {
            plan.addParticipant(partition.getActiveNodeId());
            /*
                 * if the partition original node is the returning node,
                 * add it to the list of the partitions which will be failed back
                 */
            if (partition.getNodeId().equals(failingBackNodeId)) {
                plan.addPartitionToFailback(partition.getPartitionId(), partition.getActiveNodeId());
            }
        }
    }
    if (LOGGER.isLoggable(Level.INFO)) {
        LOGGER.info("Prepared Failback plan: " + plan.toString());
    }
    processPendingFailbackPlans();
}
Also used : ReplicationProperties(org.apache.asterix.common.config.ReplicationProperties) ICcApplicationContext(org.apache.asterix.common.dataflow.ICcApplicationContext) ClusterPartition(org.apache.asterix.common.cluster.ClusterPartition)

Example 5 with ICcApplicationContext

use of org.apache.asterix.common.dataflow.ICcApplicationContext in project asterixdb by apache.

the class AutoFaultToleranceStrategy method requestMetadataNodeTakeover.

private synchronized void requestMetadataNodeTakeover() {
    //need a new node to takeover metadata node
    ICcApplicationContext appCtx = (ICcApplicationContext) serviceCtx.getApplicationContext();
    ClusterPartition metadataPartiton = appCtx.getMetadataProperties().getMetadataPartition();
    //request the metadataPartition node to register itself as the metadata node
    TakeoverMetadataNodeRequestMessage takeoverRequest = new TakeoverMetadataNodeRequestMessage();
    try {
        messageBroker.sendApplicationMessageToNC(takeoverRequest, metadataPartiton.getActiveNodeId());
        // Since the metadata node will be changed, we need to rebind the proxy object
        MetadataManager.INSTANCE.rebindMetadataNode();
    } catch (Exception e) {
        /*
             * if we fail to send the request, it means the NC we tried to send the request to
             * has failed. When the failure notification arrives, a new NC will be assigned to
             * the metadata partition and a new metadata node takeover request will be sent to it.
             */
        LOGGER.log(Level.WARNING, "Failed to send metadata node takeover request to: " + metadataPartiton.getActiveNodeId(), e);
    }
}
Also used : ICcApplicationContext(org.apache.asterix.common.dataflow.ICcApplicationContext) TakeoverMetadataNodeRequestMessage(org.apache.asterix.app.replication.message.TakeoverMetadataNodeRequestMessage) RuntimeDataException(org.apache.asterix.common.exceptions.RuntimeDataException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) ClusterPartition(org.apache.asterix.common.cluster.ClusterPartition)

Aggregations

ICcApplicationContext (org.apache.asterix.common.dataflow.ICcApplicationContext)10 ClusterPartition (org.apache.asterix.common.cluster.ClusterPartition)4 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)4 HashMap (java.util.HashMap)3 Set (java.util.Set)3 RuntimeDataException (org.apache.asterix.common.exceptions.RuntimeDataException)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 RemoteRecoveryTask (org.apache.asterix.app.nc.task.RemoteRecoveryTask)2 ReplicationProperties (org.apache.asterix.common.config.ReplicationProperties)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 PrintWriter (java.io.PrintWriter)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 Arrays (java.util.Arrays)1 LinkedList (java.util.LinkedList)1