use of org.ow2.proactive.authentication.crypto.Credentials in project scheduling by ow2-proactive.
the class SchedulerAwarePolicy method waitAndConnectToScheduler.
private void waitAndConnectToScheduler() throws Exception {
SchedulerAuthenticationInterface authentication;
boolean firstException = true;
int trialsNumber = 0;
while (scheduler == null && trialsNumber <= schedulerAwarePolicyNodeSourceRecoveryTrialsNumber) {
trialsNumber++;
try {
authentication = SchedulerConnection.join(schedulerUrl);
Credentials creds;
if (credentials != null && credentials.length > 0) {
creds = Credentials.getCredentialsBase64(credentials);
} else {
creds = nodeSource.getAdministrator().getCredentials();
}
scheduler = authentication.login(creds);
Thread.sleep(schedulerAwarePolicyNodeSourceRecoveryDelay);
} catch (Throwable t) {
if (firstException) {
logger.warn("Could not contact scheduler at url " + schedulerUrl + " this is normal if the scheduler has just been restarted", t);
firstException = false;
} else {
logger.debug("Could not contact scheduler", t);
}
}
if (trialsNumber > schedulerAwarePolicyNodeSourceRecoveryTrialsNumber)
throw new ConnectionException("Number of trials exceeded and could not contact scheduler");
}
}
use of org.ow2.proactive.authentication.crypto.Credentials in project scheduling by ow2-proactive.
the class RMAuthenticationImpl method login.
/**
* Performs user authentication
*/
public ResourceManager login(Credentials cred) throws LoginException {
Client client = new Client(authenticate(cred), true);
client.setCredentials(cred);
if (RMCore.clients.containsKey(client.getId())) {
logger.info(client + " reconnected.");
}
RMCore.clients.put(client.getId(), client);
UserHistory history = new UserHistory(client);
RMDBManager.getInstance().saveUserHistory(history);
client.setHistory(history);
logger.info(client + " connected from " + client.getId().shortString());
try {
// return the stub on ResourceManager interface to keep avoid using server class on client side
return PAActiveObject.lookupActive(ResourceManager.class, PAActiveObject.getUrl(rmcore));
} catch (ActiveObjectCreationException e) {
rethrowStubException(e);
} catch (IOException e) {
rethrowStubException(e);
}
return null;
}
use of org.ow2.proactive.authentication.crypto.Credentials in project scheduling by ow2-proactive.
the class RMNodeStarter method startMonitoring.
private void startMonitoring(RMAuthentication auth) {
if (!disabledMonitoring) {
if (sigarExposer != null) {
logger.info("Shutting down previous JMX monitoring.");
sigarExposer.shutdown();
}
// initializing JMX server with Sigar beans
sigarExposer = new SigarExposer(nodeName);
final RMAuthentication rmAuth = auth;
logger.info("Starting JMX monitoring.");
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.values().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.");
}
}
use of org.ow2.proactive.authentication.crypto.Credentials in project scheduling by ow2-proactive.
the class RMNodeStarter method loginToResourceManager.
private ResourceManager loginToResourceManager(final Credentials credentials, final RMAuthentication auth) {
try {
ResourceManager rm = auth.login(credentials);
if (rm == null) {
logger.error(ExitStatus.RM_NULL.description);
System.exit(ExitStatus.RM_NULL.exitCode);
}
return rm;
} catch (Throwable t) {
logger.error("Unable to log into the Resource Manager at " + rmURL, t);
System.exit(ExitStatus.RMNODE_ADD_ERROR.exitCode);
}
return null;
}
use of org.ow2.proactive.authentication.crypto.Credentials in project scheduling by ow2-proactive.
the class CommandLineBuilder method buildCommandLineAsList.
/**
* Same as {@link CommandLineBuilder#buildCommandLine(boolean)} but the command is a list of String.
* @param displayCredentials if true displays the credentials in the command line if false, obfuscates them
* @return The RMNodeStarter command line as a list of String.
* @throws java.io.IOException if you supplied a ProActive Configuration file that doesn't exist.
*/
public List<String> buildCommandLineAsList(boolean displayCredentials) throws IOException {
final ArrayList<String> command = new ArrayList<>();
final OperatingSystem os = targetOS;
final Properties paProp = paPropProperties;
String rmHome = this.getRmHome();
if (rmHome != null) {
if (!rmHome.endsWith(os.fs)) {
rmHome = rmHome + os.fs;
}
} else {
rmHome = "";
}
if (detached) {
makeDetachedCommand(command, os);
}
final String libRoot = rmHome + "dist" + os.fs + "lib" + os.fs;
String javaPath = this.javaPath;
if (javaPath != null) {
command.add(javaPath);
} else {
RMNodeStarter.logger.warn("Java path isn't set in RMNodeStarter configuration.");
command.add("java");
}
// building configuration
if (paProp != null) {
Set<Object> keys = paProp.keySet();
for (Object key : keys) {
command.add("-D" + key + "=" + paProp.get(key));
}
} else {
if (this.paPropList != null) {
command.addAll(this.paPropList);
}
}
// forward current charset to the forked JVM
String currentJvmCharset = PAProperties.getFileEncoding();
command.add("-Dfile.encoding=" + currentJvmCharset);
RMNodeStarter.logger.info("Using '" + currentJvmCharset + "' as file encoding");
// building classpath
command.add("-cp");
final StringBuilder classpath = new StringBuilder(".");
// add the content of addons dir on the classpath
classpath.append(os.ps).append(rmHome).append(ADDONS_DIR);
// add jars inside the addons directory
classpath.append(os.ps).append(rmHome).append(ADDONS_DIR).append(os.fs).append("*");
classpath.append(os.ps).append(libRoot).append("*");
command.add(classpath.toString());
command.add(RMNodeStarter.class.getName());
// appending options
String credsEnv = credentialsEnv;
if (credsEnv != null) {
command.add("-" + RMNodeStarter.OPTION_CREDENTIAL_ENV);
command.add(credsEnv);
}
String credsFile = this.getCredentialsFile();
if (credsFile != null) {
command.add("-" + RMNodeStarter.OPTION_CREDENTIAL_FILE);
command.add(credsFile);
}
String credsValue = this.getCredentialsValue();
if (credsValue != null) {
command.add("-" + RMNodeStarter.OPTION_CREDENTIAL_VAL);
command.add(displayCredentials ? credsValue : OBFUSC);
}
String nodename = this.getNodeName();
if (nodename != null) {
command.add("-" + RMNodeStarter.OPTION_NODE_NAME);
command.add(nodename);
}
String nodesource = this.getSourceName();
if (nodesource != null) {
command.add("-" + RMNodeStarter.OPTION_SOURCE_NAME);
command.add(nodesource);
}
String rmurl = rmURL;
if (rmurl != null) {
command.add("-" + RMNodeStarter.OPTION_RM_URL);
command.add(rmurl);
}
command.add("-" + RMNodeStarter.OPTION_WORKERS);
command.add("" + nbNodes);
if (detached && os.equals(OperatingSystem.UNIX)) {
command.add("&");
}
return command;
}
Aggregations