use of org.ow2.proactive.resourcemanager.frontend.ResourceManager in project scheduling by ow2-proactive.
the class RMNodeStarter method addNodeToResourceManager.
private void addNodeToResourceManager(String rmURL, Node node, ResourceManager rm) {
// Add the created node to the Resource Manager with a specified
// number of attempts and a timeout between each attempt
boolean isNodeAdded = false;
int attempts = 0;
String nodeUrl = node.getNodeInformation().getURL();
String nodeName = node.getNodeInformation().getName();
logger.info("Adding node " + nodeName + " to Resource Manager.");
while ((!isNodeAdded) && (attempts < NB_OF_ADD_NODE_ATTEMPTS)) {
attempts++;
try {
if (this.nodeSourceName != null) {
isNodeAdded = rm.addNode(nodeUrl, this.nodeSourceName).getBooleanValue();
} else {
isNodeAdded = rm.addNode(nodeUrl).getBooleanValue();
}
} catch (AddingNodesException addException) {
addException.printStackTrace();
System.exit(ExitStatus.RMNODE_ADD_ERROR.exitCode);
}
if (isNodeAdded) {
if (removePrevious) {
// try to remove previous URL if different...
String previousURL = this.getAndDeleteNodeURL(nodeName, rank);
if (previousURL != null && !previousURL.equals(nodeUrl)) {
logger.info("Different previous URL registered by this agent has been found. Remove previous registration.");
rm.removeNode(previousURL, true);
}
// store the node URL
this.storeNodeURL(nodeName, rank, nodeUrl);
logger.info("Node " + nodeUrl + " added. URL is stored in " + getNodeURLFilename(nodeName, rank));
} else {
logger.info("Node " + nodeUrl + " added.");
}
} else {
// not yet registered
logger.info("Attempt number " + attempts + " out of " + NB_OF_ADD_NODE_ATTEMPTS + " to add the local node to the Resource Manager at " + rmURL + " has failed.");
try {
Thread.sleep(ADD_NODE_ATTEMPTS_DELAY_IN_MS);
} catch (InterruptedException e) {
logger.info("Interrupted", e);
}
}
}
if (!isNodeAdded) {
// if not registered
logger.error("The Resource Manager was unable to add the local node " + nodeUrl + " after " + NB_OF_ADD_NODE_ATTEMPTS + " attempts. The application will exit.");
System.exit(ExitStatus.RMNODE_ADD_ERROR.exitCode);
}
}
use of org.ow2.proactive.resourcemanager.frontend.ResourceManager in project scheduling by ow2-proactive.
the class RMNodeStarter method registerInRM.
/**
* Tries to join to the Resource Manager with a specified timeout
* at the given URL, logs with provided credentials and adds the local node to
* the Resource Manager. Handles all errors/exceptions.
*/
protected ResourceManager registerInRM(final Credentials credentials, final String rmURL, final String nodeName, final Collection<Node> nodes) {
RMAuthentication auth = joinResourceManager(rmURL);
final ResourceManager rm = loginToResourceManager(credentials, auth);
SigarExposer sigarExposer = null;
if (!disabledMonitoring) {
// initializing JMX server with Sigar beans
sigarExposer = new SigarExposer(nodeName);
final RMAuthentication rmAuth = auth;
sigarExposer.boot(auth, false, new PermissionChecker() {
@Override
public boolean checkPermission(Credentials cred) {
ResourceManager rm = null;
try {
rm = rmAuth.login(cred);
if (NB_OF_ADD_NODE_ATTEMPTS == 0)
return true;
boolean isAdmin = rm.isNodeAdmin(nodes.iterator().next().getNodeInformation().getURL()).getBooleanValue();
if (!isAdmin) {
throw new SecurityException("Permission denied");
}
return true;
} catch (LoginException e) {
throw new SecurityException(e);
} finally {
if (rm != null) {
rm.disconnect();
}
}
}
});
} else {
logger.info("JMX monitoring is disabled.");
}
for (final Node node : nodes) {
nodeSetJmxUrl(sigarExposer, node);
addNodeToResourceManager(rmURL, node, rm);
}
return rm;
}
use of org.ow2.proactive.resourcemanager.frontend.ResourceManager in project scheduling by ow2-proactive.
the class RMStarter method main.
public static void main(String[] args) {
configureRMHome();
configureSecurityManager();
configureLogging();
args = JVMPropertiesPreloader.overrideJVMProperties(args);
initOptions();
CommandLineParser parser = new DefaultParser();
CommandLine cmd;
try {
cmd = parser.parse(options, args);
if (cmd.hasOption("h")) {
displayHelp();
}
logger.info("Starting the resource manager...");
RMFactory.setOsJavaProperty();
boolean localNodes = false;
if (cmd.hasOption("localNodes")) {
localNodes = true;
if (cmd.hasOption("timeout")) {
String timeout = cmd.getOptionValue("t");
try {
nodeTimeout = Integer.parseInt(timeout);
} catch (Exception e) {
logger.error("Wrong value for timeout option: " + timeout, e);
}
}
}
// starting clean resource manager
RMAuthentication auth = RMFactory.startLocal();
int defaultNodesNumber = PAResourceManagerProperties.RM_NB_LOCAL_NODES.getValueAsInt();
// -1 means that the number of local nodes depends of the number of cores in the local machine
if (defaultNodesNumber == -1) {
defaultNodesNumber = DEFAULT_NODES_NUMBER;
}
if (localNodes && defaultNodesNumber > 0) {
ResourceManager resourceManager = auth.login(Credentials.getCredentials(PAResourceManagerProperties.getAbsolutePath(PAResourceManagerProperties.RM_CREDS.getValueAsString())));
String nodeSourceName = NodeSource.DEFAULT_LOCAL_NODES_NODE_SOURCE_NAME;
// first im parameter is default rm url
byte[] creds = FileToBytesConverter.convertFileToByteArray(new File(PAResourceManagerProperties.getAbsolutePath(PAResourceManagerProperties.RM_CREDS.getValueAsString())));
resourceManager.createNodeSource(nodeSourceName, LocalInfrastructure.class.getName(), new Object[] { creds, defaultNodesNumber, nodeTimeout, "" }, RestartDownNodesPolicy.class.getName(), null, NodeSource.DEFAULT_LOCAL_NODES_NODE_SOURCE_RECOVERABLE);
resourceManager.disconnect();
logger.info("The resource manager with " + defaultNodesNumber + " local nodes created on " + auth.getHostURL());
} else {
logger.info("The resource manager created on " + auth.getHostURL());
}
} catch (ParseException e1) {
displayHelp();
} catch (Exception e) {
logger.error("", e);
System.exit(3);
}
}
use of org.ow2.proactive.resourcemanager.frontend.ResourceManager in project scheduling by ow2-proactive.
the class AuthenticationTest method loginAsAdmin.
private void loginAsAdmin(RMAuthentication auth) throws LoginException, KeyException {
log("Test 1");
log("Trying to authorized with correct admin name and password");
Credentials cred = Credentials.createCredentials(new CredData(TestUsers.DEMO.username, TestUsers.DEMO.password), auth.getPublicKey());
ResourceManager admin = auth.login(cred);
admin.disconnect().getBooleanValue();
log("Passed: successful authentication");
}
use of org.ow2.proactive.resourcemanager.frontend.ResourceManager in project scheduling by ow2-proactive.
the class AddGetReleaseRemoveTest method action.
@Test
public void action() throws Exception {
final ResourceManager rm = rmHelper.getResourceManager();
// The username and thr password must be the same a used to connect to the RM
final String adminLogin = TestUsers.TEST.username;
final String adminPassword = TestUsers.TEST.password;
// All accounting values are checked through JMX
final RMAuthentication auth = rmHelper.getRMAuth();
final PublicKey pubKey = auth.getPublicKey();
final Credentials adminCreds = Credentials.createCredentials(new CredData(adminLogin, adminPassword), pubKey);
final JMXServiceURL jmxRmiServiceURL = new JMXServiceURL(auth.getJMXConnectorURL(JMXTransportProtocol.RMI));
final HashMap<String, Object> env = new HashMap<>(1);
env.put(JMXConnector.CREDENTIALS, new Object[] { adminLogin, adminCreds });
// Connect to the JMX RMI Connector Server
final ObjectName myAccountMBeanName = new ObjectName(RMJMXBeans.MYACCOUNT_MBEAN_NAME);
final ObjectName managementMBeanName = new ObjectName(RMJMXBeans.MANAGEMENT_MBEAN_NAME);
final JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxRmiServiceURL, env);
final MBeanServerConnection conn = jmxConnector.getMBeanServerConnection();
// Ensure that no refreshes was done and all account values are correctly initialized
AttributeList atts = conn.getAttributes(myAccountMBeanName, new String[] { "UsedNodeTime", "ProvidedNodeTime", "ProvidedNodesCount" });
long usedNodeTime = (Long) ((Attribute) atts.get(0)).getValue();
long providedNodeTime = (Long) ((Attribute) atts.get(1)).getValue();
int providedNodesCount = (Integer) ((Attribute) atts.get(2)).getValue();
// ADD, GET, RELEASE, REMOVE
// 1) ADD
final long beforeAddTime = System.currentTimeMillis();
testNode = rmHelper.createNode("test");
Node node = testNode.getNode();
final String nodeURL = node.getNodeInformation().getURL();
rm.addNode(nodeURL).getBooleanValue();
// We eat the configuring to free event
rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, nodeURL);
rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, nodeURL);
// 2) GET
final long beforeGetTime = System.currentTimeMillis();
node = rm.getAtMostNodes(1, null).get(0);
// Sleep a certain amount of time that will be the minimum amount of the GET->RELEASE duration
Thread.sleep(GR_DURATION);
// 3) RELEASE
rm.releaseNode(node).getBooleanValue();
final long getReleaseMaxDuration = System.currentTimeMillis() - beforeGetTime;
// 4) REMOVE
rm.removeNode(nodeURL, true).getBooleanValue();
final long addRemoveMaxDuration = System.currentTimeMillis() - beforeAddTime;
// Refresh the account manager
conn.invoke(managementMBeanName, "clearAccoutingCache", null, null);
// Check account values validity
atts = conn.getAttributes(myAccountMBeanName, new String[] { "UsedNodeTime", "ProvidedNodeTime", "ProvidedNodesCount" });
usedNodeTime = (Long) ((Attribute) atts.get(0)).getValue() - usedNodeTime;
providedNodeTime = (Long) ((Attribute) atts.get(1)).getValue() - providedNodeTime;
providedNodesCount = (Integer) ((Attribute) atts.get(2)).getValue() - providedNodesCount;
Assert.assertTrue("Invalid value of the usedNodeTime attribute (usedNodeTime=" + usedNodeTime + ")", (usedNodeTime >= GR_DURATION));
Assert.assertTrue("Invalid value of the usedNodeTime attribute (getReleaseMaxDuration=" + getReleaseMaxDuration + ")", (usedNodeTime <= getReleaseMaxDuration));
Assert.assertTrue("Invalid value of the providedNodeTime attribute", (providedNodeTime >= usedNodeTime) && (providedNodeTime <= addRemoveMaxDuration));
}
Aggregations