Search in sources :

Example 16 with INodeManager

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);
    }
}
Also used : INodeManager(org.apache.hyracks.control.cc.cluster.INodeManager) ShutdownRun(org.apache.hyracks.control.common.shutdown.ShutdownRun) IPCException(org.apache.hyracks.ipc.exceptions.IPCException) IPCException(org.apache.hyracks.ipc.exceptions.IPCException)

Example 17 with INodeManager

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);
    }
}
Also used : INodeManager(org.apache.hyracks.control.cc.cluster.INodeManager) JobFlag(org.apache.hyracks.api.job.JobFlag) ActivityClusterGraph(org.apache.hyracks.api.job.ActivityClusterGraph) IActivityClusterGraphGeneratorFactory(org.apache.hyracks.api.job.IActivityClusterGraphGeneratorFactory) IActivityClusterGraphGenerator(org.apache.hyracks.api.job.IActivityClusterGraphGenerator) NodeControllerState(org.apache.hyracks.control.cc.NodeControllerState) CCServiceContext(org.apache.hyracks.control.cc.application.CCServiceContext)

Example 18 with INodeManager

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);
    }
}
Also used : INodeManager(org.apache.hyracks.control.cc.cluster.INodeManager) NodeControllerState(org.apache.hyracks.control.cc.NodeControllerState) HashSet(java.util.HashSet)

Example 19 with INodeManager

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();
                }
            });
        }
    }
}
Also used : INodeManager(org.apache.hyracks.control.cc.cluster.INodeManager) NodeControllerState(org.apache.hyracks.control.cc.NodeControllerState) TimeoutException(java.util.concurrent.TimeoutException) TimeoutException(java.util.concurrent.TimeoutException)

Example 20 with INodeManager

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;
}
Also used : INodeManager(org.apache.hyracks.control.cc.cluster.INodeManager) INodeController(org.apache.hyracks.control.common.base.INodeController) NodeControllerState(org.apache.hyracks.control.cc.NodeControllerState)

Aggregations

INodeManager (org.apache.hyracks.control.cc.cluster.INodeManager)21 NodeControllerState (org.apache.hyracks.control.cc.NodeControllerState)15 HyracksException (org.apache.hyracks.api.exceptions.HyracksException)6 HashMap (java.util.HashMap)4 JobId (org.apache.hyracks.api.job.JobId)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Map (java.util.Map)3 DeploymentId (org.apache.hyracks.api.deployment.DeploymentId)3 ActivityClusterGraph (org.apache.hyracks.api.job.ActivityClusterGraph)3 INodeController (org.apache.hyracks.control.common.base.INodeController)3 NetworkAddress (org.apache.hyracks.api.comm.NetworkAddress)2 LValueConstraintExpression (org.apache.hyracks.api.constraints.expressions.LValueConstraintExpression)2 ActivityId (org.apache.hyracks.api.dataflow.ActivityId)2 ConnectorDescriptorId (org.apache.hyracks.api.dataflow.ConnectorDescriptorId)2 TaskAttemptId (org.apache.hyracks.api.dataflow.TaskAttemptId)2 TaskId (org.apache.hyracks.api.dataflow.TaskId)2 IConnectorPolicy (org.apache.hyracks.api.dataflow.connectors.IConnectorPolicy)2 ClusterControllerService (org.apache.hyracks.control.cc.ClusterControllerService)2