use of org.ow2.proactive.resourcemanager.authentication.RMAuthentication 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, String nodeName, Collection<Node> nodes) {
RMAuthentication rmAuth = joinResourceManager(rmURL);
ResourceManager rm = loginToResourceManager(credentials, rmAuth);
startMonitoring(rmAuth);
for (final Node node : nodes) {
nodeSetJmxUrl(sigarExposer, node);
addNodeToResourceManager(rmURL, node, rm);
}
return rm;
}
use of org.ow2.proactive.resourcemanager.authentication.RMAuthentication in project scheduling by ow2-proactive.
the class RMNodeStarter method reconnectToResourceManager.
private ResourceManager reconnectToResourceManager() {
try {
numberOfReconnectionAttemptsLeft--;
// trying to reconnect to the resource manager
ResourceManager rm = null;
RMAuthentication rmAuth = RMConnection.waitAndJoin(rmURL, WAIT_ON_JOIN_TIMEOUT_IN_MS);
rm = rmAuth.login(credentials);
startMonitoring(rmAuth);
return rm;
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
}
return null;
}
use of org.ow2.proactive.resourcemanager.authentication.RMAuthentication in project scheduling by ow2-proactive.
the class RestFuncTHelper method startRestfulSchedulerWebapp.
public static void startRestfulSchedulerWebapp(int nbNodes) throws Exception {
// Kill all children processes on exit
org.apache.log4j.BasicConfigurator.configure(new org.apache.log4j.varia.NullAppender());
CookieBasedProcessTreeKiller.registerKillChildProcessesOnShutdown("rest_tests");
List<String> cmd = new ArrayList<>();
String javaPath = RestFuncTUtils.getJavaPathFromSystemProperties();
cmd.add(javaPath);
cmd.add("-Djava.security.manager");
cmd.add("-Dresteasy.allowGzip=true");
cmd.add("-Dfile.encoding=UTF-8");
cmd.add(CentralPAPropertyRepository.JAVA_SECURITY_POLICY.getCmdLine() + toPath(serverJavaPolicy));
cmd.add(CentralPAPropertyRepository.PA_HOME.getCmdLine() + getSchedHome());
cmd.add(PASchedulerProperties.SCHEDULER_HOME.getCmdLine() + getSchedHome());
cmd.add(PAResourceManagerProperties.RM_HOME.getCmdLine() + getRmHome());
cmd.add(PAResourceManagerProperties.RM_DB_HIBERNATE_DROPDB.getCmdLine() + System.getProperty("rm.deploy.dropDB", "true"));
cmd.add(PAResourceManagerProperties.RM_DB_HIBERNATE_CONFIG.getCmdLine() + toPath(rmHibernateConfig));
cmd.add(PASchedulerProperties.SCHEDULER_DB_HIBERNATE_DROPDB.getCmdLine() + System.getProperty("scheduler.deploy.dropDB", "true"));
cmd.add(PASchedulerProperties.SCHEDULER_DB_HIBERNATE_CONFIG.getCmdLine() + toPath(schedHibernateConfig));
cmd.add(WebProperties.WEB_HTTPS.getCmdLine() + "true");
cmd.add(CentralPAPropertyRepository.PA_COMMUNICATION_PROTOCOL.getCmdLine() + "pnp");
cmd.add(PNPConfig.PA_PNP_PORT.getCmdLine() + "1200");
cmd.add("-cp");
cmd.add(getClassPath());
cmd.add(SchedulerStarter.class.getName());
cmd.add("-ln");
cmd.add("" + nbNodes);
ProcessBuilder processBuilder = new ProcessBuilder(cmd);
processBuilder.redirectErrorStream(true);
schedProcess = processBuilder.start();
ProcessStreamReader out = new ProcessStreamReader("scheduler-output: ", schedProcess.getInputStream());
out.start();
// RM and scheduler are on the same url
String port = "1200";
String url = "pnp://localhost:" + port + "/";
// Connect a scheduler client
SchedulerAuthenticationInterface schedAuth = SchedulerConnection.waitAndJoin(url, TimeUnit.SECONDS.toMillis(120));
schedulerPublicKey = schedAuth.getPublicKey();
Credentials schedCred = RestFuncTUtils.createCredentials("admin", "admin", schedulerPublicKey);
scheduler = schedAuth.login(schedCred);
// Connect a rm client
RMAuthentication rmAuth = RMConnection.waitAndJoin(url, TimeUnit.SECONDS.toMillis(120));
Credentials rmCredentials = getRmCredentials();
rm = rmAuth.login(rmCredentials);
restServerUrl = "https://localhost:8443/rest/";
restfulSchedulerUrl = restServerUrl + "scheduler";
restfulRmUrl = restServerUrl + "rm";
await().atMost(new Duration(900, TimeUnit.SECONDS)).until(restIsStarted());
}
use of org.ow2.proactive.resourcemanager.authentication.RMAuthentication in project scheduling by ow2-proactive.
the class CreateCredentials method main.
/**
* Entry point
*
* @see org.ow2.proactive.authentication.crypto.Credentials
* @param args arguments, try '-h' for help
* @throws IOException
* @throws ParseException
*/
public static void main(String[] args) throws IOException, ParseException {
SecurityManagerConfigurator.configureSecurityManager(CreateCredentials.class.getResource("/all-permissions.security.policy").toString());
Console console = System.console();
/**
* default values
*/
boolean interactive = true;
String pubKeyPath = null;
PublicKey pubKey = null;
String login = null;
String pass = null;
String keyfile = null;
String cipher = "RSA/ECB/PKCS1Padding";
String path = Credentials.getCredentialsPath();
String rm = null;
String scheduler = null;
String url = null;
Options options = new Options();
Option opt = new Option("h", "help", false, "Display this help");
opt.setRequired(false);
options.addOption(opt);
OptionGroup group = new OptionGroup();
group.setRequired(false);
opt = new Option("F", "file", true, "Public key path on the local filesystem [default:" + Credentials.getPubKeyPath() + "]");
opt.setArgName("PATH");
opt.setArgs(1);
opt.setRequired(false);
group.addOption(opt);
opt = new Option("R", "rm", true, "Request the public key to the Resource Manager at URL");
opt.setArgName("URL");
opt.setArgs(1);
opt.setRequired(false);
group.addOption(opt);
opt = new Option("S", "scheduler", true, "Request the public key to the Scheduler at URL");
opt.setArgName("URL");
opt.setArgs(1);
opt.setRequired(false);
group.addOption(opt);
options.addOptionGroup(group);
opt = new Option("l", "login", true, "Generate credentials for this specific user, will be asked interactively if not specified");
opt.setArgName("LOGIN");
opt.setArgs(1);
opt.setRequired(false);
options.addOption(opt);
opt = new Option("p", "password", true, "Use this password, will be asked interactively if not specified");
opt.setArgName("PWD");
opt.setArgs(1);
opt.setRequired(false);
options.addOption(opt);
opt = new Option("k", "keyfile", true, "Use specified ssh private key, asked interactively if specified without PATH, not specified otherwise.");
opt.setArgName("PATH");
opt.setOptionalArg(true);
opt.setRequired(false);
options.addOption(opt);
opt = new Option("o", "output", true, "Output the resulting credentials to the specified file [default:" + path + "]");
opt.setArgName("PATH");
opt.setArgs(1);
opt.setRequired(false);
options.addOption(opt);
opt = new Option("c", "cipher", true, "Use specified cipher parameters, need to be compatible with the specified key [default:" + cipher + "]");
opt.setArgName("PARAMS");
opt.setArgs(1);
opt.setRequired(false);
options.addOption(opt);
CommandLineParser parser = new DefaultParser();
CommandLine cmd = null;
try {
cmd = parser.parse(options, args);
} catch (Exception e) {
System.err.println(newline + "ERROR : " + e.getMessage() + newline);
System.out.println("type -h or --help to display help screen");
System.exit(1);
}
if (cmd.hasOption("help")) {
displayHelp(options);
}
if (cmd.hasOption("file")) {
pubKeyPath = cmd.getOptionValue("file");
}
if (cmd.hasOption("rm")) {
rm = cmd.getOptionValue("rm");
}
if (cmd.hasOption("scheduler")) {
scheduler = cmd.getOptionValue("scheduler");
}
if (cmd.hasOption("login")) {
login = cmd.getOptionValue("login");
}
if (cmd.hasOption("password")) {
pass = cmd.getOptionValue("password");
}
if (cmd.hasOption("keyfile") && cmd.getOptionValues("keyfile") != null) {
keyfile = cmd.getOptionValue("keyfile");
}
if (cmd.hasOption("output")) {
path = cmd.getOptionValue("output");
}
if (cmd.hasOption("cipher")) {
cipher = cmd.getOptionValue("cipher");
}
int acc = 0;
if (pubKeyPath != null) {
acc++;
}
if (scheduler != null) {
url = URIBuilder.buildURI(Connection.normalize(scheduler), "SCHEDULER").toString();
acc++;
}
if (rm != null) {
url = URIBuilder.buildURI(Connection.normalize(rm), "RMAUTHENTICATION").toString();
acc++;
}
if (acc > 1) {
System.out.println("--rm, --scheduler and --file arguments cannot be combined.");
System.out.println("try -h for help.");
System.exit(1);
}
if (url != null) {
try {
Connection<AuthenticationImpl> conn = new Connection<AuthenticationImpl>(AuthenticationImpl.class) {
public Logger getLogger() {
return Logger.getLogger("pa.scheduler.credentials");
}
};
AuthenticationImpl auth = conn.connect(url);
pubKey = auth.getPublicKey();
} catch (Exception e) {
System.err.println("ERROR : Could not retrieve public key from '" + url + "'");
e.printStackTrace();
System.exit(3);
}
System.out.println("Successfully obtained public key from " + url + newline);
} else if (pubKeyPath != null) {
try {
pubKey = Credentials.getPublicKey(pubKeyPath);
} catch (KeyException e) {
System.err.println("ERROR : Could not retrieve public key from '" + pubKeyPath + "' (no such file)");
System.exit(4);
}
} else {
System.out.println("No public key specified, attempting to retrieve it from default location.");
pubKeyPath = Credentials.getPubKeyPath();
try {
pubKey = Credentials.getPublicKey(pubKeyPath);
} catch (KeyException e) {
System.err.println("ERROR : Could not retrieve public key from '" + pubKeyPath + "' (no such file)");
System.exit(5);
}
}
if (login != null && pass != null && (!cmd.hasOption("keyfile") || cmd.getOptionValues("keyfile") != null)) {
System.out.println("Running in non-interactive mode." + newline);
interactive = false;
} else {
System.out.println("Running in interactive mode.");
}
if (interactive) {
System.out.println("Please enter Scheduler credentials,");
System.out.println("they will be stored encrypted on disk for future logins." + newline);
System.out.print("login: ");
if (login == null) {
login = console.readLine();
} else {
System.out.println(login);
}
System.out.print("password: ");
if (pass == null) {
pass = new String(console.readPassword());
} else {
System.out.println("*******");
}
System.out.print("keyfile: ");
if (!cmd.hasOption("keyfile")) {
System.out.println("no key file specified");
} else if (cmd.hasOption("keyfile") && cmd.getOptionValues("keyfile") != null) {
System.out.println(keyfile);
} else {
keyfile = console.readLine();
}
}
try {
CredData credData;
if (keyfile != null && keyfile.length() > 0) {
byte[] keyfileContent = FileToBytesConverter.convertFileToByteArray(new File(keyfile));
credData = new CredData(CredData.parseLogin(login), CredData.parseDomain(login), pass, keyfileContent);
} else {
System.out.println("--> Ignoring keyfile, credential does not contain SSH key");
credData = new CredData(CredData.parseLogin(login), CredData.parseDomain(login), pass);
}
Credentials cred = Credentials.createCredentials(credData, pubKey, cipher);
cred.writeToDisk(path);
} catch (FileNotFoundException e) {
System.err.println("ERROR : Could not retrieve ssh private key from '" + keyfile + "' (no such file)");
System.exit(6);
} catch (Throwable t) {
t.printStackTrace();
System.exit(7);
}
System.out.println("Successfully stored encrypted credentials on disk at :");
System.out.println("\t" + path);
System.exit(0);
}
use of org.ow2.proactive.resourcemanager.authentication.RMAuthentication in project scheduling by ow2-proactive.
the class SchedulerStarter method startResourceManager.
private static void startResourceManager(final int numberLocalNodes, final int nodeTimeoutValue) {
final Thread rmStarter = new Thread() {
public void run() {
try {
// Starting a local RM using default deployment descriptor
RMFactory.setOsJavaProperty();
LOGGER.info("Starting the resource manager...");
RMAuthentication rmAuth = RMFactory.startLocal();
if (numberLocalNodes > 0) {
addLocalNodes(rmAuth, numberLocalNodes, nodeTimeoutValue);
}
LOGGER.info("The resource manager with " + numberLocalNodes + " local nodes created on " + rmAuth.getHostURL());
} catch (AlreadyBoundException abe) {
LOGGER.error("The resource manager already exists on local host", abe);
System.exit(4);
} catch (Exception aoce) {
LOGGER.error("Unable to create local resource manager", aoce);
System.exit(5);
}
}
};
rmStarter.start();
}
Aggregations