Search in sources :

Example 1 with ClusterStartNodeResult

use of org.apache.ignite.cluster.ClusterStartNodeResult in project ignite by apache.

the class IgniteClusterImpl method startNodesAsync0.

/**
     * @param hosts Startup parameters.
     * @param dflts Default values.
     * @param restart Whether to stop existing nodes
     * @param timeout Connection timeout in milliseconds.
     * @param maxConn Number of parallel SSH connections to one host.
     * @return Future with results.
     * @see IgniteCluster#startNodes(java.util.Collection, java.util.Map, boolean, int, int)
     */
IgniteInternalFuture<Collection<ClusterStartNodeResult>> startNodesAsync0(Collection<Map<String, Object>> hosts, @Nullable Map<String, Object> dflts, boolean restart, int timeout, int maxConn) {
    A.notNull(hosts, "hosts");
    guard();
    try {
        IgniteSshHelper sshHelper = IgniteComponentType.SSH.create(false);
        Map<String, Collection<IgniteRemoteStartSpecification>> specsMap = specifications(hosts, dflts);
        Map<String, ConcurrentLinkedQueue<StartNodeCallable>> runMap = new HashMap<>();
        int nodeCallCnt = 0;
        for (String host : specsMap.keySet()) {
            InetAddress addr;
            try {
                addr = InetAddress.getByName(host);
            } catch (UnknownHostException e) {
                throw new IgniteCheckedException("Invalid host name: " + host, e);
            }
            Collection<? extends ClusterNode> neighbors = null;
            if (addr.isLoopbackAddress())
                neighbors = neighbors();
            else {
                for (Collection<ClusterNode> p : U.neighborhood(nodes()).values()) {
                    ClusterNode node = F.first(p);
                    if (node.<String>attribute(ATTR_IPS).contains(addr.getHostAddress())) {
                        neighbors = p;
                        break;
                    }
                }
            }
            int startIdx = 1;
            if (neighbors != null) {
                if (restart && !neighbors.isEmpty()) {
                    try {
                        ctx.grid().compute(forNodes(neighbors)).execute(IgniteKillTask.class, false);
                    } catch (ClusterGroupEmptyException ignored) {
                    // No-op, nothing to restart.
                    }
                } else
                    startIdx = neighbors.size() + 1;
            }
            ConcurrentLinkedQueue<StartNodeCallable> nodeRuns = new ConcurrentLinkedQueue<>();
            runMap.put(host, nodeRuns);
            for (IgniteRemoteStartSpecification spec : specsMap.get(host)) {
                assert spec.host().equals(host);
                for (int i = startIdx; i <= spec.nodes(); i++) {
                    nodeRuns.add(sshHelper.nodeStartCallable(spec, timeout));
                    nodeCallCnt++;
                }
            }
        }
        // If there is nothing to start, return finished future with empty result.
        if (nodeCallCnt == 0)
            return new GridFinishedFuture<Collection<ClusterStartNodeResult>>(Collections.<ClusterStartNodeResult>emptyList());
        // Exceeding max line width for readability.
        GridCompoundFuture<ClusterStartNodeResult, Collection<ClusterStartNodeResult>> fut = new GridCompoundFuture<>(CU.<ClusterStartNodeResult>objectsReducer());
        AtomicInteger cnt = new AtomicInteger(nodeCallCnt);
        // Limit maximum simultaneous connection number per host.
        for (ConcurrentLinkedQueue<StartNodeCallable> queue : runMap.values()) {
            for (int i = 0; i < maxConn; i++) {
                if (!runNextNodeCallable(queue, fut, cnt))
                    break;
            }
        }
        return fut;
    } catch (IgniteCheckedException e) {
        return new GridFinishedFuture<>(e);
    } finally {
        unguard();
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteSshHelper(org.apache.ignite.internal.util.nodestart.IgniteSshHelper) UnknownHostException(java.net.UnknownHostException) HashMap(java.util.HashMap) ClusterGroupEmptyException(org.apache.ignite.cluster.ClusterGroupEmptyException) ClusterStartNodeResult(org.apache.ignite.cluster.ClusterStartNodeResult) GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteRemoteStartSpecification(org.apache.ignite.internal.util.nodestart.IgniteRemoteStartSpecification) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Collection(java.util.Collection) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) InetAddress(java.net.InetAddress) StartNodeCallable(org.apache.ignite.internal.util.nodestart.StartNodeCallable)

Example 2 with ClusterStartNodeResult

use of org.apache.ignite.cluster.ClusterStartNodeResult in project ignite by apache.

the class IgniteClusterImpl method runNextNodeCallable.

/**
     * Runs next callable from host node start queue.
     *
     * @param queue Queue of tasks to poll from.
     * @param comp Compound future that comprise all started node tasks.
     * @param cnt Atomic counter to check if all futures are added to compound future.
     * @return {@code True} if task was started, {@code false} if queue was empty.
     */
private boolean runNextNodeCallable(final ConcurrentLinkedQueue<StartNodeCallable> queue, final GridCompoundFuture<ClusterStartNodeResult, Collection<ClusterStartNodeResult>> comp, final AtomicInteger cnt) {
    StartNodeCallable call = queue.poll();
    if (call == null)
        return false;
    IgniteInternalFuture<ClusterStartNodeResult> fut = ctx.closure().callLocalSafe(call, true);
    comp.add(fut);
    if (cnt.decrementAndGet() == 0)
        comp.markInitialized();
    fut.listen(new CI1<IgniteInternalFuture<ClusterStartNodeResult>>() {

        @Override
        public void apply(IgniteInternalFuture<ClusterStartNodeResult> f) {
            runNextNodeCallable(queue, comp, cnt);
        }
    });
    return true;
}
Also used : ClusterStartNodeResult(org.apache.ignite.cluster.ClusterStartNodeResult) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) StartNodeCallable(org.apache.ignite.internal.util.nodestart.StartNodeCallable)

Example 3 with ClusterStartNodeResult

use of org.apache.ignite.cluster.ClusterStartNodeResult in project ignite by apache.

the class IgniteProjectionStartStopRestartSelfTest method testStartThreeNodes.

/**
     * @throws Exception If failed.
     */
public void testStartThreeNodes() throws Exception {
    joinedLatch = new CountDownLatch(3);
    Collection<ClusterStartNodeResult> res = startNodes(ignite.cluster(), maps(Collections.singleton(HOST), SSH_UNAME, pwd, key, 3, U.getIgniteHome(), CFG_NO_ATTR, null), null, false, DFLT_TIMEOUT, 1);
    assert res.size() == 3;
    F.forEach(res, new CI1<ClusterStartNodeResult>() {

        @Override
        public void apply(ClusterStartNodeResult t) {
            assert t.getHostName().equals(HOST);
            if (!t.isSuccess())
                throw new IgniteException(t.getError());
        }
    });
    assert joinedLatch.await(WAIT_TIMEOUT, MILLISECONDS);
    assert joinedCnt.get() == 3;
    assert leftCnt.get() == 0;
    assert ignite.cluster().nodes().size() == 3;
}
Also used : IgniteException(org.apache.ignite.IgniteException) CountDownLatch(java.util.concurrent.CountDownLatch) ClusterStartNodeResult(org.apache.ignite.cluster.ClusterStartNodeResult)

Example 4 with ClusterStartNodeResult

use of org.apache.ignite.cluster.ClusterStartNodeResult in project ignite by apache.

the class IgniteProjectionStartStopRestartSelfTest method testStartThreeNodesAndTryToStartOneNode.

/**
     * @throws Exception If failed.
     */
public void testStartThreeNodesAndTryToStartOneNode() throws Exception {
    joinedLatch = new CountDownLatch(3);
    Collection<ClusterStartNodeResult> res = startNodes(ignite.cluster(), maps(Collections.singleton(HOST), SSH_UNAME, pwd, key, 3, U.getIgniteHome(), CFG_NO_ATTR, null), null, false, 0, 16);
    assert res.size() == 3;
    F.forEach(res, new CI1<ClusterStartNodeResult>() {

        @Override
        public void apply(ClusterStartNodeResult t) {
            assert t.getHostName().equals(HOST);
            if (!t.isSuccess())
                throw new IgniteException(t.getError());
        }
    });
    assert joinedLatch.await(WAIT_TIMEOUT, MILLISECONDS);
    assert joinedCnt.get() == 3;
    assert leftCnt.get() == 0;
    assert ignite.cluster().nodes().size() == 3;
    res = startNodes(ignite.cluster(), maps(Collections.singleton(HOST), SSH_UNAME, pwd, key, 1, U.getIgniteHome(), CFG_NO_ATTR, null), null, false, 0, 16);
    assert res.isEmpty();
    assert joinedCnt.get() == 3;
    assert leftCnt.get() == 0;
    assert ignite.cluster().nodes().size() == 3;
}
Also used : IgniteException(org.apache.ignite.IgniteException) CountDownLatch(java.util.concurrent.CountDownLatch) ClusterStartNodeResult(org.apache.ignite.cluster.ClusterStartNodeResult)

Example 5 with ClusterStartNodeResult

use of org.apache.ignite.cluster.ClusterStartNodeResult in project ignite by apache.

the class IgniteProjectionStartStopRestartSelfTest method testRestartNodesByIds.

/**
     * @throws Exception If failed.
     */
public void testRestartNodesByIds() throws Exception {
    joinedLatch = new CountDownLatch(3);
    Collection<ClusterStartNodeResult> res = startNodes(ignite.cluster(), maps(Collections.singleton(HOST), SSH_UNAME, pwd, key, 3, U.getIgniteHome(), CFG_NO_ATTR, null), null, false, 0, 16);
    assert res.size() == 3;
    F.forEach(res, new CI1<ClusterStartNodeResult>() {

        @Override
        public void apply(ClusterStartNodeResult t) {
            assert t.getHostName().equals(HOST);
            if (!t.isSuccess())
                throw new IgniteException(t.getError());
        }
    });
    assert joinedLatch.await(WAIT_TIMEOUT, MILLISECONDS);
    assert ignite.cluster().nodes().size() == 3;
    joinedLatch = new CountDownLatch(2);
    leftLatch = new CountDownLatch(2);
    Iterator<ClusterNode> it = ignite.cluster().nodes().iterator();
    ignite.cluster().restartNodes(F.asList(it.next().id(), it.next().id()));
    assert joinedLatch.await(WAIT_TIMEOUT, MILLISECONDS);
    assert leftLatch.await(WAIT_TIMEOUT, MILLISECONDS);
    assert ignite.cluster().nodes().size() == 3;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteException(org.apache.ignite.IgniteException) CountDownLatch(java.util.concurrent.CountDownLatch) ClusterStartNodeResult(org.apache.ignite.cluster.ClusterStartNodeResult)

Aggregations

ClusterStartNodeResult (org.apache.ignite.cluster.ClusterStartNodeResult)20 CountDownLatch (java.util.concurrent.CountDownLatch)18 IgniteException (org.apache.ignite.IgniteException)18 ClusterNode (org.apache.ignite.cluster.ClusterNode)7 UUID (java.util.UUID)3 StartNodeCallable (org.apache.ignite.internal.util.nodestart.StartNodeCallable)2 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 ClusterGroupEmptyException (org.apache.ignite.cluster.ClusterGroupEmptyException)1 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)1 GridCompoundFuture (org.apache.ignite.internal.util.future.GridCompoundFuture)1 IgniteRemoteStartSpecification (org.apache.ignite.internal.util.nodestart.IgniteRemoteStartSpecification)1 IgniteSshHelper (org.apache.ignite.internal.util.nodestart.IgniteSshHelper)1