use of org.apache.airavata.model.appcatalog.userresourceprofile.UserResourceProfile in project airavata by apache.
the class UserResourceProfileTest method userProfileTest.
@Test
public void userProfileTest() throws Exception {
UsrResourceProfile userProfile = appcatalog.getUserResourceProfile();
UserResourceProfile uf = new UserResourceProfile();
ComputeResource computeRs = appcatalog.getComputeResource();
ComputeResourceDescription cm1 = new ComputeResourceDescription();
cm1.setHostName("localhost");
cm1.setResourceDescription("test compute host");
String hostId1 = computeRs.addComputeResource(cm1);
ComputeResourceDescription cm2 = new ComputeResourceDescription();
cm2.setHostName("localhost");
cm2.setResourceDescription("test compute host");
String hostId2 = computeRs.addComputeResource(cm2);
UserComputeResourcePreference preference1 = new UserComputeResourcePreference();
preference1.setComputeResourceId(hostId1);
preference1.setPreferredBatchQueue("queue1");
preference1.setScratchLocation("/tmp");
preference1.setAllocationProjectNumber("project1");
UserComputeResourcePreference preference2 = new UserComputeResourcePreference();
preference2.setComputeResourceId(hostId2);
preference2.setPreferredBatchQueue("queue2");
preference2.setScratchLocation("/tmp");
preference2.setAllocationProjectNumber("project2");
UserStoragePreference storagePreference = new UserStoragePreference();
storagePreference.setStorageResourceId("st3");
storagePreference.setLoginUserName("Anuj");
storagePreference.setFileSystemRootLocation("/home/Anuj/scratch/");
List<UserComputeResourcePreference> list = new ArrayList<UserComputeResourcePreference>();
list.add(preference1);
list.add(preference2);
List<UserStoragePreference> stList = new ArrayList<>();
stList.add(storagePreference);
uf.setUserComputeResourcePreferences(list);
uf.setGatewayID("airavataPGA");
uf.setUserId("Anuj");
uf.setUserStoragePreferences(stList);
// Check if UserResourceProfile exists (should not exist)
// This tests the mechanism that PGA will use to figure out if a user doesn't already have a UserResourceProfile
UserResourceProfile checkUserResourceProfile = userProfile.getUserResourceProfile(uf.getUserId(), uf.getGatewayID());
assertNotNull(checkUserResourceProfile.getUserId());
assertNotNull(checkUserResourceProfile.getGatewayID());
assertTrue(checkUserResourceProfile.isIsNull());
String gwId = userProfile.addUserResourceProfile(uf);
UserResourceProfile retrievedProfile = null;
// This test is to check whether an existing user can add more compute preferences - AIRAVATA-2245
System.out.println("*********Start Airavata-2245************");
ComputeResource computeRs1 = appcatalog.getComputeResource();
ComputeResourceDescription cm12 = new ComputeResourceDescription();
cm12.setHostName("localhost123");
cm12.setResourceDescription("test compute host");
String hostId12 = computeRs1.addComputeResource(cm12);
UserComputeResourcePreference preference12 = new UserComputeResourcePreference();
preference12.setComputeResourceId(hostId12);
preference12.setPreferredBatchQueue("queue112");
preference12.setScratchLocation("/tmp21");
preference12.setAllocationProjectNumber("project12");
List<UserComputeResourcePreference> list12 = new ArrayList<UserComputeResourcePreference>();
list12.add(preference12);
UserResourceProfile uf12 = new UserResourceProfile();
uf12.setUserComputeResourcePreferences(list12);
uf12.setGatewayID("airavataPGA");
uf12.setUserId("Anuj");
String gwId12 = userProfile.addUserResourceProfile(uf12);
System.out.println("*******End Airavata-2245******* : success");
// retrievedProfile = userProfile.getUserResourceProfile("hello",uf.getGatewayID());
if (userProfile.isUserResourceProfileExists(uf.getUserId(), uf.getGatewayID())) {
retrievedProfile = userProfile.getUserResourceProfile(uf.getUserId(), uf.getGatewayID());
assertFalse(retrievedProfile.isIsNull());
System.out.println("gateway ID :" + retrievedProfile.getGatewayID());
System.out.println("user ID : " + retrievedProfile.getUserId());
System.out.println("compute resource size : " + retrievedProfile.getUserComputeResourcePreferencesSize());
}
if (retrievedProfile != null) {
List<UserComputeResourcePreference> preferences = userProfile.getAllUserComputeResourcePreferences(retrievedProfile.getUserId(), retrievedProfile.getGatewayID());
System.out.println("compute preferences size : " + preferences.size());
if (preferences != null && !preferences.isEmpty()) {
for (UserComputeResourcePreference cm : preferences) {
System.out.println("******** host id ********* : " + cm.getComputeResourceId());
System.out.println(cm.getPreferredBatchQueue());
// this statement will remove all the compute resources created
System.out.println("Compute Preference removed : " + userProfile.removeUserComputeResourcePreferenceFromGateway(retrievedProfile.getUserId(), retrievedProfile.getGatewayID(), cm.getComputeResourceId()));
}
}
List<UserStoragePreference> storagePreferences = userProfile.getAllUserStoragePreferences(retrievedProfile.getUserId(), retrievedProfile.getGatewayID());
System.out.println("storage preferences size : " + storagePreferences.size());
if (storagePreferences != null && !storagePreferences.isEmpty()) {
for (UserStoragePreference cm : storagePreferences) {
System.out.println("******** storage id ********* : " + cm.getStorageResourceId());
System.out.println(cm.getFileSystemRootLocation());
// this statement will remove all the compute resources created
System.out.println("Storage Preference removed : " + userProfile.removeUserDataStoragePreferenceFromGateway(retrievedProfile.getUserId(), retrievedProfile.getGatewayID(), cm.getStorageResourceId()));
}
}
// remove the user resource profile created.
System.out.println("User Resource profile removed : " + userProfile.removeUserResourceProfile(retrievedProfile.getUserId(), retrievedProfile.getGatewayID()));
} else {
System.out.println("User resource profile is null");
}
assertTrue("App interface saved successfully", retrievedProfile != null);
}
use of org.apache.airavata.model.appcatalog.userresourceprofile.UserResourceProfile in project airavata by apache.
the class AppCatalogThriftConversion method createNullUserResourceProfile.
public static UserResourceProfile createNullUserResourceProfile(String userId, String gatewayId) {
UserResourceProfile userResourceProfile = new UserResourceProfile(userId, gatewayId);
userResourceProfile.setIsNull(true);
return userResourceProfile;
}
use of org.apache.airavata.model.appcatalog.userresourceprofile.UserResourceProfile in project airavata by apache.
the class UsrResourceProfileImpl method getAllUserResourceProfiles.
@Override
public List<UserResourceProfile> getAllUserResourceProfiles() throws AppCatalogException {
try {
List<UserResourceProfile> gatewayResourceProfileList = new ArrayList<UserResourceProfile>();
UserResourceProfileResource profileResource = new UserResourceProfileResource();
List<AppCatalogResource> resourceList = profileResource.getAll();
if (resourceList != null && !resourceList.isEmpty()) {
for (AppCatalogResource resource : resourceList) {
UserResourceProfileResource userProfileResource = (UserResourceProfileResource) resource;
List<UserComputeResourcePreference> computeResourcePreferences = getAllUserComputeResourcePreferences(userProfileResource.getUserId(), userProfileResource.getGatewayID());
List<UserStoragePreference> dataStoragePreferences = getAllUserStoragePreferences(userProfileResource.getUserId(), userProfileResource.getGatewayID());
UserResourceProfile gatewayResourceProfile = AppCatalogThriftConversion.getUserResourceProfile(userProfileResource, computeResourcePreferences, dataStoragePreferences);
gatewayResourceProfileList.add(gatewayResourceProfile);
}
}
return gatewayResourceProfileList;
} catch (Exception e) {
logger.error("Error while retrieving user resource profiles...", e);
throw new AppCatalogException(e);
}
}
use of org.apache.airavata.model.appcatalog.userresourceprofile.UserResourceProfile in project airavata by apache.
the class AppCatalogThriftConversion method getUserResourceProfile.
public static UserResourceProfile getUserResourceProfile(UserResourceProfileResource gw, List<UserComputeResourcePreference> preferences, List<UserStoragePreference> storagePreferences) {
UserResourceProfile userResourceProfile = new UserResourceProfile();
userResourceProfile.setGatewayID(gw.getGatewayID());
userResourceProfile.setUserId(gw.getUserId());
userResourceProfile.setCredentialStoreToken(gw.getCredentialStoreToken());
userResourceProfile.setIdentityServerTenant(gw.getIdentityServerTenant());
userResourceProfile.setIdentityServerPwdCredToken(gw.getIdentityServerPwdCredToken());
userResourceProfile.setUserComputeResourcePreferences(preferences);
userResourceProfile.setUserStoragePreferences(storagePreferences);
return userResourceProfile;
}
use of org.apache.airavata.model.appcatalog.userresourceprofile.UserResourceProfile in project airavata by apache.
the class RegistryServerHandler method addUserComputeResourcePreference.
/**
* Add a User Compute Resource Preference to a registered gateway profile.
* @param userId
* @param gatewayID The identifier for the gateway profile to be added.
* @param computeResourceId Preferences related to a particular compute resource
* @param userComputeResourcePreference The UserComputeResourcePreference object to be added to the resource profile.
* @return status
* Returns a success/failure of the addition. If a profile already exists, this operation will fail.
* Instead an update should be used.
*/
@Override
public boolean addUserComputeResourcePreference(String userId, String gatewayID, String computeResourceId, UserComputeResourcePreference userComputeResourcePreference) 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();
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!!!");
}
UserResourceProfile profile = userProfile.getUserResourceProfile(userId, gatewayID);
// gatewayProfile.removeGatewayResourceProfile(gatewayID);
profile.addToUserComputeResourcePreferences(userComputeResourcePreference);
userProfile.updateUserResourceProfile(userId, gatewayID, profile);
logger.debug("Airavata added User compute resource preference with gateway id : " + gatewayID + " and for compute resource id : " + computeResourceId);
return true;
} catch (AppCatalogException e) {
logger.error(gatewayID, "Error while registering User resource profile preference...", e);
RegistryServiceException exception = new RegistryServiceException();
exception.setMessage("Error while registering user resource profile 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;
}
}
Aggregations