use of org.ow2.proactive.authentication.crypto.Credentials 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.crypto.Credentials in project scheduling by ow2-proactive.
the class TestMultipleUsersMakingMassivGetResultRequest method testMultipleUsersMakingMassivGetResultRequest.
@Test
public void testMultipleUsersMakingMassivGetResultRequest() throws Throwable {
final SchedulerAuthenticationInterface auth = schedulerHelper.getSchedulerAuth();
// create a job
final TaskFlowJob job = new TaskFlowJob();
for (int i = 0; i < taskPerJob; i++) {
JavaTask task = new JavaTask();
task.setName("jt" + i);
task.setExecutableClassName(EmptyTask.class.getName());
job.addTask(task);
}
// start threads
for (int i = 0; i < ThreadNumber; i++) {
new Thread() {
@Override
public void run() {
try {
// connect the scheduler
log(Thread.currentThread().getName() + " -> Connecting the scheduler");
Credentials cred = Credentials.createCredentials(new CredData(TestUsers.DEMO.username, TestUsers.DEMO.password), auth.getPublicKey());
Scheduler user = auth.login(cred);
log(Thread.currentThread().getName() + " -> Connected");
long start = System.currentTimeMillis();
int submitted = 1;
while (true) {
log(Thread.currentThread().getName() + " -> Submit (" + submitted + ")");
JobId id = user.submit(job);
JobResult jr = null;
while (jr == null) {
Thread.sleep(getResultDelay);
jr = user.getJobResult(id);
}
if (System.currentTimeMillis() - start > jobSubmissionDuration) {
log(Thread.currentThread().getName() + " -> Terminate");
nbFinished++;
break;
}
submitted++;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}.start();
}
while (nbFinished < ThreadNumber) {
Thread.sleep(100);
}
log("All threads terminated.");
}
use of org.ow2.proactive.authentication.crypto.Credentials in project scheduling by ow2-proactive.
the class AuthenticationTest method loginAsUser.
private void loginAsUser(SchedulerAuthenticationInterface auth, PublicKey pubKey) throws KeyException, LoginException, AlreadyConnectedException, NotConnectedException, PermissionException {
log("Test 2");
log("Trying to authorized as a user with correct user name and password");
Credentials cred = Credentials.createCredentials(new CredData(TestUsers.USER.username, TestUsers.USER.password), pubKey);
Scheduler user = auth.login(cred);
String userName = user.getCurrentUser();
Assert.assertEquals(TestUsers.USER.username, userName);
UserData userData = user.getCurrentUserData();
Assert.assertNotNull(userData);
Assert.assertNotNull(userData.getUserName());
Assert.assertNotNull(userData.getGroups());
Assert.assertTrue(userData.getGroups().contains("user"));
user.disconnect();
log("Passed: successful authentication");
}
use of org.ow2.proactive.authentication.crypto.Credentials in project scheduling by ow2-proactive.
the class AuthenticationTest method loginAsAdminIncorrectPassword.
private void loginAsAdminIncorrectPassword(SchedulerAuthenticationInterface auth, PublicKey pubKey) {
// negative
log("Test 3");
log("Trying to authorized as an admin with incorrect user name and password");
try {
Credentials cred = Credentials.createCredentials(new CredData(TestUsers.DEMO.username, "b"), pubKey);
auth.login(cred);
fail("Error: successful authentication");
} catch (Exception e) {
log("Passed: expected error " + e.getMessage());
}
}
use of org.ow2.proactive.authentication.crypto.Credentials in project scheduling by ow2-proactive.
the class SchedulerStarter method addLocalNodes.
private static void addLocalNodes(RMAuthentication rmAuth, int numberLocalNodes, int nodeTimeoutValue) throws LoginException, KeyException, IOException {
// creating default node source
ResourceManager rman = rmAuth.login(Credentials.getCredentials(PAResourceManagerProperties.getAbsolutePath(PAResourceManagerProperties.RM_CREDS.getValueAsString())));
// first im parameter is default rm url
byte[] creds = FileToBytesConverter.convertFileToByteArray(new File(PAResourceManagerProperties.getAbsolutePath(PAResourceManagerProperties.RM_CREDS.getValueAsString())));
rman.createNodeSource(RMConstants.DEFAULT_LOCAL_NODES_NODE_SOURCE_NAME, LocalInfrastructure.class.getName(), new Object[] { creds, numberLocalNodes, nodeTimeoutValue, "" }, RestartDownNodesPolicy.class.getName(), new Object[] { "ALL", "ALL", "10000" }, NodeSource.DEFAULT_LOCAL_NODES_NODE_SOURCE_RECOVERABLE);
credentials = creds;
}
Aggregations