Search in sources :

Example 1 with Project

use of org.apache.airavata.model.workspace.Project in project airavata by apache.

the class AiravataServerHandler method deleteProject.

@Override
@SecurityCheck
public boolean deleteProject(AuthzToken authzToken, String projectId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, ProjectNotFoundException, AuthorizationException, TException {
    RegistryService.Client regClient = registryClientPool.getResource();
    SharingRegistryService.Client sharingClient = sharingClientPool.getResource();
    try {
        Project existingProject = regClient.getProject(projectId);
        if (ServerSettings.isEnableSharing() && !authzToken.getClaimsMap().get(org.apache.airavata.common.utils.Constants.USER_NAME).equals(existingProject.getOwner()) || !authzToken.getClaimsMap().get(org.apache.airavata.common.utils.Constants.GATEWAY_ID).equals(existingProject.getGatewayId())) {
            try {
                String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID);
                String userId = authzToken.getClaimsMap().get(Constants.USER_NAME);
                if (!sharingClient.userHasAccess(gatewayId, userId + "@" + gatewayId, projectId, gatewayId + ":WRITE")) {
                    throw new AuthorizationException("User does not have permission to access this resource");
                }
            } catch (Exception e) {
                throw new AuthorizationException("User does not have permission to access this resource");
            }
        }
        boolean ret = regClient.deleteProject(projectId);
        logger.debug("Airavata deleted project with project Id : " + projectId);
        registryClientPool.returnResource(regClient);
        sharingClientPool.returnResource(sharingClient);
        return ret;
    } catch (Exception e) {
        logger.error("Error while removing the project", e);
        ProjectNotFoundException exception = new ProjectNotFoundException();
        exception.setMessage("Error while removing the project. More info : " + e.getMessage());
        registryClientPool.returnBrokenResource(regClient);
        sharingClientPool.returnBrokenResource(sharingClient);
        throw exception;
    }
}
Also used : Project(org.apache.airavata.model.workspace.Project) SharingRegistryService(org.apache.airavata.sharing.registry.service.cpi.SharingRegistryService) RegistryService(org.apache.airavata.registry.api.RegistryService) SharingRegistryService(org.apache.airavata.sharing.registry.service.cpi.SharingRegistryService) RegistryServiceException(org.apache.airavata.registry.api.exception.RegistryServiceException) CredentialStoreException(org.apache.airavata.credential.store.exception.CredentialStoreException) AiravataException(org.apache.airavata.common.exception.AiravataException) TException(org.apache.thrift.TException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) SecurityCheck(org.apache.airavata.service.security.interceptor.SecurityCheck)

Example 2 with Project

use of org.apache.airavata.model.workspace.Project in project airavata by apache.

the class AiravataServerHandler method getProject.

/**
 * Get a Project by ID
 *
 * @param projectId
 */
@Override
@SecurityCheck
public Project getProject(AuthzToken authzToken, String projectId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, ProjectNotFoundException, AuthorizationException, TException {
    RegistryService.Client regClient = registryClientPool.getResource();
    SharingRegistryService.Client sharingClient = sharingClientPool.getResource();
    try {
        Project project = regClient.getProject(projectId);
        if (authzToken.getClaimsMap().get(org.apache.airavata.common.utils.Constants.USER_NAME).equals(project.getOwner()) && authzToken.getClaimsMap().get(org.apache.airavata.common.utils.Constants.GATEWAY_ID).equals(project.getGatewayId())) {
            registryClientPool.returnResource(regClient);
            sharingClientPool.returnResource(sharingClient);
            return project;
        } else if (ServerSettings.isEnableSharing()) {
            try {
                String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID);
                String userId = authzToken.getClaimsMap().get(Constants.USER_NAME);
                if (!sharingClient.userHasAccess(gatewayId, userId + "@" + gatewayId, projectId, gatewayId + ":READ")) {
                    throw new AuthorizationException("User does not have permission to access this resource");
                }
                registryClientPool.returnResource(regClient);
                sharingClientPool.returnResource(sharingClient);
                return project;
            } catch (Exception e) {
                throw new AuthorizationException("User does not have permission to access this resource");
            }
        } else {
            registryClientPool.returnResource(regClient);
            sharingClientPool.returnResource(sharingClient);
            return null;
        }
    } catch (Exception e) {
        logger.error("Error while retrieving the project", e);
        ProjectNotFoundException exception = new ProjectNotFoundException();
        exception.setMessage("Error while retrieving the project. More info : " + e.getMessage());
        registryClientPool.returnBrokenResource(regClient);
        sharingClientPool.returnBrokenResource(sharingClient);
        throw exception;
    }
}
Also used : Project(org.apache.airavata.model.workspace.Project) SharingRegistryService(org.apache.airavata.sharing.registry.service.cpi.SharingRegistryService) RegistryService(org.apache.airavata.registry.api.RegistryService) SharingRegistryService(org.apache.airavata.sharing.registry.service.cpi.SharingRegistryService) RegistryServiceException(org.apache.airavata.registry.api.exception.RegistryServiceException) CredentialStoreException(org.apache.airavata.credential.store.exception.CredentialStoreException) AiravataException(org.apache.airavata.common.exception.AiravataException) TException(org.apache.thrift.TException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) SecurityCheck(org.apache.airavata.service.security.interceptor.SecurityCheck)

Example 3 with Project

use of org.apache.airavata.model.workspace.Project in project airavata by apache.

the class ExperimentExecution method createLocalEchoExperiment.

public String createLocalEchoExperiment(String gatewayId, String applicationInterfaceId, String storageId, String computeResourceId) throws Exception {
    String experimentId = null;
    try {
        List<InputDataObjectType> applicationInputs = airavata.getApplicationInputs(authzToken, applicationInterfaceId);
        List<OutputDataObjectType> appOutputs = airavata.getApplicationOutputs(authzToken, applicationInterfaceId);
        for (InputDataObjectType inputDataObjectType : applicationInputs) {
            if (inputDataObjectType.getName().equalsIgnoreCase(INPUT_NAME)) {
                inputDataObjectType.setValue(LOCAL_ECHO_EXPERIMENT_INPUT);
            }
        }
        List<Project> projectsPerGateway = projectsMap.get(gatewayId);
        String projectID = null;
        if (projectsPerGateway != null && !projectsPerGateway.isEmpty()) {
            projectID = projectsPerGateway.get(0).getProjectID();
        }
        ExperimentModel simpleExperiment = ExperimentModelUtil.createSimpleExperiment(gatewayId, projectID, properties.getTestUserName(), "Local Echo Experiment", "Local Echo Experiment run", applicationInterfaceId, applicationInputs);
        simpleExperiment.setExperimentOutputs(appOutputs);
        ComputationalResourceSchedulingModel scheduling = ExperimentModelUtil.createComputationResourceScheduling(computeResourceId, 4, 1, 1, "cpu", 20, 0);
        UserConfigurationDataModel userConfigurationData = new UserConfigurationDataModel();
        userConfigurationData.setAiravataAutoSchedule(false);
        userConfigurationData.setOverrideManualScheduledParams(false);
        userConfigurationData.setComputationalResourceScheduling(scheduling);
        userConfigurationData.setStorageId(storageId);
        userConfigurationData.setExperimentDataDir(TestFrameworkConstants.STORAGE_LOCATION);
        simpleExperiment.setUserConfigurationData(userConfigurationData);
        experimentId = airavata.createExperiment(authzToken, gatewayId, simpleExperiment);
        experimentsWithGateway.put(experimentId, gatewayId);
    } catch (Exception e) {
        logger.error("Error while creating Echo experiment", e);
        throw new Exception("Error while creating Echo experiment", e);
    }
    return experimentId;
}
Also used : Project(org.apache.airavata.model.workspace.Project) OutputDataObjectType(org.apache.airavata.model.application.io.OutputDataObjectType) InputDataObjectType(org.apache.airavata.model.application.io.InputDataObjectType) UserConfigurationDataModel(org.apache.airavata.model.experiment.UserConfigurationDataModel) ExperimentModel(org.apache.airavata.model.experiment.ExperimentModel) ComputationalResourceSchedulingModel(org.apache.airavata.model.scheduling.ComputationalResourceSchedulingModel) InvalidRequestException(org.apache.airavata.model.error.InvalidRequestException) TException(org.apache.thrift.TException) AiravataClientException(org.apache.airavata.model.error.AiravataClientException) AiravataSystemException(org.apache.airavata.model.error.AiravataSystemException)

Example 4 with Project

use of org.apache.airavata.model.workspace.Project in project airavata by apache.

the class GatewayRegister method createProject.

public void createProject(String gatewayId) throws Exception {
    Project project = new Project();
    project.setGatewayId(gatewayId);
    project.setName(testProject);
    project.setOwner(testUser);
    String projectId = airavata.createProject(authzToken, gatewayId, project);
    projectMap.put(projectId, gatewayId);
}
Also used : Project(org.apache.airavata.model.workspace.Project)

Example 5 with Project

use of org.apache.airavata.model.workspace.Project in project airavata by apache.

the class RegistryServerHandler method getProject.

/**
 * Get a Project by ID
 * This method is to obtain a project by providing a projectId.
 *
 * @param projectId projectId of the project you require.
 * @return project
 * project data model will be returned.
 */
@Override
public Project getProject(String projectId) throws RegistryServiceException, TException {
    try {
        experimentCatalog = RegistryFactory.getDefaultExpCatalog();
        if (!experimentCatalog.isExist(ExperimentCatalogModelType.PROJECT, projectId)) {
            logger.error("Project does not exist in the system. Please provide a valid project ID...");
            ProjectNotFoundException exception = new ProjectNotFoundException();
            exception.setMessage("Project does not exist in the system. Please provide a valid project ID...");
            throw exception;
        }
        logger.debug("Airavata retrieved project with project Id : " + projectId);
        Project project = (Project) experimentCatalog.get(ExperimentCatalogModelType.PROJECT, projectId);
        return project;
    } catch (RegistryException e) {
        logger.error("Error while retrieving the project", e);
        RegistryServiceException exception = new RegistryServiceException();
        exception.setMessage("Error while retrieving the project. More info : " + e.getMessage());
        throw exception;
    }
}
Also used : Project(org.apache.airavata.model.workspace.Project) RegistryServiceException(org.apache.airavata.registry.api.exception.RegistryServiceException)

Aggregations

Project (org.apache.airavata.model.workspace.Project)32 TException (org.apache.thrift.TException)20 InputDataObjectType (org.apache.airavata.model.application.io.InputDataObjectType)17 ExperimentModel (org.apache.airavata.model.experiment.ExperimentModel)17 UserConfigurationDataModel (org.apache.airavata.model.experiment.UserConfigurationDataModel)17 ComputationalResourceSchedulingModel (org.apache.airavata.model.scheduling.ComputationalResourceSchedulingModel)17 OutputDataObjectType (org.apache.airavata.model.application.io.OutputDataObjectType)16 AuthzToken (org.apache.airavata.model.security.AuthzToken)13 ArrayList (java.util.ArrayList)9 RegistryServiceException (org.apache.airavata.registry.api.exception.RegistryServiceException)8 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)6 AiravataClientException (org.apache.airavata.model.error.AiravataClientException)6 AiravataSystemException (org.apache.airavata.model.error.AiravataSystemException)6 InvalidRequestException (org.apache.airavata.model.error.InvalidRequestException)6 AiravataException (org.apache.airavata.common.exception.AiravataException)5 CredentialStoreException (org.apache.airavata.credential.store.exception.CredentialStoreException)5 RegistryService (org.apache.airavata.registry.api.RegistryService)4 SecurityCheck (org.apache.airavata.service.security.interceptor.SecurityCheck)4 SharingRegistryService (org.apache.airavata.sharing.registry.service.cpi.SharingRegistryService)4 DocumentCreatorNew (org.apache.airavata.integration.tools.DocumentCreatorNew)3