use of org.apache.ignite.internal.IgniteInterruptedCheckedException in project ignite by apache.
the class StartNodeCallableImpl method call.
/**
* {@inheritDoc}
*/
@Override
public ClusterStartNodeResult call() {
JSch ssh = new JSch();
Session ses = null;
try {
if (spec.key() != null)
ssh.addIdentity(spec.key().getAbsolutePath());
ses = ssh.getSession(spec.username(), spec.host(), spec.port());
if (spec.password() != null)
ses.setPassword(spec.password());
ses.setConfig("StrictHostKeyChecking", "no");
ses.connect(timeout);
boolean win = isWindows(ses);
info("Windows mode: " + win, spec.logger(), log);
char separator = win ? '\\' : '/';
spec.fixPaths(separator);
String igniteHome = spec.igniteHome();
if (igniteHome == null)
igniteHome = win ? DFLT_IGNITE_HOME_WIN : DFLT_IGNITE_HOME_LINUX;
String script = spec.script();
if (script == null)
script = win ? DFLT_SCRIPT_WIN : DFLT_SCRIPT_LINUX;
String cfg = spec.configuration();
if (cfg == null)
cfg = "";
String id = FILE_NAME_DATE_FORMAT.format(new Date()) + '-' + UUID.randomUUID().toString().substring(0, 8);
String scriptOutputFileName = id + ".log";
int spaceIdx = script.indexOf(' ');
String scriptPath = spaceIdx > -1 ? script.substring(0, spaceIdx) : script;
String scriptArgs = spaceIdx > -1 ? script.substring(spaceIdx + 1) : "";
String rmtLogArgs = buildRemoteLogArguments(spec.username(), spec.host());
String scriptOutputDir;
String dfltTmpDir = igniteHome + separator + "work" + separator + "log";
if (win) {
String tmpDir = env(ses, "%TMPDIR%", dfltTmpDir, WINDOWS_ENCODING);
if ("%TMPDIR%".equals(tmpDir))
tmpDir = dfltTmpDir;
scriptOutputDir = tmpDir + "\\ignite-startNodes";
} else {
// Assume Unix.
String logDir = env(ses, "$TMPDIR", dfltTmpDir);
scriptOutputDir = logDir + "/ignite-startNodes";
}
shell(ses, "mkdir " + scriptOutputDir);
String scriptOutputPath = scriptOutputDir + separator + scriptOutputFileName;
String findSuccess;
if (win) {
String scriptFileName = scriptOutputDir + '\\' + id + ".bat";
String createScript = new SB().a("echo \"").a(igniteHome).a('\\').a(scriptPath).a("\" ").a(scriptArgs).a(!cfg.isEmpty() ? " \"" : "").a(cfg).a(!cfg.isEmpty() ? "\"" : "").a(rmtLogArgs).a(" ^> ").a(scriptOutputPath).a(" ^2^>^&^1").a(" > ").a(scriptFileName).toString();
info("Create script with command: " + createScript, spec.logger(), log);
shell(ses, createScript);
try {
String createTask = new SB().a("schtasks /create /f /sc onstart").a(" /ru ").a(spec.username()).a(" /rp ").a(spec.password()).a(" /tn ").a(id).a(" /np /tr \"").a(scriptFileName).a('\"').toString();
info("Create task with command: " + createTask, spec.logger(), log);
shell(ses, createTask);
String runTask = "schtasks /run /i /tn " + id;
info("Run task with command: " + runTask, spec.logger(), log);
shell(ses, runTask);
} finally {
String deleteTask = "schtasks /delete /f /tn " + id;
info("Delete task with command: " + deleteTask, spec.logger(), log);
shell(ses, deleteTask);
}
findSuccess = "find \"" + SUCCESSFUL_START_MSG + "\" " + scriptOutputPath;
} else {
// Mac os don't support ~ in double quotes. Trying get home path from remote system.
if (igniteHome.startsWith("~")) {
String homeDir = env(ses, "$HOME", "~");
igniteHome = igniteHome.replaceFirst("~", homeDir);
}
String startNodeCmd = new SB().a("nohup ").a("\"").a(igniteHome).a('/').a(scriptPath).a("\"").a(" ").a(scriptArgs).a(!cfg.isEmpty() ? " \"" : "").a(cfg).a(!cfg.isEmpty() ? "\"" : "").a(rmtLogArgs).a(" > ").a(scriptOutputDir).a('/').a(scriptOutputFileName).a(" 2>& 1 &").toString();
info("Starting remote node with SSH command: " + startNodeCmd, spec.logger(), log);
shell(ses, startNodeCmd);
findSuccess = "grep \"" + SUCCESSFUL_START_MSG + "\" " + scriptOutputPath;
}
for (int i = 0; i < NODE_START_CHECK_LIMIT; ++i) {
Thread.sleep(NODE_START_CHECK_PERIOD);
String res = exec(ses, findSuccess, win ? WINDOWS_ENCODING : null);
info("Find result: " + res, spec.logger(), log);
if (res != null && res.contains(SUCCESSFUL_START_MSG))
return new ClusterStartNodeResultImpl(spec.host(), true, null);
}
return new ClusterStartNodeResultImpl(spec.host(), false, "Remote node could not start. " + "See log for details: " + scriptOutputPath);
} catch (IgniteInterruptedCheckedException e) {
return new ClusterStartNodeResultImpl(spec.host(), false, e.getMessage());
} catch (Exception e) {
return new ClusterStartNodeResultImpl(spec.host(), false, X.getFullStackTrace(e));
} finally {
if (ses != null && ses.isConnected())
ses.disconnect();
}
}
use of org.apache.ignite.internal.IgniteInterruptedCheckedException in project ignite by apache.
the class GridCachePartitionedQueueEntryMoveSelfTest method testQueue.
/**
* @throws Exception If failed.
*/
public void testQueue() throws Exception {
final String queueName = "qq";
System.out.println(U.filler(20, '\n'));
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
IgniteInternalFuture<?> fut1 = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws IgniteInterruptedCheckedException {
Ignite ignite = grid(0);
IgniteQueue<Integer> queue = ignite.queue(queueName, QUEUE_CAP, config(true));
for (int i = 0; i < QUEUE_CAP * 2; i++) {
if (i == QUEUE_CAP) {
latch1.countDown();
U.await(latch2);
}
try {
info(">>> Putting value: " + i);
queue.put(i);
info(">>> Value is in queue: " + i);
} catch (Error | RuntimeException e) {
error("Failed to put value: " + i, e);
throw e;
}
}
return null;
}
});
latch1.await();
startAdditionalNodes(BACKUP_CNT + 2, queueName);
System.out.println(U.filler(20, '\n'));
latch2.countDown();
IgniteInternalFuture<?> fut2 = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws IgniteCheckedException {
Ignite ignite = grid(GRID_CNT);
IgniteQueue<Integer> queue = ignite.queue(queueName, QUEUE_CAP, config(true));
int cnt = 0;
do {
try {
Integer i = queue.poll();
if (i != null) {
info(">>> Polled value: " + cnt);
cnt++;
} else {
info(">>> Waiting for value...");
U.sleep(2000);
}
} catch (Error | RuntimeException e) {
error("Failed to poll value.", e);
throw e;
}
} while (cnt < QUEUE_CAP * 2);
return null;
}
});
fut1.get();
fut2.get();
}
use of org.apache.ignite.internal.IgniteInterruptedCheckedException in project ignite by apache.
the class GridIoManagerBenchmark method sendMessages.
/**
* @param g Kernal.
* @param threads Number of send threads.
* @param duration Test duration.
* @param outputFilename Output file name.
*/
@SuppressWarnings("deprecation")
private static void sendMessages(IgniteKernal g, int threads, int duration, @Nullable final String outputFilename) {
X.println(">>> Sending messages.");
g.context().io().addMessageListener(TEST_TOPIC, new SenderMessageListener());
Thread collector = startDaemon(new Runnable() {
@Override
public void run() {
final long initTs = System.currentTimeMillis();
long ts = initTs;
long queries = msgCntr.sum();
GridCumulativeAverage qpsAvg = new GridCumulativeAverage();
try {
while (!Thread.currentThread().isInterrupted()) {
U.sleep(10000);
long newTs = System.currentTimeMillis();
long newQueries = msgCntr.sum();
long executed = newQueries - queries;
long time = newTs - ts;
long qps = executed * 1000 / time;
boolean recordAvg = ts - initTs > WARM_UP_DUR;
if (recordAvg)
qpsAvg.update(qps);
X.println("Communication benchmark [qps=" + qps + (recordAvg ? ", qpsAvg=" + qpsAvg : "") + ", executed=" + executed + ", time=" + time + ']');
ts = newTs;
queries = newQueries;
}
} catch (IgniteInterruptedCheckedException ignored) {
// No-op.
}
X.println("Average QPS: " + qpsAvg);
if (outputFilename != null) {
try {
X.println("Saving results to output file: " + outputFilename);
appendLineToFile(outputFilename, "%s,%d", GridLoadTestUtils.DATE_TIME_FORMAT.format(new Date()), qpsAvg.get());
} catch (IOException e) {
X.println("Failed to record results to a file: " + e.getMessage());
}
}
}
});
Collection<SendThread> sndThreads = new ArrayList<>(threads);
for (int i = 0; i < threads; i++) {
SendThread t = new SendThread(g);
sndThreads.add(t);
t.start();
}
try {
U.sleep(duration > 0 ? duration * 1000 + WARM_UP_DUR : Long.MAX_VALUE);
} catch (IgniteInterruptedCheckedException ignored) {
// No-op.
}
collector.interrupt();
for (SendThread t : sndThreads) t.interrupt();
}
use of org.apache.ignite.internal.IgniteInterruptedCheckedException in project ignite by apache.
the class GridContinuousOperationsLoadTest method main.
/**
* Main method.
*
* @param args Command line arguments.
* @throws Exception If error occurs.
*/
public static void main(String[] args) throws Exception {
final String cfgPath = args.length > 0 ? args[0] : "examples/config/example-cache.xml";
final String cacheName = getStringProperty(CACHE_NAME, "partitioned");
final Integer valSize = getIntProperty(VALUE_SIZE, 1024);
final Integer threadsCnt = getIntProperty(THREADS_CNT, 8);
final Integer testDurSec = getIntProperty(TEST_DUR_SEC, 180);
final Integer filterSkipProb = getIntProperty("FILTER_SKIP_PROBABILITY", 10, new C1<Integer, String>() {
@Nullable
@Override
public String apply(Integer val) {
if (val < 0 || val > 100)
return "The value should be between 1 and 100.";
return null;
}
});
final boolean useQry = getBooleanProperty("IGNITE_USE_QUERIES", true);
final int bufSize = getIntProperty("IGNITE_BUFFER_SIZE", 1);
final long timeInterval = getLongProperty("IGNITE_TIME_INTERVAL", 0);
final int parallelCnt = getIntProperty("IGNITE_PARALLEL_COUNT", 8);
final int keyRange = getIntProperty("IGNITE_KEY_RANGE", 100000);
final long updSleepMs = getLongProperty("IGNITE_UPDATE_SLEEP_MS", 0);
final long filterSleepMs = getLongProperty("IGNITE_FILTER_SLEEP_MS", 0);
final long cbSleepMs = getLongProperty("IGNITE_CALLBACK_SLEEP_MS", 0);
X.println("The test will start with the following parameters:");
dumpProperties(System.out);
try (Ignite ignite = Ignition.start(cfgPath)) {
final IgniteCache<Object, Object> cache = ignite.cache(cacheName);
if (cache == null)
throw new IgniteCheckedException("Cache is not configured: " + cacheName);
// Continuous query manager, used to monitor queue size.
final CacheContinuousQueryManager contQryMgr = ((IgniteKernal) ignite).context().cache().cache(cacheName).context().continuousQueries();
if (contQryMgr == null)
throw new IgniteCheckedException("Could not access CacheContinuousQueryManager");
// Stop flag.
final AtomicBoolean stop = new AtomicBoolean();
// Callback counter.
final AtomicLong cbCntr = new AtomicLong();
// Update counter.
final AtomicLong updCntr = new AtomicLong();
for (int i = 0; i < parallelCnt; i++) {
if (useQry) {
ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
qry.setLocalListener(new CacheEntryUpdatedListener<Object, Object>() {
@Override
public void onUpdated(Iterable<CacheEntryEvent<?, ?>> evts) {
if (cbSleepMs > 0) {
try {
U.sleep(cbSleepMs);
} catch (IgniteInterruptedCheckedException e) {
throw new IgniteException(e);
}
}
for (CacheEntryEvent<?, ?> ignored : evts) cbCntr.incrementAndGet();
}
});
qry.setRemoteFilter(new CacheEntryEventSerializableFilter<Object, Object>() {
@Override
public boolean evaluate(CacheEntryEvent<?, ?> evt) {
if (filterSleepMs > 0) {
try {
U.sleep(filterSleepMs);
} catch (IgniteInterruptedCheckedException e) {
throw new IgniteException(e);
}
}
return Math.random() * 100 >= filterSkipProb;
}
});
qry.setPageSize(bufSize);
qry.setTimeInterval(timeInterval);
cache.query(qry);
} else {
ignite.events().remoteListen(bufSize, timeInterval, true, new PX2<UUID, Event>() {
@Override
public boolean applyx(UUID uuid, Event evt) throws IgniteInterruptedCheckedException {
if (cbSleepMs > 0)
U.sleep(cbSleepMs);
cbCntr.incrementAndGet();
// Continue listening.
return true;
}
}, new PX1<Event>() {
@Override
public boolean applyx(Event evt) throws IgniteInterruptedCheckedException {
if (filterSleepMs > 0)
U.sleep(filterSleepMs);
return Math.random() * 100 >= filterSkipProb;
}
}, EVT_CACHE_OBJECT_PUT);
}
}
// Start collector thread.
startDaemon(new Runnable() {
@Override
public void run() {
try {
while (!stop.get() && !Thread.currentThread().isInterrupted()) {
long cbCntr0 = cbCntr.get();
long updCntr0 = updCntr.get();
U.sleep(1000);
long cbDelta = cbCntr.get() - cbCntr0;
long updDelta = updCntr.get() - updCntr0;
X.println("Stats [entriesPerSec=" + cbDelta + ", updatesPerSec=" + updDelta + ']');
}
} catch (IgniteInterruptedCheckedException ignored) {
// No-op.
}
}
});
X.println("Starting " + threadsCnt + " generator thread(s).");
// Start generator threads.
IgniteInternalFuture<Long> genFut = runMultiThreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
byte[] val = new byte[valSize];
ThreadLocalRandom rnd = ThreadLocalRandom.current();
while (!stop.get() && !Thread.currentThread().isInterrupted()) {
Integer key = rnd.nextInt(keyRange);
cache.put(key, val);
updCntr.incrementAndGet();
if (updSleepMs > 0)
U.sleep(updSleepMs);
}
return true;
}
}, threadsCnt, "load-test-generator");
U.sleep(testDurSec * 1000);
stop.set(true);
genFut.get();
}
}
use of org.apache.ignite.internal.IgniteInterruptedCheckedException in project ignite by apache.
the class CacheBaselineTopologyTest method testClusterActiveWhileBaselineChanging.
/**
* @throws Exception if failed.
*/
public void testClusterActiveWhileBaselineChanging() throws Exception {
startGrids(NODE_COUNT);
IgniteEx ig = grid(0);
ig.cluster().active(true);
assertTrue(ig.cluster().active());
startGrid(NODE_COUNT);
IgniteInternalFuture fut = GridTestUtils.runAsync(() -> {
try {
U.sleep(100);
} catch (IgniteInterruptedCheckedException e) {
e.printStackTrace();
}
ig.cluster().setBaselineTopology(NODE_COUNT + 1);
});
while (!fut.isDone()) {
assertTrue(grid(0).cluster().active());
assertTrue(grid(0).context().state().publicApiActiveState(false));
assertTrue(grid(NODE_COUNT).cluster().active());
assertTrue(grid(NODE_COUNT).context().state().publicApiActiveState(false));
}
assertNull(String.valueOf(fut.error()), fut.error());
assertEquals(NODE_COUNT + 1, ig.cluster().currentBaselineTopology().size());
}
Aggregations