use of org.ow2.proactive_grid_cloud_portal.cli.cmd.Command in project scheduling by ow2-proactive.
the class AbstractJsHelpCommand method printHelp.
public void printHelp(ApplicationContext currentContext, CommandSet.Entry[]... entrySet) throws CLIException {
ObjectArrayFormatter formatter = new ObjectArrayFormatter();
formatter.setMaxColumnLength(100);
formatter.setSpace(2);
formatter.setTitle(ImmutableList.of("Command", "Description"));
formatter.addEmptyLine();
boolean versionEntryAdded = false;
List<CommandSet.Entry> entries = new ArrayList<>();
for (CommandSet.Entry[] es : entrySet) {
for (CommandSet.Entry entry : es) {
if (entry.jsCommand() != null && entry.jsCommand().equals(CommandSet.VERSION.jsCommand())) {
if (!versionEntryAdded) {
entries.add(entry);
versionEntryAdded = true;
}
} else {
entries.add(entry);
}
}
}
Collections.sort(entries);
for (CommandSet.Entry entry : entries) {
if (entry.jsCommand() != null) {
formatter.addLine(ImmutableList.of(entry.jsCommand(), entry.description()));
}
}
writeLine(currentContext, "%s", StringUtility.objectArrayFormatterAsString(formatter));
}
use of org.ow2.proactive_grid_cloud_portal.cli.cmd.Command in project scheduling by ow2-proactive.
the class SchedulingService method checkAndReconnectRM.
/**
* Check the connection to the RM. If the connection is down and automatic reconnection is enabled, this method performs n reconnection attempts before returning the result.
* These parameters can be set in the configuration :
* - Enabling/Disabling automatic reconnection: pa.scheduler.core.rmconnection.autoconnect (default is true)
* - Delay in ms between 2 consecutive attempts: pa.scheduler.core.rmconnection.timespan (default is 5000 ms)
* - Maximum number of attempts: pa.scheduler.core.rmconnection.attempts (default is 10)
*
* @return true if the RM is alive, false otherwise.
*/
private boolean checkAndReconnectRM() {
// Result of the method.
boolean alive = false;
// Checks if the option is enabled (false by default)
boolean autoReconnectRM = PASchedulerProperties.SCHEDULER_RMCONNECTION_AUTO_CONNECT.isSet() ? PASchedulerProperties.SCHEDULER_RMCONNECTION_AUTO_CONNECT.getValueAsBoolean() : false;
// Delay (in ms) between each connection attempts (5s by default)
int timespan = PASchedulerProperties.SCHEDULER_RMCONNECTION_TIMESPAN.isSet() ? PASchedulerProperties.SCHEDULER_RMCONNECTION_TIMESPAN.getValueAsInt() : 5000;
// Maximum number of attempts (10 by default)
int maxAttempts = PASchedulerProperties.SCHEDULER_RMCONNECTION_ATTEMPTS.isSet() ? PASchedulerProperties.SCHEDULER_RMCONNECTION_ATTEMPTS.getValueAsInt() : 10;
// If the options is disabled or the number of attempts is wrong, it is set to 1
if (!autoReconnectRM || maxAttempts <= 0)
maxAttempts = 1;
// Check the timespan option
if (timespan <= 0)
timespan = 5000;
// Save the url in a string of the last connected RM.
String rmURL = this.lastRmUrl.toString();
int nbAttempts = 1;
logger.info("Automatically reconnecting to RM at url " + rmURL + "...");
while (!alive && nbAttempts <= maxAttempts) {
try {
infrastructure.getRMProxiesManager().rebindRMProxiesManager(new URI(rmURL));
logger.info("Successfully reconnected to Resource Manager at " + rmURL);
alive = true;
} catch (Exception rme) {
alive = false;
if (nbAttempts != maxAttempts) {
try {
// Sleep before two attempts
logger.info("Waiting " + timespan + " ms before the next attempt...");
Thread.sleep(timespan);
} catch (InterruptedException ex) {
logger.error("An exception has occurred while waiting.");
}
}
}
nbAttempts++;
}
if (!alive) {
logger.info("Resource Manager seems to be dead.");
// Disconnect proxies and freeze the scheduler.
clearProxiesAndFreeze();
logger.fatal("\n*****************************************************************************************************************\n" + "* Resource Manager is no more available, Scheduler has been paused waiting for a resource manager to be reconnect\n" + "* Scheduler is in critical state and its functionalities are reduced : \n" + "* \t-> use the linkrm(\"" + rmURL + "\") command in scheduler-client to reconnect a new one.\n" + "*****************************************************************************************************************");
listener.schedulerStateUpdated(SchedulerEvent.RM_DOWN);
}
return alive;
}
use of org.ow2.proactive_grid_cloud_portal.cli.cmd.Command in project scheduling by ow2-proactive.
the class TestProcessTreeKiller method testProcessTreeKiller.
@Test
public void testProcessTreeKiller() throws Throwable {
schedulerHelper.addExtraNodes(2);
Logger.getLogger(ProcessTree.class).setLevel(Level.DEBUG);
Logger.getLogger(TaskLauncher.class).setLevel(Level.DEBUG);
for (int i = 0; i < NB_ITERATIONS; i++) {
log("***************************************************");
log("************** Iteration " + i + " *************************");
log("***************************************************");
log("Creating job...");
// create job 1 NativeExecutable
TaskFlowJob job1 = new TaskFlowJob();
job1.setName(this.getClass().getSimpleName() + "_1");
job1.setDescription("a command that spawn processes");
NativeTask task1 = new NativeTask();
String task1Name = "TestPTK1";
task1.setName(task1Name);
String workingDir = new File(TestProcessTreeKiller.launchersDir.toURI()).getParentFile().getCanonicalPath();
task1.setForkEnvironment(new ForkEnvironment(workingDir));
JavaSpawnExecutable executable = new JavaSpawnExecutable();
executable.home = PASchedulerProperties.SCHEDULER_HOME.getValueAsString();
task1.setCommandLine(executable.getNativeExecLauncher(false));
job1.addTask(task1);
String task2Name = "TestTK2";
TaskFlowJob job2 = createJavaExecutableJob(task2Name, true);
log("************** Test with Job Killing *************");
// submit three jobs
JobId id1 = schedulerHelper.submitJob(job1);
JobId id2 = schedulerHelper.submitJob(job2);
schedulerHelper.waitForEventTaskRunning(id1, task1Name);
schedulerHelper.waitForEventTaskRunning(id2, task2Name);
log("************** All 2 tasks running *************");
TestProcessTreeKiller.waitUntilForkedProcessesAreRunning(detachedProcNumber * 2);
// we should have 2 times (2 jobs) number of detached processes
// kill the first job
log("************** Waiting for the first job (NativeExecutable) to be killed *************");
schedulerHelper.getSchedulerInterface().killJob(id1);
schedulerHelper.waitForEventJobFinished(id1);
log("************** First job killed *************");
TestProcessTreeKiller.waitUntilForkedProcessesAreRunning(detachedProcNumber);
// kill the second job
log("************** Waiting for the second job (JavaExecutable) to be killed *************");
schedulerHelper.getSchedulerInterface().killJob(id2);
schedulerHelper.waitForEventJobFinished(id2);
log("************** Second job killed *************");
TestProcessTreeKiller.waitUntilForkedProcessesAreRunning(0);
JobResult res = schedulerHelper.getJobResult(id1);
assertEquals(JobStatus.KILLED, res.getJobInfo().getStatus());
res = schedulerHelper.getJobResult(id2);
assertEquals(JobStatus.KILLED, res.getJobInfo().getStatus());
log("************** Test with Normal Job termination *************");
// The test for normal termination in case of NativeExecutable is slightly different
// we don't spawn here a native zombie process that will wait forever, because that would mean that the
// NativeExecutable task will also wait forever !
// This is related to the current implementation of NativeExecutable, as long as there are still some IO streamed
// from the subprocesses of the main process, the task will wait
// TODO improve the test by finding a way to run a detached process without IO redirection
TaskFlowJob job4 = new TaskFlowJob();
job4.setName(this.getClass().getSimpleName() + "_4");
job4.setDescription("a command that spawn processes");
NativeTask task4 = new NativeTask();
String task4Name = "TestPTK4";
task4.setName(task4Name);
task4.setForkEnvironment(new ForkEnvironment(workingDir));
task4.setCommandLine(executable.getNativeExecLauncher(true));
job4.addTask(task4);
// submit three jobs
id1 = schedulerHelper.submitJob(job4);
id2 = schedulerHelper.submitJob(job2);
schedulerHelper.waitForEventTaskRunning(id1, task4Name);
schedulerHelper.waitForEventTaskRunning(id2, task2Name);
log("************** All 2 tasks running *************");
TestProcessTreeKiller.waitUntilForkedProcessesAreRunning(detachedProcNumber);
// we should have 1 time (2 jobs) number of detached processes as the first job won't spawn any process
log("************** Waiting for first job (NativeExecutable) to finish *************");
// wait for the first job to finish normally
schedulerHelper.waitForEventJobFinished(id1);
log("************** First job finished *************");
int runningDetachedProcNumber = countProcesses();
log("************** number of processes : " + runningDetachedProcNumber);
assertEquals(detachedProcNumber, runningDetachedProcNumber);
log("************** Waiting for second job (JavaExecutable) to finish *************");
// wait for the second job to finish normally
schedulerHelper.waitForEventJobFinished(id2);
log("************** Second job finished *************");
runningDetachedProcNumber = countProcesses();
log("************** number of processes : " + runningDetachedProcNumber);
assertEquals(0, runningDetachedProcNumber);
res = schedulerHelper.getJobResult(id1);
assertEquals(JobStatus.FINISHED, res.getJobInfo().getStatus());
res = schedulerHelper.getJobResult(id2);
assertEquals(JobStatus.FINISHED, res.getJobInfo().getStatus());
}
}
use of org.ow2.proactive_grid_cloud_portal.cli.cmd.Command in project scheduling by ow2-proactive.
the class TestWorkingDirStaticCommand method testWorkingDirStaticCommand.
@Test
public void testWorkingDirStaticCommand() throws Throwable {
String task1Name = "task1";
JobId id = null;
// set system Property for executable path
switch(OperatingSystem.getOperatingSystem()) {
case windows:
System.setProperty(executablePathPropertyName, new File(executablePathWindows.toURI()).getAbsolutePath());
System.setProperty(WorkingDirPropertyName, new File(workingDirPath.toURI()).getAbsolutePath());
// test submission and event reception
TaskFlowJob job = (TaskFlowJob) StaxJobFactory.getFactory().createJob(new File(jobDescriptor.toURI()).getAbsolutePath());
List<String> command = new ArrayList<>();
command.add("cmd");
command.add("/C");
String[] tabCommand = ((NativeTask) job.getTask("task1")).getCommandLine();
for (int i = 0; i < tabCommand.length; i++) {
if (i == 0)
command.add("\"\"" + tabCommand[i] + "\"");
else if (i == tabCommand.length - 1)
command.add("\"" + tabCommand[i] + "\"\"");
else
command.add("\"" + tabCommand[i] + "\"");
}
((NativeTask) job.getTask("task1")).setCommandLine(command.toArray(new String[command.size()]));
id = schedulerHelper.testJobSubmission(job);
break;
case unix:
System.setProperty(executablePathPropertyName, new File(executablePath.toURI()).getAbsolutePath());
System.setProperty(WorkingDirPropertyName, new File(workingDirPath.toURI()).getAbsolutePath());
SchedulerTHelper.setExecutable(new File(executablePath.toURI()).getAbsolutePath());
// test submission and event reception
id = schedulerHelper.testJobSubmission(new File(jobDescriptor.toURI()).getAbsolutePath());
break;
default:
throw new IllegalStateException("Unsupported operating system");
}
// remove job
schedulerHelper.removeJob(id);
schedulerHelper.waitForEventJobRemoved(id);
}
use of org.ow2.proactive_grid_cloud_portal.cli.cmd.Command in project scheduling by ow2-proactive.
the class SchedulingServiceTest3 method createTestJob.
private TaskFlowJob createTestJob(boolean cancelJobOnError) throws Exception {
TaskFlowJob job = new TaskFlowJob();
job.setName(this.getClass().getSimpleName());
JavaTask task1 = new JavaTask();
task1.setName("javaTask");
task1.setExecutableClassName("class");
task1.setOnTaskError(cancelJobOnError ? OnTaskError.CANCEL_JOB : OnTaskError.NONE);
job.addTask(task1);
NativeTask task2 = new NativeTask();
task2.setName("nativeTask");
task2.setCommandLine("command line");
job.addTask(task2);
return job;
}
Aggregations