Search in sources :

Example 16 with GatewayResourceProfile

use of org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile in project airavata by apache.

the class OrchestratorServerHandler method launchExperiment.

/**
 * * After creating the experiment Data user have the * experimentID as the
 * handler to the experiment, during the launchProcess * We just have to
 * give the experimentID * * @param experimentID * @return sucess/failure *
 * *
 *
 * @param experimentId
 */
public boolean launchExperiment(String experimentId, String gatewayId) throws TException {
    ExperimentModel experiment = null;
    try {
        String experimentNodePath = GFacUtils.getExperimentNodePath(experimentId);
        ZKPaths.mkdirs(curatorClient.getZookeeperClient().getZooKeeper(), experimentNodePath);
        String experimentCancelNode = ZKPaths.makePath(experimentNodePath, ZkConstants.ZOOKEEPER_CANCEL_LISTENER_NODE);
        ZKPaths.mkdirs(curatorClient.getZookeeperClient().getZooKeeper(), experimentCancelNode);
        experiment = (ExperimentModel) experimentCatalog.get(ExperimentCatalogModelType.EXPERIMENT, experimentId);
        if (experiment == null) {
            log.error("Error retrieving the Experiment by the given experimentID: {} ", experimentId);
            return false;
        }
        ComputeResourcePreference computeResourcePreference = appCatalog.getGatewayProfile().getComputeResourcePreference(gatewayId, experiment.getUserConfigurationData().getComputationalResourceScheduling().getResourceHostId());
        String token = computeResourcePreference.getResourceSpecificCredentialStoreToken();
        if (token == null || token.isEmpty()) {
            // try with gateway profile level token
            GatewayResourceProfile gatewayProfile = appCatalog.getGatewayProfile().getGatewayProfile(gatewayId);
            token = gatewayProfile.getCredentialStoreToken();
        }
        // still the token is empty, then we fail the experiment
        if (token == null || token.isEmpty()) {
            log.error("You have not configured credential store token at gateway profile or compute resource preference." + " Please provide the correct token at gateway profile or compute resource preference.");
            return false;
        }
        ExperimentType executionType = experiment.getExperimentType();
        if (executionType == ExperimentType.SINGLE_APPLICATION) {
            // its an single application execution experiment
            List<ProcessModel> processes = orchestrator.createProcesses(experimentId, gatewayId);
            for (ProcessModel processModel : processes) {
                // FIXME Resolving replica if available. This is a very crude way of resolving input replicas. A full featured
                // FIXME replica resolving logic should come here
                ReplicaCatalog replicaCatalog = RegistryFactory.getReplicaCatalog();
                processModel.getProcessInputs().stream().forEach(pi -> {
                    if (pi.getType().equals(DataType.URI) && pi.getValue().startsWith("airavata-dp://")) {
                        try {
                            DataProductModel dataProductModel = replicaCatalog.getDataProduct(pi.getValue());
                            Optional<DataReplicaLocationModel> rpLocation = dataProductModel.getReplicaLocations().stream().filter(rpModel -> rpModel.getReplicaLocationCategory().equals(ReplicaLocationCategory.GATEWAY_DATA_STORE)).findFirst();
                            if (rpLocation.isPresent()) {
                                pi.setValue(rpLocation.get().getFilePath());
                                pi.setStorageResourceId(rpLocation.get().getStorageResourceId());
                            } else {
                                log.error("Could not find a replica for the URI " + pi.getValue());
                            }
                        } catch (ReplicaCatalogException e) {
                            log.error(e.getMessage(), e);
                        }
                    } else if (pi.getType().equals(DataType.URI_COLLECTION) && pi.getValue().contains("airavata-dp://")) {
                        try {
                            String[] uriList = pi.getValue().split(",");
                            final ArrayList<String> filePathList = new ArrayList<>();
                            for (String uri : uriList) {
                                if (uri.startsWith("airavata-dp://")) {
                                    DataProductModel dataProductModel = replicaCatalog.getDataProduct(uri);
                                    Optional<DataReplicaLocationModel> rpLocation = dataProductModel.getReplicaLocations().stream().filter(rpModel -> rpModel.getReplicaLocationCategory().equals(ReplicaLocationCategory.GATEWAY_DATA_STORE)).findFirst();
                                    if (rpLocation.isPresent()) {
                                        filePathList.add(rpLocation.get().getFilePath());
                                    } else {
                                        log.error("Could not find a replica for the URI " + pi.getValue());
                                    }
                                } else {
                                    // uri is in file path format
                                    filePathList.add(uri);
                                }
                            }
                            pi.setValue(StringUtils.join(filePathList, ','));
                        } catch (ReplicaCatalogException e) {
                            log.error(e.getMessage(), e);
                        }
                    }
                });
                String taskDag = orchestrator.createAndSaveTasks(gatewayId, processModel, experiment.getUserConfigurationData().isAiravataAutoSchedule());
                processModel.setTaskDag(taskDag);
                experimentCatalog.update(ExperimentCatalogModelType.PROCESS, processModel, processModel.getProcessId());
            }
            if (!validateProcess(experimentId, processes)) {
                log.error("Validating process fails for given experiment Id : {}", experimentId);
                return false;
            }
            log.debug(experimentId, "Launching single application experiment {}.", experimentId);
            ExperimentStatus status = new ExperimentStatus(ExperimentState.LAUNCHED);
            status.setReason("submitted all processes");
            status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
            OrchestratorUtils.updageAndPublishExperimentStatus(experimentId, status, publisher, gatewayId);
            log.info("expId: {}, Launched experiment ", experimentId);
            OrchestratorServerThreadPoolExecutor.getCachedThreadPool().execute(MDCUtil.wrapWithMDC(new SingleAppExperimentRunner(experimentId, token, gatewayId)));
        } else if (executionType == ExperimentType.WORKFLOW) {
            // its a workflow execution experiment
            log.debug(experimentId, "Launching workflow experiment {}.", experimentId);
            launchWorkflowExperiment(experimentId, token, gatewayId);
        } else {
            log.error(experimentId, "Couldn't identify experiment type, experiment {} is neither single application nor workflow.", experimentId);
            throw new TException("Experiment '" + experimentId + "' launch failed. Unable to figureout execution type for application " + experiment.getExecutionId());
        }
    } catch (LaunchValidationException launchValidationException) {
        ExperimentStatus status = new ExperimentStatus(ExperimentState.FAILED);
        status.setReason("Validation failed: " + launchValidationException.getErrorMessage());
        status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
        OrchestratorUtils.updageAndPublishExperimentStatus(experimentId, status, publisher, gatewayId);
        throw new TException("Experiment '" + experimentId + "' launch failed. Experiment failed to validate: " + launchValidationException.getErrorMessage(), launchValidationException);
    } catch (Exception e) {
        throw new TException("Experiment '" + experimentId + "' launch failed. Unable to figureout execution type for application " + experiment.getExecutionId(), e);
    }
    return true;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) MDCUtil(org.apache.airavata.common.logging.MDCUtil) LoggerFactory(org.slf4j.LoggerFactory) org.apache.airavata.orchestrator.cpi.orchestrator_cpiConstants(org.apache.airavata.orchestrator.cpi.orchestrator_cpiConstants) Stat(org.apache.zookeeper.data.Stat) DataReplicaLocationModel(org.apache.airavata.model.data.replica.DataReplicaLocationModel) OrchestratorException(org.apache.airavata.orchestrator.core.exception.OrchestratorException) ZKPaths(org.apache.curator.utils.ZKPaths) ServerSettings(org.apache.airavata.common.utils.ServerSettings) TBase(org.apache.thrift.TBase) OrchestratorServerThreadPoolExecutor(org.apache.airavata.orchestrator.util.OrchestratorServerThreadPoolExecutor) AbstractExpCatResource(org.apache.airavata.registry.core.experiment.catalog.resources.AbstractExpCatResource) ZkConstants(org.apache.airavata.common.utils.ZkConstants) ApplicationInterfaceDescription(org.apache.airavata.model.appcatalog.appinterface.ApplicationInterfaceDescription) OrchestratorService(org.apache.airavata.orchestrator.cpi.OrchestratorService) DataType(org.apache.airavata.model.application.io.DataType) ValidationResults(org.apache.airavata.model.error.ValidationResults) HostScheduler(org.apache.airavata.gfac.core.scheduler.HostScheduler) AppCatAbstractResource(org.apache.airavata.registry.core.app.catalog.resources.AppCatAbstractResource) CuratorFramework(org.apache.curator.framework.CuratorFramework) ErrorModel(org.apache.airavata.model.commons.ErrorModel) RetryPolicy(org.apache.curator.RetryPolicy) AiravataUtils(org.apache.airavata.common.utils.AiravataUtils) CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) java.util(java.util) SimpleOrchestratorImpl(org.apache.airavata.orchestrator.cpi.impl.SimpleOrchestratorImpl) MDCConstants(org.apache.airavata.common.logging.MDCConstants) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) ReplicaLocationCategory(org.apache.airavata.model.data.replica.ReplicaLocationCategory) ExperimentStatus(org.apache.airavata.model.status.ExperimentStatus) AiravataException(org.apache.airavata.common.exception.AiravataException) GFacUtils(org.apache.airavata.gfac.core.GFacUtils) RegistryFactory(org.apache.airavata.registry.core.experiment.catalog.impl.RegistryFactory) LaunchValidationException(org.apache.airavata.model.error.LaunchValidationException) Logger(org.slf4j.Logger) org.apache.airavata.messaging.core(org.apache.airavata.messaging.core) ExperimentState(org.apache.airavata.model.status.ExperimentState) TException(org.apache.thrift.TException) ExperimentType(org.apache.airavata.model.experiment.ExperimentType) DataProductModel(org.apache.airavata.model.data.replica.DataProductModel) ThriftUtils(org.apache.airavata.common.utils.ThriftUtils) org.apache.airavata.registry.cpi(org.apache.airavata.registry.cpi) ComputeResourcePreference(org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference) GatewayResourceProfile(org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile) ExperimentModel(org.apache.airavata.model.experiment.ExperimentModel) ApplicationDeploymentDescription(org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription) MDC(org.slf4j.MDC) org.apache.airavata.model.messaging.event(org.apache.airavata.model.messaging.event) OrchestratorUtils(org.apache.airavata.orchestrator.util.OrchestratorUtils) ComputeResourceDescription(org.apache.airavata.model.appcatalog.computeresource.ComputeResourceDescription) ProcessModel(org.apache.airavata.model.process.ProcessModel) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) TException(org.apache.thrift.TException) ComputeResourcePreference(org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference) ProcessModel(org.apache.airavata.model.process.ProcessModel) GatewayResourceProfile(org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile) ExperimentModel(org.apache.airavata.model.experiment.ExperimentModel) LaunchValidationException(org.apache.airavata.model.error.LaunchValidationException) DataReplicaLocationModel(org.apache.airavata.model.data.replica.DataReplicaLocationModel) OrchestratorException(org.apache.airavata.orchestrator.core.exception.OrchestratorException) AiravataException(org.apache.airavata.common.exception.AiravataException) LaunchValidationException(org.apache.airavata.model.error.LaunchValidationException) TException(org.apache.thrift.TException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) DataProductModel(org.apache.airavata.model.data.replica.DataProductModel) ExperimentStatus(org.apache.airavata.model.status.ExperimentStatus) ExperimentType(org.apache.airavata.model.experiment.ExperimentType)

Example 17 with GatewayResourceProfile

use of org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile in project airavata by apache.

the class DocumentCreatorNew method getGatewayResourceProfile.

private GatewayResourceProfile getGatewayResourceProfile() throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException {
    // }
    if (gatewayResourceProfile == null) {
        gatewayResourceProfile = new GatewayResourceProfile();
        // gatewayResourceProfile.setGatewayID("default");
        gatewayResourceProfile.setGatewayID(DEFAULT_GATEWAY);
        gatewayResourceProfile.setGatewayID(client.registerGatewayResourceProfile(authzToken, gatewayResourceProfile));
    }
    // }
    return gatewayResourceProfile;
}
Also used : GatewayResourceProfile(org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile)

Example 18 with GatewayResourceProfile

use of org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile in project airavata by apache.

the class GwyResourceProfileImpl method getAllGatewayProfiles.

@Override
public List<GatewayResourceProfile> getAllGatewayProfiles() throws AppCatalogException {
    try {
        List<GatewayResourceProfile> gatewayResourceProfileList = new ArrayList<GatewayResourceProfile>();
        GatewayProfileResource profileResource = new GatewayProfileResource();
        List<AppCatalogResource> resourceList = profileResource.getAll();
        if (resourceList != null && !resourceList.isEmpty()) {
            for (AppCatalogResource resource : resourceList) {
                GatewayProfileResource gatewayProfileResource = (GatewayProfileResource) resource;
                List<ComputeResourcePreference> computeResourcePreferences = getAllComputeResourcePreferences(gatewayProfileResource.getGatewayID());
                List<StoragePreference> dataStoragePreferences = getAllStoragePreferences(gatewayProfileResource.getGatewayID());
                GatewayResourceProfile gatewayResourceProfile = AppCatalogThriftConversion.getGatewayResourceProfile(gatewayProfileResource, computeResourcePreferences, dataStoragePreferences);
                gatewayResourceProfileList.add(gatewayResourceProfile);
            }
        }
        return gatewayResourceProfileList;
    } catch (Exception e) {
        logger.error("Error while retrieving gateway ids...", e);
        throw new AppCatalogException(e);
    }
}
Also used : ComputeResourcePreference(org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) GatewayResourceProfile(org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile) ArrayList(java.util.ArrayList) StoragePreference(org.apache.airavata.model.appcatalog.gatewayprofile.StoragePreference) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException)

Example 19 with GatewayResourceProfile

use of org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile in project airavata by apache.

the class KeyCloakSecurityManager method getUserRolesFromOAuthToken.

private String[] getUserRolesFromOAuthToken(String username, String token, String gatewayId) throws Exception {
    GatewayResourceProfile gwrp = getRegistryServiceClient().getGatewayResourceProfile(gatewayId);
    String identityServerRealm = gwrp.getIdentityServerTenant();
    String openIdConnectUrl = getOpenIDConfigurationUrl(identityServerRealm);
    JSONObject openIdConnectConfig = new JSONObject(getFromUrl(openIdConnectUrl, token));
    String userInfoEndPoint = openIdConnectConfig.getString("userinfo_endpoint");
    JSONObject userInfo = new JSONObject(getFromUrl(userInfoEndPoint, token));
    if (!username.equals(userInfo.get("preferred_username"))) {
        throw new AiravataSecurityException("Subject name and username for the token doesn't match");
    }
    String userId = userInfo.getString("sub");
    String userRoleMappingUrl = ServerSettings.getRemoteIDPServiceUrl() + "/admin/realms/" + identityServerRealm + "/users/" + userId + "/role-mappings/realm";
    JSONArray roleMappings = new JSONArray(getFromUrl(userRoleMappingUrl, getAdminAccessToken(gatewayId)));
    String[] roles = new String[roleMappings.length()];
    for (int i = 0; i < roleMappings.length(); i++) {
        roles[i] = (new JSONObject(roleMappings.get(i).toString())).get("name").toString();
    }
    return roles;
}
Also used : JSONObject(org.json.JSONObject) GatewayResourceProfile(org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile) JSONArray(org.json.JSONArray) AiravataSecurityException(org.apache.airavata.security.AiravataSecurityException)

Example 20 with GatewayResourceProfile

use of org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile in project airavata by apache.

the class RegistryServerHandler method addGateway.

/**
 * Register a Gateway with Airavata.
 *
 * @param gateway The gateway data model.
 * @return gatewayId
 * Th unique identifier of the  newly registered gateway.
 */
@Override
public String addGateway(Gateway gateway) throws RegistryServiceException, DuplicateEntryException, TException {
    try {
        experimentCatalog = RegistryFactory.getDefaultExpCatalog();
        appCatalog = RegistryFactory.getAppCatalog();
        if (!validateString(gateway.getGatewayId())) {
            logger.error("Gateway id cannot be empty...");
            throw new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR);
        }
        // check if gateway exists
        if (isGatewayExist(gateway.getGatewayId())) {
            throw new DuplicateEntryException("Gateway with gatewayId: " + gateway.getGatewayId() + ", already exists in ExperimentCatalog.");
        }
        // check if gatewayresourceprofile exists
        if (appCatalog.getGatewayProfile().isGatewayResourceProfileExists(gateway.getGatewayId())) {
            throw new DuplicateEntryException("GatewayResourceProfile with gatewayId: " + gateway.getGatewayId() + ", already exists in AppCatalog.");
        }
        // add gateway in experimentCatalog
        String gatewayId = (String) experimentCatalog.add(ExpCatParentDataType.GATEWAY, gateway, gateway.getGatewayId());
        // add gatewayresourceprofile in appCatalog
        GatewayResourceProfile gatewayResourceProfile = new GatewayResourceProfile();
        gatewayResourceProfile.setGatewayID(gatewayId);
        gatewayResourceProfile.setIdentityServerTenant(gatewayId);
        gatewayResourceProfile.setIdentityServerPwdCredToken(gateway.getIdentityServerPasswordToken());
        appCatalog.getGatewayProfile().addGatewayResourceProfile(gatewayResourceProfile);
        logger.debug("Airavata added gateway with gateway id : " + gateway.getGatewayId());
        return gatewayId;
    } catch (RegistryException e) {
        logger.error("Error while adding gateway", e);
        RegistryServiceException exception = new RegistryServiceException();
        exception.setMessage("Error while adding gateway. More info : " + e.getMessage());
        throw exception;
    } catch (AppCatalogException e) {
        logger.error("Error while adding gateway profile", e);
        RegistryServiceException exception = new RegistryServiceException();
        exception.setMessage("Error while adding gateway profile. More info : " + e.getMessage());
        throw exception;
    }
}
Also used : GatewayResourceProfile(org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile) RegistryServiceException(org.apache.airavata.registry.api.exception.RegistryServiceException)

Aggregations

GatewayResourceProfile (org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile)29 RegistryServiceException (org.apache.airavata.registry.api.exception.RegistryServiceException)11 TException (org.apache.thrift.TException)11 ComputeResourcePreference (org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference)10 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)6 CredentialStoreService (org.apache.airavata.credential.store.cpi.CredentialStoreService)5 AiravataException (org.apache.airavata.common.exception.AiravataException)3 ComputeResourceDescription (org.apache.airavata.model.appcatalog.computeresource.ComputeResourceDescription)3 StoragePreference (org.apache.airavata.model.appcatalog.gatewayprofile.StoragePreference)3 PasswordCredential (org.apache.airavata.model.credential.store.PasswordCredential)3 AuthzToken (org.apache.airavata.model.security.AuthzToken)3 Gateway (org.apache.airavata.model.workspace.Gateway)3 AiravataSecurityException (org.apache.airavata.security.AiravataSecurityException)3 ArrayList (java.util.ArrayList)2 CredentialStoreException (org.apache.airavata.credential.store.exception.CredentialStoreException)2 ApplicationDeploymentDescription (org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription)2 ApplicationInterfaceDescription (org.apache.airavata.model.appcatalog.appinterface.ApplicationInterfaceDescription)2 TrustStoreManager (org.apache.airavata.security.util.TrustStoreManager)2 AxisFault (org.apache.axis2.AxisFault)2 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)2