Search in sources :

Example 1 with ConnectionException

use of org.ow2.proactive.scheduler.common.exception.ConnectionException in project scheduling by ow2-proactive.

the class CredentialsCreator method createCredentials.

private byte[] createCredentials(String username, String password) throws ConnectionException, LoginException, KeyException {
    String url = PortalConfiguration.SCHEDULER_URL.getValueAsString();
    SchedulerAuthenticationInterface auth = SchedulerConnection.join(url);
    PublicKey pubKey = auth.getPublicKey();
    byte[] privateKey = auth.getPrivateKey();
    Credentials cred = Credentials.createCredentials(new CredData(CredData.parseLogin(username), CredData.parseDomain(username), password, privateKey), pubKey);
    byte[] credentialBytes = cred.getBase64();
    return credentialBytes;
}
Also used : PublicKey(java.security.PublicKey) CredData(org.ow2.proactive.authentication.crypto.CredData) SchedulerAuthenticationInterface(org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface) Credentials(org.ow2.proactive.authentication.crypto.Credentials)

Example 2 with ConnectionException

use of org.ow2.proactive.scheduler.common.exception.ConnectionException in project scheduling by ow2-proactive.

the class SchedulerStateRest method getCreateCredential.

/**
 * generates a credential file from user provided credentials
 *
 * @return the credential file generated by the scheduler
 * @throws LoginException
 * @throws SchedulerRestException
 */
@Override
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("createcredential")
@Produces("*/*")
public byte[] getCreateCredential(@MultipartForm LoginForm multipart) throws LoginException, SchedulerRestException {
    String username = multipart.getUsername();
    String password = multipart.getPassword();
    byte[] privKey = multipart.getSshKey();
    try {
        String url = PortalConfiguration.SCHEDULER_URL.getValueAsString();
        SchedulerAuthenticationInterface auth = SchedulerConnection.join(url);
        PublicKey pubKey = auth.getPublicKey();
        sessionStore.create(username);
        Credentials cred = Credentials.createCredentials(new CredData(CredData.parseLogin(username), CredData.parseDomain(username), password, privKey), pubKey);
        return cred.getBase64();
    } catch (ConnectionException | KeyException e) {
        throw new SchedulerRestException(e);
    }
}
Also used : PublicKey(java.security.PublicKey) CredData(org.ow2.proactive.authentication.crypto.CredData) SchedulerAuthenticationInterface(org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface) SchedulerRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.SchedulerRestException) Credentials(org.ow2.proactive.authentication.crypto.Credentials) ConnectionException(org.ow2.proactive.scheduler.common.exception.ConnectionException) KeyException(java.security.KeyException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 3 with ConnectionException

use of org.ow2.proactive.scheduler.common.exception.ConnectionException 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 = Credentials.getCredentialsBase64(credentials);
            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");
    }
}
Also used : SchedulerAuthenticationInterface(org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface) Credentials(org.ow2.proactive.authentication.crypto.Credentials) ConnectionException(org.ow2.proactive.scheduler.common.exception.ConnectionException)

Aggregations

Credentials (org.ow2.proactive.authentication.crypto.Credentials)3 SchedulerAuthenticationInterface (org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface)3 PublicKey (java.security.PublicKey)2 CredData (org.ow2.proactive.authentication.crypto.CredData)2 ConnectionException (org.ow2.proactive.scheduler.common.exception.ConnectionException)2 KeyException (java.security.KeyException)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 SchedulerRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.SchedulerRestException)1