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);
}
}
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);
}
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;
}
}
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;
}
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;
}
}
Aggregations