use of org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference in project airavata by apache.
the class UsrResourceProfileImpl method addUserResourceProfile.
@Override
public String addUserResourceProfile(org.apache.airavata.model.appcatalog.userresourceprofile.UserResourceProfile userResourceProfile) throws AppCatalogException {
try {
UserResourceProfileResource profileResource = new UserResourceProfileResource();
if (!userResourceProfile.getUserId().equals("")) {
profileResource.setUserId(userResourceProfile.getUserId());
}
if (!userResourceProfile.getGatewayID().equals("")) {
profileResource.setGatewayID(userResourceProfile.getGatewayID());
}
if (userResourceProfile.getCredentialStoreToken() != null) {
profileResource.setCredentialStoreToken(userResourceProfile.getCredentialStoreToken());
}
if (userResourceProfile.getIdentityServerTenant() != null) {
profileResource.setIdentityServerTenant(userResourceProfile.getIdentityServerTenant());
}
if (userResourceProfile.getIdentityServerPwdCredToken() != null) {
profileResource.setIdentityServerPwdCredToken(userResourceProfile.getIdentityServerPwdCredToken());
}
profileResource.setUserId(userResourceProfile.getUserId());
profileResource.setGatewayID(userResourceProfile.getGatewayID());
profileResource.save();
List<UserComputeResourcePreference> userComputeResourcePreferences = userResourceProfile.getUserComputeResourcePreferences();
if (userComputeResourcePreferences != null && !userComputeResourcePreferences.isEmpty()) {
for (UserComputeResourcePreference preference : userComputeResourcePreferences) {
UserComputeHostPreferenceResource resource = new UserComputeHostPreferenceResource();
resource.setUserResourceProfileResource(profileResource);
resource.setResourceId(preference.getComputeResourceId());
ComputeResourceResource computeHostResource = new ComputeResourceResource();
resource.setComputeHostResource((ComputeResourceResource) computeHostResource.get(preference.getComputeResourceId()));
resource.setGatewayId(profileResource.getGatewayID());
resource.setUserId(profileResource.getUserId());
resource.setLoginUserName(preference.getLoginUserName());
resource.setResourceCSToken(preference.getResourceSpecificCredentialStoreToken());
resource.setBatchQueue(preference.getPreferredBatchQueue());
resource.setProjectNumber(preference.getAllocationProjectNumber());
resource.setScratchLocation(preference.getScratchLocation());
resource.setQualityOfService(preference.getQualityOfService());
resource.setReservation(preference.getReservation());
if (preference.getReservationStartTime() > 0) {
resource.setReservationStartTime(AiravataUtils.getTime(preference.getReservationStartTime()));
}
if (preference.getReservationEndTime() > 0) {
resource.setReservationEndTime(AiravataUtils.getTime(preference.getReservationEndTime()));
}
resource.setValidated(preference.isValidated());
resource.save();
}
}
List<UserStoragePreference> dataStoragePreferences = userResourceProfile.getUserStoragePreferences();
if (dataStoragePreferences != null && !dataStoragePreferences.isEmpty()) {
for (UserStoragePreference storagePreference : dataStoragePreferences) {
UserStoragePreferenceResource resource = new UserStoragePreferenceResource();
resource.setStorageResourceId(storagePreference.getStorageResourceId());
resource.setGatewayId(profileResource.getGatewayID());
resource.setUserId(profileResource.getUserId());
resource.setFsRootLocation(storagePreference.getFileSystemRootLocation());
resource.setLoginUserName(storagePreference.getLoginUserName());
resource.setResourceCSToken(storagePreference.getResourceSpecificCredentialStoreToken());
resource.setUserResourceProfileResource(profileResource);
resource.save();
}
}
return profileResource.getGatewayID();
} catch (Exception e) {
logger.error("Error while saving gateway profile...", e);
throw new AppCatalogException(e);
}
}
use of org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference in project airavata by apache.
the class RegistryServerHandler method getUserComputeResourcePreference.
/**
* Fetch a Compute Resource Preference of a registered gateway profile.
* @param userId
* @param gatewayID The identifier for the gateway profile to be requested
* @param userComputeResourceId Preferences related to a particular compute resource
* @return computeResourcePreference
* Returns the ComputeResourcePreference object.
*/
@Override
public UserComputeResourcePreference getUserComputeResourcePreference(String userId, String gatewayID, String userComputeResourceId) throws RegistryServiceException, TException {
try {
if (!ExpCatResourceUtils.isUserExist(userId, gatewayID)) {
logger.error("user does not exist.Please provide a valid user id...");
throw new RegistryServiceException("user does not exist.Please provide a valid user id...");
}
appCatalog = RegistryFactory.getAppCatalog();
appCatalog = RegistryFactory.getAppCatalog();
UsrResourceProfile userProfile = appCatalog.getUserResourceProfile();
if (!userProfile.isUserResourceProfileExists(userId, gatewayID)) {
throw new RegistryServiceException("User resource profile with user id'" + userId + " & gateway Id" + gatewayID + "' does not exist!!!");
}
ComputeResource computeResource = appCatalog.getComputeResource();
if (!computeResource.isComputeResourceExists(userComputeResourceId)) {
logger.error(userComputeResourceId, "Given compute resource does not exist in the system. Please provide a valid compute resource id...");
RegistryServiceException exception = new RegistryServiceException();
exception.setMessage("Given compute resource does not exist in the system. Please provide a valid compute resource id...");
throw exception;
}
UserComputeResourcePreference userComputeResourcePreference = userProfile.getUserComputeResourcePreference(userId, gatewayID, userComputeResourceId);
logger.debug("Airavata retrieved user compute resource preference with gateway id : " + gatewayID + " and for compute resoruce id : " + userComputeResourceId);
return userComputeResourcePreference;
} catch (AppCatalogException e) {
logger.error(gatewayID, "Error while reading user compute resource preference...", e);
RegistryServiceException exception = new RegistryServiceException();
exception.setMessage("Error while reading user compute resource preference. More info : " + e.getMessage());
throw exception;
} catch (RegistryException e) {
logger.error(userId, "Error while retrieving user resource profile...", e);
RegistryServiceException exception = new RegistryServiceException();
exception.setMessage("Error while retrieving user resource profile. More info : " + e.getMessage());
throw exception;
}
}
use of org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference in project airavata by apache.
the class AiravataServerHandler method setupUserComputeResourcePreferencesForSSH.
@Override
@SecurityCheck
public UserComputeResourcePreference setupUserComputeResourcePreferencesForSSH(AuthzToken authzToken, String computeResourceId, String userId, String airavataCredStoreToken) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException {
String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID);
CredentialStoreService.Client csClient = csClientPool.getResource();
SSHCredential sshCredential = null;
try {
sshCredential = csClient.getSSHCredential(airavataCredStoreToken, gatewayId);
} catch (Exception e) {
logger.error("Error occurred while retrieving SSH Credential", e);
AiravataSystemException exception = new AiravataSystemException();
exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
exception.setMessage("Error occurred while retrieving SSH Credential. More info : " + e.getMessage());
csClientPool.returnBrokenResource(csClient);
throw exception;
}
try {
UserComputeResourcePreference userComputeResourcePreference = SSHAccountManager.setupSSHAccount(gatewayId, computeResourceId, userId, sshCredential);
return userComputeResourcePreference;
} catch (Exception e) {
logger.error("Error occurred while automatically setting up SSH account for user [" + userId + "]", e);
AiravataSystemException exception = new AiravataSystemException();
exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
exception.setMessage("Error occurred while automatically setting up SSH account for user [" + userId + "]. More info : " + e.getMessage());
throw exception;
}
}
use of org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference in project airavata by apache.
the class AiravataServerHandler method getUserComputeResourcePreference.
/**
* Fetch a Compute Resource Preference of a registered User Resource profile.
*
* @param userId : The identifier for the User Resource profile to be requested
* @param gatewayID The identifier to link a gateway for the requested User resource
* @param userComputeResourceId Preferences related to a particular compute resource
* @return computeResourcePreference
* Returns the ComputeResourcePreference object.
*/
@Override
@SecurityCheck
public UserComputeResourcePreference getUserComputeResourcePreference(AuthzToken authzToken, String userId, String gatewayID, String userComputeResourceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException {
RegistryService.Client regClient = registryClientPool.getResource();
try {
UserComputeResourcePreference result = regClient.getUserComputeResourcePreference(userId, gatewayID, userComputeResourceId);
registryClientPool.returnResource(regClient);
return result;
} catch (Exception e) {
logger.error(userId, "Error while reading user compute resource preference...", e);
AiravataSystemException exception = new AiravataSystemException();
exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
exception.setMessage("Error while reading user compute resource preference. More info : " + e.getMessage());
registryClientPool.returnBrokenResource(regClient);
throw exception;
}
}
Aggregations