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