Search in sources :

Example 1 with IgniteRemoteStartSpecification

use of org.apache.ignite.internal.util.nodestart.IgniteRemoteStartSpecification 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)

Aggregations

InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)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 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 ClusterStartNodeResult (org.apache.ignite.cluster.ClusterStartNodeResult)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 StartNodeCallable (org.apache.ignite.internal.util.nodestart.StartNodeCallable)1