use of org.ow2.proactive.authentication.crypto.Credentials in project scheduling by ow2-proactive.
the class LoginWithCredentialsCommand method login.
@Override
protected String login(ApplicationContext currentContext) throws CLIException {
File credentials = new File(pathname);
if (!credentials.exists()) {
throw new CLIException(REASON_INVALID_ARGUMENTS, String.format("File does not exist: %s", credentials.getAbsolutePath()));
}
if (warn) {
writeLine(currentContext, "Using the default credentials file: %s", credentials.getAbsolutePath());
}
HttpPost request = new HttpPost(currentContext.getResourceUrl("login"));
MultipartEntity entity = new MultipartEntity();
entity.addPart("credential", new ByteArrayBody(FileUtility.byteArray(credentials), APPLICATION_OCTET_STREAM.getMimeType()));
request.setEntity(entity);
HttpResponseWrapper response = execute(request, currentContext);
if (statusCode(OK) == statusCode(response)) {
return StringUtility.responseAsString(response).trim();
} else {
handleError("An error occurred while logging: ", response, currentContext);
throw new CLIException(REASON_OTHER, "An error occurred while logging.");
}
}
use of org.ow2.proactive.authentication.crypto.Credentials in project scheduling by ow2-proactive.
the class GetAllNodes method main.
public static void main(String[] args) {
RMAuthentication auth;
try {
auth = RMConnection.join(RMTHelper.getLocalUrl());
Credentials cred = Credentials.createCredentials(new CredData(TestUsers.DEMO.username, TestUsers.DEMO.password), auth.getPublicKey());
ResourceManager rm = auth.login(cred);
NodeSet nodes = rm.getNodes(new Criteria(rm.getState().getFreeNodesNumber()));
// use nodes to block until the future is available
System.out.println("Got " + nodes.size());
} catch (Exception e) {
e.printStackTrace();
}
System.exit(1);
}
use of org.ow2.proactive.authentication.crypto.Credentials in project scheduling by ow2-proactive.
the class TestNodeEncoding method createNodeSourceWithOneLocalNode.
protected String createNodeSourceWithOneLocalNode() throws Exception {
byte[] credentials = FileToBytesConverter.convertFileToByteArray(new File(PAResourceManagerProperties.getAbsolutePath(PAResourceManagerProperties.RM_CREDS.getValueAsString())));
String javaProperty = "-D" + PAProperties.KEY_PA_FILE_ENCODING + "=" + FILE_ENCODING_NAME;
rmHelper.getResourceManager(TestUsers.TEST, javaProperty).createNodeSource("testEncoding", LocalInfrastructure.class.getName(), new Object[] { credentials, 1, RMTHelper.DEFAULT_NODES_TIMEOUT, "" }, StaticPolicy.class.getName(), null, NODES_NOT_RECOVERABLE);
rmHelper.waitForNodeSourceCreation("testEncoding");
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_ADDED);
RMNodeEvent rmNodeEvent = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
String nodeUrl = rmNodeEvent.getNodeUrl();
logger.info("New node added " + nodeUrl);
logger.info("Node has state '" + rmNodeEvent.getNodeState() + "'");
return nodeUrl;
}
use of org.ow2.proactive.authentication.crypto.Credentials in project scheduling by ow2-proactive.
the class NonBlockingCoreTest method action.
@Test
public void action() throws Exception {
String rmconf = new File(PAResourceManagerProperties.getAbsolutePath(getClass().getResource("/functionaltests/config/functionalTRMProperties-long-selection-script-timeout.ini").getFile())).getAbsolutePath();
rmHelper.startRM(rmconf);
ResourceManager resourceManager = rmHelper.getResourceManager();
int initialNodeNumber = 2;
rmHelper.createNodeSource("NonBlockingCoreTest1", initialNodeNumber);
long coreScriptExecutionTimeout = PAResourceManagerProperties.RM_SELECT_SCRIPT_TIMEOUT.getValueAsLong();
long scriptSleepingTime = coreScriptExecutionTimeout * 2;
log("Selecting node with timeout script");
// create the static selection script object
final SelectionScript sScript = new SelectionScript(new File(selectionScriptWithtimeOutPath.toURI()), new String[] { Long.toString(scriptSleepingTime) }, false);
// mandatory to use RMUser AO, otherwise, getAtMostNode we be send in
// RMAdmin request queue
final RMAuthentication auth = rmHelper.getRMAuth();
final Credentials cred = Credentials.createCredentials(new CredData(TestUsers.TEST.username, TestUsers.TEST.password), auth.getPublicKey());
// cannot connect twice from the same active object
// so creating another thread
Thread t = new Thread() {
public void run() {
ResourceManager rm2;
try {
rm2 = auth.login(cred);
nodes = rm2.getAtMostNodes(2, sScript);
} catch (LoginException e) {
}
}
};
t.start();
String nodeName = "node_non_blocking_test";
testNode = RMTHelper.createNode(nodeName);
String nodeUrl = testNode.getNode().getNodeInformation().getURL();
log("Adding node " + nodeUrl);
resourceManager.addNode(nodeUrl);
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, nodeUrl);
// waiting for node to be in free state, it is in configuring state when
// added...
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
assertEquals(resourceManager.getState().getTotalNodesNumber(), initialNodeNumber + 1);
assertEquals(resourceManager.getState().getFreeNodesNumber(), initialNodeNumber + 1);
// preemptive removal is useless for this case, because node is free
log("Removing node " + nodeUrl);
resourceManager.removeNode(nodeUrl, false);
rmHelper.waitForNodeEvent(RMEventType.NODE_REMOVED, nodeUrl);
assertEquals(resourceManager.getState().getTotalNodesNumber(), initialNodeNumber);
assertEquals(resourceManager.getState().getFreeNodesNumber(), initialNodeNumber);
String nsName = "NonBlockingCoreTest";
log("Creating a node source " + nsName);
int nsNodesNumber = 1;
rmHelper.createNodeSource(nsName, nsNodesNumber);
assertEquals(resourceManager.getState().getTotalNodesNumber(), nsNodesNumber + initialNodeNumber);
assertEquals(resourceManager.getState().getFreeNodesNumber(), nsNodesNumber + initialNodeNumber);
log("Removing node source " + nsName);
resourceManager.removeNodeSource(nsName, true);
boolean selectionInProgress = PAFuture.isAwaited(nodes);
if (!selectionInProgress) {
// normally we are looking for 2 nodes with timeout script,
// so the selection procedure has to finish not earlier than
// coreScriptExecutionTimeout * nodesNumber
// it should be sufficient to perform all admin operations
// concurrently
//
// if the core is blocked admin operations will be performed after
// selection
fail("Blocked inside RMCore");
} else {
log("No blocking inside RMCore");
}
t.interrupt();
}
use of org.ow2.proactive.authentication.crypto.Credentials in project scheduling by ow2-proactive.
the class TestConcurrentUsers method testConcurrency.
@Test
public void testConcurrency() throws Exception {
ResourceManager resourceManager = rmHelper.getResourceManager();
String nsName = "TestConcurrentUsers";
String node1Name = "node1";
testNode = rmHelper.createNode(node1Name);
String node1URL = testNode.getNode().getNodeInformation().getURL();
resourceManager.createNodeSource(nsName, DefaultInfrastructureManager.class.getName(), null, StaticPolicy.class.getName(), null, NODES_NOT_RECOVERABLE);
rmHelper.waitForNodeSourceEvent(RMEventType.NODESOURCE_CREATED, nsName);
resourceManager.addNode(node1URL, nsName);
// waiting for node adding event
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, node1URL);
// waiting for the node to be free
rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
assertTrue(resourceManager.getState().getTotalNodesNumber() == 1);
assertTrue(resourceManager.getState().getFreeNodesNumber() == 1);
log("Test 1 - releasing of the foreign node");
// acquiring a node
final NodeSet ns = resourceManager.getAtMostNodes(1, null);
// waiting for node busy event
RMNodeEvent evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
assertEquals(evt.getNodeState(), NodeState.BUSY);
assertEquals(ns.size(), 1);
assertTrue(resourceManager.getState().getTotalNodesNumber() == 1);
assertTrue(resourceManager.getState().getFreeNodesNumber() == 0);
Thread t = new Thread() {
@Override
public void run() {
try {
Credentials cred = Credentials.createCredentials(new CredData(CredData.parseLogin("user"), CredData.parseDomain("user"), "pwd"), TestConcurrentUsers.this.rmHelper.getRMAuth().getPublicKey());
ResourceManager rm2 = TestConcurrentUsers.this.rmHelper.getRMAuth().login(cred);
rm2.releaseNode(ns.get(0)).getBooleanValue();
Assert.assertTrue("Should not be able to release foreign node", false);
} catch (Exception e) {
log(e.getMessage());
}
}
};
t.start();
t.join();
assertEquals(1, resourceManager.getState().getTotalNodesNumber());
assertEquals(0, resourceManager.getState().getFreeNodesNumber());
resourceManager.releaseNodes(ns);
evt = rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, node1URL);
assertEquals(evt.getNodeState(), NodeState.FREE);
assertEquals(1, resourceManager.getState().getTotalNodesNumber());
assertEquals(1, resourceManager.getState().getFreeNodesNumber());
log("Test 2 - releasing node twice");
resourceManager.releaseNodes(ns);
// to make sure everything has been processed
Thread.sleep(1000);
assertEquals(1, resourceManager.getState().getTotalNodesNumber());
assertEquals(1, resourceManager.getState().getFreeNodesNumber());
log("Test 3 - client crash detection");
JVMProcessImpl nodeProcess = new JVMProcessImpl(new org.objectweb.proactive.core.process.AbstractExternalProcess.StandardOutputMessageLogger());
nodeProcess.setJvmOptions(Collections.singletonList(PAResourceManagerProperties.RM_HOME.getCmdLine() + PAResourceManagerProperties.RM_HOME.getValueAsString()));
nodeProcess.setClassname(GetAllNodes.class.getName());
nodeProcess.startProcess();
// node busy event
for (int i = 0; i < 1; i++) {
evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
assertEquals(evt.getNodeState(), NodeState.BUSY);
}
assertEquals(1, resourceManager.getState().getTotalNodesNumber());
assertEquals(0, resourceManager.getState().getFreeNodesNumber());
// client does not exist anymore
log("Client does not exist anymore. Waiting for client crash detection.");
// waiting for node free event
for (int i = 0; i < 1; i++) {
evt = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED);
assertEquals(NodeState.FREE, evt.getNodeState());
}
assertEquals(1, resourceManager.getState().getTotalNodesNumber());
assertEquals(1, resourceManager.getState().getFreeNodesNumber());
log("Test 4 - disconnecting");
NodeSet ns2 = resourceManager.getAtMostNodes(1, null);
RMNodeEvent event = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED, 10000);
Assert.assertTrue(event.getNodeState() == NodeState.BUSY);
PAFuture.waitFor(ns2);
log("Number of found nodes " + ns2.size());
assertEquals(1, ns2.size());
t = new Thread() {
public void run() {
try {
RMAuthentication auth = rmHelper.getRMAuth();
Credentials cred = Credentials.createCredentials(new CredData(TestUsers.TEST.username, TestUsers.TEST.password), auth.getPublicKey());
ResourceManager rm = auth.login(cred);
rm.disconnect().getBooleanValue();
} catch (Exception e) {
e.printStackTrace();
}
}
};
t.start();
t.join();
try {
event = rmHelper.waitForAnyNodeEvent(RMEventType.NODE_STATE_CHANGED, 10000);
fail("Unexpected event: " + event);
} catch (ProActiveTimeoutException e) {
}
}
Aggregations