use of org.ow2.proactive.authentication.Connection in project scheduling by ow2-proactive.
the class AbstractCommand method execute.
protected HttpResponseWrapper execute(HttpUriRequest request, ApplicationContext currentContext) {
String sessionId = currentContext.getSessionId();
if (sessionId != null) {
request.setHeader("sessionid", sessionId);
}
CommonHttpClientBuilder httpClientBuilder = new HttpClientBuilder().useSystemProperties();
try {
if ("https".equals(request.getURI().getScheme()) && currentContext.canInsecureAccess()) {
httpClientBuilder.insecure(true);
}
HttpResponse response = httpClientBuilder.build().execute(request);
return new HttpResponseWrapper(response);
} catch (SSLPeerUnverifiedException sslException) {
throw new CLIException(CLIException.REASON_OTHER, "SSL error. Perhaps HTTPS certificate could not be validated, " + "you can try with -k or insecure() for insecure SSL connection.", sslException);
} catch (Exception e) {
throw new CLIException(CLIException.REASON_OTHER, e.getMessage(), e);
} finally {
((HttpRequestBase) request).releaseConnection();
}
}
use of org.ow2.proactive.authentication.Connection in project scheduling by ow2-proactive.
the class TestGetUsage method testGetMyAccountUsage.
@Test
public void testGetMyAccountUsage() throws Exception {
Date beforeJobExecution = new Date();
// put some data in the database
Scheduler firstUser = schedulerHelper.getSchedulerInterface();
JobId jobId = firstUser.submit(createJob());
schedulerHelper.waitForEventJobFinished(jobId, 30000);
Date afterJobExecution = new Date();
// We try to retrieve usage on the job I just ran
List<JobUsage> adminUsages = firstUser.getMyAccountUsage(beforeJobExecution, afterJobExecution);
assertFalse(adminUsages.isEmpty());
// Do we properly check for user connection ?
firstUser.disconnect();
try {
firstUser.getMyAccountUsage(beforeJobExecution, afterJobExecution);
fail("Should throw a not connected exception because i just disconnected");
} catch (NotConnectedException e) {
// Ok that is expected
}
// another user
SchedulerAuthenticationInterface auth = schedulerHelper.getSchedulerAuth();
Credentials cred = Credentials.createCredentials(new CredData(TestUsers.USER.username, TestUsers.USER.password), auth.getPublicKey());
Scheduler otherUser = auth.login(cred);
// This user has not ran any job
List<JobUsage> userUsages = otherUser.getMyAccountUsage(beforeJobExecution, afterJobExecution);
assertTrue(userUsages.isEmpty());
otherUser.disconnect();
}
use of org.ow2.proactive.authentication.Connection 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.authentication.Connection in project scheduling by ow2-proactive.
the class TestRMReconnectionWhileRunning method testReconnectionIsNotHappen.
/**
* This case checks that even if exception was trown in main Scheduler loop it will not cause reconnection to RM.
* @throws Exception
*/
@Test
public void testReconnectionIsNotHappen() throws Exception {
ProActiveConfiguration.load();
RMFactory.setOsJavaProperty();
schedulerHelper = new SchedulerTHelper(false, true);
schedulerHelper.createNodeSource("local", 3);
schedulerHelper.getSchedulerInterface().changePolicy("functionaltests.rm.PolicyWhichThrowsExceptions");
JobId jobId = schedulerHelper.submitJob(new File(runningJob.toURI()).getAbsolutePath());
JobId jobId2 = schedulerHelper.submitJob(new File(runningJob1.toURI()).getAbsolutePath());
JobId jobId3 = schedulerHelper.submitJob(new File(runningJob2.toURI()).getAbsolutePath());
schedulerHelper.waitForEventTaskRunning(jobId, "running_task_for20s");
schedulerHelper.waitForEventJobFinished(jobId2);
schedulerHelper.waitForEventJobFinished(jobId3);
assertJobFinished(jobId2);
assertJobFinished(jobId3);
int numberOfAttemptsToReconnect = LogProcessor.linesThatMatch("Successfully reconnected to Resource Manager ").size();
int attemptsThatDidNotCauseReconnection = LogProcessor.linesThatMatch("Do not reconnect to the RM as connection is active for ").size();
int actualNumberOfReconnections = numberOfAttemptsToReconnect - attemptsThatDidNotCauseReconnection;
assertEquals(0, actualNumberOfReconnections);
}
use of org.ow2.proactive.authentication.Connection in project scheduling by ow2-proactive.
the class SchedulerRuntimeDataMBeanTest method testAsUser.
private void testAsUser() throws Exception {
final SchedulerAuthenticationInterface auth = schedulerHelper.getSchedulerAuth();
final HashMap<String, Object> env = new HashMap<>(1);
env.put(JMXConnector.CREDENTIALS, new Object[] { TestUsers.USER.username, TestUsers.USER.password });
JMXConnector userJmxConnector = JMXConnectorFactory.connect(new JMXServiceURL(auth.getJMXConnectorURL(JMXTransportProtocol.RMI)), env);
try {
MBeanServerConnection connection = userJmxConnector.getMBeanServerConnection();
final ObjectName beanName = new ObjectName(SchedulerJMXHelper.RUNTIMEDATA_MBEAN_NAME);
RuntimeDataMBean bean = JMX.newMXBeanProxy(connection, beanName, RuntimeDataMBean.class);
checkDataConsistent(bean);
} finally {
userJmxConnector.close();
}
}
Aggregations