Search in sources :

Example 21 with Project

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

the class CreateLaunchExperimentUS3 method createExperimentForStampede.

public static String createExperimentForStampede(Airavata.Client client) throws TException {
    try {
        List<InputDataObjectType> exInputs = new ArrayList<InputDataObjectType>();
        InputDataObjectType input = new InputDataObjectType();
        input.setName("echo_input");
        input.setType(DataType.STRING);
        input.setValue("echo_output=Hello World");
        exInputs.add(input);
        List<OutputDataObjectType> exOut = new ArrayList<OutputDataObjectType>();
        OutputDataObjectType output = new OutputDataObjectType();
        output.setName("echo_output");
        output.setType(DataType.STRING);
        output.setValue("");
        exOut.add(output);
        Project project = ProjectModelUtil.createProject("project1", "admin", "test project");
        String projectId = client.createProject(new AuthzToken(""), DEFAULT_GATEWAY, project);
        ExperimentModel simpleExperiment = ExperimentModelUtil.createSimpleExperiment(DEFAULT_GATEWAY, projectId, "admin", "US3EchoExperimentStatus", "US3EchoStampede", "US3EchoStampede", exInputs);
        simpleExperiment.setExperimentOutputs(exOut);
        ComputationalResourceSchedulingModel scheduling = ExperimentModelUtil.createComputationResourceScheduling("stampede.tacc.xsede.org", 1, 1, 1, "development", 0, 0);
        scheduling.setResourceHostId("gsissh-stampede");
        UserConfigurationDataModel userConfigurationData = new UserConfigurationDataModel();
        userConfigurationData.setAiravataAutoSchedule(false);
        userConfigurationData.setOverrideManualScheduledParams(false);
        userConfigurationData.setComputationalResourceScheduling(scheduling);
        simpleExperiment.setUserConfigurationData(userConfigurationData);
        return client.createExperiment(new AuthzToken(""), DEFAULT_GATEWAY, simpleExperiment);
    } catch (AiravataSystemException e) {
        logger.error("Error occured while creating the experiment...", e.getMessage());
        throw new AiravataSystemException(e);
    } catch (InvalidRequestException e) {
        logger.error("Error occured while creating the experiment...", e.getMessage());
        throw new InvalidRequestException(e);
    } catch (AiravataClientException e) {
        logger.error("Error occured while creating the experiment...", e.getMessage());
        throw new AiravataClientException(e);
    } catch (TException e) {
        logger.error("Error occured while creating the experiment...", e.getMessage());
        throw new TException(e);
    }
}
Also used : TException(org.apache.thrift.TException) InputDataObjectType(org.apache.airavata.model.application.io.InputDataObjectType) ArrayList(java.util.ArrayList) ExperimentModel(org.apache.airavata.model.experiment.ExperimentModel) Project(org.apache.airavata.model.workspace.Project) AiravataSystemException(org.apache.airavata.model.error.AiravataSystemException) OutputDataObjectType(org.apache.airavata.model.application.io.OutputDataObjectType) UserConfigurationDataModel(org.apache.airavata.model.experiment.UserConfigurationDataModel) AuthzToken(org.apache.airavata.model.security.AuthzToken) InvalidRequestException(org.apache.airavata.model.error.InvalidRequestException) AiravataClientException(org.apache.airavata.model.error.AiravataClientException) ComputationalResourceSchedulingModel(org.apache.airavata.model.scheduling.ComputationalResourceSchedulingModel)

Example 22 with Project

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

the class SampleEchoExperiment method createEchoExperiment.

private void createEchoExperiment() throws TException {
    Project project = new Project();
    project.setName("default-project");
    project.setOwner(userId);
    String projectId = airavataClient.createProject(new AuthzToken(""), gatewayId, project);
    ExperimentModel experimentModel = new ExperimentModel();
    experimentModel.setExperimentName("dummy-echo-experiment");
    experimentModel.setProjectId(projectId);
    experimentModel.setUserName(userId);
    experimentModel.setGatewayId(gatewayId);
    experimentModel.setExecutionId(echoInterfaceId);
    UserConfigurationDataModel userConfigurationDataModel = new UserConfigurationDataModel();
    ComputationalResourceSchedulingModel computationalResourceSchedulingModel = new ComputationalResourceSchedulingModel();
    computationalResourceSchedulingModel.setNodeCount(1);
    computationalResourceSchedulingModel.setTotalCPUCount(1);
    computationalResourceSchedulingModel.setTotalPhysicalMemory(512);
    computationalResourceSchedulingModel.setResourceHostId(localhostId);
    userConfigurationDataModel.setComputationalResourceScheduling(computationalResourceSchedulingModel);
    experimentModel.setUserConfigurationData(userConfigurationDataModel);
    List<InputDataObjectType> experimentInputs = new ArrayList<>();
    experimentInputs.add(RegisterSampleApplicationsUtils.createAppInput("Input_to_Echo", "Hello World", DataType.STRING, null, 1, true, true, false, "A test string to Echo", null));
    experimentModel.setExperimentInputs(experimentInputs);
    experimentModel.setExperimentOutputs(airavataClient.getApplicationOutputs(new AuthzToken(""), echoInterfaceId));
    echoExperimentId = airavataClient.createExperiment(new AuthzToken(""), gatewayId, experimentModel);
}
Also used : Project(org.apache.airavata.model.workspace.Project) UserConfigurationDataModel(org.apache.airavata.model.experiment.UserConfigurationDataModel) InputDataObjectType(org.apache.airavata.model.application.io.InputDataObjectType) AuthzToken(org.apache.airavata.model.security.AuthzToken) ExperimentModel(org.apache.airavata.model.experiment.ExperimentModel) ArrayList(java.util.ArrayList) ComputationalResourceSchedulingModel(org.apache.airavata.model.scheduling.ComputationalResourceSchedulingModel)

Example 23 with Project

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

the class AiravataServerHandler method updateProject.

@Override
@SecurityCheck
public void updateProject(AuthzToken authzToken, String projectId, Project updatedProject) 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");
            }
        }
        if (!updatedProject.getOwner().equals(existingProject.getOwner())) {
            throw new InvalidRequestException("Owner of a project cannot be changed");
        }
        if (!updatedProject.getGatewayId().equals(existingProject.getGatewayId())) {
            throw new InvalidRequestException("Gateway ID of a project cannot be changed");
        }
        regClient.updateProject(projectId, updatedProject);
        logger.debug("Airavata updated project with project Id : " + projectId);
        registryClientPool.returnResource(regClient);
        sharingClientPool.returnResource(sharingClient);
    } catch (Exception e) {
        logger.error("Error while updating the project", e);
        AiravataSystemException exception = new AiravataSystemException();
        exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
        exception.setMessage("Error while updating 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 24 with Project

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

the class AiravataServerHandler method cloneExperimentInternal.

private String cloneExperimentInternal(RegistryService.Client regClient, SharingRegistryService.Client sharingClient, AuthzToken authzToken, String existingExperimentID, String newExperimentName, String newExperimentProjectId, ExperimentModel existingExperiment) throws ExperimentNotFoundException, ProjectNotFoundException, TException, AuthorizationException, ApplicationSettingsException {
    if (existingExperiment == null) {
        logger.error(existingExperimentID, "Error while cloning experiment {}, experiment doesn't exist.", existingExperimentID);
        throw new ExperimentNotFoundException("Requested experiment id " + existingExperimentID + " does not exist in the system..");
    }
    if (newExperimentProjectId != null) {
        // getProject will apply sharing permissions
        Project project = this.getProject(authzToken, newExperimentProjectId);
        if (project == null) {
            logger.error("Error while cloning experiment {}, project {} doesn't exist.", existingExperimentID, newExperimentProjectId);
            throw new ProjectNotFoundException("Requested project id " + newExperimentProjectId + " does not exist in the system..");
        }
        existingExperiment.setProjectId(project.getProjectID());
    }
    // make sure user has write access to the project
    String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID);
    String userId = authzToken.getClaimsMap().get(Constants.USER_NAME);
    if (!sharingClient.userHasAccess(gatewayId, userId + "@" + gatewayId, existingExperiment.getProjectId(), gatewayId + ":WRITE")) {
        logger.error("Error while cloning experiment {}, user doesn't have write access to project {}", existingExperimentID, existingExperiment.getProjectId());
        throw new AuthorizationException("User does not have permission to clone an experiment in this project");
    }
    existingExperiment.setCreationTime(AiravataUtils.getCurrentTimestamp().getTime());
    if (existingExperiment.getExecutionId() != null) {
        List<OutputDataObjectType> applicationOutputs = regClient.getApplicationOutputs(existingExperiment.getExecutionId());
        existingExperiment.setExperimentOutputs(applicationOutputs);
    }
    if (validateString(newExperimentName)) {
        existingExperiment.setExperimentName(newExperimentName);
    }
    if (existingExperiment.getErrors() != null) {
        existingExperiment.getErrors().clear();
    }
    if (existingExperiment.getUserConfigurationData() != null && existingExperiment.getUserConfigurationData().getComputationalResourceScheduling() != null) {
        String compResourceId = existingExperiment.getUserConfigurationData().getComputationalResourceScheduling().getResourceHostId();
        ComputeResourceDescription computeResourceDescription = regClient.getComputeResource(compResourceId);
        if (!computeResourceDescription.isEnabled()) {
            existingExperiment.getUserConfigurationData().setComputationalResourceScheduling(null);
        }
    }
    logger.debug("Airavata cloned experiment with experiment id : " + existingExperimentID);
    existingExperiment.setUserName(userId);
    String expId = regClient.createExperiment(gatewayId, existingExperiment);
    if (ServerSettings.isEnableSharing()) {
        try {
            Entity entity = new Entity();
            entity.setEntityId(expId);
            entity.setDomainId(existingExperiment.getGatewayId());
            entity.setEntityTypeId(existingExperiment.getGatewayId() + ":" + "EXPERIMENT");
            entity.setOwnerId(existingExperiment.getUserName() + "@" + existingExperiment.getGatewayId());
            entity.setName(existingExperiment.getExperimentName());
            entity.setDescription(existingExperiment.getDescription());
            sharingClient.createEntity(entity);
        } catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
            logger.error("rolling back experiment creation Exp ID : " + expId);
            regClient.deleteExperiment(expId);
        }
    }
    return expId;
}
Also used : Project(org.apache.airavata.model.workspace.Project) OutputDataObjectType(org.apache.airavata.model.application.io.OutputDataObjectType) 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)

Example 25 with Project

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

the class AiravataServerHandler method getExperimentsInProject.

/**
 * Get Experiments within project with pagination. Results will be sorted
 * based on creation time DESC
 *
 * @param projectId
 *       Identifier of the project
 * @param limit
 *       Amount of results to be fetched
 * @param offset
 *       The starting point of the results to be fetched
 */
@Override
@SecurityCheck
public List<ExperimentModel> getExperimentsInProject(AuthzToken authzToken, String projectId, int limit, int offset) throws InvalidRequestException, AiravataClientException, AiravataSystemException, ProjectNotFoundException, AuthorizationException, TException {
    RegistryService.Client regClient = registryClientPool.getResource();
    SharingRegistryService.Client sharingClient = sharingClientPool.getResource();
    try {
        Project project = regClient.getProject(projectId);
        if (ServerSettings.isEnableSharing() && !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())) {
            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");
                }
            } catch (Exception e) {
                throw new AuthorizationException("User does not have permission to access this resource");
            }
        }
        List<ExperimentModel> result = regClient.getExperimentsInProject(projectId, limit, offset);
        registryClientPool.returnResource(regClient);
        sharingClientPool.returnResource(sharingClient);
        return result;
    } catch (Exception e) {
        logger.error("Error while retrieving the experiments", e);
        AiravataSystemException exception = new AiravataSystemException();
        exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
        exception.setMessage("Error while retrieving the experiments. 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)

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