use of org.apache.hyracks.control.cc.cluster.INodeManager in project asterixdb by apache.
the class ClusterShutdownWork method doRun.
@Override
public void doRun() {
try {
if (ccs.getShutdownRun() != null) {
throw new IPCException("Shutdown already in progress");
}
INodeManager nodeManager = ccs.getNodeManager();
Collection<String> nodeIds = nodeManager.getAllNodeIds();
/**
* set up our listener for the node ACKs
*/
final ShutdownRun shutdownStatus = new ShutdownRun(nodeIds);
// set up the CC to listen for it
ccs.setShutdownRun(shutdownStatus);
/**
* Shutdown all the nodes...
*/
nodeManager.apply(this::shutdownNode);
ccs.getExecutor().execute(new Runnable() {
@Override
public void run() {
try {
/*
* wait for all our acks
*/
LOGGER.info("Waiting for NCs to shutdown...");
boolean cleanShutdown = shutdownStatus.waitForCompletion();
if (!cleanShutdown) {
/*
* best effort - just exit, user will have to kill misbehaving NCs
*/
LOGGER.severe("Clean shutdown of NCs timed out- giving up; unresponsive nodes: " + shutdownStatus.getRemainingNodes());
}
callback.setValue(cleanShutdown);
ccs.stop(terminateNCService);
LOGGER.info("JVM Exiting.. Bye!");
Runtime rt = Runtime.getRuntime();
rt.exit(cleanShutdown ? 0 : 1);
} catch (Exception e) {
callback.setException(e);
}
}
});
} catch (Exception e) {
callback.setException(e);
}
}
use of org.apache.hyracks.control.cc.cluster.INodeManager in project asterixdb by apache.
the class DistributeJobWork method doRun.
@Override
protected void doRun() throws Exception {
try {
final CCServiceContext ccServiceCtx = ccs.getContext();
ccs.getPreDistributedJobStore().checkForExistingDistributedJobDescriptor(jobId);
IActivityClusterGraphGeneratorFactory acggf = (IActivityClusterGraphGeneratorFactory) DeploymentUtils.deserialize(acggfBytes, null, ccServiceCtx);
IActivityClusterGraphGenerator acgg = acggf.createActivityClusterGraphGenerator(jobId, ccServiceCtx, EnumSet.noneOf(JobFlag.class));
ActivityClusterGraph acg = acgg.initialize();
ccs.getPreDistributedJobStore().addDistributedJobDescriptor(jobId, acg, acggf.getJobSpecification(), acgg.getConstraints());
ccServiceCtx.notifyJobCreation(jobId, acggf.getJobSpecification());
byte[] acgBytes = JavaSerializationUtils.serialize(acg);
INodeManager nodeManager = ccs.getNodeManager();
for (NodeControllerState node : nodeManager.getAllNodeControllerStates()) {
node.getNodeController().distributeJob(jobId, acgBytes);
}
callback.setValue(jobId);
} catch (Exception e) {
callback.setException(e);
}
}
use of org.apache.hyracks.control.cc.cluster.INodeManager in project asterixdb by apache.
the class GatherStateDumpsWork method doRun.
@Override
public void doRun() throws Exception {
ccs.addStateDumpRun(sdr.stateDumpId, sdr);
INodeManager nodeManager = ccs.getNodeManager();
Collection<String> nodeIds = new HashSet<>();
nodeIds.addAll(nodeManager.getAllNodeIds());
sdr.setNCs(nodeIds);
for (NodeControllerState ncs : nodeManager.getAllNodeControllerStates()) {
ncs.getNodeController().dumpState(sdr.stateDumpId);
}
}
use of org.apache.hyracks.control.cc.cluster.INodeManager in project asterixdb by apache.
the class GetThreadDumpWork method run.
@Override
public void run() {
if (nodeId == null) {
// null nodeId means the request is for the cluster controller
try {
callback.setValue(ThreadDumpHelper.takeDumpJSON(ManagementFactory.getThreadMXBean()));
} catch (Exception e) {
LOGGER.log(Level.WARNING, "Exception taking CC thread dump", e);
callback.setException(e);
}
} else {
INodeManager nodeManager = ccs.getNodeManager();
final NodeControllerState ncState = nodeManager.getNodeControllerState(nodeId);
if (ncState == null) {
// bad node id, reply with null immediately
callback.setValue(null);
} else {
ccs.addThreadDumpRun(run.getRequestId(), run);
try {
ncState.getNodeController().takeThreadDump(run.getRequestId());
} catch (Exception e) {
ccs.removeThreadDumpRun(run.getRequestId());
callback.setException(e);
}
final long requestTime = System.currentTimeMillis();
ccs.getExecutor().execute(() -> {
try {
final long queueTime = System.currentTimeMillis() - requestTime;
final long sleepTime = TimeUnit.SECONDS.toMillis(TIMEOUT_SECS) - queueTime;
if (sleepTime > 0) {
Thread.sleep(sleepTime);
}
if (ccs.removeThreadDumpRun(run.getRequestId()) != null) {
LOGGER.log(Level.WARNING, "Timed out thread dump request " + run.getRequestId() + " for node " + nodeId);
callback.setException(new TimeoutException("Thread dump request for node " + nodeId + " timed out after " + TIMEOUT_SECS + " seconds."));
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
});
}
}
}
use of org.apache.hyracks.control.cc.cluster.INodeManager in project asterixdb by apache.
the class JobManagerTest method mockNodeManager.
private INodeManager mockNodeManager() {
INodeManager nodeManager = mock(NodeManager.class);
NodeControllerState ncState = mock(NodeControllerState.class);
INodeController nodeController = mock(INodeController.class);
when(nodeManager.getNodeControllerState(any())).thenReturn(ncState);
when(ncState.getNodeController()).thenReturn(nodeController);
return nodeManager;
}
Aggregations