use of org.apache.airavata.model.workspace.Gateway 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.workspace.Gateway in project airavata by apache.
the class GatewayRegister method writeToken.
public String writeToken() throws Exception {
String tokenWriteLocation = properties.getTokenFileLoc();
String fileName = tokenWriteLocation + File.separator + TestFrameworkConstants.CredentialStoreConstants.TOKEN_FILE_NAME;
Gateway gateway = airavata.getGateway(authzToken, properties.getGname());
PrintWriter tokenWriter = new PrintWriter(fileName, "UTF-8");
String token = TokenGenerator.generateToken(gateway.getGatewayId(), null);
tokenMap.put(gateway.getGatewayId(), token);
tokenWriter.println(gateway.getGatewayId() + ":" + token);
tokenWriter.close();
return gateway.getGatewayId() + ":" + token + "\n";
}
use of org.apache.airavata.model.workspace.Gateway 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.workspace.Gateway in project airavata by apache.
the class RegistryServerHandler method getGateway.
/**
* Get Gateway details by providing gatewayId
*
* @param gatewayId The gateway Id of the Gateway.
* @return gateway
* Gateway obejct.
*/
@Override
public Gateway getGateway(String gatewayId) throws RegistryServiceException, TException {
try {
experimentCatalog = RegistryFactory.getExperimentCatalog(gatewayId);
if (!experimentCatalog.isExist(ExperimentCatalogModelType.GATEWAY, gatewayId)) {
logger.error("Gateway does not exist in the system. Please provide a valid gateway ID...");
AiravataSystemException exception = new AiravataSystemException();
exception.setMessage("Gateway does not exist in the system. Please provide a valid gateway ID...");
throw exception;
}
Gateway gateway = (Gateway) experimentCatalog.get(ExperimentCatalogModelType.GATEWAY, gatewayId);
logger.debug("Airavata retrieved gateway with gateway id : " + gateway.getGatewayId());
return gateway;
} catch (RegistryException e) {
logger.error("Error while getting the gateway", e);
RegistryServiceException exception = new RegistryServiceException();
exception.setMessage("Error while getting the gateway. More info : " + e.getMessage());
throw exception;
}
}
use of org.apache.airavata.model.workspace.Gateway in project airavata by apache.
the class RegistryServerHandler method getAllGateways.
/**
* Get All the Gateways Connected to Airavata.
*/
@Override
public List<Gateway> getAllGateways() throws RegistryServiceException, TException {
try {
List<Gateway> gateways = new ArrayList<Gateway>();
experimentCatalog = RegistryFactory.getDefaultExpCatalog();
List<Object> list = experimentCatalog.get(ExperimentCatalogModelType.GATEWAY, null, null);
for (Object gateway : list) {
gateways.add((Gateway) gateway);
}
logger.debug("Airavata retrieved all available gateways...");
return gateways;
} catch (RegistryException e) {
logger.error("Error while getting all the gateways", e);
RegistryServiceException exception = new RegistryServiceException();
exception.setMessage("Error while getting all the gateways. More info : " + e.getMessage());
throw exception;
}
}
Aggregations