You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2017/09/25 21:10:48 UTC
[8/8] airavata git commit: AIRAVATA-2500 Returning/using username of
cluster account
AIRAVATA-2500 Returning/using username of cluster account
Project: http://git-wip-us.apache.org/repos/asf/airavata/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/50d7bb6a
Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/50d7bb6a
Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/50d7bb6a
Branch: refs/heads/AIRAVATA-2500
Commit: 50d7bb6a5b90966eb6cb78c1a5d95f7647345e1b
Parents: ba4982c
Author: Marcus Christie <ma...@apache.org>
Authored: Mon Sep 25 16:17:54 2017 -0400
Committer: Marcus Christie <ma...@apache.org>
Committed: Mon Sep 25 16:17:54 2017 -0400
----------------------------------------------------------------------
.../accountprovisioning/SSHAccountManager.java | 45 ++++++++++++++------
.../SSHAccountProvisioner.java | 6 ++-
.../IULdapSSHAccountProvisioner.java | 5 ++-
.../provisioner/TestSSHAccountProvisioner.java | 6 ++-
4 files changed, 44 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/airavata/blob/50d7bb6a/modules/compute-account-provisioning/src/main/java/org/apache/airavata/accountprovisioning/SSHAccountManager.java
----------------------------------------------------------------------
diff --git a/modules/compute-account-provisioning/src/main/java/org/apache/airavata/accountprovisioning/SSHAccountManager.java b/modules/compute-account-provisioning/src/main/java/org/apache/airavata/accountprovisioning/SSHAccountManager.java
index 136bbee..d6b9eb1 100644
--- a/modules/compute-account-provisioning/src/main/java/org/apache/airavata/accountprovisioning/SSHAccountManager.java
+++ b/modules/compute-account-provisioning/src/main/java/org/apache/airavata/accountprovisioning/SSHAccountManager.java
@@ -50,7 +50,16 @@ public class SSHAccountManager {
private final static Logger logger = LoggerFactory.getLogger(SSHAccountManager.class);
- public static boolean doesUserHaveSSHAccount(String gatewayId, String computeResourceId, String username) throws InvalidSetupException, InvalidUsernameException {
+ /**
+ * Check if user has an SSH account on the compute resource.
+ * @param gatewayId
+ * @param computeResourceId
+ * @param userId Airavata user id
+ * @return
+ * @throws InvalidSetupException
+ * @throws InvalidUsernameException
+ */
+ public static boolean doesUserHaveSSHAccount(String gatewayId, String computeResourceId, String userId) throws InvalidSetupException, InvalidUsernameException {
// get compute resource preferences for the gateway and hostname
RegistryService.Client registryServiceClient = getRegistryServiceClient();
@@ -75,15 +84,25 @@ public class SSHAccountManager {
SSHAccountProvisioner sshAccountProvisioner = createSshAccountProvisioner(gatewayId, computeResourcePreference);
try {
- return sshAccountProvisioner.hasAccount(username);
+ return sshAccountProvisioner.hasAccount(userId);
} catch (InvalidUsernameException e) {
throw e;
} catch (Exception e) {
- throw new RuntimeException("hasAccount call failed for username [" + username + "]: " + e.getMessage(), e);
+ throw new RuntimeException("hasAccount call failed for userId [" + userId + "]: " + e.getMessage(), e);
}
}
- public static UserComputeResourcePreference setupSSHAccount(String gatewayId, String computeResourceId, String username, SSHCredential sshCredential) throws InvalidSetupException, InvalidUsernameException {
+ /**
+ * Add SSH key to compute resource on behalf of user.
+ * @param gatewayId
+ * @param computeResourceId
+ * @param userId Airavata user id
+ * @param sshCredential
+ * @return a populated but not persisted UserComputeResourcePreference instance
+ * @throws InvalidSetupException
+ * @throws InvalidUsernameException
+ */
+ public static UserComputeResourcePreference setupSSHAccount(String gatewayId, String computeResourceId, String userId, SSHCredential sshCredential) throws InvalidSetupException, InvalidUsernameException {
// get compute resource preferences for the gateway and hostname
RegistryService.Client registryServiceClient = getRegistryServiceClient();
@@ -127,32 +146,34 @@ public class SSHAccountManager {
SSHAccountProvisioner sshAccountProvisioner = createSshAccountProvisioner(gatewayId, computeResourcePreference);
boolean canCreateAccount = SSHAccountProvisionerFactory.canCreateAccount(computeResourcePreference.getSshAccountProvisioner());
- // First check if username has an account
+ // First check if userId has an account
boolean hasAccount = false;
try {
- hasAccount = sshAccountProvisioner.hasAccount(username);
+ hasAccount = sshAccountProvisioner.hasAccount(userId);
} catch (InvalidUsernameException e) {
throw e;
} catch (Exception e) {
- throw new RuntimeException("hasAccount call failed for username [" + username + "]: " + e.getMessage(), e);
+ throw new RuntimeException("hasAccount call failed for userId [" + userId + "]: " + e.getMessage(), e);
}
if (!hasAccount && !canCreateAccount) {
- throw new InvalidSetupException("User [" + username + "] doesn't have account and [" + computeResourceId + "] doesn't " +
+ throw new InvalidSetupException("User [" + userId + "] doesn't have account and [" + computeResourceId + "] doesn't " +
"have a SSH Account Provisioner that supports creating accounts.");
}
+ // TODO: create account for user if user doesn't have account
+ String username = null;
// Install SSH key
try {
- sshAccountProvisioner.installSSHKey(username, sshCredential.getPublicKey());
+ username = sshAccountProvisioner.installSSHKey(userId, sshCredential.getPublicKey());
} catch (InvalidUsernameException e) {
throw e;
} catch (Exception e) {
- throw new RuntimeException("installSSHKey call failed for username [" + username + "]: " + e.getMessage(), e);
+ throw new RuntimeException("installSSHKey call failed for userId [" + userId + "]: " + e.getMessage(), e);
}
// Verify can authenticate to host
- String sshHostname = sshJobSubmission.getAlternativeSSHHostName() != null ? sshJobSubmission.getAlternativeSSHHostName() : computeResourceDescription.getHostName();
+ String sshHostname = getSSHHostname(computeResourceDescription, sshJobSubmission);
int sshPort = sshJobSubmission.getSshPort();
boolean validated = false;
try {
@@ -168,7 +189,7 @@ public class SSHAccountManager {
}
// create the scratch location on the host
- String scratchLocation = sshAccountProvisioner.getScratchLocation(username);
+ String scratchLocation = sshAccountProvisioner.getScratchLocation(userId);
try {
SSHUtil.execute(sshHostname, sshPort, username, sshCredential, "mkdir -p " + scratchLocation);
} catch (Exception e) {
http://git-wip-us.apache.org/repos/asf/airavata/blob/50d7bb6a/modules/compute-account-provisioning/src/main/java/org/apache/airavata/accountprovisioning/SSHAccountProvisioner.java
----------------------------------------------------------------------
diff --git a/modules/compute-account-provisioning/src/main/java/org/apache/airavata/accountprovisioning/SSHAccountProvisioner.java b/modules/compute-account-provisioning/src/main/java/org/apache/airavata/accountprovisioning/SSHAccountProvisioner.java
index 395b622..6ad076d 100644
--- a/modules/compute-account-provisioning/src/main/java/org/apache/airavata/accountprovisioning/SSHAccountProvisioner.java
+++ b/modules/compute-account-provisioning/src/main/java/org/apache/airavata/accountprovisioning/SSHAccountProvisioner.java
@@ -50,17 +50,19 @@ public interface SSHAccountProvisioner {
* unimplemented for this SSHAccountProvisioner.
* @param userId the Airavata user id
* @param sshPublicKey the public key part of an Airavata managed SSH credential
+ * @return username
* @throws InvalidUsernameException
*/
- void createAccount(String userId, String sshPublicKey) throws InvalidUsernameException;
+ String createAccount(String userId, String sshPublicKey) throws InvalidUsernameException;
/**
* Install an SSH key for the user on the compute host.
* @param userId the Airavata user id
* @param sshPublicKey the public key part of an Airavata managed SSH credential
+ * @return username
* @throws InvalidUsernameException
*/
- void installSSHKey(String userId, String sshPublicKey) throws InvalidUsernameException;
+ String installSSHKey(String userId, String sshPublicKey) throws InvalidUsernameException;
/**
* Get the scratch location that should be created for the user. Note: this method doesn't create the scratch
http://git-wip-us.apache.org/repos/asf/airavata/blob/50d7bb6a/modules/compute-account-provisioning/src/main/java/org/apache/airavata/accountprovisioning/provisioner/IULdapSSHAccountProvisioner.java
----------------------------------------------------------------------
diff --git a/modules/compute-account-provisioning/src/main/java/org/apache/airavata/accountprovisioning/provisioner/IULdapSSHAccountProvisioner.java b/modules/compute-account-provisioning/src/main/java/org/apache/airavata/accountprovisioning/provisioner/IULdapSSHAccountProvisioner.java
index 69ed3f6..8e717c3 100644
--- a/modules/compute-account-provisioning/src/main/java/org/apache/airavata/accountprovisioning/provisioner/IULdapSSHAccountProvisioner.java
+++ b/modules/compute-account-provisioning/src/main/java/org/apache/airavata/accountprovisioning/provisioner/IULdapSSHAccountProvisioner.java
@@ -76,13 +76,13 @@ public class IULdapSSHAccountProvisioner implements SSHAccountProvisioner {
}
@Override
- public void createAccount(String userId, String sshPublicKey) throws InvalidUsernameException {
+ public String createAccount(String userId, String sshPublicKey) throws InvalidUsernameException {
throw new UnsupportedOperationException("IULdapSSHAccountProvisioner does not support creating cluster accounts at this time.");
}
@Override
- public void installSSHKey(String userId, String sshPublicKey) throws InvalidUsernameException {
+ public String installSSHKey(String userId, String sshPublicKey) throws InvalidUsernameException {
String username = getUsername(userId);
boolean success = withLdapConnection(ldapConnection -> {
try {
@@ -127,6 +127,7 @@ public class IULdapSSHAccountProvisioner implements SSHAccountProvisioner {
throw new RuntimeException(e);
}
});
+ return username;
}
@Override
http://git-wip-us.apache.org/repos/asf/airavata/blob/50d7bb6a/modules/compute-account-provisioning/src/test/java/org/apache/airavata/accountprovisioning/provisioner/TestSSHAccountProvisioner.java
----------------------------------------------------------------------
diff --git a/modules/compute-account-provisioning/src/test/java/org/apache/airavata/accountprovisioning/provisioner/TestSSHAccountProvisioner.java b/modules/compute-account-provisioning/src/test/java/org/apache/airavata/accountprovisioning/provisioner/TestSSHAccountProvisioner.java
index f4f9958..4cdcbd6 100644
--- a/modules/compute-account-provisioning/src/test/java/org/apache/airavata/accountprovisioning/provisioner/TestSSHAccountProvisioner.java
+++ b/modules/compute-account-provisioning/src/test/java/org/apache/airavata/accountprovisioning/provisioner/TestSSHAccountProvisioner.java
@@ -42,13 +42,15 @@ public class TestSSHAccountProvisioner implements SSHAccountProvisioner {
}
@Override
- public void createAccount(String userId, String sshPublicKey) throws InvalidUsernameException {
+ public String createAccount(String userId, String sshPublicKey) throws InvalidUsernameException {
+ return userId;
}
@Override
- public void installSSHKey(String userId, String sshPublicKey) throws InvalidUsernameException {
+ public String installSSHKey(String userId, String sshPublicKey) throws InvalidUsernameException {
+ return userId;
}
@Override