use of org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile in project airavata by apache.
the class AiravataServerHandler method getGatewayResourceProfile.
/**
* Fetch the given Gateway Resource Profile.
*
* @param gatewayID The identifier for the requested gateway resource
* @return gatewayResourceProfile
* Gateway Resource Profile Object.
*/
@Override
@SecurityCheck
public GatewayResourceProfile getGatewayResourceProfile(AuthzToken authzToken, String gatewayID) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException {
RegistryService.Client regClient = registryClientPool.getResource();
try {
GatewayResourceProfile result = regClient.getGatewayResourceProfile(gatewayID);
registryClientPool.returnResource(regClient);
return result;
} catch (Exception e) {
logger.error(gatewayID, "Error while retrieving gateway resource profile...", e);
AiravataSystemException exception = new AiravataSystemException();
exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
exception.setMessage("Error while retrieving gateway resource profile. More info : " + e.getMessage());
registryClientPool.returnBrokenResource(regClient);
throw exception;
}
}
use of org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile in project airavata by apache.
the class GatewayRegister method createGateway.
public void createGateway() throws Exception {
try {
// read gateway count from properties file
List<GatewayResourceProfile> gateReourceProfiles = airavata.getAllGatewayResourceProfiles(authzToken);
for (GatewayResourceProfile gatewayResourceProfile : gateReourceProfiles) {
if (gatewayResourceProfile.getGatewayID().equals(properties.getGname())) {
createProject(gatewayResourceProfile.getGatewayID());
return;
}
}
String genericGatewayName = properties.getGname();
String genericGatewayDomain = properties.getGdomain();
Gateway gateway = new Gateway();
String gatewayId = genericGatewayName;
gateway.setGatewayId(gatewayId);
gateway.setGatewayName(gatewayId);
gateway.setDomain(gatewayId + genericGatewayDomain);
gateway.setGatewayApprovalStatus(GatewayApprovalStatus.APPROVED);
airavata.addGateway(authzToken, gateway);
String token = airavata.generateAndRegisterSSHKeys(authzToken, gatewayId, testUser, testUser, CredentialOwnerType.USER);
GatewayResourceProfile gatewayResourceProfile = new GatewayResourceProfile();
gatewayResourceProfile.setCredentialStoreToken(token);
gatewayResourceProfile.setGatewayID(gatewayId);
airavata.registerGatewayResourceProfile(authzToken, gatewayResourceProfile);
createProject(gatewayId);
} catch (AiravataSystemException e) {
logger.error("Error while creating airavata client instance", e);
throw new Exception("Error while creating airavata client instance", e);
} catch (InvalidRequestException e) {
logger.error("Invalid request for airavata client instance", e);
throw new Exception("Invalid request for airavata client instance", e);
} catch (AiravataClientException e) {
logger.error("Error while creating airavata client instance", e);
throw new Exception("Error while creating airavata client instance", e);
} catch (TException e) {
logger.error("Error while communicating with airavata client ", e);
throw new Exception("Error while communicating with airavata client", e);
}
}
use of org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile in project airavata by apache.
the class MigrationManager method migrateGatewayProfileToAiravata.
private boolean migrateGatewayProfileToAiravata() throws TException {
TenantProfileService.Client tenantProfileServiceClient = getTenantProfileServiceClient();
Airavata.Client airavataClient = airavataServiceSecure ? getAiravataSecureClient() : getAiravataClient();
IamAdminServices.Client iamAdminServicesClient = getIamAdminServicesClient();
// Get Gateway from Airavata API
Gateway gateway = airavataClient.getGateway(authzToken, gatewayId);
if (!GatewayApprovalStatus.APPROVED.equals(gateway.getGatewayApprovalStatus())) {
throw new RuntimeException("Gateway " + gatewayId + " is not APPROVED! Status is " + gateway.getGatewayApprovalStatus());
}
// Add Gateway through TenantProfileService
if (!tenantProfileServiceClient.isGatewayExist(authzToken, gatewayId)) {
System.out.println("Gateway [" + gatewayId + "] doesn't exist, adding in Profile Service...");
String airavataInternalGatewayId = tenantProfileServiceClient.addGateway(authzToken, gateway);
gateway.setAiravataInternalGatewayId(airavataInternalGatewayId);
} else {
System.out.println("Gateway [" + gatewayId + "] already exists in Profile Service");
gateway = tenantProfileServiceClient.getGateway(authzToken, gatewayId);
}
// Gateway URL is required by IAM Admin Services
if (gateway.getGatewayURL() == null) {
gateway.setGatewayURL(this.gatewayURL);
}
// Following are also required by IAM Admin Services in order to create an admin user for the realm
if (gateway.getIdentityServerUserName() == null) {
gateway.setIdentityServerUserName(this.gatewayAdminUsername);
}
if (gateway.getGatewayAdminFirstName() == null) {
gateway.setGatewayAdminFirstName(this.gatewayAdminFirstName);
}
if (gateway.getGatewayAdminLastName() == null) {
gateway.setGatewayAdminLastName(this.gatewayAdminLastName);
}
if (gateway.getGatewayAdminEmail() == null) {
gateway.setGatewayAdminEmail(this.gatewayAdminEmailAddress);
}
// Add Keycloak Tenant for Gateway
System.out.println("Creating Keycloak Tenant for gateway ...");
Gateway gatewayWithIdAndSecret = iamAdminServicesClient.setUpGateway(authzToken, gateway);
// Update Gateway profile with the client id and secret
System.out.println("Updating gateway with OAuth client id and secret ...");
tenantProfileServiceClient.updateGateway(authzToken, gatewayWithIdAndSecret);
KeycloakIdentityServerClient keycloakIdentityServerClient = getKeycloakIdentityServerClient();
// Set the admin user's password to the same as it was for wso2IS
keycloakIdentityServerClient.setUserPassword(gatewayId, this.gatewayAdminUsername, this.wso2ISAdminPassword);
// Create password credential for admin username and password
String passwordToken = airavataClient.registerPwdCredential(authzToken, gatewayId, this.gatewayAdminUsername, this.gatewayAdminUsername, this.wso2ISAdminPassword, "Keycloak admin password for realm " + gatewayId);
// Update gateway resource profile with tenant id (gatewayId) and admin user password token
GatewayResourceProfile gatewayResourceProfile = airavataClient.getGatewayResourceProfile(authzToken, gatewayId);
gatewayResourceProfile.setIdentityServerTenant(gatewayId);
gatewayResourceProfile.setIdentityServerPwdCredToken(passwordToken);
airavataClient.updateGatewayResourceProfile(authzToken, gatewayId, gatewayResourceProfile);
return true;
}
use of org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile in project airavata by apache.
the class RegistryServerHandler method updateGatewayStoragePreference.
/**
* Update a Storage Resource Preference of a registered gateway profile.
*
* @param gatewayID The identifier of the gateway profile to be updated.
* @param storageId The Storage resource identifier of the one that you want to update
* @param storagePreference The storagePreference object to be updated to the resource profile.
* @return status
* Returns a success/failure of the updation.
*/
@Override
public boolean updateGatewayStoragePreference(String gatewayID, String storageId, StoragePreference storagePreference) throws RegistryServiceException, TException {
try {
if (!isGatewayExistInternal(gatewayID)) {
logger.error("Gateway does not exist.Please provide a valid gateway id...");
throw new RegistryServiceException("Gateway does not exist.Please provide a valid gateway id...");
}
appCatalog = RegistryFactory.getAppCatalog();
GwyResourceProfile gatewayProfile = appCatalog.getGatewayProfile();
GatewayResourceProfile profile = gatewayProfile.getGatewayProfile(gatewayID);
List<StoragePreference> dataStoragePreferences = profile.getStoragePreferences();
StoragePreference preferenceToRemove = null;
for (StoragePreference preference : dataStoragePreferences) {
if (preference.getStorageResourceId().equals(storageId)) {
preferenceToRemove = preference;
break;
}
}
if (preferenceToRemove != null) {
profile.getStoragePreferences().remove(preferenceToRemove);
}
profile.getStoragePreferences().add(storagePreference);
gatewayProfile.updateGatewayResourceProfile(gatewayID, profile);
logger.debug("Airavata updated storage resource preference with gateway id : " + gatewayID + " and for storage resource id : " + storageId);
return true;
} catch (AppCatalogException e) {
logger.error(gatewayID, "Error while reading gateway data storage preference...", e);
RegistryServiceException exception = new RegistryServiceException();
exception.setMessage("Error while updating gateway data storage preference. More info : " + e.getMessage());
throw exception;
}
}
use of org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile in project airavata by apache.
the class RegistryServerHandler method getGatewayResourceProfile.
/**
* Fetch the given Gateway Resource Profile.
*
* @param gatewayID The identifier for the requested gateway resource.
* @return gatewayResourceProfile
* Gateway Resource Profile Object.
*/
@Override
public GatewayResourceProfile getGatewayResourceProfile(String gatewayID) throws RegistryServiceException, TException {
try {
if (!isGatewayExistInternal(gatewayID)) {
logger.error("Gateway does not exist.Please provide a valid gateway id...");
throw new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR);
}
appCatalog = RegistryFactory.getAppCatalog();
GwyResourceProfile gatewayProfile = appCatalog.getGatewayProfile();
GatewayResourceProfile gatewayResourceProfile = gatewayProfile.getGatewayProfile(gatewayID);
logger.debug("Airavata retrieved gateway profile with gateway id : " + gatewayID);
return gatewayResourceProfile;
} catch (AppCatalogException e) {
logger.error(gatewayID, "Error while retrieving gateway resource profile...", e);
RegistryServiceException exception = new RegistryServiceException();
exception.setMessage("Error while retrieving gateway resource profile. More info : " + e.getMessage());
throw exception;
}
}
Aggregations