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);
}
}
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);
}
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);
}
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();
}
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);
}
}
Aggregations