From 9b3b9e52d5e696187dbf1727c2d6bc7736c1fd9e Mon Sep 17 00:00:00 2001 From: yasithdev Date: Mon, 10 Nov 2025 18:39:59 -0500 Subject: [PATCH 01/26] update RegistryServerHandler --- .../handler/RegistryServerHandler.java | 3455 +++-------------- .../airavata/service/RegistryService.java | 2756 +++++++++++++ 2 files changed, 3287 insertions(+), 2924 deletions(-) create mode 100644 airavata-api/src/main/java/org/apache/airavata/service/RegistryService.java diff --git a/airavata-api/src/main/java/org/apache/airavata/registry/api/service/handler/RegistryServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/registry/api/service/handler/RegistryServerHandler.java index a3432e3f75..c6ef52e8e2 100644 --- a/airavata-api/src/main/java/org/apache/airavata/registry/api/service/handler/RegistryServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/registry/api/service/handler/RegistryServerHandler.java @@ -65,15 +65,8 @@ import org.apache.airavata.registry.api.RegistryService; import org.apache.airavata.registry.api.exception.RegistryServiceException; import org.apache.airavata.registry.api.registry_apiConstants; -import org.apache.airavata.registry.core.entities.expcatalog.JobPK; -import org.apache.airavata.registry.core.repositories.appcatalog.*; -import org.apache.airavata.registry.core.repositories.expcatalog.*; -import org.apache.airavata.registry.core.repositories.replicacatalog.DataProductRepository; -import org.apache.airavata.registry.core.repositories.replicacatalog.DataReplicaLocationRepository; -import org.apache.airavata.registry.core.repositories.workflowcatalog.WorkflowRepository; -import org.apache.airavata.registry.core.utils.DBConstants; -import org.apache.airavata.registry.cpi.*; -import org.apache.airavata.registry.cpi.utils.Constants; +import org.apache.airavata.registry.cpi.AppCatalogException; +import org.apache.airavata.registry.cpi.RegistryException; import org.apache.thrift.TException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -81,41 +74,22 @@ public class RegistryServerHandler implements RegistryService.Iface { private static final Logger logger = LoggerFactory.getLogger(RegistryServerHandler.class); - private ApplicationDeploymentRepository applicationDeploymentRepository = new ApplicationDeploymentRepository(); - private ApplicationInterfaceRepository applicationInterfaceRepository = new ApplicationInterfaceRepository(); - private StorageResourceRepository storageResourceRepository = new StorageResourceRepository(); - private UserResourceProfileRepository userResourceProfileRepository = new UserResourceProfileRepository(); - private GatewayRepository gatewayRepository = new GatewayRepository(); - private ProjectRepository projectRepository = new ProjectRepository(); - private NotificationRepository notificationRepository = new NotificationRepository(); - private ExperimentSummaryRepository experimentSummaryRepository = new ExperimentSummaryRepository(); - private ExperimentRepository experimentRepository = new ExperimentRepository(); - private ExperimentOutputRepository experimentOutputRepository = new ExperimentOutputRepository(); - private ExperimentStatusRepository experimentStatusRepository = new ExperimentStatusRepository(); - private ExperimentErrorRepository experimentErrorRepository = new ExperimentErrorRepository(); - private ProcessRepository processRepository = new ProcessRepository(); - private ProcessOutputRepository processOutputRepository = new ProcessOutputRepository(); - private ProcessWorkflowRepository processWorkflowRepository = new ProcessWorkflowRepository(); - private ProcessStatusRepository processStatusRepository = new ProcessStatusRepository(); - private ProcessErrorRepository processErrorRepository = new ProcessErrorRepository(); - private TaskRepository taskRepository = new TaskRepository(); - private TaskStatusRepository taskStatusRepository = new TaskStatusRepository(); - private TaskErrorRepository taskErrorRepository = new TaskErrorRepository(); - private JobRepository jobRepository = new JobRepository(); - private JobStatusRepository jobStatusRepository = new JobStatusRepository(); - private QueueStatusRepository queueStatusRepository = new QueueStatusRepository(); - private DataProductRepository dataProductRepository = new DataProductRepository(); - private DataReplicaLocationRepository dataReplicaLocationRepository = new DataReplicaLocationRepository(); - private WorkflowRepository workflowRepository = new WorkflowRepository(); - private GatewayGroupsRepository gatewayGroupsRepository = new GatewayGroupsRepository(); - private ParserRepository parserRepository = new ParserRepository(); - private ParserInputRepository parserInputRepository = new ParserInputRepository(); - private ParserOutputRepository parserOutputRepository = new ParserOutputRepository(); - private ParsingTemplateRepository parsingTemplateRepository = new ParsingTemplateRepository(); - private UserRepository userRepository = new UserRepository(); - private ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); - private GatewayUsageReportingCommandRepository usageReportingCommandRepository = - new GatewayUsageReportingCommandRepository(); + private org.apache.airavata.service.RegistryService registryService = new org.apache.airavata.service.RegistryService(); + + // Helper method to convert domain exceptions to Thrift exceptions + private RegistryServiceException convertToRegistryServiceException(RegistryException e, String context) { + logger.error(context, e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage(context + ". More info : " + e.getMessage()); + return exception; + } + + private RegistryServiceException convertToRegistryServiceException(AppCatalogException e, String context) { + logger.error(context, e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage(context + ". More info : " + e.getMessage()); + return exception; + } /** * Fetch Apache Registry API version @@ -135,7 +109,7 @@ public String getAPIVersion() throws TException { @Override public boolean isUserExists(String gatewayId, String userName) throws RegistryServiceException, TException { try { - return userRepository.isUserExists(gatewayId, userName); + return registryService.isUserExists(gatewayId, userName); } catch (RegistryException e) { logger.error("Error while verifying user", e); RegistryServiceException exception = new RegistryServiceException(); @@ -154,7 +128,7 @@ public boolean isUserExists(String gatewayId, String userName) throws RegistrySe @Override public List getAllUsersInGateway(String gatewayId) throws RegistryServiceException, TException { try { - return userRepository.getAllUsernamesInGateway(gatewayId); + return registryService.getAllUsersInGateway(gatewayId); } catch (RegistryException e) { logger.error("Error while retrieving users", e); RegistryServiceException exception = new RegistryServiceException(); @@ -173,15 +147,7 @@ public List getAllUsersInGateway(String gatewayId) throws RegistryServic @Override public Gateway getGateway(String gatewayId) throws RegistryServiceException, TException { try { - if (!gatewayRepository.isGatewayExist(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 = gatewayRepository.getGateway(gatewayId); - logger.debug("Airavata retrieved gateway with gateway id : " + gateway.getGatewayId()); - return gateway; + return registryService.getGateway(gatewayId); } catch (RegistryException e) { logger.error("Error while getting the gateway", e); RegistryServiceException exception = new RegistryServiceException(); @@ -200,15 +166,7 @@ public Gateway getGateway(String gatewayId) throws RegistryServiceException, TEx @Override public boolean deleteGateway(String gatewayId) throws RegistryServiceException, TException { try { - if (!gatewayRepository.isGatewayExist(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; - } - gatewayRepository.removeGateway(gatewayId); - logger.debug("Airavata deleted gateway with gateway id : " + gatewayId); - return true; + return registryService.deleteGateway(gatewayId); } catch (RegistryException e) { logger.error("Error while deleting the gateway", e); RegistryServiceException exception = new RegistryServiceException(); @@ -223,9 +181,7 @@ public boolean deleteGateway(String gatewayId) throws RegistryServiceException, @Override public List getAllGateways() throws RegistryServiceException, TException { try { - List gateways = gatewayRepository.getAllGateways(); - logger.debug("Airavata retrieved all available gateways..."); - return gateways; + return registryService.getAllGateways(); } catch (RegistryException e) { logger.error("Error while getting all the gateways", e); RegistryServiceException exception = new RegistryServiceException(); @@ -244,7 +200,7 @@ public List getAllGateways() throws RegistryServiceException, TExceptio @Override public boolean isGatewayExist(String gatewayId) throws RegistryServiceException, TException { try { - return gatewayRepository.isGatewayExist(gatewayId); + return registryService.isGatewayExist(gatewayId); } catch (RegistryException e) { logger.error("Error while getting gateway", e); RegistryServiceException exception = new RegistryServiceException(); @@ -257,8 +213,7 @@ public boolean isGatewayExist(String gatewayId) throws RegistryServiceException, public boolean deleteNotification(String gatewayId, String notificationId) throws RegistryServiceException, TException { try { - notificationRepository.deleteNotification(notificationId); - return true; + return registryService.deleteNotification(gatewayId, notificationId); } catch (RegistryException e) { logger.error("Error while deleting notification", e); RegistryServiceException exception = new RegistryServiceException(); @@ -271,7 +226,7 @@ public boolean deleteNotification(String gatewayId, String notificationId) public Notification getNotification(String gatewayId, String notificationId) throws RegistryServiceException, TException { try { - return notificationRepository.getNotification(notificationId); + return registryService.getNotification(gatewayId, notificationId); } catch (RegistryException e) { logger.error("Error while retrieving notification", e); RegistryServiceException exception = new RegistryServiceException(); @@ -283,8 +238,7 @@ public Notification getNotification(String gatewayId, String notificationId) @Override public List getAllNotifications(String gatewayId) throws RegistryServiceException, TException { try { - List notifications = notificationRepository.getAllGatewayNotifications(gatewayId); - return notifications; + return registryService.getAllNotifications(gatewayId); } catch (RegistryException e) { logger.error("Error while getting all notifications", e); RegistryServiceException exception = new RegistryServiceException(); @@ -304,16 +258,7 @@ public List getAllNotifications(String gatewayId) throws RegistryS @Override public Project getProject(String projectId) throws RegistryServiceException, TException { try { - if (!projectRepository.isProjectExist(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 = projectRepository.getProject(projectId); - return project; + return registryService.getProject(projectId); } catch (RegistryException e) { logger.error("Error while retrieving the project", e); RegistryServiceException exception = new RegistryServiceException(); @@ -335,21 +280,9 @@ public Project getProject(String projectId) throws RegistryServiceException, TEx @Override public boolean deleteProject(String projectId) throws RegistryServiceException, TException { try { - if (!projectRepository.isProjectExist(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; - } - - projectRepository.removeProject(projectId); - logger.debug("Airavata deleted project with project Id : " + projectId); - return true; + return registryService.deleteProject(projectId); } catch (RegistryException e) { - logger.error("Error while removing the project", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while removing the project. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while removing the project"); } } @@ -365,38 +298,10 @@ public boolean deleteProject(String projectId) throws RegistryServiceException, @Override public List getUserProjects(String gatewayId, String userName, int limit, int offset) throws RegistryServiceException, TException { - if (!validateString(userName)) { - logger.error("Username cannot be empty. Please provide a valid user.."); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Username cannot be empty. Please provide a valid user.."); - throw exception; - } - if (!isGatewayExistInternal(gatewayId)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new RegistryServiceException("Gateway does not exist.Please provide a valid gateway id..."); - } - List projects = new ArrayList<>(); try { - if (!userRepository.isUserExists(gatewayId, userName)) { - logger.warn("User does not exist in the system. Please provide a valid user.."); - return projects; - } - Map filters = new HashMap<>(); - filters.put(Constants.FieldConstants.ProjectConstants.OWNER, userName); - filters.put(Constants.FieldConstants.ProjectConstants.GATEWAY_ID, gatewayId); - projects = projectRepository.searchProjects( - filters, - limit, - offset, - Constants.FieldConstants.ProjectConstants.CREATION_TIME, - ResultOrderType.DESC); - logger.debug("Airavata retrieved projects for user : " + userName + " and gateway id : " + gatewayId); - return projects; + return registryService.getUserProjects(gatewayId, userName, limit, offset); } catch (RegistryException e) { - logger.error("Error while retrieving projects", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving projects. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while retrieving projects"); } } @@ -420,43 +325,12 @@ public ExperimentStatistics getExperimentStatistics( int limit, int offset) throws RegistryServiceException, TException { - if (!isGatewayExistInternal(gatewayId)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - } - // FIXME: for now allowing to pass null accessibleExpIds (only admin users should call this method) - // if (accessibleExpIds == null) { - // logger.debug("accessibleExpIds is null, defaulting to an empty list"); - // accessibleExpIds = Collections.emptyList(); - // } - try { - Map filters = new HashMap<>(); - filters.put(Constants.FieldConstants.ExperimentConstants.GATEWAY_ID, gatewayId); - filters.put(Constants.FieldConstants.ExperimentConstants.FROM_DATE, fromTime + ""); - filters.put(Constants.FieldConstants.ExperimentConstants.TO_DATE, toTime + ""); - if (userName != null) { - filters.put(Constants.FieldConstants.ExperimentConstants.USER_NAME, userName); - } - if (applicationName != null) { - filters.put(Constants.FieldConstants.ExperimentConstants.EXECUTION_ID, applicationName); - } - if (resourceHostName != null) { - filters.put(Constants.FieldConstants.ExperimentConstants.RESOURCE_HOST_ID, resourceHostName); - } - - // Cap the max returned experiment summaries at 1000 - limit = Math.min(limit, 1000); - - ExperimentStatistics result = experimentSummaryRepository.getAccessibleExperimentStatistics( - accessibleExpIds, filters, limit, offset); - logger.debug("Airavata retrieved experiments for gateway id : " + gatewayId + " between : " - + AiravataUtils.getTime(fromTime) + " and " + AiravataUtils.getTime(toTime)); - return result; - } catch (Exception e) { - logger.error("Error while retrieving experiments", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving experiments. More info : " + e.getMessage()); - throw exception; + try { + return registryService.getExperimentStatistics( + gatewayId, fromTime, toTime, userName, applicationName, resourceHostName, + accessibleExpIds, limit, offset); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while retrieving experiments"); } } @@ -472,39 +346,10 @@ public ExperimentStatistics getExperimentStatistics( @Override public List getExperimentsInProject(String gatewayId, String projectId, int limit, int offset) throws RegistryServiceException, TException { - if (!isGatewayExistInternal(gatewayId)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - } - if (!validateString(projectId)) { - logger.error("Project id cannot be empty. Please provide a valid project ID..."); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Project id cannot be empty. Please provide a valid project ID..."); - throw exception; - } try { - if (!projectRepository.isProjectExist(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; - } - - List experiments = experimentRepository.getExperimentList( - gatewayId, - Constants.FieldConstants.ExperimentConstants.PROJECT_ID, - projectId, - limit, - offset, - Constants.FieldConstants.ExperimentConstants.CREATION_TIME, - ResultOrderType.DESC); - logger.debug("Airavata retrieved experiments for project : " + projectId); - return experiments; - } catch (Exception e) { - logger.error("Error while retrieving the experiments", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving the experiments. More info : " + e.getMessage()); - throw exception; + return registryService.getExperimentsInProject(gatewayId, projectId, limit, offset); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while retrieving the experiments"); } } @@ -520,38 +365,10 @@ public List getExperimentsInProject(String gatewayId, String pr @Override public List getUserExperiments(String gatewayId, String userName, int limit, int offset) throws RegistryServiceException, TException { - if (!validateString(userName)) { - logger.error("Username cannot be empty. Please provide a valid user.."); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Username cannot be empty. Please provide a valid user.."); - throw exception; - } - if (!isGatewayExistInternal(gatewayId)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - } - List experiments = new ArrayList(); try { - if (!userRepository.isUserExists(gatewayId, userName)) { - logger.warn("User does not exist in the system. Please provide a valid user.."); - return experiments; - } - experiments = experimentRepository.getExperimentList( - gatewayId, - Constants.FieldConstants.ExperimentConstants.USER_NAME, - userName, - limit, - offset, - Constants.FieldConstants.ExperimentConstants.CREATION_TIME, - ResultOrderType.DESC); - logger.debug("Airavata retrieved experiments for user : " + userName); - return experiments; - } catch (Exception e) { - logger.error("Error while retrieving the experiments", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving the experiments. More info : " + e.getMessage()); - throw exception; + return registryService.getUserExperiments(gatewayId, userName, limit, offset); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while retrieving the experiments"); } } @@ -565,25 +382,9 @@ public List getUserExperiments(String gatewayId, String userNam @Override public boolean deleteExperiment(String experimentId) throws RegistryServiceException, TException { try { - if (!experimentRepository.isExperimentExist(experimentId)) { - throw new ExperimentNotFoundException( - "Requested experiment id " + experimentId + " does not exist in the system.."); - } - ExperimentModel experimentModel = experimentRepository.getExperiment(experimentId); - - if (!(experimentModel.getExperimentStatus().get(0).getState() == ExperimentState.CREATED)) { - logger.error("Error while deleting the experiment"); - throw new ExperimentCatalogException( - "Experiment is not in CREATED state. Hence cannot deleted. ID:" + experimentId); - } - experimentRepository.removeExperiment(experimentId); - logger.debug("Airavata removed experiment with experiment id : " + experimentId); - return true; - } catch (Exception e) { - logger.error("Error while deleting the experiment", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while deleting the experiment. More info : " + e.getMessage()); - throw exception; + return registryService.deleteExperiment(experimentId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while deleting the experiment"); } } @@ -660,39 +461,9 @@ public ExperimentModel getExperiment(String airavataExperimentId) throws Registr public ExperimentModel getDetailedExperimentTree(String airavataExperimentId) throws RegistryServiceException, TException { try { - ExperimentModel experimentModel = getExperimentInternal(airavataExperimentId); - List processList = processRepository.getProcessList( - Constants.FieldConstants.ExperimentConstants.EXPERIMENT_ID, experimentModel.getExperimentId()); - if (processList != null) { - processList.stream().forEach(p -> { - // Process already has the task object - (p).getTasks().stream().forEach(t -> { - try { - List jobList = jobRepository.getJobList( - Constants.FieldConstants.JobConstants.TASK_ID, ((TaskModel) t).getTaskId()); - if (jobList != null) { - Collections.sort(jobList, new Comparator() { - @Override - public int compare(JobModel o1, JobModel o2) { - return (int) (o1.getCreationTime() - o2.getCreationTime()); - } - }); - t.setJobs(jobList); - } - } catch (RegistryException e) { - logger.error(e.getMessage(), e); - } - }); - }); - experimentModel.setProcesses(processList); - } - logger.debug("Airavata retrieved detailed experiment with experiment id : " + airavataExperimentId); - return experimentModel; - } catch (Exception e) { - logger.error("Error while retrieving the experiment", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving the experiment. More info : " + e.getMessage()); - throw exception; + return registryService.getDetailedExperimentTree(airavataExperimentId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while retrieving the experiment"); } } @@ -708,9 +479,11 @@ public int compare(JobModel o1, JobModel o2) { @Override public ExperimentStatus getExperimentStatus(String airavataExperimentId) throws RegistryServiceException, TException { - ExperimentStatus experimentStatus = getExperimentStatusInternal(airavataExperimentId); - logger.debug("Airavata retrieved experiment status for experiment id : " + airavataExperimentId); - return experimentStatus; + try { + return registryService.getExperimentStatus(airavataExperimentId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while retrieving experiment status"); + } } /** @@ -725,21 +498,9 @@ public ExperimentStatus getExperimentStatus(String airavataExperimentId) public List getExperimentOutputs(String airavataExperimentId) throws RegistryServiceException, TException { try { - if (!experimentRepository.isExperimentExist(airavataExperimentId)) { - logger.error( - airavataExperimentId, - "Get experiment outputs failed, experiment {} doesn't exit.", - airavataExperimentId); - throw new ExperimentNotFoundException( - "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); - } - logger.debug("Airavata retrieved experiment outputs for experiment id : " + airavataExperimentId); - return experimentOutputRepository.getExperimentOutputs(airavataExperimentId); - } catch (Exception e) { - logger.error(airavataExperimentId, "Error while retrieving the experiment outputs", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving the experiment outputs. More info : " + e.getMessage()); - throw exception; + return registryService.getExperimentOutputs(airavataExperimentId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while retrieving the experiment outputs"); } } @@ -754,7 +515,11 @@ public List getExperimentOutputs(String airavataExperiment @Override public List getIntermediateOutputs(String airavataExperimentId) throws RegistryServiceException, TException { - return null; + try { + return registryService.getIntermediateOutputs(airavataExperimentId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while retrieving intermediate outputs"); + } } /** @@ -768,100 +533,38 @@ public List getIntermediateOutputs(String airavataExperime public Map getJobStatuses(String airavataExperimentId) throws RegistryServiceException, TException { try { - if (!experimentRepository.isExperimentExist(airavataExperimentId)) { - logger.error( - airavataExperimentId, - "Error while retrieving job details, experiment {} doesn't exist.", - airavataExperimentId); - throw new ExperimentNotFoundException( - "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); - } - List processModels = processRepository.getProcessList( - Constants.FieldConstants.ProcessConstants.EXPERIMENT_ID, airavataExperimentId); - Map jobStatus = new HashMap(); - if (processModels != null && !processModels.isEmpty()) { - for (ProcessModel processModel : processModels) { - List tasks = processModel.getTasks(); - if (tasks != null && !tasks.isEmpty()) { - for (TaskModel task : tasks) { - String taskId = task.getTaskId(); - List jobs = - jobRepository.getJobList(Constants.FieldConstants.JobConstants.TASK_ID, taskId); - if (jobs != null && !jobs.isEmpty()) { - for (JobModel jobModel : jobs) { - String jobID = jobModel.getJobId(); - List status = jobModel.getJobStatuses(); - if (status != null && status.size() > 0) { - JobStatus latestStatus = status.get(status.size() - 1); - jobStatus.put(jobID, latestStatus); - } - } - } - } - } - } - } - logger.debug("Airavata retrieved job statuses for experiment with experiment id : " + airavataExperimentId); - return jobStatus; - } catch (Exception e) { - logger.error(airavataExperimentId, "Error while retrieving the job statuses", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving the job statuses. More info : " + e.getMessage()); - throw exception; + return registryService.getJobStatuses(airavataExperimentId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while retrieving the job statuses"); } } @Override public void addExperimentProcessOutputs(String outputType, List outputs, String id) throws RegistryServiceException, TException { - try { - if (ExpCatChildDataType.PROCESS_OUTPUT.equals(ExpCatChildDataType.valueOf(outputType))) { - processOutputRepository.addProcessOutputs(outputs, id); - } else if (ExpCatChildDataType.EXPERIMENT_OUTPUT.equals(ExpCatChildDataType.valueOf(outputType))) { - experimentOutputRepository.addExperimentOutputs(outputs, id); - } - } catch (Exception e) { - logger.error(id, "Error while adding outputs", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding outputs. More info : " + e.getMessage()); - throw exception; + registryService.addExperimentProcessOutputs(outputType, outputs, id); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while adding outputs"); } } @Override public void addErrors(String errorType, ErrorModel errorModel, String id) throws RegistryServiceException, TException { - try { - if (ExpCatChildDataType.EXPERIMENT_ERROR.equals(ExpCatChildDataType.valueOf(errorType))) { - experimentErrorRepository.addExperimentError(errorModel, id); - } else if (ExpCatChildDataType.TASK_ERROR.equals(ExpCatChildDataType.valueOf(errorType))) { - taskErrorRepository.addTaskError(errorModel, id); - } else if (ExpCatChildDataType.PROCESS_ERROR.equals(ExpCatChildDataType.valueOf(errorType))) { - processErrorRepository.addProcessError(errorModel, id); - } - } catch (Exception e) { - logger.error(id, "Error while adding error", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding error. More info : " + e.getMessage()); - throw exception; + registryService.addErrors(errorType, errorModel, id); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while adding errors"); } } @Override public void addTaskStatus(TaskStatus taskStatus, String taskId) throws RegistryServiceException, TException { try { - taskStatusRepository.addTaskStatus(taskStatus, taskId); - } catch (Exception e) { - logger.error(taskId, "Error while adding task status", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding task status. More info : " + e.getMessage()); - throw exception; + registryService.addTaskStatus(taskStatus, taskId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while adding task status"); } } @@ -869,13 +572,9 @@ public void addTaskStatus(TaskStatus taskStatus, String taskId) throws RegistryS public void addProcessStatus(ProcessStatus processStatus, String processId) throws RegistryServiceException, TException { try { - processStatusRepository.addProcessStatus(processStatus, processId); - } catch (Exception e) { - logger.error(processId, "Error while adding process status", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding process status. More info : " + e.getMessage()); - throw exception; + registryService.addProcessStatus(processStatus, processId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while adding process status"); } } @@ -883,13 +582,9 @@ public void addProcessStatus(ProcessStatus processStatus, String processId) public void updateProcessStatus(ProcessStatus processStatus, String processId) throws RegistryServiceException, TException { try { - processStatusRepository.updateProcessStatus(processStatus, processId); - } catch (Exception e) { - logger.error(processId, "Error while updating process status", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating process status. More info : " + e.getMessage()); - throw exception; + registryService.updateProcessStatus(processStatus, processId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while updating process status"); } } @@ -897,13 +592,9 @@ public void updateProcessStatus(ProcessStatus processStatus, String processId) public void updateExperimentStatus(ExperimentStatus experimentStatus, String experimentId) throws RegistryServiceException, TException { try { - experimentStatusRepository.updateExperimentStatus(experimentStatus, experimentId); - } catch (Exception e) { - logger.error(experimentId, "Error while updating experiment status", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating experiment status. More info : " + e.getMessage()); - throw exception; + registryService.updateExperimentStatus(experimentStatus, experimentId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while updating experiment status"); } } @@ -911,45 +602,27 @@ public void updateExperimentStatus(ExperimentStatus experimentStatus, String exp public void addJobStatus(JobStatus jobStatus, String taskId, String jobId) throws RegistryServiceException, TException { try { - JobPK jobPK = new JobPK(); - jobPK.setJobId(jobId); - jobPK.setTaskId(taskId); - jobStatusRepository.addJobStatus(jobStatus, jobPK); - } catch (Exception e) { - logger.error(jobId, "Error while adding job status", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding job status. More info : " + e.getMessage()); - throw exception; + registryService.addJobStatus(jobStatus, taskId, jobId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while adding job status"); } } @Override public void addJob(JobModel jobModel, String processId) throws RegistryServiceException, TException { try { - jobRepository.addJob(jobModel, processId); - } catch (Exception e) { - logger.error(processId, "Error while adding job ", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding job. More info : " + e.getMessage()); - throw exception; + registryService.addJob(jobModel, processId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while adding job"); } } @Override public void deleteJobs(String processId) throws RegistryServiceException, TException { try { - List jobs = jobRepository.getJobList(Constants.FieldConstants.JobConstants.PROCESS_ID, processId); - for (JobModel jobModel : jobs) { - jobRepository.removeJob(jobModel); - } - } catch (Exception e) { - logger.error(processId, "Error while deleting job ", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while deleting job. More info : " + e.getMessage()); - throw exception; + registryService.deleteJobs(processId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while deleting job"); } } @@ -957,52 +630,36 @@ public void deleteJobs(String processId) throws RegistryServiceException, TExcep public String addProcess(ProcessModel processModel, String experimentId) throws RegistryServiceException, TException { try { - return processRepository.addProcess(processModel, experimentId); - } catch (Exception e) { - logger.error(experimentId, "Error while adding process ", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding process. More info : " + e.getMessage()); - throw exception; + return registryService.addProcess(processModel, experimentId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while adding process"); } } @Override public void updateProcess(ProcessModel processModel, String processId) throws RegistryServiceException, TException { try { - processRepository.updateProcess(processModel, processId); - } catch (Exception e) { - logger.error(processId, "Error while updating process ", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating process. More info : " + e.getMessage()); - throw exception; + registryService.updateProcess(processModel, processId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while updating process"); } } @Override public String addTask(TaskModel taskModel, String processId) throws RegistryServiceException, TException { try { - return taskRepository.addTask(taskModel, processId); - } catch (Exception e) { - logger.error(processId, "Error while adding task ", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding task. More info : " + e.getMessage()); - throw exception; + return registryService.addTask(taskModel, processId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while adding task"); } } @Override public void deleteTasks(String processId) throws RegistryServiceException, TException { try { - taskRepository.deleteTasks(processId); - } catch (Exception e) { - logger.error(processId, "Error while adding task ", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding task. More info : " + e.getMessage()); - throw exception; + registryService.deleteTasks(processId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while deleting tasks"); } } @@ -1010,55 +667,36 @@ public void deleteTasks(String processId) throws RegistryServiceException, TExce public UserConfigurationDataModel getUserConfigurationData(String experimentId) throws RegistryServiceException, TException { try { - return experimentRepository.getUserConfigurationData(experimentId); - } catch (Exception e) { - logger.error(experimentId, "Error while getting user configuration ", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding task. More info : " + e.getMessage()); - throw exception; + return registryService.getUserConfigurationData(experimentId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while getting user configuration"); } } @Override public ProcessModel getProcess(String processId) throws RegistryServiceException, TException { try { - return processRepository.getProcess(processId); - } catch (Exception e) { - logger.error(processId, "Error while retrieving user configuration ", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving user configuration. More info : " + e.getMessage()); - throw exception; + return registryService.getProcess(processId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while retrieving process"); } } @Override public List getProcessList(String experimentId) throws RegistryServiceException, TException { try { - List processModels = processRepository.getProcessList( - Constants.FieldConstants.ExperimentConstants.EXPERIMENT_ID, experimentId); - return processModels; - - } catch (Exception e) { - logger.error(experimentId, "Error while retrieving process list ", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving process list. More info : " + e.getMessage()); - throw exception; + return registryService.getProcessList(experimentId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while retrieving process list"); } } @Override public ProcessStatus getProcessStatus(String processId) throws RegistryServiceException, TException { try { - return processStatusRepository.getProcessStatus(processId); - } catch (Exception e) { - logger.error(processId, "Error while retrieving process status", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving process status. More info : " + e.getMessage()); - throw exception; + return registryService.getProcessStatus(processId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while retrieving process status"); } } @@ -1066,43 +704,18 @@ public ProcessStatus getProcessStatus(String processId) throws RegistryServiceEx public List getProcessListInState(ProcessState processState) throws RegistryServiceException, TException { try { - - List finalProcessList = new ArrayList<>(); - int offset = 0; - int limit = 100; - int count = 0; - do { - List processStatusList = - processStatusRepository.getProcessStatusList(processState, offset, limit); - offset += processStatusList.size(); - count = processStatusList.size(); - for (ProcessStatus processStatus : processStatusList) { - ProcessStatus latestStatus = processStatusRepository.getProcessStatus(processStatus.getProcessId()); - if (latestStatus.getState().name().equals(processState.name())) { - finalProcessList.add(processRepository.getProcess(latestStatus.getProcessId())); - } - } - } while (count == limit); - return finalProcessList; - } catch (Exception e) { - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while retrieving process list with given status. More info : " + e.getMessage()); - throw exception; + return registryService.getProcessListInState(processState); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while retrieving process list with given status"); } } @Override public List getProcessStatusList(String processId) throws RegistryServiceException, TException { try { - return processStatusRepository.getProcessStatusList(processId); - } catch (Exception e) { - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while retrieving process status list for given process Id. More info : " + e.getMessage()); - throw exception; + return registryService.getProcessStatusList(processId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while retrieving process status list for given process Id"); } } @@ -1112,14 +725,9 @@ public List getProcessStatusList(String processId) throws Registr @Override public boolean isJobExist(String queryType, String id) throws RegistryServiceException, TException { try { - JobModel jobModel = fetchJobModel(queryType, id); - return jobModel != null; - } catch (Exception e) { - logger.error(id, "Error while retrieving job", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving job. More info : " + e.getMessage()); - throw exception; + return registryService.isJobExist(queryType, id); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while retrieving job"); } } @@ -1129,30 +737,18 @@ public boolean isJobExist(String queryType, String id) throws RegistryServiceExc @Override public JobModel getJob(String queryType, String id) throws RegistryServiceException, TException { try { - JobModel jobModel = fetchJobModel(queryType, id); - if (jobModel != null) return jobModel; - throw new Exception("Job not found for queryType: " + queryType + ", id: " + id); - } catch (Exception e) { - logger.error(id, "Error while retrieving job", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving job. More info : " + e.getMessage()); - throw exception; + return registryService.getJob(queryType, id); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while retrieving job"); } } @Override public List getJobs(String queryType, String id) throws RegistryServiceException, TException { - try { - return fetchJobModels(queryType, id); - } catch (Exception e) { - logger.error(id, "Error while retrieving jobs for query " + queryType + " and id " + id, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving jobs for query " + queryType + " and id " + id - + ". More info : " + e.getMessage()); - throw exception; + return registryService.getJobs(queryType, id); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while retrieving jobs for query " + queryType + " and id " + id); } } @@ -1160,109 +756,57 @@ public List getJobs(String queryType, String id) throws RegistryServic public int getJobCount( org.apache.airavata.model.status.JobStatus jobStatus, String gatewayId, double searchBackTimeInMinutes) throws RegistryServiceException, TException { - - List jobStatusList = jobStatusRepository.getDistinctListofJobStatus( - gatewayId, jobStatus.getJobState().name(), searchBackTimeInMinutes); - return jobStatusList.size(); + try { + return registryService.getJobCount(jobStatus, gatewayId, searchBackTimeInMinutes); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while getting job count"); + } } @Override public Map getAVGTimeDistribution(String gatewayId, double searchBackTimeInMinutes) throws RegistryServiceException, TException { - return processRepository.getAVGTimeDistribution(gatewayId, searchBackTimeInMinutes); - } - - private JobModel fetchJobModel(String queryType, String id) throws RegistryException { - if (queryType.equals(Constants.FieldConstants.JobConstants.TASK_ID)) { - List jobs = jobRepository.getJobList(Constants.FieldConstants.JobConstants.TASK_ID, id); - if (jobs != null) { - for (JobModel jobModel : jobs) { - if (jobModel.getJobId() != null || !jobModel.equals("")) { - return jobModel; - } - } - } - } else if (queryType.equals(Constants.FieldConstants.JobConstants.PROCESS_ID)) { - List jobs = jobRepository.getJobList(Constants.FieldConstants.JobConstants.PROCESS_ID, id); - if (jobs != null) { - for (JobModel jobModel : jobs) { - if (jobModel.getJobId() != null || !jobModel.equals("")) { - return jobModel; - } - } - } + try { + return registryService.getAVGTimeDistribution(gatewayId, searchBackTimeInMinutes); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while getting average time distribution"); } - return null; } - private List fetchJobModels(String queryType, String id) throws RegistryException { - List jobs = new ArrayList<>(); - switch (queryType) { - case Constants.FieldConstants.JobConstants.TASK_ID: - jobs = jobRepository.getJobList(Constants.FieldConstants.JobConstants.TASK_ID, id); - break; - case Constants.FieldConstants.JobConstants.PROCESS_ID: - jobs = jobRepository.getJobList(Constants.FieldConstants.JobConstants.PROCESS_ID, id); - break; - case Constants.FieldConstants.JobConstants.JOB_ID: - jobs = jobRepository.getJobList(Constants.FieldConstants.JobConstants.JOB_ID, id); - break; - } - return jobs; - } @Override public List getProcessOutputs(String processId) throws RegistryServiceException, TException { try { - return processOutputRepository.getProcessOutputs(processId); - } catch (Exception e) { - logger.error("Error while retrieving process outputs for process id " + processId, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving process outputs. More info : " + e.getMessage()); - throw exception; + return registryService.getProcessOutputs(processId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while retrieving process outputs"); } } @Override public List getProcessWorkflows(String processId) throws RegistryServiceException, TException { - try { - return processWorkflowRepository.getProcessWorkflows(processId); - } catch (Exception e) { - logger.error("Error while retrieving process workflows for process id " + processId, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving process workflows for process id " + processId - + ". More info : " + e.getMessage()); - throw exception; + return registryService.getProcessWorkflows(processId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while retrieving process workflows for process id " + processId); } } @Override public void addProcessWorkflow(ProcessWorkflow processWorkflow) throws RegistryServiceException, TException { try { - processWorkflowRepository.addProcessWorkflow(processWorkflow, processWorkflow.getProcessId()); - } catch (Exception e) { - logger.error("Error while adding process workflows for process id " + processWorkflow.getProcessId(), e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding process workflows for process id " + processWorkflow.getProcessId() - + ". More info : " + e.getMessage()); - throw exception; + registryService.addProcessWorkflow(processWorkflow); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while adding process workflows for process id " + processWorkflow.getProcessId()); } } @Override public List getProcessIds(String experimentId) throws RegistryServiceException, TException { try { - return processRepository.getProcessIds(DBConstants.Process.EXPERIMENT_ID, experimentId); - } catch (Exception e) { - logger.error(experimentId, "Error while retrieving process ids", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving process ids. More info : " + e.getMessage()); - throw exception; + return registryService.getProcessIds(experimentId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while retrieving process ids"); } } @@ -1276,37 +820,9 @@ public List getProcessIds(String experimentId) throws RegistryServiceExc @Override public List getJobDetails(String airavataExperimentId) throws RegistryServiceException, TException { try { - if (!experimentRepository.isExperimentExist(airavataExperimentId)) { - logger.error( - airavataExperimentId, - "Error while retrieving job details, experiment {} doesn't exist.", - airavataExperimentId); - throw new ExperimentNotFoundException( - "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); - } - List processModels = processRepository.getProcessList( - Constants.FieldConstants.ProcessConstants.EXPERIMENT_ID, airavataExperimentId); - List jobList = new ArrayList<>(); - if (processModels != null && !processModels.isEmpty()) { - for (ProcessModel processModel : processModels) { - List tasks = processModel.getTasks(); - if (tasks != null && !tasks.isEmpty()) { - for (TaskModel taskModel : tasks) { - String taskId = taskModel.getTaskId(); - List taskJobs = - jobRepository.getJobList(Constants.FieldConstants.JobConstants.TASK_ID, taskId); - jobList.addAll(taskJobs); - } - } - } - } - logger.debug("Airavata retrieved job models for experiment with experiment id : " + airavataExperimentId); - return jobList; - } catch (Exception e) { - logger.error(airavataExperimentId, "Error while retrieving the job details", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving the job details. More info : " + e.getMessage()); - throw exception; + return registryService.getJobDetails(airavataExperimentId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while retrieving the job details"); } } @@ -1320,14 +836,9 @@ public List getJobDetails(String airavataExperimentId) throws Registry @Override public ApplicationModule getApplicationModule(String appModuleId) throws RegistryServiceException, TException { try { - ApplicationModule module = applicationInterfaceRepository.getApplicationModule(appModuleId); - logger.debug("Airavata retrieved application module with module id : " + appModuleId); - return module; + return registryService.getApplicationModule(appModuleId); } catch (AppCatalogException e) { - logger.error(appModuleId, "Error while retrieving application module...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving the adding application module. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while retrieving application module"); } } @@ -1340,19 +851,10 @@ public ApplicationModule getApplicationModule(String appModuleId) throws Registr */ @Override public List getAllAppModules(String gatewayId) throws RegistryServiceException, TException { - if (!isGatewayExistInternal(gatewayId)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new RegistryServiceException("Gateway does not exist.Please provide a valid gateway id..."); - } try { - List moduleList = applicationInterfaceRepository.getAllApplicationModules(gatewayId); - logger.debug("Airavata retrieved modules for gateway id : " + gatewayId); - return moduleList; + return registryService.getAllAppModules(gatewayId); } catch (AppCatalogException e) { - logger.error("Error while retrieving all application modules...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving all application modules. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while retrieving all application modules"); } } @@ -1368,20 +870,10 @@ public List getAllAppModules(String gatewayId) throws Registr public List getAccessibleAppModules( String gatewayId, List accessibleAppIds, List accessibleComputeResourceIds) throws RegistryServiceException, TException { - if (!isGatewayExistInternal(gatewayId)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new RegistryServiceException("Gateway does not exist.Please provide a valid gateway id..."); - } try { - List moduleList = applicationInterfaceRepository.getAccessibleApplicationModules( - gatewayId, accessibleAppIds, accessibleComputeResourceIds); - logger.debug("Airavata retrieved modules for gateway id : " + gatewayId); - return moduleList; + return registryService.getAccessibleAppModules(gatewayId, accessibleAppIds, accessibleComputeResourceIds); } catch (AppCatalogException e) { - logger.error("Error while retrieving all application modules...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving all application modules. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while retrieving all application modules"); } } @@ -1395,13 +887,9 @@ public List getAccessibleAppModules( @Override public boolean deleteApplicationModule(String appModuleId) throws RegistryServiceException, TException { try { - logger.debug("Airavata deleted application module with module id : " + appModuleId); - return applicationInterfaceRepository.removeApplicationModule(appModuleId); + return registryService.deleteApplicationModule(appModuleId); } catch (AppCatalogException e) { - logger.error(appModuleId, "Error while deleting application module...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while deleting the application module. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while deleting the application module"); } } @@ -1416,15 +904,9 @@ public boolean deleteApplicationModule(String appModuleId) throws RegistryServic public ApplicationDeploymentDescription getApplicationDeployment(String appDeploymentId) throws RegistryServiceException, TException { try { - ApplicationDeploymentDescription deployement = - applicationDeploymentRepository.getApplicationDeployement(appDeploymentId); - logger.debug("Airavata registered application deployment for deployment id : " + appDeploymentId); - return deployement; + return registryService.getApplicationDeployment(appDeploymentId); } catch (AppCatalogException e) { - logger.error(appDeploymentId, "Error while retrieving application deployment...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving application deployment. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while retrieving application deployment"); } } @@ -1438,14 +920,9 @@ public ApplicationDeploymentDescription getApplicationDeployment(String appDeplo @Override public boolean deleteApplicationDeployment(String appDeploymentId) throws RegistryServiceException, TException { try { - applicationDeploymentRepository.removeAppDeployment(appDeploymentId); - logger.debug("Airavata removed application deployment with deployment id : " + appDeploymentId); - return true; + return registryService.deleteApplicationDeployment(appDeploymentId); } catch (AppCatalogException e) { - logger.error(appDeploymentId, "Error while deleting application deployment...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while deleting application deployment. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while deleting application deployment"); } } @@ -1460,20 +937,10 @@ public boolean deleteApplicationDeployment(String appDeploymentId) throws Regist @Override public List getAllApplicationDeployments(String gatewayId) throws RegistryServiceException, TException { - if (!isGatewayExistInternal(gatewayId)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new RegistryServiceException("Gateway does not exist.Please provide a valid gateway id..."); - } try { - List deployements = - applicationDeploymentRepository.getAllApplicationDeployements(gatewayId); - logger.debug("Airavata retrieved application deployments for gateway id : " + gatewayId); - return deployements; + return registryService.getAllApplicationDeployments(gatewayId); } catch (AppCatalogException e) { - logger.error("Error while retrieving application deployments...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving application deployments. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while retrieving application deployments"); } } @@ -1489,21 +956,10 @@ public List getAllApplicationDeployments(Strin public List getAccessibleApplicationDeployments( String gatewayId, List accessibleAppDeploymentIds, List accessibleComputeResourceIds) throws RegistryServiceException, TException { - if (!isGatewayExistInternal(gatewayId)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new RegistryServiceException("Gateway does not exist.Please provide a valid gateway id..."); - } try { - List deployements = - applicationDeploymentRepository.getAccessibleApplicationDeployments( - gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); - logger.debug("Airavata retrieved application deployments for gateway id : " + gatewayId); - return deployements; + return registryService.getAccessibleApplicationDeployments(gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); } catch (AppCatalogException e) { - logger.error("Error while retrieving application deployments...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving application deployments. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while retrieving application deployments"); } } @@ -1524,20 +980,10 @@ public List getAccessibleApplicationDeployment List accessibleAppDeploymentIds, List accessibleComputeResourceIds) throws RegistryServiceException, TException { - if (!isGatewayExistInternal(gatewayId)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new RegistryServiceException("Gateway does not exist.Please provide a valid gateway id..."); - } try { - List deployments = - applicationDeploymentRepository.getAccessibleApplicationDeployments( - gatewayId, appModuleId, accessibleAppDeploymentIds, accessibleComputeResourceIds); - return deployments; + return registryService.getAccessibleApplicationDeploymentsForAppModule(gatewayId, appModuleId, accessibleAppDeploymentIds, accessibleComputeResourceIds); } catch (AppCatalogException e) { - logger.error("Error while retrieving application deployments...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving application deployments. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while retrieving application deployments"); } } @@ -1551,21 +997,9 @@ public List getAccessibleApplicationDeployment @Override public List getAppModuleDeployedResources(String appModuleId) throws RegistryServiceException, TException { try { - List appDeployments = new ArrayList<>(); - Map filters = new HashMap<>(); - filters.put(DBConstants.ApplicationDeployment.APPLICATION_MODULE_ID, appModuleId); - List applicationDeployments = - applicationDeploymentRepository.getApplicationDeployments(filters); - for (ApplicationDeploymentDescription description : applicationDeployments) { - appDeployments.add(description.getAppDeploymentId()); - } - logger.debug("Airavata retrieved application deployments for module id : " + appModuleId); - return appDeployments; + return registryService.getAppModuleDeployedResources(appModuleId); } catch (AppCatalogException e) { - logger.error(appModuleId, "Error while retrieving application deployments...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving application deployment. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while retrieving application deployment"); } } @@ -1573,16 +1007,9 @@ public List getAppModuleDeployedResources(String appModuleId) throws Reg public List getApplicationDeployments(String appModuleId) throws RegistryServiceException, TException { try { - Map filters = new HashMap<>(); - filters.put(DBConstants.ApplicationDeployment.APPLICATION_MODULE_ID, appModuleId); - List applicationDeployments = - applicationDeploymentRepository.getApplicationDeployments(filters); - return applicationDeployments; + return registryService.getApplicationDeployments(appModuleId); } catch (AppCatalogException e) { - logger.error(appModuleId, "Error while retrieving application deployments...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving application deployment. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while retrieving application deployment"); } } @@ -1597,15 +1024,9 @@ public List getApplicationDeployments(String a public ApplicationInterfaceDescription getApplicationInterface(String appInterfaceId) throws RegistryServiceException, TException { try { - ApplicationInterfaceDescription interfaceDescription = - applicationInterfaceRepository.getApplicationInterface(appInterfaceId); - logger.debug("Airavata retrieved application interface with interface id : " + appInterfaceId); - return interfaceDescription; + return registryService.getApplicationInterface(appInterfaceId); } catch (AppCatalogException e) { - logger.error(appInterfaceId, "Error while retrieving application interface...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving application interface. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while retrieving application interface"); } } @@ -1619,15 +1040,9 @@ public ApplicationInterfaceDescription getApplicationInterface(String appInterfa @Override public boolean deleteApplicationInterface(String appInterfaceId) throws RegistryServiceException, TException { try { - boolean removeApplicationInterface = - applicationInterfaceRepository.removeApplicationInterface(appInterfaceId); - logger.debug("Airavata removed application interface with interface id : " + appInterfaceId); - return removeApplicationInterface; + return registryService.deleteApplicationInterface(appInterfaceId); } catch (AppCatalogException e) { - logger.error(appInterfaceId, "Error while deleting application interface...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while deleting application interface. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while deleting application interface"); } } @@ -1641,28 +1056,10 @@ public boolean deleteApplicationInterface(String appInterfaceId) throws Registry @Override public Map getAllApplicationInterfaceNames(String gatewayId) throws RegistryServiceException, TException { - if (!isGatewayExistInternal(gatewayId)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new RegistryServiceException("Gateway does not exist.Please provide a valid gateway id..."); - } try { - List allApplicationInterfaces = - applicationInterfaceRepository.getAllApplicationInterfaces(gatewayId); - Map allApplicationInterfacesMap = new HashMap<>(); - if (allApplicationInterfaces != null && !allApplicationInterfaces.isEmpty()) { - for (ApplicationInterfaceDescription interfaceDescription : allApplicationInterfaces) { - allApplicationInterfacesMap.put( - interfaceDescription.getApplicationInterfaceId(), - interfaceDescription.getApplicationName()); - } - } - logger.debug("Airavata retrieved application interfaces for gateway id : " + gatewayId); - return allApplicationInterfacesMap; + return registryService.getAllApplicationInterfaceNames(gatewayId); } catch (AppCatalogException e) { - logger.error("Error while retrieving application interfaces...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving application interfaces. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while retrieving application interfaces"); } } @@ -1676,20 +1073,10 @@ public Map getAllApplicationInterfaceNames(String gatewayId) @Override public List getAllApplicationInterfaces(String gatewayId) throws RegistryServiceException, TException { - if (!isGatewayExistInternal(gatewayId)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new RegistryServiceException("Gateway does not exist.Please provide a valid gateway id..."); - } try { - List interfaces = - applicationInterfaceRepository.getAllApplicationInterfaces(gatewayId); - logger.debug("Airavata retrieved application interfaces for gateway id : " + gatewayId); - return interfaces; + return registryService.getAllApplicationInterfaces(gatewayId); } catch (AppCatalogException e) { - logger.error("Error while retrieving application interfaces...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving application interfaces. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while retrieving application interfaces"); } } @@ -1704,15 +1091,9 @@ public List getAllApplicationInterfaces(String public List getApplicationInputs(String appInterfaceId) throws RegistryServiceException, TException { try { - List applicationInputs = - applicationInterfaceRepository.getApplicationInputs(appInterfaceId); - logger.debug("Airavata retrieved application inputs for application interface id : " + appInterfaceId); - return applicationInputs; + return registryService.getApplicationInputs(appInterfaceId); } catch (AppCatalogException e) { - logger.error(appInterfaceId, "Error while retrieving application inputs...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving application inputs. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while retrieving application inputs"); } } @@ -1726,9 +1107,11 @@ public List getApplicationInputs(String appInterfaceId) @Override public List getApplicationOutputs(String appInterfaceId) throws RegistryServiceException, TException { - List list = getApplicationOutputsInternal(appInterfaceId); - logger.debug("Airavata retrieved application outputs for app interface id : " + appInterfaceId); - return list; + try { + return registryService.getApplicationOutputs(appInterfaceId); + } catch (AppCatalogException e) { + throw convertToRegistryServiceException(e, "Error while retrieving application outputs"); + } } /** @@ -1743,35 +1126,9 @@ public List getApplicationOutputs(String appInterfaceId) public Map getAvailableAppInterfaceComputeResources(String appInterfaceId) throws RegistryServiceException, TException { try { - Map allComputeResources = - new ComputeResourceRepository().getAvailableComputeResourceIdList(); - Map availableComputeResources = new HashMap(); - ApplicationInterfaceDescription applicationInterface = - applicationInterfaceRepository.getApplicationInterface(appInterfaceId); - HashMap filters = new HashMap<>(); - List applicationModules = applicationInterface.getApplicationModules(); - if (applicationModules != null && !applicationModules.isEmpty()) { - for (String moduleId : applicationModules) { - filters.put(DBConstants.ApplicationDeployment.APPLICATION_MODULE_ID, moduleId); - List applicationDeployments = - applicationDeploymentRepository.getApplicationDeployments(filters); - for (ApplicationDeploymentDescription deploymentDescription : applicationDeployments) { - if (allComputeResources.get(deploymentDescription.getComputeHostId()) != null) { - availableComputeResources.put( - deploymentDescription.getComputeHostId(), - allComputeResources.get(deploymentDescription.getComputeHostId())); - } - } - } - } - logger.debug( - "Airavata retrieved available compute resources for application interface id : " + appInterfaceId); - return availableComputeResources; + return registryService.getAvailableAppInterfaceComputeResources(appInterfaceId); } catch (AppCatalogException e) { - logger.error(appInterfaceId, "Error while saving compute resource...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while saving compute resource. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while retrieving available compute resources"); } } @@ -1786,15 +1143,9 @@ public Map getAvailableAppInterfaceComputeResources(String appIn public ComputeResourceDescription getComputeResource(String computeResourceId) throws RegistryServiceException, TException { try { - ComputeResourceDescription computeResource = - new ComputeResourceRepository().getComputeResource(computeResourceId); - logger.debug("Airavata retrieved compute resource with compute resource Id : " + computeResourceId); - return computeResource; + return registryService.getComputeResource(computeResourceId); } catch (AppCatalogException e) { - logger.error(computeResourceId, "Error while retrieving compute resource...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving compute resource. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while retrieving compute resource"); } } @@ -1807,14 +1158,9 @@ public ComputeResourceDescription getComputeResource(String computeResourceId) @Override public Map getAllComputeResourceNames() throws RegistryServiceException, TException { try { - Map computeResourceIdList = new ComputeResourceRepository().getAllComputeResourceIdList(); - logger.debug("Airavata retrieved all the available compute resources..."); - return computeResourceIdList; + return registryService.getAllComputeResourceNames(); } catch (AppCatalogException e) { - logger.error("Error while retrieving compute resource...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving compute resource. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while retrieving compute resource"); } } @@ -1828,14 +1174,9 @@ public Map getAllComputeResourceNames() throws RegistryServiceEx @Override public boolean deleteComputeResource(String computeResourceId) throws RegistryServiceException, TException { try { - new ComputeResourceRepository().removeComputeResource(computeResourceId); - logger.debug("Airavata deleted compute resource with compute resource Id : " + computeResourceId); - return true; + return registryService.deleteComputeResource(computeResourceId); } catch (AppCatalogException e) { - logger.error(computeResourceId, "Error while deleting compute resource...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while deleting compute resource. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while deleting compute resource"); } } @@ -1850,15 +1191,9 @@ public boolean deleteComputeResource(String computeResourceId) throws RegistrySe public StorageResourceDescription getStorageResource(String storageResourceId) throws RegistryServiceException, TException { try { - StorageResourceDescription storageResource = - storageResourceRepository.getStorageResource(storageResourceId); - logger.debug("Airavata retrieved storage resource with storage resource Id : " + storageResourceId); - return storageResource; + return registryService.getStorageResource(storageResourceId); } catch (AppCatalogException e) { - logger.error(storageResourceId, "Error while retrieving storage resource...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving storage resource. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while retrieving storage resource"); } } @@ -1871,14 +1206,9 @@ public StorageResourceDescription getStorageResource(String storageResourceId) @Override public Map getAllStorageResourceNames() throws RegistryServiceException, TException { try { - Map resourceIdList = storageResourceRepository.getAllStorageResourceIdList(); - logger.debug("Airavata retrieved storage resources list..."); - return resourceIdList; + return registryService.getAllStorageResourceNames(); } catch (AppCatalogException e) { - logger.error("Error while retrieving storage resource...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving storage resource. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while retrieving storage resource"); } } @@ -1892,14 +1222,9 @@ public Map getAllStorageResourceNames() throws RegistryServiceEx @Override public boolean deleteStorageResource(String storageResourceId) throws RegistryServiceException, TException { try { - storageResourceRepository.removeStorageResource(storageResourceId); - logger.debug("Airavata deleted storage resource with storage resource Id : " + storageResourceId); - return true; + return registryService.deleteStorageResource(storageResourceId); } catch (AppCatalogException e) { - logger.error(storageResourceId, "Error while deleting storage resource...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while deleting storage resource. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while deleting storage resource"); } } @@ -1911,15 +1236,9 @@ public boolean deleteStorageResource(String storageResourceId) throws RegistrySe @Override public LOCALSubmission getLocalJobSubmission(String jobSubmissionId) throws RegistryServiceException, TException { try { - LOCALSubmission localJobSubmission = new ComputeResourceRepository().getLocalJobSubmission(jobSubmissionId); - logger.debug("Airavata retrieved local job submission for job submission interface id: " + jobSubmissionId); - return localJobSubmission; + return registryService.getLocalJobSubmission(jobSubmissionId); } catch (AppCatalogException e) { - String errorMsg = "Error while retrieving local job submission interface to resource compute resource..."; - logger.error(jobSubmissionId, errorMsg, e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage(errorMsg + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while retrieving local job submission interface"); } } @@ -1931,15 +1250,9 @@ public LOCALSubmission getLocalJobSubmission(String jobSubmissionId) throws Regi @Override public SSHJobSubmission getSSHJobSubmission(String jobSubmissionId) throws RegistryServiceException, TException { try { - SSHJobSubmission sshJobSubmission = new ComputeResourceRepository().getSSHJobSubmission(jobSubmissionId); - logger.debug("Airavata retrieved SSH job submission for job submission interface id: " + jobSubmissionId); - return sshJobSubmission; + return registryService.getSSHJobSubmission(jobSubmissionId); } catch (AppCatalogException e) { - String errorMsg = "Error while retrieving SSH job submission interface to resource compute resource..."; - logger.error(jobSubmissionId, errorMsg, e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage(errorMsg + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while retrieving SSH job submission interface"); } } @@ -1959,17 +1272,9 @@ public SSHJobSubmission getSSHJobSubmission(String jobSubmissionId) throws Regis public UnicoreJobSubmission getUnicoreJobSubmission(String jobSubmissionId) throws RegistryServiceException, TException { try { - UnicoreJobSubmission unicoreJobSubmission = - new ComputeResourceRepository().getUNICOREJobSubmission(jobSubmissionId); - logger.debug( - "Airavata retrieved UNICORE job submission for job submission interface id: " + jobSubmissionId); - return unicoreJobSubmission; + return registryService.getUnicoreJobSubmission(jobSubmissionId); } catch (AppCatalogException e) { - String errorMsg = "Error while retrieving Unicore job submission interface to resource compute resource..."; - logger.error(jobSubmissionId, errorMsg, e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage(errorMsg + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while retrieving Unicore job submission interface"); } } @@ -1987,16 +1292,9 @@ public UnicoreJobSubmission getUnicoreJobSubmission(String jobSubmissionId) public CloudJobSubmission getCloudJobSubmission(String jobSubmissionId) throws RegistryServiceException, TException { try { - CloudJobSubmission cloudJobSubmission = - new ComputeResourceRepository().getCloudJobSubmission(jobSubmissionId); - logger.debug("Airavata retrieved cloud job submission for job submission interface id: " + jobSubmissionId); - return cloudJobSubmission; + return registryService.getCloudJobSubmission(jobSubmissionId); } catch (AppCatalogException e) { - String errorMsg = "Error while retrieving Cloud job submission interface to resource compute resource..."; - logger.error(jobSubmissionId, errorMsg, e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage(errorMsg + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while retrieving Cloud job submission interface"); } } @@ -2009,15 +1307,9 @@ public CloudJobSubmission getCloudJobSubmission(String jobSubmissionId) @Override public LOCALDataMovement getLocalDataMovement(String dataMovementId) throws RegistryServiceException, TException { try { - LOCALDataMovement localDataMovement = new ComputeResourceRepository().getLocalDataMovement(dataMovementId); - logger.debug("Airavata retrieved local data movement with data movement id: " + dataMovementId); - return localDataMovement; + return registryService.getLocalDataMovement(dataMovementId); } catch (AppCatalogException e) { - String errorMsg = "Error while retrieving local data movement interface to resource compute resource..."; - logger.error(dataMovementId, errorMsg, e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage(errorMsg + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while retrieving local data movement interface"); } } @@ -2030,15 +1322,9 @@ public LOCALDataMovement getLocalDataMovement(String dataMovementId) throws Regi @Override public SCPDataMovement getSCPDataMovement(String dataMovementId) throws RegistryServiceException, TException { try { - SCPDataMovement scpDataMovement = new ComputeResourceRepository().getSCPDataMovement(dataMovementId); - logger.debug("Airavata retrieved SCP data movement with data movement id: " + dataMovementId); - return scpDataMovement; + return registryService.getSCPDataMovement(dataMovementId); } catch (AppCatalogException e) { - String errorMsg = "Error while retrieving SCP data movement interface to resource compute resource..."; - logger.error(dataMovementId, errorMsg, e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage(errorMsg + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while retrieving SCP data movement interface"); } } @@ -2052,16 +1338,9 @@ public SCPDataMovement getSCPDataMovement(String dataMovementId) throws Registry public UnicoreDataMovement getUnicoreDataMovement(String dataMovementId) throws RegistryServiceException, TException { try { - UnicoreDataMovement unicoreDataMovement = - new ComputeResourceRepository().getUNICOREDataMovement(dataMovementId); - logger.debug("Airavata retrieved UNICORE data movement with data movement id: " + dataMovementId); - return unicoreDataMovement; + return registryService.getUnicoreDataMovement(dataMovementId); } catch (AppCatalogException e) { - String errorMsg = "Error while retrieving UNICORE data movement interface..."; - logger.error(dataMovementId, errorMsg, e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage(errorMsg + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while retrieving UNICORE data movement interface"); } } @@ -2075,16 +1354,9 @@ public UnicoreDataMovement getUnicoreDataMovement(String dataMovementId) public GridFTPDataMovement getGridFTPDataMovement(String dataMovementId) throws RegistryServiceException, TException { try { - GridFTPDataMovement gridFTPDataMovement = - new ComputeResourceRepository().getGridFTPDataMovement(dataMovementId); - logger.debug("Airavata retrieved GRIDFTP data movement with data movement id: " + dataMovementId); - return gridFTPDataMovement; + return registryService.getGridFTPDataMovement(dataMovementId); } catch (AppCatalogException e) { - String errorMsg = "Error while retrieving GridFTP data movement interface to resource compute resource..."; - logger.error(dataMovementId, errorMsg, e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage(errorMsg + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while retrieving GridFTP data movement interface"); } } @@ -2154,14 +1426,9 @@ public boolean changeDataMovementPriorities(Map dataMovementPri public boolean deleteJobSubmissionInterface(String computeResourceId, String jobSubmissionInterfaceId) throws RegistryServiceException, TException { try { - new ComputeResourceRepository().removeJobSubmissionInterface(computeResourceId, jobSubmissionInterfaceId); - logger.debug("Airavata deleted job submission interface with interface id : " + jobSubmissionInterfaceId); - return true; + return registryService.deleteJobSubmissionInterface(computeResourceId, jobSubmissionInterfaceId); } catch (AppCatalogException e) { - logger.error(jobSubmissionInterfaceId, "Error while deleting job submission interface...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while deleting job submission interface. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while deleting job submission interface"); } } @@ -2169,25 +1436,18 @@ public boolean deleteJobSubmissionInterface(String computeResourceId, String job public ResourceJobManager getResourceJobManager(String resourceJobManagerId) throws RegistryServiceException, TException { try { - return new ComputeResourceRepository().getResourceJobManager(resourceJobManagerId); + return registryService.getResourceJobManager(resourceJobManagerId); } catch (AppCatalogException e) { - logger.error(resourceJobManagerId, "Error while retrieving resource job manager...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving resource job manager. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while retrieving resource job manager"); } } @Override public boolean deleteResourceJobManager(String resourceJobManagerId) throws RegistryServiceException, TException { try { - new ComputeResourceRepository().deleteResourceJobManager(resourceJobManagerId); - return true; + return registryService.deleteResourceJobManager(resourceJobManagerId); } catch (AppCatalogException e) { - logger.error(resourceJobManagerId, "Error while deleting resource job manager...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while deleting resource job manager. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while deleting resource job manager"); } } @@ -2203,13 +1463,9 @@ public boolean deleteResourceJobManager(String resourceJobManagerId) throws Regi public boolean deleteBatchQueue(String computeResourceId, String queueName) throws RegistryServiceException, TException { try { - new ComputeResourceRepository().removeBatchQueue(computeResourceId, queueName); - return true; + return registryService.deleteBatchQueue(computeResourceId, queueName); } catch (AppCatalogException e) { - logger.error(computeResourceId, "Error while deleting batch queue...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while deleting batch queue. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while deleting batch queue"); } } @@ -2224,19 +1480,9 @@ public boolean deleteBatchQueue(String computeResourceId, String queueName) public GatewayResourceProfile getGatewayResourceProfile(String gatewayID) throws RegistryServiceException, TException { try { - if (!isGatewayExistInternal(gatewayID)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - } - GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); - GatewayResourceProfile gatewayResourceProfile = gwyResourceProfileRepository.getGatewayProfile(gatewayID); - logger.debug("Airavata retrieved gateway profile with gateway id : " + gatewayID); - return gatewayResourceProfile; - } catch (Exception e) { - logger.error(gatewayID, "Error while retrieving gateway resource profile...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving gateway resource profile. More info : " + e.getMessage()); - throw exception; + return registryService.getGatewayResourceProfile(gatewayID); + } catch (AppCatalogException e) { + throw convertToRegistryServiceException(e, "Error while retrieving gateway resource profile"); } } @@ -2250,19 +1496,9 @@ public GatewayResourceProfile getGatewayResourceProfile(String gatewayID) @Override public boolean deleteGatewayResourceProfile(String gatewayID) throws RegistryServiceException, TException { try { - if (!isGatewayExistInternal(gatewayID)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new RegistryServiceException("Gateway does not exist.Please provide a valid gateway id..."); - } - GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); - gwyResourceProfileRepository.delete(gatewayID); - logger.debug("Airavata deleted gateway profile with gateway id : " + gatewayID); - return true; - } catch (Exception e) { - logger.error(gatewayID, "Error while removing gateway resource profile...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while removing gateway resource profile. More info : " + e.getMessage()); - throw exception; + return registryService.deleteGatewayResourceProfile(gatewayID); + } catch (AppCatalogException e) { + throw convertToRegistryServiceException(e, "Error while removing gateway resource profile"); } } @@ -2278,41 +1514,9 @@ public boolean deleteGatewayResourceProfile(String gatewayID) throws RegistrySer public ComputeResourcePreference getGatewayComputeResourcePreference(String gatewayID, String computeResourceId) throws RegistryServiceException, TException { try { - if (!isGatewayExistInternal(gatewayID)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new RegistryServiceException("Gateway does not exist.Please provide a valid gateway id..."); - } - GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); - ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); - if (!gwyResourceProfileRepository.isGatewayResourceProfileExists(gatewayID)) { - logger.error( - gatewayID, - "Given gateway profile does not exist in the system. Please provide a valid gateway id..."); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage( - "Given gateway profile does not exist in the system. Please provide a valid gateway id..."); - throw exception; - } - if (!computeResourceRepository.isComputeResourceExists(computeResourceId)) { - logger.error( - computeResourceId, - "Given compute resource does not exist in the system. Please provide a valid compute resource id..."); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage( - "Given compute resource does not exist in the system. Please provide a valid compute resource id..."); - throw exception; - } - ComputeResourcePreference computeResourcePreference = - gwyResourceProfileRepository.getComputeResourcePreference(gatewayID, computeResourceId); - logger.debug("Airavata retrieved gateway compute resource preference with gateway id : " + gatewayID - + " and for compute resoruce id : " + computeResourceId); - return computeResourcePreference; + return registryService.getGatewayComputeResourcePreference(gatewayID, computeResourceId); } catch (AppCatalogException e) { - logger.error(gatewayID, "Error while reading gateway compute resource preference...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage( - "Error while reading gateway compute resource preference. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while reading gateway compute resource preference"); } } @@ -2328,31 +1532,9 @@ public ComputeResourcePreference getGatewayComputeResourcePreference(String gate public StoragePreference getGatewayStoragePreference(String gatewayID, String storageId) throws RegistryServiceException, TException { try { - if (!isGatewayExistInternal(gatewayID)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new RegistryServiceException("Gateway does not exist.Please provide a valid gateway id..."); - } - GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); - if (!gwyResourceProfileRepository.isGatewayResourceProfileExists(gatewayID)) { - logger.error( - gatewayID, - "Given gateway profile does not exist in the system. Please provide a valid gateway id..."); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage( - "Given gateway profile does not exist in the system. Please provide a valid gateway id..."); - throw exception; - } - - StoragePreference storagePreference = - gwyResourceProfileRepository.getStoragePreference(gatewayID, storageId); - logger.debug("Airavata retrieved storage resource preference with gateway id : " + gatewayID - + " and for storage resource id : " + storageId); - return storagePreference; + return registryService.getGatewayStoragePreference(gatewayID, storageId); } catch (AppCatalogException e) { - logger.error(gatewayID, "Error while reading gateway data storage preference...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while reading gateway data storage preference. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while reading gateway data storage preference"); } } @@ -2367,18 +1549,9 @@ public StoragePreference getGatewayStoragePreference(String gatewayID, String st public List getAllGatewayComputeResourcePreferences(String gatewayID) throws RegistryServiceException, TException { try { - if (!isGatewayExistInternal(gatewayID)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new RegistryServiceException("Gateway does not exist.Please provide a valid gateway id..."); - } - GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); - return gwyResourceProfileRepository.getGatewayProfile(gatewayID).getComputeResourcePreferences(); - } catch (Exception e) { - logger.error(gatewayID, "Error while reading gateway compute resource preferences...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage( - "Error while reading gateway compute resource preferences. More info : " + e.getMessage()); - throw exception; + return registryService.getAllGatewayComputeResourcePreferences(gatewayID); + } catch (AppCatalogException e) { + throw convertToRegistryServiceException(e, "Error while reading gateway compute resource preferences"); } } @@ -2393,17 +1566,9 @@ public List getAllGatewayComputeResourcePreferences(S public List getAllGatewayStoragePreferences(String gatewayID) throws RegistryServiceException, TException { try { - if (!isGatewayExistInternal(gatewayID)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new RegistryServiceException("Gateway does not exist.Please provide a valid gateway id..."); - } - GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); - return gwyResourceProfileRepository.getGatewayProfile(gatewayID).getStoragePreferences(); - } catch (Exception e) { - logger.error(gatewayID, "Error while reading gateway data storage preferences...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while reading gateway data storage preferences. More info : " + e.getMessage()); - throw exception; + return registryService.getAllGatewayStoragePreferences(gatewayID); + } catch (AppCatalogException e) { + throw convertToRegistryServiceException(e, "Error while reading gateway data storage preferences"); } } @@ -2416,12 +1581,9 @@ public List getAllGatewayStoragePreferences(String gatewayID) @Override public List getAllGatewayResourceProfiles() throws RegistryServiceException, TException { try { - GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); - return gwyResourceProfileRepository.getAllGatewayProfiles(); - } catch (Exception e) { - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while reading retrieving all gateway profiles. More info : " + e.getMessage()); - throw exception; + return registryService.getAllGatewayResourceProfiles(); + } catch (AppCatalogException e) { + throw convertToRegistryServiceException(e, "Error while reading retrieving all gateway profiles"); } } @@ -2437,20 +1599,9 @@ public List getAllGatewayResourceProfiles() throws Regis public boolean deleteGatewayComputeResourcePreference(String gatewayID, String computeResourceId) throws RegistryServiceException, TException { try { - if (!isGatewayExistInternal(gatewayID)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new RegistryServiceException("Gateway does not exist.Please provide a valid gateway id..."); - } - GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); - - return gwyResourceProfileRepository.removeComputeResourcePreferenceFromGateway( - gatewayID, computeResourceId); - } catch (Exception e) { - logger.error(gatewayID, "Error while reading gateway compute resource preference...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage( - "Error while updating gateway compute resource preference. More info : " + e.getMessage()); - throw exception; + return registryService.deleteGatewayComputeResourcePreference(gatewayID, computeResourceId); + } catch (AppCatalogException e) { + throw convertToRegistryServiceException(e, "Error while updating gateway compute resource preference"); } } @@ -2466,60 +1617,36 @@ public boolean deleteGatewayComputeResourcePreference(String gatewayID, String c public boolean deleteGatewayStoragePreference(String gatewayID, String storageId) throws RegistryServiceException, TException { try { - if (!isGatewayExistInternal(gatewayID)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new RegistryServiceException("Gateway does not exist.Please provide a valid gateway id..."); - } - - GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); - return gwyResourceProfileRepository.removeDataStoragePreferenceFromGateway(gatewayID, storageId); - } catch (Exception e) { - logger.error(gatewayID, "Error while reading gateway data storage preference...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while updating gateway data storage preference. More info : " + e.getMessage()); - throw exception; + return registryService.deleteGatewayStoragePreference(gatewayID, storageId); + } catch (AppCatalogException e) { + throw convertToRegistryServiceException(e, "Error while updating gateway data storage preference"); } } @Override public DataProductModel getDataProduct(String productUri) throws RegistryServiceException, TException { try { - DataProductModel dataProductModel = dataProductRepository.getDataProduct(productUri); - return dataProductModel; + return registryService.getDataProduct(productUri); } catch (RegistryException e) { - String msg = "Error in retreiving the data product " + productUri + "."; - logger.error(msg, e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error in retreiving the data product " + productUri); } } @Override public DataProductModel getParentDataProduct(String productUri) throws RegistryServiceException, TException { try { - DataProductModel dataProductModel = dataProductRepository.getParentDataProduct(productUri); - return dataProductModel; + return registryService.getParentDataProduct(productUri); } catch (RegistryException e) { - String msg = "Error in retreiving the parent data product for " + productUri + "."; - logger.error(msg, e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error in retreiving the parent data product for " + productUri); } } @Override public List getChildDataProducts(String productUri) throws RegistryServiceException, TException { try { - List dataProductModels = dataProductRepository.getChildDataProducts(productUri); - return dataProductModels; + return registryService.getChildDataProducts(productUri); } catch (RegistryException e) { - String msg = "Error in retreiving the child products for " + productUri + "."; - logger.error(msg, e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error in retreiving the child products for " + productUri); } } @@ -2528,15 +1655,9 @@ public List searchDataProductsByName( String gatewayId, String userId, String productName, int limit, int offset) throws RegistryServiceException, TException { try { - List dataProductModels = - dataProductRepository.searchDataProductsByName(gatewayId, userId, productName, limit, offset); - return dataProductModels; + return registryService.searchDataProductsByName(gatewayId, userId, productName, limit, offset); } catch (RegistryException e) { - String msg = "Error in searching the data products for name " + productName + "."; - logger.error(msg, e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error in searching the data products for name " + productName); } } @@ -2544,20 +1665,9 @@ public List searchDataProductsByName( public String createGroupResourceProfile(GroupResourceProfile groupResourceProfile) throws RegistryServiceException, TException { try { - if (!isGatewayExistInternal(groupResourceProfile.getGatewayId())) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new RegistryServiceException("Gateway does not exist.Please provide a valid gateway id..."); - } - GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); - String groupResourceProfileId = - groupResourceProfileRepository.addGroupResourceProfile(groupResourceProfile); - logger.debug("New Group Resource Profile Created: " + groupResourceProfileId); - return groupResourceProfileId; - } catch (Exception e) { - logger.error("Error while creating group resource profile...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while creating group resource profile. More info : " + e.getMessage()); - throw exception; + return registryService.createGroupResourceProfile(groupResourceProfile); + } catch (AppCatalogException e) { + throw convertToRegistryServiceException(e, "Error while creating group resource profile"); } } @@ -2565,24 +1675,9 @@ public String createGroupResourceProfile(GroupResourceProfile groupResourceProfi public void updateGroupResourceProfile(GroupResourceProfile groupResourceProfile) throws RegistryServiceException, TException { try { - GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); - if (!groupResourceProfileRepository.isGroupResourceProfileExists( - groupResourceProfile.getGroupResourceProfileId())) { - logger.error( - "Cannot update. No group resource profile found with matching gatewayId and groupResourceProfileId"); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage( - "Cannot update. No group resource profile found with matching gatewayId and groupResourceProfileId"); - throw exception; - } - String groupResourceProfileId = - groupResourceProfileRepository.updateGroupResourceProfile(groupResourceProfile); - logger.debug(" Group Resource Profile updated: " + groupResourceProfileId); - } catch (Exception e) { - logger.error("Error while updating group resource profile...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while updating group resource profile. More info : " + e.getMessage()); - throw exception; + registryService.updateGroupResourceProfile(groupResourceProfile); + } catch (AppCatalogException e) { + throw convertToRegistryServiceException(e, "Error while updating group resource profile"); } } @@ -2590,21 +1685,9 @@ public void updateGroupResourceProfile(GroupResourceProfile groupResourceProfile public GroupResourceProfile getGroupResourceProfile(String groupResourceProfileId) throws RegistryServiceException, TException { try { - GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); - if (!groupResourceProfileRepository.isGroupResourceProfileExists(groupResourceProfileId)) { - logger.error("No group resource profile found with matching gatewayId and groupResourceProfileId"); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage( - "No group resource profile found with matching gatewayId and groupResourceProfileId"); - throw exception; - } - - return groupResourceProfileRepository.getGroupResourceProfile(groupResourceProfileId); - } catch (Exception e) { - logger.error("Error while retrieving group resource profile...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving group resource profile. More info : " + e.getMessage()); - throw exception; + return registryService.getGroupResourceProfile(groupResourceProfileId); + } catch (AppCatalogException e) { + throw convertToRegistryServiceException(e, "Error while retrieving group resource profile"); } } @@ -2612,13 +1695,9 @@ public GroupResourceProfile getGroupResourceProfile(String groupResourceProfileI public boolean isGroupResourceProfileExists(String groupResourceProfileId) throws RegistryServiceException, TException { try { - GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); - return groupResourceProfileRepository.isGroupResourceProfileExists(groupResourceProfileId); - } catch (Exception e) { - logger.error("Error while retrieving group resource profile...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving group resource profile. More info : " + e.getMessage()); - throw exception; + return registryService.isGroupResourceProfileExists(groupResourceProfileId); + } catch (AppCatalogException e) { + throw convertToRegistryServiceException(e, "Error while retrieving group resource profile"); } } @@ -2626,21 +1705,9 @@ public boolean isGroupResourceProfileExists(String groupResourceProfileId) public boolean removeGroupResourceProfile(String groupResourceProfileId) throws RegistryServiceException, TException { try { - GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); - if (!groupResourceProfileRepository.isGroupResourceProfileExists(groupResourceProfileId)) { - logger.error( - "Cannot Remove. No group resource profile found with matching gatewayId and groupResourceProfileId"); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage( - "Cannot Remove. No group resource profile found with matching gatewayId and groupResourceProfileId"); - throw exception; - } - return groupResourceProfileRepository.removeGroupResourceProfile(groupResourceProfileId); - } catch (Exception e) { - logger.error("Error while removing group resource profile...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while removing group resource profile. More info : " + e.getMessage()); - throw exception; + return registryService.removeGroupResourceProfile(groupResourceProfileId); + } catch (AppCatalogException e) { + throw convertToRegistryServiceException(e, "Error while removing group resource profile"); } } @@ -2648,13 +1715,9 @@ public boolean removeGroupResourceProfile(String groupResourceProfileId) public List getGroupResourceList(String gatewayId, List accessibleGroupResProfileIds) throws RegistryServiceException, TException { try { - GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); - return groupResourceProfileRepository.getAllGroupResourceProfiles(gatewayId, accessibleGroupResProfileIds); - } catch (Exception e) { - logger.error("Error while retrieving group resource list ", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving group resource list. More info : " + e.getMessage()); - throw exception; + return registryService.getGroupResourceList(gatewayId, accessibleGroupResProfileIds); + } catch (AppCatalogException e) { + throw convertToRegistryServiceException(e, "Error while retrieving group resource list"); } } @@ -2662,16 +1725,9 @@ public List getGroupResourceList(String gatewayId, List getGroupComputeResourcePrefList(String groupResourceProfileId) throws RegistryServiceException, TException { try { - GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); - return groupResourceProfileRepository.getAllGroupComputeResourcePreferences(groupResourceProfileId); - } catch (Exception e) { - logger.error("Error while retrieving retrieving Group Compute Resource Preference list", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage( - "Error while retrieving retrieving Group Compute Resource Preference list. More info : " - + e.getMessage()); - throw exception; + return registryService.getGroupComputeResourcePrefList(groupResourceProfileId); + } catch (AppCatalogException e) { + throw convertToRegistryServiceException(e, "Error while retrieving retrieving Group Compute Resource Preference list"); } } @@ -2813,15 +1805,9 @@ public List getGroupComputeResourcePrefList(Stri public List getGroupBatchQueueResourcePolicyList(String groupResourceProfileId) throws RegistryServiceException, TException { try { - GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); - return groupResourceProfileRepository.getAllGroupBatchQueueResourcePolicies(groupResourceProfileId); - } catch (Exception e) { - logger.error("Error while retrieving retrieving Group Batch Queue Resource policy list", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage( - "Error while retrieving retrieving Group Batch Queue Resource policy list. More info : " - + e.getMessage()); - throw exception; + return registryService.getGroupBatchQueueResourcePolicyList(groupResourceProfileId); + } catch (AppCatalogException e) { + throw convertToRegistryServiceException(e, "Error while retrieving retrieving Group Batch Queue Resource policy list"); } } @@ -2829,14 +1815,9 @@ public List getGroupBatchQueueResourcePolicyList(Strin public List getGroupComputeResourcePolicyList(String groupResourceProfileId) throws RegistryServiceException, TException { try { - GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); - return groupResourceProfileRepository.getAllGroupComputeResourcePolicies(groupResourceProfileId); - } catch (Exception e) { - logger.error("Error while retrieving retrieving Group Compute Resource policy list", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving retrieving Group Compute Resource policy list. More info : " - + e.getMessage()); - throw exception; + return registryService.getGroupComputeResourcePolicyList(groupResourceProfileId); + } catch (AppCatalogException e) { + throw convertToRegistryServiceException(e, "Error while retrieving retrieving Group Compute Resource policy list"); } } @@ -2844,14 +1825,9 @@ public List getGroupComputeResourcePolicyList(String grou public String registerReplicaLocation(DataReplicaLocationModel replicaLocationModel) throws RegistryServiceException, TException { try { - String replicaId = dataReplicaLocationRepository.registerReplicaLocation(replicaLocationModel); - return replicaId; + return registryService.registerReplicaLocation(replicaLocationModel); } catch (RegistryException e) { - String msg = "Error in retreiving the replica " + replicaLocationModel.getReplicaName() + "."; - logger.error(msg, e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error in retreiving the replica " + replicaLocationModel.getReplicaName()); } } @@ -2863,14 +1839,9 @@ public String registerReplicaLocation(DataReplicaLocationModel replicaLocationMo @Override public String registerDataProduct(DataProductModel dataProductModel) throws RegistryServiceException, TException { try { - String productUrl = dataProductRepository.registerDataProduct(dataProductModel); - return productUrl; + return registryService.registerDataProduct(dataProductModel); } catch (RegistryException e) { - String msg = "Error in registering the data resource" + dataProductModel.getProductName() + "."; - logger.error(msg, e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error in registering the data resource" + dataProductModel.getProductName()); } } @@ -2888,33 +1859,9 @@ public boolean updateGatewayStoragePreference( String gatewayID, String storageId, StoragePreference storagePreference) throws RegistryServiceException, TException { try { - if (!isGatewayExistInternal(gatewayID)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new RegistryServiceException("Gateway does not exist.Please provide a valid gateway id..."); - } - GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); - GatewayResourceProfile profile = gwyResourceProfileRepository.getGatewayProfile(gatewayID); - List dataStoragePreferences = profile.getStoragePreferences(); - StoragePreference preferenceToRemove = null; - for (StoragePreference preference : dataStoragePreferences) { - if (preference.getStorageResourceId().equals(storageId)) { - preferenceToRemove = preference; - break; - } - } - if (preferenceToRemove != null) { - profile.getStoragePreferences().remove(preferenceToRemove); - } - profile.getStoragePreferences().add(storagePreference); - gwyResourceProfileRepository.updateGatewayResourceProfile(profile); - logger.debug("Airavata updated storage resource preference with gateway id : " + gatewayID - + " and for storage resource id : " + storageId); - return true; - } catch (Exception e) { - logger.error(gatewayID, "Error while reading gateway data storage preference...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while updating gateway data storage preference. More info : " + e.getMessage()); - throw exception; + return registryService.updateGatewayStoragePreference(gatewayID, storageId, storagePreference); + } catch (AppCatalogException e) { + throw convertToRegistryServiceException(e, "Error while updating gateway data storage preference"); } } @@ -2932,34 +1879,9 @@ public boolean updateGatewayComputeResourcePreference( String gatewayID, String computeResourceId, ComputeResourcePreference computeResourcePreference) throws RegistryServiceException, TException { try { - if (!isGatewayExistInternal(gatewayID)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new RegistryServiceException("Gateway does not exist.Please provide a valid gateway id..."); - } - GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); - GatewayResourceProfile profile = gwyResourceProfileRepository.getGatewayProfile(gatewayID); - List computeResourcePreferences = profile.getComputeResourcePreferences(); - ComputeResourcePreference preferenceToRemove = null; - for (ComputeResourcePreference preference : computeResourcePreferences) { - if (preference.getComputeResourceId().equals(computeResourceId)) { - preferenceToRemove = preference; - break; - } - } - if (preferenceToRemove != null) { - profile.getComputeResourcePreferences().remove(preferenceToRemove); - } - profile.getComputeResourcePreferences().add(computeResourcePreference); - gwyResourceProfileRepository.updateGatewayResourceProfile(profile); - logger.debug("Airavata updated compute resource preference with gateway id : " + gatewayID - + " and for compute resource id : " + computeResourceId); - return true; - } catch (Exception e) { - logger.error(gatewayID, "Error while reading gateway compute resource preference...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage( - "Error while updating gateway compute resource preference. More info : " + e.getMessage()); - throw exception; + return registryService.updateGatewayComputeResourcePreference(gatewayID, computeResourceId, computeResourcePreference); + } catch (AppCatalogException e) { + throw convertToRegistryServiceException(e, "Error while updating gateway compute resource preference"); } } @@ -2978,29 +1900,9 @@ public boolean addGatewayStoragePreference( String gatewayID, String storageResourceId, StoragePreference dataStoragePreference) throws RegistryServiceException, TException { try { - if (!isGatewayExistInternal(gatewayID)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new RegistryServiceException("Gateway does not exist.Please provide a valid gateway id..."); - } - - GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); - if (!(gwyResourceProfileRepository.isExists(gatewayID))) { - throw new RegistryServiceException("Gateway resource profile '" + gatewayID + "' does not exist!!!"); - } - GatewayResourceProfile profile = gwyResourceProfileRepository.getGatewayProfile(gatewayID); - - dataStoragePreference.setStorageResourceId(storageResourceId); - profile.addToStoragePreferences(dataStoragePreference); - gwyResourceProfileRepository.updateGatewayResourceProfile(profile); - logger.debug("Airavata added storage resource preference with gateway id : " + gatewayID - + " and for storage resource id : " + storageResourceId); - return true; - } catch (Exception e) { - logger.error(gatewayID, "Error while registering gateway resource profile preference...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage( - "Error while registering gateway resource profile preference. More info : " + e.getMessage()); - throw exception; + return registryService.addGatewayStoragePreference(gatewayID, storageResourceId, dataStoragePreference); + } catch (AppCatalogException e) { + throw convertToRegistryServiceException(e, "Error while registering gateway resource profile preference"); } } @@ -3019,26 +1921,9 @@ public boolean addGatewayComputeResourcePreference( String gatewayID, String computeResourceId, ComputeResourcePreference computeResourcePreference) throws RegistryServiceException, TException { try { - if (!isGatewayExistInternal(gatewayID)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new RegistryServiceException("Gateway does not exist.Please provide a valid gateway id..."); - } - GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); - if (!(gwyResourceProfileRepository.isExists(gatewayID))) { - throw new RegistryServiceException("Gateway resource profile '" + gatewayID + "' does not exist!!!"); - } - GatewayResourceProfile profile = gwyResourceProfileRepository.getGatewayProfile(gatewayID); - profile.addToComputeResourcePreferences(computeResourcePreference); - gwyResourceProfileRepository.updateGatewayResourceProfile(profile); - logger.debug("Airavata added gateway compute resource preference with gateway id : " + gatewayID - + " and for compute resource id : " + computeResourceId); - return true; - } catch (Exception e) { - logger.error(gatewayID, "Error while registering gateway resource profile preference...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage( - "Error while registering gateway resource profile preference. More info : " + e.getMessage()); - throw exception; + return registryService.addGatewayComputeResourcePreference(gatewayID, computeResourceId, computeResourcePreference); + } catch (AppCatalogException e) { + throw convertToRegistryServiceException(e, "Error while registering gateway resource profile preference"); } } @@ -3054,19 +1939,9 @@ public boolean addGatewayComputeResourcePreference( public boolean updateGatewayResourceProfile(String gatewayID, GatewayResourceProfile gatewayResourceProfile) throws RegistryServiceException, TException { try { - if (!isGatewayExistInternal(gatewayID)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new RegistryServiceException("Gateway does not exist.Please provide a valid gateway id..."); - } - GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); - gwyResourceProfileRepository.updateGatewayResourceProfile(gatewayResourceProfile); - logger.debug("Airavata updated gateway profile with gateway id : " + gatewayID); - return true; - } catch (Exception e) { - logger.error(gatewayID, "Error while updating gateway resource profile...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while updating gateway resource profile. More info : " + e.getMessage()); - throw exception; + return registryService.updateGatewayResourceProfile(gatewayID, gatewayResourceProfile); + } catch (AppCatalogException e) { + throw convertToRegistryServiceException(e, "Error while updating gateway resource profile"); } } @@ -3083,26 +1958,9 @@ public boolean updateGatewayResourceProfile(String gatewayID, GatewayResourcePro public String registerGatewayResourceProfile(GatewayResourceProfile gatewayResourceProfile) throws RegistryServiceException, TException { try { - if (!validateString(gatewayResourceProfile.getGatewayID())) { - logger.error("Cannot create gateway profile with empty gateway id"); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Cannot create gateway profile with empty gateway id"); - throw exception; - } - if (!isGatewayExistInternal(gatewayResourceProfile.getGatewayID())) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new RegistryServiceException("Gateway does not exist.Please provide a valid gateway id..."); - } - GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); - String resourceProfile = gwyResourceProfileRepository.addGatewayResourceProfile(gatewayResourceProfile); - logger.debug( - "Airavata registered gateway profile with gateway id : " + gatewayResourceProfile.getGatewayID()); - return resourceProfile; - } catch (Exception e) { - logger.error("Error while registering gateway resource profile...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while registering gateway resource profile. More info : " + e.getMessage()); - throw exception; + return registryService.registerGatewayResourceProfile(gatewayResourceProfile); + } catch (AppCatalogException e) { + throw convertToRegistryServiceException(e, "Error while registering gateway resource profile"); } } @@ -3110,13 +1968,9 @@ public String registerGatewayResourceProfile(GatewayResourceProfile gatewayResou public boolean updateResourceJobManager(String resourceJobManagerId, ResourceJobManager updatedResourceJobManager) throws RegistryServiceException, TException { try { - new ComputeResourceRepository().updateResourceJobManager(resourceJobManagerId, updatedResourceJobManager); - return true; + return registryService.updateResourceJobManager(resourceJobManagerId, updatedResourceJobManager); } catch (AppCatalogException e) { - logger.error(resourceJobManagerId, "Error while updating resource job manager...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while updating resource job manager. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while updating resource job manager"); } } @@ -3124,12 +1978,9 @@ public boolean updateResourceJobManager(String resourceJobManagerId, ResourceJob public String registerResourceJobManager(ResourceJobManager resourceJobManager) throws RegistryServiceException, TException { try { - return new ComputeResourceRepository().addResourceJobManager(resourceJobManager); + return registryService.registerResourceJobManager(resourceJobManager); } catch (AppCatalogException e) { - logger.error(resourceJobManager.getResourceJobManagerId(), "Error while adding resource job manager...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while adding resource job manager. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while adding resource job manager"); } } @@ -3145,27 +1996,9 @@ public String registerResourceJobManager(ResourceJobManager resourceJobManager) public boolean deleteDataMovementInterface(String resourceId, String dataMovementInterfaceId, DMType dmType) throws RegistryServiceException, TException { try { - switch (dmType) { - case COMPUTE_RESOURCE: - new ComputeResourceRepository().removeDataMovementInterface(resourceId, dataMovementInterfaceId); - logger.debug( - "Airavata deleted data movement interface with interface id : " + dataMovementInterfaceId); - return true; - case STORAGE_RESOURCE: - storageResourceRepository.removeDataMovementInterface(resourceId, dataMovementInterfaceId); - logger.debug( - "Airavata deleted data movement interface with interface id : " + dataMovementInterfaceId); - return true; - default: - logger.error( - "Unsupported data movement type specifies.. Please provide the correct data movement type... "); - return false; - } + return registryService.deleteDataMovementInterface(resourceId, dataMovementInterfaceId, dmType); } catch (AppCatalogException e) { - logger.error(dataMovementInterfaceId, "Error while deleting data movement interface...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while deleting data movement interface. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while deleting data movement interface"); } } @@ -3202,24 +2035,9 @@ public String addGridFTPDataMovementDetails( String computeResourceId, DMType dmType, int priorityOrder, GridFTPDataMovement gridFTPDataMovement) throws RegistryServiceException, TException { try { - ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); - String addDataMovementInterface = addDataMovementInterface( - computeResourceRepository, - computeResourceId, - dmType, - computeResourceRepository.addGridFTPDataMovement(gridFTPDataMovement), - DataMovementProtocol.GridFTP, - priorityOrder); - logger.debug("Airavata registered GridFTP data movement for resource Id: " + computeResourceId); - return addDataMovementInterface; + return registryService.addGridFTPDataMovementDetails(computeResourceId, dmType, priorityOrder, gridFTPDataMovement); } catch (AppCatalogException e) { - logger.error( - computeResourceId, "Error while adding data movement interface to resource compute resource...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding data movement interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while adding data movement interface to resource compute resource"); } } @@ -3256,22 +2074,9 @@ public String addUnicoreDataMovementDetails( String resourceId, DMType dmType, int priorityOrder, UnicoreDataMovement unicoreDataMovement) throws RegistryServiceException, TException { try { - ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); - String movementInterface = addDataMovementInterface( - computeResourceRepository, - resourceId, - dmType, - computeResourceRepository.addUnicoreDataMovement(unicoreDataMovement), - DataMovementProtocol.UNICORE_STORAGE_SERVICE, - priorityOrder); - logger.debug("Airavata registered UNICORE data movement for resource Id: " + resourceId); - return movementInterface; + return registryService.addUnicoreDataMovementDetails(resourceId, dmType, priorityOrder, unicoreDataMovement); } catch (AppCatalogException e) { - logger.error(resourceId, "Error while adding data movement interface to resource compute resource...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while adding data movement interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while adding data movement interface to resource compute resource"); } } @@ -3288,19 +2093,9 @@ public String addUnicoreDataMovementDetails( public boolean updateSCPDataMovementDetails(String dataMovementInterfaceId, SCPDataMovement scpDataMovement) throws RegistryServiceException, TException { try { - computeResourceRepository.updateScpDataMovement(scpDataMovement); - logger.debug("Airavata updated SCP data movement with data movement id: " + dataMovementInterfaceId); - return true; - } catch (Exception e) { - logger.error( - dataMovementInterfaceId, - "Error while adding job submission interface to resource compute resource...", - e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage( - "Error while adding job submission interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; + return registryService.updateSCPDataMovementDetails(dataMovementInterfaceId, scpDataMovement); + } catch (AppCatalogException e) { + throw convertToRegistryServiceException(e, "Error while updating SCP data movement"); } } @@ -3321,22 +2116,9 @@ public String addSCPDataMovementDetails( String resourceId, DMType dmType, int priorityOrder, SCPDataMovement scpDataMovement) throws RegistryServiceException, TException { try { - ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); - String movementInterface = addDataMovementInterface( - computeResourceRepository, - resourceId, - dmType, - computeResourceRepository.addScpDataMovement(scpDataMovement), - DataMovementProtocol.SCP, - priorityOrder); - logger.debug("Airavata registered SCP data movement for resource Id: " + resourceId); - return movementInterface; + return registryService.addSCPDataMovementDetails(resourceId, dmType, priorityOrder, scpDataMovement); } catch (AppCatalogException e) { - logger.error(resourceId, "Error while adding data movement interface to resource compute resource...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while adding data movement interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while adding data movement interface to resource compute resource"); } } @@ -3352,14 +2134,9 @@ public String addSCPDataMovementDetails( public boolean updateLocalDataMovementDetails(String dataMovementInterfaceId, LOCALDataMovement localDataMovement) throws RegistryServiceException, TException { try { - computeResourceRepository.updateLocalDataMovement(localDataMovement); - logger.debug("Airavata updated local data movement with data movement id: " + dataMovementInterfaceId); - return true; - } catch (Exception e) { - logger.error(dataMovementInterfaceId, "Error while updating local data movement interface..", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while updating local data movement interface. More info : " + e.getMessage()); - throw exception; + return registryService.updateLocalDataMovementDetails(dataMovementInterfaceId, localDataMovement); + } catch (AppCatalogException e) { + throw convertToRegistryServiceException(e, "Error while updating local data movement interface"); } } @@ -3380,22 +2157,9 @@ public String addLocalDataMovementDetails( String resourceId, DMType dataMoveType, int priorityOrder, LOCALDataMovement localDataMovement) throws RegistryServiceException, TException { try { - ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); - String movementInterface = addDataMovementInterface( - computeResourceRepository, - resourceId, - dataMoveType, - computeResourceRepository.addLocalDataMovement(localDataMovement), - DataMovementProtocol.LOCAL, - priorityOrder); - logger.debug("Airavata registered local data movement for resource Id: " + resourceId); - return movementInterface; + return registryService.addLocalDataMovementDetails(resourceId, dataMoveType, priorityOrder, localDataMovement); } catch (AppCatalogException e) { - logger.error(resourceId, "Error while adding data movement interface to resource resource...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage( - "Error while adding data movement interface to resource. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while adding data movement interface to resource"); } } @@ -3426,20 +2190,9 @@ public boolean updateUnicoreJobSubmissionDetails( public boolean updateCloudJobSubmissionDetails(String jobSubmissionInterfaceId, CloudJobSubmission sshJobSubmission) throws RegistryServiceException, TException { try { - computeResourceRepository.updateCloudJobSubmission(sshJobSubmission); - logger.debug("Airavata updated Cloud job submission for job submission interface id: " - + jobSubmissionInterfaceId); - return true; - } catch (Exception e) { - logger.error( - jobSubmissionInterfaceId, - "Error while adding job submission interface to resource compute resource...", - e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage( - "Error while adding job submission interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; + return registryService.updateCloudJobSubmissionDetails(jobSubmissionInterfaceId, sshJobSubmission); + } catch (AppCatalogException e) { + throw convertToRegistryServiceException(e, "Error while updating Cloud job submission"); } } @@ -3455,20 +2208,9 @@ public boolean updateCloudJobSubmissionDetails(String jobSubmissionInterfaceId, public boolean updateSSHJobSubmissionDetails(String jobSubmissionInterfaceId, SSHJobSubmission sshJobSubmission) throws RegistryServiceException, TException { try { - computeResourceRepository.updateSSHJobSubmission(sshJobSubmission); - logger.debug( - "Airavata updated SSH job submission for job submission interface id: " + jobSubmissionInterfaceId); - return true; - } catch (Exception e) { - logger.error( - jobSubmissionInterfaceId, - "Error while adding job submission interface to resource compute resource...", - e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage( - "Error while adding job submission interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; + return registryService.updateSSHJobSubmissionDetails(jobSubmissionInterfaceId, sshJobSubmission); + } catch (AppCatalogException e) { + throw convertToRegistryServiceException(e, "Error while updating SSH job submission"); } } @@ -3500,25 +2242,9 @@ public String addCloudJobSubmissionDetails( String computeResourceId, int priorityOrder, CloudJobSubmission cloudSubmission) throws RegistryServiceException, TException { try { - ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); - String submissionInterface = addJobSubmissionInterface( - computeResourceRepository, - computeResourceId, - computeResourceRepository.addCloudJobSubmission(cloudSubmission), - JobSubmissionProtocol.CLOUD, - priorityOrder); - logger.debug("Airavata registered Cloud job submission for compute resource id: " + computeResourceId); - return submissionInterface; + return registryService.addCloudJobSubmissionDetails(computeResourceId, priorityOrder, cloudSubmission); } catch (AppCatalogException e) { - logger.error( - computeResourceId, - "Error while adding job submission interface to resource compute resource...", - e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage( - "Error while adding job submission interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while adding job submission interface to resource compute resource"); } } @@ -3537,22 +2263,9 @@ public String addUNICOREJobSubmissionDetails( String computeResourceId, int priorityOrder, UnicoreJobSubmission unicoreJobSubmission) throws RegistryServiceException, TException { try { - ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); - String submissionInterface = addJobSubmissionInterface( - computeResourceRepository, - computeResourceId, - computeResourceRepository.addUNICOREJobSubmission(unicoreJobSubmission), - JobSubmissionProtocol.UNICORE, - priorityOrder); - logger.debug("Airavata registered UNICORE job submission for compute resource id: " + computeResourceId); - return submissionInterface; + return registryService.addUNICOREJobSubmissionDetails(computeResourceId, priorityOrder, unicoreJobSubmission); } catch (AppCatalogException e) { - logger.error("Error while adding job submission interface to resource compute resource...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage( - "Error while adding job submission interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while adding job submission interface to resource compute resource"); } } @@ -3571,25 +2284,9 @@ public String addSSHForkJobSubmissionDetails( String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) throws RegistryServiceException, TException { try { - ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); - String submissionDetails = addJobSubmissionInterface( - computeResourceRepository, - computeResourceId, - computeResourceRepository.addSSHJobSubmission(sshJobSubmission), - JobSubmissionProtocol.SSH_FORK, - priorityOrder); - logger.debug("Airavata registered Fork job submission for compute resource id: " + computeResourceId); - return submissionDetails; + return registryService.addSSHForkJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); } catch (AppCatalogException e) { - logger.error( - computeResourceId, - "Error while adding job submission interface to resource compute resource...", - e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage( - "Error while adding job submission interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while adding job submission interface to resource compute resource"); } } @@ -3608,25 +2305,9 @@ public String addSSHJobSubmissionDetails( String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) throws RegistryServiceException, TException { try { - ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); - String submissionInterface = addJobSubmissionInterface( - computeResourceRepository, - computeResourceId, - computeResourceRepository.addSSHJobSubmission(sshJobSubmission), - JobSubmissionProtocol.SSH, - priorityOrder); - logger.debug("Airavata registered SSH job submission for compute resource id: " + computeResourceId); - return submissionInterface; + return registryService.addSSHJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); } catch (AppCatalogException e) { - logger.error( - computeResourceId, - "Error while adding job submission interface to resource compute resource...", - e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage( - "Error while adding job submission interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while adding job submission interface to resource compute resource"); } } @@ -3642,20 +2323,9 @@ public String addSSHJobSubmissionDetails( public boolean updateLocalSubmissionDetails(String jobSubmissionInterfaceId, LOCALSubmission localSubmission) throws RegistryServiceException, TException { try { - computeResourceRepository.updateLocalJobSubmission(localSubmission); - logger.debug("Airavata updated local job submission for job submission interface id: " - + jobSubmissionInterfaceId); - return true; - } catch (Exception e) { - logger.error( - jobSubmissionInterfaceId, - "Error while adding job submission interface to resource compute resource...", - e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage( - "Error while adding job submission interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; + return registryService.updateLocalSubmissionDetails(jobSubmissionInterfaceId, localSubmission); + } catch (AppCatalogException e) { + throw convertToRegistryServiceException(e, "Error while updating local job submission"); } } @@ -3674,25 +2344,9 @@ public String addLocalSubmissionDetails( String computeResourceId, int priorityOrder, LOCALSubmission localSubmission) throws RegistryServiceException, TException { try { - ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); - String submissionInterface = addJobSubmissionInterface( - computeResourceRepository, - computeResourceId, - computeResourceRepository.addLocalJobSubmission(localSubmission), - JobSubmissionProtocol.LOCAL, - priorityOrder); - logger.debug("Airavata added local job submission for compute resource id: " + computeResourceId); - return submissionInterface; + return registryService.addLocalSubmissionDetails(computeResourceId, priorityOrder, localSubmission); } catch (AppCatalogException e) { - logger.error( - computeResourceId, - "Error while adding job submission interface to resource compute resource...", - e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage( - "Error while adding job submission interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while adding job submission interface to resource compute resource"); } } @@ -3709,14 +2363,9 @@ public boolean updateStorageResource( String storageResourceId, StorageResourceDescription storageResourceDescription) throws RegistryServiceException, TException { try { - storageResourceRepository.updateStorageResource(storageResourceId, storageResourceDescription); - logger.debug("Airavata updated storage resource with storage resource Id : " + storageResourceId); - return true; + return registryService.updateStorageResource(storageResourceId, storageResourceDescription); } catch (AppCatalogException e) { - logger.error(storageResourceId, "Error while updating storage resource...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while updaing storage resource. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while updating storage resource"); } } @@ -3731,14 +2380,9 @@ public boolean updateStorageResource( public String registerStorageResource(StorageResourceDescription storageResourceDescription) throws RegistryServiceException, TException { try { - String storageResource = storageResourceRepository.addStorageResource(storageResourceDescription); - logger.debug("Airavata registered storage resource with storage resource Id : " + storageResource); - return storageResource; + return registryService.registerStorageResource(storageResourceDescription); } catch (AppCatalogException e) { - logger.error("Error while saving storage resource...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while saving storage resource. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while saving storage resource"); } } @@ -3755,14 +2399,9 @@ public boolean updateComputeResource( String computeResourceId, ComputeResourceDescription computeResourceDescription) throws RegistryServiceException, TException { try { - new ComputeResourceRepository().updateComputeResource(computeResourceId, computeResourceDescription); - logger.debug("Airavata updated compute resource with compute resource Id : " + computeResourceId); - return true; + return registryService.updateComputeResource(computeResourceId, computeResourceDescription); } catch (AppCatalogException e) { - logger.error(computeResourceId, "Error while updating compute resource...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while updaing compute resource. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while updating compute resource"); } } @@ -3777,14 +2416,9 @@ public boolean updateComputeResource( public String registerComputeResource(ComputeResourceDescription computeResourceDescription) throws RegistryServiceException, TException { try { - String computeResource = new ComputeResourceRepository().addComputeResource(computeResourceDescription); - logger.debug("Airavata registered compute resource with compute resource Id : " + computeResource); - return computeResource; + return registryService.registerComputeResource(computeResourceDescription); } catch (AppCatalogException e) { - logger.error("Error while saving compute resource...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while saving compute resource. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while saving compute resource"); } } @@ -3801,14 +2435,9 @@ public boolean updateApplicationInterface( String appInterfaceId, ApplicationInterfaceDescription applicationInterface) throws RegistryServiceException, TException { try { - applicationInterfaceRepository.updateApplicationInterface(appInterfaceId, applicationInterface); - logger.debug("Airavata updated application interface with interface id : " + appInterfaceId); - return true; + return registryService.updateApplicationInterface(appInterfaceId, applicationInterface); } catch (AppCatalogException e) { - logger.error(appInterfaceId, "Error while updating application interface...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while updating application interface. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while updating application interface"); } } @@ -3823,20 +2452,10 @@ public boolean updateApplicationInterface( @Override public String registerApplicationInterface(String gatewayId, ApplicationInterfaceDescription applicationInterface) throws RegistryServiceException, TException { - if (!isGatewayExistInternal(gatewayId)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new RegistryServiceException("Gateway does not exist.Please provide a valid gateway id..."); - } try { - String interfaceId = - applicationInterfaceRepository.addApplicationInterface(applicationInterface, gatewayId); - logger.debug("Airavata registered application interface for gateway id : " + gatewayId); - return interfaceId; + return registryService.registerApplicationInterface(gatewayId, applicationInterface); } catch (AppCatalogException e) { - logger.error("Error while adding application interface...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while adding application interface. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while adding application interface"); } } @@ -3853,14 +2472,9 @@ public boolean updateApplicationDeployment( String appDeploymentId, ApplicationDeploymentDescription applicationDeployment) throws RegistryServiceException, TException { try { - applicationDeploymentRepository.updateApplicationDeployment(appDeploymentId, applicationDeployment); - logger.debug("Airavata updated application deployment for deployment id : " + appDeploymentId); - return true; + return registryService.updateApplicationDeployment(appDeploymentId, applicationDeployment); } catch (AppCatalogException e) { - logger.error(appDeploymentId, "Error while updating application deployment...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while updating application deployment. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while updating application deployment"); } } @@ -3876,20 +2490,10 @@ public boolean updateApplicationDeployment( public String registerApplicationDeployment( String gatewayId, ApplicationDeploymentDescription applicationDeployment) throws RegistryServiceException, TException { - if (!isGatewayExistInternal(gatewayId)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new RegistryServiceException("Gateway does not exist.Please provide a valid gateway id..."); - } try { - String deployment = - applicationDeploymentRepository.addApplicationDeployment(applicationDeployment, gatewayId); - logger.debug("Airavata registered application deployment for gateway id : " + gatewayId); - return deployment; + return registryService.registerApplicationDeployment(gatewayId, applicationDeployment); } catch (AppCatalogException e) { - logger.error("Error while adding application deployment...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while adding application deployment. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while adding application deployment"); } } @@ -3905,14 +2509,9 @@ public String registerApplicationDeployment( public boolean updateApplicationModule(String appModuleId, ApplicationModule applicationModule) throws RegistryServiceException, TException { try { - applicationInterfaceRepository.updateApplicationModule(appModuleId, applicationModule); - logger.debug("Airavata updated application module with module id: " + appModuleId); - return true; + return registryService.updateApplicationModule(appModuleId, applicationModule); } catch (AppCatalogException e) { - logger.error(appModuleId, "Error while updating application module...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while updating application module. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while updating application module"); } } @@ -3928,19 +2527,10 @@ public boolean updateApplicationModule(String appModuleId, ApplicationModule app @Override public String registerApplicationModule(String gatewayId, ApplicationModule applicationModule) throws RegistryServiceException, TException { - if (!isGatewayExistInternal(gatewayId)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new RegistryServiceException("Gateway does not exist.Please provide a valid gateway id..."); - } try { - String module = applicationInterfaceRepository.addApplicationModule(applicationModule, gatewayId); - logger.debug("Airavata registered application module for gateway id : " + gatewayId); - return module; + return registryService.registerApplicationModule(gatewayId, applicationModule); } catch (AppCatalogException e) { - logger.error("Error while adding application module...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while adding application module. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while adding application module"); } } @@ -3949,52 +2539,9 @@ public void updateResourceScheduleing( String airavataExperimentId, ComputationalResourceSchedulingModel resourceScheduling) throws RegistryServiceException, TException { try { - if (!experimentRepository.isExperimentExist(airavataExperimentId)) { - logger.debug( - airavataExperimentId, - "Update resource scheduling failed, experiment {} doesn't exist.", - airavataExperimentId); - throw new ExperimentNotFoundException( - "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); - } - ExperimentStatus experimentStatus = getExperimentStatusInternal(airavataExperimentId); - if (experimentStatus != null) { - ExperimentState experimentState = experimentStatus.getState(); - switch (experimentState) { - case CREATED: - case VALIDATED: - case CANCELED: - case FAILED: - processRepository.addProcessResourceSchedule(resourceScheduling, airavataExperimentId); - logger.debug( - airavataExperimentId, - "Successfully updated resource scheduling for the experiment {}.", - airavataExperimentId); - break; - default: - logger.error( - airavataExperimentId, - "Error while updating scheduling info. Update experiment is only valid for experiments " - + "with status CREATED, VALIDATED, CANCELLED, FAILED and UNKNOWN. Make sure the given " - + "experiment is in one of above statuses... "); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while updating experiment. Update experiment is only valid for experiments " - + "with status CREATED, VALIDATED, CANCELLED, FAILED and UNKNOWN. Make sure the given " - + "experiment is in one of above statuses... "); - throw exception; - } - } - } catch (Exception e) { - logger.error(airavataExperimentId, "Error while updating scheduling info", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage( - "Error while updating scheduling info. " + "Update experiment is only valid for experiments " - + "with status CREATED, VALIDATED, CANCELLED, FAILED and UNKNOWN. Make sure the given " - + "experiment is in one of above statuses... " - + e.getMessage()); - throw exception; + registryService.updateResourceScheduleing(airavataExperimentId, resourceScheduling); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while updating scheduling info"); } } @@ -4002,53 +2549,9 @@ public void updateResourceScheduleing( public void updateExperimentConfiguration(String airavataExperimentId, UserConfigurationDataModel userConfiguration) throws RegistryServiceException, TException { try { - if (!experimentRepository.isExperimentExist(airavataExperimentId)) { - logger.error( - airavataExperimentId, - "Update experiment configuration failed, experiment {} doesn't exist.", - airavataExperimentId); - throw new ExperimentNotFoundException( - "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); - } - ExperimentStatus experimentStatus = getExperimentStatusInternal(airavataExperimentId); - if (experimentStatus != null) { - ExperimentState experimentState = experimentStatus.getState(); - switch (experimentState) { - case CREATED: - case VALIDATED: - case CANCELED: - case FAILED: - experimentRepository.addUserConfigurationData(userConfiguration, airavataExperimentId); - logger.debug( - airavataExperimentId, - "Successfully updated experiment configuration for experiment {}.", - airavataExperimentId); - break; - default: - logger.error( - airavataExperimentId, - "Error while updating experiment {}. Update experiment is only valid for experiments " - + "with status CREATED, VALIDATED, CANCELLED, FAILED and UNKNOWN. Make sure the given " - + "experiment is in one of above statuses... ", - airavataExperimentId); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while updating experiment. Update experiment is only valid for experiments " - + "with status CREATED, VALIDATED, CANCELLED, FAILED and UNKNOWN. Make sure the given " - + "experiment is in one of above statuses... "); - throw exception; - } - } - } catch (Exception e) { - logger.error(airavataExperimentId, "Error while updating user configuration", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage( - "Error while updating user configuration. " + "Update experiment is only valid for experiments " - + "with status CREATED, VALIDATED, CANCELLED, FAILED and UNKNOWN. Make sure the given " - + "experiment is in one of above statuses... " - + e.getMessage()); - throw exception; + registryService.updateExperimentConfiguration(airavataExperimentId, userConfiguration); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while updating user configuration"); } } @@ -4080,74 +2583,9 @@ public void updateExperimentConfiguration(String airavataExperimentId, UserConfi public void updateExperiment(String airavataExperimentId, ExperimentModel experiment) throws RegistryServiceException, TException { try { - if (!experimentRepository.isExperimentExist(airavataExperimentId)) { - logger.error( - airavataExperimentId, - "Update request failed, Experiment {} doesn't exist.", - airavataExperimentId); - throw new RegistryServiceException( - "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); - } - - ExperimentStatus experimentStatus = getExperimentStatusInternal(airavataExperimentId); - if (experimentStatus != null) { - ExperimentState experimentState = experimentStatus.getState(); - switch (experimentState) { - case CREATED: - case SCHEDULED: - case VALIDATED: - if (experiment.getUserConfigurationData() != null - && experiment.getUserConfigurationData().getComputationalResourceScheduling() != null - && experiment - .getUserConfigurationData() - .getComputationalResourceScheduling() - .getResourceHostId() - != null) { - String compResourceId = experiment - .getUserConfigurationData() - .getComputationalResourceScheduling() - .getResourceHostId(); - ComputeResourceDescription computeResourceDescription = - new ComputeResourceRepository().getComputeResource(compResourceId); - if (!computeResourceDescription.isEnabled()) { - logger.error("Compute Resource is not enabled by the Admin!"); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Compute Resource is not enabled by the Admin!"); - throw exception; - } - } - experimentRepository.updateExperiment(experiment, airavataExperimentId); - logger.debug( - airavataExperimentId, - "Successfully updated experiment {} ", - experiment.getExperimentName()); - break; - default: - logger.error( - airavataExperimentId, - "Error while updating experiment. Update experiment is only valid for experiments " - + "with status CREATED, VALIDATED, CANCELLED, FAILED and UNKNOWN. Make sure the given " - + "experiment is in one of above statuses... "); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while updating experiment. Update experiment is only valid for experiments " - + "with status CREATED, VALIDATED, CANCELLED, FAILED and UNKNOWN. Make sure the given " - + "experiment is in one of above statuses... "); - throw exception; - } - } + registryService.updateExperiment(airavataExperimentId, experiment); } catch (RegistryException e) { - logger.error(airavataExperimentId, "Error while updating experiment", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while updating experiment. More info : " + e.getMessage()); - throw exception; - } catch (AppCatalogException e) { - logger.error(airavataExperimentId, "Error while updating experiment", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while updating experiment. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while updating experiment"); } } @@ -4199,74 +2637,9 @@ public void updateExperiment(String airavataExperimentId, ExperimentModel experi public String createExperiment(String gatewayId, ExperimentModel experiment) throws RegistryServiceException, TException { try { - if (!validateString(experiment.getExperimentName())) { - logger.error("Cannot create experiments with empty experiment name"); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Cannot create experiments with empty experiment name"); - throw exception; - } - logger.info("Creating experiment with name " + experiment.getExperimentName()); - if (!isGatewayExistInternal(gatewayId)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - } - - if (experiment.getUserConfigurationData() != null - && experiment.getUserConfigurationData().getComputationalResourceScheduling() != null - && experiment - .getUserConfigurationData() - .getComputationalResourceScheduling() - .getResourceHostId() - != null) { - - String compResourceId = experiment - .getUserConfigurationData() - .getComputationalResourceScheduling() - .getResourceHostId(); - ComputeResourceDescription computeResourceDescription = - new ComputeResourceRepository().getComputeResource(compResourceId); - if (!computeResourceDescription.isEnabled()) { - logger.error("Compute Resource is not enabled by the Admin!"); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Compute Resource is not enabled by the Admin!"); - throw exception; - } - } else if (!experiment - .getUserConfigurationData() - .getAutoScheduledCompResourceSchedulingList() - .isEmpty()) { - for (ComputationalResourceSchedulingModel computationalResourceScheduling : - experiment.getUserConfigurationData().getAutoScheduledCompResourceSchedulingList()) { - ComputeResourceDescription computeResourceDescription = new ComputeResourceRepository() - .getComputeResource(computationalResourceScheduling.getResourceHostId()); - if (!computeResourceDescription.isEnabled()) { - logger.error("Compute Resource with id" + computationalResourceScheduling.getResourceHostId() - + "" + " is not enabled by the Admin!"); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Compute Resource with id" + computationalResourceScheduling.getResourceHostId() + "" - + " is not enabled by the Admin!"); - throw exception; - } - } - } - - experiment.setGatewayId(gatewayId); - String experimentId = experimentRepository.addExperiment(experiment); - if (experiment.getExperimentType() == ExperimentType.WORKFLOW) { - workflowRepository.registerWorkflow(experiment.getWorkflow(), experimentId); - } - logger.debug( - experimentId, "Created new experiment with experiment name {}", experiment.getExperimentName()); - return experimentId; - } catch (Exception e) { - logger.error("Error while creating the experiment with experiment name {}", experiment.getExperimentName()); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while creating the experiment. More info : " + e.getMessage()); - throw exception; + return registryService.createExperiment(gatewayId, experiment); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while creating the experiment"); } } @@ -4291,69 +2664,10 @@ public List searchExperiments( int limit, int offset) throws RegistryServiceException, TException { - if (!validateString(userName)) { - logger.error("Username cannot be empty. Please provide a valid user.."); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Username cannot be empty. Please provide a valid user.."); - throw exception; - } - if (!isGatewayExistInternal(gatewayId)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - } try { - if (!userRepository.isUserExists(gatewayId, userName)) { - logger.error("User does not exist in the system. Please provide a valid user.."); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("User does not exist in the system. Please provide a valid user.."); - throw exception; - } - List summaries = new ArrayList(); - Map regFilters = new HashMap(); - regFilters.put(Constants.FieldConstants.ExperimentConstants.GATEWAY_ID, gatewayId); - for (Map.Entry entry : filters.entrySet()) { - if (entry.getKey().equals(ExperimentSearchFields.EXPERIMENT_NAME)) { - regFilters.put(Constants.FieldConstants.ExperimentConstants.EXPERIMENT_NAME, entry.getValue()); - } else if (entry.getKey().equals(ExperimentSearchFields.EXPERIMENT_DESC)) { - regFilters.put(Constants.FieldConstants.ExperimentConstants.DESCRIPTION, entry.getValue()); - } else if (entry.getKey().equals(ExperimentSearchFields.APPLICATION_ID)) { - regFilters.put(Constants.FieldConstants.ExperimentConstants.EXECUTION_ID, entry.getValue()); - } else if (entry.getKey().equals(ExperimentSearchFields.STATUS)) { - regFilters.put(Constants.FieldConstants.ExperimentConstants.EXPERIMENT_STATUS, entry.getValue()); - } else if (entry.getKey().equals(ExperimentSearchFields.FROM_DATE)) { - regFilters.put(Constants.FieldConstants.ExperimentConstants.FROM_DATE, entry.getValue()); - } else if (entry.getKey().equals(ExperimentSearchFields.TO_DATE)) { - regFilters.put(Constants.FieldConstants.ExperimentConstants.TO_DATE, entry.getValue()); - } else if (entry.getKey().equals(ExperimentSearchFields.PROJECT_ID)) { - regFilters.put(Constants.FieldConstants.ExperimentConstants.PROJECT_ID, entry.getValue()); - } else if (entry.getKey().equals(ExperimentSearchFields.USER_NAME)) { - regFilters.put(Constants.FieldConstants.ExperimentConstants.USER_NAME, entry.getValue()); - } else if (entry.getKey().equals(ExperimentSearchFields.JOB_ID)) { - regFilters.put(Constants.FieldConstants.JobConstants.JOB_ID, entry.getValue()); - } - } - - if (accessibleExpIds.size() == 0 && !ServerSettings.isEnableSharing()) { - if (!regFilters.containsKey(DBConstants.Experiment.USER_NAME)) { - regFilters.put(DBConstants.Experiment.USER_NAME, userName); - } - } - summaries = experimentSummaryRepository.searchAllAccessibleExperiments( - accessibleExpIds, - regFilters, - limit, - offset, - Constants.FieldConstants.ExperimentConstants.CREATION_TIME, - ResultOrderType.DESC); - logger.debug("Airavata retrieved experiments for user : " + userName + " and gateway id : " + gatewayId); - return summaries; - } catch (Exception e) { - logger.error("Error while retrieving experiments", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving experiments. More info : " + e.getMessage()); - throw exception; + return registryService.searchExperiments(gatewayId, userName, accessibleExpIds, filters, limit, offset); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while retrieving experiments"); } } @@ -4377,56 +2691,10 @@ public List searchProjects( int limit, int offset) throws RegistryServiceException, TException { - if (!validateString(userName)) { - logger.error("Username cannot be empty. Please provide a valid user.."); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Username cannot be empty. Please provide a valid user.."); - throw exception; - } - if (!isGatewayExistInternal(gatewayId)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - } try { - if (!userRepository.isUserExists(gatewayId, userName)) { - logger.error("User does not exist in the system. Please provide a valid user.."); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("User does not exist in the system. Please provide a valid user.."); - throw exception; - } - List projects = new ArrayList<>(); - Map regFilters = new HashMap<>(); - regFilters.put(Constants.FieldConstants.ProjectConstants.GATEWAY_ID, gatewayId); - for (Map.Entry entry : filters.entrySet()) { - if (entry.getKey().equals(ProjectSearchFields.PROJECT_NAME)) { - regFilters.put(Constants.FieldConstants.ProjectConstants.PROJECT_NAME, entry.getValue()); - } else if (entry.getKey().equals(ProjectSearchFields.PROJECT_DESCRIPTION)) { - regFilters.put(Constants.FieldConstants.ProjectConstants.DESCRIPTION, entry.getValue()); - } - } - - if (accessibleProjIds.size() == 0 && !ServerSettings.isEnableSharing()) { - if (!regFilters.containsKey(DBConstants.Project.OWNER)) { - regFilters.put(DBConstants.Project.OWNER, userName); - } - } - - projects = projectRepository.searchAllAccessibleProjects( - accessibleProjIds, - regFilters, - limit, - offset, - Constants.FieldConstants.ProjectConstants.CREATION_TIME, - ResultOrderType.DESC); - logger.debug("Airavata retrieved projects for user : " + userName + " and gateway id : " + gatewayId); - return projects; - } catch (Exception e) { - logger.error("Error while retrieving projects", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving projects. More info : " + e.getMessage()); - throw exception; + return registryService.searchProjects(gatewayId, userName, accessibleProjIds, filters, limit, offset); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while retrieving projects"); } } @@ -4440,28 +2708,10 @@ public List searchProjects( */ @Override public void updateProject(String projectId, Project updatedProject) throws RegistryServiceException, TException { - if (!validateString(projectId) || !validateString(projectId)) { - logger.error("Project id cannot be empty..."); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Project id cannot be empty..."); - throw exception; - } try { - if (!projectRepository.isProjectExist(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; - } - - projectRepository.updateProject(updatedProject, projectId); - logger.debug("Airavata updated project with project Id : " + projectId); + registryService.updateProject(projectId, updatedProject); } catch (RegistryException e) { - logger.error("Error while updating the project", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while updating the project. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while updating the project"); } } @@ -4475,38 +2725,18 @@ public void updateProject(String projectId, Project updatedProject) throws Regis @Override public String createProject(String gatewayId, Project project) throws RegistryServiceException, TException { try { - if (!validateString(project.getName()) || !validateString(project.getOwner())) { - logger.error("Project name and owner cannot be empty..."); - throw new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - } - if (!validateString(gatewayId)) { - logger.error("Gateway ID cannot be empty..."); - throw new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - } - if (!isGatewayExistInternal(gatewayId)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - } - String projectId = projectRepository.addProject(project, gatewayId); - return projectId; - } catch (Exception e) { - logger.error("Error while creating the project", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while creating the project. More info : " + e.getMessage()); - throw exception; + return registryService.createProject(gatewayId, project); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while creating the project"); } } @Override public boolean updateNotification(Notification notification) throws RegistryServiceException, TException { try { - notificationRepository.updateNotification(notification); - return true; + return registryService.updateNotification(notification); } catch (RegistryException e) { - logger.error("Error while updating notification", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while getting gateway. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while updating notification"); } } @@ -4519,12 +2749,9 @@ public boolean updateNotification(Notification notification) throws RegistryServ @Override public String createNotification(Notification notification) throws RegistryServiceException, TException { try { - return notificationRepository.createNotification(notification); + return registryService.createNotification(notification); } catch (RegistryException e) { - logger.error("Error while creating notification", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while creating notification. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while creating notification"); } } @@ -4540,38 +2767,11 @@ public String createNotification(Notification notification) throws RegistryServi @Override public boolean updateGateway(String gatewayId, Gateway updatedGateway) throws RegistryServiceException, TException { try { - if (!gatewayRepository.isGatewayExist(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; - } - gatewayRepository.updateGateway(gatewayId, updatedGateway); - - // check if gatewayprofile exists and check if the identity server password token equals the admin password - // token, if not update - GatewayResourceProfile existingGwyResourceProfile = - new GwyResourceProfileRepository().getGatewayProfile(gatewayId); - if (existingGwyResourceProfile.getIdentityServerPwdCredToken() == null - || !existingGwyResourceProfile - .getIdentityServerPwdCredToken() - .equals(updatedGateway.getIdentityServerPasswordToken())) { - existingGwyResourceProfile.setIdentityServerPwdCredToken( - updatedGateway.getIdentityServerPasswordToken()); - new GwyResourceProfileRepository().updateGatewayResourceProfile(gatewayId, existingGwyResourceProfile); - } - logger.debug("Airavata update gateway with gateway id : " + gatewayId); - return true; + return registryService.updateGateway(gatewayId, updatedGateway); } catch (RegistryException e) { - logger.error("Error while updating the gateway", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while updating the gateway. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while updating the gateway"); } catch (AppCatalogException e) { - logger.error("Error while updating gateway profile", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while updating gateway profile. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while updating gateway profile"); } } @@ -4585,42 +2785,11 @@ public boolean updateGateway(String gatewayId, Gateway updatedGateway) throws Re @Override public String addGateway(Gateway gateway) throws RegistryServiceException, DuplicateEntryException, TException { try { - 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 (new GwyResourceProfileRepository().isGatewayResourceProfileExists(gateway.getGatewayId())) { - throw new DuplicateEntryException("GatewayResourceProfile with gatewayId: " + gateway.getGatewayId() - + ", already exists in AppCatalog."); - } - - // add gateway in experiment catalog - String gatewayId = gatewayRepository.addGateway(gateway); - - // add gatewayresourceprofile in appCatalog - GatewayResourceProfile gatewayResourceProfile = new GatewayResourceProfile(); - gatewayResourceProfile.setGatewayID(gatewayId); - gatewayResourceProfile.setIdentityServerTenant(gatewayId); - gatewayResourceProfile.setIdentityServerPwdCredToken(gateway.getIdentityServerPasswordToken()); - new GwyResourceProfileRepository().addGatewayResourceProfile(gatewayResourceProfile); - logger.debug("Airavata added gateway with gateway id : " + gateway.getGatewayId()); - return gatewayId; + return registryService.addGateway(gateway); } 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; + throw convertToRegistryServiceException(e, "Error while adding gateway"); } 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; + throw convertToRegistryServiceException(e, "Error while adding gateway profile"); } } @@ -4637,7 +2806,7 @@ private boolean isGatewayExistInternal(String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { try { - return gatewayRepository.isGatewayExist(gatewayId); + return registryService.isGatewayExist(gatewayId); } catch (RegistryException e) { logger.error("Error while getting gateway", e); AiravataSystemException exception = new AiravataSystemException(); @@ -4652,11 +2821,7 @@ private ExperimentModel getExperimentInternal(String airavataExperimentId) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException, TException { try { - if (!experimentRepository.isExperimentExist(airavataExperimentId)) { - throw new ExperimentNotFoundException( - "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); - } - return experimentRepository.getExperiment(airavataExperimentId); + return registryService.getExperiment(airavataExperimentId); } catch (RegistryException e) { logger.error("Error while retrieving the experiment", e); RegistryServiceException exception = new RegistryServiceException(); @@ -4670,16 +2835,8 @@ private ExperimentStatus getExperimentStatusInternal(String airavataExperimentId throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException, TException { try { - if (!experimentRepository.isExperimentExist(airavataExperimentId)) { - logger.error( - airavataExperimentId, - "Error while retrieving experiment status, experiment {} doesn't exist.", - airavataExperimentId); - throw new ExperimentNotFoundException( - "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); - } - return experimentStatusRepository.getExperimentStatus(airavataExperimentId); - } catch (Exception e) { + return registryService.getExperimentStatus(airavataExperimentId); + } catch (RegistryException e) { logger.error(airavataExperimentId, "Error while retrieving the experiment status", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); @@ -4692,10 +2849,7 @@ private ExperimentStatus getExperimentStatusInternal(String airavataExperimentId private List getApplicationOutputsInternal(String appInterfaceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException { try { - List applicationOutputs = - applicationInterfaceRepository.getApplicationOutputs(appInterfaceId); - logger.debug("Airavata retrieved application outputs for application interface id : " + appInterfaceId); - return applicationOutputs; + return registryService.getApplicationOutputs(appInterfaceId); } catch (AppCatalogException e) { logger.error(appInterfaceId, "Error while retrieving application outputs...", e); AiravataSystemException exception = new AiravataSystemException(); @@ -4705,40 +2859,6 @@ private List getApplicationOutputsInternal(String appInter } } - private String addJobSubmissionInterface( - ComputeResourceRepository computeResourceRepository, - String computeResourceId, - String jobSubmissionInterfaceId, - JobSubmissionProtocol protocolType, - int priorityOrder) - throws AppCatalogException { - JobSubmissionInterface jobSubmissionInterface = new JobSubmissionInterface(); - jobSubmissionInterface.setJobSubmissionInterfaceId(jobSubmissionInterfaceId); - jobSubmissionInterface.setPriorityOrder(priorityOrder); - jobSubmissionInterface.setJobSubmissionProtocol(protocolType); - return computeResourceRepository.addJobSubmissionProtocol(computeResourceId, jobSubmissionInterface); - } - - private String addDataMovementInterface( - ComputeResource computeResource, - String computeResourceId, - DMType dmType, - String dataMovementInterfaceId, - DataMovementProtocol protocolType, - int priorityOrder) - throws AppCatalogException { - DataMovementInterface dataMovementInterface = new DataMovementInterface(); - dataMovementInterface.setDataMovementInterfaceId(dataMovementInterfaceId); - dataMovementInterface.setPriorityOrder(priorityOrder); - dataMovementInterface.setDataMovementProtocol(protocolType); - if (dmType.equals(DMType.COMPUTE_RESOURCE)) { - return computeResource.addDataMovementProtocol(computeResourceId, dmType, dataMovementInterface); - } else if (dmType.equals(DMType.STORAGE_RESOURCE)) { - dataMovementInterface.setStorageResourceId(computeResourceId); - return storageResourceRepository.addDataMovementInterface(dataMovementInterface); - } - return null; - } /** * Register a User Resource Profile. @@ -4753,37 +2873,9 @@ private String addDataMovementInterface( public String registerUserResourceProfile(UserResourceProfile userResourceProfile) throws RegistryServiceException, TException { try { - if (!validateString(userResourceProfile.getUserId())) { - logger.error("Cannot create user resource profile with empty user id"); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Cannot create user resource profile with empty gateway id"); - throw exception; - } - if (!validateString(userResourceProfile.getGatewayID())) { - logger.error("Cannot create user resource profile with empty gateway id"); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Cannot create user resource profile with empty gateway id"); - throw exception; - } - - if (!userRepository.isUserExists(userResourceProfile.getGatewayID(), userResourceProfile.getUserId())) { - logger.error("User does not exist.Please provide a valid user ID..."); - throw new RegistryServiceException("User does not exist.Please provide a valid user ID..."); - } - String resourceProfile = userResourceProfileRepository.addUserResourceProfile(userResourceProfile); - logger.debug("Airavata registered user resource profile with gateway id : " - + userResourceProfile.getGatewayID() + "and user id : " + userResourceProfile.getUserId()); - return resourceProfile; + return registryService.registerUserResourceProfile(userResourceProfile); } catch (AppCatalogException e) { - logger.error("Error while registering user resource profile...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while registering user resource profile. More info : " + e.getMessage()); - throw exception; - } catch (RegistryException e) { - logger.error("Error while registering user resource profile...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while registering user resource profile. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while registering user resource profile"); } } @@ -4791,23 +2883,9 @@ public String registerUserResourceProfile(UserResourceProfile userResourceProfil public boolean isUserResourceProfileExists(String userId, String gatewayId) throws RegistryServiceException, TException { try { - if (!userRepository.isUserExists(gatewayId, userId)) { - logger.error("user does not exist.Please provide a valid gateway id..."); - throw new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - } - return userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayId); + return registryService.isUserResourceProfileExists(userId, gatewayId); } catch (AppCatalogException e) { - logger.error("Error while checking existence of user resource profile...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage( - "Error while checking existence of user resource profile. More info : " + e.getMessage()); - throw exception; - } catch (RegistryException e) { - logger.error("Error while checking existence of user resource profile...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage( - "Error while checking existence of user resource profile. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while checking existence of user resource profile"); } } @@ -4821,24 +2899,9 @@ public boolean isUserResourceProfileExists(String userId, String gatewayId) public UserResourceProfile getUserResourceProfile(String userId, String gatewayId) throws RegistryServiceException, TException { try { - if (!userRepository.isUserExists(gatewayId, userId)) { - logger.error("user does not exist.Please provide a valid gateway id..."); - throw new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - } - UserResourceProfile userResourceProfile = - userResourceProfileRepository.getUserResourceProfile(userId, gatewayId); - logger.debug("Airavata retrieved User resource profile with user id : " + userId); - return userResourceProfile; + return registryService.getUserResourceProfile(userId, gatewayId); } catch (AppCatalogException e) { - logger.error("Error while retrieving user resource profile...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving user resource profile. More info : " + e.getMessage()); - throw exception; - } catch (RegistryException e) { - logger.error("Error while retrieving user resource profile...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving user resource profile. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while retrieving user resource profile"); } } @@ -4854,23 +2917,9 @@ public UserResourceProfile getUserResourceProfile(String userId, String gatewayI public boolean updateUserResourceProfile(String userId, String gatewayID, UserResourceProfile userResourceProfile) throws RegistryServiceException, TException { try { - if (!userRepository.isUserExists(gatewayID, userId)) { - logger.error("User does not exist.Please provide a valid user id..."); - throw new RegistryServiceException("user does not exist.Please provide a valid user id..."); - } - userResourceProfileRepository.updateUserResourceProfile(userId, gatewayID, userResourceProfile); - logger.debug("Airavata updated gateway profile with gateway id : " + userId); - return true; + return registryService.updateUserResourceProfile(userId, gatewayID, userResourceProfile); } catch (AppCatalogException e) { - logger.error(gatewayID, "Error while updating gateway resource profile...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while updating gateway resource profile. More info : " + e.getMessage()); - throw exception; - } catch (RegistryException e) { - logger.error(userId, "Error while retrieving user resource profile...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving user resource profile. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while updating gateway resource profile"); } } @@ -4886,23 +2935,9 @@ public boolean updateUserResourceProfile(String userId, String gatewayID, UserRe public boolean deleteUserResourceProfile(String userId, String gatewayID) throws RegistryServiceException, TException { try { - if (!userRepository.isUserExists(gatewayID, userId)) { - logger.error("user does not exist.Please provide a valid user id..."); - throw new RegistryServiceException("user does not exist.Please provide a valid user id..."); - } - userResourceProfileRepository.removeUserResourceProfile(userId, gatewayID); - logger.debug("Airavata deleted User profile with gateway id : " + gatewayID + " and user id : " + userId); - return true; + return registryService.deleteUserResourceProfile(userId, gatewayID); } catch (AppCatalogException e) { - logger.error(gatewayID, "Error while removing User resource profile...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while removing User resource profile. More info : " + e.getMessage()); - throw exception; - } catch (RegistryException e) { - logger.error(userId, "Error while retrieving user resource profile...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving user resource profile. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while removing User resource profile"); } } @@ -4910,18 +2945,9 @@ public boolean deleteUserResourceProfile(String userId, String gatewayID) public String addUser(UserProfile userProfile) throws RegistryServiceException, DuplicateEntryException, TException { try { - logger.info("Adding User in Registry: " + userProfile); - if (isUserExists(userProfile.getGatewayId(), userProfile.getUserId())) { - throw new DuplicateEntryException("User already exists, with userId: " + userProfile.getUserId() - + ", and gatewayId: " + userProfile.getGatewayId()); - } - UserProfile savedUser = userRepository.addUser(userProfile); - return savedUser.getUserId(); + return registryService.addUser(userProfile); } catch (RegistryException ex) { - logger.error("Error while adding user in registry: " + ex, ex); - RegistryServiceException rse = new RegistryServiceException(); - rse.setMessage("Error while adding user in registry: " + ex.getMessage()); - throw rse; + throw convertToRegistryServiceException(ex, "Error while adding user in registry"); } } @@ -4944,32 +2970,9 @@ public boolean addUserComputeResourcePreference( UserComputeResourcePreference userComputeResourcePreference) throws RegistryServiceException, TException { try { - if (!userRepository.isUserExists(gatewayID, userId)) { - logger.error("user does not exist.Please provide a valid user id..."); - throw new RegistryServiceException("user does not exist.Please provide a valid user id..."); - } - if (!userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayID)) { - throw new RegistryServiceException("User resource profile with user id'" + userId + " & gateway Id" - + gatewayID + "' does not exist!!!"); - } - UserResourceProfile profile = userResourceProfileRepository.getUserResourceProfile(userId, gatewayID); - // gatewayProfile.removeGatewayResourceProfile(gatewayID); - profile.addToUserComputeResourcePreferences(userComputeResourcePreference); - userResourceProfileRepository.updateUserResourceProfile(userId, gatewayID, profile); - logger.debug("Airavata added User compute resource preference with gateway id : " + gatewayID - + " and for compute resource id : " + computeResourceId); - return true; + return registryService.addUserComputeResourcePreference(userId, gatewayID, computeResourceId, userComputeResourcePreference); } catch (AppCatalogException e) { - logger.error(gatewayID, "Error while registering User resource profile preference...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage( - "Error while registering user resource profile preference. More info : " + e.getMessage()); - throw exception; - } catch (RegistryException e) { - logger.error(userId, "Error while retrieving user resource profile...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving user resource profile. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while registering user resource profile preference"); } } @@ -4986,22 +2989,9 @@ public boolean addUserComputeResourcePreference( public boolean isUserComputeResourcePreferenceExists(String userId, String gatewayID, String computeResourceId) throws RegistryServiceException, TException { try { - if (userRepository.isUserExists(gatewayID, userId) - && userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayID)) { - return userResourceProfileRepository.isUserComputeResourcePreferenceExists( - userId, gatewayID, computeResourceId); - } - return false; + return registryService.isUserComputeResourcePreferenceExists(userId, gatewayID, computeResourceId); } catch (AppCatalogException e) { - logger.error(gatewayID, "Error while fetching compute resource preference", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while fetching compute resource preference. More info : " + e.getMessage()); - throw exception; - } catch (RegistryException e) { - logger.error(userId, "Error while fetching compute resource preference...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while fetching compute resource preference. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while fetching compute resource preference"); } } @@ -5020,33 +3010,9 @@ public boolean addUserStoragePreference( String userId, String gatewayID, String storageResourceId, UserStoragePreference dataStoragePreference) throws RegistryServiceException, TException { try { - if (!userRepository.isUserExists(gatewayID, userId)) { - logger.error("user does not exist.Please provide a valid user id..."); - throw new RegistryServiceException("user does not exist.Please provide a valid user id..."); - } - if (!userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayID)) { - throw new RegistryServiceException("User resource profile with user id'" + userId + " & gateway Id" - + gatewayID + "' does not exist!!!"); - } - UserResourceProfile profile = userResourceProfileRepository.getUserResourceProfile(userId, gatewayID); - // gatewayProfile.removeGatewayResourceProfile(gatewayID); - dataStoragePreference.setStorageResourceId(storageResourceId); - profile.addToUserStoragePreferences(dataStoragePreference); - userResourceProfileRepository.updateUserResourceProfile(userId, gatewayID, profile); - logger.debug("Airavata added storage resource preference with gateway id : " + gatewayID - + " and for storage resource id : " + storageResourceId); - return true; + return registryService.addUserStoragePreference(userId, gatewayID, storageResourceId, dataStoragePreference); } catch (AppCatalogException e) { - logger.error(gatewayID, "Error while registering user resource profile preference...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage( - "Error while registering user resource profile preference. More info : " + e.getMessage()); - throw exception; - } catch (RegistryException e) { - logger.error(userId, "Error while retrieving user resource profile...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving user resource profile. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while registering user resource profile preference"); } } @@ -5063,40 +3029,9 @@ public boolean addUserStoragePreference( public UserComputeResourcePreference getUserComputeResourcePreference( String userId, String gatewayID, String userComputeResourceId) throws RegistryServiceException, TException { try { - if (!userRepository.isUserExists(gatewayID, userId)) { - logger.error("user does not exist.Please provide a valid user id..."); - throw new RegistryServiceException("user does not exist.Please provide a valid user id..."); - } - if (!userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayID)) { - throw new RegistryServiceException("User resource profile with user id'" + userId + " & gateway Id" - + gatewayID + "' does not exist!!!"); - } - ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); - if (!computeResourceRepository.isComputeResourceExists(userComputeResourceId)) { - logger.error( - userComputeResourceId, - "Given compute resource does not exist in the system. Please provide a valid compute resource id..."); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage( - "Given compute resource does not exist in the system. Please provide a valid compute resource id..."); - throw exception; - } - UserComputeResourcePreference userComputeResourcePreference = - userResourceProfileRepository.getUserComputeResourcePreference( - userId, gatewayID, userComputeResourceId); - logger.debug("Airavata retrieved user compute resource preference with gateway id : " + gatewayID - + " and for compute resoruce id : " + userComputeResourceId); - return userComputeResourcePreference; + return registryService.getUserComputeResourcePreference(userId, gatewayID, userComputeResourceId); } catch (AppCatalogException e) { - logger.error(gatewayID, "Error while reading user compute resource preference...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while reading user compute resource preference. More info : " + e.getMessage()); - throw exception; - } catch (RegistryException e) { - logger.error(userId, "Error while retrieving user resource profile...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving user resource profile. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while reading user compute resource preference"); } } @@ -5113,30 +3048,9 @@ public UserComputeResourcePreference getUserComputeResourcePreference( public UserStoragePreference getUserStoragePreference(String userId, String gatewayID, String storageId) throws RegistryServiceException, TException { try { - if (!userRepository.isUserExists(gatewayID, userId)) { - logger.error("user does not exist.Please provide a valid user id..."); - throw new RegistryServiceException("user does not exist.Please provide a valid user id..."); - } - if (!userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayID)) { - throw new RegistryServiceException("User resource profile with user id'" + userId + " & gateway Id" - + gatewayID + "' does not exist!!!"); - } - - UserStoragePreference storagePreference = - userResourceProfileRepository.getUserStoragePreference(userId, gatewayID, storageId); - logger.debug("Airavata retrieved user storage resource preference with gateway id : " + gatewayID - + " and for storage resource id : " + storageId); - return storagePreference; + return registryService.getUserStoragePreference(userId, gatewayID, storageId); } catch (AppCatalogException e) { - logger.error(gatewayID, "Error while reading gateway data storage preference...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while reading gateway data storage preference. More info : " + e.getMessage()); - throw exception; - } catch (RegistryException e) { - logger.error(userId, "Error while retrieving user resource profile...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving user resource profile. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while reading gateway data storage preference"); } } @@ -5149,11 +3063,9 @@ public UserStoragePreference getUserStoragePreference(String userId, String gate @Override public List getAllUserResourceProfiles() throws RegistryServiceException, TException { try { - return userResourceProfileRepository.getAllUserResourceProfiles(); + return registryService.getAllUserResourceProfiles(); } catch (AppCatalogException e) { - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while reading retrieving all gateway profiles. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while reading retrieving all gateway profiles"); } } @@ -5175,39 +3087,9 @@ public boolean updateUserComputeResourcePreference( UserComputeResourcePreference userComputeResourcePreference) throws RegistryServiceException, TException { try { - if (!userRepository.isUserExists(gatewayID, userId)) { - logger.error("user does not exist.Please provide a valid user id..."); - throw new RegistryServiceException("user does not exist.Please provide a valid user id..."); - } - UserResourceProfile profile = userResourceProfileRepository.getUserResourceProfile(userId, gatewayID); - List userComputeResourcePreferences = - profile.getUserComputeResourcePreferences(); - UserComputeResourcePreference preferenceToRemove = null; - for (UserComputeResourcePreference preference : userComputeResourcePreferences) { - if (preference.getComputeResourceId().equals(computeResourceId)) { - preferenceToRemove = preference; - break; - } - } - if (preferenceToRemove != null) { - profile.getUserComputeResourcePreferences().remove(preferenceToRemove); - } - profile.getUserComputeResourcePreferences().add(userComputeResourcePreference); - userResourceProfileRepository.updateUserResourceProfile(userId, gatewayID, profile); - logger.debug("Airavata updated compute resource preference with gateway id : " + gatewayID - + " and for compute resource id : " + computeResourceId); - return true; + return registryService.updateUserComputeResourcePreference(userId, gatewayID, computeResourceId, userComputeResourcePreference); } catch (AppCatalogException e) { - logger.error(userId, "Error while reading user compute resource preference...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage( - "Error while updating user compute resource preference. More info : " + e.getMessage()); - throw exception; - } catch (RegistryException e) { - logger.error(userId, "Error while retrieving user resource profile...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving user resource profile. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while updating user compute resource preference"); } } @@ -5226,37 +3108,9 @@ public boolean updateUserStoragePreference( String userId, String gatewayID, String storageId, UserStoragePreference userStoragePreference) throws RegistryServiceException, TException { try { - if (!userRepository.isUserExists(gatewayID, userId)) { - logger.error("user does not exist.Please provide a valid user id..."); - throw new RegistryServiceException("user does not exist.Please provide a valid user id..."); - } - UserResourceProfile profile = userResourceProfileRepository.getUserResourceProfile(userId, gatewayID); - List dataStoragePreferences = profile.getUserStoragePreferences(); - UserStoragePreference preferenceToRemove = null; - for (UserStoragePreference preference : dataStoragePreferences) { - if (preference.getStorageResourceId().equals(storageId)) { - preferenceToRemove = preference; - break; - } - } - if (preferenceToRemove != null) { - profile.getUserStoragePreferences().remove(preferenceToRemove); - } - profile.getUserStoragePreferences().add(userStoragePreference); - userResourceProfileRepository.updateUserResourceProfile(userId, gatewayID, profile); - logger.debug("Airavata updated user storage resource preference with gateway id : " + gatewayID - + " and for storage resource id : " + storageId); - return true; + return registryService.updateUserStoragePreference(userId, gatewayID, storageId, userStoragePreference); } catch (AppCatalogException e) { - logger.error(gatewayID, "Error while reading user data storage preference...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while updating user data storage preference. More info : " + e.getMessage()); - throw exception; - } catch (RegistryException e) { - logger.error(userId, "Error while retrieving user resource profile...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving user resource profile. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while updating user data storage preference"); } } @@ -5273,23 +3127,9 @@ public boolean updateUserStoragePreference( public boolean deleteUserComputeResourcePreference(String userId, String gatewayID, String computeResourceId) throws RegistryServiceException, TException { try { - if (!userRepository.isUserExists(gatewayID, userId)) { - logger.error("user does not exist.Please provide a valid user id..."); - throw new RegistryServiceException("user does not exist.Please provide a valid user id..."); - } - return userResourceProfileRepository.removeUserComputeResourcePreferenceFromGateway( - userId, gatewayID, computeResourceId); + return registryService.deleteUserComputeResourcePreference(userId, gatewayID, computeResourceId); } catch (AppCatalogException e) { - logger.error(userId, "Error while reading user compute resource preference...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage( - "Error while updating user compute resource preference. More info : " + e.getMessage()); - throw exception; - } catch (RegistryException e) { - logger.error(userId, "Error while retrieving user resource profile...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving user resource profile. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while deleting user compute resource preference"); } } @@ -5306,22 +3146,9 @@ public boolean deleteUserComputeResourcePreference(String userId, String gateway public boolean deleteUserStoragePreference(String userId, String gatewayID, String storageId) throws RegistryServiceException, TException { try { - if (!userRepository.isUserExists(gatewayID, userId)) { - logger.error("user does not exist.Please provide a valid user id..."); - throw new RegistryServiceException("user does not exist.Please provide a valid user id..."); - } - return userResourceProfileRepository.removeUserDataStoragePreferenceFromGateway( - userId, gatewayID, storageId); + return registryService.deleteUserStoragePreference(userId, gatewayID, storageId); } catch (AppCatalogException e) { - logger.error(gatewayID, "Error while reading user data storage preference...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while updating user data storage preference. More info : " + e.getMessage()); - throw exception; - } catch (RegistryException e) { - logger.error(userId, "Error while retrieving user resource profile...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving user resource profile. More info : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while deleting user storage preference"); } } @@ -5332,13 +3159,9 @@ public boolean deleteUserStoragePreference(String userId, String gatewayID, Stri @Override public List getLatestQueueStatuses() throws RegistryServiceException, TException { try { - List queueStatusModels = queueStatusRepository.getLatestQueueStatuses(); - return queueStatusModels; + return registryService.getLatestQueueStatuses(); } catch (RegistryException e) { - logger.error("Error while reading queue status models....", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while reading queue status models.... : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while reading queue status models"); } } @@ -5346,12 +3169,9 @@ public List getLatestQueueStatuses() throws RegistryServiceExc public void registerQueueStatuses(List queueStatuses) throws RegistryServiceException, TException { try { - queueStatusRepository.createQueueStatuses(queueStatuses); + registryService.registerQueueStatuses(queueStatuses); } catch (RegistryException e) { - logger.error("Error while storing queue status models....", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while storing queue status models.... : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while storing queue status models"); } } @@ -5359,26 +3179,9 @@ public void registerQueueStatuses(List queueStatuses) public QueueStatusModel getQueueStatus(String hostName, String queueName) throws RegistryServiceException, TException { try { - Optional optionalQueueStatusModel = - queueStatusRepository.getQueueStatus(hostName, queueName); - logger.info("Executed and present " + optionalQueueStatusModel.isPresent()); - if (optionalQueueStatusModel.isPresent()) { - return optionalQueueStatusModel.get(); - } else { - QueueStatusModel queueStatusModel = new QueueStatusModel(); - queueStatusModel.setHostName(hostName); - queueStatusModel.setQueueName(queueName); - queueStatusModel.setQueueUp(false); - queueStatusModel.setRunningJobs(0); - queueStatusModel.setQueuedJobs(0); - queueStatusModel.setTime(0); - return queueStatusModel; - } + return registryService.getQueueStatus(hostName, queueName); } catch (RegistryException e) { - logger.error("Error while storing queue status models....", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while storing queue status models.... : " + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while retrieving queue status"); } } @@ -5394,20 +3197,9 @@ public QueueStatusModel getQueueStatus(String hostName, String queueName) public List getAllUserComputeResourcePreferences(String userId, String gatewayID) throws RegistryServiceException, TException { try { - if (!isUserExists(gatewayID, userId)) { - logger.error("User Resource Profile does not exist.Please provide a valid gateway id..."); - throw new RegistryServiceException( - "User Resource Profile does not exist.Please provide a valid gateway id..."); - } - return userResourceProfileRepository - .getUserResourceProfile(userId, gatewayID) - .getUserComputeResourcePreferences(); + return registryService.getAllUserComputeResourcePreferences(userId, gatewayID); } catch (AppCatalogException e) { - logger.error(userId, "Error while reading User Resource Profile compute resource preferences...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while reading User Resource Profile compute resource preferences. More info : " - + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while reading User Resource Profile compute resource preferences"); } } @@ -5423,19 +3215,9 @@ public List getAllUserComputeResourcePreferences( public List getAllUserStoragePreferences(String userId, String gatewayID) throws RegistryServiceException, TException { try { - if (!isUserExists(gatewayID, userId)) { - logger.error("User does not exist.Please provide a valid gateway id..."); - throw new RegistryServiceException("Gateway does not exist.Please provide a valid gateway id..."); - } - return userResourceProfileRepository - .getUserResourceProfile(userId, gatewayID) - .getUserStoragePreferences(); + return registryService.getAllUserStoragePreferences(userId, gatewayID); } catch (AppCatalogException e) { - logger.error(userId, "Error while reading user resource Profile data storage preferences...", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while reading user resource Profile data storage preferences. More info : " - + e.getMessage()); - throw exception; + throw convertToRegistryServiceException(e, "Error while reading user resource Profile data storage preferences"); } } @@ -5443,155 +3225,75 @@ public List getAllUserStoragePreferences(String userId, S public void createGatewayGroups(GatewayGroups gatewayGroups) throws RegistryServiceException, DuplicateEntryException, TException { try { - if (gatewayGroupsRepository.isExists(gatewayGroups.getGatewayId())) { - logger.error("GatewayGroups already exists for " + gatewayGroups.getGatewayId()); - throw new DuplicateEntryException( - "GatewayGroups for gatewayId: " + gatewayGroups.getGatewayId() + " already exists."); + registryService.createGatewayGroups(gatewayGroups); + } catch (RegistryException e) { + if (e.getMessage() != null && e.getMessage().contains("already exists")) { + throw new DuplicateEntryException(e.getMessage()); } - gatewayGroupsRepository.create(gatewayGroups); - } catch (DuplicateEntryException e) { - throw e; // re-throw - } catch (Exception e) { - - final String message = - "Error while creating a GatewayGroups entry for gateway " + gatewayGroups.getGatewayId() + "."; - logger.error(message, e); - RegistryServiceException rse = new RegistryServiceException(); - rse.setMessage(message + " More info: " + e.getMessage()); - throw rse; + throw convertToRegistryServiceException(e, "Error while creating GatewayGroups"); } } @Override public void updateGatewayGroups(GatewayGroups gatewayGroups) throws RegistryServiceException, TException { try { - if (!gatewayGroupsRepository.isExists(gatewayGroups.getGatewayId())) { - final String message = "No GatewayGroups entry exists for " + gatewayGroups.getGatewayId(); - logger.error(message); - throw new RegistryServiceException(message); - } - gatewayGroupsRepository.update(gatewayGroups); - } catch (RegistryServiceException e) { - throw e; // re-throw - } catch (Exception e) { - - final String message = - "Error while updating the GatewayGroups entry for gateway " + gatewayGroups.getGatewayId() + "."; - logger.error(message, e); - RegistryServiceException rse = new RegistryServiceException(); - rse.setMessage(message + " More info: " + e.getMessage()); - throw rse; + registryService.updateGatewayGroups(gatewayGroups); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while updating GatewayGroups"); } } @Override public boolean isGatewayGroupsExists(String gatewayId) throws RegistryServiceException, TException { try { - return gatewayGroupsRepository.isExists(gatewayId); - } catch (Exception e) { - final String message = "Error checking existence of the GatewayGroups entry for gateway " + gatewayId + "."; - logger.error(message, e); - RegistryServiceException rse = new RegistryServiceException(); - rse.setMessage(message + " More info: " + e.getMessage()); - throw rse; + return registryService.isGatewayGroupsExists(gatewayId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error checking existence of GatewayGroups"); } } @Override public GatewayGroups getGatewayGroups(String gatewayId) throws RegistryServiceException, TException { try { - if (!gatewayGroupsRepository.isExists(gatewayId)) { - final String message = "No GatewayGroups entry exists for " + gatewayId; - logger.error(message); - throw new RegistryServiceException(message); - } - return gatewayGroupsRepository.get(gatewayId); - } catch (RegistryServiceException e) { - throw e; // re-throw - } catch (Exception e) { - - final String message = "Error while retrieving the GatewayGroups entry for gateway " + gatewayId + "."; - logger.error(message, e); - RegistryServiceException rse = new RegistryServiceException(); - rse.setMessage(message + " More info: " + e.getMessage()); - throw rse; + return registryService.getGatewayGroups(gatewayId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while retrieving GatewayGroups"); } } @Override public Parser getParser(String parserId, String gatewayId) throws RegistryServiceException, TException { - try { - if (!parserRepository.isExists(parserId)) { - final String message = "No Parser Info entry exists for " + parserId; - logger.error(message); - throw new RegistryServiceException(message); - } - return parserRepository.get(parserId); - - } catch (RegistryServiceException e) { - throw e; // re-throw - - } catch (Exception e) { - final String message = "Error while retrieving parser with id " + parserId + "."; - logger.error(message, e); - RegistryServiceException rse = new RegistryServiceException(); - rse.setMessage(message + " More info: " + e.getMessage()); - throw rse; + return registryService.getParser(parserId, gatewayId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while retrieving parser"); } } @Override public String saveParser(Parser parser) throws RegistryServiceException, TException { - try { - Parser created = parserRepository.saveParser(parser); - return created.getId(); - - } catch (Exception e) { - final String message = "Error while saving parser with id " + parser.getId(); - logger.error(message, e); - RegistryServiceException rse = new RegistryServiceException(); - rse.setMessage(message + " More info: " + e.getMessage()); - throw rse; + return registryService.saveParser(parser); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while saving parser"); } } @Override public List listAllParsers(String gatewayId) throws RegistryServiceException, TException { - try { - return parserRepository.getAllParsers(gatewayId); - - } catch (Exception e) { - final String message = "Error while listing parsers for gateway " + gatewayId; - logger.error(message, e); - RegistryServiceException rse = new RegistryServiceException(); - rse.setMessage(message + " More info: " + e.getMessage()); - throw rse; + return registryService.listAllParsers(gatewayId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while listing parsers"); } } @Override public void removeParser(String parserId, String gatewayId) throws RegistryServiceException, TException { - try { - boolean exists = parserRepository.isExists(parserId); - - if (exists && !gatewayId.equals(parserRepository.get(parserId).getGatewayId())) { - parserRepository.delete(parserId); - } else { - throw new RegistryServiceException("Parser " + parserId + " does not exist"); - } - } catch (RegistryServiceException e) { - throw e; // re-throw - - } catch (Exception e) { - final String message = "Error while removing parser with id " + parserId + "."; - logger.error(message, e); - RegistryServiceException rse = new RegistryServiceException(); - rse.setMessage(message + " More info: " + e.getMessage()); - throw rse; + registryService.removeParser(parserId, gatewayId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while removing parser"); } } @@ -5599,14 +3301,9 @@ public void removeParser(String parserId, String gatewayId) throws RegistryServi public ParserInput getParserInput(String parserInputId, String gatewayId) throws RegistryServiceException, TException { try { - ParserInput parserInput = parserInputRepository.getParserInput(parserInputId); - // TODO check the gateway - - return parserInput; - } catch (Exception e) { - logger.error("Failed to fetch parser input " + parserInputId + " for gateway " + gatewayId, e); - throw new RegistryServiceException("Failed to fetch parser input " + parserInputId + " for gateway " - + gatewayId + " More info: " + e.getMessage()); + return registryService.getParserInput(parserInputId, gatewayId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while retrieving parser input"); } } @@ -5614,116 +3311,56 @@ public ParserInput getParserInput(String parserInputId, String gatewayId) public ParserOutput getParserOutput(String parserOutputId, String gatewayId) throws RegistryServiceException, TException { try { - ParserOutput parserOutput = parserOutputRepository.getParserOutput(parserOutputId); - // TODO check the gateway - - return parserOutput; - } catch (Exception e) { - logger.error("Failed to fetch parser output " + parserOutputId + " for gateway " + gatewayId, e); - throw new RegistryServiceException("Failed to fetch parser output " + parserOutputId + " for gateway " - + gatewayId + " More info: " + e.getMessage()); + return registryService.getParserOutput(parserOutputId, gatewayId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while retrieving parser output"); } } @Override public ParsingTemplate getParsingTemplate(String templateId, String gatewayId) throws RegistryServiceException, TException { - try { - if (!parsingTemplateRepository.isExists(templateId)) { - final String message = "No Parsing Template entry exists for " + templateId; - logger.error(message); - throw new RegistryServiceException(message); - } - return parsingTemplateRepository.get(templateId); - - } catch (RegistryServiceException e) { - throw e; // re-throw - - } catch (Exception e) { - final String message = "Error while retrieving Parsing Template for id " + templateId + "."; - logger.error(message, e); - RegistryServiceException rse = new RegistryServiceException(); - rse.setMessage(message + " More info: " + e.getMessage()); - throw rse; + return registryService.getParsingTemplate(templateId, gatewayId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while retrieving parsing template"); } } @Override public List getParsingTemplatesForExperiment(String experimentId, String gatewayId) throws RegistryServiceException, TException { - try { - List processes = getExperiment(experimentId).getProcesses(); - if (processes.size() > 0) { - return parsingTemplateRepository.getParsingTemplatesForApplication( - processes.get(processes.size() - 1).getApplicationInterfaceId()); - } - return Collections.emptyList(); - - } catch (Exception e) { - final String message = "Error while retrieving parsing templates for experiment id " + experimentId; - logger.error(message, e); - RegistryServiceException rse = new RegistryServiceException(); - rse.setMessage(message + " More info: " + e.getMessage()); - throw rse; + return registryService.getParsingTemplatesForExperiment(experimentId, gatewayId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while retrieving parsing templates for experiment"); } } @Override public String saveParsingTemplate(ParsingTemplate parsingTemplate) throws RegistryServiceException, TException { - try { - ParsingTemplate saved = parsingTemplateRepository.create(parsingTemplate); - return saved.getId(); - - } catch (Exception e) { - final String message = "Error while saving parsing template with id " + parsingTemplate.getId(); - logger.error(message, e); - RegistryServiceException rse = new RegistryServiceException(); - rse.setMessage(message + " More info: " + e.getMessage()); - throw rse; + return registryService.saveParsingTemplate(parsingTemplate); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while saving parsing template"); } } @Override public List listAllParsingTemplates(String gatewayId) throws RegistryServiceException, TException { - try { - return parsingTemplateRepository.getAllParsingTemplates(gatewayId); - - } catch (Exception e) { - final String message = "Error while listing parsing templates for gateway " + gatewayId; - logger.error(message, e); - RegistryServiceException rse = new RegistryServiceException(); - rse.setMessage(message + " More info: " + e.getMessage()); - throw rse; + return registryService.listAllParsingTemplates(gatewayId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while listing parsing templates"); } } @Override public void removeParsingTemplate(String templateId, String gatewayId) throws RegistryServiceException, TException { - try { - boolean exists = parsingTemplateRepository.isExists(templateId); - - if (exists - && !gatewayId.equals( - parsingTemplateRepository.get(templateId).getGatewayId())) { - parsingTemplateRepository.delete(templateId); - } else { - throw new RegistryServiceException("Parsing tempolate " + templateId + " does not exist"); - } - } catch (RegistryServiceException e) { - throw e; // re-throw - - } catch (Exception e) { - - final String message = "Error while removing parsing template with id " + templateId; - logger.error(message, e); - RegistryServiceException rse = new RegistryServiceException(); - rse.setMessage(message + " More info: " + e.getMessage()); - throw rse; + registryService.removeParsingTemplate(templateId, gatewayId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while removing parsing template"); } } @@ -5731,14 +3368,9 @@ public void removeParsingTemplate(String templateId, String gatewayId) throws Re public boolean isGatewayUsageReportingAvailable(String gatewayId, String computeResourceId) throws RegistryServiceException, TException { try { - return usageReportingCommandRepository.isGatewayUsageReportingCommandExists(gatewayId, computeResourceId); - } catch (Exception e) { - String message = "Failed to check the availability to find the reporting information for the gateway " - + gatewayId + " and compute resource " + computeResourceId; - logger.error(message, e); - RegistryServiceException rse = new RegistryServiceException(); - rse.setMessage(message + ". More info " + e.getMessage()); - throw rse; + return registryService.isGatewayUsageReportingAvailable(gatewayId, computeResourceId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while checking gateway usage reporting availability"); } } @@ -5746,24 +3378,9 @@ public boolean isGatewayUsageReportingAvailable(String gatewayId, String compute public GatewayUsageReportingCommand getGatewayReportingCommand(String gatewayId, String computeResourceId) throws RegistryServiceException, TException { try { - if (usageReportingCommandRepository.isGatewayUsageReportingCommandExists(gatewayId, computeResourceId)) { - return usageReportingCommandRepository.getGatewayUsageReportingCommand(gatewayId, computeResourceId); - } else { - String message = "No usage reporting information for the gateway " + gatewayId - + " and compute resource " + computeResourceId; - logger.error(message); - throw new RegistryServiceException(message); - } - } catch (RegistryServiceException e) { - throw e; // re-throw - - } catch (Exception e) { - String message = "Failed to check the availability to find the reporting information for the gateway " - + gatewayId + " and compute resource " + computeResourceId; - logger.error(message, e); - RegistryServiceException rse = new RegistryServiceException(); - rse.setMessage(message + ". More info " + e.getMessage()); - throw rse; + return registryService.getGatewayReportingCommand(gatewayId, computeResourceId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while retrieving gateway reporting command"); } } @@ -5771,14 +3388,9 @@ public GatewayUsageReportingCommand getGatewayReportingCommand(String gatewayId, public void addGatewayUsageReportingCommand(GatewayUsageReportingCommand command) throws RegistryServiceException, TException { try { - usageReportingCommandRepository.addGatewayUsageReportingCommand(command); - } catch (Exception e) { - String message = "Failed to add the reporting information for the gateway " + command.getGatewayId() - + " and compute resource " + command.getComputeResourceId(); - logger.error(message, e); - RegistryServiceException rse = new RegistryServiceException(); - rse.setMessage(message + ". More info " + e.getMessage()); - throw rse; + registryService.addGatewayUsageReportingCommand(command); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while adding gateway usage reporting command"); } } @@ -5786,14 +3398,9 @@ public void addGatewayUsageReportingCommand(GatewayUsageReportingCommand command public void removeGatewayUsageReportingCommand(String gatewayId, String computeResourceId) throws RegistryServiceException, TException { try { - usageReportingCommandRepository.removeGatewayUsageReportingCommand(gatewayId, computeResourceId); - } catch (Exception e) { - String message = "Failed to add the reporting information for the gateway " + gatewayId - + " and compute resource " + computeResourceId; - logger.error(message, e); - RegistryServiceException rse = new RegistryServiceException(); - rse.setMessage(message + ". More info " + e.getMessage()); - throw rse; + registryService.removeGatewayUsageReportingCommand(gatewayId, computeResourceId); + } catch (RegistryException e) { + throw convertToRegistryServiceException(e, "Error while removing gateway usage reporting command"); } } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/RegistryService.java b/airavata-api/src/main/java/org/apache/airavata/service/RegistryService.java new file mode 100644 index 0000000000..2c9284fa7a --- /dev/null +++ b/airavata-api/src/main/java/org/apache/airavata/service/RegistryService.java @@ -0,0 +1,2756 @@ +/** +* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ +package org.apache.airavata.service; + +import java.util.*; +import org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription; +import org.apache.airavata.model.appcatalog.appdeployment.ApplicationModule; +import org.apache.airavata.model.appcatalog.appinterface.ApplicationInterfaceDescription; +import org.apache.airavata.model.appcatalog.computeresource.*; +import org.apache.airavata.model.appcatalog.gatewaygroups.GatewayGroups; +import org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference; +import org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile; +import org.apache.airavata.model.appcatalog.gatewayprofile.StoragePreference; +import org.apache.airavata.model.appcatalog.groupresourceprofile.BatchQueueResourcePolicy; +import org.apache.airavata.model.appcatalog.groupresourceprofile.ComputeResourcePolicy; +import org.apache.airavata.model.appcatalog.groupresourceprofile.GroupComputeResourcePreference; +import org.apache.airavata.model.appcatalog.groupresourceprofile.GroupResourceProfile; +import org.apache.airavata.model.appcatalog.parser.Parser; +import org.apache.airavata.model.appcatalog.parser.ParserInput; +import org.apache.airavata.model.appcatalog.parser.ParserOutput; +import org.apache.airavata.model.appcatalog.parser.ParsingTemplate; +import org.apache.airavata.model.appcatalog.storageresource.StorageResourceDescription; +import org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference; +import org.apache.airavata.model.appcatalog.userresourceprofile.UserResourceProfile; +import org.apache.airavata.model.appcatalog.userresourceprofile.UserStoragePreference; +import org.apache.airavata.model.application.io.InputDataObjectType; +import org.apache.airavata.model.application.io.OutputDataObjectType; +import org.apache.airavata.model.commons.ErrorModel; +import org.apache.airavata.model.data.movement.*; +import org.apache.airavata.model.data.movement.DMType; +import org.apache.airavata.model.data.replica.DataProductModel; +import org.apache.airavata.model.data.replica.DataReplicaLocationModel; +import org.apache.airavata.model.error.*; +import org.apache.airavata.model.experiment.*; +import org.apache.airavata.model.job.JobModel; +import org.apache.airavata.registry.cpi.ExpCatChildDataType; +import org.apache.airavata.model.process.ProcessModel; +import org.apache.airavata.model.process.ProcessWorkflow; +import org.apache.airavata.model.scheduling.ComputationalResourceSchedulingModel; +import org.apache.airavata.model.status.*; +import org.apache.airavata.model.task.TaskModel; +import org.apache.airavata.model.user.UserProfile; +import org.apache.airavata.model.workspace.Gateway; +import org.apache.airavata.model.workspace.GatewayUsageReportingCommand; +import org.apache.airavata.model.workspace.Notification; +import org.apache.airavata.model.workspace.Project; +import org.apache.airavata.registry.core.repositories.appcatalog.*; +import org.apache.airavata.registry.core.repositories.expcatalog.*; +import org.apache.airavata.registry.core.repositories.replicacatalog.DataProductRepository; +import org.apache.airavata.registry.core.repositories.replicacatalog.DataReplicaLocationRepository; +import org.apache.airavata.registry.core.repositories.workflowcatalog.WorkflowRepository; +import org.apache.airavata.registry.core.utils.DBConstants; +import org.apache.airavata.registry.cpi.*; +import org.apache.airavata.registry.cpi.utils.Constants; +import org.apache.airavata.registry.api.exception.RegistryServiceException; +import org.apache.airavata.model.error.AiravataSystemException; +import org.apache.airavata.model.error.AiravataErrorType; +import org.apache.airavata.registry.core.entities.expcatalog.JobPK; +import org.apache.airavata.registry.core.repositories.appcatalog.GwyResourceProfileRepository; +import org.apache.airavata.registry.core.repositories.appcatalog.GroupResourceProfileRepository; +import org.apache.airavata.common.utils.ServerSettings; +import org.apache.airavata.registry.cpi.WorkflowCatalogException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class RegistryService { + private static final Logger logger = LoggerFactory.getLogger(RegistryService.class); + + private ApplicationDeploymentRepository applicationDeploymentRepository = new ApplicationDeploymentRepository(); + private ApplicationInterfaceRepository applicationInterfaceRepository = new ApplicationInterfaceRepository(); + private StorageResourceRepository storageResourceRepository = new StorageResourceRepository(); + private UserResourceProfileRepository userResourceProfileRepository = new UserResourceProfileRepository(); + private GatewayRepository gatewayRepository = new GatewayRepository(); + private ProjectRepository projectRepository = new ProjectRepository(); + private NotificationRepository notificationRepository = new NotificationRepository(); + private ExperimentSummaryRepository experimentSummaryRepository = new ExperimentSummaryRepository(); + private ExperimentRepository experimentRepository = new ExperimentRepository(); + private ExperimentOutputRepository experimentOutputRepository = new ExperimentOutputRepository(); + private ExperimentStatusRepository experimentStatusRepository = new ExperimentStatusRepository(); + private ExperimentErrorRepository experimentErrorRepository = new ExperimentErrorRepository(); + private ProcessRepository processRepository = new ProcessRepository(); + private ProcessOutputRepository processOutputRepository = new ProcessOutputRepository(); + private ProcessWorkflowRepository processWorkflowRepository = new ProcessWorkflowRepository(); + private ProcessStatusRepository processStatusRepository = new ProcessStatusRepository(); + private ProcessErrorRepository processErrorRepository = new ProcessErrorRepository(); + private TaskRepository taskRepository = new TaskRepository(); + private TaskStatusRepository taskStatusRepository = new TaskStatusRepository(); + private TaskErrorRepository taskErrorRepository = new TaskErrorRepository(); + private JobRepository jobRepository = new JobRepository(); + private JobStatusRepository jobStatusRepository = new JobStatusRepository(); + private QueueStatusRepository queueStatusRepository = new QueueStatusRepository(); + private DataProductRepository dataProductRepository = new DataProductRepository(); + private DataReplicaLocationRepository dataReplicaLocationRepository = new DataReplicaLocationRepository(); + private WorkflowRepository workflowRepository = new WorkflowRepository(); + private GatewayGroupsRepository gatewayGroupsRepository = new GatewayGroupsRepository(); + private ParserRepository parserRepository = new ParserRepository(); + private ParserInputRepository parserInputRepository = new ParserInputRepository(); + private ParserOutputRepository parserOutputRepository = new ParserOutputRepository(); + private ParsingTemplateRepository parsingTemplateRepository = new ParsingTemplateRepository(); + private UserRepository userRepository = new UserRepository(); + private ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); + private GatewayUsageReportingCommandRepository usageReportingCommandRepository = + new GatewayUsageReportingCommandRepository(); + + public String getAPIVersion() { + return org.apache.airavata.registry.api.registry_apiConstants.REGISTRY_API_VERSION; + } + + public boolean isUserExists(String gatewayId, String userName) throws RegistryException { + return userRepository.isUserExists(gatewayId, userName); + } + + public List getAllUsersInGateway(String gatewayId) throws RegistryException { + return userRepository.getAllUsernamesInGateway(gatewayId); + } + + public Gateway getGateway(String gatewayId) throws RegistryException { + if (!gatewayRepository.isGatewayExist(gatewayId)) { + logger.error("Gateway does not exist in the system. Please provide a valid gateway ID..."); + throw new RegistryException("Gateway does not exist in the system. Please provide a valid gateway ID..."); + } + Gateway gateway = gatewayRepository.getGateway(gatewayId); + logger.debug("Airavata retrieved gateway with gateway id : " + gateway.getGatewayId()); + return gateway; + } + + public boolean deleteGateway(String gatewayId) throws RegistryException { + if (!gatewayRepository.isGatewayExist(gatewayId)) { + logger.error("Gateway does not exist in the system. Please provide a valid gateway ID..."); + throw new RegistryException("Gateway does not exist in the system. Please provide a valid gateway ID..."); + } + gatewayRepository.removeGateway(gatewayId); + logger.debug("Airavata deleted gateway with gateway id : " + gatewayId); + return true; + } + + public List getAllGateways() throws RegistryException { + List gateways = gatewayRepository.getAllGateways(); + logger.debug("Airavata retrieved all available gateways..."); + return gateways; + } + + public boolean isGatewayExist(String gatewayId) throws RegistryException { + return gatewayRepository.isGatewayExist(gatewayId); + } + + public boolean deleteNotification(String gatewayId, String notificationId) throws RegistryException { + notificationRepository.deleteNotification(notificationId); + return true; + } + + public Notification getNotification(String gatewayId, String notificationId) throws RegistryException { + return notificationRepository.getNotification(notificationId); + } + + public List getAllNotifications(String gatewayId) throws RegistryException { + List notifications = notificationRepository.getAllGatewayNotifications(gatewayId); + return notifications; + } + + public Project getProject(String projectId) throws RegistryException { + if (!projectRepository.isProjectExist(projectId)) { + logger.error("Project does not exist in the system. Please provide a valid project ID..."); + throw new RegistryException("Project does not exist in the system. Please provide a valid project ID..."); + } + logger.debug("Airavata retrieved project with project Id : " + projectId); + Project project = projectRepository.getProject(projectId); + return project; + } + + public boolean deleteProject(String projectId) throws RegistryException { + if (!projectRepository.isProjectExist(projectId)) { + logger.error("Project does not exist in the system. Please provide a valid project ID..."); + throw new RegistryException("Project does not exist in the system. Please provide a valid project ID..."); + } + projectRepository.removeProject(projectId); + logger.debug("Airavata deleted project with project Id : " + projectId); + return true; + } + + public List getUserProjects(String gatewayId, String userName, int limit, int offset) throws RegistryException { + if (!validateString(userName)) { + logger.error("Username cannot be empty. Please provide a valid user.."); + throw new RegistryException("Username cannot be empty. Please provide a valid user.."); + } + if (!isGatewayExistInternal(gatewayId)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new RegistryException("Gateway does not exist.Please provide a valid gateway id..."); + } + List projects = new ArrayList<>(); + if (!userRepository.isUserExists(gatewayId, userName)) { + logger.warn("User does not exist in the system. Please provide a valid user.."); + return projects; + } + Map filters = new HashMap<>(); + filters.put(Constants.FieldConstants.ProjectConstants.OWNER, userName); + filters.put(Constants.FieldConstants.ProjectConstants.GATEWAY_ID, gatewayId); + projects = projectRepository.searchProjects( + filters, + limit, + offset, + Constants.FieldConstants.ProjectConstants.CREATION_TIME, + ResultOrderType.DESC); + logger.debug("Airavata retrieved projects for user : " + userName + " and gateway id : " + gatewayId); + return projects; + } + + public ExperimentStatistics getExperimentStatistics( + String gatewayId, + long fromTime, + long toTime, + String userName, + String applicationName, + String resourceHostName, + List accessibleExpIds, + int limit, + int offset) throws RegistryException { + if (!isGatewayExistInternal(gatewayId)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new RegistryException("Gateway does not exist.Please provide a valid gateway id..."); + } + Map filters = new HashMap<>(); + filters.put(Constants.FieldConstants.ExperimentConstants.GATEWAY_ID, gatewayId); + filters.put(Constants.FieldConstants.ExperimentConstants.FROM_DATE, fromTime + ""); + filters.put(Constants.FieldConstants.ExperimentConstants.TO_DATE, toTime + ""); + if (userName != null) { + filters.put(Constants.FieldConstants.ExperimentConstants.USER_NAME, userName); + } + if (applicationName != null) { + filters.put(Constants.FieldConstants.ExperimentConstants.EXECUTION_ID, applicationName); + } + if (resourceHostName != null) { + filters.put(Constants.FieldConstants.ExperimentConstants.RESOURCE_HOST_ID, resourceHostName); + } + limit = Math.min(limit, 1000); + ExperimentStatistics result = experimentSummaryRepository.getAccessibleExperimentStatistics( + accessibleExpIds, filters, limit, offset); + logger.debug("Airavata retrieved experiments for gateway id : " + gatewayId + " between : " + + org.apache.airavata.common.utils.AiravataUtils.getTime(fromTime) + " and " + org.apache.airavata.common.utils.AiravataUtils.getTime(toTime)); + return result; + } + + public List getExperimentsInProject(String gatewayId, String projectId, int limit, int offset) throws RegistryException { + if (!isGatewayExistInternal(gatewayId)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new RegistryException("Gateway does not exist.Please provide a valid gateway id..."); + } + if (!validateString(projectId)) { + logger.error("Project id cannot be empty. Please provide a valid project ID..."); + throw new RegistryException("Project id cannot be empty. Please provide a valid project ID..."); + } + if (!projectRepository.isProjectExist(projectId)) { + logger.error("Project does not exist in the system. Please provide a valid project ID..."); + throw new RegistryException("Project does not exist in the system. Please provide a valid project ID..."); + } + List experiments = experimentRepository.getExperimentList( + gatewayId, + Constants.FieldConstants.ExperimentConstants.PROJECT_ID, + projectId, + limit, + offset, + Constants.FieldConstants.ExperimentConstants.CREATION_TIME, + ResultOrderType.DESC); + logger.debug("Airavata retrieved experiments for project : " + projectId); + return experiments; + } + + public List getUserExperiments(String gatewayId, String userName, int limit, int offset) throws RegistryException { + if (!validateString(userName)) { + logger.error("Username cannot be empty. Please provide a valid user.."); + throw new RegistryException("Username cannot be empty. Please provide a valid user.."); + } + if (!isGatewayExistInternal(gatewayId)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new RegistryException("Gateway does not exist.Please provide a valid gateway id..."); + } + List experiments = new ArrayList(); + if (!userRepository.isUserExists(gatewayId, userName)) { + logger.warn("User does not exist in the system. Please provide a valid user.."); + return experiments; + } + experiments = experimentRepository.getExperimentList( + gatewayId, + Constants.FieldConstants.ExperimentConstants.USER_NAME, + userName, + limit, + offset, + Constants.FieldConstants.ExperimentConstants.CREATION_TIME, + ResultOrderType.DESC); + logger.debug("Airavata retrieved experiments for user : " + userName); + return experiments; + } + + public boolean deleteExperiment(String experimentId) throws RegistryException { + if (!experimentRepository.isExperimentExist(experimentId)) { + throw new RegistryException( + "Requested experiment id " + experimentId + " does not exist in the system.."); + } + ExperimentModel experimentModel = experimentRepository.getExperiment(experimentId); + if (!(experimentModel.getExperimentStatus().get(0).getState() == ExperimentState.CREATED)) { + logger.error("Error while deleting the experiment"); + throw new RegistryException( + "Experiment is not in CREATED state. Hence cannot deleted. ID:" + experimentId); + } + experimentRepository.removeExperiment(experimentId); + logger.debug("Airavata removed experiment with experiment id : " + experimentId); + return true; + } + + private ExperimentModel getExperimentInternal(String airavataExperimentId) throws RegistryException { + if (!experimentRepository.isExperimentExist(airavataExperimentId)) { + throw new RegistryException( + "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); + } + return experimentRepository.getExperiment(airavataExperimentId); + } + + public ExperimentModel getExperiment(String airavataExperimentId) throws RegistryException { + return getExperimentInternal(airavataExperimentId); + } + + public ExperimentModel getDetailedExperimentTree(String airavataExperimentId) throws RegistryException { + ExperimentModel experimentModel = getExperimentInternal(airavataExperimentId); + List processList = processRepository.getProcessList( + Constants.FieldConstants.ExperimentConstants.EXPERIMENT_ID, experimentModel.getExperimentId()); + if (processList != null) { + processList.stream().forEach(p -> { + (p).getTasks().stream().forEach(t -> { + try { + List jobList = jobRepository.getJobList( + Constants.FieldConstants.JobConstants.TASK_ID, ((TaskModel) t).getTaskId()); + if (jobList != null) { + Collections.sort(jobList, new Comparator() { + @Override + public int compare(JobModel o1, JobModel o2) { + return (int) (o1.getCreationTime() - o2.getCreationTime()); + } + }); + t.setJobs(jobList); + } + } catch (RegistryException e) { + logger.error(e.getMessage(), e); + } + }); + }); + experimentModel.setProcesses(processList); + } + logger.debug("Airavata retrieved detailed experiment with experiment id : " + airavataExperimentId); + return experimentModel; + } + + private ExperimentStatus getExperimentStatusInternal(String airavataExperimentId) throws RegistryException { + if (!experimentRepository.isExperimentExist(airavataExperimentId)) { + logger.error( + airavataExperimentId, + "Error while retrieving experiment status, experiment {} doesn't exist.", + airavataExperimentId); + throw new RegistryException( + "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); + } + return experimentStatusRepository.getExperimentStatus(airavataExperimentId); + } + + public ExperimentStatus getExperimentStatus(String airavataExperimentId) throws RegistryException { + ExperimentStatus experimentStatus = getExperimentStatusInternal(airavataExperimentId); + logger.debug("Airavata retrieved experiment status for experiment id : " + airavataExperimentId); + return experimentStatus; + } + + public List getExperimentOutputs(String airavataExperimentId) throws RegistryException { + if (!experimentRepository.isExperimentExist(airavataExperimentId)) { + logger.error( + airavataExperimentId, + "Get experiment outputs failed, experiment {} doesn't exit.", + airavataExperimentId); + throw new RegistryException( + "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); + } + logger.debug("Airavata retrieved experiment outputs for experiment id : " + airavataExperimentId); + return experimentOutputRepository.getExperimentOutputs(airavataExperimentId); + } + + + public void updateJobStatus(JobStatus jobStatus, String taskId, String jobId) throws RegistryException { + org.apache.airavata.registry.core.entities.expcatalog.JobPK jobPK = new org.apache.airavata.registry.core.entities.expcatalog.JobPK(); + jobPK.setTaskId(taskId); + jobPK.setJobId(jobId); + jobStatusRepository.updateJobStatus(jobStatus, jobPK); + } + + public void addJob(JobModel jobModel, String processId) throws RegistryException { + jobRepository.addJob(jobModel, processId); + } + + // Note: deleteJobs method removed - JobRepository doesn't have this method + // Jobs should be deleted individually using removeJob(jobPK) or removeJob(jobModel) + + public String addProcess(ProcessModel processModel, String experimentId) throws RegistryException { + return processRepository.addProcess(processModel, experimentId); + } + + public void updateProcess(ProcessModel processModel, String processId) throws RegistryException { + processRepository.updateProcess(processModel, processId); + } + + public String addTask(TaskModel taskModel, String processId) throws RegistryException { + return taskRepository.addTask(taskModel, processId); + } + + public void deleteTasks(String processId) throws RegistryException { + taskRepository.deleteTasks(processId); + } + + public UserConfigurationDataModel getUserConfigurationData(String experimentId) throws RegistryException { + return experimentRepository.getUserConfigurationData(experimentId); + } + + public ProcessModel getProcess(String processId) throws RegistryException { + return processRepository.getProcess(processId); + } + + public List getProcessList(String experimentId) throws RegistryException { + List processModels = processRepository.getProcessList( + Constants.FieldConstants.ExperimentConstants.EXPERIMENT_ID, experimentId); + return processModels; + } + + public ProcessStatus getProcessStatus(String processId) throws RegistryException { + return processStatusRepository.getProcessStatus(processId); + } + + public List getProcessListInState(ProcessState processState) throws RegistryException { + List finalProcessList = new ArrayList<>(); + int offset = 0; + int limit = 100; + int count = 0; + do { + List processStatusList = + processStatusRepository.getProcessStatusList(processState, offset, limit); + offset += processStatusList.size(); + count = processStatusList.size(); + for (ProcessStatus processStatus : processStatusList) { + ProcessStatus latestStatus = processStatusRepository.getProcessStatus(processStatus.getProcessId()); + if (latestStatus.getState().name().equals(processState.name())) { + finalProcessList.add(processRepository.getProcess(latestStatus.getProcessId())); + } + } + } while (count == limit); + return finalProcessList; + } + + public List getProcessStatusList(String processId) throws RegistryException { + return processStatusRepository.getProcessStatusList(processId); + } + + private JobModel fetchJobModel(String queryType, String id) throws RegistryException { + if (queryType.equals(Constants.FieldConstants.JobConstants.TASK_ID)) { + List jobs = jobRepository.getJobList(Constants.FieldConstants.JobConstants.TASK_ID, id); + if (jobs != null) { + for (JobModel jobModel : jobs) { + if (jobModel.getJobId() != null || !jobModel.equals("")) { + return jobModel; + } + } + } + } else if (queryType.equals(Constants.FieldConstants.JobConstants.PROCESS_ID)) { + List jobs = jobRepository.getJobList(Constants.FieldConstants.JobConstants.PROCESS_ID, id); + if (jobs != null) { + for (JobModel jobModel : jobs) { + if (jobModel.getJobId() != null || !jobModel.equals("")) { + return jobModel; + } + } + } + } + return null; + } + + private List fetchJobModels(String queryType, String id) throws RegistryException { + List jobs = new ArrayList<>(); + switch (queryType) { + case Constants.FieldConstants.JobConstants.TASK_ID: + jobs = jobRepository.getJobList(Constants.FieldConstants.JobConstants.TASK_ID, id); + break; + case Constants.FieldConstants.JobConstants.PROCESS_ID: + jobs = jobRepository.getJobList(Constants.FieldConstants.JobConstants.PROCESS_ID, id); + break; + case Constants.FieldConstants.JobConstants.JOB_ID: + jobs = jobRepository.getJobList(Constants.FieldConstants.JobConstants.JOB_ID, id); + break; + } + return jobs; + } + + public boolean isJobExist(String queryType, String id) throws RegistryException { + JobModel jobModel = fetchJobModel(queryType, id); + return jobModel != null; + } + + public JobModel getJob(String queryType, String id) throws RegistryException { + JobModel jobModel = fetchJobModel(queryType, id); + if (jobModel != null) return jobModel; + throw new RegistryException("Job not found for queryType: " + queryType + ", id: " + id); + } + + public List getJobs(String queryType, String id) throws RegistryException { + return fetchJobModels(queryType, id); + } + + public int getJobCount( + org.apache.airavata.model.status.JobStatus jobStatus, String gatewayId, double searchBackTimeInMinutes) throws RegistryException { + List jobStatusList = jobStatusRepository.getDistinctListofJobStatus( + gatewayId, jobStatus.getJobState().name(), searchBackTimeInMinutes); + return jobStatusList.size(); + } + + public Map getAVGTimeDistribution(String gatewayId, double searchBackTimeInMinutes) throws RegistryException { + return processRepository.getAVGTimeDistribution(gatewayId, searchBackTimeInMinutes); + } + + public List getProcessOutputs(String processId) throws RegistryException { + return processOutputRepository.getProcessOutputs(processId); + } + + public List getProcessWorkflows(String processId) throws RegistryException { + return processWorkflowRepository.getProcessWorkflows(processId); + } + + public void addProcessWorkflow(ProcessWorkflow processWorkflow) throws RegistryException { + processWorkflowRepository.addProcessWorkflow(processWorkflow, processWorkflow.getProcessId()); + } + + public List getProcessIds(String experimentId) throws RegistryException { + return processRepository.getProcessIds(DBConstants.Process.EXPERIMENT_ID, experimentId); + } + + public List getJobDetails(String airavataExperimentId) throws RegistryException { + if (!experimentRepository.isExperimentExist(airavataExperimentId)) { + logger.error( + airavataExperimentId, + "Error while retrieving job details, experiment {} doesn't exist.", + airavataExperimentId); + throw new RegistryException( + "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); + } + List processModels = processRepository.getProcessList( + Constants.FieldConstants.ProcessConstants.EXPERIMENT_ID, airavataExperimentId); + List jobList = new ArrayList<>(); + if (processModels != null && !processModels.isEmpty()) { + for (ProcessModel processModel : processModels) { + List tasks = processModel.getTasks(); + if (tasks != null && !tasks.isEmpty()) { + for (TaskModel taskModel : tasks) { + String taskId = taskModel.getTaskId(); + List taskJobs = + jobRepository.getJobList(Constants.FieldConstants.JobConstants.TASK_ID, taskId); + jobList.addAll(taskJobs); + } + } + } + } + logger.debug("Airavata retrieved job models for experiment with experiment id : " + airavataExperimentId); + return jobList; + } + + private boolean validateString(String name) { + boolean valid = true; + if (name == null || name.equals("") || name.trim().length() == 0) { + valid = false; + } + return valid; + } + + public boolean isGatewayExistInternal(String gatewayId) throws RegistryException { + return gatewayRepository.isGatewayExist(gatewayId); + } + + public ApplicationModule getApplicationModule(String appModuleId) throws AppCatalogException { + ApplicationModule module = applicationInterfaceRepository.getApplicationModule(appModuleId); + logger.debug("Airavata retrieved application module with module id : " + appModuleId); + return module; + } + + public List getAllAppModules(String gatewayId) throws AppCatalogException { + try { + if (!isGatewayExistInternal(gatewayId)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + List moduleList = applicationInterfaceRepository.getAllApplicationModules(gatewayId); + logger.debug("Airavata retrieved modules for gateway id : " + gatewayId); + return moduleList; + } + + public List getAccessibleAppModules( + String gatewayId, List accessibleAppIds, List accessibleComputeResourceIds) throws AppCatalogException { + try { + if (!isGatewayExistInternal(gatewayId)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + List moduleList = applicationInterfaceRepository.getAccessibleApplicationModules( + gatewayId, accessibleAppIds, accessibleComputeResourceIds); + logger.debug("Airavata retrieved modules for gateway id : " + gatewayId); + return moduleList; + } + + public boolean deleteApplicationModule(String appModuleId) throws AppCatalogException { + logger.debug("Airavata deleted application module with module id : " + appModuleId); + return applicationInterfaceRepository.removeApplicationModule(appModuleId); + } + + public ApplicationDeploymentDescription getApplicationDeployment(String appDeploymentId) throws AppCatalogException { + ApplicationDeploymentDescription deployement = + applicationDeploymentRepository.getApplicationDeployement(appDeploymentId); + logger.debug("Airavata registered application deployment for deployment id : " + appDeploymentId); + return deployement; + } + + public boolean deleteApplicationDeployment(String appDeploymentId) throws AppCatalogException { + applicationDeploymentRepository.removeAppDeployment(appDeploymentId); + logger.debug("Airavata removed application deployment with deployment id : " + appDeploymentId); + return true; + } + + public List getAllApplicationDeployments(String gatewayId) throws AppCatalogException { + try { + if (!isGatewayExistInternal(gatewayId)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + List deployements = + applicationDeploymentRepository.getAllApplicationDeployements(gatewayId); + logger.debug("Airavata retrieved application deployments for gateway id : " + gatewayId); + return deployements; + } + + public List getAccessibleApplicationDeployments( + String gatewayId, List accessibleAppDeploymentIds, List accessibleComputeResourceIds) throws AppCatalogException { + try { + if (!isGatewayExistInternal(gatewayId)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + List deployements = + applicationDeploymentRepository.getAccessibleApplicationDeployments( + gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); + logger.debug("Airavata retrieved application deployments for gateway id : " + gatewayId); + return deployements; + } + + public List getAccessibleApplicationDeploymentsForAppModule( + String gatewayId, + String appModuleId, + List accessibleAppDeploymentIds, + List accessibleComputeResourceIds) throws AppCatalogException { + try { + if (!isGatewayExistInternal(gatewayId)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + List deployments = + applicationDeploymentRepository.getAccessibleApplicationDeployments( + gatewayId, appModuleId, accessibleAppDeploymentIds, accessibleComputeResourceIds); + return deployments; + } + + public List getAppModuleDeployedResources(String appModuleId) throws AppCatalogException { + List appDeployments = new ArrayList<>(); + Map filters = new HashMap<>(); + filters.put(DBConstants.ApplicationDeployment.APPLICATION_MODULE_ID, appModuleId); + List applicationDeployments = + applicationDeploymentRepository.getApplicationDeployments(filters); + for (ApplicationDeploymentDescription description : applicationDeployments) { + appDeployments.add(description.getAppDeploymentId()); + } + logger.debug("Airavata retrieved application deployments for module id : " + appModuleId); + return appDeployments; + } + + public List getApplicationDeployments(String appModuleId) throws AppCatalogException { + Map filters = new HashMap<>(); + filters.put(DBConstants.ApplicationDeployment.APPLICATION_MODULE_ID, appModuleId); + List applicationDeployments = + applicationDeploymentRepository.getApplicationDeployments(filters); + return applicationDeployments; + } + + public ApplicationInterfaceDescription getApplicationInterface(String appInterfaceId) throws AppCatalogException { + ApplicationInterfaceDescription interfaceDescription = + applicationInterfaceRepository.getApplicationInterface(appInterfaceId); + logger.debug("Airavata retrieved application interface with interface id : " + appInterfaceId); + return interfaceDescription; + } + + public boolean deleteApplicationInterface(String appInterfaceId) throws AppCatalogException { + boolean removeApplicationInterface = + applicationInterfaceRepository.removeApplicationInterface(appInterfaceId); + logger.debug("Airavata removed application interface with interface id : " + appInterfaceId); + return removeApplicationInterface; + } + + public Map getAllApplicationInterfaceNames(String gatewayId) throws AppCatalogException { + try { + if (!isGatewayExistInternal(gatewayId)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + List allApplicationInterfaces = + applicationInterfaceRepository.getAllApplicationInterfaces(gatewayId); + Map allApplicationInterfacesMap = new HashMap<>(); + if (allApplicationInterfaces != null && !allApplicationInterfaces.isEmpty()) { + for (ApplicationInterfaceDescription interfaceDescription : allApplicationInterfaces) { + allApplicationInterfacesMap.put( + interfaceDescription.getApplicationInterfaceId(), + interfaceDescription.getApplicationName()); + } + } + logger.debug("Airavata retrieved application interfaces for gateway id : " + gatewayId); + return allApplicationInterfacesMap; + } + + public List getAllApplicationInterfaces(String gatewayId) throws AppCatalogException { + try { + if (!isGatewayExistInternal(gatewayId)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + List interfaces = + applicationInterfaceRepository.getAllApplicationInterfaces(gatewayId); + logger.debug("Airavata retrieved application interfaces for gateway id : " + gatewayId); + return interfaces; + } + + public List getApplicationInputs(String appInterfaceId) throws AppCatalogException { + List applicationInputs = + applicationInterfaceRepository.getApplicationInputs(appInterfaceId); + logger.debug("Airavata retrieved application inputs for application interface id : " + appInterfaceId); + return applicationInputs; + } + + private List getApplicationOutputsInternal(String appInterfaceId) throws AppCatalogException { + List applicationOutputs = + applicationInterfaceRepository.getApplicationOutputs(appInterfaceId); + logger.debug("Airavata retrieved application outputs for application interface id : " + appInterfaceId); + return applicationOutputs; + } + + public List getApplicationOutputs(String appInterfaceId) throws AppCatalogException { + List list = getApplicationOutputsInternal(appInterfaceId); + logger.debug("Airavata retrieved application outputs for app interface id : " + appInterfaceId); + return list; + } + + public Map getAvailableAppInterfaceComputeResources(String appInterfaceId) throws AppCatalogException { + Map allComputeResources = + new ComputeResourceRepository().getAvailableComputeResourceIdList(); + Map availableComputeResources = new HashMap(); + ApplicationInterfaceDescription applicationInterface = + applicationInterfaceRepository.getApplicationInterface(appInterfaceId); + HashMap filters = new HashMap<>(); + List applicationModules = applicationInterface.getApplicationModules(); + if (applicationModules != null && !applicationModules.isEmpty()) { + for (String moduleId : applicationModules) { + filters.put(DBConstants.ApplicationDeployment.APPLICATION_MODULE_ID, moduleId); + List applicationDeployments = + applicationDeploymentRepository.getApplicationDeployments(filters); + for (ApplicationDeploymentDescription deploymentDescription : applicationDeployments) { + if (allComputeResources.get(deploymentDescription.getComputeHostId()) != null) { + availableComputeResources.put( + deploymentDescription.getComputeHostId(), + allComputeResources.get(deploymentDescription.getComputeHostId())); + } + } + } + } + logger.debug( + "Airavata retrieved available compute resources for application interface id : " + appInterfaceId); + return availableComputeResources; + } + + public ComputeResourceDescription getComputeResource(String computeResourceId) throws AppCatalogException { + ComputeResourceDescription computeResource = + new ComputeResourceRepository().getComputeResource(computeResourceId); + logger.debug("Airavata retrieved compute resource with compute resource Id : " + computeResourceId); + return computeResource; + } + + public Map getAllComputeResourceNames() throws AppCatalogException { + Map computeResourceIdList = new ComputeResourceRepository().getAllComputeResourceIdList(); + logger.debug("Airavata retrieved all the available compute resources..."); + return computeResourceIdList; + } + + public boolean deleteComputeResource(String computeResourceId) throws AppCatalogException { + new ComputeResourceRepository().removeComputeResource(computeResourceId); + logger.debug("Airavata deleted compute resource with compute resource Id : " + computeResourceId); + return true; + } + + public StorageResourceDescription getStorageResource(String storageResourceId) throws AppCatalogException { + StorageResourceDescription storageResource = + storageResourceRepository.getStorageResource(storageResourceId); + logger.debug("Airavata retrieved storage resource with storage resource Id : " + storageResourceId); + return storageResource; + } + + public Map getAllStorageResourceNames() throws AppCatalogException { + Map resourceIdList = storageResourceRepository.getAllStorageResourceIdList(); + logger.debug("Airavata retrieved storage resources list..."); + return resourceIdList; + } + + public boolean deleteStorageResource(String storageResourceId) throws AppCatalogException { + storageResourceRepository.removeStorageResource(storageResourceId); + logger.debug("Airavata deleted storage resource with storage resource Id : " + storageResourceId); + return true; + } + + public LOCALSubmission getLocalJobSubmission(String jobSubmissionId) throws AppCatalogException { + LOCALSubmission localJobSubmission = new ComputeResourceRepository().getLocalJobSubmission(jobSubmissionId); + logger.debug("Airavata retrieved local job submission for job submission interface id: " + jobSubmissionId); + return localJobSubmission; + } + + public SSHJobSubmission getSSHJobSubmission(String jobSubmissionId) throws AppCatalogException { + SSHJobSubmission sshJobSubmission = new ComputeResourceRepository().getSSHJobSubmission(jobSubmissionId); + logger.debug("Airavata retrieved SSH job submission for job submission interface id: " + jobSubmissionId); + return sshJobSubmission; + } + + public UnicoreJobSubmission getUnicoreJobSubmission(String jobSubmissionId) throws AppCatalogException { + UnicoreJobSubmission unicoreJobSubmission = + new ComputeResourceRepository().getUNICOREJobSubmission(jobSubmissionId); + logger.debug( + "Airavata retrieved UNICORE job submission for job submission interface id: " + jobSubmissionId); + return unicoreJobSubmission; + } + + public CloudJobSubmission getCloudJobSubmission(String jobSubmissionId) throws AppCatalogException { + CloudJobSubmission cloudJobSubmission = + new ComputeResourceRepository().getCloudJobSubmission(jobSubmissionId); + logger.debug("Airavata retrieved cloud job submission for job submission interface id: " + jobSubmissionId); + return cloudJobSubmission; + } + + public boolean changeJobSubmissionPriority(String jobSubmissionInterfaceId, int newPriorityOrder) throws RegistryException { + return false; + } + + public boolean changeDataMovementPriority(String dataMovementInterfaceId, int newPriorityOrder) throws RegistryException { + return false; + } + + public boolean changeJobSubmissionPriorities(Map jobSubmissionPriorityMap) throws RegistryException { + return false; + } + + public boolean changeDataMovementPriorities(Map dataMovementPriorityMap) throws RegistryException { + return false; + } + + public boolean deleteJobSubmissionInterface(String computeResourceId, String jobSubmissionInterfaceId) throws AppCatalogException { + new ComputeResourceRepository().removeJobSubmissionInterface(computeResourceId, jobSubmissionInterfaceId); + logger.debug("Airavata deleted job submission interface with interface id : " + jobSubmissionInterfaceId); + return true; + } + + public ResourceJobManager getResourceJobManager(String resourceJobManagerId) throws AppCatalogException { + return new ComputeResourceRepository().getResourceJobManager(resourceJobManagerId); + } + + public boolean deleteResourceJobManager(String resourceJobManagerId) throws AppCatalogException { + new ComputeResourceRepository().deleteResourceJobManager(resourceJobManagerId); + return true; + } + + public boolean deleteBatchQueue(String computeResourceId, String queueName) throws AppCatalogException { + new ComputeResourceRepository().removeBatchQueue(computeResourceId, queueName); + return true; + } + + public GatewayResourceProfile getGatewayResourceProfile(String gatewayID) throws AppCatalogException { + try { + if (!isGatewayExistInternal(gatewayID)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); + GatewayResourceProfile gatewayResourceProfile = gwyResourceProfileRepository.getGatewayProfile(gatewayID); + logger.debug("Airavata retrieved gateway profile with gateway id : " + gatewayID); + return gatewayResourceProfile; + } + + public boolean deleteGatewayResourceProfile(String gatewayID) throws AppCatalogException { + try { + if (!isGatewayExistInternal(gatewayID)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); + gwyResourceProfileRepository.delete(gatewayID); + logger.debug("Airavata deleted gateway profile with gateway id : " + gatewayID); + return true; + } + + public ComputeResourcePreference getGatewayComputeResourcePreference(String gatewayID, String computeResourceId) throws AppCatalogException { + try { + if (!isGatewayExistInternal(gatewayID)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); + ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); + if (!gwyResourceProfileRepository.isGatewayResourceProfileExists(gatewayID)) { + logger.error( + gatewayID, + "Given gateway profile does not exist in the system. Please provide a valid gateway id..."); + throw new AppCatalogException( + "Given gateway profile does not exist in the system. Please provide a valid gateway id..."); + } + if (!computeResourceRepository.isComputeResourceExists(computeResourceId)) { + logger.error( + computeResourceId, + "Given compute resource does not exist in the system. Please provide a valid compute resource id..."); + throw new AppCatalogException( + "Given compute resource does not exist in the system. Please provide a valid compute resource id..."); + } + ComputeResourcePreference computeResourcePreference = + gwyResourceProfileRepository.getComputeResourcePreference(gatewayID, computeResourceId); + logger.debug("Airavata retrieved gateway compute resource preference with gateway id : " + gatewayID + + " and for compute resoruce id : " + computeResourceId); + return computeResourcePreference; + } + + public StoragePreference getGatewayStoragePreference(String gatewayID, String storageId) throws AppCatalogException { + try { + if (!isGatewayExistInternal(gatewayID)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); + if (!gwyResourceProfileRepository.isGatewayResourceProfileExists(gatewayID)) { + logger.error( + gatewayID, + "Given gateway profile does not exist in the system. Please provide a valid gateway id..."); + throw new AppCatalogException( + "Given gateway profile does not exist in the system. Please provide a valid gateway id..."); + } + StoragePreference storagePreference = + gwyResourceProfileRepository.getStoragePreference(gatewayID, storageId); + logger.debug("Airavata retrieved storage resource preference with gateway id : " + gatewayID + + " and for storage resource id : " + storageId); + return storagePreference; + } + + public List getAllGatewayComputeResourcePreferences(String gatewayID) throws AppCatalogException { + try { + if (!isGatewayExistInternal(gatewayID)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); + return gwyResourceProfileRepository.getGatewayProfile(gatewayID).getComputeResourcePreferences(); + } + + public List getAllGatewayStoragePreferences(String gatewayID) throws AppCatalogException { + try { + if (!isGatewayExistInternal(gatewayID)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); + return gwyResourceProfileRepository.getGatewayProfile(gatewayID).getStoragePreferences(); + } + + public List getAllGatewayResourceProfiles() throws AppCatalogException { + GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); + return gwyResourceProfileRepository.getAllGatewayProfiles(); + } + + public boolean deleteGatewayComputeResourcePreference(String gatewayID, String computeResourceId) throws AppCatalogException { + try { + if (!isGatewayExistInternal(gatewayID)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); + return gwyResourceProfileRepository.removeComputeResourcePreferenceFromGateway( + gatewayID, computeResourceId); + } + + public boolean deleteGatewayStoragePreference(String gatewayID, String storageId) throws AppCatalogException { + try { + if (!isGatewayExistInternal(gatewayID)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); + return gwyResourceProfileRepository.removeDataStoragePreferenceFromGateway(gatewayID, storageId); + } + + public DataProductModel getDataProduct(String productUri) throws RegistryException { + DataProductModel dataProductModel = dataProductRepository.getDataProduct(productUri); + return dataProductModel; + } + + public DataProductModel getParentDataProduct(String productUri) throws RegistryException { + DataProductModel dataProductModel = dataProductRepository.getParentDataProduct(productUri); + return dataProductModel; + } + + public List getChildDataProducts(String productUri) throws RegistryException { + List dataProductModels = dataProductRepository.getChildDataProducts(productUri); + return dataProductModels; + } + + public List searchDataProductsByName( + String gatewayId, String userId, String productName, int limit, int offset) throws RegistryException { + List dataProductModels = + dataProductRepository.searchDataProductsByName(gatewayId, userId, productName, limit, offset); + return dataProductModels; + } + + public String createGroupResourceProfile(GroupResourceProfile groupResourceProfile) throws AppCatalogException { + try { + if (!isGatewayExistInternal(groupResourceProfile.getGatewayId())) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); + String groupResourceProfileId = + groupResourceProfileRepository.addGroupResourceProfile(groupResourceProfile); + logger.debug("New Group Resource Profile Created: " + groupResourceProfileId); + return groupResourceProfileId; + } + + public void updateGroupResourceProfile(GroupResourceProfile groupResourceProfile) throws AppCatalogException { + GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); + if (!groupResourceProfileRepository.isGroupResourceProfileExists( + groupResourceProfile.getGroupResourceProfileId())) { + logger.error( + "Cannot update. No group resource profile found with matching gatewayId and groupResourceProfileId"); + throw new AppCatalogException( + "Cannot update. No group resource profile found with matching gatewayId and groupResourceProfileId"); + } + String groupResourceProfileId = + groupResourceProfileRepository.updateGroupResourceProfile(groupResourceProfile); + logger.debug(" Group Resource Profile updated: " + groupResourceProfileId); + } + + public GroupResourceProfile getGroupResourceProfile(String groupResourceProfileId) throws AppCatalogException { + GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); + if (!groupResourceProfileRepository.isGroupResourceProfileExists(groupResourceProfileId)) { + logger.error("No group resource profile found with matching gatewayId and groupResourceProfileId"); + throw new AppCatalogException( + "No group resource profile found with matching gatewayId and groupResourceProfileId"); + } + return groupResourceProfileRepository.getGroupResourceProfile(groupResourceProfileId); + } + + public boolean isGroupResourceProfileExists(String groupResourceProfileId) throws AppCatalogException { + GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); + return groupResourceProfileRepository.isGroupResourceProfileExists(groupResourceProfileId); + } + + public boolean removeGroupResourceProfile(String groupResourceProfileId) throws AppCatalogException { + GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); + if (!groupResourceProfileRepository.isGroupResourceProfileExists(groupResourceProfileId)) { + logger.error( + "Cannot Remove. No group resource profile found with matching gatewayId and groupResourceProfileId"); + throw new AppCatalogException( + "Cannot Remove. No group resource profile found with matching gatewayId and groupResourceProfileId"); + } + return groupResourceProfileRepository.removeGroupResourceProfile(groupResourceProfileId); + } + + public List getGroupResourceList(String gatewayId, List accessibleGroupResProfileIds) throws AppCatalogException { + GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); + return groupResourceProfileRepository.getAllGroupResourceProfiles(gatewayId, accessibleGroupResProfileIds); + } + + public boolean removeGroupComputePrefs(String computeResourceId, String groupResourceProfileId) throws AppCatalogException { + GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); + groupResourceProfileRepository.removeGroupComputeResourcePreference( + computeResourceId, groupResourceProfileId); + logger.debug("Removed compute resource preferences with compute resource ID: " + computeResourceId); + return true; + } + + public boolean removeGroupComputeResourcePolicy(String resourcePolicyId) throws AppCatalogException { + GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); + groupResourceProfileRepository.removeComputeResourcePolicy(resourcePolicyId); + logger.debug("Removed compute resource policy with resource policy ID: " + resourcePolicyId); + return true; + } + + public boolean removeGroupBatchQueueResourcePolicy(String resourcePolicyId) throws AppCatalogException { + GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); + groupResourceProfileRepository.removeBatchQueueResourcePolicy(resourcePolicyId); + logger.debug("Removed batch resource policy with resource policy ID: " + resourcePolicyId); + return true; + } + + public GroupComputeResourcePreference getGroupComputeResourcePreference( + String computeResourceId, String groupResourceProfileId) throws AppCatalogException { + GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); + GroupComputeResourcePreference groupComputeResourcePreference = + groupResourceProfileRepository.getGroupComputeResourcePreference( + computeResourceId, groupResourceProfileId); + if (!(groupComputeResourcePreference != null)) { + logger.error("GroupComputeResourcePreference not found"); + throw new AppCatalogException("GroupComputeResourcePreference not found "); + } + return groupComputeResourcePreference; + } + + public boolean isGroupComputeResourcePreferenceExists(String computeResourceId, String groupResourceProfileId) throws AppCatalogException { + GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); + return groupResourceProfileRepository.isGroupComputeResourcePreferenceExists( + computeResourceId, groupResourceProfileId); + } + + public ComputeResourcePolicy getGroupComputeResourcePolicy(String resourcePolicyId) throws AppCatalogException { + GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); + ComputeResourcePolicy computeResourcePolicy = + groupResourceProfileRepository.getComputeResourcePolicy(resourcePolicyId); + if (!(computeResourcePolicy != null)) { + logger.error("Group Compute Resource policy not found"); + throw new AppCatalogException("Group Compute Resource policy not found "); + } + return computeResourcePolicy; + } + + public BatchQueueResourcePolicy getBatchQueueResourcePolicy(String resourcePolicyId) throws AppCatalogException { + GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); + BatchQueueResourcePolicy batchQueueResourcePolicy = + groupResourceProfileRepository.getBatchQueueResourcePolicy(resourcePolicyId); + if (!(batchQueueResourcePolicy != null)) { + logger.error("Group Batch Queue Resource policy not found"); + throw new AppCatalogException("Group Batch Queue Resource policy not found "); + } + return batchQueueResourcePolicy; + } + + public List getGroupComputeResourcePrefList(String groupResourceProfileId) throws AppCatalogException { + GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); + return groupResourceProfileRepository.getAllGroupComputeResourcePreferences(groupResourceProfileId); + } + + public List getGroupBatchQueueResourcePolicyList(String groupResourceProfileId) throws AppCatalogException { + GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); + return groupResourceProfileRepository.getAllGroupBatchQueueResourcePolicies(groupResourceProfileId); + } + + public List getGroupComputeResourcePolicyList(String groupResourceProfileId) throws AppCatalogException { + GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); + return groupResourceProfileRepository.getAllGroupComputeResourcePolicies(groupResourceProfileId); + } + + public String registerReplicaLocation(DataReplicaLocationModel replicaLocationModel) throws RegistryException { + String replicaId = dataReplicaLocationRepository.registerReplicaLocation(replicaLocationModel); + return replicaId; + } + + public String registerDataProduct(DataProductModel dataProductModel) throws RegistryException { + String productUrl = dataProductRepository.registerDataProduct(dataProductModel); + return productUrl; + } + + public LOCALDataMovement getLocalDataMovement(String dataMovementId) throws AppCatalogException { + LOCALDataMovement localDataMovement = new ComputeResourceRepository().getLocalDataMovement(dataMovementId); + logger.debug("Airavata retrieved local data movement with data movement id: " + dataMovementId); + return localDataMovement; + } + + public SCPDataMovement getSCPDataMovement(String dataMovementId) throws AppCatalogException { + SCPDataMovement scpDataMovement = new ComputeResourceRepository().getSCPDataMovement(dataMovementId); + logger.debug("Airavata retrieved SCP data movement with data movement id: " + dataMovementId); + return scpDataMovement; + } + + public UnicoreDataMovement getUnicoreDataMovement(String dataMovementId) throws AppCatalogException { + UnicoreDataMovement unicoreDataMovement = + new ComputeResourceRepository().getUNICOREDataMovement(dataMovementId); + logger.debug("Airavata retrieved UNICORE data movement with data movement id: " + dataMovementId); + return unicoreDataMovement; + } + + public GridFTPDataMovement getGridFTPDataMovement(String dataMovementId) throws AppCatalogException { + GridFTPDataMovement gridFTPDataMovement = + new ComputeResourceRepository().getGridFTPDataMovement(dataMovementId); + logger.debug("Airavata retrieved GRIDFTP data movement with data movement id: " + dataMovementId); + return gridFTPDataMovement; + } + + // Experiment operations + public String createExperiment(String gatewayId, ExperimentModel experiment) throws RegistryException { + if (!validateString(experiment.getExperimentName())) { + logger.error("Cannot create experiments with empty experiment name"); + throw new RegistryException("Cannot create experiments with empty experiment name"); + } + logger.info("Creating experiment with name " + experiment.getExperimentName()); + if (!isGatewayExistInternal(gatewayId)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new RegistryException("Gateway does not exist.Please provide a valid gateway id..."); + } + + if (experiment.getUserConfigurationData() != null + && experiment.getUserConfigurationData().getComputationalResourceScheduling() != null + && experiment + .getUserConfigurationData() + .getComputationalResourceScheduling() + .getResourceHostId() + != null) { + + String compResourceId = experiment + .getUserConfigurationData() + .getComputationalResourceScheduling() + .getResourceHostId(); + try { + ComputeResourceDescription computeResourceDescription = + new ComputeResourceRepository().getComputeResource(compResourceId); + if (!computeResourceDescription.isEnabled()) { + logger.error("Compute Resource is not enabled by the Admin!"); + throw new RegistryException("Compute Resource is not enabled by the Admin!"); + } + } catch (AppCatalogException e) { + throw new RegistryException("Error checking compute resource: " + e.getMessage(), e); + } + } else if (experiment.getUserConfigurationData() != null + && !experiment + .getUserConfigurationData() + .getAutoScheduledCompResourceSchedulingList() + .isEmpty()) { + for (ComputationalResourceSchedulingModel computationalResourceScheduling : + experiment.getUserConfigurationData().getAutoScheduledCompResourceSchedulingList()) { + try { + ComputeResourceDescription computeResourceDescription = new ComputeResourceRepository() + .getComputeResource(computationalResourceScheduling.getResourceHostId()); + if (!computeResourceDescription.isEnabled()) { + logger.error("Compute Resource with id" + computationalResourceScheduling.getResourceHostId() + + "" + " is not enabled by the Admin!"); + throw new RegistryException( + "Compute Resource with id" + computationalResourceScheduling.getResourceHostId() + "" + + " is not enabled by the Admin!"); + } + } catch (AppCatalogException e) { + throw new RegistryException("Error checking compute resource: " + e.getMessage(), e); + } + } + } + + experiment.setGatewayId(gatewayId); + String experimentId = experimentRepository.addExperiment(experiment); + if (experiment.getExperimentType() == ExperimentType.WORKFLOW) { + try { + workflowRepository.registerWorkflow(experiment.getWorkflow(), experimentId); + } catch (WorkflowCatalogException e) { + throw new RegistryException("Error registering workflow: " + e.getMessage(), e); + } + } + logger.debug( + experimentId, "Created new experiment with experiment name {}", experiment.getExperimentName()); + return experimentId; + } + + public List searchExperiments( + String gatewayId, + String userName, + List accessibleExpIds, + Map filters, + int limit, + int offset) throws RegistryException { + if (!validateString(userName)) { + logger.error("Username cannot be empty. Please provide a valid user.."); + throw new RegistryException("Username cannot be empty. Please provide a valid user.."); + } + if (!isGatewayExistInternal(gatewayId)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new RegistryException("Gateway does not exist.Please provide a valid gateway id..."); + } + if (!userRepository.isUserExists(gatewayId, userName)) { + logger.error("User does not exist in the system. Please provide a valid user.."); + throw new RegistryException("User does not exist in the system. Please provide a valid user.."); + } + List summaries = new ArrayList(); + Map regFilters = new HashMap(); + regFilters.put(Constants.FieldConstants.ExperimentConstants.GATEWAY_ID, gatewayId); + for (Map.Entry entry : filters.entrySet()) { + if (entry.getKey().equals(ExperimentSearchFields.EXPERIMENT_NAME)) { + regFilters.put(Constants.FieldConstants.ExperimentConstants.EXPERIMENT_NAME, entry.getValue()); + } else if (entry.getKey().equals(ExperimentSearchFields.EXPERIMENT_DESC)) { + regFilters.put(Constants.FieldConstants.ExperimentConstants.DESCRIPTION, entry.getValue()); + } else if (entry.getKey().equals(ExperimentSearchFields.APPLICATION_ID)) { + regFilters.put(Constants.FieldConstants.ExperimentConstants.EXECUTION_ID, entry.getValue()); + } else if (entry.getKey().equals(ExperimentSearchFields.STATUS)) { + regFilters.put(Constants.FieldConstants.ExperimentConstants.EXPERIMENT_STATUS, entry.getValue()); + } else if (entry.getKey().equals(ExperimentSearchFields.FROM_DATE)) { + regFilters.put(Constants.FieldConstants.ExperimentConstants.FROM_DATE, entry.getValue()); + } else if (entry.getKey().equals(ExperimentSearchFields.TO_DATE)) { + regFilters.put(Constants.FieldConstants.ExperimentConstants.TO_DATE, entry.getValue()); + } else if (entry.getKey().equals(ExperimentSearchFields.PROJECT_ID)) { + regFilters.put(Constants.FieldConstants.ExperimentConstants.PROJECT_ID, entry.getValue()); + } else if (entry.getKey().equals(ExperimentSearchFields.USER_NAME)) { + regFilters.put(Constants.FieldConstants.ExperimentConstants.USER_NAME, entry.getValue()); + } else if (entry.getKey().equals(ExperimentSearchFields.JOB_ID)) { + regFilters.put(Constants.FieldConstants.JobConstants.JOB_ID, entry.getValue()); + } + } + + try { + if (accessibleExpIds.size() == 0 && !ServerSettings.isEnableSharing()) { + if (!regFilters.containsKey(DBConstants.Experiment.USER_NAME)) { + regFilters.put(DBConstants.Experiment.USER_NAME, userName); + } + } + } catch (Exception e) { + logger.warn("Error checking sharing settings, continuing without filter", e); + } + summaries = experimentSummaryRepository.searchAllAccessibleExperiments( + accessibleExpIds, + regFilters, + limit, + offset, + Constants.FieldConstants.ExperimentConstants.CREATION_TIME, + ResultOrderType.DESC); + logger.debug("Airavata retrieved experiments for user : " + userName + " and gateway id : " + gatewayId); + return summaries; + } + + public void updateExperiment(String airavataExperimentId, ExperimentModel experiment) throws RegistryException { + if (!experimentRepository.isExperimentExist(airavataExperimentId)) { + logger.error( + airavataExperimentId, + "Update request failed, Experiment {} doesn't exist.", + airavataExperimentId); + throw new RegistryException( + "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); + } + + ExperimentStatus experimentStatus = getExperimentStatusInternal(airavataExperimentId); + if (experimentStatus != null) { + ExperimentState experimentState = experimentStatus.getState(); + switch (experimentState) { + case CREATED: + case SCHEDULED: + case VALIDATED: + if (experiment.getUserConfigurationData() != null + && experiment.getUserConfigurationData().getComputationalResourceScheduling() != null + && experiment + .getUserConfigurationData() + .getComputationalResourceScheduling() + .getResourceHostId() + != null) { + String compResourceId = experiment + .getUserConfigurationData() + .getComputationalResourceScheduling() + .getResourceHostId(); + try { + ComputeResourceDescription computeResourceDescription = + new ComputeResourceRepository().getComputeResource(compResourceId); + if (!computeResourceDescription.isEnabled()) { + logger.error("Compute Resource is not enabled by the Admin!"); + throw new RegistryException("Compute Resource is not enabled by the Admin!"); + } + } catch (AppCatalogException e) { + throw new RegistryException("Error checking compute resource: " + e.getMessage(), e); + } + } + experimentRepository.updateExperiment(experiment, airavataExperimentId); + logger.debug( + airavataExperimentId, + "Successfully updated experiment {} ", + experiment.getExperimentName()); + break; + default: + logger.error( + airavataExperimentId, + "Error while updating experiment. Update experiment is only valid for experiments " + + "with status CREATED, VALIDATED, CANCELLED, FAILED and UNKNOWN. Make sure the given " + + "experiment is in one of above statuses... "); + throw new RegistryException( + "Error while updating experiment. Update experiment is only valid for experiments " + + "with status CREATED, VALIDATED, CANCELLED, FAILED and UNKNOWN. Make sure the given " + + "experiment is in one of above statuses... "); + } + } + } + + public void updateExperimentConfiguration(String airavataExperimentId, UserConfigurationDataModel userConfiguration) throws RegistryException { + if (!experimentRepository.isExperimentExist(airavataExperimentId)) { + logger.error( + airavataExperimentId, + "Update experiment configuration failed, experiment {} doesn't exist.", + airavataExperimentId); + throw new RegistryException( + "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); + } + ExperimentStatus experimentStatus = getExperimentStatusInternal(airavataExperimentId); + if (experimentStatus != null) { + ExperimentState experimentState = experimentStatus.getState(); + switch (experimentState) { + case CREATED: + case VALIDATED: + case CANCELED: + case FAILED: + experimentRepository.addUserConfigurationData(userConfiguration, airavataExperimentId); + logger.debug( + airavataExperimentId, + "Successfully updated experiment configuration for experiment {}.", + airavataExperimentId); + break; + default: + logger.error( + airavataExperimentId, + "Error while updating experiment {}. Update experiment is only valid for experiments " + + "with status CREATED, VALIDATED, CANCELLED, FAILED and UNKNOWN. Make sure the given " + + "experiment is in one of above statuses... ", + airavataExperimentId); + throw new RegistryException( + "Error while updating experiment. Update experiment is only valid for experiments " + + "with status CREATED, VALIDATED, CANCELLED, FAILED and UNKNOWN. Make sure the given " + + "experiment is in one of above statuses... "); + } + } + } + + public List getIntermediateOutputs(String airavataExperimentId) throws RegistryException { + if (!experimentRepository.isExperimentExist(airavataExperimentId)) { + logger.error( + airavataExperimentId, + "Error while retrieving intermediate outputs, experiment {} doesn't exist.", + airavataExperimentId); + throw new RegistryException( + "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); + } + List processModels = processRepository.getProcessList( + Constants.FieldConstants.ExperimentConstants.EXPERIMENT_ID, airavataExperimentId); + List intermediateOutputs = new ArrayList<>(); + if (processModels != null && !processModels.isEmpty()) { + for (ProcessModel processModel : processModels) { + List processOutputs = processOutputRepository.getProcessOutputs(processModel.getProcessId()); + if (processOutputs != null && !processOutputs.isEmpty()) { + intermediateOutputs.addAll(processOutputs); + } + } + } + logger.debug("Airavata retrieved intermediate outputs for experiment with experiment id : " + airavataExperimentId); + return intermediateOutputs; + } + + public Map getJobStatuses(String airavataExperimentId) throws RegistryException { + if (!experimentRepository.isExperimentExist(airavataExperimentId)) { + logger.error( + airavataExperimentId, + "Error while retrieving job statuses, experiment {} doesn't exist.", + airavataExperimentId); + throw new RegistryException( + "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); + } + Map jobStatus = new HashMap<>(); + List processModels = processRepository.getProcessList( + Constants.FieldConstants.ExperimentConstants.EXPERIMENT_ID, airavataExperimentId); + if (processModels != null && !processModels.isEmpty()) { + for (ProcessModel processModel : processModels) { + List tasks = processModel.getTasks(); + if (tasks != null && !tasks.isEmpty()) { + for (TaskModel taskModel : tasks) { + String taskId = taskModel.getTaskId(); + List taskJobs = + jobRepository.getJobList(Constants.FieldConstants.JobConstants.TASK_ID, taskId); + if (taskJobs != null && !taskJobs.isEmpty()) { + for (JobModel jobModel : taskJobs) { + JobPK jobPK = new JobPK(); + jobPK.setJobId(jobModel.getJobId()); + jobPK.setTaskId(taskId); + JobStatus status = jobStatusRepository.getJobStatus(jobPK); + if (status != null) { + jobStatus.put(jobModel.getJobId(), status); + } + } + } + } + } + } + } + logger.debug("Airavata retrieved job statuses for experiment with experiment id : " + airavataExperimentId); + return jobStatus; + } + + public void addExperimentProcessOutputs(String outputType, List outputs, String id) throws RegistryException { + if (ExpCatChildDataType.PROCESS_OUTPUT.equals(ExpCatChildDataType.valueOf(outputType))) { + processOutputRepository.addProcessOutputs(outputs, id); + } else if (ExpCatChildDataType.EXPERIMENT_OUTPUT.equals(ExpCatChildDataType.valueOf(outputType))) { + experimentOutputRepository.addExperimentOutputs(outputs, id); + } + } + + public void addErrors(String errorType, ErrorModel errorModel, String id) throws RegistryException { + if (ExpCatChildDataType.EXPERIMENT_ERROR.equals(ExpCatChildDataType.valueOf(errorType))) { + experimentErrorRepository.addExperimentError(errorModel, id); + } else if (ExpCatChildDataType.TASK_ERROR.equals(ExpCatChildDataType.valueOf(errorType))) { + taskErrorRepository.addTaskError(errorModel, id); + } else if (ExpCatChildDataType.PROCESS_ERROR.equals(ExpCatChildDataType.valueOf(errorType))) { + processErrorRepository.addProcessError(errorModel, id); + } + } + + public void addTaskStatus(TaskStatus taskStatus, String taskId) throws RegistryException { + taskStatusRepository.addTaskStatus(taskStatus, taskId); + } + + public void addProcessStatus(ProcessStatus processStatus, String processId) throws RegistryException { + processStatusRepository.addProcessStatus(processStatus, processId); + } + + public void updateProcessStatus(ProcessStatus processStatus, String processId) throws RegistryException { + processStatusRepository.updateProcessStatus(processStatus, processId); + } + + public void updateExperimentStatus(ExperimentStatus experimentStatus, String experimentId) throws RegistryException { + experimentStatusRepository.updateExperimentStatus(experimentStatus, experimentId); + } + + public void addJobStatus(JobStatus jobStatus, String taskId, String jobId) throws RegistryException { + JobPK jobPK = new JobPK(); + jobPK.setJobId(jobId); + jobPK.setTaskId(taskId); + jobStatusRepository.addJobStatus(jobStatus, jobPK); + } + + public void deleteJobs(String processId) throws RegistryException { + List jobs = jobRepository.getJobList(Constants.FieldConstants.JobConstants.PROCESS_ID, processId); + for (JobModel jobModel : jobs) { + jobRepository.removeJob(jobModel); + } + } + + // Project operations + public String createProject(String gatewayId, Project project) throws RegistryException { + if (!validateString(project.getName()) || !validateString(project.getOwner())) { + logger.error("Project name and owner cannot be empty..."); + throw new RegistryException("Project name and owner cannot be empty..."); + } + if (!validateString(gatewayId)) { + logger.error("Gateway ID cannot be empty..."); + throw new RegistryException("Gateway ID cannot be empty..."); + } + if (!isGatewayExistInternal(gatewayId)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new RegistryException("Gateway does not exist.Please provide a valid gateway id..."); + } + String projectId = projectRepository.addProject(project, gatewayId); + return projectId; + } + + public void updateProject(String projectId, Project updatedProject) throws RegistryException { + if (!validateString(projectId)) { + logger.error("Project id cannot be empty..."); + throw new RegistryException("Project id cannot be empty..."); + } + if (!projectRepository.isProjectExist(projectId)) { + logger.error("Project does not exist in the system. Please provide a valid project ID..."); + throw new RegistryException("Project does not exist in the system. Please provide a valid project ID..."); + } + projectRepository.updateProject(updatedProject, projectId); + logger.debug("Airavata updated project with project Id : " + projectId); + } + + public List searchProjects( + String gatewayId, + String userName, + List accessibleProjIds, + Map filters, + int limit, + int offset) throws RegistryException { + if (!validateString(userName)) { + logger.error("Username cannot be empty. Please provide a valid user.."); + throw new RegistryException("Username cannot be empty. Please provide a valid user.."); + } + if (!isGatewayExistInternal(gatewayId)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new RegistryException("Gateway does not exist.Please provide a valid gateway id..."); + } + if (!userRepository.isUserExists(gatewayId, userName)) { + logger.error("User does not exist in the system. Please provide a valid user.."); + throw new RegistryException("User does not exist in the system. Please provide a valid user.."); + } + List projects = new ArrayList<>(); + Map regFilters = new HashMap<>(); + regFilters.put(Constants.FieldConstants.ProjectConstants.GATEWAY_ID, gatewayId); + for (Map.Entry entry : filters.entrySet()) { + if (entry.getKey().equals(ProjectSearchFields.PROJECT_NAME)) { + regFilters.put(Constants.FieldConstants.ProjectConstants.PROJECT_NAME, entry.getValue()); + } else if (entry.getKey().equals(ProjectSearchFields.PROJECT_DESCRIPTION)) { + regFilters.put(Constants.FieldConstants.ProjectConstants.DESCRIPTION, entry.getValue()); + } + } + + try { + if (accessibleProjIds.size() == 0 && !ServerSettings.isEnableSharing()) { + if (!regFilters.containsKey(DBConstants.Project.OWNER)) { + regFilters.put(DBConstants.Project.OWNER, userName); + } + } + } catch (Exception e) { + logger.warn("Error checking sharing settings, continuing without filter", e); + } + + projects = projectRepository.searchAllAccessibleProjects( + accessibleProjIds, + regFilters, + limit, + offset, + Constants.FieldConstants.ProjectConstants.CREATION_TIME, + ResultOrderType.DESC); + logger.debug("Airavata retrieved projects for user : " + userName + " and gateway id : " + gatewayId); + return projects; + } + + // Gateway Resource Profile operations + public String registerGatewayResourceProfile(GatewayResourceProfile gatewayResourceProfile) throws AppCatalogException { + if (!validateString(gatewayResourceProfile.getGatewayID())) { + logger.error("Cannot create gateway profile with empty gateway id"); + throw new AppCatalogException("Cannot create gateway profile with empty gateway id"); + } + try { + if (!isGatewayExistInternal(gatewayResourceProfile.getGatewayID())) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); + String resourceProfile = gwyResourceProfileRepository.addGatewayResourceProfile(gatewayResourceProfile); + logger.debug( + "Airavata registered gateway profile with gateway id : " + gatewayResourceProfile.getGatewayID()); + return resourceProfile; + } + + public boolean updateGatewayResourceProfile(String gatewayID, GatewayResourceProfile gatewayResourceProfile) throws AppCatalogException { + try { + if (!isGatewayExistInternal(gatewayID)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); + gwyResourceProfileRepository.updateGatewayResourceProfile(gatewayResourceProfile); + logger.debug("Airavata updated gateway profile with gateway id : " + gatewayID); + return true; + } + + public boolean addGatewayComputeResourcePreference( + String gatewayID, String computeResourceId, ComputeResourcePreference computeResourcePreference) throws AppCatalogException { + try { + if (!isGatewayExistInternal(gatewayID)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); + if (!(gwyResourceProfileRepository.isExists(gatewayID))) { + throw new AppCatalogException("Gateway resource profile '" + gatewayID + "' does not exist!!!"); + } + GatewayResourceProfile profile = gwyResourceProfileRepository.getGatewayProfile(gatewayID); + profile.addToComputeResourcePreferences(computeResourcePreference); + gwyResourceProfileRepository.updateGatewayResourceProfile(profile); + logger.debug("Airavata added gateway compute resource preference with gateway id : " + gatewayID + + " and for compute resource id : " + computeResourceId); + return true; + } + + public boolean updateGatewayComputeResourcePreference( + String gatewayID, String computeResourceId, ComputeResourcePreference computeResourcePreference) throws AppCatalogException { + try { + if (!isGatewayExistInternal(gatewayID)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); + GatewayResourceProfile profile = gwyResourceProfileRepository.getGatewayProfile(gatewayID); + List computeResourcePreferences = profile.getComputeResourcePreferences(); + ComputeResourcePreference preferenceToRemove = null; + for (ComputeResourcePreference preference : computeResourcePreferences) { + if (preference.getComputeResourceId().equals(computeResourceId)) { + preferenceToRemove = preference; + break; + } + } + if (preferenceToRemove != null) { + profile.getComputeResourcePreferences().remove(preferenceToRemove); + } + profile.getComputeResourcePreferences().add(computeResourcePreference); + gwyResourceProfileRepository.updateGatewayResourceProfile(profile); + logger.debug("Airavata updated compute resource preference with gateway id : " + gatewayID + + " and for compute resource id : " + computeResourceId); + return true; + } + + public boolean addGatewayStoragePreference( + String gatewayID, String storageResourceId, StoragePreference dataStoragePreference) throws AppCatalogException { + try { + if (!isGatewayExistInternal(gatewayID)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); + if (!(gwyResourceProfileRepository.isExists(gatewayID))) { + throw new AppCatalogException("Gateway resource profile '" + gatewayID + "' does not exist!!!"); + } + GatewayResourceProfile profile = gwyResourceProfileRepository.getGatewayProfile(gatewayID); + dataStoragePreference.setStorageResourceId(storageResourceId); + profile.addToStoragePreferences(dataStoragePreference); + gwyResourceProfileRepository.updateGatewayResourceProfile(profile); + logger.debug("Airavata added storage resource preference with gateway id : " + gatewayID + + " and for storage resource id : " + storageResourceId); + return true; + } + + public boolean updateGatewayStoragePreference( + String gatewayID, String storageId, StoragePreference storagePreference) throws AppCatalogException { + try { + if (!isGatewayExistInternal(gatewayID)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); + GatewayResourceProfile profile = gwyResourceProfileRepository.getGatewayProfile(gatewayID); + List dataStoragePreferences = profile.getStoragePreferences(); + StoragePreference preferenceToRemove = null; + for (StoragePreference preference : dataStoragePreferences) { + if (preference.getStorageResourceId().equals(storageId)) { + preferenceToRemove = preference; + break; + } + } + if (preferenceToRemove != null) { + profile.getStoragePreferences().remove(preferenceToRemove); + } + profile.getStoragePreferences().add(storagePreference); + gwyResourceProfileRepository.updateGatewayResourceProfile(profile); + logger.debug("Airavata updated storage resource preference with gateway id : " + gatewayID + + " and for storage resource id : " + storageId); + return true; + } + + // Compute Resource operations + public String registerComputeResource(ComputeResourceDescription computeResourceDescription) throws AppCatalogException { + String computeResource = new ComputeResourceRepository().addComputeResource(computeResourceDescription); + logger.debug("Airavata registered compute resource with compute resource Id : " + computeResource); + return computeResource; + } + + public boolean updateComputeResource( + String computeResourceId, ComputeResourceDescription computeResourceDescription) throws AppCatalogException { + new ComputeResourceRepository().updateComputeResource(computeResourceId, computeResourceDescription); + logger.debug("Airavata updated compute resource with compute resource Id : " + computeResourceId); + return true; + } + + public String registerResourceJobManager(ResourceJobManager resourceJobManager) throws AppCatalogException { + return new ComputeResourceRepository().addResourceJobManager(resourceJobManager); + } + + public boolean updateResourceJobManager(String resourceJobManagerId, ResourceJobManager updatedResourceJobManager) throws AppCatalogException { + new ComputeResourceRepository().updateResourceJobManager(resourceJobManagerId, updatedResourceJobManager); + return true; + } + + public boolean deleteDataMovementInterface(String resourceId, String dataMovementInterfaceId, DMType dmType) throws AppCatalogException { + switch (dmType) { + case COMPUTE_RESOURCE: + new ComputeResourceRepository().removeDataMovementInterface(resourceId, dataMovementInterfaceId); + logger.debug( + "Airavata deleted data movement interface with interface id : " + dataMovementInterfaceId); + return true; + case STORAGE_RESOURCE: + storageResourceRepository.removeDataMovementInterface(resourceId, dataMovementInterfaceId); + logger.debug( + "Airavata deleted data movement interface with interface id : " + dataMovementInterfaceId); + return true; + default: + logger.error( + "Unsupported data movement type specifies.. Please provide the correct data movement type... "); + return false; + } + } + + public boolean updateGridFTPDataMovementDetails( + String dataMovementInterfaceId, GridFTPDataMovement gridFTPDataMovement) throws AppCatalogException { + throw new AppCatalogException("updateGridFTPDataMovementDetails is not yet implemented"); + } + + public String addGridFTPDataMovementDetails( + String computeResourceId, DMType dmType, int priorityOrder, GridFTPDataMovement gridFTPDataMovement) throws AppCatalogException { + ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); + String addDataMovementInterface = addDataMovementInterface( + computeResourceRepository, + computeResourceId, + dmType, + computeResourceRepository.addGridFTPDataMovement(gridFTPDataMovement), + DataMovementProtocol.GridFTP, + priorityOrder); + logger.debug("Airavata registered GridFTP data movement for resource Id: " + computeResourceId); + return addDataMovementInterface; + } + + public boolean updateUnicoreDataMovementDetails( + String dataMovementInterfaceId, UnicoreDataMovement unicoreDataMovement) throws AppCatalogException { + throw new AppCatalogException("updateUnicoreDataMovementDetails is not yet implemented"); + } + + public String addUnicoreDataMovementDetails( + String resourceId, DMType dmType, int priorityOrder, UnicoreDataMovement unicoreDataMovement) throws AppCatalogException { + ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); + String movementInterface = addDataMovementInterface( + computeResourceRepository, + resourceId, + dmType, + computeResourceRepository.addUnicoreDataMovement(unicoreDataMovement), + DataMovementProtocol.UNICORE_STORAGE_SERVICE, + priorityOrder); + logger.debug("Airavata registered UNICORE data movement for resource Id: " + resourceId); + return movementInterface; + } + + public boolean updateSCPDataMovementDetails(String dataMovementInterfaceId, SCPDataMovement scpDataMovement) throws AppCatalogException { + new ComputeResourceRepository().updateScpDataMovement(scpDataMovement); + logger.debug("Airavata updated SCP data movement with data movement id: " + dataMovementInterfaceId); + return true; + } + + public String addSCPDataMovementDetails( + String resourceId, DMType dmType, int priorityOrder, SCPDataMovement scpDataMovement) throws AppCatalogException { + ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); + String movementInterface = addDataMovementInterface( + computeResourceRepository, + resourceId, + dmType, + computeResourceRepository.addScpDataMovement(scpDataMovement), + DataMovementProtocol.SCP, + priorityOrder); + logger.debug("Airavata registered SCP data movement for resource Id: " + resourceId); + return movementInterface; + } + + public boolean updateLocalDataMovementDetails(String dataMovementInterfaceId, LOCALDataMovement localDataMovement) throws AppCatalogException { + new ComputeResourceRepository().updateLocalDataMovement(localDataMovement); + logger.debug("Airavata updated local data movement with data movement id: " + dataMovementInterfaceId); + return true; + } + + public String addLocalDataMovementDetails( + String resourceId, DMType dataMoveType, int priorityOrder, LOCALDataMovement localDataMovement) throws AppCatalogException { + ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); + String movementInterface = addDataMovementInterface( + computeResourceRepository, + resourceId, + dataMoveType, + computeResourceRepository.addLocalDataMovement(localDataMovement), + DataMovementProtocol.LOCAL, + priorityOrder); + logger.debug("Airavata registered local data movement for resource Id: " + resourceId); + return movementInterface; + } + + // Storage Resource operations + public String registerStorageResource(StorageResourceDescription storageResourceDescription) throws AppCatalogException { + String storageResource = storageResourceRepository.addStorageResource(storageResourceDescription); + logger.debug("Airavata registered storage resource with storage resource Id : " + storageResource); + return storageResource; + } + + public boolean updateStorageResource( + String storageResourceId, StorageResourceDescription storageResourceDescription) throws AppCatalogException { + storageResourceRepository.updateStorageResource(storageResourceId, storageResourceDescription); + logger.debug("Airavata updated storage resource with storage resource Id : " + storageResourceId); + return true; + } + + // Helper methods for job submission and data movement interfaces + private String addJobSubmissionInterface( + ComputeResourceRepository computeResourceRepository, + String computeResourceId, + String jobSubmissionInterfaceId, + JobSubmissionProtocol protocolType, + int priorityOrder) throws AppCatalogException { + JobSubmissionInterface jobSubmissionInterface = new JobSubmissionInterface(); + jobSubmissionInterface.setJobSubmissionInterfaceId(jobSubmissionInterfaceId); + jobSubmissionInterface.setPriorityOrder(priorityOrder); + jobSubmissionInterface.setJobSubmissionProtocol(protocolType); + return computeResourceRepository.addJobSubmissionProtocol(computeResourceId, jobSubmissionInterface); + } + + private String addDataMovementInterface( + ComputeResourceRepository computeResourceRepository, + String computeResourceId, + DMType dmType, + String dataMovementInterfaceId, + DataMovementProtocol protocolType, + int priorityOrder) throws AppCatalogException { + DataMovementInterface dataMovementInterface = new DataMovementInterface(); + dataMovementInterface.setDataMovementInterfaceId(dataMovementInterfaceId); + dataMovementInterface.setPriorityOrder(priorityOrder); + dataMovementInterface.setDataMovementProtocol(protocolType); + if (dmType.equals(DMType.COMPUTE_RESOURCE)) { + return computeResourceRepository.addDataMovementProtocol(computeResourceId, dmType, dataMovementInterface); + } else if (dmType.equals(DMType.STORAGE_RESOURCE)) { + dataMovementInterface.setStorageResourceId(computeResourceId); + return storageResourceRepository.addDataMovementInterface(dataMovementInterface); + } + return null; + } + + // Job Submission Interface operations + public String addSSHJobSubmissionDetails( + String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) throws AppCatalogException { + ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); + String submissionInterface = addJobSubmissionInterface( + computeResourceRepository, + computeResourceId, + computeResourceRepository.addSSHJobSubmission(sshJobSubmission), + JobSubmissionProtocol.SSH, + priorityOrder); + logger.debug("Airavata registered SSH job submission for compute resource id: " + computeResourceId); + return submissionInterface; + } + + public String addSSHForkJobSubmissionDetails( + String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) throws AppCatalogException { + ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); + String submissionDetails = addJobSubmissionInterface( + computeResourceRepository, + computeResourceId, + computeResourceRepository.addSSHJobSubmission(sshJobSubmission), + JobSubmissionProtocol.SSH_FORK, + priorityOrder); + logger.debug("Airavata registered Fork job submission for compute resource id: " + computeResourceId); + return submissionDetails; + } + + public String addLocalSubmissionDetails( + String computeResourceId, int priorityOrder, LOCALSubmission localSubmission) throws AppCatalogException { + ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); + String submissionInterface = addJobSubmissionInterface( + computeResourceRepository, + computeResourceId, + computeResourceRepository.addLocalJobSubmission(localSubmission), + JobSubmissionProtocol.LOCAL, + priorityOrder); + logger.debug("Airavata added local job submission for compute resource id: " + computeResourceId); + return submissionInterface; + } + + public boolean updateLocalSubmissionDetails(String jobSubmissionInterfaceId, LOCALSubmission localSubmission) throws AppCatalogException { + new ComputeResourceRepository().updateLocalJobSubmission(localSubmission); + logger.debug("Airavata updated local job submission for job submission interface id: " + jobSubmissionInterfaceId); + return true; + } + + public String addCloudJobSubmissionDetails( + String computeResourceId, int priorityOrder, CloudJobSubmission cloudSubmission) throws AppCatalogException { + ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); + String submissionInterface = addJobSubmissionInterface( + computeResourceRepository, + computeResourceId, + computeResourceRepository.addCloudJobSubmission(cloudSubmission), + JobSubmissionProtocol.CLOUD, + priorityOrder); + logger.debug("Airavata registered Cloud job submission for compute resource id: " + computeResourceId); + return submissionInterface; + } + + public String addUNICOREJobSubmissionDetails( + String computeResourceId, int priorityOrder, UnicoreJobSubmission unicoreJobSubmission) throws AppCatalogException { + ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); + String submissionInterface = addJobSubmissionInterface( + computeResourceRepository, + computeResourceId, + computeResourceRepository.addUNICOREJobSubmission(unicoreJobSubmission), + JobSubmissionProtocol.UNICORE, + priorityOrder); + logger.debug("Airavata registered UNICORE job submission for compute resource id: " + computeResourceId); + return submissionInterface; + } + + // Application Interface/Module/Deployment operations + public String registerApplicationInterface(String gatewayId, ApplicationInterfaceDescription applicationInterface) throws AppCatalogException { + try { + if (!isGatewayExistInternal(gatewayId)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + String interfaceId = applicationInterfaceRepository.addApplicationInterface(applicationInterface, gatewayId); + logger.debug("Airavata registered application interface for gateway id : " + gatewayId); + return interfaceId; + } + + public boolean updateApplicationInterface( + String appInterfaceId, ApplicationInterfaceDescription applicationInterface) throws AppCatalogException { + applicationInterfaceRepository.updateApplicationInterface(appInterfaceId, applicationInterface); + logger.debug("Airavata updated application interface with interface id : " + appInterfaceId); + return true; + } + + public String registerApplicationModule(String gatewayId, ApplicationModule applicationModule) throws AppCatalogException { + try { + if (!isGatewayExistInternal(gatewayId)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + String module = applicationInterfaceRepository.addApplicationModule(applicationModule, gatewayId); + logger.debug("Airavata registered application module for gateway id : " + gatewayId); + return module; + } + + public boolean updateApplicationModule(String appModuleId, ApplicationModule applicationModule) throws AppCatalogException { + applicationInterfaceRepository.updateApplicationModule(appModuleId, applicationModule); + logger.debug("Airavata updated application module with module id: " + appModuleId); + return true; + } + + public String registerApplicationDeployment( + String gatewayId, ApplicationDeploymentDescription applicationDeployment) throws AppCatalogException { + try { + if (!isGatewayExistInternal(gatewayId)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + String deployment = applicationDeploymentRepository.addApplicationDeployment(applicationDeployment, gatewayId); + logger.debug("Airavata registered application deployment for gateway id : " + gatewayId); + return deployment; + } + + public boolean updateApplicationDeployment( + String appDeploymentId, ApplicationDeploymentDescription applicationDeployment) throws AppCatalogException { + applicationDeploymentRepository.updateApplicationDeployment(appDeploymentId, applicationDeployment); + logger.debug("Airavata updated application deployment for deployment id : " + appDeploymentId); + return true; + } + + // User Resource Profile operations + public String registerUserResourceProfile(UserResourceProfile userResourceProfile) throws AppCatalogException { + if (!validateString(userResourceProfile.getUserId())) { + logger.error("Cannot create user resource profile with empty user id"); + throw new AppCatalogException("Cannot create user resource profile with empty user id"); + } + if (!validateString(userResourceProfile.getGatewayID())) { + logger.error("Cannot create user resource profile with empty gateway id"); + throw new AppCatalogException("Cannot create user resource profile with empty gateway id"); + } + try { + if (!userRepository.isUserExists(userResourceProfile.getGatewayID(), userResourceProfile.getUserId())) { + logger.error("User does not exist.Please provide a valid user ID..."); + throw new AppCatalogException("User does not exist.Please provide a valid user ID..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + String resourceProfile = userResourceProfileRepository.addUserResourceProfile(userResourceProfile); + logger.debug("Airavata registered user resource profile with gateway id : " + + userResourceProfile.getGatewayID() + "and user id : " + userResourceProfile.getUserId()); + return resourceProfile; + } + + public boolean isUserResourceProfileExists(String userId, String gatewayId) throws AppCatalogException { + try { + if (!userRepository.isUserExists(gatewayId, userId)) { + logger.error("user does not exist.Please provide a valid gateway id..."); + throw new AppCatalogException("user does not exist.Please provide a valid gateway id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + return userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayId); + } + + public UserResourceProfile getUserResourceProfile(String userId, String gatewayId) throws AppCatalogException { + try { + if (!userRepository.isUserExists(gatewayId, userId)) { + logger.error("user does not exist.Please provide a valid gateway id..."); + throw new AppCatalogException("user does not exist.Please provide a valid gateway id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + UserResourceProfile userResourceProfile = userResourceProfileRepository.getUserResourceProfile(userId, gatewayId); + logger.debug("Airavata retrieved User resource profile with user id : " + userId); + return userResourceProfile; + } + + public boolean updateUserResourceProfile(String userId, String gatewayID, UserResourceProfile userResourceProfile) throws AppCatalogException { + try { + if (!userRepository.isUserExists(gatewayID, userId)) { + logger.error("User does not exist.Please provide a valid user id..."); + throw new AppCatalogException("user does not exist.Please provide a valid user id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + userResourceProfileRepository.updateUserResourceProfile(userId, gatewayID, userResourceProfile); + logger.debug("Airavata updated gateway profile with gateway id : " + userId); + return true; + } + + public boolean deleteUserResourceProfile(String userId, String gatewayID) throws AppCatalogException { + try { + if (!userRepository.isUserExists(gatewayID, userId)) { + logger.error("user does not exist.Please provide a valid user id..."); + throw new AppCatalogException("user does not exist.Please provide a valid user id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + userResourceProfileRepository.removeUserResourceProfile(userId, gatewayID); + logger.debug("Airavata deleted User profile with gateway id : " + gatewayID + " and user id : " + userId); + return true; + } + + // Resource Scheduling operations + public void updateResourceScheduleing( + String airavataExperimentId, ComputationalResourceSchedulingModel resourceScheduling) throws RegistryException { + if (!experimentRepository.isExperimentExist(airavataExperimentId)) { + logger.debug( + airavataExperimentId, + "Update resource scheduling failed, experiment {} doesn't exist.", + airavataExperimentId); + throw new RegistryException( + "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); + } + ExperimentStatus experimentStatus = getExperimentStatusInternal(airavataExperimentId); + if (experimentStatus != null) { + ExperimentState experimentState = experimentStatus.getState(); + switch (experimentState) { + case CREATED: + case VALIDATED: + case CANCELED: + case FAILED: + processRepository.addProcessResourceSchedule(resourceScheduling, airavataExperimentId); + logger.debug( + airavataExperimentId, + "Successfully updated resource scheduling for the experiment {}.", + airavataExperimentId); + break; + default: + logger.error( + airavataExperimentId, + "Error while updating scheduling info. Update experiment is only valid for experiments " + + "with status CREATED, VALIDATED, CANCELLED, FAILED and UNKNOWN. Make sure the given " + + "experiment is in one of above statuses... "); + throw new RegistryException( + "Error while updating experiment. Update experiment is only valid for experiments " + + "with status CREATED, VALIDATED, CANCELLED, FAILED and UNKNOWN. Make sure the given " + + "experiment is in one of above statuses... "); + } + } + } + + // User operations + public String addUser(UserProfile userProfile) throws RegistryException { + logger.info("Adding User in Registry: " + userProfile); + if (userRepository.isUserExists(userProfile.getGatewayId(), userProfile.getUserId())) { + throw new RegistryException("User already exists, with userId: " + userProfile.getUserId() + + ", and gatewayId: " + userProfile.getGatewayId()); + } + UserProfile savedUser = userRepository.addUser(userProfile); + return savedUser.getUserId(); + } + + // User Compute/Storage Preference operations + public boolean addUserComputeResourcePreference( + String userId, + String gatewayID, + String computeResourceId, + UserComputeResourcePreference userComputeResourcePreference) throws AppCatalogException { + try { + if (!userRepository.isUserExists(gatewayID, userId)) { + logger.error("user does not exist.Please provide a valid user id..."); + throw new AppCatalogException("user does not exist.Please provide a valid user id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + if (!userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayID)) { + throw new AppCatalogException("User resource profile with user id'" + userId + " & gateway Id" + + gatewayID + "' does not exist!!!"); + } + UserResourceProfile profile = userResourceProfileRepository.getUserResourceProfile(userId, gatewayID); + profile.addToUserComputeResourcePreferences(userComputeResourcePreference); + userResourceProfileRepository.updateUserResourceProfile(userId, gatewayID, profile); + logger.debug("Airavata added User compute resource preference with gateway id : " + gatewayID + + " and for compute resource id : " + computeResourceId); + return true; + } + + public boolean isUserComputeResourcePreferenceExists(String userId, String gatewayID, String computeResourceId) throws AppCatalogException { + try { + if (userRepository.isUserExists(gatewayID, userId) + && userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayID)) { + return userResourceProfileRepository.isUserComputeResourcePreferenceExists( + userId, gatewayID, computeResourceId); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + return false; + } + + public UserComputeResourcePreference getUserComputeResourcePreference( + String userId, String gatewayID, String userComputeResourceId) throws AppCatalogException { + try { + if (!userRepository.isUserExists(gatewayID, userId)) { + logger.error("user does not exist.Please provide a valid user id..."); + throw new AppCatalogException("user does not exist.Please provide a valid user id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + if (!userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayID)) { + throw new AppCatalogException("User resource profile with user id'" + userId + " & gateway Id" + + gatewayID + "' does not exist!!!"); + } + ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); + if (!computeResourceRepository.isComputeResourceExists(userComputeResourceId)) { + logger.error( + userComputeResourceId, + "Given compute resource does not exist in the system. Please provide a valid compute resource id..."); + throw new AppCatalogException( + "Given compute resource does not exist in the system. Please provide a valid compute resource id..."); + } + UserComputeResourcePreference userComputeResourcePreference = + userResourceProfileRepository.getUserComputeResourcePreference( + userId, gatewayID, userComputeResourceId); + logger.debug("Airavata retrieved user compute resource preference with gateway id : " + gatewayID + + " and for compute resoruce id : " + userComputeResourceId); + return userComputeResourcePreference; + } + + public boolean updateUserComputeResourcePreference( + String userId, + String gatewayID, + String computeResourceId, + UserComputeResourcePreference userComputeResourcePreference) throws AppCatalogException { + try { + if (!userRepository.isUserExists(gatewayID, userId)) { + logger.error("user does not exist.Please provide a valid user id..."); + throw new AppCatalogException("user does not exist.Please provide a valid user id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + UserResourceProfile profile = userResourceProfileRepository.getUserResourceProfile(userId, gatewayID); + List userComputeResourcePreferences = + profile.getUserComputeResourcePreferences(); + UserComputeResourcePreference preferenceToRemove = null; + for (UserComputeResourcePreference preference : userComputeResourcePreferences) { + if (preference.getComputeResourceId().equals(computeResourceId)) { + preferenceToRemove = preference; + break; + } + } + if (preferenceToRemove != null) { + profile.getUserComputeResourcePreferences().remove(preferenceToRemove); + } + profile.getUserComputeResourcePreferences().add(userComputeResourcePreference); + userResourceProfileRepository.updateUserResourceProfile(userId, gatewayID, profile); + logger.debug("Airavata updated compute resource preference with gateway id : " + gatewayID + + " and for compute resource id : " + computeResourceId); + return true; + } + + public boolean addUserStoragePreference( + String userId, String gatewayID, String storageResourceId, UserStoragePreference dataStoragePreference) throws AppCatalogException { + try { + if (!userRepository.isUserExists(gatewayID, userId)) { + logger.error("user does not exist.Please provide a valid user id..."); + throw new AppCatalogException("user does not exist.Please provide a valid user id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + if (!userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayID)) { + throw new AppCatalogException("User resource profile with user id'" + userId + " & gateway Id" + + gatewayID + "' does not exist!!!"); + } + UserResourceProfile profile = userResourceProfileRepository.getUserResourceProfile(userId, gatewayID); + dataStoragePreference.setStorageResourceId(storageResourceId); + profile.addToUserStoragePreferences(dataStoragePreference); + userResourceProfileRepository.updateUserResourceProfile(userId, gatewayID, profile); + logger.debug("Airavata added storage resource preference with gateway id : " + gatewayID + + " and for storage resource id : " + storageResourceId); + return true; + } + + public UserStoragePreference getUserStoragePreference(String userId, String gatewayID, String storageId) throws AppCatalogException { + try { + if (!userRepository.isUserExists(gatewayID, userId)) { + logger.error("user does not exist.Please provide a valid user id..."); + throw new AppCatalogException("user does not exist.Please provide a valid user id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + if (!userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayID)) { + throw new AppCatalogException("User resource profile with user id'" + userId + " & gateway Id" + + gatewayID + "' does not exist!!!"); + } + + UserStoragePreference storagePreference = + userResourceProfileRepository.getUserStoragePreference(userId, gatewayID, storageId); + logger.debug("Airavata retrieved user storage resource preference with gateway id : " + gatewayID + + " and for storage resource id : " + storageId); + return storagePreference; + } + + public List getAllUserResourceProfiles() throws AppCatalogException { + return userResourceProfileRepository.getAllUserResourceProfiles(); + } + + // Gateway Groups operations + public GatewayGroups getGatewayGroups(String gatewayId) throws RegistryException { + if (!gatewayGroupsRepository.isExists(gatewayId)) { + final String message = "No GatewayGroups entry exists for " + gatewayId; + logger.error(message); + throw new RegistryException(message); + } + return gatewayGroupsRepository.get(gatewayId); + } + + // Parser operations + public Parser getParser(String parserId, String gatewayId) throws RegistryException { + if (!parserRepository.isExists(parserId)) { + final String message = "No Parser Info entry exists for " + parserId; + logger.error(message); + throw new RegistryException(message); + } + return parserRepository.get(parserId); + } + + public String saveParser(Parser parser) throws RegistryException { + try { + Parser saved = parserRepository.saveParser(parser); + return saved.getId(); + } catch (AppCatalogException e) { + throw new RegistryException("Error saving parser: " + e.getMessage(), e); + } + } + + public void removeParser(String parserId, String gatewayId) throws RegistryException { + boolean exists = parserRepository.isExists(parserId); + if (exists && !gatewayId.equals(parserRepository.get(parserId).getGatewayId())) { + parserRepository.delete(parserId); + } else { + throw new RegistryException("Parser " + parserId + " does not exist"); + } + } + + public ParserInput getParserInput(String parserInputId, String gatewayId) throws RegistryException { + if (!parserInputRepository.isExists(parserInputId)) { + final String message = "No ParserInput entry exists for " + parserInputId; + logger.error(message); + throw new RegistryException(message); + } + return parserInputRepository.get(parserInputId); + } + + public String saveParserInput(ParserInput parserInput) throws RegistryException { + ParserInput saved = parserInputRepository.create(parserInput); + return saved.getId(); + } + + public void removeParserInput(String parserInputId, String gatewayId) throws RegistryException { + boolean exists = parserInputRepository.isExists(parserInputId); + if (exists) { + ParserInput parserInput = parserInputRepository.get(parserInputId); + Parser parser = parserRepository.get(parserInput.getParserId()); + if (gatewayId.equals(parser.getGatewayId())) { + parserInputRepository.delete(parserInputId); + } else { + throw new RegistryException("ParserInput " + parserInputId + " does not belong to gateway " + gatewayId); + } + } else { + throw new RegistryException("ParserInput " + parserInputId + " does not exist"); + } + } + + public ParserOutput getParserOutput(String parserOutputId, String gatewayId) throws RegistryException { + if (!parserOutputRepository.isExists(parserOutputId)) { + final String message = "No ParserOutput entry exists for " + parserOutputId; + logger.error(message); + throw new RegistryException(message); + } + return parserOutputRepository.get(parserOutputId); + } + + public String saveParserOutput(ParserOutput parserOutput) throws RegistryException { + ParserOutput saved = parserOutputRepository.create(parserOutput); + return saved.getId(); + } + + public void removeParserOutput(String parserOutputId, String gatewayId) throws RegistryException { + boolean exists = parserOutputRepository.isExists(parserOutputId); + if (exists) { + ParserOutput parserOutput = parserOutputRepository.get(parserOutputId); + Parser parser = parserRepository.get(parserOutput.getParserId()); + if (gatewayId.equals(parser.getGatewayId())) { + parserOutputRepository.delete(parserOutputId); + } else { + throw new RegistryException("ParserOutput " + parserOutputId + " does not belong to gateway " + gatewayId); + } + } else { + throw new RegistryException("ParserOutput " + parserOutputId + " does not exist"); + } + } + + public ParsingTemplate getParsingTemplate(String templateId, String gatewayId) throws RegistryException { + if (!parsingTemplateRepository.isExists(templateId)) { + final String message = "No ParsingTemplate entry exists for " + templateId; + logger.error(message); + throw new RegistryException(message); + } + return parsingTemplateRepository.get(templateId); + } + + public String saveParsingTemplate(ParsingTemplate parsingTemplate) throws RegistryException { + ParsingTemplate saved = parsingTemplateRepository.create(parsingTemplate); + return saved.getId(); + } + + public void removeParsingTemplate(String templateId, String gatewayId) throws RegistryException { + boolean exists = parsingTemplateRepository.isExists(templateId); + if (exists && !gatewayId.equals(parsingTemplateRepository.get(templateId).getGatewayId())) { + parsingTemplateRepository.delete(templateId); + } else { + throw new RegistryException("Parsing template " + templateId + " does not exist"); + } + } + + // Gateway Usage Reporting operations + public boolean isGatewayUsageReportingAvailable(String gatewayId, String computeResourceId) throws RegistryException { + return usageReportingCommandRepository.isGatewayUsageReportingCommandExists(gatewayId, computeResourceId); + } + + public GatewayUsageReportingCommand getGatewayReportingCommand(String gatewayId, String computeResourceId) throws RegistryException { + if (usageReportingCommandRepository.isGatewayUsageReportingCommandExists(gatewayId, computeResourceId)) { + return usageReportingCommandRepository.getGatewayUsageReportingCommand(gatewayId, computeResourceId); + } else { + String message = "No usage reporting information for the gateway " + gatewayId + + " and compute resource " + computeResourceId; + logger.error(message); + throw new RegistryException(message); + } + } + + public void addGatewayUsageReportingCommand(GatewayUsageReportingCommand command) throws RegistryException { + usageReportingCommandRepository.addGatewayUsageReportingCommand(command); + } + + public void removeGatewayUsageReportingCommand(String gatewayId, String computeResourceId) throws RegistryException { + usageReportingCommandRepository.removeGatewayUsageReportingCommand(gatewayId, computeResourceId); + } + + public boolean updateCloudJobSubmissionDetails(String jobSubmissionInterfaceId, CloudJobSubmission cloudJobSubmission) throws AppCatalogException { + cloudJobSubmission.setJobSubmissionInterfaceId(jobSubmissionInterfaceId); + computeResourceRepository.updateCloudJobSubmission(cloudJobSubmission); + logger.debug("Airavata updated Cloud job submission for job submission interface id: " + jobSubmissionInterfaceId); + return true; + } + + public boolean updateSSHJobSubmissionDetails(String jobSubmissionInterfaceId, SSHJobSubmission sshJobSubmission) throws AppCatalogException { + sshJobSubmission.setJobSubmissionInterfaceId(jobSubmissionInterfaceId); + computeResourceRepository.updateSSHJobSubmission(sshJobSubmission); + logger.debug("Airavata updated SSH job submission for job submission interface id: " + jobSubmissionInterfaceId); + return true; + } + + public boolean updateUnicoreJobSubmissionDetails(String jobSubmissionInterfaceId, UnicoreJobSubmission unicoreJobSubmission) throws AppCatalogException { + unicoreJobSubmission.setJobSubmissionInterfaceId(jobSubmissionInterfaceId); + computeResourceRepository.updateUNICOREJobSubmission(unicoreJobSubmission); + logger.debug("Airavata updated UNICORE job submission for job submission interface id: " + jobSubmissionInterfaceId); + return true; + } + + public boolean updateNotification(Notification notification) throws RegistryException { + notificationRepository.updateNotification(notification); + logger.debug("Airavata updated notification with notification id: " + notification.getNotificationId()); + return true; + } + + public String createNotification(Notification notification) throws RegistryException { + String notificationId = notificationRepository.createNotification(notification); + logger.debug("Airavata created notification with notification id: " + notificationId); + return notificationId; + } + + public boolean updateGateway(String gatewayId, Gateway updatedGateway) throws RegistryException, AppCatalogException { + if (!gatewayRepository.isGatewayExist(gatewayId)) { + logger.error("Gateway does not exist in the system. Please provide a valid gateway ID..."); + throw new RegistryException("Gateway does not exist in the system. Please provide a valid gateway ID..."); + } + updatedGateway.setGatewayId(gatewayId); + gatewayRepository.updateGateway(gatewayId, updatedGateway); + logger.debug("Airavata updated gateway with gateway id: " + gatewayId); + return true; + } + + public String addGateway(Gateway gateway) throws RegistryException, AppCatalogException { + if (gatewayRepository.isGatewayExist(gateway.getGatewayId())) { + logger.error("Gateway already exists in the system. Please provide a different gateway ID..."); + throw new AppCatalogException("Gateway already exists in the system. Please provide a different gateway ID..."); + } + String gatewayId = gatewayRepository.addGateway(gateway); + logger.debug("Airavata registered gateway with gateway id: " + gatewayId); + return gatewayId; + } + + public boolean updateUserStoragePreference( + String userId, String gatewayID, String storageId, UserStoragePreference userStoragePreference) throws AppCatalogException { + try { + if (!userRepository.isUserExists(gatewayID, userId)) { + logger.error("user does not exist.Please provide a valid user id..."); + throw new AppCatalogException("user does not exist.Please provide a valid user id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + if (!userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayID)) { + throw new AppCatalogException("User resource profile with user id'" + userId + " & gateway Id" + + gatewayID + "' does not exist!!!"); + } + UserResourceProfile profile = userResourceProfileRepository.getUserResourceProfile(userId, gatewayID); + List userStoragePreferences = profile.getUserStoragePreferences(); + UserStoragePreference preferenceToRemove = null; + for (UserStoragePreference preference : userStoragePreferences) { + if (preference.getStorageResourceId().equals(storageId)) { + preferenceToRemove = preference; + break; + } + } + if (preferenceToRemove != null) { + profile.getUserStoragePreferences().remove(preferenceToRemove); + } + userStoragePreference.setStorageResourceId(storageId); + profile.getUserStoragePreferences().add(userStoragePreference); + userResourceProfileRepository.updateUserResourceProfile(userId, gatewayID, profile); + logger.debug("Airavata updated storage resource preference with gateway id : " + gatewayID + + " and for storage resource id : " + storageId); + return true; + } + + public boolean deleteUserComputeResourcePreference(String userId, String gatewayID, String computeResourceId) throws AppCatalogException { + try { + if (!userRepository.isUserExists(gatewayID, userId)) { + logger.error("user does not exist.Please provide a valid user id..."); + throw new AppCatalogException("user does not exist.Please provide a valid user id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + return userResourceProfileRepository.removeUserComputeResourcePreferenceFromGateway(userId, gatewayID, computeResourceId); + } + + public boolean deleteUserStoragePreference(String userId, String gatewayID, String storageId) throws AppCatalogException { + try { + if (!userRepository.isUserExists(gatewayID, userId)) { + logger.error("user does not exist.Please provide a valid user id..."); + throw new AppCatalogException("user does not exist.Please provide a valid user id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + return userResourceProfileRepository.removeUserDataStoragePreferenceFromGateway(userId, gatewayID, storageId); + } + + public List getLatestQueueStatuses() throws RegistryException { + return queueStatusRepository.getLatestQueueStatuses(); + } + + public void registerQueueStatuses(List queueStatuses) throws RegistryException { + queueStatusRepository.createQueueStatuses(queueStatuses); + } + + public QueueStatusModel getQueueStatus(String hostName, String queueName) throws RegistryException { + Optional optionalQueueStatusModel = queueStatusRepository.getQueueStatus(hostName, queueName); + if (optionalQueueStatusModel.isPresent()) { + return optionalQueueStatusModel.get(); + } else { + QueueStatusModel queueStatusModel = new QueueStatusModel(); + queueStatusModel.setHostName(hostName); + queueStatusModel.setQueueName(queueName); + queueStatusModel.setQueueUp(false); + queueStatusModel.setRunningJobs(0); + queueStatusModel.setQueuedJobs(0); + queueStatusModel.setTime(0); + return queueStatusModel; + } + } + + public void createGatewayGroups(GatewayGroups gatewayGroups) throws RegistryException { + if (gatewayGroupsRepository.isExists(gatewayGroups.getGatewayId())) { + logger.error("GatewayGroups already exists for " + gatewayGroups.getGatewayId()); + throw new RegistryException("GatewayGroups for gatewayId: " + gatewayGroups.getGatewayId() + " already exists."); + } + gatewayGroupsRepository.create(gatewayGroups); + } + + public void updateGatewayGroups(GatewayGroups gatewayGroups) throws RegistryException { + if (!gatewayGroupsRepository.isExists(gatewayGroups.getGatewayId())) { + final String message = "No GatewayGroups entry exists for " + gatewayGroups.getGatewayId(); + logger.error(message); + throw new RegistryException(message); + } + gatewayGroupsRepository.update(gatewayGroups); + } + + public boolean isGatewayGroupsExists(String gatewayId) throws RegistryException { + return gatewayGroupsRepository.isExists(gatewayId); + } + + public List listAllParsers(String gatewayId) throws RegistryException { + return parserRepository.getAllParsers(gatewayId); + } + + public List getParsingTemplatesForApplication(String applicationInterfaceId) throws RegistryException { + return parsingTemplateRepository.getParsingTemplatesForApplication(applicationInterfaceId); + } + + public List getParsingTemplatesForExperiment(String experimentId, String gatewayId) throws RegistryException { + ExperimentModel experiment = experimentRepository.getExperiment(experimentId); + List processes = experiment.getProcesses(); + if (processes != null && processes.size() > 0) { + return parsingTemplateRepository.getParsingTemplatesForApplication( + processes.get(processes.size() - 1).getApplicationInterfaceId()); + } + return Collections.emptyList(); + } + + public List listAllParsingTemplates(String gatewayId) throws RegistryException { + return parsingTemplateRepository.getAllParsingTemplates(gatewayId); + } + + public List getAllUserComputeResourcePreferences(String userId, String gatewayID) throws AppCatalogException { + try { + if (!userRepository.isUserExists(gatewayID, userId)) { + logger.error("User Resource Profile does not exist.Please provide a valid gateway id..."); + throw new AppCatalogException("User Resource Profile does not exist.Please provide a valid gateway id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + return userResourceProfileRepository.getUserResourceProfile(userId, gatewayID).getUserComputeResourcePreferences(); + } + + public List getAllUserStoragePreferences(String userId, String gatewayID) throws AppCatalogException { + try { + if (!userRepository.isUserExists(gatewayID, userId)) { + logger.error("User does not exist.Please provide a valid gateway id..."); + throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); + } + } catch (RegistryException e) { + throw new AppCatalogException(e.getMessage(), e); + } + return userResourceProfileRepository.getUserResourceProfile(userId, gatewayID).getUserStoragePreferences(); + } +} + From dc9121667d8ca9ec5d6e7c4dcb72fd4205d93637 Mon Sep 17 00:00:00 2001 From: yasithdev Date: Mon, 10 Nov 2025 18:40:09 -0500 Subject: [PATCH 02/26] update AiravataServerHandler --- .../server/handler/AiravataServerHandler.java | 2772 +++++++---------- .../airavata/service/AiravataService.java | 1990 ++++++++++++ 2 files changed, 3088 insertions(+), 1674 deletions(-) create mode 100644 airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java diff --git a/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java index 4da1eb7494..ff0ee33b2c 100644 --- a/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java @@ -20,7 +20,6 @@ package org.apache.airavata.api.server.handler; import java.util.*; -import java.util.function.BiFunction; import java.util.stream.Collectors; import org.apache.airavata.accountprovisioning.ConfigParam; import org.apache.airavata.accountprovisioning.SSHAccountManager; @@ -78,27 +77,16 @@ import org.apache.airavata.model.group.ResourcePermissionType; import org.apache.airavata.model.group.ResourceType; import org.apache.airavata.model.job.JobModel; -import org.apache.airavata.model.messaging.event.ExperimentIntermediateOutputsEvent; -import org.apache.airavata.model.messaging.event.ExperimentStatusChangeEvent; -import org.apache.airavata.model.messaging.event.ExperimentSubmitEvent; -import org.apache.airavata.model.messaging.event.MessageType; -import org.apache.airavata.model.process.ProcessModel; import org.apache.airavata.model.scheduling.ComputationalResourceSchedulingModel; import org.apache.airavata.model.security.AuthzToken; -import org.apache.airavata.model.status.ExperimentState; import org.apache.airavata.model.status.ExperimentStatus; -import org.apache.airavata.model.status.JobState; import org.apache.airavata.model.status.JobStatus; -import org.apache.airavata.model.status.ProcessState; import org.apache.airavata.model.status.ProcessStatus; import org.apache.airavata.model.status.QueueStatusModel; -import org.apache.airavata.model.task.TaskTypes; import org.apache.airavata.model.workspace.Gateway; import org.apache.airavata.model.workspace.Notification; import org.apache.airavata.model.workspace.Project; import org.apache.airavata.registry.api.RegistryService; -import org.apache.airavata.registry.api.exception.RegistryServiceException; -import org.apache.airavata.service.security.GatewayGroupsInitializer; import org.apache.airavata.service.security.interceptor.SecurityCheck; import org.apache.airavata.sharing.registry.models.*; import org.apache.airavata.sharing.registry.service.cpi.SharingRegistryService; @@ -116,6 +104,7 @@ public class AiravataServerHandler implements Airavata.Iface { private ThriftClientPool sharingClientPool; private ThriftClientPool registryClientPool; private ThriftClientPool csClientPool; + private org.apache.airavata.service.AiravataService airavataService = new org.apache.airavata.service.AiravataService(); public AiravataServerHandler() { try { @@ -333,18 +322,15 @@ public String getAPIVersion() throws TException { public boolean isUserExists(AuthzToken authzToken, String gatewayId, String userName) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client client = registryClientPool.getResource(); try { - boolean isExists = client.isUserExists(gatewayId, userName); + boolean isExists = airavataService.isUserExists(gatewayId, userName); logger.debug("Checking if the user" + userName + "exists in the gateway" + gatewayId); - registryClientPool.returnResource(client); return isExists; } catch (Exception e) { logger.error("Error while verifying user", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while verifying user. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(client); throw exception; } } @@ -357,75 +343,9 @@ public String addGateway(AuthzToken authzToken, Gateway gateway) SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); RegistryService.Client registryClient = registryClientPool.getResource(); try { - String gatewayId = registryClient.addGateway(gateway); - Domain domain = new Domain(); - domain.setDomainId(gateway.getGatewayId()); - domain.setName(gateway.getGatewayName()); - domain.setDescription("Domain entry for " + domain.getName()); - sharingClient.createDomain(domain); - - // Creating Entity Types for each domain - EntityType entityType = new EntityType(); - entityType.setEntityTypeId(domain.getDomainId() + ":PROJECT"); - entityType.setDomainId(domain.getDomainId()); - entityType.setName("PROJECT"); - entityType.setDescription("Project entity type"); - sharingClient.createEntityType(entityType); - - entityType = new EntityType(); - entityType.setEntityTypeId(domain.getDomainId() + ":EXPERIMENT"); - entityType.setDomainId(domain.getDomainId()); - entityType.setName("EXPERIMENT"); - entityType.setDescription("Experiment entity type"); - sharingClient.createEntityType(entityType); - - entityType = new EntityType(); - entityType.setEntityTypeId(domain.getDomainId() + ":FILE"); - entityType.setDomainId(domain.getDomainId()); - entityType.setName("FILE"); - entityType.setDescription("File entity type"); - sharingClient.createEntityType(entityType); - - entityType = new EntityType(); - entityType.setEntityTypeId(domain.getDomainId() + ":" + ResourceType.APPLICATION_DEPLOYMENT.name()); - entityType.setDomainId(domain.getDomainId()); - entityType.setName("APPLICATION-DEPLOYMENT"); - entityType.setDescription("Application Deployment entity type"); - sharingClient.createEntityType(entityType); - - entityType = new EntityType(); - entityType.setEntityTypeId(domain.getDomainId() + ":" + ResourceType.GROUP_RESOURCE_PROFILE.name()); - entityType.setDomainId(domain.getDomainId()); - entityType.setName(ResourceType.GROUP_RESOURCE_PROFILE.name()); - entityType.setDescription("Group Resource Profile entity type"); - sharingClient.createEntityType(entityType); - - // Creating Permission Types for each domain - PermissionType permissionType = new PermissionType(); - permissionType.setPermissionTypeId(domain.getDomainId() + ":READ"); - permissionType.setDomainId(domain.getDomainId()); - permissionType.setName("READ"); - permissionType.setDescription("Read permission type"); - sharingClient.createPermissionType(permissionType); - - permissionType = new PermissionType(); - permissionType.setPermissionTypeId(domain.getDomainId() + ":WRITE"); - permissionType.setDomainId(domain.getDomainId()); - permissionType.setName("WRITE"); - permissionType.setDescription("Write permission type"); - sharingClient.createPermissionType(permissionType); - - permissionType = new PermissionType(); - permissionType.setPermissionTypeId(domain.getDomainId() + ":MANAGE_SHARING"); - permissionType.setDomainId(domain.getDomainId()); - permissionType.setName("MANAGE_SHARING"); - permissionType.setDescription("Sharing permission type"); - sharingClient.createPermissionType(permissionType); - + String gatewayId = airavataService.addGatewayWithSharing(registryClient, sharingClient, gateway); registryClientPool.returnResource(registryClient); sharingClientPool.returnResource(sharingClient); - logger.debug("Airavata successfully created the gateway with " + gatewayId); - return gatewayId; } catch (Exception e) { logger.error("Error while adding gateway", e); @@ -451,17 +371,13 @@ public String addGateway(AuthzToken authzToken, Gateway gateway) public List getAllUsersInGateway(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - List result = regClient.getAllUsersInGateway(gatewayId); - registryClientPool.returnResource(regClient); - return result; + return airavataService.getAllUsersInGateway(gatewayId); } catch (Exception e) { logger.error("Error while retrieving users", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while retrieving users. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -471,18 +387,13 @@ public List getAllUsersInGateway(AuthzToken authzToken, String gatewayId public boolean updateGateway(AuthzToken authzToken, String gatewayId, Gateway updatedGateway) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.updateGateway(gatewayId, updatedGateway); - registryClientPool.returnResource(regClient); - return result; + return airavataService.updateGateway(gatewayId, updatedGateway); } catch (Exception e) { logger.error("Error while updating the gateway", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while updating the gateway. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -492,11 +403,8 @@ public boolean updateGateway(AuthzToken authzToken, String gatewayId, Gateway up public Gateway getGateway(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - - RegistryService.Client regClient = registryClientPool.getResource(); try { - Gateway result = regClient.getGateway(gatewayId); - registryClientPool.returnResource(regClient); + Gateway result = airavataService.getGateway(gatewayId); logger.debug("Airavata found the gateway with " + gatewayId); return result; } catch (Exception e) { @@ -504,7 +412,6 @@ public Gateway getGateway(AuthzToken authzToken, String gatewayId) AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while getting the gateway. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -514,17 +421,13 @@ public Gateway getGateway(AuthzToken authzToken, String gatewayId) public boolean deleteGateway(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.deleteGateway(gatewayId); - registryClientPool.returnResource(regClient); - return result; + return airavataService.deleteGateway(gatewayId); } catch (Exception e) { logger.error("Error while deleting the gateway", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while deleting the gateway. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -534,18 +437,14 @@ public boolean deleteGateway(AuthzToken authzToken, String gatewayId) public List getAllGateways(AuthzToken authzToken) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { logger.debug("Airavata searching for all gateways"); - List result = regClient.getAllGateways(); - registryClientPool.returnResource(regClient); - return result; + return airavataService.getAllGateways(); } catch (Exception e) { logger.error("Error while getting all the gateways", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while getting all the gateways. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -555,18 +454,14 @@ public List getAllGateways(AuthzToken authzToken) public boolean isGatewayExist(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { logger.debug("Airavata verifying if the gateway with " + gatewayId + "exits"); - boolean result = regClient.isGatewayExist(gatewayId); - registryClientPool.returnResource(regClient); - return result; + return airavataService.isGatewayExist(gatewayId); } catch (Exception e) { logger.error("Error while getting gateway", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while getting gateway. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -583,17 +478,13 @@ public boolean isGatewayExist(AuthzToken authzToken, String gatewayId) public String createNotification(AuthzToken authzToken, Notification notification) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - String result = regClient.createNotification(notification); - registryClientPool.returnResource(regClient); - return result; + return airavataService.createNotification(notification); } catch (Exception e) { logger.error("Error while creating notification", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while creating notification. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -603,17 +494,13 @@ public String createNotification(AuthzToken authzToken, Notification notificatio public boolean updateNotification(AuthzToken authzToken, Notification notification) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.updateNotification(notification); - registryClientPool.returnResource(regClient); - return result; + return airavataService.updateNotification(notification); } catch (Exception e) { logger.error("Error while updating notification", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while getting gateway. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); + exception.setMessage("Error while updating notification. More info : " + e.getMessage()); throw exception; } } @@ -623,17 +510,13 @@ public boolean updateNotification(AuthzToken authzToken, Notification notificati public boolean deleteNotification(AuthzToken authzToken, String gatewayId, String notificationId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.deleteNotification(gatewayId, notificationId); - registryClientPool.returnResource(regClient); - return result; + return airavataService.deleteNotification(gatewayId, notificationId); } catch (Exception e) { logger.error("Error while deleting notification", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while deleting notification. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -643,17 +526,13 @@ public boolean deleteNotification(AuthzToken authzToken, String gatewayId, Strin public Notification getNotification(AuthzToken authzToken, String gatewayId, String notificationId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - Notification result = regClient.getNotification(gatewayId, notificationId); - registryClientPool.returnResource(regClient); - return result; + return airavataService.getNotification(gatewayId, notificationId); } catch (Exception e) { logger.error("Error while retrieving notification", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while retreiving notification. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -663,17 +542,13 @@ public Notification getNotification(AuthzToken authzToken, String gatewayId, Str public List getAllNotifications(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - List result = regClient.getAllNotifications(gatewayId); - registryClientPool.returnResource(regClient); - return result; + return airavataService.getAllNotifications(gatewayId); } catch (Exception e) { logger.error("Error while getting all notifications", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while getting all notifications. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -688,30 +563,7 @@ public String generateAndRegisterSSHKeys(AuthzToken authzToken, String descripti SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); RegistryService.Client regClient = registryClientPool.getResource(); try { - SSHCredential sshCredential = new SSHCredential(); - sshCredential.setUsername(userName); - sshCredential.setGatewayId(gatewayId); - sshCredential.setDescription(description); - String key = csClient.addSSHCredential(sshCredential); - try { - Entity entity = new Entity(); - entity.setEntityId(key); - entity.setDomainId(gatewayId); - entity.setEntityTypeId(gatewayId + ":" + ResourceType.CREDENTIAL_TOKEN); - entity.setOwnerId(userName + "@" + gatewayId); - entity.setName(key); - entity.setDescription(description); - sharingClient.createEntity(entity); - } catch (Exception ex) { - logger.error(ex.getMessage(), ex); - logger.error("Rolling back ssh key creation for user " + userName + " and description [" + description - + "]"); - csClient.deleteSSHCredential(key, gatewayId); - AiravataSystemException ase = new AiravataSystemException(); - ase.setMessage("Failed to create sharing registry record"); - throw ase; - } - logger.debug("Airavata generated SSH keys for gateway : " + gatewayId + " and for user : " + userName); + String key = airavataService.generateAndRegisterSSHKeys(csClient, sharingClient, gatewayId, userName, description); csClientPool.returnResource(csClient); sharingClientPool.returnResource(sharingClient); registryClientPool.returnResource(regClient); @@ -746,45 +598,26 @@ public String registerPwdCredential( String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); CredentialStoreService.Client csClient = csClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); - RegistryService.Client regClient = registryClientPool.getResource(); try { - PasswordCredential pwdCredential = new PasswordCredential(); - pwdCredential.setPortalUserName(userName); - pwdCredential.setLoginUserName(loginUserName); - pwdCredential.setPassword(password); - pwdCredential.setDescription(description); - pwdCredential.setGatewayId(gatewayId); - String key = csClient.addPasswordCredential(pwdCredential); - try { - Entity entity = new Entity(); - entity.setEntityId(key); - entity.setDomainId(gatewayId); - entity.setEntityTypeId(gatewayId + ":" + ResourceType.CREDENTIAL_TOKEN); - entity.setOwnerId(userName + "@" + gatewayId); - entity.setName(key); - entity.setDescription(description); - sharingClient.createEntity(entity); - } catch (Exception ex) { - logger.error(ex.getMessage(), ex); - logger.error("Rolling back password registration for user " + userName + " and description [" - + description + "]"); - csClient.deletePWDCredential(key, gatewayId); - AiravataSystemException ase = new AiravataSystemException(); - ase.setMessage("Failed to create sharing registry record"); - throw ase; - } - logger.debug("Airavata generated PWD credential for gateway : " + gatewayId + " and for user : " - + loginUserName); + String key = airavataService.registerPwdCredential(csClient, sharingClient, gatewayId, userName, loginUserName, password, description); csClientPool.returnResource(csClient); sharingClientPool.returnResource(sharingClient); - registryClientPool.returnResource(regClient); return key; + } catch (org.apache.airavata.credential.store.exception.CredentialStoreException e) { + logger.error("Error occurred while registering PWD Credential", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error occurred while registering PWD Credential. More info : " + e.getMessage()); + csClientPool.returnBrokenResource(csClient); + sharingClientPool.returnBrokenResource(sharingClient); + throw exception; } catch (Exception e) { logger.error("Error occurred while registering PWD Credential", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error occurred while registering PWD Credential. More info : " + e.getMessage()); csClientPool.returnBrokenResource(csClient); + sharingClientPool.returnBrokenResource(sharingClient); throw exception; } } @@ -798,21 +631,18 @@ public CredentialSummary getCredentialSummary(AuthzToken authzToken, String toke SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); try { - if (!userHasAccessInternal(sharingClient, authzToken, tokenId, ResourcePermissionType.READ)) { - throw new AuthorizationException("User does not have permission to access this resource"); - } - CredentialSummary credentialSummary = csClient.getCredentialSummary(tokenId, gatewayId); + CredentialSummary credentialSummary = airavataService.getCredentialSummaryWithAuth(csClient, sharingClient, authzToken, tokenId, gatewayId); csClientPool.returnResource(csClient); sharingClientPool.returnResource(sharingClient); - logger.debug("Airavata retrived the credential summary for token " + tokenId + "GatewayId: " + gatewayId); return credentialSummary; - } catch (AuthorizationException ae) { - String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); - logger.info("User " + userName + " not allowed to access credential store token " + tokenId); - csClientPool.returnResource(csClient); - sharingClientPool.returnResource(sharingClient); - throw ae; } catch (Exception e) { + if (e.getMessage() != null && e.getMessage().contains("does not have permission")) { + String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); + logger.info("User " + userName + " not allowed to access credential store token " + tokenId); + csClientPool.returnResource(csClient); + sharingClientPool.returnResource(sharingClient); + throw new AuthorizationException("User does not have permission to access this resource"); + } String msg = "Error retrieving credential summary for token " + tokenId + ". GatewayId: " + gatewayId; logger.error(msg, e); AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); @@ -832,23 +662,19 @@ public List getAllCredentialSummaries(AuthzToken authzToken, String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); try { - List filters = new ArrayList<>(); - SearchCriteria searchCriteria = new SearchCriteria(); - searchCriteria.setSearchField(EntitySearchField.ENTITY_TYPE_ID); - searchCriteria.setSearchCondition(SearchCondition.EQUAL); - searchCriteria.setValue(gatewayId + ":" + ResourceType.CREDENTIAL_TOKEN.name()); - filters.add(searchCriteria); - List accessibleTokenIds = - sharingClient.searchEntities(gatewayId, userName + "@" + gatewayId, filters, 0, -1).stream() - .map(p -> p.getEntityId()) - .collect(Collectors.toList()); List credentialSummaries = - csClient.getAllCredentialSummaries(type, accessibleTokenIds, gatewayId); + airavataService.getAllCredentialSummariesWithAuth(csClient, sharingClient, authzToken, type, gatewayId, userName); csClientPool.returnResource(csClient); sharingClientPool.returnResource(sharingClient); - logger.debug( - "Airavata successfully retrived credential summaries of type " + type + " GatewayId: " + gatewayId); return credentialSummaries; + } catch (org.apache.airavata.credential.store.exception.CredentialStoreException e) { + String msg = "Error retrieving credential summaries of type " + type + ". GatewayId: " + gatewayId; + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + " More info : " + e.getMessage()); + csClientPool.returnBrokenResource(csClient); + sharingClientPool.returnBrokenResource(sharingClient); + throw exception; } catch (Exception e) { String msg = "Error retrieving credential summaries of type " + type + ". GatewayId: " + gatewayId; logger.error(msg, e); @@ -868,24 +694,19 @@ public boolean deleteSSHPubKey(AuthzToken authzToken, String airavataCredStoreTo SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); try { - if (!userHasAccessInternal( - sharingClient, authzToken, airavataCredStoreToken, ResourcePermissionType.WRITE)) { - throw new AuthorizationException("User does not have permission to delete this resource."); - } - logger.debug("Airavata deleted SSH pub key for gateway Id : " + gatewayId + " and with token id : " - + airavataCredStoreToken); - boolean result = csClient.deleteSSHCredential(airavataCredStoreToken, gatewayId); + boolean result = airavataService.deleteSSHPubKey(csClient, sharingClient, authzToken, airavataCredStoreToken, gatewayId); csClientPool.returnResource(csClient); sharingClientPool.returnResource(sharingClient); return result; - } catch (AuthorizationException ae) { - String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); - logger.info("User " + userName + " not allowed to delete (no WRITE permission) credential store token " - + airavataCredStoreToken); - csClientPool.returnResource(csClient); - sharingClientPool.returnResource(sharingClient); - throw ae; } catch (Exception e) { + if (e.getMessage() != null && e.getMessage().contains("does not have permission")) { + String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); + logger.info("User " + userName + " not allowed to delete (no WRITE permission) credential store token " + + airavataCredStoreToken); + csClientPool.returnResource(csClient); + sharingClientPool.returnResource(sharingClient); + throw new AuthorizationException("User does not have permission to delete this resource."); + } logger.error("Error occurred while deleting SSH credential", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); @@ -904,24 +725,19 @@ public boolean deletePWDCredential(AuthzToken authzToken, String airavataCredSto SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); try { - if (!userHasAccessInternal( - sharingClient, authzToken, airavataCredStoreToken, ResourcePermissionType.WRITE)) { - throw new AuthorizationException("User does not have permission to delete this resource."); - } - logger.debug("Airavata deleted PWD credential for gateway Id : " + gatewayId + " and with token id : " - + airavataCredStoreToken); - boolean result = csClient.deletePWDCredential(airavataCredStoreToken, gatewayId); + boolean result = airavataService.deletePWDCredentialWithAuth(csClient, sharingClient, authzToken, airavataCredStoreToken, gatewayId); csClientPool.returnResource(csClient); sharingClientPool.returnResource(sharingClient); return result; - } catch (AuthorizationException ae) { - String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); - logger.info("User " + userName + " not allowed to delete (no WRITE permission) credential store token " - + airavataCredStoreToken); - csClientPool.returnResource(csClient); - sharingClientPool.returnResource(sharingClient); - throw ae; } catch (Exception e) { + if (e.getMessage() != null && e.getMessage().contains("does not have permission")) { + String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); + logger.info("User " + userName + " not allowed to delete (no WRITE permission) credential store token " + + airavataCredStoreToken); + csClientPool.returnResource(csClient); + sharingClientPool.returnResource(sharingClient); + throw new AuthorizationException("User does not have permission to delete this resource."); + } logger.error("Error occurred while deleting PWD credential", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); @@ -943,40 +759,23 @@ public String createProject(AuthzToken authzToken, String gatewayId, Project pro throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { // TODO: verify that gatewayId and project.gatewayId match authzToken - RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { - String projectId = regClient.createProject(gatewayId, project); - if (ServerSettings.isEnableSharing()) { - try { - Entity entity = new Entity(); - entity.setEntityId(projectId); - final String domainId = project.getGatewayId(); - entity.setDomainId(domainId); - entity.setEntityTypeId(domainId + ":" + "PROJECT"); - entity.setOwnerId(project.getOwner() + "@" + domainId); - entity.setName(project.getName()); - entity.setDescription(project.getDescription()); - sharingClient.createEntity(entity); - } catch (Exception ex) { - logger.error(ex.getMessage(), ex); - logger.error("Rolling back project creation Proj ID : " + projectId); - regClient.deleteProject(projectId); - AiravataSystemException ase = new AiravataSystemException(); - ase.setMessage("Failed to create entry for project in Sharing Registry"); - throw ase; - } - } - logger.debug("Airavata created project with project Id : " + projectId + " for gateway Id : " + gatewayId); - registryClientPool.returnResource(regClient); + String projectId = airavataService.createProjectWithSharing(sharingClient, gatewayId, project); sharingClientPool.returnResource(sharingClient); return projectId; + } catch (org.apache.airavata.registry.cpi.RegistryException e) { + logger.error("Error while creating the project", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while creating the project. More info : " + e.getMessage()); + sharingClientPool.returnBrokenResource(sharingClient); + throw exception; } catch (Exception e) { logger.error("Error while creating the project", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while creating the project. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); sharingClientPool.returnBrokenResource(sharingClient); throw exception; } @@ -987,46 +786,24 @@ public String createProject(AuthzToken authzToken, String gatewayId, Project pro 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) { + airavataService.updateProjectWithAuth(sharingClient, authzToken, projectId, updatedProject); + sharingClientPool.returnResource(sharingClient); + } catch (Exception e) { + if (e.getMessage() != null && (e.getMessage().contains("does not have permission") || e.getMessage().contains("cannot be changed"))) { + if (e.getMessage().contains("cannot be changed")) { + sharingClientPool.returnResource(sharingClient); + throw new InvalidRequestException(e.getMessage()); + } else { + sharingClientPool.returnResource(sharingClient); 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; } @@ -1037,40 +814,19 @@ public void updateProject(AuthzToken authzToken, String projectId, Project updat 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); + boolean ret = airavataService.deleteProjectWithAuth(sharingClient, authzToken, projectId); sharingClientPool.returnResource(sharingClient); return ret; } catch (Exception e) { + if (e.getMessage() != null && e.getMessage().contains("does not have permission")) { + sharingClientPool.returnResource(sharingClient); + throw new AuthorizationException("User does not have permission to access this resource"); + } 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; } @@ -1094,45 +850,19 @@ private boolean validateString(String name) { 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); + Project project = airavataService.getProjectWithAuth(sharingClient, authzToken, projectId); + sharingClientPool.returnResource(sharingClient); + return project; + } catch (Exception e) { + if (e.getMessage() != null && e.getMessage().contains("does not have permission")) { sharingClientPool.returnResource(sharingClient); - return null; + throw new AuthorizationException("User does not have permission to access this resource"); } - } 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; } @@ -1157,50 +887,24 @@ public List getUserProjects( AuthzToken authzToken, String gatewayId, String userName, int limit, int offset) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { - if (ServerSettings.isEnableSharing()) { - // user projects + user accessible projects - List accessibleProjectIds = new ArrayList<>(); - List filters = new ArrayList<>(); - SearchCriteria searchCriteria = new SearchCriteria(); - searchCriteria.setSearchField(EntitySearchField.ENTITY_TYPE_ID); - searchCriteria.setSearchCondition(SearchCondition.EQUAL); - searchCriteria.setValue(gatewayId + ":PROJECT"); - filters.add(searchCriteria); - sharingClient - .searchEntities( - authzToken.getClaimsMap().get(Constants.GATEWAY_ID), - userName + "@" + gatewayId, - filters, - 0, - -1) - .stream() - .forEach(p -> accessibleProjectIds.add(p.getEntityId())); - List result; - if (accessibleProjectIds.isEmpty()) { - result = Collections.emptyList(); - } else { - result = regClient.searchProjects( - gatewayId, userName, accessibleProjectIds, new HashMap<>(), limit, offset); - } - registryClientPool.returnResource(regClient); - sharingClientPool.returnResource(sharingClient); - return result; - } else { - List result = regClient.getUserProjects(gatewayId, userName, limit, offset); - registryClientPool.returnResource(regClient); - sharingClientPool.returnResource(sharingClient); - return result; - } - + List result = airavataService.getUserProjectsWithSharing( + sharingClient, authzToken, gatewayId, userName, limit, offset); + sharingClientPool.returnResource(sharingClient); + return result; + } catch (org.apache.airavata.registry.cpi.RegistryException e) { + logger.error("Error while retrieving projects", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving projects. More info : " + e.getMessage()); + sharingClientPool.returnBrokenResource(sharingClient); + throw exception; } catch (Exception e) { logger.error("Error while retrieving projects", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while retrieving projects. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); sharingClientPool.returnBrokenResource(sharingClient); throw exception; } @@ -1239,7 +943,6 @@ public List searchProjects( int offset) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { List accessibleProjIds = new ArrayList<>(); @@ -1264,20 +967,25 @@ public List searchProjects( if (accessibleProjIds.isEmpty()) { result = Collections.emptyList(); } else { - result = regClient.searchProjects(gatewayId, userName, accessibleProjIds, filters, limit, offset); + result = airavataService.searchProjects(gatewayId, userName, accessibleProjIds, filters, limit, offset); } } else { - result = regClient.searchProjects(gatewayId, userName, accessibleProjIds, filters, limit, offset); + result = airavataService.searchProjects(gatewayId, userName, accessibleProjIds, filters, limit, offset); } - registryClientPool.returnResource(regClient); sharingClientPool.returnResource(sharingClient); return result; + } catch (org.apache.airavata.registry.cpi.RegistryException e) { + logger.error("Error while retrieving projects", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving projects. More info : " + e.getMessage()); + sharingClientPool.returnBrokenResource(sharingClient); + throw exception; } catch (Exception e) { logger.error("Error while retrieving projects", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while retrieving projects. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); sharingClientPool.returnBrokenResource(sharingClient); throw exception; } @@ -1309,93 +1017,10 @@ public List searchExperiments( int offset) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); - try { - List accessibleExpIds = new ArrayList<>(); - Map filtersCopy = new HashMap<>(filters); - List sharingFilters = new ArrayList<>(); - SearchCriteria searchCriteria = new SearchCriteria(); - searchCriteria.setSearchField(EntitySearchField.ENTITY_TYPE_ID); - searchCriteria.setSearchCondition(SearchCondition.EQUAL); - searchCriteria.setValue(gatewayId + ":EXPERIMENT"); - sharingFilters.add(searchCriteria); - - // Apply as much of the filters in the sharing API as possible, - // removing each filter that can be filtered via the sharing API - if (filtersCopy.containsKey(ExperimentSearchFields.FROM_DATE)) { - String fromTime = filtersCopy.remove(ExperimentSearchFields.FROM_DATE); - SearchCriteria fromCreatedTimeCriteria = new SearchCriteria(); - fromCreatedTimeCriteria.setSearchField(EntitySearchField.CREATED_TIME); - fromCreatedTimeCriteria.setSearchCondition(SearchCondition.GTE); - fromCreatedTimeCriteria.setValue(fromTime); - sharingFilters.add(fromCreatedTimeCriteria); - } - if (filtersCopy.containsKey(ExperimentSearchFields.TO_DATE)) { - String toTime = filtersCopy.remove(ExperimentSearchFields.TO_DATE); - SearchCriteria toCreatedTimeCriteria = new SearchCriteria(); - toCreatedTimeCriteria.setSearchField(EntitySearchField.CREATED_TIME); - toCreatedTimeCriteria.setSearchCondition(SearchCondition.LTE); - toCreatedTimeCriteria.setValue(toTime); - sharingFilters.add(toCreatedTimeCriteria); - } - if (filtersCopy.containsKey(ExperimentSearchFields.PROJECT_ID)) { - String projectId = filtersCopy.remove(ExperimentSearchFields.PROJECT_ID); - SearchCriteria projectParentEntityCriteria = new SearchCriteria(); - projectParentEntityCriteria.setSearchField(EntitySearchField.PARRENT_ENTITY_ID); - projectParentEntityCriteria.setSearchCondition(SearchCondition.EQUAL); - projectParentEntityCriteria.setValue(projectId); - sharingFilters.add(projectParentEntityCriteria); - } - if (filtersCopy.containsKey(ExperimentSearchFields.USER_NAME)) { - String username = filtersCopy.remove(ExperimentSearchFields.USER_NAME); - SearchCriteria usernameOwnerCriteria = new SearchCriteria(); - usernameOwnerCriteria.setSearchField(EntitySearchField.OWNER_ID); - usernameOwnerCriteria.setSearchCondition(SearchCondition.EQUAL); - usernameOwnerCriteria.setValue(username + "@" + gatewayId); - sharingFilters.add(usernameOwnerCriteria); - } - if (filtersCopy.containsKey(ExperimentSearchFields.EXPERIMENT_NAME)) { - String experimentName = filtersCopy.remove(ExperimentSearchFields.EXPERIMENT_NAME); - SearchCriteria experimentNameCriteria = new SearchCriteria(); - experimentNameCriteria.setSearchField(EntitySearchField.NAME); - experimentNameCriteria.setSearchCondition(SearchCondition.LIKE); - experimentNameCriteria.setValue(experimentName); - sharingFilters.add(experimentNameCriteria); - } - if (filtersCopy.containsKey(ExperimentSearchFields.EXPERIMENT_DESC)) { - String experimentDescription = filtersCopy.remove(ExperimentSearchFields.EXPERIMENT_DESC); - SearchCriteria experimentDescriptionCriteria = new SearchCriteria(); - experimentDescriptionCriteria.setSearchField(EntitySearchField.DESCRIPTION); - experimentDescriptionCriteria.setSearchCondition(SearchCondition.LIKE); - experimentDescriptionCriteria.setValue(experimentDescription); - sharingFilters.add(experimentDescriptionCriteria); - } - // Grab all of the matching experiments in the sharing registry - // unless all of the filtering can be done through the sharing API - int searchOffset = 0; - int searchLimit = Integer.MAX_VALUE; - boolean filteredInSharing = filtersCopy.isEmpty(); - if (filteredInSharing) { - searchOffset = offset; - searchLimit = limit; - } - sharingClient - .searchEntities( - authzToken.getClaimsMap().get(Constants.GATEWAY_ID), - userName + "@" + gatewayId, - sharingFilters, - searchOffset, - searchLimit) - .forEach(e -> accessibleExpIds.add(e.getEntityId())); - int finalOffset = offset; - // If no more filtering to be done (either empty or all done through sharing API), set the offset to 0 - if (filteredInSharing) { - finalOffset = 0; - } - List result = - regClient.searchExperiments(gatewayId, userName, accessibleExpIds, filtersCopy, limit, finalOffset); - registryClientPool.returnResource(regClient); + SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + try { + List result = airavataService.searchExperimentsWithSharing( + sharingClient, authzToken, gatewayId, userName, filters, limit, offset); sharingClientPool.returnResource(sharingClient); return result; } catch (Exception e) { @@ -1403,7 +1028,6 @@ public List searchExperiments( AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while retrieving experiments. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); sharingClientPool.returnBrokenResource(sharingClient); throw exception; } @@ -1436,8 +1060,6 @@ public ExperimentStatistics getExperimentStatistics( int offset) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); - // SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { // FIXME: re-enable experiment statistics for non-admin users // Find accessible experiments in date range @@ -1464,7 +1086,7 @@ public ExperimentStatistics getExperimentStatistics( // accessibleExpIds.add(e.getEntityId())); List accessibleExpIds = null; - ExperimentStatistics result = regClient.getExperimentStatistics( + ExperimentStatistics result = airavataService.getExperimentStatistics( gatewayId, fromTime, toTime, @@ -1474,16 +1096,12 @@ public ExperimentStatistics getExperimentStatistics( accessibleExpIds, limit, offset); - registryClientPool.returnResource(regClient); - // sharingClientPool.returnResource(sharingClient); return result; } catch (Exception e) { logger.error("Error while retrieving experiments", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while retrieving experiments. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); - // sharingClientPool.returnBrokenResource(sharingClient); throw exception; } } @@ -1504,10 +1122,9 @@ public ExperimentStatistics getExperimentStatistics( public List 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); + Project project = airavataService.getProject(projectId); String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); if (ServerSettings.isEnableSharing() @@ -1529,8 +1146,7 @@ public List getExperimentsInProject(AuthzToken authzToken, Stri throw new AuthorizationException("User does not have permission to access this resource"); } } - List result = regClient.getExperimentsInProject(gatewayId, projectId, limit, offset); - registryClientPool.returnResource(regClient); + List result = airavataService.getExperimentsInProject(gatewayId, projectId, limit, offset); sharingClientPool.returnResource(sharingClient); return result; } catch (Exception e) { @@ -1538,7 +1154,6 @@ public List getExperimentsInProject(AuthzToken authzToken, Stri 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; } @@ -1563,20 +1178,13 @@ public List getUserExperiments( AuthzToken authzToken, String gatewayId, String userName, int limit, int offset) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { - List result = regClient.getUserExperiments(gatewayId, userName, limit, offset); - registryClientPool.returnResource(regClient); - sharingClientPool.returnResource(sharingClient); - return result; + return airavataService.getUserExperiments(gatewayId, userName, limit, offset); } 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; } } @@ -1610,51 +1218,10 @@ public String createExperiment(AuthzToken authzToken, String gatewayId, Experime TException { // TODO: verify that gatewayId and experiment.gatewayId match authzToken logger.info("Api server accepted experiment creation with name {}", experiment.getExperimentName()); - RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { - String experimentId = regClient.createExperiment(gatewayId, experiment); - - if (ServerSettings.isEnableSharing()) { - try { - Entity entity = new Entity(); - entity.setEntityId(experimentId); - final String domainId = experiment.getGatewayId(); - entity.setDomainId(domainId); - entity.setEntityTypeId(domainId + ":" + "EXPERIMENT"); - entity.setOwnerId(experiment.getUserName() + "@" + domainId); - entity.setName(experiment.getExperimentName()); - entity.setDescription(experiment.getDescription()); - entity.setParentEntityId(experiment.getProjectId()); - - sharingClient.createEntity(entity); - shareEntityWithAdminGatewayGroups(regClient, sharingClient, entity); - } catch (Exception ex) { - logger.error(ex.getMessage(), ex); - logger.error("Rolling back experiment creation Exp ID : " + experimentId); - regClient.deleteExperiment(experimentId); - AiravataSystemException ase = new AiravataSystemException(); - ase.setMessage("Failed to create sharing registry record"); - throw ase; - } - } - - ExperimentStatusChangeEvent event = - new ExperimentStatusChangeEvent(ExperimentState.CREATED, experimentId, gatewayId); - String messageId = AiravataUtils.getId("EXPERIMENT"); - MessageContext messageContext = new MessageContext(event, MessageType.EXPERIMENT, messageId, gatewayId); - messageContext.setUpdatedTime(AiravataUtils.getCurrentTimestamp()); - if (statusPublisher != null) { - statusPublisher.publish(messageContext); - } - // logger.debug(experimentId, "Created new experiment with experiment name {}", - // experiment.getExperimentName()); - logger.info( - experimentId, - "Created new experiment with experiment name {} and id ", - experiment.getExperimentName(), - experimentId); - registryClientPool.returnResource(regClient); + String experimentId = airavataService.createExperimentWithSharingAndPublish( + sharingClient, statusPublisher, gatewayId, experiment); sharingClientPool.returnResource(sharingClient); return experimentId; } catch (Exception e) { @@ -1662,7 +1229,6 @@ public String createExperiment(AuthzToken authzToken, String gatewayId, Experime AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while creating the experiment. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); sharingClientPool.returnBrokenResource(sharingClient); throw exception; } @@ -1684,39 +1250,9 @@ public String createExperiment(AuthzToken authzToken, String gatewayId, Experime public boolean deleteExperiment(AuthzToken authzToken, String experimentId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { - ExperimentModel experimentModel = regClient.getExperiment(experimentId); - - if (ServerSettings.isEnableSharing() - && !authzToken - .getClaimsMap() - .get(org.apache.airavata.common.utils.Constants.USER_NAME) - .equals(experimentModel.getUserName()) - || !authzToken - .getClaimsMap() - .get(org.apache.airavata.common.utils.Constants.GATEWAY_ID) - .equals(experimentModel.getGatewayId())) { - try { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!sharingClient.userHasAccess( - gatewayId, userId + "@" + gatewayId, experimentId, 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 (!(experimentModel.getExperimentStatus().get(0).getState() == ExperimentState.CREATED)) { - logger.error("Error while deleting the experiment"); - throw new RegistryServiceException( - "Experiment is not in CREATED state. Hence cannot deleted. ID:" + experimentId); - } - boolean result = regClient.deleteExperiment(experimentId); - registryClientPool.returnResource(regClient); + boolean result = airavataService.deleteExperimentWithAuth(sharingClient, authzToken, experimentId); sharingClientPool.returnResource(sharingClient); return result; } catch (Exception e) { @@ -1724,7 +1260,6 @@ public boolean deleteExperiment(AuthzToken authzToken, String experimentId) AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while deleting the experiment. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); sharingClientPool.returnBrokenResource(sharingClient); throw exception; } @@ -1757,11 +1292,10 @@ public boolean deleteExperiment(AuthzToken authzToken, String experimentId) public ExperimentModel getExperiment(AuthzToken authzToken, String airavataExperimentId) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); ExperimentModel experimentModel = null; try { - experimentModel = regClient.getExperiment(airavataExperimentId); + experimentModel = airavataService.getExperiment(airavataExperimentId); if (authzToken .getClaimsMap() .get(org.apache.airavata.common.utils.Constants.USER_NAME) @@ -1770,7 +1304,6 @@ public ExperimentModel getExperiment(AuthzToken authzToken, String airavataExper .getClaimsMap() .get(org.apache.airavata.common.utils.Constants.GATEWAY_ID) .equals(experimentModel.getGatewayId())) { - registryClientPool.returnResource(regClient); sharingClientPool.returnResource(sharingClient); return experimentModel; } else if (ServerSettings.isEnableSharing()) { @@ -1781,28 +1314,25 @@ public ExperimentModel getExperiment(AuthzToken authzToken, String airavataExper gatewayId, userId + "@" + gatewayId, airavataExperimentId, gatewayId + ":READ")) { throw new AuthorizationException("User does not have permission to access this resource"); } - registryClientPool.returnResource(regClient); sharingClientPool.returnResource(sharingClient); return experimentModel; } 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 (ExperimentNotFoundException e) { - logger.error(e.getMessage(), e); - registryClientPool.returnResource(regClient); - sharingClientPool.returnResource(sharingClient); - throw e; } catch (Exception e) { + if (e instanceof ExperimentNotFoundException) { + logger.error(e.getMessage(), e); + sharingClientPool.returnResource(sharingClient); + throw (ExperimentNotFoundException) e; + } logger.error("Error while getting the experiment", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while getting the experiment. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); sharingClientPool.returnBrokenResource(sharingClient); throw exception; } @@ -1813,12 +1343,9 @@ public ExperimentModel getExperiment(AuthzToken authzToken, String airavataExper public ExperimentModel getExperimentByAdmin(AuthzToken authzToken, String airavataExperimentId) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); - ExperimentModel experimentModel = null; try { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - experimentModel = regClient.getExperiment(airavataExperimentId); - registryClientPool.returnResource(regClient); + ExperimentModel experimentModel = airavataService.getExperiment(airavataExperimentId); if (gatewayId.equals(experimentModel.getGatewayId())) { return experimentModel; } else { @@ -1829,7 +1356,6 @@ public ExperimentModel getExperimentByAdmin(AuthzToken authzToken, String airava AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while getting the experiment. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -1862,11 +1388,9 @@ public ExperimentModel getExperimentByAdmin(AuthzToken authzToken, String airava public ExperimentModel getDetailedExperimentTree(AuthzToken authzToken, String airavataExperimentId) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { - ExperimentModel result = regClient.getDetailedExperimentTree(airavataExperimentId); - registryClientPool.returnResource(regClient); + ExperimentModel result = airavataService.getDetailedExperimentTree(airavataExperimentId); sharingClientPool.returnResource(sharingClient); return result; } catch (Exception e) { @@ -1874,7 +1398,6 @@ public ExperimentModel getDetailedExperimentTree(AuthzToken authzToken, String a AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while retrieving the experiment. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); sharingClientPool.returnBrokenResource(sharingClient); throw exception; } @@ -1909,10 +1432,9 @@ public ExperimentModel getDetailedExperimentTree(AuthzToken authzToken, String a public void updateExperiment(AuthzToken authzToken, String airavataExperimentId, ExperimentModel experiment) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { - ExperimentModel experimentModel = regClient.getExperiment(airavataExperimentId); + ExperimentModel experimentModel = airavataService.getExperiment(airavataExperimentId); String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); if (ServerSettings.isEnableSharing() && !authzToken @@ -1947,15 +1469,13 @@ public void updateExperiment(AuthzToken authzToken, String airavataExperimentId, throw new Exception("Failed to update entity in sharing registry", e); } - regClient.updateExperiment(airavataExperimentId, experiment); - registryClientPool.returnResource(regClient); + airavataService.updateExperiment(airavataExperimentId, experiment); sharingClientPool.returnResource(sharingClient); } catch (Exception e) { logger.error(airavataExperimentId, "Error while updating experiment", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while updating experiment. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); sharingClientPool.returnBrokenResource(sharingClient); throw exception; } @@ -1966,10 +1486,8 @@ public void updateExperiment(AuthzToken authzToken, String airavataExperimentId, public void updateExperimentConfiguration( AuthzToken authzToken, String airavataExperimentId, UserConfigurationDataModel userConfiguration) throws AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - regClient.updateExperimentConfiguration(airavataExperimentId, userConfiguration); - registryClientPool.returnResource(regClient); + airavataService.updateExperimentConfiguration(airavataExperimentId, userConfiguration); } catch (Exception e) { logger.error(airavataExperimentId, "Error while updating user configuration", e); AiravataSystemException exception = new AiravataSystemException(); @@ -1979,7 +1497,6 @@ public void updateExperimentConfiguration( + "with status CREATED, VALIDATED, CANCELLED, FAILED and UNKNOWN. Make sure the given " + "experiment is in one of above statuses... " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -1989,10 +1506,8 @@ public void updateExperimentConfiguration( public void updateResourceScheduleing( AuthzToken authzToken, String airavataExperimentId, ComputationalResourceSchedulingModel resourceScheduling) throws AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - regClient.updateResourceScheduleing(airavataExperimentId, resourceScheduling); - registryClientPool.returnResource(regClient); + airavataService.updateResourceScheduleing(airavataExperimentId, resourceScheduling); } catch (Exception e) { logger.error(airavataExperimentId, "Error while updating scheduling info", e); AiravataSystemException exception = new AiravataSystemException(); @@ -2002,7 +1517,6 @@ public void updateResourceScheduleing( + "with status CREATED, VALIDATED, CANCELLED, FAILED and UNKNOWN. Make sure the given " + "experiment is in one of above statuses... " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -2079,15 +1593,16 @@ public boolean validateExperiment(AuthzToken authzToken, String airavataExperime @Override @SecurityCheck public ExperimentStatus getExperimentStatus(AuthzToken authzToken, String airavataExperimentId) throws TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - ExperimentStatus result = regClient.getExperimentStatus(airavataExperimentId); - registryClientPool.returnResource(regClient); + ExperimentStatus result = airavataService.getExperimentStatus(airavataExperimentId); return result; + } catch (org.apache.airavata.registry.cpi.RegistryException e) { + AiravataSystemException exception = new AiravataSystemException(); + exception.setMessage(e.getMessage()); + throw exception; } catch (Exception e) { AiravataSystemException exception = new AiravataSystemException(); exception.setMessage(e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -2096,17 +1611,20 @@ public ExperimentStatus getExperimentStatus(AuthzToken authzToken, String airava @SecurityCheck public List getExperimentOutputs(AuthzToken authzToken, String airavataExperimentId) throws AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - List result = regClient.getExperimentOutputs(airavataExperimentId); - registryClientPool.returnResource(regClient); + List result = airavataService.getExperimentOutputs(airavataExperimentId); return result; + } catch (org.apache.airavata.registry.cpi.RegistryException e) { + logger.error(airavataExperimentId, "Error while retrieving the experiment outputs", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving the experiment outputs. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { logger.error(airavataExperimentId, "Error while retrieving the experiment outputs", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while retrieving the experiment outputs. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -2124,64 +1642,22 @@ public List getIntermediateOutputs(AuthzToken authzToken, public void fetchIntermediateOutputs(AuthzToken authzToken, String airavataExperimentId, List outputNames) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - - RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { - - // Verify that user has WRITE access to experiment - final boolean hasAccess = userHasAccessInternal( - sharingClient, authzToken, airavataExperimentId, ResourcePermissionType.WRITE); - if (!hasAccess) { - throw new AuthorizationException("User does not have WRITE access to this experiment"); - } - - // Verify that the experiment's job is currently ACTIVE - ExperimentModel existingExperiment = regClient.getExperiment(airavataExperimentId); - List jobs = regClient.getJobDetails(airavataExperimentId); - boolean anyJobIsActive = jobs.stream().anyMatch(j -> { - if (j.getJobStatusesSize() > 0) { - return j.getJobStatuses().get(j.getJobStatusesSize() - 1).getJobState() == JobState.ACTIVE; - } else { - return false; - } - }); - if (!anyJobIsActive) { - throw new InvalidRequestException("Experiment does not have currently ACTIVE job"); - } - - // Figure out if there are any currently running intermediate output fetching processes for outputNames - // First, find any existing intermediate output fetch processes for outputNames - List intermediateOutputFetchProcesses = existingExperiment.getProcesses().stream() - .filter(p -> { - // Filter out completed or failed processes - if (p.getProcessStatusesSize() > 0) { - ProcessStatus latestStatus = p.getProcessStatuses().get(p.getProcessStatusesSize() - 1); - if (latestStatus.getState() == ProcessState.COMPLETED - || latestStatus.getState() == ProcessState.FAILED) { - return false; - } - } - return true; - }) - .filter(p -> p.getTasks().stream().allMatch(t -> t.getTaskType() == TaskTypes.OUTPUT_FETCHING)) - .filter(p -> p.getProcessOutputs().stream().anyMatch(o -> outputNames.contains(o.getName()))) - .collect(Collectors.toList()); - if (!intermediateOutputFetchProcesses.isEmpty()) { - throw new InvalidRequestException( - "There are already intermediate output fetching tasks running for those outputs."); - } - - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - submitExperimentIntermediateOutputsEvent(gatewayId, airavataExperimentId, outputNames); - registryClientPool.returnResource(regClient); + airavataService.validateAndFetchIntermediateOutputs( + sharingClient, authzToken, airavataExperimentId, outputNames, experimentPublisher); sharingClientPool.returnResource(sharingClient); - } catch (InvalidRequestException | AuthorizationException e) { - logger.error(e.getMessage(), e); - registryClientPool.returnResource(regClient); - sharingClientPool.returnResource(sharingClient); - throw e; } catch (Exception e) { + if (e.getMessage() != null && e.getMessage().contains("does not have WRITE access")) { + logger.error(e.getMessage(), e); + sharingClientPool.returnResource(sharingClient); + throw new AuthorizationException(e.getMessage()); + } else if (e.getMessage() != null && (e.getMessage().contains("does not have currently ACTIVE job") + || e.getMessage().contains("already intermediate output fetching tasks"))) { + logger.error(e.getMessage(), e); + sharingClientPool.returnResource(sharingClient); + throw new InvalidRequestException(e.getMessage()); + } logger.error( "Error while processing request to fetch intermediate outputs for experiment: " + airavataExperimentId, @@ -2191,7 +1667,6 @@ public void fetchIntermediateOutputs(AuthzToken authzToken, String airavataExper exception.setMessage( "Error while processing request to fetch intermediate outputs for experiment. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); sharingClientPool.returnBrokenResource(sharingClient); throw exception; } @@ -2203,67 +1678,31 @@ public ProcessStatus getIntermediateOutputProcessStatus( AuthzToken authzToken, String airavataExperimentId, List outputNames) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { - - // Verify that user has READ access to experiment - final boolean hasAccess = - userHasAccessInternal(sharingClient, authzToken, airavataExperimentId, ResourcePermissionType.READ); - if (!hasAccess) { - throw new AuthorizationException("User does not have WRITE access to this experiment"); - } - - ExperimentModel existingExperiment = regClient.getExperiment(airavataExperimentId); - - // Find the most recent intermediate output fetching process for the outputNames - // Assumption: only one of these output fetching processes runs at a - // time so we only need to check the status of the most recent one - Optional mostRecentOutputFetchProcess = existingExperiment.getProcesses().stream() - .filter(p -> p.getTasks().stream().allMatch(t -> t.getTaskType() == TaskTypes.OUTPUT_FETCHING)) - .filter(p -> { - List names = p.getProcessOutputs().stream() - .map(o -> o.getName()) - .collect(Collectors.toList()); - return new HashSet<>(names).equals(new HashSet<>(outputNames)); - }) - .sorted(Comparator.comparing(ProcessModel::getLastUpdateTime) - .reversed()) - .findFirst(); - - if (!mostRecentOutputFetchProcess.isPresent()) { - throw new InvalidRequestException("No matching intermediate output fetching process found."); - } - - ProcessStatus result; - // Determine the most recent status for the most recent process - ProcessModel process = mostRecentOutputFetchProcess.get(); - if (process.getProcessStatusesSize() > 0) { - result = process.getProcessStatuses().get(process.getProcessStatusesSize() - 1); - } else { - // Process has no statuses so it must be created but not yet running - result = new ProcessStatus(ProcessState.CREATED); - } - - registryClientPool.returnResource(regClient); + ProcessStatus result = airavataService.getIntermediateOutputProcessStatusInternal( + sharingClient, authzToken, airavataExperimentId, outputNames); sharingClientPool.returnResource(sharingClient); return result; - } catch (InvalidRequestException | AuthorizationException e) { - logger.debug(e.getMessage(), e); - registryClientPool.returnResource(regClient); - sharingClientPool.returnResource(sharingClient); - throw e; } catch (Exception e) { + if (e.getMessage() != null && e.getMessage().contains("does not have READ access")) { + logger.debug(e.getMessage(), e); + sharingClientPool.returnResource(sharingClient); + throw new AuthorizationException(e.getMessage()); + } else if (e.getMessage() != null && e.getMessage().contains("No matching intermediate output")) { + logger.debug(e.getMessage(), e); + sharingClientPool.returnResource(sharingClient); + throw new InvalidRequestException(e.getMessage()); + } logger.error( - "Error while processing request to fetch intermediate outputs for experiment: " + "Error while processing request to get intermediate output process status for experiment: " + airavataExperimentId, e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage( - "Error while processing request to fetch intermediate outputs for experiment. More info : " + "Error while processing request to get intermediate output process status for experiment. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); sharingClientPool.returnBrokenResource(sharingClient); throw exception; } @@ -2272,17 +1711,20 @@ public ProcessStatus getIntermediateOutputProcessStatus( @SecurityCheck public Map getJobStatuses(AuthzToken authzToken, String airavataExperimentId) throws AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - Map result = regClient.getJobStatuses(airavataExperimentId); - registryClientPool.returnResource(regClient); + Map result = airavataService.getJobStatuses(airavataExperimentId); return result; + } catch (org.apache.airavata.registry.cpi.RegistryException e) { + logger.error(airavataExperimentId, "Error while retrieving the job statuses", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving the job statuses. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { logger.error(airavataExperimentId, "Error while retrieving the job statuses", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while retrieving the job statuses. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -2292,17 +1734,20 @@ public Map getJobStatuses(AuthzToken authzToken, String airav public List getJobDetails(AuthzToken authzToken, String airavataExperimentId) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - List result = regClient.getJobDetails(airavataExperimentId); - registryClientPool.returnResource(regClient); + List result = airavataService.getJobDetails(airavataExperimentId); return result; + } catch (org.apache.airavata.registry.cpi.RegistryException e) { + logger.error(airavataExperimentId, "Error while retrieving the job details", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving the job details. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { logger.error(airavataExperimentId, "Error while retrieving the job details", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while retrieving the job details. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -2340,119 +1785,15 @@ public void launchExperiment(AuthzToken authzToken, final String airavataExperim throws AuthorizationException, AiravataSystemException, TException { // TODO: verify that gatewayId matches gatewayId in authzToken logger.info("Launching experiment {}", airavataExperimentId); - RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { - ExperimentModel experiment = regClient.getExperiment(airavataExperimentId); - - if (experiment == null) { - logger.error( - airavataExperimentId, - "Error while launching experiment, experiment {} doesn't exist.", - airavataExperimentId); - throw new ExperimentNotFoundException( - "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); - } - String username = authzToken.getClaimsMap().get(Constants.USER_NAME); - - // For backwards compatibility, if there is no groupResourceProfileId, look up one that is shared with the - // user - if (!experiment.getUserConfigurationData().isSetGroupResourceProfileId()) { - List groupResourceProfiles = getGroupResourceList(authzToken, gatewayId); - logger.info("Checking for groupResourceProfileId for ExpID: " + airavataExperimentId); - if (!groupResourceProfiles.isEmpty()) { - // Just pick the first one - final String groupResourceProfileId = - groupResourceProfiles.get(0).getGroupResourceProfileId(); - logger.warn( - "Experiment {} doesn't have groupResourceProfileId, picking first one user has access to: {}", - airavataExperimentId, - groupResourceProfileId); - experiment.getUserConfigurationData().setGroupResourceProfileId(groupResourceProfileId); - regClient.updateExperimentConfiguration( - airavataExperimentId, experiment.getUserConfigurationData()); - } else { - throw new AuthorizationException("User " + username + " in gateway " + gatewayId - + " doesn't have access to any group resource profiles."); - } - } - - // Verify user has READ access to groupResourceProfileId - if (!sharingClient.userHasAccess( - gatewayId, - username + "@" + gatewayId, - experiment.getUserConfigurationData().getGroupResourceProfileId(), - gatewayId + ":READ")) { - throw new AuthorizationException("User " + username + " in gateway " + gatewayId - + " doesn't have access to group resource profile " - + experiment.getUserConfigurationData().getGroupResourceProfileId()); - } - - // Verify user has READ access to Application Deployment - final String appInterfaceId = experiment.getExecutionId(); - ApplicationInterfaceDescription applicationInterfaceDescription = - regClient.getApplicationInterface(appInterfaceId); - - List appModuleIds = applicationInterfaceDescription.getApplicationModules(); - // Assume that there is only one app module for this interface (otherwise, how could we figure out the - // deployment) - String appModuleId = appModuleIds.get(0); - List applicationDeploymentDescriptions = - regClient.getApplicationDeployments(appModuleId); - - if (!experiment.getUserConfigurationData().isAiravataAutoSchedule()) { - final String resourceHostId = experiment - .getUserConfigurationData() - .getComputationalResourceScheduling() - .getResourceHostId(); - - Optional applicationDeploymentDescription = - applicationDeploymentDescriptions.stream() - .filter(dep -> dep.getComputeHostId().equals(resourceHostId)) - .findFirst(); - if (applicationDeploymentDescription.isPresent()) { - final String appDeploymentId = - applicationDeploymentDescription.get().getAppDeploymentId(); - if (!sharingClient.userHasAccess( - gatewayId, username + "@" + gatewayId, appDeploymentId, gatewayId + ":READ")) { - throw new AuthorizationException("User " + username + " in gateway " + gatewayId - + " doesn't have access to app deployment " + appDeploymentId); - } - } else { - throw new InvalidRequestException("Application deployment doesn't exist for application interface " - + appInterfaceId + " and host " + resourceHostId + " in gateway " + gatewayId); - } - } else if (experiment.getUserConfigurationData().getAutoScheduledCompResourceSchedulingList() != null - && !experiment - .getUserConfigurationData() - .getAutoScheduledCompResourceSchedulingList() - .isEmpty()) { - List compResourceSchedulingList = - experiment.getUserConfigurationData().getAutoScheduledCompResourceSchedulingList(); - for (ComputationalResourceSchedulingModel crScheduling : compResourceSchedulingList) { - Optional applicationDeploymentDescription = - applicationDeploymentDescriptions.stream() - .filter(dep -> dep.getComputeHostId().equals(crScheduling.getResourceHostId())) - .findFirst(); - if (applicationDeploymentDescription.isPresent()) { - final String appDeploymentId = - applicationDeploymentDescription.get().getAppDeploymentId(); - if (!sharingClient.userHasAccess( - gatewayId, username + "@" + gatewayId, appDeploymentId, gatewayId + ":READ")) { - throw new AuthorizationException("User " + username + " in gateway " + gatewayId - + " doesn't have access to app deployment " + appDeploymentId); - } - } - } - } - submitExperiment(gatewayId, airavataExperimentId); + airavataService.launchExperimentWithValidation( + sharingClient, authzToken, gatewayId, airavataExperimentId, experimentPublisher); logger.info("Experiment with ExpId: " + airavataExperimentId + " was submitted in gateway with gatewayID: " + gatewayId); - registryClientPool.returnResource(regClient); sharingClientPool.returnResource(sharingClient); } catch (InvalidRequestException | ExperimentNotFoundException | AuthorizationException e) { logger.error(e.getMessage(), e); - registryClientPool.returnResource(regClient); sharingClientPool.returnResource(sharingClient); throw e; } catch (Exception e1) { @@ -2460,7 +1801,6 @@ public void launchExperiment(AuthzToken authzToken, final String airavataExperim AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while instantiate the registry instance. More info : " + e1.getMessage()); - registryClientPool.returnBrokenResource(regClient); sharingClientPool.returnBrokenResource(sharingClient); throw exception; } @@ -2523,20 +1863,17 @@ public String cloneExperiment( AuthzToken authzToken, String existingExperimentID, String newExperimentName, String newExperimentProjectId) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException, ProjectNotFoundException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { // getExperiment will apply sharing permissions ExperimentModel existingExperiment = this.getExperiment(authzToken, existingExperimentID); String result = cloneExperimentInternal( - regClient, sharingClient, authzToken, existingExperimentID, newExperimentName, newExperimentProjectId, existingExperiment); - registryClientPool.returnResource(regClient); sharingClientPool.returnResource(sharingClient); return result; } catch (Exception e) { @@ -2545,7 +1882,6 @@ public String cloneExperiment( exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage( "Error while cloning the experiment with existing configuration. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); sharingClientPool.returnBrokenResource(sharingClient); throw exception; } @@ -2557,20 +1893,17 @@ public String cloneExperimentByAdmin( AuthzToken authzToken, String existingExperimentID, String newExperimentName, String newExperimentProjectId) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException, ProjectNotFoundException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { // get existing experiment by bypassing normal sharing permissions for the admin user ExperimentModel existingExperiment = this.getExperimentByAdmin(authzToken, existingExperimentID); String result = cloneExperimentInternal( - regClient, sharingClient, authzToken, existingExperimentID, newExperimentName, newExperimentProjectId, existingExperiment); - registryClientPool.returnResource(regClient); sharingClientPool.returnResource(sharingClient); return result; } catch (Exception e) { @@ -2579,14 +1912,12 @@ public String cloneExperimentByAdmin( exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage( "Error while cloning the experiment with existing configuration. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); sharingClientPool.returnBrokenResource(sharingClient); throw exception; } } private String cloneExperimentInternal( - RegistryService.Client regClient, SharingRegistryService.Client sharingClient, AuthzToken authzToken, String existingExperimentID, @@ -2632,9 +1963,15 @@ private String cloneExperimentInternal( existingExperiment.setCreationTime(AiravataUtils.getCurrentTimestamp().getTime()); if (existingExperiment.getExecutionId() != null) { - List applicationOutputs = - regClient.getApplicationOutputs(existingExperiment.getExecutionId()); - existingExperiment.setExperimentOutputs(applicationOutputs); + try { + List applicationOutputs = + airavataService.getApplicationOutputs(existingExperiment.getExecutionId()); + existingExperiment.setExperimentOutputs(applicationOutputs); + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.warn("Error getting application outputs for experiment clone: " + e.getMessage()); + } catch (Exception e) { + logger.warn("Error getting application outputs for experiment clone: " + e.getMessage()); + } } if (validateString(newExperimentName)) { existingExperiment.setExperimentName(newExperimentName); @@ -2654,14 +1991,25 @@ private String cloneExperimentInternal( .getComputationalResourceScheduling() .getResourceHostId(); - ComputeResourceDescription computeResourceDescription = regClient.getComputeResource(compResourceId); - if (!computeResourceDescription.isEnabled()) { - existingExperiment.getUserConfigurationData().setComputationalResourceScheduling(null); + try { + ComputeResourceDescription computeResourceDescription = airavataService.getComputeResource(compResourceId); + if (!computeResourceDescription.isEnabled()) { + existingExperiment.getUserConfigurationData().setComputationalResourceScheduling(null); + } + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.warn("Error getting compute resource for experiment clone: " + e.getMessage()); + } catch (Exception e) { + logger.warn("Error getting compute resource for experiment clone: " + e.getMessage()); } } logger.debug("Airavata cloned experiment with experiment id : " + existingExperimentID); existingExperiment.setUserName(userId); - String expId = regClient.createExperiment(gatewayId, existingExperiment); + String expId; + try { + expId = airavataService.createExperiment(gatewayId, existingExperiment); + } catch (org.apache.airavata.registry.cpi.RegistryException e) { + throw new TException("Error creating cloned experiment: " + e.getMessage(), e); + } if (ServerSettings.isEnableSharing()) { try { @@ -2674,11 +2022,15 @@ private String cloneExperimentInternal( entity.setName(existingExperiment.getExperimentName()); entity.setDescription(existingExperiment.getDescription()); sharingClient.createEntity(entity); - shareEntityWithAdminGatewayGroups(regClient, sharingClient, entity); + airavataService.shareEntityWithAdminGatewayGroups(sharingClient, entity); } catch (Exception ex) { logger.error(ex.getMessage(), ex); logger.error("rolling back experiment creation Exp ID : " + expId); - regClient.deleteExperiment(expId); + try { + airavataService.deleteExperiment(expId); + } catch (org.apache.airavata.registry.cpi.RegistryException e) { + logger.error("Error deleting experiment during rollback: " + e.getMessage()); + } } } @@ -2710,10 +2062,9 @@ private String cloneExperimentInternal( @SecurityCheck public void terminateExperiment(AuthzToken authzToken, String airavataExperimentId, String gatewayId) throws TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - ExperimentModel existingExperiment = regClient.getExperiment(airavataExperimentId); - ExperimentStatus experimentLastStatus = regClient.getExperimentStatus(airavataExperimentId); + ExperimentModel existingExperiment = airavataService.getExperiment(airavataExperimentId); + ExperimentStatus experimentLastStatus = airavataService.getExperimentStatus(airavataExperimentId); if (existingExperiment == null) { logger.error( airavataExperimentId, @@ -2739,17 +2090,21 @@ public void terminateExperiment(AuthzToken authzToken, String airavataExperiment logger.warn("Experiment termination is only allowed for launched experiments."); break; default: - submitCancelExperiment(gatewayId, airavataExperimentId); + airavataService.publishExperimentCancelEvent(experimentPublisher, gatewayId, airavataExperimentId); logger.debug("Airavata cancelled experiment with experiment id : " + airavataExperimentId); break; } - registryClientPool.returnResource(regClient); - } catch (RegistryServiceException | AiravataException e) { + } catch (AiravataException e) { + logger.error(airavataExperimentId, "Error while cancelling the experiment...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while cancelling the experiment. More info : " + e.getMessage()); + throw exception; + } catch (Exception e) { logger.error(airavataExperimentId, "Error while cancelling the experiment...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while cancelling the experiment. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -2767,17 +2122,20 @@ public String registerApplicationModule( AuthzToken authzToken, String gatewayId, ApplicationModule applicationModule) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - String result = regClient.registerApplicationModule(gatewayId, applicationModule); - registryClientPool.returnResource(regClient); + String result = airavataService.registerApplicationModule(gatewayId, applicationModule); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error("Error while adding application module...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while adding application module. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { logger.error("Error while adding application module...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while adding application module. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -2794,17 +2152,20 @@ public String registerApplicationModule( public ApplicationModule getApplicationModule(AuthzToken authzToken, String appModuleId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - ApplicationModule result = regClient.getApplicationModule(appModuleId); - registryClientPool.returnResource(regClient); + ApplicationModule result = airavataService.getApplicationModule(appModuleId); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(appModuleId, "Error while retrieving application module...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving the adding application module. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { logger.error(appModuleId, "Error while retrieving application module...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while retrieving the adding application module. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -2823,17 +2184,20 @@ public boolean updateApplicationModule( AuthzToken authzToken, String appModuleId, ApplicationModule applicationModule) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.updateApplicationModule(appModuleId, applicationModule); - registryClientPool.returnResource(regClient); + boolean result = airavataService.updateApplicationModule(appModuleId, applicationModule); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(appModuleId, "Error while updating application module...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while updating application module. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { logger.error(appModuleId, "Error while updating application module...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while updating application module. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -2849,17 +2213,20 @@ public boolean updateApplicationModule( public List getAllAppModules(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - List result = regClient.getAllAppModules(gatewayId); - registryClientPool.returnResource(regClient); + List result = airavataService.getAllAppModules(gatewayId); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error("Error while retrieving all application modules...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving all application modules. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { logger.error("Error while retrieving all application modules...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while retrieving all application modules. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -2875,53 +2242,24 @@ public List getAllAppModules(AuthzToken authzToken, String ga public List getAccessibleAppModules(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); - String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); - try { - List accessibleAppDeploymentIds = new ArrayList<>(); - if (ServerSettings.isEnableSharing()) { - List sharingFilters = new ArrayList<>(); - SearchCriteria entityTypeFilter = new SearchCriteria(); - entityTypeFilter.setSearchField(EntitySearchField.ENTITY_TYPE_ID); - entityTypeFilter.setSearchCondition(SearchCondition.EQUAL); - entityTypeFilter.setValue(gatewayId + ":" + ResourceType.APPLICATION_DEPLOYMENT.name()); - sharingFilters.add(entityTypeFilter); - SearchCriteria permissionTypeFilter = new SearchCriteria(); - permissionTypeFilter.setSearchField(EntitySearchField.PERMISSION_TYPE_ID); - permissionTypeFilter.setSearchCondition(SearchCondition.EQUAL); - permissionTypeFilter.setValue(gatewayId + ":" + ResourcePermissionType.READ); - sharingFilters.add(permissionTypeFilter); - sharingClient - .searchEntities( - authzToken.getClaimsMap().get(Constants.GATEWAY_ID), - userName + "@" + gatewayId, - sharingFilters, - 0, - -1) - .forEach(a -> accessibleAppDeploymentIds.add(a.getEntityId())); - } - List accessibleComputeResourceIds = new ArrayList<>(); - List groupResourceProfileList = getGroupResourceList(authzToken, gatewayId); - for (GroupResourceProfile groupResourceProfile : groupResourceProfileList) { - List groupComputeResourcePreferenceList = - groupResourceProfile.getComputePreferences(); - for (GroupComputeResourcePreference groupComputeResourcePreference : - groupComputeResourcePreferenceList) { - accessibleComputeResourceIds.add(groupComputeResourcePreference.getComputeResourceId()); - } - } - List result = regClient.getAccessibleAppModules( - gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); - registryClientPool.returnResource(regClient); + SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + try { + List result = airavataService.getAccessibleAppModulesWithSharing( + sharingClient, authzToken, gatewayId); sharingClientPool.returnResource(sharingClient); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error("Error while retrieving all application modules...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving all application modules. More info : " + e.getMessage()); + sharingClientPool.returnBrokenResource(sharingClient); + throw exception; } catch (Exception e) { logger.error("Error while retrieving all application modules...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while retrieving all application modules. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); sharingClientPool.returnBrokenResource(sharingClient); throw exception; } @@ -2939,17 +2277,20 @@ public List getAccessibleAppModules(AuthzToken authzToken, St public boolean deleteApplicationModule(AuthzToken authzToken, String appModuleId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.deleteApplicationModule(appModuleId); - registryClientPool.returnResource(regClient); + boolean result = airavataService.deleteApplicationModule(appModuleId); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(appModuleId, "Error while deleting application module...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while deleting the application module. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { logger.error(appModuleId, "Error while deleting application module...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while deleting the application module. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -2967,10 +2308,9 @@ public String registerApplicationDeployment( throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { // TODO: verify that gatewayId matches authzToken gatewayId - RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { - String result = regClient.registerApplicationDeployment(gatewayId, applicationDeployment); + String result = airavataService.registerApplicationDeployment(gatewayId, applicationDeployment); Entity entity = new Entity(); entity.setEntityId(result); final String domainId = gatewayId; @@ -2981,8 +2321,7 @@ public String registerApplicationDeployment( entity.setName(result); entity.setDescription(applicationDeployment.getAppDeploymentDescription()); sharingClient.createEntity(entity); - shareEntityWithAdminGatewayGroups(regClient, sharingClient, entity); - registryClientPool.returnResource(regClient); + airavataService.shareEntityWithAdminGatewayGroups(sharingClient, entity); sharingClientPool.returnResource(sharingClient); return result; } catch (Exception e) { @@ -2990,7 +2329,6 @@ public String registerApplicationDeployment( AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while adding application deployment. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); sharingClientPool.returnBrokenResource(sharingClient); throw exception; } @@ -3008,19 +2346,17 @@ public String registerApplicationDeployment( public ApplicationDeploymentDescription getApplicationDeployment(AuthzToken authzToken, String appDeploymentId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { if (ServerSettings.isEnableSharing()) { final boolean hasAccess = - userHasAccessInternal(sharingClient, authzToken, appDeploymentId, ResourcePermissionType.READ); + airavataService.userHasAccessInternal(sharingClient, authzToken, appDeploymentId, ResourcePermissionType.READ); if (!hasAccess) { throw new AuthorizationException( "User does not have access to application deployment " + appDeploymentId); } } - ApplicationDeploymentDescription result = regClient.getApplicationDeployment(appDeploymentId); - registryClientPool.returnResource(regClient); + ApplicationDeploymentDescription result = airavataService.getApplicationDeployment(appDeploymentId); sharingClientPool.returnResource(sharingClient); return result; } catch (Exception e) { @@ -3028,7 +2364,6 @@ public ApplicationDeploymentDescription getApplicationDeployment(AuthzToken auth AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while retrieving application deployment. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); sharingClientPool.returnBrokenResource(sharingClient); throw exception; } @@ -3048,19 +2383,17 @@ public boolean updateApplicationDeployment( AuthzToken authzToken, String appDeploymentId, ApplicationDeploymentDescription applicationDeployment) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { if (ServerSettings.isEnableSharing()) { final boolean hasAccess = - userHasAccessInternal(sharingClient, authzToken, appDeploymentId, ResourcePermissionType.WRITE); + airavataService.userHasAccessInternal(sharingClient, authzToken, appDeploymentId, ResourcePermissionType.WRITE); if (!hasAccess) { throw new AuthorizationException( "User does not have WRITE access to application deployment " + appDeploymentId); } } - boolean result = regClient.updateApplicationDeployment(appDeploymentId, applicationDeployment); - registryClientPool.returnResource(regClient); + boolean result = airavataService.updateApplicationDeployment(appDeploymentId, applicationDeployment); sharingClientPool.returnResource(sharingClient); return result; } catch (Exception e) { @@ -3068,7 +2401,6 @@ public boolean updateApplicationDeployment( AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while updating application deployment. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); sharingClientPool.returnBrokenResource(sharingClient); throw exception; } @@ -3086,19 +2418,17 @@ public boolean updateApplicationDeployment( public boolean deleteApplicationDeployment(AuthzToken authzToken, String appDeploymentId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { final boolean hasAccess = - userHasAccessInternal(sharingClient, authzToken, appDeploymentId, ResourcePermissionType.WRITE); + airavataService.userHasAccessInternal(sharingClient, authzToken, appDeploymentId, ResourcePermissionType.WRITE); if (!hasAccess) { throw new AuthorizationException( "User does not have WRITE access to application deployment " + appDeploymentId); } final String domainId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - boolean result = regClient.deleteApplicationDeployment(appDeploymentId); + boolean result = airavataService.deleteApplicationDeployment(appDeploymentId); sharingClient.deleteEntity(domainId, appDeploymentId); - registryClientPool.returnResource(regClient); sharingClientPool.returnResource(sharingClient); return result; } catch (Exception e) { @@ -3106,7 +2436,6 @@ public boolean deleteApplicationDeployment(AuthzToken authzToken, String appDepl AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while deleting application deployment. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); sharingClientPool.returnBrokenResource(sharingClient); throw exception; } @@ -3138,53 +2467,24 @@ public List getAccessibleApplicationDeployment AuthzToken authzToken, String gatewayId, ResourcePermissionType permissionType) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); - String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { - List accessibleAppDeploymentIds = new ArrayList<>(); - if (ServerSettings.isEnableSharing()) { - List sharingFilters = new ArrayList<>(); - SearchCriteria entityTypeFilter = new SearchCriteria(); - entityTypeFilter.setSearchField(EntitySearchField.ENTITY_TYPE_ID); - entityTypeFilter.setSearchCondition(SearchCondition.EQUAL); - entityTypeFilter.setValue(gatewayId + ":" + ResourceType.APPLICATION_DEPLOYMENT.name()); - sharingFilters.add(entityTypeFilter); - SearchCriteria permissionTypeFilter = new SearchCriteria(); - permissionTypeFilter.setSearchField(EntitySearchField.PERMISSION_TYPE_ID); - permissionTypeFilter.setSearchCondition(SearchCondition.EQUAL); - permissionTypeFilter.setValue(gatewayId + ":" + permissionType.name()); - sharingFilters.add(permissionTypeFilter); - sharingClient - .searchEntities( - authzToken.getClaimsMap().get(Constants.GATEWAY_ID), - userName + "@" + gatewayId, - sharingFilters, - 0, - -1) - .forEach(a -> accessibleAppDeploymentIds.add(a.getEntityId())); - } - List accessibleComputeResourceIds = new ArrayList<>(); - List groupResourceProfileList = getGroupResourceList(authzToken, gatewayId); - for (GroupResourceProfile groupResourceProfile : groupResourceProfileList) { - List groupComputeResourcePreferenceList = - groupResourceProfile.getComputePreferences(); - for (GroupComputeResourcePreference groupComputeResourcePreference : - groupComputeResourcePreferenceList) { - accessibleComputeResourceIds.add(groupComputeResourcePreference.getComputeResourceId()); - } - } - List result = regClient.getAccessibleApplicationDeployments( - gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); - registryClientPool.returnResource(regClient); + List result = airavataService.getAccessibleApplicationDeploymentsWithSharing( + sharingClient, authzToken, gatewayId, permissionType); sharingClientPool.returnResource(sharingClient); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error("Error while retrieving application deployments...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving application deployments. More info : " + e.getMessage()); + sharingClientPool.returnBrokenResource(sharingClient); + throw exception; } catch (Exception e) { logger.error("Error while retrieving application deployments...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while retrieving application deployments. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); sharingClientPool.returnBrokenResource(sharingClient); throw exception; } @@ -3203,18 +2503,21 @@ public List getAccessibleApplicationDeployment public List getAppModuleDeployedResources(AuthzToken authzToken, String appModuleId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { // TODO: restrict to only application deployments that are accessible to user - List result = regClient.getAppModuleDeployedResources(appModuleId); - registryClientPool.returnResource(regClient); + List result = airavataService.getAppModuleDeployedResources(appModuleId); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(appModuleId, "Error while retrieving application deployments...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving application deployment. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { logger.error(appModuleId, "Error while retrieving application deployments...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while retrieving application deployment. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -3238,18 +2541,17 @@ public List getApplicationDeploymentsForAppMod AuthzToken authzToken, String appModuleId, String groupResourceProfileId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); try { // Get list of compute resources for this Group Resource Profile - if (!userHasAccessInternal( + if (!airavataService.userHasAccessInternal( sharingClient, authzToken, groupResourceProfileId, ResourcePermissionType.READ)) { throw new AuthorizationException( "User is not authorized to access Group Resource Profile " + groupResourceProfileId); } - GroupResourceProfile groupResourceProfile = regClient.getGroupResourceProfile(groupResourceProfileId); + GroupResourceProfile groupResourceProfile = airavataService.getGroupResourceProfile(groupResourceProfileId); List accessibleComputeResourceIds = groupResourceProfile.getComputePreferences().stream() .map(compPref -> compPref.getComputeResourceId()) .collect(Collectors.toList()); @@ -3271,22 +2573,26 @@ public List getApplicationDeploymentsForAppMod .searchEntities(gatewayId, userName + "@" + gatewayId, sharingFilters, 0, -1) .forEach(a -> accessibleAppDeploymentIds.add(a.getEntityId())); - List result = regClient.getAccessibleApplicationDeploymentsForAppModule( - gatewayId, appModuleId, accessibleAppDeploymentIds, accessibleComputeResourceIds); - registryClientPool.returnResource(regClient); + List result = airavataService.getAccessibleApplicationDeploymentsForAppModule( + appModuleId, gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); sharingClientPool.returnResource(sharingClient); return result; } catch (AuthorizationException checkedException) { logger.error("Error while retrieving application deployments...", checkedException); - registryClientPool.returnResource(regClient); sharingClientPool.returnResource(sharingClient); throw checkedException; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error("Error while retrieving application deployments...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving application deployments. More info : " + e.getMessage()); + sharingClientPool.returnBrokenResource(sharingClient); + throw exception; } catch (Exception e) { logger.error("Error while retrieving application deployments...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while retrieving application deployments. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); sharingClientPool.returnBrokenResource(sharingClient); throw exception; } @@ -3304,17 +2610,14 @@ public String registerApplicationInterface( AuthzToken authzToken, String gatewayId, ApplicationInterfaceDescription applicationInterface) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - String result = regClient.registerApplicationInterface(gatewayId, applicationInterface); - registryClientPool.returnResource(regClient); + String result = airavataService.registerApplicationInterface(gatewayId, applicationInterface); return result; } catch (Exception e) { logger.error("Error while adding application interface...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while adding application interface. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -3325,10 +2628,9 @@ public String cloneApplicationInterface( AuthzToken authzToken, String existingAppInterfaceID, String newApplicationName, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { ApplicationInterfaceDescription existingInterface = - regClient.getApplicationInterface(existingAppInterfaceID); + airavataService.getApplicationInterface(existingAppInterfaceID); if (existingInterface == null) { logger.error( "Provided application interface does not exist.Please provide a valid application interface id..."); @@ -3337,17 +2639,15 @@ public String cloneApplicationInterface( existingInterface.setApplicationName(newApplicationName); existingInterface.setApplicationInterfaceId(airavata_commonsConstants.DEFAULT_ID); - String interfaceId = regClient.registerApplicationInterface(gatewayId, existingInterface); + String interfaceId = airavataService.registerApplicationInterface(gatewayId, existingInterface); logger.debug("Airavata cloned application interface : " + existingAppInterfaceID + " for gateway id : " + gatewayId); - registryClientPool.returnResource(regClient); return interfaceId; } catch (Exception e) { logger.error("Error while adding application interface...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while adding application interface. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -3364,17 +2664,14 @@ public String cloneApplicationInterface( public ApplicationInterfaceDescription getApplicationInterface(AuthzToken authzToken, String appInterfaceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - ApplicationInterfaceDescription result = regClient.getApplicationInterface(appInterfaceId); - registryClientPool.returnResource(regClient); + ApplicationInterfaceDescription result = airavataService.getApplicationInterface(appInterfaceId); return result; } catch (Exception e) { logger.error(appInterfaceId, "Error while retrieving application interface...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while retrieving application interface. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -3393,17 +2690,14 @@ public boolean updateApplicationInterface( AuthzToken authzToken, String appInterfaceId, ApplicationInterfaceDescription applicationInterface) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.updateApplicationInterface(appInterfaceId, applicationInterface); - registryClientPool.returnResource(regClient); + boolean result = airavataService.updateApplicationInterface(appInterfaceId, applicationInterface); return result; } catch (Exception e) { logger.error(appInterfaceId, "Error while updating application interface...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while updating application interface. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -3420,17 +2714,14 @@ public boolean updateApplicationInterface( public boolean deleteApplicationInterface(AuthzToken authzToken, String appInterfaceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.deleteApplicationInterface(appInterfaceId); - registryClientPool.returnResource(regClient); + boolean result = airavataService.deleteApplicationInterface(appInterfaceId); return result; } catch (Exception e) { logger.error(appInterfaceId, "Error while deleting application interface...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while deleting application interface. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -3446,17 +2737,14 @@ public boolean deleteApplicationInterface(AuthzToken authzToken, String appInter public Map getAllApplicationInterfaceNames(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - Map result = regClient.getAllApplicationInterfaceNames(gatewayId); - registryClientPool.returnResource(regClient); + Map result = airavataService.getAllApplicationInterfaceNames(gatewayId); return result; } catch (Exception e) { logger.error("Error while retrieving application interfaces...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while retrieving application interfaces. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -3472,17 +2760,14 @@ public Map getAllApplicationInterfaceNames(AuthzToken authzToken public List getAllApplicationInterfaces(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - List result = regClient.getAllApplicationInterfaces(gatewayId); - registryClientPool.returnResource(regClient); + List result = airavataService.getAllApplicationInterfaces(gatewayId); return result; } catch (Exception e) { logger.error("Error while retrieving application interfaces...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while retrieving application interfaces. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -3499,17 +2784,14 @@ public List getAllApplicationInterfaces(AuthzTo public List getApplicationInputs(AuthzToken authzToken, String appInterfaceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - List result = regClient.getApplicationInputs(appInterfaceId); - registryClientPool.returnResource(regClient); + List result = airavataService.getApplicationInputs(appInterfaceId); return result; } catch (Exception e) { logger.error(appInterfaceId, "Error while retrieving application inputs...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while retrieving application inputs. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -3526,15 +2808,12 @@ public List getApplicationInputs(AuthzToken authzToken, Str public List getApplicationOutputs(AuthzToken authzToken, String appInterfaceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - List result = regClient.getApplicationOutputs(appInterfaceId); - registryClientPool.returnResource(regClient); + List result = airavataService.getApplicationOutputs(appInterfaceId); return result; } catch (Exception e) { AiravataSystemException exception = new AiravataSystemException(); exception.setMessage(e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -3553,17 +2832,20 @@ public List getApplicationOutputs(AuthzToken authzToken, S public Map getAvailableAppInterfaceComputeResources(AuthzToken authzToken, String appInterfaceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - Map result = regClient.getAvailableAppInterfaceComputeResources(appInterfaceId); - registryClientPool.returnResource(regClient); + Map result = airavataService.getAvailableAppInterfaceComputeResources(appInterfaceId); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(appInterfaceId, "Error while saving compute resource...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while saving compute resource. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { logger.error(appInterfaceId, "Error while saving compute resource...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while saving compute resource. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -3580,17 +2862,14 @@ public Map getAvailableAppInterfaceComputeResources(AuthzToken a public String registerComputeResource(AuthzToken authzToken, ComputeResourceDescription computeResourceDescription) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - String result = regClient.registerComputeResource(computeResourceDescription); - registryClientPool.returnResource(regClient); + String result = airavataService.registerComputeResource(computeResourceDescription); return result; } catch (Exception e) { logger.error("Error while saving compute resource...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while saving compute resource. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -3607,17 +2886,14 @@ public String registerComputeResource(AuthzToken authzToken, ComputeResourceDesc public ComputeResourceDescription getComputeResource(AuthzToken authzToken, String computeResourceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - ComputeResourceDescription result = regClient.getComputeResource(computeResourceId); - registryClientPool.returnResource(regClient); + ComputeResourceDescription result = airavataService.getComputeResource(computeResourceId); return result; } catch (Exception e) { logger.error(computeResourceId, "Error while retrieving compute resource...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while retrieving compute resource. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -3633,17 +2909,14 @@ public ComputeResourceDescription getComputeResource(AuthzToken authzToken, Stri public Map getAllComputeResourceNames(AuthzToken authzToken) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - Map result = regClient.getAllComputeResourceNames(); - registryClientPool.returnResource(regClient); + Map result = airavataService.getAllComputeResourceNames(); return result; } catch (Exception e) { logger.error("Error while retrieving compute resource...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while retrieving compute resource. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -3662,17 +2935,14 @@ public boolean updateComputeResource( AuthzToken authzToken, String computeResourceId, ComputeResourceDescription computeResourceDescription) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.updateComputeResource(computeResourceId, computeResourceDescription); - registryClientPool.returnResource(regClient); + boolean result = airavataService.updateComputeResource(computeResourceId, computeResourceDescription); return result; } catch (Exception e) { logger.error(computeResourceId, "Error while updating compute resource...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while updaing compute resource. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -3689,17 +2959,14 @@ public boolean updateComputeResource( public boolean deleteComputeResource(AuthzToken authzToken, String computeResourceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.deleteComputeResource(computeResourceId); - registryClientPool.returnResource(regClient); + boolean result = airavataService.deleteComputeResource(computeResourceId); return result; } catch (Exception e) { logger.error(computeResourceId, "Error while deleting compute resource...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while deleting compute resource. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -3717,17 +2984,14 @@ public boolean deleteComputeResource(AuthzToken authzToken, String computeResour public String registerStorageResource(AuthzToken authzToken, StorageResourceDescription storageResourceDescription) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - String result = regClient.registerStorageResource(storageResourceDescription); - registryClientPool.returnResource(regClient); + String result = airavataService.registerStorageResource(storageResourceDescription); return result; } catch (Exception e) { logger.error("Error while saving storage resource...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while saving storage resource. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -3745,17 +3009,14 @@ public String registerStorageResource(AuthzToken authzToken, StorageResourceDesc public StorageResourceDescription getStorageResource(AuthzToken authzToken, String storageResourceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - StorageResourceDescription result = regClient.getStorageResource(storageResourceId); - registryClientPool.returnResource(regClient); + StorageResourceDescription result = airavataService.getStorageResource(storageResourceId); return result; } catch (Exception e) { logger.error(storageResourceId, "Error while retrieving storage resource...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while retrieving storage resource. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -3772,17 +3033,14 @@ public StorageResourceDescription getStorageResource(AuthzToken authzToken, Stri public Map getAllStorageResourceNames(AuthzToken authzToken) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - Map result = regClient.getAllStorageResourceNames(); - registryClientPool.returnResource(regClient); + Map result = airavataService.getAllStorageResourceNames(); return result; } catch (Exception e) { logger.error("Error while retrieving storage resource...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while retrieving storage resource. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -3802,17 +3060,14 @@ public boolean updateStorageResource( AuthzToken authzToken, String storageResourceId, StorageResourceDescription storageResourceDescription) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.updateStorageResource(storageResourceId, storageResourceDescription); - registryClientPool.returnResource(regClient); + boolean result = airavataService.updateStorageResource(storageResourceId, storageResourceDescription); return result; } catch (Exception e) { logger.error(storageResourceId, "Error while updating storage resource...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while updaing storage resource. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -3830,10 +3085,8 @@ public boolean updateStorageResource( public boolean deleteStorageResource(AuthzToken authzToken, String storageResourceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.deleteStorageResource(storageResourceId); - registryClientPool.returnResource(regClient); + boolean result = airavataService.deleteStorageResource(storageResourceId); return result; } catch (Exception e) { logger.error(storageResourceId, "Error while deleting storage resource...", e); @@ -4011,11 +3264,20 @@ public String addLocalSubmissionDetails( AuthzToken authzToken, String computeResourceId, int priorityOrder, LOCALSubmission localSubmission) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - String result = regClient.addLocalSubmissionDetails(computeResourceId, priorityOrder, localSubmission); - registryClientPool.returnResource(regClient); + String result = airavataService.addLocalSubmissionDetails(computeResourceId, priorityOrder, localSubmission); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error( + computeResourceId, + "Error while adding job submission interface to resource compute resource...", + e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while adding job submission interface to resource compute resource. More info : " + + e.getMessage()); + throw exception; } catch (Exception e) { logger.error( computeResourceId, @@ -4026,7 +3288,6 @@ public String addLocalSubmissionDetails( exception.setMessage( "Error while adding job submission interface to resource compute resource. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -4045,22 +3306,30 @@ public boolean updateLocalSubmissionDetails( AuthzToken authzToken, String jobSubmissionInterfaceId, LOCALSubmission localSubmission) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.updateLocalSubmissionDetails(jobSubmissionInterfaceId, localSubmission); - registryClientPool.returnResource(regClient); + boolean result = airavataService.updateLocalSubmissionDetails(jobSubmissionInterfaceId, localSubmission); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error( + jobSubmissionInterfaceId, + "Error while updating job submission interface to resource compute resource...", + e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while updating job submission interface to resource compute resource. More info : " + + e.getMessage()); + throw exception; } catch (Exception e) { logger.error( jobSubmissionInterfaceId, - "Error while adding job submission interface to resource compute resource...", + "Error while updating job submission interface to resource compute resource...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage( - "Error while adding job submission interface to resource compute resource. More info : " + "Error while updating job submission interface to resource compute resource. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -4070,18 +3339,22 @@ public boolean updateLocalSubmissionDetails( public LOCALSubmission getLocalJobSubmission(AuthzToken authzToken, String jobSubmissionId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - LOCALSubmission result = regClient.getLocalJobSubmission(jobSubmissionId); - registryClientPool.returnResource(regClient); + LOCALSubmission result = airavataService.getLocalJobSubmission(jobSubmissionId); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + String errorMsg = "Error while retrieving local job submission interface to resource compute resource..."; + logger.error(jobSubmissionId, errorMsg, e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(errorMsg + e.getMessage()); + throw exception; } catch (Exception e) { String errorMsg = "Error while retrieving local job submission interface to resource compute resource..."; logger.error(jobSubmissionId, errorMsg, e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(errorMsg + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -4102,11 +3375,20 @@ public String addSSHJobSubmissionDetails( AuthzToken authzToken, String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - String result = regClient.addSSHJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); - registryClientPool.returnResource(regClient); + String result = airavataService.addSSHJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error( + computeResourceId, + "Error while adding job submission interface to resource compute resource...", + e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while adding job submission interface to resource compute resource. More info : " + + e.getMessage()); + throw exception; } catch (Exception e) { logger.error( computeResourceId, @@ -4117,7 +3399,6 @@ public String addSSHJobSubmissionDetails( exception.setMessage( "Error while adding job submission interface to resource compute resource. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -4138,12 +3419,21 @@ public String addSSHForkJobSubmissionDetails( AuthzToken authzToken, String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { String result = - regClient.addSSHForkJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); - registryClientPool.returnResource(regClient); + airavataService.addSSHForkJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error( + computeResourceId, + "Error while adding job submission interface to resource compute resource...", + e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while adding job submission interface to resource compute resource. More info : " + + e.getMessage()); + throw exception; } catch (Exception e) { logger.error( computeResourceId, @@ -4154,7 +3444,6 @@ public String addSSHForkJobSubmissionDetails( exception.setMessage( "Error while adding job submission interface to resource compute resource. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -4164,18 +3453,22 @@ public String addSSHForkJobSubmissionDetails( public SSHJobSubmission getSSHJobSubmission(AuthzToken authzToken, String jobSubmissionId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - SSHJobSubmission result = regClient.getSSHJobSubmission(jobSubmissionId); - registryClientPool.returnResource(regClient); + SSHJobSubmission result = airavataService.getSSHJobSubmission(jobSubmissionId); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + String errorMsg = "Error while retrieving SSH job submission interface to resource compute resource..."; + logger.error(jobSubmissionId, errorMsg, e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(errorMsg + e.getMessage()); + throw exception; } catch (Exception e) { String errorMsg = "Error while retrieving SSH job submission interface to resource compute resource..."; logger.error(jobSubmissionId, errorMsg, e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(errorMsg + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -4196,12 +3489,21 @@ public String addCloudJobSubmissionDetails( AuthzToken authzToken, String computeResourceId, int priorityOrder, CloudJobSubmission cloudJobSubmission) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { String result = - regClient.addCloudJobSubmissionDetails(computeResourceId, priorityOrder, cloudJobSubmission); - registryClientPool.returnResource(regClient); + airavataService.addCloudJobSubmissionDetails(computeResourceId, priorityOrder, cloudJobSubmission); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error( + computeResourceId, + "Error while adding job submission interface to resource compute resource...", + e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while adding job submission interface to resource compute resource. More info : " + + e.getMessage()); + throw exception; } catch (Exception e) { logger.error( computeResourceId, @@ -4212,7 +3514,6 @@ public String addCloudJobSubmissionDetails( exception.setMessage( "Error while adding job submission interface to resource compute resource. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -4222,18 +3523,22 @@ public String addCloudJobSubmissionDetails( public CloudJobSubmission getCloudJobSubmission(AuthzToken authzToken, String jobSubmissionId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - CloudJobSubmission result = regClient.getCloudJobSubmission(jobSubmissionId); - registryClientPool.returnResource(regClient); + CloudJobSubmission result = airavataService.getCloudJobSubmission(jobSubmissionId); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + String errorMsg = "Error while retrieving Cloud job submission interface to resource compute resource..."; + logger.error(jobSubmissionId, errorMsg, e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(errorMsg + e.getMessage()); + throw exception; } catch (Exception e) { String errorMsg = "Error while retrieving Cloud job submission interface to resource compute resource..."; logger.error(jobSubmissionId, errorMsg, e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(errorMsg + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -4247,12 +3552,18 @@ public String addUNICOREJobSubmissionDetails( UnicoreJobSubmission unicoreJobSubmission) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { String result = - regClient.addUNICOREJobSubmissionDetails(computeResourceId, priorityOrder, unicoreJobSubmission); - registryClientPool.returnResource(regClient); + airavataService.addUNICOREJobSubmissionDetails(computeResourceId, priorityOrder, unicoreJobSubmission); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error("Error while adding job submission interface to resource compute resource...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while adding job submission interface to resource compute resource. More info : " + + e.getMessage()); + throw exception; } catch (Exception e) { logger.error("Error while adding job submission interface to resource compute resource...", e); AiravataSystemException exception = new AiravataSystemException(); @@ -4260,7 +3571,6 @@ public String addUNICOREJobSubmissionDetails( exception.setMessage( "Error while adding job submission interface to resource compute resource. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -4270,18 +3580,22 @@ public String addUNICOREJobSubmissionDetails( public UnicoreJobSubmission getUnicoreJobSubmission(AuthzToken authzToken, String jobSubmissionId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - UnicoreJobSubmission result = regClient.getUnicoreJobSubmission(jobSubmissionId); - registryClientPool.returnResource(regClient); + UnicoreJobSubmission result = airavataService.getUnicoreJobSubmission(jobSubmissionId); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + String errorMsg = "Error while retrieving Unicore job submission interface to resource compute resource..."; + logger.error(jobSubmissionId, errorMsg, e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(errorMsg + e.getMessage()); + throw exception; } catch (Exception e) { String errorMsg = "Error while retrieving Unicore job submission interface to resource compute resource..."; logger.error(jobSubmissionId, errorMsg, e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(errorMsg + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -4300,22 +3614,30 @@ public boolean updateSSHJobSubmissionDetails( AuthzToken authzToken, String jobSubmissionInterfaceId, SSHJobSubmission sshJobSubmission) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.updateSSHJobSubmissionDetails(jobSubmissionInterfaceId, sshJobSubmission); - registryClientPool.returnResource(regClient); + boolean result = airavataService.updateSSHJobSubmissionDetails(jobSubmissionInterfaceId, sshJobSubmission); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error( + jobSubmissionInterfaceId, + "Error while updating job submission interface to resource compute resource...", + e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while updating job submission interface to resource compute resource. More info : " + + e.getMessage()); + throw exception; } catch (Exception e) { logger.error( jobSubmissionInterfaceId, - "Error while adding job submission interface to resource compute resource...", + "Error while updating job submission interface to resource compute resource...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage( - "Error while adding job submission interface to resource compute resource. More info : " + "Error while updating job submission interface to resource compute resource. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -4334,22 +3656,30 @@ public boolean updateCloudJobSubmissionDetails( AuthzToken authzToken, String jobSubmissionInterfaceId, CloudJobSubmission cloudJobSubmission) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.updateCloudJobSubmissionDetails(jobSubmissionInterfaceId, cloudJobSubmission); - registryClientPool.returnResource(regClient); + boolean result = airavataService.updateCloudJobSubmissionDetails(jobSubmissionInterfaceId, cloudJobSubmission); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error( + jobSubmissionInterfaceId, + "Error while updating job submission interface to resource compute resource...", + e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while updating job submission interface to resource compute resource. More info : " + + e.getMessage()); + throw exception; } catch (Exception e) { logger.error( jobSubmissionInterfaceId, - "Error while adding job submission interface to resource compute resource...", + "Error while updating job submission interface to resource compute resource...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage( - "Error while adding job submission interface to resource compute resource. More info : " + "Error while updating job submission interface to resource compute resource. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -4360,23 +3690,31 @@ public boolean updateUnicoreJobSubmissionDetails( AuthzToken authzToken, String jobSubmissionInterfaceId, UnicoreJobSubmission unicoreJobSubmission) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { boolean result = - regClient.updateUnicoreJobSubmissionDetails(jobSubmissionInterfaceId, unicoreJobSubmission); - registryClientPool.returnResource(regClient); + airavataService.updateUnicoreJobSubmissionDetails(jobSubmissionInterfaceId, unicoreJobSubmission); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error( + jobSubmissionInterfaceId, + "Error while updating job submission interface to resource compute resource...", + e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while updating job submission interface to resource compute resource. More info : " + + e.getMessage()); + throw exception; } catch (Exception e) { logger.error( jobSubmissionInterfaceId, - "Error while adding job submission interface to resource compute resource...", + "Error while updating job submission interface to resource compute resource...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage( - "Error while adding job submission interface to resource compute resource. More info : " + "Error while updating job submission interface to resource compute resource. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -4401,18 +3739,22 @@ public String addLocalDataMovementDetails( LOCALDataMovement localDataMovement) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - String result = regClient.addLocalDataMovementDetails(resourceId, dmType, priorityOrder, localDataMovement); - registryClientPool.returnResource(regClient); + String result = airavataService.addLocalDataMovementDetails(resourceId, dmType, priorityOrder, localDataMovement); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(resourceId, "Error while adding data movement interface to resource resource...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while adding data movement interface to resource. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { logger.error(resourceId, "Error while adding data movement interface to resource resource...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage( "Error while adding data movement interface to resource. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -4431,17 +3773,20 @@ public boolean updateLocalDataMovementDetails( AuthzToken authzToken, String dataMovementInterfaceId, LOCALDataMovement localDataMovement) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.updateLocalDataMovementDetails(dataMovementInterfaceId, localDataMovement); - registryClientPool.returnResource(regClient); + boolean result = airavataService.updateLocalDataMovementDetails(dataMovementInterfaceId, localDataMovement); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(dataMovementInterfaceId, "Error while updating local data movement interface..", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while updating local data movement interface. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { logger.error(dataMovementInterfaceId, "Error while updating local data movement interface..", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while updating local data movement interface. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -4451,18 +3796,22 @@ public boolean updateLocalDataMovementDetails( public LOCALDataMovement getLocalDataMovement(AuthzToken authzToken, String dataMovementId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - LOCALDataMovement result = regClient.getLocalDataMovement(dataMovementId); - registryClientPool.returnResource(regClient); + LOCALDataMovement result = airavataService.getLocalDataMovement(dataMovementId); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + String errorMsg = "Error while retrieving local data movement interface to resource compute resource..."; + logger.error(dataMovementId, errorMsg, e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(errorMsg + e.getMessage()); + throw exception; } catch (Exception e) { String errorMsg = "Error while retrieving local data movement interface to resource compute resource..."; logger.error(dataMovementId, errorMsg, e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(errorMsg + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -4483,18 +3832,22 @@ public String addSCPDataMovementDetails( AuthzToken authzToken, String resourceId, DMType dmType, int priorityOrder, SCPDataMovement scpDataMovement) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - String result = regClient.addSCPDataMovementDetails(resourceId, dmType, priorityOrder, scpDataMovement); - registryClientPool.returnResource(regClient); + String result = airavataService.addSCPDataMovementDetails(resourceId, dmType, priorityOrder, scpDataMovement); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(resourceId, "Error while adding data movement interface to resource compute resource...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while adding data movement interface to resource compute resource. More info : " + + e.getMessage()); + throw exception; } catch (Exception e) { logger.error(resourceId, "Error while adding data movement interface to resource compute resource...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while adding data movement interface to resource compute resource. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -4514,22 +3867,30 @@ public boolean updateSCPDataMovementDetails( AuthzToken authzToken, String dataMovementInterfaceId, SCPDataMovement scpDataMovement) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.updateSCPDataMovementDetails(dataMovementInterfaceId, scpDataMovement); - registryClientPool.returnResource(regClient); + boolean result = airavataService.updateSCPDataMovementDetails(dataMovementInterfaceId, scpDataMovement); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error( + dataMovementInterfaceId, + "Error while updating data movement interface to resource compute resource...", + e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while updating data movement interface to resource compute resource. More info : " + + e.getMessage()); + throw exception; } catch (Exception e) { logger.error( dataMovementInterfaceId, - "Error while adding job submission interface to resource compute resource...", + "Error while updating data movement interface to resource compute resource...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage( - "Error while adding job submission interface to resource compute resource. More info : " + "Error while updating data movement interface to resource compute resource. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -4539,18 +3900,22 @@ public boolean updateSCPDataMovementDetails( public SCPDataMovement getSCPDataMovement(AuthzToken authzToken, String dataMovementId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - SCPDataMovement result = regClient.getSCPDataMovement(dataMovementId); - registryClientPool.returnResource(regClient); + SCPDataMovement result = airavataService.getSCPDataMovement(dataMovementId); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + String errorMsg = "Error while retrieving SCP data movement interface to resource compute resource..."; + logger.error(dataMovementId, errorMsg, e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(errorMsg + e.getMessage()); + throw exception; } catch (Exception e) { String errorMsg = "Error while retrieving SCP data movement interface to resource compute resource..."; logger.error(dataMovementId, errorMsg, e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(errorMsg + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -4565,19 +3930,23 @@ public String addUnicoreDataMovementDetails( UnicoreDataMovement unicoreDataMovement) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { String result = - regClient.addUnicoreDataMovementDetails(resourceId, dmType, priorityOrder, unicoreDataMovement); - registryClientPool.returnResource(regClient); + airavataService.addUnicoreDataMovementDetails(resourceId, dmType, priorityOrder, unicoreDataMovement); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(resourceId, "Error while adding data movement interface to resource compute resource...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while adding data movement interface to resource compute resource. More info : " + + e.getMessage()); + throw exception; } catch (Exception e) { logger.error(resourceId, "Error while adding data movement interface to resource compute resource...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while adding data movement interface to resource compute resource. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -4588,11 +3957,17 @@ public boolean updateUnicoreDataMovementDetails( AuthzToken authzToken, String dataMovementInterfaceId, UnicoreDataMovement unicoreDataMovement) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.updateUnicoreDataMovementDetails(dataMovementInterfaceId, unicoreDataMovement); - registryClientPool.returnResource(regClient); + boolean result = airavataService.updateUnicoreDataMovementDetails(dataMovementInterfaceId, unicoreDataMovement); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error( + dataMovementInterfaceId, "Error while updating unicore data movement to compute resource...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while updating unicore data movement to compute resource. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { logger.error( dataMovementInterfaceId, "Error while updating unicore data movement to compute resource...", e); @@ -4600,7 +3975,6 @@ public boolean updateUnicoreDataMovementDetails( exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage( "Error while updating unicore data movement to compute resource. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -4610,18 +3984,22 @@ public boolean updateUnicoreDataMovementDetails( public UnicoreDataMovement getUnicoreDataMovement(AuthzToken authzToken, String dataMovementId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - UnicoreDataMovement result = regClient.getUnicoreDataMovement(dataMovementId); - registryClientPool.returnResource(regClient); + UnicoreDataMovement result = airavataService.getUnicoreDataMovement(dataMovementId); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + String errorMsg = "Error while retrieving UNICORE data movement interface..."; + logger.error(dataMovementId, errorMsg, e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(errorMsg + e.getMessage()); + throw exception; } catch (Exception e) { String errorMsg = "Error while retrieving UNICORE data movement interface..."; logger.error(dataMovementId, errorMsg, e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(errorMsg + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -4646,12 +4024,18 @@ public String addGridFTPDataMovementDetails( GridFTPDataMovement gridFTPDataMovement) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - String result = regClient.addGridFTPDataMovementDetails( + String result = airavataService.addGridFTPDataMovementDetails( computeResourceId, dmType, priorityOrder, gridFTPDataMovement); - registryClientPool.returnResource(regClient); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error( + computeResourceId, "Error while adding data movement interface to resource compute resource...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while adding data movement interface to resource compute resource. More info : " + + e.getMessage()); + throw exception; } catch (Exception e) { logger.error( computeResourceId, "Error while adding data movement interface to resource compute resource...", e); @@ -4659,7 +4043,6 @@ public String addGridFTPDataMovementDetails( exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while adding data movement interface to resource compute resource. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -4679,22 +4062,30 @@ public boolean updateGridFTPDataMovementDetails( AuthzToken authzToken, String dataMovementInterfaceId, GridFTPDataMovement gridFTPDataMovement) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.updateGridFTPDataMovementDetails(dataMovementInterfaceId, gridFTPDataMovement); - registryClientPool.returnResource(regClient); + boolean result = airavataService.updateGridFTPDataMovementDetails(dataMovementInterfaceId, gridFTPDataMovement); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error( + dataMovementInterfaceId, + "Error while updating GridFTP data movement interface to resource compute resource...", + e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while updating GridFTP data movement interface to resource compute resource. More info : " + + e.getMessage()); + throw exception; } catch (Exception e) { logger.error( dataMovementInterfaceId, - "Error while adding job submission interface to resource compute resource...", + "Error while updating GridFTP data movement interface to resource compute resource...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage( - "Error while adding job submission interface to resource compute resource. More info : " + "Error while updating GridFTP data movement interface to resource compute resource. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -4704,18 +4095,22 @@ public boolean updateGridFTPDataMovementDetails( public GridFTPDataMovement getGridFTPDataMovement(AuthzToken authzToken, String dataMovementId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - GridFTPDataMovement result = regClient.getGridFTPDataMovement(dataMovementId); - registryClientPool.returnResource(regClient); + GridFTPDataMovement result = airavataService.getGridFTPDataMovement(dataMovementId); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + String errorMsg = "Error while retrieving GridFTP data movement interface to resource compute resource..."; + logger.error(dataMovementId, errorMsg, e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(errorMsg + e.getMessage()); + throw exception; } catch (Exception e) { String errorMsg = "Error while retrieving GridFTP data movement interface to resource compute resource..."; logger.error(dataMovementId, errorMsg, e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(errorMsg + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -4797,17 +4192,20 @@ public boolean deleteJobSubmissionInterface( AuthzToken authzToken, String computeResourceId, String jobSubmissionInterfaceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.deleteJobSubmissionInterface(computeResourceId, jobSubmissionInterfaceId); - registryClientPool.returnResource(regClient); + boolean result = airavataService.deleteJobSubmissionInterface(computeResourceId, jobSubmissionInterfaceId); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(jobSubmissionInterfaceId, "Error while deleting job submission interface...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while deleting job submission interface. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { logger.error(jobSubmissionInterfaceId, "Error while deleting job submission interface...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while deleting job submission interface. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -4825,17 +4223,20 @@ public boolean deleteDataMovementInterface( AuthzToken authzToken, String resourceId, String dataMovementInterfaceId, DMType dmType) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.deleteDataMovementInterface(resourceId, dataMovementInterfaceId, dmType); - registryClientPool.returnResource(regClient); + boolean result = airavataService.deleteDataMovementInterface(resourceId, dataMovementInterfaceId, dmType); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(dataMovementInterfaceId, "Error while deleting data movement interface...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while deleting data movement interface. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { logger.error(dataMovementInterfaceId, "Error while deleting data movement interface...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while deleting data movement interface. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -4845,17 +4246,20 @@ public boolean deleteDataMovementInterface( public String registerResourceJobManager(AuthzToken authzToken, ResourceJobManager resourceJobManager) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - String result = regClient.registerResourceJobManager(resourceJobManager); - registryClientPool.returnResource(regClient); + String result = airavataService.registerResourceJobManager(resourceJobManager); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(resourceJobManager.getResourceJobManagerId(), "Error while adding resource job manager...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while adding resource job manager. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { logger.error(resourceJobManager.getResourceJobManagerId(), "Error while adding resource job manager...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while adding resource job manager. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -4866,17 +4270,20 @@ public boolean updateResourceJobManager( AuthzToken authzToken, String resourceJobManagerId, ResourceJobManager updatedResourceJobManager) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.updateResourceJobManager(resourceJobManagerId, updatedResourceJobManager); - registryClientPool.returnResource(regClient); + boolean result = airavataService.updateResourceJobManager(resourceJobManagerId, updatedResourceJobManager); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(resourceJobManagerId, "Error while updating resource job manager...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while updating resource job manager. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { logger.error(resourceJobManagerId, "Error while updating resource job manager...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while updating resource job manager. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -4886,17 +4293,20 @@ public boolean updateResourceJobManager( public ResourceJobManager getResourceJobManager(AuthzToken authzToken, String resourceJobManagerId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - ResourceJobManager result = regClient.getResourceJobManager(resourceJobManagerId); - registryClientPool.returnResource(regClient); + ResourceJobManager result = airavataService.getResourceJobManager(resourceJobManagerId); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(resourceJobManagerId, "Error while retrieving resource job manager...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving resource job manager. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { logger.error(resourceJobManagerId, "Error while retrieving resource job manager...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while retrieving resource job manager. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -4906,17 +4316,20 @@ public ResourceJobManager getResourceJobManager(AuthzToken authzToken, String re public boolean deleteResourceJobManager(AuthzToken authzToken, String resourceJobManagerId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.deleteResourceJobManager(resourceJobManagerId); - registryClientPool.returnResource(regClient); + boolean result = airavataService.deleteResourceJobManager(resourceJobManagerId); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(resourceJobManagerId, "Error while deleting resource job manager...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while deleting resource job manager. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { logger.error(resourceJobManagerId, "Error while deleting resource job manager...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while deleting resource job manager. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -4926,17 +4339,20 @@ public boolean deleteResourceJobManager(AuthzToken authzToken, String resourceJo public boolean deleteBatchQueue(AuthzToken authzToken, String computeResourceId, String queueName) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.deleteBatchQueue(computeResourceId, queueName); - registryClientPool.returnResource(regClient); + boolean result = airavataService.deleteBatchQueue(computeResourceId, queueName); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(computeResourceId, "Error while deleting batch queue...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while deleting batch queue. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { logger.error(computeResourceId, "Error while deleting batch queue...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while deleting batch queue. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -4955,17 +4371,20 @@ public boolean deleteBatchQueue(AuthzToken authzToken, String computeResourceId, public String registerGatewayResourceProfile(AuthzToken authzToken, GatewayResourceProfile gatewayResourceProfile) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - String result = regClient.registerGatewayResourceProfile(gatewayResourceProfile); - registryClientPool.returnResource(regClient); + String result = airavataService.registerGatewayResourceProfile(gatewayResourceProfile); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error("Error while registering gateway resource profile...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while registering gateway resource profile. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { logger.error("Error while registering gateway resource profile...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while registering gateway resource profile. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -4982,17 +4401,14 @@ public String registerGatewayResourceProfile(AuthzToken authzToken, GatewayResou public GatewayResourceProfile getGatewayResourceProfile(AuthzToken authzToken, String gatewayID) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - GatewayResourceProfile result = regClient.getGatewayResourceProfile(gatewayID); - registryClientPool.returnResource(regClient); + GatewayResourceProfile result = airavataService.getGatewayResourceProfile(gatewayID); return result; } catch (Exception e) { logger.error(gatewayID, "Error while retrieving gateway resource profile...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while retrieving gateway resource profile. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -5009,17 +4425,14 @@ public GatewayResourceProfile getGatewayResourceProfile(AuthzToken authzToken, S @SecurityCheck public boolean updateGatewayResourceProfile( AuthzToken authzToken, String gatewayID, GatewayResourceProfile gatewayResourceProfile) throws TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.updateGatewayResourceProfile(gatewayID, gatewayResourceProfile); - registryClientPool.returnResource(regClient); + boolean result = airavataService.updateGatewayResourceProfile(gatewayID, gatewayResourceProfile); return result; } catch (Exception e) { logger.error(gatewayID, "Error while updating gateway resource profile...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while updating gateway resource profile. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -5034,17 +4447,14 @@ public boolean updateGatewayResourceProfile( @Override @SecurityCheck public boolean deleteGatewayResourceProfile(AuthzToken authzToken, String gatewayID) throws TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.deleteGatewayResourceProfile(gatewayID); - registryClientPool.returnResource(regClient); + boolean result = airavataService.deleteGatewayResourceProfile(gatewayID); return result; } catch (Exception e) { logger.error(gatewayID, "Error while removing gateway resource profile...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while removing gateway resource profile. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -5068,19 +4478,23 @@ public boolean addGatewayComputeResourcePreference( ComputeResourcePreference computeResourcePreference) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.addGatewayComputeResourcePreference( + boolean result = airavataService.addGatewayComputeResourcePreference( gatewayID, computeResourceId, computeResourcePreference); - registryClientPool.returnResource(regClient); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(gatewayID, "Error while registering gateway resource profile preference...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while registering gateway resource profile preference. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { logger.error(gatewayID, "Error while registering gateway resource profile preference...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage( "Error while registering gateway resource profile preference. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -5091,18 +4505,22 @@ public boolean addGatewayStoragePreference( AuthzToken authzToken, String gatewayID, String storageResourceId, StoragePreference dataStoragePreference) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.addGatewayStoragePreference(gatewayID, storageResourceId, dataStoragePreference); - registryClientPool.returnResource(regClient); + boolean result = airavataService.addGatewayStoragePreference(gatewayID, storageResourceId, dataStoragePreference); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(gatewayID, "Error while registering gateway resource profile preference...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while registering gateway resource profile preference. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { logger.error(gatewayID, "Error while registering gateway resource profile preference...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage( "Error while registering gateway resource profile preference. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -5121,19 +4539,23 @@ public ComputeResourcePreference getGatewayComputeResourcePreference( AuthzToken authzToken, String gatewayID, String computeResourceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { ComputeResourcePreference result = - regClient.getGatewayComputeResourcePreference(gatewayID, computeResourceId); - registryClientPool.returnResource(regClient); + airavataService.getGatewayComputeResourcePreference(gatewayID, computeResourceId); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(gatewayID, "Error while reading gateway compute resource preference...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while reading gateway compute resource preference. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { logger.error(gatewayID, "Error while reading gateway compute resource preference...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage( "Error while reading gateway compute resource preference. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -5143,17 +4565,20 @@ public ComputeResourcePreference getGatewayComputeResourcePreference( public StoragePreference getGatewayStoragePreference(AuthzToken authzToken, String gatewayID, String storageId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - StoragePreference result = regClient.getGatewayStoragePreference(gatewayID, storageId); - registryClientPool.returnResource(regClient); + StoragePreference result = airavataService.getGatewayStoragePreference(gatewayID, storageId); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(gatewayID, "Error while reading gateway data storage preference...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while reading gateway data storage preference. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { logger.error(gatewayID, "Error while reading gateway data storage preference...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while reading gateway data storage preference. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -5171,18 +4596,22 @@ public List getAllGatewayComputeResourcePreferences( AuthzToken authzToken, String gatewayID) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - List result = regClient.getAllGatewayComputeResourcePreferences(gatewayID); - registryClientPool.returnResource(regClient); + List result = airavataService.getAllGatewayComputeResourcePreferences(gatewayID); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(gatewayID, "Error while reading gateway compute resource preferences...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while reading gateway compute resource preferences. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { logger.error(gatewayID, "Error while reading gateway compute resource preferences...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage( "Error while reading gateway compute resource preferences. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -5192,17 +4621,20 @@ public List getAllGatewayComputeResourcePreferences( public List getAllGatewayStoragePreferences(AuthzToken authzToken, String gatewayID) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - List result = regClient.getAllGatewayStoragePreferences(gatewayID); - registryClientPool.returnResource(regClient); + List result = airavataService.getAllGatewayStoragePreferences(gatewayID); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(gatewayID, "Error while reading gateway data storage preferences...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while reading gateway data storage preferences. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { logger.error(gatewayID, "Error while reading gateway data storage preferences...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while reading gateway data storage preferences. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -5212,16 +4644,18 @@ public List getAllGatewayStoragePreferences(AuthzToken authzT public List getAllGatewayResourceProfiles(AuthzToken authzToken) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - List result = regClient.getAllGatewayResourceProfiles(); - registryClientPool.returnResource(regClient); + List result = airavataService.getAllGatewayResourceProfiles(); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while reading retrieving all gateway profiles. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while reading retrieving all gateway profiles. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -5244,19 +4678,23 @@ public boolean updateGatewayComputeResourcePreference( ComputeResourcePreference computeResourcePreference) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.updateGatewayComputeResourcePreference( + boolean result = airavataService.updateGatewayComputeResourcePreference( gatewayID, computeResourceId, computeResourcePreference); - registryClientPool.returnResource(regClient); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(gatewayID, "Error while updating gateway compute resource preference...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while updating gateway compute resource preference. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { - logger.error(gatewayID, "Error while reading gateway compute resource preference...", e); + logger.error(gatewayID, "Error while updating gateway compute resource preference...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage( "Error while updating gateway compute resource preference. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -5267,17 +4705,20 @@ public boolean updateGatewayStoragePreference( AuthzToken authzToken, String gatewayID, String storageId, StoragePreference dataStoragePreference) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.updateGatewayStoragePreference(gatewayID, storageId, dataStoragePreference); - registryClientPool.returnResource(regClient); + boolean result = airavataService.updateGatewayStoragePreference(gatewayID, storageId, dataStoragePreference); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(gatewayID, "Error while updating gateway data storage preference...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while updating gateway data storage preference. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { - logger.error(gatewayID, "Error while reading gateway data storage preference...", e); + logger.error(gatewayID, "Error while updating gateway data storage preference...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while updating gateway data storage preference. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -5296,18 +4737,22 @@ public boolean deleteGatewayComputeResourcePreference( AuthzToken authzToken, String gatewayID, String computeResourceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.deleteGatewayComputeResourcePreference(gatewayID, computeResourceId); - registryClientPool.returnResource(regClient); + boolean result = airavataService.deleteGatewayComputeResourcePreference(gatewayID, computeResourceId); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(gatewayID, "Error while deleting gateway compute resource preference...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while deleting gateway compute resource preference. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { - logger.error(gatewayID, "Error while reading gateway compute resource preference...", e); + logger.error(gatewayID, "Error while deleting gateway compute resource preference...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage( - "Error while updating gateway compute resource preference. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); + "Error while deleting gateway compute resource preference. More info : " + e.getMessage()); throw exception; } } @@ -5317,17 +4762,20 @@ public boolean deleteGatewayComputeResourcePreference( public boolean deleteGatewayStoragePreference(AuthzToken authzToken, String gatewayID, String storageId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.deleteGatewayStoragePreference(gatewayID, storageId); - registryClientPool.returnResource(regClient); + boolean result = airavataService.deleteGatewayStoragePreference(gatewayID, storageId); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(gatewayID, "Error while deleting gateway data storage preference...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while deleting gateway data storage preference. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { - logger.error(gatewayID, "Error while reading gateway data storage preference...", e); + logger.error(gatewayID, "Error while deleting gateway data storage preference...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating gateway data storage preference. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); + exception.setMessage("Error while deleting gateway data storage preference. More info : " + e.getMessage()); throw exception; } } @@ -5474,17 +4922,20 @@ public UserComputeResourcePreference setupUserComputeResourcePreferencesForSSH( public String registerUserResourceProfile(AuthzToken authzToken, UserResourceProfile userResourceProfile) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - String result = regClient.registerUserResourceProfile(userResourceProfile); - registryClientPool.returnResource(regClient); + String result = airavataService.registerUserResourceProfile(userResourceProfile); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error("Error while registering user resource profile...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while registering user resource profile. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { logger.error("Error while registering user resource profile...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while registering user resource profile. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -5494,18 +4945,22 @@ public String registerUserResourceProfile(AuthzToken authzToken, UserResourcePro public boolean isUserResourceProfileExists(AuthzToken authzToken, String userId, String gatewayID) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.isUserResourceProfileExists(userId, gatewayID); - registryClientPool.returnResource(regClient); + boolean result = airavataService.isUserResourceProfileExists(userId, gatewayID); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error("Error while checking existence of user resource profile for " + userId, e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while checking existence of user resource profile. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { logger.error("Error while checking existence of user resource profile for " + userId, e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage( "Error while checking existence of user resource profile. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -5525,17 +4980,14 @@ public boolean isUserResourceProfileExists(AuthzToken authzToken, String userId, public UserResourceProfile getUserResourceProfile(AuthzToken authzToken, String userId, String gatewayID) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - UserResourceProfile result = regClient.getUserResourceProfile(userId, gatewayID); - registryClientPool.returnResource(regClient); + UserResourceProfile result = airavataService.getUserResourceProfile(userId, gatewayID); return result; } catch (Exception e) { logger.error("Error while retrieving user resource profile for " + userId, e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while retrieving user resource profile. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -5554,17 +5006,14 @@ public UserResourceProfile getUserResourceProfile(AuthzToken authzToken, String public boolean updateUserResourceProfile( AuthzToken authzToken, String userId, String gatewayID, UserResourceProfile userResourceProfile) throws TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.updateUserResourceProfile(userId, gatewayID, userResourceProfile); - registryClientPool.returnResource(regClient); + boolean result = airavataService.updateUserResourceProfile(userId, gatewayID, userResourceProfile); return result; } catch (Exception e) { logger.error(userId, "Error while updating user resource profile...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while updating user resource profile. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -5580,17 +5029,14 @@ public boolean updateUserResourceProfile( @Override @SecurityCheck public boolean deleteUserResourceProfile(AuthzToken authzToken, String userId, String gatewayID) throws TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.deleteUserResourceProfile(userId, gatewayID); - registryClientPool.returnResource(regClient); + boolean result = airavataService.deleteUserResourceProfile(userId, gatewayID); return result; } catch (Exception e) { logger.error(userId, "Error while removing user resource profile...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while removing user resource profile. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -5616,19 +5062,23 @@ public boolean addUserComputeResourcePreference( UserComputeResourcePreference userComputeResourcePreference) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.addUserComputeResourcePreference( + boolean result = airavataService.addUserComputeResourcePreference( userId, gatewayID, userComputeResourceId, userComputeResourcePreference); - registryClientPool.returnResource(regClient); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(userId, "Error while registering user resource profile preference...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while registering user resource profile preference. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { logger.error(userId, "Error while registering user resource profile preference...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage( "Error while registering user resource profile preference. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -5643,18 +5093,21 @@ public boolean addUserStoragePreference( UserStoragePreference dataStoragePreference) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { boolean result = - regClient.addUserStoragePreference(userId, gatewayID, userStorageResourceId, dataStoragePreference); - registryClientPool.returnResource(regClient); + airavataService.addUserStoragePreference(userId, gatewayID, userStorageResourceId, dataStoragePreference); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(userId, "Error while registering user storage preference...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while registering user storage preference. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { logger.error(userId, "Error while registering user storage preference...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while registering user storage preference. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -5674,18 +5127,21 @@ public UserComputeResourcePreference getUserComputeResourcePreference( AuthzToken authzToken, String userId, String gatewayID, String userComputeResourceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { UserComputeResourcePreference result = - regClient.getUserComputeResourcePreference(userId, gatewayID, userComputeResourceId); - registryClientPool.returnResource(regClient); + airavataService.getUserComputeResourcePreference(userId, gatewayID, userComputeResourceId); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(userId, "Error while reading user compute resource preference...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while reading user compute resource preference. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { logger.error(userId, "Error while reading user compute resource preference...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while reading user compute resource preference. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -5696,17 +5152,20 @@ public UserStoragePreference getUserStoragePreference( AuthzToken authzToken, String userId, String gatewayID, String userStorageId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - UserStoragePreference result = regClient.getUserStoragePreference(userId, gatewayID, userStorageId); - registryClientPool.returnResource(regClient); + UserStoragePreference result = airavataService.getUserStoragePreference(userId, gatewayID, userStorageId); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(userId, "Error while reading user data storage preference...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while reading user data storage preference. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { logger.error(userId, "Error while reading user data storage preference...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while reading user data storage preference. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -5725,19 +5184,23 @@ public List getAllUserComputeResourcePreferences( AuthzToken authzToken, String userId, String gatewayID) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { List result = - regClient.getAllUserComputeResourcePreferences(userId, gatewayID); - registryClientPool.returnResource(regClient); + airavataService.getAllUserComputeResourcePreferences(userId, gatewayID); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(userId, "Error while reading User compute resource preferences...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while reading User compute resource preferences. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { logger.error(userId, "Error while reading User compute resource preferences...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage( "Error while reading User compute resource preferences. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -5748,17 +5211,20 @@ public List getAllUserStoragePreferences( AuthzToken authzToken, String userId, String gatewayID) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - List result = regClient.getAllUserStoragePreferences(userId, gatewayID); - registryClientPool.returnResource(regClient); + List result = airavataService.getAllUserStoragePreferences(userId, gatewayID); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(userId, "Error while reading User data storage preferences...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while reading User data storage preferences. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { logger.error(userId, "Error while reading User data storage preferences...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while reading User data storage preferences. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -5768,17 +5234,20 @@ public List getAllUserStoragePreferences( public List getAllUserResourceProfiles(AuthzToken authzToken) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - List result = regClient.getAllUserResourceProfiles(); - registryClientPool.returnResource(regClient); + List result = airavataService.getAllUserResourceProfiles(); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while reading retrieving all user resource profiles. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage( "Error while reading retrieving all user resource profiles. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -5803,19 +5272,23 @@ public boolean updateUserComputeResourcePreference( UserComputeResourcePreference userComputeResourcePreference) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.updateUserComputeResourcePreference( + boolean result = airavataService.updateUserComputeResourcePreference( userId, gatewayID, userComputeResourceId, userComputeResourcePreference); - registryClientPool.returnResource(regClient); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(userId, "Error while updating user compute resource preference...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while updating user compute resource preference. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { - logger.error(userId, "Error while reading user compute resource preference...", e); + logger.error(userId, "Error while updating user compute resource preference...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage( "Error while updating user compute resource preference. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -5830,18 +5303,21 @@ public boolean updateUserStoragePreference( UserStoragePreference dataStoragePreference) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { boolean result = - regClient.updateUserStoragePreference(userId, gatewayID, userStorageId, dataStoragePreference); - registryClientPool.returnResource(regClient); + airavataService.updateUserStoragePreference(userId, gatewayID, userStorageId, dataStoragePreference); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(userId, "Error while updating user data storage preference...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while updating user data storage preference. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { - logger.error(userId, "Error while reading user data storage preference...", e); + logger.error(userId, "Error while updating user data storage preference...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while updating user data storage preference. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -5861,18 +5337,22 @@ public boolean deleteUserComputeResourcePreference( AuthzToken authzToken, String userId, String gatewayID, String userComputeResourceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.deleteUserComputeResourcePreference(userId, gatewayID, userComputeResourceId); - registryClientPool.returnResource(regClient); + boolean result = airavataService.deleteUserComputeResourcePreference(userId, gatewayID, userComputeResourceId); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(userId, "Error while deleting user compute resource preference...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while deleting user compute resource preference. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { - logger.error(userId, "Error while reading user compute resource preference...", e); + logger.error(userId, "Error while deleting user compute resource preference...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage( - "Error while updating user compute resource preference. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); + "Error while deleting user compute resource preference. More info : " + e.getMessage()); throw exception; } } @@ -5883,17 +5363,20 @@ public boolean deleteUserStoragePreference( AuthzToken authzToken, String userId, String gatewayID, String userStorageId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - boolean result = regClient.deleteUserStoragePreference(userId, gatewayID, userStorageId); - registryClientPool.returnResource(regClient); + boolean result = airavataService.deleteUserStoragePreference(userId, gatewayID, userStorageId); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error(userId, "Error while deleting user data storage preference...", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while deleting user data storage preference. More info : " + e.getMessage()); + throw exception; } catch (Exception e) { - logger.error(userId, "Error while reading user data storage preference...", e); + logger.error(userId, "Error while deleting user data storage preference...", e); AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating user data storage preference. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); + exception.setMessage("Error while deleting user data storage preference. More info : " + e.getMessage()); throw exception; } } @@ -5903,17 +5386,20 @@ public boolean deleteUserStoragePreference( public List getLatestQueueStatuses(AuthzToken authzToken) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - List result = regClient.getLatestQueueStatuses(); - registryClientPool.returnResource(regClient); + List result = airavataService.getLatestQueueStatuses(); return result; + } catch (org.apache.airavata.registry.cpi.RegistryException e) { + String msg = "Error in retrieving queue statuses"; + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + " More info : " + e.getMessage()); + throw exception; } catch (Exception e) { String msg = "Error in retrieving queue statuses"; logger.error(msg, e); AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + " More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -5929,17 +5415,13 @@ public List getLatestQueueStatuses(AuthzToken authzToken) public String registerDataProduct(AuthzToken authzToken, DataProductModel dataProductModel) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - String result = regClient.registerDataProduct(dataProductModel); - registryClientPool.returnResource(regClient); - return result; + return airavataService.registerDataProduct(dataProductModel); } catch (Exception e) { String msg = "Error in registering the data resource" + dataProductModel.getProductName() + "."; logger.error(msg, e); AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + " More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -5949,17 +5431,13 @@ public String registerDataProduct(AuthzToken authzToken, DataProductModel dataPr public DataProductModel getDataProduct(AuthzToken authzToken, String productUri) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - DataProductModel result = regClient.getDataProduct(productUri); - registryClientPool.returnResource(regClient); - return result; + return airavataService.getDataProduct(productUri); } catch (Exception e) { String msg = "Error in retreiving the data product " + productUri + "."; logger.error(msg, e); AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + " More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -5969,17 +5447,13 @@ public DataProductModel getDataProduct(AuthzToken authzToken, String productUri) public String registerReplicaLocation(AuthzToken authzToken, DataReplicaLocationModel replicaLocationModel) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - String result = regClient.registerReplicaLocation(replicaLocationModel); - registryClientPool.returnResource(regClient); - return result; + return airavataService.registerReplicaLocation(replicaLocationModel); } catch (Exception e) { String msg = "Error in retreiving the replica " + replicaLocationModel.getReplicaName() + "."; logger.error(msg, e); AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + " More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -5989,17 +5463,13 @@ public String registerReplicaLocation(AuthzToken authzToken, DataReplicaLocation public DataProductModel getParentDataProduct(AuthzToken authzToken, String productUri) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - DataProductModel result = regClient.getParentDataProduct(productUri); - registryClientPool.returnResource(regClient); - return result; + return airavataService.getParentDataProduct(productUri); } catch (Exception e) { String msg = "Error in retreiving the parent data product for " + productUri + "."; logger.error(msg, e); AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + " More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -6009,17 +5479,13 @@ public DataProductModel getParentDataProduct(AuthzToken authzToken, String produ public List getChildDataProducts(AuthzToken authzToken, String productUri) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - List result = regClient.getChildDataProducts(productUri); - registryClientPool.returnResource(regClient); - return result; + return airavataService.getChildDataProducts(productUri); } catch (Exception e) { String msg = "Error in retreiving the child products for " + productUri + "."; logger.error(msg, e); AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + " More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -6040,8 +5506,8 @@ public boolean shareResourceWithUsers( RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { - if (!userHasAccessInternal(sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER) - && !userHasAccessInternal( + if (!airavataService.userHasAccessInternal(sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER) + && !airavataService.userHasAccessInternal( sharingClient, authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { throw new AuthorizationException( "User is not allowed to change sharing because the user is either not the resource owner or does not have access to share the resource"); @@ -6063,8 +5529,8 @@ else if (userPermission.getValue().equals(ResourcePermissionType.READ)) authzToken.getClaimsMap().get(Constants.GATEWAY_ID) + ":" + "READ", true); else if (userPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING)) { - if (userHasAccessInternal(sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER)) { - createManageSharingPermissionTypeIfMissing(sharingClient, gatewayId); + if (airavataService.userHasAccessInternal(sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER)) { + airavataService.createManageSharingPermissionTypeIfMissing(sharingClient, gatewayId); sharingClient.shareEntityWithUsers( gatewayId, resourceId, @@ -6103,8 +5569,8 @@ public boolean shareResourceWithGroups( RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { - if (!userHasAccessInternal(sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER) - && !userHasAccessInternal( + if (!airavataService.userHasAccessInternal(sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER) + && !airavataService.userHasAccessInternal( sharingClient, authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { throw new AuthorizationException( "User is not allowed to change sharing because the user is either not the resource owner or does not have access to share the resource"); @@ -6126,8 +5592,8 @@ else if (groupPermission.getValue().equals(ResourcePermissionType.READ)) authzToken.getClaimsMap().get(Constants.GATEWAY_ID) + ":" + "READ", true); else if (groupPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING)) { - if (userHasAccessInternal(sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER)) { - createManageSharingPermissionTypeIfMissing(sharingClient, gatewayId); + if (airavataService.userHasAccessInternal(sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER)) { + airavataService.createManageSharingPermissionTypeIfMissing(sharingClient, gatewayId); sharingClient.shareEntityWithGroups( gatewayId, resourceId, @@ -6166,8 +5632,8 @@ public boolean revokeSharingOfResourceFromUsers( RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { - if (!userHasAccessInternal(sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER) - && !userHasAccessInternal( + if (!airavataService.userHasAccessInternal(sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER) + && !airavataService.userHasAccessInternal( sharingClient, authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { throw new AuthorizationException( "User is not allowed to change sharing because the user is either not the resource owner or does not have access to share the resource"); @@ -6187,8 +5653,8 @@ else if (userPermission.getValue().equals(ResourcePermissionType.READ)) Arrays.asList(userPermission.getKey()), authzToken.getClaimsMap().get(Constants.GATEWAY_ID) + ":" + "READ"); else if (userPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING)) { - if (userHasAccessInternal(sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER)) { - createManageSharingPermissionTypeIfMissing(sharingClient, gatewayId); + if (airavataService.userHasAccessInternal(sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER)) { + airavataService.createManageSharingPermissionTypeIfMissing(sharingClient, gatewayId); sharingClient.revokeEntitySharingFromUsers( gatewayId, resourceId, @@ -6227,19 +5693,19 @@ public boolean revokeSharingOfResourceFromGroups( SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); final String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); try { - if (!userHasAccessInternal(sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER) - && !userHasAccessInternal( + if (!airavataService.userHasAccessInternal(sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER) + && !airavataService.userHasAccessInternal( sharingClient, authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { throw new AuthorizationException( "User is not allowed to change sharing because the user is either not the resource owner or does not have access to share the resource"); } // For certain resource types, restrict them from being unshared with admin groups - ResourceType resourceType = getResourceType(sharingClient, gatewayId, resourceId); + ResourceType resourceType = airavataService.getResourceType(sharingClient, gatewayId, resourceId); Set adminRestrictedResourceTypes = new HashSet<>(Arrays.asList( ResourceType.EXPERIMENT, ResourceType.APPLICATION_DEPLOYMENT, ResourceType.GROUP_RESOURCE_PROFILE)); if (adminRestrictedResourceTypes.contains(resourceType)) { // Prevent removing Admins WRITE/MANAGE_SHARING access and Read Only Admins READ access - GatewayGroups gatewayGroups = retrieveGatewayGroups(regClient, gatewayId); + GatewayGroups gatewayGroups = airavataService.retrieveGatewayGroups(gatewayId); if (groupPermissionList.containsKey(gatewayGroups.getAdminsGroupId()) && groupPermissionList .get(gatewayGroups.getAdminsGroupId()) @@ -6273,8 +5739,8 @@ else if (groupPermission.getValue().equals(ResourcePermissionType.READ)) sharingClient.revokeEntitySharingFromUsers( gatewayId, resourceId, Arrays.asList(groupPermission.getKey()), gatewayId + ":" + "READ"); else if (groupPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING)) { - if (userHasAccessInternal(sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER)) { - createManageSharingPermissionTypeIfMissing(sharingClient, gatewayId); + if (airavataService.userHasAccessInternal(sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER)) { + airavataService.createManageSharingPermissionTypeIfMissing(sharingClient, gatewayId); sharingClient.revokeEntitySharingFromUsers( gatewayId, resourceId, @@ -6309,14 +5775,20 @@ public List getAllAccessibleUsers( AuthzToken authzToken, String resourceId, ResourcePermissionType permissionType) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - return getAllAccessibleUsersInternal(authzToken, resourceId, permissionType, (c, t) -> { - try { - return c.getListOfSharedUsers(gatewayId, resourceId, gatewayId + ":" + t.name()); - } catch (TException e) { - throw new RuntimeException(e); - } - }); + SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + try { + List accessibleUsers = airavataService.getAllAccessibleUsersWithSharing( + sharingClient, authzToken, resourceId, permissionType, false); + sharingClientPool.returnResource(sharingClient); + return accessibleUsers; + } catch (Exception e) { + String msg = "Error in getting all accessible users for resource. Resource ID : " + resourceId; + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + " More info : " + e.getMessage()); + sharingClientPool.returnBrokenResource(sharingClient); + throw exception; + } } @Override @@ -6325,56 +5797,18 @@ public List getAllDirectlyAccessibleUsers( AuthzToken authzToken, String resourceId, ResourcePermissionType permissionType) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - return getAllAccessibleUsersInternal(authzToken, resourceId, permissionType, (c, t) -> { - try { - return c.getListOfDirectlySharedUsers(gatewayId, resourceId, gatewayId + ":" + t.name()); - } catch (TException e) { - throw new RuntimeException(e); - } - }); - } - - private List getAllAccessibleUsersInternal( - AuthzToken authzToken, - String resourceId, - ResourcePermissionType permissionType, - BiFunction> userListFunction) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { - HashSet accessibleUsers = new HashSet<>(); - if (permissionType.equals(ResourcePermissionType.WRITE)) { - userListFunction.apply(sharingClient, ResourcePermissionType.WRITE).stream() - .forEach(u -> accessibleUsers.add(u.getUserId())); - userListFunction.apply(sharingClient, ResourcePermissionType.OWNER).stream() - .forEach(u -> accessibleUsers.add(u.getUserId())); - } else if (permissionType.equals(ResourcePermissionType.READ)) { - userListFunction.apply(sharingClient, ResourcePermissionType.READ).stream() - .forEach(u -> accessibleUsers.add(u.getUserId())); - userListFunction.apply(sharingClient, ResourcePermissionType.OWNER).stream() - .forEach(u -> accessibleUsers.add(u.getUserId())); - } else if (permissionType.equals(ResourcePermissionType.OWNER)) { - userListFunction.apply(sharingClient, ResourcePermissionType.OWNER).stream() - .forEach(u -> accessibleUsers.add(u.getUserId())); - } else if (permissionType.equals(ResourcePermissionType.MANAGE_SHARING)) { - userListFunction.apply(sharingClient, ResourcePermissionType.MANAGE_SHARING).stream() - .forEach(u -> accessibleUsers.add(u.getUserId())); - userListFunction.apply(sharingClient, ResourcePermissionType.OWNER).stream() - .forEach(u -> accessibleUsers.add(u.getUserId())); - } - registryClientPool.returnResource(regClient); + List accessibleUsers = airavataService.getAllAccessibleUsersWithSharing( + sharingClient, authzToken, resourceId, permissionType, true); sharingClientPool.returnResource(sharingClient); - return new ArrayList<>(accessibleUsers); + return accessibleUsers; } catch (Exception e) { - String msg = "Error in getting all accessible users for resource. Resource ID : " + resourceId; + String msg = "Error in getting all directly accessible users for resource. Resource ID : " + resourceId; logger.error(msg, e); AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + " More info : " + e.getMessage()); sharingClientPool.returnBrokenResource(sharingClient); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -6385,63 +5819,40 @@ public List getAllAccessibleGroups( AuthzToken authzToken, String resourceId, ResourcePermissionType permissionType) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - return getAllAccessibleGroupsInternal(authzToken, resourceId, permissionType, (c, t) -> { - try { - return c.getListOfSharedGroups(gatewayId, resourceId, gatewayId + ":" + t.name()); - } catch (TException e) { - throw new RuntimeException(e); - } - }); - } - - @Override - @SecurityCheck - public List getAllDirectlyAccessibleGroups( - AuthzToken authzToken, String resourceId, ResourcePermissionType permissionType) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - return getAllAccessibleGroupsInternal(authzToken, resourceId, permissionType, (c, t) -> { - try { - return c.getListOfDirectlySharedGroups(gatewayId, resourceId, gatewayId + ":" + t.name()); - } catch (TException e) { - throw new RuntimeException(e); - } - }); + SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + try { + List accessibleGroups = airavataService.getAllAccessibleGroupsWithSharing( + sharingClient, authzToken, resourceId, permissionType, false); + sharingClientPool.returnResource(sharingClient); + return accessibleGroups; + } catch (Exception e) { + String msg = "Error in getting all accessible groups for resource. Resource ID : " + resourceId; + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + " More info : " + e.getMessage()); + sharingClientPool.returnBrokenResource(sharingClient); + throw exception; + } } - private List getAllAccessibleGroupsInternal( - AuthzToken authzToken, - String resourceId, - ResourcePermissionType permissionType, - BiFunction> groupListFunction) + @Override + @SecurityCheck + public List getAllDirectlyAccessibleGroups( + AuthzToken authzToken, String resourceId, ResourcePermissionType permissionType) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { - HashSet accessibleGroups = new HashSet<>(); - if (permissionType.equals(ResourcePermissionType.WRITE)) { - groupListFunction.apply(sharingClient, ResourcePermissionType.WRITE).stream() - .forEach(g -> accessibleGroups.add(g.getGroupId())); - } else if (permissionType.equals(ResourcePermissionType.READ)) { - groupListFunction.apply(sharingClient, ResourcePermissionType.READ).stream() - .forEach(g -> accessibleGroups.add(g.getGroupId())); - } else if (permissionType.equals(ResourcePermissionType.MANAGE_SHARING)) { - groupListFunction.apply(sharingClient, ResourcePermissionType.MANAGE_SHARING).stream() - .forEach(g -> accessibleGroups.add(g.getGroupId())); - } - registryClientPool.returnResource(regClient); + List accessibleGroups = airavataService.getAllAccessibleGroupsWithSharing( + sharingClient, authzToken, resourceId, permissionType, true); sharingClientPool.returnResource(sharingClient); - return new ArrayList<>(accessibleGroups); + return accessibleGroups; } catch (Exception e) { - String msg = "Error in getting all accessible groups for resource. Resource ID : " + resourceId; + String msg = "Error in getting all directly accessible groups for resource. Resource ID : " + resourceId; logger.error(msg, e); AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + " More info : " + e.getMessage()); sharingClientPool.returnBrokenResource(sharingClient); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -6455,7 +5866,7 @@ public boolean userHasAccess(AuthzToken authzToken, String resourceId, ResourceP final String userId = authzToken.getClaimsMap().get(Constants.USER_NAME) + "@" + domainId; SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { - final boolean hasAccess = userHasAccessInternal(sharingClient, authzToken, resourceId, permissionType); + final boolean hasAccess = airavataService.userHasAccessInternal(sharingClient, authzToken, resourceId, permissionType); sharingClientPool.returnResource(sharingClient); return hasAccess; } catch (Exception e) { @@ -6475,104 +5886,57 @@ public String createGroupResourceProfile(AuthzToken authzToken, GroupResourcePro throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { // TODO: verify that gatewayId in groupResourceProfile matches authzToken gatewayId - RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); - String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); try { - validateGroupResourceProfile(sharingClient, authzToken, groupResourceProfile); - String groupResourceProfileId = regClient.createGroupResourceProfile(groupResourceProfile); - if (ServerSettings.isEnableSharing()) { - try { - Entity entity = new Entity(); - entity.setEntityId(groupResourceProfileId); - final String domainId = groupResourceProfile.getGatewayId(); - entity.setDomainId(groupResourceProfile.getGatewayId()); - entity.setEntityTypeId(groupResourceProfile.getGatewayId() + ":" + "GROUP_RESOURCE_PROFILE"); - entity.setOwnerId(userName + "@" + groupResourceProfile.getGatewayId()); - entity.setName(groupResourceProfile.getGroupResourceProfileName()); - - sharingClient.createEntity(entity); - - shareEntityWithAdminGatewayGroups(regClient, sharingClient, entity); - } catch (Exception ex) { - logger.error(ex.getMessage(), ex); - logger.error("Rolling back group resource profile creation Group Resource Profile ID : " - + groupResourceProfileId); - regClient.removeGroupResourceProfile(groupResourceProfileId); - AiravataSystemException ase = new AiravataSystemException(); - ase.setMessage("Failed to create sharing registry record"); - throw ase; - } - } - registryClientPool.returnResource(regClient); + String groupResourceProfileId = airavataService.createGroupResourceProfileWithSharing( + sharingClient, authzToken, groupResourceProfile); sharingClientPool.returnResource(sharingClient); return groupResourceProfileId; } catch (AuthorizationException ae) { + String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); logger.info("User " + userName + " not allowed access to resources referenced in this GroupResourceProfile. Reason: " + ae.getMessage()); - registryClientPool.returnResource(regClient); sharingClientPool.returnResource(sharingClient); throw ae; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + String msg = "Error creating group resource profile."; + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + " More info : " + e.getMessage()); + sharingClientPool.returnBrokenResource(sharingClient); + throw exception; } catch (Exception e) { String msg = "Error creating group resource profile."; logger.error(msg, e); AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + " More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); + sharingClientPool.returnBrokenResource(sharingClient); throw exception; } } - private void validateGroupResourceProfile( - SharingRegistryService.Client sharingClient, - AuthzToken authzToken, - GroupResourceProfile groupResourceProfile) - throws AuthorizationException { - Set tokenIds = new HashSet<>(); - if (groupResourceProfile.getComputePreferences() != null) { - for (GroupComputeResourcePreference groupComputeResourcePreference : - groupResourceProfile.getComputePreferences()) { - if (groupComputeResourcePreference.getResourceSpecificCredentialStoreToken() != null) { - tokenIds.add(groupComputeResourcePreference.getResourceSpecificCredentialStoreToken()); - } - } - } - if (groupResourceProfile.getDefaultCredentialStoreToken() != null) { - tokenIds.add(groupResourceProfile.getDefaultCredentialStoreToken()); - } - for (String tokenId : tokenIds) { - if (!userHasAccessInternal(sharingClient, authzToken, tokenId, ResourcePermissionType.READ)) { - throw new AuthorizationException( - "User does not have READ permission to credential token " + tokenId + "."); - } - } - } - @Override @SecurityCheck public void updateGroupResourceProfile(AuthzToken authzToken, GroupResourceProfile groupResourceProfile) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { - validateGroupResourceProfile(sharingClient, authzToken, groupResourceProfile); - if (!userHasAccessInternal( + airavataService.validateGroupResourceProfile(sharingClient, authzToken, groupResourceProfile); + if (!airavataService.userHasAccessInternal( sharingClient, authzToken, groupResourceProfile.getGroupResourceProfileId(), ResourcePermissionType.WRITE)) { throw new AuthorizationException("User does not have permission to update group resource profile"); } - regClient.updateGroupResourceProfile(groupResourceProfile); - registryClientPool.returnResource(regClient); + airavataService.updateGroupResourceProfile(groupResourceProfile); sharingClientPool.returnResource(sharingClient); } catch (AuthorizationException ae) { String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); logger.info("User " + userName + " not allowed access to update GroupResourceProfile " + groupResourceProfile.getGroupResourceProfileId() + ", reason: " + ae.getMessage()); - registryClientPool.returnResource(regClient); sharingClientPool.returnResource(sharingClient); throw ae; } catch (Exception e) { @@ -6581,7 +5945,7 @@ public void updateGroupResourceProfile(AuthzToken authzToken, GroupResourceProfi logger.error(msg, e); AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + " More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); + sharingClientPool.returnBrokenResource(sharingClient); throw exception; } } @@ -6591,7 +5955,6 @@ public void updateGroupResourceProfile(AuthzToken authzToken, GroupResourceProfi public GroupResourceProfile getGroupResourceProfile(AuthzToken authzToken, String groupResourceProfileId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { if (ServerSettings.isEnableSharing()) { @@ -6607,15 +5970,13 @@ public GroupResourceProfile getGroupResourceProfile(AuthzToken authzToken, Strin throw new AuthorizationException("User does not have permission to access group resource profile"); } } - GroupResourceProfile groupResourceProfile = regClient.getGroupResourceProfile(groupResourceProfileId); - registryClientPool.returnResource(regClient); + GroupResourceProfile groupResourceProfile = airavataService.getGroupResourceProfile(groupResourceProfileId); sharingClientPool.returnResource(sharingClient); return groupResourceProfile; } catch (AuthorizationException checkedException) { logger.error( "Error while retrieving group resource profile. groupResourceProfileId: " + groupResourceProfileId, checkedException); - registryClientPool.returnResource(regClient); sharingClientPool.returnResource(sharingClient); throw checkedException; } catch (Exception e) { @@ -6623,7 +5984,7 @@ public GroupResourceProfile getGroupResourceProfile(AuthzToken authzToken, Strin logger.error(msg, e); AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + " More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); + sharingClientPool.returnBrokenResource(sharingClient); throw exception; } } @@ -6633,7 +5994,6 @@ public GroupResourceProfile getGroupResourceProfile(AuthzToken authzToken, Strin public boolean removeGroupResourceProfile(AuthzToken authzToken, String groupResourceProfileId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); @@ -6649,17 +6009,23 @@ public boolean removeGroupResourceProfile(AuthzToken authzToken, String groupRes throw new AuthorizationException("User does not have permission to remove group resource profile"); } } - boolean result = regClient.removeGroupResourceProfile(groupResourceProfileId); + boolean result = airavataService.removeGroupResourceProfile(groupResourceProfileId); sharingClient.deleteEntity(gatewayId, groupResourceProfileId); - registryClientPool.returnResource(regClient); sharingClientPool.returnResource(sharingClient); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + String msg = "Error removing group resource profile. groupResourceProfileId: " + groupResourceProfileId; + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + " More info : " + e.getMessage()); + sharingClientPool.returnBrokenResource(sharingClient); + throw exception; } catch (Exception e) { String msg = "Error removing group resource profile. groupResourceProfileId: " + groupResourceProfileId; logger.error(msg, e); AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + " More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); + sharingClientPool.returnBrokenResource(sharingClient); throw exception; } } @@ -6669,39 +6035,24 @@ public boolean removeGroupResourceProfile(AuthzToken authzToken, String groupRes public List getGroupResourceList(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); - String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); try { - List accessibleGroupResProfileIds = new ArrayList<>(); - if (ServerSettings.isEnableSharing()) { - List filters = new ArrayList<>(); - SearchCriteria searchCriteria = new SearchCriteria(); - searchCriteria.setSearchField(EntitySearchField.ENTITY_TYPE_ID); - searchCriteria.setSearchCondition(SearchCondition.EQUAL); - searchCriteria.setValue(gatewayId + ":" + ResourceType.GROUP_RESOURCE_PROFILE.name()); - filters.add(searchCriteria); - sharingClient - .searchEntities( - authzToken.getClaimsMap().get(Constants.GATEWAY_ID), - userName + "@" + gatewayId, - filters, - 0, - -1) - .stream() - .forEach(p -> accessibleGroupResProfileIds.add(p.getEntityId())); - } - List groupResourceProfileList = - regClient.getGroupResourceList(gatewayId, accessibleGroupResProfileIds); - registryClientPool.returnResource(regClient); + List groupResourceProfileList = airavataService.getGroupResourceListWithSharing( + sharingClient, authzToken, gatewayId); sharingClientPool.returnResource(sharingClient); return groupResourceProfileList; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + String msg = "Error retrieving list group resource profile list. GatewayId: " + gatewayId; + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + " More info : " + e.getMessage()); + sharingClientPool.returnBrokenResource(sharingClient); + throw exception; } catch (Exception e) { String msg = "Error retrieving list group resource profile list. GatewayId: " + gatewayId; logger.error(msg, e); AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + " More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); sharingClientPool.returnBrokenResource(sharingClient); throw exception; } @@ -6713,7 +6064,6 @@ public boolean removeGroupComputePrefs( AuthzToken authzToken, String computeResourceId, String groupResourceProfileId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { if (ServerSettings.isEnableSharing()) { @@ -6730,17 +6080,24 @@ public boolean removeGroupComputePrefs( "User does not have permission to remove group compute preferences"); } } - boolean result = regClient.removeGroupComputePrefs(computeResourceId, groupResourceProfileId); - registryClientPool.returnResource(regClient); + boolean result = airavataService.removeGroupComputePrefs(computeResourceId, groupResourceProfileId); sharingClientPool.returnResource(sharingClient); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + String msg = "Error removing group compute resource preferences. GroupResourceProfileId: " + + groupResourceProfileId; + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + " More info : " + e.getMessage()); + sharingClientPool.returnBrokenResource(sharingClient); + throw exception; } catch (Exception e) { String msg = "Error removing group compute resource preferences. GroupResourceProfileId: " + groupResourceProfileId; logger.error(msg, e); AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + " More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); + sharingClientPool.returnBrokenResource(sharingClient); throw exception; } } @@ -6750,13 +6107,12 @@ public boolean removeGroupComputePrefs( public boolean removeGroupComputeResourcePolicy(AuthzToken authzToken, String resourcePolicyId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { if (ServerSettings.isEnableSharing()) { try { ComputeResourcePolicy computeResourcePolicy = - regClient.getGroupComputeResourcePolicy(resourcePolicyId); + airavataService.getGroupComputeResourcePolicy(resourcePolicyId); String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); if (!sharingClient.userHasAccess( @@ -6772,16 +6128,22 @@ public boolean removeGroupComputeResourcePolicy(AuthzToken authzToken, String re "User does not have permission to remove group compute resource policy"); } } - boolean result = regClient.removeGroupComputeResourcePolicy(resourcePolicyId); - registryClientPool.returnResource(regClient); + boolean result = airavataService.removeGroupComputeResourcePolicy(resourcePolicyId); sharingClientPool.returnResource(sharingClient); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + String msg = "Error removing group compute resource policy. ResourcePolicyId: " + resourcePolicyId; + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + " More info : " + e.getMessage()); + sharingClientPool.returnBrokenResource(sharingClient); + throw exception; } catch (Exception e) { String msg = "Error removing group compute resource policy. ResourcePolicyId: " + resourcePolicyId; logger.error(msg, e); AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + " More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); + sharingClientPool.returnBrokenResource(sharingClient); throw exception; } } @@ -6791,13 +6153,12 @@ public boolean removeGroupComputeResourcePolicy(AuthzToken authzToken, String re public boolean removeGroupBatchQueueResourcePolicy(AuthzToken authzToken, String resourcePolicyId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { if (ServerSettings.isEnableSharing()) { try { BatchQueueResourcePolicy batchQueueResourcePolicy = - regClient.getBatchQueueResourcePolicy(resourcePolicyId); + airavataService.getBatchQueueResourcePolicy(resourcePolicyId); String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); if (!sharingClient.userHasAccess( @@ -6813,16 +6174,22 @@ public boolean removeGroupBatchQueueResourcePolicy(AuthzToken authzToken, String "User does not have permission to remove batch queue resource policy"); } } - boolean result = regClient.removeGroupBatchQueueResourcePolicy(resourcePolicyId); - registryClientPool.returnResource(regClient); + boolean result = airavataService.removeGroupBatchQueueResourcePolicy(resourcePolicyId); sharingClientPool.returnResource(sharingClient); return result; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + String msg = "Error removing batch queue resource policy. ResourcePolicyId: " + resourcePolicyId; + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + " More info : " + e.getMessage()); + sharingClientPool.returnBrokenResource(sharingClient); + throw exception; } catch (Exception e) { String msg = "Error removing batch queue resource policy. ResourcePolicyId: " + resourcePolicyId; logger.error(msg, e); AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + " More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); + sharingClientPool.returnBrokenResource(sharingClient); throw exception; } } @@ -6833,7 +6200,6 @@ public GroupComputeResourcePreference getGroupComputeResourcePreference( AuthzToken authzToken, String computeResourceId, String groupResourceProfileId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { if (ServerSettings.isEnableSharing()) { @@ -6850,16 +6216,22 @@ public GroupComputeResourcePreference getGroupComputeResourcePreference( } } GroupComputeResourcePreference groupComputeResourcePreference = - regClient.getGroupComputeResourcePreference(computeResourceId, groupResourceProfileId); - registryClientPool.returnResource(regClient); + airavataService.getGroupComputeResourcePreference(computeResourceId, groupResourceProfileId); sharingClientPool.returnResource(sharingClient); return groupComputeResourcePreference; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + String msg = "Error retrieving Group compute preference. GroupResourceProfileId: " + groupResourceProfileId; + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + " More info : " + e.getMessage()); + sharingClientPool.returnBrokenResource(sharingClient); + throw exception; } catch (Exception e) { String msg = "Error retrieving Group compute preference. GroupResourceProfileId: " + groupResourceProfileId; logger.error(msg, e); AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + " More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); + sharingClientPool.returnBrokenResource(sharingClient); throw exception; } } @@ -6869,13 +6241,12 @@ public GroupComputeResourcePreference getGroupComputeResourcePreference( public ComputeResourcePolicy getGroupComputeResourcePolicy(AuthzToken authzToken, String resourcePolicyId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { if (ServerSettings.isEnableSharing()) { try { ComputeResourcePolicy computeResourcePolicy = - regClient.getGroupComputeResourcePolicy(resourcePolicyId); + airavataService.getGroupComputeResourcePolicy(resourcePolicyId); String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); if (!sharingClient.userHasAccess( @@ -6891,16 +6262,22 @@ public ComputeResourcePolicy getGroupComputeResourcePolicy(AuthzToken authzToken } } - ComputeResourcePolicy computeResourcePolicy = regClient.getGroupComputeResourcePolicy(resourcePolicyId); - registryClientPool.returnResource(regClient); + ComputeResourcePolicy computeResourcePolicy = airavataService.getGroupComputeResourcePolicy(resourcePolicyId); sharingClientPool.returnResource(sharingClient); return computeResourcePolicy; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + String msg = "Error retrieving Group compute resource policy. ResourcePolicyId: " + resourcePolicyId; + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + " More info : " + e.getMessage()); + sharingClientPool.returnBrokenResource(sharingClient); + throw exception; } catch (Exception e) { String msg = "Error retrieving Group compute resource policy. ResourcePolicyId: " + resourcePolicyId; logger.error(msg, e); AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + " More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); + sharingClientPool.returnBrokenResource(sharingClient); throw exception; } } @@ -6910,13 +6287,12 @@ public ComputeResourcePolicy getGroupComputeResourcePolicy(AuthzToken authzToken public BatchQueueResourcePolicy getBatchQueueResourcePolicy(AuthzToken authzToken, String resourcePolicyId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { if (ServerSettings.isEnableSharing()) { try { BatchQueueResourcePolicy batchQueueResourcePolicy = - regClient.getBatchQueueResourcePolicy(resourcePolicyId); + airavataService.getBatchQueueResourcePolicy(resourcePolicyId); String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); if (!sharingClient.userHasAccess( @@ -6931,16 +6307,22 @@ public BatchQueueResourcePolicy getBatchQueueResourcePolicy(AuthzToken authzToke throw new AuthorizationException("User does not have permission to access group resource profile"); } } - BatchQueueResourcePolicy batchQueueResourcePolicy = regClient.getBatchQueueResourcePolicy(resourcePolicyId); - registryClientPool.returnResource(regClient); + BatchQueueResourcePolicy batchQueueResourcePolicy = airavataService.getBatchQueueResourcePolicy(resourcePolicyId); sharingClientPool.returnResource(sharingClient); return batchQueueResourcePolicy; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + String msg = "Error retrieving Group batch queue resource policy. ResourcePolicyId: " + resourcePolicyId; + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + " More info : " + e.getMessage()); + sharingClientPool.returnBrokenResource(sharingClient); + throw exception; } catch (Exception e) { String msg = "Error retrieving Group batch queue resource policy. ResourcePolicyId: " + resourcePolicyId; logger.error(msg, e); AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + " More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); + sharingClientPool.returnBrokenResource(sharingClient); throw exception; } } @@ -6951,7 +6333,6 @@ public List getGroupComputeResourcePrefList( AuthzToken authzToken, String groupResourceProfileId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { if (ServerSettings.isEnableSharing()) { @@ -6968,17 +6349,24 @@ public List getGroupComputeResourcePrefList( } } List groupComputeResourcePreferenceList = - regClient.getGroupComputeResourcePrefList(groupResourceProfileId); - registryClientPool.returnResource(regClient); + airavataService.getGroupComputeResourcePrefList(groupResourceProfileId); sharingClientPool.returnResource(sharingClient); return groupComputeResourcePreferenceList; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + String msg = "Error retrieving Group compute resource preference. GroupResourceProfileId: " + + groupResourceProfileId; + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + " More info : " + e.getMessage()); + sharingClientPool.returnBrokenResource(sharingClient); + throw exception; } catch (Exception e) { String msg = "Error retrieving Group compute resource preference. GroupResourceProfileId: " + groupResourceProfileId; logger.error(msg, e); AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + " More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); + sharingClientPool.returnBrokenResource(sharingClient); throw exception; } } @@ -6989,7 +6377,6 @@ public List getGroupBatchQueueResourcePolicyList( AuthzToken authzToken, String groupResourceProfileId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { if (ServerSettings.isEnableSharing()) { @@ -7006,17 +6393,24 @@ public List getGroupBatchQueueResourcePolicyList( } } List batchQueueResourcePolicyList = - regClient.getGroupBatchQueueResourcePolicyList(groupResourceProfileId); - registryClientPool.returnResource(regClient); + airavataService.getGroupBatchQueueResourcePolicyList(groupResourceProfileId); sharingClientPool.returnResource(sharingClient); return batchQueueResourcePolicyList; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + String msg = "Error retrieving Group batch queue resource policy list. GroupResourceProfileId: " + + groupResourceProfileId; + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + " More info : " + e.getMessage()); + sharingClientPool.returnBrokenResource(sharingClient); + throw exception; } catch (Exception e) { String msg = "Error retrieving Group batch queue resource policy list. GroupResourceProfileId: " + groupResourceProfileId; logger.error(msg, e); AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + " More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); + sharingClientPool.returnBrokenResource(sharingClient); throw exception; } } @@ -7027,7 +6421,6 @@ public List getGroupComputeResourcePolicyList( AuthzToken authzToken, String groupResourceProfileId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { if (ServerSettings.isEnableSharing()) { @@ -7044,17 +6437,24 @@ public List getGroupComputeResourcePolicyList( } } List computeResourcePolicyList = - regClient.getGroupComputeResourcePolicyList(groupResourceProfileId); - registryClientPool.returnResource(regClient); + airavataService.getGroupComputeResourcePolicyList(groupResourceProfileId); sharingClientPool.returnResource(sharingClient); return computeResourcePolicyList; + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + String msg = "Error retrieving Group compute resource policy list. GroupResourceProfileId: " + + groupResourceProfileId; + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + " More info : " + e.getMessage()); + sharingClientPool.returnBrokenResource(sharingClient); + throw exception; } catch (Exception e) { String msg = "Error retrieving Group compute resource policy list. GroupResourceProfileId: " + groupResourceProfileId; logger.error(msg, e); AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + " More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); + sharingClientPool.returnBrokenResource(sharingClient); throw exception; } } @@ -7066,17 +6466,14 @@ public GatewayGroups getGatewayGroups(AuthzToken authzToken) TException { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - RegistryService.Client regClient = registryClientPool.getResource(); try { - GatewayGroups gatewayGroups = retrieveGatewayGroups(regClient, gatewayId); - registryClientPool.returnResource(regClient); + GatewayGroups gatewayGroups = airavataService.retrieveGatewayGroups(gatewayId); return gatewayGroups; } catch (Exception e) { String msg = "Error retrieving GatewayGroups for gateway: " + gatewayId; logger.error(msg, e); AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + " More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -7086,17 +6483,20 @@ public GatewayGroups getGatewayGroups(AuthzToken authzToken) public Parser getParser(AuthzToken authzToken, String parserId, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - Parser parser = regClient.getParser(parserId, gatewayId); - registryClientPool.returnResource(regClient); + Parser parser = airavataService.getParser(parserId, gatewayId); return parser; + } catch (org.apache.airavata.registry.cpi.RegistryException e) { + String msg = "Error retrieving parser with id: " + parserId; + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + " More info : " + e.getMessage()); + throw exception; } catch (Exception e) { String msg = "Error retrieving parser with id: " + parserId; logger.error(msg, e); AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + " More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -7106,17 +6506,20 @@ public Parser getParser(AuthzToken authzToken, String parserId, String gatewayId public String saveParser(AuthzToken authzToken, Parser parser) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - String parserId = regClient.saveParser(parser); - registryClientPool.returnResource(regClient); + String parserId = airavataService.saveParser(parser); return parserId; + } catch (org.apache.airavata.registry.cpi.RegistryException e) { + String msg = "Error while saving the parser"; + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + " More info : " + e.getMessage()); + throw exception; } catch (Exception e) { String msg = "Error while saving the parser"; logger.error(msg, e); AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + " More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -7126,17 +6529,20 @@ public String saveParser(AuthzToken authzToken, Parser parser) public List listAllParsers(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - List parsers = regClient.listAllParsers(gatewayId); - registryClientPool.returnResource(regClient); + List parsers = airavataService.listAllParsers(gatewayId); return parsers; + } catch (org.apache.airavata.registry.cpi.RegistryException e) { + String msg = "Error while listing the parsers for gateway " + gatewayId; + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + " More info : " + e.getMessage()); + throw exception; } catch (Exception e) { String msg = "Error while listing the parsers for gateway " + gatewayId; logger.error(msg, e); AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + " More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -7146,17 +6552,20 @@ public List listAllParsers(AuthzToken authzToken, String gatewayId) public boolean removeParser(AuthzToken authzToken, String parserId, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - regClient.removeParser(parserId, gatewayId); - registryClientPool.returnResource(regClient); + airavataService.removeParser(parserId, gatewayId); return true; + } catch (org.apache.airavata.registry.cpi.RegistryException e) { + String msg = "Error while removing the parser " + parserId + " in gateway " + gatewayId; + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + " More info : " + e.getMessage()); + throw exception; } catch (Exception e) { String msg = "Error while removing the parser " + parserId + " in gateway " + gatewayId; logger.error(msg, e); AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + " More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -7166,17 +6575,20 @@ public boolean removeParser(AuthzToken authzToken, String parserId, String gatew public ParsingTemplate getParsingTemplate(AuthzToken authzToken, String templateId, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - ParsingTemplate parsingTemplate = regClient.getParsingTemplate(templateId, gatewayId); - registryClientPool.returnResource(regClient); + ParsingTemplate parsingTemplate = airavataService.getParsingTemplate(templateId, gatewayId); return parsingTemplate; + } catch (org.apache.airavata.registry.cpi.RegistryException e) { + String msg = "Error retrieving parsing template with id: " + templateId; + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + " More info : " + e.getMessage()); + throw exception; } catch (Exception e) { String msg = "Error retrieving parsing template with id: " + templateId; logger.error(msg, e); AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + " More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -7187,18 +6599,21 @@ public List getParsingTemplatesForExperiment( AuthzToken authzToken, String experimentId, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { List parsingTemplates = - regClient.getParsingTemplatesForExperiment(experimentId, gatewayId); - registryClientPool.returnResource(regClient); + airavataService.getParsingTemplatesForExperiment(experimentId, gatewayId); return parsingTemplates; + } catch (org.apache.airavata.registry.cpi.RegistryException e) { + String msg = "Error retrieving parsing templates for experiment: " + experimentId; + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + " More info : " + e.getMessage()); + throw exception; } catch (Exception e) { String msg = "Error retrieving parsing templates for experiment: " + experimentId; logger.error(msg, e); AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + " More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -7208,17 +6623,20 @@ public List getParsingTemplatesForExperiment( public String saveParsingTemplate(AuthzToken authzToken, ParsingTemplate parsingTemplate) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - String templateId = regClient.saveParsingTemplate(parsingTemplate); - registryClientPool.returnResource(regClient); + String templateId = airavataService.saveParsingTemplate(parsingTemplate); return templateId; + } catch (org.apache.airavata.registry.cpi.RegistryException e) { + String msg = "Error saving the parsing template"; + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + " More info : " + e.getMessage()); + throw exception; } catch (Exception e) { String msg = "Error saving the parsing template"; logger.error(msg, e); AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + " More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -7228,17 +6646,20 @@ public String saveParsingTemplate(AuthzToken authzToken, ParsingTemplate parsing public boolean removeParsingTemplate(AuthzToken authzToken, String templateId, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - regClient.removeParsingTemplate(templateId, gatewayId); - registryClientPool.returnResource(regClient); + airavataService.removeParsingTemplate(templateId, gatewayId); return true; + } catch (org.apache.airavata.registry.cpi.RegistryException e) { + String msg = "Error while removing the parsing template " + templateId + " in gateway " + gatewayId; + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + " More info : " + e.getMessage()); + throw exception; } catch (Exception e) { String msg = "Error while removing the parsing template " + templateId + " in gateway " + gatewayId; logger.error(msg, e); AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + " More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -7248,17 +6669,20 @@ public boolean removeParsingTemplate(AuthzToken authzToken, String templateId, S public List listAllParsingTemplates(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - RegistryService.Client regClient = registryClientPool.getResource(); try { - List templates = regClient.listAllParsingTemplates(gatewayId); - registryClientPool.returnResource(regClient); + List templates = airavataService.listAllParsingTemplates(gatewayId); return templates; + } catch (org.apache.airavata.registry.cpi.RegistryException e) { + String msg = "Error while listing the parsing templates for gateway " + gatewayId; + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + " More info : " + e.getMessage()); + throw exception; } catch (Exception e) { String msg = "Error while listing the parsing templates for gateway " + gatewayId; logger.error(msg, e); AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + " More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java b/airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java new file mode 100644 index 0000000000..d04db0d61f --- /dev/null +++ b/airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java @@ -0,0 +1,1990 @@ +/** +* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ +package org.apache.airavata.service; + +import java.util.List; +import java.util.Map; +import org.apache.airavata.model.application.io.InputDataObjectType; +import org.apache.airavata.model.application.io.OutputDataObjectType; +import org.apache.airavata.model.appcatalog.appdeployment.ApplicationModule; +import org.apache.airavata.model.appcatalog.computeresource.ComputeResourceDescription; +import org.apache.airavata.model.appcatalog.computeresource.CloudJobSubmission; +import org.apache.airavata.model.appcatalog.computeresource.LOCALSubmission; +import org.apache.airavata.model.appcatalog.computeresource.ResourceJobManager; +import org.apache.airavata.model.appcatalog.computeresource.SSHJobSubmission; +import org.apache.airavata.model.appcatalog.computeresource.UnicoreJobSubmission; +import org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile; +import org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference; +import org.apache.airavata.model.appcatalog.gatewayprofile.StoragePreference; +import org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference; +import org.apache.airavata.model.appcatalog.userresourceprofile.UserStoragePreference; +import org.apache.airavata.model.appcatalog.groupresourceprofile.GroupComputeResourcePreference; +import org.apache.airavata.model.appcatalog.groupresourceprofile.ComputeResourcePolicy; +import org.apache.airavata.model.appcatalog.groupresourceprofile.BatchQueueResourcePolicy; +import org.apache.airavata.model.status.QueueStatusModel; +import org.apache.airavata.model.appcatalog.parser.Parser; +import org.apache.airavata.model.appcatalog.parser.ParsingTemplate; +import org.apache.airavata.model.data.movement.DMType; +import org.apache.airavata.model.data.movement.LOCALDataMovement; +import org.apache.airavata.model.data.movement.SCPDataMovement; +import org.apache.airavata.model.data.movement.UnicoreDataMovement; +import org.apache.airavata.model.data.movement.GridFTPDataMovement; +import org.apache.airavata.model.appcatalog.groupresourceprofile.GroupResourceProfile; +import org.apache.airavata.model.appcatalog.userresourceprofile.UserResourceProfile; +import org.apache.airavata.model.appcatalog.storageresource.StorageResourceDescription; +import org.apache.airavata.model.data.replica.DataProductModel; +import org.apache.airavata.model.data.replica.DataReplicaLocationModel; +import org.apache.airavata.model.experiment.ExperimentModel; +import org.apache.airavata.model.experiment.ExperimentSearchFields; +import org.apache.airavata.model.experiment.ExperimentStatistics; +import org.apache.airavata.model.experiment.ExperimentSummaryModel; +import org.apache.airavata.model.experiment.ProjectSearchFields; +import org.apache.airavata.model.job.JobModel; +import org.apache.airavata.model.process.ProcessModel; +import org.apache.airavata.model.status.ExperimentStatus; +import org.apache.airavata.model.status.JobState; +import org.apache.airavata.model.status.JobStatus; +import org.apache.airavata.model.status.ProcessState; +import org.apache.airavata.model.status.ProcessStatus; +import org.apache.airavata.model.task.TaskTypes; +import org.apache.airavata.model.experiment.UserConfigurationDataModel; +import org.apache.airavata.model.scheduling.ComputationalResourceSchedulingModel; +import org.apache.airavata.model.workspace.Gateway; +import org.apache.airavata.model.workspace.Notification; +import org.apache.airavata.model.workspace.Project; +import org.apache.airavata.model.appcatalog.appinterface.ApplicationInterfaceDescription; +import org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription; +import org.apache.airavata.model.credential.store.CredentialSummary; +import org.apache.airavata.model.credential.store.PasswordCredential; +import org.apache.airavata.model.credential.store.SSHCredential; +import org.apache.airavata.model.credential.store.SummaryType; +import org.apache.airavata.model.group.ResourcePermissionType; +import org.apache.airavata.model.group.ResourceType; +import org.apache.airavata.model.security.AuthzToken; +import org.apache.airavata.common.utils.Constants; +import org.apache.airavata.common.utils.ServerSettings; +import org.apache.airavata.credential.store.cpi.CredentialStoreService; +import org.apache.airavata.credential.store.exception.CredentialStoreException; +import org.apache.airavata.registry.cpi.RegistryException; +import org.apache.airavata.registry.cpi.AppCatalogException; +import org.apache.airavata.service.security.GatewayGroupsInitializer; +import org.apache.airavata.sharing.registry.models.Domain; +import org.apache.airavata.sharing.registry.models.Entity; +import org.apache.airavata.sharing.registry.models.EntityType; +import org.apache.airavata.sharing.registry.models.PermissionType; +import org.apache.airavata.sharing.registry.models.SearchCriteria; +import org.apache.airavata.sharing.registry.models.EntitySearchField; +import org.apache.airavata.sharing.registry.models.SearchCondition; +import org.apache.airavata.sharing.registry.service.cpi.SharingRegistryService; +import org.apache.airavata.registry.api.RegistryService; +import org.apache.airavata.model.appcatalog.gatewaygroups.GatewayGroups; +import org.apache.airavata.messaging.core.MessageContext; +import org.apache.airavata.messaging.core.Publisher; +import org.apache.airavata.model.messaging.event.ExperimentIntermediateOutputsEvent; +import org.apache.airavata.model.messaging.event.ExperimentStatusChangeEvent; +import org.apache.airavata.model.messaging.event.ExperimentSubmitEvent; +import org.apache.airavata.model.messaging.event.MessageType; +import org.apache.airavata.model.status.ExperimentState; +import org.apache.airavata.common.utils.AiravataUtils; +import org.apache.airavata.sharing.registry.models.User; +import org.apache.airavata.sharing.registry.models.UserGroup; +import org.apache.thrift.TException; +import java.util.UUID; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; +import java.util.function.BiFunction; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Optional; +import java.util.stream.Collectors; + +public class AiravataService { + private static final Logger logger = LoggerFactory.getLogger(AiravataService.class); + + private org.apache.airavata.service.RegistryService registryService = new org.apache.airavata.service.RegistryService(); + + public List getAllUsersInGateway(String gatewayId) throws RegistryException { + return registryService.getAllUsersInGateway(gatewayId); + } + + public boolean updateGateway(String gatewayId, Gateway updatedGateway) throws RegistryException, AppCatalogException { + return registryService.updateGateway(gatewayId, updatedGateway); + } + + public Gateway getGateway(String gatewayId) throws RegistryException { + return registryService.getGateway(gatewayId); + } + + public boolean deleteGateway(String gatewayId) throws RegistryException { + return registryService.deleteGateway(gatewayId); + } + + public List getAllGateways() throws RegistryException { + return registryService.getAllGateways(); + } + + public boolean isGatewayExist(String gatewayId) throws RegistryException { + return registryService.isGatewayExist(gatewayId); + } + + public String createNotification(Notification notification) throws RegistryException { + return registryService.createNotification(notification); + } + + public boolean updateNotification(Notification notification) throws RegistryException { + return registryService.updateNotification(notification); + } + + public boolean deleteNotification(String gatewayId, String notificationId) throws RegistryException { + return registryService.deleteNotification(gatewayId, notificationId); + } + + public Notification getNotification(String gatewayId, String notificationId) throws RegistryException { + return registryService.getNotification(gatewayId, notificationId); + } + + public List getAllNotifications(String gatewayId) throws RegistryException { + return registryService.getAllNotifications(gatewayId); + } + + public String registerDataProduct(DataProductModel dataProductModel) throws RegistryException { + return registryService.registerDataProduct(dataProductModel); + } + + public DataProductModel getDataProduct(String productUri) throws RegistryException { + return registryService.getDataProduct(productUri); + } + + public String registerReplicaLocation(DataReplicaLocationModel replicaLocationModel) throws RegistryException { + return registryService.registerReplicaLocation(replicaLocationModel); + } + + public DataProductModel getParentDataProduct(String productUri) throws RegistryException { + return registryService.getParentDataProduct(productUri); + } + + public List getChildDataProducts(String productUri) throws RegistryException { + return registryService.getChildDataProducts(productUri); + } + + public boolean isUserExists(String gatewayId, String userName) throws RegistryException { + return registryService.isUserExists(gatewayId, userName); + } + + public Project getProject(String projectId) throws RegistryException { + return registryService.getProject(projectId); + } + + public String createProject(String gatewayId, Project project) throws RegistryException { + return registryService.createProject(gatewayId, project); + } + + public void updateProject(String projectId, Project updatedProject) throws RegistryException { + registryService.updateProject(projectId, updatedProject); + } + + public boolean deleteProject(String projectId) throws RegistryException { + return registryService.deleteProject(projectId); + } + + public List searchProjects(String gatewayId, String userName, List accessibleProjectIds, Map filters, int limit, int offset) throws RegistryException { + return registryService.searchProjects(gatewayId, userName, accessibleProjectIds, filters, limit, offset); + } + + public List getUserExperiments(String gatewayId, String userName, int limit, int offset) throws RegistryException { + return registryService.getUserExperiments(gatewayId, userName, limit, offset); + } + + public List getExperimentsInProject(String gatewayId, String projectId, int limit, int offset) throws RegistryException { + return registryService.getExperimentsInProject(gatewayId, projectId, limit, offset); + } + + public ExperimentStatistics getExperimentStatistics(String gatewayId, long fromTime, long toTime, String userName, String applicationName, String resourceHostName, List accessibleExpIds, int limit, int offset) throws RegistryException { + return registryService.getExperimentStatistics(gatewayId, fromTime, toTime, userName, applicationName, resourceHostName, accessibleExpIds, limit, offset); + } + + public ExperimentModel getExperiment(String airavataExperimentId) throws RegistryException { + return registryService.getExperiment(airavataExperimentId); + } + + public String createExperiment(String gatewayId, ExperimentModel experiment) throws RegistryException { + return registryService.createExperiment(gatewayId, experiment); + } + + public void updateExperiment(String airavataExperimentId, ExperimentModel experiment) throws RegistryException { + registryService.updateExperiment(airavataExperimentId, experiment); + } + + public boolean deleteExperiment(String experimentId) throws RegistryException { + return registryService.deleteExperiment(experimentId); + } + + public List searchExperiments(String gatewayId, String userName, List accessibleExpIds, Map filters, int limit, int offset) throws RegistryException { + return registryService.searchExperiments(gatewayId, userName, accessibleExpIds, filters, limit, offset); + } + + /** + * Search experiments with sharing registry integration - processes filters and builds search criteria + */ + public List searchExperimentsWithSharing( + SharingRegistryService.Client sharingClient, + AuthzToken authzToken, + String gatewayId, + String userName, + Map filters, + int limit, + int offset) throws Exception { + List accessibleExpIds = new ArrayList<>(); + Map filtersCopy = new HashMap<>(filters); + List sharingFilters = new ArrayList<>(); + SearchCriteria searchCriteria = new SearchCriteria(); + searchCriteria.setSearchField(EntitySearchField.ENTITY_TYPE_ID); + searchCriteria.setSearchCondition(SearchCondition.EQUAL); + searchCriteria.setValue(gatewayId + ":EXPERIMENT"); + sharingFilters.add(searchCriteria); + + // Apply as much of the filters in the sharing API as possible, + // removing each filter that can be filtered via the sharing API + if (filtersCopy.containsKey(ExperimentSearchFields.FROM_DATE)) { + String fromTime = filtersCopy.remove(ExperimentSearchFields.FROM_DATE); + SearchCriteria fromCreatedTimeCriteria = new SearchCriteria(); + fromCreatedTimeCriteria.setSearchField(EntitySearchField.CREATED_TIME); + fromCreatedTimeCriteria.setSearchCondition(SearchCondition.GTE); + fromCreatedTimeCriteria.setValue(fromTime); + sharingFilters.add(fromCreatedTimeCriteria); + } + if (filtersCopy.containsKey(ExperimentSearchFields.TO_DATE)) { + String toTime = filtersCopy.remove(ExperimentSearchFields.TO_DATE); + SearchCriteria toCreatedTimeCriteria = new SearchCriteria(); + toCreatedTimeCriteria.setSearchField(EntitySearchField.CREATED_TIME); + toCreatedTimeCriteria.setSearchCondition(SearchCondition.LTE); + toCreatedTimeCriteria.setValue(toTime); + sharingFilters.add(toCreatedTimeCriteria); + } + if (filtersCopy.containsKey(ExperimentSearchFields.PROJECT_ID)) { + String projectId = filtersCopy.remove(ExperimentSearchFields.PROJECT_ID); + SearchCriteria projectParentEntityCriteria = new SearchCriteria(); + projectParentEntityCriteria.setSearchField(EntitySearchField.PARRENT_ENTITY_ID); + projectParentEntityCriteria.setSearchCondition(SearchCondition.EQUAL); + projectParentEntityCriteria.setValue(projectId); + sharingFilters.add(projectParentEntityCriteria); + } + if (filtersCopy.containsKey(ExperimentSearchFields.USER_NAME)) { + String username = filtersCopy.remove(ExperimentSearchFields.USER_NAME); + SearchCriteria usernameOwnerCriteria = new SearchCriteria(); + usernameOwnerCriteria.setSearchField(EntitySearchField.OWNER_ID); + usernameOwnerCriteria.setSearchCondition(SearchCondition.EQUAL); + usernameOwnerCriteria.setValue(username + "@" + gatewayId); + sharingFilters.add(usernameOwnerCriteria); + } + if (filtersCopy.containsKey(ExperimentSearchFields.EXPERIMENT_NAME)) { + String experimentName = filtersCopy.remove(ExperimentSearchFields.EXPERIMENT_NAME); + SearchCriteria experimentNameCriteria = new SearchCriteria(); + experimentNameCriteria.setSearchField(EntitySearchField.NAME); + experimentNameCriteria.setSearchCondition(SearchCondition.LIKE); + experimentNameCriteria.setValue(experimentName); + sharingFilters.add(experimentNameCriteria); + } + if (filtersCopy.containsKey(ExperimentSearchFields.EXPERIMENT_DESC)) { + String experimentDescription = filtersCopy.remove(ExperimentSearchFields.EXPERIMENT_DESC); + SearchCriteria experimentDescriptionCriteria = new SearchCriteria(); + experimentDescriptionCriteria.setSearchField(EntitySearchField.DESCRIPTION); + experimentDescriptionCriteria.setSearchCondition(SearchCondition.LIKE); + experimentDescriptionCriteria.setValue(experimentDescription); + sharingFilters.add(experimentDescriptionCriteria); + } + // Grab all of the matching experiments in the sharing registry + // unless all of the filtering can be done through the sharing API + int searchOffset = 0; + int searchLimit = Integer.MAX_VALUE; + boolean filteredInSharing = filtersCopy.isEmpty(); + if (filteredInSharing) { + searchOffset = offset; + searchLimit = limit; + } + sharingClient + .searchEntities( + authzToken.getClaimsMap().get(Constants.GATEWAY_ID), + userName + "@" + gatewayId, + sharingFilters, + searchOffset, + searchLimit) + .forEach(e -> accessibleExpIds.add(e.getEntityId())); + int finalOffset = offset; + // If no more filtering to be done (either empty or all done through sharing API), set the offset to 0 + if (filteredInSharing) { + finalOffset = 0; + } + return searchExperiments(gatewayId, userName, accessibleExpIds, filtersCopy, limit, finalOffset); + } + + public ExperimentStatus getExperimentStatus(String airavataExperimentId) throws RegistryException { + return registryService.getExperimentStatus(airavataExperimentId); + } + + public List getExperimentOutputs(String airavataExperimentId) throws RegistryException { + return registryService.getExperimentOutputs(airavataExperimentId); + } + + public ExperimentModel getDetailedExperimentTree(String airavataExperimentId) throws RegistryException { + return registryService.getDetailedExperimentTree(airavataExperimentId); + } + + public List getApplicationOutputs(String appInterfaceId) throws AppCatalogException { + return registryService.getApplicationOutputs(appInterfaceId); + } + + public ComputeResourceDescription getComputeResource(String computeResourceId) throws AppCatalogException { + return registryService.getComputeResource(computeResourceId); + } + + public String registerComputeResource(ComputeResourceDescription computeResourceDescription) throws AppCatalogException { + return registryService.registerComputeResource(computeResourceDescription); + } + + public boolean updateComputeResource(String computeResourceId, ComputeResourceDescription computeResourceDescription) throws AppCatalogException { + return registryService.updateComputeResource(computeResourceId, computeResourceDescription); + } + + public boolean deleteComputeResource(String computeResourceId) throws AppCatalogException { + return registryService.deleteComputeResource(computeResourceId); + } + + public Map getAllComputeResourceNames() throws AppCatalogException { + return registryService.getAllComputeResourceNames(); + } + + public String registerStorageResource(StorageResourceDescription storageResourceDescription) throws AppCatalogException { + return registryService.registerStorageResource(storageResourceDescription); + } + + public StorageResourceDescription getStorageResource(String storageResourceId) throws AppCatalogException { + return registryService.getStorageResource(storageResourceId); + } + + public boolean updateStorageResource(String storageResourceId, StorageResourceDescription storageResourceDescription) throws AppCatalogException { + return registryService.updateStorageResource(storageResourceId, storageResourceDescription); + } + + public boolean deleteStorageResource(String storageResourceId) throws AppCatalogException { + return registryService.deleteStorageResource(storageResourceId); + } + + public Map getAllStorageResourceNames() throws AppCatalogException { + return registryService.getAllStorageResourceNames(); + } + + public String registerGatewayResourceProfile(GatewayResourceProfile gatewayResourceProfile) throws AppCatalogException { + return registryService.registerGatewayResourceProfile(gatewayResourceProfile); + } + + public GatewayResourceProfile getGatewayResourceProfile(String gatewayID) throws AppCatalogException { + return registryService.getGatewayResourceProfile(gatewayID); + } + + public boolean updateGatewayResourceProfile(String gatewayID, GatewayResourceProfile gatewayResourceProfile) throws AppCatalogException { + return registryService.updateGatewayResourceProfile(gatewayID, gatewayResourceProfile); + } + + public boolean deleteGatewayResourceProfile(String gatewayID) throws AppCatalogException { + return registryService.deleteGatewayResourceProfile(gatewayID); + } + + public UserResourceProfile getUserResourceProfile(String userId, String gatewayId) throws AppCatalogException { + return registryService.getUserResourceProfile(userId, gatewayId); + } + + public boolean updateUserResourceProfile(String userId, String gatewayID, UserResourceProfile userResourceProfile) throws AppCatalogException { + return registryService.updateUserResourceProfile(userId, gatewayID, userResourceProfile); + } + + public boolean deleteUserResourceProfile(String userId, String gatewayID) throws AppCatalogException { + return registryService.deleteUserResourceProfile(userId, gatewayID); + } + + public GroupResourceProfile getGroupResourceProfile(String groupResourceProfileId) throws AppCatalogException { + return registryService.getGroupResourceProfile(groupResourceProfileId); + } + + public void updateGroupResourceProfile(GroupResourceProfile groupResourceProfile) throws AppCatalogException { + registryService.updateGroupResourceProfile(groupResourceProfile); + } + + public List getGroupResourceList(String gatewayId, List accessibleGroupResProfileIds) throws AppCatalogException { + return registryService.getGroupResourceList(gatewayId, accessibleGroupResProfileIds); + } + + public GatewayGroups getGatewayGroups(String gatewayId) throws RegistryException { + return registryService.getGatewayGroups(gatewayId); + } + + public boolean isGatewayGroupsExists(String gatewayId) throws RegistryException { + return registryService.isGatewayGroupsExists(gatewayId); + } + + public void updateExperimentConfiguration(String airavataExperimentId, UserConfigurationDataModel userConfiguration) throws RegistryException { + registryService.updateExperimentConfiguration(airavataExperimentId, userConfiguration); + } + + public void updateResourceScheduleing(String airavataExperimentId, ComputationalResourceSchedulingModel resourceScheduling) throws RegistryException { + registryService.updateResourceScheduleing(airavataExperimentId, resourceScheduling); + } + + public String registerApplicationDeployment(String gatewayId, ApplicationDeploymentDescription applicationDeployment) throws AppCatalogException { + return registryService.registerApplicationDeployment(gatewayId, applicationDeployment); + } + + public ApplicationDeploymentDescription getApplicationDeployment(String appDeploymentId) throws AppCatalogException { + return registryService.getApplicationDeployment(appDeploymentId); + } + + public boolean updateApplicationDeployment(String appDeploymentId, ApplicationDeploymentDescription applicationDeployment) throws AppCatalogException { + return registryService.updateApplicationDeployment(appDeploymentId, applicationDeployment); + } + + public boolean deleteApplicationDeployment(String appDeploymentId) throws AppCatalogException { + return registryService.deleteApplicationDeployment(appDeploymentId); + } + + public ApplicationInterfaceDescription getApplicationInterface(String appInterfaceId) throws AppCatalogException { + return registryService.getApplicationInterface(appInterfaceId); + } + + public List getApplicationDeployments(String appModuleId) throws AppCatalogException { + return registryService.getApplicationDeployments(appModuleId); + } + + public String registerApplicationInterface(String gatewayId, ApplicationInterfaceDescription applicationInterface) throws AppCatalogException { + return registryService.registerApplicationInterface(gatewayId, applicationInterface); + } + + public boolean updateApplicationInterface(String appInterfaceId, ApplicationInterfaceDescription applicationInterface) throws AppCatalogException { + return registryService.updateApplicationInterface(appInterfaceId, applicationInterface); + } + + public boolean deleteApplicationInterface(String appInterfaceId) throws AppCatalogException { + return registryService.deleteApplicationInterface(appInterfaceId); + } + + public Map getAllApplicationInterfaceNames(String gatewayId) throws AppCatalogException { + return registryService.getAllApplicationInterfaceNames(gatewayId); + } + + public List getAllApplicationInterfaces(String gatewayId) throws AppCatalogException { + return registryService.getAllApplicationInterfaces(gatewayId); + } + + public List getApplicationInputs(String appInterfaceId) throws AppCatalogException { + return registryService.getApplicationInputs(appInterfaceId); + } + + public String registerApplicationModule(String gatewayId, ApplicationModule applicationModule) throws AppCatalogException { + return registryService.registerApplicationModule(gatewayId, applicationModule); + } + + public ApplicationModule getApplicationModule(String appModuleId) throws AppCatalogException { + return registryService.getApplicationModule(appModuleId); + } + + public boolean updateApplicationModule(String appModuleId, ApplicationModule applicationModule) throws AppCatalogException { + return registryService.updateApplicationModule(appModuleId, applicationModule); + } + + public List getAllAppModules(String gatewayId) throws AppCatalogException { + return registryService.getAllAppModules(gatewayId); + } + + public boolean deleteApplicationModule(String appModuleId) throws AppCatalogException { + return registryService.deleteApplicationModule(appModuleId); + } + + public List getAccessibleAppModules(String gatewayId, List accessibleAppIds, List accessibleComputeResourceIds) throws AppCatalogException { + return registryService.getAccessibleAppModules(gatewayId, accessibleAppIds, accessibleComputeResourceIds); + } + + /** + * Get accessible app modules with sharing registry integration + */ + public List getAccessibleAppModulesWithSharing( + SharingRegistryService.Client sharingClient, + AuthzToken authzToken, + String gatewayId) throws Exception { + String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); + List accessibleAppDeploymentIds = new ArrayList<>(); + if (ServerSettings.isEnableSharing()) { + List sharingFilters = new ArrayList<>(); + SearchCriteria entityTypeFilter = new SearchCriteria(); + entityTypeFilter.setSearchField(EntitySearchField.ENTITY_TYPE_ID); + entityTypeFilter.setSearchCondition(SearchCondition.EQUAL); + entityTypeFilter.setValue(gatewayId + ":" + ResourceType.APPLICATION_DEPLOYMENT.name()); + sharingFilters.add(entityTypeFilter); + SearchCriteria permissionTypeFilter = new SearchCriteria(); + permissionTypeFilter.setSearchField(EntitySearchField.PERMISSION_TYPE_ID); + permissionTypeFilter.setSearchCondition(SearchCondition.EQUAL); + permissionTypeFilter.setValue(gatewayId + ":" + ResourcePermissionType.READ); + sharingFilters.add(permissionTypeFilter); + sharingClient + .searchEntities( + authzToken.getClaimsMap().get(Constants.GATEWAY_ID), + userName + "@" + gatewayId, + sharingFilters, + 0, + -1) + .forEach(a -> accessibleAppDeploymentIds.add(a.getEntityId())); + } + List accessibleComputeResourceIds = new ArrayList<>(); + List groupResourceProfileList = getGroupResourceListWithSharing( + sharingClient, authzToken, gatewayId); + for (GroupResourceProfile groupResourceProfile : groupResourceProfileList) { + List groupComputeResourcePreferenceList = + groupResourceProfile.getComputePreferences(); + for (GroupComputeResourcePreference groupComputeResourcePreference : + groupComputeResourcePreferenceList) { + accessibleComputeResourceIds.add(groupComputeResourcePreference.getComputeResourceId()); + } + } + return getAccessibleAppModules(gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); + } + + public Map getJobStatuses(String airavataExperimentId) throws RegistryException { + return registryService.getJobStatuses(airavataExperimentId); + } + + public List getJobDetails(String airavataExperimentId) throws RegistryException { + return registryService.getJobDetails(airavataExperimentId); + } + + public String addLocalSubmissionDetails(String computeResourceId, int priorityOrder, LOCALSubmission localSubmission) throws AppCatalogException { + return registryService.addLocalSubmissionDetails(computeResourceId, priorityOrder, localSubmission); + } + + public String addSSHJobSubmissionDetails(String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) throws AppCatalogException { + return registryService.addSSHJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); + } + + public String addSSHForkJobSubmissionDetails(String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) throws AppCatalogException { + return registryService.addSSHForkJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); + } + + public String addCloudJobSubmissionDetails(String computeResourceId, int priorityOrder, CloudJobSubmission cloudJobSubmission) throws AppCatalogException { + return registryService.addCloudJobSubmissionDetails(computeResourceId, priorityOrder, cloudJobSubmission); + } + + public String addUNICOREJobSubmissionDetails(String computeResourceId, int priorityOrder, UnicoreJobSubmission unicoreJobSubmission) throws AppCatalogException { + return registryService.addUNICOREJobSubmissionDetails(computeResourceId, priorityOrder, unicoreJobSubmission); + } + + public boolean updateLocalSubmissionDetails(String jobSubmissionInterfaceId, LOCALSubmission localSubmission) throws AppCatalogException { + return registryService.updateLocalSubmissionDetails(jobSubmissionInterfaceId, localSubmission); + } + + public LOCALSubmission getLocalJobSubmission(String jobSubmissionId) throws AppCatalogException { + return registryService.getLocalJobSubmission(jobSubmissionId); + } + + public SSHJobSubmission getSSHJobSubmission(String jobSubmissionId) throws AppCatalogException { + return registryService.getSSHJobSubmission(jobSubmissionId); + } + + public CloudJobSubmission getCloudJobSubmission(String jobSubmissionId) throws AppCatalogException { + return registryService.getCloudJobSubmission(jobSubmissionId); + } + + public UnicoreJobSubmission getUnicoreJobSubmission(String jobSubmissionId) throws AppCatalogException { + return registryService.getUnicoreJobSubmission(jobSubmissionId); + } + + public boolean updateSSHJobSubmissionDetails(String jobSubmissionInterfaceId, SSHJobSubmission sshJobSubmission) throws AppCatalogException { + return registryService.updateSSHJobSubmissionDetails(jobSubmissionInterfaceId, sshJobSubmission); + } + + public boolean updateCloudJobSubmissionDetails(String jobSubmissionInterfaceId, CloudJobSubmission cloudJobSubmission) throws AppCatalogException { + return registryService.updateCloudJobSubmissionDetails(jobSubmissionInterfaceId, cloudJobSubmission); + } + + public boolean updateUnicoreJobSubmissionDetails(String jobSubmissionInterfaceId, UnicoreJobSubmission unicoreJobSubmission) throws AppCatalogException { + return registryService.updateUnicoreJobSubmissionDetails(jobSubmissionInterfaceId, unicoreJobSubmission); + } + + public boolean deleteJobSubmissionInterface(String computeResourceId, String jobSubmissionInterfaceId) throws AppCatalogException { + return registryService.deleteJobSubmissionInterface(computeResourceId, jobSubmissionInterfaceId); + } + + public String registerResourceJobManager(ResourceJobManager resourceJobManager) throws AppCatalogException { + return registryService.registerResourceJobManager(resourceJobManager); + } + + public boolean updateResourceJobManager(String resourceJobManagerId, ResourceJobManager updatedResourceJobManager) throws AppCatalogException { + return registryService.updateResourceJobManager(resourceJobManagerId, updatedResourceJobManager); + } + + public ResourceJobManager getResourceJobManager(String resourceJobManagerId) throws AppCatalogException { + return registryService.getResourceJobManager(resourceJobManagerId); + } + + public boolean deleteResourceJobManager(String resourceJobManagerId) throws AppCatalogException { + return registryService.deleteResourceJobManager(resourceJobManagerId); + } + + public String addPasswordCredential(CredentialStoreService.Client csClient, PasswordCredential passwordCredential) throws CredentialStoreException, TException { + return csClient.addPasswordCredential(passwordCredential); + } + + public void deletePWDCredential(CredentialStoreService.Client csClient, String tokenId, String gatewayId) throws CredentialStoreException, TException { + csClient.deletePWDCredential(tokenId, gatewayId); + } + + public boolean deleteSSHCredential(CredentialStoreService.Client csClient, String tokenId, String gatewayId) throws CredentialStoreException, TException { + return csClient.deleteSSHCredential(tokenId, gatewayId); + } + + public CredentialSummary getCredentialSummary(CredentialStoreService.Client csClient, String tokenId, String gatewayId) throws CredentialStoreException, TException { + return csClient.getCredentialSummary(tokenId, gatewayId); + } + + public List getAllCredentialSummaries(CredentialStoreService.Client csClient, SummaryType type, List accessibleTokenIds, String gatewayId) throws CredentialStoreException, TException { + return csClient.getAllCredentialSummaries(type, accessibleTokenIds, gatewayId); + } + + public String addLocalDataMovementDetails(String resourceId, DMType dmType, int priorityOrder, LOCALDataMovement localDataMovement) throws AppCatalogException { + return registryService.addLocalDataMovementDetails(resourceId, dmType, priorityOrder, localDataMovement); + } + + public boolean updateLocalDataMovementDetails(String dataMovementInterfaceId, LOCALDataMovement localDataMovement) throws AppCatalogException { + return registryService.updateLocalDataMovementDetails(dataMovementInterfaceId, localDataMovement); + } + + public LOCALDataMovement getLocalDataMovement(String dataMovementId) throws AppCatalogException { + return registryService.getLocalDataMovement(dataMovementId); + } + + public String addSCPDataMovementDetails(String resourceId, DMType dmType, int priorityOrder, SCPDataMovement scpDataMovement) throws AppCatalogException { + return registryService.addSCPDataMovementDetails(resourceId, dmType, priorityOrder, scpDataMovement); + } + + public boolean updateSCPDataMovementDetails(String dataMovementInterfaceId, SCPDataMovement scpDataMovement) throws AppCatalogException { + return registryService.updateSCPDataMovementDetails(dataMovementInterfaceId, scpDataMovement); + } + + public List getUserProjects(String gatewayId, String userName, int limit, int offset) throws RegistryException { + return registryService.getUserProjects(gatewayId, userName, limit, offset); + } + + /** + * Get user projects with sharing registry integration + */ + public List getUserProjectsWithSharing( + SharingRegistryService.Client sharingClient, + AuthzToken authzToken, + String gatewayId, + String userName, + int limit, + int offset) throws Exception { + if (ServerSettings.isEnableSharing()) { + // user projects + user accessible projects + List accessibleProjectIds = new ArrayList<>(); + List filters = new ArrayList<>(); + SearchCriteria searchCriteria = new SearchCriteria(); + searchCriteria.setSearchField(EntitySearchField.ENTITY_TYPE_ID); + searchCriteria.setSearchCondition(SearchCondition.EQUAL); + searchCriteria.setValue(gatewayId + ":PROJECT"); + filters.add(searchCriteria); + sharingClient + .searchEntities( + authzToken.getClaimsMap().get(Constants.GATEWAY_ID), + userName + "@" + gatewayId, + filters, + 0, + -1) + .stream() + .forEach(p -> accessibleProjectIds.add(p.getEntityId())); + List result; + if (accessibleProjectIds.isEmpty()) { + result = Collections.emptyList(); + } else { + result = searchProjects( + gatewayId, userName, accessibleProjectIds, new HashMap<>(), limit, offset); + } + return result; + } else { + return getUserProjects(gatewayId, userName, limit, offset); + } + } + + public List getAccessibleApplicationDeployments(String gatewayId, List accessibleAppDeploymentIds, List accessibleComputeResourceIds) throws AppCatalogException { + return registryService.getAccessibleApplicationDeployments(gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); + } + + /** + * Get accessible application deployments with sharing registry integration + */ + public List getAccessibleApplicationDeploymentsWithSharing( + SharingRegistryService.Client sharingClient, + AuthzToken authzToken, + String gatewayId, + ResourcePermissionType permissionType) throws Exception { + String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); + List accessibleAppDeploymentIds = new ArrayList<>(); + if (ServerSettings.isEnableSharing()) { + List sharingFilters = new ArrayList<>(); + SearchCriteria entityTypeFilter = new SearchCriteria(); + entityTypeFilter.setSearchField(EntitySearchField.ENTITY_TYPE_ID); + entityTypeFilter.setSearchCondition(SearchCondition.EQUAL); + entityTypeFilter.setValue(gatewayId + ":" + ResourceType.APPLICATION_DEPLOYMENT.name()); + sharingFilters.add(entityTypeFilter); + SearchCriteria permissionTypeFilter = new SearchCriteria(); + permissionTypeFilter.setSearchField(EntitySearchField.PERMISSION_TYPE_ID); + permissionTypeFilter.setSearchCondition(SearchCondition.EQUAL); + permissionTypeFilter.setValue(gatewayId + ":" + permissionType.name()); + sharingFilters.add(permissionTypeFilter); + sharingClient + .searchEntities( + authzToken.getClaimsMap().get(Constants.GATEWAY_ID), + userName + "@" + gatewayId, + sharingFilters, + 0, + -1) + .forEach(a -> accessibleAppDeploymentIds.add(a.getEntityId())); + } + List accessibleComputeResourceIds = new ArrayList<>(); + List groupResourceProfileList = getGroupResourceListWithSharing( + sharingClient, authzToken, gatewayId); + for (GroupResourceProfile groupResourceProfile : groupResourceProfileList) { + List groupComputeResourcePreferenceList = + groupResourceProfile.getComputePreferences(); + for (GroupComputeResourcePreference groupComputeResourcePreference : + groupComputeResourcePreferenceList) { + accessibleComputeResourceIds.add(groupComputeResourcePreference.getComputeResourceId()); + } + } + return getAccessibleApplicationDeployments(gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); + } + + public List getAppModuleDeployedResources(String appModuleId) throws AppCatalogException { + return registryService.getAppModuleDeployedResources(appModuleId); + } + + public List getAccessibleApplicationDeploymentsForAppModule(String appModuleId, String gatewayId, List accessibleAppDeploymentIds, List accessibleComputeResourceIds) throws AppCatalogException { + return registryService.getAccessibleApplicationDeploymentsForAppModule(gatewayId, appModuleId, accessibleAppDeploymentIds, accessibleComputeResourceIds); + } + + public Map getAvailableAppInterfaceComputeResources(String appInterfaceId) throws AppCatalogException { + return registryService.getAvailableAppInterfaceComputeResources(appInterfaceId); + } + + public SCPDataMovement getSCPDataMovement(String dataMovementId) throws AppCatalogException { + return registryService.getSCPDataMovement(dataMovementId); + } + + public String addUnicoreDataMovementDetails(String resourceId, DMType dmType, int priorityOrder, UnicoreDataMovement unicoreDataMovement) throws AppCatalogException { + return registryService.addUnicoreDataMovementDetails(resourceId, dmType, priorityOrder, unicoreDataMovement); + } + + public boolean updateUnicoreDataMovementDetails(String dataMovementInterfaceId, UnicoreDataMovement unicoreDataMovement) throws AppCatalogException { + return registryService.updateUnicoreDataMovementDetails(dataMovementInterfaceId, unicoreDataMovement); + } + + public UnicoreDataMovement getUnicoreDataMovement(String dataMovementId) throws AppCatalogException { + return registryService.getUnicoreDataMovement(dataMovementId); + } + + public String addGridFTPDataMovementDetails(String resourceId, DMType dmType, int priorityOrder, GridFTPDataMovement gridFTPDataMovement) throws AppCatalogException { + return registryService.addGridFTPDataMovementDetails(resourceId, dmType, priorityOrder, gridFTPDataMovement); + } + + public boolean updateGridFTPDataMovementDetails(String dataMovementInterfaceId, GridFTPDataMovement gridFTPDataMovement) throws AppCatalogException { + return registryService.updateGridFTPDataMovementDetails(dataMovementInterfaceId, gridFTPDataMovement); + } + + public GridFTPDataMovement getGridFTPDataMovement(String dataMovementId) throws AppCatalogException { + return registryService.getGridFTPDataMovement(dataMovementId); + } + + public boolean deleteDataMovementInterface(String resourceId, String dataMovementInterfaceId, DMType dmType) throws AppCatalogException { + return registryService.deleteDataMovementInterface(resourceId, dataMovementInterfaceId, dmType); + } + + public boolean deleteBatchQueue(String computeResourceId, String queueName) throws AppCatalogException { + return registryService.deleteBatchQueue(computeResourceId, queueName); + } + + public boolean addGatewayComputeResourcePreference(String gatewayID, String computeResourceId, ComputeResourcePreference computeResourcePreference) throws AppCatalogException { + return registryService.addGatewayComputeResourcePreference(gatewayID, computeResourceId, computeResourcePreference); + } + + public boolean addGatewayStoragePreference(String gatewayID, String storageResourceId, StoragePreference dataStoragePreference) throws AppCatalogException { + return registryService.addGatewayStoragePreference(gatewayID, storageResourceId, dataStoragePreference); + } + + public ComputeResourcePreference getGatewayComputeResourcePreference(String gatewayID, String computeResourceId) throws AppCatalogException { + return registryService.getGatewayComputeResourcePreference(gatewayID, computeResourceId); + } + + public StoragePreference getGatewayStoragePreference(String gatewayID, String storageId) throws AppCatalogException { + return registryService.getGatewayStoragePreference(gatewayID, storageId); + } + + public List getAllGatewayComputeResourcePreferences(String gatewayID) throws AppCatalogException { + return registryService.getAllGatewayComputeResourcePreferences(gatewayID); + } + + public List getAllGatewayStoragePreferences(String gatewayID) throws AppCatalogException { + return registryService.getAllGatewayStoragePreferences(gatewayID); + } + + public List getAllGatewayResourceProfiles() throws AppCatalogException { + return registryService.getAllGatewayResourceProfiles(); + } + + public boolean updateGatewayComputeResourcePreference(String gatewayID, String computeResourceId, ComputeResourcePreference computeResourcePreference) throws AppCatalogException { + return registryService.updateGatewayComputeResourcePreference(gatewayID, computeResourceId, computeResourcePreference); + } + + public boolean updateGatewayStoragePreference(String gatewayID, String storageId, StoragePreference dataStoragePreference) throws AppCatalogException { + return registryService.updateGatewayStoragePreference(gatewayID, storageId, dataStoragePreference); + } + + public boolean deleteGatewayComputeResourcePreference(String gatewayID, String computeResourceId) throws AppCatalogException { + return registryService.deleteGatewayComputeResourcePreference(gatewayID, computeResourceId); + } + + public boolean deleteGatewayStoragePreference(String gatewayID, String storageId) throws AppCatalogException { + return registryService.deleteGatewayStoragePreference(gatewayID, storageId); + } + + public String registerUserResourceProfile(UserResourceProfile userResourceProfile) throws AppCatalogException { + return registryService.registerUserResourceProfile(userResourceProfile); + } + + public boolean isUserResourceProfileExists(String userId, String gatewayId) throws AppCatalogException { + return registryService.isUserResourceProfileExists(userId, gatewayId); + } + + public boolean addUserComputeResourcePreference(String userId, String gatewayID, String computeResourceId, UserComputeResourcePreference userComputeResourcePreference) throws AppCatalogException { + return registryService.addUserComputeResourcePreference(userId, gatewayID, computeResourceId, userComputeResourcePreference); + } + + public boolean addUserStoragePreference(String userId, String gatewayID, String userStorageResourceId, UserStoragePreference dataStoragePreference) throws AppCatalogException { + return registryService.addUserStoragePreference(userId, gatewayID, userStorageResourceId, dataStoragePreference); + } + + public UserComputeResourcePreference getUserComputeResourcePreference(String userId, String gatewayID, String userComputeResourceId) throws AppCatalogException { + return registryService.getUserComputeResourcePreference(userId, gatewayID, userComputeResourceId); + } + + public UserStoragePreference getUserStoragePreference(String userId, String gatewayID, String userStorageId) throws AppCatalogException { + return registryService.getUserStoragePreference(userId, gatewayID, userStorageId); + } + + public List getAllUserComputeResourcePreferences(String userId, String gatewayID) throws AppCatalogException { + return registryService.getAllUserComputeResourcePreferences(userId, gatewayID); + } + + public List getAllUserStoragePreferences(String userId, String gatewayID) throws AppCatalogException { + return registryService.getAllUserStoragePreferences(userId, gatewayID); + } + + public List getAllUserResourceProfiles() throws AppCatalogException { + return registryService.getAllUserResourceProfiles(); + } + + public boolean updateUserComputeResourcePreference(String userId, String gatewayID, String computeResourceId, UserComputeResourcePreference userComputeResourcePreference) throws AppCatalogException { + return registryService.updateUserComputeResourcePreference(userId, gatewayID, computeResourceId, userComputeResourcePreference); + } + + public boolean updateUserStoragePreference(String userId, String gatewayID, String userStorageId, UserStoragePreference userStoragePreference) throws AppCatalogException { + return registryService.updateUserStoragePreference(userId, gatewayID, userStorageId, userStoragePreference); + } + + public boolean deleteUserComputeResourcePreference(String userId, String gatewayID, String userComputeResourceId) throws AppCatalogException { + return registryService.deleteUserComputeResourcePreference(userId, gatewayID, userComputeResourceId); + } + + public boolean deleteUserStoragePreference(String userId, String gatewayID, String userStorageId) throws AppCatalogException { + return registryService.deleteUserStoragePreference(userId, gatewayID, userStorageId); + } + + public List getLatestQueueStatuses() throws RegistryException { + return registryService.getLatestQueueStatuses(); + } + + public String createGroupResourceProfile(GroupResourceProfile groupResourceProfile) throws AppCatalogException { + return registryService.createGroupResourceProfile(groupResourceProfile); + } + + public boolean removeGroupResourceProfile(String groupResourceProfileId) throws AppCatalogException { + return registryService.removeGroupResourceProfile(groupResourceProfileId); + } + + public boolean removeGroupComputePrefs(String computeResourceId, String groupResourceProfileId) throws AppCatalogException { + return registryService.removeGroupComputePrefs(computeResourceId, groupResourceProfileId); + } + + public GroupComputeResourcePreference getGroupComputeResourcePreference(String computeResourceId, String groupResourceProfileId) throws AppCatalogException { + return registryService.getGroupComputeResourcePreference(computeResourceId, groupResourceProfileId); + } + + public ComputeResourcePolicy getGroupComputeResourcePolicy(String resourcePolicyId) throws AppCatalogException { + return registryService.getGroupComputeResourcePolicy(resourcePolicyId); + } + + public boolean removeGroupComputeResourcePolicy(String resourcePolicyId) throws AppCatalogException { + return registryService.removeGroupComputeResourcePolicy(resourcePolicyId); + } + + public BatchQueueResourcePolicy getBatchQueueResourcePolicy(String resourcePolicyId) throws AppCatalogException { + return registryService.getBatchQueueResourcePolicy(resourcePolicyId); + } + + public boolean removeGroupBatchQueueResourcePolicy(String resourcePolicyId) throws AppCatalogException { + return registryService.removeGroupBatchQueueResourcePolicy(resourcePolicyId); + } + + public List getGroupComputeResourcePrefList(String groupResourceProfileId) throws AppCatalogException { + return registryService.getGroupComputeResourcePrefList(groupResourceProfileId); + } + + public List getGroupBatchQueueResourcePolicyList(String groupResourceProfileId) throws AppCatalogException { + return registryService.getGroupBatchQueueResourcePolicyList(groupResourceProfileId); + } + + public List getGroupComputeResourcePolicyList(String groupResourceProfileId) throws AppCatalogException { + return registryService.getGroupComputeResourcePolicyList(groupResourceProfileId); + } + + public Parser getParser(String parserId, String gatewayId) throws RegistryException { + return registryService.getParser(parserId, gatewayId); + } + + public String saveParser(Parser parser) throws RegistryException { + return registryService.saveParser(parser); + } + + public List listAllParsers(String gatewayId) throws RegistryException { + return registryService.listAllParsers(gatewayId); + } + + public void removeParser(String parserId, String gatewayId) throws RegistryException { + registryService.removeParser(parserId, gatewayId); + } + + public ParsingTemplate getParsingTemplate(String templateId, String gatewayId) throws RegistryException { + return registryService.getParsingTemplate(templateId, gatewayId); + } + + public List getParsingTemplatesForExperiment(String experimentId, String gatewayId) throws RegistryException { + return registryService.getParsingTemplatesForExperiment(experimentId, gatewayId); + } + + public String saveParsingTemplate(ParsingTemplate parsingTemplate) throws RegistryException { + return registryService.saveParsingTemplate(parsingTemplate); + } + + public void removeParsingTemplate(String templateId, String gatewayId) throws RegistryException { + registryService.removeParsingTemplate(templateId, gatewayId); + } + + public List listAllParsingTemplates(String gatewayId) throws RegistryException { + return registryService.listAllParsingTemplates(gatewayId); + } + + // Helper methods for sharing registry and authorization + public GatewayGroups retrieveGatewayGroups(String gatewayId) throws TException { + try { + if (isGatewayGroupsExists(gatewayId)) { + return getGatewayGroups(gatewayId); + } else { + return GatewayGroupsInitializer.initializeGatewayGroups(gatewayId); + } + } catch (Exception e) { + throw new TException("Error retrieving gateway groups: " + e.getMessage(), e); + } + } + + public void createManageSharingPermissionTypeIfMissing( + SharingRegistryService.Client sharingClient, String domainId) throws TException { + // AIRAVATA-3297 Some gateways were created without the MANAGE_SHARING permission, so add it if missing + String permissionTypeId = domainId + ":MANAGE_SHARING"; + try { + if (!sharingClient.isPermissionExists(domainId, permissionTypeId)) { + PermissionType permissionType = new PermissionType(); + permissionType.setPermissionTypeId(permissionTypeId); + permissionType.setDomainId(domainId); + permissionType.setName("MANAGE_SHARING"); + permissionType.setDescription("Manage sharing permission type"); + sharingClient.createPermissionType(permissionType); + logger.info("Created MANAGE_SHARING permission type for domain " + domainId); + } + } catch (TException e) { + throw e; + } catch (Exception e) { + throw new TException("Error creating MANAGE_SHARING permission type", e); + } + } + + public void shareEntityWithAdminGatewayGroups( + SharingRegistryService.Client sharingClient, Entity entity) + throws TException { + final String domainId = entity.getDomainId(); + GatewayGroups gatewayGroups = retrieveGatewayGroups(domainId); + createManageSharingPermissionTypeIfMissing(sharingClient, domainId); + sharingClient.shareEntityWithGroups( + domainId, + entity.getEntityId(), + Arrays.asList(gatewayGroups.getAdminsGroupId()), + domainId + ":MANAGE_SHARING", + true); + sharingClient.shareEntityWithGroups( + domainId, + entity.getEntityId(), + Arrays.asList(gatewayGroups.getAdminsGroupId()), + domainId + ":WRITE", + true); + sharingClient.shareEntityWithGroups( + domainId, + entity.getEntityId(), + Arrays.asList(gatewayGroups.getAdminsGroupId(), gatewayGroups.getReadOnlyAdminsGroupId()), + domainId + ":READ", + true); + } + + public boolean userHasAccessInternal( + SharingRegistryService.Client sharingClient, + AuthzToken authzToken, + String entityId, + ResourcePermissionType permissionType) { + final String domainId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + final String userId = authzToken.getClaimsMap().get(Constants.USER_NAME) + "@" + domainId; + try { + final boolean hasOwnerAccess = sharingClient.userHasAccess( + domainId, userId, entityId, domainId + ":" + ResourcePermissionType.OWNER); + boolean hasAccess = false; + if (permissionType.equals(ResourcePermissionType.WRITE)) { + hasAccess = hasOwnerAccess + || sharingClient.userHasAccess( + domainId, userId, entityId, domainId + ":" + ResourcePermissionType.WRITE); + } else if (permissionType.equals(ResourcePermissionType.READ)) { + hasAccess = hasOwnerAccess + || sharingClient.userHasAccess( + domainId, userId, entityId, domainId + ":" + ResourcePermissionType.READ); + } else if (permissionType.equals(ResourcePermissionType.MANAGE_SHARING)) { + hasAccess = hasOwnerAccess + || sharingClient.userHasAccess( + domainId, userId, entityId, domainId + ":" + ResourcePermissionType.MANAGE_SHARING); + } else if (permissionType.equals(ResourcePermissionType.OWNER)) { + hasAccess = hasOwnerAccess; + } + return hasAccess; + } catch (Exception e) { + throw new RuntimeException("Unable to check if user has access", e); + } + } + + // Credential management methods + public String generateAndRegisterSSHKeys( + CredentialStoreService.Client csClient, + SharingRegistryService.Client sharingClient, + String gatewayId, + String userName, + String description) throws Exception { + SSHCredential sshCredential = new SSHCredential(); + sshCredential.setUsername(userName); + sshCredential.setGatewayId(gatewayId); + sshCredential.setDescription(description); + String key = csClient.addSSHCredential(sshCredential); + try { + Entity entity = new Entity(); + entity.setEntityId(key); + entity.setDomainId(gatewayId); + entity.setEntityTypeId(gatewayId + ":" + ResourceType.CREDENTIAL_TOKEN); + entity.setOwnerId(userName + "@" + gatewayId); + entity.setName(key); + entity.setDescription(description); + sharingClient.createEntity(entity); + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + logger.error("Rolling back ssh key creation for user " + userName + " and description [" + description + + "]"); + csClient.deleteSSHCredential(key, gatewayId); + throw new Exception("Failed to create sharing registry record", ex); + } + logger.debug("Airavata generated SSH keys for gateway : " + gatewayId + " and for user : " + userName); + return key; + } + + public String registerPwdCredential( + CredentialStoreService.Client csClient, + SharingRegistryService.Client sharingClient, + String gatewayId, + String userName, + String loginUserName, + String password, + String description) throws Exception { + PasswordCredential pwdCredential = new PasswordCredential(); + pwdCredential.setPortalUserName(userName); + pwdCredential.setLoginUserName(loginUserName); + pwdCredential.setPassword(password); + pwdCredential.setDescription(description); + pwdCredential.setGatewayId(gatewayId); + String key = addPasswordCredential(csClient, pwdCredential); + try { + Entity entity = new Entity(); + entity.setEntityId(key); + entity.setDomainId(gatewayId); + entity.setEntityTypeId(gatewayId + ":" + ResourceType.CREDENTIAL_TOKEN); + entity.setOwnerId(userName + "@" + gatewayId); + entity.setName(key); + entity.setDescription(description); + sharingClient.createEntity(entity); + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + logger.error("Rolling back password registration for user " + userName + " and description [" + + description + "]"); + try { + deletePWDCredential(csClient, key, gatewayId); + } catch (Exception rollbackEx) { + logger.error("Failed to rollback password credential deletion", rollbackEx); + } + throw new Exception("Failed to create sharing registry record", ex); + } + logger.debug("Airavata generated PWD credential for gateway : " + gatewayId + " and for user : " + + loginUserName); + return key; + } + + public CredentialSummary getCredentialSummaryWithAuth( + CredentialStoreService.Client csClient, + SharingRegistryService.Client sharingClient, + AuthzToken authzToken, + String tokenId, + String gatewayId) throws Exception { + if (!userHasAccessInternal(sharingClient, authzToken, tokenId, ResourcePermissionType.READ)) { + throw new Exception("User does not have permission to access this resource"); + } + CredentialSummary credentialSummary = getCredentialSummary(csClient, tokenId, gatewayId); + logger.debug("Airavata retrived the credential summary for token " + tokenId + "GatewayId: " + gatewayId); + return credentialSummary; + } + + public List getAllCredentialSummariesWithAuth( + CredentialStoreService.Client csClient, + SharingRegistryService.Client sharingClient, + AuthzToken authzToken, + SummaryType type, + String gatewayId, + String userName) throws Exception { + List filters = new ArrayList<>(); + SearchCriteria searchCriteria = new SearchCriteria(); + searchCriteria.setSearchField(EntitySearchField.ENTITY_TYPE_ID); + searchCriteria.setSearchCondition(SearchCondition.EQUAL); + searchCriteria.setValue(gatewayId + ":" + ResourceType.CREDENTIAL_TOKEN.name()); + filters.add(searchCriteria); + List accessibleTokenIds = + sharingClient.searchEntities(gatewayId, userName + "@" + gatewayId, filters, 0, -1).stream() + .map(p -> p.getEntityId()) + .collect(Collectors.toList()); + List credentialSummaries = + getAllCredentialSummaries(csClient, type, accessibleTokenIds, gatewayId); + logger.debug( + "Airavata successfully retrived credential summaries of type " + type + " GatewayId: " + gatewayId); + return credentialSummaries; + } + + public boolean deleteSSHPubKey( + CredentialStoreService.Client csClient, + SharingRegistryService.Client sharingClient, + AuthzToken authzToken, + String airavataCredStoreToken, + String gatewayId) throws Exception { + if (!userHasAccessInternal( + sharingClient, authzToken, airavataCredStoreToken, ResourcePermissionType.WRITE)) { + throw new Exception("User does not have permission to delete this resource."); + } + logger.debug("Airavata deleted SSH pub key for gateway Id : " + gatewayId + " and with token id : " + + airavataCredStoreToken); + return deleteSSHCredential(csClient, airavataCredStoreToken, gatewayId); + } + + public boolean deletePWDCredentialWithAuth( + CredentialStoreService.Client csClient, + SharingRegistryService.Client sharingClient, + AuthzToken authzToken, + String airavataCredStoreToken, + String gatewayId) throws Exception { + if (!userHasAccessInternal( + sharingClient, authzToken, airavataCredStoreToken, ResourcePermissionType.WRITE)) { + throw new Exception("User does not have permission to delete this resource."); + } + logger.debug("Airavata deleted PWD credential for gateway Id : " + gatewayId + " and with token id : " + + airavataCredStoreToken); + deletePWDCredential(csClient, airavataCredStoreToken, gatewayId); + return true; + } + + // Project management methods with sharing registry integration + public String createProjectWithSharing( + SharingRegistryService.Client sharingClient, + String gatewayId, + Project project) throws Exception { + String projectId = createProject(gatewayId, project); + if (ServerSettings.isEnableSharing()) { + try { + Entity entity = new Entity(); + entity.setEntityId(projectId); + final String domainId = project.getGatewayId(); + entity.setDomainId(domainId); + entity.setEntityTypeId(domainId + ":" + "PROJECT"); + entity.setOwnerId(project.getOwner() + "@" + domainId); + entity.setName(project.getName()); + entity.setDescription(project.getDescription()); + sharingClient.createEntity(entity); + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + logger.error("Rolling back project creation Proj ID : " + projectId); + try { + deleteProject(projectId); + } catch (RegistryException rollbackEx) { + logger.error("Failed to rollback project deletion", rollbackEx); + } + throw new Exception("Failed to create entry for project in Sharing Registry", ex); + } + } + logger.debug("Airavata created project with project Id : " + projectId + " for gateway Id : " + gatewayId); + return projectId; + } + + public void updateProjectWithAuth( + SharingRegistryService.Client sharingClient, + AuthzToken authzToken, + String projectId, + Project updatedProject) throws Exception { + Project existingProject = getProject(projectId); + if (ServerSettings.isEnableSharing() + && !authzToken + .getClaimsMap() + .get(Constants.USER_NAME) + .equals(existingProject.getOwner()) + || !authzToken + .getClaimsMap() + .get(Constants.GATEWAY_ID) + .equals(existingProject.getGatewayId())) { + 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 Exception("User does not have permission to access this resource"); + } + } + if (!updatedProject.getOwner().equals(existingProject.getOwner())) { + throw new Exception("Owner of a project cannot be changed"); + } + if (!updatedProject.getGatewayId().equals(existingProject.getGatewayId())) { + throw new Exception("Gateway ID of a project cannot be changed"); + } + updateProject(projectId, updatedProject); + logger.debug("Airavata updated project with project Id : " + projectId); + } + + public boolean deleteProjectWithAuth( + SharingRegistryService.Client sharingClient, + AuthzToken authzToken, + String projectId) throws Exception { + Project existingProject = getProject(projectId); + if (ServerSettings.isEnableSharing() + && !authzToken + .getClaimsMap() + .get(Constants.USER_NAME) + .equals(existingProject.getOwner()) + || !authzToken + .getClaimsMap() + .get(Constants.GATEWAY_ID) + .equals(existingProject.getGatewayId())) { + 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 Exception("User does not have permission to access this resource"); + } + } + boolean ret = deleteProject(projectId); + logger.debug("Airavata deleted project with project Id : " + projectId); + return ret; + } + + public Project getProjectWithAuth( + SharingRegistryService.Client sharingClient, + AuthzToken authzToken, + String projectId) throws Exception { + Project project = getProject(projectId); + if (authzToken + .getClaimsMap() + .get(Constants.USER_NAME) + .equals(project.getOwner()) + && authzToken + .getClaimsMap() + .get(Constants.GATEWAY_ID) + .equals(project.getGatewayId())) { + return project; + } else if (ServerSettings.isEnableSharing()) { + 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 Exception("User does not have permission to access this resource"); + } + return project; + } else { + return null; + } + } + + // Experiment management methods with sharing registry integration + public String createExperimentWithSharing( + SharingRegistryService.Client sharingClient, + String gatewayId, + ExperimentModel experiment) throws Exception { + String experimentId = createExperiment(gatewayId, experiment); + + if (ServerSettings.isEnableSharing()) { + try { + Entity entity = new Entity(); + entity.setEntityId(experimentId); + final String domainId = experiment.getGatewayId(); + entity.setDomainId(domainId); + entity.setEntityTypeId(domainId + ":" + "EXPERIMENT"); + entity.setOwnerId(experiment.getUserName() + "@" + domainId); + entity.setName(experiment.getExperimentName()); + entity.setDescription(experiment.getDescription()); + entity.setParentEntityId(experiment.getProjectId()); + + sharingClient.createEntity(entity); + shareEntityWithAdminGatewayGroups(sharingClient, entity); + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + logger.error("Rolling back experiment creation Exp ID : " + experimentId); + deleteExperiment(experimentId); + throw new Exception("Failed to create sharing registry record", ex); + } + } + + logger.info( + experimentId, + "Created new experiment with experiment name {} and id ", + experiment.getExperimentName(), + experimentId); + return experimentId; + } + + public String createExperimentWithSharingAndPublish( + SharingRegistryService.Client sharingClient, + Publisher statusPublisher, + String gatewayId, + ExperimentModel experiment) throws Exception { + String experimentId = createExperimentWithSharing(sharingClient, gatewayId, experiment); + + if (statusPublisher != null) { + ExperimentStatusChangeEvent event = + new ExperimentStatusChangeEvent(ExperimentState.CREATED, experimentId, gatewayId); + String messageId = AiravataUtils.getId("EXPERIMENT"); + MessageContext messageContext = new MessageContext(event, MessageType.EXPERIMENT, messageId, gatewayId); + messageContext.setUpdatedTime(AiravataUtils.getCurrentTimestamp()); + statusPublisher.publish(messageContext); + } + + return experimentId; + } + + public void validateLaunchExperimentAccess( + SharingRegistryService.Client sharingClient, + AuthzToken authzToken, + String gatewayId, + ExperimentModel experiment) throws Exception { + String username = authzToken.getClaimsMap().get(Constants.USER_NAME); + + // For backwards compatibility, if there is no groupResourceProfileId, look up one that is shared with the user + if (!experiment.getUserConfigurationData().isSetGroupResourceProfileId()) { + // This will be handled by the handler calling getGroupResourceList + throw new Exception("Experiment doesn't have groupResourceProfileId"); + } + + // Verify user has READ access to groupResourceProfileId + if (!sharingClient.userHasAccess( + gatewayId, + username + "@" + gatewayId, + experiment.getUserConfigurationData().getGroupResourceProfileId(), + gatewayId + ":READ")) { + throw new Exception("User " + username + " in gateway " + gatewayId + + " doesn't have access to group resource profile " + + experiment.getUserConfigurationData().getGroupResourceProfileId()); + } + + // Verify user has READ access to Application Deployment + final String appInterfaceId = experiment.getExecutionId(); + ApplicationInterfaceDescription applicationInterfaceDescription = + getApplicationInterface(appInterfaceId); + + List appModuleIds = applicationInterfaceDescription.getApplicationModules(); + // Assume that there is only one app module for this interface + String appModuleId = appModuleIds.get(0); + List applicationDeploymentDescriptions = + getApplicationDeployments(appModuleId); + + if (!experiment.getUserConfigurationData().isAiravataAutoSchedule()) { + final String resourceHostId = experiment + .getUserConfigurationData() + .getComputationalResourceScheduling() + .getResourceHostId(); + + Optional applicationDeploymentDescription = + applicationDeploymentDescriptions.stream() + .filter(dep -> dep.getComputeHostId().equals(resourceHostId)) + .findFirst(); + if (applicationDeploymentDescription.isPresent()) { + final String appDeploymentId = + applicationDeploymentDescription.get().getAppDeploymentId(); + if (!sharingClient.userHasAccess( + gatewayId, username + "@" + gatewayId, appDeploymentId, gatewayId + ":READ")) { + throw new Exception("User " + username + " in gateway " + gatewayId + + " doesn't have access to app deployment " + appDeploymentId); + } + } else { + throw new Exception("Application deployment doesn't exist for application interface " + + appInterfaceId + " and host " + resourceHostId + " in gateway " + gatewayId); + } + } else if (experiment.getUserConfigurationData().getAutoScheduledCompResourceSchedulingList() != null + && !experiment + .getUserConfigurationData() + .getAutoScheduledCompResourceSchedulingList() + .isEmpty()) { + List compResourceSchedulingList = + experiment.getUserConfigurationData().getAutoScheduledCompResourceSchedulingList(); + for (ComputationalResourceSchedulingModel crScheduling : compResourceSchedulingList) { + Optional applicationDeploymentDescription = + applicationDeploymentDescriptions.stream() + .filter(dep -> dep.getComputeHostId().equals(crScheduling.getResourceHostId())) + .findFirst(); + if (applicationDeploymentDescription.isPresent()) { + final String appDeploymentId = + applicationDeploymentDescription.get().getAppDeploymentId(); + if (!sharingClient.userHasAccess( + gatewayId, username + "@" + gatewayId, appDeploymentId, gatewayId + ":READ")) { + throw new Exception("User " + username + " in gateway " + gatewayId + + " doesn't have access to app deployment " + appDeploymentId); + } + } + } + } + } + + public boolean deleteExperimentWithAuth( + SharingRegistryService.Client sharingClient, + AuthzToken authzToken, + String experimentId) throws Exception { + ExperimentModel experimentModel = getExperiment(experimentId); + + if (ServerSettings.isEnableSharing() + && !authzToken + .getClaimsMap() + .get(Constants.USER_NAME) + .equals(experimentModel.getUserName()) + || !authzToken + .getClaimsMap() + .get(Constants.GATEWAY_ID) + .equals(experimentModel.getGatewayId())) { + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + if (!sharingClient.userHasAccess( + gatewayId, userId + "@" + gatewayId, experimentId, gatewayId + ":WRITE")) { + throw new Exception("User does not have permission to access this resource"); + } + } + + if (!(experimentModel.getExperimentStatus().get(0).getState() == org.apache.airavata.model.status.ExperimentState.CREATED)) { + throw new Exception("Experiment is not in CREATED state. Hence cannot deleted. ID:" + experimentId); + } + return deleteExperiment(experimentId); + } + + public ResourceType getResourceType(SharingRegistryService.Client sharingClient, String domainId, String entityId) + throws TException { + Entity entity = sharingClient.getEntity(domainId, entityId); + for (ResourceType resourceType : ResourceType.values()) { + if (entity.getEntityTypeId().equals(domainId + ":" + resourceType.name())) { + return resourceType; + } + } + throw new RuntimeException("Unrecognized entity type id: " + entity.getEntityTypeId()); + } + + // Gateway management methods with sharing registry integration + public String addGatewayWithSharing( + RegistryService.Client registryClient, + SharingRegistryService.Client sharingClient, + Gateway gateway) throws Exception { + String gatewayId = registryClient.addGateway(gateway); + Domain domain = new Domain(); + domain.setDomainId(gateway.getGatewayId()); + domain.setName(gateway.getGatewayName()); + domain.setDescription("Domain entry for " + domain.getName()); + sharingClient.createDomain(domain); + + // Creating Entity Types for each domain + EntityType entityType = new EntityType(); + entityType.setEntityTypeId(domain.getDomainId() + ":PROJECT"); + entityType.setDomainId(domain.getDomainId()); + entityType.setName("PROJECT"); + entityType.setDescription("Project entity type"); + sharingClient.createEntityType(entityType); + + entityType = new EntityType(); + entityType.setEntityTypeId(domain.getDomainId() + ":EXPERIMENT"); + entityType.setDomainId(domain.getDomainId()); + entityType.setName("EXPERIMENT"); + entityType.setDescription("Experiment entity type"); + sharingClient.createEntityType(entityType); + + entityType = new EntityType(); + entityType.setEntityTypeId(domain.getDomainId() + ":FILE"); + entityType.setDomainId(domain.getDomainId()); + entityType.setName("FILE"); + entityType.setDescription("File entity type"); + sharingClient.createEntityType(entityType); + + entityType = new EntityType(); + entityType.setEntityTypeId(domain.getDomainId() + ":" + ResourceType.APPLICATION_DEPLOYMENT.name()); + entityType.setDomainId(domain.getDomainId()); + entityType.setName("APPLICATION-DEPLOYMENT"); + entityType.setDescription("Application Deployment entity type"); + sharingClient.createEntityType(entityType); + + entityType = new EntityType(); + entityType.setEntityTypeId(domain.getDomainId() + ":" + ResourceType.GROUP_RESOURCE_PROFILE.name()); + entityType.setDomainId(domain.getDomainId()); + entityType.setName(ResourceType.GROUP_RESOURCE_PROFILE.name()); + entityType.setDescription("Group Resource Profile entity type"); + sharingClient.createEntityType(entityType); + + // Creating Permission Types for each domain + PermissionType permissionType = new PermissionType(); + permissionType.setPermissionTypeId(domain.getDomainId() + ":READ"); + permissionType.setDomainId(domain.getDomainId()); + permissionType.setName("READ"); + permissionType.setDescription("Read permission type"); + sharingClient.createPermissionType(permissionType); + + permissionType = new PermissionType(); + permissionType.setPermissionTypeId(domain.getDomainId() + ":WRITE"); + permissionType.setDomainId(domain.getDomainId()); + permissionType.setName("WRITE"); + permissionType.setDescription("Write permission type"); + sharingClient.createPermissionType(permissionType); + + permissionType = new PermissionType(); + permissionType.setPermissionTypeId(domain.getDomainId() + ":MANAGE_SHARING"); + permissionType.setDomainId(domain.getDomainId()); + permissionType.setName("MANAGE_SHARING"); + permissionType.setDescription("Sharing permission type"); + sharingClient.createPermissionType(permissionType); + + logger.debug("Airavata successfully created the gateway with " + gatewayId); + return gatewayId; + } + + // Event publishing methods + public void publishExperimentSubmitEvent(Publisher experimentPublisher, String gatewayId, String experimentId) throws Exception { + ExperimentSubmitEvent event = new ExperimentSubmitEvent(experimentId, gatewayId); + MessageContext messageContext = new MessageContext( + event, MessageType.EXPERIMENT, "LAUNCH.EXP-" + UUID.randomUUID().toString(), gatewayId); + messageContext.setUpdatedTime(AiravataUtils.getCurrentTimestamp()); + experimentPublisher.publish(messageContext); + } + + public void publishExperimentCancelEvent(Publisher experimentPublisher, String gatewayId, String experimentId) throws Exception { + ExperimentSubmitEvent event = new ExperimentSubmitEvent(experimentId, gatewayId); + MessageContext messageContext = new MessageContext( + event, + MessageType.EXPERIMENT_CANCEL, + "CANCEL.EXP-" + UUID.randomUUID().toString(), + gatewayId); + messageContext.setUpdatedTime(AiravataUtils.getCurrentTimestamp()); + experimentPublisher.publish(messageContext); + } + + public void publishExperimentIntermediateOutputsEvent( + Publisher experimentPublisher, String gatewayId, String experimentId, List outputNames) throws Exception { + ExperimentIntermediateOutputsEvent event = + new ExperimentIntermediateOutputsEvent(experimentId, gatewayId, outputNames); + MessageContext messageContext = new MessageContext( + event, + MessageType.INTERMEDIATE_OUTPUTS, + "INTERMEDIATE_OUTPUTS.EXP-" + UUID.randomUUID().toString(), + gatewayId); + messageContext.setUpdatedTime(AiravataUtils.getCurrentTimestamp()); + experimentPublisher.publish(messageContext); + } + + /** + * Validate and fetch intermediate outputs - checks access, job state, and existing processes + */ + public void validateAndFetchIntermediateOutputs( + SharingRegistryService.Client sharingClient, + AuthzToken authzToken, + String airavataExperimentId, + List outputNames, + Publisher experimentPublisher) throws Exception { + // Verify that user has WRITE access to experiment + final boolean hasAccess = userHasAccessInternal( + sharingClient, authzToken, airavataExperimentId, ResourcePermissionType.WRITE); + if (!hasAccess) { + throw new Exception("User does not have WRITE access to this experiment"); + } + + // Verify that the experiment's job is currently ACTIVE + ExperimentModel existingExperiment = getExperiment(airavataExperimentId); + List jobs = getJobDetails(airavataExperimentId); + boolean anyJobIsActive = jobs.stream().anyMatch(j -> { + if (j.getJobStatusesSize() > 0) { + return j.getJobStatuses().get(j.getJobStatusesSize() - 1).getJobState() == JobState.ACTIVE; + } else { + return false; + } + }); + if (!anyJobIsActive) { + throw new Exception("Experiment does not have currently ACTIVE job"); + } + + // Figure out if there are any currently running intermediate output fetching processes for outputNames + // First, find any existing intermediate output fetch processes for outputNames + List intermediateOutputFetchProcesses = existingExperiment.getProcesses().stream() + .filter(p -> { + // Filter out completed or failed processes + if (p.getProcessStatusesSize() > 0) { + ProcessStatus latestStatus = p.getProcessStatuses().get(p.getProcessStatusesSize() - 1); + if (latestStatus.getState() == ProcessState.COMPLETED + || latestStatus.getState() == ProcessState.FAILED) { + return false; + } + } + return true; + }) + .filter(p -> p.getTasks().stream().allMatch(t -> t.getTaskType() == TaskTypes.OUTPUT_FETCHING)) + .filter(p -> p.getProcessOutputs().stream().anyMatch(o -> outputNames.contains(o.getName()))) + .collect(Collectors.toList()); + if (!intermediateOutputFetchProcesses.isEmpty()) { + throw new Exception("There are already intermediate output fetching tasks running for those outputs."); + } + + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + publishExperimentIntermediateOutputsEvent(experimentPublisher, gatewayId, airavataExperimentId, outputNames); + } + + /** + * Get intermediate output process status - finds the most recent matching process and returns its status + */ + public ProcessStatus getIntermediateOutputProcessStatusInternal( + SharingRegistryService.Client sharingClient, + AuthzToken authzToken, + String airavataExperimentId, + List outputNames) throws Exception { + // Verify that user has READ access to experiment + final boolean hasAccess = userHasAccessInternal( + sharingClient, authzToken, airavataExperimentId, ResourcePermissionType.READ); + if (!hasAccess) { + throw new Exception("User does not have READ access to this experiment"); + } + + ExperimentModel existingExperiment = getExperiment(airavataExperimentId); + + // Find the most recent intermediate output fetching process for the outputNames + // Assumption: only one of these output fetching processes runs at a + // time so we only need to check the status of the most recent one + Optional mostRecentOutputFetchProcess = existingExperiment.getProcesses().stream() + .filter(p -> p.getTasks().stream().allMatch(t -> t.getTaskType() == TaskTypes.OUTPUT_FETCHING)) + .filter(p -> { + List names = p.getProcessOutputs().stream() + .map(o -> o.getName()) + .collect(Collectors.toList()); + return new HashSet<>(names).equals(new HashSet<>(outputNames)); + }) + .sorted(Comparator.comparing(ProcessModel::getLastUpdateTime) + .reversed()) + .findFirst(); + + if (!mostRecentOutputFetchProcess.isPresent()) { + throw new Exception("No matching intermediate output fetching process found."); + } + + ProcessStatus result; + // Determine the most recent status for the most recent process + ProcessModel process = mostRecentOutputFetchProcess.get(); + if (process.getProcessStatusesSize() > 0) { + result = process.getProcessStatuses().get(process.getProcessStatusesSize() - 1); + } else { + // Process has no statuses so it must be created but not yet running + result = new ProcessStatus(ProcessState.CREATED); + } + + return result; + } + + // Access control methods + public List getAllAccessibleUsers( + SharingRegistryService.Client sharingClient, + String gatewayId, + String resourceId, + ResourcePermissionType permissionType, + BiFunction> userListFunction) throws Exception { + HashSet accessibleUsers = new HashSet<>(); + if (permissionType.equals(ResourcePermissionType.WRITE)) { + userListFunction.apply(sharingClient, ResourcePermissionType.WRITE).stream() + .forEach(u -> accessibleUsers.add(u.getUserId())); + userListFunction.apply(sharingClient, ResourcePermissionType.OWNER).stream() + .forEach(u -> accessibleUsers.add(u.getUserId())); + } else if (permissionType.equals(ResourcePermissionType.READ)) { + userListFunction.apply(sharingClient, ResourcePermissionType.READ).stream() + .forEach(u -> accessibleUsers.add(u.getUserId())); + userListFunction.apply(sharingClient, ResourcePermissionType.OWNER).stream() + .forEach(u -> accessibleUsers.add(u.getUserId())); + } else if (permissionType.equals(ResourcePermissionType.OWNER)) { + userListFunction.apply(sharingClient, ResourcePermissionType.OWNER).stream() + .forEach(u -> accessibleUsers.add(u.getUserId())); + } else if (permissionType.equals(ResourcePermissionType.MANAGE_SHARING)) { + userListFunction.apply(sharingClient, ResourcePermissionType.MANAGE_SHARING).stream() + .forEach(u -> accessibleUsers.add(u.getUserId())); + userListFunction.apply(sharingClient, ResourcePermissionType.OWNER).stream() + .forEach(u -> accessibleUsers.add(u.getUserId())); + } + return new ArrayList<>(accessibleUsers); + } + + public List getAllAccessibleGroups( + SharingRegistryService.Client sharingClient, + String gatewayId, + String resourceId, + ResourcePermissionType permissionType, + BiFunction> groupListFunction) throws Exception { + HashSet accessibleGroups = new HashSet<>(); + if (permissionType.equals(ResourcePermissionType.WRITE)) { + groupListFunction.apply(sharingClient, ResourcePermissionType.WRITE).stream() + .forEach(g -> accessibleGroups.add(g.getGroupId())); + } else if (permissionType.equals(ResourcePermissionType.READ)) { + groupListFunction.apply(sharingClient, ResourcePermissionType.READ).stream() + .forEach(g -> accessibleGroups.add(g.getGroupId())); + } else if (permissionType.equals(ResourcePermissionType.MANAGE_SHARING)) { + groupListFunction.apply(sharingClient, ResourcePermissionType.MANAGE_SHARING).stream() + .forEach(g -> accessibleGroups.add(g.getGroupId())); + } + return new ArrayList<>(accessibleGroups); + } + + /** + * Get all accessible users for a resource (includes shared and directly shared) + */ + public List getAllAccessibleUsersWithSharing( + SharingRegistryService.Client sharingClient, + AuthzToken authzToken, + String resourceId, + ResourcePermissionType permissionType, + boolean directlySharedOnly) throws Exception { + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + BiFunction> userListFunction; + if (directlySharedOnly) { + userListFunction = (c, t) -> { + try { + return c.getListOfDirectlySharedUsers(gatewayId, resourceId, gatewayId + ":" + t.name()); + } catch (TException e) { + throw new RuntimeException(e); + } + }; + } else { + userListFunction = (c, t) -> { + try { + return c.getListOfSharedUsers(gatewayId, resourceId, gatewayId + ":" + t.name()); + } catch (TException e) { + throw new RuntimeException(e); + } + }; + } + return getAllAccessibleUsers(sharingClient, gatewayId, resourceId, permissionType, userListFunction); + } + + /** + * Get all accessible groups for a resource (includes shared and directly shared) + */ + public List getAllAccessibleGroupsWithSharing( + SharingRegistryService.Client sharingClient, + AuthzToken authzToken, + String resourceId, + ResourcePermissionType permissionType, + boolean directlySharedOnly) throws Exception { + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + BiFunction> groupListFunction; + if (directlySharedOnly) { + groupListFunction = (c, t) -> { + try { + return c.getListOfDirectlySharedGroups(gatewayId, resourceId, gatewayId + ":" + t.name()); + } catch (TException e) { + throw new RuntimeException(e); + } + }; + } else { + groupListFunction = (c, t) -> { + try { + return c.getListOfSharedGroups(gatewayId, resourceId, gatewayId + ":" + t.name()); + } catch (TException e) { + throw new RuntimeException(e); + } + }; + } + return getAllAccessibleGroups(sharingClient, gatewayId, resourceId, permissionType, groupListFunction); + } + + // Group resource profile management with sharing registry integration + public String createGroupResourceProfileWithSharing( + SharingRegistryService.Client sharingClient, + AuthzToken authzToken, + GroupResourceProfile groupResourceProfile) throws Exception { + String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); + validateGroupResourceProfile(sharingClient, authzToken, groupResourceProfile); + String groupResourceProfileId = createGroupResourceProfile(groupResourceProfile); + if (ServerSettings.isEnableSharing()) { + try { + Entity entity = new Entity(); + entity.setEntityId(groupResourceProfileId); + entity.setDomainId(groupResourceProfile.getGatewayId()); + entity.setEntityTypeId(groupResourceProfile.getGatewayId() + ":" + "GROUP_RESOURCE_PROFILE"); + entity.setOwnerId(userName + "@" + groupResourceProfile.getGatewayId()); + entity.setName(groupResourceProfile.getGroupResourceProfileName()); + + sharingClient.createEntity(entity); + shareEntityWithAdminGatewayGroups(sharingClient, entity); + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + logger.error("Rolling back group resource profile creation Group Resource Profile ID : " + + groupResourceProfileId); + try { + removeGroupResourceProfile(groupResourceProfileId); + } catch (AppCatalogException rollbackEx) { + logger.error("Failed to rollback group resource profile deletion", rollbackEx); + } + throw new Exception("Failed to create sharing registry record", ex); + } + } + return groupResourceProfileId; + } + + public void validateGroupResourceProfile( + SharingRegistryService.Client sharingClient, + AuthzToken authzToken, + GroupResourceProfile groupResourceProfile) throws Exception { + Set tokenIds = new HashSet<>(); + if (groupResourceProfile.getComputePreferences() != null) { + for (GroupComputeResourcePreference groupComputeResourcePreference : + groupResourceProfile.getComputePreferences()) { + if (groupComputeResourcePreference.getResourceSpecificCredentialStoreToken() != null) { + tokenIds.add(groupComputeResourcePreference.getResourceSpecificCredentialStoreToken()); + } + } + } + if (groupResourceProfile.getDefaultCredentialStoreToken() != null) { + tokenIds.add(groupResourceProfile.getDefaultCredentialStoreToken()); + } + for (String tokenId : tokenIds) { + if (!userHasAccessInternal(sharingClient, authzToken, tokenId, ResourcePermissionType.READ)) { + throw new Exception("User does not have READ permission to credential token " + tokenId + "."); + } + } + } + + // Launch experiment business logic + public void launchExperimentWithValidation( + SharingRegistryService.Client sharingClient, + AuthzToken authzToken, + String gatewayId, + String airavataExperimentId, + Publisher experimentPublisher) throws Exception { + ExperimentModel experiment = getExperiment(airavataExperimentId); + + if (experiment == null) { + throw new Exception("Requested experiment id " + airavataExperimentId + " does not exist in the system.."); + } + String username = authzToken.getClaimsMap().get(Constants.USER_NAME); + + // For backwards compatibility, if there is no groupResourceProfileId, look up one that is shared with the user + if (!experiment.getUserConfigurationData().isSetGroupResourceProfileId()) { + List groupResourceProfiles = getGroupResourceListWithSharing( + sharingClient, authzToken, gatewayId); + if (groupResourceProfiles != null && !groupResourceProfiles.isEmpty()) { + // Just pick the first one + final String groupResourceProfileId = + groupResourceProfiles.get(0).getGroupResourceProfileId(); + logger.warn( + "Experiment {} doesn't have groupResourceProfileId, picking first one user has access to: {}", + airavataExperimentId, + groupResourceProfileId); + experiment.getUserConfigurationData().setGroupResourceProfileId(groupResourceProfileId); + updateExperimentConfiguration(airavataExperimentId, experiment.getUserConfigurationData()); + } else { + throw new Exception("User " + username + " in gateway " + gatewayId + + " doesn't have access to any group resource profiles."); + } + } + + // Validate access to group resource profile and application deployments + validateLaunchExperimentAccess(sharingClient, authzToken, gatewayId, experiment); + publishExperimentSubmitEvent(experimentPublisher, gatewayId, airavataExperimentId); + } + + /** + * Get group resource list with sharing registry integration + */ + public List getGroupResourceListWithSharing( + SharingRegistryService.Client sharingClient, + AuthzToken authzToken, + String gatewayId) throws Exception { + String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); + List accessibleGroupResProfileIds = new ArrayList<>(); + if (ServerSettings.isEnableSharing()) { + List filters = new ArrayList<>(); + SearchCriteria searchCriteria = new SearchCriteria(); + searchCriteria.setSearchField(EntitySearchField.ENTITY_TYPE_ID); + searchCriteria.setSearchCondition(SearchCondition.EQUAL); + searchCriteria.setValue(gatewayId + ":" + ResourceType.GROUP_RESOURCE_PROFILE.name()); + filters.add(searchCriteria); + sharingClient + .searchEntities( + authzToken.getClaimsMap().get(Constants.GATEWAY_ID), + userName + "@" + gatewayId, + filters, + 0, + -1) + .stream() + .forEach(p -> accessibleGroupResProfileIds.add(p.getEntityId())); + } + return getGroupResourceList(gatewayId, accessibleGroupResProfileIds); + } +} + From 12472d4bacccd42fe7857c351ad29993dc3e6c39 Mon Sep 17 00:00:00 2001 From: yasithdev Date: Mon, 10 Nov 2025 18:40:24 -0500 Subject: [PATCH 03/26] update CredentialStoreServerHandler --- .../server/CredentialStoreServerHandler.java | 402 ++----------- .../service/CredentialStoreService.java | 538 ++++++++++++++++++ 2 files changed, 572 insertions(+), 368 deletions(-) create mode 100644 airavata-api/src/main/java/org/apache/airavata/service/CredentialStoreService.java diff --git a/airavata-api/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java index 113d2f770e..bef4b1813a 100644 --- a/airavata-api/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java @@ -19,59 +19,28 @@ */ package org.apache.airavata.credential.store.server; -import java.io.ByteArrayInputStream; import java.io.IOException; -import java.security.cert.CertificateFactory; -import java.security.cert.X509Certificate; import java.sql.SQLException; -import java.util.*; -import java.util.stream.Collectors; +import java.util.List; +import java.util.Map; import org.apache.airavata.common.exception.ApplicationSettingsException; -import org.apache.airavata.common.utils.DBInitializer; -import org.apache.airavata.common.utils.DBUtil; -import org.apache.airavata.common.utils.ServerSettings; import org.apache.airavata.credential.store.cpi.CredentialStoreService; import org.apache.airavata.credential.store.cpi.credential_store_cpiConstants; -import org.apache.airavata.credential.store.credential.CommunityUser; -import org.apache.airavata.credential.store.credential.Credential; -import org.apache.airavata.credential.store.credential.CredentialOwnerType; import org.apache.airavata.credential.store.store.CredentialStoreException; -import org.apache.airavata.credential.store.store.impl.CertificateCredentialWriter; -import org.apache.airavata.credential.store.store.impl.CredentialReaderImpl; -import org.apache.airavata.credential.store.store.impl.SSHCredentialWriter; -import org.apache.airavata.credential.store.store.impl.util.CredentialStoreDBInitConfig; -import org.apache.airavata.credential.store.util.TokenGenerator; -import org.apache.airavata.credential.store.util.Utility; import org.apache.airavata.model.credential.store.*; -import org.apache.commons.codec.binary.Base64; import org.apache.thrift.TException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; // import sun.security.provider.X509Factory; -public class CredentialStoreServerHandler implements CredentialStoreService.Iface { +public class CredentialStoreServerHandler implements org.apache.airavata.credential.store.cpi.CredentialStoreService.Iface { protected static Logger log = LoggerFactory.getLogger(CredentialStoreServerHandler.class); - private DBUtil dbUtil; - private SSHCredentialWriter sshCredentialWriter; - private CertificateCredentialWriter certificateCredentialWriter; - private CredentialReaderImpl credentialReader; + private org.apache.airavata.service.CredentialStoreService credentialStoreService; public CredentialStoreServerHandler() throws ApplicationSettingsException, IllegalAccessException, ClassNotFoundException, InstantiationException, SQLException, IOException { - String jdbcUrl = ServerSettings.getCredentialStoreDBURL(); - String userName = ServerSettings.getCredentialStoreDBUser(); - String password = ServerSettings.getCredentialStoreDBPassword(); - String driverName = ServerSettings.getCredentialStoreDBDriver(); - - log.debug("Starting credential store, connecting to database - " + jdbcUrl + " DB user - " + userName - + " driver name - " + driverName); - DBInitializer.initializeDB(new CredentialStoreDBInitConfig()); - - dbUtil = new DBUtil(jdbcUrl, userName, password, driverName); - sshCredentialWriter = new SSHCredentialWriter(dbUtil); - certificateCredentialWriter = new CertificateCredentialWriter(dbUtil); - credentialReader = new CredentialReaderImpl(dbUtil); + credentialStoreService = new org.apache.airavata.service.CredentialStoreService(); } @Override @@ -83,37 +52,15 @@ public String getAPIVersion() throws TException { public String addSSHCredential(SSHCredential sshCredential) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { try { - org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential credential = - new org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential(); - credential.setGateway(sshCredential.getGatewayId()); - credential.setPortalUserName(sshCredential.getUsername()); - // only username and gateway id will be sent by client. - String token = TokenGenerator.generateToken(sshCredential.getGatewayId(), null); - credential.setToken(token); - credential.setPassphrase(String.valueOf(UUID.randomUUID())); - if (sshCredential.getPrivateKey() != null) { - credential.setPrivateKey(sshCredential.getPrivateKey().getBytes()); - } - if (sshCredential.getDescription() != null) { - credential.setDescription(sshCredential.getDescription()); - } - if (sshCredential.getPublicKey() != null) { - credential.setPublicKey(sshCredential.getPublicKey().getBytes()); - } - if (sshCredential.getPublicKey() == null || sshCredential.getPrivateKey() == null) { - credential = Utility.generateKeyPair(credential); - } - credential.setCredentialOwnerType(CredentialOwnerType.GATEWAY); - sshCredentialWriter.writeCredentials(credential); - return token; + return credentialStoreService.addSSHCredential(sshCredential); } catch (CredentialStoreException e) { log.error("Error occurred while saving SSH Credentials.", e); throw new org.apache.airavata.credential.store.exception.CredentialStoreException( "Error occurred while saving SSH Credentials."); } catch (Exception e) { - log.error("Error occurred while generating key pair.", e); + log.error("Error occurred while saving SSH Credentials.", e); throw new org.apache.airavata.credential.store.exception.CredentialStoreException( - "Error occurred while generating key pair.."); + "Error occurred while saving SSH Credentials."); } } @@ -121,37 +68,15 @@ public String addSSHCredential(SSHCredential sshCredential) public String addCertificateCredential(CertificateCredential certificateCredential) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { try { - org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential credential = - new org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential(); - credential.setPortalUserName( - certificateCredential.getCommunityUser().getUsername()); - credential.setCommunityUser(new CommunityUser( - certificateCredential.getCommunityUser().getGatewayName(), - certificateCredential.getCommunityUser().getUsername(), - certificateCredential.getCommunityUser().getUserEmail())); - String token = TokenGenerator.generateToken( - certificateCredential.getCommunityUser().getGatewayName(), null); - credential.setToken(token); - Base64 encoder = new Base64(64); - byte[] decoded = encoder.decode(certificateCredential - .getX509Cert() - .replaceAll("-----BEGIN CERTIFICATE-----", "") - .replaceAll("-----END CERTIFICATE-----", "")); - CertificateFactory cf = CertificateFactory.getInstance("X.509"); - X509Certificate certificate = (X509Certificate) cf.generateCertificate(new ByteArrayInputStream(decoded)); - X509Certificate[] certificates = new X509Certificate[1]; - certificates[0] = certificate; - credential.setCertificates(certificates); - certificateCredentialWriter.writeCredentials(credential); - return token; + return credentialStoreService.addCertificateCredential(certificateCredential); } catch (CredentialStoreException e) { log.error("Error occurred while saving Certificate Credentials.", e); throw new org.apache.airavata.credential.store.exception.CredentialStoreException( "Error occurred while saving Certificate Credentials."); } catch (Exception e) { - log.error("Error occurred while converting to X509 certificate.", e); + log.error("Error occurred while saving Certificate Credentials.", e); throw new org.apache.airavata.credential.store.exception.CredentialStoreException( - "Error occurred while converting to X509 certificate.."); + "Error occurred while saving Certificate Credentials."); } } @@ -159,25 +84,15 @@ public String addCertificateCredential(CertificateCredential certificateCredenti public String addPasswordCredential(PasswordCredential passwordCredential) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { try { - org.apache.airavata.credential.store.credential.impl.password.PasswordCredential credential = - new org.apache.airavata.credential.store.credential.impl.password.PasswordCredential(); - credential.setGateway(passwordCredential.getGatewayId()); - credential.setPortalUserName(passwordCredential.getPortalUserName()); - credential.setUserName(passwordCredential.getLoginUserName()); - credential.setPassword(passwordCredential.getPassword()); - credential.setDescription(passwordCredential.getDescription()); - String token = TokenGenerator.generateToken(passwordCredential.getGatewayId(), null); - credential.setToken(token); - sshCredentialWriter.writeCredentials(credential); - return token; + return credentialStoreService.addPasswordCredential(passwordCredential); } catch (CredentialStoreException e) { log.error("Error occurred while saving PWD Credentials.", e); throw new org.apache.airavata.credential.store.exception.CredentialStoreException( "Error occurred while saving PWD Credentials."); } catch (Exception e) { - log.error("Error occurred while registering PWD Credentials.", e); + log.error("Error occurred while saving PWD Credentials.", e); throw new org.apache.airavata.credential.store.exception.CredentialStoreException( - "Error occurred while registering PWD Credentials.."); + "Error occurred while saving PWD Credentials."); } } @@ -185,29 +100,7 @@ public String addPasswordCredential(PasswordCredential passwordCredential) public SSHCredential getSSHCredential(String tokenId, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { try { - Credential credential = credentialReader.getCredential(gatewayId, tokenId); - if (credential instanceof org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential - && !(credential - instanceof - org.apache.airavata.credential.store.credential.impl.password.PasswordCredential)) { - org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential credential1 = - (org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) credential; - SSHCredential sshCredential = new SSHCredential(); - sshCredential.setUsername(credential1.getPortalUserName()); - sshCredential.setGatewayId(credential1.getGateway()); - sshCredential.setPublicKey(new String(credential1.getPublicKey())); - sshCredential.setPrivateKey(new String(credential1.getPrivateKey())); - sshCredential.setPassphrase(credential1.getPassphrase()); - sshCredential.setToken(credential1.getToken()); - sshCredential.setPersistedTime( - credential1.getCertificateRequestedTime().getTime()); - sshCredential.setDescription(credential1.getDescription()); - return sshCredential; - } else { - log.info("Could not find SSH credentials for token - " + tokenId + " and " + "gateway id - " - + gatewayId); - return null; - } + return credentialStoreService.getSSHCredential(tokenId, gatewayId); } catch (CredentialStoreException e) { log.error( "Error occurred while retrieving SSH credentialfor token - " + tokenId + " and gateway id - " @@ -223,20 +116,7 @@ public SSHCredential getSSHCredential(String tokenId, String gatewayId) public CredentialSummary getCredentialSummary(String tokenId, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { try { - Credential credential = credentialReader.getCredential(gatewayId, tokenId); - if (isSSHCredential(credential)) { - return convertToCredentialSummary( - (org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) credential); - } else if (isCertificateCredential(credential)) { - return convertToCredentialSummary( - (org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) - credential); - } else if (isPasswordCredential(credential)) { - return convertToCredentialSummary( - (org.apache.airavata.credential.store.credential.impl.password.PasswordCredential) credential); - } - throw new org.apache.airavata.credential.store.exception.CredentialStoreException( - "Unrecognized type of credential for token: " + tokenId); + return credentialStoreService.getCredentialSummary(tokenId, gatewayId); } catch (CredentialStoreException e) { final String msg = "Error occurred while retrieving credential summary for token - " + tokenId + " and gateway id - " + gatewayId; @@ -250,32 +130,7 @@ public List getAllCredentialSummaries( SummaryType type, List accessibleTokenIds, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { try { - List credentials = - credentialReader.getAllAccessibleCredentialsPerGateway(gatewayId, accessibleTokenIds); - if (type.equals(SummaryType.SSH)) { - return credentials.stream() - .filter(this::isSSHCredential) - .map(cred -> (org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) cred) - .map(cred -> convertToCredentialSummary(cred)) - .collect(Collectors.toList()); - } else if (type.equals(SummaryType.CERT)) { - return credentials.stream() - .filter(this::isCertificateCredential) - .map(cred -> - (org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) - cred) - .map(cred -> convertToCredentialSummary(cred)) - .collect(Collectors.toList()); - } else if (type.equals(SummaryType.PASSWD)) { - return credentials.stream() - .filter(this::isPasswordCredential) - .map(cred -> - (org.apache.airavata.credential.store.credential.impl.password.PasswordCredential) cred) - .map(cred -> convertToCredentialSummary(cred)) - .collect(Collectors.toList()); - } else { - throw new RuntimeException("Summary Type " + type + " is not supported."); - } + return credentialStoreService.getAllCredentialSummaries(type, accessibleTokenIds, gatewayId); } catch (CredentialStoreException e) { final String msg = "Error occurred while retrieving " + type + " credential Summary for tokens - " + accessibleTokenIds + " and gateway id - " + gatewayId; @@ -284,93 +139,12 @@ public List getAllCredentialSummaries( } } - private boolean isSSHCredential(Credential cred) { - return cred instanceof org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential - && !(cred instanceof org.apache.airavata.credential.store.credential.impl.password.PasswordCredential); - } - - private boolean isCertificateCredential(Credential cred) { - return cred instanceof org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential; - } - - private boolean isPasswordCredential(Credential cred) { - return cred instanceof org.apache.airavata.credential.store.credential.impl.password.PasswordCredential; - } - - private CredentialSummary convertToCredentialSummary( - org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential cred) { - CredentialSummary credentialSummary = new CredentialSummary(); - credentialSummary.setType(SummaryType.SSH); - credentialSummary.setUsername(cred.getPortalUserName()); - credentialSummary.setGatewayId(cred.getGateway()); - credentialSummary.setPublicKey(new String(cred.getPublicKey())); - credentialSummary.setToken(cred.getToken()); - credentialSummary.setPersistedTime(cred.getCertificateRequestedTime().getTime()); - credentialSummary.setDescription(cred.getDescription()); - return credentialSummary; - } - - private CredentialSummary convertToCredentialSummary( - org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential cred) { - CredentialSummary credentialSummary = new CredentialSummary(); - credentialSummary.setType(SummaryType.CERT); - credentialSummary.setUsername(cred.getPortalUserName()); - // FIXME: need to get gatewayId for CertificateCredentials - credentialSummary.setGatewayId(""); - // FIXME: get the public key? Or what would be appropriate for a summary of a CertificateCredential? - // credentialSummary.setPublicKey(new String(cred.getPublicKey())); - credentialSummary.setToken(cred.getToken()); - credentialSummary.setPersistedTime(cred.getCertificateRequestedTime().getTime()); - credentialSummary.setDescription(cred.getDescription()); - return credentialSummary; - } - - private CredentialSummary convertToCredentialSummary( - org.apache.airavata.credential.store.credential.impl.password.PasswordCredential cred) { - CredentialSummary credentialSummary = new CredentialSummary(); - credentialSummary.setType(SummaryType.PASSWD); - credentialSummary.setUsername(cred.getPortalUserName()); - credentialSummary.setGatewayId(cred.getGateway()); - credentialSummary.setToken(cred.getToken()); - credentialSummary.setPersistedTime(cred.getCertificateRequestedTime().getTime()); - credentialSummary.setDescription(cred.getDescription()); - return credentialSummary; - } @Override public CertificateCredential getCertificateCredential(String tokenId, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { try { - Credential credential = credentialReader.getCredential(gatewayId, tokenId); - if (credential - instanceof org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) { - org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential credential1 = - (org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) - credential; - CertificateCredential certificateCredential = new CertificateCredential(); - org.apache.airavata.model.credential.store.CommunityUser communityUser = - new org.apache.airavata.model.credential.store.CommunityUser(); - communityUser.setGatewayName(credential1.getCommunityUser().getGatewayName()); - communityUser.setUsername(credential1.getCommunityUser().getUserName()); - communityUser.setUserEmail(credential1.getCommunityUser().getUserEmail()); - certificateCredential.setCommunityUser(communityUser); - certificateCredential.setToken(credential1.getToken()); - certificateCredential.setLifeTime(credential1.getLifeTime()); - certificateCredential.setNotAfter(credential1.getNotAfter()); - certificateCredential.setNotBefore(credential1.getNotBefore()); - certificateCredential.setPersistedTime( - credential1.getCertificateRequestedTime().getTime()); - if (credential1.getPrivateKey() != null) { - certificateCredential.setPrivateKey( - credential1.getPrivateKey().toString()); - } - certificateCredential.setX509Cert(credential1.getCertificates()[0].toString()); - return certificateCredential; - } else { - log.info("Could not find Certificate credentials for token - " + tokenId + " and " + "gateway id - " - + gatewayId); - return null; - } + return credentialStoreService.getCertificateCredential(tokenId, gatewayId); } catch (CredentialStoreException e) { log.error( "Error occurred while retrieving Certificate credential for token - " + tokenId @@ -386,26 +160,7 @@ public CertificateCredential getCertificateCredential(String tokenId, String gat public PasswordCredential getPasswordCredential(String tokenId, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { try { - Credential credential = credentialReader.getCredential(gatewayId, tokenId); - if (credential - instanceof org.apache.airavata.credential.store.credential.impl.password.PasswordCredential) { - org.apache.airavata.credential.store.credential.impl.password.PasswordCredential credential1 = - (org.apache.airavata.credential.store.credential.impl.password.PasswordCredential) credential; - PasswordCredential pwdCredential = new PasswordCredential(); - pwdCredential.setGatewayId(credential1.getGateway()); - pwdCredential.setPortalUserName(credential1.getPortalUserName()); - pwdCredential.setLoginUserName(credential1.getUserName()); - pwdCredential.setPassword(credential1.getPassword()); - pwdCredential.setDescription(credential1.getDescription()); - pwdCredential.setToken(credential1.getToken()); - pwdCredential.setPersistedTime( - credential1.getCertificateRequestedTime().getTime()); - return pwdCredential; - } else { - log.info("Could not find PWD credentials for token - " + tokenId + " and " + "gateway id - " - + gatewayId); - return null; - } + return credentialStoreService.getPasswordCredential(tokenId, gatewayId); } catch (CredentialStoreException e) { log.error( "Error occurred while retrieving PWD credentialfor token - " + tokenId + " and gateway id - " @@ -421,41 +176,12 @@ public PasswordCredential getPasswordCredential(String tokenId, String gatewayId @Deprecated public List getAllCredentialSummaryForGateway(SummaryType type, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { - if (type.equals(SummaryType.SSH)) { - Map sshKeyMap = new HashMap<>(); - List summaryList = new ArrayList<>(); - try { - List allCredentials = credentialReader.getAllCredentialsPerGateway(gatewayId); - if (allCredentials != null && !allCredentials.isEmpty()) { - for (Credential credential : allCredentials) { - if (credential instanceof org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential - && !(credential - instanceof - org.apache.airavata.credential.store.credential.impl.password - .PasswordCredential) - && credential.getCredentialOwnerType() == CredentialOwnerType.GATEWAY) { - org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential sshCredential = - (org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) credential; - CredentialSummary sshCredentialSummary = new CredentialSummary(); - sshCredentialSummary.setType(SummaryType.SSH); - sshCredentialSummary.setToken(sshCredential.getToken()); - sshCredentialSummary.setUsername(sshCredential.getPortalUserName()); - sshCredentialSummary.setGatewayId(sshCredential.getGateway()); - sshCredentialSummary.setDescription(sshCredential.getDescription()); - sshCredentialSummary.setPublicKey(new String(sshCredential.getPublicKey())); - summaryList.add(sshCredentialSummary); - } - } - } - } catch (CredentialStoreException e) { - log.error("Error occurred while retrieving credential Summary", e); - throw new org.apache.airavata.credential.store.exception.CredentialStoreException( - "Error occurred while retrieving credential Summary"); - } - return summaryList; - } else { - log.info("Summay Type" + type.toString() + " not supported for gateway id - " + gatewayId); - return null; + try { + return credentialStoreService.getAllCredentialSummaryForGateway(type, gatewayId); + } catch (CredentialStoreException e) { + log.error("Error occurred while retrieving credential Summary", e); + throw new org.apache.airavata.credential.store.exception.CredentialStoreException( + "Error occurred while retrieving credential Summary"); } } @@ -464,54 +190,12 @@ public List getAllCredentialSummaryForGateway(SummaryType typ public List getAllCredentialSummaryForUserInGateway( SummaryType type, String gatewayId, String userId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { - if (type.equals(SummaryType.SSH)) { - Map sshKeyMap = new HashMap<>(); - List summaryList = new ArrayList<>(); - try { - List allCredentials = credentialReader.getAllCredentials(); - if (allCredentials != null && !allCredentials.isEmpty()) { - for (Credential credential : allCredentials) { - if (credential instanceof org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential - && !(credential - instanceof - org.apache.airavata.credential.store.credential.impl.password - .PasswordCredential)) { - org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential sshCredential = - (org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) credential; - String portalUserName = sshCredential.getPortalUserName(); - String gateway = sshCredential.getGateway(); - if (portalUserName != null && gateway != null) { - if (portalUserName.equals(userId) - && gateway.equals(gatewayId) - && sshCredential.getCredentialOwnerType() == CredentialOwnerType.USER) { - org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential - sshCredentialKey = - (org.apache.airavata.credential.store.credential.impl.ssh - .SSHCredential) - credential; - CredentialSummary sshCredentialSummary = new CredentialSummary(); - sshCredentialSummary.setType(SummaryType.SSH); - sshCredentialSummary.setToken(sshCredentialKey.getToken()); - sshCredentialSummary.setUsername(sshCredentialKey.getPortalUserName()); - sshCredentialSummary.setGatewayId(sshCredentialKey.getGateway()); - sshCredentialSummary.setDescription(sshCredentialKey.getDescription()); - sshCredentialSummary.setPublicKey(new String(sshCredentialKey.getPublicKey())); - summaryList.add(sshCredentialSummary); - } - } - } - } - } - } catch (CredentialStoreException e) { - log.error("Error occurred while retrieving credential Summary", e); - throw new org.apache.airavata.credential.store.exception.CredentialStoreException( - "Error occurred while retrieving credential Summary"); - } - return summaryList; - } else { - log.info("Summay Type" + type.toString() + " not supported for user Id - " + userId + " and " - + "gateway id - " + gatewayId); - return null; + try { + return credentialStoreService.getAllCredentialSummaryForUserInGateway(type, gatewayId, userId); + } catch (CredentialStoreException e) { + log.error("Error occurred while retrieving credential Summary", e); + throw new org.apache.airavata.credential.store.exception.CredentialStoreException( + "Error occurred while retrieving credential Summary"); } } @@ -519,37 +203,20 @@ public List getAllCredentialSummaryForUserInGateway( @Deprecated public Map getAllPWDCredentialsForGateway(String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { - Map pwdCredMap = new HashMap<>(); try { - List allCredentials = credentialReader.getAllCredentialsPerGateway(gatewayId); - if (allCredentials != null && !allCredentials.isEmpty()) { - for (Credential credential : allCredentials) { - if (credential - instanceof - org.apache.airavata.credential.store.credential.impl.password.PasswordCredential) { - org.apache.airavata.credential.store.credential.impl.password.PasswordCredential pwdCredential = - (org.apache.airavata.credential.store.credential.impl.password.PasswordCredential) - credential; - pwdCredMap.put( - pwdCredential.getToken(), - pwdCredential.getDescription() == null ? "" : pwdCredential.getDescription()); - } - } - } + return credentialStoreService.getAllPWDCredentialsForGateway(gatewayId); } catch (CredentialStoreException e) { log.error("Error occurred while retrieving credentials", e); throw new org.apache.airavata.credential.store.exception.CredentialStoreException( "Error occurred while retrieving credentials"); } - return pwdCredMap; } @Override public boolean deleteSSHCredential(String tokenId, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { try { - credentialReader.removeCredentials(gatewayId, tokenId); - return true; + return credentialStoreService.deleteSSHCredential(tokenId, gatewayId); } catch (CredentialStoreException e) { log.error( "Error occurred while deleting SSH credential for token - " + tokenId + " and gateway id - " @@ -565,8 +232,7 @@ public boolean deleteSSHCredential(String tokenId, String gatewayId) public boolean deletePWDCredential(String tokenId, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { try { - credentialReader.removeCredentials(gatewayId, tokenId); - return true; + return credentialStoreService.deletePWDCredential(tokenId, gatewayId); } catch (CredentialStoreException e) { log.error( "Error occurred while deleting PWD credential for token - " + tokenId + " and gateway id - " diff --git a/airavata-api/src/main/java/org/apache/airavata/service/CredentialStoreService.java b/airavata-api/src/main/java/org/apache/airavata/service/CredentialStoreService.java new file mode 100644 index 0000000000..129de089f2 --- /dev/null +++ b/airavata-api/src/main/java/org/apache/airavata/service/CredentialStoreService.java @@ -0,0 +1,538 @@ +/** +* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ +package org.apache.airavata.service; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.security.cert.CertificateFactory; +import java.security.cert.X509Certificate; +import java.sql.SQLException; +import java.util.*; +import java.util.stream.Collectors; +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.DBInitializer; +import org.apache.airavata.common.utils.DBUtil; +import org.apache.airavata.common.utils.ServerSettings; +import org.apache.airavata.credential.store.credential.CommunityUser; +import org.apache.airavata.credential.store.credential.Credential; +import org.apache.airavata.credential.store.credential.CredentialOwnerType; +import org.apache.airavata.credential.store.store.CredentialStoreException; +import org.apache.airavata.credential.store.store.impl.CertificateCredentialWriter; +import org.apache.airavata.credential.store.store.impl.CredentialReaderImpl; +import org.apache.airavata.credential.store.store.impl.SSHCredentialWriter; +import org.apache.airavata.credential.store.store.impl.util.CredentialStoreDBInitConfig; +import org.apache.airavata.credential.store.util.TokenGenerator; +import org.apache.airavata.credential.store.util.Utility; +import org.apache.airavata.model.credential.store.*; +import org.apache.commons.codec.binary.Base64; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class CredentialStoreService { + private static final Logger logger = LoggerFactory.getLogger(CredentialStoreService.class); + + private DBUtil dbUtil; + private SSHCredentialWriter sshCredentialWriter; + private CertificateCredentialWriter certificateCredentialWriter; + private CredentialReaderImpl credentialReader; + + public CredentialStoreService() + throws ApplicationSettingsException, IllegalAccessException, ClassNotFoundException, InstantiationException, + SQLException, IOException { + String jdbcUrl = ServerSettings.getCredentialStoreDBURL(); + String userName = ServerSettings.getCredentialStoreDBUser(); + String password = ServerSettings.getCredentialStoreDBPassword(); + String driverName = ServerSettings.getCredentialStoreDBDriver(); + + logger.debug("Starting credential store, connecting to database - " + jdbcUrl + " DB user - " + userName + + " driver name - " + driverName); + DBInitializer.initializeDB(new CredentialStoreDBInitConfig()); + + dbUtil = new DBUtil(jdbcUrl, userName, password, driverName); + sshCredentialWriter = new SSHCredentialWriter(dbUtil); + certificateCredentialWriter = new CertificateCredentialWriter(dbUtil); + credentialReader = new CredentialReaderImpl(dbUtil); + } + + public String addSSHCredential(SSHCredential sshCredential) throws CredentialStoreException { + try { + org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential credential = + new org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential(); + credential.setGateway(sshCredential.getGatewayId()); + credential.setPortalUserName(sshCredential.getUsername()); + // only username and gateway id will be sent by client. + String token = TokenGenerator.generateToken(sshCredential.getGatewayId(), null); + credential.setToken(token); + credential.setPassphrase(String.valueOf(UUID.randomUUID())); + if (sshCredential.getPrivateKey() != null) { + credential.setPrivateKey(sshCredential.getPrivateKey().getBytes()); + } + if (sshCredential.getDescription() != null) { + credential.setDescription(sshCredential.getDescription()); + } + if (sshCredential.getPublicKey() != null) { + credential.setPublicKey(sshCredential.getPublicKey().getBytes()); + } + if (sshCredential.getPublicKey() == null || sshCredential.getPrivateKey() == null) { + credential = Utility.generateKeyPair(credential); + } + credential.setCredentialOwnerType(CredentialOwnerType.GATEWAY); + sshCredentialWriter.writeCredentials(credential); + return token; + } catch (CredentialStoreException e) { + logger.error("Error occurred while saving SSH Credentials.", e); + throw new CredentialStoreException("Error occurred while saving SSH Credentials."); + } catch (Exception e) { + logger.error("Error occurred while generating key pair.", e); + throw new CredentialStoreException("Error occurred while generating key pair.."); + } + } + + public String addCertificateCredential(CertificateCredential certificateCredential) throws CredentialStoreException { + try { + org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential credential = + new org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential(); + credential.setPortalUserName( + certificateCredential.getCommunityUser().getUsername()); + credential.setCommunityUser(new CommunityUser( + certificateCredential.getCommunityUser().getGatewayName(), + certificateCredential.getCommunityUser().getUsername(), + certificateCredential.getCommunityUser().getUserEmail())); + String token = TokenGenerator.generateToken( + certificateCredential.getCommunityUser().getGatewayName(), null); + credential.setToken(token); + Base64 encoder = new Base64(64); + byte[] decoded = encoder.decode(certificateCredential + .getX509Cert() + .replaceAll("-----BEGIN CERTIFICATE-----", "") + .replaceAll("-----END CERTIFICATE-----", "")); + CertificateFactory cf = CertificateFactory.getInstance("X.509"); + X509Certificate certificate = (X509Certificate) cf.generateCertificate(new ByteArrayInputStream(decoded)); + X509Certificate[] certificates = new X509Certificate[1]; + certificates[0] = certificate; + credential.setCertificates(certificates); + certificateCredentialWriter.writeCredentials(credential); + return token; + } catch (CredentialStoreException e) { + logger.error("Error occurred while saving Certificate Credentials.", e); + throw new CredentialStoreException("Error occurred while saving Certificate Credentials."); + } catch (Exception e) { + logger.error("Error occurred while converting to X509 certificate.", e); + throw new CredentialStoreException("Error occurred while converting to X509 certificate.."); + } + } + + public String addPasswordCredential(PasswordCredential passwordCredential) throws CredentialStoreException { + try { + org.apache.airavata.credential.store.credential.impl.password.PasswordCredential credential = + new org.apache.airavata.credential.store.credential.impl.password.PasswordCredential(); + credential.setGateway(passwordCredential.getGatewayId()); + credential.setPortalUserName(passwordCredential.getPortalUserName()); + credential.setUserName(passwordCredential.getLoginUserName()); + credential.setPassword(passwordCredential.getPassword()); + credential.setDescription(passwordCredential.getDescription()); + String token = TokenGenerator.generateToken(passwordCredential.getGatewayId(), null); + credential.setToken(token); + sshCredentialWriter.writeCredentials(credential); + return token; + } catch (CredentialStoreException e) { + logger.error("Error occurred while saving PWD Credentials.", e); + throw new CredentialStoreException("Error occurred while saving PWD Credentials."); + } catch (Exception e) { + logger.error("Error occurred while registering PWD Credentials.", e); + throw new CredentialStoreException("Error occurred while registering PWD Credentials.."); + } + } + + public SSHCredential getSSHCredential(String tokenId, String gatewayId) throws CredentialStoreException { + try { + Credential credential = credentialReader.getCredential(gatewayId, tokenId); + if (credential instanceof org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential + && !(credential + instanceof + org.apache.airavata.credential.store.credential.impl.password.PasswordCredential)) { + org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential credential1 = + (org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) credential; + SSHCredential sshCredential = new SSHCredential(); + sshCredential.setUsername(credential1.getPortalUserName()); + sshCredential.setGatewayId(credential1.getGateway()); + sshCredential.setPublicKey(new String(credential1.getPublicKey())); + sshCredential.setPrivateKey(new String(credential1.getPrivateKey())); + sshCredential.setPassphrase(credential1.getPassphrase()); + sshCredential.setToken(credential1.getToken()); + sshCredential.setPersistedTime( + credential1.getCertificateRequestedTime().getTime()); + sshCredential.setDescription(credential1.getDescription()); + return sshCredential; + } else { + logger.info("Could not find SSH credentials for token - " + tokenId + " and " + "gateway id - " + + gatewayId); + return null; + } + } catch (CredentialStoreException e) { + logger.error( + "Error occurred while retrieving SSH credentialfor token - " + tokenId + " and gateway id - " + + gatewayId, + e); + throw new CredentialStoreException( + "Error occurred while retrieving SSH credential for token - " + tokenId + " and gateway id - " + + gatewayId); + } + } + + public CredentialSummary getCredentialSummary(String tokenId, String gatewayId) throws CredentialStoreException { + try { + Credential credential = credentialReader.getCredential(gatewayId, tokenId); + if (isSSHCredential(credential)) { + return convertToCredentialSummary( + (org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) credential); + } else if (isCertificateCredential(credential)) { + return convertToCredentialSummary( + (org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) + credential); + } else if (isPasswordCredential(credential)) { + return convertToCredentialSummary( + (org.apache.airavata.credential.store.credential.impl.password.PasswordCredential) credential); + } + throw new CredentialStoreException( + "Unrecognized type of credential for token: " + tokenId); + } catch (CredentialStoreException e) { + final String msg = "Error occurred while retrieving credential summary for token - " + tokenId + + " and gateway id - " + gatewayId; + logger.error(msg, e); + throw new CredentialStoreException(msg); + } + } + + public List getAllCredentialSummaries( + SummaryType type, List accessibleTokenIds, String gatewayId) throws CredentialStoreException { + try { + List credentials = + credentialReader.getAllAccessibleCredentialsPerGateway(gatewayId, accessibleTokenIds); + if (type.equals(SummaryType.SSH)) { + return credentials.stream() + .filter(this::isSSHCredential) + .map(cred -> (org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) cred) + .map(cred -> convertToCredentialSummary(cred)) + .collect(Collectors.toList()); + } else if (type.equals(SummaryType.CERT)) { + return credentials.stream() + .filter(this::isCertificateCredential) + .map(cred -> + (org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) + cred) + .map(cred -> convertToCredentialSummary(cred)) + .collect(Collectors.toList()); + } else if (type.equals(SummaryType.PASSWD)) { + return credentials.stream() + .filter(this::isPasswordCredential) + .map(cred -> + (org.apache.airavata.credential.store.credential.impl.password.PasswordCredential) cred) + .map(cred -> convertToCredentialSummary(cred)) + .collect(Collectors.toList()); + } else { + throw new RuntimeException("Summary Type " + type + " is not supported."); + } + } catch (CredentialStoreException e) { + final String msg = "Error occurred while retrieving " + type + " credential Summary for tokens - " + + accessibleTokenIds + " and gateway id - " + gatewayId; + logger.error(msg, e); + throw new CredentialStoreException(msg); + } + } + + private boolean isSSHCredential(Credential cred) { + return cred instanceof org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential + && !(cred instanceof org.apache.airavata.credential.store.credential.impl.password.PasswordCredential); + } + + private boolean isCertificateCredential(Credential cred) { + return cred instanceof org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential; + } + + private boolean isPasswordCredential(Credential cred) { + return cred instanceof org.apache.airavata.credential.store.credential.impl.password.PasswordCredential; + } + + private CredentialSummary convertToCredentialSummary( + org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential cred) { + CredentialSummary credentialSummary = new CredentialSummary(); + credentialSummary.setType(SummaryType.SSH); + credentialSummary.setUsername(cred.getPortalUserName()); + credentialSummary.setGatewayId(cred.getGateway()); + credentialSummary.setPublicKey(new String(cred.getPublicKey())); + credentialSummary.setToken(cred.getToken()); + credentialSummary.setPersistedTime(cred.getCertificateRequestedTime().getTime()); + credentialSummary.setDescription(cred.getDescription()); + return credentialSummary; + } + + private CredentialSummary convertToCredentialSummary( + org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential cred) { + CredentialSummary credentialSummary = new CredentialSummary(); + credentialSummary.setType(SummaryType.CERT); + credentialSummary.setUsername(cred.getPortalUserName()); + // FIXME: need to get gatewayId for CertificateCredentials + credentialSummary.setGatewayId(""); + // FIXME: get the public key? Or what would be appropriate for a summary of a CertificateCredential? + // credentialSummary.setPublicKey(new String(cred.getPublicKey())); + credentialSummary.setToken(cred.getToken()); + credentialSummary.setPersistedTime(cred.getCertificateRequestedTime().getTime()); + credentialSummary.setDescription(cred.getDescription()); + return credentialSummary; + } + + private CredentialSummary convertToCredentialSummary( + org.apache.airavata.credential.store.credential.impl.password.PasswordCredential cred) { + CredentialSummary credentialSummary = new CredentialSummary(); + credentialSummary.setType(SummaryType.PASSWD); + credentialSummary.setUsername(cred.getPortalUserName()); + credentialSummary.setGatewayId(cred.getGateway()); + credentialSummary.setToken(cred.getToken()); + credentialSummary.setPersistedTime(cred.getCertificateRequestedTime().getTime()); + credentialSummary.setDescription(cred.getDescription()); + return credentialSummary; + } + + public CertificateCredential getCertificateCredential(String tokenId, String gatewayId) throws CredentialStoreException { + try { + Credential credential = credentialReader.getCredential(gatewayId, tokenId); + if (credential + instanceof org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) { + org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential credential1 = + (org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential) + credential; + CertificateCredential certificateCredential = new CertificateCredential(); + org.apache.airavata.model.credential.store.CommunityUser communityUser = + new org.apache.airavata.model.credential.store.CommunityUser(); + communityUser.setGatewayName(credential1.getCommunityUser().getGatewayName()); + communityUser.setUsername(credential1.getCommunityUser().getUserName()); + communityUser.setUserEmail(credential1.getCommunityUser().getUserEmail()); + certificateCredential.setCommunityUser(communityUser); + certificateCredential.setToken(credential1.getToken()); + certificateCredential.setLifeTime(credential1.getLifeTime()); + certificateCredential.setNotAfter(credential1.getNotAfter()); + certificateCredential.setNotBefore(credential1.getNotBefore()); + certificateCredential.setPersistedTime( + credential1.getCertificateRequestedTime().getTime()); + if (credential1.getPrivateKey() != null) { + certificateCredential.setPrivateKey( + credential1.getPrivateKey().toString()); + } + certificateCredential.setX509Cert(credential1.getCertificates()[0].toString()); + return certificateCredential; + } else { + logger.info("Could not find Certificate credentials for token - " + tokenId + " and " + "gateway id - " + + gatewayId); + return null; + } + } catch (CredentialStoreException e) { + logger.error( + "Error occurred while retrieving Certificate credential for token - " + tokenId + + " and gateway id - " + gatewayId, + e); + throw new CredentialStoreException( + "Error occurred while retrieving Certificate credential for token - " + tokenId + + " and gateway id - " + gatewayId); + } + } + + public PasswordCredential getPasswordCredential(String tokenId, String gatewayId) throws CredentialStoreException { + try { + Credential credential = credentialReader.getCredential(gatewayId, tokenId); + if (credential + instanceof org.apache.airavata.credential.store.credential.impl.password.PasswordCredential) { + org.apache.airavata.credential.store.credential.impl.password.PasswordCredential credential1 = + (org.apache.airavata.credential.store.credential.impl.password.PasswordCredential) credential; + PasswordCredential pwdCredential = new PasswordCredential(); + pwdCredential.setGatewayId(credential1.getGateway()); + pwdCredential.setPortalUserName(credential1.getPortalUserName()); + pwdCredential.setLoginUserName(credential1.getUserName()); + pwdCredential.setPassword(credential1.getPassword()); + pwdCredential.setDescription(credential1.getDescription()); + pwdCredential.setToken(credential1.getToken()); + pwdCredential.setPersistedTime( + credential1.getCertificateRequestedTime().getTime()); + return pwdCredential; + } else { + logger.info("Could not find PWD credentials for token - " + tokenId + " and " + "gateway id - " + + gatewayId); + return null; + } + } catch (CredentialStoreException e) { + logger.error( + "Error occurred while retrieving PWD credentialfor token - " + tokenId + " and gateway id - " + + gatewayId, + e); + throw new CredentialStoreException( + "Error occurred while retrieving PWD credential for token - " + tokenId + " and gateway id - " + + gatewayId); + } + } + + @Deprecated + public List getAllCredentialSummaryForGateway(SummaryType type, String gatewayId) throws CredentialStoreException { + if (type.equals(SummaryType.SSH)) { + Map sshKeyMap = new HashMap<>(); + List summaryList = new ArrayList<>(); + try { + List allCredentials = credentialReader.getAllCredentialsPerGateway(gatewayId); + if (allCredentials != null && !allCredentials.isEmpty()) { + for (Credential credential : allCredentials) { + if (credential instanceof org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential + && !(credential + instanceof + org.apache.airavata.credential.store.credential.impl.password + .PasswordCredential) + && credential.getCredentialOwnerType() == CredentialOwnerType.GATEWAY) { + org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential sshCredential = + (org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) credential; + CredentialSummary sshCredentialSummary = new CredentialSummary(); + sshCredentialSummary.setType(SummaryType.SSH); + sshCredentialSummary.setToken(sshCredential.getToken()); + sshCredentialSummary.setUsername(sshCredential.getPortalUserName()); + sshCredentialSummary.setGatewayId(sshCredential.getGateway()); + sshCredentialSummary.setDescription(sshCredential.getDescription()); + sshCredentialSummary.setPublicKey(new String(sshCredential.getPublicKey())); + summaryList.add(sshCredentialSummary); + } + } + } + } catch (CredentialStoreException e) { + logger.error("Error occurred while retrieving credential Summary", e); + throw new CredentialStoreException("Error occurred while retrieving credential Summary"); + } + return summaryList; + } else { + logger.info("Summay Type" + type.toString() + " not supported for gateway id - " + gatewayId); + return null; + } + } + + @Deprecated + public List getAllCredentialSummaryForUserInGateway( + SummaryType type, String gatewayId, String userId) throws CredentialStoreException { + if (type.equals(SummaryType.SSH)) { + Map sshKeyMap = new HashMap<>(); + List summaryList = new ArrayList<>(); + try { + List allCredentials = credentialReader.getAllCredentials(); + if (allCredentials != null && !allCredentials.isEmpty()) { + for (Credential credential : allCredentials) { + if (credential instanceof org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential + && !(credential + instanceof + org.apache.airavata.credential.store.credential.impl.password + .PasswordCredential)) { + org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential sshCredential = + (org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential) credential; + String portalUserName = sshCredential.getPortalUserName(); + String gateway = sshCredential.getGateway(); + if (portalUserName != null && gateway != null) { + if (portalUserName.equals(userId) + && gateway.equals(gatewayId) + && sshCredential.getCredentialOwnerType() == CredentialOwnerType.USER) { + org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential + sshCredentialKey = + (org.apache.airavata.credential.store.credential.impl.ssh + .SSHCredential) + credential; + CredentialSummary sshCredentialSummary = new CredentialSummary(); + sshCredentialSummary.setType(SummaryType.SSH); + sshCredentialSummary.setToken(sshCredentialKey.getToken()); + sshCredentialSummary.setUsername(sshCredentialKey.getPortalUserName()); + sshCredentialSummary.setGatewayId(sshCredentialKey.getGateway()); + sshCredentialSummary.setDescription(sshCredentialKey.getDescription()); + sshCredentialSummary.setPublicKey(new String(sshCredentialKey.getPublicKey())); + summaryList.add(sshCredentialSummary); + } + } + } + } + } + } catch (CredentialStoreException e) { + logger.error("Error occurred while retrieving credential Summary", e); + throw new CredentialStoreException("Error occurred while retrieving credential Summary"); + } + return summaryList; + } else { + logger.info("Summay Type" + type.toString() + " not supported for user Id - " + userId + " and " + + "gateway id - " + gatewayId); + return null; + } + } + + @Deprecated + public Map getAllPWDCredentialsForGateway(String gatewayId) throws CredentialStoreException { + Map pwdCredMap = new HashMap<>(); + try { + List allCredentials = credentialReader.getAllCredentialsPerGateway(gatewayId); + if (allCredentials != null && !allCredentials.isEmpty()) { + for (Credential credential : allCredentials) { + if (credential + instanceof + org.apache.airavata.credential.store.credential.impl.password.PasswordCredential) { + org.apache.airavata.credential.store.credential.impl.password.PasswordCredential pwdCredential = + (org.apache.airavata.credential.store.credential.impl.password.PasswordCredential) + credential; + pwdCredMap.put( + pwdCredential.getToken(), + pwdCredential.getDescription() == null ? "" : pwdCredential.getDescription()); + } + } + } + } catch (CredentialStoreException e) { + logger.error("Error occurred while retrieving credentials", e); + throw new CredentialStoreException("Error occurred while retrieving credentials"); + } + return pwdCredMap; + } + + public boolean deleteSSHCredential(String tokenId, String gatewayId) throws CredentialStoreException { + try { + credentialReader.removeCredentials(gatewayId, tokenId); + return true; + } catch (CredentialStoreException e) { + logger.error( + "Error occurred while deleting SSH credential for token - " + tokenId + " and gateway id - " + + gatewayId, + e); + throw new CredentialStoreException( + "Error occurred while deleting SSH credential for token - " + tokenId + " and gateway id - " + + gatewayId); + } + } + + public boolean deletePWDCredential(String tokenId, String gatewayId) throws CredentialStoreException { + try { + credentialReader.removeCredentials(gatewayId, tokenId); + return true; + } catch (CredentialStoreException e) { + logger.error( + "Error occurred while deleting PWD credential for token - " + tokenId + " and gateway id - " + + gatewayId, + e); + throw new CredentialStoreException( + "Error occurred while deleting PWD credential for token - " + tokenId + " and gateway id - " + + gatewayId); + } + } +} + From 47b7eb70dcb9cc00a2a7c06c4eae454cd9b27886 Mon Sep 17 00:00:00 2001 From: yasithdev Date: Mon, 10 Nov 2025 18:40:37 -0500 Subject: [PATCH 04/26] update OrchestratorServerHandler --- .../server/OrchestratorServerHandler.java | 802 +----------------- .../airavata/service/OrchestratorService.java | 737 ++++++++++++++++ 2 files changed, 783 insertions(+), 756 deletions(-) create mode 100644 airavata-api/src/main/java/org/apache/airavata/service/OrchestratorService.java diff --git a/airavata-api/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java index e00a9d1c3c..6390572085 100644 --- a/airavata-api/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java @@ -60,9 +60,7 @@ import org.apache.airavata.orchestrator.cpi.impl.SimpleOrchestratorImpl; import org.apache.airavata.orchestrator.util.OrchestratorServerThreadPoolExecutor; import org.apache.airavata.orchestrator.util.OrchestratorUtils; -import org.apache.airavata.registry.api.RegistryService; -import org.apache.airavata.registry.api.RegistryService.Client; -import org.apache.airavata.registry.api.client.RegistryServiceClientFactory; +import org.apache.airavata.service.OrchestratorRegistryService; import org.apache.airavata.registry.api.exception.RegistryServiceException; import org.apache.commons.lang3.StringUtils; import org.apache.curator.RetryPolicy; @@ -87,6 +85,8 @@ public class OrchestratorServerHandler implements OrchestratorService.Iface { private final Subscriber experimentSubscriber; private CuratorFramework curatorClient; + private OrchestratorRegistryService orchestratorRegistryService = new OrchestratorRegistryService(); + private org.apache.airavata.service.OrchestratorService orchestratorService; /** * Query orchestrator server to fetch the CPI version @@ -106,10 +106,11 @@ public OrchestratorServerHandler() throws OrchestratorException, TException { publisher = MessagingFactory.getPublisher(Type.STATUS); orchestrator.initialize(); - orchestrator.getOrchestratorContext().setPublisher(this.publisher); + orchestrator.getOrchestratorContext().setPublisher(publisher); statusSubscribe = getStatusSubscriber(); experimentSubscriber = getExperimentSubscriber(); startCurator(); + orchestratorService = new org.apache.airavata.service.OrchestratorService(orchestratorRegistryService, orchestrator, curatorClient, publisher); } catch (OrchestratorException | AiravataException e) { log.error(e.getMessage(), e); throw new OrchestratorException("Error while initializing orchestrator service", e); @@ -139,178 +140,14 @@ private Subscriber getExperimentSubscriber() throws AiravataException { * @param experimentId */ public boolean launchExperiment(String experimentId, String gatewayId) throws TException { - ExperimentModel experiment = null; - final RegistryService.Client registryClient = getRegistryServiceClient(); try { - // TODO deprecate this approach as we are replacing gfac - String experimentNodePath = 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 = registryClient.getExperiment(experimentId); - if (experiment == null) { - throw new Exception("Error retrieving the Experiment by the given experimentID: " + experimentId); - } - - UserConfigurationDataModel userConfigurationData = experiment.getUserConfigurationData(); - String token = null; - final String groupResourceProfileId = userConfigurationData.getGroupResourceProfileId(); - if (groupResourceProfileId == null) { - throw new Exception("Experiment not configured with a Group Resource Profile: " + experimentId); - } - - if (userConfigurationData.getComputationalResourceScheduling() != null - && userConfigurationData - .getComputationalResourceScheduling() - .isSet(ComputationalResourceSchedulingModel._Fields.RESOURCE_HOST_ID)) { - GroupComputeResourcePreference groupComputeResourcePreference = - registryClient.getGroupComputeResourcePreference( - userConfigurationData - .getComputationalResourceScheduling() - .getResourceHostId(), - groupResourceProfileId); - - if (groupComputeResourcePreference.getResourceSpecificCredentialStoreToken() != null) { - token = groupComputeResourcePreference.getResourceSpecificCredentialStoreToken(); - } - } - if (token == null || token.isEmpty()) { - // try with group resource profile level token - GroupResourceProfile groupResourceProfile = - registryClient.getGroupResourceProfile(groupResourceProfileId); - token = groupResourceProfile.getDefaultCredentialStoreToken(); - } - // still the token is empty, then we fail the experiment - if (token == null || token.isEmpty()) { - throw new Exception( - "You have not configured credential store token at group resource profile or compute resource preference." - + " Please provide the correct token at group resource profile or compute resource preference."); - } - ExperimentType executionType = experiment.getExperimentType(); - if (executionType == ExperimentType.SINGLE_APPLICATION) { - // its an single application execution experiment - List 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 - processModel.getProcessInputs().stream().forEach(pi -> { - if (pi.getType().equals(DataType.URI) - && pi.getValue() != null - && pi.getValue().startsWith("airavata-dp://")) { - try { - DataProductModel dataProductModel = registryClient.getDataProduct(pi.getValue()); - Optional 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 (RegistryServiceException e) { - throw new RuntimeException("Error while launching experiment", e); - } catch (TException e) { - throw new RuntimeException("Error while launching experiment", e); - } - } else if (pi.getType().equals(DataType.URI_COLLECTION) - && pi.getValue() != null - && pi.getValue().contains("airavata-dp://")) { - try { - String[] uriList = pi.getValue().split(","); - final ArrayList filePathList = new ArrayList<>(); - for (String uri : uriList) { - if (uri.startsWith("airavata-dp://")) { - DataProductModel dataProductModel = registryClient.getDataProduct(uri); - Optional 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 (RegistryServiceException e) { - throw new RuntimeException("Error while launching experiment", e); - } catch (TException e) { - throw new RuntimeException("Error while launching experiment", e); - } - } - }); - - if (!experiment.getUserConfigurationData().isAiravataAutoSchedule()) { - String taskDag = orchestrator.createAndSaveTasks(gatewayId, processModel); - processModel.setTaskDag(taskDag); - } - registryClient.updateProcess(processModel, processModel.getProcessId()); - } - - if (!experiment.getUserConfigurationData().isAiravataAutoSchedule() - && !validateProcess(experimentId, processes)) { - throw new Exception("Validating process fails for given experiment Id : " + experimentId); - } - - ProcessScheduler scheduler = new ProcessSchedulerImpl(); - if (!experiment.getUserConfigurationData().isAiravataAutoSchedule() - || scheduler.canLaunch(experimentId)) { - createAndValidateTasks(experiment, registryClient, false); - runExperimentLauncher(experimentId, gatewayId, token); - } else { - log.debug(experimentId, "Queuing single application experiment {}.", experimentId); - ExperimentStatus status = new ExperimentStatus(ExperimentState.SCHEDULED); - status.setReason("Compute resources are not ready"); - status.setTimeOfStateChange( - AiravataUtils.getCurrentTimestamp().getTime()); - OrchestratorUtils.updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); - log.info("expId: {}, Scheduled experiment ", experimentId); - } - } 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.updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); - throw new TException( - "Experiment '" + experimentId + "' launch failed. Experiment failed to validate: " - + launchValidationException.getErrorMessage(), - launchValidationException); + return orchestratorService.launchExperimentWithErrorHandling( + experimentId, gatewayId, OrchestratorServerThreadPoolExecutor.getCachedThreadPool()); + } catch (TException e) { + throw e; } catch (Exception e) { - ExperimentStatus status = new ExperimentStatus(ExperimentState.FAILED); - status.setReason("Unexpected error occurred: " + e.getMessage()); - status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime()); - OrchestratorUtils.updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); throw new TException("Experiment '" + experimentId + "' launch failed.", e); - } finally { - if (registryClient != null) { - ThriftUtils.close(registryClient); - } } - return true; } /** @@ -323,50 +160,39 @@ public boolean launchExperiment(String experimentId, String gatewayId) throws TE * @throws TException */ public boolean validateExperiment(String experimentId) throws TException, LaunchValidationException { - final RegistryService.Client registryClient = getRegistryServiceClient(); try { - ExperimentModel experimentModel = registryClient.getExperiment(experimentId); - return orchestrator.validateExperiment(experimentModel).isValidationState(); + return orchestratorService.validateExperiment(experimentId); } catch (OrchestratorException e) { log.error(experimentId, "Error while validating experiment", e); throw new TException(e); - } finally { - if (registryClient != null) { - ThriftUtils.close(registryClient); - } + } catch (org.apache.airavata.registry.cpi.RegistryException e) { + log.error(experimentId, "Error while retrieving experiment for validation", e); + throw new TException(e); } } @Override public boolean validateProcess(String experimentId, List processes) throws LaunchValidationException, TException { - final RegistryService.Client registryClient = getRegistryServiceClient(); try { - ExperimentModel experimentModel = registryClient.getExperiment(experimentId); - for (ProcessModel processModel : processes) { - boolean state = orchestrator - .validateProcess(experimentModel, processModel) - .isSetValidationState(); - if (!state) { - return false; - } - } - return true; + return orchestratorService.validateProcess(experimentId, processes); } catch (LaunchValidationException lve) { - // If a process failed to validate, also add an error message at the experiment level ErrorModel details = new ErrorModel(); details.setActualErrorMessage(lve.getErrorMessage()); details.setCreationTime(Calendar.getInstance().getTimeInMillis()); - registryClient.addErrors(OrchestratorConstants.EXPERIMENT_ERROR, details, experimentId); + try { + orchestratorService.addProcessValidationErrors(experimentId, details); + } catch (org.apache.airavata.registry.cpi.RegistryException e) { + log.error(experimentId, "Error while adding errors to experiment", e); + } throw lve; } catch (OrchestratorException e) { log.error(experimentId, "Error while validating process", e); throw new TException(e); - } finally { - if (registryClient != null) { - ThriftUtils.close(registryClient); - } + } catch (org.apache.airavata.registry.cpi.RegistryException e) { + log.error(experimentId, "Error while retrieving experiment for process validation", e); + throw new TException(e); } } @@ -379,112 +205,24 @@ public boolean validateProcess(String experimentId, List processes * @throws TException */ public boolean terminateExperiment(String experimentId, String gatewayId) throws TException { - final RegistryService.Client registryClient = getRegistryServiceClient(); log.info(experimentId, "Experiment: {} is cancelling !!!!!", experimentId); try { - return validateStatesAndCancel(registryClient, experimentId, gatewayId); + return orchestratorService.terminateExperiment(experimentId, gatewayId); } catch (Exception e) { log.error("expId : " + experimentId + " :- Error while cancelling experiment", e); return false; - } finally { - if (registryClient != null) { - ThriftUtils.close(registryClient); - } } } public void fetchIntermediateOutputs(String experimentId, String gatewayId, List outputNames) throws TException { - final RegistryService.Client registryClient = getRegistryServiceClient(); try { - submitIntermediateOutputsProcess(registryClient, experimentId, gatewayId, outputNames); + orchestratorService.fetchIntermediateOutputs(experimentId, gatewayId, outputNames); } catch (Exception e) { log.error("expId : " + experimentId + " :- Error while fetching intermediate", e); - } finally { - if (registryClient != null) { - ThriftUtils.close(registryClient); - } } } - private void submitIntermediateOutputsProcess( - Client registryClient, String experimentId, String gatewayId, List outputNames) throws Exception { - - ExperimentModel experimentModel = registryClient.getExperiment(experimentId); - ProcessModel processModel = ExperimentModelUtil.cloneProcessFromExperiment(experimentModel); - processModel.setExperimentDataDir(processModel.getExperimentDataDir() + "/intermediates"); - - List applicationOutputs = registryClient.getApplicationOutputs( - experimentModel.getExecutionId()); // This is to get a clean output object set - List requestedOutputs = new ArrayList<>(); - - for (OutputDataObjectType output : applicationOutputs) { - if (outputNames.contains(output.getName())) { - requestedOutputs.add(output); - } - } - processModel.setProcessOutputs(requestedOutputs); - String processId = registryClient.addProcess(processModel, experimentId); - processModel.setProcessId(processId); - - try { - // Find the process that is responsible for main experiment workflow by - // looking for the process that has the JOB_SUBMISSION task - Optional jobSubmissionProcess = experimentModel.getProcesses().stream() - .filter(p -> p.getTasks().stream().anyMatch(t -> t.getTaskType() == TaskTypes.JOB_SUBMISSION)) - .findFirst(); - if (!jobSubmissionProcess.isPresent()) { - throw new Exception(MessageFormat.format( - "Could not find job submission process for experiment {0}, unable to fetch intermediate outputs {1}", - experimentId, outputNames)); - } - String taskDag = orchestrator.createAndSaveIntermediateOutputFetchingTasks( - gatewayId, processModel, jobSubmissionProcess.get()); - processModel.setTaskDag(taskDag); - - registryClient.updateProcess(processModel, processModel.getProcessId()); - - // Figure out the credential token - UserConfigurationDataModel userConfigurationData = experimentModel.getUserConfigurationData(); - String token = null; - final String groupResourceProfileId = userConfigurationData.getGroupResourceProfileId(); - if (groupResourceProfileId == null) { - throw new Exception("Experiment not configured with a Group Resource Profile: " + experimentId); - } - GroupComputeResourcePreference groupComputeResourcePreference = - registryClient.getGroupComputeResourcePreference( - userConfigurationData - .getComputationalResourceScheduling() - .getResourceHostId(), - groupResourceProfileId); - if (groupComputeResourcePreference.getResourceSpecificCredentialStoreToken() != null) { - token = groupComputeResourcePreference.getResourceSpecificCredentialStoreToken(); - } - if (token == null || token.isEmpty()) { - // try with group resource profile level token - GroupResourceProfile groupResourceProfile = - registryClient.getGroupResourceProfile(groupResourceProfileId); - token = groupResourceProfile.getDefaultCredentialStoreToken(); - } - // still the token is empty, then we fail the experiment - if (token == null || token.isEmpty()) { - throw new Exception( - "You have not configured credential store token at group resource profile or compute resource preference." - + " Please provide the correct token at group resource profile or compute resource preference."); - } - orchestrator.launchProcess(processModel, token); - } catch (Exception e) { - log.error("Failed to launch process for intermediate output fetching", e); - - // Update Process status to FAILED - ProcessStatus status = new ProcessStatus(ProcessState.FAILED); - status.setReason("Intermediate output fetching process failed to launch: " + e.getMessage()); - status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime()); - registryClient.addProcessStatus(status, processId); - - throw e; - } - } private String getAiravataUserName() { return airavataUserName; @@ -504,234 +242,18 @@ public void setGatewayName(String gatewayName) { @Override public boolean launchProcess(String processId, String airavataCredStoreToken, String gatewayId) throws TException { - final RegistryService.Client registryClient = getRegistryServiceClient(); try { - ProcessStatus processStatus = registryClient.getProcessStatus(processId); - - switch (processStatus.getState()) { - case CREATED: - case VALIDATED: - case DEQUEUING: - ProcessModel processModel = registryClient.getProcess(processId); - String applicationId = processModel.getApplicationInterfaceId(); - if (applicationId == null) { - log.error(processId, "Application interface id shouldn't be null."); - throw new OrchestratorException( - "Error executing the job, application interface id shouldn't be null."); - } - // set application deployment id to process model - ApplicationDeploymentDescription applicationDeploymentDescription = - getAppDeployment(registryClient, processModel, applicationId); - if (applicationDeploymentDescription == null) { - log.error("Could not find an application deployment for " + processModel.getComputeResourceId() - + " and application " + applicationId); - throw new OrchestratorException("Could not find an application deployment for " - + processModel.getComputeResourceId() + " and application " + applicationId); - } - processModel.setApplicationDeploymentId(applicationDeploymentDescription.getAppDeploymentId()); - // set compute resource id to process model, default we set the same in the user preferred compute - // host id - processModel.setComputeResourceId( - processModel.getProcessResourceSchedule().getResourceHostId()); - registryClient.updateProcess(processModel, processModel.getProcessId()); - return orchestrator.launchProcess(processModel, airavataCredStoreToken); - - default: - log.warn("Process " + processId + " is already launched. So it can not be relaunched"); - return false; - } - + return orchestratorService.launchProcess(processId, airavataCredStoreToken, gatewayId); + } catch (org.apache.airavata.registry.cpi.RegistryException e) { + log.error(processId, "Error while launching process ", e); + throw new TException(e); } catch (Exception e) { log.error(processId, "Error while launching process ", e); throw new TException(e); - } finally { - if (registryClient != null) { - ThriftUtils.close(registryClient); - } } } - private ApplicationDeploymentDescription getAppDeployment( - RegistryService.Client registryClient, ProcessModel processModel, String applicationId) - throws OrchestratorException, ClassNotFoundException, ApplicationSettingsException, InstantiationException, - IllegalAccessException, TException { - String selectedModuleId = getModuleId(registryClient, applicationId); - return getAppDeploymentForModule(registryClient, processModel, selectedModuleId); - } - - private ApplicationDeploymentDescription getAppDeploymentForModule( - RegistryService.Client registryClient, ProcessModel processModel, String selectedModuleId) - throws ClassNotFoundException, ApplicationSettingsException, InstantiationException, IllegalAccessException, - TException { - List applicationDeployements = - registryClient.getApplicationDeployments(selectedModuleId); - Map deploymentMap = - new HashMap(); - - for (ApplicationDeploymentDescription deploymentDescription : applicationDeployements) { - if (processModel.getComputeResourceId().equals(deploymentDescription.getComputeHostId())) { - deploymentMap.put( - registryClient.getComputeResource(deploymentDescription.getComputeHostId()), - deploymentDescription); - } - } - List computeHostList = - Arrays.asList(deploymentMap.keySet().toArray(new ComputeResourceDescription[] {})); - Class aClass = - Class.forName(ServerSettings.getHostScheduler()).asSubclass(HostScheduler.class); - HostScheduler hostScheduler = aClass.newInstance(); - ComputeResourceDescription ComputeResourceDescription = hostScheduler.schedule(computeHostList); - return deploymentMap.get(ComputeResourceDescription); - } - - private String getModuleId(RegistryService.Client registryClient, String applicationId) - throws OrchestratorException, TException { - ApplicationInterfaceDescription applicationInterface = registryClient.getApplicationInterface(applicationId); - List applicationModules = applicationInterface.getApplicationModules(); - if (applicationModules.size() == 0) { - throw new OrchestratorException("No modules defined for application " + applicationId); - } - // AiravataAPI airavataAPI = getAiravataAPI(); - String selectedModuleId = applicationModules.get(0); - return selectedModuleId; - } - - private boolean validateStatesAndCancel( - RegistryService.Client registryClient, String experimentId, String gatewayId) throws Exception { - ExperimentStatus experimentStatus = registryClient.getExperimentStatus(experimentId); - switch (experimentStatus.getState()) { - case COMPLETED: - case CANCELED: - case FAILED: - case CANCELING: - log.warn( - "Can't terminate already {} experiment", - experimentStatus.getState().name()); - return false; - case CREATED: - log.warn("Experiment termination is only allowed for launched experiments."); - return false; - default: - ExperimentModel experimentModel = registryClient.getExperiment(experimentId); - final UserConfigurationDataModel userConfigurationData = experimentModel.getUserConfigurationData(); - final String groupResourceProfileId = userConfigurationData.getGroupResourceProfileId(); - - GroupComputeResourcePreference groupComputeResourcePreference = - registryClient.getGroupComputeResourcePreference( - userConfigurationData - .getComputationalResourceScheduling() - .getResourceHostId(), - groupResourceProfileId); - String token = groupComputeResourcePreference.getResourceSpecificCredentialStoreToken(); - if (token == null || token.isEmpty()) { - // try with group resource profile level token - GroupResourceProfile groupResourceProfile = - registryClient.getGroupResourceProfile(groupResourceProfileId); - token = groupResourceProfile.getDefaultCredentialStoreToken(); - } - // 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 group resource profile or compute resource preference." - + " Please provide the correct token at group resource profile or compute resource preference."); - return false; - } - - orchestrator.cancelExperiment(experimentModel, token); - // TODO deprecate this approach as we are replacing gfac - String expCancelNodePath = ZKPaths.makePath( - ZKPaths.makePath(ZkConstants.ZOOKEEPER_EXPERIMENT_NODE, experimentId), - ZkConstants.ZOOKEEPER_CANCEL_LISTENER_NODE); - Stat stat = curatorClient.checkExists().forPath(expCancelNodePath); - if (stat != null) { - curatorClient - .setData() - .withVersion(-1) - .forPath(expCancelNodePath, ZkConstants.ZOOKEEPER_CANCEL_REQEUST.getBytes()); - ExperimentStatus status = new ExperimentStatus(ExperimentState.CANCELING); - status.setReason("Experiment cancel request processed"); - status.setTimeOfStateChange( - AiravataUtils.getCurrentTimestamp().getTime()); - OrchestratorUtils.updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); - log.info("expId : " + experimentId + " :- Experiment status updated to " + status.getState()); - } - return true; - } - } - - private void launchWorkflowExperiment(String experimentId, String airavataCredStoreToken, String gatewayId) - throws TException { - // FIXME - // try { - // WorkflowEnactmentService.getInstance(). - // submitWorkflow(experimentId, airavataCredStoreToken, getGatewayName(), - // getRabbitMQProcessPublisher()); - // } catch (Exception e) { - // log.error("Error while launching workflow", e); - // } - } - - private class SingleAppExperimentRunner implements Runnable { - - String experimentId; - String airavataCredStoreToken; - String gatewayId; - - public SingleAppExperimentRunner(String experimentId, String airavataCredStoreToken, String gatewayId) { - this.experimentId = experimentId; - this.airavataCredStoreToken = airavataCredStoreToken; - this.gatewayId = gatewayId; - } - - @Override - public void run() { - try { - launchSingleAppExperiment(); - } catch (TException e) { - log.error("Unable to launch experiment..", e); - throw new RuntimeException("Error while launching experiment", e); - } catch (AiravataException e) { - log.error("Unable to publish experiment status..", e); - } - } - - private boolean launchSingleAppExperiment() throws TException, AiravataException { - final RegistryService.Client registryClient = getRegistryServiceClient(); - try { - List processIds = registryClient.getProcessIds(experimentId); - for (String processId : processIds) { - launchProcess(processId, airavataCredStoreToken, gatewayId); - } - // ExperimentStatus status = new ExperimentStatus(ExperimentState.LAUNCHED); - // status.setReason("submitted all processes"); - // status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime()); - // OrchestratorUtils.updageAndPublishExperimentStatus(experimentId, status); - // log.info("expId: {}, Launched experiment ", experimentId); - } catch (Exception e) { - ExperimentStatus status = new ExperimentStatus(ExperimentState.FAILED); - status.setReason("Error while updating task status"); - OrchestratorUtils.updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); - log.error( - "expId: " + experimentId - + ", Error while updating task status, hence updated experiment status to " - + ExperimentState.FAILED, - e); - ExperimentStatusChangeEvent event = - new ExperimentStatusChangeEvent(ExperimentState.FAILED, experimentId, gatewayId); - String messageId = AiravataUtils.getId("EXPERIMENT"); - MessageContext messageContext = new MessageContext(event, MessageType.EXPERIMENT, messageId, gatewayId); - messageContext.setUpdatedTime(AiravataUtils.getCurrentTimestamp()); - publisher.publish(messageContext); - throw new TException(e); - } finally { - if (registryClient != null) { - ThriftUtils.close(registryClient); - } - } - return true; - } - } private class ProcessStatusHandler implements MessageHandler { /** @@ -747,154 +269,21 @@ public void onMessage(MessageContext message) { TBase event = message.getEvent(); byte[] bytes = ThriftUtils.serializeThriftObject(event); ThriftUtils.createThriftFromBytes(bytes, processStatusChangeEvent); - ExperimentStatus status = new ExperimentStatus(); ProcessIdentifier processIdentity = processStatusChangeEvent.getProcessIdentity(); log.info( "expId: {}, processId: {} :- Process status changed event received for status {}", processIdentity.getExperimentId(), processIdentity.getProcessId(), processStatusChangeEvent.getState().name()); - try { - ProcessModel process = OrchestratorUtils.getProcess(processIdentity.getProcessId()); - boolean isIntermediateOutputFetchingProcess = - process.getTasks().stream().anyMatch(t -> t.getTaskType() == TaskTypes.OUTPUT_FETCHING); - if (isIntermediateOutputFetchingProcess) { - log.info( - "Not updating experiment status because process is an intermediate output fetching one"); - return; - } - } catch (ApplicationSettingsException e) { - throw new RuntimeException("Error getting process " + processIdentity.getProcessId(), e); - } - switch (processStatusChangeEvent.getState()) { - // case CREATED: - // case VALIDATED: - case STARTED: - try { - ExperimentStatus stat = - OrchestratorUtils.getExperimentStatus(processIdentity.getExperimentId()); - if (stat.getState() == ExperimentState.CANCELING) { - status.setState(ExperimentState.CANCELING); - status.setReason("Process started but experiment cancelling is triggered"); - } else { - status.setState(ExperimentState.EXECUTING); - status.setReason("process started"); - } - } catch (ApplicationSettingsException e) { - throw new RuntimeException("Error ", e); - } - break; - // case PRE_PROCESSING: - // break; - // case CONFIGURING_WORKSPACE: - // case INPUT_DATA_STAGING: - // case EXECUTING: - // case MONITORING: - // case OUTPUT_DATA_STAGING: - // case POST_PROCESSING: - // case CANCELLING: - // break; - case COMPLETED: - try { - ExperimentStatus stat = - OrchestratorUtils.getExperimentStatus(processIdentity.getExperimentId()); - if (stat.getState() == ExperimentState.CANCELING) { - status.setState(ExperimentState.CANCELED); - status.setReason("Process competed but experiment cancelling is triggered"); - } else { - status.setState(ExperimentState.COMPLETED); - status.setReason("process completed"); - } - } catch (ApplicationSettingsException e) { - throw new RuntimeException("Error ", e); - } - break; - case FAILED: - try { - ExperimentStatus stat = - OrchestratorUtils.getExperimentStatus(processIdentity.getExperimentId()); - if (stat.getState() == ExperimentState.CANCELING) { - status.setState(ExperimentState.CANCELED); - status.setReason("Process failed but experiment cancelling is triggered"); - } else { - status.setState(ExperimentState.FAILED); - status.setReason("process failed"); - } - } catch (ApplicationSettingsException e) { - throw new RuntimeException("Unable to create registry client...", e); - } - break; - case CANCELED: - // TODO if experiment have more than one process associated with it, then this should be - // changed. - status.setState(ExperimentState.CANCELED); - status.setReason("process cancelled"); - break; - case QUEUED: - status.setState(ExperimentState.SCHEDULED); - status.setReason("Process started but compute resource not avaialable"); - break; - case REQUEUED: - status.setState(ExperimentState.SCHEDULED); - status.setReason("Job submission failed, requeued to resubmit"); - List queueStatusModels = new ArrayList<>(); - final RegistryService.Client registryClient = getRegistryServiceClient(); - ExperimentModel experimentModel = - registryClient.getExperiment(processIdentity.getExperimentId()); - UserConfigurationDataModel userConfigurationDataModel = - experimentModel.getUserConfigurationData(); - if (userConfigurationDataModel != null) { - ComputationalResourceSchedulingModel computationalResourceSchedulingModel = - userConfigurationDataModel.getComputationalResourceScheduling(); - if (computationalResourceSchedulingModel != null) { - String queueName = computationalResourceSchedulingModel.getQueueName(); - String resourceId = computationalResourceSchedulingModel.getResourceHostId(); - ComputeResourceDescription comResourceDes = - registryClient.getComputeResource(resourceId); - QueueStatusModel queueStatusModel = new QueueStatusModel(); - queueStatusModel.setHostName(comResourceDes.getHostName()); - queueStatusModel.setQueueName(queueName); - queueStatusModel.setQueueUp(false); - queueStatusModel.setRunningJobs(0); - queueStatusModel.setQueuedJobs(0); - queueStatusModel.setTime(System.currentTimeMillis()); - queueStatusModels.add(queueStatusModel); - registryClient.registerQueueStatuses(queueStatusModels); - } - } - - break; - case DEQUEUING: - try { - ExperimentStatus stat = - OrchestratorUtils.getExperimentStatus(processIdentity.getExperimentId()); - if (stat.getState() == ExperimentState.CANCELING) { - status.setState(ExperimentState.CANCELING); - status.setReason("Process started but experiment cancelling is triggered"); - } else { - launchQueuedExperiment(processIdentity.getExperimentId()); - } - - } catch (Exception e) { - throw new RuntimeException("Error ", e); - } - break; - default: - // ignore other status changes, thoes will not affect for experiment status changes - return; - } - if (status.getState() != null) { - status.setTimeOfStateChange( - AiravataUtils.getCurrentTimestamp().getTime()); - OrchestratorUtils.updateAndPublishExperimentStatus( - processIdentity.getExperimentId(), status, publisher, processIdentity.getGatewayId()); - log.info("expId : " + processIdentity.getExperimentId() + " :- Experiment status updated to " - + status.getState()); - } + orchestratorService.handleProcessStatusChange(processStatusChangeEvent, processIdentity); } catch (TException e) { log.error("Message Id : " + message.getMessageId() + ", Message type : " + message.getType() + "Error" + " while prcessing process status change event"); throw new RuntimeException("Error while updating experiment status", e); + } catch (Exception e) { + log.error("Message Id : " + message.getMessageId() + ", Message type : " + message.getType() + + "Error" + " while prcessing process status change event", e); + throw new RuntimeException("Error while updating experiment status", e); } } else { System.out.println("Message Recieved with message id " + message.getMessageId() + " and with message " @@ -935,10 +324,13 @@ private void cancelExperiment(MessageContext messageContext) { "Cancelling experiment with experimentId: {} gateway Id: {}", expEvent.getExperimentId(), expEvent.getGatewayId()); - terminateExperiment(expEvent.getExperimentId(), expEvent.getGatewayId()); + orchestratorService.handleCancelExperiment(expEvent); } catch (TException e) { log.error("Error while cancelling experiment", e); throw new RuntimeException("Error while cancelling experiment", e); + } catch (Exception e) { + log.error("Error while cancelling experiment", e); + throw new RuntimeException("Error while cancelling experiment", e); } finally { experimentSubscriber.sendAck(messageContext.getDeliveryTag()); } @@ -954,10 +346,13 @@ private void handleIntermediateOutputsEvent(MessageContext messageContext) { event.getExperimentId(), event.getGatewayId(), event.getOutputNames()); - fetchIntermediateOutputs(event.getExperimentId(), event.getGatewayId(), event.getOutputNames()); + orchestratorService.handleIntermediateOutputsEvent(event); } catch (TException e) { log.error("Error while fetching intermediate outputs", e); throw new RuntimeException("Error while fetching intermediate outputs", e); + } catch (Exception e) { + log.error("Error while fetching intermediate outputs", e); + throw new RuntimeException("Error while fetching intermediate outputs", e); } finally { experimentSubscriber.sendAck(messageContext.getDeliveryTag()); } @@ -965,57 +360,20 @@ private void handleIntermediateOutputsEvent(MessageContext messageContext) { } private void launchExperiment(MessageContext messageContext) { - ExperimentSubmitEvent expEvent = new ExperimentSubmitEvent(); - final RegistryService.Client registryClient = getRegistryServiceClient(); try { - byte[] bytes = ThriftUtils.serializeThriftObject(messageContext.getEvent()); - ThriftUtils.createThriftFromBytes(bytes, expEvent); - MDC.put(MDCConstants.EXPERIMENT_ID, expEvent.getExperimentId()); - log.info( - "Launching experiment with experimentId: {} gateway Id: {}", - expEvent.getExperimentId(), - expEvent.getGatewayId()); - if (messageContext.isRedeliver()) { - ExperimentModel experimentModel = registryClient.getExperiment(expEvent.getExperimentId()); - MDC.put(MDCConstants.EXPERIMENT_NAME, experimentModel.getExperimentName()); - if (experimentModel.getExperimentStatus().get(0).getState() == ExperimentState.CREATED) { - launchExperiment(expEvent.getExperimentId(), expEvent.getGatewayId()); - } - } else { - launchExperiment(expEvent.getExperimentId(), expEvent.getGatewayId()); - } + orchestratorService.handleLaunchExperimentFromMessage(messageContext); } catch (TException e) { - String logMessage = expEvent.getExperimentId() != null && expEvent.getGatewayId() != null - ? String.format( - "Experiment launch failed due to Thrift conversion error, experimentId: %s, gatewayId: %s", - expEvent.getExperimentId(), expEvent.getGatewayId()) - : "Experiment launch failed due to Thrift conversion error"; - log.error(logMessage, e); + log.error("Experiment launch failed due to Thrift conversion error", e); + } catch (org.apache.airavata.registry.cpi.RegistryException e) { + log.error("Experiment launch failed due to registry error", e); } catch (Exception e) { - log.error( - "An unknown issue while launching experiment " - + Optional.ofNullable(expEvent.getExperimentId()).orElse("missing experiment") - + " on gateway " - + Optional.ofNullable(expEvent.getGatewayId()).orElse("missing gateway"), - e); + log.error("An unknown issue while launching experiment", e); } finally { experimentSubscriber.sendAck(messageContext.getDeliveryTag()); MDC.clear(); - if (registryClient != null) { - ThriftUtils.close(registryClient); - } } } - private RegistryService.Client getRegistryServiceClient() { - try { - final int serverPort = Integer.parseInt(ServerSettings.getRegistryServerPort()); - final String serverHost = ServerSettings.getRegistryServerHost(); - return RegistryServiceClientFactory.createRegistryClient(serverHost, serverPort); - } catch (RegistryServiceException | ApplicationSettingsException e) { - throw new RuntimeException("Unable to create registry client...", e); - } - } private void startCurator() throws ApplicationSettingsException { String connectionSting = ServerSettings.getZookeeperConnection(); @@ -1028,72 +386,4 @@ public String getExperimentNodePath(String experimentId) { return ZKPaths.makePath(ZkConstants.ZOOKEEPER_EXPERIMENT_NODE, experimentId); } - private void runExperimentLauncher(String experimentId, String gatewayId, String token) throws TException { - ExperimentStatus status = new ExperimentStatus(ExperimentState.LAUNCHED); - status.setReason("submitted all processes"); - status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime()); - OrchestratorUtils.updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); - log.info("expId: {}, Launched experiment ", experimentId); - OrchestratorServerThreadPoolExecutor.getCachedThreadPool() - .execute(MDCUtil.wrapWithMDC(new SingleAppExperimentRunner(experimentId, token, gatewayId))); - } - - private void launchQueuedExperiment(String experimentId) throws TException, Exception { - ExperimentModel experiment = null; - final RegistryService.Client registryClient = getRegistryServiceClient(); - // TODO deprecate this approach as we are replacing gfac - experiment = registryClient.getExperiment(experimentId); - if (experiment == null) { - throw new Exception("Error retrieving the Experiment by the given experimentID: " + experimentId); - } - - UserConfigurationDataModel userConfigurationData = experiment.getUserConfigurationData(); - String token = null; - final String groupResourceProfileId = userConfigurationData.getGroupResourceProfileId(); - if (groupResourceProfileId == null) { - throw new Exception("Experiment not configured with a Group Resource Profile: " + experimentId); - } - GroupComputeResourcePreference groupComputeResourcePreference = - registryClient.getGroupComputeResourcePreference( - userConfigurationData - .getComputationalResourceScheduling() - .getResourceHostId(), - groupResourceProfileId); - if (groupComputeResourcePreference.getResourceSpecificCredentialStoreToken() != null) { - token = groupComputeResourcePreference.getResourceSpecificCredentialStoreToken(); - } - if (token == null || token.isEmpty()) { - // try with group resource profile level token - GroupResourceProfile groupResourceProfile = registryClient.getGroupResourceProfile(groupResourceProfileId); - token = groupResourceProfile.getDefaultCredentialStoreToken(); - } - // still the token is empty, then we fail the experiment - if (token == null || token.isEmpty()) { - throw new Exception( - "You have not configured credential store token at group resource profile or compute resource preference." - + " Please provide the correct token at group resource profile or compute resource preference."); - } - createAndValidateTasks(experiment, registryClient, true); - runExperimentLauncher(experimentId, experiment.getGatewayId(), token); - } - - private void createAndValidateTasks( - ExperimentModel experiment, RegistryService.Client registryClient, boolean recreateTaskDag) - throws Exception { - if (experiment.getUserConfigurationData().isAiravataAutoSchedule()) { - List processModels = registryClient.getProcessList(experiment.getExperimentId()); - for (ProcessModel processModel : processModels) { - if (processModel.getTaskDag() == null || recreateTaskDag) { - registryClient.deleteTasks(processModel.getProcessId()); - String taskDag = orchestrator.createAndSaveTasks(experiment.getGatewayId(), processModel); - processModel.setTaskDag(taskDag); - registryClient.updateProcess(processModel, processModel.getProcessId()); - } - } - if (!validateProcess(experiment.getExperimentId(), processModels)) { - throw new Exception( - "Validating process fails for given experiment Id : " + experiment.getExperimentId()); - } - } - } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorService.java b/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorService.java new file mode 100644 index 0000000000..d9e073102b --- /dev/null +++ b/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorService.java @@ -0,0 +1,737 @@ +/** +* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ +package org.apache.airavata.service; + +import java.text.MessageFormat; +import java.util.*; +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.logging.MDCUtil; +import org.apache.airavata.common.utils.AiravataUtils; +import org.apache.airavata.common.utils.ServerSettings; +import org.apache.airavata.common.utils.ThriftUtils; +import org.apache.airavata.common.utils.ZkConstants; +import org.apache.airavata.messaging.core.MessageContext; +import org.apache.airavata.messaging.core.Publisher; +import org.apache.airavata.metascheduler.core.api.ProcessScheduler; +import org.apache.airavata.metascheduler.process.scheduling.api.ProcessSchedulerImpl; +import org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription; +import org.apache.airavata.model.appcatalog.appinterface.ApplicationInterfaceDescription; +import org.apache.airavata.model.appcatalog.computeresource.ComputeResourceDescription; +import org.apache.airavata.model.appcatalog.groupresourceprofile.GroupComputeResourcePreference; +import org.apache.airavata.model.appcatalog.groupresourceprofile.GroupResourceProfile; +import org.apache.airavata.model.application.io.DataType; +import org.apache.airavata.model.application.io.OutputDataObjectType; +import org.apache.airavata.model.commons.ErrorModel; +import org.apache.airavata.model.data.replica.DataProductModel; +import org.apache.airavata.model.data.replica.DataReplicaLocationModel; +import org.apache.airavata.model.data.replica.ReplicaLocationCategory; +import org.apache.airavata.model.error.LaunchValidationException; +import org.apache.airavata.model.experiment.ExperimentModel; +import org.apache.airavata.model.experiment.ExperimentType; +import org.apache.airavata.model.experiment.UserConfigurationDataModel; +import org.apache.airavata.model.process.ProcessModel; +import org.apache.airavata.model.scheduling.ComputationalResourceSchedulingModel; +import org.apache.airavata.model.status.ExperimentState; +import org.apache.airavata.model.status.ExperimentStatus; +import org.apache.airavata.model.status.ProcessState; +import org.apache.airavata.model.status.ProcessStatus; +import org.apache.airavata.model.status.QueueStatusModel; +import org.apache.airavata.model.task.TaskTypes; +import org.apache.airavata.model.messaging.event.ExperimentIntermediateOutputsEvent; +import org.apache.airavata.model.messaging.event.ExperimentSubmitEvent; +import org.apache.airavata.model.messaging.event.ProcessIdentifier; +import org.apache.airavata.model.messaging.event.ProcessStatusChangeEvent; +import org.apache.airavata.model.util.ExperimentModelUtil; +import org.apache.airavata.orchestrator.core.exception.OrchestratorException; +import org.apache.airavata.orchestrator.core.schedule.HostScheduler; +import org.apache.airavata.orchestrator.core.utils.OrchestratorConstants; +import org.apache.airavata.orchestrator.cpi.impl.SimpleOrchestratorImpl; +import org.apache.airavata.orchestrator.util.OrchestratorUtils; +import org.apache.airavata.registry.cpi.AppCatalogException; +import org.apache.airavata.registry.cpi.RegistryException; +import org.apache.commons.lang3.StringUtils; +import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.utils.ZKPaths; +import org.apache.thrift.TException; +import org.apache.zookeeper.data.Stat; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class OrchestratorService { + private static final Logger logger = LoggerFactory.getLogger(OrchestratorService.class); + + private OrchestratorRegistryService orchestratorRegistryService; + private SimpleOrchestratorImpl orchestrator; + private CuratorFramework curatorClient; + private Publisher publisher; + + public OrchestratorService( + OrchestratorRegistryService orchestratorRegistryService, + SimpleOrchestratorImpl orchestrator, + CuratorFramework curatorClient, + Publisher publisher) { + this.orchestratorRegistryService = orchestratorRegistryService; + this.orchestrator = orchestrator; + this.curatorClient = curatorClient; + this.publisher = publisher; + } + + public boolean launchExperiment(String experimentId, String gatewayId) throws Exception { + String experimentNodePath = getExperimentNodePath(experimentId); + ZKPaths.mkdirs(curatorClient.getZookeeperClient().getZooKeeper(), experimentNodePath); + String experimentCancelNode = + ZKPaths.makePath(experimentNodePath, ZkConstants.ZOOKEEPER_CANCEL_LISTENER_NODE); + ZKPaths.mkdirs(curatorClient.getZookeeperClient().getZooKeeper(), experimentCancelNode); + ExperimentModel experiment = orchestratorRegistryService.getExperiment(experimentId); + if (experiment == null) { + throw new Exception("Error retrieving the Experiment by the given experimentID: " + experimentId); + } + + UserConfigurationDataModel userConfigurationData = experiment.getUserConfigurationData(); + String token = getCredentialToken(experiment, userConfigurationData); + + ExperimentType executionType = experiment.getExperimentType(); + if (executionType == ExperimentType.SINGLE_APPLICATION) { + return launchSingleAppExperiment(experiment, experimentId, gatewayId, token); + } else if (executionType == ExperimentType.WORKFLOW) { + logger.debug(experimentId, "Launching workflow experiment {}.", experimentId); + launchWorkflowExperiment(experimentId, token, gatewayId); + return true; + } else { + logger.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()); + } + } + + private boolean launchSingleAppExperiment( + ExperimentModel experiment, String experimentId, String gatewayId, String token) throws Exception { + List processes = orchestrator.createProcesses(experimentId, gatewayId); + + for (ProcessModel processModel : processes) { + resolveInputReplicas(processModel); + + if (!experiment.getUserConfigurationData().isAiravataAutoSchedule()) { + String taskDag = orchestrator.createAndSaveTasks(gatewayId, processModel); + processModel.setTaskDag(taskDag); + } + orchestratorRegistryService.updateProcess(processModel, processModel.getProcessId()); + } + + if (!experiment.getUserConfigurationData().isAiravataAutoSchedule() + && !validateProcess(experimentId, processes)) { + throw new Exception("Validating process fails for given experiment Id : " + experimentId); + } + + ProcessScheduler scheduler = new ProcessSchedulerImpl(); + if (!experiment.getUserConfigurationData().isAiravataAutoSchedule() + || scheduler.canLaunch(experimentId)) { + createAndValidateTasks(experiment, false); + return true; // runExperimentLauncher will be called separately + } else { + logger.debug(experimentId, "Queuing single application experiment {}.", experimentId); + ExperimentStatus status = new ExperimentStatus(ExperimentState.SCHEDULED); + status.setReason("Compute resources are not ready"); + status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime()); + OrchestratorUtils.updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); + logger.info("expId: {}, Scheduled experiment ", experimentId); + return false; + } + } + + private void resolveInputReplicas(ProcessModel processModel) throws Exception { + for (var pi : processModel.getProcessInputs()) { + if (pi.getType().equals(DataType.URI) + && pi.getValue() != null + && pi.getValue().startsWith("airavata-dp://")) { + try { + DataProductModel dataProductModel = orchestratorRegistryService.getDataProduct(pi.getValue()); + Optional 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 { + logger.error("Could not find a replica for the URI " + pi.getValue()); + } + } catch (RegistryException e) { + throw new Exception("Error while launching experiment", e); + } + } else if (pi.getType().equals(DataType.URI_COLLECTION) + && pi.getValue() != null + && pi.getValue().contains("airavata-dp://")) { + try { + String[] uriList = pi.getValue().split(","); + final ArrayList filePathList = new ArrayList<>(); + for (String uri : uriList) { + if (uri.startsWith("airavata-dp://")) { + DataProductModel dataProductModel = orchestratorRegistryService.getDataProduct(uri); + Optional rpLocation = + dataProductModel.getReplicaLocations().stream() + .filter(rpModel -> rpModel.getReplicaLocationCategory() + .equals(ReplicaLocationCategory.GATEWAY_DATA_STORE)) + .findFirst(); + if (rpLocation.isPresent()) { + filePathList.add(rpLocation.get().getFilePath()); + } else { + logger.error("Could not find a replica for the URI " + pi.getValue()); + } + } else { + filePathList.add(uri); + } + } + pi.setValue(StringUtils.join(filePathList, ',')); + } catch (RegistryException e) { + throw new Exception("Error while launching experiment", e); + } + } + } + } + + public String getCredentialToken(ExperimentModel experiment, UserConfigurationDataModel userConfigurationData) throws Exception { + String token = null; + final String groupResourceProfileId = userConfigurationData.getGroupResourceProfileId(); + if (groupResourceProfileId == null) { + throw new Exception("Experiment not configured with a Group Resource Profile: " + experiment.getExperimentId()); + } + + if (userConfigurationData.getComputationalResourceScheduling() != null + && userConfigurationData + .getComputationalResourceScheduling() + .isSet(ComputationalResourceSchedulingModel._Fields.RESOURCE_HOST_ID)) { + GroupComputeResourcePreference groupComputeResourcePreference = + orchestratorRegistryService.getGroupComputeResourcePreference( + userConfigurationData + .getComputationalResourceScheduling() + .getResourceHostId(), + groupResourceProfileId); + + if (groupComputeResourcePreference.getResourceSpecificCredentialStoreToken() != null) { + token = groupComputeResourcePreference.getResourceSpecificCredentialStoreToken(); + } + } + if (token == null || token.isEmpty()) { + GroupResourceProfile groupResourceProfile = + orchestratorRegistryService.getGroupResourceProfile(groupResourceProfileId); + token = groupResourceProfile.getDefaultCredentialStoreToken(); + } + if (token == null || token.isEmpty()) { + throw new Exception( + "You have not configured credential store token at group resource profile or compute resource preference." + + " Please provide the correct token at group resource profile or compute resource preference."); + } + return token; + } + + public boolean validateExperiment(String experimentId) throws TException, LaunchValidationException, RegistryException, OrchestratorException { + ExperimentModel experimentModel = orchestratorRegistryService.getExperiment(experimentId); + return orchestrator.validateExperiment(experimentModel).isValidationState(); + } + + public boolean validateProcess(String experimentId, List processes) + throws LaunchValidationException, TException, RegistryException, OrchestratorException { + ExperimentModel experimentModel = orchestratorRegistryService.getExperiment(experimentId); + for (ProcessModel processModel : processes) { + boolean state = orchestrator + .validateProcess(experimentModel, processModel) + .isSetValidationState(); + if (!state) { + return false; + } + } + return true; + } + + public boolean terminateExperiment(String experimentId, String gatewayId) throws Exception { + logger.info(experimentId, "Experiment: {} is cancelling !!!!!", experimentId); + return validateStatesAndCancel(experimentId, gatewayId); + } + + private boolean validateStatesAndCancel(String experimentId, String gatewayId) throws Exception { + ExperimentStatus experimentStatus = orchestratorRegistryService.getExperimentStatus(experimentId); + switch (experimentStatus.getState()) { + case COMPLETED: + case CANCELED: + case FAILED: + case CANCELING: + logger.warn( + "Can't terminate already {} experiment", + experimentStatus.getState().name()); + return false; + case CREATED: + logger.warn("Experiment termination is only allowed for launched experiments."); + return false; + default: + ExperimentModel experimentModel = orchestratorRegistryService.getExperiment(experimentId); + final UserConfigurationDataModel userConfigurationData = experimentModel.getUserConfigurationData(); + final String groupResourceProfileId = userConfigurationData.getGroupResourceProfileId(); + + GroupComputeResourcePreference groupComputeResourcePreference = + orchestratorRegistryService.getGroupComputeResourcePreference( + userConfigurationData + .getComputationalResourceScheduling() + .getResourceHostId(), + groupResourceProfileId); + String token = groupComputeResourcePreference.getResourceSpecificCredentialStoreToken(); + if (token == null || token.isEmpty()) { + GroupResourceProfile groupResourceProfile = + orchestratorRegistryService.getGroupResourceProfile(groupResourceProfileId); + token = groupResourceProfile.getDefaultCredentialStoreToken(); + } + if (token == null || token.isEmpty()) { + logger.error( + "You have not configured credential store token at group resource profile or compute resource preference." + + " Please provide the correct token at group resource profile or compute resource preference."); + return false; + } + + orchestrator.cancelExperiment(experimentModel, token); + String expCancelNodePath = ZKPaths.makePath( + ZKPaths.makePath(ZkConstants.ZOOKEEPER_EXPERIMENT_NODE, experimentId), + ZkConstants.ZOOKEEPER_CANCEL_LISTENER_NODE); + Stat stat = curatorClient.checkExists().forPath(expCancelNodePath); + if (stat != null) { + curatorClient + .setData() + .withVersion(-1) + .forPath(expCancelNodePath, ZkConstants.ZOOKEEPER_CANCEL_REQEUST.getBytes()); + ExperimentStatus status = new ExperimentStatus(ExperimentState.CANCELING); + status.setReason("Experiment cancel request processed"); + status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime()); + OrchestratorUtils.updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); + logger.info("expId : " + experimentId + " :- Experiment status updated to " + status.getState()); + } + return true; + } + } + + public void fetchIntermediateOutputs(String experimentId, String gatewayId, List outputNames) + throws Exception { + submitIntermediateOutputsProcess(experimentId, gatewayId, outputNames); + } + + private void submitIntermediateOutputsProcess( + String experimentId, String gatewayId, List outputNames) throws Exception { + + ExperimentModel experimentModel = orchestratorRegistryService.getExperiment(experimentId); + ProcessModel processModel = ExperimentModelUtil.cloneProcessFromExperiment(experimentModel); + processModel.setExperimentDataDir(processModel.getExperimentDataDir() + "/intermediates"); + + List applicationOutputs = orchestratorRegistryService.getApplicationOutputs( + experimentModel.getExecutionId()); + List requestedOutputs = new ArrayList<>(); + + for (OutputDataObjectType output : applicationOutputs) { + if (outputNames.contains(output.getName())) { + requestedOutputs.add(output); + } + } + processModel.setProcessOutputs(requestedOutputs); + String processId = orchestratorRegistryService.addProcess(processModel, experimentId); + processModel.setProcessId(processId); + + try { + Optional jobSubmissionProcess = experimentModel.getProcesses().stream() + .filter(p -> p.getTasks().stream().anyMatch(t -> t.getTaskType() == TaskTypes.JOB_SUBMISSION)) + .findFirst(); + if (!jobSubmissionProcess.isPresent()) { + throw new Exception(MessageFormat.format( + "Could not find job submission process for experiment {0}, unable to fetch intermediate outputs {1}", + experimentId, outputNames)); + } + String taskDag = orchestrator.createAndSaveIntermediateOutputFetchingTasks( + gatewayId, processModel, jobSubmissionProcess.get()); + processModel.setTaskDag(taskDag); + + orchestratorRegistryService.updateProcess(processModel, processModel.getProcessId()); + + String token = getCredentialToken(experimentModel, experimentModel.getUserConfigurationData()); + orchestrator.launchProcess(processModel, token); + } catch (Exception e) { + logger.error("Failed to launch process for intermediate output fetching", e); + + ProcessStatus status = new ProcessStatus(ProcessState.FAILED); + status.setReason("Intermediate output fetching process failed to launch: " + e.getMessage()); + status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime()); + orchestratorRegistryService.addProcessStatus(status, processId); + + throw e; + } + } + + public boolean launchProcess(String processId, String airavataCredStoreToken, String gatewayId) throws Exception { + ProcessStatus processStatus = orchestratorRegistryService.getProcessStatus(processId); + + switch (processStatus.getState()) { + case CREATED: + case VALIDATED: + case DEQUEUING: + ProcessModel processModel = orchestratorRegistryService.getProcess(processId); + String applicationId = processModel.getApplicationInterfaceId(); + if (applicationId == null) { + logger.error(processId, "Application interface id shouldn't be null."); + throw new OrchestratorException( + "Error executing the job, application interface id shouldn't be null."); + } + ApplicationDeploymentDescription applicationDeploymentDescription = + getAppDeployment(processModel, applicationId); + if (applicationDeploymentDescription == null) { + logger.error("Could not find an application deployment for " + processModel.getComputeResourceId() + + " and application " + applicationId); + throw new OrchestratorException("Could not find an application deployment for " + + processModel.getComputeResourceId() + " and application " + applicationId); + } + processModel.setApplicationDeploymentId(applicationDeploymentDescription.getAppDeploymentId()); + processModel.setComputeResourceId( + processModel.getProcessResourceSchedule().getResourceHostId()); + orchestratorRegistryService.updateProcess(processModel, processModel.getProcessId()); + return orchestrator.launchProcess(processModel, airavataCredStoreToken); + + default: + logger.warn("Process " + processId + " is already launched. So it can not be relaunched"); + return false; + } + } + + private ApplicationDeploymentDescription getAppDeployment( + ProcessModel processModel, String applicationId) + throws Exception { + String selectedModuleId = getModuleId(applicationId); + return getAppDeploymentForModule(processModel, selectedModuleId); + } + + private ApplicationDeploymentDescription getAppDeploymentForModule( + ProcessModel processModel, String selectedModuleId) + throws Exception { + + List applicationDeployements = + orchestratorRegistryService.getApplicationDeployments(selectedModuleId); + Map deploymentMap = + new HashMap<>(); + + for (ApplicationDeploymentDescription deploymentDescription : applicationDeployements) { + if (processModel.getComputeResourceId().equals(deploymentDescription.getComputeHostId())) { + deploymentMap.put( + orchestratorRegistryService.getComputeResource(deploymentDescription.getComputeHostId()), + deploymentDescription); + } + } + List computeHostList = + Arrays.asList(deploymentMap.keySet().toArray(new ComputeResourceDescription[] {})); + Class aClass = + Class.forName(ServerSettings.getHostScheduler()).asSubclass(HostScheduler.class); + HostScheduler hostScheduler = aClass.newInstance(); + ComputeResourceDescription ComputeResourceDescription = hostScheduler.schedule(computeHostList); + return deploymentMap.get(ComputeResourceDescription); + } + + private String getModuleId(String applicationId) + throws Exception { + ApplicationInterfaceDescription applicationInterface = orchestratorRegistryService.getApplicationInterface(applicationId); + List applicationModules = applicationInterface.getApplicationModules(); + if (applicationModules.size() == 0) { + throw new OrchestratorException("No modules defined for application " + applicationId); + } + String selectedModuleId = applicationModules.get(0); + return selectedModuleId; + } + + private void launchWorkflowExperiment(String experimentId, String airavataCredStoreToken, String gatewayId) + throws TException { + // FIXME - Workflow support not implemented + } + + public void createAndValidateTasks(ExperimentModel experiment, boolean recreateTaskDag) throws Exception { + if (experiment.getUserConfigurationData().isAiravataAutoSchedule()) { + List processModels = orchestratorRegistryService.getProcessList(experiment.getExperimentId()); + for (ProcessModel processModel : processModels) { + if (processModel.getTaskDag() == null || recreateTaskDag) { + orchestratorRegistryService.deleteTasks(processModel.getProcessId()); + String taskDag = orchestrator.createAndSaveTasks(experiment.getGatewayId(), processModel); + processModel.setTaskDag(taskDag); + orchestratorRegistryService.updateProcess(processModel, processModel.getProcessId()); + } + } + if (!validateProcess(experiment.getExperimentId(), processModels)) { + throw new Exception( + "Validating process fails for given experiment Id : " + experiment.getExperimentId()); + } + } + } + + public void addProcessValidationErrors(String experimentId, ErrorModel details) throws RegistryException { + orchestratorRegistryService.addErrors(OrchestratorConstants.EXPERIMENT_ERROR, details, experimentId); + } + + public String getExperimentNodePath(String experimentId) { + return ZKPaths.makePath(ZkConstants.ZOOKEEPER_EXPERIMENT_NODE, experimentId); + } + + public boolean launchSingleAppExperimentInternal(String experimentId, String airavataCredStoreToken, String gatewayId) throws Exception { + try { + List processIds = orchestratorRegistryService.getProcessIds(experimentId); + for (String processId : processIds) { + launchProcess(processId, airavataCredStoreToken, gatewayId); + } + return true; + } catch (org.apache.airavata.registry.cpi.RegistryException e) { + ExperimentStatus status = new ExperimentStatus(ExperimentState.FAILED); + status.setReason("Error while retrieving process IDs"); + OrchestratorUtils.updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); + logger.error("expId: " + experimentId + ", Error while retrieving process IDs", e); + throw new Exception("Error while retrieving process IDs", e); + } catch (Exception e) { + ExperimentStatus status = new ExperimentStatus(ExperimentState.FAILED); + status.setReason("Error while launching processes"); + OrchestratorUtils.updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); + logger.error("expId: " + experimentId + ", Error while launching processes", e); + throw e; + } + } + + public void launchQueuedExperiment(String experimentId) throws Exception { + ExperimentModel experiment = orchestratorRegistryService.getExperiment(experimentId); + if (experiment == null) { + throw new Exception("Error retrieving the Experiment by the given experimentID: " + experimentId); + } + + UserConfigurationDataModel userConfigurationData = experiment.getUserConfigurationData(); + String token = getCredentialToken(experiment, userConfigurationData); + createAndValidateTasks(experiment, true); + + // Publish experiment launched status and run launcher + ExperimentStatus status = new ExperimentStatus(ExperimentState.LAUNCHED); + status.setReason("submitted all processes"); + status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime()); + OrchestratorUtils.updateAndPublishExperimentStatus(experimentId, status, publisher, experiment.getGatewayId()); + logger.info("expId: {}, Launched experiment ", experimentId); + + // Launch processes + launchSingleAppExperimentInternal(experimentId, token, experiment.getGatewayId()); + } + + public void handleProcessStatusChange( + ProcessStatusChangeEvent processStatusChangeEvent, + ProcessIdentifier processIdentity) throws Exception { + ExperimentStatus status = new ExperimentStatus(); + + // Check if this is an intermediate output fetching process + ProcessModel process = orchestratorRegistryService.getProcess(processIdentity.getProcessId()); + boolean isIntermediateOutputFetchingProcess = + process.getTasks().stream().anyMatch(t -> t.getTaskType() == TaskTypes.OUTPUT_FETCHING); + if (isIntermediateOutputFetchingProcess) { + logger.info("Not updating experiment status because process is an intermediate output fetching one"); + return; + } + + switch (processStatusChangeEvent.getState()) { + case STARTED: + ExperimentStatus stat = orchestratorRegistryService.getExperimentStatus(processIdentity.getExperimentId()); + if (stat.getState() == ExperimentState.CANCELING) { + status.setState(ExperimentState.CANCELING); + status.setReason("Process started but experiment cancelling is triggered"); + } else { + status.setState(ExperimentState.EXECUTING); + status.setReason("process started"); + } + break; + case COMPLETED: + stat = orchestratorRegistryService.getExperimentStatus(processIdentity.getExperimentId()); + if (stat.getState() == ExperimentState.CANCELING) { + status.setState(ExperimentState.CANCELED); + status.setReason("Process competed but experiment cancelling is triggered"); + } else { + status.setState(ExperimentState.COMPLETED); + status.setReason("process completed"); + } + break; + case FAILED: + stat = orchestratorRegistryService.getExperimentStatus(processIdentity.getExperimentId()); + if (stat.getState() == ExperimentState.CANCELING) { + status.setState(ExperimentState.CANCELED); + status.setReason("Process failed but experiment cancelling is triggered"); + } else { + status.setState(ExperimentState.FAILED); + status.setReason("process failed"); + } + break; + case CANCELED: + status.setState(ExperimentState.CANCELED); + status.setReason("process cancelled"); + break; + case QUEUED: + status.setState(ExperimentState.SCHEDULED); + status.setReason("Process started but compute resource not avaialable"); + break; + case REQUEUED: + status.setState(ExperimentState.SCHEDULED); + status.setReason("Job submission failed, requeued to resubmit"); + registerQueueStatusForRequeue(processIdentity.getExperimentId()); + break; + case DEQUEUING: + stat = orchestratorRegistryService.getExperimentStatus(processIdentity.getExperimentId()); + if (stat.getState() == ExperimentState.CANCELING) { + status.setState(ExperimentState.CANCELING); + status.setReason("Process started but experiment cancelling is triggered"); + } else { + launchQueuedExperiment(processIdentity.getExperimentId()); + } + break; + default: + // ignore other status changes + return; + } + + if (status.getState() != null) { + status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime()); + OrchestratorUtils.updateAndPublishExperimentStatus( + processIdentity.getExperimentId(), status, publisher, processIdentity.getGatewayId()); + logger.info("expId : " + processIdentity.getExperimentId() + " :- Experiment status updated to " + + status.getState()); + } + } + + private void registerQueueStatusForRequeue(String experimentId) { + try { + List queueStatusModels = new ArrayList<>(); + ExperimentModel experimentModel = orchestratorRegistryService.getExperiment(experimentId); + UserConfigurationDataModel userConfigurationDataModel = experimentModel.getUserConfigurationData(); + if (userConfigurationDataModel != null) { + ComputationalResourceSchedulingModel computationalResourceSchedulingModel = + userConfigurationDataModel.getComputationalResourceScheduling(); + if (computationalResourceSchedulingModel != null) { + String queueName = computationalResourceSchedulingModel.getQueueName(); + String resourceId = computationalResourceSchedulingModel.getResourceHostId(); + ComputeResourceDescription comResourceDes = + orchestratorRegistryService.getComputeResource(resourceId); + QueueStatusModel queueStatusModel = new QueueStatusModel(); + queueStatusModel.setHostName(comResourceDes.getHostName()); + queueStatusModel.setQueueName(queueName); + queueStatusModel.setQueueUp(false); + queueStatusModel.setRunningJobs(0); + queueStatusModel.setQueuedJobs(0); + queueStatusModel.setTime(System.currentTimeMillis()); + queueStatusModels.add(queueStatusModel); + orchestratorRegistryService.registerQueueStatuses(queueStatusModels); + } + } + } catch (org.apache.airavata.registry.cpi.RegistryException e) { + logger.error("Error while registering queue statuses", e); + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + logger.error("Error while getting compute resource for queue status", e); + } + } + + public void handleLaunchExperiment(ExperimentSubmitEvent expEvent) throws Exception { + ExperimentModel experimentModel = orchestratorRegistryService.getExperiment(expEvent.getExperimentId()); + if (experimentModel.getExperimentStatus().get(0).getState() == ExperimentState.CREATED) { + launchExperiment(expEvent.getExperimentId(), expEvent.getGatewayId()); + } + } + + /** + * Handle launch experiment from message context with deserialization and redelivery checks + */ + public void handleLaunchExperimentFromMessage(MessageContext messageContext) throws Exception { + ExperimentSubmitEvent expEvent = new ExperimentSubmitEvent(); + byte[] bytes = ThriftUtils.serializeThriftObject(messageContext.getEvent()); + ThriftUtils.createThriftFromBytes(bytes, expEvent); + + if (messageContext.isRedeliver()) { + ExperimentModel experimentModel = orchestratorRegistryService.getExperiment(expEvent.getExperimentId()); + if (experimentModel != null && experimentModel.getExperimentStatus().get(0).getState() == ExperimentState.CREATED) { + handleLaunchExperiment(expEvent); + } + } else { + handleLaunchExperiment(expEvent); + } + } + + public void handleCancelExperiment(ExperimentSubmitEvent expEvent) throws Exception { + terminateExperiment(expEvent.getExperimentId(), expEvent.getGatewayId()); + } + + public void handleIntermediateOutputsEvent(ExperimentIntermediateOutputsEvent event) throws Exception { + fetchIntermediateOutputs(event.getExperimentId(), event.getGatewayId(), event.getOutputNames()); + } + + public boolean launchExperimentWithErrorHandling(String experimentId, String gatewayId, java.util.concurrent.ExecutorService executorService) throws TException { + try { + boolean result = launchExperiment(experimentId, gatewayId); + if (result) { + ExperimentModel experiment = orchestratorRegistryService.getExperiment(experimentId); + String token = getCredentialToken(experiment, experiment.getUserConfigurationData()); + ExperimentStatus status = new ExperimentStatus(ExperimentState.LAUNCHED); + status.setReason("submitted all processes"); + status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime()); + OrchestratorUtils.updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); + logger.info("expId: {}, Launched experiment ", experimentId); + + // Execute the single app experiment runner in the provided thread pool + if (executorService != null) { + Runnable runner = () -> { + try { + launchSingleAppExperimentInternal(experimentId, token, gatewayId); + } catch (Exception e) { + logger.error("expId: " + experimentId + ", Error while launching single app experiment", e); + } + }; + executorService.execute(MDCUtil.wrapWithMDC(runner)); + } + } + return result; + } catch (LaunchValidationException launchValidationException) { + ExperimentStatus status = new ExperimentStatus(ExperimentState.FAILED); + status.setReason("Validation failed: " + launchValidationException.getErrorMessage()); + status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime()); + OrchestratorUtils.updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); + throw new TException( + "Experiment '" + experimentId + "' launch failed. Experiment failed to validate: " + + launchValidationException.getErrorMessage(), + launchValidationException); + } catch (org.apache.airavata.registry.cpi.RegistryException e) { + ExperimentStatus status = new ExperimentStatus(ExperimentState.FAILED); + status.setReason("Registry error: " + e.getMessage()); + status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime()); + OrchestratorUtils.updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); + throw new TException("Experiment '" + experimentId + "' launch failed.", e); + } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + ExperimentStatus status = new ExperimentStatus(ExperimentState.FAILED); + status.setReason("App catalog error: " + e.getMessage()); + status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime()); + OrchestratorUtils.updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); + throw new TException("Experiment '" + experimentId + "' launch failed.", e); + } catch (Exception e) { + ExperimentStatus status = new ExperimentStatus(ExperimentState.FAILED); + status.setReason("Unexpected error occurred: " + e.getMessage()); + status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime()); + OrchestratorUtils.updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); + throw new TException("Experiment '" + experimentId + "' launch failed.", e); + } + } +} + From 0e1e26bcf0d6fb016bd281cb330e5254e9ebf9ab Mon Sep 17 00:00:00 2001 From: yasithdev Date: Mon, 10 Nov 2025 18:41:33 -0500 Subject: [PATCH 05/26] update Orchestrator (fix) --- .../service/OrchestratorRegistryService.java | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 airavata-api/src/main/java/org/apache/airavata/service/OrchestratorRegistryService.java diff --git a/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorRegistryService.java b/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorRegistryService.java new file mode 100644 index 0000000000..c9e8cb33d3 --- /dev/null +++ b/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorRegistryService.java @@ -0,0 +1,123 @@ +/** +* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ +package org.apache.airavata.service; + +import java.util.List; +import org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription; +import org.apache.airavata.model.appcatalog.appinterface.ApplicationInterfaceDescription; +import org.apache.airavata.model.appcatalog.computeresource.ComputeResourceDescription; +import org.apache.airavata.model.appcatalog.groupresourceprofile.GroupComputeResourcePreference; +import org.apache.airavata.model.appcatalog.groupresourceprofile.GroupResourceProfile; +import org.apache.airavata.model.application.io.OutputDataObjectType; +import org.apache.airavata.model.commons.ErrorModel; +import org.apache.airavata.model.data.replica.DataProductModel; +import org.apache.airavata.model.experiment.ExperimentModel; +import org.apache.airavata.model.process.ProcessModel; +import org.apache.airavata.model.status.ExperimentStatus; +import org.apache.airavata.model.status.ProcessStatus; +import org.apache.airavata.model.status.QueueStatusModel; +import org.apache.airavata.registry.cpi.AppCatalogException; +import org.apache.airavata.registry.cpi.RegistryException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class OrchestratorRegistryService { + private static final Logger logger = LoggerFactory.getLogger(OrchestratorRegistryService.class); + + private org.apache.airavata.service.RegistryService registryService = new org.apache.airavata.service.RegistryService(); + + public ExperimentModel getExperiment(String airavataExperimentId) throws RegistryException { + return registryService.getExperiment(airavataExperimentId); + } + + public GroupComputeResourcePreference getGroupComputeResourcePreference( + String computeResourceId, String groupResourceProfileId) throws AppCatalogException { + return registryService.getGroupComputeResourcePreference(computeResourceId, groupResourceProfileId); + } + + public GroupResourceProfile getGroupResourceProfile(String groupResourceProfileId) throws AppCatalogException { + return registryService.getGroupResourceProfile(groupResourceProfileId); + } + + public DataProductModel getDataProduct(String productUri) throws RegistryException { + return registryService.getDataProduct(productUri); + } + + public void updateProcess(ProcessModel processModel, String processId) throws RegistryException { + registryService.updateProcess(processModel, processId); + } + + public void addErrors(String errorType, ErrorModel errorModel, String id) throws RegistryException { + registryService.addErrors(errorType, errorModel, id); + } + + public ExperimentStatus getExperimentStatus(String airavataExperimentId) throws RegistryException { + return registryService.getExperimentStatus(airavataExperimentId); + } + + public String addProcess(ProcessModel processModel, String experimentId) throws RegistryException { + return registryService.addProcess(processModel, experimentId); + } + + public ProcessModel getProcess(String processId) throws RegistryException { + return registryService.getProcess(processId); + } + + public List getProcessList(String experimentId) throws RegistryException { + return registryService.getProcessList(experimentId); + } + + public ProcessStatus getProcessStatus(String processId) throws RegistryException { + return registryService.getProcessStatus(processId); + } + + public List getProcessIds(String experimentId) throws RegistryException { + return registryService.getProcessIds(experimentId); + } + + public void addProcessStatus(ProcessStatus processStatus, String processId) throws RegistryException { + registryService.addProcessStatus(processStatus, processId); + } + + public List getApplicationOutputs(String appInterfaceId) throws AppCatalogException { + return registryService.getApplicationOutputs(appInterfaceId); + } + + public ApplicationInterfaceDescription getApplicationInterface(String appInterfaceId) throws AppCatalogException { + return registryService.getApplicationInterface(appInterfaceId); + } + + public List getApplicationDeployments(String appModuleId) throws AppCatalogException { + return registryService.getApplicationDeployments(appModuleId); + } + + public ComputeResourceDescription getComputeResource(String computeResourceId) throws AppCatalogException { + return registryService.getComputeResource(computeResourceId); + } + + public void deleteTasks(String processId) throws RegistryException { + registryService.deleteTasks(processId); + } + + public void registerQueueStatuses(List queueStatuses) throws RegistryException { + registryService.registerQueueStatuses(queueStatuses); + } +} + From 53a32847f5ad508d910bbf865ccc562c1718f1cd Mon Sep 17 00:00:00 2001 From: yasithdev Date: Mon, 10 Nov 2025 18:41:45 -0500 Subject: [PATCH 06/26] add missing function to computeresourcerepo --- .../appcatalog/ComputeResourceRepository.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/airavata-api/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/ComputeResourceRepository.java b/airavata-api/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/ComputeResourceRepository.java index a56cca9f4a..a75ce4488f 100644 --- a/airavata-api/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/ComputeResourceRepository.java +++ b/airavata-api/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/ComputeResourceRepository.java @@ -408,6 +408,16 @@ public String addUNICOREJobSubmission(UnicoreJobSubmission unicoreJobSubmission) return unicoreJobSubmission.getJobSubmissionInterfaceId(); } + public void updateUNICOREJobSubmission(UnicoreJobSubmission unicoreJobSubmission) throws AppCatalogException { + Mapper mapper = ObjectMapperSingleton.getInstance(); + UnicoreSubmissionEntity unicoreSubmissionEntity = + mapper.map(unicoreJobSubmission, UnicoreSubmissionEntity.class); + if (unicoreJobSubmission.getSecurityProtocol() != null) { + unicoreSubmissionEntity.setSecurityProtocol(unicoreJobSubmission.getSecurityProtocol()); + } + execute(entityManager -> entityManager.merge(unicoreSubmissionEntity)); + } + @Override public String addLocalDataMovement(LOCALDataMovement localDataMovement) throws AppCatalogException { localDataMovement.setDataMovementInterfaceId(AppCatalogUtils.getID("LOCAL")); From 1bd31be11a9d30f0d674c569b275f9ed1dd60d60 Mon Sep 17 00:00:00 2001 From: yasithdev Date: Mon, 10 Nov 2025 18:42:00 -0500 Subject: [PATCH 07/26] update groupmanagerserverhandler --- .../airavata/service/GroupManagerService.java | 397 ++++++++++++++++++ .../handlers/GroupManagerServiceHandler.java | 258 ++---------- 2 files changed, 441 insertions(+), 214 deletions(-) create mode 100644 airavata-api/src/main/java/org/apache/airavata/service/GroupManagerService.java diff --git a/airavata-api/src/main/java/org/apache/airavata/service/GroupManagerService.java b/airavata-api/src/main/java/org/apache/airavata/service/GroupManagerService.java new file mode 100644 index 0000000000..3da76eabc9 --- /dev/null +++ b/airavata-api/src/main/java/org/apache/airavata/service/GroupManagerService.java @@ -0,0 +1,397 @@ +/** +* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ +package org.apache.airavata.service; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.Constants; +import org.apache.airavata.common.utils.ServerSettings; +import org.apache.airavata.model.group.GroupModel; +import org.apache.airavata.model.security.AuthzToken; +import org.apache.airavata.model.user.UserProfile; +import org.apache.airavata.service.profile.groupmanager.cpi.exception.GroupManagerServiceException; +import org.apache.airavata.service.profile.user.core.repositories.UserProfileRepository; +import org.apache.airavata.sharing.registry.client.SharingRegistryServiceClientFactory; +import org.apache.airavata.sharing.registry.models.GroupCardinality; +import org.apache.airavata.sharing.registry.models.GroupType; +import org.apache.airavata.sharing.registry.models.SharingRegistryException; +import org.apache.airavata.sharing.registry.models.User; +import org.apache.airavata.sharing.registry.models.UserGroup; +import org.apache.airavata.sharing.registry.service.cpi.SharingRegistryService; +import org.apache.thrift.TException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class GroupManagerService { + private static final Logger logger = LoggerFactory.getLogger(GroupManagerService.class); + private UserProfileRepository userProfileRepository = new UserProfileRepository(); + + public String createGroup(AuthzToken authzToken, GroupModel groupModel) throws GroupManagerServiceException { + try { + // TODO Validations for authorization + SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); + + UserGroup sharingUserGroup = new UserGroup(); + sharingUserGroup.setGroupId(UUID.randomUUID().toString()); + sharingUserGroup.setName(groupModel.getName()); + sharingUserGroup.setDescription(groupModel.getDescription()); + sharingUserGroup.setGroupType(GroupType.USER_LEVEL_GROUP); + sharingUserGroup.setGroupCardinality(GroupCardinality.MULTI_USER); + String gatewayId = getDomainId(authzToken); + sharingUserGroup.setDomainId(gatewayId); + sharingUserGroup.setOwnerId(getUserId(authzToken)); + + String groupId = sharingClient.createGroup(sharingUserGroup); + internalAddUsersToGroup(sharingClient, gatewayId, groupModel.getMembers(), groupId); + if (groupModel.getAdmins() != null && !groupModel.getAdmins().isEmpty()) { + sharingClient.addGroupAdmins(gatewayId, groupId, groupModel.getAdmins()); + } + return groupId; + } catch (Exception e) { + String msg = "Error Creating Group"; + logger.error(msg, e); + GroupManagerServiceException exception = new GroupManagerServiceException(); + exception.setMessage(msg + " More info : " + e.getMessage()); + throw exception; + } + } + + public boolean updateGroup(AuthzToken authzToken, GroupModel groupModel) throws GroupManagerServiceException { + try { + SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); + String userId = getUserId(authzToken); + String domainId = getDomainId(authzToken); + if (!(sharingClient.hasOwnerAccess(domainId, groupModel.getId(), userId) + || sharingClient.hasAdminAccess(domainId, groupModel.getId(), userId))) { + throw new GroupManagerServiceException("User does not have permission to update group"); + } + + UserGroup sharingUserGroup = new UserGroup(); + sharingUserGroup.setGroupId(groupModel.getId()); + sharingUserGroup.setName(groupModel.getName()); + sharingUserGroup.setDescription(groupModel.getDescription()); + sharingUserGroup.setGroupType(GroupType.USER_LEVEL_GROUP); + sharingUserGroup.setDomainId(getDomainId(authzToken)); + + // adding and removal of users should be handle separately + sharingClient.updateGroup(sharingUserGroup); + return true; + } catch (Exception e) { + String msg = "Error Updating Group"; + logger.error(msg, e); + GroupManagerServiceException exception = new GroupManagerServiceException(); + exception.setMessage(msg + " More info : " + e.getMessage()); + throw exception; + } + } + + public boolean deleteGroup(AuthzToken authzToken, String groupId, String ownerId) throws GroupManagerServiceException { + try { + SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); + String userId = getUserId(authzToken); + String domainId = getDomainId(authzToken); + if (!(sharingClient.hasOwnerAccess(domainId, groupId, userId))) { + throw new GroupManagerServiceException("User does not have permission to delete group"); + } + + sharingClient.deleteGroup(getDomainId(authzToken), groupId); + return true; + } catch (Exception e) { + String msg = "Error Deleting Group. Group ID: " + groupId; + logger.error(msg, e); + GroupManagerServiceException exception = new GroupManagerServiceException(); + exception.setMessage(msg + " More info : " + e.getMessage()); + throw exception; + } + } + + public GroupModel getGroup(AuthzToken authzToken, String groupId) throws GroupManagerServiceException { + try { + SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); + final String domainId = getDomainId(authzToken); + UserGroup userGroup = sharingClient.getGroup(domainId, groupId); + + GroupModel groupModel = convertToGroupModel(userGroup, sharingClient); + + return groupModel; + } catch (Exception e) { + String msg = "Error Retreiving Group. Group ID: " + groupId; + logger.error(msg, e); + GroupManagerServiceException exception = new GroupManagerServiceException(); + exception.setMessage(msg + " More info : " + e.getMessage()); + throw exception; + } + } + + public List getGroups(AuthzToken authzToken) throws GroupManagerServiceException { + final String domainId = getDomainId(authzToken); + SharingRegistryService.Client sharingClient = null; + try { + sharingClient = getSharingRegistryServiceClient(); + List userGroups = sharingClient.getGroups(domainId, 0, -1); + + return convertToGroupModels(userGroups, sharingClient); + } catch (Exception e) { + String msg = "Error Retrieving Groups. Domain ID: " + domainId; + logger.error(msg, e); + GroupManagerServiceException exception = new GroupManagerServiceException(); + exception.setMessage(msg + " More info : " + e.getMessage()); + throw exception; + } finally { + closeSharingClient(sharingClient); + } + } + + public List getAllGroupsUserBelongs(AuthzToken authzToken, String userName) + throws GroupManagerServiceException { + try { + SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); + List groupModels = new ArrayList(); + final String domainId = getDomainId(authzToken); + List userGroups = sharingClient.getAllMemberGroupsForUser(domainId, userName); + + return convertToGroupModels(userGroups, sharingClient); + } catch (Exception e) { + String msg = "Error Retreiving All Groups for User. User ID: " + userName; + logger.error(msg, e); + GroupManagerServiceException exception = new GroupManagerServiceException(); + exception.setMessage(msg + " More info : " + e.getMessage()); + throw exception; + } + } + + public boolean addUsersToGroup(AuthzToken authzToken, List userIds, String groupId) + throws GroupManagerServiceException { + try { + SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); + String userId = getUserId(authzToken); + String domainId = getDomainId(authzToken); + if (!(sharingClient.hasOwnerAccess(domainId, groupId, userId) + || sharingClient.hasAdminAccess(domainId, groupId, userId))) { + throw new GroupManagerServiceException("User does not have access to add users to the group"); + } + return internalAddUsersToGroup(sharingClient, domainId, userIds, groupId); + + } catch (Exception e) { + String msg = "Error adding users to group. Group ID: " + groupId; + logger.error(msg, e); + GroupManagerServiceException exception = new GroupManagerServiceException(); + exception.setMessage(msg + " More info : " + e.getMessage()); + throw exception; + } + } + + public boolean removeUsersFromGroup(AuthzToken authzToken, List userIds, String groupId) + throws GroupManagerServiceException { + try { + SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); + String userId = getUserId(authzToken); + String domainId = getDomainId(authzToken); + if (!(sharingClient.hasOwnerAccess(domainId, groupId, userId) + || sharingClient.hasAdminAccess(domainId, groupId, userId))) { + throw new GroupManagerServiceException("User does not have access to remove users to the group"); + } + return sharingClient.removeUsersFromGroup(domainId, userIds, groupId); + } catch (Exception e) { + String msg = "Error remove users to group. Group ID: " + groupId; + logger.error(msg, e); + GroupManagerServiceException exception = new GroupManagerServiceException(); + exception.setMessage(msg + " More info : " + e.getMessage()); + throw exception; + } + } + + public boolean transferGroupOwnership(AuthzToken authzToken, String groupId, String newOwnerId) + throws GroupManagerServiceException { + try { + SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); + String userId = getUserId(authzToken); + String domainId = getDomainId(authzToken); + if (!(sharingClient.hasOwnerAccess(domainId, groupId, userId))) { + throw new GroupManagerServiceException( + "User does not have Owner permission to transfer group ownership"); + } + return sharingClient.transferGroupOwnership(getDomainId(authzToken), groupId, newOwnerId); + } catch (Exception e) { + String msg = "Error Transferring Group Ownership"; + logger.error(msg, e); + GroupManagerServiceException exception = new GroupManagerServiceException(); + exception.setMessage(msg + " More info : " + e.getMessage()); + throw exception; + } + } + + public boolean addGroupAdmins(AuthzToken authzToken, String groupId, List adminIds) + throws GroupManagerServiceException { + try { + SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); + String userId = getUserId(authzToken); + String domainId = getDomainId(authzToken); + if (!(sharingClient.hasOwnerAccess(domainId, groupId, userId))) { + throw new GroupManagerServiceException("User does not have Owner permission to add group admins"); + } + return sharingClient.addGroupAdmins(getDomainId(authzToken), groupId, adminIds); + } catch (Exception e) { + String msg = "Error Adding Admins to Group. Group ID: " + groupId; + logger.error(msg, e); + GroupManagerServiceException exception = new GroupManagerServiceException(); + exception.setMessage(msg + " More info : " + e.getMessage()); + throw exception; + } + } + + public boolean removeGroupAdmins(AuthzToken authzToken, String groupId, List adminIds) + throws GroupManagerServiceException { + try { + SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); + String userId = getUserId(authzToken); + String domainId = getDomainId(authzToken); + if (!(sharingClient.hasOwnerAccess(domainId, groupId, userId))) { + throw new GroupManagerServiceException("User does not have Owner permission to remove group admins"); + } + return sharingClient.removeGroupAdmins(getDomainId(authzToken), groupId, adminIds); + } catch (Exception e) { + String msg = "Error Removing Admins from the Group. Group ID: " + groupId; + logger.error(msg, e); + GroupManagerServiceException exception = new GroupManagerServiceException(); + exception.setMessage(msg + " More info : " + e.getMessage()); + throw exception; + } + } + + public boolean hasAdminAccess(AuthzToken authzToken, String groupId, String adminId) + throws GroupManagerServiceException { + try { + SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); + return sharingClient.hasAdminAccess(getDomainId(authzToken), groupId, adminId); + } catch (Exception e) { + String msg = "Error Checking Admin Access for the Group. Group ID: " + groupId + " Admin ID: " + adminId; + logger.error(msg, e); + GroupManagerServiceException exception = new GroupManagerServiceException(); + exception.setMessage(msg + " More info : " + e.getMessage()); + throw exception; + } + } + + public boolean hasOwnerAccess(AuthzToken authzToken, String groupId, String ownerId) + throws GroupManagerServiceException { + try { + SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); + return sharingClient.hasOwnerAccess(getDomainId(authzToken), groupId, ownerId); + } catch (Exception e) { + String msg = "Error Checking Owner Access for the Group. Group ID: " + groupId + " Owner ID: " + ownerId; + logger.error(msg, e); + GroupManagerServiceException exception = new GroupManagerServiceException(); + exception.setMessage(msg + " More info : " + e.getMessage()); + throw exception; + } + } + + // TODO: replace these methods with ThriftClientPool (see AIRAVATA-2607) + private SharingRegistryService.Client getSharingRegistryServiceClient() + throws TException, ApplicationSettingsException { + final int serverPort = Integer.parseInt(ServerSettings.getSharingRegistryPort()); + final String serverHost = ServerSettings.getSharingRegistryHost(); + try { + return SharingRegistryServiceClientFactory.createSharingRegistryClient(serverHost, serverPort); + } catch (SharingRegistryException e) { + throw new TException("Unable to create sharing registry client...", e); + } + } + + private String getDomainId(AuthzToken authzToken) { + return authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + } + + private String getUserId(AuthzToken authzToken) { + return authzToken.getClaimsMap().get(Constants.USER_NAME) + "@" + getDomainId(authzToken); + } + + private List convertToGroupModels( + List userGroups, SharingRegistryService.Client sharingClient) throws TException { + + List groupModels = new ArrayList<>(); + + for (UserGroup userGroup : userGroups) { + GroupModel groupModel = convertToGroupModel(userGroup, sharingClient); + + groupModels.add(groupModel); + } + return groupModels; + } + + private GroupModel convertToGroupModel(UserGroup userGroup, SharingRegistryService.Client sharingClient) + throws TException { + GroupModel groupModel = new GroupModel(); + groupModel.setId(userGroup.getGroupId()); + groupModel.setName(userGroup.getName()); + groupModel.setDescription(userGroup.getDescription()); + groupModel.setOwnerId(userGroup.getOwnerId()); + final List admins = userGroup.getGroupAdmins().stream() + .map(groupAdmin -> groupAdmin.getAdminId()) + .collect(Collectors.toList()); + groupModel.setAdmins(admins); + + sharingClient.getGroupMembersOfTypeUser(userGroup.getDomainId(), userGroup.getGroupId(), 0, -1).stream() + .forEach(user -> groupModel.addToMembers(user.getUserId())); + return groupModel; + } + + private void closeSharingClient(SharingRegistryService.Client sharingClient) { + if (sharingClient != null) { + if (sharingClient.getInputProtocol().getTransport().isOpen()) { + sharingClient.getInputProtocol().getTransport().close(); + } + if (sharingClient.getOutputProtocol().getTransport().isOpen()) { + sharingClient.getOutputProtocol().getTransport().close(); + } + } + } + + private boolean internalAddUsersToGroup( + SharingRegistryService.Client sharingClient, String domainId, List userIds, String groupId) + throws SharingRegistryException, TException { + + // FIXME: workaround for UserProfiles that failed to sync to the sharing + // registry: create any missing users in the sharing registry + for (String userId : userIds) { + if (!sharingClient.isUserExists(domainId, userId)) { + User user = new User(); + user.setDomainId(domainId); + user.setUserId(userId); + UserProfile userProfile = userProfileRepository.get(userId); + user.setUserName(userProfile.getUserId()); + user.setCreatedTime(userProfile.getCreationTime()); + user.setEmail( + userProfile.getEmailsSize() > 0 + ? userProfile.getEmails().get(0) + : null); + user.setFirstName(userProfile.getFirstName()); + user.setLastName(userProfile.getLastName()); + sharingClient.createUser(user); + } + } + return sharingClient.addUsersToGroup(domainId, userIds, groupId); + } +} + diff --git a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/GroupManagerServiceHandler.java b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/GroupManagerServiceHandler.java index 9b445aa11b..a983205e41 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/GroupManagerServiceHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/GroupManagerServiceHandler.java @@ -19,29 +19,14 @@ */ package org.apache.airavata.service.profile.handlers; -import java.util.ArrayList; import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; -import org.apache.airavata.common.exception.ApplicationSettingsException; -import org.apache.airavata.common.utils.Constants; -import org.apache.airavata.common.utils.ServerSettings; import org.apache.airavata.model.error.AuthorizationException; import org.apache.airavata.model.group.GroupModel; import org.apache.airavata.model.security.AuthzToken; -import org.apache.airavata.model.user.UserProfile; import org.apache.airavata.service.profile.groupmanager.cpi.GroupManagerService; import org.apache.airavata.service.profile.groupmanager.cpi.exception.GroupManagerServiceException; import org.apache.airavata.service.profile.groupmanager.cpi.group_manager_cpiConstants; -import org.apache.airavata.service.profile.user.core.repositories.UserProfileRepository; import org.apache.airavata.service.security.interceptor.SecurityCheck; -import org.apache.airavata.sharing.registry.client.SharingRegistryServiceClientFactory; -import org.apache.airavata.sharing.registry.models.GroupCardinality; -import org.apache.airavata.sharing.registry.models.GroupType; -import org.apache.airavata.sharing.registry.models.SharingRegistryException; -import org.apache.airavata.sharing.registry.models.User; -import org.apache.airavata.sharing.registry.models.UserGroup; -import org.apache.airavata.sharing.registry.service.cpi.SharingRegistryService; import org.apache.thrift.TException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,10 +34,11 @@ public class GroupManagerServiceHandler implements GroupManagerService.Iface { private static final Logger logger = LoggerFactory.getLogger(GroupManagerServiceHandler.class); + private org.apache.airavata.service.GroupManagerService groupManagerService; - private UserProfileRepository userProfileRepository = new UserProfileRepository(); - - public GroupManagerServiceHandler() {} + public GroupManagerServiceHandler() { + groupManagerService = new org.apache.airavata.service.GroupManagerService(); + } @Override public String getAPIVersion() throws TException { @@ -64,23 +50,9 @@ public String getAPIVersion() throws TException { public String createGroup(AuthzToken authzToken, GroupModel groupModel) throws GroupManagerServiceException, AuthorizationException, TException { try { - // TODO Validations for authorization - SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); - - UserGroup sharingUserGroup = new UserGroup(); - sharingUserGroup.setGroupId(UUID.randomUUID().toString()); - sharingUserGroup.setName(groupModel.getName()); - sharingUserGroup.setDescription(groupModel.getDescription()); - sharingUserGroup.setGroupType(GroupType.USER_LEVEL_GROUP); - sharingUserGroup.setGroupCardinality(GroupCardinality.MULTI_USER); - String gatewayId = getDomainId(authzToken); - sharingUserGroup.setDomainId(gatewayId); - sharingUserGroup.setOwnerId(getUserId(authzToken)); - - String groupId = sharingClient.createGroup(sharingUserGroup); - internalAddUsersToGroup(sharingClient, gatewayId, groupModel.getMembers(), groupId); - addGroupAdmins(authzToken, groupId, groupModel.getAdmins()); - return groupId; + return groupManagerService.createGroup(authzToken, groupModel); + } catch (GroupManagerServiceException e) { + throw e; } catch (Exception e) { String msg = "Error Creating Group"; logger.error(msg, e); @@ -95,24 +67,9 @@ public String createGroup(AuthzToken authzToken, GroupModel groupModel) public boolean updateGroup(AuthzToken authzToken, GroupModel groupModel) throws GroupManagerServiceException, AuthorizationException, TException { try { - SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); - String userId = getUserId(authzToken); - String domainId = getDomainId(authzToken); - if (!(sharingClient.hasOwnerAccess(domainId, groupModel.getId(), userId) - || sharingClient.hasAdminAccess(domainId, groupModel.getId(), userId))) { - throw new GroupManagerServiceException("User does not have permission to update group"); - } - - UserGroup sharingUserGroup = new UserGroup(); - sharingUserGroup.setGroupId(groupModel.getId()); - sharingUserGroup.setName(groupModel.getName()); - sharingUserGroup.setDescription(groupModel.getDescription()); - sharingUserGroup.setGroupType(GroupType.USER_LEVEL_GROUP); - sharingUserGroup.setDomainId(getDomainId(authzToken)); - - // adding and removal of users should be handle separately - sharingClient.updateGroup(sharingUserGroup); - return true; + return groupManagerService.updateGroup(authzToken, groupModel); + } catch (GroupManagerServiceException e) { + throw e; } catch (Exception e) { String msg = "Error Updating Group"; logger.error(msg, e); @@ -127,15 +84,9 @@ public boolean updateGroup(AuthzToken authzToken, GroupModel groupModel) public boolean deleteGroup(AuthzToken authzToken, String groupId, String ownerId) throws GroupManagerServiceException, AuthorizationException, TException { try { - SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); - String userId = getUserId(authzToken); - String domainId = getDomainId(authzToken); - if (!(sharingClient.hasOwnerAccess(domainId, groupId, userId))) { - throw new GroupManagerServiceException("User does not have permission to delete group"); - } - - sharingClient.deleteGroup(getDomainId(authzToken), groupId); - return true; + return groupManagerService.deleteGroup(authzToken, groupId, ownerId); + } catch (GroupManagerServiceException e) { + throw e; } catch (Exception e) { String msg = "Error Deleting Group. Group ID: " + groupId; logger.error(msg, e); @@ -150,13 +101,9 @@ public boolean deleteGroup(AuthzToken authzToken, String groupId, String ownerId public GroupModel getGroup(AuthzToken authzToken, String groupId) throws GroupManagerServiceException, AuthorizationException, TException { try { - SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); - final String domainId = getDomainId(authzToken); - UserGroup userGroup = sharingClient.getGroup(domainId, groupId); - - GroupModel groupModel = convertToGroupModel(userGroup, sharingClient); - - return groupModel; + return groupManagerService.getGroup(authzToken, groupId); + } catch (GroupManagerServiceException e) { + throw e; } catch (Exception e) { String msg = "Error Retreiving Group. Group ID: " + groupId; logger.error(msg, e); @@ -170,21 +117,16 @@ public GroupModel getGroup(AuthzToken authzToken, String groupId) @SecurityCheck public List getGroups(AuthzToken authzToken) throws GroupManagerServiceException, AuthorizationException, TException { - final String domainId = getDomainId(authzToken); - SharingRegistryService.Client sharingClient = null; try { - sharingClient = getSharingRegistryServiceClient(); - List userGroups = sharingClient.getGroups(domainId, 0, -1); - - return convertToGroupModels(userGroups, sharingClient); + return groupManagerService.getGroups(authzToken); + } catch (GroupManagerServiceException e) { + throw e; } catch (Exception e) { - String msg = "Error Retrieving Groups. Domain ID: " + domainId; + String msg = "Error Retrieving Groups"; logger.error(msg, e); GroupManagerServiceException exception = new GroupManagerServiceException(); exception.setMessage(msg + " More info : " + e.getMessage()); throw exception; - } finally { - closeSharingClient(sharingClient); } } @@ -193,12 +135,9 @@ public List getGroups(AuthzToken authzToken) public List getAllGroupsUserBelongs(AuthzToken authzToken, String userName) throws GroupManagerServiceException, AuthorizationException, TException { try { - SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); - List groupModels = new ArrayList(); - final String domainId = getDomainId(authzToken); - List userGroups = sharingClient.getAllMemberGroupsForUser(domainId, userName); - - return convertToGroupModels(userGroups, sharingClient); + return groupManagerService.getAllGroupsUserBelongs(authzToken, userName); + } catch (GroupManagerServiceException e) { + throw e; } catch (Exception e) { String msg = "Error Retreiving All Groups for User. User ID: " + userName; logger.error(msg, e); @@ -212,15 +151,9 @@ public List getAllGroupsUserBelongs(AuthzToken authzToken, String us public boolean addUsersToGroup(AuthzToken authzToken, List userIds, String groupId) throws GroupManagerServiceException, AuthorizationException, TException { try { - SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); - String userId = getUserId(authzToken); - String domainId = getDomainId(authzToken); - if (!(sharingClient.hasOwnerAccess(domainId, groupId, userId) - || sharingClient.hasAdminAccess(domainId, groupId, userId))) { - throw new GroupManagerServiceException("User does not have access to add users to the group"); - } - return internalAddUsersToGroup(sharingClient, domainId, userIds, groupId); - + return groupManagerService.addUsersToGroup(authzToken, userIds, groupId); + } catch (GroupManagerServiceException e) { + throw e; } catch (Exception e) { String msg = "Error adding users to group. Group ID: " + groupId; logger.error(msg, e); @@ -234,14 +167,9 @@ public boolean addUsersToGroup(AuthzToken authzToken, List userIds, Stri public boolean removeUsersFromGroup(AuthzToken authzToken, List userIds, String groupId) throws GroupManagerServiceException, AuthorizationException, TException { try { - SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); - String userId = getUserId(authzToken); - String domainId = getDomainId(authzToken); - if (!(sharingClient.hasOwnerAccess(domainId, groupId, userId) - || sharingClient.hasAdminAccess(domainId, groupId, userId))) { - throw new GroupManagerServiceException("User does not have access to remove users to the group"); - } - return sharingClient.removeUsersFromGroup(domainId, userIds, groupId); + return groupManagerService.removeUsersFromGroup(authzToken, userIds, groupId); + } catch (GroupManagerServiceException e) { + throw e; } catch (Exception e) { String msg = "Error remove users to group. Group ID: " + groupId; logger.error(msg, e); @@ -256,14 +184,9 @@ public boolean removeUsersFromGroup(AuthzToken authzToken, List userIds, public boolean transferGroupOwnership(AuthzToken authzToken, String groupId, String newOwnerId) throws GroupManagerServiceException, AuthorizationException, TException { try { - SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); - String userId = getUserId(authzToken); - String domainId = getDomainId(authzToken); - if (!(sharingClient.hasOwnerAccess(domainId, groupId, userId))) { - throw new GroupManagerServiceException( - "User does not have Owner permission to transfer group ownership"); - } - return sharingClient.transferGroupOwnership(getDomainId(authzToken), groupId, newOwnerId); + return groupManagerService.transferGroupOwnership(authzToken, groupId, newOwnerId); + } catch (GroupManagerServiceException e) { + throw e; } catch (Exception e) { String msg = "Error Transferring Group Ownership"; logger.error(msg, e); @@ -278,13 +201,9 @@ public boolean transferGroupOwnership(AuthzToken authzToken, String groupId, Str public boolean addGroupAdmins(AuthzToken authzToken, String groupId, List adminIds) throws GroupManagerServiceException, AuthorizationException, TException { try { - SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); - String userId = getUserId(authzToken); - String domainId = getDomainId(authzToken); - if (!(sharingClient.hasOwnerAccess(domainId, groupId, userId))) { - throw new GroupManagerServiceException("User does not have Owner permission to add group admins"); - } - return sharingClient.addGroupAdmins(getDomainId(authzToken), groupId, adminIds); + return groupManagerService.addGroupAdmins(authzToken, groupId, adminIds); + } catch (GroupManagerServiceException e) { + throw e; } catch (Exception e) { String msg = "Error Adding Admins to Group. Group ID: " + groupId; logger.error(msg, e); @@ -299,13 +218,9 @@ public boolean addGroupAdmins(AuthzToken authzToken, String groupId, List adminIds) throws GroupManagerServiceException, AuthorizationException, TException { try { - SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); - String userId = getUserId(authzToken); - String domainId = getDomainId(authzToken); - if (!(sharingClient.hasOwnerAccess(domainId, groupId, userId))) { - throw new GroupManagerServiceException("User does not have Owner permission to remove group admins"); - } - return sharingClient.removeGroupAdmins(getDomainId(authzToken), groupId, adminIds); + return groupManagerService.removeGroupAdmins(authzToken, groupId, adminIds); + } catch (GroupManagerServiceException e) { + throw e; } catch (Exception e) { String msg = "Error Removing Admins from the Group. Group ID: " + groupId; logger.error(msg, e); @@ -320,8 +235,9 @@ public boolean removeGroupAdmins(AuthzToken authzToken, String groupId, List convertToGroupModels( - List userGroups, SharingRegistryService.Client sharingClient) throws TException { - - List groupModels = new ArrayList<>(); - - for (UserGroup userGroup : userGroups) { - GroupModel groupModel = convertToGroupModel(userGroup, sharingClient); - - groupModels.add(groupModel); - } - return groupModels; - } - - private GroupModel convertToGroupModel(UserGroup userGroup, SharingRegistryService.Client sharingClient) - throws TException { - GroupModel groupModel = new GroupModel(); - groupModel.setId(userGroup.getGroupId()); - groupModel.setName(userGroup.getName()); - groupModel.setDescription(userGroup.getDescription()); - groupModel.setOwnerId(userGroup.getOwnerId()); - final List admins = userGroup.getGroupAdmins().stream() - .map(groupAdmin -> groupAdmin.getAdminId()) - .collect(Collectors.toList()); - groupModel.setAdmins(admins); - - sharingClient.getGroupMembersOfTypeUser(userGroup.getDomainId(), userGroup.getGroupId(), 0, -1).stream() - .forEach(user -> groupModel.addToMembers(user.getUserId())); - return groupModel; - } - - private void closeSharingClient(SharingRegistryService.Client sharingClient) { - if (sharingClient != null) { - if (sharingClient.getInputProtocol().getTransport().isOpen()) { - sharingClient.getInputProtocol().getTransport().close(); - } - if (sharingClient.getOutputProtocol().getTransport().isOpen()) { - sharingClient.getOutputProtocol().getTransport().close(); - } - } - } - - private boolean internalAddUsersToGroup( - SharingRegistryService.Client sharingClient, String domainId, List userIds, String groupId) - throws SharingRegistryException, TException { - - // FIXME: workaround for UserProfiles that failed to sync to the sharing - // registry: create any missing users in the sharing registry - for (String userId : userIds) { - if (!sharingClient.isUserExists(domainId, userId)) { - User user = new User(); - user.setDomainId(domainId); - user.setUserId(userId); - UserProfile userProfile = userProfileRepository.get(userId); - user.setUserName(userProfile.getUserId()); - user.setCreatedTime(userProfile.getCreationTime()); - user.setEmail( - userProfile.getEmailsSize() > 0 - ? userProfile.getEmails().get(0) - : null); - user.setFirstName(userProfile.getFirstName()); - user.setLastName(userProfile.getLastName()); - sharingClient.createUser(user); - } - } - return sharingClient.addUsersToGroup(domainId, userIds, groupId); - } } From 75896eac9667786b6d126251b8d27d30663ab0be Mon Sep 17 00:00:00 2001 From: yasithdev Date: Mon, 10 Nov 2025 18:42:14 -0500 Subject: [PATCH 08/26] update iamadminserviceshandler --- .../airavata/service/IamAdminService.java | 312 ++++++++++++++++++ .../handlers/IamAdminServicesHandler.java | 236 +++++-------- 2 files changed, 387 insertions(+), 161 deletions(-) create mode 100644 airavata-api/src/main/java/org/apache/airavata/service/IamAdminService.java diff --git a/airavata-api/src/main/java/org/apache/airavata/service/IamAdminService.java b/airavata-api/src/main/java/org/apache/airavata/service/IamAdminService.java new file mode 100644 index 0000000000..5a9ffd6d69 --- /dev/null +++ b/airavata-api/src/main/java/org/apache/airavata/service/IamAdminService.java @@ -0,0 +1,312 @@ +/** +* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ +package org.apache.airavata.service; + +import java.util.List; +import org.apache.airavata.common.exception.AiravataException; +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.AiravataUtils; +import org.apache.airavata.common.utils.Constants; +import org.apache.airavata.common.utils.DBEventService; +import org.apache.airavata.common.utils.ServerSettings; +import org.apache.airavata.credential.store.client.CredentialStoreClientFactory; +import org.apache.airavata.credential.store.cpi.CredentialStoreService; +import org.apache.airavata.credential.store.exception.CredentialStoreException; +import org.apache.airavata.messaging.core.util.DBEventPublisherUtils; +import org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile; +import org.apache.airavata.model.credential.store.PasswordCredential; +import org.apache.airavata.model.dbevent.CrudType; +import org.apache.airavata.model.dbevent.EntityType; +import org.apache.airavata.model.security.AuthzToken; +import org.apache.airavata.model.user.UserProfile; +import org.apache.airavata.model.workspace.Gateway; +import org.apache.airavata.registry.api.RegistryService; +import org.apache.airavata.registry.api.client.RegistryServiceClientFactory; +import org.apache.airavata.registry.api.exception.RegistryServiceException; +import org.apache.airavata.service.profile.iam.admin.services.core.impl.TenantManagementKeycloakImpl; +import org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException; +import org.apache.airavata.service.profile.user.core.repositories.UserProfileRepository; +import org.apache.thrift.TException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class IamAdminService { + private static final Logger logger = LoggerFactory.getLogger(IamAdminService.class); + private UserProfileRepository userProfileRepository = new UserProfileRepository(); + private DBEventPublisherUtils dbEventPublisherUtils = new DBEventPublisherUtils(DBEventService.IAM_ADMIN); + + public Gateway setUpGateway(AuthzToken authzToken, Gateway gateway) throws IamAdminServicesException { + TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl(); + PasswordCredential isSuperAdminCredentials = getSuperAdminPasswordCredential(); + try { + keycloakclient.addTenant(isSuperAdminCredentials, gateway); + + // Load the tenant admin password stored in gateway request + CredentialStoreService.Client credentialStoreClient = getCredentialStoreServiceClient(); + // Admin password token should already be stored under requested gateway's gatewayId + PasswordCredential tenantAdminPasswordCredential = credentialStoreClient.getPasswordCredential( + gateway.getIdentityServerPasswordToken(), gateway.getGatewayId()); + + if (!keycloakclient.createTenantAdminAccount( + isSuperAdminCredentials, gateway, tenantAdminPasswordCredential.getPassword())) { + logger.error("Admin account creation failed !!, please refer error logs for reason"); + } + Gateway gatewayWithIdAndSecret = keycloakclient.configureClient(isSuperAdminCredentials, gateway); + return gatewayWithIdAndSecret; + } catch (TException | ApplicationSettingsException ex) { + logger.error("Gateway Setup Failed, reason: " + ex.getMessage(), ex); + IamAdminServicesException iamAdminServicesException = new IamAdminServicesException(ex.getMessage()); + throw iamAdminServicesException; + } + } + + public boolean isUsernameAvailable(AuthzToken authzToken, String username) throws IamAdminServicesException { + TenantManagementKeycloakImpl keycloakClient = new TenantManagementKeycloakImpl(); + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + return keycloakClient.isUsernameAvailable(authzToken.getAccessToken(), gatewayId, username); + } + + public boolean registerUser( + AuthzToken authzToken, + String username, + String emailAddress, + String firstName, + String lastName, + String newPassword) + throws IamAdminServicesException { + TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl(); + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + try { + if (keycloakclient.createUser( + authzToken.getAccessToken(), gatewayId, username, emailAddress, firstName, lastName, newPassword)) + return true; + else return false; + } catch (TException ex) { + String msg = "Error while registering user into Identity Server, reason: " + ex.getMessage(); + logger.error(msg, ex); + throw new IamAdminServicesException(msg); + } + } + + public boolean enableUser(AuthzToken authzToken, String username) throws IamAdminServicesException { + TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl(); + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + try { + if (keycloakclient.enableUserAccount(authzToken.getAccessToken(), gatewayId, username)) { + // Check if user profile exists, if not create it + boolean userProfileExists = + userProfileRepository.getUserProfileByIdAndGateWay(username, gatewayId) != null; + if (!userProfileExists) { + // Load basic user profile information from Keycloak and then save in UserProfileRepository + UserProfile userProfile = keycloakclient.getUser(authzToken.getAccessToken(), gatewayId, username); + userProfile.setCreationTime( + AiravataUtils.getCurrentTimestamp().getTime()); + userProfile.setLastAccessTime( + AiravataUtils.getCurrentTimestamp().getTime()); + userProfile.setValidUntil(-1); + userProfileRepository.createUserProfile(userProfile); + // Dispatch IAM_ADMIN service event for a new USER_PROFILE + dbEventPublisherUtils.publish(EntityType.USER_PROFILE, CrudType.CREATE, userProfile); + } + return true; + } else { + return false; + } + } catch (TException | AiravataException ex) { + String msg = "Error while enabling user account, reason: " + ex.getMessage(); + logger.error(msg, ex); + throw new IamAdminServicesException(msg); + } + } + + public boolean isUserEnabled(AuthzToken authzToken, String username) throws IamAdminServicesException { + TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl(); + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + try { + return keycloakclient.isUserAccountEnabled(authzToken.getAccessToken(), gatewayId, username); + } catch (Exception ex) { + String msg = "Error while checking if user account is enabled, reason: " + ex.getMessage(); + logger.error(msg, ex); + throw new IamAdminServicesException(msg); + } + } + + public boolean isUserExist(AuthzToken authzToken, String username) throws IamAdminServicesException { + TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl(); + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + try { + return keycloakclient.isUserExist(authzToken.getAccessToken(), gatewayId, username); + } catch (Exception ex) { + String msg = "Error while checking if user account exists, reason: " + ex.getMessage(); + logger.error(msg, ex); + throw new IamAdminServicesException(msg); + } + } + + public UserProfile getUser(AuthzToken authzToken, String username) throws IamAdminServicesException { + TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl(); + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + try { + return keycloakclient.getUser(authzToken.getAccessToken(), gatewayId, username); + } catch (Exception ex) { + String msg = "Error while retrieving user profile from IAM backend, reason: " + ex.getMessage(); + logger.error(msg, ex); + throw new IamAdminServicesException(msg); + } + } + + public List getUsers(AuthzToken authzToken, int offset, int limit, String search) + throws IamAdminServicesException { + TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl(); + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + try { + return keycloakclient.getUsers(authzToken.getAccessToken(), gatewayId, offset, limit, search); + } catch (Exception ex) { + String msg = "Error while retrieving user profile from IAM backend, reason: " + ex.getMessage(); + logger.error(msg, ex); + throw new IamAdminServicesException(msg); + } + } + + public boolean resetUserPassword(AuthzToken authzToken, String username, String newPassword) + throws IamAdminServicesException { + TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl(); + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + try { + if (keycloakclient.resetUserPassword(authzToken.getAccessToken(), gatewayId, username, newPassword)) + return true; + else return false; + } catch (TException ex) { + String msg = "Error while resetting user password in Identity Server, reason: " + ex.getMessage(); + logger.error(msg, ex); + throw new IamAdminServicesException(msg); + } + } + + public List findUsers(AuthzToken authzToken, String email, String userId) + throws IamAdminServicesException { + TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl(); + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + try { + return keycloakclient.findUser(authzToken.getAccessToken(), gatewayId, email, userId); + } catch (TException ex) { + String msg = "Error while retrieving users from Identity Server, reason: " + ex.getMessage(); + logger.error(msg, ex); + throw new IamAdminServicesException(msg); + } + } + + public void updateUserProfile(AuthzToken authzToken, UserProfile userDetails) throws IamAdminServicesException { + TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl(); + String username = userDetails.getUserId(); + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + keycloakclient.updateUserProfile(authzToken.getAccessToken(), gatewayId, username, userDetails); + } + + public boolean deleteUser(AuthzToken authzToken, String username) throws IamAdminServicesException { + TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl(); + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + return keycloakclient.deleteUser(authzToken.getAccessToken(), gatewayId, username); + } + + public boolean addRoleToUser(AuthzToken authzToken, String username, String roleName) + throws IamAdminServicesException { + TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl(); + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + try { + PasswordCredential isRealmAdminCredentials = getTenantAdminPasswordCredential(gatewayId); + return keycloakclient.addRoleToUser(isRealmAdminCredentials, gatewayId, username, roleName); + } catch (TException | ApplicationSettingsException ex) { + String msg = "Error while adding role to user, reason: " + ex.getMessage(); + logger.error(msg, ex); + throw new IamAdminServicesException(msg); + } + } + + public boolean removeRoleFromUser(AuthzToken authzToken, String username, String roleName) + throws IamAdminServicesException { + TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl(); + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + try { + PasswordCredential isRealmAdminCredentials = getTenantAdminPasswordCredential(gatewayId); + return keycloakclient.removeRoleFromUser(isRealmAdminCredentials, gatewayId, username, roleName); + } catch (TException | ApplicationSettingsException ex) { + String msg = "Error while removing role from user, reason: " + ex.getMessage(); + logger.error(msg, ex); + throw new IamAdminServicesException(msg); + } + } + + public List getUsersWithRole(AuthzToken authzToken, String roleName) + throws IamAdminServicesException { + TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl(); + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + try { + PasswordCredential isRealmAdminCredentials = getTenantAdminPasswordCredential(gatewayId); + return keycloakclient.getUsersWithRole(isRealmAdminCredentials, gatewayId, roleName); + } catch (Exception ex) { + String msg = "Error while retrieving users with role, reason: " + ex.getMessage(); + logger.error(msg, ex); + throw new IamAdminServicesException(msg); + } + } + + private PasswordCredential getSuperAdminPasswordCredential() { + PasswordCredential isSuperAdminCredentials = new PasswordCredential(); + try { + isSuperAdminCredentials.setLoginUserName(ServerSettings.getIamServerSuperAdminUsername()); + isSuperAdminCredentials.setPassword(ServerSettings.getIamServerSuperAdminPassword()); + } catch (ApplicationSettingsException e) { + throw new RuntimeException("Unable to get settings for IAM super admin username/password", e); + } + return isSuperAdminCredentials; + } + + private PasswordCredential getTenantAdminPasswordCredential(String tenantId) + throws TException, ApplicationSettingsException { + + GatewayResourceProfile gwrp = getRegistryServiceClient().getGatewayResourceProfile(tenantId); + + CredentialStoreService.Client csClient = getCredentialStoreServiceClient(); + return csClient.getPasswordCredential(gwrp.getIdentityServerPwdCredToken(), gwrp.getGatewayID()); + } + + private RegistryService.Client getRegistryServiceClient() throws TException, ApplicationSettingsException { + final int serverPort = Integer.parseInt(ServerSettings.getRegistryServerPort()); + final String serverHost = ServerSettings.getRegistryServerHost(); + try { + return RegistryServiceClientFactory.createRegistryClient(serverHost, serverPort); + } catch (RegistryServiceException e) { + throw new TException("Unable to create registry client...", e); + } + } + + private CredentialStoreService.Client getCredentialStoreServiceClient() + throws TException, ApplicationSettingsException { + final int serverPort = Integer.parseInt(ServerSettings.getCredentialStoreServerPort()); + final String serverHost = ServerSettings.getCredentialStoreServerHost(); + try { + return CredentialStoreClientFactory.createAiravataCSClient(serverHost, serverPort); + } catch (CredentialStoreException e) { + throw new TException("Unable to create credential store client...", e); + } + } +} + diff --git a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/IamAdminServicesHandler.java b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/IamAdminServicesHandler.java index 2da10e50fe..ca72627f70 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/IamAdminServicesHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/IamAdminServicesHandler.java @@ -20,32 +20,13 @@ package org.apache.airavata.service.profile.handlers; import java.util.List; -import org.apache.airavata.common.exception.AiravataException; -import org.apache.airavata.common.exception.ApplicationSettingsException; -import org.apache.airavata.common.utils.AiravataUtils; -import org.apache.airavata.common.utils.Constants; -import org.apache.airavata.common.utils.DBEventService; -import org.apache.airavata.common.utils.ServerSettings; -import org.apache.airavata.credential.store.client.CredentialStoreClientFactory; -import org.apache.airavata.credential.store.cpi.CredentialStoreService; -import org.apache.airavata.credential.store.exception.CredentialStoreException; -import org.apache.airavata.messaging.core.util.DBEventPublisherUtils; -import org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile; -import org.apache.airavata.model.credential.store.PasswordCredential; -import org.apache.airavata.model.dbevent.CrudType; -import org.apache.airavata.model.dbevent.EntityType; import org.apache.airavata.model.error.AuthorizationException; import org.apache.airavata.model.security.AuthzToken; import org.apache.airavata.model.user.UserProfile; import org.apache.airavata.model.workspace.Gateway; -import org.apache.airavata.registry.api.RegistryService; -import org.apache.airavata.registry.api.client.RegistryServiceClientFactory; -import org.apache.airavata.registry.api.exception.RegistryServiceException; -import org.apache.airavata.service.profile.iam.admin.services.core.impl.TenantManagementKeycloakImpl; import org.apache.airavata.service.profile.iam.admin.services.cpi.IamAdminServices; import org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException; import org.apache.airavata.service.profile.iam.admin.services.cpi.iam_admin_services_cpiConstants; -import org.apache.airavata.service.profile.user.core.repositories.UserProfileRepository; import org.apache.airavata.service.security.interceptor.SecurityCheck; import org.apache.thrift.TException; import org.slf4j.Logger; @@ -54,8 +35,11 @@ public class IamAdminServicesHandler implements IamAdminServices.Iface { private static final Logger logger = LoggerFactory.getLogger(IamAdminServicesHandler.class); - private UserProfileRepository userProfileRepository = new UserProfileRepository(); - private DBEventPublisherUtils dbEventPublisherUtils = new DBEventPublisherUtils(DBEventService.IAM_ADMIN); + private org.apache.airavata.service.IamAdminService iamAdminService; + + public IamAdminServicesHandler() { + iamAdminService = new org.apache.airavata.service.IamAdminService(); + } @Override public String getAPIVersion() throws TException { @@ -66,24 +50,11 @@ public String getAPIVersion() throws TException { @SecurityCheck public Gateway setUpGateway(AuthzToken authzToken, Gateway gateway) throws IamAdminServicesException, AuthorizationException { - TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl(); - PasswordCredential isSuperAdminCredentials = getSuperAdminPasswordCredential(); try { - keycloakclient.addTenant(isSuperAdminCredentials, gateway); - - // Load the tenant admin password stored in gateway request - CredentialStoreService.Client credentialStoreClient = getCredentialStoreServiceClient(); - // Admin password token should already be stored under requested gateway's gatewayId - PasswordCredential tenantAdminPasswordCredential = credentialStoreClient.getPasswordCredential( - gateway.getIdentityServerPasswordToken(), gateway.getGatewayId()); - - if (!keycloakclient.createTenantAdminAccount( - isSuperAdminCredentials, gateway, tenantAdminPasswordCredential.getPassword())) { - logger.error("Admin account creation failed !!, please refer error logs for reason"); - } - Gateway gatewayWithIdAndSecret = keycloakclient.configureClient(isSuperAdminCredentials, gateway); - return gatewayWithIdAndSecret; - } catch (TException | ApplicationSettingsException ex) { + return iamAdminService.setUpGateway(authzToken, gateway); + } catch (IamAdminServicesException e) { + throw e; + } catch (Exception ex) { logger.error("Gateway Setup Failed, reason: " + ex.getMessage(), ex); IamAdminServicesException iamAdminServicesException = new IamAdminServicesException(ex.getMessage()); throw iamAdminServicesException; @@ -94,12 +65,17 @@ public Gateway setUpGateway(AuthzToken authzToken, Gateway gateway) @SecurityCheck public boolean isUsernameAvailable(AuthzToken authzToken, String username) throws IamAdminServicesException, AuthorizationException, TException { - TenantManagementKeycloakImpl keycloakClient = new TenantManagementKeycloakImpl(); - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - return keycloakClient.isUsernameAvailable(authzToken.getAccessToken(), gatewayId, username); + try { + return iamAdminService.isUsernameAvailable(authzToken, username); + } catch (IamAdminServicesException e) { + throw e; + } catch (Exception ex) { + String msg = "Error while checking username availability, reason: " + ex.getMessage(); + logger.error(msg, ex); + throw new IamAdminServicesException(msg); + } } - // ToDo: Will only be secure when using SSL between PGA and Airavata @Override @SecurityCheck public boolean registerUser( @@ -110,14 +86,11 @@ public boolean registerUser( String lastName, String newPassword) throws IamAdminServicesException, AuthorizationException { - TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl(); - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); try { - if (keycloakclient.createUser( - authzToken.getAccessToken(), gatewayId, username, emailAddress, firstName, lastName, newPassword)) - return true; - else return false; - } catch (TException ex) { + return iamAdminService.registerUser(authzToken, username, emailAddress, firstName, lastName, newPassword); + } catch (IamAdminServicesException e) { + throw e; + } catch (Exception ex) { String msg = "Error while registering user into Identity Server, reason: " + ex.getMessage(); logger.error(msg, ex); throw new IamAdminServicesException(msg); @@ -128,30 +101,11 @@ public boolean registerUser( @SecurityCheck public boolean enableUser(AuthzToken authzToken, String username) throws IamAdminServicesException, AuthorizationException { - TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl(); - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); try { - if (keycloakclient.enableUserAccount(authzToken.getAccessToken(), gatewayId, username)) { - // Check if user profile exists, if not create it - boolean userProfileExists = - userProfileRepository.getUserProfileByIdAndGateWay(username, gatewayId) != null; - if (!userProfileExists) { - // Load basic user profile information from Keycloak and then save in UserProfileRepository - UserProfile userProfile = keycloakclient.getUser(authzToken.getAccessToken(), gatewayId, username); - userProfile.setCreationTime( - AiravataUtils.getCurrentTimestamp().getTime()); - userProfile.setLastAccessTime( - AiravataUtils.getCurrentTimestamp().getTime()); - userProfile.setValidUntil(-1); - userProfileRepository.createUserProfile(userProfile); - // Dispatch IAM_ADMIN service event for a new USER_PROFILE - dbEventPublisherUtils.publish(EntityType.USER_PROFILE, CrudType.CREATE, userProfile); - } - return true; - } else { - return false; - } - } catch (TException | AiravataException ex) { + return iamAdminService.enableUser(authzToken, username); + } catch (IamAdminServicesException e) { + throw e; + } catch (Exception ex) { String msg = "Error while enabling user account, reason: " + ex.getMessage(); logger.error(msg, ex); throw new IamAdminServicesException(msg); @@ -162,10 +116,10 @@ public boolean enableUser(AuthzToken authzToken, String username) @SecurityCheck public boolean isUserEnabled(AuthzToken authzToken, String username) throws IamAdminServicesException, AuthorizationException, TException { - TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl(); - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); try { - return keycloakclient.isUserAccountEnabled(authzToken.getAccessToken(), gatewayId, username); + return iamAdminService.isUserEnabled(authzToken, username); + } catch (IamAdminServicesException e) { + throw e; } catch (Exception ex) { String msg = "Error while checking if user account is enabled, reason: " + ex.getMessage(); logger.error(msg, ex); @@ -177,10 +131,10 @@ public boolean isUserEnabled(AuthzToken authzToken, String username) @SecurityCheck public boolean isUserExist(AuthzToken authzToken, String username) throws IamAdminServicesException, AuthorizationException, TException { - TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl(); - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); try { - return keycloakclient.isUserExist(authzToken.getAccessToken(), gatewayId, username); + return iamAdminService.isUserExist(authzToken, username); + } catch (IamAdminServicesException e) { + throw e; } catch (Exception ex) { String msg = "Error while checking if user account exists, reason: " + ex.getMessage(); logger.error(msg, ex); @@ -192,10 +146,10 @@ public boolean isUserExist(AuthzToken authzToken, String username) @SecurityCheck public UserProfile getUser(AuthzToken authzToken, String username) throws IamAdminServicesException, AuthorizationException, TException { - TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl(); - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); try { - return keycloakclient.getUser(authzToken.getAccessToken(), gatewayId, username); + return iamAdminService.getUser(authzToken, username); + } catch (IamAdminServicesException e) { + throw e; } catch (Exception ex) { String msg = "Error while retrieving user profile from IAM backend, reason: " + ex.getMessage(); logger.error(msg, ex); @@ -207,10 +161,10 @@ public UserProfile getUser(AuthzToken authzToken, String username) @SecurityCheck public List getUsers(AuthzToken authzToken, int offset, int limit, String search) throws IamAdminServicesException, AuthorizationException, TException { - TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl(); - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); try { - return keycloakclient.getUsers(authzToken.getAccessToken(), gatewayId, offset, limit, search); + return iamAdminService.getUsers(authzToken, offset, limit, search); + } catch (IamAdminServicesException e) { + throw e; } catch (Exception ex) { String msg = "Error while retrieving user profile from IAM backend, reason: " + ex.getMessage(); logger.error(msg, ex); @@ -222,13 +176,11 @@ public List getUsers(AuthzToken authzToken, int offset, int limit, @SecurityCheck public boolean resetUserPassword(AuthzToken authzToken, String username, String newPassword) throws IamAdminServicesException, AuthorizationException, TException { - TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl(); - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); try { - if (keycloakclient.resetUserPassword(authzToken.getAccessToken(), gatewayId, username, newPassword)) - return true; - else return false; - } catch (TException ex) { + return iamAdminService.resetUserPassword(authzToken, username, newPassword); + } catch (IamAdminServicesException e) { + throw e; + } catch (Exception ex) { String msg = "Error while resetting user password in Identity Server, reason: " + ex.getMessage(); logger.error(msg, ex); throw new IamAdminServicesException(msg); @@ -239,11 +191,11 @@ public boolean resetUserPassword(AuthzToken authzToken, String username, String @SecurityCheck public List findUsers(AuthzToken authzToken, String email, String userId) throws IamAdminServicesException, AuthorizationException, TException { - TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl(); - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); try { - return keycloakclient.findUser(authzToken.getAccessToken(), gatewayId, email, userId); - } catch (TException ex) { + return iamAdminService.findUsers(authzToken, email, userId); + } catch (IamAdminServicesException e) { + throw e; + } catch (Exception ex) { String msg = "Error while retrieving users from Identity Server, reason: " + ex.getMessage(); logger.error(msg, ex); throw new IamAdminServicesException(msg); @@ -254,23 +206,30 @@ public List findUsers(AuthzToken authzToken, String email, String u @SecurityCheck public void updateUserProfile(AuthzToken authzToken, UserProfile userDetails) throws IamAdminServicesException, AuthorizationException, TException { - - TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl(); - String username = userDetails.getUserId(); - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - - keycloakclient.updateUserProfile(authzToken.getAccessToken(), gatewayId, username, userDetails); + try { + iamAdminService.updateUserProfile(authzToken, userDetails); + } catch (IamAdminServicesException e) { + throw e; + } catch (Exception ex) { + String msg = "Error while updating user profile, reason: " + ex.getMessage(); + logger.error(msg, ex); + throw new IamAdminServicesException(msg); + } } @Override @SecurityCheck public boolean deleteUser(AuthzToken authzToken, String username) throws IamAdminServicesException, AuthorizationException, TException { - - TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl(); - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - - return keycloakclient.deleteUser(authzToken.getAccessToken(), gatewayId, username); + try { + return iamAdminService.deleteUser(authzToken, username); + } catch (IamAdminServicesException e) { + throw e; + } catch (Exception ex) { + String msg = "Error while deleting user, reason: " + ex.getMessage(); + logger.error(msg, ex); + throw new IamAdminServicesException(msg); + } } @Override @@ -278,12 +237,11 @@ public boolean deleteUser(AuthzToken authzToken, String username) @Deprecated public boolean addRoleToUser(AuthzToken authzToken, String username, String roleName) throws IamAdminServicesException, AuthorizationException, TException { - TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl(); - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); try { - PasswordCredential isRealmAdminCredentials = getTenantAdminPasswordCredential(gatewayId); - return keycloakclient.addRoleToUser(isRealmAdminCredentials, gatewayId, username, roleName); - } catch (TException | ApplicationSettingsException ex) { + return iamAdminService.addRoleToUser(authzToken, username, roleName); + } catch (IamAdminServicesException e) { + throw e; + } catch (Exception ex) { String msg = "Error while adding role to user, reason: " + ex.getMessage(); logger.error(msg, ex); throw new IamAdminServicesException(msg); @@ -295,12 +253,11 @@ public boolean addRoleToUser(AuthzToken authzToken, String username, String role @Deprecated public boolean removeRoleFromUser(AuthzToken authzToken, String username, String roleName) throws IamAdminServicesException, AuthorizationException, TException { - TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl(); - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); try { - PasswordCredential isRealmAdminCredentials = getTenantAdminPasswordCredential(gatewayId); - return keycloakclient.removeRoleFromUser(isRealmAdminCredentials, gatewayId, username, roleName); - } catch (TException | ApplicationSettingsException ex) { + return iamAdminService.removeRoleFromUser(authzToken, username, roleName); + } catch (IamAdminServicesException e) { + throw e; + } catch (Exception ex) { String msg = "Error while removing role from user, reason: " + ex.getMessage(); logger.error(msg, ex); throw new IamAdminServicesException(msg); @@ -312,57 +269,14 @@ public boolean removeRoleFromUser(AuthzToken authzToken, String username, String @Deprecated public List getUsersWithRole(AuthzToken authzToken, String roleName) throws IamAdminServicesException, AuthorizationException, TException { - - TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl(); - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); try { - PasswordCredential isRealmAdminCredentials = getTenantAdminPasswordCredential(gatewayId); - return keycloakclient.getUsersWithRole(isRealmAdminCredentials, gatewayId, roleName); + return iamAdminService.getUsersWithRole(authzToken, roleName); + } catch (IamAdminServicesException e) { + throw e; } catch (Exception ex) { String msg = "Error while retrieving users with role, reason: " + ex.getMessage(); logger.error(msg, ex); throw new IamAdminServicesException(msg); } } - - private PasswordCredential getSuperAdminPasswordCredential() { - PasswordCredential isSuperAdminCredentials = new PasswordCredential(); - try { - isSuperAdminCredentials.setLoginUserName(ServerSettings.getIamServerSuperAdminUsername()); - isSuperAdminCredentials.setPassword(ServerSettings.getIamServerSuperAdminPassword()); - } catch (ApplicationSettingsException e) { - throw new RuntimeException("Unable to get settings for IAM super admin username/password", e); - } - return isSuperAdminCredentials; - } - - private PasswordCredential getTenantAdminPasswordCredential(String tenantId) - throws TException, ApplicationSettingsException { - - GatewayResourceProfile gwrp = getRegistryServiceClient().getGatewayResourceProfile(tenantId); - - CredentialStoreService.Client csClient = getCredentialStoreServiceClient(); - return csClient.getPasswordCredential(gwrp.getIdentityServerPwdCredToken(), gwrp.getGatewayID()); - } - - private RegistryService.Client getRegistryServiceClient() throws TException, ApplicationSettingsException { - final int serverPort = Integer.parseInt(ServerSettings.getRegistryServerPort()); - final String serverHost = ServerSettings.getRegistryServerHost(); - try { - return RegistryServiceClientFactory.createRegistryClient(serverHost, serverPort); - } catch (RegistryServiceException e) { - throw new TException("Unable to create registry client...", e); - } - } - - private CredentialStoreService.Client getCredentialStoreServiceClient() - throws TException, ApplicationSettingsException { - final int serverPort = Integer.parseInt(ServerSettings.getCredentialStoreServerPort()); - final String serverHost = ServerSettings.getCredentialStoreServerHost(); - try { - return CredentialStoreClientFactory.createAiravataCSClient(serverHost, serverPort); - } catch (CredentialStoreException e) { - throw new TException("Unable to create credential store client...", e); - } - } } From f4b9eab0b674fa57bd4c5564cbed1ce0c36d323d Mon Sep 17 00:00:00 2001 From: yasithdev Date: Mon, 10 Nov 2025 18:42:24 -0500 Subject: [PATCH 09/26] update sharingregistryserverhandler --- .../service/SharingRegistryService.java | 918 ++++++++++++++++++ .../server/SharingRegistryServerHandler.java | 842 ++++------------ 2 files changed, 1094 insertions(+), 666 deletions(-) create mode 100644 airavata-api/src/main/java/org/apache/airavata/service/SharingRegistryService.java diff --git a/airavata-api/src/main/java/org/apache/airavata/service/SharingRegistryService.java b/airavata-api/src/main/java/org/apache/airavata/service/SharingRegistryService.java new file mode 100644 index 0000000000..ad9552f8e3 --- /dev/null +++ b/airavata-api/src/main/java/org/apache/airavata/service/SharingRegistryService.java @@ -0,0 +1,918 @@ +/** +* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ +package org.apache.airavata.service; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.*; +import org.apache.airavata.sharing.registry.db.entities.*; +import org.apache.airavata.sharing.registry.db.repositories.*; +import org.apache.airavata.sharing.registry.db.utils.DBConstants; +import org.apache.airavata.sharing.registry.models.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SharingRegistryService { + private static final Logger logger = LoggerFactory.getLogger(SharingRegistryService.class); + + public static String OWNER_PERMISSION_NAME = "OWNER"; + + /** + * * Domain Operations + * * + */ + public String createDomain(Domain domain) throws SharingRegistryException, DuplicateEntryException { + if ((new DomainRepository()).get(domain.getDomainId()) != null) + throw new DuplicateEntryException("There exist domain with given domain id"); + + domain.setCreatedTime(System.currentTimeMillis()); + domain.setUpdatedTime(System.currentTimeMillis()); + (new DomainRepository()).create(domain); + + // create the global permission for the domain + PermissionType permissionType = new PermissionType(); + permissionType.setPermissionTypeId(domain.getDomainId() + ":" + OWNER_PERMISSION_NAME); + permissionType.setDomainId(domain.getDomainId()); + permissionType.setName(OWNER_PERMISSION_NAME); + permissionType.setDescription("GLOBAL permission to " + domain.getDomainId()); + permissionType.setCreatedTime(System.currentTimeMillis()); + permissionType.setUpdatedTime(System.currentTimeMillis()); + (new PermissionTypeRepository()).create(permissionType); + + return domain.getDomainId(); + } + + public boolean updateDomain(Domain domain) throws SharingRegistryException { + Domain oldDomain = (new DomainRepository()).get(domain.getDomainId()); + domain.setCreatedTime(oldDomain.getCreatedTime()); + domain.setUpdatedTime(System.currentTimeMillis()); + domain = getUpdatedObject(oldDomain, domain); + (new DomainRepository()).update(domain); + return true; + } + + public boolean isDomainExists(String domainId) throws SharingRegistryException { + return (new DomainRepository()).isExists(domainId); + } + + public boolean deleteDomain(String domainId) throws SharingRegistryException { + (new DomainRepository()).delete(domainId); + return true; + } + + public Domain getDomain(String domainId) throws SharingRegistryException { + return (new DomainRepository()).get(domainId); + } + + public List getDomains(int offset, int limit) throws SharingRegistryException { + return (new DomainRepository()).select(new HashMap<>(), offset, limit); + } + + /** + * * User Operations + * * + */ + public String createUser(User user) throws SharingRegistryException, DuplicateEntryException { + UserPK userPK = new UserPK(); + userPK.setUserId(user.getUserId()); + userPK.setDomainId(user.getDomainId()); + if ((new UserRepository()).get(userPK) != null) + throw new DuplicateEntryException("There exist user with given user id"); + + user.setCreatedTime(System.currentTimeMillis()); + user.setUpdatedTime(System.currentTimeMillis()); + (new UserRepository()).create(user); + + UserGroup userGroup = new UserGroup(); + userGroup.setGroupId(user.getUserId()); + userGroup.setDomainId(user.getDomainId()); + userGroup.setName(user.getUserName()); + userGroup.setDescription("user " + user.getUserName() + " group"); + userGroup.setOwnerId(user.getUserId()); + userGroup.setGroupType(GroupType.USER_LEVEL_GROUP); + userGroup.setGroupCardinality(GroupCardinality.SINGLE_USER); + (new UserGroupRepository()).create(userGroup); + + Domain domain = new DomainRepository().get(user.getDomainId()); + if (domain.getInitialUserGroupId() != null) { + addUsersToGroup( + user.getDomainId(), + Collections.singletonList(user.getUserId()), + domain.getInitialUserGroupId()); + } + + return user.getUserId(); + } + + public boolean updatedUser(User user) throws SharingRegistryException { + UserPK userPK = new UserPK(); + userPK.setUserId(user.getUserId()); + userPK.setDomainId(user.getDomainId()); + User oldUser = (new UserRepository()).get(userPK); + user.setCreatedTime(oldUser.getCreatedTime()); + user.setUpdatedTime(System.currentTimeMillis()); + user = getUpdatedObject(oldUser, user); + (new UserRepository()).update(user); + + UserGroupPK userGroupPK = new UserGroupPK(); + userGroupPK.setGroupId(user.getUserId()); + userGroupPK.setDomainId(user.getDomainId()); + UserGroup userGroup = (new UserGroupRepository()).get(userGroupPK); + userGroup.setName(user.getUserName()); + userGroup.setDescription("user " + user.getUserName() + " group"); + updateGroup(userGroup); + return true; + } + + public boolean isUserExists(String domainId, String userId) throws SharingRegistryException { + UserPK userPK = new UserPK(); + userPK.setDomainId(domainId); + userPK.setUserId(userId); + return (new UserRepository()).isExists(userPK); + } + + public boolean deleteUser(String domainId, String userId) throws SharingRegistryException { + UserPK userPK = new UserPK(); + userPK.setUserId(userId); + userPK.setDomainId(domainId); + (new UserRepository()).delete(userPK); + + UserGroupPK userGroupPK = new UserGroupPK(); + userGroupPK.setGroupId(userId); + userGroupPK.setDomainId(domainId); + (new UserGroupRepository()).delete(userGroupPK); + return true; + } + + public User getUser(String domainId, String userId) throws SharingRegistryException { + UserPK userPK = new UserPK(); + userPK.setUserId(userId); + userPK.setDomainId(domainId); + return (new UserRepository()).get(userPK); + } + + public List getUsers(String domain, int offset, int limit) throws SharingRegistryException { + HashMap filters = new HashMap<>(); + filters.put(DBConstants.UserTable.DOMAIN_ID, domain); + return (new UserRepository()).select(filters, offset, limit); + } + + /** + * * Group Operations + * * + */ + public String createGroup(UserGroup group) throws SharingRegistryException { + UserGroupPK userGroupPK = new UserGroupPK(); + userGroupPK.setGroupId(group.getGroupId()); + userGroupPK.setDomainId(group.getDomainId()); + if ((new UserGroupRepository()).get(userGroupPK) != null) + throw new SharingRegistryException("There exist group with given group id"); + // Client created groups are always of type MULTI_USER + group.setGroupCardinality(GroupCardinality.MULTI_USER); + group.setCreatedTime(System.currentTimeMillis()); + group.setUpdatedTime(System.currentTimeMillis()); + // Add group admins once the group is created + group.unsetGroupAdmins(); + (new UserGroupRepository()).create(group); + + addUsersToGroup(group.getDomainId(), Arrays.asList(group.getOwnerId()), group.getGroupId()); + return group.getGroupId(); + } + + public boolean updateGroup(UserGroup group) throws SharingRegistryException { + group.setUpdatedTime(System.currentTimeMillis()); + UserGroupPK userGroupPK = new UserGroupPK(); + userGroupPK.setGroupId(group.getGroupId()); + userGroupPK.setDomainId(group.getDomainId()); + UserGroup oldGroup = (new UserGroupRepository()).get(userGroupPK); + group.setGroupCardinality(oldGroup.getGroupCardinality()); + group.setCreatedTime(oldGroup.getCreatedTime()); + group = getUpdatedObject(oldGroup, group); + + if (!group.getOwnerId().equals(oldGroup.getOwnerId())) + throw new SharingRegistryException("Group owner cannot be changed"); + + (new UserGroupRepository()).update(group); + return true; + } + + public boolean isGroupExists(String domainId, String groupId) throws SharingRegistryException { + UserGroupPK userGroupPK = new UserGroupPK(); + userGroupPK.setDomainId(domainId); + userGroupPK.setGroupId(groupId); + return (new UserGroupRepository()).isExists(userGroupPK); + } + + public boolean deleteGroup(String domainId, String groupId) throws SharingRegistryException { + UserGroupPK userGroupPK = new UserGroupPK(); + userGroupPK.setGroupId(groupId); + userGroupPK.setDomainId(domainId); + (new UserGroupRepository()).delete(userGroupPK); + return true; + } + + public UserGroup getGroup(String domainId, String groupId) throws SharingRegistryException { + UserGroupPK userGroupPK = new UserGroupPK(); + userGroupPK.setGroupId(groupId); + userGroupPK.setDomainId(domainId); + return (new UserGroupRepository()).get(userGroupPK); + } + + public List getGroups(String domain, int offset, int limit) throws SharingRegistryException { + HashMap filters = new HashMap<>(); + filters.put(DBConstants.UserGroupTable.DOMAIN_ID, domain); + // Only return groups with MULTI_USER cardinality which is the only type of cardinality allowed for client + // created groups + filters.put(DBConstants.UserGroupTable.GROUP_CARDINALITY, GroupCardinality.MULTI_USER.name()); + return (new UserGroupRepository()).select(filters, offset, limit); + } + + public boolean addUsersToGroup(String domainId, List userIds, String groupId) + throws SharingRegistryException { + for (int i = 0; i < userIds.size(); i++) { + GroupMembership groupMembership = new GroupMembership(); + groupMembership.setParentId(groupId); + groupMembership.setChildId(userIds.get(i)); + groupMembership.setChildType(GroupChildType.USER); + groupMembership.setDomainId(domainId); + groupMembership.setCreatedTime(System.currentTimeMillis()); + groupMembership.setUpdatedTime(System.currentTimeMillis()); + (new GroupMembershipRepository()).create(groupMembership); + } + return true; + } + + public boolean removeUsersFromGroup(String domainId, List userIds, String groupId) + throws SharingRegistryException { + for (String userId : userIds) { + if (hasOwnerAccess(domainId, groupId, userId)) { + throw new SharingRegistryException( + "List of User Ids contains Owner Id. Cannot remove owner from the group"); + } + } + + for (int i = 0; i < userIds.size(); i++) { + GroupMembershipPK groupMembershipPK = new GroupMembershipPK(); + groupMembershipPK.setParentId(groupId); + groupMembershipPK.setChildId(userIds.get(i)); + groupMembershipPK.setDomainId(domainId); + (new GroupMembershipRepository()).delete(groupMembershipPK); + } + return true; + } + + public boolean transferGroupOwnership(String domainId, String groupId, String newOwnerId) + throws SharingRegistryException, DuplicateEntryException { + List groupUser = getGroupMembersOfTypeUser(domainId, groupId, 0, -1); + if (!isUserBelongsToGroup(groupUser, newOwnerId)) { + throw new SharingRegistryException("New group owner is not part of the group"); + } + + if (hasOwnerAccess(domainId, groupId, newOwnerId)) { + throw new DuplicateEntryException("User already the current owner of the group"); + } + // remove the new owner as Admin if present + if (hasAdminAccess(domainId, groupId, newOwnerId)) { + removeGroupAdmins(domainId, groupId, Arrays.asList(newOwnerId)); + } + + UserGroupPK userGroupPK = new UserGroupPK(); + userGroupPK.setGroupId(groupId); + userGroupPK.setDomainId(domainId); + UserGroup userGroup = (new UserGroupRepository()).get(userGroupPK); + UserGroup newUserGroup = new UserGroup(); + newUserGroup.setUpdatedTime(System.currentTimeMillis()); + newUserGroup.setOwnerId(newOwnerId); + newUserGroup.setGroupCardinality(GroupCardinality.MULTI_USER); + newUserGroup.setCreatedTime(userGroup.getCreatedTime()); + newUserGroup = getUpdatedObject(userGroup, newUserGroup); + + (new UserGroupRepository()).update(newUserGroup); + + return true; + } + + private boolean isUserBelongsToGroup(List groupUser, String newOwnerId) { + for (User user : groupUser) { + if (user.getUserId().equals(newOwnerId)) { + return true; + } + } + return false; + } + + public boolean addGroupAdmins(String domainId, String groupId, List adminIds) + throws SharingRegistryException, DuplicateEntryException { + List groupUser = getGroupMembersOfTypeUser(domainId, groupId, 0, -1); + + for (String adminId : adminIds) { + if (!isUserBelongsToGroup(groupUser, adminId)) { + throw new SharingRegistryException( + "Admin not the user of the group. GroupId : " + groupId + ", AdminId : " + adminId); + } + GroupAdminPK groupAdminPK = new GroupAdminPK(); + groupAdminPK.setGroupId(groupId); + groupAdminPK.setAdminId(adminId); + groupAdminPK.setDomainId(domainId); + + if ((new GroupAdminRepository()).get(groupAdminPK) != null) + throw new DuplicateEntryException("User already an admin for the group"); + + GroupAdmin admin = new GroupAdmin(); + admin.setAdminId(adminId); + admin.setDomainId(domainId); + admin.setGroupId(groupId); + (new GroupAdminRepository()).create(admin); + } + return true; + } + + public boolean removeGroupAdmins(String domainId, String groupId, List adminIds) + throws SharingRegistryException { + for (String adminId : adminIds) { + GroupAdminPK groupAdminPK = new GroupAdminPK(); + groupAdminPK.setAdminId(adminId); + groupAdminPK.setDomainId(domainId); + groupAdminPK.setGroupId(groupId); + (new GroupAdminRepository()).delete(groupAdminPK); + } + return true; + } + + public boolean hasAdminAccess(String domainId, String groupId, String adminId) + throws SharingRegistryException { + GroupAdminPK groupAdminPK = new GroupAdminPK(); + groupAdminPK.setGroupId(groupId); + groupAdminPK.setAdminId(adminId); + groupAdminPK.setDomainId(domainId); + + if ((new GroupAdminRepository()).get(groupAdminPK) != null) return true; + return false; + } + + public boolean hasOwnerAccess(String domainId, String groupId, String ownerId) + throws SharingRegistryException { + UserGroupPK userGroupPK = new UserGroupPK(); + userGroupPK.setGroupId(groupId); + userGroupPK.setDomainId(domainId); + UserGroup getGroup = (new UserGroupRepository()).get(userGroupPK); + + if (getGroup.getOwnerId().equals(ownerId)) return true; + return false; + } + + public List getGroupMembersOfTypeUser(String domainId, String groupId, int offset, int limit) + throws SharingRegistryException { + // TODO limit offset + List groupMemberUsers = (new GroupMembershipRepository()).getAllChildUsers(domainId, groupId); + return groupMemberUsers; + } + + public List getGroupMembersOfTypeGroup(String domainId, String groupId, int offset, int limit) + throws SharingRegistryException { + // TODO limit offset + List groupMemberGroups = (new GroupMembershipRepository()).getAllChildGroups(domainId, groupId); + return groupMemberGroups; + } + + public boolean addChildGroupsToParentGroup(String domainId, List childIds, String groupId) + throws SharingRegistryException { + for (String childId : childIds) { + // Todo check for cyclic dependencies + GroupMembership groupMembership = new GroupMembership(); + groupMembership.setParentId(groupId); + groupMembership.setChildId(childId); + groupMembership.setChildType(GroupChildType.GROUP); + groupMembership.setDomainId(domainId); + groupMembership.setCreatedTime(System.currentTimeMillis()); + groupMembership.setUpdatedTime(System.currentTimeMillis()); + (new GroupMembershipRepository()).create(groupMembership); + } + return true; + } + + public boolean removeChildGroupFromParentGroup(String domainId, String childId, String groupId) + throws SharingRegistryException { + GroupMembershipPK groupMembershipPK = new GroupMembershipPK(); + groupMembershipPK.setParentId(groupId); + groupMembershipPK.setChildId(childId); + groupMembershipPK.setDomainId(domainId); + (new GroupMembershipRepository()).delete(groupMembershipPK); + return true; + } + + public List getAllMemberGroupsForUser(String domainId, String userId) + throws SharingRegistryException { + GroupMembershipRepository groupMembershipRepository = new GroupMembershipRepository(); + return groupMembershipRepository.getAllMemberGroupsForUser(domainId, userId); + } + + /** + * * EntityType Operations + * * + */ + public String createEntityType(EntityType entityType) + throws SharingRegistryException, DuplicateEntryException { + EntityTypePK entityTypePK = new EntityTypePK(); + entityTypePK.setDomainId(entityType.getDomainId()); + entityTypePK.setEntityTypeId(entityType.getEntityTypeId()); + if ((new EntityTypeRepository()).get(entityTypePK) != null) + throw new DuplicateEntryException("There exist EntityType with given EntityType id"); + + entityType.setCreatedTime(System.currentTimeMillis()); + entityType.setUpdatedTime(System.currentTimeMillis()); + (new EntityTypeRepository()).create(entityType); + return entityType.getEntityTypeId(); + } + + public boolean updateEntityType(EntityType entityType) throws SharingRegistryException { + entityType.setUpdatedTime(System.currentTimeMillis()); + EntityTypePK entityTypePK = new EntityTypePK(); + entityTypePK.setDomainId(entityType.getDomainId()); + entityTypePK.setEntityTypeId(entityType.getEntityTypeId()); + EntityType oldEntityType = (new EntityTypeRepository()).get(entityTypePK); + entityType.setCreatedTime(oldEntityType.getCreatedTime()); + entityType = getUpdatedObject(oldEntityType, entityType); + (new EntityTypeRepository()).update(entityType); + return true; + } + + public boolean isEntityTypeExists(String domainId, String entityTypeId) + throws SharingRegistryException { + EntityTypePK entityTypePK = new EntityTypePK(); + entityTypePK.setDomainId(domainId); + entityTypePK.setEntityTypeId(entityTypeId); + return (new EntityTypeRepository()).isExists(entityTypePK); + } + + public boolean deleteEntityType(String domainId, String entityTypeId) throws SharingRegistryException { + EntityTypePK entityTypePK = new EntityTypePK(); + entityTypePK.setDomainId(domainId); + entityTypePK.setEntityTypeId(entityTypeId); + (new EntityTypeRepository()).delete(entityTypePK); + return true; + } + + public EntityType getEntityType(String domainId, String entityTypeId) throws SharingRegistryException { + EntityTypePK entityTypePK = new EntityTypePK(); + entityTypePK.setDomainId(domainId); + entityTypePK.setEntityTypeId(entityTypeId); + return (new EntityTypeRepository()).get(entityTypePK); + } + + public List getEntityTypes(String domain, int offset, int limit) throws SharingRegistryException { + HashMap filters = new HashMap<>(); + filters.put(DBConstants.EntityTypeTable.DOMAIN_ID, domain); + return (new EntityTypeRepository()).select(filters, offset, limit); + } + + /** + * * Permission Operations + * * + */ + public String createPermissionType(PermissionType permissionType) + throws SharingRegistryException, DuplicateEntryException { + PermissionTypePK permissionTypePK = new PermissionTypePK(); + permissionTypePK.setDomainId(permissionType.getDomainId()); + permissionTypePK.setPermissionTypeId(permissionType.getPermissionTypeId()); + if ((new PermissionTypeRepository()).get(permissionTypePK) != null) + throw new DuplicateEntryException("There exist PermissionType with given PermissionType id"); + permissionType.setCreatedTime(System.currentTimeMillis()); + permissionType.setUpdatedTime(System.currentTimeMillis()); + (new PermissionTypeRepository()).create(permissionType); + return permissionType.getPermissionTypeId(); + } + + public boolean updatePermissionType(PermissionType permissionType) throws SharingRegistryException { + permissionType.setUpdatedTime(System.currentTimeMillis()); + PermissionTypePK permissionTypePK = new PermissionTypePK(); + permissionTypePK.setDomainId(permissionType.getDomainId()); + permissionTypePK.setPermissionTypeId(permissionType.getPermissionTypeId()); + PermissionType oldPermissionType = (new PermissionTypeRepository()).get(permissionTypePK); + permissionType = getUpdatedObject(oldPermissionType, permissionType); + (new PermissionTypeRepository()).update(permissionType); + return true; + } + + public boolean isPermissionExists(String domainId, String permissionId) + throws SharingRegistryException { + PermissionTypePK permissionTypePK = new PermissionTypePK(); + permissionTypePK.setDomainId(domainId); + permissionTypePK.setPermissionTypeId(permissionId); + return (new PermissionTypeRepository()).isExists(permissionTypePK); + } + + public boolean deletePermissionType(String domainId, String permissionTypeId) + throws SharingRegistryException { + PermissionTypePK permissionTypePK = new PermissionTypePK(); + permissionTypePK.setDomainId(domainId); + permissionTypePK.setPermissionTypeId(permissionTypeId); + (new PermissionTypeRepository()).delete(permissionTypePK); + return true; + } + + public PermissionType getPermissionType(String domainId, String permissionTypeId) + throws SharingRegistryException { + PermissionTypePK permissionTypePK = new PermissionTypePK(); + permissionTypePK.setDomainId(domainId); + permissionTypePK.setPermissionTypeId(permissionTypeId); + return (new PermissionTypeRepository()).get(permissionTypePK); + } + + public List getPermissionTypes(String domain, int offset, int limit) + throws SharingRegistryException { + HashMap filters = new HashMap<>(); + filters.put(DBConstants.PermissionTypeTable.DOMAIN_ID, domain); + return (new PermissionTypeRepository()).select(filters, offset, limit); + } + + /** + * * Entity Operations + * * + */ + public String createEntity(Entity entity) throws SharingRegistryException, DuplicateEntryException { + EntityPK entityPK = new EntityPK(); + entityPK.setDomainId(entity.getDomainId()); + entityPK.setEntityId(entity.getEntityId()); + if ((new EntityRepository()).get(entityPK) != null) + throw new DuplicateEntryException("There exist Entity with given Entity id"); + + UserPK userPK = new UserPK(); + userPK.setDomainId(entity.getDomainId()); + userPK.setUserId(entity.getOwnerId()); + if (!(new UserRepository()).isExists(userPK)) { + // Todo this is for Airavata easy integration. Proper thing is to throw an exception here + User user = new User(); + user.setUserId(entity.getOwnerId()); + user.setDomainId(entity.getDomainId()); + user.setUserName(user.getUserId().split("@")[0]); + + createUser(user); + } + entity.setCreatedTime(System.currentTimeMillis()); + entity.setUpdatedTime(System.currentTimeMillis()); + + if (entity.getOriginalEntityCreationTime() == 0) { + entity.setOriginalEntityCreationTime(entity.getCreatedTime()); + } + (new EntityRepository()).create(entity); + + // Assigning global permission for the owner + Sharing newSharing = new Sharing(); + newSharing.setPermissionTypeId( + (new PermissionTypeRepository()).getOwnerPermissionTypeIdForDomain(entity.getDomainId())); + newSharing.setEntityId(entity.getEntityId()); + newSharing.setGroupId(entity.getOwnerId()); + newSharing.setSharingType(SharingType.DIRECT_CASCADING); + newSharing.setInheritedParentId(entity.getEntityId()); + newSharing.setDomainId(entity.getDomainId()); + newSharing.setCreatedTime(System.currentTimeMillis()); + newSharing.setUpdatedTime(System.currentTimeMillis()); + + (new SharingRepository()).create(newSharing); + + // creating records for inherited permissions + if (entity.getParentEntityId() != null && entity.getParentEntityId() != "") { + addCascadingPermissionsForEntity(entity); + } + + return entity.getEntityId(); + } + + private void addCascadingPermissionsForEntity(Entity entity) throws SharingRegistryException { + Sharing newSharing; + List sharings = (new SharingRepository()) + .getCascadingPermissionsForEntity(entity.getDomainId(), entity.getParentEntityId()); + for (Sharing sharing : sharings) { + newSharing = new Sharing(); + newSharing.setPermissionTypeId(sharing.getPermissionTypeId()); + newSharing.setEntityId(entity.getEntityId()); + newSharing.setGroupId(sharing.getGroupId()); + newSharing.setInheritedParentId(sharing.getInheritedParentId()); + newSharing.setSharingType(SharingType.INDIRECT_CASCADING); + newSharing.setDomainId(entity.getDomainId()); + newSharing.setCreatedTime(System.currentTimeMillis()); + newSharing.setUpdatedTime(System.currentTimeMillis()); + + (new SharingRepository()).create(newSharing); + } + } + + public boolean updateEntity(Entity entity) throws SharingRegistryException { + // TODO Check for permission changes + entity.setUpdatedTime(System.currentTimeMillis()); + EntityPK entityPK = new EntityPK(); + entityPK.setDomainId(entity.getDomainId()); + entityPK.setEntityId(entity.getEntityId()); + Entity oldEntity = (new EntityRepository()).get(entityPK); + entity.setCreatedTime(oldEntity.getCreatedTime()); + // check if parent entity changed and re-add inherited permissions + if (!Objects.equals(oldEntity.getParentEntityId(), entity.getParentEntityId())) { + logger.debug("Parent entity changed for {}, updating inherited permissions", entity.getEntityId()); + if (oldEntity.getParentEntityId() != null && oldEntity.getParentEntityId() != "") { + logger.debug( + "Removing inherited permissions from {} that were inherited from parent {}", + entity.getEntityId(), + oldEntity.getParentEntityId()); + (new SharingRepository()) + .removeAllIndirectCascadingPermissionsForEntity(entity.getDomainId(), entity.getEntityId()); + } + if (entity.getParentEntityId() != null && entity.getParentEntityId() != "") { + // re-add INDIRECT_CASCADING permissions + logger.debug( + "Adding inherited permissions to {} that are inherited from parent {}", + entity.getEntityId(), + entity.getParentEntityId()); + addCascadingPermissionsForEntity(entity); + } + } + entity = getUpdatedObject(oldEntity, entity); + entity.setSharedCount((new SharingRepository()).getSharedCount(entity.getDomainId(), entity.getEntityId())); + (new EntityRepository()).update(entity); + return true; + } + + public boolean isEntityExists(String domainId, String entityId) throws SharingRegistryException { + EntityPK entityPK = new EntityPK(); + entityPK.setDomainId(domainId); + entityPK.setEntityId(entityId); + return (new EntityRepository()).isExists(entityPK); + } + + public boolean deleteEntity(String domainId, String entityId) throws SharingRegistryException { + // TODO Check for permission changes + EntityPK entityPK = new EntityPK(); + entityPK.setDomainId(domainId); + entityPK.setEntityId(entityId); + (new EntityRepository()).delete(entityPK); + return true; + } + + public Entity getEntity(String domainId, String entityId) throws SharingRegistryException { + EntityPK entityPK = new EntityPK(); + entityPK.setDomainId(domainId); + entityPK.setEntityId(entityId); + return (new EntityRepository()).get(entityPK); + } + + public List searchEntities( + String domainId, String userId, List filters, int offset, int limit) + throws SharingRegistryException { + List groupIds = new ArrayList<>(); + groupIds.add(userId); + (new GroupMembershipRepository()) + .getAllParentMembershipsForChild(domainId, userId).stream() + .forEach(gm -> groupIds.add(gm.getParentId())); + return (new EntityRepository()).searchEntities(domainId, groupIds, filters, offset, limit); + } + + public List getListOfSharedUsers(String domainId, String entityId, String permissionTypeId) + throws SharingRegistryException { + return (new UserRepository()).getAccessibleUsers(domainId, entityId, permissionTypeId); + } + + public List getListOfDirectlySharedUsers(String domainId, String entityId, String permissionTypeId) + throws SharingRegistryException { + return (new UserRepository()).getDirectlyAccessibleUsers(domainId, entityId, permissionTypeId); + } + + public List getListOfSharedGroups(String domainId, String entityId, String permissionTypeId) + throws SharingRegistryException { + return (new UserGroupRepository()).getAccessibleGroups(domainId, entityId, permissionTypeId); + } + + public List getListOfDirectlySharedGroups(String domainId, String entityId, String permissionTypeId) + throws SharingRegistryException { + return (new UserGroupRepository()).getDirectlyAccessibleGroups(domainId, entityId, permissionTypeId); + } + + public boolean shareEntityWithUsers( + String domainId, String entityId, List userList, String permissionTypeId, boolean cascadePermission) + throws SharingRegistryException { + return shareEntity(domainId, entityId, userList, permissionTypeId, cascadePermission); + } + + public boolean shareEntityWithGroups( + String domainId, + String entityId, + List groupList, + String permissionTypeId, + boolean cascadePermission) + throws SharingRegistryException { + return shareEntity(domainId, entityId, groupList, permissionTypeId, cascadePermission); + } + + private boolean shareEntity( + String domainId, + String entityId, + List groupOrUserList, + String permissionTypeId, + boolean cascadePermission) + throws SharingRegistryException { + if (permissionTypeId.equals((new PermissionTypeRepository()).getOwnerPermissionTypeIdForDomain(domainId))) { + throw new SharingRegistryException(OWNER_PERMISSION_NAME + " permission cannot be assigned or removed"); + } + + List sharings = new ArrayList<>(); + + // Adding permission for the specified users/groups for the specified entity + LinkedList temp = new LinkedList<>(); + for (String userId : groupOrUserList) { + Sharing sharing = new Sharing(); + sharing.setPermissionTypeId(permissionTypeId); + sharing.setEntityId(entityId); + sharing.setGroupId(userId); + sharing.setInheritedParentId(entityId); + sharing.setDomainId(domainId); + if (cascadePermission) { + sharing.setSharingType(SharingType.DIRECT_CASCADING); + } else { + sharing.setSharingType(SharingType.DIRECT_NON_CASCADING); + } + sharing.setCreatedTime(System.currentTimeMillis()); + sharing.setUpdatedTime(System.currentTimeMillis()); + + sharings.add(sharing); + } + + if (cascadePermission) { + // Adding permission for the specified users/groups for all child entities + (new EntityRepository()) + .getChildEntities(domainId, entityId).stream().forEach(e -> temp.addLast(e)); + while (temp.size() > 0) { + Entity entity = temp.pop(); + String childEntityId = entity.getEntityId(); + for (String userId : groupOrUserList) { + Sharing sharing = new Sharing(); + sharing.setPermissionTypeId(permissionTypeId); + sharing.setEntityId(childEntityId); + sharing.setGroupId(userId); + sharing.setInheritedParentId(entityId); + sharing.setSharingType(SharingType.INDIRECT_CASCADING); + sharing.setInheritedParentId(entityId); + sharing.setDomainId(domainId); + sharing.setCreatedTime(System.currentTimeMillis()); + sharing.setUpdatedTime(System.currentTimeMillis()); + sharings.add(sharing); + (new EntityRepository()) + .getChildEntities(domainId, childEntityId).stream() + .forEach(e -> temp.addLast(e)); + } + } + } + (new SharingRepository()).create(sharings); + + EntityPK entityPK = new EntityPK(); + entityPK.setDomainId(domainId); + entityPK.setEntityId(entityId); + Entity entity = (new EntityRepository()).get(entityPK); + entity.setSharedCount((new SharingRepository()).getSharedCount(domainId, entityId)); + (new EntityRepository()).update(entity); + return true; + } + + public boolean revokeEntitySharingFromUsers( + String domainId, String entityId, List userList, String permissionTypeId) + throws SharingRegistryException { + if (permissionTypeId.equals((new PermissionTypeRepository()).getOwnerPermissionTypeIdForDomain(domainId))) { + throw new SharingRegistryException(OWNER_PERMISSION_NAME + " permission cannot be assigned or removed"); + } + return revokeEntitySharing(domainId, entityId, userList, permissionTypeId); + } + + public boolean revokeEntitySharingFromGroups( + String domainId, String entityId, List groupList, String permissionTypeId) + throws SharingRegistryException { + if (permissionTypeId.equals((new PermissionTypeRepository()).getOwnerPermissionTypeIdForDomain(domainId))) { + throw new SharingRegistryException(OWNER_PERMISSION_NAME + " permission cannot be assigned or removed"); + } + return revokeEntitySharing(domainId, entityId, groupList, permissionTypeId); + } + + public boolean userHasAccess(String domainId, String userId, String entityId, String permissionTypeId) + throws SharingRegistryException { + // check whether the user has permission directly or indirectly + List parentMemberships = + (new GroupMembershipRepository()).getAllParentMembershipsForChild(domainId, userId); + List groupIds = new ArrayList<>(); + parentMemberships.stream().forEach(pm -> groupIds.add(pm.getParentId())); + groupIds.add(userId); + return (new SharingRepository()) + .hasAccess( + domainId, + entityId, + groupIds, + Arrays.asList( + permissionTypeId, + (new PermissionTypeRepository()).getOwnerPermissionTypeIdForDomain(domainId))); + } + + public boolean revokeEntitySharing( + String domainId, String entityId, List groupOrUserList, String permissionTypeId) + throws SharingRegistryException { + if (permissionTypeId.equals((new PermissionTypeRepository()).getOwnerPermissionTypeIdForDomain(domainId))) { + throw new SharingRegistryException(OWNER_PERMISSION_NAME + " permission cannot be removed"); + } + + // revoking permission for the entity + for (String groupId : groupOrUserList) { + SharingPK sharingPK = new SharingPK(); + sharingPK.setEntityId(entityId); + sharingPK.setGroupId(groupId); + sharingPK.setPermissionTypeId(permissionTypeId); + sharingPK.setInheritedParentId(entityId); + sharingPK.setDomainId(domainId); + + (new SharingRepository()).delete(sharingPK); + } + + // revoking permission from inheritance + List temp = new ArrayList<>(); + (new SharingRepository()) + .getIndirectSharedChildren(domainId, entityId, permissionTypeId).stream() + .forEach(s -> temp.add(s)); + for (Sharing sharing : temp) { + String childEntityId = sharing.getEntityId(); + for (String groupId : groupOrUserList) { + SharingPK sharingPK = new SharingPK(); + sharingPK.setEntityId(childEntityId); + sharingPK.setGroupId(groupId); + sharingPK.setPermissionTypeId(permissionTypeId); + sharingPK.setInheritedParentId(entityId); + sharingPK.setDomainId(domainId); + + (new SharingRepository()).delete(sharingPK); + } + } + + EntityPK entityPK = new EntityPK(); + entityPK.setDomainId(domainId); + entityPK.setEntityId(entityId); + Entity entity = (new EntityRepository()).get(entityPK); + entity.setSharedCount((new SharingRepository()).getSharedCount(domainId, entityId)); + (new EntityRepository()).update(entity); + return true; + } + + private T getUpdatedObject(T oldEntity, T newEntity) throws SharingRegistryException { + Field[] newEntityFields = newEntity.getClass().getDeclaredFields(); + Hashtable newHT = fieldsToHT(newEntityFields, newEntity); + + Class oldEntityClass = oldEntity.getClass(); + Field[] oldEntityFields = oldEntityClass.getDeclaredFields(); + + for (Field field : oldEntityFields) { + if (!Modifier.isFinal(field.getModifiers())) { + field.setAccessible(true); + Object o = newHT.get(field.getName()); + if (o != null) { + Field f = null; + try { + f = oldEntityClass.getDeclaredField(field.getName()); + f.setAccessible(true); + logger.debug("setting " + f.getName()); + f.set(oldEntity, o); + } catch (Exception e) { + throw new SharingRegistryException(e.getMessage()); + } + } + } + } + return oldEntity; + } + + private static Hashtable fieldsToHT(Field[] fields, Object obj) { + Hashtable hashtable = new Hashtable<>(); + for (Field field : fields) { + field.setAccessible(true); + try { + Object retrievedObject = field.get(obj); + if (retrievedObject != null) { + logger.debug("scanning " + field.getName()); + hashtable.put(field.getName(), field.get(obj)); + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + return hashtable; + } +} + diff --git a/airavata-api/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java index c171359b7f..e7c244fe29 100644 --- a/airavata-api/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java @@ -19,14 +19,9 @@ */ package org.apache.airavata.sharing.registry.server; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.*; +import java.util.List; import org.apache.airavata.common.exception.ApplicationSettingsException; import org.apache.airavata.common.utils.DBInitializer; -import org.apache.airavata.sharing.registry.db.entities.*; -import org.apache.airavata.sharing.registry.db.repositories.*; -import org.apache.airavata.sharing.registry.db.utils.DBConstants; import org.apache.airavata.sharing.registry.db.utils.SharingRegistryDBInitConfig; import org.apache.airavata.sharing.registry.models.*; import org.apache.airavata.sharing.registry.service.cpi.SharingRegistryService; @@ -38,8 +33,9 @@ public class SharingRegistryServerHandler implements SharingRegistryService.Iface { private static final Logger logger = LoggerFactory.getLogger(SharingRegistryServerHandler.class); - - public static String OWNER_PERMISSION_NAME = "OWNER"; + private org.apache.airavata.service.SharingRegistryService sharingRegistryService; + + public static String OWNER_PERMISSION_NAME = org.apache.airavata.service.SharingRegistryService.OWNER_PERMISSION_NAME; public SharingRegistryServerHandler() throws ApplicationSettingsException, TException { this(new SharingRegistryDBInitConfig()); @@ -48,6 +44,7 @@ public SharingRegistryServerHandler() throws ApplicationSettingsException, TExce public SharingRegistryServerHandler(SharingRegistryDBInitConfig sharingRegistryDBInitConfig) throws ApplicationSettingsException, TException { DBInitializer.initializeDB(sharingRegistryDBInitConfig); + sharingRegistryService = new org.apache.airavata.service.SharingRegistryService(); } @Override @@ -62,24 +59,9 @@ public String getAPIVersion() throws TException { @Override public String createDomain(Domain domain) throws SharingRegistryException, DuplicateEntryException, TException { try { - if ((new DomainRepository()).get(domain.getDomainId()) != null) - throw new DuplicateEntryException("There exist domain with given domain id"); - - domain.setCreatedTime(System.currentTimeMillis()); - domain.setUpdatedTime(System.currentTimeMillis()); - (new DomainRepository()).create(domain); - - // create the global permission for the domain - PermissionType permissionType = new PermissionType(); - permissionType.setPermissionTypeId(domain.getDomainId() + ":" + OWNER_PERMISSION_NAME); - permissionType.setDomainId(domain.getDomainId()); - permissionType.setName(OWNER_PERMISSION_NAME); - permissionType.setDescription("GLOBAL permission to " + domain.getDomainId()); - permissionType.setCreatedTime(System.currentTimeMillis()); - permissionType.setUpdatedTime(System.currentTimeMillis()); - (new PermissionTypeRepository()).create(permissionType); - - return domain.getDomainId(); + return sharingRegistryService.createDomain(domain); + } catch (SharingRegistryException | DuplicateEntryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -89,12 +71,9 @@ public String createDomain(Domain domain) throws SharingRegistryException, Dupli @Override public boolean updateDomain(Domain domain) throws SharingRegistryException, TException { try { - Domain oldDomain = (new DomainRepository()).get(domain.getDomainId()); - domain.setCreatedTime(oldDomain.getCreatedTime()); - domain.setUpdatedTime(System.currentTimeMillis()); - domain = getUpdatedObject(oldDomain, domain); - (new DomainRepository()).update(domain); - return true; + return sharingRegistryService.updateDomain(domain); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -109,7 +88,9 @@ public boolean updateDomain(Domain domain) throws SharingRegistryException, TExc @Override public boolean isDomainExists(String domainId) throws SharingRegistryException, TException { try { - return (new DomainRepository()).isExists(domainId); + return sharingRegistryService.isDomainExists(domainId); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -119,8 +100,9 @@ public boolean isDomainExists(String domainId) throws SharingRegistryException, @Override public boolean deleteDomain(String domainId) throws SharingRegistryException, TException { try { - (new DomainRepository()).delete(domainId); - return true; + return sharingRegistryService.deleteDomain(domainId); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -130,7 +112,9 @@ public boolean deleteDomain(String domainId) throws SharingRegistryException, TE @Override public Domain getDomain(String domainId) throws SharingRegistryException, TException { try { - return (new DomainRepository()).get(domainId); + return sharingRegistryService.getDomain(domainId); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -140,7 +124,9 @@ public Domain getDomain(String domainId) throws SharingRegistryException, TExcep @Override public List getDomains(int offset, int limit) throws TException { try { - return (new DomainRepository()).select(new HashMap<>(), offset, limit); + return sharingRegistryService.getDomains(offset, limit); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -154,35 +140,9 @@ public List getDomains(int offset, int limit) throws TException { @Override public String createUser(User user) throws SharingRegistryException, DuplicateEntryException, TException { try { - UserPK userPK = new UserPK(); - userPK.setUserId(user.getUserId()); - userPK.setDomainId(user.getDomainId()); - if ((new UserRepository()).get(userPK) != null) - throw new DuplicateEntryException("There exist user with given user id"); - - user.setCreatedTime(System.currentTimeMillis()); - user.setUpdatedTime(System.currentTimeMillis()); - (new UserRepository()).create(user); - - UserGroup userGroup = new UserGroup(); - userGroup.setGroupId(user.getUserId()); - userGroup.setDomainId(user.getDomainId()); - userGroup.setName(user.getUserName()); - userGroup.setDescription("user " + user.getUserName() + " group"); - userGroup.setOwnerId(user.getUserId()); - userGroup.setGroupType(GroupType.USER_LEVEL_GROUP); - userGroup.setGroupCardinality(GroupCardinality.SINGLE_USER); - (new UserGroupRepository()).create(userGroup); - - Domain domain = new DomainRepository().get(user.getDomainId()); - if (domain.getInitialUserGroupId() != null) { - addUsersToGroup( - user.getDomainId(), - Collections.singletonList(user.getUserId()), - domain.getInitialUserGroupId()); - } - - return user.getUserId(); + return sharingRegistryService.createUser(user); + } catch (SharingRegistryException | DuplicateEntryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -192,23 +152,9 @@ public String createUser(User user) throws SharingRegistryException, DuplicateEn @Override public boolean updatedUser(User user) throws SharingRegistryException, TException { try { - UserPK userPK = new UserPK(); - userPK.setUserId(user.getUserId()); - userPK.setDomainId(user.getDomainId()); - User oldUser = (new UserRepository()).get(userPK); - user.setCreatedTime(oldUser.getCreatedTime()); - user.setUpdatedTime(System.currentTimeMillis()); - user = getUpdatedObject(oldUser, user); - (new UserRepository()).update(user); - - UserGroupPK userGroupPK = new UserGroupPK(); - userGroupPK.setGroupId(user.getUserId()); - userGroupPK.setDomainId(user.getDomainId()); - UserGroup userGroup = (new UserGroupRepository()).get(userGroupPK); - userGroup.setName(user.getUserName()); - userGroup.setDescription("user " + user.getUserName() + " group"); - updateGroup(userGroup); - return true; + return sharingRegistryService.updatedUser(user); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -223,10 +169,9 @@ public boolean updatedUser(User user) throws SharingRegistryException, TExceptio @Override public boolean isUserExists(String domainId, String userId) throws SharingRegistryException, TException { try { - UserPK userPK = new UserPK(); - userPK.setDomainId(domainId); - userPK.setUserId(userId); - return (new UserRepository()).isExists(userPK); + return sharingRegistryService.isUserExists(domainId, userId); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -236,16 +181,9 @@ public boolean isUserExists(String domainId, String userId) throws SharingRegist @Override public boolean deleteUser(String domainId, String userId) throws SharingRegistryException, TException { try { - UserPK userPK = new UserPK(); - userPK.setUserId(userId); - userPK.setDomainId(domainId); - (new UserRepository()).delete(userPK); - - UserGroupPK userGroupPK = new UserGroupPK(); - userGroupPK.setGroupId(userId); - userGroupPK.setDomainId(domainId); - (new UserGroupRepository()).delete(userGroupPK); - return true; + return sharingRegistryService.deleteUser(domainId, userId); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -255,10 +193,9 @@ public boolean deleteUser(String domainId, String userId) throws SharingRegistry @Override public User getUser(String domainId, String userId) throws SharingRegistryException, TException { try { - UserPK userPK = new UserPK(); - userPK.setUserId(userId); - userPK.setDomainId(domainId); - return (new UserRepository()).get(userPK); + return sharingRegistryService.getUser(domainId, userId); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -268,9 +205,9 @@ public User getUser(String domainId, String userId) throws SharingRegistryExcept @Override public List getUsers(String domain, int offset, int limit) throws SharingRegistryException, TException { try { - HashMap filters = new HashMap<>(); - filters.put(DBConstants.UserTable.DOMAIN_ID, domain); - return (new UserRepository()).select(filters, offset, limit); + return sharingRegistryService.getUsers(domain, offset, limit); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -284,21 +221,9 @@ public List getUsers(String domain, int offset, int limit) throws SharingR @Override public String createGroup(UserGroup group) throws SharingRegistryException, TException { try { - UserGroupPK userGroupPK = new UserGroupPK(); - userGroupPK.setGroupId(group.getGroupId()); - userGroupPK.setDomainId(group.getDomainId()); - if ((new UserGroupRepository()).get(userGroupPK) != null) - throw new SharingRegistryException("There exist group with given group id"); - // Client created groups are always of type MULTI_USER - group.setGroupCardinality(GroupCardinality.MULTI_USER); - group.setCreatedTime(System.currentTimeMillis()); - group.setUpdatedTime(System.currentTimeMillis()); - // Add group admins once the group is created - group.unsetGroupAdmins(); - (new UserGroupRepository()).create(group); - - addUsersToGroup(group.getDomainId(), Arrays.asList(group.getOwnerId()), group.getGroupId()); - return group.getGroupId(); + return sharingRegistryService.createGroup(group); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -308,20 +233,9 @@ public String createGroup(UserGroup group) throws SharingRegistryException, TExc @Override public boolean updateGroup(UserGroup group) throws SharingRegistryException, TException { try { - group.setUpdatedTime(System.currentTimeMillis()); - UserGroupPK userGroupPK = new UserGroupPK(); - userGroupPK.setGroupId(group.getGroupId()); - userGroupPK.setDomainId(group.getDomainId()); - UserGroup oldGroup = (new UserGroupRepository()).get(userGroupPK); - group.setGroupCardinality(oldGroup.getGroupCardinality()); - group.setCreatedTime(oldGroup.getCreatedTime()); - group = getUpdatedObject(oldGroup, group); - - if (!group.getOwnerId().equals(oldGroup.getOwnerId())) - throw new SharingRegistryException("Group owner cannot be changed"); - - (new UserGroupRepository()).update(group); - return true; + return sharingRegistryService.updateGroup(group); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -339,10 +253,9 @@ public boolean updateGroup(UserGroup group) throws SharingRegistryException, TEx @Override public boolean isGroupExists(String domainId, String groupId) throws SharingRegistryException, TException { try { - UserGroupPK userGroupPK = new UserGroupPK(); - userGroupPK.setDomainId(domainId); - userGroupPK.setGroupId(groupId); - return (new UserGroupRepository()).isExists(userGroupPK); + return sharingRegistryService.isGroupExists(domainId, groupId); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -352,11 +265,9 @@ public boolean isGroupExists(String domainId, String groupId) throws SharingRegi @Override public boolean deleteGroup(String domainId, String groupId) throws SharingRegistryException, TException { try { - UserGroupPK userGroupPK = new UserGroupPK(); - userGroupPK.setGroupId(groupId); - userGroupPK.setDomainId(domainId); - (new UserGroupRepository()).delete(userGroupPK); - return true; + return sharingRegistryService.deleteGroup(domainId, groupId); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -366,10 +277,9 @@ public boolean deleteGroup(String domainId, String groupId) throws SharingRegist @Override public UserGroup getGroup(String domainId, String groupId) throws SharingRegistryException, TException { try { - UserGroupPK userGroupPK = new UserGroupPK(); - userGroupPK.setGroupId(groupId); - userGroupPK.setDomainId(domainId); - return (new UserGroupRepository()).get(userGroupPK); + return sharingRegistryService.getGroup(domainId, groupId); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -379,12 +289,9 @@ public UserGroup getGroup(String domainId, String groupId) throws SharingRegistr @Override public List getGroups(String domain, int offset, int limit) throws TException { try { - HashMap filters = new HashMap<>(); - filters.put(DBConstants.UserGroupTable.DOMAIN_ID, domain); - // Only return groups with MULTI_USER cardinality which is the only type of cardinality allowed for client - // created groups - filters.put(DBConstants.UserGroupTable.GROUP_CARDINALITY, GroupCardinality.MULTI_USER.name()); - return (new UserGroupRepository()).select(filters, offset, limit); + return sharingRegistryService.getGroups(domain, offset, limit); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -395,17 +302,9 @@ public List getGroups(String domain, int offset, int limit) throws TE public boolean addUsersToGroup(String domainId, List userIds, String groupId) throws SharingRegistryException, TException { try { - for (int i = 0; i < userIds.size(); i++) { - GroupMembership groupMembership = new GroupMembership(); - groupMembership.setParentId(groupId); - groupMembership.setChildId(userIds.get(i)); - groupMembership.setChildType(GroupChildType.USER); - groupMembership.setDomainId(domainId); - groupMembership.setCreatedTime(System.currentTimeMillis()); - groupMembership.setUpdatedTime(System.currentTimeMillis()); - (new GroupMembershipRepository()).create(groupMembership); - } - return true; + return sharingRegistryService.addUsersToGroup(domainId, userIds, groupId); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -416,21 +315,9 @@ public boolean addUsersToGroup(String domainId, List userIds, String gro public boolean removeUsersFromGroup(String domainId, List userIds, String groupId) throws SharingRegistryException, TException { try { - for (String userId : userIds) { - if (hasOwnerAccess(domainId, groupId, userId)) { - throw new SharingRegistryException( - "List of User Ids contains Owner Id. Cannot remove owner from the group"); - } - } - - for (int i = 0; i < userIds.size(); i++) { - GroupMembershipPK groupMembershipPK = new GroupMembershipPK(); - groupMembershipPK.setParentId(groupId); - groupMembershipPK.setChildId(userIds.get(i)); - groupMembershipPK.setDomainId(domainId); - (new GroupMembershipRepository()).delete(groupMembershipPK); - } - return true; + return sharingRegistryService.removeUsersFromGroup(domainId, userIds, groupId); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -441,74 +328,22 @@ public boolean removeUsersFromGroup(String domainId, List userIds, Strin public boolean transferGroupOwnership(String domainId, String groupId, String newOwnerId) throws SharingRegistryException, TException { try { - List groupUser = getGroupMembersOfTypeUser(domainId, groupId, 0, -1); - if (!isUserBelongsToGroup(groupUser, newOwnerId)) { - throw new SharingRegistryException("New group owner is not part of the group"); - } - - if (hasOwnerAccess(domainId, groupId, newOwnerId)) { - throw new DuplicateEntryException("User already the current owner of the group"); - } - // remove the new owner as Admin if present - if (hasAdminAccess(domainId, groupId, newOwnerId)) { - removeGroupAdmins(domainId, groupId, Arrays.asList(newOwnerId)); - } - - UserGroupPK userGroupPK = new UserGroupPK(); - userGroupPK.setGroupId(groupId); - userGroupPK.setDomainId(domainId); - UserGroup userGroup = (new UserGroupRepository()).get(userGroupPK); - UserGroup newUserGroup = new UserGroup(); - newUserGroup.setUpdatedTime(System.currentTimeMillis()); - newUserGroup.setOwnerId(newOwnerId); - newUserGroup.setGroupCardinality(GroupCardinality.MULTI_USER); - newUserGroup.setCreatedTime(userGroup.getCreatedTime()); - newUserGroup = getUpdatedObject(userGroup, newUserGroup); - - (new UserGroupRepository()).update(newUserGroup); - - return true; + return sharingRegistryService.transferGroupOwnership(domainId, groupId, newOwnerId); + } catch (SharingRegistryException | DuplicateEntryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); } } - private boolean isUserBelongsToGroup(List groupUser, String newOwnerId) { - for (User user : groupUser) { - if (user.getUserId().equals(newOwnerId)) { - return true; - } - } - return false; - } - @Override public boolean addGroupAdmins(String domainId, String groupId, List adminIds) throws SharingRegistryException, TException { try { - List groupUser = getGroupMembersOfTypeUser(domainId, groupId, 0, -1); - - for (String adminId : adminIds) { - if (!isUserBelongsToGroup(groupUser, adminId)) { - throw new SharingRegistryException( - "Admin not the user of the group. GroupId : " + groupId + ", AdminId : " + adminId); - } - GroupAdminPK groupAdminPK = new GroupAdminPK(); - groupAdminPK.setGroupId(groupId); - groupAdminPK.setAdminId(adminId); - groupAdminPK.setDomainId(domainId); - - if ((new GroupAdminRepository()).get(groupAdminPK) != null) - throw new DuplicateEntryException("User already an admin for the group"); - - GroupAdmin admin = new GroupAdmin(); - admin.setAdminId(adminId); - admin.setDomainId(domainId); - admin.setGroupId(groupId); - (new GroupAdminRepository()).create(admin); - } - return true; + return sharingRegistryService.addGroupAdmins(domainId, groupId, adminIds); + } catch (SharingRegistryException | DuplicateEntryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -519,14 +354,9 @@ public boolean addGroupAdmins(String domainId, String groupId, List admi public boolean removeGroupAdmins(String domainId, String groupId, List adminIds) throws SharingRegistryException, TException { try { - for (String adminId : adminIds) { - GroupAdminPK groupAdminPK = new GroupAdminPK(); - groupAdminPK.setAdminId(adminId); - groupAdminPK.setDomainId(domainId); - groupAdminPK.setGroupId(groupId); - (new GroupAdminRepository()).delete(groupAdminPK); - } - return true; + return sharingRegistryService.removeGroupAdmins(domainId, groupId, adminIds); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -537,13 +367,9 @@ public boolean removeGroupAdmins(String domainId, String groupId, List a public boolean hasAdminAccess(String domainId, String groupId, String adminId) throws SharingRegistryException, TException { try { - GroupAdminPK groupAdminPK = new GroupAdminPK(); - groupAdminPK.setGroupId(groupId); - groupAdminPK.setAdminId(adminId); - groupAdminPK.setDomainId(domainId); - - if ((new GroupAdminRepository()).get(groupAdminPK) != null) return true; - return false; + return sharingRegistryService.hasAdminAccess(domainId, groupId, adminId); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -554,13 +380,9 @@ public boolean hasAdminAccess(String domainId, String groupId, String adminId) public boolean hasOwnerAccess(String domainId, String groupId, String ownerId) throws SharingRegistryException, TException { try { - UserGroupPK userGroupPK = new UserGroupPK(); - userGroupPK.setGroupId(groupId); - userGroupPK.setDomainId(domainId); - UserGroup getGroup = (new UserGroupRepository()).get(userGroupPK); - - if (getGroup.getOwnerId().equals(ownerId)) return true; - return false; + return sharingRegistryService.hasOwnerAccess(domainId, groupId, ownerId); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -571,9 +393,9 @@ public boolean hasOwnerAccess(String domainId, String groupId, String ownerId) public List getGroupMembersOfTypeUser(String domainId, String groupId, int offset, int limit) throws SharingRegistryException, TException { try { - // TODO limit offset - List groupMemberUsers = (new GroupMembershipRepository()).getAllChildUsers(domainId, groupId); - return groupMemberUsers; + return sharingRegistryService.getGroupMembersOfTypeUser(domainId, groupId, offset, limit); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -584,9 +406,9 @@ public List getGroupMembersOfTypeUser(String domainId, String groupId, int public List getGroupMembersOfTypeGroup(String domainId, String groupId, int offset, int limit) throws SharingRegistryException, TException { try { - // TODO limit offset - List groupMemberGroups = (new GroupMembershipRepository()).getAllChildGroups(domainId, groupId); - return groupMemberGroups; + return sharingRegistryService.getGroupMembersOfTypeGroup(domainId, groupId, offset, limit); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -597,18 +419,9 @@ public List getGroupMembersOfTypeGroup(String domainId, String groupI public boolean addChildGroupsToParentGroup(String domainId, List childIds, String groupId) throws SharingRegistryException, TException { try { - for (String childId : childIds) { - // Todo check for cyclic dependencies - GroupMembership groupMembership = new GroupMembership(); - groupMembership.setParentId(groupId); - groupMembership.setChildId(childId); - groupMembership.setChildType(GroupChildType.GROUP); - groupMembership.setDomainId(domainId); - groupMembership.setCreatedTime(System.currentTimeMillis()); - groupMembership.setUpdatedTime(System.currentTimeMillis()); - (new GroupMembershipRepository()).create(groupMembership); - } - return true; + return sharingRegistryService.addChildGroupsToParentGroup(domainId, childIds, groupId); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -619,12 +432,9 @@ public boolean addChildGroupsToParentGroup(String domainId, List childId public boolean removeChildGroupFromParentGroup(String domainId, String childId, String groupId) throws SharingRegistryException, TException { try { - GroupMembershipPK groupMembershipPK = new GroupMembershipPK(); - groupMembershipPK.setParentId(groupId); - groupMembershipPK.setChildId(childId); - groupMembershipPK.setDomainId(domainId); - (new GroupMembershipRepository()).delete(groupMembershipPK); - return true; + return sharingRegistryService.removeChildGroupFromParentGroup(domainId, childId, groupId); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -635,8 +445,9 @@ public boolean removeChildGroupFromParentGroup(String domainId, String childId, public List getAllMemberGroupsForUser(String domainId, String userId) throws SharingRegistryException, TException { try { - GroupMembershipRepository groupMembershipRepository = new GroupMembershipRepository(); - return groupMembershipRepository.getAllMemberGroupsForUser(domainId, userId); + return sharingRegistryService.getAllMemberGroupsForUser(domainId, userId); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -651,16 +462,9 @@ public List getAllMemberGroupsForUser(String domainId, String userId) public String createEntityType(EntityType entityType) throws SharingRegistryException, DuplicateEntryException, TException { try { - EntityTypePK entityTypePK = new EntityTypePK(); - entityTypePK.setDomainId(entityType.getDomainId()); - entityTypePK.setEntityTypeId(entityType.getEntityTypeId()); - if ((new EntityTypeRepository()).get(entityTypePK) != null) - throw new DuplicateEntryException("There exist EntityType with given EntityType id"); - - entityType.setCreatedTime(System.currentTimeMillis()); - entityType.setUpdatedTime(System.currentTimeMillis()); - (new EntityTypeRepository()).create(entityType); - return entityType.getEntityTypeId(); + return sharingRegistryService.createEntityType(entityType); + } catch (SharingRegistryException | DuplicateEntryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -670,15 +474,9 @@ public String createEntityType(EntityType entityType) @Override public boolean updateEntityType(EntityType entityType) throws SharingRegistryException, TException { try { - entityType.setUpdatedTime(System.currentTimeMillis()); - EntityTypePK entityTypePK = new EntityTypePK(); - entityTypePK.setDomainId(entityType.getDomainId()); - entityTypePK.setEntityTypeId(entityType.getEntityTypeId()); - EntityType oldEntityType = (new EntityTypeRepository()).get(entityTypePK); - entityType.setCreatedTime(oldEntityType.getCreatedTime()); - entityType = getUpdatedObject(oldEntityType, entityType); - (new EntityTypeRepository()).update(entityType); - return true; + return sharingRegistryService.updateEntityType(entityType); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -694,10 +492,9 @@ public boolean updateEntityType(EntityType entityType) throws SharingRegistryExc public boolean isEntityTypeExists(String domainId, String entityTypeId) throws SharingRegistryException, TException { try { - EntityTypePK entityTypePK = new EntityTypePK(); - entityTypePK.setDomainId(domainId); - entityTypePK.setEntityTypeId(entityTypeId); - return (new EntityTypeRepository()).isExists(entityTypePK); + return sharingRegistryService.isEntityTypeExists(domainId, entityTypeId); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -707,11 +504,9 @@ public boolean isEntityTypeExists(String domainId, String entityTypeId) @Override public boolean deleteEntityType(String domainId, String entityTypeId) throws SharingRegistryException, TException { try { - EntityTypePK entityTypePK = new EntityTypePK(); - entityTypePK.setDomainId(domainId); - entityTypePK.setEntityTypeId(entityTypeId); - (new EntityTypeRepository()).delete(entityTypePK); - return true; + return sharingRegistryService.deleteEntityType(domainId, entityTypeId); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -721,10 +516,9 @@ public boolean deleteEntityType(String domainId, String entityTypeId) throws Sha @Override public EntityType getEntityType(String domainId, String entityTypeId) throws SharingRegistryException, TException { try { - EntityTypePK entityTypePK = new EntityTypePK(); - entityTypePK.setDomainId(domainId); - entityTypePK.setEntityTypeId(entityTypeId); - return (new EntityTypeRepository()).get(entityTypePK); + return sharingRegistryService.getEntityType(domainId, entityTypeId); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -734,9 +528,9 @@ public EntityType getEntityType(String domainId, String entityTypeId) throws Sha @Override public List getEntityTypes(String domain, int offset, int limit) throws TException { try { - HashMap filters = new HashMap<>(); - filters.put(DBConstants.EntityTypeTable.DOMAIN_ID, domain); - return (new EntityTypeRepository()).select(filters, offset, limit); + return sharingRegistryService.getEntityTypes(domain, offset, limit); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -751,15 +545,9 @@ public List getEntityTypes(String domain, int offset, int limit) thr public String createPermissionType(PermissionType permissionType) throws SharingRegistryException, DuplicateEntryException, TException { try { - PermissionTypePK permissionTypePK = new PermissionTypePK(); - permissionTypePK.setDomainId(permissionType.getDomainId()); - permissionTypePK.setPermissionTypeId(permissionType.getPermissionTypeId()); - if ((new PermissionTypeRepository()).get(permissionTypePK) != null) - throw new DuplicateEntryException("There exist PermissionType with given PermissionType id"); - permissionType.setCreatedTime(System.currentTimeMillis()); - permissionType.setUpdatedTime(System.currentTimeMillis()); - (new PermissionTypeRepository()).create(permissionType); - return permissionType.getPermissionTypeId(); + return sharingRegistryService.createPermissionType(permissionType); + } catch (SharingRegistryException | DuplicateEntryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -769,14 +557,9 @@ public String createPermissionType(PermissionType permissionType) @Override public boolean updatePermissionType(PermissionType permissionType) throws SharingRegistryException, TException { try { - permissionType.setUpdatedTime(System.currentTimeMillis()); - PermissionTypePK permissionTypePK = new PermissionTypePK(); - permissionTypePK.setDomainId(permissionType.getDomainId()); - permissionTypePK.setPermissionTypeId(permissionType.getPermissionTypeId()); - PermissionType oldPermissionType = (new PermissionTypeRepository()).get(permissionTypePK); - permissionType = getUpdatedObject(oldPermissionType, permissionType); - (new PermissionTypeRepository()).update(permissionType); - return true; + return sharingRegistryService.updatePermissionType(permissionType); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -792,10 +575,9 @@ public boolean updatePermissionType(PermissionType permissionType) throws Sharin public boolean isPermissionExists(String domainId, String permissionId) throws SharingRegistryException, TException { try { - PermissionTypePK permissionTypePK = new PermissionTypePK(); - permissionTypePK.setDomainId(domainId); - permissionTypePK.setPermissionTypeId(permissionId); - return (new PermissionTypeRepository()).isExists(permissionTypePK); + return sharingRegistryService.isPermissionExists(domainId, permissionId); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -806,11 +588,9 @@ public boolean isPermissionExists(String domainId, String permissionId) public boolean deletePermissionType(String domainId, String permissionTypeId) throws SharingRegistryException, TException { try { - PermissionTypePK permissionTypePK = new PermissionTypePK(); - permissionTypePK.setDomainId(domainId); - permissionTypePK.setPermissionTypeId(permissionTypeId); - (new PermissionTypeRepository()).delete(permissionTypePK); - return true; + return sharingRegistryService.deletePermissionType(domainId, permissionTypeId); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -821,10 +601,9 @@ public boolean deletePermissionType(String domainId, String permissionTypeId) public PermissionType getPermissionType(String domainId, String permissionTypeId) throws SharingRegistryException, TException { try { - PermissionTypePK permissionTypePK = new PermissionTypePK(); - permissionTypePK.setDomainId(domainId); - permissionTypePK.setPermissionTypeId(permissionTypeId); - return (new PermissionTypeRepository()).get(permissionTypePK); + return sharingRegistryService.getPermissionType(domainId, permissionTypeId); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -835,9 +614,9 @@ public PermissionType getPermissionType(String domainId, String permissionTypeId public List getPermissionTypes(String domain, int offset, int limit) throws SharingRegistryException, TException { try { - HashMap filters = new HashMap<>(); - filters.put(DBConstants.PermissionTypeTable.DOMAIN_ID, domain); - return (new PermissionTypeRepository()).select(filters, offset, limit); + return sharingRegistryService.getPermissionTypes(domain, offset, limit); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -851,52 +630,9 @@ public List getPermissionTypes(String domain, int offset, int li @Override public String createEntity(Entity entity) throws SharingRegistryException, DuplicateEntryException, TException { try { - EntityPK entityPK = new EntityPK(); - entityPK.setDomainId(entity.getDomainId()); - entityPK.setEntityId(entity.getEntityId()); - if ((new EntityRepository()).get(entityPK) != null) - throw new DuplicateEntryException("There exist Entity with given Entity id"); - - UserPK userPK = new UserPK(); - userPK.setDomainId(entity.getDomainId()); - userPK.setUserId(entity.getOwnerId()); - if (!(new UserRepository()).isExists(userPK)) { - // Todo this is for Airavata easy integration. Proper thing is to throw an exception here - User user = new User(); - user.setUserId(entity.getOwnerId()); - user.setDomainId(entity.getDomainId()); - user.setUserName(user.getUserId().split("@")[0]); - - createUser(user); - } - entity.setCreatedTime(System.currentTimeMillis()); - entity.setUpdatedTime(System.currentTimeMillis()); - - if (entity.getOriginalEntityCreationTime() == 0) { - entity.setOriginalEntityCreationTime(entity.getCreatedTime()); - } - (new EntityRepository()).create(entity); - - // Assigning global permission for the owner - Sharing newSharing = new Sharing(); - newSharing.setPermissionTypeId( - (new PermissionTypeRepository()).getOwnerPermissionTypeIdForDomain(entity.getDomainId())); - newSharing.setEntityId(entity.getEntityId()); - newSharing.setGroupId(entity.getOwnerId()); - newSharing.setSharingType(SharingType.DIRECT_CASCADING); - newSharing.setInheritedParentId(entity.getEntityId()); - newSharing.setDomainId(entity.getDomainId()); - newSharing.setCreatedTime(System.currentTimeMillis()); - newSharing.setUpdatedTime(System.currentTimeMillis()); - - (new SharingRepository()).create(newSharing); - - // creating records for inherited permissions - if (entity.getParentEntityId() != null && entity.getParentEntityId() != "") { - addCascadingPermissionsForEntity(entity); - } - - return entity.getEntityId(); + return sharingRegistryService.createEntity(entity); + } catch (SharingRegistryException | DuplicateEntryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); SharingRegistryException sharingRegistryException = new SharingRegistryException(); @@ -905,59 +641,12 @@ public String createEntity(Entity entity) throws SharingRegistryException, Dupli } } - private void addCascadingPermissionsForEntity(Entity entity) throws SharingRegistryException { - Sharing newSharing; - List sharings = (new SharingRepository()) - .getCascadingPermissionsForEntity(entity.getDomainId(), entity.getParentEntityId()); - for (Sharing sharing : sharings) { - newSharing = new Sharing(); - newSharing.setPermissionTypeId(sharing.getPermissionTypeId()); - newSharing.setEntityId(entity.getEntityId()); - newSharing.setGroupId(sharing.getGroupId()); - newSharing.setInheritedParentId(sharing.getInheritedParentId()); - newSharing.setSharingType(SharingType.INDIRECT_CASCADING); - newSharing.setDomainId(entity.getDomainId()); - newSharing.setCreatedTime(System.currentTimeMillis()); - newSharing.setUpdatedTime(System.currentTimeMillis()); - - (new SharingRepository()).create(newSharing); - } - } - @Override public boolean updateEntity(Entity entity) throws SharingRegistryException, TException { try { - // TODO Check for permission changes - entity.setUpdatedTime(System.currentTimeMillis()); - EntityPK entityPK = new EntityPK(); - entityPK.setDomainId(entity.getDomainId()); - entityPK.setEntityId(entity.getEntityId()); - Entity oldEntity = (new EntityRepository()).get(entityPK); - entity.setCreatedTime(oldEntity.getCreatedTime()); - // check if parent entity changed and re-add inherited permissions - if (!Objects.equals(oldEntity.getParentEntityId(), entity.getParentEntityId())) { - logger.debug("Parent entity changed for {}, updating inherited permissions", entity.getEntityId()); - if (oldEntity.getParentEntityId() != null && oldEntity.getParentEntityId() != "") { - logger.debug( - "Removing inherited permissions from {} that were inherited from parent {}", - entity.getEntityId(), - oldEntity.getParentEntityId()); - (new SharingRepository()) - .removeAllIndirectCascadingPermissionsForEntity(entity.getDomainId(), entity.getEntityId()); - } - if (entity.getParentEntityId() != null && entity.getParentEntityId() != "") { - // re-add INDIRECT_CASCADING permissions - logger.debug( - "Adding inherited permissions to {} that are inherited from parent {}", - entity.getEntityId(), - entity.getParentEntityId()); - addCascadingPermissionsForEntity(entity); - } - } - entity = getUpdatedObject(oldEntity, entity); - entity.setSharedCount((new SharingRepository()).getSharedCount(entity.getDomainId(), entity.getEntityId())); - (new EntityRepository()).update(entity); - return true; + return sharingRegistryService.updateEntity(entity); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -972,10 +661,9 @@ public boolean updateEntity(Entity entity) throws SharingRegistryException, TExc @Override public boolean isEntityExists(String domainId, String entityId) throws SharingRegistryException, TException { try { - EntityPK entityPK = new EntityPK(); - entityPK.setDomainId(domainId); - entityPK.setEntityId(entityId); - return (new EntityRepository()).isExists(entityPK); + return sharingRegistryService.isEntityExists(domainId, entityId); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -985,12 +673,9 @@ public boolean isEntityExists(String domainId, String entityId) throws SharingRe @Override public boolean deleteEntity(String domainId, String entityId) throws SharingRegistryException, TException { try { - // TODO Check for permission changes - EntityPK entityPK = new EntityPK(); - entityPK.setDomainId(domainId); - entityPK.setEntityId(entityId); - (new EntityRepository()).delete(entityPK); - return true; + return sharingRegistryService.deleteEntity(domainId, entityId); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -1000,10 +685,9 @@ public boolean deleteEntity(String domainId, String entityId) throws SharingRegi @Override public Entity getEntity(String domainId, String entityId) throws SharingRegistryException, TException { try { - EntityPK entityPK = new EntityPK(); - entityPK.setDomainId(domainId); - entityPK.setEntityId(entityId); - return (new EntityRepository()).get(entityPK); + return sharingRegistryService.getEntity(domainId, entityId); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -1015,12 +699,9 @@ public List searchEntities( String domainId, String userId, List filters, int offset, int limit) throws SharingRegistryException, TException { try { - List groupIds = new ArrayList<>(); - groupIds.add(userId); - (new GroupMembershipRepository()) - .getAllParentMembershipsForChild(domainId, userId).stream() - .forEach(gm -> groupIds.add(gm.getParentId())); - return (new EntityRepository()).searchEntities(domainId, groupIds, filters, offset, limit); + return sharingRegistryService.searchEntities(domainId, userId, filters, offset, limit); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -1031,7 +712,9 @@ public List searchEntities( public List getListOfSharedUsers(String domainId, String entityId, String permissionTypeId) throws SharingRegistryException, TException { try { - return (new UserRepository()).getAccessibleUsers(domainId, entityId, permissionTypeId); + return sharingRegistryService.getListOfSharedUsers(domainId, entityId, permissionTypeId); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -1042,7 +725,9 @@ public List getListOfSharedUsers(String domainId, String entityId, String public List getListOfDirectlySharedUsers(String domainId, String entityId, String permissionTypeId) throws SharingRegistryException, TException { try { - return (new UserRepository()).getDirectlyAccessibleUsers(domainId, entityId, permissionTypeId); + return sharingRegistryService.getListOfDirectlySharedUsers(domainId, entityId, permissionTypeId); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); SharingRegistryException sharingRegistryException = new SharingRegistryException(); @@ -1055,7 +740,9 @@ public List getListOfDirectlySharedUsers(String domainId, String entityId, public List getListOfSharedGroups(String domainId, String entityId, String permissionTypeId) throws SharingRegistryException, TException { try { - return (new UserGroupRepository()).getAccessibleGroups(domainId, entityId, permissionTypeId); + return sharingRegistryService.getListOfSharedGroups(domainId, entityId, permissionTypeId); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -1066,7 +753,9 @@ public List getListOfSharedGroups(String domainId, String entityId, S public List getListOfDirectlySharedGroups(String domainId, String entityId, String permissionTypeId) throws SharingRegistryException, TException { try { - return (new UserGroupRepository()).getDirectlyAccessibleGroups(domainId, entityId, permissionTypeId); + return sharingRegistryService.getListOfDirectlySharedGroups(domainId, entityId, permissionTypeId); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); SharingRegistryException sharingRegistryException = new SharingRegistryException(); @@ -1091,7 +780,9 @@ public boolean shareEntityWithUsers( String domainId, String entityId, List userList, String permissionTypeId, boolean cascadePermission) throws SharingRegistryException, TException { try { - return shareEntity(domainId, entityId, userList, permissionTypeId, cascadePermission); + return sharingRegistryService.shareEntityWithUsers(domainId, entityId, userList, permissionTypeId, cascadePermission); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -1107,81 +798,9 @@ public boolean shareEntityWithGroups( boolean cascadePermission) throws SharingRegistryException, TException { try { - return shareEntity(domainId, entityId, groupList, permissionTypeId, cascadePermission); - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } - } - - private boolean shareEntity( - String domainId, - String entityId, - List groupOrUserList, - String permissionTypeId, - boolean cascadePermission) - throws SharingRegistryException, TException { - try { - if (permissionTypeId.equals((new PermissionTypeRepository()).getOwnerPermissionTypeIdForDomain(domainId))) { - throw new SharingRegistryException(OWNER_PERMISSION_NAME + " permission cannot be assigned or removed"); - } - - List sharings = new ArrayList<>(); - - // Adding permission for the specified users/groups for the specified entity - LinkedList temp = new LinkedList<>(); - for (String userId : groupOrUserList) { - Sharing sharing = new Sharing(); - sharing.setPermissionTypeId(permissionTypeId); - sharing.setEntityId(entityId); - sharing.setGroupId(userId); - sharing.setInheritedParentId(entityId); - sharing.setDomainId(domainId); - if (cascadePermission) { - sharing.setSharingType(SharingType.DIRECT_CASCADING); - } else { - sharing.setSharingType(SharingType.DIRECT_NON_CASCADING); - } - sharing.setCreatedTime(System.currentTimeMillis()); - sharing.setUpdatedTime(System.currentTimeMillis()); - - sharings.add(sharing); - } - - if (cascadePermission) { - // Adding permission for the specified users/groups for all child entities - (new EntityRepository()) - .getChildEntities(domainId, entityId).stream().forEach(e -> temp.addLast(e)); - while (temp.size() > 0) { - Entity entity = temp.pop(); - String childEntityId = entity.getEntityId(); - for (String userId : groupOrUserList) { - Sharing sharing = new Sharing(); - sharing.setPermissionTypeId(permissionTypeId); - sharing.setEntityId(childEntityId); - sharing.setGroupId(userId); - sharing.setInheritedParentId(entityId); - sharing.setSharingType(SharingType.INDIRECT_CASCADING); - sharing.setInheritedParentId(entityId); - sharing.setDomainId(domainId); - sharing.setCreatedTime(System.currentTimeMillis()); - sharing.setUpdatedTime(System.currentTimeMillis()); - sharings.add(sharing); - (new EntityRepository()) - .getChildEntities(domainId, childEntityId).stream() - .forEach(e -> temp.addLast(e)); - } - } - } - (new SharingRepository()).create(sharings); - - EntityPK entityPK = new EntityPK(); - entityPK.setDomainId(domainId); - entityPK.setEntityId(entityId); - Entity entity = (new EntityRepository()).get(entityPK); - entity.setSharedCount((new SharingRepository()).getSharedCount(domainId, entityId)); - (new EntityRepository()).update(entity); - return true; + return sharingRegistryService.shareEntityWithGroups(domainId, entityId, groupList, permissionTypeId, cascadePermission); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -1193,10 +812,9 @@ public boolean revokeEntitySharingFromUsers( String domainId, String entityId, List userList, String permissionTypeId) throws SharingRegistryException, TException { try { - if (permissionTypeId.equals((new PermissionTypeRepository()).getOwnerPermissionTypeIdForDomain(domainId))) { - throw new SharingRegistryException(OWNER_PERMISSION_NAME + " permission cannot be assigned or removed"); - } - return revokeEntitySharing(domainId, entityId, userList, permissionTypeId); + return sharingRegistryService.revokeEntitySharingFromUsers(domainId, entityId, userList, permissionTypeId); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -1208,10 +826,9 @@ public boolean revokeEntitySharingFromGroups( String domainId, String entityId, List groupList, String permissionTypeId) throws SharingRegistryException, TException { try { - if (permissionTypeId.equals((new PermissionTypeRepository()).getOwnerPermissionTypeIdForDomain(domainId))) { - throw new SharingRegistryException(OWNER_PERMISSION_NAME + " permission cannot be assigned or removed"); - } - return revokeEntitySharing(domainId, entityId, groupList, permissionTypeId); + return sharingRegistryService.revokeEntitySharingFromGroups(domainId, entityId, groupList, permissionTypeId); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); @@ -1222,119 +839,12 @@ public boolean revokeEntitySharingFromGroups( public boolean userHasAccess(String domainId, String userId, String entityId, String permissionTypeId) throws SharingRegistryException, TException { try { - // check whether the user has permission directly or indirectly - List parentMemberships = - (new GroupMembershipRepository()).getAllParentMembershipsForChild(domainId, userId); - List groupIds = new ArrayList<>(); - parentMemberships.stream().forEach(pm -> groupIds.add(pm.getParentId())); - groupIds.add(userId); - return (new SharingRepository()) - .hasAccess( - domainId, - entityId, - groupIds, - Arrays.asList( - permissionTypeId, - (new PermissionTypeRepository()).getOwnerPermissionTypeIdForDomain(domainId))); + return sharingRegistryService.userHasAccess(domainId, userId, entityId, permissionTypeId); + } catch (SharingRegistryException e) { + throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); } } - - public boolean revokeEntitySharing( - String domainId, String entityId, List groupOrUserList, String permissionTypeId) - throws SharingRegistryException { - try { - if (permissionTypeId.equals((new PermissionTypeRepository()).getOwnerPermissionTypeIdForDomain(domainId))) { - throw new SharingRegistryException(OWNER_PERMISSION_NAME + " permission cannot be removed"); - } - - // revoking permission for the entity - for (String groupId : groupOrUserList) { - SharingPK sharingPK = new SharingPK(); - sharingPK.setEntityId(entityId); - sharingPK.setGroupId(groupId); - sharingPK.setPermissionTypeId(permissionTypeId); - sharingPK.setInheritedParentId(entityId); - sharingPK.setDomainId(domainId); - - (new SharingRepository()).delete(sharingPK); - } - - // revoking permission from inheritance - List temp = new ArrayList<>(); - (new SharingRepository()) - .getIndirectSharedChildren(domainId, entityId, permissionTypeId).stream() - .forEach(s -> temp.add(s)); - for (Sharing sharing : temp) { - String childEntityId = sharing.getEntityId(); - for (String groupId : groupOrUserList) { - SharingPK sharingPK = new SharingPK(); - sharingPK.setEntityId(childEntityId); - sharingPK.setGroupId(groupId); - sharingPK.setPermissionTypeId(permissionTypeId); - sharingPK.setInheritedParentId(entityId); - sharingPK.setDomainId(domainId); - - (new SharingRepository()).delete(sharingPK); - } - } - - EntityPK entityPK = new EntityPK(); - entityPK.setDomainId(domainId); - entityPK.setEntityId(entityId); - Entity entity = (new EntityRepository()).get(entityPK); - entity.setSharedCount((new SharingRepository()).getSharedCount(domainId, entityId)); - (new EntityRepository()).update(entity); - return true; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } - } - - private T getUpdatedObject(T oldEntity, T newEntity) throws SharingRegistryException { - Field[] newEntityFields = newEntity.getClass().getDeclaredFields(); - Hashtable newHT = fieldsToHT(newEntityFields, newEntity); - - Class oldEntityClass = oldEntity.getClass(); - Field[] oldEntityFields = oldEntityClass.getDeclaredFields(); - - for (Field field : oldEntityFields) { - if (!Modifier.isFinal(field.getModifiers())) { - field.setAccessible(true); - Object o = newHT.get(field.getName()); - if (o != null) { - Field f = null; - try { - f = oldEntityClass.getDeclaredField(field.getName()); - f.setAccessible(true); - logger.debug("setting " + f.getName()); - f.set(oldEntity, o); - } catch (Exception e) { - throw new SharingRegistryException(e.getMessage()); - } - } - } - } - return oldEntity; - } - - private static Hashtable fieldsToHT(Field[] fields, Object obj) { - Hashtable hashtable = new Hashtable<>(); - for (Field field : fields) { - field.setAccessible(true); - try { - Object retrievedObject = field.get(obj); - if (retrievedObject != null) { - logger.debug("scanning " + field.getName()); - hashtable.put(field.getName(), field.get(obj)); - } - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - } - return hashtable; - } } From f4275360142eee383db38efed0da3667854401e1 Mon Sep 17 00:00:00 2001 From: yasithdev Date: Mon, 10 Nov 2025 18:42:34 -0500 Subject: [PATCH 10/26] update tenantprofileservicehandler --- .../service/TenantProfileService.java | 243 ++++++++++++++++++ .../handlers/TenantProfileServiceHandler.java | 156 ++--------- 2 files changed, 266 insertions(+), 133 deletions(-) create mode 100644 airavata-api/src/main/java/org/apache/airavata/service/TenantProfileService.java diff --git a/airavata-api/src/main/java/org/apache/airavata/service/TenantProfileService.java b/airavata-api/src/main/java/org/apache/airavata/service/TenantProfileService.java new file mode 100644 index 0000000000..c6e9b7c157 --- /dev/null +++ b/airavata-api/src/main/java/org/apache/airavata/service/TenantProfileService.java @@ -0,0 +1,243 @@ +/** +* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ +package org.apache.airavata.service; + +import java.util.List; +import java.util.UUID; +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.Constants; +import org.apache.airavata.common.utils.DBEventService; +import org.apache.airavata.common.utils.ServerSettings; +import org.apache.airavata.credential.store.client.CredentialStoreClientFactory; +import org.apache.airavata.credential.store.cpi.CredentialStoreService; +import org.apache.airavata.credential.store.exception.CredentialStoreException; +import org.apache.airavata.messaging.core.util.DBEventPublisherUtils; +import org.apache.airavata.model.credential.store.PasswordCredential; +import org.apache.airavata.model.dbevent.CrudType; +import org.apache.airavata.model.dbevent.EntityType; +import org.apache.airavata.model.security.AuthzToken; +import org.apache.airavata.model.workspace.Gateway; +import org.apache.airavata.model.workspace.GatewayApprovalStatus; +import org.apache.airavata.service.profile.commons.tenant.entities.GatewayEntity; +import org.apache.airavata.service.profile.tenant.core.repositories.TenantProfileRepository; +import org.apache.airavata.service.profile.tenant.cpi.exception.TenantProfileServiceException; +import org.apache.thrift.TException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class TenantProfileService { + private static final Logger logger = LoggerFactory.getLogger(TenantProfileService.class); + + private TenantProfileRepository tenantProfileRepository; + private DBEventPublisherUtils dbEventPublisherUtils = new DBEventPublisherUtils(DBEventService.TENANT); + + public TenantProfileService() { + logger.debug("Initializing TenantProfileService"); + this.tenantProfileRepository = new TenantProfileRepository(Gateway.class, GatewayEntity.class); + } + + public String addGateway(AuthzToken authzToken, Gateway gateway) throws TenantProfileServiceException { + try { + // Assign UUID to gateway + gateway.setAiravataInternalGatewayId(UUID.randomUUID().toString()); + if (!checkDuplicateGateway(gateway)) { + // If admin password, copy it in the credential store under the requested gateway's gatewayId + if (gateway.getIdentityServerPasswordToken() != null) { + copyAdminPasswordToGateway(authzToken, gateway); + } + gateway = tenantProfileRepository.create(gateway); + if (gateway != null) { + logger.info("Added Airavata Gateway with Id: " + gateway.getGatewayId()); + // replicate tenant at end-places only if status is APPROVED + if (gateway.getGatewayApprovalStatus().equals(GatewayApprovalStatus.APPROVED)) { + logger.info( + "Gateway with ID: {}, is now APPROVED, replicating to subscribers.", + gateway.getGatewayId()); + dbEventPublisherUtils.publish(EntityType.TENANT, CrudType.CREATE, gateway); + } + // return internal id + return gateway.getAiravataInternalGatewayId(); + } else { + throw new Exception("Gateway object is null."); + } + } else { + throw new TenantProfileServiceException( + "An approved Gateway already exists with the same GatewayId, Name or URL"); + } + } catch (Exception ex) { + logger.error("Error adding gateway-profile, reason: " + ex.getMessage(), ex); + TenantProfileServiceException exception = new TenantProfileServiceException(); + exception.setMessage("Error adding gateway-profile, reason: " + ex.getMessage()); + throw exception; + } + } + + public boolean updateGateway(AuthzToken authzToken, Gateway updatedGateway) throws TenantProfileServiceException { + try { + + // if admin password token changes then copy the admin password and store under this gateway id and then + // update the admin password token + Gateway existingGateway = tenantProfileRepository.getGateway(updatedGateway.getAiravataInternalGatewayId()); + if (updatedGateway.getIdentityServerPasswordToken() != null + && (existingGateway.getIdentityServerPasswordToken() == null + || !existingGateway + .getIdentityServerPasswordToken() + .equals(updatedGateway.getIdentityServerPasswordToken()))) { + copyAdminPasswordToGateway(authzToken, updatedGateway); + } + + if (tenantProfileRepository.update(updatedGateway) != null) { + logger.debug("Updated gateway-profile with ID: " + updatedGateway.getGatewayId()); + // replicate tenant at end-places + dbEventPublisherUtils.publish(EntityType.TENANT, CrudType.UPDATE, updatedGateway); + return true; + } else { + return false; + } + } catch (Exception ex) { + logger.error("Error updating gateway-profile, reason: " + ex.getMessage(), ex); + TenantProfileServiceException exception = new TenantProfileServiceException(); + exception.setMessage("Error updating gateway-profile, reason: " + ex.getMessage()); + return false; + } + } + + public Gateway getGateway(AuthzToken authzToken, String airavataInternalGatewayId) + throws TenantProfileServiceException { + try { + Gateway gateway = tenantProfileRepository.getGateway(airavataInternalGatewayId); + if (gateway == null) { + throw new Exception("Could not find Gateway with internal ID: " + airavataInternalGatewayId); + } + return gateway; + } catch (Exception ex) { + logger.error("Error getting gateway-profile, reason: " + ex.getMessage(), ex); + TenantProfileServiceException exception = new TenantProfileServiceException(); + exception.setMessage("Error getting gateway-profile, reason: " + ex.getMessage()); + throw exception; + } + } + + public boolean deleteGateway(AuthzToken authzToken, String airavataInternalGatewayId, String gatewayId) + throws TenantProfileServiceException { + try { + logger.debug("Deleting Airavata gateway-profile with ID: " + gatewayId + "Internal ID: " + + airavataInternalGatewayId); + boolean deleteSuccess = tenantProfileRepository.delete(airavataInternalGatewayId); + if (deleteSuccess) { + // delete tenant at end-places + dbEventPublisherUtils.publish( + EntityType.TENANT, + CrudType.DELETE, + // pass along gateway datamodel, with correct gatewayId; + // approvalstatus is not used for delete, hence set dummy value + new Gateway(gatewayId, GatewayApprovalStatus.DEACTIVATED)); + } + return deleteSuccess; + } catch (Exception ex) { + logger.error("Error deleting gateway-profile, reason: " + ex.getMessage(), ex); + TenantProfileServiceException exception = new TenantProfileServiceException(); + exception.setMessage("Error deleting gateway-profile, reason: " + ex.getMessage()); + throw exception; + } + } + + public List getAllGateways(AuthzToken authzToken) throws TenantProfileServiceException { + try { + return tenantProfileRepository.getAllGateways(); + } catch (Exception ex) { + logger.error("Error getting all gateway-profiles, reason: " + ex.getMessage(), ex); + TenantProfileServiceException exception = new TenantProfileServiceException(); + exception.setMessage("Error getting all gateway-profiles, reason: " + ex.getMessage()); + throw exception; + } + } + + public boolean isGatewayExist(AuthzToken authzToken, String gatewayId) throws TenantProfileServiceException { + try { + Gateway gateway = tenantProfileRepository.getGateway(gatewayId); + return (gateway != null); + } catch (Exception ex) { + logger.error("Error checking if gateway-profile exists, reason: " + ex.getMessage(), ex); + TenantProfileServiceException exception = new TenantProfileServiceException(); + exception.setMessage("Error checking if gateway-profile exists, reason: " + ex.getMessage()); + throw exception; + } + } + + public List getAllGatewaysForUser(AuthzToken authzToken, String requesterUsername) + throws TenantProfileServiceException { + try { + return tenantProfileRepository.getAllGatewaysForUser(requesterUsername); + } catch (Exception ex) { + logger.error("Error getting user's gateway-profiles, reason: " + ex.getMessage(), ex); + TenantProfileServiceException exception = new TenantProfileServiceException(); + exception.setMessage("Error getting user's gateway-profiles, reason: " + ex.getMessage()); + throw exception; + } + } + + private boolean checkDuplicateGateway(Gateway gateway) throws TenantProfileServiceException { + try { + Gateway duplicateGateway = tenantProfileRepository.getDuplicateGateway( + gateway.getGatewayId(), gateway.getGatewayName(), gateway.getGatewayURL()); + return duplicateGateway != null; + } catch (Exception ex) { + logger.error("Error checking if duplicate gateway-profile exists, reason: " + ex.getMessage(), ex); + TenantProfileServiceException exception = new TenantProfileServiceException(); + exception.setMessage("Error checking if duplicate gateway-profiles exists, reason: " + ex.getMessage()); + throw exception; + } + } + + // admin passwords are stored in credential store in the super portal gateway and need to be + // copied to a credential that is stored in the requested/newly created gateway + private void copyAdminPasswordToGateway(AuthzToken authzToken, Gateway gateway) + throws TException, ApplicationSettingsException { + CredentialStoreService.Client csClient = getCredentialStoreServiceClient(); + try { + String requestGatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + PasswordCredential adminPasswordCredential = + csClient.getPasswordCredential(gateway.getIdentityServerPasswordToken(), requestGatewayId); + adminPasswordCredential.setGatewayId(gateway.getGatewayId()); + String newAdminPasswordCredentialToken = csClient.addPasswordCredential(adminPasswordCredential); + gateway.setIdentityServerPasswordToken(newAdminPasswordCredentialToken); + } finally { + if (csClient.getInputProtocol().getTransport().isOpen()) { + csClient.getInputProtocol().getTransport().close(); + } + if (csClient.getOutputProtocol().getTransport().isOpen()) { + csClient.getOutputProtocol().getTransport().close(); + } + } + } + + private CredentialStoreService.Client getCredentialStoreServiceClient() + throws TException, ApplicationSettingsException { + final int serverPort = Integer.parseInt(ServerSettings.getCredentialStoreServerPort()); + final String serverHost = ServerSettings.getCredentialStoreServerHost(); + try { + return CredentialStoreClientFactory.createAiravataCSClient(serverHost, serverPort); + } catch (CredentialStoreException e) { + throw new TException("Unable to create credential store client...", e); + } + } +} + diff --git a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/TenantProfileServiceHandler.java b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/TenantProfileServiceHandler.java index 2f856cc07d..3db89e09ec 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/TenantProfileServiceHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/TenantProfileServiceHandler.java @@ -20,24 +20,9 @@ package org.apache.airavata.service.profile.handlers; import java.util.List; -import java.util.UUID; -import org.apache.airavata.common.exception.ApplicationSettingsException; -import org.apache.airavata.common.utils.Constants; -import org.apache.airavata.common.utils.DBEventService; -import org.apache.airavata.common.utils.ServerSettings; -import org.apache.airavata.credential.store.client.CredentialStoreClientFactory; -import org.apache.airavata.credential.store.cpi.CredentialStoreService; -import org.apache.airavata.credential.store.exception.CredentialStoreException; -import org.apache.airavata.messaging.core.util.DBEventPublisherUtils; -import org.apache.airavata.model.credential.store.PasswordCredential; -import org.apache.airavata.model.dbevent.CrudType; -import org.apache.airavata.model.dbevent.EntityType; import org.apache.airavata.model.error.AuthorizationException; import org.apache.airavata.model.security.AuthzToken; import org.apache.airavata.model.workspace.Gateway; -import org.apache.airavata.model.workspace.GatewayApprovalStatus; -import org.apache.airavata.service.profile.commons.tenant.entities.GatewayEntity; -import org.apache.airavata.service.profile.tenant.core.repositories.TenantProfileRepository; import org.apache.airavata.service.profile.tenant.cpi.TenantProfileService; import org.apache.airavata.service.profile.tenant.cpi.exception.TenantProfileServiceException; import org.apache.airavata.service.profile.tenant.cpi.profile_tenant_cpiConstants; @@ -52,13 +37,11 @@ public class TenantProfileServiceHandler implements TenantProfileService.Iface { private static final Logger logger = LoggerFactory.getLogger(TenantProfileServiceHandler.class); - - private TenantProfileRepository tenantProfileRepository; - private DBEventPublisherUtils dbEventPublisherUtils = new DBEventPublisherUtils(DBEventService.TENANT); + private org.apache.airavata.service.TenantProfileService tenantProfileService; public TenantProfileServiceHandler() { logger.debug("Initializing TenantProfileServiceHandler"); - this.tenantProfileRepository = new TenantProfileRepository(Gateway.class, GatewayEntity.class); + tenantProfileService = new org.apache.airavata.service.TenantProfileService(); } @Override @@ -71,32 +54,9 @@ public String getAPIVersion() throws TException { public String addGateway(AuthzToken authzToken, Gateway gateway) throws TenantProfileServiceException, AuthorizationException, TException { try { - // Assign UUID to gateway - gateway.setAiravataInternalGatewayId(UUID.randomUUID().toString()); - if (!checkDuplicateGateway(gateway)) { - // If admin password, copy it in the credential store under the requested gateway's gatewayId - if (gateway.getIdentityServerPasswordToken() != null) { - copyAdminPasswordToGateway(authzToken, gateway); - } - gateway = tenantProfileRepository.create(gateway); - if (gateway != null) { - logger.info("Added Airavata Gateway with Id: " + gateway.getGatewayId()); - // replicate tenant at end-places only if status is APPROVED - if (gateway.getGatewayApprovalStatus().equals(GatewayApprovalStatus.APPROVED)) { - logger.info( - "Gateway with ID: {}, is now APPROVED, replicating to subscribers.", - gateway.getGatewayId()); - dbEventPublisherUtils.publish(EntityType.TENANT, CrudType.CREATE, gateway); - } - // return internal id - return gateway.getAiravataInternalGatewayId(); - } else { - throw new Exception("Gateway object is null."); - } - } else { - throw new TenantProfileServiceException( - "An approved Gateway already exists with the same GatewayId, Name or URL"); - } + return tenantProfileService.addGateway(authzToken, gateway); + } catch (TenantProfileServiceException e) { + throw e; } catch (Exception ex) { logger.error("Error adding gateway-profile, reason: " + ex.getMessage(), ex); TenantProfileServiceException exception = new TenantProfileServiceException(); @@ -110,26 +70,9 @@ public String addGateway(AuthzToken authzToken, Gateway gateway) public boolean updateGateway(AuthzToken authzToken, Gateway updatedGateway) throws TenantProfileServiceException, AuthorizationException, TException { try { - - // if admin password token changes then copy the admin password and store under this gateway id and then - // update the admin password token - Gateway existingGateway = tenantProfileRepository.getGateway(updatedGateway.getAiravataInternalGatewayId()); - if (updatedGateway.getIdentityServerPasswordToken() != null - && (existingGateway.getIdentityServerPasswordToken() == null - || !existingGateway - .getIdentityServerPasswordToken() - .equals(updatedGateway.getIdentityServerPasswordToken()))) { - copyAdminPasswordToGateway(authzToken, updatedGateway); - } - - if (tenantProfileRepository.update(updatedGateway) != null) { - logger.debug("Updated gateway-profile with ID: " + updatedGateway.getGatewayId()); - // replicate tenant at end-places - dbEventPublisherUtils.publish(EntityType.TENANT, CrudType.UPDATE, updatedGateway); - return true; - } else { - return false; - } + return tenantProfileService.updateGateway(authzToken, updatedGateway); + } catch (TenantProfileServiceException e) { + throw e; } catch (Exception ex) { logger.error("Error updating gateway-profile, reason: " + ex.getMessage(), ex); TenantProfileServiceException exception = new TenantProfileServiceException(); @@ -143,11 +86,9 @@ public boolean updateGateway(AuthzToken authzToken, Gateway updatedGateway) public Gateway getGateway(AuthzToken authzToken, String airavataInternalGatewayId) throws TenantProfileServiceException, AuthorizationException, TException { try { - Gateway gateway = tenantProfileRepository.getGateway(airavataInternalGatewayId); - if (gateway == null) { - throw new Exception("Could not find Gateway with internal ID: " + airavataInternalGatewayId); - } - return gateway; + return tenantProfileService.getGateway(authzToken, airavataInternalGatewayId); + } catch (TenantProfileServiceException e) { + throw e; } catch (Exception ex) { logger.error("Error getting gateway-profile, reason: " + ex.getMessage(), ex); TenantProfileServiceException exception = new TenantProfileServiceException(); @@ -161,19 +102,9 @@ public Gateway getGateway(AuthzToken authzToken, String airavataInternalGatewayI public boolean deleteGateway(AuthzToken authzToken, String airavataInternalGatewayId, String gatewayId) throws TenantProfileServiceException, AuthorizationException, TException { try { - logger.debug("Deleting Airavata gateway-profile with ID: " + gatewayId + "Internal ID: " - + airavataInternalGatewayId); - boolean deleteSuccess = tenantProfileRepository.delete(airavataInternalGatewayId); - if (deleteSuccess) { - // delete tenant at end-places - dbEventPublisherUtils.publish( - EntityType.TENANT, - CrudType.DELETE, - // pass along gateway datamodel, with correct gatewayId; - // approvalstatus is not used for delete, hence set dummy value - new Gateway(gatewayId, GatewayApprovalStatus.DEACTIVATED)); - } - return deleteSuccess; + return tenantProfileService.deleteGateway(authzToken, airavataInternalGatewayId, gatewayId); + } catch (TenantProfileServiceException e) { + throw e; } catch (Exception ex) { logger.error("Error deleting gateway-profile, reason: " + ex.getMessage(), ex); TenantProfileServiceException exception = new TenantProfileServiceException(); @@ -187,7 +118,9 @@ public boolean deleteGateway(AuthzToken authzToken, String airavataInternalGatew public List getAllGateways(AuthzToken authzToken) throws TenantProfileServiceException, AuthorizationException, TException { try { - return tenantProfileRepository.getAllGateways(); + return tenantProfileService.getAllGateways(authzToken); + } catch (TenantProfileServiceException e) { + throw e; } catch (Exception ex) { logger.error("Error getting all gateway-profiles, reason: " + ex.getMessage(), ex); TenantProfileServiceException exception = new TenantProfileServiceException(); @@ -201,8 +134,9 @@ public List getAllGateways(AuthzToken authzToken) public boolean isGatewayExist(AuthzToken authzToken, String gatewayId) throws TenantProfileServiceException, AuthorizationException, TException { try { - Gateway gateway = tenantProfileRepository.getGateway(gatewayId); - return (gateway != null); + return tenantProfileService.isGatewayExist(authzToken, gatewayId); + } catch (TenantProfileServiceException e) { + throw e; } catch (Exception ex) { logger.error("Error checking if gateway-profile exists, reason: " + ex.getMessage(), ex); TenantProfileServiceException exception = new TenantProfileServiceException(); @@ -216,7 +150,9 @@ public boolean isGatewayExist(AuthzToken authzToken, String gatewayId) public List getAllGatewaysForUser(AuthzToken authzToken, String requesterUsername) throws TenantProfileServiceException, AuthorizationException, TException { try { - return tenantProfileRepository.getAllGatewaysForUser(requesterUsername); + return tenantProfileService.getAllGatewaysForUser(authzToken, requesterUsername); + } catch (TenantProfileServiceException e) { + throw e; } catch (Exception ex) { logger.error("Error getting user's gateway-profiles, reason: " + ex.getMessage(), ex); TenantProfileServiceException exception = new TenantProfileServiceException(); @@ -224,50 +160,4 @@ public List getAllGatewaysForUser(AuthzToken authzToken, String request throw exception; } } - - private boolean checkDuplicateGateway(Gateway gateway) throws TenantProfileServiceException { - try { - Gateway duplicateGateway = tenantProfileRepository.getDuplicateGateway( - gateway.getGatewayId(), gateway.getGatewayName(), gateway.getGatewayURL()); - return duplicateGateway != null; - } catch (Exception ex) { - logger.error("Error checking if duplicate gateway-profile exists, reason: " + ex.getMessage(), ex); - TenantProfileServiceException exception = new TenantProfileServiceException(); - exception.setMessage("Error checking if duplicate gateway-profiles exists, reason: " + ex.getMessage()); - throw exception; - } - } - - // admin passwords are stored in credential store in the super portal gateway and need to be - // copied to a credential that is stored in the requested/newly created gateway - private void copyAdminPasswordToGateway(AuthzToken authzToken, Gateway gateway) - throws TException, ApplicationSettingsException { - CredentialStoreService.Client csClient = getCredentialStoreServiceClient(); - try { - String requestGatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - PasswordCredential adminPasswordCredential = - csClient.getPasswordCredential(gateway.getIdentityServerPasswordToken(), requestGatewayId); - adminPasswordCredential.setGatewayId(gateway.getGatewayId()); - String newAdminPasswordCredentialToken = csClient.addPasswordCredential(adminPasswordCredential); - gateway.setIdentityServerPasswordToken(newAdminPasswordCredentialToken); - } finally { - if (csClient.getInputProtocol().getTransport().isOpen()) { - csClient.getInputProtocol().getTransport().close(); - } - if (csClient.getOutputProtocol().getTransport().isOpen()) { - csClient.getOutputProtocol().getTransport().close(); - } - } - } - - private CredentialStoreService.Client getCredentialStoreServiceClient() - throws TException, ApplicationSettingsException { - final int serverPort = Integer.parseInt(ServerSettings.getCredentialStoreServerPort()); - final String serverHost = ServerSettings.getCredentialStoreServerHost(); - try { - return CredentialStoreClientFactory.createAiravataCSClient(serverHost, serverPort); - } catch (CredentialStoreException e) { - throw new TException("Unable to create credential store client...", e); - } - } } From 79be600951ab091693f34234b3ca66b11f5db9dd Mon Sep 17 00:00:00 2001 From: yasithdev Date: Mon, 10 Nov 2025 18:42:41 -0500 Subject: [PATCH 11/26] update userprofileservicehandler --- .../airavata/service/UserProfileService.java | 236 ++++++++++++++++++ .../handlers/UserProfileServiceHandler.java | 151 ++--------- 2 files changed, 259 insertions(+), 128 deletions(-) create mode 100644 airavata-api/src/main/java/org/apache/airavata/service/UserProfileService.java diff --git a/airavata-api/src/main/java/org/apache/airavata/service/UserProfileService.java b/airavata-api/src/main/java/org/apache/airavata/service/UserProfileService.java new file mode 100644 index 0000000000..ea0553c13b --- /dev/null +++ b/airavata-api/src/main/java/org/apache/airavata/service/UserProfileService.java @@ -0,0 +1,236 @@ +/** +* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ +package org.apache.airavata.service; + +import java.util.List; +import org.apache.airavata.common.utils.AiravataUtils; +import org.apache.airavata.common.utils.Constants; +import org.apache.airavata.common.utils.DBEventService; +import org.apache.airavata.common.utils.ServerSettings; +import org.apache.airavata.messaging.core.util.DBEventPublisherUtils; +import org.apache.airavata.model.dbevent.CrudType; +import org.apache.airavata.model.dbevent.EntityType; +import org.apache.airavata.model.security.AuthzToken; +import org.apache.airavata.model.user.Status; +import org.apache.airavata.model.user.UserProfile; +import org.apache.airavata.security.AiravataSecurityException; +import org.apache.airavata.service.profile.client.ProfileServiceClientFactory; +import org.apache.airavata.service.profile.iam.admin.services.cpi.IamAdminServices; +import org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException; +import org.apache.airavata.service.profile.user.core.repositories.UserProfileRepository; +import org.apache.airavata.service.profile.user.cpi.exception.UserProfileServiceException; +import org.apache.airavata.service.security.AiravataSecurityManager; +import org.apache.airavata.service.security.SecurityManagerFactory; +import org.apache.airavata.service.security.UserInfo; +import org.apache.thrift.TException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class UserProfileService { + private static final Logger logger = LoggerFactory.getLogger(UserProfileService.class); + + private UserProfileRepository userProfileRepository; + private DBEventPublisherUtils dbEventPublisherUtils = new DBEventPublisherUtils(DBEventService.USER_PROFILE); + + public UserProfileService() { + userProfileRepository = new UserProfileRepository(); + } + + public String initializeUserProfile(AuthzToken authzToken) throws UserProfileServiceException { + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + try { + // Load UserInfo for the access token and create an initial UserProfile from it + UserInfo userInfo = SecurityManagerFactory.getSecurityManager().getUserInfoFromAuthzToken(authzToken); + final UserProfile existingProfile = + userProfileRepository.getUserProfileByIdAndGateWay(userInfo.getUsername(), gatewayId); + // If a user profile already exists, just return the userId + if (existingProfile != null) { + return existingProfile.getUserId(); + } + UserProfile userProfile = new UserProfile(); + userProfile.setUserId(userInfo.getUsername().toLowerCase()); + userProfile.setGatewayId(gatewayId); + userProfile.setAiravataInternalUserId(userProfile.getUserId() + "@" + gatewayId); + userProfile.addToEmails(userInfo.getEmailAddress()); + userProfile.setFirstName(userInfo.getFirstName()); + userProfile.setLastName(userInfo.getLastName()); + userProfile.setCreationTime(AiravataUtils.getCurrentTimestamp().getTime()); + userProfile.setLastAccessTime(AiravataUtils.getCurrentTimestamp().getTime()); + userProfile.setValidUntil(-1); + userProfile.setState(Status.ACTIVE); + userProfile = userProfileRepository.createUserProfile(userProfile); + if (null != userProfile) { + logger.info("Added UserProfile with userId: " + userProfile.getUserId()); + // replicate userProfile at end-places + dbEventPublisherUtils.publish(EntityType.USER_PROFILE, CrudType.CREATE, userProfile); + // return userId + return userProfile.getUserId(); + } else { + throw new Exception("User creation failed. Please try again."); + } + } catch (Exception e) { + logger.error("Error while initializing user profile", e); + UserProfileServiceException exception = new UserProfileServiceException(); + exception.setMessage("Error while initializing user profile. More info : " + e.getMessage()); + throw exception; + } + } + + public String addUserProfile(AuthzToken authzToken, UserProfile userProfile) throws UserProfileServiceException { + try { + // Lowercase user id and internal id + userProfile.setUserId(userProfile.getUserId().toLowerCase()); + userProfile.setAiravataInternalUserId(userProfile.getUserId() + "@" + userProfile.getGatewayId()); + userProfile = userProfileRepository.updateUserProfile( + userProfile, getIAMUserProfileUpdater(authzToken, userProfile)); + if (null != userProfile) { + logger.info("Added UserProfile with userId: " + userProfile.getUserId()); + // replicate userProfile at end-places + dbEventPublisherUtils.publish(EntityType.USER_PROFILE, CrudType.CREATE, userProfile); + // return userId + return userProfile.getUserId(); + } else { + throw new Exception("User creation failed. Please try again."); + } + } catch (Exception e) { + logger.error("Error while creating user profile", e); + UserProfileServiceException exception = new UserProfileServiceException(); + exception.setMessage("Error while creating user profile. More info : " + e.getMessage()); + throw exception; + } + } + + public boolean updateUserProfile(AuthzToken authzToken, UserProfile userProfile) throws UserProfileServiceException { + try { + // After updating the user profile in the database but before committing the transaction, the + // following will update the user profile in the IAM service also. If the update in the IAM service + // fails then the transaction will be rolled back. + Runnable iamUserProfileUpdater = getIAMUserProfileUpdater(authzToken, userProfile); + if (userProfileRepository.updateUserProfile(userProfile, iamUserProfileUpdater) != null) { + logger.info("Updated UserProfile with userId: " + userProfile.getUserId()); + // replicate userProfile at end-places + dbEventPublisherUtils.publish(EntityType.USER_PROFILE, CrudType.UPDATE, userProfile); + return true; + } + return false; + } catch (Exception e) { + logger.error("Error while Updating user profile", e); + UserProfileServiceException exception = new UserProfileServiceException(); + exception.setMessage("Error while Updating user profile. More info : " + e.getMessage()); + throw exception; + } + } + + private Runnable getIAMUserProfileUpdater(AuthzToken authzToken, UserProfile userProfile) + throws UserProfileServiceException { + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + return () -> { + try { + AiravataSecurityManager securityManager = SecurityManagerFactory.getSecurityManager(); + AuthzToken serviceAccountAuthzToken = + securityManager.getUserManagementServiceAccountAuthzToken(gatewayId); + IamAdminServices.Client iamAdminServicesClient = getIamAdminServicesClient(); + iamAdminServicesClient.updateUserProfile(serviceAccountAuthzToken, userProfile); + } catch (AiravataSecurityException | TException e) { + throw new RuntimeException("Failed to update user profile in IAM service", e); + } + }; + } + + public UserProfile getUserProfileById(AuthzToken authzToken, String userId, String gatewayId) + throws UserProfileServiceException { + try { + UserProfile userProfile = userProfileRepository.getUserProfileByIdAndGateWay(userId, gatewayId); + if (userProfile != null) return userProfile; + else + throw new Exception("User with userId: " + userId + ", in Gateway: " + gatewayId + ", does not exist."); + } catch (Exception e) { + logger.error("Error retrieving user profile by ID", e); + UserProfileServiceException exception = new UserProfileServiceException(); + exception.setMessage("Error retrieving user profile by ID. More info : " + e.getMessage()); + throw exception; + } + } + + public boolean deleteUserProfile(AuthzToken authzToken, String userId, String gatewayId) + throws UserProfileServiceException { + try { + // find user-profile + UserProfile userProfile = userProfileRepository.getUserProfileByIdAndGateWay(userId, gatewayId); + + // delete user + boolean deleteSuccess = userProfileRepository.delete(userId); + logger.info("Delete UserProfile with userId: " + userId + ", " + (deleteSuccess ? "Success!" : "Failed!")); + + if (deleteSuccess) { + // delete userProfile at end-places + dbEventPublisherUtils.publish(EntityType.USER_PROFILE, CrudType.DELETE, userProfile); + } + return deleteSuccess; + } catch (Exception e) { + logger.error("Error while deleting user profile", e); + UserProfileServiceException exception = new UserProfileServiceException(); + exception.setMessage("Error while deleting user profile. More info : " + e.getMessage()); + throw exception; + } + } + + public List getAllUserProfilesInGateway(AuthzToken authzToken, String gatewayId, int offset, int limit) + throws UserProfileServiceException { + try { + List usersInGateway = + userProfileRepository.getAllUserProfilesInGateway(gatewayId, offset, limit); + if (usersInGateway != null) return usersInGateway; + else throw new Exception("There are no users for the requested gatewayId: " + gatewayId); + } catch (Exception e) { + logger.error("Error while retrieving user profile List", e); + UserProfileServiceException exception = new UserProfileServiceException(); + exception.setMessage("Error while retrieving user profile List. More info : " + e.getMessage()); + throw exception; + } + } + + public boolean doesUserExist(AuthzToken authzToken, String userId, String gatewayId) + throws UserProfileServiceException { + try { + UserProfile userProfile = userProfileRepository.getUserProfileByIdAndGateWay(userId, gatewayId); + return null != userProfile; + } catch (Exception e) { + logger.error("Error while finding user profile", e); + UserProfileServiceException exception = new UserProfileServiceException(); + exception.setMessage("Error while finding user profile. More info : " + e.getMessage()); + throw exception; + } + } + + private IamAdminServices.Client getIamAdminServicesClient() throws UserProfileServiceException { + try { + final int serverPort = Integer.parseInt(ServerSettings.getProfileServiceServerPort()); + final String serverHost = ServerSettings.getProfileServiceServerHost(); + return ProfileServiceClientFactory.createIamAdminServiceClient(serverHost, serverPort); + } catch (IamAdminServicesException | org.apache.airavata.common.exception.ApplicationSettingsException e) { + logger.error("Failed to create IAM Admin Services client", e); + UserProfileServiceException ex = + new UserProfileServiceException("Failed to create IAM Admin Services client"); + throw ex; + } + } +} + diff --git a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/UserProfileServiceHandler.java b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/UserProfileServiceHandler.java index 2dec971b1b..fb4ef9a2d6 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/UserProfileServiceHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/UserProfileServiceHandler.java @@ -20,29 +20,12 @@ package org.apache.airavata.service.profile.handlers; import java.util.List; -import org.apache.airavata.common.exception.ApplicationSettingsException; -import org.apache.airavata.common.utils.AiravataUtils; -import org.apache.airavata.common.utils.Constants; -import org.apache.airavata.common.utils.DBEventService; -import org.apache.airavata.common.utils.ServerSettings; -import org.apache.airavata.messaging.core.util.DBEventPublisherUtils; -import org.apache.airavata.model.dbevent.CrudType; -import org.apache.airavata.model.dbevent.EntityType; import org.apache.airavata.model.error.AuthorizationException; import org.apache.airavata.model.security.AuthzToken; -import org.apache.airavata.model.user.Status; import org.apache.airavata.model.user.UserProfile; -import org.apache.airavata.security.AiravataSecurityException; -import org.apache.airavata.service.profile.client.ProfileServiceClientFactory; -import org.apache.airavata.service.profile.iam.admin.services.cpi.IamAdminServices; -import org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException; -import org.apache.airavata.service.profile.user.core.repositories.UserProfileRepository; import org.apache.airavata.service.profile.user.cpi.UserProfileService; import org.apache.airavata.service.profile.user.cpi.exception.UserProfileServiceException; import org.apache.airavata.service.profile.user.cpi.profile_user_cpiConstants; -import org.apache.airavata.service.security.AiravataSecurityManager; -import org.apache.airavata.service.security.SecurityManagerFactory; -import org.apache.airavata.service.security.UserInfo; import org.apache.airavata.service.security.interceptor.SecurityCheck; import org.apache.thrift.TException; import org.slf4j.Logger; @@ -51,13 +34,10 @@ public class UserProfileServiceHandler implements UserProfileService.Iface { private static final Logger logger = LoggerFactory.getLogger(UserProfileServiceHandler.class); - - private UserProfileRepository userProfileRepository; - private DBEventPublisherUtils dbEventPublisherUtils = new DBEventPublisherUtils(DBEventService.USER_PROFILE); + private org.apache.airavata.service.UserProfileService userProfileService; public UserProfileServiceHandler() { - - userProfileRepository = new UserProfileRepository(); + userProfileService = new org.apache.airavata.service.UserProfileService(); } @Override @@ -69,37 +49,10 @@ public String getAPIVersion() throws TException { @SecurityCheck public String initializeUserProfile(AuthzToken authzToken) throws UserProfileServiceException, AuthorizationException, TException { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); try { - // Load UserInfo for the access token and create an initial UserProfile from it - UserInfo userInfo = SecurityManagerFactory.getSecurityManager().getUserInfoFromAuthzToken(authzToken); - final UserProfile existingProfile = - userProfileRepository.getUserProfileByIdAndGateWay(userInfo.getUsername(), gatewayId); - // If a user profile already exists, just return the userId - if (existingProfile != null) { - return existingProfile.getUserId(); - } - UserProfile userProfile = new UserProfile(); - userProfile.setUserId(userInfo.getUsername().toLowerCase()); - userProfile.setGatewayId(gatewayId); - userProfile.setAiravataInternalUserId(userProfile.getUserId() + "@" + gatewayId); - userProfile.addToEmails(userInfo.getEmailAddress()); - userProfile.setFirstName(userInfo.getFirstName()); - userProfile.setLastName(userInfo.getLastName()); - userProfile.setCreationTime(AiravataUtils.getCurrentTimestamp().getTime()); - userProfile.setLastAccessTime(AiravataUtils.getCurrentTimestamp().getTime()); - userProfile.setValidUntil(-1); - userProfile.setState(Status.ACTIVE); - userProfile = userProfileRepository.createUserProfile(userProfile); - if (null != userProfile) { - logger.info("Added UserProfile with userId: " + userProfile.getUserId()); - // replicate userProfile at end-places - dbEventPublisherUtils.publish(EntityType.USER_PROFILE, CrudType.CREATE, userProfile); - // return userId - return userProfile.getUserId(); - } else { - throw new Exception("User creation failed. Please try again."); - } + return userProfileService.initializeUserProfile(authzToken); + } catch (UserProfileServiceException e) { + throw e; } catch (Exception e) { logger.error("Error while initializing user profile", e); UserProfileServiceException exception = new UserProfileServiceException(); @@ -113,20 +66,9 @@ public String initializeUserProfile(AuthzToken authzToken) public String addUserProfile(AuthzToken authzToken, UserProfile userProfile) throws UserProfileServiceException, AuthorizationException, TException { try { - // Lowercase user id and internal id - userProfile.setUserId(userProfile.getUserId().toLowerCase()); - userProfile.setAiravataInternalUserId(userProfile.getUserId() + "@" + userProfile.getGatewayId()); - userProfile = userProfileRepository.updateUserProfile( - userProfile, getIAMUserProfileUpdater(authzToken, userProfile)); - if (null != userProfile) { - logger.info("Added UserProfile with userId: " + userProfile.getUserId()); - // replicate userProfile at end-places - dbEventPublisherUtils.publish(EntityType.USER_PROFILE, CrudType.CREATE, userProfile); - // return userId - return userProfile.getUserId(); - } else { - throw new Exception("User creation failed. Please try again."); - } + return userProfileService.addUserProfile(authzToken, userProfile); + } catch (UserProfileServiceException e) { + throw e; } catch (Exception e) { logger.error("Error while creating user profile", e); UserProfileServiceException exception = new UserProfileServiceException(); @@ -140,17 +82,9 @@ public String addUserProfile(AuthzToken authzToken, UserProfile userProfile) public boolean updateUserProfile(AuthzToken authzToken, UserProfile userProfile) throws UserProfileServiceException, AuthorizationException, TException { try { - // After updating the user profile in the database but before committing the transaction, the - // following will update the user profile in the IAM service also. If the update in the IAM service - // fails then the transaction will be rolled back. - Runnable iamUserProfileUpdater = getIAMUserProfileUpdater(authzToken, userProfile); - if (userProfileRepository.updateUserProfile(userProfile, iamUserProfileUpdater) != null) { - logger.info("Updated UserProfile with userId: " + userProfile.getUserId()); - // replicate userProfile at end-places - dbEventPublisherUtils.publish(EntityType.USER_PROFILE, CrudType.UPDATE, userProfile); - return true; - } - return false; + return userProfileService.updateUserProfile(authzToken, userProfile); + } catch (UserProfileServiceException e) { + throw e; } catch (Exception e) { logger.error("Error while Updating user profile", e); UserProfileServiceException exception = new UserProfileServiceException(); @@ -159,31 +93,14 @@ public boolean updateUserProfile(AuthzToken authzToken, UserProfile userProfile) } } - private Runnable getIAMUserProfileUpdater(AuthzToken authzToken, UserProfile userProfile) - throws UserProfileServiceException { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - return () -> { - try { - AiravataSecurityManager securityManager = SecurityManagerFactory.getSecurityManager(); - AuthzToken serviceAccountAuthzToken = - securityManager.getUserManagementServiceAccountAuthzToken(gatewayId); - IamAdminServices.Client iamAdminServicesClient = getIamAdminServicesClient(); - iamAdminServicesClient.updateUserProfile(serviceAccountAuthzToken, userProfile); - } catch (AiravataSecurityException | TException e) { - throw new RuntimeException("Failed to update user profile in IAM service", e); - } - }; - } - @Override @SecurityCheck public UserProfile getUserProfileById(AuthzToken authzToken, String userId, String gatewayId) throws UserProfileServiceException, AuthorizationException, TException { try { - UserProfile userProfile = userProfileRepository.getUserProfileByIdAndGateWay(userId, gatewayId); - if (userProfile != null) return userProfile; - else - throw new Exception("User with userId: " + userId + ", in Gateway: " + gatewayId + ", does not exist."); + return userProfileService.getUserProfileById(authzToken, userId, gatewayId); + } catch (UserProfileServiceException e) { + throw e; } catch (Exception e) { logger.error("Error retrieving user profile by ID", e); UserProfileServiceException exception = new UserProfileServiceException(); @@ -197,18 +114,9 @@ public UserProfile getUserProfileById(AuthzToken authzToken, String userId, Stri public boolean deleteUserProfile(AuthzToken authzToken, String userId, String gatewayId) throws UserProfileServiceException, AuthorizationException, TException { try { - // find user-profile - UserProfile userProfile = userProfileRepository.getUserProfileByIdAndGateWay(userId, gatewayId); - - // delete user - boolean deleteSuccess = userProfileRepository.delete(userId); - logger.info("Delete UserProfile with userId: " + userId + ", " + (deleteSuccess ? "Success!" : "Failed!")); - - if (deleteSuccess) { - // delete userProfile at end-places - dbEventPublisherUtils.publish(EntityType.USER_PROFILE, CrudType.DELETE, userProfile); - } - return deleteSuccess; + return userProfileService.deleteUserProfile(authzToken, userId, gatewayId); + } catch (UserProfileServiceException e) { + throw e; } catch (Exception e) { logger.error("Error while deleting user profile", e); UserProfileServiceException exception = new UserProfileServiceException(); @@ -222,10 +130,9 @@ public boolean deleteUserProfile(AuthzToken authzToken, String userId, String ga public List getAllUserProfilesInGateway(AuthzToken authzToken, String gatewayId, int offset, int limit) throws UserProfileServiceException, AuthorizationException, TException { try { - List usersInGateway = - userProfileRepository.getAllUserProfilesInGateway(gatewayId, offset, limit); - if (usersInGateway != null) return usersInGateway; - else throw new Exception("There are no users for the requested gatewayId: " + gatewayId); + return userProfileService.getAllUserProfilesInGateway(authzToken, gatewayId, offset, limit); + } catch (UserProfileServiceException e) { + throw e; } catch (Exception e) { logger.error("Error while retrieving user profile List", e); UserProfileServiceException exception = new UserProfileServiceException(); @@ -238,8 +145,9 @@ public List getAllUserProfilesInGateway(AuthzToken authzToken, Stri public boolean doesUserExist(AuthzToken authzToken, String userId, String gatewayId) throws UserProfileServiceException, AuthorizationException, TException { try { - UserProfile userProfile = userProfileRepository.getUserProfileByIdAndGateWay(userId, gatewayId); - return null != userProfile; + return userProfileService.doesUserExist(authzToken, userId, gatewayId); + } catch (UserProfileServiceException e) { + throw e; } catch (Exception e) { logger.error("Error while finding user profile", e); UserProfileServiceException exception = new UserProfileServiceException(); @@ -247,17 +155,4 @@ public boolean doesUserExist(AuthzToken authzToken, String userId, String gatewa throw exception; } } - - private IamAdminServices.Client getIamAdminServicesClient() throws UserProfileServiceException { - try { - final int serverPort = Integer.parseInt(ServerSettings.getProfileServiceServerPort()); - final String serverHost = ServerSettings.getProfileServiceServerHost(); - return ProfileServiceClientFactory.createIamAdminServiceClient(serverHost, serverPort); - } catch (IamAdminServicesException | ApplicationSettingsException e) { - logger.error("Failed to create IAM Admin Services client", e); - UserProfileServiceException ex = - new UserProfileServiceException("Failed to create IAM Admin Services client"); - throw ex; - } - } } From 00dbd243e262c2709ea3c42c27b375d24f39ed09 Mon Sep 17 00:00:00 2001 From: yasithdev Date: Wed, 12 Nov 2025 13:28:48 -0500 Subject: [PATCH 12/26] fix airavataserverhandler bugs --- .../server/handler/AiravataServerHandler.java | 62 +------------------ 1 file changed, 2 insertions(+), 60 deletions(-) diff --git a/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java index ff0ee33b2c..41d7166cb0 100644 --- a/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java @@ -3093,7 +3093,6 @@ public boolean deleteStorageResource(AuthzToken authzToken, String storageResour AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage("Error while deleting storage resource. More info : " + e.getMessage()); - registryClientPool.returnBrokenResource(regClient); throw exception; } } @@ -6687,45 +6686,12 @@ public List listAllParsingTemplates(AuthzToken authzToken, Stri } } - private void submitExperiment(String gatewayId, String experimentId) throws AiravataException { - ExperimentSubmitEvent event = new ExperimentSubmitEvent(experimentId, gatewayId); - MessageContext messageContext = new MessageContext( - event, MessageType.EXPERIMENT, "LAUNCH.EXP-" + UUID.randomUUID().toString(), gatewayId); - messageContext.setUpdatedTime(AiravataUtils.getCurrentTimestamp()); - experimentPublisher.publish(messageContext); - } - - private void submitCancelExperiment(String gatewayId, String experimentId) throws AiravataException { - ExperimentSubmitEvent event = new ExperimentSubmitEvent(experimentId, gatewayId); - MessageContext messageContext = new MessageContext( - event, - MessageType.EXPERIMENT_CANCEL, - "CANCEL.EXP-" + UUID.randomUUID().toString(), - gatewayId); - messageContext.setUpdatedTime(AiravataUtils.getCurrentTimestamp()); - experimentPublisher.publish(messageContext); - } - - private void submitExperimentIntermediateOutputsEvent( - String gatewayId, String experimentId, List outputNames) throws AiravataException { - - ExperimentIntermediateOutputsEvent event = - new ExperimentIntermediateOutputsEvent(experimentId, gatewayId, outputNames); - MessageContext messageContext = new MessageContext( - event, - MessageType.INTERMEDIATE_OUTPUTS, - "INTERMEDIATE_OUTPUTS.EXP-" + UUID.randomUUID().toString(), - gatewayId); - messageContext.setUpdatedTime(AiravataUtils.getCurrentTimestamp()); - experimentPublisher.publish(messageContext); - } - private void shareEntityWithAdminGatewayGroups( RegistryService.Client regClient, SharingRegistryService.Client sharingClient, Entity entity) throws TException { final String domainId = entity.getDomainId(); - GatewayGroups gatewayGroups = retrieveGatewayGroups(regClient, domainId); - createManageSharingPermissionTypeIfMissing(sharingClient, domainId); + GatewayGroups gatewayGroups = airavataService.retrieveGatewayGroups(domainId); + airavataService.createManageSharingPermissionTypeIfMissing(sharingClient, domainId); sharingClient.shareEntityWithGroups( domainId, entity.getEntityId(), @@ -6789,30 +6755,6 @@ private ResourceType getResourceType(SharingRegistryService.Client sharingClient throw new RuntimeException("Unrecognized entity type id: " + entity.getEntityTypeId()); } - private void createManageSharingPermissionTypeIfMissing( - SharingRegistryService.Client sharingClient, String domainId) throws TException { - // AIRAVATA-3297 Some gateways were created without the MANAGE_SHARING permission, so add it if missing - String permissionTypeId = domainId + ":MANAGE_SHARING"; - if (!sharingClient.isPermissionExists(domainId, permissionTypeId)) { - PermissionType permissionType = new PermissionType(); - permissionType.setPermissionTypeId(permissionTypeId); - permissionType.setDomainId(domainId); - permissionType.setName("MANAGE_SHARING"); - permissionType.setDescription("Manage sharing permission type"); - sharingClient.createPermissionType(permissionType); - logger.info("Created MANAGE_SHARING permission type for domain " + domainId); - } - } - - private GatewayGroups retrieveGatewayGroups(RegistryService.Client regClient, String gatewayId) throws TException { - - if (regClient.isGatewayGroupsExists(gatewayId)) { - return regClient.getGatewayGroups(gatewayId); - } else { - return GatewayGroupsInitializer.initializeGatewayGroups(gatewayId); - } - } - /** * To hold storage info context (login username, credential token, and adaptor) */ From dc64fb2b9326865d4a6b692df93f08d5e71e68a7 Mon Sep 17 00:00:00 2001 From: yasithdev Date: Thu, 13 Nov 2025 10:48:49 -0500 Subject: [PATCH 13/26] fix error in airavataserverhandler --- .../server/handler/AiravataServerHandler.java | 75 +------------------ 1 file changed, 3 insertions(+), 72 deletions(-) diff --git a/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java index 41d7166cb0..f645822bfb 100644 --- a/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java @@ -19,6 +19,7 @@ */ package org.apache.airavata.api.server.handler; +import java.time.Duration; import java.util.*; import java.util.stream.Collectors; import org.apache.airavata.accountprovisioning.ConfigParam; @@ -37,7 +38,6 @@ import org.apache.airavata.common.utils.ThriftClientPool; import org.apache.airavata.credential.store.cpi.CredentialStoreService; import org.apache.airavata.helix.core.support.adaptor.AdaptorSupportImpl; -import org.apache.airavata.messaging.core.MessageContext; import org.apache.airavata.messaging.core.MessagingFactory; import org.apache.airavata.messaging.core.Publisher; import org.apache.airavata.messaging.core.Type; @@ -147,9 +147,9 @@ private GenericObjectPoolConfig createGenericObjectPoolConfig() { poolConfig.setTestOnBorrow(true); poolConfig.setTestWhileIdle(true); // must set timeBetweenEvictionRunsMillis since eviction doesn't run unless that is positive - poolConfig.setTimeBetweenEvictionRunsMillis(5L * 60L * 1000L); + poolConfig.setTimeBetweenEvictionRuns(Duration.ofMinutes(5)); poolConfig.setNumTestsPerEvictionRun(10); - poolConfig.setMaxWaitMillis(3000); + poolConfig.setMaxWait(Duration.ofSeconds(3)); return poolConfig; } @@ -6686,75 +6686,6 @@ public List listAllParsingTemplates(AuthzToken authzToken, Stri } } - private void shareEntityWithAdminGatewayGroups( - RegistryService.Client regClient, SharingRegistryService.Client sharingClient, Entity entity) - throws TException { - final String domainId = entity.getDomainId(); - GatewayGroups gatewayGroups = airavataService.retrieveGatewayGroups(domainId); - airavataService.createManageSharingPermissionTypeIfMissing(sharingClient, domainId); - sharingClient.shareEntityWithGroups( - domainId, - entity.getEntityId(), - Arrays.asList(gatewayGroups.getAdminsGroupId()), - domainId + ":MANAGE_SHARING", - true); - sharingClient.shareEntityWithGroups( - domainId, - entity.getEntityId(), - Arrays.asList(gatewayGroups.getAdminsGroupId()), - domainId + ":WRITE", - true); - sharingClient.shareEntityWithGroups( - domainId, - entity.getEntityId(), - Arrays.asList(gatewayGroups.getAdminsGroupId(), gatewayGroups.getReadOnlyAdminsGroupId()), - domainId + ":READ", - true); - } - - private boolean userHasAccessInternal( - SharingRegistryService.Client sharingClient, - AuthzToken authzToken, - String entityId, - ResourcePermissionType permissionType) { - final String domainId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - final String userId = authzToken.getClaimsMap().get(Constants.USER_NAME) + "@" + domainId; - try { - final boolean hasOwnerAccess = sharingClient.userHasAccess( - domainId, userId, entityId, domainId + ":" + ResourcePermissionType.OWNER); - boolean hasAccess = false; - if (permissionType.equals(ResourcePermissionType.WRITE)) { - hasAccess = hasOwnerAccess - || sharingClient.userHasAccess( - domainId, userId, entityId, domainId + ":" + ResourcePermissionType.WRITE); - } else if (permissionType.equals(ResourcePermissionType.READ)) { - hasAccess = hasOwnerAccess - || sharingClient.userHasAccess( - domainId, userId, entityId, domainId + ":" + ResourcePermissionType.READ); - } else if (permissionType.equals(ResourcePermissionType.MANAGE_SHARING)) { - hasAccess = hasOwnerAccess - || sharingClient.userHasAccess( - domainId, userId, entityId, domainId + ":" + ResourcePermissionType.MANAGE_SHARING); - } else if (permissionType.equals(ResourcePermissionType.OWNER)) { - hasAccess = hasOwnerAccess; - } - return hasAccess; - } catch (Exception e) { - throw new RuntimeException("Unable to check if user has access", e); - } - } - - private ResourceType getResourceType(SharingRegistryService.Client sharingClient, String domainId, String entityId) - throws TException { - Entity entity = sharingClient.getEntity(domainId, entityId); - for (ResourceType resourceType : ResourceType.values()) { - if (entity.getEntityTypeId().equals(domainId + ":" + resourceType.name())) { - return resourceType; - } - } - throw new RuntimeException("Unrecognized entity type id: " + entity.getEntityTypeId()); - } - /** * To hold storage info context (login username, credential token, and adaptor) */ From c7153fdda2586a72b61631712e9a19dc269f23d9 Mon Sep 17 00:00:00 2001 From: yasithdev Date: Fri, 14 Nov 2025 16:59:48 -0500 Subject: [PATCH 14/26] run spotless:apply --- .../server/handler/AiravataServerHandler.java | 146 ++-- .../server/CredentialStoreServerHandler.java | 5 +- .../server/OrchestratorServerHandler.java | 41 +- .../handler/RegistryServerHandler.java | 108 ++- .../airavata/service/AiravataService.java | 668 +++++++++++------- .../service/CredentialStoreService.java | 40 +- .../airavata/service/GroupManagerService.java | 4 +- .../airavata/service/IamAdminService.java | 4 +- .../service/OrchestratorRegistryService.java | 9 +- .../airavata/service/OrchestratorService.java | 100 ++- .../airavata/service/RegistryService.java | 406 ++++++----- .../service/SharingRegistryService.java | 32 +- .../service/TenantProfileService.java | 1 - .../airavata/service/UserProfileService.java | 4 +- .../server/SharingRegistryServerHandler.java | 14 +- 15 files changed, 897 insertions(+), 685 deletions(-) diff --git a/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java index f645822bfb..acbf591e14 100644 --- a/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java @@ -104,7 +104,8 @@ public class AiravataServerHandler implements Airavata.Iface { private ThriftClientPool sharingClientPool; private ThriftClientPool registryClientPool; private ThriftClientPool csClientPool; - private org.apache.airavata.service.AiravataService airavataService = new org.apache.airavata.service.AiravataService(); + private org.apache.airavata.service.AiravataService airavataService = + new org.apache.airavata.service.AiravataService(); public AiravataServerHandler() { try { @@ -563,7 +564,8 @@ public String generateAndRegisterSSHKeys(AuthzToken authzToken, String descripti SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); RegistryService.Client regClient = registryClientPool.getResource(); try { - String key = airavataService.generateAndRegisterSSHKeys(csClient, sharingClient, gatewayId, userName, description); + String key = airavataService.generateAndRegisterSSHKeys( + csClient, sharingClient, gatewayId, userName, description); csClientPool.returnResource(csClient); sharingClientPool.returnResource(sharingClient); registryClientPool.returnResource(regClient); @@ -599,7 +601,8 @@ public String registerPwdCredential( CredentialStoreService.Client csClient = csClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { - String key = airavataService.registerPwdCredential(csClient, sharingClient, gatewayId, userName, loginUserName, password, description); + String key = airavataService.registerPwdCredential( + csClient, sharingClient, gatewayId, userName, loginUserName, password, description); csClientPool.returnResource(csClient); sharingClientPool.returnResource(sharingClient); return key; @@ -631,7 +634,8 @@ public CredentialSummary getCredentialSummary(AuthzToken authzToken, String toke SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); try { - CredentialSummary credentialSummary = airavataService.getCredentialSummaryWithAuth(csClient, sharingClient, authzToken, tokenId, gatewayId); + CredentialSummary credentialSummary = airavataService.getCredentialSummaryWithAuth( + csClient, sharingClient, authzToken, tokenId, gatewayId); csClientPool.returnResource(csClient); sharingClientPool.returnResource(sharingClient); return credentialSummary; @@ -662,8 +666,8 @@ public List getAllCredentialSummaries(AuthzToken authzToken, String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); try { - List credentialSummaries = - airavataService.getAllCredentialSummariesWithAuth(csClient, sharingClient, authzToken, type, gatewayId, userName); + List credentialSummaries = airavataService.getAllCredentialSummariesWithAuth( + csClient, sharingClient, authzToken, type, gatewayId, userName); csClientPool.returnResource(csClient); sharingClientPool.returnResource(sharingClient); return credentialSummaries; @@ -694,7 +698,8 @@ public boolean deleteSSHPubKey(AuthzToken authzToken, String airavataCredStoreTo SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); try { - boolean result = airavataService.deleteSSHPubKey(csClient, sharingClient, authzToken, airavataCredStoreToken, gatewayId); + boolean result = airavataService.deleteSSHPubKey( + csClient, sharingClient, authzToken, airavataCredStoreToken, gatewayId); csClientPool.returnResource(csClient); sharingClientPool.returnResource(sharingClient); return result; @@ -725,7 +730,8 @@ public boolean deletePWDCredential(AuthzToken authzToken, String airavataCredSto SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); try { - boolean result = airavataService.deletePWDCredentialWithAuth(csClient, sharingClient, authzToken, airavataCredStoreToken, gatewayId); + boolean result = airavataService.deletePWDCredentialWithAuth( + csClient, sharingClient, authzToken, airavataCredStoreToken, gatewayId); csClientPool.returnResource(csClient); sharingClientPool.returnResource(sharingClient); return result; @@ -791,7 +797,9 @@ public void updateProject(AuthzToken authzToken, String projectId, Project updat airavataService.updateProjectWithAuth(sharingClient, authzToken, projectId, updatedProject); sharingClientPool.returnResource(sharingClient); } catch (Exception e) { - if (e.getMessage() != null && (e.getMessage().contains("does not have permission") || e.getMessage().contains("cannot be changed"))) { + if (e.getMessage() != null + && (e.getMessage().contains("does not have permission") + || e.getMessage().contains("cannot be changed"))) { if (e.getMessage().contains("cannot be changed")) { sharingClientPool.returnResource(sharingClient); throw new InvalidRequestException(e.getMessage()); @@ -967,7 +975,8 @@ public List searchProjects( if (accessibleProjIds.isEmpty()) { result = Collections.emptyList(); } else { - result = airavataService.searchProjects(gatewayId, userName, accessibleProjIds, filters, limit, offset); + result = airavataService.searchProjects( + gatewayId, userName, accessibleProjIds, filters, limit, offset); } } else { result = airavataService.searchProjects(gatewayId, userName, accessibleProjIds, filters, limit, offset); @@ -1652,8 +1661,9 @@ public void fetchIntermediateOutputs(AuthzToken authzToken, String airavataExper logger.error(e.getMessage(), e); sharingClientPool.returnResource(sharingClient); throw new AuthorizationException(e.getMessage()); - } else if (e.getMessage() != null && (e.getMessage().contains("does not have currently ACTIVE job") - || e.getMessage().contains("already intermediate output fetching tasks"))) { + } else if (e.getMessage() != null + && (e.getMessage().contains("does not have currently ACTIVE job") + || e.getMessage().contains("already intermediate output fetching tasks"))) { logger.error(e.getMessage(), e); sharingClientPool.returnResource(sharingClient); throw new InvalidRequestException(e.getMessage()); @@ -1992,7 +2002,8 @@ private String cloneExperimentInternal( .getResourceHostId(); try { - ComputeResourceDescription computeResourceDescription = airavataService.getComputeResource(compResourceId); + ComputeResourceDescription computeResourceDescription = + airavataService.getComputeResource(compResourceId); if (!computeResourceDescription.isEnabled()) { existingExperiment.getUserConfigurationData().setComputationalResourceScheduling(null); } @@ -2244,8 +2255,8 @@ public List getAccessibleAppModules(AuthzToken authzToken, St TException { SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { - List result = airavataService.getAccessibleAppModulesWithSharing( - sharingClient, authzToken, gatewayId); + List result = + airavataService.getAccessibleAppModulesWithSharing(sharingClient, authzToken, gatewayId); sharingClientPool.returnResource(sharingClient); return result; } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { @@ -2349,8 +2360,8 @@ public ApplicationDeploymentDescription getApplicationDeployment(AuthzToken auth SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { if (ServerSettings.isEnableSharing()) { - final boolean hasAccess = - airavataService.userHasAccessInternal(sharingClient, authzToken, appDeploymentId, ResourcePermissionType.READ); + final boolean hasAccess = airavataService.userHasAccessInternal( + sharingClient, authzToken, appDeploymentId, ResourcePermissionType.READ); if (!hasAccess) { throw new AuthorizationException( "User does not have access to application deployment " + appDeploymentId); @@ -2386,8 +2397,8 @@ public boolean updateApplicationDeployment( SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { if (ServerSettings.isEnableSharing()) { - final boolean hasAccess = - airavataService.userHasAccessInternal(sharingClient, authzToken, appDeploymentId, ResourcePermissionType.WRITE); + final boolean hasAccess = airavataService.userHasAccessInternal( + sharingClient, authzToken, appDeploymentId, ResourcePermissionType.WRITE); if (!hasAccess) { throw new AuthorizationException( "User does not have WRITE access to application deployment " + appDeploymentId); @@ -2420,8 +2431,8 @@ public boolean deleteApplicationDeployment(AuthzToken authzToken, String appDepl TException { SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { - final boolean hasAccess = - airavataService.userHasAccessInternal(sharingClient, authzToken, appDeploymentId, ResourcePermissionType.WRITE); + final boolean hasAccess = airavataService.userHasAccessInternal( + sharingClient, authzToken, appDeploymentId, ResourcePermissionType.WRITE); if (!hasAccess) { throw new AuthorizationException( "User does not have WRITE access to application deployment " + appDeploymentId); @@ -2469,8 +2480,9 @@ public List getAccessibleApplicationDeployment TException { SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { - List result = airavataService.getAccessibleApplicationDeploymentsWithSharing( - sharingClient, authzToken, gatewayId, permissionType); + List result = + airavataService.getAccessibleApplicationDeploymentsWithSharing( + sharingClient, authzToken, gatewayId, permissionType); sharingClientPool.returnResource(sharingClient); return result; } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { @@ -2573,8 +2585,9 @@ public List getApplicationDeploymentsForAppMod .searchEntities(gatewayId, userName + "@" + gatewayId, sharingFilters, 0, -1) .forEach(a -> accessibleAppDeploymentIds.add(a.getEntityId())); - List result = airavataService.getAccessibleApplicationDeploymentsForAppModule( - appModuleId, gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); + List result = + airavataService.getAccessibleApplicationDeploymentsForAppModule( + appModuleId, gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); sharingClientPool.returnResource(sharingClient); return result; } catch (AuthorizationException checkedException) { @@ -3264,7 +3277,8 @@ public String addLocalSubmissionDetails( throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { try { - String result = airavataService.addLocalSubmissionDetails(computeResourceId, priorityOrder, localSubmission); + String result = + airavataService.addLocalSubmissionDetails(computeResourceId, priorityOrder, localSubmission); return result; } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { logger.error( @@ -3375,7 +3389,8 @@ public String addSSHJobSubmissionDetails( throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { try { - String result = airavataService.addSSHJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); + String result = + airavataService.addSSHJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); return result; } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { logger.error( @@ -3552,8 +3567,8 @@ public String addUNICOREJobSubmissionDetails( throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { try { - String result = - airavataService.addUNICOREJobSubmissionDetails(computeResourceId, priorityOrder, unicoreJobSubmission); + String result = airavataService.addUNICOREJobSubmissionDetails( + computeResourceId, priorityOrder, unicoreJobSubmission); return result; } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { logger.error("Error while adding job submission interface to resource compute resource...", e); @@ -3656,7 +3671,8 @@ public boolean updateCloudJobSubmissionDetails( throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { try { - boolean result = airavataService.updateCloudJobSubmissionDetails(jobSubmissionInterfaceId, cloudJobSubmission); + boolean result = + airavataService.updateCloudJobSubmissionDetails(jobSubmissionInterfaceId, cloudJobSubmission); return result; } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { logger.error( @@ -3739,7 +3755,8 @@ public String addLocalDataMovementDetails( throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { try { - String result = airavataService.addLocalDataMovementDetails(resourceId, dmType, priorityOrder, localDataMovement); + String result = + airavataService.addLocalDataMovementDetails(resourceId, dmType, priorityOrder, localDataMovement); return result; } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { logger.error(resourceId, "Error while adding data movement interface to resource resource...", e); @@ -3832,7 +3849,8 @@ public String addSCPDataMovementDetails( throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { try { - String result = airavataService.addSCPDataMovementDetails(resourceId, dmType, priorityOrder, scpDataMovement); + String result = + airavataService.addSCPDataMovementDetails(resourceId, dmType, priorityOrder, scpDataMovement); return result; } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { logger.error(resourceId, "Error while adding data movement interface to resource compute resource...", e); @@ -3930,8 +3948,8 @@ public String addUnicoreDataMovementDetails( throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { try { - String result = - airavataService.addUnicoreDataMovementDetails(resourceId, dmType, priorityOrder, unicoreDataMovement); + String result = airavataService.addUnicoreDataMovementDetails( + resourceId, dmType, priorityOrder, unicoreDataMovement); return result; } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { logger.error(resourceId, "Error while adding data movement interface to resource compute resource...", e); @@ -3957,7 +3975,8 @@ public boolean updateUnicoreDataMovementDetails( throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { try { - boolean result = airavataService.updateUnicoreDataMovementDetails(dataMovementInterfaceId, unicoreDataMovement); + boolean result = + airavataService.updateUnicoreDataMovementDetails(dataMovementInterfaceId, unicoreDataMovement); return result; } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { logger.error( @@ -4062,7 +4081,8 @@ public boolean updateGridFTPDataMovementDetails( throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { try { - boolean result = airavataService.updateGridFTPDataMovementDetails(dataMovementInterfaceId, gridFTPDataMovement); + boolean result = + airavataService.updateGridFTPDataMovementDetails(dataMovementInterfaceId, gridFTPDataMovement); return result; } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { logger.error( @@ -4505,7 +4525,8 @@ public boolean addGatewayStoragePreference( throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { try { - boolean result = airavataService.addGatewayStoragePreference(gatewayID, storageResourceId, dataStoragePreference); + boolean result = + airavataService.addGatewayStoragePreference(gatewayID, storageResourceId, dataStoragePreference); return result; } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { logger.error(gatewayID, "Error while registering gateway resource profile preference...", e); @@ -4705,7 +4726,8 @@ public boolean updateGatewayStoragePreference( throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { try { - boolean result = airavataService.updateGatewayStoragePreference(gatewayID, storageId, dataStoragePreference); + boolean result = + airavataService.updateGatewayStoragePreference(gatewayID, storageId, dataStoragePreference); return result; } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { logger.error(gatewayID, "Error while updating gateway data storage preference...", e); @@ -5093,8 +5115,8 @@ public boolean addUserStoragePreference( throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { try { - boolean result = - airavataService.addUserStoragePreference(userId, gatewayID, userStorageResourceId, dataStoragePreference); + boolean result = airavataService.addUserStoragePreference( + userId, gatewayID, userStorageResourceId, dataStoragePreference); return result; } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { logger.error(userId, "Error while registering user storage preference...", e); @@ -5303,8 +5325,8 @@ public boolean updateUserStoragePreference( throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { try { - boolean result = - airavataService.updateUserStoragePreference(userId, gatewayID, userStorageId, dataStoragePreference); + boolean result = airavataService.updateUserStoragePreference( + userId, gatewayID, userStorageId, dataStoragePreference); return result; } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { logger.error(userId, "Error while updating user data storage preference...", e); @@ -5337,7 +5359,8 @@ public boolean deleteUserComputeResourcePreference( throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { try { - boolean result = airavataService.deleteUserComputeResourcePreference(userId, gatewayID, userComputeResourceId); + boolean result = + airavataService.deleteUserComputeResourcePreference(userId, gatewayID, userComputeResourceId); return result; } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { logger.error(userId, "Error while deleting user compute resource preference...", e); @@ -5505,7 +5528,8 @@ public boolean shareResourceWithUsers( RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { - if (!airavataService.userHasAccessInternal(sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER) + if (!airavataService.userHasAccessInternal( + sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER) && !airavataService.userHasAccessInternal( sharingClient, authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { throw new AuthorizationException( @@ -5528,7 +5552,8 @@ else if (userPermission.getValue().equals(ResourcePermissionType.READ)) authzToken.getClaimsMap().get(Constants.GATEWAY_ID) + ":" + "READ", true); else if (userPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING)) { - if (airavataService.userHasAccessInternal(sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER)) { + if (airavataService.userHasAccessInternal( + sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER)) { airavataService.createManageSharingPermissionTypeIfMissing(sharingClient, gatewayId); sharingClient.shareEntityWithUsers( gatewayId, @@ -5568,7 +5593,8 @@ public boolean shareResourceWithGroups( RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { - if (!airavataService.userHasAccessInternal(sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER) + if (!airavataService.userHasAccessInternal( + sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER) && !airavataService.userHasAccessInternal( sharingClient, authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { throw new AuthorizationException( @@ -5591,7 +5617,8 @@ else if (groupPermission.getValue().equals(ResourcePermissionType.READ)) authzToken.getClaimsMap().get(Constants.GATEWAY_ID) + ":" + "READ", true); else if (groupPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING)) { - if (airavataService.userHasAccessInternal(sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER)) { + if (airavataService.userHasAccessInternal( + sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER)) { airavataService.createManageSharingPermissionTypeIfMissing(sharingClient, gatewayId); sharingClient.shareEntityWithGroups( gatewayId, @@ -5631,7 +5658,8 @@ public boolean revokeSharingOfResourceFromUsers( RegistryService.Client regClient = registryClientPool.getResource(); SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { - if (!airavataService.userHasAccessInternal(sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER) + if (!airavataService.userHasAccessInternal( + sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER) && !airavataService.userHasAccessInternal( sharingClient, authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { throw new AuthorizationException( @@ -5652,7 +5680,8 @@ else if (userPermission.getValue().equals(ResourcePermissionType.READ)) Arrays.asList(userPermission.getKey()), authzToken.getClaimsMap().get(Constants.GATEWAY_ID) + ":" + "READ"); else if (userPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING)) { - if (airavataService.userHasAccessInternal(sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER)) { + if (airavataService.userHasAccessInternal( + sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER)) { airavataService.createManageSharingPermissionTypeIfMissing(sharingClient, gatewayId); sharingClient.revokeEntitySharingFromUsers( gatewayId, @@ -5692,7 +5721,8 @@ public boolean revokeSharingOfResourceFromGroups( SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); final String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); try { - if (!airavataService.userHasAccessInternal(sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER) + if (!airavataService.userHasAccessInternal( + sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER) && !airavataService.userHasAccessInternal( sharingClient, authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { throw new AuthorizationException( @@ -5738,7 +5768,8 @@ else if (groupPermission.getValue().equals(ResourcePermissionType.READ)) sharingClient.revokeEntitySharingFromUsers( gatewayId, resourceId, Arrays.asList(groupPermission.getKey()), gatewayId + ":" + "READ"); else if (groupPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING)) { - if (airavataService.userHasAccessInternal(sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER)) { + if (airavataService.userHasAccessInternal( + sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER)) { airavataService.createManageSharingPermissionTypeIfMissing(sharingClient, gatewayId); sharingClient.revokeEntitySharingFromUsers( gatewayId, @@ -5865,7 +5896,8 @@ public boolean userHasAccess(AuthzToken authzToken, String resourceId, ResourceP final String userId = authzToken.getClaimsMap().get(Constants.USER_NAME) + "@" + domainId; SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { - final boolean hasAccess = airavataService.userHasAccessInternal(sharingClient, authzToken, resourceId, permissionType); + final boolean hasAccess = + airavataService.userHasAccessInternal(sharingClient, authzToken, resourceId, permissionType); sharingClientPool.returnResource(sharingClient); return hasAccess; } catch (Exception e) { @@ -6036,8 +6068,8 @@ public List getGroupResourceList(AuthzToken authzToken, St TException { SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { - List groupResourceProfileList = airavataService.getGroupResourceListWithSharing( - sharingClient, authzToken, gatewayId); + List groupResourceProfileList = + airavataService.getGroupResourceListWithSharing(sharingClient, authzToken, gatewayId); sharingClientPool.returnResource(sharingClient); return groupResourceProfileList; } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { @@ -6261,7 +6293,8 @@ public ComputeResourcePolicy getGroupComputeResourcePolicy(AuthzToken authzToken } } - ComputeResourcePolicy computeResourcePolicy = airavataService.getGroupComputeResourcePolicy(resourcePolicyId); + ComputeResourcePolicy computeResourcePolicy = + airavataService.getGroupComputeResourcePolicy(resourcePolicyId); sharingClientPool.returnResource(sharingClient); return computeResourcePolicy; } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { @@ -6306,7 +6339,8 @@ public BatchQueueResourcePolicy getBatchQueueResourcePolicy(AuthzToken authzToke throw new AuthorizationException("User does not have permission to access group resource profile"); } } - BatchQueueResourcePolicy batchQueueResourcePolicy = airavataService.getBatchQueueResourcePolicy(resourcePolicyId); + BatchQueueResourcePolicy batchQueueResourcePolicy = + airavataService.getBatchQueueResourcePolicy(resourcePolicyId); sharingClientPool.returnResource(sharingClient); return batchQueueResourcePolicy; } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { diff --git a/airavata-api/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java index bef4b1813a..ff4ee71c83 100644 --- a/airavata-api/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java @@ -24,7 +24,6 @@ import java.util.List; import java.util.Map; import org.apache.airavata.common.exception.ApplicationSettingsException; -import org.apache.airavata.credential.store.cpi.CredentialStoreService; import org.apache.airavata.credential.store.cpi.credential_store_cpiConstants; import org.apache.airavata.credential.store.store.CredentialStoreException; import org.apache.airavata.model.credential.store.*; @@ -33,7 +32,8 @@ import org.slf4j.LoggerFactory; // import sun.security.provider.X509Factory; -public class CredentialStoreServerHandler implements org.apache.airavata.credential.store.cpi.CredentialStoreService.Iface { +public class CredentialStoreServerHandler + implements org.apache.airavata.credential.store.cpi.CredentialStoreService.Iface { protected static Logger log = LoggerFactory.getLogger(CredentialStoreServerHandler.class); private org.apache.airavata.service.CredentialStoreService credentialStoreService; @@ -139,7 +139,6 @@ public List getAllCredentialSummaries( } } - @Override public CertificateCredential getCertificateCredential(String tokenId, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { diff --git a/airavata-api/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java index 6390572085..c0e1851a47 100644 --- a/airavata-api/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java @@ -19,50 +19,24 @@ */ package org.apache.airavata.orchestrator.server; -import java.text.MessageFormat; import java.util.*; import org.apache.airavata.common.exception.AiravataException; import org.apache.airavata.common.exception.ApplicationSettingsException; import org.apache.airavata.common.logging.MDCConstants; -import org.apache.airavata.common.logging.MDCUtil; -import org.apache.airavata.common.utils.AiravataUtils; import org.apache.airavata.common.utils.ServerSettings; import org.apache.airavata.common.utils.ThriftUtils; import org.apache.airavata.common.utils.ZkConstants; import org.apache.airavata.messaging.core.*; -import org.apache.airavata.metascheduler.core.api.ProcessScheduler; -import org.apache.airavata.metascheduler.process.scheduling.api.ProcessSchedulerImpl; -import org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription; -import org.apache.airavata.model.appcatalog.appinterface.ApplicationInterfaceDescription; -import org.apache.airavata.model.appcatalog.computeresource.ComputeResourceDescription; -import org.apache.airavata.model.appcatalog.groupresourceprofile.GroupComputeResourcePreference; -import org.apache.airavata.model.appcatalog.groupresourceprofile.GroupResourceProfile; -import org.apache.airavata.model.application.io.DataType; -import org.apache.airavata.model.application.io.OutputDataObjectType; import org.apache.airavata.model.commons.ErrorModel; -import org.apache.airavata.model.data.replica.DataProductModel; -import org.apache.airavata.model.data.replica.DataReplicaLocationModel; -import org.apache.airavata.model.data.replica.ReplicaLocationCategory; import org.apache.airavata.model.error.LaunchValidationException; -import org.apache.airavata.model.experiment.ExperimentModel; -import org.apache.airavata.model.experiment.ExperimentType; -import org.apache.airavata.model.experiment.UserConfigurationDataModel; import org.apache.airavata.model.messaging.event.*; import org.apache.airavata.model.process.ProcessModel; -import org.apache.airavata.model.scheduling.ComputationalResourceSchedulingModel; import org.apache.airavata.model.status.*; -import org.apache.airavata.model.task.TaskTypes; -import org.apache.airavata.model.util.ExperimentModelUtil; import org.apache.airavata.orchestrator.core.exception.OrchestratorException; -import org.apache.airavata.orchestrator.core.schedule.HostScheduler; -import org.apache.airavata.orchestrator.core.utils.OrchestratorConstants; import org.apache.airavata.orchestrator.cpi.OrchestratorService; import org.apache.airavata.orchestrator.cpi.impl.SimpleOrchestratorImpl; import org.apache.airavata.orchestrator.util.OrchestratorServerThreadPoolExecutor; -import org.apache.airavata.orchestrator.util.OrchestratorUtils; import org.apache.airavata.service.OrchestratorRegistryService; -import org.apache.airavata.registry.api.exception.RegistryServiceException; -import org.apache.commons.lang3.StringUtils; import org.apache.curator.RetryPolicy; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFrameworkFactory; @@ -70,7 +44,6 @@ import org.apache.curator.utils.ZKPaths; import org.apache.thrift.TBase; import org.apache.thrift.TException; -import org.apache.zookeeper.data.Stat; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.MDC; @@ -110,7 +83,8 @@ public OrchestratorServerHandler() throws OrchestratorException, TException { statusSubscribe = getStatusSubscriber(); experimentSubscriber = getExperimentSubscriber(); startCurator(); - orchestratorService = new org.apache.airavata.service.OrchestratorService(orchestratorRegistryService, orchestrator, curatorClient, publisher); + orchestratorService = new org.apache.airavata.service.OrchestratorService( + orchestratorRegistryService, orchestrator, curatorClient, publisher); } catch (OrchestratorException | AiravataException e) { log.error(e.getMessage(), e); throw new OrchestratorException("Error while initializing orchestrator service", e); @@ -223,7 +197,6 @@ public void fetchIntermediateOutputs(String experimentId, String gatewayId, List } } - private String getAiravataUserName() { return airavataUserName; } @@ -253,8 +226,6 @@ public boolean launchProcess(String processId, String airavataCredStoreToken, St } } - - private class ProcessStatusHandler implements MessageHandler { /** * This method only handle MessageType.PROCESS type messages. @@ -281,8 +252,10 @@ public void onMessage(MessageContext message) { + "Error" + " while prcessing process status change event"); throw new RuntimeException("Error while updating experiment status", e); } catch (Exception e) { - log.error("Message Id : " + message.getMessageId() + ", Message type : " + message.getType() - + "Error" + " while prcessing process status change event", e); + log.error( + "Message Id : " + message.getMessageId() + ", Message type : " + message.getType() + "Error" + + " while prcessing process status change event", + e); throw new RuntimeException("Error while updating experiment status", e); } } else { @@ -374,7 +347,6 @@ private void launchExperiment(MessageContext messageContext) { } } - private void startCurator() throws ApplicationSettingsException { String connectionSting = ServerSettings.getZookeeperConnection(); RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 5); @@ -385,5 +357,4 @@ private void startCurator() throws ApplicationSettingsException { public String getExperimentNodePath(String experimentId) { return ZKPaths.makePath(ZkConstants.ZOOKEEPER_EXPERIMENT_NODE, experimentId); } - } diff --git a/airavata-api/src/main/java/org/apache/airavata/registry/api/service/handler/RegistryServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/registry/api/service/handler/RegistryServerHandler.java index c6ef52e8e2..61a1a0bf2b 100644 --- a/airavata-api/src/main/java/org/apache/airavata/registry/api/service/handler/RegistryServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/registry/api/service/handler/RegistryServerHandler.java @@ -20,8 +20,6 @@ package org.apache.airavata.registry.api.service.handler; import java.util.*; -import org.apache.airavata.common.utils.AiravataUtils; -import org.apache.airavata.common.utils.ServerSettings; import org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription; import org.apache.airavata.model.appcatalog.appdeployment.ApplicationModule; import org.apache.airavata.model.appcatalog.appinterface.ApplicationInterfaceDescription; @@ -74,7 +72,8 @@ public class RegistryServerHandler implements RegistryService.Iface { private static final Logger logger = LoggerFactory.getLogger(RegistryServerHandler.class); - private org.apache.airavata.service.RegistryService registryService = new org.apache.airavata.service.RegistryService(); + private org.apache.airavata.service.RegistryService registryService = + new org.apache.airavata.service.RegistryService(); // Helper method to convert domain exceptions to Thrift exceptions private RegistryServiceException convertToRegistryServiceException(RegistryException e, String context) { @@ -327,8 +326,15 @@ public ExperimentStatistics getExperimentStatistics( throws RegistryServiceException, TException { try { return registryService.getExperimentStatistics( - gatewayId, fromTime, toTime, userName, applicationName, resourceHostName, - accessibleExpIds, limit, offset); + gatewayId, + fromTime, + toTime, + userName, + applicationName, + resourceHostName, + accessibleExpIds, + limit, + offset); } catch (RegistryException e) { throw convertToRegistryServiceException(e, "Error while retrieving experiments"); } @@ -715,7 +721,8 @@ public List getProcessStatusList(String processId) throws Registr try { return registryService.getProcessStatusList(processId); } catch (RegistryException e) { - throw convertToRegistryServiceException(e, "Error while retrieving process status list for given process Id"); + throw convertToRegistryServiceException( + e, "Error while retrieving process status list for given process Id"); } } @@ -748,7 +755,8 @@ public List getJobs(String queryType, String id) throws RegistryServic try { return registryService.getJobs(queryType, id); } catch (RegistryException e) { - throw convertToRegistryServiceException(e, "Error while retrieving jobs for query " + queryType + " and id " + id); + throw convertToRegistryServiceException( + e, "Error while retrieving jobs for query " + queryType + " and id " + id); } } @@ -773,7 +781,6 @@ public Map getAVGTimeDistribution(String gatewayId, double searc } } - @Override public List getProcessOutputs(String processId) throws RegistryServiceException, TException { try { @@ -788,7 +795,8 @@ public List getProcessWorkflows(String processId) throws Regist try { return registryService.getProcessWorkflows(processId); } catch (RegistryException e) { - throw convertToRegistryServiceException(e, "Error while retrieving process workflows for process id " + processId); + throw convertToRegistryServiceException( + e, "Error while retrieving process workflows for process id " + processId); } } @@ -797,7 +805,8 @@ public void addProcessWorkflow(ProcessWorkflow processWorkflow) throws RegistryS try { registryService.addProcessWorkflow(processWorkflow); } catch (RegistryException e) { - throw convertToRegistryServiceException(e, "Error while adding process workflows for process id " + processWorkflow.getProcessId()); + throw convertToRegistryServiceException( + e, "Error while adding process workflows for process id " + processWorkflow.getProcessId()); } } @@ -957,7 +966,8 @@ public List getAccessibleApplicationDeployment String gatewayId, List accessibleAppDeploymentIds, List accessibleComputeResourceIds) throws RegistryServiceException, TException { try { - return registryService.getAccessibleApplicationDeployments(gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); + return registryService.getAccessibleApplicationDeployments( + gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); } catch (AppCatalogException e) { throw convertToRegistryServiceException(e, "Error while retrieving application deployments"); } @@ -981,7 +991,8 @@ public List getAccessibleApplicationDeployment List accessibleComputeResourceIds) throws RegistryServiceException, TException { try { - return registryService.getAccessibleApplicationDeploymentsForAppModule(gatewayId, appModuleId, accessibleAppDeploymentIds, accessibleComputeResourceIds); + return registryService.getAccessibleApplicationDeploymentsForAppModule( + gatewayId, appModuleId, accessibleAppDeploymentIds, accessibleComputeResourceIds); } catch (AppCatalogException e) { throw convertToRegistryServiceException(e, "Error while retrieving application deployments"); } @@ -1797,7 +1808,8 @@ public List getGroupComputeResourcePrefList(Stri try { return registryService.getGroupComputeResourcePrefList(groupResourceProfileId); } catch (AppCatalogException e) { - throw convertToRegistryServiceException(e, "Error while retrieving retrieving Group Compute Resource Preference list"); + throw convertToRegistryServiceException( + e, "Error while retrieving retrieving Group Compute Resource Preference list"); } } @@ -1807,7 +1819,8 @@ public List getGroupBatchQueueResourcePolicyList(Strin try { return registryService.getGroupBatchQueueResourcePolicyList(groupResourceProfileId); } catch (AppCatalogException e) { - throw convertToRegistryServiceException(e, "Error while retrieving retrieving Group Batch Queue Resource policy list"); + throw convertToRegistryServiceException( + e, "Error while retrieving retrieving Group Batch Queue Resource policy list"); } } @@ -1817,7 +1830,8 @@ public List getGroupComputeResourcePolicyList(String grou try { return registryService.getGroupComputeResourcePolicyList(groupResourceProfileId); } catch (AppCatalogException e) { - throw convertToRegistryServiceException(e, "Error while retrieving retrieving Group Compute Resource policy list"); + throw convertToRegistryServiceException( + e, "Error while retrieving retrieving Group Compute Resource policy list"); } } @@ -1827,7 +1841,8 @@ public String registerReplicaLocation(DataReplicaLocationModel replicaLocationMo try { return registryService.registerReplicaLocation(replicaLocationModel); } catch (RegistryException e) { - throw convertToRegistryServiceException(e, "Error in retreiving the replica " + replicaLocationModel.getReplicaName()); + throw convertToRegistryServiceException( + e, "Error in retreiving the replica " + replicaLocationModel.getReplicaName()); } } @@ -1841,7 +1856,8 @@ public String registerDataProduct(DataProductModel dataProductModel) throws Regi try { return registryService.registerDataProduct(dataProductModel); } catch (RegistryException e) { - throw convertToRegistryServiceException(e, "Error in registering the data resource" + dataProductModel.getProductName()); + throw convertToRegistryServiceException( + e, "Error in registering the data resource" + dataProductModel.getProductName()); } } @@ -1879,7 +1895,8 @@ public boolean updateGatewayComputeResourcePreference( String gatewayID, String computeResourceId, ComputeResourcePreference computeResourcePreference) throws RegistryServiceException, TException { try { - return registryService.updateGatewayComputeResourcePreference(gatewayID, computeResourceId, computeResourcePreference); + return registryService.updateGatewayComputeResourcePreference( + gatewayID, computeResourceId, computeResourcePreference); } catch (AppCatalogException e) { throw convertToRegistryServiceException(e, "Error while updating gateway compute resource preference"); } @@ -1921,7 +1938,8 @@ public boolean addGatewayComputeResourcePreference( String gatewayID, String computeResourceId, ComputeResourcePreference computeResourcePreference) throws RegistryServiceException, TException { try { - return registryService.addGatewayComputeResourcePreference(gatewayID, computeResourceId, computeResourcePreference); + return registryService.addGatewayComputeResourcePreference( + gatewayID, computeResourceId, computeResourcePreference); } catch (AppCatalogException e) { throw convertToRegistryServiceException(e, "Error while registering gateway resource profile preference"); } @@ -2035,9 +2053,11 @@ public String addGridFTPDataMovementDetails( String computeResourceId, DMType dmType, int priorityOrder, GridFTPDataMovement gridFTPDataMovement) throws RegistryServiceException, TException { try { - return registryService.addGridFTPDataMovementDetails(computeResourceId, dmType, priorityOrder, gridFTPDataMovement); + return registryService.addGridFTPDataMovementDetails( + computeResourceId, dmType, priorityOrder, gridFTPDataMovement); } catch (AppCatalogException e) { - throw convertToRegistryServiceException(e, "Error while adding data movement interface to resource compute resource"); + throw convertToRegistryServiceException( + e, "Error while adding data movement interface to resource compute resource"); } } @@ -2074,9 +2094,11 @@ public String addUnicoreDataMovementDetails( String resourceId, DMType dmType, int priorityOrder, UnicoreDataMovement unicoreDataMovement) throws RegistryServiceException, TException { try { - return registryService.addUnicoreDataMovementDetails(resourceId, dmType, priorityOrder, unicoreDataMovement); + return registryService.addUnicoreDataMovementDetails( + resourceId, dmType, priorityOrder, unicoreDataMovement); } catch (AppCatalogException e) { - throw convertToRegistryServiceException(e, "Error while adding data movement interface to resource compute resource"); + throw convertToRegistryServiceException( + e, "Error while adding data movement interface to resource compute resource"); } } @@ -2118,7 +2140,8 @@ public String addSCPDataMovementDetails( try { return registryService.addSCPDataMovementDetails(resourceId, dmType, priorityOrder, scpDataMovement); } catch (AppCatalogException e) { - throw convertToRegistryServiceException(e, "Error while adding data movement interface to resource compute resource"); + throw convertToRegistryServiceException( + e, "Error while adding data movement interface to resource compute resource"); } } @@ -2157,7 +2180,8 @@ public String addLocalDataMovementDetails( String resourceId, DMType dataMoveType, int priorityOrder, LOCALDataMovement localDataMovement) throws RegistryServiceException, TException { try { - return registryService.addLocalDataMovementDetails(resourceId, dataMoveType, priorityOrder, localDataMovement); + return registryService.addLocalDataMovementDetails( + resourceId, dataMoveType, priorityOrder, localDataMovement); } catch (AppCatalogException e) { throw convertToRegistryServiceException(e, "Error while adding data movement interface to resource"); } @@ -2244,7 +2268,8 @@ public String addCloudJobSubmissionDetails( try { return registryService.addCloudJobSubmissionDetails(computeResourceId, priorityOrder, cloudSubmission); } catch (AppCatalogException e) { - throw convertToRegistryServiceException(e, "Error while adding job submission interface to resource compute resource"); + throw convertToRegistryServiceException( + e, "Error while adding job submission interface to resource compute resource"); } } @@ -2263,9 +2288,11 @@ public String addUNICOREJobSubmissionDetails( String computeResourceId, int priorityOrder, UnicoreJobSubmission unicoreJobSubmission) throws RegistryServiceException, TException { try { - return registryService.addUNICOREJobSubmissionDetails(computeResourceId, priorityOrder, unicoreJobSubmission); + return registryService.addUNICOREJobSubmissionDetails( + computeResourceId, priorityOrder, unicoreJobSubmission); } catch (AppCatalogException e) { - throw convertToRegistryServiceException(e, "Error while adding job submission interface to resource compute resource"); + throw convertToRegistryServiceException( + e, "Error while adding job submission interface to resource compute resource"); } } @@ -2286,7 +2313,8 @@ public String addSSHForkJobSubmissionDetails( try { return registryService.addSSHForkJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); } catch (AppCatalogException e) { - throw convertToRegistryServiceException(e, "Error while adding job submission interface to resource compute resource"); + throw convertToRegistryServiceException( + e, "Error while adding job submission interface to resource compute resource"); } } @@ -2307,7 +2335,8 @@ public String addSSHJobSubmissionDetails( try { return registryService.addSSHJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); } catch (AppCatalogException e) { - throw convertToRegistryServiceException(e, "Error while adding job submission interface to resource compute resource"); + throw convertToRegistryServiceException( + e, "Error while adding job submission interface to resource compute resource"); } } @@ -2346,7 +2375,8 @@ public String addLocalSubmissionDetails( try { return registryService.addLocalSubmissionDetails(computeResourceId, priorityOrder, localSubmission); } catch (AppCatalogException e) { - throw convertToRegistryServiceException(e, "Error while adding job submission interface to resource compute resource"); + throw convertToRegistryServiceException( + e, "Error while adding job submission interface to resource compute resource"); } } @@ -2859,7 +2889,6 @@ private List getApplicationOutputsInternal(String appInter } } - /** * Register a User Resource Profile. * @@ -2970,7 +2999,8 @@ public boolean addUserComputeResourcePreference( UserComputeResourcePreference userComputeResourcePreference) throws RegistryServiceException, TException { try { - return registryService.addUserComputeResourcePreference(userId, gatewayID, computeResourceId, userComputeResourcePreference); + return registryService.addUserComputeResourcePreference( + userId, gatewayID, computeResourceId, userComputeResourcePreference); } catch (AppCatalogException e) { throw convertToRegistryServiceException(e, "Error while registering user resource profile preference"); } @@ -3010,7 +3040,8 @@ public boolean addUserStoragePreference( String userId, String gatewayID, String storageResourceId, UserStoragePreference dataStoragePreference) throws RegistryServiceException, TException { try { - return registryService.addUserStoragePreference(userId, gatewayID, storageResourceId, dataStoragePreference); + return registryService.addUserStoragePreference( + userId, gatewayID, storageResourceId, dataStoragePreference); } catch (AppCatalogException e) { throw convertToRegistryServiceException(e, "Error while registering user resource profile preference"); } @@ -3087,7 +3118,8 @@ public boolean updateUserComputeResourcePreference( UserComputeResourcePreference userComputeResourcePreference) throws RegistryServiceException, TException { try { - return registryService.updateUserComputeResourcePreference(userId, gatewayID, computeResourceId, userComputeResourcePreference); + return registryService.updateUserComputeResourcePreference( + userId, gatewayID, computeResourceId, userComputeResourcePreference); } catch (AppCatalogException e) { throw convertToRegistryServiceException(e, "Error while updating user compute resource preference"); } @@ -3199,7 +3231,8 @@ public List getAllUserComputeResourcePreferences( try { return registryService.getAllUserComputeResourcePreferences(userId, gatewayID); } catch (AppCatalogException e) { - throw convertToRegistryServiceException(e, "Error while reading User Resource Profile compute resource preferences"); + throw convertToRegistryServiceException( + e, "Error while reading User Resource Profile compute resource preferences"); } } @@ -3217,7 +3250,8 @@ public List getAllUserStoragePreferences(String userId, S try { return registryService.getAllUserStoragePreferences(userId, gatewayID); } catch (AppCatalogException e) { - throw convertToRegistryServiceException(e, "Error while reading user resource Profile data storage preferences"); + throw convertToRegistryServiceException( + e, "Error while reading user resource Profile data storage preferences"); } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java b/airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java index d04db0d61f..79d4ed6124 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java @@ -19,36 +19,61 @@ */ package org.apache.airavata.service; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; -import org.apache.airavata.model.application.io.InputDataObjectType; -import org.apache.airavata.model.application.io.OutputDataObjectType; +import java.util.Optional; +import java.util.Set; +import java.util.UUID; +import java.util.function.BiFunction; +import java.util.stream.Collectors; +import org.apache.airavata.common.utils.AiravataUtils; +import org.apache.airavata.common.utils.Constants; +import org.apache.airavata.common.utils.ServerSettings; +import org.apache.airavata.credential.store.cpi.CredentialStoreService; +import org.apache.airavata.credential.store.exception.CredentialStoreException; +import org.apache.airavata.messaging.core.MessageContext; +import org.apache.airavata.messaging.core.Publisher; +import org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription; import org.apache.airavata.model.appcatalog.appdeployment.ApplicationModule; -import org.apache.airavata.model.appcatalog.computeresource.ComputeResourceDescription; +import org.apache.airavata.model.appcatalog.appinterface.ApplicationInterfaceDescription; import org.apache.airavata.model.appcatalog.computeresource.CloudJobSubmission; +import org.apache.airavata.model.appcatalog.computeresource.ComputeResourceDescription; import org.apache.airavata.model.appcatalog.computeresource.LOCALSubmission; import org.apache.airavata.model.appcatalog.computeresource.ResourceJobManager; import org.apache.airavata.model.appcatalog.computeresource.SSHJobSubmission; import org.apache.airavata.model.appcatalog.computeresource.UnicoreJobSubmission; -import org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile; +import org.apache.airavata.model.appcatalog.gatewaygroups.GatewayGroups; import org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference; +import org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile; import org.apache.airavata.model.appcatalog.gatewayprofile.StoragePreference; -import org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference; -import org.apache.airavata.model.appcatalog.userresourceprofile.UserStoragePreference; -import org.apache.airavata.model.appcatalog.groupresourceprofile.GroupComputeResourcePreference; -import org.apache.airavata.model.appcatalog.groupresourceprofile.ComputeResourcePolicy; import org.apache.airavata.model.appcatalog.groupresourceprofile.BatchQueueResourcePolicy; -import org.apache.airavata.model.status.QueueStatusModel; +import org.apache.airavata.model.appcatalog.groupresourceprofile.ComputeResourcePolicy; +import org.apache.airavata.model.appcatalog.groupresourceprofile.GroupComputeResourcePreference; +import org.apache.airavata.model.appcatalog.groupresourceprofile.GroupResourceProfile; import org.apache.airavata.model.appcatalog.parser.Parser; import org.apache.airavata.model.appcatalog.parser.ParsingTemplate; +import org.apache.airavata.model.appcatalog.storageresource.StorageResourceDescription; +import org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference; +import org.apache.airavata.model.appcatalog.userresourceprofile.UserResourceProfile; +import org.apache.airavata.model.appcatalog.userresourceprofile.UserStoragePreference; +import org.apache.airavata.model.application.io.InputDataObjectType; +import org.apache.airavata.model.application.io.OutputDataObjectType; +import org.apache.airavata.model.credential.store.CredentialSummary; +import org.apache.airavata.model.credential.store.PasswordCredential; +import org.apache.airavata.model.credential.store.SSHCredential; +import org.apache.airavata.model.credential.store.SummaryType; import org.apache.airavata.model.data.movement.DMType; +import org.apache.airavata.model.data.movement.GridFTPDataMovement; import org.apache.airavata.model.data.movement.LOCALDataMovement; import org.apache.airavata.model.data.movement.SCPDataMovement; import org.apache.airavata.model.data.movement.UnicoreDataMovement; -import org.apache.airavata.model.data.movement.GridFTPDataMovement; -import org.apache.airavata.model.appcatalog.groupresourceprofile.GroupResourceProfile; -import org.apache.airavata.model.appcatalog.userresourceprofile.UserResourceProfile; -import org.apache.airavata.model.appcatalog.storageresource.StorageResourceDescription; import org.apache.airavata.model.data.replica.DataProductModel; import org.apache.airavata.model.data.replica.DataReplicaLocationModel; import org.apache.airavata.model.experiment.ExperimentModel; @@ -56,81 +81,58 @@ import org.apache.airavata.model.experiment.ExperimentStatistics; import org.apache.airavata.model.experiment.ExperimentSummaryModel; import org.apache.airavata.model.experiment.ProjectSearchFields; +import org.apache.airavata.model.experiment.UserConfigurationDataModel; +import org.apache.airavata.model.group.ResourcePermissionType; +import org.apache.airavata.model.group.ResourceType; import org.apache.airavata.model.job.JobModel; +import org.apache.airavata.model.messaging.event.ExperimentIntermediateOutputsEvent; +import org.apache.airavata.model.messaging.event.ExperimentStatusChangeEvent; +import org.apache.airavata.model.messaging.event.ExperimentSubmitEvent; +import org.apache.airavata.model.messaging.event.MessageType; import org.apache.airavata.model.process.ProcessModel; +import org.apache.airavata.model.scheduling.ComputationalResourceSchedulingModel; +import org.apache.airavata.model.security.AuthzToken; +import org.apache.airavata.model.status.ExperimentState; import org.apache.airavata.model.status.ExperimentStatus; import org.apache.airavata.model.status.JobState; import org.apache.airavata.model.status.JobStatus; import org.apache.airavata.model.status.ProcessState; import org.apache.airavata.model.status.ProcessStatus; +import org.apache.airavata.model.status.QueueStatusModel; import org.apache.airavata.model.task.TaskTypes; -import org.apache.airavata.model.experiment.UserConfigurationDataModel; -import org.apache.airavata.model.scheduling.ComputationalResourceSchedulingModel; import org.apache.airavata.model.workspace.Gateway; import org.apache.airavata.model.workspace.Notification; import org.apache.airavata.model.workspace.Project; -import org.apache.airavata.model.appcatalog.appinterface.ApplicationInterfaceDescription; -import org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription; -import org.apache.airavata.model.credential.store.CredentialSummary; -import org.apache.airavata.model.credential.store.PasswordCredential; -import org.apache.airavata.model.credential.store.SSHCredential; -import org.apache.airavata.model.credential.store.SummaryType; -import org.apache.airavata.model.group.ResourcePermissionType; -import org.apache.airavata.model.group.ResourceType; -import org.apache.airavata.model.security.AuthzToken; -import org.apache.airavata.common.utils.Constants; -import org.apache.airavata.common.utils.ServerSettings; -import org.apache.airavata.credential.store.cpi.CredentialStoreService; -import org.apache.airavata.credential.store.exception.CredentialStoreException; -import org.apache.airavata.registry.cpi.RegistryException; +import org.apache.airavata.registry.api.RegistryService; import org.apache.airavata.registry.cpi.AppCatalogException; +import org.apache.airavata.registry.cpi.RegistryException; import org.apache.airavata.service.security.GatewayGroupsInitializer; import org.apache.airavata.sharing.registry.models.Domain; import org.apache.airavata.sharing.registry.models.Entity; +import org.apache.airavata.sharing.registry.models.EntitySearchField; import org.apache.airavata.sharing.registry.models.EntityType; import org.apache.airavata.sharing.registry.models.PermissionType; -import org.apache.airavata.sharing.registry.models.SearchCriteria; -import org.apache.airavata.sharing.registry.models.EntitySearchField; import org.apache.airavata.sharing.registry.models.SearchCondition; -import org.apache.airavata.sharing.registry.service.cpi.SharingRegistryService; -import org.apache.airavata.registry.api.RegistryService; -import org.apache.airavata.model.appcatalog.gatewaygroups.GatewayGroups; -import org.apache.airavata.messaging.core.MessageContext; -import org.apache.airavata.messaging.core.Publisher; -import org.apache.airavata.model.messaging.event.ExperimentIntermediateOutputsEvent; -import org.apache.airavata.model.messaging.event.ExperimentStatusChangeEvent; -import org.apache.airavata.model.messaging.event.ExperimentSubmitEvent; -import org.apache.airavata.model.messaging.event.MessageType; -import org.apache.airavata.model.status.ExperimentState; -import org.apache.airavata.common.utils.AiravataUtils; +import org.apache.airavata.sharing.registry.models.SearchCriteria; import org.apache.airavata.sharing.registry.models.User; import org.apache.airavata.sharing.registry.models.UserGroup; +import org.apache.airavata.sharing.registry.service.cpi.SharingRegistryService; import org.apache.thrift.TException; -import java.util.UUID; -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; -import java.util.function.BiFunction; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Optional; -import java.util.stream.Collectors; public class AiravataService { private static final Logger logger = LoggerFactory.getLogger(AiravataService.class); - - private org.apache.airavata.service.RegistryService registryService = new org.apache.airavata.service.RegistryService(); + + private org.apache.airavata.service.RegistryService registryService = + new org.apache.airavata.service.RegistryService(); public List getAllUsersInGateway(String gatewayId) throws RegistryException { return registryService.getAllUsersInGateway(gatewayId); } - public boolean updateGateway(String gatewayId, Gateway updatedGateway) throws RegistryException, AppCatalogException { + public boolean updateGateway(String gatewayId, Gateway updatedGateway) + throws RegistryException, AppCatalogException { return registryService.updateGateway(gatewayId, updatedGateway); } @@ -210,20 +212,48 @@ public boolean deleteProject(String projectId) throws RegistryException { return registryService.deleteProject(projectId); } - public List searchProjects(String gatewayId, String userName, List accessibleProjectIds, Map filters, int limit, int offset) throws RegistryException { + public List searchProjects( + String gatewayId, + String userName, + List accessibleProjectIds, + Map filters, + int limit, + int offset) + throws RegistryException { return registryService.searchProjects(gatewayId, userName, accessibleProjectIds, filters, limit, offset); } - public List getUserExperiments(String gatewayId, String userName, int limit, int offset) throws RegistryException { + public List getUserExperiments(String gatewayId, String userName, int limit, int offset) + throws RegistryException { return registryService.getUserExperiments(gatewayId, userName, limit, offset); } - public List getExperimentsInProject(String gatewayId, String projectId, int limit, int offset) throws RegistryException { + public List getExperimentsInProject(String gatewayId, String projectId, int limit, int offset) + throws RegistryException { return registryService.getExperimentsInProject(gatewayId, projectId, limit, offset); } - public ExperimentStatistics getExperimentStatistics(String gatewayId, long fromTime, long toTime, String userName, String applicationName, String resourceHostName, List accessibleExpIds, int limit, int offset) throws RegistryException { - return registryService.getExperimentStatistics(gatewayId, fromTime, toTime, userName, applicationName, resourceHostName, accessibleExpIds, limit, offset); + public ExperimentStatistics getExperimentStatistics( + String gatewayId, + long fromTime, + long toTime, + String userName, + String applicationName, + String resourceHostName, + List accessibleExpIds, + int limit, + int offset) + throws RegistryException { + return registryService.getExperimentStatistics( + gatewayId, + fromTime, + toTime, + userName, + applicationName, + resourceHostName, + accessibleExpIds, + limit, + offset); } public ExperimentModel getExperiment(String airavataExperimentId) throws RegistryException { @@ -242,7 +272,14 @@ public boolean deleteExperiment(String experimentId) throws RegistryException { return registryService.deleteExperiment(experimentId); } - public List searchExperiments(String gatewayId, String userName, List accessibleExpIds, Map filters, int limit, int offset) throws RegistryException { + public List searchExperiments( + String gatewayId, + String userName, + List accessibleExpIds, + Map filters, + int limit, + int offset) + throws RegistryException { return registryService.searchExperiments(gatewayId, userName, accessibleExpIds, filters, limit, offset); } @@ -256,7 +293,8 @@ public List searchExperimentsWithSharing( String userName, Map filters, int limit, - int offset) throws Exception { + int offset) + throws Exception { List accessibleExpIds = new ArrayList<>(); Map filtersCopy = new HashMap<>(filters); List sharingFilters = new ArrayList<>(); @@ -361,11 +399,14 @@ public ComputeResourceDescription getComputeResource(String computeResourceId) t return registryService.getComputeResource(computeResourceId); } - public String registerComputeResource(ComputeResourceDescription computeResourceDescription) throws AppCatalogException { + public String registerComputeResource(ComputeResourceDescription computeResourceDescription) + throws AppCatalogException { return registryService.registerComputeResource(computeResourceDescription); } - public boolean updateComputeResource(String computeResourceId, ComputeResourceDescription computeResourceDescription) throws AppCatalogException { + public boolean updateComputeResource( + String computeResourceId, ComputeResourceDescription computeResourceDescription) + throws AppCatalogException { return registryService.updateComputeResource(computeResourceId, computeResourceDescription); } @@ -377,7 +418,8 @@ public Map getAllComputeResourceNames() throws AppCatalogExcepti return registryService.getAllComputeResourceNames(); } - public String registerStorageResource(StorageResourceDescription storageResourceDescription) throws AppCatalogException { + public String registerStorageResource(StorageResourceDescription storageResourceDescription) + throws AppCatalogException { return registryService.registerStorageResource(storageResourceDescription); } @@ -385,7 +427,9 @@ public StorageResourceDescription getStorageResource(String storageResourceId) t return registryService.getStorageResource(storageResourceId); } - public boolean updateStorageResource(String storageResourceId, StorageResourceDescription storageResourceDescription) throws AppCatalogException { + public boolean updateStorageResource( + String storageResourceId, StorageResourceDescription storageResourceDescription) + throws AppCatalogException { return registryService.updateStorageResource(storageResourceId, storageResourceDescription); } @@ -397,7 +441,8 @@ public Map getAllStorageResourceNames() throws AppCatalogExcepti return registryService.getAllStorageResourceNames(); } - public String registerGatewayResourceProfile(GatewayResourceProfile gatewayResourceProfile) throws AppCatalogException { + public String registerGatewayResourceProfile(GatewayResourceProfile gatewayResourceProfile) + throws AppCatalogException { return registryService.registerGatewayResourceProfile(gatewayResourceProfile); } @@ -405,7 +450,8 @@ public GatewayResourceProfile getGatewayResourceProfile(String gatewayID) throws return registryService.getGatewayResourceProfile(gatewayID); } - public boolean updateGatewayResourceProfile(String gatewayID, GatewayResourceProfile gatewayResourceProfile) throws AppCatalogException { + public boolean updateGatewayResourceProfile(String gatewayID, GatewayResourceProfile gatewayResourceProfile) + throws AppCatalogException { return registryService.updateGatewayResourceProfile(gatewayID, gatewayResourceProfile); } @@ -417,7 +463,8 @@ public UserResourceProfile getUserResourceProfile(String userId, String gatewayI return registryService.getUserResourceProfile(userId, gatewayId); } - public boolean updateUserResourceProfile(String userId, String gatewayID, UserResourceProfile userResourceProfile) throws AppCatalogException { + public boolean updateUserResourceProfile(String userId, String gatewayID, UserResourceProfile userResourceProfile) + throws AppCatalogException { return registryService.updateUserResourceProfile(userId, gatewayID, userResourceProfile); } @@ -433,7 +480,8 @@ public void updateGroupResourceProfile(GroupResourceProfile groupResourceProfile registryService.updateGroupResourceProfile(groupResourceProfile); } - public List getGroupResourceList(String gatewayId, List accessibleGroupResProfileIds) throws AppCatalogException { + public List getGroupResourceList(String gatewayId, List accessibleGroupResProfileIds) + throws AppCatalogException { return registryService.getGroupResourceList(gatewayId, accessibleGroupResProfileIds); } @@ -445,23 +493,29 @@ public boolean isGatewayGroupsExists(String gatewayId) throws RegistryException return registryService.isGatewayGroupsExists(gatewayId); } - public void updateExperimentConfiguration(String airavataExperimentId, UserConfigurationDataModel userConfiguration) throws RegistryException { + public void updateExperimentConfiguration(String airavataExperimentId, UserConfigurationDataModel userConfiguration) + throws RegistryException { registryService.updateExperimentConfiguration(airavataExperimentId, userConfiguration); } - public void updateResourceScheduleing(String airavataExperimentId, ComputationalResourceSchedulingModel resourceScheduling) throws RegistryException { + public void updateResourceScheduleing( + String airavataExperimentId, ComputationalResourceSchedulingModel resourceScheduling) + throws RegistryException { registryService.updateResourceScheduleing(airavataExperimentId, resourceScheduling); } - public String registerApplicationDeployment(String gatewayId, ApplicationDeploymentDescription applicationDeployment) throws AppCatalogException { + public String registerApplicationDeployment( + String gatewayId, ApplicationDeploymentDescription applicationDeployment) throws AppCatalogException { return registryService.registerApplicationDeployment(gatewayId, applicationDeployment); } - public ApplicationDeploymentDescription getApplicationDeployment(String appDeploymentId) throws AppCatalogException { + public ApplicationDeploymentDescription getApplicationDeployment(String appDeploymentId) + throws AppCatalogException { return registryService.getApplicationDeployment(appDeploymentId); } - public boolean updateApplicationDeployment(String appDeploymentId, ApplicationDeploymentDescription applicationDeployment) throws AppCatalogException { + public boolean updateApplicationDeployment( + String appDeploymentId, ApplicationDeploymentDescription applicationDeployment) throws AppCatalogException { return registryService.updateApplicationDeployment(appDeploymentId, applicationDeployment); } @@ -473,15 +527,18 @@ public ApplicationInterfaceDescription getApplicationInterface(String appInterfa return registryService.getApplicationInterface(appInterfaceId); } - public List getApplicationDeployments(String appModuleId) throws AppCatalogException { + public List getApplicationDeployments(String appModuleId) + throws AppCatalogException { return registryService.getApplicationDeployments(appModuleId); } - public String registerApplicationInterface(String gatewayId, ApplicationInterfaceDescription applicationInterface) throws AppCatalogException { + public String registerApplicationInterface(String gatewayId, ApplicationInterfaceDescription applicationInterface) + throws AppCatalogException { return registryService.registerApplicationInterface(gatewayId, applicationInterface); } - public boolean updateApplicationInterface(String appInterfaceId, ApplicationInterfaceDescription applicationInterface) throws AppCatalogException { + public boolean updateApplicationInterface( + String appInterfaceId, ApplicationInterfaceDescription applicationInterface) throws AppCatalogException { return registryService.updateApplicationInterface(appInterfaceId, applicationInterface); } @@ -493,7 +550,8 @@ public Map getAllApplicationInterfaceNames(String gatewayId) thr return registryService.getAllApplicationInterfaceNames(gatewayId); } - public List getAllApplicationInterfaces(String gatewayId) throws AppCatalogException { + public List getAllApplicationInterfaces(String gatewayId) + throws AppCatalogException { return registryService.getAllApplicationInterfaces(gatewayId); } @@ -501,7 +559,8 @@ public List getApplicationInputs(String appInterfaceId) thr return registryService.getApplicationInputs(appInterfaceId); } - public String registerApplicationModule(String gatewayId, ApplicationModule applicationModule) throws AppCatalogException { + public String registerApplicationModule(String gatewayId, ApplicationModule applicationModule) + throws AppCatalogException { return registryService.registerApplicationModule(gatewayId, applicationModule); } @@ -509,7 +568,8 @@ public ApplicationModule getApplicationModule(String appModuleId) throws AppCata return registryService.getApplicationModule(appModuleId); } - public boolean updateApplicationModule(String appModuleId, ApplicationModule applicationModule) throws AppCatalogException { + public boolean updateApplicationModule(String appModuleId, ApplicationModule applicationModule) + throws AppCatalogException { return registryService.updateApplicationModule(appModuleId, applicationModule); } @@ -521,7 +581,9 @@ public boolean deleteApplicationModule(String appModuleId) throws AppCatalogExce return registryService.deleteApplicationModule(appModuleId); } - public List getAccessibleAppModules(String gatewayId, List accessibleAppIds, List accessibleComputeResourceIds) throws AppCatalogException { + public List getAccessibleAppModules( + String gatewayId, List accessibleAppIds, List accessibleComputeResourceIds) + throws AppCatalogException { return registryService.getAccessibleAppModules(gatewayId, accessibleAppIds, accessibleComputeResourceIds); } @@ -529,9 +591,7 @@ public List getAccessibleAppModules(String gatewayId, List getAccessibleAppModulesWithSharing( - SharingRegistryService.Client sharingClient, - AuthzToken authzToken, - String gatewayId) throws Exception { + SharingRegistryService.Client sharingClient, AuthzToken authzToken, String gatewayId) throws Exception { String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); List accessibleAppDeploymentIds = new ArrayList<>(); if (ServerSettings.isEnableSharing()) { @@ -556,13 +616,12 @@ public List getAccessibleAppModulesWithSharing( .forEach(a -> accessibleAppDeploymentIds.add(a.getEntityId())); } List accessibleComputeResourceIds = new ArrayList<>(); - List groupResourceProfileList = getGroupResourceListWithSharing( - sharingClient, authzToken, gatewayId); + List groupResourceProfileList = + getGroupResourceListWithSharing(sharingClient, authzToken, gatewayId); for (GroupResourceProfile groupResourceProfile : groupResourceProfileList) { List groupComputeResourcePreferenceList = groupResourceProfile.getComputePreferences(); - for (GroupComputeResourcePreference groupComputeResourcePreference : - groupComputeResourcePreferenceList) { + for (GroupComputeResourcePreference groupComputeResourcePreference : groupComputeResourcePreferenceList) { accessibleComputeResourceIds.add(groupComputeResourcePreference.getComputeResourceId()); } } @@ -577,27 +636,35 @@ public List getJobDetails(String airavataExperimentId) throws Registry return registryService.getJobDetails(airavataExperimentId); } - public String addLocalSubmissionDetails(String computeResourceId, int priorityOrder, LOCALSubmission localSubmission) throws AppCatalogException { + public String addLocalSubmissionDetails( + String computeResourceId, int priorityOrder, LOCALSubmission localSubmission) throws AppCatalogException { return registryService.addLocalSubmissionDetails(computeResourceId, priorityOrder, localSubmission); } - public String addSSHJobSubmissionDetails(String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) throws AppCatalogException { + public String addSSHJobSubmissionDetails( + String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) throws AppCatalogException { return registryService.addSSHJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); } - public String addSSHForkJobSubmissionDetails(String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) throws AppCatalogException { + public String addSSHForkJobSubmissionDetails( + String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) throws AppCatalogException { return registryService.addSSHForkJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); } - public String addCloudJobSubmissionDetails(String computeResourceId, int priorityOrder, CloudJobSubmission cloudJobSubmission) throws AppCatalogException { + public String addCloudJobSubmissionDetails( + String computeResourceId, int priorityOrder, CloudJobSubmission cloudJobSubmission) + throws AppCatalogException { return registryService.addCloudJobSubmissionDetails(computeResourceId, priorityOrder, cloudJobSubmission); } - public String addUNICOREJobSubmissionDetails(String computeResourceId, int priorityOrder, UnicoreJobSubmission unicoreJobSubmission) throws AppCatalogException { + public String addUNICOREJobSubmissionDetails( + String computeResourceId, int priorityOrder, UnicoreJobSubmission unicoreJobSubmission) + throws AppCatalogException { return registryService.addUNICOREJobSubmissionDetails(computeResourceId, priorityOrder, unicoreJobSubmission); } - public boolean updateLocalSubmissionDetails(String jobSubmissionInterfaceId, LOCALSubmission localSubmission) throws AppCatalogException { + public boolean updateLocalSubmissionDetails(String jobSubmissionInterfaceId, LOCALSubmission localSubmission) + throws AppCatalogException { return registryService.updateLocalSubmissionDetails(jobSubmissionInterfaceId, localSubmission); } @@ -617,19 +684,23 @@ public UnicoreJobSubmission getUnicoreJobSubmission(String jobSubmissionId) thro return registryService.getUnicoreJobSubmission(jobSubmissionId); } - public boolean updateSSHJobSubmissionDetails(String jobSubmissionInterfaceId, SSHJobSubmission sshJobSubmission) throws AppCatalogException { + public boolean updateSSHJobSubmissionDetails(String jobSubmissionInterfaceId, SSHJobSubmission sshJobSubmission) + throws AppCatalogException { return registryService.updateSSHJobSubmissionDetails(jobSubmissionInterfaceId, sshJobSubmission); } - public boolean updateCloudJobSubmissionDetails(String jobSubmissionInterfaceId, CloudJobSubmission cloudJobSubmission) throws AppCatalogException { + public boolean updateCloudJobSubmissionDetails( + String jobSubmissionInterfaceId, CloudJobSubmission cloudJobSubmission) throws AppCatalogException { return registryService.updateCloudJobSubmissionDetails(jobSubmissionInterfaceId, cloudJobSubmission); } - public boolean updateUnicoreJobSubmissionDetails(String jobSubmissionInterfaceId, UnicoreJobSubmission unicoreJobSubmission) throws AppCatalogException { + public boolean updateUnicoreJobSubmissionDetails( + String jobSubmissionInterfaceId, UnicoreJobSubmission unicoreJobSubmission) throws AppCatalogException { return registryService.updateUnicoreJobSubmissionDetails(jobSubmissionInterfaceId, unicoreJobSubmission); } - public boolean deleteJobSubmissionInterface(String computeResourceId, String jobSubmissionInterfaceId) throws AppCatalogException { + public boolean deleteJobSubmissionInterface(String computeResourceId, String jobSubmissionInterfaceId) + throws AppCatalogException { return registryService.deleteJobSubmissionInterface(computeResourceId, jobSubmissionInterfaceId); } @@ -637,7 +708,8 @@ public String registerResourceJobManager(ResourceJobManager resourceJobManager) return registryService.registerResourceJobManager(resourceJobManager); } - public boolean updateResourceJobManager(String resourceJobManagerId, ResourceJobManager updatedResourceJobManager) throws AppCatalogException { + public boolean updateResourceJobManager(String resourceJobManagerId, ResourceJobManager updatedResourceJobManager) + throws AppCatalogException { return registryService.updateResourceJobManager(resourceJobManagerId, updatedResourceJobManager); } @@ -649,31 +721,41 @@ public boolean deleteResourceJobManager(String resourceJobManagerId) throws AppC return registryService.deleteResourceJobManager(resourceJobManagerId); } - public String addPasswordCredential(CredentialStoreService.Client csClient, PasswordCredential passwordCredential) throws CredentialStoreException, TException { + public String addPasswordCredential(CredentialStoreService.Client csClient, PasswordCredential passwordCredential) + throws CredentialStoreException, TException { return csClient.addPasswordCredential(passwordCredential); } - public void deletePWDCredential(CredentialStoreService.Client csClient, String tokenId, String gatewayId) throws CredentialStoreException, TException { + public void deletePWDCredential(CredentialStoreService.Client csClient, String tokenId, String gatewayId) + throws CredentialStoreException, TException { csClient.deletePWDCredential(tokenId, gatewayId); } - public boolean deleteSSHCredential(CredentialStoreService.Client csClient, String tokenId, String gatewayId) throws CredentialStoreException, TException { + public boolean deleteSSHCredential(CredentialStoreService.Client csClient, String tokenId, String gatewayId) + throws CredentialStoreException, TException { return csClient.deleteSSHCredential(tokenId, gatewayId); } - public CredentialSummary getCredentialSummary(CredentialStoreService.Client csClient, String tokenId, String gatewayId) throws CredentialStoreException, TException { + public CredentialSummary getCredentialSummary( + CredentialStoreService.Client csClient, String tokenId, String gatewayId) + throws CredentialStoreException, TException { return csClient.getCredentialSummary(tokenId, gatewayId); } - public List getAllCredentialSummaries(CredentialStoreService.Client csClient, SummaryType type, List accessibleTokenIds, String gatewayId) throws CredentialStoreException, TException { + public List getAllCredentialSummaries( + CredentialStoreService.Client csClient, SummaryType type, List accessibleTokenIds, String gatewayId) + throws CredentialStoreException, TException { return csClient.getAllCredentialSummaries(type, accessibleTokenIds, gatewayId); } - public String addLocalDataMovementDetails(String resourceId, DMType dmType, int priorityOrder, LOCALDataMovement localDataMovement) throws AppCatalogException { + public String addLocalDataMovementDetails( + String resourceId, DMType dmType, int priorityOrder, LOCALDataMovement localDataMovement) + throws AppCatalogException { return registryService.addLocalDataMovementDetails(resourceId, dmType, priorityOrder, localDataMovement); } - public boolean updateLocalDataMovementDetails(String dataMovementInterfaceId, LOCALDataMovement localDataMovement) throws AppCatalogException { + public boolean updateLocalDataMovementDetails(String dataMovementInterfaceId, LOCALDataMovement localDataMovement) + throws AppCatalogException { return registryService.updateLocalDataMovementDetails(dataMovementInterfaceId, localDataMovement); } @@ -681,15 +763,19 @@ public LOCALDataMovement getLocalDataMovement(String dataMovementId) throws AppC return registryService.getLocalDataMovement(dataMovementId); } - public String addSCPDataMovementDetails(String resourceId, DMType dmType, int priorityOrder, SCPDataMovement scpDataMovement) throws AppCatalogException { + public String addSCPDataMovementDetails( + String resourceId, DMType dmType, int priorityOrder, SCPDataMovement scpDataMovement) + throws AppCatalogException { return registryService.addSCPDataMovementDetails(resourceId, dmType, priorityOrder, scpDataMovement); } - public boolean updateSCPDataMovementDetails(String dataMovementInterfaceId, SCPDataMovement scpDataMovement) throws AppCatalogException { + public boolean updateSCPDataMovementDetails(String dataMovementInterfaceId, SCPDataMovement scpDataMovement) + throws AppCatalogException { return registryService.updateSCPDataMovementDetails(dataMovementInterfaceId, scpDataMovement); } - public List getUserProjects(String gatewayId, String userName, int limit, int offset) throws RegistryException { + public List getUserProjects(String gatewayId, String userName, int limit, int offset) + throws RegistryException { return registryService.getUserProjects(gatewayId, userName, limit, offset); } @@ -702,7 +788,8 @@ public List getUserProjectsWithSharing( String gatewayId, String userName, int limit, - int offset) throws Exception { + int offset) + throws Exception { if (ServerSettings.isEnableSharing()) { // user projects + user accessible projects List accessibleProjectIds = new ArrayList<>(); @@ -725,8 +812,7 @@ public List getUserProjectsWithSharing( if (accessibleProjectIds.isEmpty()) { result = Collections.emptyList(); } else { - result = searchProjects( - gatewayId, userName, accessibleProjectIds, new HashMap<>(), limit, offset); + result = searchProjects(gatewayId, userName, accessibleProjectIds, new HashMap<>(), limit, offset); } return result; } else { @@ -734,8 +820,11 @@ public List getUserProjectsWithSharing( } } - public List getAccessibleApplicationDeployments(String gatewayId, List accessibleAppDeploymentIds, List accessibleComputeResourceIds) throws AppCatalogException { - return registryService.getAccessibleApplicationDeployments(gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); + public List getAccessibleApplicationDeployments( + String gatewayId, List accessibleAppDeploymentIds, List accessibleComputeResourceIds) + throws AppCatalogException { + return registryService.getAccessibleApplicationDeployments( + gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); } /** @@ -745,7 +834,8 @@ public List getAccessibleApplicationDeployment SharingRegistryService.Client sharingClient, AuthzToken authzToken, String gatewayId, - ResourcePermissionType permissionType) throws Exception { + ResourcePermissionType permissionType) + throws Exception { String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); List accessibleAppDeploymentIds = new ArrayList<>(); if (ServerSettings.isEnableSharing()) { @@ -770,13 +860,12 @@ public List getAccessibleApplicationDeployment .forEach(a -> accessibleAppDeploymentIds.add(a.getEntityId())); } List accessibleComputeResourceIds = new ArrayList<>(); - List groupResourceProfileList = getGroupResourceListWithSharing( - sharingClient, authzToken, gatewayId); + List groupResourceProfileList = + getGroupResourceListWithSharing(sharingClient, authzToken, gatewayId); for (GroupResourceProfile groupResourceProfile : groupResourceProfileList) { List groupComputeResourcePreferenceList = groupResourceProfile.getComputePreferences(); - for (GroupComputeResourcePreference groupComputeResourcePreference : - groupComputeResourcePreferenceList) { + for (GroupComputeResourcePreference groupComputeResourcePreference : groupComputeResourcePreferenceList) { accessibleComputeResourceIds.add(groupComputeResourcePreference.getComputeResourceId()); } } @@ -787,11 +876,18 @@ public List getAppModuleDeployedResources(String appModuleId) throws App return registryService.getAppModuleDeployedResources(appModuleId); } - public List getAccessibleApplicationDeploymentsForAppModule(String appModuleId, String gatewayId, List accessibleAppDeploymentIds, List accessibleComputeResourceIds) throws AppCatalogException { - return registryService.getAccessibleApplicationDeploymentsForAppModule(gatewayId, appModuleId, accessibleAppDeploymentIds, accessibleComputeResourceIds); + public List getAccessibleApplicationDeploymentsForAppModule( + String appModuleId, + String gatewayId, + List accessibleAppDeploymentIds, + List accessibleComputeResourceIds) + throws AppCatalogException { + return registryService.getAccessibleApplicationDeploymentsForAppModule( + gatewayId, appModuleId, accessibleAppDeploymentIds, accessibleComputeResourceIds); } - public Map getAvailableAppInterfaceComputeResources(String appInterfaceId) throws AppCatalogException { + public Map getAvailableAppInterfaceComputeResources(String appInterfaceId) + throws AppCatalogException { return registryService.getAvailableAppInterfaceComputeResources(appInterfaceId); } @@ -799,11 +895,14 @@ public SCPDataMovement getSCPDataMovement(String dataMovementId) throws AppCatal return registryService.getSCPDataMovement(dataMovementId); } - public String addUnicoreDataMovementDetails(String resourceId, DMType dmType, int priorityOrder, UnicoreDataMovement unicoreDataMovement) throws AppCatalogException { + public String addUnicoreDataMovementDetails( + String resourceId, DMType dmType, int priorityOrder, UnicoreDataMovement unicoreDataMovement) + throws AppCatalogException { return registryService.addUnicoreDataMovementDetails(resourceId, dmType, priorityOrder, unicoreDataMovement); } - public boolean updateUnicoreDataMovementDetails(String dataMovementInterfaceId, UnicoreDataMovement unicoreDataMovement) throws AppCatalogException { + public boolean updateUnicoreDataMovementDetails( + String dataMovementInterfaceId, UnicoreDataMovement unicoreDataMovement) throws AppCatalogException { return registryService.updateUnicoreDataMovementDetails(dataMovementInterfaceId, unicoreDataMovement); } @@ -811,11 +910,14 @@ public UnicoreDataMovement getUnicoreDataMovement(String dataMovementId) throws return registryService.getUnicoreDataMovement(dataMovementId); } - public String addGridFTPDataMovementDetails(String resourceId, DMType dmType, int priorityOrder, GridFTPDataMovement gridFTPDataMovement) throws AppCatalogException { + public String addGridFTPDataMovementDetails( + String resourceId, DMType dmType, int priorityOrder, GridFTPDataMovement gridFTPDataMovement) + throws AppCatalogException { return registryService.addGridFTPDataMovementDetails(resourceId, dmType, priorityOrder, gridFTPDataMovement); } - public boolean updateGridFTPDataMovementDetails(String dataMovementInterfaceId, GridFTPDataMovement gridFTPDataMovement) throws AppCatalogException { + public boolean updateGridFTPDataMovementDetails( + String dataMovementInterfaceId, GridFTPDataMovement gridFTPDataMovement) throws AppCatalogException { return registryService.updateGridFTPDataMovementDetails(dataMovementInterfaceId, gridFTPDataMovement); } @@ -823,7 +925,8 @@ public GridFTPDataMovement getGridFTPDataMovement(String dataMovementId) throws return registryService.getGridFTPDataMovement(dataMovementId); } - public boolean deleteDataMovementInterface(String resourceId, String dataMovementInterfaceId, DMType dmType) throws AppCatalogException { + public boolean deleteDataMovementInterface(String resourceId, String dataMovementInterfaceId, DMType dmType) + throws AppCatalogException { return registryService.deleteDataMovementInterface(resourceId, dataMovementInterfaceId, dmType); } @@ -831,23 +934,31 @@ public boolean deleteBatchQueue(String computeResourceId, String queueName) thro return registryService.deleteBatchQueue(computeResourceId, queueName); } - public boolean addGatewayComputeResourcePreference(String gatewayID, String computeResourceId, ComputeResourcePreference computeResourcePreference) throws AppCatalogException { - return registryService.addGatewayComputeResourcePreference(gatewayID, computeResourceId, computeResourcePreference); + public boolean addGatewayComputeResourcePreference( + String gatewayID, String computeResourceId, ComputeResourcePreference computeResourcePreference) + throws AppCatalogException { + return registryService.addGatewayComputeResourcePreference( + gatewayID, computeResourceId, computeResourcePreference); } - public boolean addGatewayStoragePreference(String gatewayID, String storageResourceId, StoragePreference dataStoragePreference) throws AppCatalogException { + public boolean addGatewayStoragePreference( + String gatewayID, String storageResourceId, StoragePreference dataStoragePreference) + throws AppCatalogException { return registryService.addGatewayStoragePreference(gatewayID, storageResourceId, dataStoragePreference); } - public ComputeResourcePreference getGatewayComputeResourcePreference(String gatewayID, String computeResourceId) throws AppCatalogException { + public ComputeResourcePreference getGatewayComputeResourcePreference(String gatewayID, String computeResourceId) + throws AppCatalogException { return registryService.getGatewayComputeResourcePreference(gatewayID, computeResourceId); } - public StoragePreference getGatewayStoragePreference(String gatewayID, String storageId) throws AppCatalogException { + public StoragePreference getGatewayStoragePreference(String gatewayID, String storageId) + throws AppCatalogException { return registryService.getGatewayStoragePreference(gatewayID, storageId); } - public List getAllGatewayComputeResourcePreferences(String gatewayID) throws AppCatalogException { + public List getAllGatewayComputeResourcePreferences(String gatewayID) + throws AppCatalogException { return registryService.getAllGatewayComputeResourcePreferences(gatewayID); } @@ -859,15 +970,20 @@ public List getAllGatewayResourceProfiles() throws AppCa return registryService.getAllGatewayResourceProfiles(); } - public boolean updateGatewayComputeResourcePreference(String gatewayID, String computeResourceId, ComputeResourcePreference computeResourcePreference) throws AppCatalogException { - return registryService.updateGatewayComputeResourcePreference(gatewayID, computeResourceId, computeResourcePreference); + public boolean updateGatewayComputeResourcePreference( + String gatewayID, String computeResourceId, ComputeResourcePreference computeResourcePreference) + throws AppCatalogException { + return registryService.updateGatewayComputeResourcePreference( + gatewayID, computeResourceId, computeResourcePreference); } - public boolean updateGatewayStoragePreference(String gatewayID, String storageId, StoragePreference dataStoragePreference) throws AppCatalogException { + public boolean updateGatewayStoragePreference( + String gatewayID, String storageId, StoragePreference dataStoragePreference) throws AppCatalogException { return registryService.updateGatewayStoragePreference(gatewayID, storageId, dataStoragePreference); } - public boolean deleteGatewayComputeResourcePreference(String gatewayID, String computeResourceId) throws AppCatalogException { + public boolean deleteGatewayComputeResourcePreference(String gatewayID, String computeResourceId) + throws AppCatalogException { return registryService.deleteGatewayComputeResourcePreference(gatewayID, computeResourceId); } @@ -883,27 +999,40 @@ public boolean isUserResourceProfileExists(String userId, String gatewayId) thro return registryService.isUserResourceProfileExists(userId, gatewayId); } - public boolean addUserComputeResourcePreference(String userId, String gatewayID, String computeResourceId, UserComputeResourcePreference userComputeResourcePreference) throws AppCatalogException { - return registryService.addUserComputeResourcePreference(userId, gatewayID, computeResourceId, userComputeResourcePreference); + public boolean addUserComputeResourcePreference( + String userId, + String gatewayID, + String computeResourceId, + UserComputeResourcePreference userComputeResourcePreference) + throws AppCatalogException { + return registryService.addUserComputeResourcePreference( + userId, gatewayID, computeResourceId, userComputeResourcePreference); } - public boolean addUserStoragePreference(String userId, String gatewayID, String userStorageResourceId, UserStoragePreference dataStoragePreference) throws AppCatalogException { - return registryService.addUserStoragePreference(userId, gatewayID, userStorageResourceId, dataStoragePreference); + public boolean addUserStoragePreference( + String userId, String gatewayID, String userStorageResourceId, UserStoragePreference dataStoragePreference) + throws AppCatalogException { + return registryService.addUserStoragePreference( + userId, gatewayID, userStorageResourceId, dataStoragePreference); } - public UserComputeResourcePreference getUserComputeResourcePreference(String userId, String gatewayID, String userComputeResourceId) throws AppCatalogException { + public UserComputeResourcePreference getUserComputeResourcePreference( + String userId, String gatewayID, String userComputeResourceId) throws AppCatalogException { return registryService.getUserComputeResourcePreference(userId, gatewayID, userComputeResourceId); } - public UserStoragePreference getUserStoragePreference(String userId, String gatewayID, String userStorageId) throws AppCatalogException { + public UserStoragePreference getUserStoragePreference(String userId, String gatewayID, String userStorageId) + throws AppCatalogException { return registryService.getUserStoragePreference(userId, gatewayID, userStorageId); } - public List getAllUserComputeResourcePreferences(String userId, String gatewayID) throws AppCatalogException { + public List getAllUserComputeResourcePreferences(String userId, String gatewayID) + throws AppCatalogException { return registryService.getAllUserComputeResourcePreferences(userId, gatewayID); } - public List getAllUserStoragePreferences(String userId, String gatewayID) throws AppCatalogException { + public List getAllUserStoragePreferences(String userId, String gatewayID) + throws AppCatalogException { return registryService.getAllUserStoragePreferences(userId, gatewayID); } @@ -911,19 +1040,29 @@ public List getAllUserResourceProfiles() throws AppCatalogE return registryService.getAllUserResourceProfiles(); } - public boolean updateUserComputeResourcePreference(String userId, String gatewayID, String computeResourceId, UserComputeResourcePreference userComputeResourcePreference) throws AppCatalogException { - return registryService.updateUserComputeResourcePreference(userId, gatewayID, computeResourceId, userComputeResourcePreference); + public boolean updateUserComputeResourcePreference( + String userId, + String gatewayID, + String computeResourceId, + UserComputeResourcePreference userComputeResourcePreference) + throws AppCatalogException { + return registryService.updateUserComputeResourcePreference( + userId, gatewayID, computeResourceId, userComputeResourcePreference); } - public boolean updateUserStoragePreference(String userId, String gatewayID, String userStorageId, UserStoragePreference userStoragePreference) throws AppCatalogException { + public boolean updateUserStoragePreference( + String userId, String gatewayID, String userStorageId, UserStoragePreference userStoragePreference) + throws AppCatalogException { return registryService.updateUserStoragePreference(userId, gatewayID, userStorageId, userStoragePreference); } - public boolean deleteUserComputeResourcePreference(String userId, String gatewayID, String userComputeResourceId) throws AppCatalogException { + public boolean deleteUserComputeResourcePreference(String userId, String gatewayID, String userComputeResourceId) + throws AppCatalogException { return registryService.deleteUserComputeResourcePreference(userId, gatewayID, userComputeResourceId); } - public boolean deleteUserStoragePreference(String userId, String gatewayID, String userStorageId) throws AppCatalogException { + public boolean deleteUserStoragePreference(String userId, String gatewayID, String userStorageId) + throws AppCatalogException { return registryService.deleteUserStoragePreference(userId, gatewayID, userStorageId); } @@ -939,11 +1078,13 @@ public boolean removeGroupResourceProfile(String groupResourceProfileId) throws return registryService.removeGroupResourceProfile(groupResourceProfileId); } - public boolean removeGroupComputePrefs(String computeResourceId, String groupResourceProfileId) throws AppCatalogException { + public boolean removeGroupComputePrefs(String computeResourceId, String groupResourceProfileId) + throws AppCatalogException { return registryService.removeGroupComputePrefs(computeResourceId, groupResourceProfileId); } - public GroupComputeResourcePreference getGroupComputeResourcePreference(String computeResourceId, String groupResourceProfileId) throws AppCatalogException { + public GroupComputeResourcePreference getGroupComputeResourcePreference( + String computeResourceId, String groupResourceProfileId) throws AppCatalogException { return registryService.getGroupComputeResourcePreference(computeResourceId, groupResourceProfileId); } @@ -963,15 +1104,18 @@ public boolean removeGroupBatchQueueResourcePolicy(String resourcePolicyId) thro return registryService.removeGroupBatchQueueResourcePolicy(resourcePolicyId); } - public List getGroupComputeResourcePrefList(String groupResourceProfileId) throws AppCatalogException { + public List getGroupComputeResourcePrefList(String groupResourceProfileId) + throws AppCatalogException { return registryService.getGroupComputeResourcePrefList(groupResourceProfileId); } - public List getGroupBatchQueueResourcePolicyList(String groupResourceProfileId) throws AppCatalogException { + public List getGroupBatchQueueResourcePolicyList(String groupResourceProfileId) + throws AppCatalogException { return registryService.getGroupBatchQueueResourcePolicyList(groupResourceProfileId); } - public List getGroupComputeResourcePolicyList(String groupResourceProfileId) throws AppCatalogException { + public List getGroupComputeResourcePolicyList(String groupResourceProfileId) + throws AppCatalogException { return registryService.getGroupComputeResourcePolicyList(groupResourceProfileId); } @@ -995,7 +1139,8 @@ public ParsingTemplate getParsingTemplate(String templateId, String gatewayId) t return registryService.getParsingTemplate(templateId, gatewayId); } - public List getParsingTemplatesForExperiment(String experimentId, String gatewayId) throws RegistryException { + public List getParsingTemplatesForExperiment(String experimentId, String gatewayId) + throws RegistryException { return registryService.getParsingTemplatesForExperiment(experimentId, gatewayId); } @@ -1024,8 +1169,8 @@ public GatewayGroups retrieveGatewayGroups(String gatewayId) throws TException { } } - public void createManageSharingPermissionTypeIfMissing( - SharingRegistryService.Client sharingClient, String domainId) throws TException { + public void createManageSharingPermissionTypeIfMissing(SharingRegistryService.Client sharingClient, String domainId) + throws TException { // AIRAVATA-3297 Some gateways were created without the MANAGE_SHARING permission, so add it if missing String permissionTypeId = domainId + ":MANAGE_SHARING"; try { @@ -1045,8 +1190,7 @@ public void createManageSharingPermissionTypeIfMissing( } } - public void shareEntityWithAdminGatewayGroups( - SharingRegistryService.Client sharingClient, Entity entity) + public void shareEntityWithAdminGatewayGroups(SharingRegistryService.Client sharingClient, Entity entity) throws TException { final String domainId = entity.getDomainId(); GatewayGroups gatewayGroups = retrieveGatewayGroups(domainId); @@ -1109,7 +1253,8 @@ public String generateAndRegisterSSHKeys( SharingRegistryService.Client sharingClient, String gatewayId, String userName, - String description) throws Exception { + String description) + throws Exception { SSHCredential sshCredential = new SSHCredential(); sshCredential.setUsername(userName); sshCredential.setGatewayId(gatewayId); @@ -1126,8 +1271,8 @@ public String generateAndRegisterSSHKeys( sharingClient.createEntity(entity); } catch (Exception ex) { logger.error(ex.getMessage(), ex); - logger.error("Rolling back ssh key creation for user " + userName + " and description [" + description - + "]"); + logger.error( + "Rolling back ssh key creation for user " + userName + " and description [" + description + "]"); csClient.deleteSSHCredential(key, gatewayId); throw new Exception("Failed to create sharing registry record", ex); } @@ -1142,7 +1287,8 @@ public String registerPwdCredential( String userName, String loginUserName, String password, - String description) throws Exception { + String description) + throws Exception { PasswordCredential pwdCredential = new PasswordCredential(); pwdCredential.setPortalUserName(userName); pwdCredential.setLoginUserName(loginUserName); @@ -1161,8 +1307,8 @@ public String registerPwdCredential( sharingClient.createEntity(entity); } catch (Exception ex) { logger.error(ex.getMessage(), ex); - logger.error("Rolling back password registration for user " + userName + " and description [" - + description + "]"); + logger.error("Rolling back password registration for user " + userName + " and description [" + description + + "]"); try { deletePWDCredential(csClient, key, gatewayId); } catch (Exception rollbackEx) { @@ -1170,8 +1316,8 @@ public String registerPwdCredential( } throw new Exception("Failed to create sharing registry record", ex); } - logger.debug("Airavata generated PWD credential for gateway : " + gatewayId + " and for user : " - + loginUserName); + logger.debug( + "Airavata generated PWD credential for gateway : " + gatewayId + " and for user : " + loginUserName); return key; } @@ -1180,7 +1326,8 @@ public CredentialSummary getCredentialSummaryWithAuth( SharingRegistryService.Client sharingClient, AuthzToken authzToken, String tokenId, - String gatewayId) throws Exception { + String gatewayId) + throws Exception { if (!userHasAccessInternal(sharingClient, authzToken, tokenId, ResourcePermissionType.READ)) { throw new Exception("User does not have permission to access this resource"); } @@ -1195,7 +1342,8 @@ public List getAllCredentialSummariesWithAuth( AuthzToken authzToken, SummaryType type, String gatewayId, - String userName) throws Exception { + String userName) + throws Exception { List filters = new ArrayList<>(); SearchCriteria searchCriteria = new SearchCriteria(); searchCriteria.setSearchField(EntitySearchField.ENTITY_TYPE_ID); @@ -1218,9 +1366,9 @@ public boolean deleteSSHPubKey( SharingRegistryService.Client sharingClient, AuthzToken authzToken, String airavataCredStoreToken, - String gatewayId) throws Exception { - if (!userHasAccessInternal( - sharingClient, authzToken, airavataCredStoreToken, ResourcePermissionType.WRITE)) { + String gatewayId) + throws Exception { + if (!userHasAccessInternal(sharingClient, authzToken, airavataCredStoreToken, ResourcePermissionType.WRITE)) { throw new Exception("User does not have permission to delete this resource."); } logger.debug("Airavata deleted SSH pub key for gateway Id : " + gatewayId + " and with token id : " @@ -1233,9 +1381,9 @@ public boolean deletePWDCredentialWithAuth( SharingRegistryService.Client sharingClient, AuthzToken authzToken, String airavataCredStoreToken, - String gatewayId) throws Exception { - if (!userHasAccessInternal( - sharingClient, authzToken, airavataCredStoreToken, ResourcePermissionType.WRITE)) { + String gatewayId) + throws Exception { + if (!userHasAccessInternal(sharingClient, authzToken, airavataCredStoreToken, ResourcePermissionType.WRITE)) { throw new Exception("User does not have permission to delete this resource."); } logger.debug("Airavata deleted PWD credential for gateway Id : " + gatewayId + " and with token id : " @@ -1246,9 +1394,7 @@ public boolean deletePWDCredentialWithAuth( // Project management methods with sharing registry integration public String createProjectWithSharing( - SharingRegistryService.Client sharingClient, - String gatewayId, - Project project) throws Exception { + SharingRegistryService.Client sharingClient, String gatewayId, Project project) throws Exception { String projectId = createProject(gatewayId, project); if (ServerSettings.isEnableSharing()) { try { @@ -1280,21 +1426,15 @@ public void updateProjectWithAuth( SharingRegistryService.Client sharingClient, AuthzToken authzToken, String projectId, - Project updatedProject) throws Exception { + Project updatedProject) + throws Exception { Project existingProject = getProject(projectId); if (ServerSettings.isEnableSharing() - && !authzToken - .getClaimsMap() - .get(Constants.USER_NAME) - .equals(existingProject.getOwner()) - || !authzToken - .getClaimsMap() - .get(Constants.GATEWAY_ID) - .equals(existingProject.getGatewayId())) { + && !authzToken.getClaimsMap().get(Constants.USER_NAME).equals(existingProject.getOwner()) + || !authzToken.getClaimsMap().get(Constants.GATEWAY_ID).equals(existingProject.getGatewayId())) { 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")) { + if (!sharingClient.userHasAccess(gatewayId, userId + "@" + gatewayId, projectId, gatewayId + ":WRITE")) { throw new Exception("User does not have permission to access this resource"); } } @@ -1309,23 +1449,14 @@ public void updateProjectWithAuth( } public boolean deleteProjectWithAuth( - SharingRegistryService.Client sharingClient, - AuthzToken authzToken, - String projectId) throws Exception { + SharingRegistryService.Client sharingClient, AuthzToken authzToken, String projectId) throws Exception { Project existingProject = getProject(projectId); if (ServerSettings.isEnableSharing() - && !authzToken - .getClaimsMap() - .get(Constants.USER_NAME) - .equals(existingProject.getOwner()) - || !authzToken - .getClaimsMap() - .get(Constants.GATEWAY_ID) - .equals(existingProject.getGatewayId())) { + && !authzToken.getClaimsMap().get(Constants.USER_NAME).equals(existingProject.getOwner()) + || !authzToken.getClaimsMap().get(Constants.GATEWAY_ID).equals(existingProject.getGatewayId())) { 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")) { + if (!sharingClient.userHasAccess(gatewayId, userId + "@" + gatewayId, projectId, gatewayId + ":WRITE")) { throw new Exception("User does not have permission to access this resource"); } } @@ -1335,24 +1466,15 @@ public boolean deleteProjectWithAuth( } public Project getProjectWithAuth( - SharingRegistryService.Client sharingClient, - AuthzToken authzToken, - String projectId) throws Exception { + SharingRegistryService.Client sharingClient, AuthzToken authzToken, String projectId) throws Exception { Project project = getProject(projectId); - if (authzToken - .getClaimsMap() - .get(Constants.USER_NAME) - .equals(project.getOwner()) - && authzToken - .getClaimsMap() - .get(Constants.GATEWAY_ID) - .equals(project.getGatewayId())) { + if (authzToken.getClaimsMap().get(Constants.USER_NAME).equals(project.getOwner()) + && authzToken.getClaimsMap().get(Constants.GATEWAY_ID).equals(project.getGatewayId())) { return project; } else if (ServerSettings.isEnableSharing()) { 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")) { + if (!sharingClient.userHasAccess(gatewayId, userId + "@" + gatewayId, projectId, gatewayId + ":READ")) { throw new Exception("User does not have permission to access this resource"); } return project; @@ -1363,9 +1485,8 @@ public Project getProjectWithAuth( // Experiment management methods with sharing registry integration public String createExperimentWithSharing( - SharingRegistryService.Client sharingClient, - String gatewayId, - ExperimentModel experiment) throws Exception { + SharingRegistryService.Client sharingClient, String gatewayId, ExperimentModel experiment) + throws Exception { String experimentId = createExperiment(gatewayId, experiment); if (ServerSettings.isEnableSharing()) { @@ -1402,9 +1523,10 @@ public String createExperimentWithSharingAndPublish( SharingRegistryService.Client sharingClient, Publisher statusPublisher, String gatewayId, - ExperimentModel experiment) throws Exception { + ExperimentModel experiment) + throws Exception { String experimentId = createExperimentWithSharing(sharingClient, gatewayId, experiment); - + if (statusPublisher != null) { ExperimentStatusChangeEvent event = new ExperimentStatusChangeEvent(ExperimentState.CREATED, experimentId, gatewayId); @@ -1413,7 +1535,7 @@ public String createExperimentWithSharingAndPublish( messageContext.setUpdatedTime(AiravataUtils.getCurrentTimestamp()); statusPublisher.publish(messageContext); } - + return experimentId; } @@ -1421,7 +1543,8 @@ public void validateLaunchExperimentAccess( SharingRegistryService.Client sharingClient, AuthzToken authzToken, String gatewayId, - ExperimentModel experiment) throws Exception { + ExperimentModel experiment) + throws Exception { String username = authzToken.getClaimsMap().get(Constants.USER_NAME); // For backwards compatibility, if there is no groupResourceProfileId, look up one that is shared with the user @@ -1443,8 +1566,7 @@ public void validateLaunchExperimentAccess( // Verify user has READ access to Application Deployment final String appInterfaceId = experiment.getExecutionId(); - ApplicationInterfaceDescription applicationInterfaceDescription = - getApplicationInterface(appInterfaceId); + ApplicationInterfaceDescription applicationInterfaceDescription = getApplicationInterface(appInterfaceId); List appModuleIds = applicationInterfaceDescription.getApplicationModules(); // Assume that there is only one app module for this interface @@ -1471,8 +1593,8 @@ public void validateLaunchExperimentAccess( + " doesn't have access to app deployment " + appDeploymentId); } } else { - throw new Exception("Application deployment doesn't exist for application interface " - + appInterfaceId + " and host " + resourceHostId + " in gateway " + gatewayId); + throw new Exception("Application deployment doesn't exist for application interface " + appInterfaceId + + " and host " + resourceHostId + " in gateway " + gatewayId); } } else if (experiment.getUserConfigurationData().getAutoScheduledCompResourceSchedulingList() != null && !experiment @@ -1500,29 +1622,21 @@ public void validateLaunchExperimentAccess( } public boolean deleteExperimentWithAuth( - SharingRegistryService.Client sharingClient, - AuthzToken authzToken, - String experimentId) throws Exception { + SharingRegistryService.Client sharingClient, AuthzToken authzToken, String experimentId) throws Exception { ExperimentModel experimentModel = getExperiment(experimentId); if (ServerSettings.isEnableSharing() - && !authzToken - .getClaimsMap() - .get(Constants.USER_NAME) - .equals(experimentModel.getUserName()) - || !authzToken - .getClaimsMap() - .get(Constants.GATEWAY_ID) - .equals(experimentModel.getGatewayId())) { + && !authzToken.getClaimsMap().get(Constants.USER_NAME).equals(experimentModel.getUserName()) + || !authzToken.getClaimsMap().get(Constants.GATEWAY_ID).equals(experimentModel.getGatewayId())) { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!sharingClient.userHasAccess( - gatewayId, userId + "@" + gatewayId, experimentId, gatewayId + ":WRITE")) { + if (!sharingClient.userHasAccess(gatewayId, userId + "@" + gatewayId, experimentId, gatewayId + ":WRITE")) { throw new Exception("User does not have permission to access this resource"); } } - if (!(experimentModel.getExperimentStatus().get(0).getState() == org.apache.airavata.model.status.ExperimentState.CREATED)) { + if (!(experimentModel.getExperimentStatus().get(0).getState() + == org.apache.airavata.model.status.ExperimentState.CREATED)) { throw new Exception("Experiment is not in CREATED state. Hence cannot deleted. ID:" + experimentId); } return deleteExperiment(experimentId); @@ -1541,9 +1655,8 @@ public ResourceType getResourceType(SharingRegistryService.Client sharingClient, // Gateway management methods with sharing registry integration public String addGatewayWithSharing( - RegistryService.Client registryClient, - SharingRegistryService.Client sharingClient, - Gateway gateway) throws Exception { + RegistryService.Client registryClient, SharingRegistryService.Client sharingClient, Gateway gateway) + throws Exception { String gatewayId = registryClient.addGateway(gateway); Domain domain = new Domain(); domain.setDomainId(gateway.getGatewayId()); @@ -1614,7 +1727,8 @@ public String addGatewayWithSharing( } // Event publishing methods - public void publishExperimentSubmitEvent(Publisher experimentPublisher, String gatewayId, String experimentId) throws Exception { + public void publishExperimentSubmitEvent(Publisher experimentPublisher, String gatewayId, String experimentId) + throws Exception { ExperimentSubmitEvent event = new ExperimentSubmitEvent(experimentId, gatewayId); MessageContext messageContext = new MessageContext( event, MessageType.EXPERIMENT, "LAUNCH.EXP-" + UUID.randomUUID().toString(), gatewayId); @@ -1622,7 +1736,8 @@ public void publishExperimentSubmitEvent(Publisher experimentPublisher, String g experimentPublisher.publish(messageContext); } - public void publishExperimentCancelEvent(Publisher experimentPublisher, String gatewayId, String experimentId) throws Exception { + public void publishExperimentCancelEvent(Publisher experimentPublisher, String gatewayId, String experimentId) + throws Exception { ExperimentSubmitEvent event = new ExperimentSubmitEvent(experimentId, gatewayId); MessageContext messageContext = new MessageContext( event, @@ -1634,7 +1749,8 @@ public void publishExperimentCancelEvent(Publisher experimentPublisher, String g } public void publishExperimentIntermediateOutputsEvent( - Publisher experimentPublisher, String gatewayId, String experimentId, List outputNames) throws Exception { + Publisher experimentPublisher, String gatewayId, String experimentId, List outputNames) + throws Exception { ExperimentIntermediateOutputsEvent event = new ExperimentIntermediateOutputsEvent(experimentId, gatewayId, outputNames); MessageContext messageContext = new MessageContext( @@ -1654,10 +1770,11 @@ public void validateAndFetchIntermediateOutputs( AuthzToken authzToken, String airavataExperimentId, List outputNames, - Publisher experimentPublisher) throws Exception { + Publisher experimentPublisher) + throws Exception { // Verify that user has WRITE access to experiment - final boolean hasAccess = userHasAccessInternal( - sharingClient, authzToken, airavataExperimentId, ResourcePermissionType.WRITE); + final boolean hasAccess = + userHasAccessInternal(sharingClient, authzToken, airavataExperimentId, ResourcePermissionType.WRITE); if (!hasAccess) { throw new Exception("User does not have WRITE access to this experiment"); } @@ -1708,10 +1825,11 @@ public ProcessStatus getIntermediateOutputProcessStatusInternal( SharingRegistryService.Client sharingClient, AuthzToken authzToken, String airavataExperimentId, - List outputNames) throws Exception { + List outputNames) + throws Exception { // Verify that user has READ access to experiment - final boolean hasAccess = userHasAccessInternal( - sharingClient, authzToken, airavataExperimentId, ResourcePermissionType.READ); + final boolean hasAccess = + userHasAccessInternal(sharingClient, authzToken, airavataExperimentId, ResourcePermissionType.READ); if (!hasAccess) { throw new Exception("User does not have READ access to this experiment"); } @@ -1724,13 +1842,11 @@ public ProcessStatus getIntermediateOutputProcessStatusInternal( Optional mostRecentOutputFetchProcess = existingExperiment.getProcesses().stream() .filter(p -> p.getTasks().stream().allMatch(t -> t.getTaskType() == TaskTypes.OUTPUT_FETCHING)) .filter(p -> { - List names = p.getProcessOutputs().stream() - .map(o -> o.getName()) - .collect(Collectors.toList()); + List names = + p.getProcessOutputs().stream().map(o -> o.getName()).collect(Collectors.toList()); return new HashSet<>(names).equals(new HashSet<>(outputNames)); }) - .sorted(Comparator.comparing(ProcessModel::getLastUpdateTime) - .reversed()) + .sorted(Comparator.comparing(ProcessModel::getLastUpdateTime).reversed()) .findFirst(); if (!mostRecentOutputFetchProcess.isPresent()) { @@ -1756,7 +1872,8 @@ public List getAllAccessibleUsers( String gatewayId, String resourceId, ResourcePermissionType permissionType, - BiFunction> userListFunction) throws Exception { + BiFunction> userListFunction) + throws Exception { HashSet accessibleUsers = new HashSet<>(); if (permissionType.equals(ResourcePermissionType.WRITE)) { userListFunction.apply(sharingClient, ResourcePermissionType.WRITE).stream() @@ -1785,7 +1902,8 @@ public List getAllAccessibleGroups( String gatewayId, String resourceId, ResourcePermissionType permissionType, - BiFunction> groupListFunction) throws Exception { + BiFunction> groupListFunction) + throws Exception { HashSet accessibleGroups = new HashSet<>(); if (permissionType.equals(ResourcePermissionType.WRITE)) { groupListFunction.apply(sharingClient, ResourcePermissionType.WRITE).stream() @@ -1808,7 +1926,8 @@ public List getAllAccessibleUsersWithSharing( AuthzToken authzToken, String resourceId, ResourcePermissionType permissionType, - boolean directlySharedOnly) throws Exception { + boolean directlySharedOnly) + throws Exception { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); BiFunction> userListFunction; if (directlySharedOnly) { @@ -1839,7 +1958,8 @@ public List getAllAccessibleGroupsWithSharing( AuthzToken authzToken, String resourceId, ResourcePermissionType permissionType, - boolean directlySharedOnly) throws Exception { + boolean directlySharedOnly) + throws Exception { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); BiFunction> groupListFunction; if (directlySharedOnly) { @@ -1866,7 +1986,8 @@ public List getAllAccessibleGroupsWithSharing( public String createGroupResourceProfileWithSharing( SharingRegistryService.Client sharingClient, AuthzToken authzToken, - GroupResourceProfile groupResourceProfile) throws Exception { + GroupResourceProfile groupResourceProfile) + throws Exception { String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); validateGroupResourceProfile(sharingClient, authzToken, groupResourceProfile); String groupResourceProfileId = createGroupResourceProfile(groupResourceProfile); @@ -1899,7 +2020,8 @@ public String createGroupResourceProfileWithSharing( public void validateGroupResourceProfile( SharingRegistryService.Client sharingClient, AuthzToken authzToken, - GroupResourceProfile groupResourceProfile) throws Exception { + GroupResourceProfile groupResourceProfile) + throws Exception { Set tokenIds = new HashSet<>(); if (groupResourceProfile.getComputePreferences() != null) { for (GroupComputeResourcePreference groupComputeResourcePreference : @@ -1925,7 +2047,8 @@ public void launchExperimentWithValidation( AuthzToken authzToken, String gatewayId, String airavataExperimentId, - Publisher experimentPublisher) throws Exception { + Publisher experimentPublisher) + throws Exception { ExperimentModel experiment = getExperiment(airavataExperimentId); if (experiment == null) { @@ -1935,8 +2058,8 @@ public void launchExperimentWithValidation( // For backwards compatibility, if there is no groupResourceProfileId, look up one that is shared with the user if (!experiment.getUserConfigurationData().isSetGroupResourceProfileId()) { - List groupResourceProfiles = getGroupResourceListWithSharing( - sharingClient, authzToken, gatewayId); + List groupResourceProfiles = + getGroupResourceListWithSharing(sharingClient, authzToken, gatewayId); if (groupResourceProfiles != null && !groupResourceProfiles.isEmpty()) { // Just pick the first one final String groupResourceProfileId = @@ -1962,9 +2085,7 @@ public void launchExperimentWithValidation( * Get group resource list with sharing registry integration */ public List getGroupResourceListWithSharing( - SharingRegistryService.Client sharingClient, - AuthzToken authzToken, - String gatewayId) throws Exception { + SharingRegistryService.Client sharingClient, AuthzToken authzToken, String gatewayId) throws Exception { String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); List accessibleGroupResProfileIds = new ArrayList<>(); if (ServerSettings.isEnableSharing()) { @@ -1987,4 +2108,3 @@ public List getGroupResourceListWithSharing( return getGroupResourceList(gatewayId, accessibleGroupResProfileIds); } } - diff --git a/airavata-api/src/main/java/org/apache/airavata/service/CredentialStoreService.java b/airavata-api/src/main/java/org/apache/airavata/service/CredentialStoreService.java index 129de089f2..314dbd3798 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/CredentialStoreService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/CredentialStoreService.java @@ -47,7 +47,7 @@ public class CredentialStoreService { private static final Logger logger = LoggerFactory.getLogger(CredentialStoreService.class); - + private DBUtil dbUtil; private SSHCredentialWriter sshCredentialWriter; private CertificateCredentialWriter certificateCredentialWriter; @@ -105,7 +105,8 @@ public String addSSHCredential(SSHCredential sshCredential) throws CredentialSto } } - public String addCertificateCredential(CertificateCredential certificateCredential) throws CredentialStoreException { + public String addCertificateCredential(CertificateCredential certificateCredential) + throws CredentialStoreException { try { org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential credential = new org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential(); @@ -191,9 +192,8 @@ public SSHCredential getSSHCredential(String tokenId, String gatewayId) throws C "Error occurred while retrieving SSH credentialfor token - " + tokenId + " and gateway id - " + gatewayId, e); - throw new CredentialStoreException( - "Error occurred while retrieving SSH credential for token - " + tokenId + " and gateway id - " - + gatewayId); + throw new CredentialStoreException("Error occurred while retrieving SSH credential for token - " + tokenId + + " and gateway id - " + gatewayId); } } @@ -211,8 +211,7 @@ public CredentialSummary getCredentialSummary(String tokenId, String gatewayId) return convertToCredentialSummary( (org.apache.airavata.credential.store.credential.impl.password.PasswordCredential) credential); } - throw new CredentialStoreException( - "Unrecognized type of credential for token: " + tokenId); + throw new CredentialStoreException("Unrecognized type of credential for token: " + tokenId); } catch (CredentialStoreException e) { final String msg = "Error occurred while retrieving credential summary for token - " + tokenId + " and gateway id - " + gatewayId; @@ -311,7 +310,8 @@ private CredentialSummary convertToCredentialSummary( return credentialSummary; } - public CertificateCredential getCertificateCredential(String tokenId, String gatewayId) throws CredentialStoreException { + public CertificateCredential getCertificateCredential(String tokenId, String gatewayId) + throws CredentialStoreException { try { Credential credential = credentialReader.getCredential(gatewayId, tokenId); if (credential @@ -348,9 +348,8 @@ public CertificateCredential getCertificateCredential(String tokenId, String gat "Error occurred while retrieving Certificate credential for token - " + tokenId + " and gateway id - " + gatewayId, e); - throw new CredentialStoreException( - "Error occurred while retrieving Certificate credential for token - " + tokenId - + " and gateway id - " + gatewayId); + throw new CredentialStoreException("Error occurred while retrieving Certificate credential for token - " + + tokenId + " and gateway id - " + gatewayId); } } @@ -381,14 +380,14 @@ public PasswordCredential getPasswordCredential(String tokenId, String gatewayId "Error occurred while retrieving PWD credentialfor token - " + tokenId + " and gateway id - " + gatewayId, e); - throw new CredentialStoreException( - "Error occurred while retrieving PWD credential for token - " + tokenId + " and gateway id - " - + gatewayId); + throw new CredentialStoreException("Error occurred while retrieving PWD credential for token - " + tokenId + + " and gateway id - " + gatewayId); } } @Deprecated - public List getAllCredentialSummaryForGateway(SummaryType type, String gatewayId) throws CredentialStoreException { + public List getAllCredentialSummaryForGateway(SummaryType type, String gatewayId) + throws CredentialStoreException { if (type.equals(SummaryType.SSH)) { Map sshKeyMap = new HashMap<>(); List summaryList = new ArrayList<>(); @@ -514,9 +513,8 @@ public boolean deleteSSHCredential(String tokenId, String gatewayId) throws Cred "Error occurred while deleting SSH credential for token - " + tokenId + " and gateway id - " + gatewayId, e); - throw new CredentialStoreException( - "Error occurred while deleting SSH credential for token - " + tokenId + " and gateway id - " - + gatewayId); + throw new CredentialStoreException("Error occurred while deleting SSH credential for token - " + tokenId + + " and gateway id - " + gatewayId); } } @@ -529,10 +527,8 @@ public boolean deletePWDCredential(String tokenId, String gatewayId) throws Cred "Error occurred while deleting PWD credential for token - " + tokenId + " and gateway id - " + gatewayId, e); - throw new CredentialStoreException( - "Error occurred while deleting PWD credential for token - " + tokenId + " and gateway id - " - + gatewayId); + throw new CredentialStoreException("Error occurred while deleting PWD credential for token - " + tokenId + + " and gateway id - " + gatewayId); } } } - diff --git a/airavata-api/src/main/java/org/apache/airavata/service/GroupManagerService.java b/airavata-api/src/main/java/org/apache/airavata/service/GroupManagerService.java index 3da76eabc9..78f3f8abb4 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/GroupManagerService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/GroupManagerService.java @@ -105,7 +105,8 @@ public boolean updateGroup(AuthzToken authzToken, GroupModel groupModel) throws } } - public boolean deleteGroup(AuthzToken authzToken, String groupId, String ownerId) throws GroupManagerServiceException { + public boolean deleteGroup(AuthzToken authzToken, String groupId, String ownerId) + throws GroupManagerServiceException { try { SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); String userId = getUserId(authzToken); @@ -394,4 +395,3 @@ private boolean internalAddUsersToGroup( return sharingClient.addUsersToGroup(domainId, userIds, groupId); } } - diff --git a/airavata-api/src/main/java/org/apache/airavata/service/IamAdminService.java b/airavata-api/src/main/java/org/apache/airavata/service/IamAdminService.java index 5a9ffd6d69..80e45c6138 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/IamAdminService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/IamAdminService.java @@ -254,8 +254,7 @@ public boolean removeRoleFromUser(AuthzToken authzToken, String username, String } } - public List getUsersWithRole(AuthzToken authzToken, String roleName) - throws IamAdminServicesException { + public List getUsersWithRole(AuthzToken authzToken, String roleName) throws IamAdminServicesException { TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl(); String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); try { @@ -309,4 +308,3 @@ private CredentialStoreService.Client getCredentialStoreServiceClient() } } } - diff --git a/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorRegistryService.java b/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorRegistryService.java index c9e8cb33d3..c734011a72 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorRegistryService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorRegistryService.java @@ -40,8 +40,9 @@ public class OrchestratorRegistryService { private static final Logger logger = LoggerFactory.getLogger(OrchestratorRegistryService.class); - - private org.apache.airavata.service.RegistryService registryService = new org.apache.airavata.service.RegistryService(); + + private org.apache.airavata.service.RegistryService registryService = + new org.apache.airavata.service.RegistryService(); public ExperimentModel getExperiment(String airavataExperimentId) throws RegistryException { return registryService.getExperiment(airavataExperimentId); @@ -104,7 +105,8 @@ public ApplicationInterfaceDescription getApplicationInterface(String appInterfa return registryService.getApplicationInterface(appInterfaceId); } - public List getApplicationDeployments(String appModuleId) throws AppCatalogException { + public List getApplicationDeployments(String appModuleId) + throws AppCatalogException { return registryService.getApplicationDeployments(appModuleId); } @@ -120,4 +122,3 @@ public void registerQueueStatuses(List queueStatuses) throws R registryService.registerQueueStatuses(queueStatuses); } } - diff --git a/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorService.java b/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorService.java index d9e073102b..4ada03ee17 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorService.java @@ -21,7 +21,6 @@ import java.text.MessageFormat; import java.util.*; -import org.apache.airavata.common.exception.ApplicationSettingsException; import org.apache.airavata.common.logging.MDCUtil; import org.apache.airavata.common.utils.AiravataUtils; import org.apache.airavata.common.utils.ServerSettings; @@ -46,6 +45,10 @@ import org.apache.airavata.model.experiment.ExperimentModel; import org.apache.airavata.model.experiment.ExperimentType; import org.apache.airavata.model.experiment.UserConfigurationDataModel; +import org.apache.airavata.model.messaging.event.ExperimentIntermediateOutputsEvent; +import org.apache.airavata.model.messaging.event.ExperimentSubmitEvent; +import org.apache.airavata.model.messaging.event.ProcessIdentifier; +import org.apache.airavata.model.messaging.event.ProcessStatusChangeEvent; import org.apache.airavata.model.process.ProcessModel; import org.apache.airavata.model.scheduling.ComputationalResourceSchedulingModel; import org.apache.airavata.model.status.ExperimentState; @@ -54,17 +57,12 @@ import org.apache.airavata.model.status.ProcessStatus; import org.apache.airavata.model.status.QueueStatusModel; import org.apache.airavata.model.task.TaskTypes; -import org.apache.airavata.model.messaging.event.ExperimentIntermediateOutputsEvent; -import org.apache.airavata.model.messaging.event.ExperimentSubmitEvent; -import org.apache.airavata.model.messaging.event.ProcessIdentifier; -import org.apache.airavata.model.messaging.event.ProcessStatusChangeEvent; import org.apache.airavata.model.util.ExperimentModelUtil; import org.apache.airavata.orchestrator.core.exception.OrchestratorException; import org.apache.airavata.orchestrator.core.schedule.HostScheduler; import org.apache.airavata.orchestrator.core.utils.OrchestratorConstants; import org.apache.airavata.orchestrator.cpi.impl.SimpleOrchestratorImpl; import org.apache.airavata.orchestrator.util.OrchestratorUtils; -import org.apache.airavata.registry.cpi.AppCatalogException; import org.apache.airavata.registry.cpi.RegistryException; import org.apache.commons.lang3.StringUtils; import org.apache.curator.framework.CuratorFramework; @@ -76,7 +74,7 @@ public class OrchestratorService { private static final Logger logger = LoggerFactory.getLogger(OrchestratorService.class); - + private OrchestratorRegistryService orchestratorRegistryService; private SimpleOrchestratorImpl orchestrator; private CuratorFramework curatorClient; @@ -96,8 +94,7 @@ public OrchestratorService( public boolean launchExperiment(String experimentId, String gatewayId) throws Exception { String experimentNodePath = getExperimentNodePath(experimentId); ZKPaths.mkdirs(curatorClient.getZookeeperClient().getZooKeeper(), experimentNodePath); - String experimentCancelNode = - ZKPaths.makePath(experimentNodePath, ZkConstants.ZOOKEEPER_CANCEL_LISTENER_NODE); + String experimentCancelNode = ZKPaths.makePath(experimentNodePath, ZkConstants.ZOOKEEPER_CANCEL_LISTENER_NODE); ZKPaths.mkdirs(curatorClient.getZookeeperClient().getZooKeeper(), experimentCancelNode); ExperimentModel experiment = orchestratorRegistryService.getExperiment(experimentId); if (experiment == null) { @@ -131,7 +128,7 @@ private boolean launchSingleAppExperiment( for (ProcessModel processModel : processes) { resolveInputReplicas(processModel); - + if (!experiment.getUserConfigurationData().isAiravataAutoSchedule()) { String taskDag = orchestrator.createAndSaveTasks(gatewayId, processModel); processModel.setTaskDag(taskDag); @@ -145,8 +142,7 @@ private boolean launchSingleAppExperiment( } ProcessScheduler scheduler = new ProcessSchedulerImpl(); - if (!experiment.getUserConfigurationData().isAiravataAutoSchedule() - || scheduler.canLaunch(experimentId)) { + if (!experiment.getUserConfigurationData().isAiravataAutoSchedule() || scheduler.canLaunch(experimentId)) { createAndValidateTasks(experiment, false); return true; // runExperimentLauncher will be called separately } else { @@ -167,11 +163,10 @@ private void resolveInputReplicas(ProcessModel processModel) throws Exception { && pi.getValue().startsWith("airavata-dp://")) { try { DataProductModel dataProductModel = orchestratorRegistryService.getDataProduct(pi.getValue()); - Optional rpLocation = - dataProductModel.getReplicaLocations().stream() - .filter(rpModel -> rpModel.getReplicaLocationCategory() - .equals(ReplicaLocationCategory.GATEWAY_DATA_STORE)) - .findFirst(); + Optional 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()); @@ -212,11 +207,13 @@ private void resolveInputReplicas(ProcessModel processModel) throws Exception { } } - public String getCredentialToken(ExperimentModel experiment, UserConfigurationDataModel userConfigurationData) throws Exception { + public String getCredentialToken(ExperimentModel experiment, UserConfigurationDataModel userConfigurationData) + throws Exception { String token = null; final String groupResourceProfileId = userConfigurationData.getGroupResourceProfileId(); if (groupResourceProfileId == null) { - throw new Exception("Experiment not configured with a Group Resource Profile: " + experiment.getExperimentId()); + throw new Exception( + "Experiment not configured with a Group Resource Profile: " + experiment.getExperimentId()); } if (userConfigurationData.getComputationalResourceScheduling() != null @@ -247,7 +244,8 @@ public String getCredentialToken(ExperimentModel experiment, UserConfigurationDa return token; } - public boolean validateExperiment(String experimentId) throws TException, LaunchValidationException, RegistryException, OrchestratorException { + public boolean validateExperiment(String experimentId) + throws TException, LaunchValidationException, RegistryException, OrchestratorException { ExperimentModel experimentModel = orchestratorRegistryService.getExperiment(experimentId); return orchestrator.validateExperiment(experimentModel).isValidationState(); } @@ -256,9 +254,8 @@ public boolean validateProcess(String experimentId, List processes throws LaunchValidationException, TException, RegistryException, OrchestratorException { ExperimentModel experimentModel = orchestratorRegistryService.getExperiment(experimentId); for (ProcessModel processModel : processes) { - boolean state = orchestrator - .validateProcess(experimentModel, processModel) - .isSetValidationState(); + boolean state = + orchestrator.validateProcess(experimentModel, processModel).isSetValidationState(); if (!state) { return false; } @@ -321,7 +318,8 @@ private boolean validateStatesAndCancel(String experimentId, String gatewayId) t .forPath(expCancelNodePath, ZkConstants.ZOOKEEPER_CANCEL_REQEUST.getBytes()); ExperimentStatus status = new ExperimentStatus(ExperimentState.CANCELING); status.setReason("Experiment cancel request processed"); - status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime()); + status.setTimeOfStateChange( + AiravataUtils.getCurrentTimestamp().getTime()); OrchestratorUtils.updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); logger.info("expId : " + experimentId + " :- Experiment status updated to " + status.getState()); } @@ -334,15 +332,15 @@ public void fetchIntermediateOutputs(String experimentId, String gatewayId, List submitIntermediateOutputsProcess(experimentId, gatewayId, outputNames); } - private void submitIntermediateOutputsProcess( - String experimentId, String gatewayId, List outputNames) throws Exception { + private void submitIntermediateOutputsProcess(String experimentId, String gatewayId, List outputNames) + throws Exception { ExperimentModel experimentModel = orchestratorRegistryService.getExperiment(experimentId); ProcessModel processModel = ExperimentModelUtil.cloneProcessFromExperiment(experimentModel); processModel.setExperimentDataDir(processModel.getExperimentDataDir() + "/intermediates"); - List applicationOutputs = orchestratorRegistryService.getApplicationOutputs( - experimentModel.getExecutionId()); + List applicationOutputs = + orchestratorRegistryService.getApplicationOutputs(experimentModel.getExecutionId()); List requestedOutputs = new ArrayList<>(); for (OutputDataObjectType output : applicationOutputs) { @@ -417,21 +415,18 @@ public boolean launchProcess(String processId, String airavataCredStoreToken, St } } - private ApplicationDeploymentDescription getAppDeployment( - ProcessModel processModel, String applicationId) + private ApplicationDeploymentDescription getAppDeployment(ProcessModel processModel, String applicationId) throws Exception { String selectedModuleId = getModuleId(applicationId); return getAppDeploymentForModule(processModel, selectedModuleId); } private ApplicationDeploymentDescription getAppDeploymentForModule( - ProcessModel processModel, String selectedModuleId) - throws Exception { + ProcessModel processModel, String selectedModuleId) throws Exception { List applicationDeployements = orchestratorRegistryService.getApplicationDeployments(selectedModuleId); - Map deploymentMap = - new HashMap<>(); + Map deploymentMap = new HashMap<>(); for (ApplicationDeploymentDescription deploymentDescription : applicationDeployements) { if (processModel.getComputeResourceId().equals(deploymentDescription.getComputeHostId())) { @@ -449,9 +444,9 @@ private ApplicationDeploymentDescription getAppDeploymentForModule( return deploymentMap.get(ComputeResourceDescription); } - private String getModuleId(String applicationId) - throws Exception { - ApplicationInterfaceDescription applicationInterface = orchestratorRegistryService.getApplicationInterface(applicationId); + private String getModuleId(String applicationId) throws Exception { + ApplicationInterfaceDescription applicationInterface = + orchestratorRegistryService.getApplicationInterface(applicationId); List applicationModules = applicationInterface.getApplicationModules(); if (applicationModules.size() == 0) { throw new OrchestratorException("No modules defined for application " + applicationId); @@ -491,7 +486,8 @@ public String getExperimentNodePath(String experimentId) { return ZKPaths.makePath(ZkConstants.ZOOKEEPER_EXPERIMENT_NODE, experimentId); } - public boolean launchSingleAppExperimentInternal(String experimentId, String airavataCredStoreToken, String gatewayId) throws Exception { + public boolean launchSingleAppExperimentInternal( + String experimentId, String airavataCredStoreToken, String gatewayId) throws Exception { try { List processIds = orchestratorRegistryService.getProcessIds(experimentId); for (String processId : processIds) { @@ -522,23 +518,22 @@ public void launchQueuedExperiment(String experimentId) throws Exception { UserConfigurationDataModel userConfigurationData = experiment.getUserConfigurationData(); String token = getCredentialToken(experiment, userConfigurationData); createAndValidateTasks(experiment, true); - + // Publish experiment launched status and run launcher ExperimentStatus status = new ExperimentStatus(ExperimentState.LAUNCHED); status.setReason("submitted all processes"); status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime()); OrchestratorUtils.updateAndPublishExperimentStatus(experimentId, status, publisher, experiment.getGatewayId()); logger.info("expId: {}, Launched experiment ", experimentId); - + // Launch processes launchSingleAppExperimentInternal(experimentId, token, experiment.getGatewayId()); } public void handleProcessStatusChange( - ProcessStatusChangeEvent processStatusChangeEvent, - ProcessIdentifier processIdentity) throws Exception { + ProcessStatusChangeEvent processStatusChangeEvent, ProcessIdentifier processIdentity) throws Exception { ExperimentStatus status = new ExperimentStatus(); - + // Check if this is an intermediate output fetching process ProcessModel process = orchestratorRegistryService.getProcess(processIdentity.getProcessId()); boolean isIntermediateOutputFetchingProcess = @@ -547,10 +542,11 @@ public void handleProcessStatusChange( logger.info("Not updating experiment status because process is an intermediate output fetching one"); return; } - + switch (processStatusChangeEvent.getState()) { case STARTED: - ExperimentStatus stat = orchestratorRegistryService.getExperimentStatus(processIdentity.getExperimentId()); + ExperimentStatus stat = + orchestratorRegistryService.getExperimentStatus(processIdentity.getExperimentId()); if (stat.getState() == ExperimentState.CANCELING) { status.setState(ExperimentState.CANCELING); status.setReason("Process started but experiment cancelling is triggered"); @@ -605,7 +601,7 @@ public void handleProcessStatusChange( // ignore other status changes return; } - + if (status.getState() != null) { status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime()); OrchestratorUtils.updateAndPublishExperimentStatus( @@ -660,10 +656,11 @@ public void handleLaunchExperimentFromMessage(MessageContext messageContext) thr ExperimentSubmitEvent expEvent = new ExperimentSubmitEvent(); byte[] bytes = ThriftUtils.serializeThriftObject(messageContext.getEvent()); ThriftUtils.createThriftFromBytes(bytes, expEvent); - + if (messageContext.isRedeliver()) { ExperimentModel experimentModel = orchestratorRegistryService.getExperiment(expEvent.getExperimentId()); - if (experimentModel != null && experimentModel.getExperimentStatus().get(0).getState() == ExperimentState.CREATED) { + if (experimentModel != null + && experimentModel.getExperimentStatus().get(0).getState() == ExperimentState.CREATED) { handleLaunchExperiment(expEvent); } } else { @@ -679,7 +676,9 @@ public void handleIntermediateOutputsEvent(ExperimentIntermediateOutputsEvent ev fetchIntermediateOutputs(event.getExperimentId(), event.getGatewayId(), event.getOutputNames()); } - public boolean launchExperimentWithErrorHandling(String experimentId, String gatewayId, java.util.concurrent.ExecutorService executorService) throws TException { + public boolean launchExperimentWithErrorHandling( + String experimentId, String gatewayId, java.util.concurrent.ExecutorService executorService) + throws TException { try { boolean result = launchExperiment(experimentId, gatewayId); if (result) { @@ -690,7 +689,7 @@ public boolean launchExperimentWithErrorHandling(String experimentId, String gat status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime()); OrchestratorUtils.updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); logger.info("expId: {}, Launched experiment ", experimentId); - + // Execute the single app experiment runner in the provided thread pool if (executorService != null) { Runnable runner = () -> { @@ -734,4 +733,3 @@ public boolean launchExperimentWithErrorHandling(String experimentId, String gat } } } - diff --git a/airavata-api/src/main/java/org/apache/airavata/service/RegistryService.java b/airavata-api/src/main/java/org/apache/airavata/service/RegistryService.java index 2c9284fa7a..8e280292a6 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/RegistryService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/RegistryService.java @@ -20,6 +20,7 @@ package org.apache.airavata.service; import java.util.*; +import org.apache.airavata.common.utils.ServerSettings; import org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription; import org.apache.airavata.model.appcatalog.appdeployment.ApplicationModule; import org.apache.airavata.model.appcatalog.appinterface.ApplicationInterfaceDescription; @@ -50,7 +51,6 @@ import org.apache.airavata.model.error.*; import org.apache.airavata.model.experiment.*; import org.apache.airavata.model.job.JobModel; -import org.apache.airavata.registry.cpi.ExpCatChildDataType; import org.apache.airavata.model.process.ProcessModel; import org.apache.airavata.model.process.ProcessWorkflow; import org.apache.airavata.model.scheduling.ComputationalResourceSchedulingModel; @@ -61,22 +61,19 @@ import org.apache.airavata.model.workspace.GatewayUsageReportingCommand; import org.apache.airavata.model.workspace.Notification; import org.apache.airavata.model.workspace.Project; +import org.apache.airavata.registry.core.entities.expcatalog.JobPK; import org.apache.airavata.registry.core.repositories.appcatalog.*; +import org.apache.airavata.registry.core.repositories.appcatalog.GroupResourceProfileRepository; +import org.apache.airavata.registry.core.repositories.appcatalog.GwyResourceProfileRepository; import org.apache.airavata.registry.core.repositories.expcatalog.*; import org.apache.airavata.registry.core.repositories.replicacatalog.DataProductRepository; import org.apache.airavata.registry.core.repositories.replicacatalog.DataReplicaLocationRepository; import org.apache.airavata.registry.core.repositories.workflowcatalog.WorkflowRepository; import org.apache.airavata.registry.core.utils.DBConstants; import org.apache.airavata.registry.cpi.*; -import org.apache.airavata.registry.cpi.utils.Constants; -import org.apache.airavata.registry.api.exception.RegistryServiceException; -import org.apache.airavata.model.error.AiravataSystemException; -import org.apache.airavata.model.error.AiravataErrorType; -import org.apache.airavata.registry.core.entities.expcatalog.JobPK; -import org.apache.airavata.registry.core.repositories.appcatalog.GwyResourceProfileRepository; -import org.apache.airavata.registry.core.repositories.appcatalog.GroupResourceProfileRepository; -import org.apache.airavata.common.utils.ServerSettings; +import org.apache.airavata.registry.cpi.ExpCatChildDataType; import org.apache.airavata.registry.cpi.WorkflowCatalogException; +import org.apache.airavata.registry.cpi.utils.Constants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -195,7 +192,8 @@ public boolean deleteProject(String projectId) throws RegistryException { return true; } - public List getUserProjects(String gatewayId, String userName, int limit, int offset) throws RegistryException { + public List getUserProjects(String gatewayId, String userName, int limit, int offset) + throws RegistryException { if (!validateString(userName)) { logger.error("Username cannot be empty. Please provide a valid user.."); throw new RegistryException("Username cannot be empty. Please provide a valid user.."); @@ -213,11 +211,7 @@ public List getUserProjects(String gatewayId, String userName, int limi filters.put(Constants.FieldConstants.ProjectConstants.OWNER, userName); filters.put(Constants.FieldConstants.ProjectConstants.GATEWAY_ID, gatewayId); projects = projectRepository.searchProjects( - filters, - limit, - offset, - Constants.FieldConstants.ProjectConstants.CREATION_TIME, - ResultOrderType.DESC); + filters, limit, offset, Constants.FieldConstants.ProjectConstants.CREATION_TIME, ResultOrderType.DESC); logger.debug("Airavata retrieved projects for user : " + userName + " and gateway id : " + gatewayId); return projects; } @@ -231,7 +225,8 @@ public ExperimentStatistics getExperimentStatistics( String resourceHostName, List accessibleExpIds, int limit, - int offset) throws RegistryException { + int offset) + throws RegistryException { if (!isGatewayExistInternal(gatewayId)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new RegistryException("Gateway does not exist.Please provide a valid gateway id..."); @@ -250,14 +245,16 @@ public ExperimentStatistics getExperimentStatistics( filters.put(Constants.FieldConstants.ExperimentConstants.RESOURCE_HOST_ID, resourceHostName); } limit = Math.min(limit, 1000); - ExperimentStatistics result = experimentSummaryRepository.getAccessibleExperimentStatistics( - accessibleExpIds, filters, limit, offset); + ExperimentStatistics result = + experimentSummaryRepository.getAccessibleExperimentStatistics(accessibleExpIds, filters, limit, offset); logger.debug("Airavata retrieved experiments for gateway id : " + gatewayId + " between : " - + org.apache.airavata.common.utils.AiravataUtils.getTime(fromTime) + " and " + org.apache.airavata.common.utils.AiravataUtils.getTime(toTime)); + + org.apache.airavata.common.utils.AiravataUtils.getTime(fromTime) + " and " + + org.apache.airavata.common.utils.AiravataUtils.getTime(toTime)); return result; } - public List getExperimentsInProject(String gatewayId, String projectId, int limit, int offset) throws RegistryException { + public List getExperimentsInProject(String gatewayId, String projectId, int limit, int offset) + throws RegistryException { if (!isGatewayExistInternal(gatewayId)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new RegistryException("Gateway does not exist.Please provide a valid gateway id..."); @@ -282,7 +279,8 @@ public List getExperimentsInProject(String gatewayId, String pr return experiments; } - public List getUserExperiments(String gatewayId, String userName, int limit, int offset) throws RegistryException { + public List getUserExperiments(String gatewayId, String userName, int limit, int offset) + throws RegistryException { if (!validateString(userName)) { logger.error("Username cannot be empty. Please provide a valid user.."); throw new RegistryException("Username cannot be empty. Please provide a valid user.."); @@ -310,14 +308,12 @@ public List getUserExperiments(String gatewayId, String userNam public boolean deleteExperiment(String experimentId) throws RegistryException { if (!experimentRepository.isExperimentExist(experimentId)) { - throw new RegistryException( - "Requested experiment id " + experimentId + " does not exist in the system.."); + throw new RegistryException("Requested experiment id " + experimentId + " does not exist in the system.."); } ExperimentModel experimentModel = experimentRepository.getExperiment(experimentId); if (!(experimentModel.getExperimentStatus().get(0).getState() == ExperimentState.CREATED)) { logger.error("Error while deleting the experiment"); - throw new RegistryException( - "Experiment is not in CREATED state. Hence cannot deleted. ID:" + experimentId); + throw new RegistryException("Experiment is not in CREATED state. Hence cannot deleted. ID:" + experimentId); } experimentRepository.removeExperiment(experimentId); logger.debug("Airavata removed experiment with experiment id : " + experimentId); @@ -397,9 +393,9 @@ public List getExperimentOutputs(String airavataExperiment return experimentOutputRepository.getExperimentOutputs(airavataExperimentId); } - public void updateJobStatus(JobStatus jobStatus, String taskId, String jobId) throws RegistryException { - org.apache.airavata.registry.core.entities.expcatalog.JobPK jobPK = new org.apache.airavata.registry.core.entities.expcatalog.JobPK(); + org.apache.airavata.registry.core.entities.expcatalog.JobPK jobPK = + new org.apache.airavata.registry.core.entities.expcatalog.JobPK(); jobPK.setTaskId(taskId); jobPK.setJobId(jobId); jobStatusRepository.updateJobStatus(jobStatus, jobPK); @@ -525,13 +521,15 @@ public List getJobs(String queryType, String id) throws RegistryExcept } public int getJobCount( - org.apache.airavata.model.status.JobStatus jobStatus, String gatewayId, double searchBackTimeInMinutes) throws RegistryException { + org.apache.airavata.model.status.JobStatus jobStatus, String gatewayId, double searchBackTimeInMinutes) + throws RegistryException { List jobStatusList = jobStatusRepository.getDistinctListofJobStatus( gatewayId, jobStatus.getJobState().name(), searchBackTimeInMinutes); return jobStatusList.size(); } - public Map getAVGTimeDistribution(String gatewayId, double searchBackTimeInMinutes) throws RegistryException { + public Map getAVGTimeDistribution(String gatewayId, double searchBackTimeInMinutes) + throws RegistryException { return processRepository.getAVGTimeDistribution(gatewayId, searchBackTimeInMinutes); } @@ -613,7 +611,8 @@ public List getAllAppModules(String gatewayId) throws AppCata } public List getAccessibleAppModules( - String gatewayId, List accessibleAppIds, List accessibleComputeResourceIds) throws AppCatalogException { + String gatewayId, List accessibleAppIds, List accessibleComputeResourceIds) + throws AppCatalogException { try { if (!isGatewayExistInternal(gatewayId)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); @@ -633,7 +632,8 @@ public boolean deleteApplicationModule(String appModuleId) throws AppCatalogExce return applicationInterfaceRepository.removeApplicationModule(appModuleId); } - public ApplicationDeploymentDescription getApplicationDeployment(String appDeploymentId) throws AppCatalogException { + public ApplicationDeploymentDescription getApplicationDeployment(String appDeploymentId) + throws AppCatalogException { ApplicationDeploymentDescription deployement = applicationDeploymentRepository.getApplicationDeployement(appDeploymentId); logger.debug("Airavata registered application deployment for deployment id : " + appDeploymentId); @@ -646,7 +646,8 @@ public boolean deleteApplicationDeployment(String appDeploymentId) throws AppCat return true; } - public List getAllApplicationDeployments(String gatewayId) throws AppCatalogException { + public List getAllApplicationDeployments(String gatewayId) + throws AppCatalogException { try { if (!isGatewayExistInternal(gatewayId)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); @@ -662,7 +663,8 @@ public List getAllApplicationDeployments(Strin } public List getAccessibleApplicationDeployments( - String gatewayId, List accessibleAppDeploymentIds, List accessibleComputeResourceIds) throws AppCatalogException { + String gatewayId, List accessibleAppDeploymentIds, List accessibleComputeResourceIds) + throws AppCatalogException { try { if (!isGatewayExistInternal(gatewayId)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); @@ -682,7 +684,8 @@ public List getAccessibleApplicationDeployment String gatewayId, String appModuleId, List accessibleAppDeploymentIds, - List accessibleComputeResourceIds) throws AppCatalogException { + List accessibleComputeResourceIds) + throws AppCatalogException { try { if (!isGatewayExistInternal(gatewayId)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); @@ -710,7 +713,8 @@ public List getAppModuleDeployedResources(String appModuleId) throws App return appDeployments; } - public List getApplicationDeployments(String appModuleId) throws AppCatalogException { + public List getApplicationDeployments(String appModuleId) + throws AppCatalogException { Map filters = new HashMap<>(); filters.put(DBConstants.ApplicationDeployment.APPLICATION_MODULE_ID, appModuleId); List applicationDeployments = @@ -726,8 +730,7 @@ public ApplicationInterfaceDescription getApplicationInterface(String appInterfa } public boolean deleteApplicationInterface(String appInterfaceId) throws AppCatalogException { - boolean removeApplicationInterface = - applicationInterfaceRepository.removeApplicationInterface(appInterfaceId); + boolean removeApplicationInterface = applicationInterfaceRepository.removeApplicationInterface(appInterfaceId); logger.debug("Airavata removed application interface with interface id : " + appInterfaceId); return removeApplicationInterface; } @@ -747,15 +750,15 @@ public Map getAllApplicationInterfaceNames(String gatewayId) thr if (allApplicationInterfaces != null && !allApplicationInterfaces.isEmpty()) { for (ApplicationInterfaceDescription interfaceDescription : allApplicationInterfaces) { allApplicationInterfacesMap.put( - interfaceDescription.getApplicationInterfaceId(), - interfaceDescription.getApplicationName()); + interfaceDescription.getApplicationInterfaceId(), interfaceDescription.getApplicationName()); } } logger.debug("Airavata retrieved application interfaces for gateway id : " + gatewayId); return allApplicationInterfacesMap; } - public List getAllApplicationInterfaces(String gatewayId) throws AppCatalogException { + public List getAllApplicationInterfaces(String gatewayId) + throws AppCatalogException { try { if (!isGatewayExistInternal(gatewayId)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); @@ -790,9 +793,9 @@ public List getApplicationOutputs(String appInterfaceId) t return list; } - public Map getAvailableAppInterfaceComputeResources(String appInterfaceId) throws AppCatalogException { - Map allComputeResources = - new ComputeResourceRepository().getAvailableComputeResourceIdList(); + public Map getAvailableAppInterfaceComputeResources(String appInterfaceId) + throws AppCatalogException { + Map allComputeResources = new ComputeResourceRepository().getAvailableComputeResourceIdList(); Map availableComputeResources = new HashMap(); ApplicationInterfaceDescription applicationInterface = applicationInterfaceRepository.getApplicationInterface(appInterfaceId); @@ -812,8 +815,7 @@ public Map getAvailableAppInterfaceComputeResources(String appIn } } } - logger.debug( - "Airavata retrieved available compute resources for application interface id : " + appInterfaceId); + logger.debug("Airavata retrieved available compute resources for application interface id : " + appInterfaceId); return availableComputeResources; } @@ -837,8 +839,7 @@ public boolean deleteComputeResource(String computeResourceId) throws AppCatalog } public StorageResourceDescription getStorageResource(String storageResourceId) throws AppCatalogException { - StorageResourceDescription storageResource = - storageResourceRepository.getStorageResource(storageResourceId); + StorageResourceDescription storageResource = storageResourceRepository.getStorageResource(storageResourceId); logger.debug("Airavata retrieved storage resource with storage resource Id : " + storageResourceId); return storageResource; } @@ -870,27 +871,28 @@ public SSHJobSubmission getSSHJobSubmission(String jobSubmissionId) throws AppCa public UnicoreJobSubmission getUnicoreJobSubmission(String jobSubmissionId) throws AppCatalogException { UnicoreJobSubmission unicoreJobSubmission = new ComputeResourceRepository().getUNICOREJobSubmission(jobSubmissionId); - logger.debug( - "Airavata retrieved UNICORE job submission for job submission interface id: " + jobSubmissionId); + logger.debug("Airavata retrieved UNICORE job submission for job submission interface id: " + jobSubmissionId); return unicoreJobSubmission; } public CloudJobSubmission getCloudJobSubmission(String jobSubmissionId) throws AppCatalogException { - CloudJobSubmission cloudJobSubmission = - new ComputeResourceRepository().getCloudJobSubmission(jobSubmissionId); + CloudJobSubmission cloudJobSubmission = new ComputeResourceRepository().getCloudJobSubmission(jobSubmissionId); logger.debug("Airavata retrieved cloud job submission for job submission interface id: " + jobSubmissionId); return cloudJobSubmission; } - public boolean changeJobSubmissionPriority(String jobSubmissionInterfaceId, int newPriorityOrder) throws RegistryException { + public boolean changeJobSubmissionPriority(String jobSubmissionInterfaceId, int newPriorityOrder) + throws RegistryException { return false; } - public boolean changeDataMovementPriority(String dataMovementInterfaceId, int newPriorityOrder) throws RegistryException { + public boolean changeDataMovementPriority(String dataMovementInterfaceId, int newPriorityOrder) + throws RegistryException { return false; } - public boolean changeJobSubmissionPriorities(Map jobSubmissionPriorityMap) throws RegistryException { + public boolean changeJobSubmissionPriorities(Map jobSubmissionPriorityMap) + throws RegistryException { return false; } @@ -898,7 +900,8 @@ public boolean changeDataMovementPriorities(Map dataMovementPri return false; } - public boolean deleteJobSubmissionInterface(String computeResourceId, String jobSubmissionInterfaceId) throws AppCatalogException { + public boolean deleteJobSubmissionInterface(String computeResourceId, String jobSubmissionInterfaceId) + throws AppCatalogException { new ComputeResourceRepository().removeJobSubmissionInterface(computeResourceId, jobSubmissionInterfaceId); logger.debug("Airavata deleted job submission interface with interface id : " + jobSubmissionInterfaceId); return true; @@ -948,7 +951,8 @@ public boolean deleteGatewayResourceProfile(String gatewayID) throws AppCatalogE return true; } - public ComputeResourcePreference getGatewayComputeResourcePreference(String gatewayID, String computeResourceId) throws AppCatalogException { + public ComputeResourcePreference getGatewayComputeResourcePreference(String gatewayID, String computeResourceId) + throws AppCatalogException { try { if (!isGatewayExistInternal(gatewayID)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); @@ -980,7 +984,8 @@ public ComputeResourcePreference getGatewayComputeResourcePreference(String gate return computeResourcePreference; } - public StoragePreference getGatewayStoragePreference(String gatewayID, String storageId) throws AppCatalogException { + public StoragePreference getGatewayStoragePreference(String gatewayID, String storageId) + throws AppCatalogException { try { if (!isGatewayExistInternal(gatewayID)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); @@ -997,14 +1002,14 @@ public StoragePreference getGatewayStoragePreference(String gatewayID, String st throw new AppCatalogException( "Given gateway profile does not exist in the system. Please provide a valid gateway id..."); } - StoragePreference storagePreference = - gwyResourceProfileRepository.getStoragePreference(gatewayID, storageId); + StoragePreference storagePreference = gwyResourceProfileRepository.getStoragePreference(gatewayID, storageId); logger.debug("Airavata retrieved storage resource preference with gateway id : " + gatewayID + " and for storage resource id : " + storageId); return storagePreference; } - public List getAllGatewayComputeResourcePreferences(String gatewayID) throws AppCatalogException { + public List getAllGatewayComputeResourcePreferences(String gatewayID) + throws AppCatalogException { try { if (!isGatewayExistInternal(gatewayID)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); @@ -1035,7 +1040,8 @@ public List getAllGatewayResourceProfiles() throws AppCa return gwyResourceProfileRepository.getAllGatewayProfiles(); } - public boolean deleteGatewayComputeResourcePreference(String gatewayID, String computeResourceId) throws AppCatalogException { + public boolean deleteGatewayComputeResourcePreference(String gatewayID, String computeResourceId) + throws AppCatalogException { try { if (!isGatewayExistInternal(gatewayID)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); @@ -1045,8 +1051,7 @@ public boolean deleteGatewayComputeResourcePreference(String gatewayID, String c throw new AppCatalogException(e.getMessage(), e); } GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); - return gwyResourceProfileRepository.removeComputeResourcePreferenceFromGateway( - gatewayID, computeResourceId); + return gwyResourceProfileRepository.removeComputeResourcePreferenceFromGateway(gatewayID, computeResourceId); } public boolean deleteGatewayStoragePreference(String gatewayID, String storageId) throws AppCatalogException { @@ -1094,8 +1099,7 @@ public String createGroupResourceProfile(GroupResourceProfile groupResourceProfi throw new AppCatalogException(e.getMessage(), e); } GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); - String groupResourceProfileId = - groupResourceProfileRepository.addGroupResourceProfile(groupResourceProfile); + String groupResourceProfileId = groupResourceProfileRepository.addGroupResourceProfile(groupResourceProfile); logger.debug("New Group Resource Profile Created: " + groupResourceProfileId); return groupResourceProfileId; } @@ -1109,8 +1113,7 @@ public void updateGroupResourceProfile(GroupResourceProfile groupResourceProfile throw new AppCatalogException( "Cannot update. No group resource profile found with matching gatewayId and groupResourceProfileId"); } - String groupResourceProfileId = - groupResourceProfileRepository.updateGroupResourceProfile(groupResourceProfile); + String groupResourceProfileId = groupResourceProfileRepository.updateGroupResourceProfile(groupResourceProfile); logger.debug(" Group Resource Profile updated: " + groupResourceProfileId); } @@ -1140,15 +1143,16 @@ public boolean removeGroupResourceProfile(String groupResourceProfileId) throws return groupResourceProfileRepository.removeGroupResourceProfile(groupResourceProfileId); } - public List getGroupResourceList(String gatewayId, List accessibleGroupResProfileIds) throws AppCatalogException { + public List getGroupResourceList(String gatewayId, List accessibleGroupResProfileIds) + throws AppCatalogException { GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); return groupResourceProfileRepository.getAllGroupResourceProfiles(gatewayId, accessibleGroupResProfileIds); } - public boolean removeGroupComputePrefs(String computeResourceId, String groupResourceProfileId) throws AppCatalogException { + public boolean removeGroupComputePrefs(String computeResourceId, String groupResourceProfileId) + throws AppCatalogException { GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); - groupResourceProfileRepository.removeGroupComputeResourcePreference( - computeResourceId, groupResourceProfileId); + groupResourceProfileRepository.removeGroupComputeResourcePreference(computeResourceId, groupResourceProfileId); logger.debug("Removed compute resource preferences with compute resource ID: " + computeResourceId); return true; } @@ -1180,7 +1184,8 @@ public GroupComputeResourcePreference getGroupComputeResourcePreference( return groupComputeResourcePreference; } - public boolean isGroupComputeResourcePreferenceExists(String computeResourceId, String groupResourceProfileId) throws AppCatalogException { + public boolean isGroupComputeResourcePreferenceExists(String computeResourceId, String groupResourceProfileId) + throws AppCatalogException { GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); return groupResourceProfileRepository.isGroupComputeResourcePreferenceExists( computeResourceId, groupResourceProfileId); @@ -1208,17 +1213,20 @@ public BatchQueueResourcePolicy getBatchQueueResourcePolicy(String resourcePolic return batchQueueResourcePolicy; } - public List getGroupComputeResourcePrefList(String groupResourceProfileId) throws AppCatalogException { + public List getGroupComputeResourcePrefList(String groupResourceProfileId) + throws AppCatalogException { GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); return groupResourceProfileRepository.getAllGroupComputeResourcePreferences(groupResourceProfileId); } - public List getGroupBatchQueueResourcePolicyList(String groupResourceProfileId) throws AppCatalogException { + public List getGroupBatchQueueResourcePolicyList(String groupResourceProfileId) + throws AppCatalogException { GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); return groupResourceProfileRepository.getAllGroupBatchQueueResourcePolicies(groupResourceProfileId); } - public List getGroupComputeResourcePolicyList(String groupResourceProfileId) throws AppCatalogException { + public List getGroupComputeResourcePolicyList(String groupResourceProfileId) + throws AppCatalogException { GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); return groupResourceProfileRepository.getAllGroupComputeResourcePolicies(groupResourceProfileId); } @@ -1325,8 +1333,7 @@ public String createExperiment(String gatewayId, ExperimentModel experiment) thr throw new RegistryException("Error registering workflow: " + e.getMessage(), e); } } - logger.debug( - experimentId, "Created new experiment with experiment name {}", experiment.getExperimentName()); + logger.debug(experimentId, "Created new experiment with experiment name {}", experiment.getExperimentName()); return experimentId; } @@ -1336,7 +1343,8 @@ public List searchExperiments( List accessibleExpIds, Map filters, int limit, - int offset) throws RegistryException { + int offset) + throws RegistryException { if (!validateString(userName)) { logger.error("Username cannot be empty. Please provide a valid user.."); throw new RegistryException("Username cannot be empty. Please provide a valid user.."); @@ -1397,9 +1405,7 @@ public List searchExperiments( public void updateExperiment(String airavataExperimentId, ExperimentModel experiment) throws RegistryException { if (!experimentRepository.isExperimentExist(airavataExperimentId)) { logger.error( - airavataExperimentId, - "Update request failed, Experiment {} doesn't exist.", - airavataExperimentId); + airavataExperimentId, "Update request failed, Experiment {} doesn't exist.", airavataExperimentId); throw new RegistryException( "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); } @@ -1453,7 +1459,8 @@ public void updateExperiment(String airavataExperimentId, ExperimentModel experi } } - public void updateExperimentConfiguration(String airavataExperimentId, UserConfigurationDataModel userConfiguration) throws RegistryException { + public void updateExperimentConfiguration(String airavataExperimentId, UserConfigurationDataModel userConfiguration) + throws RegistryException { if (!experimentRepository.isExperimentExist(airavataExperimentId)) { logger.error( airavataExperimentId, @@ -1505,13 +1512,15 @@ public List getIntermediateOutputs(String airavataExperime List intermediateOutputs = new ArrayList<>(); if (processModels != null && !processModels.isEmpty()) { for (ProcessModel processModel : processModels) { - List processOutputs = processOutputRepository.getProcessOutputs(processModel.getProcessId()); + List processOutputs = + processOutputRepository.getProcessOutputs(processModel.getProcessId()); if (processOutputs != null && !processOutputs.isEmpty()) { intermediateOutputs.addAll(processOutputs); } } } - logger.debug("Airavata retrieved intermediate outputs for experiment with experiment id : " + airavataExperimentId); + logger.debug( + "Airavata retrieved intermediate outputs for experiment with experiment id : " + airavataExperimentId); return intermediateOutputs; } @@ -1554,7 +1563,8 @@ public Map getJobStatuses(String airavataExperimentId) throws return jobStatus; } - public void addExperimentProcessOutputs(String outputType, List outputs, String id) throws RegistryException { + public void addExperimentProcessOutputs(String outputType, List outputs, String id) + throws RegistryException { if (ExpCatChildDataType.PROCESS_OUTPUT.equals(ExpCatChildDataType.valueOf(outputType))) { processOutputRepository.addProcessOutputs(outputs, id); } else if (ExpCatChildDataType.EXPERIMENT_OUTPUT.equals(ExpCatChildDataType.valueOf(outputType))) { @@ -1584,7 +1594,8 @@ public void updateProcessStatus(ProcessStatus processStatus, String processId) t processStatusRepository.updateProcessStatus(processStatus, processId); } - public void updateExperimentStatus(ExperimentStatus experimentStatus, String experimentId) throws RegistryException { + public void updateExperimentStatus(ExperimentStatus experimentStatus, String experimentId) + throws RegistryException { experimentStatusRepository.updateExperimentStatus(experimentStatus, experimentId); } @@ -1639,7 +1650,8 @@ public List searchProjects( List accessibleProjIds, Map filters, int limit, - int offset) throws RegistryException { + int offset) + throws RegistryException { if (!validateString(userName)) { logger.error("Username cannot be empty. Please provide a valid user.."); throw new RegistryException("Username cannot be empty. Please provide a valid user.."); @@ -1685,7 +1697,8 @@ public List searchProjects( } // Gateway Resource Profile operations - public String registerGatewayResourceProfile(GatewayResourceProfile gatewayResourceProfile) throws AppCatalogException { + public String registerGatewayResourceProfile(GatewayResourceProfile gatewayResourceProfile) + throws AppCatalogException { if (!validateString(gatewayResourceProfile.getGatewayID())) { logger.error("Cannot create gateway profile with empty gateway id"); throw new AppCatalogException("Cannot create gateway profile with empty gateway id"); @@ -1700,12 +1713,12 @@ public String registerGatewayResourceProfile(GatewayResourceProfile gatewayResou } GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); String resourceProfile = gwyResourceProfileRepository.addGatewayResourceProfile(gatewayResourceProfile); - logger.debug( - "Airavata registered gateway profile with gateway id : " + gatewayResourceProfile.getGatewayID()); + logger.debug("Airavata registered gateway profile with gateway id : " + gatewayResourceProfile.getGatewayID()); return resourceProfile; } - public boolean updateGatewayResourceProfile(String gatewayID, GatewayResourceProfile gatewayResourceProfile) throws AppCatalogException { + public boolean updateGatewayResourceProfile(String gatewayID, GatewayResourceProfile gatewayResourceProfile) + throws AppCatalogException { try { if (!isGatewayExistInternal(gatewayID)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); @@ -1721,7 +1734,8 @@ public boolean updateGatewayResourceProfile(String gatewayID, GatewayResourcePro } public boolean addGatewayComputeResourcePreference( - String gatewayID, String computeResourceId, ComputeResourcePreference computeResourcePreference) throws AppCatalogException { + String gatewayID, String computeResourceId, ComputeResourcePreference computeResourcePreference) + throws AppCatalogException { try { if (!isGatewayExistInternal(gatewayID)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); @@ -1743,7 +1757,8 @@ public boolean addGatewayComputeResourcePreference( } public boolean updateGatewayComputeResourcePreference( - String gatewayID, String computeResourceId, ComputeResourcePreference computeResourcePreference) throws AppCatalogException { + String gatewayID, String computeResourceId, ComputeResourcePreference computeResourcePreference) + throws AppCatalogException { try { if (!isGatewayExistInternal(gatewayID)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); @@ -1773,7 +1788,8 @@ public boolean updateGatewayComputeResourcePreference( } public boolean addGatewayStoragePreference( - String gatewayID, String storageResourceId, StoragePreference dataStoragePreference) throws AppCatalogException { + String gatewayID, String storageResourceId, StoragePreference dataStoragePreference) + throws AppCatalogException { try { if (!isGatewayExistInternal(gatewayID)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); @@ -1826,14 +1842,16 @@ public boolean updateGatewayStoragePreference( } // Compute Resource operations - public String registerComputeResource(ComputeResourceDescription computeResourceDescription) throws AppCatalogException { + public String registerComputeResource(ComputeResourceDescription computeResourceDescription) + throws AppCatalogException { String computeResource = new ComputeResourceRepository().addComputeResource(computeResourceDescription); logger.debug("Airavata registered compute resource with compute resource Id : " + computeResource); return computeResource; } public boolean updateComputeResource( - String computeResourceId, ComputeResourceDescription computeResourceDescription) throws AppCatalogException { + String computeResourceId, ComputeResourceDescription computeResourceDescription) + throws AppCatalogException { new ComputeResourceRepository().updateComputeResource(computeResourceId, computeResourceDescription); logger.debug("Airavata updated compute resource with compute resource Id : " + computeResourceId); return true; @@ -1843,22 +1861,22 @@ public String registerResourceJobManager(ResourceJobManager resourceJobManager) return new ComputeResourceRepository().addResourceJobManager(resourceJobManager); } - public boolean updateResourceJobManager(String resourceJobManagerId, ResourceJobManager updatedResourceJobManager) throws AppCatalogException { + public boolean updateResourceJobManager(String resourceJobManagerId, ResourceJobManager updatedResourceJobManager) + throws AppCatalogException { new ComputeResourceRepository().updateResourceJobManager(resourceJobManagerId, updatedResourceJobManager); return true; } - public boolean deleteDataMovementInterface(String resourceId, String dataMovementInterfaceId, DMType dmType) throws AppCatalogException { + public boolean deleteDataMovementInterface(String resourceId, String dataMovementInterfaceId, DMType dmType) + throws AppCatalogException { switch (dmType) { case COMPUTE_RESOURCE: new ComputeResourceRepository().removeDataMovementInterface(resourceId, dataMovementInterfaceId); - logger.debug( - "Airavata deleted data movement interface with interface id : " + dataMovementInterfaceId); + logger.debug("Airavata deleted data movement interface with interface id : " + dataMovementInterfaceId); return true; case STORAGE_RESOURCE: storageResourceRepository.removeDataMovementInterface(resourceId, dataMovementInterfaceId); - logger.debug( - "Airavata deleted data movement interface with interface id : " + dataMovementInterfaceId); + logger.debug("Airavata deleted data movement interface with interface id : " + dataMovementInterfaceId); return true; default: logger.error( @@ -1873,7 +1891,8 @@ public boolean updateGridFTPDataMovementDetails( } public String addGridFTPDataMovementDetails( - String computeResourceId, DMType dmType, int priorityOrder, GridFTPDataMovement gridFTPDataMovement) throws AppCatalogException { + String computeResourceId, DMType dmType, int priorityOrder, GridFTPDataMovement gridFTPDataMovement) + throws AppCatalogException { ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); String addDataMovementInterface = addDataMovementInterface( computeResourceRepository, @@ -1892,7 +1911,8 @@ public boolean updateUnicoreDataMovementDetails( } public String addUnicoreDataMovementDetails( - String resourceId, DMType dmType, int priorityOrder, UnicoreDataMovement unicoreDataMovement) throws AppCatalogException { + String resourceId, DMType dmType, int priorityOrder, UnicoreDataMovement unicoreDataMovement) + throws AppCatalogException { ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); String movementInterface = addDataMovementInterface( computeResourceRepository, @@ -1905,14 +1925,16 @@ public String addUnicoreDataMovementDetails( return movementInterface; } - public boolean updateSCPDataMovementDetails(String dataMovementInterfaceId, SCPDataMovement scpDataMovement) throws AppCatalogException { + public boolean updateSCPDataMovementDetails(String dataMovementInterfaceId, SCPDataMovement scpDataMovement) + throws AppCatalogException { new ComputeResourceRepository().updateScpDataMovement(scpDataMovement); logger.debug("Airavata updated SCP data movement with data movement id: " + dataMovementInterfaceId); return true; } public String addSCPDataMovementDetails( - String resourceId, DMType dmType, int priorityOrder, SCPDataMovement scpDataMovement) throws AppCatalogException { + String resourceId, DMType dmType, int priorityOrder, SCPDataMovement scpDataMovement) + throws AppCatalogException { ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); String movementInterface = addDataMovementInterface( computeResourceRepository, @@ -1925,14 +1947,16 @@ public String addSCPDataMovementDetails( return movementInterface; } - public boolean updateLocalDataMovementDetails(String dataMovementInterfaceId, LOCALDataMovement localDataMovement) throws AppCatalogException { + public boolean updateLocalDataMovementDetails(String dataMovementInterfaceId, LOCALDataMovement localDataMovement) + throws AppCatalogException { new ComputeResourceRepository().updateLocalDataMovement(localDataMovement); logger.debug("Airavata updated local data movement with data movement id: " + dataMovementInterfaceId); return true; } public String addLocalDataMovementDetails( - String resourceId, DMType dataMoveType, int priorityOrder, LOCALDataMovement localDataMovement) throws AppCatalogException { + String resourceId, DMType dataMoveType, int priorityOrder, LOCALDataMovement localDataMovement) + throws AppCatalogException { ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); String movementInterface = addDataMovementInterface( computeResourceRepository, @@ -1946,14 +1970,16 @@ public String addLocalDataMovementDetails( } // Storage Resource operations - public String registerStorageResource(StorageResourceDescription storageResourceDescription) throws AppCatalogException { + public String registerStorageResource(StorageResourceDescription storageResourceDescription) + throws AppCatalogException { String storageResource = storageResourceRepository.addStorageResource(storageResourceDescription); logger.debug("Airavata registered storage resource with storage resource Id : " + storageResource); return storageResource; } public boolean updateStorageResource( - String storageResourceId, StorageResourceDescription storageResourceDescription) throws AppCatalogException { + String storageResourceId, StorageResourceDescription storageResourceDescription) + throws AppCatalogException { storageResourceRepository.updateStorageResource(storageResourceId, storageResourceDescription); logger.debug("Airavata updated storage resource with storage resource Id : " + storageResourceId); return true; @@ -1965,7 +1991,8 @@ private String addJobSubmissionInterface( String computeResourceId, String jobSubmissionInterfaceId, JobSubmissionProtocol protocolType, - int priorityOrder) throws AppCatalogException { + int priorityOrder) + throws AppCatalogException { JobSubmissionInterface jobSubmissionInterface = new JobSubmissionInterface(); jobSubmissionInterface.setJobSubmissionInterfaceId(jobSubmissionInterfaceId); jobSubmissionInterface.setPriorityOrder(priorityOrder); @@ -1979,7 +2006,8 @@ private String addDataMovementInterface( DMType dmType, String dataMovementInterfaceId, DataMovementProtocol protocolType, - int priorityOrder) throws AppCatalogException { + int priorityOrder) + throws AppCatalogException { DataMovementInterface dataMovementInterface = new DataMovementInterface(); dataMovementInterface.setDataMovementInterfaceId(dataMovementInterfaceId); dataMovementInterface.setPriorityOrder(priorityOrder); @@ -2033,14 +2061,17 @@ public String addLocalSubmissionDetails( return submissionInterface; } - public boolean updateLocalSubmissionDetails(String jobSubmissionInterfaceId, LOCALSubmission localSubmission) throws AppCatalogException { + public boolean updateLocalSubmissionDetails(String jobSubmissionInterfaceId, LOCALSubmission localSubmission) + throws AppCatalogException { new ComputeResourceRepository().updateLocalJobSubmission(localSubmission); - logger.debug("Airavata updated local job submission for job submission interface id: " + jobSubmissionInterfaceId); + logger.debug( + "Airavata updated local job submission for job submission interface id: " + jobSubmissionInterfaceId); return true; } public String addCloudJobSubmissionDetails( - String computeResourceId, int priorityOrder, CloudJobSubmission cloudSubmission) throws AppCatalogException { + String computeResourceId, int priorityOrder, CloudJobSubmission cloudSubmission) + throws AppCatalogException { ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); String submissionInterface = addJobSubmissionInterface( computeResourceRepository, @@ -2053,7 +2084,8 @@ public String addCloudJobSubmissionDetails( } public String addUNICOREJobSubmissionDetails( - String computeResourceId, int priorityOrder, UnicoreJobSubmission unicoreJobSubmission) throws AppCatalogException { + String computeResourceId, int priorityOrder, UnicoreJobSubmission unicoreJobSubmission) + throws AppCatalogException { ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); String submissionInterface = addJobSubmissionInterface( computeResourceRepository, @@ -2066,7 +2098,8 @@ public String addUNICOREJobSubmissionDetails( } // Application Interface/Module/Deployment operations - public String registerApplicationInterface(String gatewayId, ApplicationInterfaceDescription applicationInterface) throws AppCatalogException { + public String registerApplicationInterface(String gatewayId, ApplicationInterfaceDescription applicationInterface) + throws AppCatalogException { try { if (!isGatewayExistInternal(gatewayId)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); @@ -2087,7 +2120,8 @@ public boolean updateApplicationInterface( return true; } - public String registerApplicationModule(String gatewayId, ApplicationModule applicationModule) throws AppCatalogException { + public String registerApplicationModule(String gatewayId, ApplicationModule applicationModule) + throws AppCatalogException { try { if (!isGatewayExistInternal(gatewayId)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); @@ -2101,7 +2135,8 @@ public String registerApplicationModule(String gatewayId, ApplicationModule appl return module; } - public boolean updateApplicationModule(String appModuleId, ApplicationModule applicationModule) throws AppCatalogException { + public boolean updateApplicationModule(String appModuleId, ApplicationModule applicationModule) + throws AppCatalogException { applicationInterfaceRepository.updateApplicationModule(appModuleId, applicationModule); logger.debug("Airavata updated application module with module id: " + appModuleId); return true; @@ -2148,8 +2183,8 @@ public String registerUserResourceProfile(UserResourceProfile userResourceProfil throw new AppCatalogException(e.getMessage(), e); } String resourceProfile = userResourceProfileRepository.addUserResourceProfile(userResourceProfile); - logger.debug("Airavata registered user resource profile with gateway id : " - + userResourceProfile.getGatewayID() + "and user id : " + userResourceProfile.getUserId()); + logger.debug("Airavata registered user resource profile with gateway id : " + userResourceProfile.getGatewayID() + + "and user id : " + userResourceProfile.getUserId()); return resourceProfile; } @@ -2174,12 +2209,14 @@ public UserResourceProfile getUserResourceProfile(String userId, String gatewayI } catch (RegistryException e) { throw new AppCatalogException(e.getMessage(), e); } - UserResourceProfile userResourceProfile = userResourceProfileRepository.getUserResourceProfile(userId, gatewayId); + UserResourceProfile userResourceProfile = + userResourceProfileRepository.getUserResourceProfile(userId, gatewayId); logger.debug("Airavata retrieved User resource profile with user id : " + userId); return userResourceProfile; } - public boolean updateUserResourceProfile(String userId, String gatewayID, UserResourceProfile userResourceProfile) throws AppCatalogException { + public boolean updateUserResourceProfile(String userId, String gatewayID, UserResourceProfile userResourceProfile) + throws AppCatalogException { try { if (!userRepository.isUserExists(gatewayID, userId)) { logger.error("User does not exist.Please provide a valid user id..."); @@ -2209,7 +2246,8 @@ public boolean deleteUserResourceProfile(String userId, String gatewayID) throws // Resource Scheduling operations public void updateResourceScheduleing( - String airavataExperimentId, ComputationalResourceSchedulingModel resourceScheduling) throws RegistryException { + String airavataExperimentId, ComputationalResourceSchedulingModel resourceScheduling) + throws RegistryException { if (!experimentRepository.isExperimentExist(airavataExperimentId)) { logger.debug( airavataExperimentId, @@ -2262,7 +2300,8 @@ public boolean addUserComputeResourcePreference( String userId, String gatewayID, String computeResourceId, - UserComputeResourcePreference userComputeResourcePreference) throws AppCatalogException { + UserComputeResourcePreference userComputeResourcePreference) + throws AppCatalogException { try { if (!userRepository.isUserExists(gatewayID, userId)) { logger.error("user does not exist.Please provide a valid user id..."); @@ -2272,8 +2311,8 @@ public boolean addUserComputeResourcePreference( throw new AppCatalogException(e.getMessage(), e); } if (!userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayID)) { - throw new AppCatalogException("User resource profile with user id'" + userId + " & gateway Id" - + gatewayID + "' does not exist!!!"); + throw new AppCatalogException("User resource profile with user id'" + userId + " & gateway Id" + gatewayID + + "' does not exist!!!"); } UserResourceProfile profile = userResourceProfileRepository.getUserResourceProfile(userId, gatewayID); profile.addToUserComputeResourcePreferences(userComputeResourcePreference); @@ -2283,7 +2322,8 @@ public boolean addUserComputeResourcePreference( return true; } - public boolean isUserComputeResourcePreferenceExists(String userId, String gatewayID, String computeResourceId) throws AppCatalogException { + public boolean isUserComputeResourcePreferenceExists(String userId, String gatewayID, String computeResourceId) + throws AppCatalogException { try { if (userRepository.isUserExists(gatewayID, userId) && userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayID)) { @@ -2307,8 +2347,8 @@ public UserComputeResourcePreference getUserComputeResourcePreference( throw new AppCatalogException(e.getMessage(), e); } if (!userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayID)) { - throw new AppCatalogException("User resource profile with user id'" + userId + " & gateway Id" - + gatewayID + "' does not exist!!!"); + throw new AppCatalogException("User resource profile with user id'" + userId + " & gateway Id" + gatewayID + + "' does not exist!!!"); } ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); if (!computeResourceRepository.isComputeResourceExists(userComputeResourceId)) { @@ -2330,7 +2370,8 @@ public boolean updateUserComputeResourcePreference( String userId, String gatewayID, String computeResourceId, - UserComputeResourcePreference userComputeResourcePreference) throws AppCatalogException { + UserComputeResourcePreference userComputeResourcePreference) + throws AppCatalogException { try { if (!userRepository.isUserExists(gatewayID, userId)) { logger.error("user does not exist.Please provide a valid user id..."); @@ -2360,7 +2401,8 @@ public boolean updateUserComputeResourcePreference( } public boolean addUserStoragePreference( - String userId, String gatewayID, String storageResourceId, UserStoragePreference dataStoragePreference) throws AppCatalogException { + String userId, String gatewayID, String storageResourceId, UserStoragePreference dataStoragePreference) + throws AppCatalogException { try { if (!userRepository.isUserExists(gatewayID, userId)) { logger.error("user does not exist.Please provide a valid user id..."); @@ -2370,8 +2412,8 @@ public boolean addUserStoragePreference( throw new AppCatalogException(e.getMessage(), e); } if (!userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayID)) { - throw new AppCatalogException("User resource profile with user id'" + userId + " & gateway Id" - + gatewayID + "' does not exist!!!"); + throw new AppCatalogException("User resource profile with user id'" + userId + " & gateway Id" + gatewayID + + "' does not exist!!!"); } UserResourceProfile profile = userResourceProfileRepository.getUserResourceProfile(userId, gatewayID); dataStoragePreference.setStorageResourceId(storageResourceId); @@ -2382,7 +2424,8 @@ public boolean addUserStoragePreference( return true; } - public UserStoragePreference getUserStoragePreference(String userId, String gatewayID, String storageId) throws AppCatalogException { + public UserStoragePreference getUserStoragePreference(String userId, String gatewayID, String storageId) + throws AppCatalogException { try { if (!userRepository.isUserExists(gatewayID, userId)) { logger.error("user does not exist.Please provide a valid user id..."); @@ -2392,8 +2435,8 @@ public UserStoragePreference getUserStoragePreference(String userId, String gate throw new AppCatalogException(e.getMessage(), e); } if (!userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayID)) { - throw new AppCatalogException("User resource profile with user id'" + userId + " & gateway Id" - + gatewayID + "' does not exist!!!"); + throw new AppCatalogException("User resource profile with user id'" + userId + " & gateway Id" + gatewayID + + "' does not exist!!!"); } UserStoragePreference storagePreference = @@ -2467,7 +2510,8 @@ public void removeParserInput(String parserInputId, String gatewayId) throws Reg if (gatewayId.equals(parser.getGatewayId())) { parserInputRepository.delete(parserInputId); } else { - throw new RegistryException("ParserInput " + parserInputId + " does not belong to gateway " + gatewayId); + throw new RegistryException( + "ParserInput " + parserInputId + " does not belong to gateway " + gatewayId); } } else { throw new RegistryException("ParserInput " + parserInputId + " does not exist"); @@ -2496,7 +2540,8 @@ public void removeParserOutput(String parserOutputId, String gatewayId) throws R if (gatewayId.equals(parser.getGatewayId())) { parserOutputRepository.delete(parserOutputId); } else { - throw new RegistryException("ParserOutput " + parserOutputId + " does not belong to gateway " + gatewayId); + throw new RegistryException( + "ParserOutput " + parserOutputId + " does not belong to gateway " + gatewayId); } } else { throw new RegistryException("ParserOutput " + parserOutputId + " does not exist"); @@ -2519,7 +2564,8 @@ public String saveParsingTemplate(ParsingTemplate parsingTemplate) throws Regist public void removeParsingTemplate(String templateId, String gatewayId) throws RegistryException { boolean exists = parsingTemplateRepository.isExists(templateId); - if (exists && !gatewayId.equals(parsingTemplateRepository.get(templateId).getGatewayId())) { + if (exists + && !gatewayId.equals(parsingTemplateRepository.get(templateId).getGatewayId())) { parsingTemplateRepository.delete(templateId); } else { throw new RegistryException("Parsing template " + templateId + " does not exist"); @@ -2527,16 +2573,18 @@ public void removeParsingTemplate(String templateId, String gatewayId) throws Re } // Gateway Usage Reporting operations - public boolean isGatewayUsageReportingAvailable(String gatewayId, String computeResourceId) throws RegistryException { + public boolean isGatewayUsageReportingAvailable(String gatewayId, String computeResourceId) + throws RegistryException { return usageReportingCommandRepository.isGatewayUsageReportingCommandExists(gatewayId, computeResourceId); } - public GatewayUsageReportingCommand getGatewayReportingCommand(String gatewayId, String computeResourceId) throws RegistryException { + public GatewayUsageReportingCommand getGatewayReportingCommand(String gatewayId, String computeResourceId) + throws RegistryException { if (usageReportingCommandRepository.isGatewayUsageReportingCommandExists(gatewayId, computeResourceId)) { return usageReportingCommandRepository.getGatewayUsageReportingCommand(gatewayId, computeResourceId); } else { - String message = "No usage reporting information for the gateway " + gatewayId - + " and compute resource " + computeResourceId; + String message = "No usage reporting information for the gateway " + gatewayId + " and compute resource " + + computeResourceId; logger.error(message); throw new RegistryException(message); } @@ -2546,28 +2594,35 @@ public void addGatewayUsageReportingCommand(GatewayUsageReportingCommand command usageReportingCommandRepository.addGatewayUsageReportingCommand(command); } - public void removeGatewayUsageReportingCommand(String gatewayId, String computeResourceId) throws RegistryException { + public void removeGatewayUsageReportingCommand(String gatewayId, String computeResourceId) + throws RegistryException { usageReportingCommandRepository.removeGatewayUsageReportingCommand(gatewayId, computeResourceId); } - public boolean updateCloudJobSubmissionDetails(String jobSubmissionInterfaceId, CloudJobSubmission cloudJobSubmission) throws AppCatalogException { + public boolean updateCloudJobSubmissionDetails( + String jobSubmissionInterfaceId, CloudJobSubmission cloudJobSubmission) throws AppCatalogException { cloudJobSubmission.setJobSubmissionInterfaceId(jobSubmissionInterfaceId); computeResourceRepository.updateCloudJobSubmission(cloudJobSubmission); - logger.debug("Airavata updated Cloud job submission for job submission interface id: " + jobSubmissionInterfaceId); + logger.debug( + "Airavata updated Cloud job submission for job submission interface id: " + jobSubmissionInterfaceId); return true; } - public boolean updateSSHJobSubmissionDetails(String jobSubmissionInterfaceId, SSHJobSubmission sshJobSubmission) throws AppCatalogException { + public boolean updateSSHJobSubmissionDetails(String jobSubmissionInterfaceId, SSHJobSubmission sshJobSubmission) + throws AppCatalogException { sshJobSubmission.setJobSubmissionInterfaceId(jobSubmissionInterfaceId); computeResourceRepository.updateSSHJobSubmission(sshJobSubmission); - logger.debug("Airavata updated SSH job submission for job submission interface id: " + jobSubmissionInterfaceId); + logger.debug( + "Airavata updated SSH job submission for job submission interface id: " + jobSubmissionInterfaceId); return true; } - public boolean updateUnicoreJobSubmissionDetails(String jobSubmissionInterfaceId, UnicoreJobSubmission unicoreJobSubmission) throws AppCatalogException { + public boolean updateUnicoreJobSubmissionDetails( + String jobSubmissionInterfaceId, UnicoreJobSubmission unicoreJobSubmission) throws AppCatalogException { unicoreJobSubmission.setJobSubmissionInterfaceId(jobSubmissionInterfaceId); computeResourceRepository.updateUNICOREJobSubmission(unicoreJobSubmission); - logger.debug("Airavata updated UNICORE job submission for job submission interface id: " + jobSubmissionInterfaceId); + logger.debug( + "Airavata updated UNICORE job submission for job submission interface id: " + jobSubmissionInterfaceId); return true; } @@ -2583,7 +2638,8 @@ public String createNotification(Notification notification) throws RegistryExcep return notificationId; } - public boolean updateGateway(String gatewayId, Gateway updatedGateway) throws RegistryException, AppCatalogException { + public boolean updateGateway(String gatewayId, Gateway updatedGateway) + throws RegistryException, AppCatalogException { if (!gatewayRepository.isGatewayExist(gatewayId)) { logger.error("Gateway does not exist in the system. Please provide a valid gateway ID..."); throw new RegistryException("Gateway does not exist in the system. Please provide a valid gateway ID..."); @@ -2597,7 +2653,8 @@ public boolean updateGateway(String gatewayId, Gateway updatedGateway) throws Re public String addGateway(Gateway gateway) throws RegistryException, AppCatalogException { if (gatewayRepository.isGatewayExist(gateway.getGatewayId())) { logger.error("Gateway already exists in the system. Please provide a different gateway ID..."); - throw new AppCatalogException("Gateway already exists in the system. Please provide a different gateway ID..."); + throw new AppCatalogException( + "Gateway already exists in the system. Please provide a different gateway ID..."); } String gatewayId = gatewayRepository.addGateway(gateway); logger.debug("Airavata registered gateway with gateway id: " + gatewayId); @@ -2605,7 +2662,8 @@ public String addGateway(Gateway gateway) throws RegistryException, AppCatalogEx } public boolean updateUserStoragePreference( - String userId, String gatewayID, String storageId, UserStoragePreference userStoragePreference) throws AppCatalogException { + String userId, String gatewayID, String storageId, UserStoragePreference userStoragePreference) + throws AppCatalogException { try { if (!userRepository.isUserExists(gatewayID, userId)) { logger.error("user does not exist.Please provide a valid user id..."); @@ -2615,8 +2673,8 @@ public boolean updateUserStoragePreference( throw new AppCatalogException(e.getMessage(), e); } if (!userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayID)) { - throw new AppCatalogException("User resource profile with user id'" + userId + " & gateway Id" - + gatewayID + "' does not exist!!!"); + throw new AppCatalogException("User resource profile with user id'" + userId + " & gateway Id" + gatewayID + + "' does not exist!!!"); } UserResourceProfile profile = userResourceProfileRepository.getUserResourceProfile(userId, gatewayID); List userStoragePreferences = profile.getUserStoragePreferences(); @@ -2638,7 +2696,8 @@ public boolean updateUserStoragePreference( return true; } - public boolean deleteUserComputeResourcePreference(String userId, String gatewayID, String computeResourceId) throws AppCatalogException { + public boolean deleteUserComputeResourcePreference(String userId, String gatewayID, String computeResourceId) + throws AppCatalogException { try { if (!userRepository.isUserExists(gatewayID, userId)) { logger.error("user does not exist.Please provide a valid user id..."); @@ -2647,10 +2706,12 @@ public boolean deleteUserComputeResourcePreference(String userId, String gateway } catch (RegistryException e) { throw new AppCatalogException(e.getMessage(), e); } - return userResourceProfileRepository.removeUserComputeResourcePreferenceFromGateway(userId, gatewayID, computeResourceId); + return userResourceProfileRepository.removeUserComputeResourcePreferenceFromGateway( + userId, gatewayID, computeResourceId); } - public boolean deleteUserStoragePreference(String userId, String gatewayID, String storageId) throws AppCatalogException { + public boolean deleteUserStoragePreference(String userId, String gatewayID, String storageId) + throws AppCatalogException { try { if (!userRepository.isUserExists(gatewayID, userId)) { logger.error("user does not exist.Please provide a valid user id..."); @@ -2689,7 +2750,8 @@ public QueueStatusModel getQueueStatus(String hostName, String queueName) throws public void createGatewayGroups(GatewayGroups gatewayGroups) throws RegistryException { if (gatewayGroupsRepository.isExists(gatewayGroups.getGatewayId())) { logger.error("GatewayGroups already exists for " + gatewayGroups.getGatewayId()); - throw new RegistryException("GatewayGroups for gatewayId: " + gatewayGroups.getGatewayId() + " already exists."); + throw new RegistryException( + "GatewayGroups for gatewayId: " + gatewayGroups.getGatewayId() + " already exists."); } gatewayGroupsRepository.create(gatewayGroups); } @@ -2711,11 +2773,13 @@ public List listAllParsers(String gatewayId) throws RegistryException { return parserRepository.getAllParsers(gatewayId); } - public List getParsingTemplatesForApplication(String applicationInterfaceId) throws RegistryException { + public List getParsingTemplatesForApplication(String applicationInterfaceId) + throws RegistryException { return parsingTemplateRepository.getParsingTemplatesForApplication(applicationInterfaceId); } - public List getParsingTemplatesForExperiment(String experimentId, String gatewayId) throws RegistryException { + public List getParsingTemplatesForExperiment(String experimentId, String gatewayId) + throws RegistryException { ExperimentModel experiment = experimentRepository.getExperiment(experimentId); List processes = experiment.getProcesses(); if (processes != null && processes.size() > 0) { @@ -2729,19 +2793,24 @@ public List listAllParsingTemplates(String gatewayId) throws Re return parsingTemplateRepository.getAllParsingTemplates(gatewayId); } - public List getAllUserComputeResourcePreferences(String userId, String gatewayID) throws AppCatalogException { + public List getAllUserComputeResourcePreferences(String userId, String gatewayID) + throws AppCatalogException { try { if (!userRepository.isUserExists(gatewayID, userId)) { logger.error("User Resource Profile does not exist.Please provide a valid gateway id..."); - throw new AppCatalogException("User Resource Profile does not exist.Please provide a valid gateway id..."); + throw new AppCatalogException( + "User Resource Profile does not exist.Please provide a valid gateway id..."); } } catch (RegistryException e) { throw new AppCatalogException(e.getMessage(), e); } - return userResourceProfileRepository.getUserResourceProfile(userId, gatewayID).getUserComputeResourcePreferences(); + return userResourceProfileRepository + .getUserResourceProfile(userId, gatewayID) + .getUserComputeResourcePreferences(); } - public List getAllUserStoragePreferences(String userId, String gatewayID) throws AppCatalogException { + public List getAllUserStoragePreferences(String userId, String gatewayID) + throws AppCatalogException { try { if (!userRepository.isUserExists(gatewayID, userId)) { logger.error("User does not exist.Please provide a valid gateway id..."); @@ -2750,7 +2819,8 @@ public List getAllUserStoragePreferences(String userId, S } catch (RegistryException e) { throw new AppCatalogException(e.getMessage(), e); } - return userResourceProfileRepository.getUserResourceProfile(userId, gatewayID).getUserStoragePreferences(); + return userResourceProfileRepository + .getUserResourceProfile(userId, gatewayID) + .getUserStoragePreferences(); } } - diff --git a/airavata-api/src/main/java/org/apache/airavata/service/SharingRegistryService.java b/airavata-api/src/main/java/org/apache/airavata/service/SharingRegistryService.java index ad9552f8e3..583e11c9d8 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/SharingRegistryService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/SharingRegistryService.java @@ -113,9 +113,7 @@ public String createUser(User user) throws SharingRegistryException, DuplicateEn Domain domain = new DomainRepository().get(user.getDomainId()); if (domain.getInitialUserGroupId() != null) { addUsersToGroup( - user.getDomainId(), - Collections.singletonList(user.getUserId()), - domain.getInitialUserGroupId()); + user.getDomainId(), Collections.singletonList(user.getUserId()), domain.getInitialUserGroupId()); } return user.getUserId(); @@ -356,8 +354,7 @@ public boolean removeGroupAdmins(String domainId, String groupId, List a return true; } - public boolean hasAdminAccess(String domainId, String groupId, String adminId) - throws SharingRegistryException { + public boolean hasAdminAccess(String domainId, String groupId, String adminId) throws SharingRegistryException { GroupAdminPK groupAdminPK = new GroupAdminPK(); groupAdminPK.setGroupId(groupId); groupAdminPK.setAdminId(adminId); @@ -367,8 +364,7 @@ public boolean hasAdminAccess(String domainId, String groupId, String adminId) return false; } - public boolean hasOwnerAccess(String domainId, String groupId, String ownerId) - throws SharingRegistryException { + public boolean hasOwnerAccess(String domainId, String groupId, String ownerId) throws SharingRegistryException { UserGroupPK userGroupPK = new UserGroupPK(); userGroupPK.setGroupId(groupId); userGroupPK.setDomainId(domainId); @@ -418,8 +414,7 @@ public boolean removeChildGroupFromParentGroup(String domainId, String childId, return true; } - public List getAllMemberGroupsForUser(String domainId, String userId) - throws SharingRegistryException { + public List getAllMemberGroupsForUser(String domainId, String userId) throws SharingRegistryException { GroupMembershipRepository groupMembershipRepository = new GroupMembershipRepository(); return groupMembershipRepository.getAllMemberGroupsForUser(domainId, userId); } @@ -428,8 +423,7 @@ public List getAllMemberGroupsForUser(String domainId, String userId) * * EntityType Operations * * */ - public String createEntityType(EntityType entityType) - throws SharingRegistryException, DuplicateEntryException { + public String createEntityType(EntityType entityType) throws SharingRegistryException, DuplicateEntryException { EntityTypePK entityTypePK = new EntityTypePK(); entityTypePK.setDomainId(entityType.getDomainId()); entityTypePK.setEntityTypeId(entityType.getEntityTypeId()); @@ -454,8 +448,7 @@ public boolean updateEntityType(EntityType entityType) throws SharingRegistryExc return true; } - public boolean isEntityTypeExists(String domainId, String entityTypeId) - throws SharingRegistryException { + public boolean isEntityTypeExists(String domainId, String entityTypeId) throws SharingRegistryException { EntityTypePK entityTypePK = new EntityTypePK(); entityTypePK.setDomainId(domainId); entityTypePK.setEntityTypeId(entityTypeId); @@ -511,16 +504,14 @@ public boolean updatePermissionType(PermissionType permissionType) throws Sharin return true; } - public boolean isPermissionExists(String domainId, String permissionId) - throws SharingRegistryException { + public boolean isPermissionExists(String domainId, String permissionId) throws SharingRegistryException { PermissionTypePK permissionTypePK = new PermissionTypePK(); permissionTypePK.setDomainId(domainId); permissionTypePK.setPermissionTypeId(permissionId); return (new PermissionTypeRepository()).isExists(permissionTypePK); } - public boolean deletePermissionType(String domainId, String permissionTypeId) - throws SharingRegistryException { + public boolean deletePermissionType(String domainId, String permissionTypeId) throws SharingRegistryException { PermissionTypePK permissionTypePK = new PermissionTypePK(); permissionTypePK.setDomainId(domainId); permissionTypePK.setPermissionTypeId(permissionTypeId); @@ -528,8 +519,7 @@ public boolean deletePermissionType(String domainId, String permissionTypeId) return true; } - public PermissionType getPermissionType(String domainId, String permissionTypeId) - throws SharingRegistryException { + public PermissionType getPermissionType(String domainId, String permissionTypeId) throws SharingRegistryException { PermissionTypePK permissionTypePK = new PermissionTypePK(); permissionTypePK.setDomainId(domainId); permissionTypePK.setPermissionTypeId(permissionTypeId); @@ -772,8 +762,7 @@ private boolean shareEntity( sharing.setUpdatedTime(System.currentTimeMillis()); sharings.add(sharing); (new EntityRepository()) - .getChildEntities(domainId, childEntityId).stream() - .forEach(e -> temp.addLast(e)); + .getChildEntities(domainId, childEntityId).stream().forEach(e -> temp.addLast(e)); } } } @@ -915,4 +904,3 @@ private static Hashtable fieldsToHT(Field[] fields, Object obj) return hashtable; } } - diff --git a/airavata-api/src/main/java/org/apache/airavata/service/TenantProfileService.java b/airavata-api/src/main/java/org/apache/airavata/service/TenantProfileService.java index c6e9b7c157..e730bdd457 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/TenantProfileService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/TenantProfileService.java @@ -240,4 +240,3 @@ private CredentialStoreService.Client getCredentialStoreServiceClient() } } } - diff --git a/airavata-api/src/main/java/org/apache/airavata/service/UserProfileService.java b/airavata-api/src/main/java/org/apache/airavata/service/UserProfileService.java index ea0553c13b..530dcc4284 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/UserProfileService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/UserProfileService.java @@ -117,7 +117,8 @@ public String addUserProfile(AuthzToken authzToken, UserProfile userProfile) thr } } - public boolean updateUserProfile(AuthzToken authzToken, UserProfile userProfile) throws UserProfileServiceException { + public boolean updateUserProfile(AuthzToken authzToken, UserProfile userProfile) + throws UserProfileServiceException { try { // After updating the user profile in the database but before committing the transaction, the // following will update the user profile in the IAM service also. If the update in the IAM service @@ -233,4 +234,3 @@ private IamAdminServices.Client getIamAdminServicesClient() throws UserProfileSe } } } - diff --git a/airavata-api/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java index e7c244fe29..b9b30e05f0 100644 --- a/airavata-api/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java @@ -34,8 +34,9 @@ public class SharingRegistryServerHandler implements SharingRegistryService.Iface { private static final Logger logger = LoggerFactory.getLogger(SharingRegistryServerHandler.class); private org.apache.airavata.service.SharingRegistryService sharingRegistryService; - - public static String OWNER_PERMISSION_NAME = org.apache.airavata.service.SharingRegistryService.OWNER_PERMISSION_NAME; + + public static String OWNER_PERMISSION_NAME = + org.apache.airavata.service.SharingRegistryService.OWNER_PERMISSION_NAME; public SharingRegistryServerHandler() throws ApplicationSettingsException, TException { this(new SharingRegistryDBInitConfig()); @@ -780,7 +781,8 @@ public boolean shareEntityWithUsers( String domainId, String entityId, List userList, String permissionTypeId, boolean cascadePermission) throws SharingRegistryException, TException { try { - return sharingRegistryService.shareEntityWithUsers(domainId, entityId, userList, permissionTypeId, cascadePermission); + return sharingRegistryService.shareEntityWithUsers( + domainId, entityId, userList, permissionTypeId, cascadePermission); } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { @@ -798,7 +800,8 @@ public boolean shareEntityWithGroups( boolean cascadePermission) throws SharingRegistryException, TException { try { - return sharingRegistryService.shareEntityWithGroups(domainId, entityId, groupList, permissionTypeId, cascadePermission); + return sharingRegistryService.shareEntityWithGroups( + domainId, entityId, groupList, permissionTypeId, cascadePermission); } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { @@ -826,7 +829,8 @@ public boolean revokeEntitySharingFromGroups( String domainId, String entityId, List groupList, String permissionTypeId) throws SharingRegistryException, TException { try { - return sharingRegistryService.revokeEntitySharingFromGroups(domainId, entityId, groupList, permissionTypeId); + return sharingRegistryService.revokeEntitySharingFromGroups( + domainId, entityId, groupList, permissionTypeId); } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { From c4ca9f893263fd5fc1ca99391decf3fa91499ac6 Mon Sep 17 00:00:00 2001 From: Dimuthu Wannipurage Date: Wed, 12 Nov 2025 14:15:47 -0500 Subject: [PATCH 15/26] Making experiment data path relative when the destination and source storages are different (#574) * Making experiment data path relative when the destination and source storage are different. * Storage directory size fetching api (#575) * Making experiment data path relative when the destination and source storage are different. * Enabling storage directory size listing api * Adding storage directory size listing api to python sdk * bump up the sdk version and spotless apply From 7fb22d928c44766aecbf517c8c4e4af59d14c6be Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 14 Nov 2025 17:15:38 -0500 Subject: [PATCH 16/26] Bump io.github.ascopes:protobuf-maven-plugin from 2.12.1 to 3.10.2 (#576) Bumps [io.github.ascopes:protobuf-maven-plugin](https://github.com/ascopes/protobuf-maven-plugin) from 2.12.1 to 3.10.2. - [Release notes](https://github.com/ascopes/protobuf-maven-plugin/releases) - [Commits](https://github.com/ascopes/protobuf-maven-plugin/compare/v2.12.1...v3.10.2) --- updated-dependencies: - dependency-name: io.github.ascopes:protobuf-maven-plugin dependency-version: 3.10.2 dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> From aff3d9e3ecd06f4b2a5e742a887eac27622ad636 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 14 Nov 2025 17:15:49 -0500 Subject: [PATCH 17/26] Bump io.github.ascopes:protobuf-maven-plugin (#568) Bumps [io.github.ascopes:protobuf-maven-plugin](https://github.com/ascopes/protobuf-maven-plugin) from 2.12.1 to 3.10.2. - [Release notes](https://github.com/ascopes/protobuf-maven-plugin/releases) - [Commits](https://github.com/ascopes/protobuf-maven-plugin/compare/v2.12.1...v3.10.2) --- updated-dependencies: - dependency-name: io.github.ascopes:protobuf-maven-plugin dependency-version: 3.10.2 dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> From 8900c3192ffcbd6cf5f5234f497acf3ffdb63ed5 Mon Sep 17 00:00:00 2001 From: yasithdev Date: Mon, 24 Nov 2025 20:05:45 -0600 Subject: [PATCH 18/26] partial fix --- .../server/handler/AiravataServerHandler.java | 4375 ++++------------- .../handler/ThriftExceptionHandler.java | 50 + .../server/CredentialStoreServerHandler.java | 16 +- .../server/OrchestratorServerHandler.java | 270 +- .../handler/RegistryServerHandler.java | 503 +- .../airavata/service/AiravataService.java | 1149 +++-- .../service/CredentialStoreService.java | 15 +- .../airavata/service/OrchestratorService.java | 185 +- .../airavata/service/RegistryService.java | 90 +- .../handlers/GroupManagerServiceHandler.java | 156 +- .../handlers/IamAdminServicesHandler.java | 30 +- .../handlers/TenantProfileServiceHandler.java | 14 +- .../handlers/UserProfileServiceHandler.java | 14 +- 13 files changed, 2345 insertions(+), 4522 deletions(-) create mode 100644 airavata-api/src/main/java/org/apache/airavata/api/server/handler/ThriftExceptionHandler.java diff --git a/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java index acbf591e14..ab9973f5e7 100644 --- a/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java @@ -19,7 +19,6 @@ */ package org.apache.airavata.api.server.handler; -import java.time.Duration; import java.util.*; import java.util.stream.Collectors; import org.apache.airavata.accountprovisioning.ConfigParam; @@ -27,16 +26,15 @@ import org.apache.airavata.accountprovisioning.SSHAccountProvisionerFactory; import org.apache.airavata.accountprovisioning.SSHAccountProvisionerProvider; import org.apache.airavata.agents.api.AgentAdaptor; -import org.apache.airavata.agents.api.AgentException; + import org.apache.airavata.api.Airavata; import org.apache.airavata.api.airavata_apiConstants; -import org.apache.airavata.common.exception.AiravataException; + import org.apache.airavata.common.exception.ApplicationSettingsException; import org.apache.airavata.common.utils.AiravataUtils; import org.apache.airavata.common.utils.Constants; import org.apache.airavata.common.utils.ServerSettings; -import org.apache.airavata.common.utils.ThriftClientPool; -import org.apache.airavata.credential.store.cpi.CredentialStoreService; + import org.apache.airavata.helix.core.support.adaptor.AdaptorSupportImpl; import org.apache.airavata.messaging.core.MessagingFactory; import org.apache.airavata.messaging.core.Publisher; @@ -86,13 +84,12 @@ import org.apache.airavata.model.workspace.Gateway; import org.apache.airavata.model.workspace.Notification; import org.apache.airavata.model.workspace.Project; -import org.apache.airavata.registry.api.RegistryService; + import org.apache.airavata.service.security.interceptor.SecurityCheck; import org.apache.airavata.sharing.registry.models.*; -import org.apache.airavata.sharing.registry.service.cpi.SharingRegistryService; -import org.apache.commons.pool2.impl.GenericObjectPoolConfig; -import org.apache.thrift.TApplicationException; + import org.apache.thrift.TException; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -101,9 +98,6 @@ public class AiravataServerHandler implements Airavata.Iface { private Publisher statusPublisher; private Publisher experimentPublisher; - private ThriftClientPool sharingClientPool; - private ThriftClientPool registryClientPool; - private ThriftClientPool csClientPool; private org.apache.airavata.service.AiravataService airavataService = new org.apache.airavata.service.AiravataService(); @@ -111,202 +105,20 @@ public AiravataServerHandler() { try { statusPublisher = MessagingFactory.getPublisher(Type.STATUS); experimentPublisher = MessagingFactory.getPublisher(Type.EXPERIMENT_LAUNCH); - - sharingClientPool = new ThriftClientPool<>( - tProtocol -> new SharingRegistryService.Client(tProtocol), - this.createGenericObjectPoolConfig(), - ServerSettings.getSharingRegistryHost(), - Integer.parseInt(ServerSettings.getSharingRegistryPort())); - registryClientPool = new ThriftClientPool<>( - tProtocol -> new RegistryService.Client(tProtocol), - this.createGenericObjectPoolConfig(), - ServerSettings.getRegistryServerHost(), - Integer.parseInt(ServerSettings.getRegistryServerPort())); - csClientPool = new ThriftClientPool<>( - tProtocol -> new CredentialStoreService.Client(tProtocol), - this.createGenericObjectPoolConfig(), - ServerSettings.getCredentialStoreServerHost(), - Integer.parseInt(ServerSettings.getCredentialStoreServerPort())); - - initSharingRegistry(); - postInitDefaultGateway(); + airavataService.init(); } catch (ApplicationSettingsException e) { logger.error("Error occured while reading airavata-server properties..", e); - } catch (AiravataException e) { - logger.error("Error occured while reading airavata-server properties..", e); - } catch (TException e) { + } catch (Throwable e) { logger.error("Error occured while reading airavata-server properties..", e); } } - private GenericObjectPoolConfig createGenericObjectPoolConfig() { - - GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig(); - poolConfig.setMaxTotal(100); - poolConfig.setMinIdle(5); - poolConfig.setBlockWhenExhausted(true); - poolConfig.setTestOnBorrow(true); - poolConfig.setTestWhileIdle(true); - // must set timeBetweenEvictionRunsMillis since eviction doesn't run unless that is positive - poolConfig.setTimeBetweenEvictionRuns(Duration.ofMinutes(5)); - poolConfig.setNumTestsPerEvictionRun(10); - poolConfig.setMaxWait(Duration.ofSeconds(3)); - return poolConfig; - } - - /** - * This method creates a password token for the default gateway profile. Default gateway is originally initialized - * at the registry server but we can not add the password token at that step as the credential store is not initialized - * before registry server. - */ - private void postInitDefaultGateway() { - - RegistryService.Client registryClient = registryClientPool.getResource(); - try { - - GatewayResourceProfile gatewayResourceProfile = - registryClient.getGatewayResourceProfile(ServerSettings.getDefaultUserGateway()); - if (gatewayResourceProfile != null && gatewayResourceProfile.getIdentityServerPwdCredToken() == null) { - - logger.debug("Starting to add the password credential for default gateway : " - + ServerSettings.getDefaultUserGateway()); - - PasswordCredential passwordCredential = new PasswordCredential(); - passwordCredential.setPortalUserName(ServerSettings.getDefaultUser()); - passwordCredential.setGatewayId(ServerSettings.getDefaultUserGateway()); - passwordCredential.setLoginUserName(ServerSettings.getDefaultUser()); - passwordCredential.setPassword(ServerSettings.getDefaultUserPassword()); - passwordCredential.setDescription("Credentials for default gateway"); - - CredentialStoreService.Client csClient = csClientPool.getResource(); - String token = null; - try { - logger.info("Creating password credential for default gateway"); - token = csClient.addPasswordCredential(passwordCredential); - csClientPool.returnResource(csClient); - } catch (Exception ex) { - logger.error( - "Failed to create the password credential for the default gateway : " - + ServerSettings.getDefaultUserGateway(), - ex); - if (csClient != null) { - csClientPool.returnBrokenResource(csClient); - } - } - - if (token != null) { - logger.debug("Adding password credential token " + token + " to the default gateway : " - + ServerSettings.getDefaultUserGateway()); - gatewayResourceProfile.setIdentityServerPwdCredToken(token); - gatewayResourceProfile.setIdentityServerTenant(ServerSettings.getDefaultUserGateway()); - registryClient.updateGatewayResourceProfile( - ServerSettings.getDefaultUserGateway(), gatewayResourceProfile); - } - } - - registryClientPool.returnResource(registryClient); - } catch (Exception e) { - logger.error("Failed to add the password credentials for the default gateway", e); - - if (registryClient != null) { - registryClientPool.returnBrokenResource(registryClient); - } - } - } - - private void initSharingRegistry() throws ApplicationSettingsException, TException { - SharingRegistryService.Client client = sharingClientPool.getResource(); - try { - if (!client.isDomainExists(ServerSettings.getDefaultUserGateway())) { - Domain domain = new Domain(); - domain.setDomainId(ServerSettings.getDefaultUserGateway()); - domain.setName(ServerSettings.getDefaultUserGateway()); - domain.setDescription("Domain entry for " + domain.getName()); - client.createDomain(domain); - - User user = new User(); - user.setDomainId(domain.getDomainId()); - user.setUserId(ServerSettings.getDefaultUser() + "@" + ServerSettings.getDefaultUserGateway()); - user.setUserName(ServerSettings.getDefaultUser()); - client.createUser(user); - - // Creating Entity Types for each domain - EntityType entityType = new EntityType(); - entityType.setEntityTypeId(domain.getDomainId() + ":PROJECT"); - entityType.setDomainId(domain.getDomainId()); - entityType.setName("PROJECT"); - entityType.setDescription("Project entity type"); - client.createEntityType(entityType); - - entityType = new EntityType(); - entityType.setEntityTypeId(domain.getDomainId() + ":EXPERIMENT"); - entityType.setDomainId(domain.getDomainId()); - entityType.setName("EXPERIMENT"); - entityType.setDescription("Experiment entity type"); - client.createEntityType(entityType); - - entityType = new EntityType(); - entityType.setEntityTypeId(domain.getDomainId() + ":FILE"); - entityType.setDomainId(domain.getDomainId()); - entityType.setName("FILE"); - entityType.setDescription("File entity type"); - client.createEntityType(entityType); - - entityType = new EntityType(); - entityType.setEntityTypeId(domain.getDomainId() + ":" + ResourceType.APPLICATION_DEPLOYMENT.name()); - entityType.setDomainId(domain.getDomainId()); - entityType.setName("APPLICATION-DEPLOYMENT"); - entityType.setDescription("Application Deployment entity type"); - client.createEntityType(entityType); - - entityType = new EntityType(); - entityType.setEntityTypeId(domain.getDomainId() + ":" + ResourceType.GROUP_RESOURCE_PROFILE.name()); - entityType.setDomainId(domain.getDomainId()); - entityType.setName(ResourceType.GROUP_RESOURCE_PROFILE.name()); - entityType.setDescription("Group Resource Profile entity type"); - client.createEntityType(entityType); - - entityType = new EntityType(); - entityType.setEntityTypeId(domain.getDomainId() + ":" + ResourceType.CREDENTIAL_TOKEN.name()); - entityType.setDomainId(domain.getDomainId()); - entityType.setName(ResourceType.CREDENTIAL_TOKEN.name()); - entityType.setDescription("Credential Store Token entity type"); - client.createEntityType(entityType); - - // Creating Permission Types for each domain - PermissionType permissionType = new PermissionType(); - permissionType.setPermissionTypeId(domain.getDomainId() + ":READ"); - permissionType.setDomainId(domain.getDomainId()); - permissionType.setName("READ"); - permissionType.setDescription("Read permission type"); - client.createPermissionType(permissionType); - - permissionType = new PermissionType(); - permissionType.setPermissionTypeId(domain.getDomainId() + ":WRITE"); - permissionType.setDomainId(domain.getDomainId()); - permissionType.setName("WRITE"); - permissionType.setDescription("Write permission type"); - client.createPermissionType(permissionType); - - permissionType = new PermissionType(); - permissionType.setPermissionTypeId(domain.getDomainId() + ":MANAGE_SHARING"); - permissionType.setDomainId(domain.getDomainId()); - permissionType.setName("MANAGE_SHARING"); - permissionType.setDescription("Sharing permission type"); - client.createPermissionType(permissionType); - } - sharingClientPool.returnResource(client); - } catch (Exception ex) { - sharingClientPool.returnBrokenResource(client); - throw ex; - } - } /** * Query Airavata to fetch the API version */ @Override - public String getAPIVersion() throws TException { + public String getAPIVersion() { return airavata_apiConstants.AIRAVATA_API_VERSION; } @@ -321,42 +133,16 @@ public String getAPIVersion() throws TException { @Override @SecurityCheck public boolean isUserExists(AuthzToken authzToken, String gatewayId, String userName) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - try { - boolean isExists = airavataService.isUserExists(gatewayId, userName); - logger.debug("Checking if the user" + userName + "exists in the gateway" + gatewayId); - return isExists; - } catch (Exception e) { - logger.error("Error while verifying user", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while verifying user. More info : " + e.getMessage()); - throw exception; - } + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + logger.debug("Checking if the user" + userName + "exists in the gateway" + gatewayId); + return airavataService.isUserExists(gatewayId, userName); } @Override @SecurityCheck public String addGateway(AuthzToken authzToken, Gateway gateway) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); - RegistryService.Client registryClient = registryClientPool.getResource(); - try { - String gatewayId = airavataService.addGatewayWithSharing(registryClient, sharingClient, gateway); - registryClientPool.returnResource(registryClient); - sharingClientPool.returnResource(sharingClient); - return gatewayId; - } catch (Exception e) { - logger.error("Error while adding gateway", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding gateway. More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - registryClientPool.returnBrokenResource(registryClient); - throw exception; - } + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + return airavataService.addGatewayWithSharing(gateway); } /** @@ -370,100 +156,66 @@ public String addGateway(AuthzToken authzToken, Gateway gateway) @Override @SecurityCheck public List getAllUsersInGateway(AuthzToken authzToken, String gatewayId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - try { - return airavataService.getAllUsersInGateway(gatewayId); - } catch (Exception e) { - logger.error("Error while retrieving users", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving users. More info : " + e.getMessage()); - throw exception; - } + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + return airavataService.getAllUsersInGateway(gatewayId); } @Override @SecurityCheck public boolean updateGateway(AuthzToken authzToken, String gatewayId, Gateway updatedGateway) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return airavataService.updateGateway(gatewayId, updatedGateway); - } catch (Exception e) { - logger.error("Error while updating the gateway", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating the gateway. More info : " + e.getMessage()); - throw exception; + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while updating the gateway"); } } @Override @SecurityCheck public Gateway getGateway(AuthzToken authzToken, String gatewayId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { Gateway result = airavataService.getGateway(gatewayId); logger.debug("Airavata found the gateway with " + gatewayId); return result; - } catch (Exception e) { - logger.error("Error while getting the gateway", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while getting the gateway. More info : " + e.getMessage()); - throw exception; + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while retrieving gateway"); } } @Override @SecurityCheck public boolean deleteGateway(AuthzToken authzToken, String gatewayId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return airavataService.deleteGateway(gatewayId); - } catch (Exception e) { - logger.error("Error while deleting the gateway", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while deleting the gateway. More info : " + e.getMessage()); - throw exception; + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while deleting the gateway"); } } @Override @SecurityCheck public List getAllGateways(AuthzToken authzToken) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { logger.debug("Airavata searching for all gateways"); return airavataService.getAllGateways(); - } catch (Exception e) { - logger.error("Error while getting all the gateways", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while getting all the gateways. More info : " + e.getMessage()); - throw exception; + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while retrieving all gateways"); } } @Override @SecurityCheck public boolean isGatewayExist(AuthzToken authzToken, String gatewayId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { logger.debug("Airavata verifying if the gateway with " + gatewayId + "exits"); return airavataService.isGatewayExist(gatewayId); - } catch (Exception e) { - logger.error("Error while getting gateway", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while getting gateway. More info : " + e.getMessage()); - throw exception; + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while checking if gateway exists"); } } @@ -477,108 +229,68 @@ public boolean isGatewayExist(AuthzToken authzToken, String gatewayId) @Override @SecurityCheck public String createNotification(AuthzToken authzToken, Notification notification) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return airavataService.createNotification(notification); - } catch (Exception e) { - logger.error("Error while creating notification", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while creating notification. More info : " + e.getMessage()); - throw exception; + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while creating notification"); } } @Override @SecurityCheck public boolean updateNotification(AuthzToken authzToken, Notification notification) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return airavataService.updateNotification(notification); - } catch (Exception e) { - logger.error("Error while updating notification", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating notification. More info : " + e.getMessage()); - throw exception; + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while updating notification"); } } @Override @SecurityCheck public boolean deleteNotification(AuthzToken authzToken, String gatewayId, String notificationId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return airavataService.deleteNotification(gatewayId, notificationId); - } catch (Exception e) { - logger.error("Error while deleting notification", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while deleting notification. More info : " + e.getMessage()); - throw exception; + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while deleting notification"); } } // No security check @Override public Notification getNotification(AuthzToken authzToken, String gatewayId, String notificationId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return airavataService.getNotification(gatewayId, notificationId); - } catch (Exception e) { - logger.error("Error while retrieving notification", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retreiving notification. More info : " + e.getMessage()); - throw exception; + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while retrieving notification"); } } // No security check @Override public List getAllNotifications(AuthzToken authzToken, String gatewayId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return airavataService.getAllNotifications(gatewayId); - } catch (Exception e) { - logger.error("Error while getting all notifications", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while getting all notifications. More info : " + e.getMessage()); - throw exception; + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while getting all notifications"); } } @Override @SecurityCheck public String generateAndRegisterSSHKeys(AuthzToken authzToken, String description) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); - CredentialStoreService.Client csClient = csClientPool.getResource(); - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); - RegistryService.Client regClient = registryClientPool.getResource(); - try { - String key = airavataService.generateAndRegisterSSHKeys( - csClient, sharingClient, gatewayId, userName, description); - csClientPool.returnResource(csClient); - sharingClientPool.returnResource(sharingClient); - registryClientPool.returnResource(regClient); - return key; - } catch (Exception e) { - logger.error("Error occurred while registering SSH Credential", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while registering SSH Credential. More info : " + e.getMessage()); - csClientPool.returnBrokenResource(csClient); - sharingClientPool.returnBrokenResource(sharingClient); - registryClientPool.returnBrokenResource(regClient); - throw exception; + try { + return airavataService.generateAndRegisterSSHKeys( gatewayId, userName, description); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error occurred while registering SSH Credential"); } } @@ -595,162 +307,63 @@ public String generateAndRegisterSSHKeys(AuthzToken authzToken, String descripti @SecurityCheck public String registerPwdCredential( AuthzToken authzToken, String loginUserName, String password, String description) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException { + throws AiravataClientException, AiravataSystemException, AuthorizationException, InvalidRequestException { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); - CredentialStoreService.Client csClient = csClientPool.getResource(); - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); - try { - String key = airavataService.registerPwdCredential( - csClient, sharingClient, gatewayId, userName, loginUserName, password, description); - csClientPool.returnResource(csClient); - sharingClientPool.returnResource(sharingClient); - return key; - } catch (org.apache.airavata.credential.store.exception.CredentialStoreException e) { - logger.error("Error occurred while registering PWD Credential", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while registering PWD Credential. More info : " + e.getMessage()); - csClientPool.returnBrokenResource(csClient); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; - } catch (Exception e) { - logger.error("Error occurred while registering PWD Credential", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while registering PWD Credential. More info : " + e.getMessage()); - csClientPool.returnBrokenResource(csClient); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + try { + return airavataService.registerPwdCredential( gatewayId, userName, loginUserName, password, description); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error occurred while registering PWD Credential"); } } @Override @SecurityCheck public CredentialSummary getCredentialSummary(AuthzToken authzToken, String tokenId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - CredentialStoreService.Client csClient = csClientPool.getResource(); - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); try { - CredentialSummary credentialSummary = airavataService.getCredentialSummaryWithAuth( - csClient, sharingClient, authzToken, tokenId, gatewayId); - csClientPool.returnResource(csClient); - sharingClientPool.returnResource(sharingClient); - return credentialSummary; - } catch (Exception e) { - if (e.getMessage() != null && e.getMessage().contains("does not have permission")) { - String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); - logger.info("User " + userName + " not allowed to access credential store token " + tokenId); - csClientPool.returnResource(csClient); - sharingClientPool.returnResource(sharingClient); - throw new AuthorizationException("User does not have permission to access this resource"); - } + return airavataService.getCredentialSummaryWithAuth( authzToken, tokenId, gatewayId); + } catch (Throwable e) { String msg = "Error retrieving credential summary for token " + tokenId + ". GatewayId: " + gatewayId; - logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - csClientPool.returnBrokenResource(csClient); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @Override @SecurityCheck public List getAllCredentialSummaries(AuthzToken authzToken, SummaryType type) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException { - CredentialStoreService.Client csClient = csClientPool.getResource(); - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + throws InvalidRequestException, AiravataClientException, AiravataSystemException { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); try { - List credentialSummaries = airavataService.getAllCredentialSummariesWithAuth( - csClient, sharingClient, authzToken, type, gatewayId, userName); - csClientPool.returnResource(csClient); - sharingClientPool.returnResource(sharingClient); - return credentialSummaries; - } catch (org.apache.airavata.credential.store.exception.CredentialStoreException e) { - String msg = "Error retrieving credential summaries of type " + type + ". GatewayId: " + gatewayId; - logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - csClientPool.returnBrokenResource(csClient); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; - } catch (Exception e) { - String msg = "Error retrieving credential summaries of type " + type + ". GatewayId: " + gatewayId; - logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - csClientPool.returnBrokenResource(csClient); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + return airavataService.getAllCredentialSummariesWithAuth( authzToken, type, gatewayId, userName); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error retrieving credential summaries of type " + type + ". GatewayId: " + gatewayId); } } @Override @SecurityCheck public boolean deleteSSHPubKey(AuthzToken authzToken, String airavataCredStoreToken) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException { - CredentialStoreService.Client csClient = csClientPool.getResource(); - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + throws AiravataClientException, AiravataSystemException, AuthorizationException, InvalidRequestException { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); try { - boolean result = airavataService.deleteSSHPubKey( - csClient, sharingClient, authzToken, airavataCredStoreToken, gatewayId); - csClientPool.returnResource(csClient); - sharingClientPool.returnResource(sharingClient); - return result; - } catch (Exception e) { - if (e.getMessage() != null && e.getMessage().contains("does not have permission")) { - String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); - logger.info("User " + userName + " not allowed to delete (no WRITE permission) credential store token " - + airavataCredStoreToken); - csClientPool.returnResource(csClient); - sharingClientPool.returnResource(sharingClient); - throw new AuthorizationException("User does not have permission to delete this resource."); - } - logger.error("Error occurred while deleting SSH credential", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while deleting SSH credential. More info : " + e.getMessage()); - csClientPool.returnBrokenResource(csClient); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + return airavataService.deleteSSHPubKey( authzToken, airavataCredStoreToken, gatewayId); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error occurred while deleting SSH credential"); } } @Override @SecurityCheck public boolean deletePWDCredential(AuthzToken authzToken, String airavataCredStoreToken) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException { - CredentialStoreService.Client csClient = csClientPool.getResource(); - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + throws AiravataClientException, AiravataSystemException, AuthorizationException, InvalidRequestException { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); try { - boolean result = airavataService.deletePWDCredentialWithAuth( - csClient, sharingClient, authzToken, airavataCredStoreToken, gatewayId); - csClientPool.returnResource(csClient); - sharingClientPool.returnResource(sharingClient); - return result; - } catch (Exception e) { - if (e.getMessage() != null && e.getMessage().contains("does not have permission")) { - String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); - logger.info("User " + userName + " not allowed to delete (no WRITE permission) credential store token " - + airavataCredStoreToken); - csClientPool.returnResource(csClient); - sharingClientPool.returnResource(sharingClient); - throw new AuthorizationException("User does not have permission to delete this resource."); - } - logger.error("Error occurred while deleting PWD credential", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while deleting PWD credential. More info : " + e.getMessage()); - csClientPool.returnBrokenResource(csClient); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + return airavataService.deletePWDCredentialWithAuth( authzToken, airavataCredStoreToken, gatewayId); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error occurred while deleting PWD credential"); } } @@ -762,28 +375,11 @@ public boolean deletePWDCredential(AuthzToken authzToken, String airavataCredSto @Override @SecurityCheck public String createProject(AuthzToken authzToken, String gatewayId, Project project) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - // TODO: verify that gatewayId and project.gatewayId match authzToken - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - String projectId = airavataService.createProjectWithSharing(sharingClient, gatewayId, project); - sharingClientPool.returnResource(sharingClient); - return projectId; - } catch (org.apache.airavata.registry.cpi.RegistryException e) { - logger.error("Error while creating the project", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while creating the project. More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; - } catch (Exception e) { - logger.error("Error while creating the project", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while creating the project. More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + return airavataService.createProjectWithSharing( gatewayId, project); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while creating the project"); } } @@ -791,29 +387,11 @@ public String createProject(AuthzToken authzToken, String gatewayId, Project pro @SecurityCheck public void updateProject(AuthzToken authzToken, String projectId, Project updatedProject) throws InvalidRequestException, AiravataClientException, AiravataSystemException, ProjectNotFoundException, - AuthorizationException, TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); - try { - airavataService.updateProjectWithAuth(sharingClient, authzToken, projectId, updatedProject); - sharingClientPool.returnResource(sharingClient); - } catch (Exception e) { - if (e.getMessage() != null - && (e.getMessage().contains("does not have permission") - || e.getMessage().contains("cannot be changed"))) { - if (e.getMessage().contains("cannot be changed")) { - sharingClientPool.returnResource(sharingClient); - throw new InvalidRequestException(e.getMessage()); - } else { - sharingClientPool.returnResource(sharingClient); - throw new AuthorizationException("User does not have permission to access this resource"); - } - } - 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()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + AuthorizationException { + try { + airavataService.updateProjectWithAuth( authzToken, projectId, updatedProject); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while updating the project"); } } @@ -821,22 +399,11 @@ public void updateProject(AuthzToken authzToken, String projectId, Project updat @SecurityCheck public boolean deleteProject(AuthzToken authzToken, String projectId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, ProjectNotFoundException, - AuthorizationException, TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); - try { - boolean ret = airavataService.deleteProjectWithAuth(sharingClient, authzToken, projectId); - sharingClientPool.returnResource(sharingClient); - return ret; - } catch (Exception e) { - if (e.getMessage() != null && e.getMessage().contains("does not have permission")) { - sharingClientPool.returnResource(sharingClient); - throw new AuthorizationException("User does not have permission to access this resource"); - } - logger.error("Error while removing the project", e); - ProjectNotFoundException exception = new ProjectNotFoundException(); - exception.setMessage("Error while removing the project. More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + AuthorizationException { + try { + return airavataService.deleteProjectWithAuth( authzToken, projectId); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while removing the project"); } } @@ -857,22 +424,11 @@ private boolean validateString(String name) { @SecurityCheck public Project getProject(AuthzToken authzToken, String projectId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, ProjectNotFoundException, - AuthorizationException, TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); - try { - Project project = airavataService.getProjectWithAuth(sharingClient, authzToken, projectId); - sharingClientPool.returnResource(sharingClient); - return project; - } catch (Exception e) { - if (e.getMessage() != null && e.getMessage().contains("does not have permission")) { - sharingClientPool.returnResource(sharingClient); - throw new AuthorizationException("User does not have permission to access this resource"); - } - logger.error("Error while retrieving the project", e); - ProjectNotFoundException exception = new ProjectNotFoundException(); - exception.setMessage("Error while retrieving the project. More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + AuthorizationException { + try { + return airavataService.getProjectWithAuth( authzToken, projectId); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while retrieving the project"); } } @@ -893,29 +449,8 @@ public Project getProject(AuthzToken authzToken, String projectId) @SecurityCheck public List getUserProjects( AuthzToken authzToken, String gatewayId, String userName, int limit, int offset) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); - try { - List result = airavataService.getUserProjectsWithSharing( - sharingClient, authzToken, gatewayId, userName, limit, offset); - sharingClientPool.returnResource(sharingClient); - return result; - } catch (org.apache.airavata.registry.cpi.RegistryException e) { - logger.error("Error while retrieving projects", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving projects. More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; - } catch (Exception e) { - logger.error("Error while retrieving projects", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving projects. More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; - } + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + return airavataService.getUserProjectsWithSharing( authzToken, gatewayId, userName, limit, offset); } /** @@ -949,55 +484,8 @@ public List searchProjects( Map filters, int limit, int offset) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); - try { - List accessibleProjIds = new ArrayList<>(); - - List result; - if (ServerSettings.isEnableSharing()) { - List sharingFilters = new ArrayList<>(); - SearchCriteria searchCriteria = new SearchCriteria(); - searchCriteria.setSearchField(EntitySearchField.ENTITY_TYPE_ID); - searchCriteria.setSearchCondition(SearchCondition.EQUAL); - searchCriteria.setValue(gatewayId + ":PROJECT"); - sharingFilters.add(searchCriteria); - sharingClient - .searchEntities( - authzToken.getClaimsMap().get(Constants.GATEWAY_ID), - userName + "@" + gatewayId, - sharingFilters, - 0, - Integer.MAX_VALUE) - .stream() - .forEach(e -> accessibleProjIds.add(e.getEntityId())); - if (accessibleProjIds.isEmpty()) { - result = Collections.emptyList(); - } else { - result = airavataService.searchProjects( - gatewayId, userName, accessibleProjIds, filters, limit, offset); - } - } else { - result = airavataService.searchProjects(gatewayId, userName, accessibleProjIds, filters, limit, offset); - } - sharingClientPool.returnResource(sharingClient); - return result; - } catch (org.apache.airavata.registry.cpi.RegistryException e) { - logger.error("Error while retrieving projects", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving projects. More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; - } catch (Exception e) { - logger.error("Error while retrieving projects", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving projects. More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; - } + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + return airavataService.searchProjectsWithSharing(authzToken, gatewayId, userName, filters, limit, offset); } /** @@ -1024,22 +512,8 @@ public List searchExperiments( Map filters, int limit, int offset) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); - try { - List result = airavataService.searchExperimentsWithSharing( - sharingClient, authzToken, gatewayId, userName, filters, limit, offset); - sharingClientPool.returnResource(sharingClient); - return result; - } catch (Exception e) { - logger.error("Error while retrieving experiments", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving experiments. More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; - } + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + return airavataService.searchExperimentsWithSharing( authzToken, gatewayId, userName, filters, limit, offset); } /** @@ -1067,52 +541,10 @@ public ExperimentStatistics getExperimentStatistics( String resourceHostName, int limit, int offset) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - try { - // FIXME: re-enable experiment statistics for non-admin users - // Find accessible experiments in date range - // List accessibleExpIds = new ArrayList<>(); - // List sharingFilters = new ArrayList<>(); - // SearchCriteria entityTypeCriteria = new SearchCriteria(); - // entityTypeCriteria.setSearchField(EntitySearchField.ENTITY_TYPE_ID); - // entityTypeCriteria.setSearchCondition(SearchCondition.EQUAL); - // entityTypeCriteria.setValue(gatewayId + ":EXPERIMENT"); - // sharingFilters.add(entityTypeCriteria); - // SearchCriteria fromCreatedTimeCriteria = new SearchCriteria(); - // fromCreatedTimeCriteria.setSearchField(EntitySearchField.CREATED_TIME); - // fromCreatedTimeCriteria.setSearchCondition(SearchCondition.GTE); - // fromCreatedTimeCriteria.setValue(Long.toString(fromTime)); - // sharingFilters.add(fromCreatedTimeCriteria); - // SearchCriteria toCreatedTimeCriteria = new SearchCriteria(); - // toCreatedTimeCriteria.setSearchField(EntitySearchField.CREATED_TIME); - // toCreatedTimeCriteria.setSearchCondition(SearchCondition.LTE); - // toCreatedTimeCriteria.setValue(Long.toString(toTime)); - // sharingFilters.add(toCreatedTimeCriteria); - // String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - // sharingClient.searchEntities(authzToken.getClaimsMap().get(Constants.GATEWAY_ID), - // userId + "@" + gatewayId, sharingFilters, 0, Integer.MAX_VALUE).forEach(e -> - // accessibleExpIds.add(e.getEntityId())); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { List accessibleExpIds = null; - - ExperimentStatistics result = airavataService.getExperimentStatistics( - gatewayId, - fromTime, - toTime, - userName, - applicationName, - resourceHostName, - accessibleExpIds, - limit, - offset); - return result; - } catch (Exception e) { - logger.error("Error while retrieving experiments", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving experiments. More info : " + e.getMessage()); - throw exception; - } + return airavataService.getExperimentStatistics( + gatewayId, fromTime, toTime, userName, applicationName, resourceHostName, accessibleExpIds, limit, offset); } /** @@ -1131,41 +563,7 @@ public ExperimentStatistics getExperimentStatistics( public List getExperimentsInProject(AuthzToken authzToken, String projectId, int limit, int offset) throws InvalidRequestException, AiravataClientException, AiravataSystemException, ProjectNotFoundException, AuthorizationException, TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); - try { - Project project = airavataService.getProject(projectId); - - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - 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 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 result = airavataService.getExperimentsInProject(gatewayId, projectId, limit, offset); - 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()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; - } + return airavataService.getExperimentsInProject(authzToken, projectId, limit, offset); } /** @@ -1185,16 +583,11 @@ public List getExperimentsInProject(AuthzToken authzToken, Stri @SecurityCheck public List getUserExperiments( AuthzToken authzToken, String gatewayId, String userName, int limit, int offset) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return airavataService.getUserExperiments(gatewayId, userName, limit, offset); - } 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()); - throw exception; + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while retrieving the experiments. More info :"); } } @@ -1223,23 +616,13 @@ public List getUserExperiments( @Override @SecurityCheck public String createExperiment(AuthzToken authzToken, String gatewayId, ExperimentModel experiment) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { // TODO: verify that gatewayId and experiment.gatewayId match authzToken logger.info("Api server accepted experiment creation with name {}", experiment.getExperimentName()); - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); - try { - String experimentId = airavataService.createExperimentWithSharingAndPublish( - sharingClient, statusPublisher, gatewayId, experiment); - sharingClientPool.returnResource(sharingClient); - return experimentId; - } catch (Exception e) { - logger.error("Error while creating the experiment with experiment name {}", experiment.getExperimentName()); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while creating the experiment. More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + try { + return airavataService.createExperimentWithSharingAndPublish( statusPublisher, gatewayId, experiment); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while creating the experiment"); } } @@ -1257,20 +640,11 @@ public String createExperiment(AuthzToken authzToken, String gatewayId, Experime @Override @SecurityCheck public boolean deleteExperiment(AuthzToken authzToken, String experimentId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - boolean result = airavataService.deleteExperimentWithAuth(sharingClient, authzToken, experimentId); - sharingClientPool.returnResource(sharingClient); - return result; - } catch (Exception e) { - logger.error("Error while deleting the experiment", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while deleting the experiment. More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + return airavataService.deleteExperimentWithAuth( authzToken, experimentId); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while deleting the experiment"); } } @@ -1301,50 +675,7 @@ public boolean deleteExperiment(AuthzToken authzToken, String experimentId) public ExperimentModel getExperiment(AuthzToken authzToken, String airavataExperimentId) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); - ExperimentModel experimentModel = null; - try { - experimentModel = airavataService.getExperiment(airavataExperimentId); - if (authzToken - .getClaimsMap() - .get(org.apache.airavata.common.utils.Constants.USER_NAME) - .equals(experimentModel.getUserName()) - && authzToken - .getClaimsMap() - .get(org.apache.airavata.common.utils.Constants.GATEWAY_ID) - .equals(experimentModel.getGatewayId())) { - sharingClientPool.returnResource(sharingClient); - return experimentModel; - } 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, airavataExperimentId, gatewayId + ":READ")) { - throw new AuthorizationException("User does not have permission to access this resource"); - } - sharingClientPool.returnResource(sharingClient); - return experimentModel; - } catch (Exception e) { - throw new AuthorizationException("User does not have permission to access this resource"); - } - } else { - sharingClientPool.returnResource(sharingClient); - return null; - } - } catch (Exception e) { - if (e instanceof ExperimentNotFoundException) { - logger.error(e.getMessage(), e); - sharingClientPool.returnResource(sharingClient); - throw (ExperimentNotFoundException) e; - } - logger.error("Error while getting the experiment", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while getting the experiment. More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; - } + return airavataService.getExperiment(authzToken, airavataExperimentId); } @Override @@ -1352,23 +683,8 @@ public ExperimentModel getExperiment(AuthzToken authzToken, String airavataExper public ExperimentModel getExperimentByAdmin(AuthzToken authzToken, String airavataExperimentId) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - try { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - ExperimentModel experimentModel = airavataService.getExperiment(airavataExperimentId); - if (gatewayId.equals(experimentModel.getGatewayId())) { - return experimentModel; - } else { - throw new AuthorizationException("User does not have permission to access this resource"); - } - } catch (Exception e) { - logger.error("Error while getting the experiment", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while getting the experiment. More info : " + e.getMessage()); - throw exception; - } + return airavataService.getExperimentByAdmin(authzToken, airavataExperimentId); } - /** * Fetch the completed nested tree structue of previously created experiment metadata which includes processes -> * tasks -> jobs information. @@ -1396,19 +712,12 @@ public ExperimentModel getExperimentByAdmin(AuthzToken authzToken, String airava @SecurityCheck public ExperimentModel getDetailedExperimentTree(AuthzToken authzToken, String airavataExperimentId) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, - AiravataSystemException, AuthorizationException, TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + AiravataSystemException, AuthorizationException { try { ExperimentModel result = airavataService.getDetailedExperimentTree(airavataExperimentId); - sharingClientPool.returnResource(sharingClient); return result; - } catch (Exception e) { - logger.error("Error while retrieving the experiment", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving the experiment. More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while retrieving the experiment"); } } @@ -1441,73 +750,15 @@ public ExperimentModel getDetailedExperimentTree(AuthzToken authzToken, String a public void updateExperiment(AuthzToken authzToken, String airavataExperimentId, ExperimentModel experiment) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); - try { - ExperimentModel experimentModel = airavataService.getExperiment(airavataExperimentId); - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - if (ServerSettings.isEnableSharing() - && !authzToken - .getClaimsMap() - .get(org.apache.airavata.common.utils.Constants.USER_NAME) - .equals(experimentModel.getUserName()) - || !authzToken - .getClaimsMap() - .get(org.apache.airavata.common.utils.Constants.GATEWAY_ID) - .equals(experimentModel.getGatewayId())) { - try { - // Verify WRITE access - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!sharingClient.userHasAccess( - gatewayId, userId + "@" + gatewayId, airavataExperimentId, 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"); - } - } - - try { - // Update name, description and parent on Entity - // TODO: update the experiment via a DB event - Entity entity = sharingClient.getEntity(gatewayId, airavataExperimentId); - entity.setName(experiment.getExperimentName()); - entity.setDescription(experiment.getDescription()); - entity.setParentEntityId(experiment.getProjectId()); - sharingClient.updateEntity(entity); - } catch (Exception e) { - throw new Exception("Failed to update entity in sharing registry", e); - } - - airavataService.updateExperiment(airavataExperimentId, experiment); - sharingClientPool.returnResource(sharingClient); - } catch (Exception e) { - logger.error(airavataExperimentId, "Error while updating experiment", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating experiment. More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; - } - } + airavataService.updateExperiment(authzToken, airavataExperimentId, experiment); + } @Override @SecurityCheck public void updateExperimentConfiguration( AuthzToken authzToken, String airavataExperimentId, UserConfigurationDataModel userConfiguration) throws AuthorizationException, TException { - try { - airavataService.updateExperimentConfiguration(airavataExperimentId, userConfiguration); - } catch (Exception e) { - logger.error(airavataExperimentId, "Error while updating user configuration", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while updating user configuration. " + "Update experiment is only valid for experiments " - + "with status CREATED, VALIDATED, CANCELLED, FAILED and UNKNOWN. Make sure the given " - + "experiment is in one of above statuses... " - + e.getMessage()); - throw exception; - } + airavataService.updateExperimentConfiguration(airavataExperimentId, userConfiguration); } @Override @@ -1515,19 +766,7 @@ public void updateExperimentConfiguration( public void updateResourceScheduleing( AuthzToken authzToken, String airavataExperimentId, ComputationalResourceSchedulingModel resourceScheduling) throws AuthorizationException, TException { - try { - airavataService.updateResourceScheduleing(airavataExperimentId, resourceScheduling); - } catch (Exception e) { - logger.error(airavataExperimentId, "Error while updating scheduling info", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while updating scheduling info. " + "Update experiment is only valid for experiments " - + "with status CREATED, VALIDATED, CANCELLED, FAILED and UNKNOWN. Make sure the given " - + "experiment is in one of above statuses... " - + e.getMessage()); - throw exception; - } + airavataService.updateResourceScheduleing(airavataExperimentId, resourceScheduling); } /** @@ -1543,33 +782,28 @@ public void updateResourceScheduleing( */ @Override @SecurityCheck - public boolean validateExperiment(AuthzToken authzToken, String airavataExperimentId) throws TException { + public boolean validateExperiment(AuthzToken authzToken, String airavataExperimentId) + throws AiravataClientException, AiravataSystemException, AuthorizationException, ExperimentNotFoundException, InvalidRequestException { // TODO - call validation module and validate experiment /* try { - ExperimentModel experimentModel = regClient.getExperiment(airavataExperimentId); + ExperimentModel existingExperiment = airavataService.getExperiment(airavataExperimentId); if (experimentModel == null) { logger.error(airavataExperimentId, "Experiment validation failed , experiment {} doesn't exist.", airavataExperimentId); throw new ExperimentNotFoundException("Requested experiment id " + airavataExperimentId + " does not exist in the system.."); } } catch (RegistryServiceException | ApplicationSettingsException e1) { logger.error(airavataExperimentId, "Error while retrieving projects", e1); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving projects. More info : " + e1.getMessage()); - throw exception; + throw ThriftExceptionHandler.convertException(e, "Error occurred"); } Client orchestratorClient = getOrchestratorClient(); try{ if (orchestratorClient.validateExperiment(airavataExperimentId)) { logger.debug(airavataExperimentId, "Experiment validation succeed."); - return true; } else { logger.debug(airavataExperimentId, "Experiment validation failed."); return false; - }}catch (TException e){ - throw e; - }finally { + }}finally { orchestratorClient.getOutputProtocol().getTransport().close(); orchestratorClient.getInputProtocol().getTransport().close(); }*/ @@ -1601,48 +835,28 @@ public boolean validateExperiment(AuthzToken authzToken, String airavataExperime */ @Override @SecurityCheck - public ExperimentStatus getExperimentStatus(AuthzToken authzToken, String airavataExperimentId) throws TException { + public ExperimentStatus getExperimentStatus(AuthzToken authzToken, String airavataExperimentId) { try { - ExperimentStatus result = airavataService.getExperimentStatus(airavataExperimentId); - return result; - } catch (org.apache.airavata.registry.cpi.RegistryException e) { - AiravataSystemException exception = new AiravataSystemException(); - exception.setMessage(e.getMessage()); - throw exception; - } catch (Exception e) { - AiravataSystemException exception = new AiravataSystemException(); - exception.setMessage(e.getMessage()); - throw exception; - } - } + return airavataService.getExperimentStatus(airavataExperimentId); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error retrieving experiment status"); + } } @Override @SecurityCheck public List getExperimentOutputs(AuthzToken authzToken, String airavataExperimentId) - throws AuthorizationException, TException { + throws AuthorizationException { try { - List result = airavataService.getExperimentOutputs(airavataExperimentId); - return result; - } catch (org.apache.airavata.registry.cpi.RegistryException e) { - logger.error(airavataExperimentId, "Error while retrieving the experiment outputs", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving the experiment outputs. More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error(airavataExperimentId, "Error while retrieving the experiment outputs", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving the experiment outputs. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.getExperimentOutputs(airavataExperimentId); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while retrieving the experiment outputs"); + } } @Override @SecurityCheck public List getIntermediateOutputs(AuthzToken authzToken, String airavataExperimentId) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, - AiravataSystemException, AuthorizationException, TException { + AiravataSystemException, AuthorizationException { return null; } @@ -1650,35 +864,24 @@ public List getIntermediateOutputs(AuthzToken authzToken, @SecurityCheck public void fetchIntermediateOutputs(AuthzToken authzToken, String airavataExperimentId, List outputNames) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, - AiravataSystemException, AuthorizationException, TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + AiravataSystemException, AuthorizationException { try { - airavataService.validateAndFetchIntermediateOutputs( - sharingClient, authzToken, airavataExperimentId, outputNames, experimentPublisher); - sharingClientPool.returnResource(sharingClient); - } catch (Exception e) { + airavataService.validateAndFetchIntermediateOutputs( authzToken, airavataExperimentId, outputNames, experimentPublisher); + } catch (Throwable e) { if (e.getMessage() != null && e.getMessage().contains("does not have WRITE access")) { logger.error(e.getMessage(), e); - sharingClientPool.returnResource(sharingClient); throw new AuthorizationException(e.getMessage()); } else if (e.getMessage() != null && (e.getMessage().contains("does not have currently ACTIVE job") || e.getMessage().contains("already intermediate output fetching tasks"))) { logger.error(e.getMessage(), e); - sharingClientPool.returnResource(sharingClient); throw new InvalidRequestException(e.getMessage()); } logger.error( "Error while processing request to fetch intermediate outputs for experiment: " + airavataExperimentId, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while processing request to fetch intermediate outputs for experiment. More info : " - + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + throw ThriftExceptionHandler.convertException(e, "Error occurred"); } } @@ -1687,80 +890,44 @@ public void fetchIntermediateOutputs(AuthzToken authzToken, String airavataExper public ProcessStatus getIntermediateOutputProcessStatus( AuthzToken authzToken, String airavataExperimentId, List outputNames) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, - AiravataSystemException, AuthorizationException, TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + AiravataSystemException, AuthorizationException { try { - ProcessStatus result = airavataService.getIntermediateOutputProcessStatusInternal( - sharingClient, authzToken, airavataExperimentId, outputNames); - sharingClientPool.returnResource(sharingClient); - return result; - } catch (Exception e) { + return airavataService.getIntermediateOutputProcessStatusInternal( authzToken, airavataExperimentId, outputNames); + } catch (Throwable e) { if (e.getMessage() != null && e.getMessage().contains("does not have READ access")) { logger.debug(e.getMessage(), e); - sharingClientPool.returnResource(sharingClient); throw new AuthorizationException(e.getMessage()); } else if (e.getMessage() != null && e.getMessage().contains("No matching intermediate output")) { logger.debug(e.getMessage(), e); - sharingClientPool.returnResource(sharingClient); throw new InvalidRequestException(e.getMessage()); } logger.error( "Error while processing request to get intermediate output process status for experiment: " + airavataExperimentId, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while processing request to get intermediate output process status for experiment. More info : " - + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + throw ThriftExceptionHandler.convertException(e, "Error occurred"); } } @SecurityCheck public Map getJobStatuses(AuthzToken authzToken, String airavataExperimentId) - throws AuthorizationException, TException { + throws AuthorizationException { try { - Map result = airavataService.getJobStatuses(airavataExperimentId); - return result; - } catch (org.apache.airavata.registry.cpi.RegistryException e) { - logger.error(airavataExperimentId, "Error while retrieving the job statuses", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving the job statuses. More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error(airavataExperimentId, "Error while retrieving the job statuses", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving the job statuses. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.getJobStatuses(airavataExperimentId); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while retrieving the job statuses"); + } } @Override @SecurityCheck public List getJobDetails(AuthzToken authzToken, String airavataExperimentId) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, - AiravataSystemException, AuthorizationException, TException { + AiravataSystemException, AuthorizationException { try { - List result = airavataService.getJobDetails(airavataExperimentId); - return result; - } catch (org.apache.airavata.registry.cpi.RegistryException e) { - logger.error(airavataExperimentId, "Error while retrieving the job details", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving the job details. More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error(airavataExperimentId, "Error while retrieving the job details", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving the job details. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.getJobDetails(airavataExperimentId); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while retrieving the job details"); + } } /** * Launch a previously created and configured experiment. Airavata Server will then start processing the request and appropriate @@ -1792,36 +959,20 @@ public List getJobDetails(AuthzToken authzToken, String airavataExperi @Override @SecurityCheck public void launchExperiment(AuthzToken authzToken, final String airavataExperimentId, String gatewayId) - throws AuthorizationException, AiravataSystemException, TException { + throws AiravataClientException, AiravataSystemException, AuthorizationException, ExperimentNotFoundException, InvalidRequestException, TException { // TODO: verify that gatewayId matches gatewayId in authzToken logger.info("Launching experiment {}", airavataExperimentId); - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); - try { - airavataService.launchExperimentWithValidation( - sharingClient, authzToken, gatewayId, airavataExperimentId, experimentPublisher); - logger.info("Experiment with ExpId: " + airavataExperimentId + " was submitted in gateway with gatewayID: " - + gatewayId); - sharingClientPool.returnResource(sharingClient); - } catch (InvalidRequestException | ExperimentNotFoundException | AuthorizationException e) { - logger.error(e.getMessage(), e); - sharingClientPool.returnResource(sharingClient); - throw e; - } catch (Exception e1) { - logger.error(airavataExperimentId, "Error while instantiate the registry instance", e1); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while instantiate the registry instance. More info : " + e1.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; - } + airavataService.launchExperimentWithValidation( authzToken, gatewayId, airavataExperimentId, experimentPublisher); + logger.info("Experiment with ExpId: " + airavataExperimentId + " was submitted in gateway with gatewayID: " + + gatewayId); } - // private OrchestratorService.Client getOrchestratorClient() throws TException { + // private OrchestratorService.Client getOrchestratorClient() { // try { // final String serverHost = ServerSettings.getOrchestratorServerHost(); // final int serverPort = ServerSettings.getOrchestratorServerPort(); // return OrchestratorClientFactory.createOrchestratorClient(serverHost, serverPort); - // } catch (AiravataException e) { + // } catch (Throwable e) { // throw new TException(e); // } // } @@ -1872,28 +1023,19 @@ public void launchExperiment(AuthzToken authzToken, final String airavataExperim public String cloneExperiment( AuthzToken authzToken, String existingExperimentID, String newExperimentName, String newExperimentProjectId) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, - AiravataSystemException, AuthorizationException, ProjectNotFoundException, TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + AiravataSystemException, AuthorizationException, ProjectNotFoundException { try { // getExperiment will apply sharing permissions ExperimentModel existingExperiment = this.getExperiment(authzToken, existingExperimentID); - String result = cloneExperimentInternal( - sharingClient, + return cloneExperimentInternal( authzToken, existingExperimentID, newExperimentName, newExperimentProjectId, existingExperiment); - sharingClientPool.returnResource(sharingClient); - return result; - } catch (Exception e) { + } catch (Throwable e) { logger.error(existingExperimentID, "Error while cloning the experiment with existing configuration...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while cloning the experiment with existing configuration. More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + throw ThriftExceptionHandler.convertException(e, "Error occurred"); } } @@ -1902,40 +1044,30 @@ public String cloneExperiment( public String cloneExperimentByAdmin( AuthzToken authzToken, String existingExperimentID, String newExperimentName, String newExperimentProjectId) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, - AiravataSystemException, AuthorizationException, ProjectNotFoundException, TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + AiravataSystemException, AuthorizationException, ProjectNotFoundException { try { // get existing experiment by bypassing normal sharing permissions for the admin user ExperimentModel existingExperiment = this.getExperimentByAdmin(authzToken, existingExperimentID); - String result = cloneExperimentInternal( - sharingClient, + return cloneExperimentInternal( authzToken, existingExperimentID, newExperimentName, newExperimentProjectId, existingExperiment); - sharingClientPool.returnResource(sharingClient); - return result; - } catch (Exception e) { + } catch (Throwable e) { logger.error(existingExperimentID, "Error while cloning the experiment with existing configuration...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while cloning the experiment with existing configuration. More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + throw ThriftExceptionHandler.convertException(e, "Error occurred"); } } private String cloneExperimentInternal( - SharingRegistryService.Client sharingClient, AuthzToken authzToken, String existingExperimentID, String newExperimentName, String newExperimentProjectId, ExperimentModel existingExperiment) - throws ExperimentNotFoundException, ProjectNotFoundException, TException, AuthorizationException, - ApplicationSettingsException { + throws ExperimentNotFoundException, ProjectNotFoundException , AuthorizationException, + ApplicationSettingsException, InvalidRequestException, AiravataSystemException, AiravataClientException, org.apache.airavata.sharing.registry.models.SharingRegistryException { if (existingExperiment == null) { logger.error( existingExperimentID, @@ -1962,7 +1094,7 @@ private String cloneExperimentInternal( // 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( + if (!airavataService.userHasAccess( gatewayId, userId + "@" + gatewayId, existingExperiment.getProjectId(), gatewayId + ":WRITE")) { logger.error( "Error while cloning experiment {}, user doesn't have write access to project {}", @@ -1974,12 +1106,11 @@ private String cloneExperimentInternal( existingExperiment.setCreationTime(AiravataUtils.getCurrentTimestamp().getTime()); if (existingExperiment.getExecutionId() != null) { try { - List applicationOutputs = - airavataService.getApplicationOutputs(existingExperiment.getExecutionId()); + List applicationOutputs = airavataService.getApplicationOutputs(existingExperiment.getExecutionId()); existingExperiment.setExperimentOutputs(applicationOutputs); } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { logger.warn("Error getting application outputs for experiment clone: " + e.getMessage()); - } catch (Exception e) { + } catch (Throwable e) { logger.warn("Error getting application outputs for experiment clone: " + e.getMessage()); } } @@ -2002,26 +1133,25 @@ private String cloneExperimentInternal( .getResourceHostId(); try { - ComputeResourceDescription computeResourceDescription = - airavataService.getComputeResource(compResourceId); - if (!computeResourceDescription.isEnabled()) { + ComputeResourceDescription computeResource = airavataService.getComputeResource(compResourceId); + if (!computeResource.isEnabled()) { existingExperiment.getUserConfigurationData().setComputationalResourceScheduling(null); } } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { logger.warn("Error getting compute resource for experiment clone: " + e.getMessage()); - } catch (Exception e) { + } catch (Throwable e) { logger.warn("Error getting compute resource for experiment clone: " + e.getMessage()); } } logger.debug("Airavata cloned experiment with experiment id : " + existingExperimentID); existingExperiment.setUserName(userId); + String expId; try { expId = airavataService.createExperiment(gatewayId, existingExperiment); - } catch (org.apache.airavata.registry.cpi.RegistryException e) { - throw new TException("Error creating cloned experiment: " + e.getMessage(), e); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error creating cloned experiment"); } - if (ServerSettings.isEnableSharing()) { try { Entity entity = new Entity(); @@ -2032,9 +1162,9 @@ private String cloneExperimentInternal( entity.setOwnerId(existingExperiment.getUserName() + "@" + domainId); entity.setName(existingExperiment.getExperimentName()); entity.setDescription(existingExperiment.getDescription()); - sharingClient.createEntity(entity); - airavataService.shareEntityWithAdminGatewayGroups(sharingClient, entity); - } catch (Exception ex) { + airavataService.createEntity(entity); + airavataService.shareEntityWithAdminGatewayGroups( entity); + } catch (Throwable ex) { logger.error(ex.getMessage(), ex); logger.error("rolling back experiment creation Exp ID : " + expId); try { @@ -2052,7 +1182,7 @@ private String cloneExperimentInternal( * Terminate a running experiment. * * @param airavataExperimentId The identifier for the requested experiment. This is returned during the create experiment step. - * @return This method call does not have a return value. + * @This method call does not have a value. * @throws org.apache.airavata.model.error.InvalidRequestException For any incorrect forming of the request itself. * @throws org.apache.airavata.model.error.ExperimentNotFoundException If the specified experiment is not previously created, then an Experiment Not Found Exception is thrown. * @throws org.apache.airavata.model.error.AiravataClientException The following list of exceptions are thrown which Airavata Client can take corrective actions to resolve: @@ -2072,7 +1202,8 @@ private String cloneExperimentInternal( @Override @SecurityCheck public void terminateExperiment(AuthzToken authzToken, String airavataExperimentId, String gatewayId) - throws TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, + ExperimentNotFoundException { try { ExperimentModel existingExperiment = airavataService.getExperiment(airavataExperimentId); ExperimentStatus experimentLastStatus = airavataService.getExperimentStatus(airavataExperimentId); @@ -2105,18 +1236,9 @@ public void terminateExperiment(AuthzToken authzToken, String airavataExperiment logger.debug("Airavata cancelled experiment with experiment id : " + airavataExperimentId); break; } - } catch (AiravataException e) { - logger.error(airavataExperimentId, "Error while cancelling the experiment...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while cancelling the experiment. More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { + } catch (Throwable e) { logger.error(airavataExperimentId, "Error while cancelling the experiment...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while cancelling the experiment. More info : " + e.getMessage()); - throw exception; + throw ThriftExceptionHandler.convertException(e, "Error occurred"); } } @@ -2131,25 +1253,12 @@ public void terminateExperiment(AuthzToken authzToken, String airavataExperiment @SecurityCheck public String registerApplicationModule( AuthzToken authzToken, String gatewayId, ApplicationModule applicationModule) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - String result = airavataService.registerApplicationModule(gatewayId, applicationModule); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error("Error while adding application module...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding application module. More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error("Error while adding application module...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding application module. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.registerApplicationModule(gatewayId, applicationModule); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while adding application module"); + } } /** * Fetch a Application Module. @@ -2161,25 +1270,12 @@ public String registerApplicationModule( @Override @SecurityCheck public ApplicationModule getApplicationModule(AuthzToken authzToken, String appModuleId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - ApplicationModule result = airavataService.getApplicationModule(appModuleId); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error(appModuleId, "Error while retrieving application module...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving the adding application module. More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error(appModuleId, "Error while retrieving application module...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving the adding application module. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.getApplicationModule(appModuleId); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while retrieving application module"); + } } /** * Update a Application Module. @@ -2193,25 +1289,12 @@ public ApplicationModule getApplicationModule(AuthzToken authzToken, String appM @SecurityCheck public boolean updateApplicationModule( AuthzToken authzToken, String appModuleId, ApplicationModule applicationModule) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - boolean result = airavataService.updateApplicationModule(appModuleId, applicationModule); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error(appModuleId, "Error while updating application module...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating application module. More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error(appModuleId, "Error while updating application module...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating application module. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.updateApplicationModule(appModuleId, applicationModule); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while updating application module"); + } } /** * Fetch all Application Module Descriptions. @@ -2222,23 +1305,11 @@ public boolean updateApplicationModule( @Override @SecurityCheck public List getAllAppModules(AuthzToken authzToken, String gatewayId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - List result = airavataService.getAllAppModules(gatewayId); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error("Error while retrieving all application modules...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving all application modules. More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error("Error while retrieving all application modules...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving all application modules. More info : " + e.getMessage()); - throw exception; + return airavataService.getAllAppModules(gatewayId); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while retrieving all application modules"); } } @@ -2251,28 +1322,11 @@ public List getAllAppModules(AuthzToken authzToken, String ga @Override @SecurityCheck public List getAccessibleAppModules(AuthzToken authzToken, String gatewayId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - List result = - airavataService.getAccessibleAppModulesWithSharing(sharingClient, authzToken, gatewayId); - sharingClientPool.returnResource(sharingClient); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error("Error while retrieving all application modules...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving all application modules. More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; - } catch (Exception e) { - logger.error("Error while retrieving all application modules...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving all application modules. More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + return airavataService.getAccessibleAppModulesWithSharing( authzToken, gatewayId); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while retrieving all application modules"); } } @@ -2286,25 +1340,12 @@ public List getAccessibleAppModules(AuthzToken authzToken, St @Override @SecurityCheck public boolean deleteApplicationModule(AuthzToken authzToken, String appModuleId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - boolean result = airavataService.deleteApplicationModule(appModuleId); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error(appModuleId, "Error while deleting application module...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while deleting the application module. More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error(appModuleId, "Error while deleting application module...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while deleting the application module. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.deleteApplicationModule(appModuleId); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while deleting application module"); + } } /** * Register a Application Deployment. @@ -2316,32 +1357,26 @@ public boolean deleteApplicationModule(AuthzToken authzToken, String appModuleId @SecurityCheck public String registerApplicationDeployment( AuthzToken authzToken, String gatewayId, ApplicationDeploymentDescription applicationDeployment) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { // TODO: verify that gatewayId matches authzToken gatewayId - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { String result = airavataService.registerApplicationDeployment(gatewayId, applicationDeployment); - Entity entity = new Entity(); - entity.setEntityId(result); - final String domainId = gatewayId; - entity.setDomainId(domainId); - entity.setEntityTypeId(domainId + ":" + ResourceType.APPLICATION_DEPLOYMENT.name()); - String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); - entity.setOwnerId(userName + "@" + domainId); - entity.setName(result); - entity.setDescription(applicationDeployment.getAppDeploymentDescription()); - sharingClient.createEntity(entity); - airavataService.shareEntityWithAdminGatewayGroups(sharingClient, entity); - sharingClientPool.returnResource(sharingClient); + if (ServerSettings.isEnableSharing()) { + Entity entity = new Entity(); + entity.setEntityId(result); + final String domainId = gatewayId; + entity.setDomainId(domainId); + entity.setEntityTypeId(domainId + ":" + ResourceType.APPLICATION_DEPLOYMENT.name()); + String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); + entity.setOwnerId(userName + "@" + domainId); + entity.setName(result); + entity.setDescription(applicationDeployment.getAppDeploymentDescription()); + airavataService.createEntity(entity); + airavataService.shareEntityWithAdminGatewayGroups( entity); + } return result; - } catch (Exception e) { - logger.error("Error while adding application deployment...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding application deployment. More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while adding application deployment"); } } @@ -2355,28 +1390,19 @@ public String registerApplicationDeployment( @Override @SecurityCheck public ApplicationDeploymentDescription getApplicationDeployment(AuthzToken authzToken, String appDeploymentId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { if (ServerSettings.isEnableSharing()) { - final boolean hasAccess = airavataService.userHasAccessInternal( - sharingClient, authzToken, appDeploymentId, ResourcePermissionType.READ); + final boolean hasAccess = airavataService.userHasAccessInternal( authzToken, appDeploymentId, ResourcePermissionType.READ); if (!hasAccess) { throw new AuthorizationException( "User does not have access to application deployment " + appDeploymentId); } } ApplicationDeploymentDescription result = airavataService.getApplicationDeployment(appDeploymentId); - sharingClientPool.returnResource(sharingClient); return result; - } catch (Exception e) { - logger.error(appDeploymentId, "Error while retrieving application deployment...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving application deployment. More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while retrieving application deployment"); } } @@ -2392,28 +1418,18 @@ public ApplicationDeploymentDescription getApplicationDeployment(AuthzToken auth @SecurityCheck public boolean updateApplicationDeployment( AuthzToken authzToken, String appDeploymentId, ApplicationDeploymentDescription applicationDeployment) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { if (ServerSettings.isEnableSharing()) { - final boolean hasAccess = airavataService.userHasAccessInternal( - sharingClient, authzToken, appDeploymentId, ResourcePermissionType.WRITE); + final boolean hasAccess = airavataService.userHasAccessInternal( authzToken, appDeploymentId, ResourcePermissionType.WRITE); if (!hasAccess) { throw new AuthorizationException( "User does not have WRITE access to application deployment " + appDeploymentId); } } - boolean result = airavataService.updateApplicationDeployment(appDeploymentId, applicationDeployment); - sharingClientPool.returnResource(sharingClient); - return result; - } catch (Exception e) { - logger.error(appDeploymentId, "Error while updating application deployment...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating application deployment. More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + return airavataService.updateApplicationDeployment(appDeploymentId, applicationDeployment); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while updating application deployment"); } } @@ -2427,28 +1443,16 @@ public boolean updateApplicationDeployment( @Override @SecurityCheck public boolean deleteApplicationDeployment(AuthzToken authzToken, String appDeploymentId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - final boolean hasAccess = airavataService.userHasAccessInternal( - sharingClient, authzToken, appDeploymentId, ResourcePermissionType.WRITE); + final boolean hasAccess = airavataService.userHasAccessInternal( authzToken, appDeploymentId, ResourcePermissionType.WRITE); if (!hasAccess) { throw new AuthorizationException( "User does not have WRITE access to application deployment " + appDeploymentId); } - final String domainId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - boolean result = airavataService.deleteApplicationDeployment(appDeploymentId); - sharingClient.deleteEntity(domainId, appDeploymentId); - sharingClientPool.returnResource(sharingClient); - return result; - } catch (Exception e) { - logger.error(appDeploymentId, "Error while deleting application deployment...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while deleting application deployment. More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + return airavataService.deleteApplicationDeployment(appDeploymentId); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while deleting application deployment"); } } @@ -2461,8 +1465,7 @@ public boolean deleteApplicationDeployment(AuthzToken authzToken, String appDepl @Override @SecurityCheck public List getAllApplicationDeployments(AuthzToken authzToken, String gatewayId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { return getAccessibleApplicationDeployments(authzToken, gatewayId, ResourcePermissionType.READ); } @@ -2476,29 +1479,11 @@ public List getAllApplicationDeployments(Authz @SecurityCheck public List getAccessibleApplicationDeployments( AuthzToken authzToken, String gatewayId, ResourcePermissionType permissionType) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - List result = - airavataService.getAccessibleApplicationDeploymentsWithSharing( - sharingClient, authzToken, gatewayId, permissionType); - sharingClientPool.returnResource(sharingClient); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error("Error while retrieving application deployments...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving application deployments. More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; - } catch (Exception e) { - logger.error("Error while retrieving application deployments...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving application deployments. More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + return airavataService.getAccessibleApplicationDeploymentsWithSharing( authzToken, gatewayId, permissionType); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while retrieving application deployments"); } } @@ -2513,24 +1498,11 @@ public List getAccessibleApplicationDeployment @SecurityCheck @Deprecated public List getAppModuleDeployedResources(AuthzToken authzToken, String appModuleId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - // TODO: restrict to only application deployments that are accessible to user - List result = airavataService.getAppModuleDeployedResources(appModuleId); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error(appModuleId, "Error while retrieving application deployments...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving application deployment. More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error(appModuleId, "Error while retrieving application deployments...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving application deployment. More info : " + e.getMessage()); - throw exception; + return airavataService.getAppModuleDeployedResources(appModuleId); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while retrieving application deployment"); } } @@ -2551,15 +1523,12 @@ public List getAppModuleDeployedResources(AuthzToken authzToken, String @SecurityCheck public List getApplicationDeploymentsForAppModuleAndGroupResourceProfile( AuthzToken authzToken, String appModuleId, String groupResourceProfileId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); try { // Get list of compute resources for this Group Resource Profile - if (!airavataService.userHasAccessInternal( - sharingClient, authzToken, groupResourceProfileId, ResourcePermissionType.READ)) { + if (!airavataService.userHasAccessInternal( authzToken, groupResourceProfileId, ResourcePermissionType.READ)) { throw new AuthorizationException( "User is not authorized to access Group Resource Profile " + groupResourceProfileId); } @@ -2581,33 +1550,13 @@ public List getApplicationDeploymentsForAppMod permissionTypeFilter.setSearchCondition(SearchCondition.EQUAL); permissionTypeFilter.setValue(gatewayId + ":" + ResourcePermissionType.READ); sharingFilters.add(permissionTypeFilter); - sharingClient - .searchEntities(gatewayId, userName + "@" + gatewayId, sharingFilters, 0, -1) + airavataService.searchEntities(gatewayId, userName + "@" + gatewayId, sharingFilters, 0, -1) .forEach(a -> accessibleAppDeploymentIds.add(a.getEntityId())); - List result = - airavataService.getAccessibleApplicationDeploymentsForAppModule( + return airavataService.getAccessibleApplicationDeploymentsForAppModule( appModuleId, gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); - sharingClientPool.returnResource(sharingClient); - return result; - } catch (AuthorizationException checkedException) { - logger.error("Error while retrieving application deployments...", checkedException); - sharingClientPool.returnResource(sharingClient); - throw checkedException; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error("Error while retrieving application deployments...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving application deployments. More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; - } catch (Exception e) { - logger.error("Error while retrieving application deployments...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving application deployments. More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while retrieving application deployments"); } } @@ -2621,29 +1570,20 @@ public List getApplicationDeploymentsForAppMod @SecurityCheck public String registerApplicationInterface( AuthzToken authzToken, String gatewayId, ApplicationInterfaceDescription applicationInterface) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - String result = airavataService.registerApplicationInterface(gatewayId, applicationInterface); - return result; - } catch (Exception e) { - logger.error("Error while adding application interface...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding application interface. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.registerApplicationInterface(gatewayId, applicationInterface); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while adding application interface"); + } } @Override @SecurityCheck public String cloneApplicationInterface( AuthzToken authzToken, String existingAppInterfaceID, String newApplicationName, String gatewayId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - ApplicationInterfaceDescription existingInterface = - airavataService.getApplicationInterface(existingAppInterfaceID); + ApplicationInterfaceDescription existingInterface = airavataService.getApplicationInterface(existingAppInterfaceID); if (existingInterface == null) { logger.error( "Provided application interface does not exist.Please provide a valid application interface id..."); @@ -2656,12 +1596,8 @@ public String cloneApplicationInterface( logger.debug("Airavata cloned application interface : " + existingAppInterfaceID + " for gateway id : " + gatewayId); return interfaceId; - } catch (Exception e) { - logger.error("Error while adding application interface...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding application interface. More info : " + e.getMessage()); - throw exception; + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Provided application interface does not exist.Please provide a valid application interface id..."); } } @@ -2675,19 +1611,13 @@ public String cloneApplicationInterface( @Override @SecurityCheck public ApplicationInterfaceDescription getApplicationInterface(AuthzToken authzToken, String appInterfaceId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - ApplicationInterfaceDescription result = airavataService.getApplicationInterface(appInterfaceId); - return result; - } catch (Exception e) { - logger.error(appInterfaceId, "Error while retrieving application interface...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving application interface. More info : " + e.getMessage()); - throw exception; - } - } + ApplicationInterfaceDescription existingInterface = airavataService.getApplicationInterface(appInterfaceId); + return existingInterface; + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while retrieving application interface"); + } } /** * Update a Application Interface. @@ -2701,19 +1631,12 @@ public ApplicationInterfaceDescription getApplicationInterface(AuthzToken authzT @SecurityCheck public boolean updateApplicationInterface( AuthzToken authzToken, String appInterfaceId, ApplicationInterfaceDescription applicationInterface) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - boolean result = airavataService.updateApplicationInterface(appInterfaceId, applicationInterface); - return result; - } catch (Exception e) { - logger.error(appInterfaceId, "Error while updating application interface...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating application interface. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.updateApplicationInterface(appInterfaceId, applicationInterface); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while updating application interface"); + } } /** * Delete a Application Interface. @@ -2725,19 +1648,12 @@ public boolean updateApplicationInterface( @Override @SecurityCheck public boolean deleteApplicationInterface(AuthzToken authzToken, String appInterfaceId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - boolean result = airavataService.deleteApplicationInterface(appInterfaceId); - return result; - } catch (Exception e) { - logger.error(appInterfaceId, "Error while deleting application interface...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while deleting application interface. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.deleteApplicationInterface(appInterfaceId); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while deleting application interface"); + } } /** * Fetch name and id of Application Interface documents. @@ -2748,17 +1664,11 @@ public boolean deleteApplicationInterface(AuthzToken authzToken, String appInter @Override @SecurityCheck public Map getAllApplicationInterfaceNames(AuthzToken authzToken, String gatewayId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - Map result = airavataService.getAllApplicationInterfaceNames(gatewayId); - return result; - } catch (Exception e) { - logger.error("Error while retrieving application interfaces...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving application interfaces. More info : " + e.getMessage()); - throw exception; + return airavataService.getAllApplicationInterfaceNames(gatewayId); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while retrieving application interfaces"); } } @@ -2771,17 +1681,11 @@ public Map getAllApplicationInterfaceNames(AuthzToken authzToken @Override @SecurityCheck public List getAllApplicationInterfaces(AuthzToken authzToken, String gatewayId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - List result = airavataService.getAllApplicationInterfaces(gatewayId); - return result; - } catch (Exception e) { - logger.error("Error while retrieving application interfaces...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving application interfaces. More info : " + e.getMessage()); - throw exception; + return airavataService.getAllApplicationInterfaces(gatewayId); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while retrieving application interfaces"); } } @@ -2795,17 +1699,11 @@ public List getAllApplicationInterfaces(AuthzTo @Override @SecurityCheck public List getApplicationInputs(AuthzToken authzToken, String appInterfaceId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - List result = airavataService.getApplicationInputs(appInterfaceId); - return result; - } catch (Exception e) { - logger.error(appInterfaceId, "Error while retrieving application inputs...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving application inputs. More info : " + e.getMessage()); - throw exception; + return airavataService.getApplicationInputs(appInterfaceId); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while retrieving application inputs"); } } @@ -2819,12 +1717,11 @@ public List getApplicationInputs(AuthzToken authzToken, Str @Override @SecurityCheck public List getApplicationOutputs(AuthzToken authzToken, String appInterfaceId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - List result = airavataService.getApplicationOutputs(appInterfaceId); - return result; - } catch (Exception e) { + List applicationOutputs = airavataService.getApplicationOutputs(appInterfaceId); + return applicationOutputs; + } catch (Throwable e) { AiravataSystemException exception = new AiravataSystemException(); exception.setMessage(e.getMessage()); throw exception; @@ -2843,23 +1740,11 @@ public List getApplicationOutputs(AuthzToken authzToken, S @SecurityCheck @Deprecated public Map getAvailableAppInterfaceComputeResources(AuthzToken authzToken, String appInterfaceId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - Map result = airavataService.getAvailableAppInterfaceComputeResources(appInterfaceId); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error(appInterfaceId, "Error while saving compute resource...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while saving compute resource. More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error(appInterfaceId, "Error while saving compute resource...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while saving compute resource. More info : " + e.getMessage()); - throw exception; + return airavataService.getAvailableAppInterfaceComputeResources(appInterfaceId); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while retrieving available compute resources"); } } @@ -2873,19 +1758,12 @@ public Map getAvailableAppInterfaceComputeResources(AuthzToken a @Override @SecurityCheck public String registerComputeResource(AuthzToken authzToken, ComputeResourceDescription computeResourceDescription) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - String result = airavataService.registerComputeResource(computeResourceDescription); - return result; - } catch (Exception e) { - logger.error("Error while saving compute resource...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while saving compute resource. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.registerComputeResource(computeResourceDescription); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while saving compute resource"); + } } /** * Fetch the given Compute Resource. @@ -2897,19 +1775,12 @@ public String registerComputeResource(AuthzToken authzToken, ComputeResourceDesc @Override @SecurityCheck public ComputeResourceDescription getComputeResource(AuthzToken authzToken, String computeResourceId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - ComputeResourceDescription result = airavataService.getComputeResource(computeResourceId); - return result; - } catch (Exception e) { - logger.error(computeResourceId, "Error while retrieving compute resource...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving compute resource. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.getComputeResource(computeResourceId); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while retrieving compute resource"); + } } /** * Fetch all registered Compute Resources. @@ -2920,19 +1791,12 @@ public ComputeResourceDescription getComputeResource(AuthzToken authzToken, Stri @Override @SecurityCheck public Map getAllComputeResourceNames(AuthzToken authzToken) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - Map result = airavataService.getAllComputeResourceNames(); - return result; - } catch (Exception e) { - logger.error("Error while retrieving compute resource...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving compute resource. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.getAllComputeResourceNames(); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while retrieving compute resource names"); + } } /** * Update a Compute Resource. @@ -2946,19 +1810,12 @@ public Map getAllComputeResourceNames(AuthzToken authzToken) @SecurityCheck public boolean updateComputeResource( AuthzToken authzToken, String computeResourceId, ComputeResourceDescription computeResourceDescription) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - boolean result = airavataService.updateComputeResource(computeResourceId, computeResourceDescription); - return result; - } catch (Exception e) { - logger.error(computeResourceId, "Error while updating compute resource...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updaing compute resource. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.updateComputeResource(computeResourceId, computeResourceDescription); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while updating compute resource"); + } } /** * Delete a Compute Resource. @@ -2970,19 +1827,12 @@ public boolean updateComputeResource( @Override @SecurityCheck public boolean deleteComputeResource(AuthzToken authzToken, String computeResourceId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - boolean result = airavataService.deleteComputeResource(computeResourceId); - return result; - } catch (Exception e) { - logger.error(computeResourceId, "Error while deleting compute resource...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while deleting compute resource. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.deleteComputeResource(computeResourceId); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while deleting compute resource"); + } } /** * Register a Storage Resource. @@ -2995,19 +1845,12 @@ public boolean deleteComputeResource(AuthzToken authzToken, String computeResour @Override @SecurityCheck public String registerStorageResource(AuthzToken authzToken, StorageResourceDescription storageResourceDescription) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - String result = airavataService.registerStorageResource(storageResourceDescription); - return result; - } catch (Exception e) { - logger.error("Error while saving storage resource...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while saving storage resource. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.registerStorageResource(storageResourceDescription); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while saving storage resource"); + } } /** * Fetch the given Storage Resource. @@ -3020,19 +1863,12 @@ public String registerStorageResource(AuthzToken authzToken, StorageResourceDesc @Override @SecurityCheck public StorageResourceDescription getStorageResource(AuthzToken authzToken, String storageResourceId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - StorageResourceDescription result = airavataService.getStorageResource(storageResourceId); - return result; - } catch (Exception e) { - logger.error(storageResourceId, "Error while retrieving storage resource...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving storage resource. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.getStorageResource(storageResourceId); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while retrieving storage resource"); + } } /** * Fetch all registered Storage Resources. @@ -3044,19 +1880,12 @@ public StorageResourceDescription getStorageResource(AuthzToken authzToken, Stri @Override @SecurityCheck public Map getAllStorageResourceNames(AuthzToken authzToken) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - Map result = airavataService.getAllStorageResourceNames(); - return result; - } catch (Exception e) { - logger.error("Error while retrieving storage resource...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving storage resource. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.getAllStorageResourceNames(); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while retrieving storage resource names"); + } } /** * Update a Compute Resource. @@ -3071,19 +1900,12 @@ public Map getAllStorageResourceNames(AuthzToken authzToken) @SecurityCheck public boolean updateStorageResource( AuthzToken authzToken, String storageResourceId, StorageResourceDescription storageResourceDescription) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - boolean result = airavataService.updateStorageResource(storageResourceId, storageResourceDescription); - return result; - } catch (Exception e) { - logger.error(storageResourceId, "Error while updating storage resource...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updaing storage resource. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.updateStorageResource(storageResourceId, storageResourceDescription); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while updating storage resource"); + } } /** * Delete a Storage Resource. @@ -3096,54 +1918,41 @@ public boolean updateStorageResource( @Override @SecurityCheck public boolean deleteStorageResource(AuthzToken authzToken, String storageResourceId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - boolean result = airavataService.deleteStorageResource(storageResourceId); - return result; - } catch (Exception e) { - logger.error(storageResourceId, "Error while deleting storage resource...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while deleting storage resource. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.deleteStorageResource(storageResourceId); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while deleting storage resource"); + } } @Override @SecurityCheck public StorageVolumeInfo getResourceStorageInfo(AuthzToken authzToken, String resourceId, String location) - throws TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - RegistryService.Client regClient = registryClientPool.getResource(); StorageInfoContext context; try { Optional computeResourceOp = Optional.empty(); try { - ComputeResourceDescription computeResource = regClient.getComputeResource(resourceId); + ComputeResourceDescription computeResource = airavataService.getComputeResource(resourceId); if (computeResource != null) { computeResourceOp = Optional.of(computeResource); } - } catch (TApplicationException e) { - // TApplicationException with "unknown result" means resource not found (null return for non-nullable - // type) - logger.debug("Compute resource {} not found (TApplicationException): {}", resourceId, e.getMessage()); + } catch (Throwable e) { + logger.debug("Compute resource {} not found: {}", resourceId, e.getMessage()); } Optional storageResourceOp = Optional.empty(); if (computeResourceOp.isEmpty()) { try { - StorageResourceDescription storageResource = regClient.getStorageResource(resourceId); + StorageResourceDescription storageResource = airavataService.getStorageResource(resourceId); if (storageResource != null) { storageResourceOp = Optional.of(storageResource); } - } catch (TApplicationException e) { - // TApplicationException with "unknown result" means resource not found (null return for - // non-nullable type) - logger.debug( - "Storage resource {} not found (TApplicationException): {}", resourceId, e.getMessage()); + } catch (Throwable e) { + logger.debug("Storage resource {} not found: {}", resourceId, e.getMessage()); } } @@ -3162,63 +1971,43 @@ public StorageVolumeInfo getResourceStorageInfo(AuthzToken authzToken, String re context = resolveStorageStorageInfoContext(authzToken, gatewayId, userId, resourceId); } - registryClientPool.returnResource(regClient); - regClient = null; - return context.adaptor.getStorageVolumeInfo(location); - - } catch (InvalidRequestException | AiravataClientException e) { - if (regClient != null) { - registryClientPool.returnResource(regClient); - } + } catch (InvalidRequestException e) { logger.error("Error while retrieving storage resource.", e); throw e; - - } catch (Exception e) { - logger.error("Error while retrieving storage volume info for resource {}", resourceId, e); - registryClientPool.returnBrokenResource(regClient); - - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving storage volume info. More info: " + e.getMessage()); - throw exception; + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while retrieving storage resource"); } } @Override @SecurityCheck public StorageDirectoryInfo getStorageDirectoryInfo(AuthzToken authzToken, String resourceId, String location) - throws TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - RegistryService.Client regClient = registryClientPool.getResource(); StorageInfoContext context; try { Optional computeResourceOp = Optional.empty(); try { - ComputeResourceDescription computeResource = regClient.getComputeResource(resourceId); + ComputeResourceDescription computeResource = airavataService.getComputeResource(resourceId); if (computeResource != null) { computeResourceOp = Optional.of(computeResource); } - } catch (TApplicationException e) { - // TApplicationException with "unknown result" means resource not found (null return for non-nullable - // type) - logger.debug("Compute resource {} not found (TApplicationException): {}", resourceId, e.getMessage()); + } catch (Throwable e) { + logger.debug("Compute resource {} not found: {}", resourceId, e.getMessage()); } Optional storageResourceOp = Optional.empty(); if (computeResourceOp.isEmpty()) { try { - StorageResourceDescription storageResource = regClient.getStorageResource(resourceId); + StorageResourceDescription storageResource = airavataService.getStorageResource(resourceId); if (storageResource != null) { storageResourceOp = Optional.of(storageResource); } - } catch (TApplicationException e) { - // TApplicationException with "unknown result" means resource not found (null return for - // non-nullable type) - logger.debug( - "Storage resource {} not found (TApplicationException): {}", resourceId, e.getMessage()); + } catch (Throwable e) { + logger.debug("Storage resource {} not found: {}", resourceId, e.getMessage()); } } @@ -3237,26 +2026,12 @@ public StorageDirectoryInfo getStorageDirectoryInfo(AuthzToken authzToken, Strin context = resolveStorageStorageInfoContext(authzToken, gatewayId, userId, resourceId); } - registryClientPool.returnResource(regClient); - regClient = null; - return context.adaptor.getStorageDirectoryInfo(location); - - } catch (InvalidRequestException | AiravataClientException e) { - if (regClient != null) { - registryClientPool.returnResource(regClient); - } + } catch (InvalidRequestException e) { logger.error("Error while retrieving storage resource.", e); throw e; - - } catch (Exception e) { - logger.error("Error while retrieving storage volume info for resource {}", resourceId, e); - registryClientPool.returnBrokenResource(regClient); - - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving storage volume info. More info: " + e.getMessage()); - throw exception; + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while retrieving storage directory info"); } } @@ -3273,37 +2048,12 @@ public StorageDirectoryInfo getStorageDirectoryInfo(AuthzToken authzToken, Strin @Override @SecurityCheck public String addLocalSubmissionDetails( - AuthzToken authzToken, String computeResourceId, int priorityOrder, LOCALSubmission localSubmission) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + AuthzToken authzToken, String computeResourceId, int priorityOrder, LOCALSubmission localSubmission){ try { - String result = - airavataService.addLocalSubmissionDetails(computeResourceId, priorityOrder, localSubmission); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error( - computeResourceId, - "Error while adding job submission interface to resource compute resource...", - e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while adding job submission interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error( - computeResourceId, - "Error while adding job submission interface to resource compute resource...", - e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while adding job submission interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; - } - } + return airavataService.addLocalSubmissionDetails(computeResourceId, priorityOrder, localSubmission); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while adding local job submission interface"); + } } /** * Update the given Local Job Submission details @@ -3317,60 +2067,22 @@ public String addLocalSubmissionDetails( @SecurityCheck public boolean updateLocalSubmissionDetails( AuthzToken authzToken, String jobSubmissionInterfaceId, LOCALSubmission localSubmission) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - boolean result = airavataService.updateLocalSubmissionDetails(jobSubmissionInterfaceId, localSubmission); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error( - jobSubmissionInterfaceId, - "Error while updating job submission interface to resource compute resource...", - e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while updating job submission interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error( - jobSubmissionInterfaceId, - "Error while updating job submission interface to resource compute resource...", - e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while updating job submission interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; - } - } + return airavataService.updateLocalSubmissionDetails(jobSubmissionInterfaceId, localSubmission); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while updating local job submission interface"); + } } @Override @SecurityCheck public LOCALSubmission getLocalJobSubmission(AuthzToken authzToken, String jobSubmissionId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - LOCALSubmission result = airavataService.getLocalJobSubmission(jobSubmissionId); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - String errorMsg = "Error while retrieving local job submission interface to resource compute resource..."; - logger.error(jobSubmissionId, errorMsg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(errorMsg + e.getMessage()); - throw exception; - } catch (Exception e) { - String errorMsg = "Error while retrieving local job submission interface to resource compute resource..."; - logger.error(jobSubmissionId, errorMsg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(errorMsg + e.getMessage()); - throw exception; - } - } + return airavataService.getLocalJobSubmission(jobSubmissionId); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while retrieving local job submission interface"); + } } /** * Add a SSH Job Submission details to a compute resource @@ -3386,36 +2098,12 @@ public LOCALSubmission getLocalJobSubmission(AuthzToken authzToken, String jobSu @SecurityCheck public String addSSHJobSubmissionDetails( AuthzToken authzToken, String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - String result = - airavataService.addSSHJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error( - computeResourceId, - "Error while adding job submission interface to resource compute resource...", - e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while adding job submission interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error( - computeResourceId, - "Error while adding job submission interface to resource compute resource...", - e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while adding job submission interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; - } - } + return airavataService.addSSHJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while adding SSH job submission interface"); + } } /** * Add a SSH_FORK Job Submission details to a compute resource @@ -3431,61 +2119,22 @@ public String addSSHJobSubmissionDetails( @SecurityCheck public String addSSHForkJobSubmissionDetails( AuthzToken authzToken, String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - String result = - airavataService.addSSHForkJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error( - computeResourceId, - "Error while adding job submission interface to resource compute resource...", - e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while adding job submission interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error( - computeResourceId, - "Error while adding job submission interface to resource compute resource...", - e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while adding job submission interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; - } - } + return airavataService.addSSHForkJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while adding SSH fork job submission interface"); + } } @Override @SecurityCheck public SSHJobSubmission getSSHJobSubmission(AuthzToken authzToken, String jobSubmissionId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - SSHJobSubmission result = airavataService.getSSHJobSubmission(jobSubmissionId); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - String errorMsg = "Error while retrieving SSH job submission interface to resource compute resource..."; - logger.error(jobSubmissionId, errorMsg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(errorMsg + e.getMessage()); - throw exception; - } catch (Exception e) { - String errorMsg = "Error while retrieving SSH job submission interface to resource compute resource..."; - logger.error(jobSubmissionId, errorMsg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(errorMsg + e.getMessage()); - throw exception; - } - } + return airavataService.getSSHJobSubmission(jobSubmissionId); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while retrieving SSH job submission interface"); + } } /** * Add a Cloud Job Submission details to a compute resource @@ -3501,59 +2150,27 @@ public SSHJobSubmission getSSHJobSubmission(AuthzToken authzToken, String jobSub @SecurityCheck public String addCloudJobSubmissionDetails( AuthzToken authzToken, String computeResourceId, int priorityOrder, CloudJobSubmission cloudJobSubmission) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - String result = - airavataService.addCloudJobSubmissionDetails(computeResourceId, priorityOrder, cloudJobSubmission); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error( - computeResourceId, - "Error while adding job submission interface to resource compute resource...", - e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while adding job submission interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error( - computeResourceId, - "Error while adding job submission interface to resource compute resource...", - e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while adding job submission interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; - } - } + return airavataService.addCloudJobSubmissionDetails(computeResourceId, priorityOrder, cloudJobSubmission); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while adding cloud job submission interface"); + } } @Override @SecurityCheck public CloudJobSubmission getCloudJobSubmission(AuthzToken authzToken, String jobSubmissionId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - CloudJobSubmission result = airavataService.getCloudJobSubmission(jobSubmissionId); - return result; + return airavataService.getCloudJobSubmission(jobSubmissionId); } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { String errorMsg = "Error while retrieving Cloud job submission interface to resource compute resource..."; logger.error(jobSubmissionId, errorMsg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(errorMsg + e.getMessage()); - throw exception; - } catch (Exception e) { + throw ThriftExceptionHandler.convertException(e, "Error occurred"); + } catch (Throwable e) { String errorMsg = "Error while retrieving Cloud job submission interface to resource compute resource..."; logger.error(jobSubmissionId, errorMsg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(errorMsg + e.getMessage()); - throw exception; + throw ThriftExceptionHandler.convertException(e, "Error occurred"); } } @@ -3564,53 +2181,33 @@ public String addUNICOREJobSubmissionDetails( String computeResourceId, int priorityOrder, UnicoreJobSubmission unicoreJobSubmission) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - String result = airavataService.addUNICOREJobSubmissionDetails( + return airavataService.addUNICOREJobSubmissionDetails( computeResourceId, priorityOrder, unicoreJobSubmission); - return result; } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { logger.error("Error while adding job submission interface to resource compute resource...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while adding job submission interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; - } catch (Exception e) { + throw ThriftExceptionHandler.convertException(e, "Error occurred"); + } catch (Throwable e) { logger.error("Error while adding job submission interface to resource compute resource...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while adding job submission interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; + throw ThriftExceptionHandler.convertException(e, "Error occurred"); } } @Override @SecurityCheck public UnicoreJobSubmission getUnicoreJobSubmission(AuthzToken authzToken, String jobSubmissionId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - UnicoreJobSubmission result = airavataService.getUnicoreJobSubmission(jobSubmissionId); - return result; + return airavataService.getUnicoreJobSubmission(jobSubmissionId); } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { String errorMsg = "Error while retrieving Unicore job submission interface to resource compute resource..."; logger.error(jobSubmissionId, errorMsg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(errorMsg + e.getMessage()); - throw exception; - } catch (Exception e) { + throw ThriftExceptionHandler.convertException(e, "Error occurred"); + } catch (Throwable e) { String errorMsg = "Error while retrieving Unicore job submission interface to resource compute resource..."; logger.error(jobSubmissionId, errorMsg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(errorMsg + e.getMessage()); - throw exception; + throw ThriftExceptionHandler.convertException(e, "Error occurred"); } } @@ -3626,33 +2223,21 @@ public UnicoreJobSubmission getUnicoreJobSubmission(AuthzToken authzToken, Strin @SecurityCheck public boolean updateSSHJobSubmissionDetails( AuthzToken authzToken, String jobSubmissionInterfaceId, SSHJobSubmission sshJobSubmission) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - boolean result = airavataService.updateSSHJobSubmissionDetails(jobSubmissionInterfaceId, sshJobSubmission); - return result; + return airavataService.updateSSHJobSubmissionDetails(jobSubmissionInterfaceId, sshJobSubmission); } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { logger.error( jobSubmissionInterfaceId, "Error while updating job submission interface to resource compute resource...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while updating job submission interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; - } catch (Exception e) { + throw ThriftExceptionHandler.convertException(e, "Error occurred"); + } catch (Throwable e) { logger.error( jobSubmissionInterfaceId, "Error while updating job submission interface to resource compute resource...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while updating job submission interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; + throw ThriftExceptionHandler.convertException(e, "Error occurred"); } } @@ -3668,34 +2253,21 @@ public boolean updateSSHJobSubmissionDetails( @SecurityCheck public boolean updateCloudJobSubmissionDetails( AuthzToken authzToken, String jobSubmissionInterfaceId, CloudJobSubmission cloudJobSubmission) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - boolean result = - airavataService.updateCloudJobSubmissionDetails(jobSubmissionInterfaceId, cloudJobSubmission); - return result; + return airavataService.updateCloudJobSubmissionDetails(jobSubmissionInterfaceId, cloudJobSubmission); } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { logger.error( jobSubmissionInterfaceId, "Error while updating job submission interface to resource compute resource...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while updating job submission interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; - } catch (Exception e) { + throw ThriftExceptionHandler.convertException(e, "Error occurred"); + } catch (Throwable e) { logger.error( jobSubmissionInterfaceId, "Error while updating job submission interface to resource compute resource...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while updating job submission interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; + throw ThriftExceptionHandler.convertException(e, "Error occurred"); } } @@ -3703,34 +2275,21 @@ public boolean updateCloudJobSubmissionDetails( @SecurityCheck public boolean updateUnicoreJobSubmissionDetails( AuthzToken authzToken, String jobSubmissionInterfaceId, UnicoreJobSubmission unicoreJobSubmission) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - boolean result = - airavataService.updateUnicoreJobSubmissionDetails(jobSubmissionInterfaceId, unicoreJobSubmission); - return result; + return airavataService.updateUnicoreJobSubmissionDetails(jobSubmissionInterfaceId, unicoreJobSubmission); } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { logger.error( jobSubmissionInterfaceId, "Error while updating job submission interface to resource compute resource...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while updating job submission interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; - } catch (Exception e) { + throw ThriftExceptionHandler.convertException(e, "Error occurred"); + } catch (Throwable e) { logger.error( jobSubmissionInterfaceId, "Error while updating job submission interface to resource compute resource...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while updating job submission interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; + throw ThriftExceptionHandler.convertException(e, "Error occurred"); } } @@ -3752,28 +2311,12 @@ public String addLocalDataMovementDetails( DMType dmType, int priorityOrder, LOCALDataMovement localDataMovement) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - String result = - airavataService.addLocalDataMovementDetails(resourceId, dmType, priorityOrder, localDataMovement); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error(resourceId, "Error while adding data movement interface to resource resource...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while adding data movement interface to resource. More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error(resourceId, "Error while adding data movement interface to resource resource...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while adding data movement interface to resource. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.addLocalDataMovementDetails(resourceId, dmType, priorityOrder, localDataMovement); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while adding data movement interface to resource"); + } } /** * Update the given Local data movement details @@ -3787,50 +2330,12 @@ public String addLocalDataMovementDetails( @SecurityCheck public boolean updateLocalDataMovementDetails( AuthzToken authzToken, String dataMovementInterfaceId, LOCALDataMovement localDataMovement) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - boolean result = airavataService.updateLocalDataMovementDetails(dataMovementInterfaceId, localDataMovement); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error(dataMovementInterfaceId, "Error while updating local data movement interface..", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating local data movement interface. More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error(dataMovementInterfaceId, "Error while updating local data movement interface..", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating local data movement interface. More info : " + e.getMessage()); - throw exception; - } - } - - @Override - @SecurityCheck - public LOCALDataMovement getLocalDataMovement(AuthzToken authzToken, String dataMovementId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - try { - LOCALDataMovement result = airavataService.getLocalDataMovement(dataMovementId); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - String errorMsg = "Error while retrieving local data movement interface to resource compute resource..."; - logger.error(dataMovementId, errorMsg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(errorMsg + e.getMessage()); - throw exception; - } catch (Exception e) { - String errorMsg = "Error while retrieving local data movement interface to resource compute resource..."; - logger.error(dataMovementId, errorMsg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(errorMsg + e.getMessage()); - throw exception; - } - } + return airavataService.updateLocalDataMovementDetails(dataMovementInterfaceId, localDataMovement); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while updating local data movement interface"); + } } /** * Add a SCP data moevement details to a compute resource @@ -3846,26 +2351,11 @@ public LOCALDataMovement getLocalDataMovement(AuthzToken authzToken, String data @SecurityCheck public String addSCPDataMovementDetails( AuthzToken authzToken, String resourceId, DMType dmType, int priorityOrder, SCPDataMovement scpDataMovement) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - String result = - airavataService.addSCPDataMovementDetails(resourceId, dmType, priorityOrder, scpDataMovement); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error(resourceId, "Error while adding data movement interface to resource compute resource...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding data movement interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error(resourceId, "Error while adding data movement interface to resource compute resource...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding data movement interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; + return airavataService.addSCPDataMovementDetails(resourceId, dmType, priorityOrder, scpDataMovement); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while adding SCP data movement interface"); } } @@ -3882,58 +2372,22 @@ public String addSCPDataMovementDetails( @SecurityCheck public boolean updateSCPDataMovementDetails( AuthzToken authzToken, String dataMovementInterfaceId, SCPDataMovement scpDataMovement) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - boolean result = airavataService.updateSCPDataMovementDetails(dataMovementInterfaceId, scpDataMovement); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error( - dataMovementInterfaceId, - "Error while updating data movement interface to resource compute resource...", - e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while updating data movement interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error( - dataMovementInterfaceId, - "Error while updating data movement interface to resource compute resource...", - e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while updating data movement interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; + return airavataService.updateSCPDataMovementDetails(dataMovementInterfaceId, scpDataMovement); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while updating SCP data movement interface"); } } @Override @SecurityCheck public SCPDataMovement getSCPDataMovement(AuthzToken authzToken, String dataMovementId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - SCPDataMovement result = airavataService.getSCPDataMovement(dataMovementId); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - String errorMsg = "Error while retrieving SCP data movement interface to resource compute resource..."; - logger.error(dataMovementId, errorMsg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(errorMsg + e.getMessage()); - throw exception; - } catch (Exception e) { - String errorMsg = "Error while retrieving SCP data movement interface to resource compute resource..."; - logger.error(dataMovementId, errorMsg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(errorMsg + e.getMessage()); - throw exception; + return airavataService.getSCPDataMovement(dataMovementId); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while retrieving SCP data movement interface"); } } @@ -3945,26 +2399,11 @@ public String addUnicoreDataMovementDetails( DMType dmType, int priorityOrder, UnicoreDataMovement unicoreDataMovement) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - String result = airavataService.addUnicoreDataMovementDetails( - resourceId, dmType, priorityOrder, unicoreDataMovement); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error(resourceId, "Error while adding data movement interface to resource compute resource...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding data movement interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error(resourceId, "Error while adding data movement interface to resource compute resource...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding data movement interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; + return airavataService.addUnicoreDataMovementDetails(resourceId, dmType, priorityOrder, unicoreDataMovement); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while adding UNICORE data movement interface"); } } @@ -3972,53 +2411,33 @@ public String addUnicoreDataMovementDetails( @SecurityCheck public boolean updateUnicoreDataMovementDetails( AuthzToken authzToken, String dataMovementInterfaceId, UnicoreDataMovement unicoreDataMovement) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - boolean result = - airavataService.updateUnicoreDataMovementDetails(dataMovementInterfaceId, unicoreDataMovement); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error( - dataMovementInterfaceId, "Error while updating unicore data movement to compute resource...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while updating unicore data movement to compute resource. More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error( - dataMovementInterfaceId, "Error while updating unicore data movement to compute resource...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while updating unicore data movement to compute resource. More info : " + e.getMessage()); - throw exception; + return airavataService.updateUnicoreDataMovementDetails(dataMovementInterfaceId, unicoreDataMovement); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while updating unicore data movement interface"); + } + } + + @Override + @SecurityCheck + public LOCALDataMovement getLocalDataMovement(AuthzToken authzToken, String dataMovementId) + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + try { + return airavataService.getLocalDataMovement(dataMovementId); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while retrieving local data movement interface"); } } @Override @SecurityCheck public UnicoreDataMovement getUnicoreDataMovement(AuthzToken authzToken, String dataMovementId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - UnicoreDataMovement result = airavataService.getUnicoreDataMovement(dataMovementId); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - String errorMsg = "Error while retrieving UNICORE data movement interface..."; - logger.error(dataMovementId, errorMsg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(errorMsg + e.getMessage()); - throw exception; - } catch (Exception e) { - String errorMsg = "Error while retrieving UNICORE data movement interface..."; - logger.error(dataMovementId, errorMsg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(errorMsg + e.getMessage()); - throw exception; + return airavataService.getUnicoreDataMovement(dataMovementId); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while retrieving UNICORE data movement interface"); } } @@ -4040,28 +2459,11 @@ public String addGridFTPDataMovementDetails( DMType dmType, int priorityOrder, GridFTPDataMovement gridFTPDataMovement) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - String result = airavataService.addGridFTPDataMovementDetails( - computeResourceId, dmType, priorityOrder, gridFTPDataMovement); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error( - computeResourceId, "Error while adding data movement interface to resource compute resource...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding data movement interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error( - computeResourceId, "Error while adding data movement interface to resource compute resource...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding data movement interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; + return airavataService.addGridFTPDataMovementDetails(computeResourceId, dmType, priorityOrder, gridFTPDataMovement); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while adding GridFTP data movement interface"); } } @@ -4078,59 +2480,28 @@ public String addGridFTPDataMovementDetails( @SecurityCheck public boolean updateGridFTPDataMovementDetails( AuthzToken authzToken, String dataMovementInterfaceId, GridFTPDataMovement gridFTPDataMovement) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - boolean result = - airavataService.updateGridFTPDataMovementDetails(dataMovementInterfaceId, gridFTPDataMovement); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error( - dataMovementInterfaceId, - "Error while updating GridFTP data movement interface to resource compute resource...", - e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while updating GridFTP data movement interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error( - dataMovementInterfaceId, - "Error while updating GridFTP data movement interface to resource compute resource...", - e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while updating GridFTP data movement interface to resource compute resource. More info : " - + e.getMessage()); - throw exception; + return airavataService.updateGridFTPDataMovementDetails(dataMovementInterfaceId, gridFTPDataMovement); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while updating GridFTP data movement interface"); } } @Override @SecurityCheck public GridFTPDataMovement getGridFTPDataMovement(AuthzToken authzToken, String dataMovementId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - GridFTPDataMovement result = airavataService.getGridFTPDataMovement(dataMovementId); - return result; + return airavataService.getGridFTPDataMovement(dataMovementId); } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { String errorMsg = "Error while retrieving GridFTP data movement interface to resource compute resource..."; logger.error(dataMovementId, errorMsg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(errorMsg + e.getMessage()); - throw exception; - } catch (Exception e) { + throw ThriftExceptionHandler.convertException(e, "Error occurred"); + } catch (Throwable e) { String errorMsg = "Error while retrieving GridFTP data movement interface to resource compute resource..."; logger.error(dataMovementId, errorMsg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(errorMsg + e.getMessage()); - throw exception; + throw ThriftExceptionHandler.convertException(e, "Error occurred"); } } @@ -4146,8 +2517,7 @@ public GridFTPDataMovement getGridFTPDataMovement(AuthzToken authzToken, String @SecurityCheck public boolean changeJobSubmissionPriority( AuthzToken authzToken, String jobSubmissionInterfaceId, int newPriorityOrder) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { return false; } @@ -4163,8 +2533,7 @@ public boolean changeJobSubmissionPriority( @SecurityCheck public boolean changeDataMovementPriority( AuthzToken authzToken, String dataMovementInterfaceId, int newPriorityOrder) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { return false; } @@ -4178,8 +2547,7 @@ public boolean changeDataMovementPriority( @Override @SecurityCheck public boolean changeJobSubmissionPriorities(AuthzToken authzToken, Map jobSubmissionPriorityMap) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { return false; } @@ -4193,8 +2561,7 @@ public boolean changeJobSubmissionPriorities(AuthzToken authzToken, Map dataMovementPriorityMap) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { return false; } @@ -4209,25 +2576,12 @@ public boolean changeDataMovementPriorities(AuthzToken authzToken, Map getAllGatewayComputeResourcePreferences( AuthzToken authzToken, String gatewayID) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - List result = airavataService.getAllGatewayComputeResourcePreferences(gatewayID); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error(gatewayID, "Error while reading gateway compute resource preferences...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while reading gateway compute resource preferences. More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error(gatewayID, "Error while reading gateway compute resource preferences...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while reading gateway compute resource preferences. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.getAllGatewayComputeResourcePreferences(gatewayID); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while reading gateway compute resource preferences"); + } } @Override @SecurityCheck public List getAllGatewayStoragePreferences(AuthzToken authzToken, String gatewayID) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - List result = airavataService.getAllGatewayStoragePreferences(gatewayID); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error(gatewayID, "Error while reading gateway data storage preferences...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while reading gateway data storage preferences. More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error(gatewayID, "Error while reading gateway data storage preferences...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while reading gateway data storage preferences. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.getAllGatewayStoragePreferences(gatewayID); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while reading gateway data storage preferences"); + } } @Override @SecurityCheck public List getAllGatewayResourceProfiles(AuthzToken authzToken) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - List result = airavataService.getAllGatewayResourceProfiles(); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while reading retrieving all gateway profiles. More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while reading retrieving all gateway profiles. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.getAllGatewayResourceProfiles(); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while retrieving all gateway profiles"); + } } /** * Update a Compute Resource Preference to a registered gateway profile. @@ -4696,53 +2842,23 @@ public boolean updateGatewayComputeResourcePreference( String gatewayID, String computeResourceId, ComputeResourcePreference computeResourcePreference) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - boolean result = airavataService.updateGatewayComputeResourcePreference( - gatewayID, computeResourceId, computeResourcePreference); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error(gatewayID, "Error while updating gateway compute resource preference...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while updating gateway compute resource preference. More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error(gatewayID, "Error while updating gateway compute resource preference...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while updating gateway compute resource preference. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.updateGatewayComputeResourcePreference(gatewayID, computeResourceId, computeResourcePreference); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while updating gateway compute resource preference"); + } } @Override @SecurityCheck public boolean updateGatewayStoragePreference( AuthzToken authzToken, String gatewayID, String storageId, StoragePreference dataStoragePreference) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - boolean result = - airavataService.updateGatewayStoragePreference(gatewayID, storageId, dataStoragePreference); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error(gatewayID, "Error while updating gateway data storage preference...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating gateway data storage preference. More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error(gatewayID, "Error while updating gateway data storage preference...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating gateway data storage preference. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.updateGatewayStoragePreference(gatewayID, storageId, dataStoragePreference); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while updating gateway data storage preference"); + } } /** * Delete the Compute Resource Preference of a registered gateway profile. @@ -4756,56 +2872,32 @@ public boolean updateGatewayStoragePreference( @SecurityCheck public boolean deleteGatewayComputeResourcePreference( AuthzToken authzToken, String gatewayID, String computeResourceId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - boolean result = airavataService.deleteGatewayComputeResourcePreference(gatewayID, computeResourceId); - return result; + return airavataService.deleteGatewayComputeResourcePreference(gatewayID, computeResourceId); } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { logger.error(gatewayID, "Error while deleting gateway compute resource preference...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while deleting gateway compute resource preference. More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { + throw ThriftExceptionHandler.convertException(e, "Error occurred"); + } catch (Throwable e) { logger.error(gatewayID, "Error while deleting gateway compute resource preference...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while deleting gateway compute resource preference. More info : " + e.getMessage()); - throw exception; + throw ThriftExceptionHandler.convertException(e, "Error occurred"); } } @Override @SecurityCheck public boolean deleteGatewayStoragePreference(AuthzToken authzToken, String gatewayID, String storageId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - boolean result = airavataService.deleteGatewayStoragePreference(gatewayID, storageId); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error(gatewayID, "Error while deleting gateway data storage preference...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while deleting gateway data storage preference. More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error(gatewayID, "Error while deleting gateway data storage preference...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while deleting gateway data storage preference. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.deleteGatewayStoragePreference(gatewayID, storageId); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while deleting gateway data storage preference"); + } } @Override @SecurityCheck public List getSSHAccountProvisioners(AuthzToken authzToken) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { List sshAccountProvisioners = new ArrayList<>(); List sshAccountProvisionerProviders = @@ -4843,19 +2935,12 @@ public List getSSHAccountProvisioners(AuthzToken authzTok @Override @SecurityCheck public boolean doesUserHaveSSHAccount(AuthzToken authzToken, String computeResourceId, String userId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); return SSHAccountManager.doesUserHaveSSHAccount(gatewayId, computeResourceId, userId); - } catch (Exception e) { - String errorMessage = "Error occurred while checking if [" + userId + "] has an SSH Account on [" - + computeResourceId + "]."; - logger.error(errorMessage, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(errorMessage + " More info : " + e.getMessage()); - throw exception; + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error occurred while checking if user has an SSH Account"); } } @@ -4863,34 +2948,20 @@ public boolean doesUserHaveSSHAccount(AuthzToken authzToken, String computeResou @SecurityCheck public boolean isSSHSetupCompleteForUserComputeResourcePreference( AuthzToken authzToken, String computeResourceId, String airavataCredStoreToken) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - CredentialStoreService.Client csClient = csClientPool.getResource(); SSHCredential sshCredential = null; try { - sshCredential = csClient.getSSHCredential(airavataCredStoreToken, gatewayId); - csClientPool.returnResource(csClient); - } catch (Exception e) { - logger.error("Error occurred while retrieving SSH Credential", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while retrieving SSH Credential. More info : " + e.getMessage()); - csClientPool.returnBrokenResource(csClient); - throw exception; + sshCredential = airavataService.getSSHCredential(airavataCredStoreToken, gatewayId);; + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error occurred while retrieving SSH Credential"); } try { return SSHAccountManager.isSSHAccountSetupComplete(gatewayId, computeResourceId, userId, sshCredential); - } catch (Exception e) { - final String msg = - "Error occurred while checking if setup of SSH account is complete for user [" + userId + "]."; - logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error occurred while checking if setup of SSH account is complete"); } } @@ -4898,34 +2969,20 @@ public boolean isSSHSetupCompleteForUserComputeResourcePreference( @SecurityCheck public UserComputeResourcePreference setupUserComputeResourcePreferencesForSSH( AuthzToken authzToken, String computeResourceId, String userId, String airavataCredStoreToken) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - CredentialStoreService.Client csClient = csClientPool.getResource(); SSHCredential sshCredential = null; try { - sshCredential = csClient.getSSHCredential(airavataCredStoreToken, gatewayId); - csClientPool.returnResource(csClient); - } catch (Exception e) { - logger.error("Error occurred while retrieving SSH Credential", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while retrieving SSH Credential. More info : " + e.getMessage()); - csClientPool.returnBrokenResource(csClient); - throw exception; + try { + sshCredential = airavataService.getSSHCredential(airavataCredStoreToken, gatewayId);; + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error occurred while retrieving SSH Credential"); } - - try { - UserComputeResourcePreference userComputeResourcePreference = - SSHAccountManager.setupSSHAccount(gatewayId, computeResourceId, userId, sshCredential); - return userComputeResourcePreference; - } catch (Exception e) { - logger.error("Error occurred while automatically setting up SSH account for user [" + userId + "]", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while automatically setting up SSH account for user [" + userId - + "]. More info : " + e.getMessage()); - throw exception; + + return SSHAccountManager.setupSSHAccount(gatewayId, computeResourceId, userId, sshCredential); + } catch (Throwable e) { + + throw ThriftExceptionHandler.convertException(e, "Error occurred while automatically setting up SSH account for user"); } } @@ -4941,50 +2998,22 @@ public UserComputeResourcePreference setupUserComputeResourcePreferencesForSSH( @Override @SecurityCheck public String registerUserResourceProfile(AuthzToken authzToken, UserResourceProfile userResourceProfile) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - String result = airavataService.registerUserResourceProfile(userResourceProfile); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error("Error while registering user resource profile...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while registering user resource profile. More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error("Error while registering user resource profile...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while registering user resource profile. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.registerUserResourceProfile(userResourceProfile); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while registering user resource profile"); + } } @Override @SecurityCheck public boolean isUserResourceProfileExists(AuthzToken authzToken, String userId, String gatewayID) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - boolean result = airavataService.isUserResourceProfileExists(userId, gatewayID); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error("Error while checking existence of user resource profile for " + userId, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while checking existence of user resource profile. More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error("Error while checking existence of user resource profile for " + userId, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while checking existence of user resource profile. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.isUserResourceProfileExists(userId, gatewayID); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while checking existence of user resource profile"); + } } /** * Fetch the given User Resource Profile. @@ -4995,23 +3024,16 @@ public boolean isUserResourceProfileExists(AuthzToken authzToken, String userId, * * @return userResourceProfile * User Resource Profile Object. - */ - @Override - @SecurityCheck - public UserResourceProfile getUserResourceProfile(AuthzToken authzToken, String userId, String gatewayID) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - try { - UserResourceProfile result = airavataService.getUserResourceProfile(userId, gatewayID); - return result; - } catch (Exception e) { - logger.error("Error while retrieving user resource profile for " + userId, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving user resource profile. More info : " + e.getMessage()); - throw exception; - } - } + */ + @Override + @SecurityCheck + public UserResourceProfile getUserResourceProfile(AuthzToken authzToken, String userId, String gatewayID) + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + try { + return airavataService.getUserResourceProfile(userId, gatewayID); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while retrieving user resource profile"); + } } /** * Update a User Resource Profile. @@ -5026,18 +3048,12 @@ public UserResourceProfile getUserResourceProfile(AuthzToken authzToken, String @SecurityCheck public boolean updateUserResourceProfile( AuthzToken authzToken, String userId, String gatewayID, UserResourceProfile userResourceProfile) - throws TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - boolean result = airavataService.updateUserResourceProfile(userId, gatewayID, userResourceProfile); - return result; - } catch (Exception e) { - logger.error(userId, "Error while updating user resource profile...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating user resource profile. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.updateUserResourceProfile(userId, gatewayID, userResourceProfile); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while updating user resource profile"); + } } /** * Delete the given User Resource Profile. @@ -5049,18 +3065,13 @@ public boolean updateUserResourceProfile( */ @Override @SecurityCheck - public boolean deleteUserResourceProfile(AuthzToken authzToken, String userId, String gatewayID) throws TException { + public boolean deleteUserResourceProfile(AuthzToken authzToken, String userId, String gatewayID) + throws AiravataClientException, AiravataSystemException, AuthorizationException, InvalidRequestException { try { - boolean result = airavataService.deleteUserResourceProfile(userId, gatewayID); - return result; - } catch (Exception e) { - logger.error(userId, "Error while removing user resource profile...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while removing user resource profile. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.deleteUserResourceProfile(userId, gatewayID); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while removing user resource profile"); + } } /** * Add a Compute Resource Preference to a registered User Resource profile. @@ -5081,26 +3092,16 @@ public boolean addUserComputeResourcePreference( String gatewayID, String userComputeResourceId, UserComputeResourcePreference userComputeResourcePreference) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - boolean result = airavataService.addUserComputeResourcePreference( + return airavataService.addUserComputeResourcePreference( userId, gatewayID, userComputeResourceId, userComputeResourcePreference); - return result; } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { logger.error(userId, "Error while registering user resource profile preference...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while registering user resource profile preference. More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { + throw ThriftExceptionHandler.convertException(e, "Error occurred"); + } catch (Throwable e) { logger.error(userId, "Error while registering user resource profile preference...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while registering user resource profile preference. More info : " + e.getMessage()); - throw exception; + throw ThriftExceptionHandler.convertException(e, "Error occurred"); } } @@ -5112,26 +3113,12 @@ public boolean addUserStoragePreference( String gatewayID, String userStorageResourceId, UserStoragePreference dataStoragePreference) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - boolean result = airavataService.addUserStoragePreference( - userId, gatewayID, userStorageResourceId, dataStoragePreference); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error(userId, "Error while registering user storage preference...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while registering user storage preference. More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error(userId, "Error while registering user storage preference...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while registering user storage preference. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.addUserStoragePreference(userId, gatewayID, userStorageResourceId, dataStoragePreference); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while registering user storage preference"); + } } /** * Fetch a Compute Resource Preference of a registered User Resource profile. @@ -5146,50 +3133,23 @@ public boolean addUserStoragePreference( @SecurityCheck public UserComputeResourcePreference getUserComputeResourcePreference( AuthzToken authzToken, String userId, String gatewayID, String userComputeResourceId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - UserComputeResourcePreference result = - airavataService.getUserComputeResourcePreference(userId, gatewayID, userComputeResourceId); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error(userId, "Error while reading user compute resource preference...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while reading user compute resource preference. More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error(userId, "Error while reading user compute resource preference...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while reading user compute resource preference. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.getUserComputeResourcePreference(userId, gatewayID, userComputeResourceId); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while reading user compute resource preference"); + } } @Override @SecurityCheck public UserStoragePreference getUserStoragePreference( AuthzToken authzToken, String userId, String gatewayID, String userStorageId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - UserStoragePreference result = airavataService.getUserStoragePreference(userId, gatewayID, userStorageId); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error(userId, "Error while reading user data storage preference...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while reading user data storage preference. More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error(userId, "Error while reading user data storage preference...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while reading user data storage preference. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.getUserStoragePreference(userId, gatewayID, userStorageId); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while reading user data storage preference"); + } } /** * Fetch all User Compute Resource Preferences of a registered gateway profile. @@ -5203,68 +3163,37 @@ public UserStoragePreference getUserStoragePreference( @SecurityCheck public List getAllUserComputeResourcePreferences( AuthzToken authzToken, String userId, String gatewayID) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - List result = - airavataService.getAllUserComputeResourcePreferences(userId, gatewayID); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error(userId, "Error while reading User compute resource preferences...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while reading User compute resource preferences. More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error(userId, "Error while reading User compute resource preferences...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while reading User compute resource preferences. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.getAllUserComputeResourcePreferences(userId, gatewayID); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while reading User compute resource preferences"); + } } @Override @SecurityCheck public List getAllUserStoragePreferences( AuthzToken authzToken, String userId, String gatewayID) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - List result = airavataService.getAllUserStoragePreferences(userId, gatewayID); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error(userId, "Error while reading User data storage preferences...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while reading User data storage preferences. More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error(userId, "Error while reading User data storage preferences...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while reading User data storage preferences. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.getAllUserStoragePreferences(userId, gatewayID); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while reading User data storage preferences"); + } } @Override @SecurityCheck public List getAllUserResourceProfiles(AuthzToken authzToken) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - List result = airavataService.getAllUserResourceProfiles(); - return result; + return airavataService.getAllUserResourceProfiles(); } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage( "Error while reading retrieving all user resource profiles. More info : " + e.getMessage()); throw exception; - } catch (Exception e) { + } catch (Throwable e) { AiravataSystemException exception = new AiravataSystemException(); exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage( @@ -5291,28 +3220,12 @@ public boolean updateUserComputeResourcePreference( String gatewayID, String userComputeResourceId, UserComputeResourcePreference userComputeResourcePreference) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - boolean result = airavataService.updateUserComputeResourcePreference( - userId, gatewayID, userComputeResourceId, userComputeResourcePreference); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error(userId, "Error while updating user compute resource preference...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while updating user compute resource preference. More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error(userId, "Error while updating user compute resource preference...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while updating user compute resource preference. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.updateUserComputeResourcePreference(userId, gatewayID, userComputeResourceId, userComputeResourcePreference); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while updating user compute resource preference"); + } } @Override @SecurityCheck @@ -5322,26 +3235,12 @@ public boolean updateUserStoragePreference( String gatewayID, String userStorageId, UserStoragePreference dataStoragePreference) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - boolean result = airavataService.updateUserStoragePreference( - userId, gatewayID, userStorageId, dataStoragePreference); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error(userId, "Error while updating user data storage preference...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating user data storage preference. More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error(userId, "Error while updating user data storage preference...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating user data storage preference. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.updateUserStoragePreference(userId, gatewayID, userStorageId, dataStoragePreference); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while updating user data storage preference"); + } } /** * Delete the Compute Resource Preference of a registered User Resource profile. @@ -5356,26 +3255,15 @@ public boolean updateUserStoragePreference( @SecurityCheck public boolean deleteUserComputeResourcePreference( AuthzToken authzToken, String userId, String gatewayID, String userComputeResourceId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - boolean result = - airavataService.deleteUserComputeResourcePreference(userId, gatewayID, userComputeResourceId); - return result; + return airavataService.deleteUserComputeResourcePreference(userId, gatewayID, userComputeResourceId); } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { logger.error(userId, "Error while deleting user compute resource preference...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while deleting user compute resource preference. More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { + throw ThriftExceptionHandler.convertException(e, "Error occurred"); + } catch (Throwable e) { logger.error(userId, "Error while deleting user compute resource preference...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while deleting user compute resource preference. More info : " + e.getMessage()); - throw exception; + throw ThriftExceptionHandler.convertException(e, "Error occurred"); } } @@ -5383,46 +3271,27 @@ public boolean deleteUserComputeResourcePreference( @SecurityCheck public boolean deleteUserStoragePreference( AuthzToken authzToken, String userId, String gatewayID, String userStorageId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - boolean result = airavataService.deleteUserStoragePreference(userId, gatewayID, userStorageId); - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error(userId, "Error while deleting user data storage preference...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while deleting user data storage preference. More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { - logger.error(userId, "Error while deleting user data storage preference...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while deleting user data storage preference. More info : " + e.getMessage()); - throw exception; - } - } + return airavataService.deleteUserStoragePreference(userId, gatewayID, userStorageId); + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error while deleting user data storage preference"); + } } @Override @SecurityCheck public List getLatestQueueStatuses(AuthzToken authzToken) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - List result = airavataService.getLatestQueueStatuses(); - return result; + return airavataService.getLatestQueueStatuses(); } catch (org.apache.airavata.registry.cpi.RegistryException e) { String msg = "Error in retrieving queue statuses"; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { + throw ThriftExceptionHandler.convertException(e, msg); + } catch (Throwable e) { String msg = "Error in retrieving queue statuses"; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @@ -5435,80 +3304,62 @@ public List getLatestQueueStatuses(AuthzToken authzToken) @Override @SecurityCheck public String registerDataProduct(AuthzToken authzToken, DataProductModel dataProductModel) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return airavataService.registerDataProduct(dataProductModel); - } catch (Exception e) { + } catch (Throwable e) { String msg = "Error in registering the data resource" + dataProductModel.getProductName() + "."; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @Override @SecurityCheck public DataProductModel getDataProduct(AuthzToken authzToken, String productUri) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return airavataService.getDataProduct(productUri); - } catch (Exception e) { - String msg = "Error in retreiving the data product " + productUri + "."; - logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; - } - } + } catch (Throwable e) { + throw ThriftExceptionHandler.convertException(e, "Error retrieving data product"); + } } @Override @SecurityCheck public String registerReplicaLocation(AuthzToken authzToken, DataReplicaLocationModel replicaLocationModel) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return airavataService.registerReplicaLocation(replicaLocationModel); - } catch (Exception e) { + } catch (Throwable e) { String msg = "Error in retreiving the replica " + replicaLocationModel.getReplicaName() + "."; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @Override @SecurityCheck public DataProductModel getParentDataProduct(AuthzToken authzToken, String productUri) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return airavataService.getParentDataProduct(productUri); - } catch (Exception e) { + } catch (Throwable e) { String msg = "Error in retreiving the parent data product for " + productUri + "."; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @Override @SecurityCheck public List getChildDataProducts(AuthzToken authzToken, String productUri) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return airavataService.getChildDataProducts(productUri); - } catch (Exception e) { + } catch (Throwable e) { String msg = "Error in retreiving the child products for " + productUri + "."; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @@ -5523,39 +3374,33 @@ public List getChildDataProducts(AuthzToken authzToken, String @SecurityCheck public boolean shareResourceWithUsers( AuthzToken authzToken, String resourceId, Map userPermissionList) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - RegistryService.Client regClient = registryClientPool.getResource(); - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - if (!airavataService.userHasAccessInternal( - sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER) - && !airavataService.userHasAccessInternal( - sharingClient, authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { + if (!airavataService.userHasAccessInternal( authzToken, resourceId, ResourcePermissionType.OWNER) + && !airavataService.userHasAccessInternal( authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { throw new AuthorizationException( "User is not allowed to change sharing because the user is either not the resource owner or does not have access to share the resource"); } for (Map.Entry userPermission : userPermissionList.entrySet()) { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); if (userPermission.getValue().equals(ResourcePermissionType.WRITE)) - sharingClient.shareEntityWithUsers( + airavataService.shareEntityWithUsers( gatewayId, resourceId, Arrays.asList(userPermission.getKey()), authzToken.getClaimsMap().get(Constants.GATEWAY_ID) + ":" + "WRITE", true); else if (userPermission.getValue().equals(ResourcePermissionType.READ)) - sharingClient.shareEntityWithUsers( + airavataService.shareEntityWithUsers( gatewayId, resourceId, Arrays.asList(userPermission.getKey()), authzToken.getClaimsMap().get(Constants.GATEWAY_ID) + ":" + "READ", true); else if (userPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING)) { - if (airavataService.userHasAccessInternal( - sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER)) { - airavataService.createManageSharingPermissionTypeIfMissing(sharingClient, gatewayId); - sharingClient.shareEntityWithUsers( + if (airavataService.userHasAccessInternal( authzToken, resourceId, ResourcePermissionType.OWNER)) { + airavataService.createManageSharingPermissionTypeIfMissing( gatewayId); + airavataService.shareEntityWithUsers( gatewayId, resourceId, Arrays.asList(userPermission.getKey()), @@ -5570,17 +3415,11 @@ else if (userPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING) throw new AiravataClientException(AiravataErrorType.UNSUPPORTED_OPERATION); } } - registryClientPool.returnResource(regClient); - sharingClientPool.returnResource(sharingClient); return true; - } catch (Exception e) { + } catch (Throwable e) { String msg = "Error in sharing resource with users. Resource ID : " + resourceId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - registryClientPool.returnBrokenResource(regClient); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @@ -5588,39 +3427,33 @@ else if (userPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING) @SecurityCheck public boolean shareResourceWithGroups( AuthzToken authzToken, String resourceId, Map groupPermissionList) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - RegistryService.Client regClient = registryClientPool.getResource(); - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - if (!airavataService.userHasAccessInternal( - sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER) - && !airavataService.userHasAccessInternal( - sharingClient, authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { + if (!airavataService.userHasAccessInternal( authzToken, resourceId, ResourcePermissionType.OWNER) + && !airavataService.userHasAccessInternal( authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { throw new AuthorizationException( "User is not allowed to change sharing because the user is either not the resource owner or does not have access to share the resource"); } for (Map.Entry groupPermission : groupPermissionList.entrySet()) { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); if (groupPermission.getValue().equals(ResourcePermissionType.WRITE)) - sharingClient.shareEntityWithGroups( + airavataService.shareEntityWithGroups( gatewayId, resourceId, Arrays.asList(groupPermission.getKey()), authzToken.getClaimsMap().get(Constants.GATEWAY_ID) + ":" + "WRITE", true); else if (groupPermission.getValue().equals(ResourcePermissionType.READ)) - sharingClient.shareEntityWithGroups( + airavataService.shareEntityWithGroups( gatewayId, resourceId, Arrays.asList(groupPermission.getKey()), authzToken.getClaimsMap().get(Constants.GATEWAY_ID) + ":" + "READ", true); else if (groupPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING)) { - if (airavataService.userHasAccessInternal( - sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER)) { - airavataService.createManageSharingPermissionTypeIfMissing(sharingClient, gatewayId); - sharingClient.shareEntityWithGroups( + if (airavataService.userHasAccessInternal( authzToken, resourceId, ResourcePermissionType.OWNER)) { + airavataService.createManageSharingPermissionTypeIfMissing( gatewayId); + airavataService.shareEntityWithGroups( gatewayId, resourceId, Arrays.asList(groupPermission.getKey()), @@ -5635,17 +3468,11 @@ else if (groupPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING throw new AiravataClientException(AiravataErrorType.UNSUPPORTED_OPERATION); } } - registryClientPool.returnResource(regClient); - sharingClientPool.returnResource(sharingClient); return true; - } catch (Exception e) { + } catch (Throwable e) { String msg = "Error in sharing resource with groups. Resource ID : " + resourceId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - registryClientPool.returnBrokenResource(regClient); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @@ -5653,37 +3480,31 @@ else if (groupPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING @SecurityCheck public boolean revokeSharingOfResourceFromUsers( AuthzToken authzToken, String resourceId, Map userPermissionList) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - RegistryService.Client regClient = registryClientPool.getResource(); - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - if (!airavataService.userHasAccessInternal( - sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER) - && !airavataService.userHasAccessInternal( - sharingClient, authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { + if (!airavataService.userHasAccessInternal( authzToken, resourceId, ResourcePermissionType.OWNER) + && !airavataService.userHasAccessInternal( authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { throw new AuthorizationException( "User is not allowed to change sharing because the user is either not the resource owner or does not have access to share the resource"); } for (Map.Entry userPermission : userPermissionList.entrySet()) { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); if (userPermission.getValue().equals(ResourcePermissionType.WRITE)) - sharingClient.revokeEntitySharingFromUsers( + airavataService.revokeEntitySharingFromUsers( gatewayId, resourceId, Arrays.asList(userPermission.getKey()), authzToken.getClaimsMap().get(Constants.GATEWAY_ID) + ":" + "WRITE"); else if (userPermission.getValue().equals(ResourcePermissionType.READ)) - sharingClient.revokeEntitySharingFromUsers( + airavataService.revokeEntitySharingFromUsers( gatewayId, resourceId, Arrays.asList(userPermission.getKey()), authzToken.getClaimsMap().get(Constants.GATEWAY_ID) + ":" + "READ"); else if (userPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING)) { - if (airavataService.userHasAccessInternal( - sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER)) { - airavataService.createManageSharingPermissionTypeIfMissing(sharingClient, gatewayId); - sharingClient.revokeEntitySharingFromUsers( + if (airavataService.userHasAccessInternal( authzToken, resourceId, ResourcePermissionType.OWNER)) { + airavataService.createManageSharingPermissionTypeIfMissing( gatewayId); + airavataService.revokeEntitySharingFromUsers( gatewayId, resourceId, Arrays.asList(userPermission.getKey()), @@ -5697,17 +3518,11 @@ else if (userPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING) throw new AiravataClientException(AiravataErrorType.UNSUPPORTED_OPERATION); } } - registryClientPool.returnResource(regClient); - sharingClientPool.returnResource(sharingClient); return true; - } catch (Exception e) { + } catch (Throwable e) { String msg = "Error in revoking access to resource from users. Resource ID : " + resourceId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - registryClientPool.returnBrokenResource(regClient); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @@ -5715,21 +3530,16 @@ else if (userPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING) @SecurityCheck public boolean revokeSharingOfResourceFromGroups( AuthzToken authzToken, String resourceId, Map groupPermissionList) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - RegistryService.Client regClient = registryClientPool.getResource(); - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { final String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); try { - if (!airavataService.userHasAccessInternal( - sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER) - && !airavataService.userHasAccessInternal( - sharingClient, authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { + if (!airavataService.userHasAccessInternal( authzToken, resourceId, ResourcePermissionType.OWNER) + && !airavataService.userHasAccessInternal( authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { throw new AuthorizationException( "User is not allowed to change sharing because the user is either not the resource owner or does not have access to share the resource"); } // For certain resource types, restrict them from being unshared with admin groups - ResourceType resourceType = airavataService.getResourceType(sharingClient, gatewayId, resourceId); + ResourceType resourceType = airavataService.getResourceType( gatewayId, resourceId); Set adminRestrictedResourceTypes = new HashSet<>(Arrays.asList( ResourceType.EXPERIMENT, ResourceType.APPLICATION_DEPLOYMENT, ResourceType.GROUP_RESOURCE_PROFILE)); if (adminRestrictedResourceTypes.contains(resourceType)) { @@ -5762,16 +3572,15 @@ public boolean revokeSharingOfResourceFromGroups( } for (Map.Entry groupPermission : groupPermissionList.entrySet()) { if (groupPermission.getValue().equals(ResourcePermissionType.WRITE)) - sharingClient.revokeEntitySharingFromUsers( + airavataService.revokeEntitySharingFromUsers( gatewayId, resourceId, Arrays.asList(groupPermission.getKey()), gatewayId + ":" + "WRITE"); else if (groupPermission.getValue().equals(ResourcePermissionType.READ)) - sharingClient.revokeEntitySharingFromUsers( + airavataService.revokeEntitySharingFromUsers( gatewayId, resourceId, Arrays.asList(groupPermission.getKey()), gatewayId + ":" + "READ"); else if (groupPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING)) { - if (airavataService.userHasAccessInternal( - sharingClient, authzToken, resourceId, ResourcePermissionType.OWNER)) { - airavataService.createManageSharingPermissionTypeIfMissing(sharingClient, gatewayId); - sharingClient.revokeEntitySharingFromUsers( + if (airavataService.userHasAccessInternal( authzToken, resourceId, ResourcePermissionType.OWNER)) { + airavataService.createManageSharingPermissionTypeIfMissing( gatewayId); + airavataService.revokeEntitySharingFromUsers( gatewayId, resourceId, Arrays.asList(groupPermission.getKey()), @@ -5785,17 +3594,11 @@ else if (groupPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING throw new AiravataClientException(AiravataErrorType.UNSUPPORTED_OPERATION); } } - registryClientPool.returnResource(regClient); - sharingClientPool.returnResource(sharingClient); return true; - } catch (Exception e) { + } catch (Throwable e) { String msg = "Error in revoking access to resource from groups. Resource ID : " + resourceId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - registryClientPool.returnBrokenResource(regClient); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @@ -5803,21 +3606,13 @@ else if (groupPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING @SecurityCheck public List getAllAccessibleUsers( AuthzToken authzToken, String resourceId, ResourcePermissionType permissionType) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); - try { - List accessibleUsers = airavataService.getAllAccessibleUsersWithSharing( - sharingClient, authzToken, resourceId, permissionType, false); - sharingClientPool.returnResource(sharingClient); - return accessibleUsers; - } catch (Exception e) { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + try { + return airavataService.getAllAccessibleUsersWithSharing( authzToken, resourceId, permissionType, false); + } catch (Throwable e) { String msg = "Error in getting all accessible users for resource. Resource ID : " + resourceId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @@ -5825,21 +3620,13 @@ public List getAllAccessibleUsers( @SecurityCheck public List getAllDirectlyAccessibleUsers( AuthzToken authzToken, String resourceId, ResourcePermissionType permissionType) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); - try { - List accessibleUsers = airavataService.getAllAccessibleUsersWithSharing( - sharingClient, authzToken, resourceId, permissionType, true); - sharingClientPool.returnResource(sharingClient); - return accessibleUsers; - } catch (Exception e) { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + try { + return airavataService.getAllAccessibleUsersWithSharing( authzToken, resourceId, permissionType, true); + } catch (Throwable e) { String msg = "Error in getting all directly accessible users for resource. Resource ID : " + resourceId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @@ -5847,21 +3634,13 @@ public List getAllDirectlyAccessibleUsers( @SecurityCheck public List getAllAccessibleGroups( AuthzToken authzToken, String resourceId, ResourcePermissionType permissionType) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); - try { - List accessibleGroups = airavataService.getAllAccessibleGroupsWithSharing( - sharingClient, authzToken, resourceId, permissionType, false); - sharingClientPool.returnResource(sharingClient); - return accessibleGroups; - } catch (Exception e) { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + try { + return airavataService.getAllAccessibleGroupsWithSharing( authzToken, resourceId, permissionType, false); + } catch (Throwable e) { String msg = "Error in getting all accessible groups for resource. Resource ID : " + resourceId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @@ -5869,223 +3648,162 @@ public List getAllAccessibleGroups( @SecurityCheck public List getAllDirectlyAccessibleGroups( AuthzToken authzToken, String resourceId, ResourcePermissionType permissionType) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); - try { - List accessibleGroups = airavataService.getAllAccessibleGroupsWithSharing( - sharingClient, authzToken, resourceId, permissionType, true); - sharingClientPool.returnResource(sharingClient); - return accessibleGroups; - } catch (Exception e) { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + try { + return airavataService.getAllAccessibleGroupsWithSharing( authzToken, resourceId, permissionType, true); + } catch (Throwable e) { String msg = "Error in getting all directly accessible groups for resource. Resource ID : " + resourceId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @Override @SecurityCheck public boolean userHasAccess(AuthzToken authzToken, String resourceId, ResourcePermissionType permissionType) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { final String domainId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); final String userId = authzToken.getClaimsMap().get(Constants.USER_NAME) + "@" + domainId; - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { - final boolean hasAccess = - airavataService.userHasAccessInternal(sharingClient, authzToken, resourceId, permissionType); - sharingClientPool.returnResource(sharingClient); - return hasAccess; - } catch (Exception e) { + return airavataService.userHasAccessInternal( authzToken, resourceId, permissionType); + } catch (Throwable e) { String msg = "Error in if user can access resource. User ID : " + userId + ", Resource ID : " + resourceId + ", Resource Permission Type : " + permissionType.toString(); logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @Override @SecurityCheck public String createGroupResourceProfile(AuthzToken authzToken, GroupResourceProfile groupResourceProfile) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { // TODO: verify that gatewayId in groupResourceProfile matches authzToken gatewayId - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); try { - String groupResourceProfileId = airavataService.createGroupResourceProfileWithSharing( - sharingClient, authzToken, groupResourceProfile); - sharingClientPool.returnResource(sharingClient); - return groupResourceProfileId; + return airavataService.createGroupResourceProfileWithSharing( authzToken, groupResourceProfile); } catch (AuthorizationException ae) { String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); logger.info("User " + userName + " not allowed access to resources referenced in this GroupResourceProfile. Reason: " + ae.getMessage()); - sharingClientPool.returnResource(sharingClient); throw ae; } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { String msg = "Error creating group resource profile."; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; - } catch (Exception e) { + throw ThriftExceptionHandler.convertException(e, msg); + } catch (Throwable e) { String msg = "Error creating group resource profile."; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @Override @SecurityCheck public void updateGroupResourceProfile(AuthzToken authzToken, GroupResourceProfile groupResourceProfile) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - airavataService.validateGroupResourceProfile(sharingClient, authzToken, groupResourceProfile); + airavataService.validateGroupResourceProfile( authzToken, groupResourceProfile); if (!airavataService.userHasAccessInternal( - sharingClient, authzToken, groupResourceProfile.getGroupResourceProfileId(), ResourcePermissionType.WRITE)) { throw new AuthorizationException("User does not have permission to update group resource profile"); } airavataService.updateGroupResourceProfile(groupResourceProfile); - sharingClientPool.returnResource(sharingClient); } catch (AuthorizationException ae) { String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); logger.info("User " + userName + " not allowed access to update GroupResourceProfile " + groupResourceProfile.getGroupResourceProfileId() + ", reason: " + ae.getMessage()); - sharingClientPool.returnResource(sharingClient); throw ae; - } catch (Exception e) { + } catch (Throwable e) { String msg = "Error updating group resource profile. groupResourceProfileId: " + groupResourceProfile.getGroupResourceProfileId(); logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @Override @SecurityCheck public GroupResourceProfile getGroupResourceProfile(AuthzToken authzToken, String groupResourceProfileId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { if (ServerSettings.isEnableSharing()) { try { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!sharingClient.userHasAccess( + if (!airavataService.userHasAccess( gatewayId, userId + "@" + gatewayId, groupResourceProfileId, gatewayId + ":READ")) { throw new AuthorizationException( "User does not have permission to access group resource profile"); } - } catch (Exception e) { + } catch (Throwable e) { throw new AuthorizationException("User does not have permission to access group resource profile"); } } GroupResourceProfile groupResourceProfile = airavataService.getGroupResourceProfile(groupResourceProfileId); - sharingClientPool.returnResource(sharingClient); return groupResourceProfile; } catch (AuthorizationException checkedException) { logger.error( "Error while retrieving group resource profile. groupResourceProfileId: " + groupResourceProfileId, checkedException); - sharingClientPool.returnResource(sharingClient); throw checkedException; - } catch (Exception e) { + } catch (Throwable e) { String msg = "Error retrieving group resource profile. groupResourceProfileId: " + groupResourceProfileId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @Override @SecurityCheck public boolean removeGroupResourceProfile(AuthzToken authzToken, String groupResourceProfileId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); if (ServerSettings.isEnableSharing()) { try { String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!sharingClient.userHasAccess( + if (!airavataService.userHasAccess( gatewayId, userId + "@" + gatewayId, groupResourceProfileId, gatewayId + ":WRITE")) { throw new AuthorizationException( "User does not have permission to remove group resource profile"); } - } catch (Exception e) { + } catch (Throwable e) { throw new AuthorizationException("User does not have permission to remove group resource profile"); } } boolean result = airavataService.removeGroupResourceProfile(groupResourceProfileId); - sharingClient.deleteEntity(gatewayId, groupResourceProfileId); - sharingClientPool.returnResource(sharingClient); + if (result) { + airavataService.deleteEntity(gatewayId, groupResourceProfileId); + } return result; } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { String msg = "Error removing group resource profile. groupResourceProfileId: " + groupResourceProfileId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; - } catch (Exception e) { + throw ThriftExceptionHandler.convertException(e, msg); + } catch (Throwable e) { String msg = "Error removing group resource profile. groupResourceProfileId: " + groupResourceProfileId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @Override @SecurityCheck public List getGroupResourceList(AuthzToken authzToken, String gatewayId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - List groupResourceProfileList = - airavataService.getGroupResourceListWithSharing(sharingClient, authzToken, gatewayId); - sharingClientPool.returnResource(sharingClient); - return groupResourceProfileList; + return airavataService.getGroupResourceListWithSharing( authzToken, gatewayId); } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { String msg = "Error retrieving list group resource profile list. GatewayId: " + gatewayId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; - } catch (Exception e) { + throw ThriftExceptionHandler.convertException(e, msg); + } catch (Throwable e) { String msg = "Error retrieving list group resource profile list. GatewayId: " + gatewayId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @@ -6093,60 +3811,47 @@ public List getGroupResourceList(AuthzToken authzToken, St @SecurityCheck public boolean removeGroupComputePrefs( AuthzToken authzToken, String computeResourceId, String groupResourceProfileId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { if (ServerSettings.isEnableSharing()) { try { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!sharingClient.userHasAccess( + if (!airavataService.userHasAccess( gatewayId, userId + "@" + gatewayId, groupResourceProfileId, gatewayId + ":WRITE")) { throw new AuthorizationException( "User does not have permission to remove group compute preferences"); } - } catch (Exception e) { + } catch (Throwable e) { throw new AuthorizationException( "User does not have permission to remove group compute preferences"); } } - boolean result = airavataService.removeGroupComputePrefs(computeResourceId, groupResourceProfileId); - sharingClientPool.returnResource(sharingClient); - return result; + return airavataService.removeGroupComputePrefs(computeResourceId, groupResourceProfileId); } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { String msg = "Error removing group compute resource preferences. GroupResourceProfileId: " + groupResourceProfileId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; - } catch (Exception e) { + throw ThriftExceptionHandler.convertException(e, msg); + } catch (Throwable e) { String msg = "Error removing group compute resource preferences. GroupResourceProfileId: " + groupResourceProfileId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @Override @SecurityCheck public boolean removeGroupComputeResourcePolicy(AuthzToken authzToken, String resourcePolicyId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { if (ServerSettings.isEnableSharing()) { try { - ComputeResourcePolicy computeResourcePolicy = - airavataService.getGroupComputeResourcePolicy(resourcePolicyId); + ComputeResourcePolicy computeResourcePolicy = airavataService.getGroupComputeResourcePolicy(resourcePolicyId); String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!sharingClient.userHasAccess( + if (!airavataService.userHasAccess( gatewayId, userId + "@" + gatewayId, computeResourcePolicy.getGroupResourceProfileId(), @@ -6154,45 +3859,34 @@ public boolean removeGroupComputeResourcePolicy(AuthzToken authzToken, String re throw new AuthorizationException( "User does not have permission to remove group compute resource policy"); } - } catch (Exception e) { + } catch (Throwable e) { throw new AuthorizationException( "User does not have permission to remove group compute resource policy"); } } - boolean result = airavataService.removeGroupComputeResourcePolicy(resourcePolicyId); - sharingClientPool.returnResource(sharingClient); - return result; + return airavataService.removeGroupComputeResourcePolicy(resourcePolicyId); } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { String msg = "Error removing group compute resource policy. ResourcePolicyId: " + resourcePolicyId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; - } catch (Exception e) { + throw ThriftExceptionHandler.convertException(e, msg); + } catch (Throwable e) { String msg = "Error removing group compute resource policy. ResourcePolicyId: " + resourcePolicyId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @Override @SecurityCheck public boolean removeGroupBatchQueueResourcePolicy(AuthzToken authzToken, String resourcePolicyId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { if (ServerSettings.isEnableSharing()) { try { - BatchQueueResourcePolicy batchQueueResourcePolicy = - airavataService.getBatchQueueResourcePolicy(resourcePolicyId); + BatchQueueResourcePolicy batchQueueResourcePolicy = airavataService.getBatchQueueResourcePolicy(resourcePolicyId); String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!sharingClient.userHasAccess( + if (!airavataService.userHasAccess( gatewayId, userId + "@" + gatewayId, batchQueueResourcePolicy.getGroupResourceProfileId(), @@ -6200,28 +3894,20 @@ public boolean removeGroupBatchQueueResourcePolicy(AuthzToken authzToken, String throw new AuthorizationException( "User does not have permission to remove batch queue resource policy"); } - } catch (Exception e) { + } catch (Throwable e) { throw new AuthorizationException( "User does not have permission to remove batch queue resource policy"); } } - boolean result = airavataService.removeGroupBatchQueueResourcePolicy(resourcePolicyId); - sharingClientPool.returnResource(sharingClient); - return result; + return airavataService.removeGroupBatchQueueResourcePolicy(resourcePolicyId); } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { String msg = "Error removing batch queue resource policy. ResourcePolicyId: " + resourcePolicyId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; - } catch (Exception e) { + throw ThriftExceptionHandler.convertException(e, msg); + } catch (Throwable e) { String msg = "Error removing batch queue resource policy. ResourcePolicyId: " + resourcePolicyId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @@ -6229,58 +3915,44 @@ public boolean removeGroupBatchQueueResourcePolicy(AuthzToken authzToken, String @SecurityCheck public GroupComputeResourcePreference getGroupComputeResourcePreference( AuthzToken authzToken, String computeResourceId, String groupResourceProfileId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { if (ServerSettings.isEnableSharing()) { try { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!sharingClient.userHasAccess( + if (!airavataService.userHasAccess( gatewayId, userId + "@" + gatewayId, groupResourceProfileId, gatewayId + ":READ")) { throw new AuthorizationException( "User does not have permission to access group resource profile"); } - } catch (Exception e) { + } catch (Throwable e) { throw new AuthorizationException("User does not have permission to access group resource profile"); } } - GroupComputeResourcePreference groupComputeResourcePreference = - airavataService.getGroupComputeResourcePreference(computeResourceId, groupResourceProfileId); - sharingClientPool.returnResource(sharingClient); - return groupComputeResourcePreference; + return airavataService.getGroupComputeResourcePreference(computeResourceId, groupResourceProfileId); } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { String msg = "Error retrieving Group compute preference. GroupResourceProfileId: " + groupResourceProfileId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; - } catch (Exception e) { + throw ThriftExceptionHandler.convertException(e, msg); + } catch (Throwable e) { String msg = "Error retrieving Group compute preference. GroupResourceProfileId: " + groupResourceProfileId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @Override @SecurityCheck public ComputeResourcePolicy getGroupComputeResourcePolicy(AuthzToken authzToken, String resourcePolicyId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { if (ServerSettings.isEnableSharing()) { try { - ComputeResourcePolicy computeResourcePolicy = - airavataService.getGroupComputeResourcePolicy(resourcePolicyId); + ComputeResourcePolicy computeResourcePolicy = airavataService.getGroupComputeResourcePolicy(resourcePolicyId); String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!sharingClient.userHasAccess( + if (!airavataService.userHasAccess( gatewayId, userId + "@" + gatewayId, computeResourcePolicy.getGroupResourceProfileId(), @@ -6288,46 +3960,34 @@ public ComputeResourcePolicy getGroupComputeResourcePolicy(AuthzToken authzToken throw new AuthorizationException( "User does not have permission to access group resource profile"); } - } catch (Exception e) { + } catch (Throwable e) { throw new AuthorizationException("User does not have permission to access group resource profile"); } } - ComputeResourcePolicy computeResourcePolicy = - airavataService.getGroupComputeResourcePolicy(resourcePolicyId); - sharingClientPool.returnResource(sharingClient); - return computeResourcePolicy; + return airavataService.getGroupComputeResourcePolicy(resourcePolicyId); } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { String msg = "Error retrieving Group compute resource policy. ResourcePolicyId: " + resourcePolicyId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; - } catch (Exception e) { + throw ThriftExceptionHandler.convertException(e, msg); + } catch (Throwable e) { String msg = "Error retrieving Group compute resource policy. ResourcePolicyId: " + resourcePolicyId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @Override @SecurityCheck public BatchQueueResourcePolicy getBatchQueueResourcePolicy(AuthzToken authzToken, String resourcePolicyId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { if (ServerSettings.isEnableSharing()) { try { - BatchQueueResourcePolicy batchQueueResourcePolicy = - airavataService.getBatchQueueResourcePolicy(resourcePolicyId); + BatchQueueResourcePolicy batchQueueResourcePolicy = airavataService.getBatchQueueResourcePolicy(resourcePolicyId); String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!sharingClient.userHasAccess( + if (!airavataService.userHasAccess( gatewayId, userId + "@" + gatewayId, batchQueueResourcePolicy.getGroupResourceProfileId(), @@ -6335,28 +3995,19 @@ public BatchQueueResourcePolicy getBatchQueueResourcePolicy(AuthzToken authzToke throw new AuthorizationException( "User does not have permission to access group resource profile"); } - } catch (Exception e) { + } catch (Throwable e) { throw new AuthorizationException("User does not have permission to access group resource profile"); } } - BatchQueueResourcePolicy batchQueueResourcePolicy = - airavataService.getBatchQueueResourcePolicy(resourcePolicyId); - sharingClientPool.returnResource(sharingClient); - return batchQueueResourcePolicy; + return airavataService.getBatchQueueResourcePolicy(resourcePolicyId); } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { String msg = "Error retrieving Group batch queue resource policy. ResourcePolicyId: " + resourcePolicyId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; - } catch (Exception e) { + throw ThriftExceptionHandler.convertException(e, msg); + } catch (Throwable e) { String msg = "Error retrieving Group batch queue resource policy. ResourcePolicyId: " + resourcePolicyId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @@ -6364,43 +4015,32 @@ public BatchQueueResourcePolicy getBatchQueueResourcePolicy(AuthzToken authzToke @SecurityCheck public List getGroupComputeResourcePrefList( AuthzToken authzToken, String groupResourceProfileId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { if (ServerSettings.isEnableSharing()) { try { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!sharingClient.userHasAccess( + if (!airavataService.userHasAccess( gatewayId, userId + "@" + gatewayId, groupResourceProfileId, gatewayId + ":READ")) { throw new AuthorizationException( "User does not have permission to access group resource profile"); } - } catch (Exception e) { + } catch (Throwable e) { throw new AuthorizationException("User does not have permission to access group resource profile"); } } - List groupComputeResourcePreferenceList = - airavataService.getGroupComputeResourcePrefList(groupResourceProfileId); - sharingClientPool.returnResource(sharingClient); - return groupComputeResourcePreferenceList; + return airavataService.getGroupComputeResourcePrefList(groupResourceProfileId); } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { String msg = "Error retrieving Group compute resource preference. GroupResourceProfileId: " + groupResourceProfileId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; - } catch (Exception e) { + throw ThriftExceptionHandler.convertException(e, msg); + } catch (Throwable e) { String msg = "Error retrieving Group compute resource preference. GroupResourceProfileId: " + groupResourceProfileId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @@ -6408,43 +4048,32 @@ public List getGroupComputeResourcePrefList( @SecurityCheck public List getGroupBatchQueueResourcePolicyList( AuthzToken authzToken, String groupResourceProfileId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { if (ServerSettings.isEnableSharing()) { try { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!sharingClient.userHasAccess( + if (!airavataService.userHasAccess( gatewayId, userId + "@" + gatewayId, groupResourceProfileId, gatewayId + ":READ")) { throw new AuthorizationException( "User does not have permission to access group resource profile"); } - } catch (Exception e) { + } catch (Throwable e) { throw new AuthorizationException("User does not have permission to access group resource profile"); } } - List batchQueueResourcePolicyList = - airavataService.getGroupBatchQueueResourcePolicyList(groupResourceProfileId); - sharingClientPool.returnResource(sharingClient); - return batchQueueResourcePolicyList; + return airavataService.getGroupBatchQueueResourcePolicyList(groupResourceProfileId); } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { String msg = "Error retrieving Group batch queue resource policy list. GroupResourceProfileId: " + groupResourceProfileId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; - } catch (Exception e) { + throw ThriftExceptionHandler.convertException(e, msg); + } catch (Throwable e) { String msg = "Error retrieving Group batch queue resource policy list. GroupResourceProfileId: " + groupResourceProfileId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @@ -6452,177 +4081,132 @@ public List getGroupBatchQueueResourcePolicyList( @SecurityCheck public List getGroupComputeResourcePolicyList( AuthzToken authzToken, String groupResourceProfileId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - SharingRegistryService.Client sharingClient = sharingClientPool.getResource(); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { if (ServerSettings.isEnableSharing()) { try { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!sharingClient.userHasAccess( + if (!airavataService.userHasAccess( gatewayId, userId + "@" + gatewayId, groupResourceProfileId, gatewayId + ":READ")) { throw new AuthorizationException( "User does not have permission to access group resource profile"); } - } catch (Exception e) { + } catch (Throwable e) { throw new AuthorizationException("User does not have permission to access group resource profile"); } } - List computeResourcePolicyList = - airavataService.getGroupComputeResourcePolicyList(groupResourceProfileId); - sharingClientPool.returnResource(sharingClient); - return computeResourcePolicyList; + return airavataService.getGroupComputeResourcePolicyList(groupResourceProfileId); } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { String msg = "Error retrieving Group compute resource policy list. GroupResourceProfileId: " + groupResourceProfileId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; - } catch (Exception e) { + throw ThriftExceptionHandler.convertException(e, msg); + } catch (Throwable e) { String msg = "Error retrieving Group compute resource policy list. GroupResourceProfileId: " + groupResourceProfileId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - sharingClientPool.returnBrokenResource(sharingClient); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @Override @SecurityCheck public GatewayGroups getGatewayGroups(AuthzToken authzToken) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); try { - GatewayGroups gatewayGroups = airavataService.retrieveGatewayGroups(gatewayId); - return gatewayGroups; - } catch (Exception e) { + return airavataService.retrieveGatewayGroups(gatewayId); + } catch (Throwable e) { String msg = "Error retrieving GatewayGroups for gateway: " + gatewayId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @Override @SecurityCheck public Parser getParser(AuthzToken authzToken, String parserId, String gatewayId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - Parser parser = airavataService.getParser(parserId, gatewayId); - return parser; + return airavataService.getParser(parserId, gatewayId); } catch (org.apache.airavata.registry.cpi.RegistryException e) { String msg = "Error retrieving parser with id: " + parserId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { + throw ThriftExceptionHandler.convertException(e, msg); + } catch (Throwable e) { String msg = "Error retrieving parser with id: " + parserId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @Override @SecurityCheck public String saveParser(AuthzToken authzToken, Parser parser) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - String parserId = airavataService.saveParser(parser); - return parserId; + return airavataService.saveParser(parser); } catch (org.apache.airavata.registry.cpi.RegistryException e) { String msg = "Error while saving the parser"; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { + throw ThriftExceptionHandler.convertException(e, msg); + } catch (Throwable e) { String msg = "Error while saving the parser"; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @Override @SecurityCheck public List listAllParsers(AuthzToken authzToken, String gatewayId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - List parsers = airavataService.listAllParsers(gatewayId); - return parsers; + return airavataService.listAllParsers(gatewayId); } catch (org.apache.airavata.registry.cpi.RegistryException e) { String msg = "Error while listing the parsers for gateway " + gatewayId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { + throw ThriftExceptionHandler.convertException(e, msg); + } catch (Throwable e) { String msg = "Error while listing the parsers for gateway " + gatewayId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @Override @SecurityCheck - public boolean removeParser(AuthzToken authzToken, String parserId, String gatewayId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + public boolean removeParser(AuthzToken authzToken, String parserId, String gatewayId){ try { airavataService.removeParser(parserId, gatewayId); return true; } catch (org.apache.airavata.registry.cpi.RegistryException e) { String msg = "Error while removing the parser " + parserId + " in gateway " + gatewayId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { + throw ThriftExceptionHandler.convertException(e, msg); + } catch (Throwable e) { String msg = "Error while removing the parser " + parserId + " in gateway " + gatewayId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @Override @SecurityCheck public ParsingTemplate getParsingTemplate(AuthzToken authzToken, String templateId, String gatewayId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - ParsingTemplate parsingTemplate = airavataService.getParsingTemplate(templateId, gatewayId); - return parsingTemplate; + return airavataService.getParsingTemplate(templateId, gatewayId); } catch (org.apache.airavata.registry.cpi.RegistryException e) { String msg = "Error retrieving parsing template with id: " + templateId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { + throw ThriftExceptionHandler.convertException(e, msg); + } catch (Throwable e) { String msg = "Error retrieving parsing template with id: " + templateId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @@ -6630,93 +4214,69 @@ public ParsingTemplate getParsingTemplate(AuthzToken authzToken, String template @SecurityCheck public List getParsingTemplatesForExperiment( AuthzToken authzToken, String experimentId, String gatewayId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - List parsingTemplates = - airavataService.getParsingTemplatesForExperiment(experimentId, gatewayId); - return parsingTemplates; + return airavataService.getParsingTemplatesForExperiment(experimentId, gatewayId); } catch (org.apache.airavata.registry.cpi.RegistryException e) { String msg = "Error retrieving parsing templates for experiment: " + experimentId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { + throw ThriftExceptionHandler.convertException(e, msg); + } catch (Throwable e) { String msg = "Error retrieving parsing templates for experiment: " + experimentId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @Override @SecurityCheck public String saveParsingTemplate(AuthzToken authzToken, ParsingTemplate parsingTemplate) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - String templateId = airavataService.saveParsingTemplate(parsingTemplate); - return templateId; + return airavataService.saveParsingTemplate(parsingTemplate); } catch (org.apache.airavata.registry.cpi.RegistryException e) { String msg = "Error saving the parsing template"; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { + throw ThriftExceptionHandler.convertException(e, msg); + } catch (Throwable e) { String msg = "Error saving the parsing template"; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @Override @SecurityCheck public boolean removeParsingTemplate(AuthzToken authzToken, String templateId, String gatewayId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { airavataService.removeParsingTemplate(templateId, gatewayId); return true; } catch (org.apache.airavata.registry.cpi.RegistryException e) { String msg = "Error while removing the parsing template " + templateId + " in gateway " + gatewayId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { + throw ThriftExceptionHandler.convertException(e, msg); + } catch (Throwable e) { String msg = "Error while removing the parsing template " + templateId + " in gateway " + gatewayId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @Override @SecurityCheck public List listAllParsingTemplates(AuthzToken authzToken, String gatewayId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - List templates = airavataService.listAllParsingTemplates(gatewayId); - return templates; + return airavataService.listAllParsingTemplates(gatewayId); } catch (org.apache.airavata.registry.cpi.RegistryException e) { String msg = "Error while listing the parsing templates for gateway " + gatewayId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; - } catch (Exception e) { + throw ThriftExceptionHandler.convertException(e, msg); + } catch (Throwable e) { String msg = "Error while listing the parsing templates for gateway " + gatewayId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; + throw ThriftExceptionHandler.convertException(e, msg); } } @@ -6728,22 +4288,13 @@ private record StorageInfoContext(String loginUserName, String credentialToken, /** * Check if a gateway resource profile exists */ - private boolean isGatewayResourceProfileExists(String gatewayId) throws TException { - RegistryService.Client regClient = registryClientPool.getResource(); + private boolean isGatewayResourceProfileExists(String gatewayId) { try { - try { - GatewayResourceProfile profile = regClient.getGatewayResourceProfile(gatewayId); - registryClientPool.returnResource(regClient); - return profile != null; - } catch (org.apache.thrift.TApplicationException e) { - logger.error("Gateway resource profile does not exist for gateway: {}", gatewayId, e); - registryClientPool.returnResource(regClient); - return false; - } - } catch (Exception e) { - registryClientPool.returnBrokenResource(regClient); + GatewayResourceProfile profile = airavataService.getGatewayResourceProfile(gatewayId); + return profile != null; + } catch (Throwable e) { logger.error("Error while checking if gateway resource profile exists", e); - throw e; + return false; } } @@ -6760,14 +4311,14 @@ private AiravataClientException clientException(AiravataErrorType errorType, Str */ private StorageInfoContext resolveComputeStorageInfoContext( AuthzToken authzToken, String gatewayId, String userId, String resourceId) - throws AgentException, TException { + throws Exception { String loginUserName = null; boolean loginFromUserPref = false; GroupComputeResourcePreference groupComputePref = null; GroupResourceProfile groupResourceProfile = null; UserComputeResourcePreference userComputePref = null; - if (isUserResourceProfileExists(authzToken, userId, gatewayId)) { + if (safeIsUserResourceProfileExists(authzToken, userId, gatewayId)) { userComputePref = getUserComputeResourcePreference(authzToken, userId, gatewayId, resourceId); } else { logger.debug( @@ -6883,9 +4434,9 @@ private StorageInfoContext resolveComputeStorageInfoContext( */ private StorageInfoContext resolveStorageStorageInfoContext( AuthzToken authzToken, String gatewayId, String userId, String resourceId) - throws AgentException, TException { + throws Exception { UserStoragePreference userStoragePref = null; - if (isUserResourceProfileExists(authzToken, userId, gatewayId)) { + if (safeIsUserResourceProfileExists(authzToken, userId, gatewayId)) { userStoragePref = getUserStoragePreference(authzToken, userId, gatewayId, resourceId); } else { logger.debug( @@ -6983,4 +4534,14 @@ private StorageInfoContext resolveStorageStorageInfoContext( return new StorageInfoContext(loginUserName, credentialToken, adaptor); } -} + + private boolean safeIsUserResourceProfileExists(AuthzToken authzToken, String userId, String gatewayId) { + try { + return isUserResourceProfileExists(authzToken, userId, gatewayId); + } catch (Throwable e) { + logger.error("Error checking if user resource profile exists", e); + return false; + } + } + +} \ No newline at end of file diff --git a/airavata-api/src/main/java/org/apache/airavata/api/server/handler/ThriftExceptionHandler.java b/airavata-api/src/main/java/org/apache/airavata/api/server/handler/ThriftExceptionHandler.java new file mode 100644 index 0000000000..63ab0dc7ca --- /dev/null +++ b/airavata-api/src/main/java/org/apache/airavata/api/server/handler/ThriftExceptionHandler.java @@ -0,0 +1,50 @@ +package org.apache.airavata.api.server.handler; + +import org.apache.airavata.registry.cpi.AppCatalogException; +import org.apache.airavata.registry.cpi.RegistryException; +import org.apache.thrift.TException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Global exception handler for Thrift server handlers. + * Converts service layer exceptions to appropriate Thrift exceptions. + */ +public class ThriftExceptionHandler { + private static final Logger logger = LoggerFactory.getLogger(ThriftExceptionHandler.class); + + public static RuntimeException convertException(Throwable e, String context) { + // Re-throw Thrift exceptions as-is + if (e instanceof org.apache.airavata.model.error.InvalidRequestException || + e instanceof org.apache.airavata.model.error.AiravataClientException || + e instanceof org.apache.airavata.model.error.AiravataSystemException || + e instanceof org.apache.airavata.model.error.AuthorizationException || + e instanceof org.apache.airavata.model.error.ExperimentNotFoundException || + e instanceof org.apache.airavata.model.error.ProjectNotFoundException) { + throw sneakyThrow(e); + } + + // Convert service exceptions to AiravataSystemException + if (e instanceof RegistryException || e instanceof AppCatalogException || + e instanceof org.apache.airavata.credential.store.store.CredentialStoreException || + e instanceof org.apache.airavata.sharing.registry.models.SharingRegistryException) { + logger.error(context, e); + org.apache.airavata.model.error.AiravataSystemException exception = new org.apache.airavata.model.error.AiravataSystemException(); + exception.setAiravataErrorType(org.apache.airavata.model.error.AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(context + ". More info : " + e.getMessage()); + throw sneakyThrow(exception); + } + + // Handle any other exception + logger.error(context, e); + org.apache.airavata.model.error.AiravataSystemException exception = new org.apache.airavata.model.error.AiravataSystemException(); + exception.setAiravataErrorType(org.apache.airavata.model.error.AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(context + ". More info : " + e.getMessage()); + throw sneakyThrow(exception); + } + + @SuppressWarnings("unchecked") + private static RuntimeException sneakyThrow(Throwable e) throws E { + throw (E) e; + } +} diff --git a/airavata-api/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java index ff4ee71c83..6be8b1bb8c 100644 --- a/airavata-api/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java @@ -51,17 +51,7 @@ public String getAPIVersion() throws TException { @Override public String addSSHCredential(SSHCredential sshCredential) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { - try { - return credentialStoreService.addSSHCredential(sshCredential); - } catch (CredentialStoreException e) { - log.error("Error occurred while saving SSH Credentials.", e); - throw new org.apache.airavata.credential.store.exception.CredentialStoreException( - "Error occurred while saving SSH Credentials."); - } catch (Exception e) { - log.error("Error occurred while saving SSH Credentials.", e); - throw new org.apache.airavata.credential.store.exception.CredentialStoreException( - "Error occurred while saving SSH Credentials."); - } + return credentialStoreService.addSSHCredential(sshCredential); } @Override @@ -73,7 +63,7 @@ public String addCertificateCredential(CertificateCredential certificateCredenti log.error("Error occurred while saving Certificate Credentials.", e); throw new org.apache.airavata.credential.store.exception.CredentialStoreException( "Error occurred while saving Certificate Credentials."); - } catch (Exception e) { + } catch (Throwable e) { log.error("Error occurred while saving Certificate Credentials.", e); throw new org.apache.airavata.credential.store.exception.CredentialStoreException( "Error occurred while saving Certificate Credentials."); @@ -89,7 +79,7 @@ public String addPasswordCredential(PasswordCredential passwordCredential) log.error("Error occurred while saving PWD Credentials.", e); throw new org.apache.airavata.credential.store.exception.CredentialStoreException( "Error occurred while saving PWD Credentials."); - } catch (Exception e) { + } catch (Throwable e) { log.error("Error occurred while saving PWD Credentials.", e); throw new org.apache.airavata.credential.store.exception.CredentialStoreException( "Error occurred while saving PWD Credentials."); diff --git a/airavata-api/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java index c0e1851a47..acabc1e2e7 100644 --- a/airavata-api/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java @@ -22,43 +22,16 @@ import java.util.*; import org.apache.airavata.common.exception.AiravataException; import org.apache.airavata.common.exception.ApplicationSettingsException; -import org.apache.airavata.common.logging.MDCConstants; -import org.apache.airavata.common.utils.ServerSettings; -import org.apache.airavata.common.utils.ThriftUtils; -import org.apache.airavata.common.utils.ZkConstants; -import org.apache.airavata.messaging.core.*; -import org.apache.airavata.model.commons.ErrorModel; import org.apache.airavata.model.error.LaunchValidationException; -import org.apache.airavata.model.messaging.event.*; import org.apache.airavata.model.process.ProcessModel; -import org.apache.airavata.model.status.*; import org.apache.airavata.orchestrator.core.exception.OrchestratorException; import org.apache.airavata.orchestrator.cpi.OrchestratorService; -import org.apache.airavata.orchestrator.cpi.impl.SimpleOrchestratorImpl; -import org.apache.airavata.orchestrator.util.OrchestratorServerThreadPoolExecutor; -import org.apache.airavata.service.OrchestratorRegistryService; -import org.apache.curator.RetryPolicy; -import org.apache.curator.framework.CuratorFramework; -import org.apache.curator.framework.CuratorFrameworkFactory; -import org.apache.curator.retry.ExponentialBackoffRetry; -import org.apache.curator.utils.ZKPaths; -import org.apache.thrift.TBase; import org.apache.thrift.TException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.slf4j.MDC; public class OrchestratorServerHandler implements OrchestratorService.Iface { private static Logger log = LoggerFactory.getLogger(OrchestratorServerHandler.class); - private SimpleOrchestratorImpl orchestrator = null; - private String airavataUserName; - private String gatewayName; - private Publisher publisher; - private final Subscriber statusSubscribe; - private final Subscriber experimentSubscriber; - - private CuratorFramework curatorClient; - private OrchestratorRegistryService orchestratorRegistryService = new OrchestratorRegistryService(); private org.apache.airavata.service.OrchestratorService orchestratorService; /** @@ -70,41 +43,14 @@ public String getAPIVersion() throws TException { } public OrchestratorServerHandler() throws OrchestratorException, TException { - // orchestrator init try { - // first constructing the monitorManager and orchestrator, then fill - // the required properties - setAiravataUserName(ServerSettings.getDefaultUser()); - orchestrator = new SimpleOrchestratorImpl(); - - publisher = MessagingFactory.getPublisher(Type.STATUS); - orchestrator.initialize(); - orchestrator.getOrchestratorContext().setPublisher(publisher); - statusSubscribe = getStatusSubscriber(); - experimentSubscriber = getExperimentSubscriber(); - startCurator(); - orchestratorService = new org.apache.airavata.service.OrchestratorService( - orchestratorRegistryService, orchestrator, curatorClient, publisher); - } catch (OrchestratorException | AiravataException e) { + orchestratorService = new org.apache.airavata.service.OrchestratorService(); + } catch (OrchestratorException e) { log.error(e.getMessage(), e); throw new OrchestratorException("Error while initializing orchestrator service", e); } } - private Subscriber getStatusSubscriber() throws AiravataException { - List routingKeys = new ArrayList<>(); - // routingKeys.add("*"); // listen for gateway level messages - // routingKeys.add("*.*"); // listen for gateway/experiment level messages - routingKeys.add("*.*.*"); // listen for gateway/experiment/process level messages - return MessagingFactory.getSubscriber(new ProcessStatusHandler(), routingKeys, Type.STATUS); - } - - private Subscriber getExperimentSubscriber() throws AiravataException { - List routingKeys = new ArrayList<>(); - routingKeys.add(ServerSettings.getRabbitmqExperimentLaunchQueueName()); - return MessagingFactory.getSubscriber(new ExperimentHandler(), routingKeys, Type.EXPERIMENT_LAUNCH); - } - /** * * After creating the experiment Data user have the * experimentID as the * handler to the experiment, during the launchProcess * We just have to @@ -114,14 +60,8 @@ private Subscriber getExperimentSubscriber() throws AiravataException { * @param experimentId */ public boolean launchExperiment(String experimentId, String gatewayId) throws TException { - try { - return orchestratorService.launchExperimentWithErrorHandling( - experimentId, gatewayId, OrchestratorServerThreadPoolExecutor.getCachedThreadPool()); - } catch (TException e) { - throw e; - } catch (Exception e) { - throw new TException("Experiment '" + experimentId + "' launch failed.", e); - } + return orchestratorService.launchExperimentWithErrorHandling( + experimentId, gatewayId, org.apache.airavata.orchestrator.util.OrchestratorServerThreadPoolExecutor.getCachedThreadPool()); } /** @@ -134,40 +74,13 @@ public boolean launchExperiment(String experimentId, String gatewayId) throws TE * @throws TException */ public boolean validateExperiment(String experimentId) throws TException, LaunchValidationException { - try { - return orchestratorService.validateExperiment(experimentId); - } catch (OrchestratorException e) { - log.error(experimentId, "Error while validating experiment", e); - throw new TException(e); - } catch (org.apache.airavata.registry.cpi.RegistryException e) { - log.error(experimentId, "Error while retrieving experiment for validation", e); - throw new TException(e); - } + return orchestratorService.validateExperiment(experimentId); } @Override public boolean validateProcess(String experimentId, List processes) throws LaunchValidationException, TException { - try { - return orchestratorService.validateProcess(experimentId, processes); - } catch (LaunchValidationException lve) { - // If a process failed to validate, also add an error message at the experiment level - ErrorModel details = new ErrorModel(); - details.setActualErrorMessage(lve.getErrorMessage()); - details.setCreationTime(Calendar.getInstance().getTimeInMillis()); - try { - orchestratorService.addProcessValidationErrors(experimentId, details); - } catch (org.apache.airavata.registry.cpi.RegistryException e) { - log.error(experimentId, "Error while adding errors to experiment", e); - } - throw lve; - } catch (OrchestratorException e) { - log.error(experimentId, "Error while validating process", e); - throw new TException(e); - } catch (org.apache.airavata.registry.cpi.RegistryException e) { - log.error(experimentId, "Error while retrieving experiment for process validation", e); - throw new TException(e); - } + return orchestratorService.validateProcess(experimentId, processes); } /** @@ -180,181 +93,16 @@ public boolean validateProcess(String experimentId, List processes */ public boolean terminateExperiment(String experimentId, String gatewayId) throws TException { log.info(experimentId, "Experiment: {} is cancelling !!!!!", experimentId); - try { - return orchestratorService.terminateExperiment(experimentId, gatewayId); - } catch (Exception e) { - log.error("expId : " + experimentId + " :- Error while cancelling experiment", e); - return false; - } + return orchestratorService.terminateExperiment(experimentId, gatewayId); } public void fetchIntermediateOutputs(String experimentId, String gatewayId, List outputNames) throws TException { - try { - orchestratorService.fetchIntermediateOutputs(experimentId, gatewayId, outputNames); - } catch (Exception e) { - log.error("expId : " + experimentId + " :- Error while fetching intermediate", e); - } - } - - private String getAiravataUserName() { - return airavataUserName; - } - - private String getGatewayName() { - return gatewayName; - } - - public void setAiravataUserName(String airavataUserName) { - this.airavataUserName = airavataUserName; - } - - public void setGatewayName(String gatewayName) { - this.gatewayName = gatewayName; + orchestratorService.fetchIntermediateOutputs(experimentId, gatewayId, outputNames); } @Override public boolean launchProcess(String processId, String airavataCredStoreToken, String gatewayId) throws TException { - try { - return orchestratorService.launchProcess(processId, airavataCredStoreToken, gatewayId); - } catch (org.apache.airavata.registry.cpi.RegistryException e) { - log.error(processId, "Error while launching process ", e); - throw new TException(e); - } catch (Exception e) { - log.error(processId, "Error while launching process ", e); - throw new TException(e); - } - } - - private class ProcessStatusHandler implements MessageHandler { - /** - * This method only handle MessageType.PROCESS type messages. - * - * @param message - */ - @Override - public void onMessage(MessageContext message) { - if (message.getType().equals(MessageType.PROCESS)) { - try { - ProcessStatusChangeEvent processStatusChangeEvent = new ProcessStatusChangeEvent(); - TBase event = message.getEvent(); - byte[] bytes = ThriftUtils.serializeThriftObject(event); - ThriftUtils.createThriftFromBytes(bytes, processStatusChangeEvent); - ProcessIdentifier processIdentity = processStatusChangeEvent.getProcessIdentity(); - log.info( - "expId: {}, processId: {} :- Process status changed event received for status {}", - processIdentity.getExperimentId(), - processIdentity.getProcessId(), - processStatusChangeEvent.getState().name()); - orchestratorService.handleProcessStatusChange(processStatusChangeEvent, processIdentity); - } catch (TException e) { - log.error("Message Id : " + message.getMessageId() + ", Message type : " + message.getType() - + "Error" + " while prcessing process status change event"); - throw new RuntimeException("Error while updating experiment status", e); - } catch (Exception e) { - log.error( - "Message Id : " + message.getMessageId() + ", Message type : " + message.getType() + "Error" - + " while prcessing process status change event", - e); - throw new RuntimeException("Error while updating experiment status", e); - } - } else { - System.out.println("Message Recieved with message id " + message.getMessageId() + " and with message " - + "type " + message.getType().name()); - } - } - } - - private class ExperimentHandler implements MessageHandler { - - @Override - public void onMessage(MessageContext messageContext) { - MDC.put(MDCConstants.GATEWAY_ID, messageContext.getGatewayId()); - switch (messageContext.getType()) { - case EXPERIMENT: - launchExperiment(messageContext); - break; - case EXPERIMENT_CANCEL: - cancelExperiment(messageContext); - break; - case INTERMEDIATE_OUTPUTS: - handleIntermediateOutputsEvent(messageContext); - break; - default: - experimentSubscriber.sendAck(messageContext.getDeliveryTag()); - log.error("Orchestrator got un-support message type : " + messageContext.getType()); - break; - } - MDC.clear(); - } - - private void cancelExperiment(MessageContext messageContext) { - try { - byte[] bytes = ThriftUtils.serializeThriftObject(messageContext.getEvent()); - ExperimentSubmitEvent expEvent = new ExperimentSubmitEvent(); - ThriftUtils.createThriftFromBytes(bytes, expEvent); - log.info( - "Cancelling experiment with experimentId: {} gateway Id: {}", - expEvent.getExperimentId(), - expEvent.getGatewayId()); - orchestratorService.handleCancelExperiment(expEvent); - } catch (TException e) { - log.error("Error while cancelling experiment", e); - throw new RuntimeException("Error while cancelling experiment", e); - } catch (Exception e) { - log.error("Error while cancelling experiment", e); - throw new RuntimeException("Error while cancelling experiment", e); - } finally { - experimentSubscriber.sendAck(messageContext.getDeliveryTag()); - } - } - - private void handleIntermediateOutputsEvent(MessageContext messageContext) { - try { - byte[] bytes = ThriftUtils.serializeThriftObject(messageContext.getEvent()); - ExperimentIntermediateOutputsEvent event = new ExperimentIntermediateOutputsEvent(); - ThriftUtils.createThriftFromBytes(bytes, event); - log.info( - "INTERMEDIATE_OUTPUTS event for experimentId: {} gateway Id: {} outputs: {}", - event.getExperimentId(), - event.getGatewayId(), - event.getOutputNames()); - orchestratorService.handleIntermediateOutputsEvent(event); - } catch (TException e) { - log.error("Error while fetching intermediate outputs", e); - throw new RuntimeException("Error while fetching intermediate outputs", e); - } catch (Exception e) { - log.error("Error while fetching intermediate outputs", e); - throw new RuntimeException("Error while fetching intermediate outputs", e); - } finally { - experimentSubscriber.sendAck(messageContext.getDeliveryTag()); - } - } - } - - private void launchExperiment(MessageContext messageContext) { - try { - orchestratorService.handleLaunchExperimentFromMessage(messageContext); - } catch (TException e) { - log.error("Experiment launch failed due to Thrift conversion error", e); - } catch (org.apache.airavata.registry.cpi.RegistryException e) { - log.error("Experiment launch failed due to registry error", e); - } catch (Exception e) { - log.error("An unknown issue while launching experiment", e); - } finally { - experimentSubscriber.sendAck(messageContext.getDeliveryTag()); - MDC.clear(); - } - } - - private void startCurator() throws ApplicationSettingsException { - String connectionSting = ServerSettings.getZookeeperConnection(); - RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 5); - curatorClient = CuratorFrameworkFactory.newClient(connectionSting, retryPolicy); - curatorClient.start(); - } - - public String getExperimentNodePath(String experimentId) { - return ZKPaths.makePath(ZkConstants.ZOOKEEPER_EXPERIMENT_NODE, experimentId); + return orchestratorService.launchProcess(processId, airavataCredStoreToken, gatewayId); } } diff --git a/airavata-api/src/main/java/org/apache/airavata/registry/api/service/handler/RegistryServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/registry/api/service/handler/RegistryServerHandler.java index 61a1a0bf2b..54aee30298 100644 --- a/airavata-api/src/main/java/org/apache/airavata/registry/api/service/handler/RegistryServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/registry/api/service/handler/RegistryServerHandler.java @@ -63,7 +63,6 @@ import org.apache.airavata.registry.api.RegistryService; import org.apache.airavata.registry.api.exception.RegistryServiceException; import org.apache.airavata.registry.api.registry_apiConstants; -import org.apache.airavata.registry.cpi.AppCatalogException; import org.apache.airavata.registry.cpi.RegistryException; import org.apache.thrift.TException; import org.slf4j.Logger; @@ -76,14 +75,7 @@ public class RegistryServerHandler implements RegistryService.Iface { new org.apache.airavata.service.RegistryService(); // Helper method to convert domain exceptions to Thrift exceptions - private RegistryServiceException convertToRegistryServiceException(RegistryException e, String context) { - logger.error(context, e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage(context + ". More info : " + e.getMessage()); - return exception; - } - - private RegistryServiceException convertToRegistryServiceException(AppCatalogException e, String context) { + private RegistryServiceException convertToRegistryServiceException(Throwable e, String context) { logger.error(context, e); RegistryServiceException exception = new RegistryServiceException(); exception.setMessage(context + ". More info : " + e.getMessage()); @@ -107,14 +99,7 @@ public String getAPIVersion() throws TException { */ @Override public boolean isUserExists(String gatewayId, String userName) throws RegistryServiceException, TException { - try { - return registryService.isUserExists(gatewayId, userName); - } catch (RegistryException e) { - logger.error("Error while verifying user", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while verifying user. More info : " + e.getMessage()); - throw exception; - } + return registryService.isUserExists(gatewayId, userName); } /** @@ -126,14 +111,7 @@ public boolean isUserExists(String gatewayId, String userName) throws RegistrySe */ @Override public List getAllUsersInGateway(String gatewayId) throws RegistryServiceException, TException { - try { - return registryService.getAllUsersInGateway(gatewayId); - } catch (RegistryException e) { - logger.error("Error while retrieving users", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retrieving users. More info : " + e.getMessage()); - throw exception; - } + return registryService.getAllUsersInGateway(gatewayId); } /** @@ -145,14 +123,7 @@ public List getAllUsersInGateway(String gatewayId) throws RegistryServic */ @Override public Gateway getGateway(String gatewayId) throws RegistryServiceException, TException { - try { - return registryService.getGateway(gatewayId); - } 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; - } + return registryService.getGateway(gatewayId); } /** @@ -164,14 +135,7 @@ public Gateway getGateway(String gatewayId) throws RegistryServiceException, TEx */ @Override public boolean deleteGateway(String gatewayId) throws RegistryServiceException, TException { - try { - return registryService.deleteGateway(gatewayId); - } catch (RegistryException e) { - logger.error("Error while deleting the gateway", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while deleting the gateway. More info : " + e.getMessage()); - throw exception; - } + return registryService.deleteGateway(gatewayId); } /** @@ -181,7 +145,7 @@ public boolean deleteGateway(String gatewayId) throws RegistryServiceException, public List getAllGateways() throws RegistryServiceException, TException { try { return registryService.getAllGateways(); - } catch (RegistryException e) { + } catch (Throwable 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()); @@ -200,7 +164,7 @@ public List getAllGateways() throws RegistryServiceException, TExceptio public boolean isGatewayExist(String gatewayId) throws RegistryServiceException, TException { try { return registryService.isGatewayExist(gatewayId); - } catch (RegistryException e) { + } catch (Throwable e) { logger.error("Error while getting gateway", e); RegistryServiceException exception = new RegistryServiceException(); exception.setMessage("Error while getting gateway. More info : " + e.getMessage()); @@ -213,7 +177,7 @@ public boolean deleteNotification(String gatewayId, String notificationId) throws RegistryServiceException, TException { try { return registryService.deleteNotification(gatewayId, notificationId); - } catch (RegistryException e) { + } catch (Throwable e) { logger.error("Error while deleting notification", e); RegistryServiceException exception = new RegistryServiceException(); exception.setMessage("Error while deleting notification. More info : " + e.getMessage()); @@ -226,7 +190,7 @@ public Notification getNotification(String gatewayId, String notificationId) throws RegistryServiceException, TException { try { return registryService.getNotification(gatewayId, notificationId); - } catch (RegistryException e) { + } catch (Throwable e) { logger.error("Error while retrieving notification", e); RegistryServiceException exception = new RegistryServiceException(); exception.setMessage("Error while retreiving notification. More info : " + e.getMessage()); @@ -238,7 +202,7 @@ public Notification getNotification(String gatewayId, String notificationId) public List getAllNotifications(String gatewayId) throws RegistryServiceException, TException { try { return registryService.getAllNotifications(gatewayId); - } catch (RegistryException e) { + } catch (Throwable e) { logger.error("Error while getting all notifications", e); RegistryServiceException exception = new RegistryServiceException(); exception.setMessage("Error while getting all notifications. More info : " + e.getMessage()); @@ -258,11 +222,8 @@ public List getAllNotifications(String gatewayId) throws RegistryS public Project getProject(String projectId) throws RegistryServiceException, TException { try { return registryService.getProject(projectId); - } 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; + } catch (Throwable e) { + throw convertToRegistryServiceException(e, "Error while retrieving the project"); } } @@ -280,7 +241,7 @@ public Project getProject(String projectId) throws RegistryServiceException, TEx public boolean deleteProject(String projectId) throws RegistryServiceException, TException { try { return registryService.deleteProject(projectId); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while removing the project"); } } @@ -299,7 +260,7 @@ public List getUserProjects(String gatewayId, String userName, int limi throws RegistryServiceException, TException { try { return registryService.getUserProjects(gatewayId, userName, limit, offset); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving projects"); } } @@ -335,7 +296,7 @@ public ExperimentStatistics getExperimentStatistics( accessibleExpIds, limit, offset); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving experiments"); } } @@ -354,7 +315,7 @@ public List getExperimentsInProject(String gatewayId, String pr throws RegistryServiceException, TException { try { return registryService.getExperimentsInProject(gatewayId, projectId, limit, offset); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving the experiments"); } } @@ -373,7 +334,7 @@ public List getUserExperiments(String gatewayId, String userNam throws RegistryServiceException, TException { try { return registryService.getUserExperiments(gatewayId, userName, limit, offset); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving the experiments"); } } @@ -389,7 +350,7 @@ public List getUserExperiments(String gatewayId, String userNam public boolean deleteExperiment(String experimentId) throws RegistryServiceException, TException { try { return registryService.deleteExperiment(experimentId); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while deleting the experiment"); } } @@ -468,7 +429,7 @@ public ExperimentModel getDetailedExperimentTree(String airavataExperimentId) throws RegistryServiceException, TException { try { return registryService.getDetailedExperimentTree(airavataExperimentId); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving the experiment"); } } @@ -487,7 +448,7 @@ public ExperimentStatus getExperimentStatus(String airavataExperimentId) throws RegistryServiceException, TException { try { return registryService.getExperimentStatus(airavataExperimentId); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving experiment status"); } } @@ -505,7 +466,7 @@ public List getExperimentOutputs(String airavataExperiment throws RegistryServiceException, TException { try { return registryService.getExperimentOutputs(airavataExperimentId); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving the experiment outputs"); } } @@ -523,7 +484,7 @@ public List getIntermediateOutputs(String airavataExperime throws RegistryServiceException, TException { try { return registryService.getIntermediateOutputs(airavataExperimentId); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving intermediate outputs"); } } @@ -540,7 +501,7 @@ public Map getJobStatuses(String airavataExperimentId) throws RegistryServiceException, TException { try { return registryService.getJobStatuses(airavataExperimentId); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving the job statuses"); } } @@ -550,7 +511,7 @@ public void addExperimentProcessOutputs(String outputType, List getProcessList(String experimentId) throws RegistryServiceException, TException { try { return registryService.getProcessList(experimentId); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving process list"); } } @@ -701,7 +662,7 @@ public List getProcessList(String experimentId) throws RegistrySer public ProcessStatus getProcessStatus(String processId) throws RegistryServiceException, TException { try { return registryService.getProcessStatus(processId); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving process status"); } } @@ -711,7 +672,7 @@ public List getProcessListInState(ProcessState processState) throws RegistryServiceException, TException { try { return registryService.getProcessListInState(processState); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving process list with given status"); } } @@ -720,7 +681,7 @@ public List getProcessListInState(ProcessState processState) public List getProcessStatusList(String processId) throws RegistryServiceException, TException { try { return registryService.getProcessStatusList(processId); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException( e, "Error while retrieving process status list for given process Id"); } @@ -733,7 +694,7 @@ public List getProcessStatusList(String processId) throws Registr public boolean isJobExist(String queryType, String id) throws RegistryServiceException, TException { try { return registryService.isJobExist(queryType, id); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving job"); } } @@ -745,7 +706,7 @@ public boolean isJobExist(String queryType, String id) throws RegistryServiceExc public JobModel getJob(String queryType, String id) throws RegistryServiceException, TException { try { return registryService.getJob(queryType, id); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving job"); } } @@ -754,7 +715,7 @@ public JobModel getJob(String queryType, String id) throws RegistryServiceExcept public List getJobs(String queryType, String id) throws RegistryServiceException, TException { try { return registryService.getJobs(queryType, id); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException( e, "Error while retrieving jobs for query " + queryType + " and id " + id); } @@ -766,7 +727,7 @@ public int getJobCount( throws RegistryServiceException, TException { try { return registryService.getJobCount(jobStatus, gatewayId, searchBackTimeInMinutes); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while getting job count"); } } @@ -776,7 +737,7 @@ public Map getAVGTimeDistribution(String gatewayId, double searc throws RegistryServiceException, TException { try { return registryService.getAVGTimeDistribution(gatewayId, searchBackTimeInMinutes); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while getting average time distribution"); } } @@ -785,7 +746,7 @@ public Map getAVGTimeDistribution(String gatewayId, double searc public List getProcessOutputs(String processId) throws RegistryServiceException, TException { try { return registryService.getProcessOutputs(processId); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving process outputs"); } } @@ -794,7 +755,7 @@ public List getProcessOutputs(String processId) throws Reg public List getProcessWorkflows(String processId) throws RegistryServiceException, TException { try { return registryService.getProcessWorkflows(processId); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException( e, "Error while retrieving process workflows for process id " + processId); } @@ -804,7 +765,7 @@ public List getProcessWorkflows(String processId) throws Regist public void addProcessWorkflow(ProcessWorkflow processWorkflow) throws RegistryServiceException, TException { try { registryService.addProcessWorkflow(processWorkflow); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException( e, "Error while adding process workflows for process id " + processWorkflow.getProcessId()); } @@ -814,7 +775,7 @@ public void addProcessWorkflow(ProcessWorkflow processWorkflow) throws RegistryS public List getProcessIds(String experimentId) throws RegistryServiceException, TException { try { return registryService.getProcessIds(experimentId); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving process ids"); } } @@ -830,7 +791,7 @@ public List getProcessIds(String experimentId) throws RegistryServiceExc public List getJobDetails(String airavataExperimentId) throws RegistryServiceException, TException { try { return registryService.getJobDetails(airavataExperimentId); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving the job details"); } } @@ -846,7 +807,7 @@ public List getJobDetails(String airavataExperimentId) throws Registry public ApplicationModule getApplicationModule(String appModuleId) throws RegistryServiceException, TException { try { return registryService.getApplicationModule(appModuleId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving application module"); } } @@ -862,7 +823,7 @@ public ApplicationModule getApplicationModule(String appModuleId) throws Registr public List getAllAppModules(String gatewayId) throws RegistryServiceException, TException { try { return registryService.getAllAppModules(gatewayId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving all application modules"); } } @@ -881,7 +842,7 @@ public List getAccessibleAppModules( throws RegistryServiceException, TException { try { return registryService.getAccessibleAppModules(gatewayId, accessibleAppIds, accessibleComputeResourceIds); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving all application modules"); } } @@ -897,7 +858,7 @@ public List getAccessibleAppModules( public boolean deleteApplicationModule(String appModuleId) throws RegistryServiceException, TException { try { return registryService.deleteApplicationModule(appModuleId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while deleting the application module"); } } @@ -914,7 +875,7 @@ public ApplicationDeploymentDescription getApplicationDeployment(String appDeplo throws RegistryServiceException, TException { try { return registryService.getApplicationDeployment(appDeploymentId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving application deployment"); } } @@ -930,7 +891,7 @@ public ApplicationDeploymentDescription getApplicationDeployment(String appDeplo public boolean deleteApplicationDeployment(String appDeploymentId) throws RegistryServiceException, TException { try { return registryService.deleteApplicationDeployment(appDeploymentId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while deleting application deployment"); } } @@ -948,7 +909,7 @@ public List getAllApplicationDeployments(Strin throws RegistryServiceException, TException { try { return registryService.getAllApplicationDeployments(gatewayId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving application deployments"); } } @@ -968,7 +929,7 @@ public List getAccessibleApplicationDeployment try { return registryService.getAccessibleApplicationDeployments( gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving application deployments"); } } @@ -993,7 +954,7 @@ public List getAccessibleApplicationDeployment try { return registryService.getAccessibleApplicationDeploymentsForAppModule( gatewayId, appModuleId, accessibleAppDeploymentIds, accessibleComputeResourceIds); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving application deployments"); } } @@ -1009,7 +970,7 @@ public List getAccessibleApplicationDeployment public List getAppModuleDeployedResources(String appModuleId) throws RegistryServiceException, TException { try { return registryService.getAppModuleDeployedResources(appModuleId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving application deployment"); } } @@ -1019,7 +980,7 @@ public List getApplicationDeployments(String a throws RegistryServiceException, TException { try { return registryService.getApplicationDeployments(appModuleId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving application deployment"); } } @@ -1036,7 +997,7 @@ public ApplicationInterfaceDescription getApplicationInterface(String appInterfa throws RegistryServiceException, TException { try { return registryService.getApplicationInterface(appInterfaceId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving application interface"); } } @@ -1052,7 +1013,7 @@ public ApplicationInterfaceDescription getApplicationInterface(String appInterfa public boolean deleteApplicationInterface(String appInterfaceId) throws RegistryServiceException, TException { try { return registryService.deleteApplicationInterface(appInterfaceId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while deleting application interface"); } } @@ -1069,7 +1030,7 @@ public Map getAllApplicationInterfaceNames(String gatewayId) throws RegistryServiceException, TException { try { return registryService.getAllApplicationInterfaceNames(gatewayId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving application interfaces"); } } @@ -1086,7 +1047,7 @@ public List getAllApplicationInterfaces(String throws RegistryServiceException, TException { try { return registryService.getAllApplicationInterfaces(gatewayId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving application interfaces"); } } @@ -1103,7 +1064,7 @@ public List getApplicationInputs(String appInterfaceId) throws RegistryServiceException, TException { try { return registryService.getApplicationInputs(appInterfaceId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving application inputs"); } } @@ -1120,7 +1081,7 @@ public List getApplicationOutputs(String appInterfaceId) throws RegistryServiceException, TException { try { return registryService.getApplicationOutputs(appInterfaceId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving application outputs"); } } @@ -1138,7 +1099,7 @@ public Map getAvailableAppInterfaceComputeResources(String appIn throws RegistryServiceException, TException { try { return registryService.getAvailableAppInterfaceComputeResources(appInterfaceId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving available compute resources"); } } @@ -1155,7 +1116,7 @@ public ComputeResourceDescription getComputeResource(String computeResourceId) throws RegistryServiceException, TException { try { return registryService.getComputeResource(computeResourceId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving compute resource"); } } @@ -1170,7 +1131,7 @@ public ComputeResourceDescription getComputeResource(String computeResourceId) public Map getAllComputeResourceNames() throws RegistryServiceException, TException { try { return registryService.getAllComputeResourceNames(); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving compute resource"); } } @@ -1186,7 +1147,7 @@ public Map getAllComputeResourceNames() throws RegistryServiceEx public boolean deleteComputeResource(String computeResourceId) throws RegistryServiceException, TException { try { return registryService.deleteComputeResource(computeResourceId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while deleting compute resource"); } } @@ -1203,7 +1164,7 @@ public StorageResourceDescription getStorageResource(String storageResourceId) throws RegistryServiceException, TException { try { return registryService.getStorageResource(storageResourceId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving storage resource"); } } @@ -1218,7 +1179,7 @@ public StorageResourceDescription getStorageResource(String storageResourceId) public Map getAllStorageResourceNames() throws RegistryServiceException, TException { try { return registryService.getAllStorageResourceNames(); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving storage resource"); } } @@ -1234,7 +1195,7 @@ public Map getAllStorageResourceNames() throws RegistryServiceEx public boolean deleteStorageResource(String storageResourceId) throws RegistryServiceException, TException { try { return registryService.deleteStorageResource(storageResourceId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while deleting storage resource"); } } @@ -1248,7 +1209,7 @@ public boolean deleteStorageResource(String storageResourceId) throws RegistrySe public LOCALSubmission getLocalJobSubmission(String jobSubmissionId) throws RegistryServiceException, TException { try { return registryService.getLocalJobSubmission(jobSubmissionId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving local job submission interface"); } } @@ -1262,7 +1223,7 @@ public LOCALSubmission getLocalJobSubmission(String jobSubmissionId) throws Regi public SSHJobSubmission getSSHJobSubmission(String jobSubmissionId) throws RegistryServiceException, TException { try { return registryService.getSSHJobSubmission(jobSubmissionId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving SSH job submission interface"); } } @@ -1284,7 +1245,7 @@ public UnicoreJobSubmission getUnicoreJobSubmission(String jobSubmissionId) throws RegistryServiceException, TException { try { return registryService.getUnicoreJobSubmission(jobSubmissionId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving Unicore job submission interface"); } } @@ -1304,7 +1265,7 @@ public CloudJobSubmission getCloudJobSubmission(String jobSubmissionId) throws RegistryServiceException, TException { try { return registryService.getCloudJobSubmission(jobSubmissionId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving Cloud job submission interface"); } } @@ -1319,7 +1280,7 @@ public CloudJobSubmission getCloudJobSubmission(String jobSubmissionId) public LOCALDataMovement getLocalDataMovement(String dataMovementId) throws RegistryServiceException, TException { try { return registryService.getLocalDataMovement(dataMovementId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving local data movement interface"); } } @@ -1334,7 +1295,7 @@ public LOCALDataMovement getLocalDataMovement(String dataMovementId) throws Regi public SCPDataMovement getSCPDataMovement(String dataMovementId) throws RegistryServiceException, TException { try { return registryService.getSCPDataMovement(dataMovementId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving SCP data movement interface"); } } @@ -1350,7 +1311,7 @@ public UnicoreDataMovement getUnicoreDataMovement(String dataMovementId) throws RegistryServiceException, TException { try { return registryService.getUnicoreDataMovement(dataMovementId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving UNICORE data movement interface"); } } @@ -1366,7 +1327,7 @@ public GridFTPDataMovement getGridFTPDataMovement(String dataMovementId) throws RegistryServiceException, TException { try { return registryService.getGridFTPDataMovement(dataMovementId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving GridFTP data movement interface"); } } @@ -1438,7 +1399,7 @@ public boolean deleteJobSubmissionInterface(String computeResourceId, String job throws RegistryServiceException, TException { try { return registryService.deleteJobSubmissionInterface(computeResourceId, jobSubmissionInterfaceId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while deleting job submission interface"); } } @@ -1448,7 +1409,7 @@ public ResourceJobManager getResourceJobManager(String resourceJobManagerId) throws RegistryServiceException, TException { try { return registryService.getResourceJobManager(resourceJobManagerId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving resource job manager"); } } @@ -1457,7 +1418,7 @@ public ResourceJobManager getResourceJobManager(String resourceJobManagerId) public boolean deleteResourceJobManager(String resourceJobManagerId) throws RegistryServiceException, TException { try { return registryService.deleteResourceJobManager(resourceJobManagerId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while deleting resource job manager"); } } @@ -1475,7 +1436,7 @@ public boolean deleteBatchQueue(String computeResourceId, String queueName) throws RegistryServiceException, TException { try { return registryService.deleteBatchQueue(computeResourceId, queueName); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while deleting batch queue"); } } @@ -1492,7 +1453,7 @@ public GatewayResourceProfile getGatewayResourceProfile(String gatewayID) throws RegistryServiceException, TException { try { return registryService.getGatewayResourceProfile(gatewayID); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving gateway resource profile"); } } @@ -1508,7 +1469,7 @@ public GatewayResourceProfile getGatewayResourceProfile(String gatewayID) public boolean deleteGatewayResourceProfile(String gatewayID) throws RegistryServiceException, TException { try { return registryService.deleteGatewayResourceProfile(gatewayID); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while removing gateway resource profile"); } } @@ -1526,7 +1487,7 @@ public ComputeResourcePreference getGatewayComputeResourcePreference(String gate throws RegistryServiceException, TException { try { return registryService.getGatewayComputeResourcePreference(gatewayID, computeResourceId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while reading gateway compute resource preference"); } } @@ -1544,7 +1505,7 @@ public StoragePreference getGatewayStoragePreference(String gatewayID, String st throws RegistryServiceException, TException { try { return registryService.getGatewayStoragePreference(gatewayID, storageId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while reading gateway data storage preference"); } } @@ -1561,7 +1522,7 @@ public List getAllGatewayComputeResourcePreferences(S throws RegistryServiceException, TException { try { return registryService.getAllGatewayComputeResourcePreferences(gatewayID); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while reading gateway compute resource preferences"); } } @@ -1578,7 +1539,7 @@ public List getAllGatewayStoragePreferences(String gatewayID) throws RegistryServiceException, TException { try { return registryService.getAllGatewayStoragePreferences(gatewayID); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while reading gateway data storage preferences"); } } @@ -1593,7 +1554,7 @@ public List getAllGatewayStoragePreferences(String gatewayID) public List getAllGatewayResourceProfiles() throws RegistryServiceException, TException { try { return registryService.getAllGatewayResourceProfiles(); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while reading retrieving all gateway profiles"); } } @@ -1611,7 +1572,7 @@ public boolean deleteGatewayComputeResourcePreference(String gatewayID, String c throws RegistryServiceException, TException { try { return registryService.deleteGatewayComputeResourcePreference(gatewayID, computeResourceId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while updating gateway compute resource preference"); } } @@ -1629,7 +1590,7 @@ public boolean deleteGatewayStoragePreference(String gatewayID, String storageId throws RegistryServiceException, TException { try { return registryService.deleteGatewayStoragePreference(gatewayID, storageId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while updating gateway data storage preference"); } } @@ -1638,7 +1599,7 @@ public boolean deleteGatewayStoragePreference(String gatewayID, String storageId public DataProductModel getDataProduct(String productUri) throws RegistryServiceException, TException { try { return registryService.getDataProduct(productUri); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error in retreiving the data product " + productUri); } } @@ -1647,7 +1608,7 @@ public DataProductModel getDataProduct(String productUri) throws RegistryService public DataProductModel getParentDataProduct(String productUri) throws RegistryServiceException, TException { try { return registryService.getParentDataProduct(productUri); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error in retreiving the parent data product for " + productUri); } } @@ -1656,7 +1617,7 @@ public DataProductModel getParentDataProduct(String productUri) throws RegistryS public List getChildDataProducts(String productUri) throws RegistryServiceException, TException { try { return registryService.getChildDataProducts(productUri); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error in retreiving the child products for " + productUri); } } @@ -1667,7 +1628,7 @@ public List searchDataProductsByName( throws RegistryServiceException, TException { try { return registryService.searchDataProductsByName(gatewayId, userId, productName, limit, offset); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error in searching the data products for name " + productName); } } @@ -1677,7 +1638,7 @@ public String createGroupResourceProfile(GroupResourceProfile groupResourceProfi throws RegistryServiceException, TException { try { return registryService.createGroupResourceProfile(groupResourceProfile); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while creating group resource profile"); } } @@ -1687,7 +1648,7 @@ public void updateGroupResourceProfile(GroupResourceProfile groupResourceProfile throws RegistryServiceException, TException { try { registryService.updateGroupResourceProfile(groupResourceProfile); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while updating group resource profile"); } } @@ -1697,7 +1658,7 @@ public GroupResourceProfile getGroupResourceProfile(String groupResourceProfileI throws RegistryServiceException, TException { try { return registryService.getGroupResourceProfile(groupResourceProfileId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving group resource profile"); } } @@ -1707,7 +1668,7 @@ public boolean isGroupResourceProfileExists(String groupResourceProfileId) throws RegistryServiceException, TException { try { return registryService.isGroupResourceProfileExists(groupResourceProfileId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving group resource profile"); } } @@ -1717,7 +1678,7 @@ public boolean removeGroupResourceProfile(String groupResourceProfileId) throws RegistryServiceException, TException { try { return registryService.removeGroupResourceProfile(groupResourceProfileId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while removing group resource profile"); } } @@ -1727,7 +1688,7 @@ public List getGroupResourceList(String gatewayId, List getGroupComputeResourcePrefList(Stri throws RegistryServiceException, TException { try { return registryService.getGroupComputeResourcePrefList(groupResourceProfileId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException( e, "Error while retrieving retrieving Group Compute Resource Preference list"); } @@ -1818,7 +1779,7 @@ public List getGroupBatchQueueResourcePolicyList(Strin throws RegistryServiceException, TException { try { return registryService.getGroupBatchQueueResourcePolicyList(groupResourceProfileId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException( e, "Error while retrieving retrieving Group Batch Queue Resource policy list"); } @@ -1829,7 +1790,7 @@ public List getGroupComputeResourcePolicyList(String grou throws RegistryServiceException, TException { try { return registryService.getGroupComputeResourcePolicyList(groupResourceProfileId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException( e, "Error while retrieving retrieving Group Compute Resource policy list"); } @@ -1840,7 +1801,7 @@ public String registerReplicaLocation(DataReplicaLocationModel replicaLocationMo throws RegistryServiceException, TException { try { return registryService.registerReplicaLocation(replicaLocationModel); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException( e, "Error in retreiving the replica " + replicaLocationModel.getReplicaName()); } @@ -1855,7 +1816,7 @@ public String registerReplicaLocation(DataReplicaLocationModel replicaLocationMo public String registerDataProduct(DataProductModel dataProductModel) throws RegistryServiceException, TException { try { return registryService.registerDataProduct(dataProductModel); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException( e, "Error in registering the data resource" + dataProductModel.getProductName()); } @@ -1876,7 +1837,7 @@ public boolean updateGatewayStoragePreference( throws RegistryServiceException, TException { try { return registryService.updateGatewayStoragePreference(gatewayID, storageId, storagePreference); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while updating gateway data storage preference"); } } @@ -1897,7 +1858,7 @@ public boolean updateGatewayComputeResourcePreference( try { return registryService.updateGatewayComputeResourcePreference( gatewayID, computeResourceId, computeResourcePreference); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while updating gateway compute resource preference"); } } @@ -1918,7 +1879,7 @@ public boolean addGatewayStoragePreference( throws RegistryServiceException, TException { try { return registryService.addGatewayStoragePreference(gatewayID, storageResourceId, dataStoragePreference); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while registering gateway resource profile preference"); } } @@ -1940,7 +1901,7 @@ public boolean addGatewayComputeResourcePreference( try { return registryService.addGatewayComputeResourcePreference( gatewayID, computeResourceId, computeResourcePreference); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while registering gateway resource profile preference"); } } @@ -1958,7 +1919,7 @@ public boolean updateGatewayResourceProfile(String gatewayID, GatewayResourcePro throws RegistryServiceException, TException { try { return registryService.updateGatewayResourceProfile(gatewayID, gatewayResourceProfile); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while updating gateway resource profile"); } } @@ -1977,7 +1938,7 @@ public String registerGatewayResourceProfile(GatewayResourceProfile gatewayResou throws RegistryServiceException, TException { try { return registryService.registerGatewayResourceProfile(gatewayResourceProfile); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while registering gateway resource profile"); } } @@ -1987,7 +1948,7 @@ public boolean updateResourceJobManager(String resourceJobManagerId, ResourceJob throws RegistryServiceException, TException { try { return registryService.updateResourceJobManager(resourceJobManagerId, updatedResourceJobManager); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while updating resource job manager"); } } @@ -1997,7 +1958,7 @@ public String registerResourceJobManager(ResourceJobManager resourceJobManager) throws RegistryServiceException, TException { try { return registryService.registerResourceJobManager(resourceJobManager); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while adding resource job manager"); } } @@ -2015,7 +1976,7 @@ public boolean deleteDataMovementInterface(String resourceId, String dataMovemen throws RegistryServiceException, TException { try { return registryService.deleteDataMovementInterface(resourceId, dataMovementInterfaceId, dmType); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while deleting data movement interface"); } } @@ -2055,7 +2016,7 @@ public String addGridFTPDataMovementDetails( try { return registryService.addGridFTPDataMovementDetails( computeResourceId, dmType, priorityOrder, gridFTPDataMovement); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException( e, "Error while adding data movement interface to resource compute resource"); } @@ -2096,7 +2057,7 @@ public String addUnicoreDataMovementDetails( try { return registryService.addUnicoreDataMovementDetails( resourceId, dmType, priorityOrder, unicoreDataMovement); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException( e, "Error while adding data movement interface to resource compute resource"); } @@ -2116,7 +2077,7 @@ public boolean updateSCPDataMovementDetails(String dataMovementInterfaceId, SCPD throws RegistryServiceException, TException { try { return registryService.updateSCPDataMovementDetails(dataMovementInterfaceId, scpDataMovement); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while updating SCP data movement"); } } @@ -2139,7 +2100,7 @@ public String addSCPDataMovementDetails( throws RegistryServiceException, TException { try { return registryService.addSCPDataMovementDetails(resourceId, dmType, priorityOrder, scpDataMovement); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException( e, "Error while adding data movement interface to resource compute resource"); } @@ -2158,7 +2119,7 @@ public boolean updateLocalDataMovementDetails(String dataMovementInterfaceId, LO throws RegistryServiceException, TException { try { return registryService.updateLocalDataMovementDetails(dataMovementInterfaceId, localDataMovement); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while updating local data movement interface"); } } @@ -2182,7 +2143,7 @@ public String addLocalDataMovementDetails( try { return registryService.addLocalDataMovementDetails( resourceId, dataMoveType, priorityOrder, localDataMovement); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while adding data movement interface to resource"); } } @@ -2215,7 +2176,7 @@ public boolean updateCloudJobSubmissionDetails(String jobSubmissionInterfaceId, throws RegistryServiceException, TException { try { return registryService.updateCloudJobSubmissionDetails(jobSubmissionInterfaceId, sshJobSubmission); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while updating Cloud job submission"); } } @@ -2233,7 +2194,7 @@ public boolean updateSSHJobSubmissionDetails(String jobSubmissionInterfaceId, SS throws RegistryServiceException, TException { try { return registryService.updateSSHJobSubmissionDetails(jobSubmissionInterfaceId, sshJobSubmission); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while updating SSH job submission"); } } @@ -2267,7 +2228,7 @@ public String addCloudJobSubmissionDetails( throws RegistryServiceException, TException { try { return registryService.addCloudJobSubmissionDetails(computeResourceId, priorityOrder, cloudSubmission); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException( e, "Error while adding job submission interface to resource compute resource"); } @@ -2290,7 +2251,7 @@ public String addUNICOREJobSubmissionDetails( try { return registryService.addUNICOREJobSubmissionDetails( computeResourceId, priorityOrder, unicoreJobSubmission); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException( e, "Error while adding job submission interface to resource compute resource"); } @@ -2312,7 +2273,7 @@ public String addSSHForkJobSubmissionDetails( throws RegistryServiceException, TException { try { return registryService.addSSHForkJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException( e, "Error while adding job submission interface to resource compute resource"); } @@ -2334,7 +2295,7 @@ public String addSSHJobSubmissionDetails( throws RegistryServiceException, TException { try { return registryService.addSSHJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException( e, "Error while adding job submission interface to resource compute resource"); } @@ -2353,7 +2314,7 @@ public boolean updateLocalSubmissionDetails(String jobSubmissionInterfaceId, LOC throws RegistryServiceException, TException { try { return registryService.updateLocalSubmissionDetails(jobSubmissionInterfaceId, localSubmission); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while updating local job submission"); } } @@ -2374,7 +2335,7 @@ public String addLocalSubmissionDetails( throws RegistryServiceException, TException { try { return registryService.addLocalSubmissionDetails(computeResourceId, priorityOrder, localSubmission); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException( e, "Error while adding job submission interface to resource compute resource"); } @@ -2394,7 +2355,7 @@ public boolean updateStorageResource( throws RegistryServiceException, TException { try { return registryService.updateStorageResource(storageResourceId, storageResourceDescription); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while updating storage resource"); } } @@ -2411,7 +2372,7 @@ public String registerStorageResource(StorageResourceDescription storageResource throws RegistryServiceException, TException { try { return registryService.registerStorageResource(storageResourceDescription); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while saving storage resource"); } } @@ -2430,7 +2391,7 @@ public boolean updateComputeResource( throws RegistryServiceException, TException { try { return registryService.updateComputeResource(computeResourceId, computeResourceDescription); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while updating compute resource"); } } @@ -2447,7 +2408,7 @@ public String registerComputeResource(ComputeResourceDescription computeResource throws RegistryServiceException, TException { try { return registryService.registerComputeResource(computeResourceDescription); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while saving compute resource"); } } @@ -2466,7 +2427,7 @@ public boolean updateApplicationInterface( throws RegistryServiceException, TException { try { return registryService.updateApplicationInterface(appInterfaceId, applicationInterface); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while updating application interface"); } } @@ -2484,7 +2445,7 @@ public String registerApplicationInterface(String gatewayId, ApplicationInterfac throws RegistryServiceException, TException { try { return registryService.registerApplicationInterface(gatewayId, applicationInterface); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while adding application interface"); } } @@ -2503,7 +2464,7 @@ public boolean updateApplicationDeployment( throws RegistryServiceException, TException { try { return registryService.updateApplicationDeployment(appDeploymentId, applicationDeployment); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while updating application deployment"); } } @@ -2522,7 +2483,7 @@ public String registerApplicationDeployment( throws RegistryServiceException, TException { try { return registryService.registerApplicationDeployment(gatewayId, applicationDeployment); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while adding application deployment"); } } @@ -2540,7 +2501,7 @@ public boolean updateApplicationModule(String appModuleId, ApplicationModule app throws RegistryServiceException, TException { try { return registryService.updateApplicationModule(appModuleId, applicationModule); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while updating application module"); } } @@ -2559,7 +2520,7 @@ public String registerApplicationModule(String gatewayId, ApplicationModule appl throws RegistryServiceException, TException { try { return registryService.registerApplicationModule(gatewayId, applicationModule); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while adding application module"); } } @@ -2570,7 +2531,7 @@ public void updateResourceScheduleing( throws RegistryServiceException, TException { try { registryService.updateResourceScheduleing(airavataExperimentId, resourceScheduling); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while updating scheduling info"); } } @@ -2580,7 +2541,7 @@ public void updateExperimentConfiguration(String airavataExperimentId, UserConfi throws RegistryServiceException, TException { try { registryService.updateExperimentConfiguration(airavataExperimentId, userConfiguration); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while updating user configuration"); } } @@ -2614,7 +2575,7 @@ public void updateExperiment(String airavataExperimentId, ExperimentModel experi throws RegistryServiceException, TException { try { registryService.updateExperiment(airavataExperimentId, experiment); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while updating experiment"); } } @@ -2668,7 +2629,7 @@ public String createExperiment(String gatewayId, ExperimentModel experiment) throws RegistryServiceException, TException { try { return registryService.createExperiment(gatewayId, experiment); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while creating the experiment"); } } @@ -2696,7 +2657,7 @@ public List searchExperiments( throws RegistryServiceException, TException { try { return registryService.searchExperiments(gatewayId, userName, accessibleExpIds, filters, limit, offset); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving experiments"); } } @@ -2723,7 +2684,7 @@ public List searchProjects( throws RegistryServiceException, TException { try { return registryService.searchProjects(gatewayId, userName, accessibleProjIds, filters, limit, offset); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving projects"); } } @@ -2740,7 +2701,7 @@ public List searchProjects( public void updateProject(String projectId, Project updatedProject) throws RegistryServiceException, TException { try { registryService.updateProject(projectId, updatedProject); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while updating the project"); } } @@ -2756,7 +2717,7 @@ public void updateProject(String projectId, Project updatedProject) throws Regis public String createProject(String gatewayId, Project project) throws RegistryServiceException, TException { try { return registryService.createProject(gatewayId, project); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while creating the project"); } } @@ -2765,7 +2726,7 @@ public String createProject(String gatewayId, Project project) throws RegistrySe public boolean updateNotification(Notification notification) throws RegistryServiceException, TException { try { return registryService.updateNotification(notification); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while updating notification"); } } @@ -2780,7 +2741,7 @@ public boolean updateNotification(Notification notification) throws RegistryServ public String createNotification(Notification notification) throws RegistryServiceException, TException { try { return registryService.createNotification(notification); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while creating notification"); } } @@ -2798,10 +2759,8 @@ public String createNotification(Notification notification) throws RegistryServi public boolean updateGateway(String gatewayId, Gateway updatedGateway) throws RegistryServiceException, TException { try { return registryService.updateGateway(gatewayId, updatedGateway); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while updating the gateway"); - } catch (AppCatalogException e) { - throw convertToRegistryServiceException(e, "Error while updating gateway profile"); } } @@ -2816,35 +2775,12 @@ public boolean updateGateway(String gatewayId, Gateway updatedGateway) throws Re public String addGateway(Gateway gateway) throws RegistryServiceException, DuplicateEntryException, TException { try { return registryService.addGateway(gateway); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while adding gateway"); - } catch (AppCatalogException e) { - throw convertToRegistryServiceException(e, "Error while adding gateway profile"); } } - private boolean validateString(String name) { - boolean valid = true; - if (name == null || name.equals("") || name.trim().length() == 0) { - valid = false; - } - return valid; - } - /*Following method wraps the logic of isGatewayExist method and this is to be called by any other method of the API as needed.*/ - private boolean isGatewayExistInternal(String gatewayId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, - TException { - try { - return registryService.isGatewayExist(gatewayId); - } catch (RegistryException e) { - logger.error("Error while getting gateway", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while getting gateway. More info : " + e.getMessage()); - throw exception; - } - } /*This private method wraps the logic of getExperiment method as this method is called internally in the API.*/ private ExperimentModel getExperimentInternal(String airavataExperimentId) @@ -2852,7 +2788,7 @@ private ExperimentModel getExperimentInternal(String airavataExperimentId) AiravataSystemException, TException { try { return registryService.getExperiment(airavataExperimentId); - } catch (RegistryException e) { + } catch (Throwable e) { logger.error("Error while retrieving the experiment", e); RegistryServiceException exception = new RegistryServiceException(); exception.setMessage("Error while retrieving the experiment. More info : " + e.getMessage()); @@ -2860,35 +2796,6 @@ private ExperimentModel getExperimentInternal(String airavataExperimentId) } } - /*Private method wraps the logic of getExperimentStatus method since this method is called internally.*/ - private ExperimentStatus getExperimentStatusInternal(String airavataExperimentId) - throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, - AiravataSystemException, TException { - try { - return registryService.getExperimentStatus(airavataExperimentId); - } catch (RegistryException e) { - logger.error(airavataExperimentId, "Error while retrieving the experiment status", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving the experiment status. More info : " + e.getMessage()); - throw exception; - } - } - - /*This private method wraps the logic of getApplicationOutputs method as this method is called internally in the API.*/ - private List getApplicationOutputsInternal(String appInterfaceId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException { - try { - return registryService.getApplicationOutputs(appInterfaceId); - } catch (AppCatalogException e) { - logger.error(appInterfaceId, "Error while retrieving application outputs...", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving application outputs. More info : " + e.getMessage()); - throw exception; - } - } - /** * Register a User Resource Profile. * @@ -2903,7 +2810,7 @@ public String registerUserResourceProfile(UserResourceProfile userResourceProfil throws RegistryServiceException, TException { try { return registryService.registerUserResourceProfile(userResourceProfile); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while registering user resource profile"); } } @@ -2913,7 +2820,7 @@ public boolean isUserResourceProfileExists(String userId, String gatewayId) throws RegistryServiceException, TException { try { return registryService.isUserResourceProfileExists(userId, gatewayId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while checking existence of user resource profile"); } } @@ -2929,7 +2836,7 @@ public UserResourceProfile getUserResourceProfile(String userId, String gatewayI throws RegistryServiceException, TException { try { return registryService.getUserResourceProfile(userId, gatewayId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving user resource profile"); } } @@ -2947,7 +2854,7 @@ public boolean updateUserResourceProfile(String userId, String gatewayID, UserRe throws RegistryServiceException, TException { try { return registryService.updateUserResourceProfile(userId, gatewayID, userResourceProfile); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while updating gateway resource profile"); } } @@ -2965,7 +2872,7 @@ public boolean deleteUserResourceProfile(String userId, String gatewayID) throws RegistryServiceException, TException { try { return registryService.deleteUserResourceProfile(userId, gatewayID); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while removing User resource profile"); } } @@ -2975,7 +2882,7 @@ public String addUser(UserProfile userProfile) throws RegistryServiceException, DuplicateEntryException, TException { try { return registryService.addUser(userProfile); - } catch (RegistryException ex) { + } catch (Exception ex) { throw convertToRegistryServiceException(ex, "Error while adding user in registry"); } } @@ -3001,7 +2908,7 @@ public boolean addUserComputeResourcePreference( try { return registryService.addUserComputeResourcePreference( userId, gatewayID, computeResourceId, userComputeResourcePreference); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while registering user resource profile preference"); } } @@ -3020,7 +2927,7 @@ public boolean isUserComputeResourcePreferenceExists(String userId, String gatew throws RegistryServiceException, TException { try { return registryService.isUserComputeResourcePreferenceExists(userId, gatewayID, computeResourceId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while fetching compute resource preference"); } } @@ -3042,7 +2949,7 @@ public boolean addUserStoragePreference( try { return registryService.addUserStoragePreference( userId, gatewayID, storageResourceId, dataStoragePreference); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while registering user resource profile preference"); } } @@ -3061,7 +2968,7 @@ public UserComputeResourcePreference getUserComputeResourcePreference( String userId, String gatewayID, String userComputeResourceId) throws RegistryServiceException, TException { try { return registryService.getUserComputeResourcePreference(userId, gatewayID, userComputeResourceId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while reading user compute resource preference"); } } @@ -3080,7 +2987,7 @@ public UserStoragePreference getUserStoragePreference(String userId, String gate throws RegistryServiceException, TException { try { return registryService.getUserStoragePreference(userId, gatewayID, storageId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while reading gateway data storage preference"); } } @@ -3095,7 +3002,7 @@ public UserStoragePreference getUserStoragePreference(String userId, String gate public List getAllUserResourceProfiles() throws RegistryServiceException, TException { try { return registryService.getAllUserResourceProfiles(); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while reading retrieving all gateway profiles"); } } @@ -3120,7 +3027,7 @@ public boolean updateUserComputeResourcePreference( try { return registryService.updateUserComputeResourcePreference( userId, gatewayID, computeResourceId, userComputeResourcePreference); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while updating user compute resource preference"); } } @@ -3141,7 +3048,7 @@ public boolean updateUserStoragePreference( throws RegistryServiceException, TException { try { return registryService.updateUserStoragePreference(userId, gatewayID, storageId, userStoragePreference); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while updating user data storage preference"); } } @@ -3160,7 +3067,7 @@ public boolean deleteUserComputeResourcePreference(String userId, String gateway throws RegistryServiceException, TException { try { return registryService.deleteUserComputeResourcePreference(userId, gatewayID, computeResourceId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while deleting user compute resource preference"); } } @@ -3179,7 +3086,7 @@ public boolean deleteUserStoragePreference(String userId, String gatewayID, Stri throws RegistryServiceException, TException { try { return registryService.deleteUserStoragePreference(userId, gatewayID, storageId); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while deleting user storage preference"); } } @@ -3192,7 +3099,7 @@ public boolean deleteUserStoragePreference(String userId, String gatewayID, Stri public List getLatestQueueStatuses() throws RegistryServiceException, TException { try { return registryService.getLatestQueueStatuses(); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while reading queue status models"); } } @@ -3202,7 +3109,7 @@ public void registerQueueStatuses(List queueStatuses) throws RegistryServiceException, TException { try { registryService.registerQueueStatuses(queueStatuses); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while storing queue status models"); } } @@ -3212,7 +3119,7 @@ public QueueStatusModel getQueueStatus(String hostName, String queueName) throws RegistryServiceException, TException { try { return registryService.getQueueStatus(hostName, queueName); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving queue status"); } } @@ -3230,7 +3137,7 @@ public List getAllUserComputeResourcePreferences( throws RegistryServiceException, TException { try { return registryService.getAllUserComputeResourcePreferences(userId, gatewayID); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException( e, "Error while reading User Resource Profile compute resource preferences"); } @@ -3249,7 +3156,7 @@ public List getAllUserStoragePreferences(String userId, S throws RegistryServiceException, TException { try { return registryService.getAllUserStoragePreferences(userId, gatewayID); - } catch (AppCatalogException e) { + } catch (Throwable e) { throw convertToRegistryServiceException( e, "Error while reading user resource Profile data storage preferences"); } @@ -3260,7 +3167,7 @@ public void createGatewayGroups(GatewayGroups gatewayGroups) throws RegistryServiceException, DuplicateEntryException, TException { try { registryService.createGatewayGroups(gatewayGroups); - } catch (RegistryException e) { + } catch (Throwable e) { if (e.getMessage() != null && e.getMessage().contains("already exists")) { throw new DuplicateEntryException(e.getMessage()); } @@ -3272,7 +3179,7 @@ public void createGatewayGroups(GatewayGroups gatewayGroups) public void updateGatewayGroups(GatewayGroups gatewayGroups) throws RegistryServiceException, TException { try { registryService.updateGatewayGroups(gatewayGroups); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while updating GatewayGroups"); } } @@ -3281,7 +3188,7 @@ public void updateGatewayGroups(GatewayGroups gatewayGroups) throws RegistryServ public boolean isGatewayGroupsExists(String gatewayId) throws RegistryServiceException, TException { try { return registryService.isGatewayGroupsExists(gatewayId); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error checking existence of GatewayGroups"); } } @@ -3290,7 +3197,7 @@ public boolean isGatewayGroupsExists(String gatewayId) throws RegistryServiceExc public GatewayGroups getGatewayGroups(String gatewayId) throws RegistryServiceException, TException { try { return registryService.getGatewayGroups(gatewayId); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving GatewayGroups"); } } @@ -3299,7 +3206,7 @@ public GatewayGroups getGatewayGroups(String gatewayId) throws RegistryServiceEx public Parser getParser(String parserId, String gatewayId) throws RegistryServiceException, TException { try { return registryService.getParser(parserId, gatewayId); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving parser"); } } @@ -3308,7 +3215,7 @@ public Parser getParser(String parserId, String gatewayId) throws RegistryServic public String saveParser(Parser parser) throws RegistryServiceException, TException { try { return registryService.saveParser(parser); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while saving parser"); } } @@ -3317,7 +3224,7 @@ public String saveParser(Parser parser) throws RegistryServiceException, TExcept public List listAllParsers(String gatewayId) throws RegistryServiceException, TException { try { return registryService.listAllParsers(gatewayId); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while listing parsers"); } } @@ -3326,7 +3233,7 @@ public List listAllParsers(String gatewayId) throws RegistryServiceExcep public void removeParser(String parserId, String gatewayId) throws RegistryServiceException, TException { try { registryService.removeParser(parserId, gatewayId); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while removing parser"); } } @@ -3336,7 +3243,7 @@ public ParserInput getParserInput(String parserInputId, String gatewayId) throws RegistryServiceException, TException { try { return registryService.getParserInput(parserInputId, gatewayId); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving parser input"); } } @@ -3346,7 +3253,7 @@ public ParserOutput getParserOutput(String parserOutputId, String gatewayId) throws RegistryServiceException, TException { try { return registryService.getParserOutput(parserOutputId, gatewayId); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving parser output"); } } @@ -3356,7 +3263,7 @@ public ParsingTemplate getParsingTemplate(String templateId, String gatewayId) throws RegistryServiceException, TException { try { return registryService.getParsingTemplate(templateId, gatewayId); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving parsing template"); } } @@ -3366,7 +3273,7 @@ public List getParsingTemplatesForExperiment(String experimentI throws RegistryServiceException, TException { try { return registryService.getParsingTemplatesForExperiment(experimentId, gatewayId); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving parsing templates for experiment"); } } @@ -3375,7 +3282,7 @@ public List getParsingTemplatesForExperiment(String experimentI public String saveParsingTemplate(ParsingTemplate parsingTemplate) throws RegistryServiceException, TException { try { return registryService.saveParsingTemplate(parsingTemplate); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while saving parsing template"); } } @@ -3384,7 +3291,7 @@ public String saveParsingTemplate(ParsingTemplate parsingTemplate) throws Regist public List listAllParsingTemplates(String gatewayId) throws RegistryServiceException, TException { try { return registryService.listAllParsingTemplates(gatewayId); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while listing parsing templates"); } } @@ -3393,7 +3300,7 @@ public List listAllParsingTemplates(String gatewayId) throws Re public void removeParsingTemplate(String templateId, String gatewayId) throws RegistryServiceException, TException { try { registryService.removeParsingTemplate(templateId, gatewayId); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while removing parsing template"); } } @@ -3403,7 +3310,7 @@ public boolean isGatewayUsageReportingAvailable(String gatewayId, String compute throws RegistryServiceException, TException { try { return registryService.isGatewayUsageReportingAvailable(gatewayId, computeResourceId); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while checking gateway usage reporting availability"); } } @@ -3413,7 +3320,7 @@ public GatewayUsageReportingCommand getGatewayReportingCommand(String gatewayId, throws RegistryServiceException, TException { try { return registryService.getGatewayReportingCommand(gatewayId, computeResourceId); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while retrieving gateway reporting command"); } } @@ -3423,7 +3330,7 @@ public void addGatewayUsageReportingCommand(GatewayUsageReportingCommand command throws RegistryServiceException, TException { try { registryService.addGatewayUsageReportingCommand(command); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while adding gateway usage reporting command"); } } @@ -3433,7 +3340,7 @@ public void removeGatewayUsageReportingCommand(String gatewayId, String computeR throws RegistryServiceException, TException { try { registryService.removeGatewayUsageReportingCommand(gatewayId, computeResourceId); - } catch (RegistryException e) { + } catch (Throwable e) { throw convertToRegistryServiceException(e, "Error while removing gateway usage reporting command"); } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java b/airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java index 79d4ed6124..f6070b6a0e 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java @@ -36,8 +36,7 @@ import org.apache.airavata.common.utils.AiravataUtils; import org.apache.airavata.common.utils.Constants; import org.apache.airavata.common.utils.ServerSettings; -import org.apache.airavata.credential.store.cpi.CredentialStoreService; -import org.apache.airavata.credential.store.exception.CredentialStoreException; +import org.apache.airavata.credential.store.store.CredentialStoreException; import org.apache.airavata.messaging.core.MessageContext; import org.apache.airavata.messaging.core.Publisher; import org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription; @@ -104,6 +103,12 @@ import org.apache.airavata.model.workspace.Notification; import org.apache.airavata.model.workspace.Project; import org.apache.airavata.registry.api.RegistryService; +import org.apache.airavata.model.error.AiravataClientException; +import org.apache.airavata.model.error.AiravataSystemException; +import org.apache.airavata.model.error.AuthorizationException; +import org.apache.airavata.model.error.InvalidRequestException; +import org.apache.airavata.model.error.ProjectNotFoundException; +import org.apache.airavata.model.error.ExperimentNotFoundException; import org.apache.airavata.registry.cpi.AppCatalogException; import org.apache.airavata.registry.cpi.RegistryException; import org.apache.airavata.service.security.GatewayGroupsInitializer; @@ -116,7 +121,6 @@ import org.apache.airavata.sharing.registry.models.SearchCriteria; import org.apache.airavata.sharing.registry.models.User; import org.apache.airavata.sharing.registry.models.UserGroup; -import org.apache.airavata.sharing.registry.service.cpi.SharingRegistryService; import org.apache.thrift.TException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -124,92 +128,395 @@ public class AiravataService { private static final Logger logger = LoggerFactory.getLogger(AiravataService.class); + @SuppressWarnings("unchecked") + private static RuntimeException sneakyThrow(Throwable e) throws E { + throw (E) e; + } + + private RuntimeException convertException(Throwable e, String msg) { + if (e instanceof org.apache.airavata.model.error.InvalidRequestException || + e instanceof org.apache.airavata.model.error.AiravataClientException || + e instanceof org.apache.airavata.model.error.AiravataSystemException || + e instanceof org.apache.airavata.model.error.AuthorizationException || + e instanceof org.apache.airavata.model.error.ExperimentNotFoundException || + e instanceof org.apache.airavata.model.error.ProjectNotFoundException) { + throw sneakyThrow(e); + } + if (e instanceof RegistryException || e instanceof AppCatalogException || + e instanceof org.apache.airavata.credential.store.store.CredentialStoreException || + e instanceof org.apache.airavata.sharing.registry.models.SharingRegistryException) { + logger.error(msg, e); + org.apache.airavata.model.error.AiravataSystemException exception = new org.apache.airavata.model.error.AiravataSystemException(); + exception.setAiravataErrorType(org.apache.airavata.model.error.AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + ". More info : " + e.getMessage()); + throw sneakyThrow(exception); + } + logger.error(msg, e); + org.apache.airavata.model.error.AiravataSystemException exception = new org.apache.airavata.model.error.AiravataSystemException(); + exception.setAiravataErrorType(org.apache.airavata.model.error.AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + ". More info : " + e.getMessage()); + throw sneakyThrow(exception); + } + private org.apache.airavata.service.RegistryService registryService = new org.apache.airavata.service.RegistryService(); - public List getAllUsersInGateway(String gatewayId) throws RegistryException { - return registryService.getAllUsersInGateway(gatewayId); + private org.apache.airavata.service.SharingRegistryService sharingRegistryService = + new org.apache.airavata.service.SharingRegistryService(); + + private org.apache.airavata.service.CredentialStoreService credentialStoreService; + + public AiravataService() { + try { + credentialStoreService = new org.apache.airavata.service.CredentialStoreService(); + } catch (Exception e) { + logger.error("Failed to initialize CredentialStoreService", e); + throw new RuntimeException("Failed to initialize CredentialStoreService", e); + } + } + + public void init() { + try { + initSharingRegistry(); + postInitDefaultGateway(); + } catch (Exception e) { + logger.error("Error occurred while initializing Airavata Service", e); + throw new RuntimeException("Error occurred while initializing Airavata Service", e); + } + } + + + private void postInitDefaultGateway() { + try { + GatewayResourceProfile gatewayResourceProfile = getGatewayResourceProfile(ServerSettings.getDefaultUserGateway()); + if (gatewayResourceProfile != null && gatewayResourceProfile.getIdentityServerPwdCredToken() == null) { + + logger.debug("Starting to add the password credential for default gateway : " + + ServerSettings.getDefaultUserGateway()); + + PasswordCredential passwordCredential = new PasswordCredential(); + passwordCredential.setPortalUserName(ServerSettings.getDefaultUser()); + passwordCredential.setGatewayId(ServerSettings.getDefaultUserGateway()); + passwordCredential.setLoginUserName(ServerSettings.getDefaultUser()); + passwordCredential.setPassword(ServerSettings.getDefaultUserPassword()); + passwordCredential.setDescription("Credentials for default gateway"); + String token = null; + try { + logger.info("Creating password credential for default gateway"); + token = addPasswordCredential(passwordCredential); + } catch (Throwable ex) { + logger.error( + "Failed to create the password credential for the default gateway : " + + ServerSettings.getDefaultUserGateway(), + ex); + } + + if (token != null) { + logger.debug("Adding password credential token " + token + " to the default gateway : " + + ServerSettings.getDefaultUserGateway()); + gatewayResourceProfile.setIdentityServerPwdCredToken(token); + gatewayResourceProfile.setIdentityServerTenant(ServerSettings.getDefaultUserGateway()); + updateGatewayResourceProfile( + ServerSettings.getDefaultUserGateway(), gatewayResourceProfile); + } + } + } catch (Throwable e) { + logger.error("Failed to add the password credentials for the default gateway", e); + } + } + + private void initSharingRegistry() throws Exception { + try { + if (!isDomainExists(ServerSettings.getDefaultUserGateway())) { + Domain domain = new Domain(); + domain.setDomainId(ServerSettings.getDefaultUserGateway()); + domain.setName(ServerSettings.getDefaultUserGateway()); + domain.setDescription("Domain entry for " + domain.getName()); + createDomain(domain); + + User user = new User(); + user.setDomainId(domain.getDomainId()); + user.setUserId(ServerSettings.getDefaultUser() + "@" + ServerSettings.getDefaultUserGateway()); + user.setUserName(ServerSettings.getDefaultUser()); + createUser(user); + + // Creating Entity Types for each domain + EntityType entityType = new EntityType(); + entityType.setEntityTypeId(domain.getDomainId() + ":PROJECT"); + entityType.setDomainId(domain.getDomainId()); + entityType.setName("PROJECT"); + entityType.setDescription("Project entity type"); + createEntityType(entityType); + + entityType = new EntityType(); + entityType.setEntityTypeId(domain.getDomainId() + ":EXPERIMENT"); + entityType.setDomainId(domain.getDomainId()); + entityType.setName("EXPERIMENT"); + entityType.setDescription("Experiment entity type"); + createEntityType(entityType); + + entityType = new EntityType(); + entityType.setEntityTypeId(domain.getDomainId() + ":FILE"); + entityType.setDomainId(domain.getDomainId()); + entityType.setName("FILE"); + entityType.setDescription("File entity type"); + createEntityType(entityType); + + entityType = new EntityType(); + entityType.setEntityTypeId(domain.getDomainId() + ":" + ResourceType.APPLICATION_DEPLOYMENT.name()); + entityType.setDomainId(domain.getDomainId()); + entityType.setName("APPLICATION-DEPLOYMENT"); + entityType.setDescription("Application Deployment entity type"); + createEntityType(entityType); + + entityType = new EntityType(); + entityType.setEntityTypeId(domain.getDomainId() + ":" + ResourceType.GROUP_RESOURCE_PROFILE.name()); + entityType.setDomainId(domain.getDomainId()); + entityType.setName(ResourceType.GROUP_RESOURCE_PROFILE.name()); + entityType.setDescription("Group Resource Profile entity type"); + createEntityType(entityType); + + entityType = new EntityType(); + entityType.setEntityTypeId(domain.getDomainId() + ":" + ResourceType.CREDENTIAL_TOKEN.name()); + entityType.setDomainId(domain.getDomainId()); + entityType.setName(ResourceType.CREDENTIAL_TOKEN.name()); + entityType.setDescription("Credential Store Token entity type"); + createEntityType(entityType); + + // Creating Permission Types for each domain + PermissionType permissionType = new PermissionType(); + permissionType.setPermissionTypeId(domain.getDomainId() + ":READ"); + permissionType.setDomainId(domain.getDomainId()); + permissionType.setName("READ"); + permissionType.setDescription("Read permission type"); + createPermissionType(permissionType); + + permissionType = new PermissionType(); + permissionType.setPermissionTypeId(domain.getDomainId() + ":WRITE"); + permissionType.setDomainId(domain.getDomainId()); + permissionType.setName("WRITE"); + permissionType.setDescription("Write permission type"); + createPermissionType(permissionType); + + permissionType = new PermissionType(); + permissionType.setPermissionTypeId(domain.getDomainId() + ":MANAGE_SHARING"); + permissionType.setDomainId(domain.getDomainId()); + permissionType.setName("MANAGE_SHARING"); + permissionType.setDescription("Sharing permission type"); + createPermissionType(permissionType); + } + } catch (Throwable ex) { + throw ex; + } + } + + public List getAllUsersInGateway(String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.getAllUsersInGateway(gatewayId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving users"); + } } public boolean updateGateway(String gatewayId, Gateway updatedGateway) - throws RegistryException, AppCatalogException { - return registryService.updateGateway(gatewayId, updatedGateway); + throws RegistryException, AppCatalogException, TException { + try { + return registryService.updateGateway(gatewayId, updatedGateway); + } catch (Throwable e) { + throw convertException(e, "Error while updating gateway"); + } } - public Gateway getGateway(String gatewayId) throws RegistryException { - return registryService.getGateway(gatewayId); + public Gateway getGateway(String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.getGateway(gatewayId); + } catch (Throwable e) { + throw convertException(e, "Error while getting the gateway"); + } } - public boolean deleteGateway(String gatewayId) throws RegistryException { - return registryService.deleteGateway(gatewayId); + public boolean deleteGateway(String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.deleteGateway(gatewayId); + } catch (Throwable e) { + throw convertException(e, "Error while deleting the gateway"); + } } - public List getAllGateways() throws RegistryException { - return registryService.getAllGateways(); + public List getAllGateways() throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.getAllGateways(); + } catch (Throwable e) { + throw convertException(e, "Error while getting all the gateways"); + } } - public boolean isGatewayExist(String gatewayId) throws RegistryException { - return registryService.isGatewayExist(gatewayId); + public boolean isGatewayExist(String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.isGatewayExist(gatewayId); + } catch (Throwable e) { + throw convertException(e, "Error while getting gateway"); + } } - public String createNotification(Notification notification) throws RegistryException { - return registryService.createNotification(notification); + public String createNotification(Notification notification) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.createNotification(notification); + } catch (Throwable e) { + throw convertException(e, "Error while creating notification"); + } } - public boolean updateNotification(Notification notification) throws RegistryException { - return registryService.updateNotification(notification); + public boolean updateNotification(Notification notification) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.updateNotification(notification); + } catch (Throwable e) { + throw convertException(e, "Error while updating notification"); + } } - public boolean deleteNotification(String gatewayId, String notificationId) throws RegistryException { - return registryService.deleteNotification(gatewayId, notificationId); + public boolean deleteNotification(String gatewayId, String notificationId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.deleteNotification(gatewayId, notificationId); + } catch (Throwable e) { + throw convertException(e, "Error while deleting notification"); + } } - public Notification getNotification(String gatewayId, String notificationId) throws RegistryException { - return registryService.getNotification(gatewayId, notificationId); + public Notification getNotification(String gatewayId, String notificationId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.getNotification(gatewayId, notificationId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving notification"); + } } - public List getAllNotifications(String gatewayId) throws RegistryException { - return registryService.getAllNotifications(gatewayId); + public List getAllNotifications(String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.getAllNotifications(gatewayId); + } catch (Throwable e) { + throw convertException(e, "Error while getting all notifications"); + } } - public String registerDataProduct(DataProductModel dataProductModel) throws RegistryException { - return registryService.registerDataProduct(dataProductModel); + public String registerDataProduct(DataProductModel dataProductModel) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.registerDataProduct(dataProductModel); + } catch (Throwable e) { + throw convertException(e, "Error while registering data product"); + } } - public DataProductModel getDataProduct(String productUri) throws RegistryException { - return registryService.getDataProduct(productUri); + public DataProductModel getDataProduct(String productUri) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.getDataProduct(productUri); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving data product"); + } } - public String registerReplicaLocation(DataReplicaLocationModel replicaLocationModel) throws RegistryException { - return registryService.registerReplicaLocation(replicaLocationModel); + public String registerReplicaLocation(DataReplicaLocationModel replicaLocationModel) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.registerReplicaLocation(replicaLocationModel); + } catch (Throwable e) { + throw convertException(e, "Error while registering replica location"); + } } - public DataProductModel getParentDataProduct(String productUri) throws RegistryException { - return registryService.getParentDataProduct(productUri); + public DataProductModel getParentDataProduct(String productUri) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.getParentDataProduct(productUri); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving parent data product"); + } } - public List getChildDataProducts(String productUri) throws RegistryException { - return registryService.getChildDataProducts(productUri); + public List getChildDataProducts(String productUri) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.getChildDataProducts(productUri); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving child data products"); + } } - public boolean isUserExists(String gatewayId, String userName) throws RegistryException { - return registryService.isUserExists(gatewayId, userName); + public boolean isUserExists(String gatewayId, String userName) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.isUserExists(gatewayId, userName); + } catch (Throwable e) { + throw convertException(e, "Error while verifying user"); + } } - public Project getProject(String projectId) throws RegistryException { - return registryService.getProject(projectId); + public Project getProject(String projectId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.getProject(projectId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving the project"); + } + } + + public String createProject(String gatewayId, Project project) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.createProject(gatewayId, project); + } catch (Throwable e) { + throw convertException(e, "Error while creating project"); + } } - public String createProject(String gatewayId, Project project) throws RegistryException { - return registryService.createProject(gatewayId, project); + public void updateProject(String projectId, Project updatedProject) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + registryService.updateProject(projectId, updatedProject); + } catch (Throwable e) { + throw convertException(e, "Error while updating project"); + } } - public void updateProject(String projectId, Project updatedProject) throws RegistryException { - registryService.updateProject(projectId, updatedProject); + public boolean deleteProject(String projectId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.deleteProject(projectId); + } catch (Throwable e) { + throw convertException(e, "Error while removing the project"); + } } - public boolean deleteProject(String projectId) throws RegistryException { - return registryService.deleteProject(projectId); + public List searchProjectsWithSharing( + AuthzToken authzToken, + String gatewayId, + String userName, + Map filters, + int limit, + int offset) throws TException { + try { + List accessibleProjIds = new ArrayList<>(); + List result; + if (ServerSettings.isEnableSharing()) { + List sharingFilters = new ArrayList<>(); + SearchCriteria searchCriteria = new SearchCriteria(); + searchCriteria.setSearchField(EntitySearchField.ENTITY_TYPE_ID); + searchCriteria.setSearchCondition(SearchCondition.EQUAL); + searchCriteria.setValue(gatewayId + ":PROJECT"); + sharingFilters.add(searchCriteria); + sharingRegistryService.searchEntities( + authzToken.getClaimsMap().get(Constants.GATEWAY_ID), + userName + "@" + gatewayId, + sharingFilters, + 0, + Integer.MAX_VALUE) + .stream() + .forEach(e -> accessibleProjIds.add(e.getEntityId())); + if (accessibleProjIds.isEmpty()) { + result = Collections.emptyList(); + } else { + result = registryService.searchProjects( + gatewayId, userName, accessibleProjIds, filters, limit, offset); + } + } else { + result = registryService.searchProjects(gatewayId, userName, accessibleProjIds, filters, limit, offset); + } + return result; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving projects"); + } } public List searchProjects( @@ -233,6 +540,27 @@ public List getExperimentsInProject(String gatewayId, String pr return registryService.getExperimentsInProject(gatewayId, projectId, limit, offset); } + public List getExperimentsInProject( + AuthzToken authzToken, String projectId, int limit, int offset) + throws TException { + try { + Project project = getProject(projectId); + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + if (ServerSettings.isEnableSharing() + && (!authzToken.getClaimsMap().get(Constants.USER_NAME).equals(project.getOwner()) + || !authzToken.getClaimsMap().get(Constants.GATEWAY_ID).equals(project.getGatewayId()))) { + String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + if (!userHasAccess( + gatewayId, userId + "@" + gatewayId, projectId, gatewayId + ":READ")) { + throw new AuthorizationException("User does not have permission to access this resource"); + } + } + return registryService.getExperimentsInProject(gatewayId, projectId, limit, offset); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving the experiments"); + } + } + public ExperimentStatistics getExperimentStatistics( String gatewayId, long fromTime, @@ -243,7 +571,8 @@ public ExperimentStatistics getExperimentStatistics( List accessibleExpIds, int limit, int offset) - throws RegistryException { + throws TException { + try { return registryService.getExperimentStatistics( gatewayId, fromTime, @@ -254,6 +583,9 @@ public ExperimentStatistics getExperimentStatistics( accessibleExpIds, limit, offset); + } catch (Throwable e) { + throw convertException(e, "Error while getting experiment statistics"); + } } public ExperimentModel getExperiment(String airavataExperimentId) throws RegistryException { @@ -264,6 +596,74 @@ public String createExperiment(String gatewayId, ExperimentModel experiment) thr return registryService.createExperiment(gatewayId, experiment); } + public ExperimentModel getExperiment(AuthzToken authzToken, String airavataExperimentId) throws TException { + try { + ExperimentModel existingExperiment = getExperiment(airavataExperimentId); + if (authzToken.getClaimsMap().get(Constants.USER_NAME).equals(existingExperiment.getUserName()) + && authzToken.getClaimsMap().get(Constants.GATEWAY_ID).equals(existingExperiment.getGatewayId())) { + return existingExperiment; + } else if (ServerSettings.isEnableSharing()) { + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + if (!userHasAccess( + gatewayId, userId + "@" + gatewayId, airavataExperimentId, gatewayId + ":READ")) { + throw new AuthorizationException("User does not have permission to access this resource"); + } + return existingExperiment; + } else { + throw new AuthorizationException("User does not have permission to access this resource"); + } + } catch (Throwable e) { + throw convertException(e, "Error while getting the experiment"); + } + } + + public ExperimentModel getExperimentByAdmin(AuthzToken authzToken, String airavataExperimentId) throws TException { + try { + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + ExperimentModel existingExperiment = getExperiment(airavataExperimentId); + if (gatewayId.equals(existingExperiment.getGatewayId())) { + return existingExperiment; + } else { + throw new AuthorizationException("User does not have permission to access this resource"); + } + } catch (Throwable e) { + throw convertException(e, "Error while getting experiment by admin"); + } + } + + public void updateExperiment(AuthzToken authzToken, String airavataExperimentId, ExperimentModel experiment) throws TException { + try { + ExperimentModel existingExperiment = getExperiment(airavataExperimentId); + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + if (ServerSettings.isEnableSharing() + && (!authzToken.getClaimsMap().get(Constants.USER_NAME).equals(existingExperiment.getUserName()) + || !authzToken.getClaimsMap().get(Constants.GATEWAY_ID).equals(existingExperiment.getGatewayId()))) { + String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + if (!userHasAccess( + gatewayId, userId + "@" + gatewayId, airavataExperimentId, gatewayId + ":WRITE")) { + throw new AuthorizationException("User does not have permission to access this resource"); + } + } + + try { + // Update name, description and parent on Entity + // TODO: update the experiment via a DB event + Entity entity = getEntity(gatewayId, airavataExperimentId); + entity.setName(experiment.getExperimentName()); + entity.setDescription(experiment.getDescription()); + entity.setParentEntityId(experiment.getProjectId()); + updateEntity(entity); + } catch (Throwable e) { + throw new Exception("Failed to update entity in sharing registry", e); + } + + updateExperiment(airavataExperimentId, experiment); + } catch (Throwable e) { + throw convertException(e, "Error while updating experiment"); + } + } + public void updateExperiment(String airavataExperimentId, ExperimentModel experiment) throws RegistryException { registryService.updateExperiment(airavataExperimentId, experiment); } @@ -287,14 +687,15 @@ public List searchExperiments( * Search experiments with sharing registry integration - processes filters and builds search criteria */ public List searchExperimentsWithSharing( - SharingRegistryService.Client sharingClient, + AuthzToken authzToken, String gatewayId, String userName, Map filters, int limit, int offset) - throws Exception { + throws TException { + try { List accessibleExpIds = new ArrayList<>(); Map filtersCopy = new HashMap<>(filters); List sharingFilters = new ArrayList<>(); @@ -363,7 +764,7 @@ public List searchExperimentsWithSharing( searchOffset = offset; searchLimit = limit; } - sharingClient + sharingRegistryService .searchEntities( authzToken.getClaimsMap().get(Constants.GATEWAY_ID), userName + "@" + gatewayId, @@ -377,6 +778,9 @@ public List searchExperimentsWithSharing( finalOffset = 0; } return searchExperiments(gatewayId, userName, accessibleExpIds, filtersCopy, limit, finalOffset); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving experiments"); + } } public ExperimentStatus getExperimentStatus(String airavataExperimentId) throws RegistryException { @@ -494,14 +898,22 @@ public boolean isGatewayGroupsExists(String gatewayId) throws RegistryException } public void updateExperimentConfiguration(String airavataExperimentId, UserConfigurationDataModel userConfiguration) - throws RegistryException { - registryService.updateExperimentConfiguration(airavataExperimentId, userConfiguration); + throws TException { + try { + registryService.updateExperimentConfiguration(airavataExperimentId, userConfiguration); + } catch (Throwable e) { + throw convertException(e, "Error while updating experiment configuration"); + } } public void updateResourceScheduleing( String airavataExperimentId, ComputationalResourceSchedulingModel resourceScheduling) - throws RegistryException { - registryService.updateResourceScheduleing(airavataExperimentId, resourceScheduling); + throws TException { + try { + registryService.updateResourceScheduleing(airavataExperimentId, resourceScheduling); + } catch (Throwable e) { + throw convertException(e, "Error while updating resource scheduling"); + } } public String registerApplicationDeployment( @@ -591,7 +1003,7 @@ public List getAccessibleAppModules( * Get accessible app modules with sharing registry integration */ public List getAccessibleAppModulesWithSharing( - SharingRegistryService.Client sharingClient, AuthzToken authzToken, String gatewayId) throws Exception { + AuthzToken authzToken, String gatewayId) throws Exception { String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); List accessibleAppDeploymentIds = new ArrayList<>(); if (ServerSettings.isEnableSharing()) { @@ -606,7 +1018,7 @@ public List getAccessibleAppModulesWithSharing( permissionTypeFilter.setSearchCondition(SearchCondition.EQUAL); permissionTypeFilter.setValue(gatewayId + ":" + ResourcePermissionType.READ); sharingFilters.add(permissionTypeFilter); - sharingClient + sharingRegistryService .searchEntities( authzToken.getClaimsMap().get(Constants.GATEWAY_ID), userName + "@" + gatewayId, @@ -617,7 +1029,7 @@ public List getAccessibleAppModulesWithSharing( } List accessibleComputeResourceIds = new ArrayList<>(); List groupResourceProfileList = - getGroupResourceListWithSharing(sharingClient, authzToken, gatewayId); + getGroupResourceListWithSharing( authzToken, gatewayId); for (GroupResourceProfile groupResourceProfile : groupResourceProfileList) { List groupComputeResourcePreferenceList = groupResourceProfile.getComputePreferences(); @@ -721,31 +1133,31 @@ public boolean deleteResourceJobManager(String resourceJobManagerId) throws AppC return registryService.deleteResourceJobManager(resourceJobManagerId); } - public String addPasswordCredential(CredentialStoreService.Client csClient, PasswordCredential passwordCredential) + public String addPasswordCredential( PasswordCredential passwordCredential) throws CredentialStoreException, TException { - return csClient.addPasswordCredential(passwordCredential); + return credentialStoreService.addPasswordCredential(passwordCredential); } - public void deletePWDCredential(CredentialStoreService.Client csClient, String tokenId, String gatewayId) + public void deletePWDCredential( String tokenId, String gatewayId) throws CredentialStoreException, TException { - csClient.deletePWDCredential(tokenId, gatewayId); + credentialStoreService.deletePWDCredential(tokenId, gatewayId); } - public boolean deleteSSHCredential(CredentialStoreService.Client csClient, String tokenId, String gatewayId) + public boolean deleteSSHCredential( String tokenId, String gatewayId) throws CredentialStoreException, TException { - return csClient.deleteSSHCredential(tokenId, gatewayId); + return credentialStoreService.deleteSSHCredential(tokenId, gatewayId); } public CredentialSummary getCredentialSummary( - CredentialStoreService.Client csClient, String tokenId, String gatewayId) + String tokenId, String gatewayId) throws CredentialStoreException, TException { - return csClient.getCredentialSummary(tokenId, gatewayId); + return credentialStoreService.getCredentialSummary(tokenId, gatewayId); } public List getAllCredentialSummaries( - CredentialStoreService.Client csClient, SummaryType type, List accessibleTokenIds, String gatewayId) + SummaryType type, List accessibleTokenIds, String gatewayId) throws CredentialStoreException, TException { - return csClient.getAllCredentialSummaries(type, accessibleTokenIds, gatewayId); + return credentialStoreService.getAllCredentialSummaries(type, accessibleTokenIds, gatewayId); } public String addLocalDataMovementDetails( @@ -783,40 +1195,43 @@ public List getUserProjects(String gatewayId, String userName, int limi * Get user projects with sharing registry integration */ public List getUserProjectsWithSharing( - SharingRegistryService.Client sharingClient, AuthzToken authzToken, String gatewayId, String userName, int limit, int offset) - throws Exception { - if (ServerSettings.isEnableSharing()) { - // user projects + user accessible projects - List accessibleProjectIds = new ArrayList<>(); - List filters = new ArrayList<>(); - SearchCriteria searchCriteria = new SearchCriteria(); - searchCriteria.setSearchField(EntitySearchField.ENTITY_TYPE_ID); - searchCriteria.setSearchCondition(SearchCondition.EQUAL); - searchCriteria.setValue(gatewayId + ":PROJECT"); - filters.add(searchCriteria); - sharingClient - .searchEntities( - authzToken.getClaimsMap().get(Constants.GATEWAY_ID), - userName + "@" + gatewayId, - filters, - 0, - -1) - .stream() - .forEach(p -> accessibleProjectIds.add(p.getEntityId())); - List result; - if (accessibleProjectIds.isEmpty()) { - result = Collections.emptyList(); + throws TException { + try { + if (ServerSettings.isEnableSharing()) { + // user projects + user accessible projects + List accessibleProjectIds = new ArrayList<>(); + List filters = new ArrayList<>(); + SearchCriteria searchCriteria = new SearchCriteria(); + searchCriteria.setSearchField(EntitySearchField.ENTITY_TYPE_ID); + searchCriteria.setSearchCondition(SearchCondition.EQUAL); + searchCriteria.setValue(gatewayId + ":PROJECT"); + filters.add(searchCriteria); + sharingRegistryService + .searchEntities( + authzToken.getClaimsMap().get(Constants.GATEWAY_ID), + userName + "@" + gatewayId, + filters, + 0, + -1) + .stream() + .forEach(p -> accessibleProjectIds.add(p.getEntityId())); + List result; + if (accessibleProjectIds.isEmpty()) { + result = Collections.emptyList(); + } else { + result = searchProjects(gatewayId, userName, accessibleProjectIds, new HashMap<>(), limit, offset); + } + return result; } else { - result = searchProjects(gatewayId, userName, accessibleProjectIds, new HashMap<>(), limit, offset); + return getUserProjects(gatewayId, userName, limit, offset); } - return result; - } else { - return getUserProjects(gatewayId, userName, limit, offset); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving user projects"); } } @@ -831,7 +1246,7 @@ public List getAccessibleApplicationDeployment * Get accessible application deployments with sharing registry integration */ public List getAccessibleApplicationDeploymentsWithSharing( - SharingRegistryService.Client sharingClient, + AuthzToken authzToken, String gatewayId, ResourcePermissionType permissionType) @@ -850,7 +1265,7 @@ public List getAccessibleApplicationDeployment permissionTypeFilter.setSearchCondition(SearchCondition.EQUAL); permissionTypeFilter.setValue(gatewayId + ":" + permissionType.name()); sharingFilters.add(permissionTypeFilter); - sharingClient + sharingRegistryService .searchEntities( authzToken.getClaimsMap().get(Constants.GATEWAY_ID), userName + "@" + gatewayId, @@ -861,7 +1276,7 @@ public List getAccessibleApplicationDeployment } List accessibleComputeResourceIds = new ArrayList<>(); List groupResourceProfileList = - getGroupResourceListWithSharing(sharingClient, authzToken, gatewayId); + getGroupResourceListWithSharing( authzToken, gatewayId); for (GroupResourceProfile groupResourceProfile : groupResourceProfileList) { List groupComputeResourcePreferenceList = groupResourceProfile.getComputePreferences(); @@ -1169,45 +1584,43 @@ public GatewayGroups retrieveGatewayGroups(String gatewayId) throws TException { } } - public void createManageSharingPermissionTypeIfMissing(SharingRegistryService.Client sharingClient, String domainId) + public void createManageSharingPermissionTypeIfMissing( String domainId) throws TException { // AIRAVATA-3297 Some gateways were created without the MANAGE_SHARING permission, so add it if missing String permissionTypeId = domainId + ":MANAGE_SHARING"; try { - if (!sharingClient.isPermissionExists(domainId, permissionTypeId)) { + if (!sharingRegistryService.isPermissionExists(domainId, permissionTypeId)) { PermissionType permissionType = new PermissionType(); permissionType.setPermissionTypeId(permissionTypeId); permissionType.setDomainId(domainId); permissionType.setName("MANAGE_SHARING"); permissionType.setDescription("Manage sharing permission type"); - sharingClient.createPermissionType(permissionType); + sharingRegistryService.createPermissionType(permissionType); logger.info("Created MANAGE_SHARING permission type for domain " + domainId); } - } catch (TException e) { - throw e; } catch (Exception e) { throw new TException("Error creating MANAGE_SHARING permission type", e); } } - public void shareEntityWithAdminGatewayGroups(SharingRegistryService.Client sharingClient, Entity entity) + public void shareEntityWithAdminGatewayGroups( Entity entity) throws TException { final String domainId = entity.getDomainId(); GatewayGroups gatewayGroups = retrieveGatewayGroups(domainId); - createManageSharingPermissionTypeIfMissing(sharingClient, domainId); - sharingClient.shareEntityWithGroups( + createManageSharingPermissionTypeIfMissing( domainId); + sharingRegistryService.shareEntityWithGroups( domainId, entity.getEntityId(), Arrays.asList(gatewayGroups.getAdminsGroupId()), domainId + ":MANAGE_SHARING", true); - sharingClient.shareEntityWithGroups( + sharingRegistryService.shareEntityWithGroups( domainId, entity.getEntityId(), Arrays.asList(gatewayGroups.getAdminsGroupId()), domainId + ":WRITE", true); - sharingClient.shareEntityWithGroups( + sharingRegistryService.shareEntityWithGroups( domainId, entity.getEntityId(), Arrays.asList(gatewayGroups.getAdminsGroupId(), gatewayGroups.getReadOnlyAdminsGroupId()), @@ -1216,27 +1629,27 @@ public void shareEntityWithAdminGatewayGroups(SharingRegistryService.Client shar } public boolean userHasAccessInternal( - SharingRegistryService.Client sharingClient, + AuthzToken authzToken, String entityId, ResourcePermissionType permissionType) { final String domainId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); final String userId = authzToken.getClaimsMap().get(Constants.USER_NAME) + "@" + domainId; try { - final boolean hasOwnerAccess = sharingClient.userHasAccess( + final boolean hasOwnerAccess = sharingRegistryService.userHasAccess( domainId, userId, entityId, domainId + ":" + ResourcePermissionType.OWNER); boolean hasAccess = false; if (permissionType.equals(ResourcePermissionType.WRITE)) { hasAccess = hasOwnerAccess - || sharingClient.userHasAccess( + || sharingRegistryService.userHasAccess( domainId, userId, entityId, domainId + ":" + ResourcePermissionType.WRITE); } else if (permissionType.equals(ResourcePermissionType.READ)) { hasAccess = hasOwnerAccess - || sharingClient.userHasAccess( + || sharingRegistryService.userHasAccess( domainId, userId, entityId, domainId + ":" + ResourcePermissionType.READ); } else if (permissionType.equals(ResourcePermissionType.MANAGE_SHARING)) { hasAccess = hasOwnerAccess - || sharingClient.userHasAccess( + || sharingRegistryService.userHasAccess( domainId, userId, entityId, domainId + ":" + ResourcePermissionType.MANAGE_SHARING); } else if (permissionType.equals(ResourcePermissionType.OWNER)) { hasAccess = hasOwnerAccess; @@ -1249,40 +1662,43 @@ public boolean userHasAccessInternal( // Credential management methods public String generateAndRegisterSSHKeys( - CredentialStoreService.Client csClient, - SharingRegistryService.Client sharingClient, String gatewayId, String userName, String description) - throws Exception { - SSHCredential sshCredential = new SSHCredential(); - sshCredential.setUsername(userName); - sshCredential.setGatewayId(gatewayId); - sshCredential.setDescription(description); - String key = csClient.addSSHCredential(sshCredential); + throws TException { try { - Entity entity = new Entity(); - entity.setEntityId(key); - entity.setDomainId(gatewayId); - entity.setEntityTypeId(gatewayId + ":" + ResourceType.CREDENTIAL_TOKEN); - entity.setOwnerId(userName + "@" + gatewayId); - entity.setName(key); - entity.setDescription(description); - sharingClient.createEntity(entity); - } catch (Exception ex) { - logger.error(ex.getMessage(), ex); - logger.error( - "Rolling back ssh key creation for user " + userName + " and description [" + description + "]"); - csClient.deleteSSHCredential(key, gatewayId); - throw new Exception("Failed to create sharing registry record", ex); + SSHCredential sshCredential = new SSHCredential(); + sshCredential.setUsername(userName); + sshCredential.setGatewayId(gatewayId); + sshCredential.setDescription(description); + String key = credentialStoreService.addSSHCredential(sshCredential); + + try { + Entity entity = new Entity(); + entity.setEntityId(key); + entity.setDomainId(gatewayId); + entity.setEntityTypeId(gatewayId + ":" + ResourceType.CREDENTIAL_TOKEN); + entity.setOwnerId(userName + "@" + gatewayId); + entity.setName(key); + entity.setDescription(description); + sharingRegistryService.createEntity(entity); + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + logger.error( + "Rolling back ssh key creation for user " + userName + " and description [" + description + "]"); + credentialStoreService.deleteSSHCredential(key, gatewayId); + throw new Exception("Failed to create sharing registry record", ex); + } + logger.debug("Airavata generated SSH keys for gateway : " + gatewayId + " and for user : " + userName); + return key; + } catch (Throwable e) { + throw convertException(e, "Error occurred while registering SSH Credential"); } - logger.debug("Airavata generated SSH keys for gateway : " + gatewayId + " and for user : " + userName); - return key; } public String registerPwdCredential( - CredentialStoreService.Client csClient, - SharingRegistryService.Client sharingClient, + + String gatewayId, String userName, String loginUserName, @@ -1295,7 +1711,7 @@ public String registerPwdCredential( pwdCredential.setPassword(password); pwdCredential.setDescription(description); pwdCredential.setGatewayId(gatewayId); - String key = addPasswordCredential(csClient, pwdCredential); + String key = addPasswordCredential( pwdCredential); try { Entity entity = new Entity(); entity.setEntityId(key); @@ -1304,13 +1720,13 @@ public String registerPwdCredential( entity.setOwnerId(userName + "@" + gatewayId); entity.setName(key); entity.setDescription(description); - sharingClient.createEntity(entity); + sharingRegistryService.createEntity(entity); } catch (Exception ex) { logger.error(ex.getMessage(), ex); logger.error("Rolling back password registration for user " + userName + " and description [" + description + "]"); try { - deletePWDCredential(csClient, key, gatewayId); + deletePWDCredential( key, gatewayId); } catch (Exception rollbackEx) { logger.error("Failed to rollback password credential deletion", rollbackEx); } @@ -1322,23 +1738,23 @@ public String registerPwdCredential( } public CredentialSummary getCredentialSummaryWithAuth( - CredentialStoreService.Client csClient, - SharingRegistryService.Client sharingClient, + + AuthzToken authzToken, String tokenId, String gatewayId) - throws Exception { - if (!userHasAccessInternal(sharingClient, authzToken, tokenId, ResourcePermissionType.READ)) { - throw new Exception("User does not have permission to access this resource"); + throws AuthorizationException, Exception { + if (!userHasAccessInternal( authzToken, tokenId, ResourcePermissionType.READ)) { + throw new AuthorizationException("User does not have permission to access this resource"); } - CredentialSummary credentialSummary = getCredentialSummary(csClient, tokenId, gatewayId); + CredentialSummary credentialSummary = getCredentialSummary( tokenId, gatewayId); logger.debug("Airavata retrived the credential summary for token " + tokenId + "GatewayId: " + gatewayId); return credentialSummary; } public List getAllCredentialSummariesWithAuth( - CredentialStoreService.Client csClient, - SharingRegistryService.Client sharingClient, + + AuthzToken authzToken, SummaryType type, String gatewayId, @@ -1351,51 +1767,52 @@ public List getAllCredentialSummariesWithAuth( searchCriteria.setValue(gatewayId + ":" + ResourceType.CREDENTIAL_TOKEN.name()); filters.add(searchCriteria); List accessibleTokenIds = - sharingClient.searchEntities(gatewayId, userName + "@" + gatewayId, filters, 0, -1).stream() + sharingRegistryService.searchEntities(gatewayId, userName + "@" + gatewayId, filters, 0, -1).stream() .map(p -> p.getEntityId()) .collect(Collectors.toList()); List credentialSummaries = - getAllCredentialSummaries(csClient, type, accessibleTokenIds, gatewayId); + getAllCredentialSummaries( type, accessibleTokenIds, gatewayId); logger.debug( "Airavata successfully retrived credential summaries of type " + type + " GatewayId: " + gatewayId); return credentialSummaries; } public boolean deleteSSHPubKey( - CredentialStoreService.Client csClient, - SharingRegistryService.Client sharingClient, + + AuthzToken authzToken, String airavataCredStoreToken, String gatewayId) - throws Exception { - if (!userHasAccessInternal(sharingClient, authzToken, airavataCredStoreToken, ResourcePermissionType.WRITE)) { - throw new Exception("User does not have permission to delete this resource."); + throws AuthorizationException, Exception { + if (!userHasAccessInternal( authzToken, airavataCredStoreToken, ResourcePermissionType.WRITE)) { + throw new AuthorizationException("User does not have permission to delete this resource."); } logger.debug("Airavata deleted SSH pub key for gateway Id : " + gatewayId + " and with token id : " + airavataCredStoreToken); - return deleteSSHCredential(csClient, airavataCredStoreToken, gatewayId); + return deleteSSHCredential( airavataCredStoreToken, gatewayId); } public boolean deletePWDCredentialWithAuth( - CredentialStoreService.Client csClient, - SharingRegistryService.Client sharingClient, + + AuthzToken authzToken, String airavataCredStoreToken, String gatewayId) - throws Exception { - if (!userHasAccessInternal(sharingClient, authzToken, airavataCredStoreToken, ResourcePermissionType.WRITE)) { - throw new Exception("User does not have permission to delete this resource."); + throws AuthorizationException, Exception { + if (!userHasAccessInternal( authzToken, airavataCredStoreToken, ResourcePermissionType.WRITE)) { + throw new AuthorizationException("User does not have permission to delete this resource."); } logger.debug("Airavata deleted PWD credential for gateway Id : " + gatewayId + " and with token id : " + airavataCredStoreToken); - deletePWDCredential(csClient, airavataCredStoreToken, gatewayId); + deletePWDCredential( airavataCredStoreToken, gatewayId); return true; } // Project management methods with sharing registry integration public String createProjectWithSharing( - SharingRegistryService.Client sharingClient, String gatewayId, Project project) throws Exception { + String gatewayId, Project project) throws Exception { String projectId = createProject(gatewayId, project); + // TODO: verify that gatewayId and project.gatewayId match authzToken if (ServerSettings.isEnableSharing()) { try { Entity entity = new Entity(); @@ -1406,15 +1823,11 @@ public String createProjectWithSharing( entity.setOwnerId(project.getOwner() + "@" + domainId); entity.setName(project.getName()); entity.setDescription(project.getDescription()); - sharingClient.createEntity(entity); + sharingRegistryService.createEntity(entity); } catch (Exception ex) { logger.error(ex.getMessage(), ex); logger.error("Rolling back project creation Proj ID : " + projectId); - try { - deleteProject(projectId); - } catch (RegistryException rollbackEx) { - logger.error("Failed to rollback project deletion", rollbackEx); - } + deleteProject(projectId); throw new Exception("Failed to create entry for project in Sharing Registry", ex); } } @@ -1423,7 +1836,7 @@ public String createProjectWithSharing( } public void updateProjectWithAuth( - SharingRegistryService.Client sharingClient, + AuthzToken authzToken, String projectId, Project updatedProject) @@ -1434,30 +1847,30 @@ public void updateProjectWithAuth( || !authzToken.getClaimsMap().get(Constants.GATEWAY_ID).equals(existingProject.getGatewayId())) { 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 Exception("User does not have permission to access this resource"); + if (!sharingRegistryService.userHasAccess(gatewayId, userId + "@" + gatewayId, projectId, gatewayId + ":WRITE")) { + throw new AuthorizationException("User does not have permission to access this resource"); } } if (!updatedProject.getOwner().equals(existingProject.getOwner())) { - throw new Exception("Owner of a project cannot be changed"); + throw new InvalidRequestException("Owner of a project cannot be changed"); } if (!updatedProject.getGatewayId().equals(existingProject.getGatewayId())) { - throw new Exception("Gateway ID of a project cannot be changed"); + throw new InvalidRequestException("Gateway ID of a project cannot be changed"); } updateProject(projectId, updatedProject); logger.debug("Airavata updated project with project Id : " + projectId); } public boolean deleteProjectWithAuth( - SharingRegistryService.Client sharingClient, AuthzToken authzToken, String projectId) throws Exception { + AuthzToken authzToken, String projectId) throws ProjectNotFoundException, AuthorizationException, Exception { Project existingProject = getProject(projectId); if (ServerSettings.isEnableSharing() && !authzToken.getClaimsMap().get(Constants.USER_NAME).equals(existingProject.getOwner()) || !authzToken.getClaimsMap().get(Constants.GATEWAY_ID).equals(existingProject.getGatewayId())) { 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 Exception("User does not have permission to access this resource"); + if (!sharingRegistryService.userHasAccess(gatewayId, userId + "@" + gatewayId, projectId, gatewayId + ":WRITE")) { + throw new AuthorizationException("User does not have permission to access this resource"); } } boolean ret = deleteProject(projectId); @@ -1466,7 +1879,7 @@ public boolean deleteProjectWithAuth( } public Project getProjectWithAuth( - SharingRegistryService.Client sharingClient, AuthzToken authzToken, String projectId) throws Exception { + AuthzToken authzToken, String projectId) throws ProjectNotFoundException, AuthorizationException, Exception { Project project = getProject(projectId); if (authzToken.getClaimsMap().get(Constants.USER_NAME).equals(project.getOwner()) && authzToken.getClaimsMap().get(Constants.GATEWAY_ID).equals(project.getGatewayId())) { @@ -1474,8 +1887,8 @@ public Project getProjectWithAuth( } else if (ServerSettings.isEnableSharing()) { 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 Exception("User does not have permission to access this resource"); + if (!sharingRegistryService.userHasAccess(gatewayId, userId + "@" + gatewayId, projectId, gatewayId + ":READ")) { + throw new AuthorizationException("User does not have permission to access this resource"); } return project; } else { @@ -1485,7 +1898,7 @@ public Project getProjectWithAuth( // Experiment management methods with sharing registry integration public String createExperimentWithSharing( - SharingRegistryService.Client sharingClient, String gatewayId, ExperimentModel experiment) + String gatewayId, ExperimentModel experiment) throws Exception { String experimentId = createExperiment(gatewayId, experiment); @@ -1501,8 +1914,8 @@ public String createExperimentWithSharing( entity.setDescription(experiment.getDescription()); entity.setParentEntityId(experiment.getProjectId()); - sharingClient.createEntity(entity); - shareEntityWithAdminGatewayGroups(sharingClient, entity); + sharingRegistryService.createEntity(entity); + shareEntityWithAdminGatewayGroups( entity); } catch (Exception ex) { logger.error(ex.getMessage(), ex); logger.error("Rolling back experiment creation Exp ID : " + experimentId); @@ -1520,12 +1933,12 @@ public String createExperimentWithSharing( } public String createExperimentWithSharingAndPublish( - SharingRegistryService.Client sharingClient, + Publisher statusPublisher, String gatewayId, ExperimentModel experiment) throws Exception { - String experimentId = createExperimentWithSharing(sharingClient, gatewayId, experiment); + String experimentId = createExperimentWithSharing( gatewayId, experiment); if (statusPublisher != null) { ExperimentStatusChangeEvent event = @@ -1540,7 +1953,7 @@ public String createExperimentWithSharingAndPublish( } public void validateLaunchExperimentAccess( - SharingRegistryService.Client sharingClient, + AuthzToken authzToken, String gatewayId, ExperimentModel experiment) @@ -1554,7 +1967,7 @@ public void validateLaunchExperimentAccess( } // Verify user has READ access to groupResourceProfileId - if (!sharingClient.userHasAccess( + if (!sharingRegistryService.userHasAccess( gatewayId, username + "@" + gatewayId, experiment.getUserConfigurationData().getGroupResourceProfileId(), @@ -1587,7 +2000,7 @@ public void validateLaunchExperimentAccess( if (applicationDeploymentDescription.isPresent()) { final String appDeploymentId = applicationDeploymentDescription.get().getAppDeploymentId(); - if (!sharingClient.userHasAccess( + if (!sharingRegistryService.userHasAccess( gatewayId, username + "@" + gatewayId, appDeploymentId, gatewayId + ":READ")) { throw new Exception("User " + username + " in gateway " + gatewayId + " doesn't have access to app deployment " + appDeploymentId); @@ -1611,7 +2024,7 @@ public void validateLaunchExperimentAccess( if (applicationDeploymentDescription.isPresent()) { final String appDeploymentId = applicationDeploymentDescription.get().getAppDeploymentId(); - if (!sharingClient.userHasAccess( + if (!sharingRegistryService.userHasAccess( gatewayId, username + "@" + gatewayId, appDeploymentId, gatewayId + ":READ")) { throw new Exception("User " + username + " in gateway " + gatewayId + " doesn't have access to app deployment " + appDeploymentId); @@ -1622,7 +2035,7 @@ public void validateLaunchExperimentAccess( } public boolean deleteExperimentWithAuth( - SharingRegistryService.Client sharingClient, AuthzToken authzToken, String experimentId) throws Exception { + AuthzToken authzToken, String experimentId) throws Exception { ExperimentModel experimentModel = getExperiment(experimentId); if (ServerSettings.isEnableSharing() @@ -1630,8 +2043,8 @@ public boolean deleteExperimentWithAuth( || !authzToken.getClaimsMap().get(Constants.GATEWAY_ID).equals(experimentModel.getGatewayId())) { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!sharingClient.userHasAccess(gatewayId, userId + "@" + gatewayId, experimentId, gatewayId + ":WRITE")) { - throw new Exception("User does not have permission to access this resource"); + if (!sharingRegistryService.userHasAccess(gatewayId, userId + "@" + gatewayId, experimentId, gatewayId + ":WRITE")) { + throw new AuthorizationException("User does not have permission to access this resource"); } } @@ -1642,9 +2055,9 @@ public boolean deleteExperimentWithAuth( return deleteExperiment(experimentId); } - public ResourceType getResourceType(SharingRegistryService.Client sharingClient, String domainId, String entityId) + public ResourceType getResourceType( String domainId, String entityId) throws TException { - Entity entity = sharingClient.getEntity(domainId, entityId); + Entity entity = sharingRegistryService.getEntity(domainId, entityId); for (ResourceType resourceType : ResourceType.values()) { if (entity.getEntityTypeId().equals(domainId + ":" + resourceType.name())) { return resourceType; @@ -1654,76 +2067,78 @@ public ResourceType getResourceType(SharingRegistryService.Client sharingClient, } // Gateway management methods with sharing registry integration - public String addGatewayWithSharing( - RegistryService.Client registryClient, SharingRegistryService.Client sharingClient, Gateway gateway) - throws Exception { - String gatewayId = registryClient.addGateway(gateway); - Domain domain = new Domain(); - domain.setDomainId(gateway.getGatewayId()); - domain.setName(gateway.getGatewayName()); - domain.setDescription("Domain entry for " + domain.getName()); - sharingClient.createDomain(domain); - - // Creating Entity Types for each domain - EntityType entityType = new EntityType(); - entityType.setEntityTypeId(domain.getDomainId() + ":PROJECT"); - entityType.setDomainId(domain.getDomainId()); - entityType.setName("PROJECT"); - entityType.setDescription("Project entity type"); - sharingClient.createEntityType(entityType); - - entityType = new EntityType(); - entityType.setEntityTypeId(domain.getDomainId() + ":EXPERIMENT"); - entityType.setDomainId(domain.getDomainId()); - entityType.setName("EXPERIMENT"); - entityType.setDescription("Experiment entity type"); - sharingClient.createEntityType(entityType); - - entityType = new EntityType(); - entityType.setEntityTypeId(domain.getDomainId() + ":FILE"); - entityType.setDomainId(domain.getDomainId()); - entityType.setName("FILE"); - entityType.setDescription("File entity type"); - sharingClient.createEntityType(entityType); - - entityType = new EntityType(); - entityType.setEntityTypeId(domain.getDomainId() + ":" + ResourceType.APPLICATION_DEPLOYMENT.name()); - entityType.setDomainId(domain.getDomainId()); - entityType.setName("APPLICATION-DEPLOYMENT"); - entityType.setDescription("Application Deployment entity type"); - sharingClient.createEntityType(entityType); - - entityType = new EntityType(); - entityType.setEntityTypeId(domain.getDomainId() + ":" + ResourceType.GROUP_RESOURCE_PROFILE.name()); - entityType.setDomainId(domain.getDomainId()); - entityType.setName(ResourceType.GROUP_RESOURCE_PROFILE.name()); - entityType.setDescription("Group Resource Profile entity type"); - sharingClient.createEntityType(entityType); - - // Creating Permission Types for each domain - PermissionType permissionType = new PermissionType(); - permissionType.setPermissionTypeId(domain.getDomainId() + ":READ"); - permissionType.setDomainId(domain.getDomainId()); - permissionType.setName("READ"); - permissionType.setDescription("Read permission type"); - sharingClient.createPermissionType(permissionType); - - permissionType = new PermissionType(); - permissionType.setPermissionTypeId(domain.getDomainId() + ":WRITE"); - permissionType.setDomainId(domain.getDomainId()); - permissionType.setName("WRITE"); - permissionType.setDescription("Write permission type"); - sharingClient.createPermissionType(permissionType); - - permissionType = new PermissionType(); - permissionType.setPermissionTypeId(domain.getDomainId() + ":MANAGE_SHARING"); - permissionType.setDomainId(domain.getDomainId()); - permissionType.setName("MANAGE_SHARING"); - permissionType.setDescription("Sharing permission type"); - sharingClient.createPermissionType(permissionType); - - logger.debug("Airavata successfully created the gateway with " + gatewayId); - return gatewayId; + public String addGatewayWithSharing(Gateway gateway) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + String gatewayId = registryService.addGateway(gateway); + Domain domain = new Domain(); + domain.setDomainId(gateway.getGatewayId()); + domain.setName(gateway.getGatewayName()); + domain.setDescription("Domain entry for " + domain.getName()); + sharingRegistryService.createDomain(domain); + + // Creating Entity Types for each domain + EntityType entityType = new EntityType(); + entityType.setEntityTypeId(domain.getDomainId() + ":PROJECT"); + entityType.setDomainId(domain.getDomainId()); + entityType.setName("PROJECT"); + entityType.setDescription("Project entity type"); + sharingRegistryService.createEntityType(entityType); + + entityType = new EntityType(); + entityType.setEntityTypeId(domain.getDomainId() + ":EXPERIMENT"); + entityType.setDomainId(domain.getDomainId()); + entityType.setName("EXPERIMENT"); + entityType.setDescription("Experiment entity type"); + sharingRegistryService.createEntityType(entityType); + + entityType = new EntityType(); + entityType.setEntityTypeId(domain.getDomainId() + ":FILE"); + entityType.setDomainId(domain.getDomainId()); + entityType.setName("FILE"); + entityType.setDescription("File entity type"); + sharingRegistryService.createEntityType(entityType); + + entityType = new EntityType(); + entityType.setEntityTypeId(domain.getDomainId() + ":" + ResourceType.APPLICATION_DEPLOYMENT.name()); + entityType.setDomainId(domain.getDomainId()); + entityType.setName("APPLICATION-DEPLOYMENT"); + entityType.setDescription("Application Deployment entity type"); + sharingRegistryService.createEntityType(entityType); + + entityType = new EntityType(); + entityType.setEntityTypeId(domain.getDomainId() + ":" + ResourceType.GROUP_RESOURCE_PROFILE.name()); + entityType.setDomainId(domain.getDomainId()); + entityType.setName(ResourceType.GROUP_RESOURCE_PROFILE.name()); + entityType.setDescription("Group Resource Profile entity type"); + sharingRegistryService.createEntityType(entityType); + + // Creating Permission Types for each domain + PermissionType permissionType = new PermissionType(); + permissionType.setPermissionTypeId(domain.getDomainId() + ":READ"); + permissionType.setDomainId(domain.getDomainId()); + permissionType.setName("READ"); + permissionType.setDescription("Read permission type"); + sharingRegistryService.createPermissionType(permissionType); + + permissionType = new PermissionType(); + permissionType.setPermissionTypeId(domain.getDomainId() + ":WRITE"); + permissionType.setDomainId(domain.getDomainId()); + permissionType.setName("WRITE"); + permissionType.setDescription("Write permission type"); + sharingRegistryService.createPermissionType(permissionType); + + permissionType = new PermissionType(); + permissionType.setPermissionTypeId(domain.getDomainId() + ":MANAGE_SHARING"); + permissionType.setDomainId(domain.getDomainId()); + permissionType.setName("MANAGE_SHARING"); + permissionType.setDescription("Sharing permission type"); + sharingRegistryService.createPermissionType(permissionType); + + logger.debug("Airavata successfully created the gateway with " + gatewayId); + return gatewayId; + } catch (Throwable e) { + throw convertException(e, "Error while adding gateway"); + } } // Event publishing methods @@ -1766,7 +2181,7 @@ public void publishExperimentIntermediateOutputsEvent( * Validate and fetch intermediate outputs - checks access, job state, and existing processes */ public void validateAndFetchIntermediateOutputs( - SharingRegistryService.Client sharingClient, + AuthzToken authzToken, String airavataExperimentId, List outputNames, @@ -1774,7 +2189,7 @@ public void validateAndFetchIntermediateOutputs( throws Exception { // Verify that user has WRITE access to experiment final boolean hasAccess = - userHasAccessInternal(sharingClient, authzToken, airavataExperimentId, ResourcePermissionType.WRITE); + userHasAccessInternal( authzToken, airavataExperimentId, ResourcePermissionType.WRITE); if (!hasAccess) { throw new Exception("User does not have WRITE access to this experiment"); } @@ -1822,14 +2237,14 @@ public void validateAndFetchIntermediateOutputs( * Get intermediate output process status - finds the most recent matching process and returns its status */ public ProcessStatus getIntermediateOutputProcessStatusInternal( - SharingRegistryService.Client sharingClient, + AuthzToken authzToken, String airavataExperimentId, List outputNames) throws Exception { // Verify that user has READ access to experiment final boolean hasAccess = - userHasAccessInternal(sharingClient, authzToken, airavataExperimentId, ResourcePermissionType.READ); + userHasAccessInternal( authzToken, airavataExperimentId, ResourcePermissionType.READ); if (!hasAccess) { throw new Exception("User does not have READ access to this experiment"); } @@ -1868,51 +2283,51 @@ public ProcessStatus getIntermediateOutputProcessStatusInternal( // Access control methods public List getAllAccessibleUsers( - SharingRegistryService.Client sharingClient, + String gatewayId, String resourceId, ResourcePermissionType permissionType, - BiFunction> userListFunction) + BiFunction> userListFunction) throws Exception { HashSet accessibleUsers = new HashSet<>(); if (permissionType.equals(ResourcePermissionType.WRITE)) { - userListFunction.apply(sharingClient, ResourcePermissionType.WRITE).stream() + userListFunction.apply(sharingRegistryService, ResourcePermissionType.WRITE).stream() .forEach(u -> accessibleUsers.add(u.getUserId())); - userListFunction.apply(sharingClient, ResourcePermissionType.OWNER).stream() + userListFunction.apply(sharingRegistryService, ResourcePermissionType.OWNER).stream() .forEach(u -> accessibleUsers.add(u.getUserId())); } else if (permissionType.equals(ResourcePermissionType.READ)) { - userListFunction.apply(sharingClient, ResourcePermissionType.READ).stream() + userListFunction.apply(sharingRegistryService, ResourcePermissionType.READ).stream() .forEach(u -> accessibleUsers.add(u.getUserId())); - userListFunction.apply(sharingClient, ResourcePermissionType.OWNER).stream() + userListFunction.apply(sharingRegistryService, ResourcePermissionType.OWNER).stream() .forEach(u -> accessibleUsers.add(u.getUserId())); } else if (permissionType.equals(ResourcePermissionType.OWNER)) { - userListFunction.apply(sharingClient, ResourcePermissionType.OWNER).stream() + userListFunction.apply(sharingRegistryService, ResourcePermissionType.OWNER).stream() .forEach(u -> accessibleUsers.add(u.getUserId())); } else if (permissionType.equals(ResourcePermissionType.MANAGE_SHARING)) { - userListFunction.apply(sharingClient, ResourcePermissionType.MANAGE_SHARING).stream() + userListFunction.apply(sharingRegistryService, ResourcePermissionType.MANAGE_SHARING).stream() .forEach(u -> accessibleUsers.add(u.getUserId())); - userListFunction.apply(sharingClient, ResourcePermissionType.OWNER).stream() + userListFunction.apply(sharingRegistryService, ResourcePermissionType.OWNER).stream() .forEach(u -> accessibleUsers.add(u.getUserId())); } return new ArrayList<>(accessibleUsers); } public List getAllAccessibleGroups( - SharingRegistryService.Client sharingClient, + String gatewayId, String resourceId, ResourcePermissionType permissionType, - BiFunction> groupListFunction) + BiFunction> groupListFunction) throws Exception { HashSet accessibleGroups = new HashSet<>(); if (permissionType.equals(ResourcePermissionType.WRITE)) { - groupListFunction.apply(sharingClient, ResourcePermissionType.WRITE).stream() + groupListFunction.apply(sharingRegistryService, ResourcePermissionType.WRITE).stream() .forEach(g -> accessibleGroups.add(g.getGroupId())); } else if (permissionType.equals(ResourcePermissionType.READ)) { - groupListFunction.apply(sharingClient, ResourcePermissionType.READ).stream() + groupListFunction.apply(sharingRegistryService, ResourcePermissionType.READ).stream() .forEach(g -> accessibleGroups.add(g.getGroupId())); } else if (permissionType.equals(ResourcePermissionType.MANAGE_SHARING)) { - groupListFunction.apply(sharingClient, ResourcePermissionType.MANAGE_SHARING).stream() + groupListFunction.apply(sharingRegistryService, ResourcePermissionType.MANAGE_SHARING).stream() .forEach(g -> accessibleGroups.add(g.getGroupId())); } return new ArrayList<>(accessibleGroups); @@ -1922,19 +2337,19 @@ public List getAllAccessibleGroups( * Get all accessible users for a resource (includes shared and directly shared) */ public List getAllAccessibleUsersWithSharing( - SharingRegistryService.Client sharingClient, + AuthzToken authzToken, String resourceId, ResourcePermissionType permissionType, boolean directlySharedOnly) throws Exception { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - BiFunction> userListFunction; + BiFunction> userListFunction; if (directlySharedOnly) { userListFunction = (c, t) -> { try { return c.getListOfDirectlySharedUsers(gatewayId, resourceId, gatewayId + ":" + t.name()); - } catch (TException e) { + } catch (Exception e) { throw new RuntimeException(e); } }; @@ -1942,31 +2357,31 @@ public List getAllAccessibleUsersWithSharing( userListFunction = (c, t) -> { try { return c.getListOfSharedUsers(gatewayId, resourceId, gatewayId + ":" + t.name()); - } catch (TException e) { + } catch (Exception e) { throw new RuntimeException(e); } }; } - return getAllAccessibleUsers(sharingClient, gatewayId, resourceId, permissionType, userListFunction); + return getAllAccessibleUsers( gatewayId, resourceId, permissionType, userListFunction); } /** * Get all accessible groups for a resource (includes shared and directly shared) */ public List getAllAccessibleGroupsWithSharing( - SharingRegistryService.Client sharingClient, + AuthzToken authzToken, String resourceId, ResourcePermissionType permissionType, boolean directlySharedOnly) throws Exception { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - BiFunction> groupListFunction; + BiFunction> groupListFunction; if (directlySharedOnly) { groupListFunction = (c, t) -> { try { return c.getListOfDirectlySharedGroups(gatewayId, resourceId, gatewayId + ":" + t.name()); - } catch (TException e) { + } catch (Exception e) { throw new RuntimeException(e); } }; @@ -1974,22 +2389,22 @@ public List getAllAccessibleGroupsWithSharing( groupListFunction = (c, t) -> { try { return c.getListOfSharedGroups(gatewayId, resourceId, gatewayId + ":" + t.name()); - } catch (TException e) { + } catch (Exception e) { throw new RuntimeException(e); } }; } - return getAllAccessibleGroups(sharingClient, gatewayId, resourceId, permissionType, groupListFunction); + return getAllAccessibleGroups( gatewayId, resourceId, permissionType, groupListFunction); } // Group resource profile management with sharing registry integration public String createGroupResourceProfileWithSharing( - SharingRegistryService.Client sharingClient, + AuthzToken authzToken, GroupResourceProfile groupResourceProfile) throws Exception { String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); - validateGroupResourceProfile(sharingClient, authzToken, groupResourceProfile); + validateGroupResourceProfile( authzToken, groupResourceProfile); String groupResourceProfileId = createGroupResourceProfile(groupResourceProfile); if (ServerSettings.isEnableSharing()) { try { @@ -2000,8 +2415,8 @@ public String createGroupResourceProfileWithSharing( entity.setOwnerId(userName + "@" + groupResourceProfile.getGatewayId()); entity.setName(groupResourceProfile.getGroupResourceProfileName()); - sharingClient.createEntity(entity); - shareEntityWithAdminGatewayGroups(sharingClient, entity); + sharingRegistryService.createEntity(entity); + shareEntityWithAdminGatewayGroups( entity); } catch (Exception ex) { logger.error(ex.getMessage(), ex); logger.error("Rolling back group resource profile creation Group Resource Profile ID : " @@ -2018,7 +2433,7 @@ public String createGroupResourceProfileWithSharing( } public void validateGroupResourceProfile( - SharingRegistryService.Client sharingClient, + AuthzToken authzToken, GroupResourceProfile groupResourceProfile) throws Exception { @@ -2035,7 +2450,7 @@ public void validateGroupResourceProfile( tokenIds.add(groupResourceProfile.getDefaultCredentialStoreToken()); } for (String tokenId : tokenIds) { - if (!userHasAccessInternal(sharingClient, authzToken, tokenId, ResourcePermissionType.READ)) { + if (!userHasAccessInternal( authzToken, tokenId, ResourcePermissionType.READ)) { throw new Exception("User does not have READ permission to credential token " + tokenId + "."); } } @@ -2043,49 +2458,52 @@ public void validateGroupResourceProfile( // Launch experiment business logic public void launchExperimentWithValidation( - SharingRegistryService.Client sharingClient, AuthzToken authzToken, String gatewayId, String airavataExperimentId, Publisher experimentPublisher) - throws Exception { - ExperimentModel experiment = getExperiment(airavataExperimentId); - - if (experiment == null) { - throw new Exception("Requested experiment id " + airavataExperimentId + " does not exist in the system.."); - } - String username = authzToken.getClaimsMap().get(Constants.USER_NAME); + throws TException { + try { + ExperimentModel experiment = getExperiment(airavataExperimentId); - // For backwards compatibility, if there is no groupResourceProfileId, look up one that is shared with the user - if (!experiment.getUserConfigurationData().isSetGroupResourceProfileId()) { - List groupResourceProfiles = - getGroupResourceListWithSharing(sharingClient, authzToken, gatewayId); - if (groupResourceProfiles != null && !groupResourceProfiles.isEmpty()) { - // Just pick the first one - final String groupResourceProfileId = - groupResourceProfiles.get(0).getGroupResourceProfileId(); - logger.warn( - "Experiment {} doesn't have groupResourceProfileId, picking first one user has access to: {}", - airavataExperimentId, - groupResourceProfileId); - experiment.getUserConfigurationData().setGroupResourceProfileId(groupResourceProfileId); - updateExperimentConfiguration(airavataExperimentId, experiment.getUserConfigurationData()); - } else { - throw new Exception("User " + username + " in gateway " + gatewayId - + " doesn't have access to any group resource profiles."); + if (experiment == null) { + throw new ExperimentNotFoundException("Requested experiment id " + airavataExperimentId + " does not exist in the system.."); + } + String username = authzToken.getClaimsMap().get(Constants.USER_NAME); + + // For backwards compatibility, if there is no groupResourceProfileId, look up one that is shared with the user + if (!experiment.getUserConfigurationData().isSetGroupResourceProfileId()) { + List groupResourceProfiles = + getGroupResourceListWithSharing( authzToken, gatewayId); + if (groupResourceProfiles != null && !groupResourceProfiles.isEmpty()) { + // Just pick the first one + final String groupResourceProfileId = + groupResourceProfiles.get(0).getGroupResourceProfileId(); + logger.warn( + "Experiment {} doesn't have groupResourceProfileId, picking first one user has access to: {}", + airavataExperimentId, + groupResourceProfileId); + experiment.getUserConfigurationData().setGroupResourceProfileId(groupResourceProfileId); + updateExperimentConfiguration(airavataExperimentId, experiment.getUserConfigurationData()); + } else { + throw new Exception("User " + username + " in gateway " + gatewayId + + " doesn't have access to any group resource profiles."); + } } - } - // Validate access to group resource profile and application deployments - validateLaunchExperimentAccess(sharingClient, authzToken, gatewayId, experiment); - publishExperimentSubmitEvent(experimentPublisher, gatewayId, airavataExperimentId); + // Validate access to group resource profile and application deployments + validateLaunchExperimentAccess( authzToken, gatewayId, experiment); + publishExperimentSubmitEvent(experimentPublisher, gatewayId, airavataExperimentId); + } catch (Throwable e) { + throw convertException(e, "Error launching experiment"); + } } /** * Get group resource list with sharing registry integration */ public List getGroupResourceListWithSharing( - SharingRegistryService.Client sharingClient, AuthzToken authzToken, String gatewayId) throws Exception { + AuthzToken authzToken, String gatewayId) throws Exception { String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); List accessibleGroupResProfileIds = new ArrayList<>(); if (ServerSettings.isEnableSharing()) { @@ -2095,7 +2513,7 @@ public List getGroupResourceListWithSharing( searchCriteria.setSearchCondition(SearchCondition.EQUAL); searchCriteria.setValue(gatewayId + ":" + ResourceType.GROUP_RESOURCE_PROFILE.name()); filters.add(searchCriteria); - sharingClient + sharingRegistryService .searchEntities( authzToken.getClaimsMap().get(Constants.GATEWAY_ID), userName + "@" + gatewayId, @@ -2107,4 +2525,77 @@ public List getGroupResourceListWithSharing( } return getGroupResourceList(gatewayId, accessibleGroupResProfileIds); } + + // Sharing Registry Delegation Methods for ServerHandler + public boolean isDomainExists(String domainId) throws org.apache.airavata.sharing.registry.models.SharingRegistryException { + return sharingRegistryService.isDomainExists(domainId); + } + + public String createDomain(Domain domain) throws org.apache.airavata.sharing.registry.models.SharingRegistryException, org.apache.airavata.sharing.registry.models.DuplicateEntryException { + return sharingRegistryService.createDomain(domain); + } + + public String createUser(User user) throws org.apache.airavata.sharing.registry.models.SharingRegistryException, org.apache.airavata.sharing.registry.models.DuplicateEntryException { + return sharingRegistryService.createUser(user); + } + + public String createGroup(UserGroup group) throws org.apache.airavata.sharing.registry.models.SharingRegistryException, org.apache.airavata.sharing.registry.models.DuplicateEntryException { + return sharingRegistryService.createGroup(group); + } + + public boolean addUsersToGroup(String domainId, List userIds, String groupId) throws org.apache.airavata.sharing.registry.models.SharingRegistryException { + return sharingRegistryService.addUsersToGroup(domainId, userIds, groupId); + } + + public String createEntityType(org.apache.airavata.sharing.registry.models.EntityType entityType) throws org.apache.airavata.sharing.registry.models.SharingRegistryException, org.apache.airavata.sharing.registry.models.DuplicateEntryException { + return sharingRegistryService.createEntityType(entityType); + } + + public String createPermissionType(org.apache.airavata.sharing.registry.models.PermissionType permissionType) throws org.apache.airavata.sharing.registry.models.SharingRegistryException, org.apache.airavata.sharing.registry.models.DuplicateEntryException { + return sharingRegistryService.createPermissionType(permissionType); + } + + public boolean userHasAccess(String domainId, String userId, String entityId, String permissionTypeId) throws org.apache.airavata.sharing.registry.models.SharingRegistryException { + return sharingRegistryService.userHasAccess(domainId, userId, entityId, permissionTypeId); + } + + public org.apache.airavata.sharing.registry.models.Entity getEntity(String domainId, String entityId) throws org.apache.airavata.sharing.registry.models.SharingRegistryException { + return sharingRegistryService.getEntity(domainId, entityId); + } + + public void updateEntity(org.apache.airavata.sharing.registry.models.Entity entity) throws org.apache.airavata.sharing.registry.models.SharingRegistryException { + sharingRegistryService.updateEntity(entity); + } + + public boolean shareEntityWithUsers(String domainId, String entityId, List userList, String permissionTypeId, boolean cascade) throws org.apache.airavata.sharing.registry.models.SharingRegistryException { + return sharingRegistryService.shareEntityWithUsers(domainId, entityId, userList, permissionTypeId, cascade); + } + + public org.apache.airavata.model.credential.store.SSHCredential getSSHCredential(String token, String gatewayId) throws org.apache.airavata.credential.store.store.CredentialStoreException { + return credentialStoreService.getSSHCredential(token, gatewayId); + } + + public void createEntity(org.apache.airavata.sharing.registry.models.Entity entity) throws org.apache.airavata.sharing.registry.models.SharingRegistryException, org.apache.airavata.sharing.registry.models.DuplicateEntryException { + sharingRegistryService.createEntity(entity); + } + + public java.util.List searchEntities(String domainId, String userId, java.util.List filters, int offset, int limit) throws org.apache.airavata.sharing.registry.models.SharingRegistryException { + return sharingRegistryService.searchEntities(domainId, userId, filters, offset, limit); + } + + public boolean shareEntityWithGroups(String domainId, String entityId, List groupList, String permissionTypeId, boolean cascade) throws org.apache.airavata.sharing.registry.models.SharingRegistryException { + return sharingRegistryService.shareEntityWithGroups(domainId, entityId, groupList, permissionTypeId, cascade); + } + + public boolean revokeEntitySharingFromUsers(String domainId, String entityId, List userList, String permissionTypeId) throws org.apache.airavata.sharing.registry.models.SharingRegistryException { + return sharingRegistryService.revokeEntitySharingFromUsers(domainId, entityId, userList, permissionTypeId); + } + + public boolean revokeEntitySharingFromGroups(String domainId, String entityId, List groupList, String permissionTypeId) throws org.apache.airavata.sharing.registry.models.SharingRegistryException { + return sharingRegistryService.revokeEntitySharingFromGroups(domainId, entityId, groupList, permissionTypeId); + } + + public boolean deleteEntity(String domainId, String entityId) throws org.apache.airavata.sharing.registry.models.SharingRegistryException { + return sharingRegistryService.deleteEntity(domainId, entityId); + } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/CredentialStoreService.java b/airavata-api/src/main/java/org/apache/airavata/service/CredentialStoreService.java index 314dbd3798..f249231de5 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/CredentialStoreService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/CredentialStoreService.java @@ -71,7 +71,12 @@ public CredentialStoreService() credentialReader = new CredentialReaderImpl(dbUtil); } - public String addSSHCredential(SSHCredential sshCredential) throws CredentialStoreException { + private org.apache.airavata.credential.store.exception.CredentialStoreException convertException(Throwable e, String msg) { + logger.error(msg, e); + return new org.apache.airavata.credential.store.exception.CredentialStoreException(msg); + } + + public String addSSHCredential(SSHCredential sshCredential) throws org.apache.airavata.credential.store.exception.CredentialStoreException { try { org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential credential = new org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential(); @@ -96,12 +101,8 @@ public String addSSHCredential(SSHCredential sshCredential) throws CredentialSto credential.setCredentialOwnerType(CredentialOwnerType.GATEWAY); sshCredentialWriter.writeCredentials(credential); return token; - } catch (CredentialStoreException e) { - logger.error("Error occurred while saving SSH Credentials.", e); - throw new CredentialStoreException("Error occurred while saving SSH Credentials."); - } catch (Exception e) { - logger.error("Error occurred while generating key pair.", e); - throw new CredentialStoreException("Error occurred while generating key pair.."); + } catch (Throwable e) { + throw convertException(e, "Error occurred while saving SSH Credentials."); } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorService.java b/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorService.java index 4ada03ee17..d1af731fea 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorService.java @@ -41,6 +41,7 @@ import org.apache.airavata.model.data.replica.DataProductModel; import org.apache.airavata.model.data.replica.DataReplicaLocationModel; import org.apache.airavata.model.data.replica.ReplicaLocationCategory; +import org.apache.airavata.model.error.ExperimentNotFoundException; import org.apache.airavata.model.error.LaunchValidationException; import org.apache.airavata.model.experiment.ExperimentModel; import org.apache.airavata.model.experiment.ExperimentType; @@ -72,6 +73,21 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.exception.AiravataException; +import org.apache.airavata.common.logging.MDCConstants; +import org.apache.airavata.messaging.core.MessageHandler; +import org.apache.airavata.messaging.core.MessagingFactory; +import org.apache.airavata.messaging.core.Publisher; +import org.apache.airavata.messaging.core.Subscriber; +import org.apache.airavata.messaging.core.Type; +import org.apache.airavata.model.messaging.event.*; +import org.apache.curator.RetryPolicy; +import org.apache.curator.framework.CuratorFrameworkFactory; +import org.apache.curator.retry.ExponentialBackoffRetry; +import org.apache.thrift.TBase; +import org.slf4j.MDC; + public class OrchestratorService { private static final Logger logger = LoggerFactory.getLogger(OrchestratorService.class); @@ -79,6 +95,26 @@ public class OrchestratorService { private SimpleOrchestratorImpl orchestrator; private CuratorFramework curatorClient; private Publisher publisher; + private Subscriber statusSubscribe; + private Subscriber experimentSubscriber; + private String airavataUserName; + private String gatewayName; + + public OrchestratorService() throws OrchestratorException { + try { + this.orchestratorRegistryService = new OrchestratorRegistryService(); + setAiravataUserName(ServerSettings.getDefaultUser()); + this.orchestrator = new SimpleOrchestratorImpl(); + this.publisher = MessagingFactory.getPublisher(Type.STATUS); + this.orchestrator.initialize(); + this.orchestrator.getOrchestratorContext().setPublisher(this.publisher); + startCurator(); + this.statusSubscribe = getStatusSubscriber(); + this.experimentSubscriber = getExperimentSubscriber(); + } catch (Exception e) { + throw new OrchestratorException("Error initializing OrchestratorService", e); + } + } public OrchestratorService( OrchestratorRegistryService orchestratorRegistryService, @@ -98,7 +134,7 @@ public boolean launchExperiment(String experimentId, String gatewayId) throws Ex ZKPaths.mkdirs(curatorClient.getZookeeperClient().getZooKeeper(), experimentCancelNode); ExperimentModel experiment = orchestratorRegistryService.getExperiment(experimentId); if (experiment == null) { - throw new Exception("Error retrieving the Experiment by the given experimentID: " + experimentId); + throw new ExperimentNotFoundException("Error retrieving the Experiment by the given experimentID: " + experimentId); } UserConfigurationDataModel userConfigurationData = experiment.getUserConfigurationData(); @@ -457,7 +493,7 @@ private String getModuleId(String applicationId) throws Exception { private void launchWorkflowExperiment(String experimentId, String airavataCredStoreToken, String gatewayId) throws TException { - // FIXME - Workflow support not implemented + throw new UnsupportedOperationException("Workflow support not implemented"); } public void createAndValidateTasks(ExperimentModel experiment, boolean recreateTaskDag) throws Exception { @@ -512,7 +548,7 @@ public boolean launchSingleAppExperimentInternal( public void launchQueuedExperiment(String experimentId) throws Exception { ExperimentModel experiment = orchestratorRegistryService.getExperiment(experimentId); if (experiment == null) { - throw new Exception("Error retrieving the Experiment by the given experimentID: " + experimentId); + throw new ExperimentNotFoundException("Error retrieving the Experiment by the given experimentID: " + experimentId); } UserConfigurationDataModel userConfigurationData = experiment.getUserConfigurationData(); @@ -732,4 +768,147 @@ public boolean launchExperimentWithErrorHandling( throw new TException("Experiment '" + experimentId + "' launch failed.", e); } } + + private void startCurator() throws ApplicationSettingsException { + String connectionSting = ServerSettings.getZookeeperConnection(); + RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 5); + curatorClient = CuratorFrameworkFactory.newClient(connectionSting, retryPolicy); + curatorClient.start(); + } + + public String getExperimentNodePath(String experimentId) { + return ZKPaths.makePath(ZkConstants.ZOOKEEPER_EXPERIMENT_NODE, experimentId); + } + + private Subscriber getStatusSubscriber() throws AiravataException { + List routingKeys = new ArrayList<>(); + routingKeys.add("*.*.*"); + return MessagingFactory.getSubscriber(new ProcessStatusHandler(), routingKeys, Type.STATUS); + } + + private Subscriber getExperimentSubscriber() throws AiravataException { + List routingKeys = new ArrayList<>(); + routingKeys.add(ServerSettings.getRabbitmqExperimentLaunchQueueName()); + return MessagingFactory.getSubscriber(new ExperimentHandler(), routingKeys, Type.EXPERIMENT_LAUNCH); + } + + private void setAiravataUserName(String airavataUserName) { + this.airavataUserName = airavataUserName; + } + + private class ProcessStatusHandler implements MessageHandler { + @Override + public void onMessage(MessageContext message) { + if (message.getType().equals(MessageType.PROCESS)) { + try { + ProcessStatusChangeEvent processStatusChangeEvent = new ProcessStatusChangeEvent(); + TBase event = message.getEvent(); + byte[] bytes = ThriftUtils.serializeThriftObject(event); + ThriftUtils.createThriftFromBytes(bytes, processStatusChangeEvent); + ProcessIdentifier processIdentity = processStatusChangeEvent.getProcessIdentity(); + logger.info( + "expId: {}, processId: {} :- Process status changed event received for status {}", + processIdentity.getExperimentId(), + processIdentity.getProcessId(), + processStatusChangeEvent.getState().name()); + handleProcessStatusChange(processStatusChangeEvent, processIdentity); + } catch (TException e) { + logger.error("Message Id : " + message.getMessageId() + ", Message type : " + message.getType() + + "Error" + " while prcessing process status change event"); + throw new RuntimeException("Error while updating experiment status", e); + } catch (Throwable e) { + logger.error( + "Message Id : " + message.getMessageId() + ", Message type : " + message.getType() + "Error" + + " while prcessing process status change event", + e); + throw new RuntimeException("Error while updating experiment status", e); + } + } else { + System.out.println("Message Recieved with message id " + message.getMessageId() + " and with message " + + "type " + message.getType().name()); + } + } + } + + private class ExperimentHandler implements MessageHandler { + + @Override + public void onMessage(MessageContext messageContext) { + MDC.put(MDCConstants.GATEWAY_ID, messageContext.getGatewayId()); + switch (messageContext.getType()) { + case EXPERIMENT: + launchExperiment(messageContext); + break; + case EXPERIMENT_CANCEL: + cancelExperiment(messageContext); + break; + case INTERMEDIATE_OUTPUTS: + handleIntermediateOutputsEvent(messageContext); + break; + default: + experimentSubscriber.sendAck(messageContext.getDeliveryTag()); + logger.error("Orchestrator got un-support message type : " + messageContext.getType()); + break; + } + MDC.clear(); + } + + private void cancelExperiment(MessageContext messageContext) { + try { + byte[] bytes = ThriftUtils.serializeThriftObject(messageContext.getEvent()); + ExperimentSubmitEvent expEvent = new ExperimentSubmitEvent(); + ThriftUtils.createThriftFromBytes(bytes, expEvent); + logger.info( + "Cancelling experiment with experimentId: {} gateway Id: {}", + expEvent.getExperimentId(), + expEvent.getGatewayId()); + handleCancelExperiment(expEvent); + } catch (TException e) { + logger.error("Error while cancelling experiment", e); + throw new RuntimeException("Error while cancelling experiment", e); + } catch (Throwable e) { + logger.error("Error while cancelling experiment", e); + throw new RuntimeException("Error while cancelling experiment", e); + } finally { + experimentSubscriber.sendAck(messageContext.getDeliveryTag()); + } + } + + private void handleIntermediateOutputsEvent(MessageContext messageContext) { + try { + byte[] bytes = ThriftUtils.serializeThriftObject(messageContext.getEvent()); + ExperimentIntermediateOutputsEvent event = new ExperimentIntermediateOutputsEvent(); + ThriftUtils.createThriftFromBytes(bytes, event); + logger.info( + "INTERMEDIATE_OUTPUTS event for experimentId: {} gateway Id: {} outputs: {}", + event.getExperimentId(), + event.getGatewayId(), + event.getOutputNames()); + handleIntermediateOutputsEvent(event); + } catch (TException e) { + logger.error("Error while fetching intermediate outputs", e); + throw new RuntimeException("Error while fetching intermediate outputs", e); + } catch (Throwable e) { + logger.error("Error while fetching intermediate outputs", e); + throw new RuntimeException("Error while fetching intermediate outputs", e); + } finally { + experimentSubscriber.sendAck(messageContext.getDeliveryTag()); + } + } + + private void launchExperiment(MessageContext messageContext) { + try { + handleLaunchExperimentFromMessage(messageContext); + } catch (TException e) { + logger.error("Experiment launch failed due to Thrift conversion error", e); + } catch (org.apache.airavata.registry.cpi.RegistryException e) { + logger.error("Experiment launch failed due to registry error", e); + } catch (Throwable e) { + logger.error("An unknown issue while launching experiment", e); + } finally { + experimentSubscriber.sendAck(messageContext.getDeliveryTag()); + MDC.clear(); + } + } + } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/RegistryService.java b/airavata-api/src/main/java/org/apache/airavata/service/RegistryService.java index 8e280292a6..a66a269af4 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/RegistryService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/RegistryService.java @@ -73,6 +73,7 @@ import org.apache.airavata.registry.cpi.*; import org.apache.airavata.registry.cpi.ExpCatChildDataType; import org.apache.airavata.registry.cpi.WorkflowCatalogException; +import org.apache.airavata.registry.api.exception.RegistryServiceException; import org.apache.airavata.registry.cpi.utils.Constants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -80,6 +81,13 @@ public class RegistryService { private static final Logger logger = LoggerFactory.getLogger(RegistryService.class); + private RegistryServiceException convertException(Throwable e, String msg) { + logger.error(msg, e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage(msg + " More info : " + e.getMessage()); + return exception; + } + private ApplicationDeploymentRepository applicationDeploymentRepository = new ApplicationDeploymentRepository(); private ApplicationInterfaceRepository applicationInterfaceRepository = new ApplicationInterfaceRepository(); private StorageResourceRepository storageResourceRepository = new StorageResourceRepository(); @@ -120,32 +128,48 @@ public String getAPIVersion() { return org.apache.airavata.registry.api.registry_apiConstants.REGISTRY_API_VERSION; } - public boolean isUserExists(String gatewayId, String userName) throws RegistryException { - return userRepository.isUserExists(gatewayId, userName); + public boolean isUserExists(String gatewayId, String userName) throws RegistryServiceException { + try { + return userRepository.isUserExists(gatewayId, userName); + } catch (Throwable e) { + throw convertException(e, "Error while verifying user"); + } } - public List getAllUsersInGateway(String gatewayId) throws RegistryException { - return userRepository.getAllUsernamesInGateway(gatewayId); + public List getAllUsersInGateway(String gatewayId) throws RegistryServiceException { + try { + return userRepository.getAllUsernamesInGateway(gatewayId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving users"); + } } - public Gateway getGateway(String gatewayId) throws RegistryException { - if (!gatewayRepository.isGatewayExist(gatewayId)) { - logger.error("Gateway does not exist in the system. Please provide a valid gateway ID..."); - throw new RegistryException("Gateway does not exist in the system. Please provide a valid gateway ID..."); + public Gateway getGateway(String gatewayId) throws RegistryServiceException { + try { + if (!gatewayRepository.isGatewayExist(gatewayId)) { + logger.error("Gateway does not exist in the system. Please provide a valid gateway ID..."); + throw new RegistryException("Gateway does not exist in the system. Please provide a valid gateway ID..."); + } + Gateway gateway = gatewayRepository.getGateway(gatewayId); + logger.debug("Airavata retrieved gateway with gateway id : " + gateway.getGatewayId()); + return gateway; + } catch (Throwable e) { + throw convertException(e, "Error while getting the gateway"); } - Gateway gateway = gatewayRepository.getGateway(gatewayId); - logger.debug("Airavata retrieved gateway with gateway id : " + gateway.getGatewayId()); - return gateway; } - public boolean deleteGateway(String gatewayId) throws RegistryException { - if (!gatewayRepository.isGatewayExist(gatewayId)) { - logger.error("Gateway does not exist in the system. Please provide a valid gateway ID..."); - throw new RegistryException("Gateway does not exist in the system. Please provide a valid gateway ID..."); + public boolean deleteGateway(String gatewayId) throws RegistryServiceException { + try { + if (!gatewayRepository.isGatewayExist(gatewayId)) { + logger.error("Gateway does not exist in the system. Please provide a valid gateway ID..."); + throw new RegistryException("Gateway does not exist in the system. Please provide a valid gateway ID..."); + } + gatewayRepository.removeGateway(gatewayId); + logger.debug("Airavata deleted gateway with gateway id : " + gatewayId); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while deleting the gateway"); } - gatewayRepository.removeGateway(gatewayId); - logger.debug("Airavata deleted gateway with gateway id : " + gatewayId); - return true; } public List getAllGateways() throws RegistryException { @@ -172,20 +196,24 @@ public List getAllNotifications(String gatewayId) throws RegistryE return notifications; } - public Project getProject(String projectId) throws RegistryException { + public Project getProject(String projectId) throws RegistryException, ProjectNotFoundException { if (!projectRepository.isProjectExist(projectId)) { logger.error("Project does not exist in the system. Please provide a valid project ID..."); - throw new RegistryException("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 = projectRepository.getProject(projectId); return project; } - public boolean deleteProject(String projectId) throws RegistryException { + public boolean deleteProject(String projectId) throws RegistryException, ProjectNotFoundException { if (!projectRepository.isProjectExist(projectId)) { logger.error("Project does not exist in the system. Please provide a valid project ID..."); - throw new RegistryException("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; } projectRepository.removeProject(projectId); logger.debug("Airavata deleted project with project Id : " + projectId); @@ -1281,11 +1309,10 @@ public String createExperiment(String gatewayId, ExperimentModel experiment) thr if (experiment.getUserConfigurationData() != null && experiment.getUserConfigurationData().getComputationalResourceScheduling() != null - && experiment - .getUserConfigurationData() - .getComputationalResourceScheduling() - .getResourceHostId() - != null) { + && experiment.getUserConfigurationData() + .getComputationalResourceScheduling() + .getResourceHostId() + != null) { String compResourceId = experiment .getUserConfigurationData() @@ -1419,11 +1446,10 @@ public void updateExperiment(String airavataExperimentId, ExperimentModel experi case VALIDATED: if (experiment.getUserConfigurationData() != null && experiment.getUserConfigurationData().getComputationalResourceScheduling() != null - && experiment - .getUserConfigurationData() - .getComputationalResourceScheduling() - .getResourceHostId() - != null) { + && experiment.getUserConfigurationData() + .getComputationalResourceScheduling() + .getResourceHostId() + != null) { String compResourceId = experiment .getUserConfigurationData() .getComputationalResourceScheduling() diff --git a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/GroupManagerServiceHandler.java b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/GroupManagerServiceHandler.java index a983205e41..5bbc22f794 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/GroupManagerServiceHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/GroupManagerServiceHandler.java @@ -49,218 +49,88 @@ public String getAPIVersion() throws TException { @SecurityCheck public String createGroup(AuthzToken authzToken, GroupModel groupModel) throws GroupManagerServiceException, AuthorizationException, TException { - try { - return groupManagerService.createGroup(authzToken, groupModel); - } catch (GroupManagerServiceException e) { - throw e; - } catch (Exception e) { - String msg = "Error Creating Group"; - logger.error(msg, e); - GroupManagerServiceException exception = new GroupManagerServiceException(); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; - } + return groupManagerService.createGroup(authzToken, groupModel); } @Override @SecurityCheck public boolean updateGroup(AuthzToken authzToken, GroupModel groupModel) throws GroupManagerServiceException, AuthorizationException, TException { - try { - return groupManagerService.updateGroup(authzToken, groupModel); - } catch (GroupManagerServiceException e) { - throw e; - } catch (Exception e) { - String msg = "Error Updating Group"; - logger.error(msg, e); - GroupManagerServiceException exception = new GroupManagerServiceException(); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; - } + return groupManagerService.updateGroup(authzToken, groupModel); } @Override @SecurityCheck public boolean deleteGroup(AuthzToken authzToken, String groupId, String ownerId) throws GroupManagerServiceException, AuthorizationException, TException { - try { - return groupManagerService.deleteGroup(authzToken, groupId, ownerId); - } catch (GroupManagerServiceException e) { - throw e; - } catch (Exception e) { - String msg = "Error Deleting Group. Group ID: " + groupId; - logger.error(msg, e); - GroupManagerServiceException exception = new GroupManagerServiceException(); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; - } + return groupManagerService.deleteGroup(authzToken, groupId, ownerId); } @Override @SecurityCheck public GroupModel getGroup(AuthzToken authzToken, String groupId) throws GroupManagerServiceException, AuthorizationException, TException { - try { - return groupManagerService.getGroup(authzToken, groupId); - } catch (GroupManagerServiceException e) { - throw e; - } catch (Exception e) { - String msg = "Error Retreiving Group. Group ID: " + groupId; - logger.error(msg, e); - GroupManagerServiceException exception = new GroupManagerServiceException(); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; - } + return groupManagerService.getGroup(authzToken, groupId); } @Override @SecurityCheck public List getGroups(AuthzToken authzToken) throws GroupManagerServiceException, AuthorizationException, TException { - try { - return groupManagerService.getGroups(authzToken); - } catch (GroupManagerServiceException e) { - throw e; - } catch (Exception e) { - String msg = "Error Retrieving Groups"; - logger.error(msg, e); - GroupManagerServiceException exception = new GroupManagerServiceException(); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; - } + return groupManagerService.getGroups(authzToken); } @Override @SecurityCheck public List getAllGroupsUserBelongs(AuthzToken authzToken, String userName) throws GroupManagerServiceException, AuthorizationException, TException { - try { - return groupManagerService.getAllGroupsUserBelongs(authzToken, userName); - } catch (GroupManagerServiceException e) { - throw e; - } catch (Exception e) { - String msg = "Error Retreiving All Groups for User. User ID: " + userName; - logger.error(msg, e); - GroupManagerServiceException exception = new GroupManagerServiceException(); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; - } + return groupManagerService.getAllGroupsUserBelongs(authzToken, userName); } @Override public boolean addUsersToGroup(AuthzToken authzToken, List userIds, String groupId) throws GroupManagerServiceException, AuthorizationException, TException { - try { - return groupManagerService.addUsersToGroup(authzToken, userIds, groupId); - } catch (GroupManagerServiceException e) { - throw e; - } catch (Exception e) { - String msg = "Error adding users to group. Group ID: " + groupId; - logger.error(msg, e); - GroupManagerServiceException exception = new GroupManagerServiceException(); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; - } + return groupManagerService.addUsersToGroup(authzToken, userIds, groupId); } @Override public boolean removeUsersFromGroup(AuthzToken authzToken, List userIds, String groupId) throws GroupManagerServiceException, AuthorizationException, TException { - try { - return groupManagerService.removeUsersFromGroup(authzToken, userIds, groupId); - } catch (GroupManagerServiceException e) { - throw e; - } catch (Exception e) { - String msg = "Error remove users to group. Group ID: " + groupId; - logger.error(msg, e); - GroupManagerServiceException exception = new GroupManagerServiceException(); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; - } + return groupManagerService.removeUsersFromGroup(authzToken, userIds, groupId); } @Override @SecurityCheck public boolean transferGroupOwnership(AuthzToken authzToken, String groupId, String newOwnerId) throws GroupManagerServiceException, AuthorizationException, TException { - try { - return groupManagerService.transferGroupOwnership(authzToken, groupId, newOwnerId); - } catch (GroupManagerServiceException e) { - throw e; - } catch (Exception e) { - String msg = "Error Transferring Group Ownership"; - logger.error(msg, e); - GroupManagerServiceException exception = new GroupManagerServiceException(); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; - } + return groupManagerService.transferGroupOwnership(authzToken, groupId, newOwnerId); } @Override @SecurityCheck public boolean addGroupAdmins(AuthzToken authzToken, String groupId, List adminIds) throws GroupManagerServiceException, AuthorizationException, TException { - try { - return groupManagerService.addGroupAdmins(authzToken, groupId, adminIds); - } catch (GroupManagerServiceException e) { - throw e; - } catch (Exception e) { - String msg = "Error Adding Admins to Group. Group ID: " + groupId; - logger.error(msg, e); - GroupManagerServiceException exception = new GroupManagerServiceException(); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; - } + return groupManagerService.addGroupAdmins(authzToken, groupId, adminIds); } @Override @SecurityCheck public boolean removeGroupAdmins(AuthzToken authzToken, String groupId, List adminIds) throws GroupManagerServiceException, AuthorizationException, TException { - try { - return groupManagerService.removeGroupAdmins(authzToken, groupId, adminIds); - } catch (GroupManagerServiceException e) { - throw e; - } catch (Exception e) { - String msg = "Error Removing Admins from the Group. Group ID: " + groupId; - logger.error(msg, e); - GroupManagerServiceException exception = new GroupManagerServiceException(); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; - } + return groupManagerService.removeGroupAdmins(authzToken, groupId, adminIds); } @Override @SecurityCheck public boolean hasAdminAccess(AuthzToken authzToken, String groupId, String adminId) throws GroupManagerServiceException, AuthorizationException, TException { - try { - return groupManagerService.hasAdminAccess(authzToken, groupId, adminId); - } catch (GroupManagerServiceException e) { - throw e; - } catch (Exception e) { - String msg = "Error Checking Admin Access for the Group. Group ID: " + groupId + " Admin ID: " + adminId; - logger.error(msg, e); - GroupManagerServiceException exception = new GroupManagerServiceException(); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; - } + return groupManagerService.hasAdminAccess(authzToken, groupId, adminId); } @Override @SecurityCheck public boolean hasOwnerAccess(AuthzToken authzToken, String groupId, String ownerId) throws GroupManagerServiceException, AuthorizationException, TException { - try { - return groupManagerService.hasOwnerAccess(authzToken, groupId, ownerId); - } catch (GroupManagerServiceException e) { - throw e; - } catch (Exception e) { - String msg = "Error Checking Owner Access for the Group. Group ID: " + groupId + " Owner ID: " + ownerId; - logger.error(msg, e); - GroupManagerServiceException exception = new GroupManagerServiceException(); - exception.setMessage(msg + " More info : " + e.getMessage()); - throw exception; - } + return groupManagerService.hasOwnerAccess(authzToken, groupId, ownerId); } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/IamAdminServicesHandler.java b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/IamAdminServicesHandler.java index ca72627f70..13191d832e 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/IamAdminServicesHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/IamAdminServicesHandler.java @@ -54,7 +54,7 @@ public Gateway setUpGateway(AuthzToken authzToken, Gateway gateway) return iamAdminService.setUpGateway(authzToken, gateway); } catch (IamAdminServicesException e) { throw e; - } catch (Exception ex) { + } catch (Throwable ex) { logger.error("Gateway Setup Failed, reason: " + ex.getMessage(), ex); IamAdminServicesException iamAdminServicesException = new IamAdminServicesException(ex.getMessage()); throw iamAdminServicesException; @@ -69,7 +69,7 @@ public boolean isUsernameAvailable(AuthzToken authzToken, String username) return iamAdminService.isUsernameAvailable(authzToken, username); } catch (IamAdminServicesException e) { throw e; - } catch (Exception ex) { + } catch (Throwable ex) { String msg = "Error while checking username availability, reason: " + ex.getMessage(); logger.error(msg, ex); throw new IamAdminServicesException(msg); @@ -90,7 +90,7 @@ public boolean registerUser( return iamAdminService.registerUser(authzToken, username, emailAddress, firstName, lastName, newPassword); } catch (IamAdminServicesException e) { throw e; - } catch (Exception ex) { + } catch (Throwable ex) { String msg = "Error while registering user into Identity Server, reason: " + ex.getMessage(); logger.error(msg, ex); throw new IamAdminServicesException(msg); @@ -105,7 +105,7 @@ public boolean enableUser(AuthzToken authzToken, String username) return iamAdminService.enableUser(authzToken, username); } catch (IamAdminServicesException e) { throw e; - } catch (Exception ex) { + } catch (Throwable ex) { String msg = "Error while enabling user account, reason: " + ex.getMessage(); logger.error(msg, ex); throw new IamAdminServicesException(msg); @@ -120,7 +120,7 @@ public boolean isUserEnabled(AuthzToken authzToken, String username) return iamAdminService.isUserEnabled(authzToken, username); } catch (IamAdminServicesException e) { throw e; - } catch (Exception ex) { + } catch (Throwable ex) { String msg = "Error while checking if user account is enabled, reason: " + ex.getMessage(); logger.error(msg, ex); throw new IamAdminServicesException(msg); @@ -135,7 +135,7 @@ public boolean isUserExist(AuthzToken authzToken, String username) return iamAdminService.isUserExist(authzToken, username); } catch (IamAdminServicesException e) { throw e; - } catch (Exception ex) { + } catch (Throwable ex) { String msg = "Error while checking if user account exists, reason: " + ex.getMessage(); logger.error(msg, ex); throw new IamAdminServicesException(msg); @@ -150,7 +150,7 @@ public UserProfile getUser(AuthzToken authzToken, String username) return iamAdminService.getUser(authzToken, username); } catch (IamAdminServicesException e) { throw e; - } catch (Exception ex) { + } catch (Throwable ex) { String msg = "Error while retrieving user profile from IAM backend, reason: " + ex.getMessage(); logger.error(msg, ex); throw new IamAdminServicesException(msg); @@ -165,7 +165,7 @@ public List getUsers(AuthzToken authzToken, int offset, int limit, return iamAdminService.getUsers(authzToken, offset, limit, search); } catch (IamAdminServicesException e) { throw e; - } catch (Exception ex) { + } catch (Throwable ex) { String msg = "Error while retrieving user profile from IAM backend, reason: " + ex.getMessage(); logger.error(msg, ex); throw new IamAdminServicesException(msg); @@ -180,7 +180,7 @@ public boolean resetUserPassword(AuthzToken authzToken, String username, String return iamAdminService.resetUserPassword(authzToken, username, newPassword); } catch (IamAdminServicesException e) { throw e; - } catch (Exception ex) { + } catch (Throwable ex) { String msg = "Error while resetting user password in Identity Server, reason: " + ex.getMessage(); logger.error(msg, ex); throw new IamAdminServicesException(msg); @@ -195,7 +195,7 @@ public List findUsers(AuthzToken authzToken, String email, String u return iamAdminService.findUsers(authzToken, email, userId); } catch (IamAdminServicesException e) { throw e; - } catch (Exception ex) { + } catch (Throwable ex) { String msg = "Error while retrieving users from Identity Server, reason: " + ex.getMessage(); logger.error(msg, ex); throw new IamAdminServicesException(msg); @@ -210,7 +210,7 @@ public void updateUserProfile(AuthzToken authzToken, UserProfile userDetails) iamAdminService.updateUserProfile(authzToken, userDetails); } catch (IamAdminServicesException e) { throw e; - } catch (Exception ex) { + } catch (Throwable ex) { String msg = "Error while updating user profile, reason: " + ex.getMessage(); logger.error(msg, ex); throw new IamAdminServicesException(msg); @@ -225,7 +225,7 @@ public boolean deleteUser(AuthzToken authzToken, String username) return iamAdminService.deleteUser(authzToken, username); } catch (IamAdminServicesException e) { throw e; - } catch (Exception ex) { + } catch (Throwable ex) { String msg = "Error while deleting user, reason: " + ex.getMessage(); logger.error(msg, ex); throw new IamAdminServicesException(msg); @@ -241,7 +241,7 @@ public boolean addRoleToUser(AuthzToken authzToken, String username, String role return iamAdminService.addRoleToUser(authzToken, username, roleName); } catch (IamAdminServicesException e) { throw e; - } catch (Exception ex) { + } catch (Throwable ex) { String msg = "Error while adding role to user, reason: " + ex.getMessage(); logger.error(msg, ex); throw new IamAdminServicesException(msg); @@ -257,7 +257,7 @@ public boolean removeRoleFromUser(AuthzToken authzToken, String username, String return iamAdminService.removeRoleFromUser(authzToken, username, roleName); } catch (IamAdminServicesException e) { throw e; - } catch (Exception ex) { + } catch (Throwable ex) { String msg = "Error while removing role from user, reason: " + ex.getMessage(); logger.error(msg, ex); throw new IamAdminServicesException(msg); @@ -273,7 +273,7 @@ public List getUsersWithRole(AuthzToken authzToken, String roleName return iamAdminService.getUsersWithRole(authzToken, roleName); } catch (IamAdminServicesException e) { throw e; - } catch (Exception ex) { + } catch (Throwable ex) { String msg = "Error while retrieving users with role, reason: " + ex.getMessage(); logger.error(msg, ex); throw new IamAdminServicesException(msg); diff --git a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/TenantProfileServiceHandler.java b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/TenantProfileServiceHandler.java index 3db89e09ec..75b6d9413e 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/TenantProfileServiceHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/TenantProfileServiceHandler.java @@ -57,7 +57,7 @@ public String addGateway(AuthzToken authzToken, Gateway gateway) return tenantProfileService.addGateway(authzToken, gateway); } catch (TenantProfileServiceException e) { throw e; - } catch (Exception ex) { + } catch (Throwable ex) { logger.error("Error adding gateway-profile, reason: " + ex.getMessage(), ex); TenantProfileServiceException exception = new TenantProfileServiceException(); exception.setMessage("Error adding gateway-profile, reason: " + ex.getMessage()); @@ -73,7 +73,7 @@ public boolean updateGateway(AuthzToken authzToken, Gateway updatedGateway) return tenantProfileService.updateGateway(authzToken, updatedGateway); } catch (TenantProfileServiceException e) { throw e; - } catch (Exception ex) { + } catch (Throwable ex) { logger.error("Error updating gateway-profile, reason: " + ex.getMessage(), ex); TenantProfileServiceException exception = new TenantProfileServiceException(); exception.setMessage("Error updating gateway-profile, reason: " + ex.getMessage()); @@ -89,7 +89,7 @@ public Gateway getGateway(AuthzToken authzToken, String airavataInternalGatewayI return tenantProfileService.getGateway(authzToken, airavataInternalGatewayId); } catch (TenantProfileServiceException e) { throw e; - } catch (Exception ex) { + } catch (Throwable ex) { logger.error("Error getting gateway-profile, reason: " + ex.getMessage(), ex); TenantProfileServiceException exception = new TenantProfileServiceException(); exception.setMessage("Error getting gateway-profile, reason: " + ex.getMessage()); @@ -105,7 +105,7 @@ public boolean deleteGateway(AuthzToken authzToken, String airavataInternalGatew return tenantProfileService.deleteGateway(authzToken, airavataInternalGatewayId, gatewayId); } catch (TenantProfileServiceException e) { throw e; - } catch (Exception ex) { + } catch (Throwable ex) { logger.error("Error deleting gateway-profile, reason: " + ex.getMessage(), ex); TenantProfileServiceException exception = new TenantProfileServiceException(); exception.setMessage("Error deleting gateway-profile, reason: " + ex.getMessage()); @@ -121,7 +121,7 @@ public List getAllGateways(AuthzToken authzToken) return tenantProfileService.getAllGateways(authzToken); } catch (TenantProfileServiceException e) { throw e; - } catch (Exception ex) { + } catch (Throwable ex) { logger.error("Error getting all gateway-profiles, reason: " + ex.getMessage(), ex); TenantProfileServiceException exception = new TenantProfileServiceException(); exception.setMessage("Error getting all gateway-profiles, reason: " + ex.getMessage()); @@ -137,7 +137,7 @@ public boolean isGatewayExist(AuthzToken authzToken, String gatewayId) return tenantProfileService.isGatewayExist(authzToken, gatewayId); } catch (TenantProfileServiceException e) { throw e; - } catch (Exception ex) { + } catch (Throwable ex) { logger.error("Error checking if gateway-profile exists, reason: " + ex.getMessage(), ex); TenantProfileServiceException exception = new TenantProfileServiceException(); exception.setMessage("Error checking if gateway-profile exists, reason: " + ex.getMessage()); @@ -153,7 +153,7 @@ public List getAllGatewaysForUser(AuthzToken authzToken, String request return tenantProfileService.getAllGatewaysForUser(authzToken, requesterUsername); } catch (TenantProfileServiceException e) { throw e; - } catch (Exception ex) { + } catch (Throwable ex) { logger.error("Error getting user's gateway-profiles, reason: " + ex.getMessage(), ex); TenantProfileServiceException exception = new TenantProfileServiceException(); exception.setMessage("Error getting user's gateway-profiles, reason: " + ex.getMessage()); diff --git a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/UserProfileServiceHandler.java b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/UserProfileServiceHandler.java index fb4ef9a2d6..91fb2df49f 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/UserProfileServiceHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/UserProfileServiceHandler.java @@ -53,7 +53,7 @@ public String initializeUserProfile(AuthzToken authzToken) return userProfileService.initializeUserProfile(authzToken); } catch (UserProfileServiceException e) { throw e; - } catch (Exception e) { + } catch (Throwable e) { logger.error("Error while initializing user profile", e); UserProfileServiceException exception = new UserProfileServiceException(); exception.setMessage("Error while initializing user profile. More info : " + e.getMessage()); @@ -69,7 +69,7 @@ public String addUserProfile(AuthzToken authzToken, UserProfile userProfile) return userProfileService.addUserProfile(authzToken, userProfile); } catch (UserProfileServiceException e) { throw e; - } catch (Exception e) { + } catch (Throwable e) { logger.error("Error while creating user profile", e); UserProfileServiceException exception = new UserProfileServiceException(); exception.setMessage("Error while creating user profile. More info : " + e.getMessage()); @@ -85,7 +85,7 @@ public boolean updateUserProfile(AuthzToken authzToken, UserProfile userProfile) return userProfileService.updateUserProfile(authzToken, userProfile); } catch (UserProfileServiceException e) { throw e; - } catch (Exception e) { + } catch (Throwable e) { logger.error("Error while Updating user profile", e); UserProfileServiceException exception = new UserProfileServiceException(); exception.setMessage("Error while Updating user profile. More info : " + e.getMessage()); @@ -101,7 +101,7 @@ public UserProfile getUserProfileById(AuthzToken authzToken, String userId, Stri return userProfileService.getUserProfileById(authzToken, userId, gatewayId); } catch (UserProfileServiceException e) { throw e; - } catch (Exception e) { + } catch (Throwable e) { logger.error("Error retrieving user profile by ID", e); UserProfileServiceException exception = new UserProfileServiceException(); exception.setMessage("Error retrieving user profile by ID. More info : " + e.getMessage()); @@ -117,7 +117,7 @@ public boolean deleteUserProfile(AuthzToken authzToken, String userId, String ga return userProfileService.deleteUserProfile(authzToken, userId, gatewayId); } catch (UserProfileServiceException e) { throw e; - } catch (Exception e) { + } catch (Throwable e) { logger.error("Error while deleting user profile", e); UserProfileServiceException exception = new UserProfileServiceException(); exception.setMessage("Error while deleting user profile. More info : " + e.getMessage()); @@ -133,7 +133,7 @@ public List getAllUserProfilesInGateway(AuthzToken authzToken, Stri return userProfileService.getAllUserProfilesInGateway(authzToken, gatewayId, offset, limit); } catch (UserProfileServiceException e) { throw e; - } catch (Exception e) { + } catch (Throwable e) { logger.error("Error while retrieving user profile List", e); UserProfileServiceException exception = new UserProfileServiceException(); exception.setMessage("Error while retrieving user profile List. More info : " + e.getMessage()); @@ -148,7 +148,7 @@ public boolean doesUserExist(AuthzToken authzToken, String userId, String gatewa return userProfileService.doesUserExist(authzToken, userId, gatewayId); } catch (UserProfileServiceException e) { throw e; - } catch (Exception e) { + } catch (Throwable e) { logger.error("Error while finding user profile", e); UserProfileServiceException exception = new UserProfileServiceException(); exception.setMessage("Error while finding user profile. More info : " + e.getMessage()); From 50586e36c30e8e9641dce45f3a68871f2bdb6b0d Mon Sep 17 00:00:00 2001 From: yasithdev Date: Tue, 25 Nov 2025 13:16:47 -0600 Subject: [PATCH 19/26] do all exception handling in services, and handlers simply call them --- .../server/handler/AiravataServerHandler.java | 2049 +-------- .../server/CredentialStoreServerHandler.java | 126 +- .../handler/RegistryServerHandler.java | 1222 +---- .../airavata/service/AiravataService.java | 2659 +++++++++-- .../airavata/service/GroupManagerService.java | 7 + .../airavata/service/IamAdminService.java | 43 +- .../airavata/service/RegistryService.java | 4054 ++++++++++------- .../service/SharingRegistryService.java | 1362 +++--- .../service/TenantProfileService.java | 7 + .../airavata/service/UserProfileService.java | 7 + .../handlers/IamAdminServicesHandler.java | 153 +- .../handlers/TenantProfileServiceHandler.java | 77 +- .../handlers/UserProfileServiceHandler.java | 80 +- .../server/SharingRegistryServerHandler.java | 523 +-- 14 files changed, 5905 insertions(+), 6464 deletions(-) diff --git a/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java index ab9973f5e7..cdea1d8f48 100644 --- a/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java @@ -134,7 +134,6 @@ public String getAPIVersion() { @SecurityCheck public boolean isUserExists(AuthzToken authzToken, String gatewayId, String userName) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - logger.debug("Checking if the user" + userName + "exists in the gateway" + gatewayId); return airavataService.isUserExists(gatewayId, userName); } @@ -164,59 +163,35 @@ public List getAllUsersInGateway(AuthzToken authzToken, String gatewayId @SecurityCheck public boolean updateGateway(AuthzToken authzToken, String gatewayId, Gateway updatedGateway) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.updateGateway(gatewayId, updatedGateway); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while updating the gateway"); - } } @Override @SecurityCheck public Gateway getGateway(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { - Gateway result = airavataService.getGateway(gatewayId); - logger.debug("Airavata found the gateway with " + gatewayId); - return result; - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while retrieving gateway"); - } + return airavataService.getGateway(gatewayId); } @Override @SecurityCheck public boolean deleteGateway(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.deleteGateway(gatewayId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while deleting the gateway"); - } } @Override @SecurityCheck public List getAllGateways(AuthzToken authzToken) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { - logger.debug("Airavata searching for all gateways"); return airavataService.getAllGateways(); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while retrieving all gateways"); - } } @Override @SecurityCheck public boolean isGatewayExist(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { - logger.debug("Airavata verifying if the gateway with " + gatewayId + "exits"); return airavataService.isGatewayExist(gatewayId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while checking if gateway exists"); - } } /** @@ -230,55 +205,35 @@ public boolean isGatewayExist(AuthzToken authzToken, String gatewayId) @SecurityCheck public String createNotification(AuthzToken authzToken, Notification notification) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.createNotification(notification); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while creating notification"); - } } @Override @SecurityCheck public boolean updateNotification(AuthzToken authzToken, Notification notification) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.updateNotification(notification); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while updating notification"); - } } @Override @SecurityCheck public boolean deleteNotification(AuthzToken authzToken, String gatewayId, String notificationId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.deleteNotification(gatewayId, notificationId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while deleting notification"); - } } // No security check @Override public Notification getNotification(AuthzToken authzToken, String gatewayId, String notificationId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getNotification(gatewayId, notificationId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while retrieving notification"); - } } // No security check @Override public List getAllNotifications(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getAllNotifications(gatewayId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while getting all notifications"); - } } @Override @@ -287,11 +242,7 @@ public String generateAndRegisterSSHKeys(AuthzToken authzToken, String descripti throws InvalidRequestException, AiravataClientException, AiravataSystemException { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); - try { return airavataService.generateAndRegisterSSHKeys( gatewayId, userName, description); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error occurred while registering SSH Credential"); - } } /** @@ -310,11 +261,7 @@ public String registerPwdCredential( throws AiravataClientException, AiravataSystemException, AuthorizationException, InvalidRequestException { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); - try { return airavataService.registerPwdCredential( gatewayId, userName, loginUserName, password, description); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error occurred while registering PWD Credential"); - } } @Override @@ -322,12 +269,7 @@ public String registerPwdCredential( public CredentialSummary getCredentialSummary(AuthzToken authzToken, String tokenId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - try { return airavataService.getCredentialSummaryWithAuth( authzToken, tokenId, gatewayId); - } catch (Throwable e) { - String msg = "Error retrieving credential summary for token " + tokenId + ". GatewayId: " + gatewayId; - throw ThriftExceptionHandler.convertException(e, msg); - } } @Override @@ -336,11 +278,7 @@ public List getAllCredentialSummaries(AuthzToken authzToken, throws InvalidRequestException, AiravataClientException, AiravataSystemException { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); - try { return airavataService.getAllCredentialSummariesWithAuth( authzToken, type, gatewayId, userName); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error retrieving credential summaries of type " + type + ". GatewayId: " + gatewayId); - } } @Override @@ -348,11 +286,7 @@ public List getAllCredentialSummaries(AuthzToken authzToken, public boolean deleteSSHPubKey(AuthzToken authzToken, String airavataCredStoreToken) throws AiravataClientException, AiravataSystemException, AuthorizationException, InvalidRequestException { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - try { return airavataService.deleteSSHPubKey( authzToken, airavataCredStoreToken, gatewayId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error occurred while deleting SSH credential"); - } } @Override @@ -360,11 +294,7 @@ public boolean deleteSSHPubKey(AuthzToken authzToken, String airavataCredStoreTo public boolean deletePWDCredential(AuthzToken authzToken, String airavataCredStoreToken) throws AiravataClientException, AiravataSystemException, AuthorizationException, InvalidRequestException { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - try { return airavataService.deletePWDCredentialWithAuth( authzToken, airavataCredStoreToken, gatewayId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error occurred while deleting PWD credential"); - } } /** @@ -376,11 +306,7 @@ public boolean deletePWDCredential(AuthzToken authzToken, String airavataCredSto @SecurityCheck public String createProject(AuthzToken authzToken, String gatewayId, Project project) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.createProjectWithSharing( gatewayId, project); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while creating the project"); - } } @Override @@ -388,11 +314,7 @@ public String createProject(AuthzToken authzToken, String gatewayId, Project pro public void updateProject(AuthzToken authzToken, String projectId, Project updatedProject) throws InvalidRequestException, AiravataClientException, AiravataSystemException, ProjectNotFoundException, AuthorizationException { - try { airavataService.updateProjectWithAuth( authzToken, projectId, updatedProject); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while updating the project"); - } } @Override @@ -400,11 +322,7 @@ public void updateProject(AuthzToken authzToken, String projectId, Project updat public boolean deleteProject(AuthzToken authzToken, String projectId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, ProjectNotFoundException, AuthorizationException { - try { return airavataService.deleteProjectWithAuth( authzToken, projectId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while removing the project"); - } } private boolean validateString(String name) { @@ -425,11 +343,7 @@ private boolean validateString(String name) { public Project getProject(AuthzToken authzToken, String projectId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, ProjectNotFoundException, AuthorizationException { - try { return airavataService.getProjectWithAuth( authzToken, projectId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while retrieving the project"); - } } /** @@ -584,11 +498,7 @@ public List getExperimentsInProject(AuthzToken authzToken, Stri public List getUserExperiments( AuthzToken authzToken, String gatewayId, String userName, int limit, int offset) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getUserExperiments(gatewayId, userName, limit, offset); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while retrieving the experiments. More info :"); - } } /** @@ -617,13 +527,7 @@ public List getUserExperiments( @SecurityCheck public String createExperiment(AuthzToken authzToken, String gatewayId, ExperimentModel experiment) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - // TODO: verify that gatewayId and experiment.gatewayId match authzToken - logger.info("Api server accepted experiment creation with name {}", experiment.getExperimentName()); - try { return airavataService.createExperimentWithSharingAndPublish( statusPublisher, gatewayId, experiment); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while creating the experiment"); - } } /** @@ -641,11 +545,7 @@ public String createExperiment(AuthzToken authzToken, String gatewayId, Experime @SecurityCheck public boolean deleteExperiment(AuthzToken authzToken, String experimentId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.deleteExperimentWithAuth( authzToken, experimentId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while deleting the experiment"); - } } /** @@ -713,12 +613,7 @@ public ExperimentModel getExperimentByAdmin(AuthzToken authzToken, String airava public ExperimentModel getDetailedExperimentTree(AuthzToken authzToken, String airavataExperimentId) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { - ExperimentModel result = airavataService.getDetailedExperimentTree(airavataExperimentId); - return result; - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while retrieving the experiment"); - } + return airavataService.getDetailedExperimentTree(airavataExperimentId); } /** @@ -836,21 +731,15 @@ public boolean validateExperiment(AuthzToken authzToken, String airavataExperime @Override @SecurityCheck public ExperimentStatus getExperimentStatus(AuthzToken authzToken, String airavataExperimentId) { - try { return airavataService.getExperimentStatus(airavataExperimentId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error retrieving experiment status"); - } } + } @Override @SecurityCheck public List getExperimentOutputs(AuthzToken authzToken, String airavataExperimentId) throws AuthorizationException { - try { return airavataService.getExperimentOutputs(airavataExperimentId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while retrieving the experiment outputs"); - } } + } @Override @SecurityCheck @@ -865,24 +754,7 @@ public List getIntermediateOutputs(AuthzToken authzToken, public void fetchIntermediateOutputs(AuthzToken authzToken, String airavataExperimentId, List outputNames) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { airavataService.validateAndFetchIntermediateOutputs( authzToken, airavataExperimentId, outputNames, experimentPublisher); - } catch (Throwable e) { - if (e.getMessage() != null && e.getMessage().contains("does not have WRITE access")) { - logger.error(e.getMessage(), e); - throw new AuthorizationException(e.getMessage()); - } else if (e.getMessage() != null - && (e.getMessage().contains("does not have currently ACTIVE job") - || e.getMessage().contains("already intermediate output fetching tasks"))) { - logger.error(e.getMessage(), e); - throw new InvalidRequestException(e.getMessage()); - } - logger.error( - "Error while processing request to fetch intermediate outputs for experiment: " - + airavataExperimentId, - e); - throw ThriftExceptionHandler.convertException(e, "Error occurred"); - } } @Override @@ -891,43 +763,22 @@ public ProcessStatus getIntermediateOutputProcessStatus( AuthzToken authzToken, String airavataExperimentId, List outputNames) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getIntermediateOutputProcessStatusInternal( authzToken, airavataExperimentId, outputNames); - } catch (Throwable e) { - if (e.getMessage() != null && e.getMessage().contains("does not have READ access")) { - logger.debug(e.getMessage(), e); - throw new AuthorizationException(e.getMessage()); - } else if (e.getMessage() != null && e.getMessage().contains("No matching intermediate output")) { - logger.debug(e.getMessage(), e); - throw new InvalidRequestException(e.getMessage()); - } - logger.error( - "Error while processing request to get intermediate output process status for experiment: " - + airavataExperimentId, - e); - throw ThriftExceptionHandler.convertException(e, "Error occurred"); - } } @SecurityCheck public Map getJobStatuses(AuthzToken authzToken, String airavataExperimentId) throws AuthorizationException { - try { return airavataService.getJobStatuses(airavataExperimentId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while retrieving the job statuses"); - } } + } @Override @SecurityCheck public List getJobDetails(AuthzToken authzToken, String airavataExperimentId) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getJobDetails(airavataExperimentId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while retrieving the job details"); - } } + } /** * Launch a previously created and configured experiment. Airavata Server will then start processing the request and appropriate @@ -960,23 +811,9 @@ public List getJobDetails(AuthzToken authzToken, String airavataExperi @SecurityCheck public void launchExperiment(AuthzToken authzToken, final String airavataExperimentId, String gatewayId) throws AiravataClientException, AiravataSystemException, AuthorizationException, ExperimentNotFoundException, InvalidRequestException, TException { - // TODO: verify that gatewayId matches gatewayId in authzToken - logger.info("Launching experiment {}", airavataExperimentId); airavataService.launchExperimentWithValidation( authzToken, gatewayId, airavataExperimentId, experimentPublisher); - logger.info("Experiment with ExpId: " + airavataExperimentId + " was submitted in gateway with gatewayID: " - + gatewayId); } - // private OrchestratorService.Client getOrchestratorClient() { - // try { - // final String serverHost = ServerSettings.getOrchestratorServerHost(); - // final int serverPort = ServerSettings.getOrchestratorServerPort(); - // return OrchestratorClientFactory.createOrchestratorClient(serverHost, serverPort); - // } catch (Throwable e) { - // throw new TException(e); - // } - // } - /** * Clone an specified experiment with a new name. A copy of the experiment configuration is made and is persisted with new metadata. * The client has to subsequently update this configuration if needed and launch the cloned experiment. @@ -1024,19 +861,14 @@ public String cloneExperiment( AuthzToken authzToken, String existingExperimentID, String newExperimentName, String newExperimentProjectId) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException, ProjectNotFoundException { - try { // getExperiment will apply sharing permissions ExperimentModel existingExperiment = this.getExperiment(authzToken, existingExperimentID); - return cloneExperimentInternal( + return airavataService.cloneExperimentInternal( authzToken, existingExperimentID, newExperimentName, newExperimentProjectId, existingExperiment); - } catch (Throwable e) { - logger.error(existingExperimentID, "Error while cloning the experiment with existing configuration...", e); - throw ThriftExceptionHandler.convertException(e, "Error occurred"); - } } @Override @@ -1045,137 +877,14 @@ public String cloneExperimentByAdmin( AuthzToken authzToken, String existingExperimentID, String newExperimentName, String newExperimentProjectId) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException, ProjectNotFoundException { - try { // get existing experiment by bypassing normal sharing permissions for the admin user ExperimentModel existingExperiment = this.getExperimentByAdmin(authzToken, existingExperimentID); - return cloneExperimentInternal( + return airavataService.cloneExperimentInternal( authzToken, existingExperimentID, newExperimentName, newExperimentProjectId, existingExperiment); - } catch (Throwable e) { - logger.error(existingExperimentID, "Error while cloning the experiment with existing configuration...", e); - throw ThriftExceptionHandler.convertException(e, "Error occurred"); - } - } - - private String cloneExperimentInternal( - AuthzToken authzToken, - String existingExperimentID, - String newExperimentName, - String newExperimentProjectId, - ExperimentModel existingExperiment) - throws ExperimentNotFoundException, ProjectNotFoundException , AuthorizationException, - ApplicationSettingsException, InvalidRequestException, AiravataSystemException, AiravataClientException, org.apache.airavata.sharing.registry.models.SharingRegistryException { - 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 (!airavataService.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) { - try { - List applicationOutputs = airavataService.getApplicationOutputs(existingExperiment.getExecutionId()); - existingExperiment.setExperimentOutputs(applicationOutputs); - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.warn("Error getting application outputs for experiment clone: " + e.getMessage()); - } catch (Throwable e) { - logger.warn("Error getting application outputs for experiment clone: " + e.getMessage()); - } - } - if (validateString(newExperimentName)) { - existingExperiment.setExperimentName(newExperimentName); - } - existingExperiment.unsetErrors(); - existingExperiment.unsetProcesses(); - existingExperiment.unsetExperimentStatus(); - if (existingExperiment.getUserConfigurationData() != null - && existingExperiment.getUserConfigurationData().getComputationalResourceScheduling() != null - && existingExperiment - .getUserConfigurationData() - .getComputationalResourceScheduling() - .getResourceHostId() - != null) { - String compResourceId = existingExperiment - .getUserConfigurationData() - .getComputationalResourceScheduling() - .getResourceHostId(); - - try { - ComputeResourceDescription computeResource = airavataService.getComputeResource(compResourceId); - if (!computeResource.isEnabled()) { - existingExperiment.getUserConfigurationData().setComputationalResourceScheduling(null); - } - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.warn("Error getting compute resource for experiment clone: " + e.getMessage()); - } catch (Throwable e) { - logger.warn("Error getting compute resource for experiment clone: " + e.getMessage()); - } - } - logger.debug("Airavata cloned experiment with experiment id : " + existingExperimentID); - existingExperiment.setUserName(userId); - - String expId; - try { - expId = airavataService.createExperiment(gatewayId, existingExperiment); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error creating cloned experiment"); - } - if (ServerSettings.isEnableSharing()) { - try { - Entity entity = new Entity(); - entity.setEntityId(expId); - final String domainId = existingExperiment.getGatewayId(); - entity.setDomainId(domainId); - entity.setEntityTypeId(domainId + ":" + "EXPERIMENT"); - entity.setOwnerId(existingExperiment.getUserName() + "@" + domainId); - entity.setName(existingExperiment.getExperimentName()); - entity.setDescription(existingExperiment.getDescription()); - airavataService.createEntity(entity); - airavataService.shareEntityWithAdminGatewayGroups( entity); - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - logger.error("rolling back experiment creation Exp ID : " + expId); - try { - airavataService.deleteExperiment(expId); - } catch (org.apache.airavata.registry.cpi.RegistryException e) { - logger.error("Error deleting experiment during rollback: " + e.getMessage()); - } - } - } - - return expId; } /** @@ -1204,42 +913,7 @@ private String cloneExperimentInternal( public void terminateExperiment(AuthzToken authzToken, String airavataExperimentId, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, ExperimentNotFoundException { - try { - ExperimentModel existingExperiment = airavataService.getExperiment(airavataExperimentId); - ExperimentStatus experimentLastStatus = airavataService.getExperimentStatus(airavataExperimentId); - if (existingExperiment == null) { - logger.error( - airavataExperimentId, - "Error while cancelling experiment {}, experiment doesn't exist.", - airavataExperimentId); - throw new ExperimentNotFoundException( - "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); - } - switch (experimentLastStatus.getState()) { - case COMPLETED: - case CANCELED: - case FAILED: - case CANCELING: - logger.warn( - "Can't terminate already {} experiment", - existingExperiment - .getExperimentStatus() - .get(0) - .getState() - .name()); - break; - case CREATED: - logger.warn("Experiment termination is only allowed for launched experiments."); - break; - default: - airavataService.publishExperimentCancelEvent(experimentPublisher, gatewayId, airavataExperimentId); - logger.debug("Airavata cancelled experiment with experiment id : " + airavataExperimentId); - break; - } - } catch (Throwable e) { - logger.error(airavataExperimentId, "Error while cancelling the experiment...", e); - throw ThriftExceptionHandler.convertException(e, "Error occurred"); - } + airavataService.terminateExperiment(experimentPublisher, airavataExperimentId, gatewayId); } /** @@ -1254,11 +928,8 @@ public void terminateExperiment(AuthzToken authzToken, String airavataExperiment public String registerApplicationModule( AuthzToken authzToken, String gatewayId, ApplicationModule applicationModule) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.registerApplicationModule(gatewayId, applicationModule); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while adding application module"); - } } + } /** * Fetch a Application Module. @@ -1271,11 +942,8 @@ public String registerApplicationModule( @SecurityCheck public ApplicationModule getApplicationModule(AuthzToken authzToken, String appModuleId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getApplicationModule(appModuleId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while retrieving application module"); - } } + } /** * Update a Application Module. @@ -1290,11 +958,8 @@ public ApplicationModule getApplicationModule(AuthzToken authzToken, String appM public boolean updateApplicationModule( AuthzToken authzToken, String appModuleId, ApplicationModule applicationModule) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.updateApplicationModule(appModuleId, applicationModule); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while updating application module"); - } } + } /** * Fetch all Application Module Descriptions. @@ -1306,11 +971,7 @@ public boolean updateApplicationModule( @SecurityCheck public List getAllAppModules(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getAllAppModules(gatewayId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while retrieving all application modules"); - } } /** @@ -1323,11 +984,7 @@ public List getAllAppModules(AuthzToken authzToken, String ga @SecurityCheck public List getAccessibleAppModules(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getAccessibleAppModulesWithSharing( authzToken, gatewayId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while retrieving all application modules"); - } } /** @@ -1341,11 +998,8 @@ public List getAccessibleAppModules(AuthzToken authzToken, St @SecurityCheck public boolean deleteApplicationModule(AuthzToken authzToken, String appModuleId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.deleteApplicationModule(appModuleId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while deleting application module"); - } } + } /** * Register a Application Deployment. @@ -1358,26 +1012,7 @@ public boolean deleteApplicationModule(AuthzToken authzToken, String appModuleId public String registerApplicationDeployment( AuthzToken authzToken, String gatewayId, ApplicationDeploymentDescription applicationDeployment) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - // TODO: verify that gatewayId matches authzToken gatewayId - try { - String result = airavataService.registerApplicationDeployment(gatewayId, applicationDeployment); - if (ServerSettings.isEnableSharing()) { - Entity entity = new Entity(); - entity.setEntityId(result); - final String domainId = gatewayId; - entity.setDomainId(domainId); - entity.setEntityTypeId(domainId + ":" + ResourceType.APPLICATION_DEPLOYMENT.name()); - String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); - entity.setOwnerId(userName + "@" + domainId); - entity.setName(result); - entity.setDescription(applicationDeployment.getAppDeploymentDescription()); - airavataService.createEntity(entity); - airavataService.shareEntityWithAdminGatewayGroups( entity); - } - return result; - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while adding application deployment"); - } + return airavataService.registerApplicationDeploymentWithSharing(authzToken, gatewayId, applicationDeployment); } /** @@ -1391,19 +1026,7 @@ public String registerApplicationDeployment( @SecurityCheck public ApplicationDeploymentDescription getApplicationDeployment(AuthzToken authzToken, String appDeploymentId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { - if (ServerSettings.isEnableSharing()) { - final boolean hasAccess = airavataService.userHasAccessInternal( authzToken, appDeploymentId, ResourcePermissionType.READ); - if (!hasAccess) { - throw new AuthorizationException( - "User does not have access to application deployment " + appDeploymentId); - } - } - ApplicationDeploymentDescription result = airavataService.getApplicationDeployment(appDeploymentId); - return result; - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while retrieving application deployment"); - } + return airavataService.getApplicationDeploymentWithAuth(authzToken, appDeploymentId); } /** @@ -1419,18 +1042,7 @@ public ApplicationDeploymentDescription getApplicationDeployment(AuthzToken auth public boolean updateApplicationDeployment( AuthzToken authzToken, String appDeploymentId, ApplicationDeploymentDescription applicationDeployment) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { - if (ServerSettings.isEnableSharing()) { - final boolean hasAccess = airavataService.userHasAccessInternal( authzToken, appDeploymentId, ResourcePermissionType.WRITE); - if (!hasAccess) { - throw new AuthorizationException( - "User does not have WRITE access to application deployment " + appDeploymentId); - } - } - return airavataService.updateApplicationDeployment(appDeploymentId, applicationDeployment); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while updating application deployment"); - } + return airavataService.updateApplicationDeploymentWithAuth(authzToken, appDeploymentId, applicationDeployment); } /** @@ -1444,16 +1056,7 @@ public boolean updateApplicationDeployment( @SecurityCheck public boolean deleteApplicationDeployment(AuthzToken authzToken, String appDeploymentId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { - final boolean hasAccess = airavataService.userHasAccessInternal( authzToken, appDeploymentId, ResourcePermissionType.WRITE); - if (!hasAccess) { - throw new AuthorizationException( - "User does not have WRITE access to application deployment " + appDeploymentId); - } - return airavataService.deleteApplicationDeployment(appDeploymentId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while deleting application deployment"); - } + return airavataService.deleteApplicationDeploymentWithAuth(authzToken, appDeploymentId); } /** @@ -1480,11 +1083,7 @@ public List getAllApplicationDeployments(Authz public List getAccessibleApplicationDeployments( AuthzToken authzToken, String gatewayId, ResourcePermissionType permissionType) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getAccessibleApplicationDeploymentsWithSharing( authzToken, gatewayId, permissionType); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while retrieving application deployments"); - } } /** @@ -1499,11 +1098,7 @@ public List getAccessibleApplicationDeployment @Deprecated public List getAppModuleDeployedResources(AuthzToken authzToken, String appModuleId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getAppModuleDeployedResources(appModuleId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while retrieving application deployment"); - } } /** @@ -1524,40 +1119,8 @@ public List getAppModuleDeployedResources(AuthzToken authzToken, String public List getApplicationDeploymentsForAppModuleAndGroupResourceProfile( AuthzToken authzToken, String appModuleId, String groupResourceProfileId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - try { - // Get list of compute resources for this Group Resource Profile - if (!airavataService.userHasAccessInternal( authzToken, groupResourceProfileId, ResourcePermissionType.READ)) { - throw new AuthorizationException( - "User is not authorized to access Group Resource Profile " + groupResourceProfileId); - } - GroupResourceProfile groupResourceProfile = airavataService.getGroupResourceProfile(groupResourceProfileId); - List accessibleComputeResourceIds = groupResourceProfile.getComputePreferences().stream() - .map(compPref -> compPref.getComputeResourceId()) - .collect(Collectors.toList()); - - // Get list of accessible Application Deployments - List accessibleAppDeploymentIds = new ArrayList<>(); - List sharingFilters = new ArrayList<>(); - SearchCriteria entityTypeFilter = new SearchCriteria(); - entityTypeFilter.setSearchField(EntitySearchField.ENTITY_TYPE_ID); - entityTypeFilter.setSearchCondition(SearchCondition.EQUAL); - entityTypeFilter.setValue(gatewayId + ":" + ResourceType.APPLICATION_DEPLOYMENT.name()); - sharingFilters.add(entityTypeFilter); - SearchCriteria permissionTypeFilter = new SearchCriteria(); - permissionTypeFilter.setSearchField(EntitySearchField.PERMISSION_TYPE_ID); - permissionTypeFilter.setSearchCondition(SearchCondition.EQUAL); - permissionTypeFilter.setValue(gatewayId + ":" + ResourcePermissionType.READ); - sharingFilters.add(permissionTypeFilter); - airavataService.searchEntities(gatewayId, userName + "@" + gatewayId, sharingFilters, 0, -1) - .forEach(a -> accessibleAppDeploymentIds.add(a.getEntityId())); - - return airavataService.getAccessibleApplicationDeploymentsForAppModule( - appModuleId, gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while retrieving application deployments"); - } + return airavataService.getApplicationDeploymentsForAppModuleAndGroupResourceProfile( + authzToken, appModuleId, groupResourceProfileId); } /** @@ -1571,34 +1134,15 @@ public List getApplicationDeploymentsForAppMod public String registerApplicationInterface( AuthzToken authzToken, String gatewayId, ApplicationInterfaceDescription applicationInterface) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.registerApplicationInterface(gatewayId, applicationInterface); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while adding application interface"); - } } + } @Override @SecurityCheck public String cloneApplicationInterface( AuthzToken authzToken, String existingAppInterfaceID, String newApplicationName, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { - ApplicationInterfaceDescription existingInterface = airavataService.getApplicationInterface(existingAppInterfaceID); - if (existingInterface == null) { - logger.error( - "Provided application interface does not exist.Please provide a valid application interface id..."); - throw new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); - } - - existingInterface.setApplicationName(newApplicationName); - existingInterface.setApplicationInterfaceId(airavata_commonsConstants.DEFAULT_ID); - String interfaceId = airavataService.registerApplicationInterface(gatewayId, existingInterface); - logger.debug("Airavata cloned application interface : " + existingAppInterfaceID + " for gateway id : " - + gatewayId); - return interfaceId; - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Provided application interface does not exist.Please provide a valid application interface id..."); - } + return airavataService.cloneApplicationInterface(existingAppInterfaceID, newApplicationName, gatewayId); } /** @@ -1612,12 +1156,8 @@ public String cloneApplicationInterface( @SecurityCheck public ApplicationInterfaceDescription getApplicationInterface(AuthzToken authzToken, String appInterfaceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { - ApplicationInterfaceDescription existingInterface = airavataService.getApplicationInterface(appInterfaceId); - return existingInterface; - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while retrieving application interface"); - } } + return airavataService.getApplicationInterface(appInterfaceId); + } /** * Update a Application Interface. @@ -1632,11 +1172,8 @@ public ApplicationInterfaceDescription getApplicationInterface(AuthzToken authzT public boolean updateApplicationInterface( AuthzToken authzToken, String appInterfaceId, ApplicationInterfaceDescription applicationInterface) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.updateApplicationInterface(appInterfaceId, applicationInterface); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while updating application interface"); - } } + } /** * Delete a Application Interface. @@ -1649,11 +1186,8 @@ public boolean updateApplicationInterface( @SecurityCheck public boolean deleteApplicationInterface(AuthzToken authzToken, String appInterfaceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.deleteApplicationInterface(appInterfaceId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while deleting application interface"); - } } + } /** * Fetch name and id of Application Interface documents. @@ -1665,11 +1199,7 @@ public boolean deleteApplicationInterface(AuthzToken authzToken, String appInter @SecurityCheck public Map getAllApplicationInterfaceNames(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getAllApplicationInterfaceNames(gatewayId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while retrieving application interfaces"); - } } /** @@ -1682,11 +1212,7 @@ public Map getAllApplicationInterfaceNames(AuthzToken authzToken @SecurityCheck public List getAllApplicationInterfaces(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getAllApplicationInterfaces(gatewayId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while retrieving application interfaces"); - } } /** @@ -1700,11 +1226,7 @@ public List getAllApplicationInterfaces(AuthzTo @SecurityCheck public List getApplicationInputs(AuthzToken authzToken, String appInterfaceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getApplicationInputs(appInterfaceId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while retrieving application inputs"); - } } /** @@ -1718,14 +1240,7 @@ public List getApplicationInputs(AuthzToken authzToken, Str @SecurityCheck public List getApplicationOutputs(AuthzToken authzToken, String appInterfaceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { - List applicationOutputs = airavataService.getApplicationOutputs(appInterfaceId); - return applicationOutputs; - } catch (Throwable e) { - AiravataSystemException exception = new AiravataSystemException(); - exception.setMessage(e.getMessage()); - throw exception; - } + return airavataService.getApplicationOutputs(appInterfaceId); } /** @@ -1741,11 +1256,7 @@ public List getApplicationOutputs(AuthzToken authzToken, S @Deprecated public Map getAvailableAppInterfaceComputeResources(AuthzToken authzToken, String appInterfaceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getAvailableAppInterfaceComputeResources(appInterfaceId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while retrieving available compute resources"); - } } /** @@ -1759,11 +1270,8 @@ public Map getAvailableAppInterfaceComputeResources(AuthzToken a @SecurityCheck public String registerComputeResource(AuthzToken authzToken, ComputeResourceDescription computeResourceDescription) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.registerComputeResource(computeResourceDescription); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while saving compute resource"); - } } + } /** * Fetch the given Compute Resource. @@ -1776,11 +1284,8 @@ public String registerComputeResource(AuthzToken authzToken, ComputeResourceDesc @SecurityCheck public ComputeResourceDescription getComputeResource(AuthzToken authzToken, String computeResourceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getComputeResource(computeResourceId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while retrieving compute resource"); - } } + } /** * Fetch all registered Compute Resources. @@ -1792,11 +1297,8 @@ public ComputeResourceDescription getComputeResource(AuthzToken authzToken, Stri @SecurityCheck public Map getAllComputeResourceNames(AuthzToken authzToken) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getAllComputeResourceNames(); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while retrieving compute resource names"); - } } + } /** * Update a Compute Resource. @@ -1811,11 +1313,8 @@ public Map getAllComputeResourceNames(AuthzToken authzToken) public boolean updateComputeResource( AuthzToken authzToken, String computeResourceId, ComputeResourceDescription computeResourceDescription) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.updateComputeResource(computeResourceId, computeResourceDescription); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while updating compute resource"); - } } + } /** * Delete a Compute Resource. @@ -1828,11 +1327,8 @@ public boolean updateComputeResource( @SecurityCheck public boolean deleteComputeResource(AuthzToken authzToken, String computeResourceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.deleteComputeResource(computeResourceId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while deleting compute resource"); - } } + } /** * Register a Storage Resource. @@ -1846,11 +1342,8 @@ public boolean deleteComputeResource(AuthzToken authzToken, String computeResour @SecurityCheck public String registerStorageResource(AuthzToken authzToken, StorageResourceDescription storageResourceDescription) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.registerStorageResource(storageResourceDescription); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while saving storage resource"); - } } + } /** * Fetch the given Storage Resource. @@ -1864,11 +1357,8 @@ public String registerStorageResource(AuthzToken authzToken, StorageResourceDesc @SecurityCheck public StorageResourceDescription getStorageResource(AuthzToken authzToken, String storageResourceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getStorageResource(storageResourceId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while retrieving storage resource"); - } } + } /** * Fetch all registered Storage Resources. @@ -1881,11 +1371,8 @@ public StorageResourceDescription getStorageResource(AuthzToken authzToken, Stri @SecurityCheck public Map getAllStorageResourceNames(AuthzToken authzToken) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getAllStorageResourceNames(); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while retrieving storage resource names"); - } } + } /** * Update a Compute Resource. @@ -1901,11 +1388,8 @@ public Map getAllStorageResourceNames(AuthzToken authzToken) public boolean updateStorageResource( AuthzToken authzToken, String storageResourceId, StorageResourceDescription storageResourceDescription) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.updateStorageResource(storageResourceId, storageResourceDescription); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while updating storage resource"); - } } + } /** * Delete a Storage Resource. @@ -1919,120 +1403,21 @@ public boolean updateStorageResource( @SecurityCheck public boolean deleteStorageResource(AuthzToken authzToken, String storageResourceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.deleteStorageResource(storageResourceId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while deleting storage resource"); - } } + } @Override @SecurityCheck public StorageVolumeInfo getResourceStorageInfo(AuthzToken authzToken, String resourceId, String location) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - StorageInfoContext context; - - try { - Optional computeResourceOp = Optional.empty(); - try { - ComputeResourceDescription computeResource = airavataService.getComputeResource(resourceId); - if (computeResource != null) { - computeResourceOp = Optional.of(computeResource); - } - } catch (Throwable e) { - logger.debug("Compute resource {} not found: {}", resourceId, e.getMessage()); - } - - Optional storageResourceOp = Optional.empty(); - if (computeResourceOp.isEmpty()) { - try { - StorageResourceDescription storageResource = airavataService.getStorageResource(resourceId); - if (storageResource != null) { - storageResourceOp = Optional.of(storageResource); - } - } catch (Throwable e) { - logger.debug("Storage resource {} not found: {}", resourceId, e.getMessage()); - } - } - - if (computeResourceOp.isEmpty() && storageResourceOp.isEmpty()) { - logger.error( - "Resource with ID {} not found as either compute resource or storage resource", resourceId); - throw new InvalidRequestException("Resource with ID '" + resourceId - + "' not found as either compute resource or storage resource"); - } - - if (computeResourceOp.isPresent()) { - logger.debug("Found compute resource with ID {}. Resolving login username and credentials", resourceId); - context = resolveComputeStorageInfoContext(authzToken, gatewayId, userId, resourceId); - } else { - logger.debug("Found storage resource with ID {}. Resolving login username and credentials", resourceId); - context = resolveStorageStorageInfoContext(authzToken, gatewayId, userId, resourceId); - } - - return context.adaptor.getStorageVolumeInfo(location); - } catch (InvalidRequestException e) { - logger.error("Error while retrieving storage resource.", e); - throw e; - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while retrieving storage resource"); - } + return airavataService.getResourceStorageInfo(authzToken, resourceId, location); } @Override @SecurityCheck public StorageDirectoryInfo getStorageDirectoryInfo(AuthzToken authzToken, String resourceId, String location) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - StorageInfoContext context; - - try { - Optional computeResourceOp = Optional.empty(); - try { - ComputeResourceDescription computeResource = airavataService.getComputeResource(resourceId); - if (computeResource != null) { - computeResourceOp = Optional.of(computeResource); - } - } catch (Throwable e) { - logger.debug("Compute resource {} not found: {}", resourceId, e.getMessage()); - } - - Optional storageResourceOp = Optional.empty(); - if (computeResourceOp.isEmpty()) { - try { - StorageResourceDescription storageResource = airavataService.getStorageResource(resourceId); - if (storageResource != null) { - storageResourceOp = Optional.of(storageResource); - } - } catch (Throwable e) { - logger.debug("Storage resource {} not found: {}", resourceId, e.getMessage()); - } - } - - if (computeResourceOp.isEmpty() && storageResourceOp.isEmpty()) { - logger.error( - "Resource with ID {} not found as either compute resource or storage resource", resourceId); - throw new InvalidRequestException("Resource with ID '" + resourceId - + "' not found as either compute resource or storage resource"); - } - - if (computeResourceOp.isPresent()) { - logger.debug("Found compute resource with ID {}. Resolving login username and credentials", resourceId); - context = resolveComputeStorageInfoContext(authzToken, gatewayId, userId, resourceId); - } else { - logger.debug("Found storage resource with ID {}. Resolving login username and credentials", resourceId); - context = resolveStorageStorageInfoContext(authzToken, gatewayId, userId, resourceId); - } - - return context.adaptor.getStorageDirectoryInfo(location); - } catch (InvalidRequestException e) { - logger.error("Error while retrieving storage resource.", e); - throw e; - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while retrieving storage directory info"); - } + return airavataService.getStorageDirectoryInfo(authzToken, resourceId, location); } /** @@ -2049,11 +1434,8 @@ public StorageDirectoryInfo getStorageDirectoryInfo(AuthzToken authzToken, Strin @SecurityCheck public String addLocalSubmissionDetails( AuthzToken authzToken, String computeResourceId, int priorityOrder, LOCALSubmission localSubmission){ - try { return airavataService.addLocalSubmissionDetails(computeResourceId, priorityOrder, localSubmission); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while adding local job submission interface"); - } } + } /** * Update the given Local Job Submission details @@ -2068,21 +1450,15 @@ public String addLocalSubmissionDetails( public boolean updateLocalSubmissionDetails( AuthzToken authzToken, String jobSubmissionInterfaceId, LOCALSubmission localSubmission) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.updateLocalSubmissionDetails(jobSubmissionInterfaceId, localSubmission); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while updating local job submission interface"); - } } + } @Override @SecurityCheck public LOCALSubmission getLocalJobSubmission(AuthzToken authzToken, String jobSubmissionId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getLocalJobSubmission(jobSubmissionId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while retrieving local job submission interface"); - } } + } /** * Add a SSH Job Submission details to a compute resource @@ -2099,11 +1475,8 @@ public LOCALSubmission getLocalJobSubmission(AuthzToken authzToken, String jobSu public String addSSHJobSubmissionDetails( AuthzToken authzToken, String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.addSSHJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while adding SSH job submission interface"); - } } + } /** * Add a SSH_FORK Job Submission details to a compute resource @@ -2120,21 +1493,15 @@ public String addSSHJobSubmissionDetails( public String addSSHForkJobSubmissionDetails( AuthzToken authzToken, String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.addSSHForkJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while adding SSH fork job submission interface"); - } } + } @Override @SecurityCheck public SSHJobSubmission getSSHJobSubmission(AuthzToken authzToken, String jobSubmissionId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getSSHJobSubmission(jobSubmissionId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while retrieving SSH job submission interface"); - } } + } /** * Add a Cloud Job Submission details to a compute resource @@ -2151,27 +1518,14 @@ public SSHJobSubmission getSSHJobSubmission(AuthzToken authzToken, String jobSub public String addCloudJobSubmissionDetails( AuthzToken authzToken, String computeResourceId, int priorityOrder, CloudJobSubmission cloudJobSubmission) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.addCloudJobSubmissionDetails(computeResourceId, priorityOrder, cloudJobSubmission); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while adding cloud job submission interface"); - } } + } @Override @SecurityCheck public CloudJobSubmission getCloudJobSubmission(AuthzToken authzToken, String jobSubmissionId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getCloudJobSubmission(jobSubmissionId); - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - String errorMsg = "Error while retrieving Cloud job submission interface to resource compute resource..."; - logger.error(jobSubmissionId, errorMsg, e); - throw ThriftExceptionHandler.convertException(e, "Error occurred"); - } catch (Throwable e) { - String errorMsg = "Error while retrieving Cloud job submission interface to resource compute resource..."; - logger.error(jobSubmissionId, errorMsg, e); - throw ThriftExceptionHandler.convertException(e, "Error occurred"); - } } @Override @@ -2182,33 +1536,15 @@ public String addUNICOREJobSubmissionDetails( int priorityOrder, UnicoreJobSubmission unicoreJobSubmission) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.addUNICOREJobSubmissionDetails( computeResourceId, priorityOrder, unicoreJobSubmission); - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error("Error while adding job submission interface to resource compute resource...", e); - throw ThriftExceptionHandler.convertException(e, "Error occurred"); - } catch (Throwable e) { - logger.error("Error while adding job submission interface to resource compute resource...", e); - throw ThriftExceptionHandler.convertException(e, "Error occurred"); - } } @Override @SecurityCheck public UnicoreJobSubmission getUnicoreJobSubmission(AuthzToken authzToken, String jobSubmissionId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getUnicoreJobSubmission(jobSubmissionId); - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - String errorMsg = "Error while retrieving Unicore job submission interface to resource compute resource..."; - logger.error(jobSubmissionId, errorMsg, e); - throw ThriftExceptionHandler.convertException(e, "Error occurred"); - } catch (Throwable e) { - String errorMsg = "Error while retrieving Unicore job submission interface to resource compute resource..."; - logger.error(jobSubmissionId, errorMsg, e); - throw ThriftExceptionHandler.convertException(e, "Error occurred"); - } } /** @@ -2224,21 +1560,7 @@ public UnicoreJobSubmission getUnicoreJobSubmission(AuthzToken authzToken, Strin public boolean updateSSHJobSubmissionDetails( AuthzToken authzToken, String jobSubmissionInterfaceId, SSHJobSubmission sshJobSubmission) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.updateSSHJobSubmissionDetails(jobSubmissionInterfaceId, sshJobSubmission); - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error( - jobSubmissionInterfaceId, - "Error while updating job submission interface to resource compute resource...", - e); - throw ThriftExceptionHandler.convertException(e, "Error occurred"); - } catch (Throwable e) { - logger.error( - jobSubmissionInterfaceId, - "Error while updating job submission interface to resource compute resource...", - e); - throw ThriftExceptionHandler.convertException(e, "Error occurred"); - } } /** @@ -2254,21 +1576,7 @@ public boolean updateSSHJobSubmissionDetails( public boolean updateCloudJobSubmissionDetails( AuthzToken authzToken, String jobSubmissionInterfaceId, CloudJobSubmission cloudJobSubmission) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.updateCloudJobSubmissionDetails(jobSubmissionInterfaceId, cloudJobSubmission); - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error( - jobSubmissionInterfaceId, - "Error while updating job submission interface to resource compute resource...", - e); - throw ThriftExceptionHandler.convertException(e, "Error occurred"); - } catch (Throwable e) { - logger.error( - jobSubmissionInterfaceId, - "Error while updating job submission interface to resource compute resource...", - e); - throw ThriftExceptionHandler.convertException(e, "Error occurred"); - } } @Override @@ -2276,21 +1584,7 @@ public boolean updateCloudJobSubmissionDetails( public boolean updateUnicoreJobSubmissionDetails( AuthzToken authzToken, String jobSubmissionInterfaceId, UnicoreJobSubmission unicoreJobSubmission) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.updateUnicoreJobSubmissionDetails(jobSubmissionInterfaceId, unicoreJobSubmission); - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error( - jobSubmissionInterfaceId, - "Error while updating job submission interface to resource compute resource...", - e); - throw ThriftExceptionHandler.convertException(e, "Error occurred"); - } catch (Throwable e) { - logger.error( - jobSubmissionInterfaceId, - "Error while updating job submission interface to resource compute resource...", - e); - throw ThriftExceptionHandler.convertException(e, "Error occurred"); - } } /** @@ -2312,11 +1606,8 @@ public String addLocalDataMovementDetails( int priorityOrder, LOCALDataMovement localDataMovement) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.addLocalDataMovementDetails(resourceId, dmType, priorityOrder, localDataMovement); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while adding data movement interface to resource"); - } } + } /** * Update the given Local data movement details @@ -2331,11 +1622,8 @@ public String addLocalDataMovementDetails( public boolean updateLocalDataMovementDetails( AuthzToken authzToken, String dataMovementInterfaceId, LOCALDataMovement localDataMovement) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.updateLocalDataMovementDetails(dataMovementInterfaceId, localDataMovement); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while updating local data movement interface"); - } } + } /** * Add a SCP data moevement details to a compute resource @@ -2352,11 +1640,7 @@ public boolean updateLocalDataMovementDetails( public String addSCPDataMovementDetails( AuthzToken authzToken, String resourceId, DMType dmType, int priorityOrder, SCPDataMovement scpDataMovement) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.addSCPDataMovementDetails(resourceId, dmType, priorityOrder, scpDataMovement); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while adding SCP data movement interface"); - } } /** @@ -2373,22 +1657,14 @@ public String addSCPDataMovementDetails( public boolean updateSCPDataMovementDetails( AuthzToken authzToken, String dataMovementInterfaceId, SCPDataMovement scpDataMovement) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.updateSCPDataMovementDetails(dataMovementInterfaceId, scpDataMovement); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while updating SCP data movement interface"); - } } @Override @SecurityCheck public SCPDataMovement getSCPDataMovement(AuthzToken authzToken, String dataMovementId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getSCPDataMovement(dataMovementId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while retrieving SCP data movement interface"); - } } @Override @@ -2400,11 +1676,7 @@ public String addUnicoreDataMovementDetails( int priorityOrder, UnicoreDataMovement unicoreDataMovement) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.addUnicoreDataMovementDetails(resourceId, dmType, priorityOrder, unicoreDataMovement); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while adding UNICORE data movement interface"); - } } @Override @@ -2412,33 +1684,21 @@ public String addUnicoreDataMovementDetails( public boolean updateUnicoreDataMovementDetails( AuthzToken authzToken, String dataMovementInterfaceId, UnicoreDataMovement unicoreDataMovement) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.updateUnicoreDataMovementDetails(dataMovementInterfaceId, unicoreDataMovement); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while updating unicore data movement interface"); - } } @Override @SecurityCheck public LOCALDataMovement getLocalDataMovement(AuthzToken authzToken, String dataMovementId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getLocalDataMovement(dataMovementId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while retrieving local data movement interface"); - } } @Override @SecurityCheck public UnicoreDataMovement getUnicoreDataMovement(AuthzToken authzToken, String dataMovementId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getUnicoreDataMovement(dataMovementId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while retrieving UNICORE data movement interface"); - } } /** @@ -2460,11 +1720,7 @@ public String addGridFTPDataMovementDetails( int priorityOrder, GridFTPDataMovement gridFTPDataMovement) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.addGridFTPDataMovementDetails(computeResourceId, dmType, priorityOrder, gridFTPDataMovement); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while adding GridFTP data movement interface"); - } } /** @@ -2481,28 +1737,14 @@ public String addGridFTPDataMovementDetails( public boolean updateGridFTPDataMovementDetails( AuthzToken authzToken, String dataMovementInterfaceId, GridFTPDataMovement gridFTPDataMovement) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.updateGridFTPDataMovementDetails(dataMovementInterfaceId, gridFTPDataMovement); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while updating GridFTP data movement interface"); - } } @Override @SecurityCheck public GridFTPDataMovement getGridFTPDataMovement(AuthzToken authzToken, String dataMovementId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getGridFTPDataMovement(dataMovementId); - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - String errorMsg = "Error while retrieving GridFTP data movement interface to resource compute resource..."; - logger.error(dataMovementId, errorMsg, e); - throw ThriftExceptionHandler.convertException(e, "Error occurred"); - } catch (Throwable e) { - String errorMsg = "Error while retrieving GridFTP data movement interface to resource compute resource..."; - logger.error(dataMovementId, errorMsg, e); - throw ThriftExceptionHandler.convertException(e, "Error occurred"); - } } /** @@ -2577,11 +1819,8 @@ public boolean changeDataMovementPriorities(AuthzToken authzToken, Map getAllGatewayComputeResourcePreferences( AuthzToken authzToken, String gatewayID) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getAllGatewayComputeResourcePreferences(gatewayID); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while reading gateway compute resource preferences"); - } } + } @Override @SecurityCheck public List getAllGatewayStoragePreferences(AuthzToken authzToken, String gatewayID) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getAllGatewayStoragePreferences(gatewayID); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while reading gateway data storage preferences"); - } } + } @Override @SecurityCheck public List getAllGatewayResourceProfiles(AuthzToken authzToken) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getAllGatewayResourceProfiles(); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while retrieving all gateway profiles"); - } } + } /** * Update a Compute Resource Preference to a registered gateway profile. @@ -2843,22 +2031,16 @@ public boolean updateGatewayComputeResourcePreference( String computeResourceId, ComputeResourcePreference computeResourcePreference) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.updateGatewayComputeResourcePreference(gatewayID, computeResourceId, computeResourcePreference); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while updating gateway compute resource preference"); - } } + } @Override @SecurityCheck public boolean updateGatewayStoragePreference( AuthzToken authzToken, String gatewayID, String storageId, StoragePreference dataStoragePreference) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.updateGatewayStoragePreference(gatewayID, storageId, dataStoragePreference); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while updating gateway data storage preference"); - } } + } /** * Delete the Compute Resource Preference of a registered gateway profile. @@ -2873,26 +2055,15 @@ public boolean updateGatewayStoragePreference( public boolean deleteGatewayComputeResourcePreference( AuthzToken authzToken, String gatewayID, String computeResourceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.deleteGatewayComputeResourcePreference(gatewayID, computeResourceId); - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error(gatewayID, "Error while deleting gateway compute resource preference...", e); - throw ThriftExceptionHandler.convertException(e, "Error occurred"); - } catch (Throwable e) { - logger.error(gatewayID, "Error while deleting gateway compute resource preference...", e); - throw ThriftExceptionHandler.convertException(e, "Error occurred"); - } } @Override @SecurityCheck public boolean deleteGatewayStoragePreference(AuthzToken authzToken, String gatewayID, String storageId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.deleteGatewayStoragePreference(gatewayID, storageId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while deleting gateway data storage preference"); - } } + } @Override @SecurityCheck @@ -2936,12 +2107,7 @@ public List getSSHAccountProvisioners(AuthzToken authzTok @SecurityCheck public boolean doesUserHaveSSHAccount(AuthzToken authzToken, String computeResourceId, String userId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - return SSHAccountManager.doesUserHaveSSHAccount(gatewayId, computeResourceId, userId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error occurred while checking if user has an SSH Account"); - } + return airavataService.doesUserHaveSSHAccount(authzToken, computeResourceId, userId); } @Override @@ -2949,20 +2115,7 @@ public boolean doesUserHaveSSHAccount(AuthzToken authzToken, String computeResou public boolean isSSHSetupCompleteForUserComputeResourcePreference( AuthzToken authzToken, String computeResourceId, String airavataCredStoreToken) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - SSHCredential sshCredential = null; - try { - sshCredential = airavataService.getSSHCredential(airavataCredStoreToken, gatewayId);; - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error occurred while retrieving SSH Credential"); - } - - try { - return SSHAccountManager.isSSHAccountSetupComplete(gatewayId, computeResourceId, userId, sshCredential); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error occurred while checking if setup of SSH account is complete"); - } + return airavataService.isSSHAccountSetupComplete(authzToken, computeResourceId, airavataCredStoreToken); } @Override @@ -2970,20 +2123,7 @@ public boolean isSSHSetupCompleteForUserComputeResourcePreference( public UserComputeResourcePreference setupUserComputeResourcePreferencesForSSH( AuthzToken authzToken, String computeResourceId, String userId, String airavataCredStoreToken) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - SSHCredential sshCredential = null; - try { - try { - sshCredential = airavataService.getSSHCredential(airavataCredStoreToken, gatewayId);; - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error occurred while retrieving SSH Credential"); - } - - return SSHAccountManager.setupSSHAccount(gatewayId, computeResourceId, userId, sshCredential); - } catch (Throwable e) { - - throw ThriftExceptionHandler.convertException(e, "Error occurred while automatically setting up SSH account for user"); - } + return airavataService.setupSSHAccount(authzToken, computeResourceId, userId, airavataCredStoreToken); } /** @@ -2999,21 +2139,15 @@ public UserComputeResourcePreference setupUserComputeResourcePreferencesForSSH( @SecurityCheck public String registerUserResourceProfile(AuthzToken authzToken, UserResourceProfile userResourceProfile) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.registerUserResourceProfile(userResourceProfile); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while registering user resource profile"); - } } + } @Override @SecurityCheck public boolean isUserResourceProfileExists(AuthzToken authzToken, String userId, String gatewayID) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.isUserResourceProfileExists(userId, gatewayID); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while checking existence of user resource profile"); - } } + } /** * Fetch the given User Resource Profile. @@ -3029,11 +2163,8 @@ public boolean isUserResourceProfileExists(AuthzToken authzToken, String userId, @SecurityCheck public UserResourceProfile getUserResourceProfile(AuthzToken authzToken, String userId, String gatewayID) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getUserResourceProfile(userId, gatewayID); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while retrieving user resource profile"); - } } + } /** * Update a User Resource Profile. @@ -3049,11 +2180,8 @@ public UserResourceProfile getUserResourceProfile(AuthzToken authzToken, String public boolean updateUserResourceProfile( AuthzToken authzToken, String userId, String gatewayID, UserResourceProfile userResourceProfile) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.updateUserResourceProfile(userId, gatewayID, userResourceProfile); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while updating user resource profile"); - } } + } /** * Delete the given User Resource Profile. @@ -3067,11 +2195,8 @@ public boolean updateUserResourceProfile( @SecurityCheck public boolean deleteUserResourceProfile(AuthzToken authzToken, String userId, String gatewayID) throws AiravataClientException, AiravataSystemException, AuthorizationException, InvalidRequestException { - try { return airavataService.deleteUserResourceProfile(userId, gatewayID); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while removing user resource profile"); - } } + } /** * Add a Compute Resource Preference to a registered User Resource profile. @@ -3093,16 +2218,8 @@ public boolean addUserComputeResourcePreference( String userComputeResourceId, UserComputeResourcePreference userComputeResourcePreference) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.addUserComputeResourcePreference( userId, gatewayID, userComputeResourceId, userComputeResourcePreference); - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error(userId, "Error while registering user resource profile preference...", e); - throw ThriftExceptionHandler.convertException(e, "Error occurred"); - } catch (Throwable e) { - logger.error(userId, "Error while registering user resource profile preference...", e); - throw ThriftExceptionHandler.convertException(e, "Error occurred"); - } } @Override @@ -3114,11 +2231,8 @@ public boolean addUserStoragePreference( String userStorageResourceId, UserStoragePreference dataStoragePreference) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.addUserStoragePreference(userId, gatewayID, userStorageResourceId, dataStoragePreference); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while registering user storage preference"); - } } + } /** * Fetch a Compute Resource Preference of a registered User Resource profile. @@ -3134,22 +2248,16 @@ public boolean addUserStoragePreference( public UserComputeResourcePreference getUserComputeResourcePreference( AuthzToken authzToken, String userId, String gatewayID, String userComputeResourceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getUserComputeResourcePreference(userId, gatewayID, userComputeResourceId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while reading user compute resource preference"); - } } + } @Override @SecurityCheck public UserStoragePreference getUserStoragePreference( AuthzToken authzToken, String userId, String gatewayID, String userStorageId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getUserStoragePreference(userId, gatewayID, userStorageId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while reading user data storage preference"); - } } + } /** * Fetch all User Compute Resource Preferences of a registered gateway profile. @@ -3164,42 +2272,22 @@ public UserStoragePreference getUserStoragePreference( public List getAllUserComputeResourcePreferences( AuthzToken authzToken, String userId, String gatewayID) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getAllUserComputeResourcePreferences(userId, gatewayID); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while reading User compute resource preferences"); - } } + } @Override @SecurityCheck public List getAllUserStoragePreferences( AuthzToken authzToken, String userId, String gatewayID) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getAllUserStoragePreferences(userId, gatewayID); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while reading User data storage preferences"); - } } + } @Override @SecurityCheck public List getAllUserResourceProfiles(AuthzToken authzToken) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getAllUserResourceProfiles(); - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while reading retrieving all user resource profiles. More info : " + e.getMessage()); - throw exception; - } catch (Throwable e) { - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while reading retrieving all user resource profiles. More info : " + e.getMessage()); - throw exception; - } } /** @@ -3221,11 +2309,8 @@ public boolean updateUserComputeResourcePreference( String userComputeResourceId, UserComputeResourcePreference userComputeResourcePreference) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.updateUserComputeResourcePreference(userId, gatewayID, userComputeResourceId, userComputeResourcePreference); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while updating user compute resource preference"); - } } + } @Override @SecurityCheck @@ -3236,11 +2321,8 @@ public boolean updateUserStoragePreference( String userStorageId, UserStoragePreference dataStoragePreference) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.updateUserStoragePreference(userId, gatewayID, userStorageId, dataStoragePreference); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while updating user data storage preference"); - } } + } /** * Delete the Compute Resource Preference of a registered User Resource profile. @@ -3256,15 +2338,7 @@ public boolean updateUserStoragePreference( public boolean deleteUserComputeResourcePreference( AuthzToken authzToken, String userId, String gatewayID, String userComputeResourceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.deleteUserComputeResourcePreference(userId, gatewayID, userComputeResourceId); - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - logger.error(userId, "Error while deleting user compute resource preference...", e); - throw ThriftExceptionHandler.convertException(e, "Error occurred"); - } catch (Throwable e) { - logger.error(userId, "Error while deleting user compute resource preference...", e); - throw ThriftExceptionHandler.convertException(e, "Error occurred"); - } } @Override @@ -3272,27 +2346,14 @@ public boolean deleteUserComputeResourcePreference( public boolean deleteUserStoragePreference( AuthzToken authzToken, String userId, String gatewayID, String userStorageId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.deleteUserStoragePreference(userId, gatewayID, userStorageId); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error while deleting user data storage preference"); - } } + } @Override @SecurityCheck public List getLatestQueueStatuses(AuthzToken authzToken) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getLatestQueueStatuses(); - } catch (org.apache.airavata.registry.cpi.RegistryException e) { - String msg = "Error in retrieving queue statuses"; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } catch (Throwable e) { - String msg = "Error in retrieving queue statuses"; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } } /** @@ -3305,62 +2366,35 @@ public List getLatestQueueStatuses(AuthzToken authzToken) @SecurityCheck public String registerDataProduct(AuthzToken authzToken, DataProductModel dataProductModel) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.registerDataProduct(dataProductModel); - } catch (Throwable e) { - String msg = "Error in registering the data resource" + dataProductModel.getProductName() + "."; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } } @Override @SecurityCheck public DataProductModel getDataProduct(AuthzToken authzToken, String productUri) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getDataProduct(productUri); - } catch (Throwable e) { - throw ThriftExceptionHandler.convertException(e, "Error retrieving data product"); - } } + } @Override @SecurityCheck public String registerReplicaLocation(AuthzToken authzToken, DataReplicaLocationModel replicaLocationModel) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.registerReplicaLocation(replicaLocationModel); - } catch (Throwable e) { - String msg = "Error in retreiving the replica " + replicaLocationModel.getReplicaName() + "."; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } } @Override @SecurityCheck public DataProductModel getParentDataProduct(AuthzToken authzToken, String productUri) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getParentDataProduct(productUri); - } catch (Throwable e) { - String msg = "Error in retreiving the parent data product for " + productUri + "."; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } } @Override @SecurityCheck public List getChildDataProducts(AuthzToken authzToken, String productUri) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getChildDataProducts(productUri); - } catch (Throwable e) { - String msg = "Error in retreiving the child products for " + productUri + "."; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } } /** @@ -3375,52 +2409,7 @@ public List getChildDataProducts(AuthzToken authzToken, String public boolean shareResourceWithUsers( AuthzToken authzToken, String resourceId, Map userPermissionList) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { - if (!airavataService.userHasAccessInternal( authzToken, resourceId, ResourcePermissionType.OWNER) - && !airavataService.userHasAccessInternal( authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { - throw new AuthorizationException( - "User is not allowed to change sharing because the user is either not the resource owner or does not have access to share the resource"); - } - for (Map.Entry userPermission : userPermissionList.entrySet()) { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - if (userPermission.getValue().equals(ResourcePermissionType.WRITE)) - airavataService.shareEntityWithUsers( - gatewayId, - resourceId, - Arrays.asList(userPermission.getKey()), - authzToken.getClaimsMap().get(Constants.GATEWAY_ID) + ":" + "WRITE", - true); - else if (userPermission.getValue().equals(ResourcePermissionType.READ)) - airavataService.shareEntityWithUsers( - gatewayId, - resourceId, - Arrays.asList(userPermission.getKey()), - authzToken.getClaimsMap().get(Constants.GATEWAY_ID) + ":" + "READ", - true); - else if (userPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING)) { - if (airavataService.userHasAccessInternal( authzToken, resourceId, ResourcePermissionType.OWNER)) { - airavataService.createManageSharingPermissionTypeIfMissing( gatewayId); - airavataService.shareEntityWithUsers( - gatewayId, - resourceId, - Arrays.asList(userPermission.getKey()), - authzToken.getClaimsMap().get(Constants.GATEWAY_ID) + ":" + "MANAGE_SHARING", - true); - } else - throw new AuthorizationException( - "User is not allowed to grant sharing permission because the user is not the resource owner."); - } else { - logger.error("Invalid ResourcePermissionType : " - + userPermission.getValue().toString()); - throw new AiravataClientException(AiravataErrorType.UNSUPPORTED_OPERATION); - } - } - return true; - } catch (Throwable e) { - String msg = "Error in sharing resource with users. Resource ID : " + resourceId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } + return airavataService.shareResourceWithUsers(authzToken, resourceId, userPermissionList); } @Override @@ -3428,52 +2417,7 @@ else if (userPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING) public boolean shareResourceWithGroups( AuthzToken authzToken, String resourceId, Map groupPermissionList) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { - if (!airavataService.userHasAccessInternal( authzToken, resourceId, ResourcePermissionType.OWNER) - && !airavataService.userHasAccessInternal( authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { - throw new AuthorizationException( - "User is not allowed to change sharing because the user is either not the resource owner or does not have access to share the resource"); - } - for (Map.Entry groupPermission : groupPermissionList.entrySet()) { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - if (groupPermission.getValue().equals(ResourcePermissionType.WRITE)) - airavataService.shareEntityWithGroups( - gatewayId, - resourceId, - Arrays.asList(groupPermission.getKey()), - authzToken.getClaimsMap().get(Constants.GATEWAY_ID) + ":" + "WRITE", - true); - else if (groupPermission.getValue().equals(ResourcePermissionType.READ)) - airavataService.shareEntityWithGroups( - gatewayId, - resourceId, - Arrays.asList(groupPermission.getKey()), - authzToken.getClaimsMap().get(Constants.GATEWAY_ID) + ":" + "READ", - true); - else if (groupPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING)) { - if (airavataService.userHasAccessInternal( authzToken, resourceId, ResourcePermissionType.OWNER)) { - airavataService.createManageSharingPermissionTypeIfMissing( gatewayId); - airavataService.shareEntityWithGroups( - gatewayId, - resourceId, - Arrays.asList(groupPermission.getKey()), - authzToken.getClaimsMap().get(Constants.GATEWAY_ID) + ":" + "MANAGE_SHARING", - true); - } else - throw new AuthorizationException( - "User is not allowed to grant sharing permission because the user is not the resource owner."); - } else { - logger.error("Invalid ResourcePermissionType : " - + groupPermission.getValue().toString()); - throw new AiravataClientException(AiravataErrorType.UNSUPPORTED_OPERATION); - } - } - return true; - } catch (Throwable e) { - String msg = "Error in sharing resource with groups. Resource ID : " + resourceId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } + return airavataService.shareResourceWithGroups(authzToken, resourceId, groupPermissionList); } @Override @@ -3481,49 +2425,7 @@ else if (groupPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING public boolean revokeSharingOfResourceFromUsers( AuthzToken authzToken, String resourceId, Map userPermissionList) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { - if (!airavataService.userHasAccessInternal( authzToken, resourceId, ResourcePermissionType.OWNER) - && !airavataService.userHasAccessInternal( authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { - throw new AuthorizationException( - "User is not allowed to change sharing because the user is either not the resource owner or does not have access to share the resource"); - } - for (Map.Entry userPermission : userPermissionList.entrySet()) { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - if (userPermission.getValue().equals(ResourcePermissionType.WRITE)) - airavataService.revokeEntitySharingFromUsers( - gatewayId, - resourceId, - Arrays.asList(userPermission.getKey()), - authzToken.getClaimsMap().get(Constants.GATEWAY_ID) + ":" + "WRITE"); - else if (userPermission.getValue().equals(ResourcePermissionType.READ)) - airavataService.revokeEntitySharingFromUsers( - gatewayId, - resourceId, - Arrays.asList(userPermission.getKey()), - authzToken.getClaimsMap().get(Constants.GATEWAY_ID) + ":" + "READ"); - else if (userPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING)) { - if (airavataService.userHasAccessInternal( authzToken, resourceId, ResourcePermissionType.OWNER)) { - airavataService.createManageSharingPermissionTypeIfMissing( gatewayId); - airavataService.revokeEntitySharingFromUsers( - gatewayId, - resourceId, - Arrays.asList(userPermission.getKey()), - authzToken.getClaimsMap().get(Constants.GATEWAY_ID) + ":" + "MANAGE_SHARING"); - } else - throw new AuthorizationException( - "User is not allowed to change sharing permission because the user is not the resource owner."); - } else { - logger.error("Invalid ResourcePermissionType : " - + userPermission.getValue().toString()); - throw new AiravataClientException(AiravataErrorType.UNSUPPORTED_OPERATION); - } - } - return true; - } catch (Throwable e) { - String msg = "Error in revoking access to resource from users. Resource ID : " + resourceId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } + return airavataService.revokeSharingOfResourceFromUsers(authzToken, resourceId, userPermissionList); } @Override @@ -3607,13 +2509,7 @@ else if (groupPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING public List getAllAccessibleUsers( AuthzToken authzToken, String resourceId, ResourcePermissionType permissionType) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getAllAccessibleUsersWithSharing( authzToken, resourceId, permissionType, false); - } catch (Throwable e) { - String msg = "Error in getting all accessible users for resource. Resource ID : " + resourceId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } } @Override @@ -3621,13 +2517,7 @@ public List getAllAccessibleUsers( public List getAllDirectlyAccessibleUsers( AuthzToken authzToken, String resourceId, ResourcePermissionType permissionType) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getAllAccessibleUsersWithSharing( authzToken, resourceId, permissionType, true); - } catch (Throwable e) { - String msg = "Error in getting all directly accessible users for resource. Resource ID : " + resourceId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } } @Override @@ -3635,13 +2525,7 @@ public List getAllDirectlyAccessibleUsers( public List getAllAccessibleGroups( AuthzToken authzToken, String resourceId, ResourcePermissionType permissionType) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getAllAccessibleGroupsWithSharing( authzToken, resourceId, permissionType, false); - } catch (Throwable e) { - String msg = "Error in getting all accessible groups for resource. Resource ID : " + resourceId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } } @Override @@ -3649,162 +2533,49 @@ public List getAllAccessibleGroups( public List getAllDirectlyAccessibleGroups( AuthzToken authzToken, String resourceId, ResourcePermissionType permissionType) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getAllAccessibleGroupsWithSharing( authzToken, resourceId, permissionType, true); - } catch (Throwable e) { - String msg = "Error in getting all directly accessible groups for resource. Resource ID : " + resourceId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } } @Override @SecurityCheck public boolean userHasAccess(AuthzToken authzToken, String resourceId, ResourcePermissionType permissionType) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - final String domainId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - final String userId = authzToken.getClaimsMap().get(Constants.USER_NAME) + "@" + domainId; - try { - return airavataService.userHasAccessInternal( authzToken, resourceId, permissionType); - } catch (Throwable e) { - String msg = "Error in if user can access resource. User ID : " + userId + ", Resource ID : " + resourceId - + ", Resource Permission Type : " + permissionType.toString(); - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } + return airavataService.userHasAccessInternal(authzToken, resourceId, permissionType); } @Override @SecurityCheck public String createGroupResourceProfile(AuthzToken authzToken, GroupResourceProfile groupResourceProfile) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - // TODO: verify that gatewayId in groupResourceProfile matches authzToken gatewayId - try { - return airavataService.createGroupResourceProfileWithSharing( authzToken, groupResourceProfile); - } catch (AuthorizationException ae) { - String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); - logger.info("User " + userName - + " not allowed access to resources referenced in this GroupResourceProfile. Reason: " - + ae.getMessage()); - throw ae; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - String msg = "Error creating group resource profile."; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } catch (Throwable e) { - String msg = "Error creating group resource profile."; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } + return airavataService.createGroupResourceProfileWithAuth(authzToken, groupResourceProfile); } @Override @SecurityCheck public void updateGroupResourceProfile(AuthzToken authzToken, GroupResourceProfile groupResourceProfile) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { - airavataService.validateGroupResourceProfile( authzToken, groupResourceProfile); - if (!airavataService.userHasAccessInternal( - authzToken, - groupResourceProfile.getGroupResourceProfileId(), - ResourcePermissionType.WRITE)) { - throw new AuthorizationException("User does not have permission to update group resource profile"); - } - airavataService.updateGroupResourceProfile(groupResourceProfile); - } catch (AuthorizationException ae) { - String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); - logger.info("User " + userName + " not allowed access to update GroupResourceProfile " - + groupResourceProfile.getGroupResourceProfileId() + ", reason: " + ae.getMessage()); - throw ae; - } catch (Throwable e) { - String msg = "Error updating group resource profile. groupResourceProfileId: " - + groupResourceProfile.getGroupResourceProfileId(); - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } + airavataService.updateGroupResourceProfileWithAuth(authzToken, groupResourceProfile); } @Override @SecurityCheck public GroupResourceProfile getGroupResourceProfile(AuthzToken authzToken, String groupResourceProfileId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { - if (ServerSettings.isEnableSharing()) { - try { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!airavataService.userHasAccess( - gatewayId, userId + "@" + gatewayId, groupResourceProfileId, gatewayId + ":READ")) { - throw new AuthorizationException( - "User does not have permission to access group resource profile"); - } - } catch (Throwable e) { - throw new AuthorizationException("User does not have permission to access group resource profile"); - } - } - GroupResourceProfile groupResourceProfile = airavataService.getGroupResourceProfile(groupResourceProfileId); - return groupResourceProfile; - } catch (AuthorizationException checkedException) { - logger.error( - "Error while retrieving group resource profile. groupResourceProfileId: " + groupResourceProfileId, - checkedException); - throw checkedException; - } catch (Throwable e) { - String msg = "Error retrieving group resource profile. groupResourceProfileId: " + groupResourceProfileId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } + return airavataService.getGroupResourceProfileWithAuth(authzToken, groupResourceProfileId); } @Override @SecurityCheck public boolean removeGroupResourceProfile(AuthzToken authzToken, String groupResourceProfileId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - if (ServerSettings.isEnableSharing()) { - try { - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!airavataService.userHasAccess( - gatewayId, userId + "@" + gatewayId, groupResourceProfileId, gatewayId + ":WRITE")) { - throw new AuthorizationException( - "User does not have permission to remove group resource profile"); - } - } catch (Throwable e) { - throw new AuthorizationException("User does not have permission to remove group resource profile"); - } - } - boolean result = airavataService.removeGroupResourceProfile(groupResourceProfileId); - if (result) { - airavataService.deleteEntity(gatewayId, groupResourceProfileId); - } - return result; - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - String msg = "Error removing group resource profile. groupResourceProfileId: " + groupResourceProfileId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } catch (Throwable e) { - String msg = "Error removing group resource profile. groupResourceProfileId: " + groupResourceProfileId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } + return airavataService.removeGroupResourceProfileWithAuth(authzToken, groupResourceProfileId); } @Override @SecurityCheck public List getGroupResourceList(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { return airavataService.getGroupResourceListWithSharing( authzToken, gatewayId); - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - String msg = "Error retrieving list group resource profile list. GatewayId: " + gatewayId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } catch (Throwable e) { - String msg = "Error retrieving list group resource profile list. GatewayId: " + gatewayId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } } @Override @@ -3812,103 +2583,21 @@ public List getGroupResourceList(AuthzToken authzToken, St public boolean removeGroupComputePrefs( AuthzToken authzToken, String computeResourceId, String groupResourceProfileId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { - if (ServerSettings.isEnableSharing()) { - try { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!airavataService.userHasAccess( - gatewayId, userId + "@" + gatewayId, groupResourceProfileId, gatewayId + ":WRITE")) { - throw new AuthorizationException( - "User does not have permission to remove group compute preferences"); - } - } catch (Throwable e) { - throw new AuthorizationException( - "User does not have permission to remove group compute preferences"); - } - } - return airavataService.removeGroupComputePrefs(computeResourceId, groupResourceProfileId); - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - String msg = "Error removing group compute resource preferences. GroupResourceProfileId: " - + groupResourceProfileId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } catch (Throwable e) { - String msg = "Error removing group compute resource preferences. GroupResourceProfileId: " - + groupResourceProfileId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } + return airavataService.removeGroupComputePrefsWithAuth(authzToken, computeResourceId, groupResourceProfileId); } @Override @SecurityCheck public boolean removeGroupComputeResourcePolicy(AuthzToken authzToken, String resourcePolicyId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { - if (ServerSettings.isEnableSharing()) { - try { - ComputeResourcePolicy computeResourcePolicy = airavataService.getGroupComputeResourcePolicy(resourcePolicyId); - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!airavataService.userHasAccess( - gatewayId, - userId + "@" + gatewayId, - computeResourcePolicy.getGroupResourceProfileId(), - gatewayId + ":WRITE")) { - throw new AuthorizationException( - "User does not have permission to remove group compute resource policy"); - } - } catch (Throwable e) { - throw new AuthorizationException( - "User does not have permission to remove group compute resource policy"); - } - } - return airavataService.removeGroupComputeResourcePolicy(resourcePolicyId); - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - String msg = "Error removing group compute resource policy. ResourcePolicyId: " + resourcePolicyId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } catch (Throwable e) { - String msg = "Error removing group compute resource policy. ResourcePolicyId: " + resourcePolicyId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } + return airavataService.removeGroupComputeResourcePolicyWithAuth(authzToken, resourcePolicyId); } @Override @SecurityCheck public boolean removeGroupBatchQueueResourcePolicy(AuthzToken authzToken, String resourcePolicyId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { - if (ServerSettings.isEnableSharing()) { - try { - BatchQueueResourcePolicy batchQueueResourcePolicy = airavataService.getBatchQueueResourcePolicy(resourcePolicyId); - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!airavataService.userHasAccess( - gatewayId, - userId + "@" + gatewayId, - batchQueueResourcePolicy.getGroupResourceProfileId(), - gatewayId + ":WRITE")) { - throw new AuthorizationException( - "User does not have permission to remove batch queue resource policy"); - } - } catch (Throwable e) { - throw new AuthorizationException( - "User does not have permission to remove batch queue resource policy"); - } - } - return airavataService.removeGroupBatchQueueResourcePolicy(resourcePolicyId); - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - String msg = "Error removing batch queue resource policy. ResourcePolicyId: " + resourcePolicyId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } catch (Throwable e) { - String msg = "Error removing batch queue resource policy. ResourcePolicyId: " + resourcePolicyId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } + return airavataService.removeGroupBatchQueueResourcePolicyWithAuth(authzToken, resourcePolicyId); } @Override @@ -3916,99 +2605,21 @@ public boolean removeGroupBatchQueueResourcePolicy(AuthzToken authzToken, String public GroupComputeResourcePreference getGroupComputeResourcePreference( AuthzToken authzToken, String computeResourceId, String groupResourceProfileId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { - if (ServerSettings.isEnableSharing()) { - try { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!airavataService.userHasAccess( - gatewayId, userId + "@" + gatewayId, groupResourceProfileId, gatewayId + ":READ")) { - throw new AuthorizationException( - "User does not have permission to access group resource profile"); - } - } catch (Throwable e) { - throw new AuthorizationException("User does not have permission to access group resource profile"); - } - } - return airavataService.getGroupComputeResourcePreference(computeResourceId, groupResourceProfileId); - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - String msg = "Error retrieving Group compute preference. GroupResourceProfileId: " + groupResourceProfileId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } catch (Throwable e) { - String msg = "Error retrieving Group compute preference. GroupResourceProfileId: " + groupResourceProfileId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } + return airavataService.getGroupComputeResourcePreferenceWithAuth(authzToken, computeResourceId, groupResourceProfileId); } @Override @SecurityCheck public ComputeResourcePolicy getGroupComputeResourcePolicy(AuthzToken authzToken, String resourcePolicyId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { - if (ServerSettings.isEnableSharing()) { - try { - ComputeResourcePolicy computeResourcePolicy = airavataService.getGroupComputeResourcePolicy(resourcePolicyId); - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!airavataService.userHasAccess( - gatewayId, - userId + "@" + gatewayId, - computeResourcePolicy.getGroupResourceProfileId(), - gatewayId + ":READ")) { - throw new AuthorizationException( - "User does not have permission to access group resource profile"); - } - } catch (Throwable e) { - throw new AuthorizationException("User does not have permission to access group resource profile"); - } - } - - return airavataService.getGroupComputeResourcePolicy(resourcePolicyId); - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - String msg = "Error retrieving Group compute resource policy. ResourcePolicyId: " + resourcePolicyId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } catch (Throwable e) { - String msg = "Error retrieving Group compute resource policy. ResourcePolicyId: " + resourcePolicyId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } + return airavataService.getGroupComputeResourcePolicyWithAuth(authzToken, resourcePolicyId); } @Override @SecurityCheck public BatchQueueResourcePolicy getBatchQueueResourcePolicy(AuthzToken authzToken, String resourcePolicyId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { - if (ServerSettings.isEnableSharing()) { - try { - BatchQueueResourcePolicy batchQueueResourcePolicy = airavataService.getBatchQueueResourcePolicy(resourcePolicyId); - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!airavataService.userHasAccess( - gatewayId, - userId + "@" + gatewayId, - batchQueueResourcePolicy.getGroupResourceProfileId(), - gatewayId + ":READ")) { - throw new AuthorizationException( - "User does not have permission to access group resource profile"); - } - } catch (Throwable e) { - throw new AuthorizationException("User does not have permission to access group resource profile"); - } - } - return airavataService.getBatchQueueResourcePolicy(resourcePolicyId); - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - String msg = "Error retrieving Group batch queue resource policy. ResourcePolicyId: " + resourcePolicyId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } catch (Throwable e) { - String msg = "Error retrieving Group batch queue resource policy. ResourcePolicyId: " + resourcePolicyId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } + return airavataService.getBatchQueueResourcePolicyWithAuth(authzToken, resourcePolicyId); } @Override @@ -4016,32 +2627,7 @@ public BatchQueueResourcePolicy getBatchQueueResourcePolicy(AuthzToken authzToke public List getGroupComputeResourcePrefList( AuthzToken authzToken, String groupResourceProfileId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { - if (ServerSettings.isEnableSharing()) { - try { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!airavataService.userHasAccess( - gatewayId, userId + "@" + gatewayId, groupResourceProfileId, gatewayId + ":READ")) { - throw new AuthorizationException( - "User does not have permission to access group resource profile"); - } - } catch (Throwable e) { - throw new AuthorizationException("User does not have permission to access group resource profile"); - } - } - return airavataService.getGroupComputeResourcePrefList(groupResourceProfileId); - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - String msg = "Error retrieving Group compute resource preference. GroupResourceProfileId: " - + groupResourceProfileId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } catch (Throwable e) { - String msg = "Error retrieving Group compute resource preference. GroupResourceProfileId: " - + groupResourceProfileId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } + return airavataService.getGroupComputeResourcePrefListWithAuth(authzToken, groupResourceProfileId); } @Override @@ -4049,32 +2635,7 @@ public List getGroupComputeResourcePrefList( public List getGroupBatchQueueResourcePolicyList( AuthzToken authzToken, String groupResourceProfileId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { - if (ServerSettings.isEnableSharing()) { - try { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!airavataService.userHasAccess( - gatewayId, userId + "@" + gatewayId, groupResourceProfileId, gatewayId + ":READ")) { - throw new AuthorizationException( - "User does not have permission to access group resource profile"); - } - } catch (Throwable e) { - throw new AuthorizationException("User does not have permission to access group resource profile"); - } - } - return airavataService.getGroupBatchQueueResourcePolicyList(groupResourceProfileId); - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - String msg = "Error retrieving Group batch queue resource policy list. GroupResourceProfileId: " - + groupResourceProfileId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } catch (Throwable e) { - String msg = "Error retrieving Group batch queue resource policy list. GroupResourceProfileId: " - + groupResourceProfileId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } + return airavataService.getGroupBatchQueueResourcePolicyListWithAuth(authzToken, groupResourceProfileId); } @Override @@ -4082,32 +2643,7 @@ public List getGroupBatchQueueResourcePolicyList( public List getGroupComputeResourcePolicyList( AuthzToken authzToken, String groupResourceProfileId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { - if (ServerSettings.isEnableSharing()) { - try { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!airavataService.userHasAccess( - gatewayId, userId + "@" + gatewayId, groupResourceProfileId, gatewayId + ":READ")) { - throw new AuthorizationException( - "User does not have permission to access group resource profile"); - } - } catch (Throwable e) { - throw new AuthorizationException("User does not have permission to access group resource profile"); - } - } - return airavataService.getGroupComputeResourcePolicyList(groupResourceProfileId); - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { - String msg = "Error retrieving Group compute resource policy list. GroupResourceProfileId: " - + groupResourceProfileId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } catch (Throwable e) { - String msg = "Error retrieving Group compute resource policy list. GroupResourceProfileId: " - + groupResourceProfileId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } + return airavataService.getGroupComputeResourcePolicyListWithAuth(authzToken, groupResourceProfileId); } @Override @@ -4115,99 +2651,42 @@ public List getGroupComputeResourcePolicyList( public GatewayGroups getGatewayGroups(AuthzToken authzToken) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - - try { - return airavataService.retrieveGatewayGroups(gatewayId); - } catch (Throwable e) { - String msg = "Error retrieving GatewayGroups for gateway: " + gatewayId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } + return airavataService.retrieveGatewayGroups(gatewayId); } @Override @SecurityCheck public Parser getParser(AuthzToken authzToken, String parserId, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { - return airavataService.getParser(parserId, gatewayId); - } catch (org.apache.airavata.registry.cpi.RegistryException e) { - String msg = "Error retrieving parser with id: " + parserId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } catch (Throwable e) { - String msg = "Error retrieving parser with id: " + parserId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } + return airavataService.getParser(parserId, gatewayId); } @Override @SecurityCheck public String saveParser(AuthzToken authzToken, Parser parser) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { - return airavataService.saveParser(parser); - } catch (org.apache.airavata.registry.cpi.RegistryException e) { - String msg = "Error while saving the parser"; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } catch (Throwable e) { - String msg = "Error while saving the parser"; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } + return airavataService.saveParser(parser); } @Override @SecurityCheck public List listAllParsers(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { - return airavataService.listAllParsers(gatewayId); - } catch (org.apache.airavata.registry.cpi.RegistryException e) { - String msg = "Error while listing the parsers for gateway " + gatewayId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } catch (Throwable e) { - String msg = "Error while listing the parsers for gateway " + gatewayId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } + return airavataService.listAllParsers(gatewayId); } @Override @SecurityCheck public boolean removeParser(AuthzToken authzToken, String parserId, String gatewayId){ - try { - airavataService.removeParser(parserId, gatewayId); - return true; - } catch (org.apache.airavata.registry.cpi.RegistryException e) { - String msg = "Error while removing the parser " + parserId + " in gateway " + gatewayId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } catch (Throwable e) { - String msg = "Error while removing the parser " + parserId + " in gateway " + gatewayId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } + airavataService.removeParser(parserId, gatewayId); + return true; } @Override @SecurityCheck public ParsingTemplate getParsingTemplate(AuthzToken authzToken, String templateId, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { - return airavataService.getParsingTemplate(templateId, gatewayId); - } catch (org.apache.airavata.registry.cpi.RegistryException e) { - String msg = "Error retrieving parsing template with id: " + templateId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } catch (Throwable e) { - String msg = "Error retrieving parsing template with id: " + templateId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } + return airavataService.getParsingTemplate(templateId, gatewayId); } @Override @@ -4215,333 +2694,33 @@ public ParsingTemplate getParsingTemplate(AuthzToken authzToken, String template public List getParsingTemplatesForExperiment( AuthzToken authzToken, String experimentId, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { - return airavataService.getParsingTemplatesForExperiment(experimentId, gatewayId); - } catch (org.apache.airavata.registry.cpi.RegistryException e) { - String msg = "Error retrieving parsing templates for experiment: " + experimentId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } catch (Throwable e) { - String msg = "Error retrieving parsing templates for experiment: " + experimentId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } + return airavataService.getParsingTemplatesForExperiment(experimentId, gatewayId); } @Override @SecurityCheck public String saveParsingTemplate(AuthzToken authzToken, ParsingTemplate parsingTemplate) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { - return airavataService.saveParsingTemplate(parsingTemplate); - } catch (org.apache.airavata.registry.cpi.RegistryException e) { - String msg = "Error saving the parsing template"; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } catch (Throwable e) { - String msg = "Error saving the parsing template"; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } + return airavataService.saveParsingTemplate(parsingTemplate); } @Override @SecurityCheck public boolean removeParsingTemplate(AuthzToken authzToken, String templateId, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { - airavataService.removeParsingTemplate(templateId, gatewayId); - return true; - } catch (org.apache.airavata.registry.cpi.RegistryException e) { - String msg = "Error while removing the parsing template " + templateId + " in gateway " + gatewayId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } catch (Throwable e) { - String msg = "Error while removing the parsing template " + templateId + " in gateway " + gatewayId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } + airavataService.removeParsingTemplate(templateId, gatewayId); + return true; } @Override @SecurityCheck public List listAllParsingTemplates(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { - return airavataService.listAllParsingTemplates(gatewayId); - } catch (org.apache.airavata.registry.cpi.RegistryException e) { - String msg = "Error while listing the parsing templates for gateway " + gatewayId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } catch (Throwable e) { - String msg = "Error while listing the parsing templates for gateway " + gatewayId; - logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); - } + return airavataService.listAllParsingTemplates(gatewayId); } /** * To hold storage info context (login username, credential token, and adaptor) */ - private record StorageInfoContext(String loginUserName, String credentialToken, AgentAdaptor adaptor) {} - - /** - * Check if a gateway resource profile exists - */ - private boolean isGatewayResourceProfileExists(String gatewayId) { - try { - GatewayResourceProfile profile = airavataService.getGatewayResourceProfile(gatewayId); - return profile != null; - } catch (Throwable e) { - logger.error("Error while checking if gateway resource profile exists", e); - return false; - } - } - - private AiravataClientException clientException(AiravataErrorType errorType, String parameter) { - AiravataClientException exception = new AiravataClientException(); - exception.setAiravataErrorType(errorType); - exception.setParameter(parameter); - return exception; - } - - /** - * Resolves compute resource storage info context (login username, credential token, and adaptor). - * Handles user preference → group preference fallback for both login and credentials. - */ - private StorageInfoContext resolveComputeStorageInfoContext( - AuthzToken authzToken, String gatewayId, String userId, String resourceId) - throws Exception { - String loginUserName = null; - boolean loginFromUserPref = false; - GroupComputeResourcePreference groupComputePref = null; - GroupResourceProfile groupResourceProfile = null; - - UserComputeResourcePreference userComputePref = null; - if (safeIsUserResourceProfileExists(authzToken, userId, gatewayId)) { - userComputePref = getUserComputeResourcePreference(authzToken, userId, gatewayId, resourceId); - } else { - logger.debug( - "User resource profile does not exist for user {} in gateway {}, will try group preferences", - userId, - gatewayId); - } - - if (userComputePref != null - && userComputePref.getLoginUserName() != null - && !userComputePref.getLoginUserName().trim().isEmpty()) { - loginUserName = userComputePref.getLoginUserName(); - loginFromUserPref = true; - logger.debug("Using user preference login username: {}", loginUserName); - - } else { - // Fallback to GroupComputeResourcePreference - List groupResourceProfiles = getGroupResourceList(authzToken, gatewayId); - for (GroupResourceProfile groupProfile : groupResourceProfiles) { - List groupComputePrefs = groupProfile.getComputePreferences(); - - if (groupComputePrefs != null && !groupComputePrefs.isEmpty()) { - for (GroupComputeResourcePreference groupPref : groupComputePrefs) { - if (resourceId.equals(groupPref.getComputeResourceId()) - && groupPref.getLoginUserName() != null - && !groupPref.getLoginUserName().trim().isEmpty()) { - loginUserName = groupPref.getLoginUserName(); - groupComputePref = groupPref; - groupResourceProfile = groupProfile; - logger.debug( - "Using login username from group compute resource preference for resource {}", - resourceId); - break; - } - } - } - if (loginUserName != null) { - break; - } - } - if (loginUserName == null) { - logger.debug("No login username found for compute resource {}", resourceId); - throw new InvalidRequestException("No login username found for compute resource " + resourceId); - } - } - - // Resolve credential token based on where login came from - String credentialToken; - if (loginFromUserPref) { - // Login username came from user preference. Use user preference token → user profile token - if (userComputePref != null - && userComputePref.getResourceSpecificCredentialStoreToken() != null - && !userComputePref - .getResourceSpecificCredentialStoreToken() - .trim() - .isEmpty()) { - credentialToken = userComputePref.getResourceSpecificCredentialStoreToken(); - } else { - UserResourceProfile userResourceProfile = getUserResourceProfile(authzToken, userId, gatewayId); - if (userResourceProfile == null - || userResourceProfile.getCredentialStoreToken() == null - || userResourceProfile.getCredentialStoreToken().trim().isEmpty()) { - logger.error("No credential store token found for user {} in gateway {}", userId, gatewayId); - throw clientException( - AiravataErrorType.AUTHENTICATION_FAILURE, - "No credential store token found for user " + userId + " in gateway " + gatewayId); - } - credentialToken = userResourceProfile.getCredentialStoreToken(); - } - } else { - // Login username came from group preference. Use group preference token → group profile default token → - // user profile token (fallback) - if (groupComputePref != null - && groupComputePref.getResourceSpecificCredentialStoreToken() != null - && !groupComputePref - .getResourceSpecificCredentialStoreToken() - .trim() - .isEmpty()) { - credentialToken = groupComputePref.getResourceSpecificCredentialStoreToken(); - - } else if (groupResourceProfile != null - && groupResourceProfile.getDefaultCredentialStoreToken() != null - && !groupResourceProfile - .getDefaultCredentialStoreToken() - .trim() - .isEmpty()) { - credentialToken = groupResourceProfile.getDefaultCredentialStoreToken(); - - } else { - UserResourceProfile userResourceProfile = getUserResourceProfile(authzToken, userId, gatewayId); - if (userResourceProfile == null - || userResourceProfile.getCredentialStoreToken() == null - || userResourceProfile.getCredentialStoreToken().trim().isEmpty()) { - logger.error("No credential store token found for user {} in gateway {}", userId, gatewayId); - throw clientException( - AiravataErrorType.AUTHENTICATION_FAILURE, - "No credential store token found for compute resource " + resourceId); - } - credentialToken = userResourceProfile.getCredentialStoreToken(); - } - } - - AgentAdaptor adaptor = AdaptorSupportImpl.getInstance() - .fetchComputeSSHAdaptor(gatewayId, resourceId, credentialToken, userId, loginUserName); - logger.info("Resolved resource {} as compute resource to fetch storage details", resourceId); - - return new StorageInfoContext(loginUserName, credentialToken, adaptor); - } - - /** - * Resolves storage resource storage info context (login username, credential token, and adaptor). - * Handles user preference → gateway preference fallback for both login and credentials. - */ - private StorageInfoContext resolveStorageStorageInfoContext( - AuthzToken authzToken, String gatewayId, String userId, String resourceId) - throws Exception { - UserStoragePreference userStoragePref = null; - if (safeIsUserResourceProfileExists(authzToken, userId, gatewayId)) { - userStoragePref = getUserStoragePreference(authzToken, userId, gatewayId, resourceId); - } else { - logger.debug( - "User resource profile does not exist for user {} in gateway {}, will try gateway preferences", - userId, - gatewayId); - } - - StoragePreference storagePref = null; - if (isGatewayResourceProfileExists(gatewayId)) { - storagePref = getGatewayStoragePreference(authzToken, gatewayId, resourceId); - } else { - logger.debug( - "Gateway resource profile does not exist for gateway {}, will check if user preference exists", - gatewayId); - } - - String loginUserName; - boolean loginFromUserPref; - - if (userStoragePref != null - && userStoragePref.getLoginUserName() != null - && !userStoragePref.getLoginUserName().trim().isEmpty()) { - loginUserName = userStoragePref.getLoginUserName(); - loginFromUserPref = true; - logger.debug("Using login username from user storage preference for resource {}", resourceId); - - } else if (storagePref != null - && storagePref.getLoginUserName() != null - && !storagePref.getLoginUserName().trim().isEmpty()) { - loginUserName = storagePref.getLoginUserName(); - loginFromUserPref = false; - logger.debug("Using login username from gateway storage preference for resource {}", resourceId); - - } else { - logger.error("No login username found for storage resource {}", resourceId); - throw new InvalidRequestException("No login username found for storage resource " + resourceId); - } - - // Resolve credential token based on where login came from - String credentialToken; - if (loginFromUserPref) { - // Login came from user preference. Use user preference token or user profile token - if (userStoragePref != null - && userStoragePref.getResourceSpecificCredentialStoreToken() != null - && !userStoragePref - .getResourceSpecificCredentialStoreToken() - .trim() - .isEmpty()) { - credentialToken = userStoragePref.getResourceSpecificCredentialStoreToken(); - logger.debug("Using login username from user preference for resource {}", resourceId); - - } else { - UserResourceProfile userResourceProfile = getUserResourceProfile(authzToken, userId, gatewayId); - if (userResourceProfile == null - || userResourceProfile.getCredentialStoreToken() == null - || userResourceProfile.getCredentialStoreToken().trim().isEmpty()) { - logger.error("No credential store token found for user {} in gateway {}", userId, gatewayId); - throw clientException( - AiravataErrorType.AUTHENTICATION_FAILURE, - "No credential store token found for user " + userId + " in gateway " + gatewayId); - } - credentialToken = userResourceProfile.getCredentialStoreToken(); - } - } else { - // Login came from gateway preference. Use gateway preference token or gateway profile token - if (storagePref != null - && storagePref.getResourceSpecificCredentialStoreToken() != null - && !storagePref - .getResourceSpecificCredentialStoreToken() - .trim() - .isEmpty()) { - credentialToken = storagePref.getResourceSpecificCredentialStoreToken(); - - } else { - GatewayResourceProfile gatewayResourceProfile = getGatewayResourceProfile(authzToken, gatewayId); - if (gatewayResourceProfile == null - || gatewayResourceProfile.getCredentialStoreToken() == null - || gatewayResourceProfile - .getCredentialStoreToken() - .trim() - .isEmpty()) { - logger.error("No credential store token found for gateway {}", gatewayId); - throw clientException( - AiravataErrorType.AUTHENTICATION_FAILURE, - "No credential store token found for gateway " + gatewayId); - } - credentialToken = gatewayResourceProfile.getCredentialStoreToken(); - } - } - - AgentAdaptor adaptor = AdaptorSupportImpl.getInstance() - .fetchStorageSSHAdaptor(gatewayId, resourceId, credentialToken, userId, loginUserName); - logger.info("Resolved resource {} as storage resource to fetch storage details", resourceId); - - return new StorageInfoContext(loginUserName, credentialToken, adaptor); - } - - private boolean safeIsUserResourceProfileExists(AuthzToken authzToken, String userId, String gatewayId) { - try { - return isUserResourceProfileExists(authzToken, userId, gatewayId); - } catch (Throwable e) { - logger.error("Error checking if user resource profile exists", e); - return false; - } - } } \ No newline at end of file diff --git a/airavata-api/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java index 6be8b1bb8c..7f2a11bfc3 100644 --- a/airavata-api/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java @@ -57,121 +57,51 @@ public String addSSHCredential(SSHCredential sshCredential) @Override public String addCertificateCredential(CertificateCredential certificateCredential) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { - try { - return credentialStoreService.addCertificateCredential(certificateCredential); - } catch (CredentialStoreException e) { - log.error("Error occurred while saving Certificate Credentials.", e); - throw new org.apache.airavata.credential.store.exception.CredentialStoreException( - "Error occurred while saving Certificate Credentials."); - } catch (Throwable e) { - log.error("Error occurred while saving Certificate Credentials.", e); - throw new org.apache.airavata.credential.store.exception.CredentialStoreException( - "Error occurred while saving Certificate Credentials."); - } + return credentialStoreService.addCertificateCredential(certificateCredential); } @Override public String addPasswordCredential(PasswordCredential passwordCredential) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { - try { - return credentialStoreService.addPasswordCredential(passwordCredential); - } catch (CredentialStoreException e) { - log.error("Error occurred while saving PWD Credentials.", e); - throw new org.apache.airavata.credential.store.exception.CredentialStoreException( - "Error occurred while saving PWD Credentials."); - } catch (Throwable e) { - log.error("Error occurred while saving PWD Credentials.", e); - throw new org.apache.airavata.credential.store.exception.CredentialStoreException( - "Error occurred while saving PWD Credentials."); - } + return credentialStoreService.addPasswordCredential(passwordCredential); } @Override public SSHCredential getSSHCredential(String tokenId, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { - try { - return credentialStoreService.getSSHCredential(tokenId, gatewayId); - } catch (CredentialStoreException e) { - log.error( - "Error occurred while retrieving SSH credentialfor token - " + tokenId + " and gateway id - " - + gatewayId, - e); - throw new org.apache.airavata.credential.store.exception.CredentialStoreException( - "Error occurred while retrieving SSH credential for token - " + tokenId + " and gateway id - " - + gatewayId); - } + return credentialStoreService.getSSHCredential(tokenId, gatewayId); } @Override public CredentialSummary getCredentialSummary(String tokenId, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { - try { - return credentialStoreService.getCredentialSummary(tokenId, gatewayId); - } catch (CredentialStoreException e) { - final String msg = "Error occurred while retrieving credential summary for token - " + tokenId - + " and gateway id - " + gatewayId; - log.error(msg, e); - throw new org.apache.airavata.credential.store.exception.CredentialStoreException(msg); - } + return credentialStoreService.getCredentialSummary(tokenId, gatewayId); } @Override public List getAllCredentialSummaries( SummaryType type, List accessibleTokenIds, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { - try { - return credentialStoreService.getAllCredentialSummaries(type, accessibleTokenIds, gatewayId); - } catch (CredentialStoreException e) { - final String msg = "Error occurred while retrieving " + type + " credential Summary for tokens - " - + accessibleTokenIds + " and gateway id - " + gatewayId; - log.error(msg, e); - throw new org.apache.airavata.credential.store.exception.CredentialStoreException(msg); - } + return credentialStoreService.getAllCredentialSummaries(type, accessibleTokenIds, gatewayId); } @Override public CertificateCredential getCertificateCredential(String tokenId, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { - try { - return credentialStoreService.getCertificateCredential(tokenId, gatewayId); - } catch (CredentialStoreException e) { - log.error( - "Error occurred while retrieving Certificate credential for token - " + tokenId - + " and gateway id - " + gatewayId, - e); - throw new org.apache.airavata.credential.store.exception.CredentialStoreException( - "Error occurred while retrieving Certificate credential for token - " + tokenId - + " and gateway id - " + gatewayId); - } + return credentialStoreService.getCertificateCredential(tokenId, gatewayId); } @Override public PasswordCredential getPasswordCredential(String tokenId, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { - try { - return credentialStoreService.getPasswordCredential(tokenId, gatewayId); - } catch (CredentialStoreException e) { - log.error( - "Error occurred while retrieving PWD credentialfor token - " + tokenId + " and gateway id - " - + gatewayId, - e); - throw new org.apache.airavata.credential.store.exception.CredentialStoreException( - "Error occurred while retrieving PWD credential for token - " + tokenId + " and gateway id - " - + gatewayId); - } + return credentialStoreService.getPasswordCredential(tokenId, gatewayId); } @Override @Deprecated public List getAllCredentialSummaryForGateway(SummaryType type, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { - try { - return credentialStoreService.getAllCredentialSummaryForGateway(type, gatewayId); - } catch (CredentialStoreException e) { - log.error("Error occurred while retrieving credential Summary", e); - throw new org.apache.airavata.credential.store.exception.CredentialStoreException( - "Error occurred while retrieving credential Summary"); - } + return credentialStoreService.getAllCredentialSummaryForGateway(type, gatewayId); } @Override @@ -179,57 +109,25 @@ public List getAllCredentialSummaryForGateway(SummaryType typ public List getAllCredentialSummaryForUserInGateway( SummaryType type, String gatewayId, String userId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { - try { - return credentialStoreService.getAllCredentialSummaryForUserInGateway(type, gatewayId, userId); - } catch (CredentialStoreException e) { - log.error("Error occurred while retrieving credential Summary", e); - throw new org.apache.airavata.credential.store.exception.CredentialStoreException( - "Error occurred while retrieving credential Summary"); - } + return credentialStoreService.getAllCredentialSummaryForUserInGateway(type, gatewayId, userId); } @Override @Deprecated public Map getAllPWDCredentialsForGateway(String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { - try { - return credentialStoreService.getAllPWDCredentialsForGateway(gatewayId); - } catch (CredentialStoreException e) { - log.error("Error occurred while retrieving credentials", e); - throw new org.apache.airavata.credential.store.exception.CredentialStoreException( - "Error occurred while retrieving credentials"); - } + return credentialStoreService.getAllPWDCredentialsForGateway(gatewayId); } @Override public boolean deleteSSHCredential(String tokenId, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { - try { - return credentialStoreService.deleteSSHCredential(tokenId, gatewayId); - } catch (CredentialStoreException e) { - log.error( - "Error occurred while deleting SSH credential for token - " + tokenId + " and gateway id - " - + gatewayId, - e); - throw new org.apache.airavata.credential.store.exception.CredentialStoreException( - "Error occurred while deleting SSH credential for token - " + tokenId + " and gateway id - " - + gatewayId); - } + return credentialStoreService.deleteSSHCredential(tokenId, gatewayId); } @Override public boolean deletePWDCredential(String tokenId, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { - try { - return credentialStoreService.deletePWDCredential(tokenId, gatewayId); - } catch (CredentialStoreException e) { - log.error( - "Error occurred while deleting PWD credential for token - " + tokenId + " and gateway id - " - + gatewayId, - e); - throw new org.apache.airavata.credential.store.exception.CredentialStoreException( - "Error occurred while deleting PWD credential for token - " + tokenId + " and gateway id - " - + gatewayId); - } + return credentialStoreService.deletePWDCredential(tokenId, gatewayId); } } diff --git a/airavata-api/src/main/java/org/apache/airavata/registry/api/service/handler/RegistryServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/registry/api/service/handler/RegistryServerHandler.java index 54aee30298..da76b54cad 100644 --- a/airavata-api/src/main/java/org/apache/airavata/registry/api/service/handler/RegistryServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/registry/api/service/handler/RegistryServerHandler.java @@ -143,14 +143,7 @@ public boolean deleteGateway(String gatewayId) throws RegistryServiceException, */ @Override public List getAllGateways() throws RegistryServiceException, TException { - try { - return registryService.getAllGateways(); - } catch (Throwable 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; - } + return registryService.getAllGateways(); } /** @@ -162,52 +155,24 @@ public List getAllGateways() throws RegistryServiceException, TExceptio */ @Override public boolean isGatewayExist(String gatewayId) throws RegistryServiceException, TException { - try { - return registryService.isGatewayExist(gatewayId); - } catch (Throwable e) { - logger.error("Error while getting gateway", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while getting gateway. More info : " + e.getMessage()); - throw exception; - } + return registryService.isGatewayExist(gatewayId); } @Override public boolean deleteNotification(String gatewayId, String notificationId) throws RegistryServiceException, TException { - try { - return registryService.deleteNotification(gatewayId, notificationId); - } catch (Throwable e) { - logger.error("Error while deleting notification", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while deleting notification. More info : " + e.getMessage()); - throw exception; - } + return registryService.deleteNotification(gatewayId, notificationId); } @Override public Notification getNotification(String gatewayId, String notificationId) throws RegistryServiceException, TException { - try { - return registryService.getNotification(gatewayId, notificationId); - } catch (Throwable e) { - logger.error("Error while retrieving notification", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while retreiving notification. More info : " + e.getMessage()); - throw exception; - } + return registryService.getNotification(gatewayId, notificationId); } @Override public List getAllNotifications(String gatewayId) throws RegistryServiceException, TException { - try { - return registryService.getAllNotifications(gatewayId); - } catch (Throwable e) { - logger.error("Error while getting all notifications", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while getting all notifications. More info : " + e.getMessage()); - throw exception; - } + return registryService.getAllNotifications(gatewayId); } /** @@ -220,11 +185,7 @@ public List getAllNotifications(String gatewayId) throws RegistryS */ @Override public Project getProject(String projectId) throws RegistryServiceException, TException { - try { - return registryService.getProject(projectId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving the project"); - } + return registryService.getProject(projectId); } /** @@ -239,11 +200,7 @@ public Project getProject(String projectId) throws RegistryServiceException, TEx */ @Override public boolean deleteProject(String projectId) throws RegistryServiceException, TException { - try { - return registryService.deleteProject(projectId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while removing the project"); - } + return registryService.deleteProject(projectId); } /** @@ -258,11 +215,7 @@ public boolean deleteProject(String projectId) throws RegistryServiceException, @Override public List getUserProjects(String gatewayId, String userName, int limit, int offset) throws RegistryServiceException, TException { - try { - return registryService.getUserProjects(gatewayId, userName, limit, offset); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving projects"); - } + return registryService.getUserProjects(gatewayId, userName, limit, offset); } /** @@ -285,20 +238,16 @@ public ExperimentStatistics getExperimentStatistics( int limit, int offset) throws RegistryServiceException, TException { - try { - return registryService.getExperimentStatistics( - gatewayId, - fromTime, - toTime, - userName, - applicationName, - resourceHostName, - accessibleExpIds, - limit, - offset); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving experiments"); - } + return registryService.getExperimentStatistics( + gatewayId, + fromTime, + toTime, + userName, + applicationName, + resourceHostName, + accessibleExpIds, + limit, + offset); } /** @@ -313,11 +262,7 @@ public ExperimentStatistics getExperimentStatistics( @Override public List getExperimentsInProject(String gatewayId, String projectId, int limit, int offset) throws RegistryServiceException, TException { - try { - return registryService.getExperimentsInProject(gatewayId, projectId, limit, offset); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving the experiments"); - } + return registryService.getExperimentsInProject(gatewayId, projectId, limit, offset); } /** @@ -332,11 +277,7 @@ public List getExperimentsInProject(String gatewayId, String pr @Override public List getUserExperiments(String gatewayId, String userName, int limit, int offset) throws RegistryServiceException, TException { - try { - return registryService.getUserExperiments(gatewayId, userName, limit, offset); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving the experiments"); - } + return registryService.getUserExperiments(gatewayId, userName, limit, offset); } /** @@ -348,11 +289,7 @@ public List getUserExperiments(String gatewayId, String userNam */ @Override public boolean deleteExperiment(String experimentId) throws RegistryServiceException, TException { - try { - return registryService.deleteExperiment(experimentId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while deleting the experiment"); - } + return registryService.deleteExperiment(experimentId); } /** @@ -427,11 +364,7 @@ public ExperimentModel getExperiment(String airavataExperimentId) throws Registr @Override public ExperimentModel getDetailedExperimentTree(String airavataExperimentId) throws RegistryServiceException, TException { - try { - return registryService.getDetailedExperimentTree(airavataExperimentId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving the experiment"); - } + return registryService.getDetailedExperimentTree(airavataExperimentId); } /** @@ -446,11 +379,7 @@ public ExperimentModel getDetailedExperimentTree(String airavataExperimentId) @Override public ExperimentStatus getExperimentStatus(String airavataExperimentId) throws RegistryServiceException, TException { - try { - return registryService.getExperimentStatus(airavataExperimentId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving experiment status"); - } + return registryService.getExperimentStatus(airavataExperimentId); } /** @@ -464,11 +393,7 @@ public ExperimentStatus getExperimentStatus(String airavataExperimentId) @Override public List getExperimentOutputs(String airavataExperimentId) throws RegistryServiceException, TException { - try { - return registryService.getExperimentOutputs(airavataExperimentId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving the experiment outputs"); - } + return registryService.getExperimentOutputs(airavataExperimentId); } /** @@ -482,11 +407,7 @@ public List getExperimentOutputs(String airavataExperiment @Override public List getIntermediateOutputs(String airavataExperimentId) throws RegistryServiceException, TException { - try { - return registryService.getIntermediateOutputs(airavataExperimentId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving intermediate outputs"); - } + return registryService.getIntermediateOutputs(airavataExperimentId); } /** @@ -499,192 +420,111 @@ public List getIntermediateOutputs(String airavataExperime @Override public Map getJobStatuses(String airavataExperimentId) throws RegistryServiceException, TException { - try { - return registryService.getJobStatuses(airavataExperimentId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving the job statuses"); - } + return registryService.getJobStatuses(airavataExperimentId); } @Override public void addExperimentProcessOutputs(String outputType, List outputs, String id) throws RegistryServiceException, TException { - try { - registryService.addExperimentProcessOutputs(outputType, outputs, id); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while adding outputs"); - } + registryService.addExperimentProcessOutputs(outputType, outputs, id); } @Override public void addErrors(String errorType, ErrorModel errorModel, String id) throws RegistryServiceException, TException { - try { - registryService.addErrors(errorType, errorModel, id); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while adding errors"); - } + registryService.addErrors(errorType, errorModel, id); } @Override public void addTaskStatus(TaskStatus taskStatus, String taskId) throws RegistryServiceException, TException { - try { - registryService.addTaskStatus(taskStatus, taskId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while adding task status"); - } + registryService.addTaskStatus(taskStatus, taskId); } @Override public void addProcessStatus(ProcessStatus processStatus, String processId) throws RegistryServiceException, TException { - try { - registryService.addProcessStatus(processStatus, processId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while adding process status"); - } + registryService.addProcessStatus(processStatus, processId); } @Override public void updateProcessStatus(ProcessStatus processStatus, String processId) throws RegistryServiceException, TException { - try { - registryService.updateProcessStatus(processStatus, processId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while updating process status"); - } + registryService.updateProcessStatus(processStatus, processId); } @Override public void updateExperimentStatus(ExperimentStatus experimentStatus, String experimentId) throws RegistryServiceException, TException { - try { - registryService.updateExperimentStatus(experimentStatus, experimentId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while updating experiment status"); - } + registryService.updateExperimentStatus(experimentStatus, experimentId); } @Override public void addJobStatus(JobStatus jobStatus, String taskId, String jobId) throws RegistryServiceException, TException { - try { - registryService.addJobStatus(jobStatus, taskId, jobId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while adding job status"); - } + registryService.addJobStatus(jobStatus, taskId, jobId); } @Override public void addJob(JobModel jobModel, String processId) throws RegistryServiceException, TException { - try { - registryService.addJob(jobModel, processId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while adding job"); - } + registryService.addJob(jobModel, processId); } @Override public void deleteJobs(String processId) throws RegistryServiceException, TException { - try { - registryService.deleteJobs(processId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while deleting job"); - } + registryService.deleteJobs(processId); } @Override public String addProcess(ProcessModel processModel, String experimentId) throws RegistryServiceException, TException { - try { - return registryService.addProcess(processModel, experimentId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while adding process"); - } + return registryService.addProcess(processModel, experimentId); } @Override public void updateProcess(ProcessModel processModel, String processId) throws RegistryServiceException, TException { - try { - registryService.updateProcess(processModel, processId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while updating process"); - } + registryService.updateProcess(processModel, processId); } @Override public String addTask(TaskModel taskModel, String processId) throws RegistryServiceException, TException { - try { - return registryService.addTask(taskModel, processId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while adding task"); - } + return registryService.addTask(taskModel, processId); } @Override public void deleteTasks(String processId) throws RegistryServiceException, TException { - try { - registryService.deleteTasks(processId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while deleting tasks"); - } + registryService.deleteTasks(processId); } @Override public UserConfigurationDataModel getUserConfigurationData(String experimentId) throws RegistryServiceException, TException { - try { - return registryService.getUserConfigurationData(experimentId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while getting user configuration"); - } + return registryService.getUserConfigurationData(experimentId); } @Override public ProcessModel getProcess(String processId) throws RegistryServiceException, TException { - try { - return registryService.getProcess(processId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving process"); - } + return registryService.getProcess(processId); } @Override public List getProcessList(String experimentId) throws RegistryServiceException, TException { - try { - return registryService.getProcessList(experimentId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving process list"); - } + return registryService.getProcessList(experimentId); } @Override public ProcessStatus getProcessStatus(String processId) throws RegistryServiceException, TException { - try { - return registryService.getProcessStatus(processId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving process status"); - } + return registryService.getProcessStatus(processId); } @Override public List getProcessListInState(ProcessState processState) throws RegistryServiceException, TException { - try { - return registryService.getProcessListInState(processState); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving process list with given status"); - } + return registryService.getProcessListInState(processState); } @Override public List getProcessStatusList(String processId) throws RegistryServiceException, TException { - try { - return registryService.getProcessStatusList(processId); - } catch (Throwable e) { - throw convertToRegistryServiceException( - e, "Error while retrieving process status list for given process Id"); - } + return registryService.getProcessStatusList(processId); } /** @@ -692,11 +532,7 @@ public List getProcessStatusList(String processId) throws Registr */ @Override public boolean isJobExist(String queryType, String id) throws RegistryServiceException, TException { - try { - return registryService.isJobExist(queryType, id); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving job"); - } + return registryService.isJobExist(queryType, id); } /** @@ -704,80 +540,45 @@ public boolean isJobExist(String queryType, String id) throws RegistryServiceExc */ @Override public JobModel getJob(String queryType, String id) throws RegistryServiceException, TException { - try { - return registryService.getJob(queryType, id); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving job"); - } + return registryService.getJob(queryType, id); } @Override public List getJobs(String queryType, String id) throws RegistryServiceException, TException { - try { - return registryService.getJobs(queryType, id); - } catch (Throwable e) { - throw convertToRegistryServiceException( - e, "Error while retrieving jobs for query " + queryType + " and id " + id); - } + return registryService.getJobs(queryType, id); } @Override public int getJobCount( org.apache.airavata.model.status.JobStatus jobStatus, String gatewayId, double searchBackTimeInMinutes) throws RegistryServiceException, TException { - try { - return registryService.getJobCount(jobStatus, gatewayId, searchBackTimeInMinutes); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while getting job count"); - } + return registryService.getJobCount(jobStatus, gatewayId, searchBackTimeInMinutes); } @Override public Map getAVGTimeDistribution(String gatewayId, double searchBackTimeInMinutes) throws RegistryServiceException, TException { - try { - return registryService.getAVGTimeDistribution(gatewayId, searchBackTimeInMinutes); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while getting average time distribution"); - } + return registryService.getAVGTimeDistribution(gatewayId, searchBackTimeInMinutes); } @Override public List getProcessOutputs(String processId) throws RegistryServiceException, TException { - try { - return registryService.getProcessOutputs(processId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving process outputs"); - } + return registryService.getProcessOutputs(processId); } @Override public List getProcessWorkflows(String processId) throws RegistryServiceException, TException { - try { - return registryService.getProcessWorkflows(processId); - } catch (Throwable e) { - throw convertToRegistryServiceException( - e, "Error while retrieving process workflows for process id " + processId); - } + return registryService.getProcessWorkflows(processId); } @Override public void addProcessWorkflow(ProcessWorkflow processWorkflow) throws RegistryServiceException, TException { - try { - registryService.addProcessWorkflow(processWorkflow); - } catch (Throwable e) { - throw convertToRegistryServiceException( - e, "Error while adding process workflows for process id " + processWorkflow.getProcessId()); - } + registryService.addProcessWorkflow(processWorkflow); } @Override public List getProcessIds(String experimentId) throws RegistryServiceException, TException { - try { - return registryService.getProcessIds(experimentId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving process ids"); - } + return registryService.getProcessIds(experimentId); } /** @@ -789,11 +590,7 @@ public List getProcessIds(String experimentId) throws RegistryServiceExc */ @Override public List getJobDetails(String airavataExperimentId) throws RegistryServiceException, TException { - try { - return registryService.getJobDetails(airavataExperimentId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving the job details"); - } + return registryService.getJobDetails(airavataExperimentId); } /** @@ -805,11 +602,7 @@ public List getJobDetails(String airavataExperimentId) throws Registry */ @Override public ApplicationModule getApplicationModule(String appModuleId) throws RegistryServiceException, TException { - try { - return registryService.getApplicationModule(appModuleId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving application module"); - } + return registryService.getApplicationModule(appModuleId); } /** @@ -821,11 +614,7 @@ public ApplicationModule getApplicationModule(String appModuleId) throws Registr */ @Override public List getAllAppModules(String gatewayId) throws RegistryServiceException, TException { - try { - return registryService.getAllAppModules(gatewayId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving all application modules"); - } + return registryService.getAllAppModules(gatewayId); } /** @@ -840,11 +629,7 @@ public List getAllAppModules(String gatewayId) throws Registr public List getAccessibleAppModules( String gatewayId, List accessibleAppIds, List accessibleComputeResourceIds) throws RegistryServiceException, TException { - try { - return registryService.getAccessibleAppModules(gatewayId, accessibleAppIds, accessibleComputeResourceIds); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving all application modules"); - } + return registryService.getAccessibleAppModules(gatewayId, accessibleAppIds, accessibleComputeResourceIds); } /** @@ -856,11 +641,7 @@ public List getAccessibleAppModules( */ @Override public boolean deleteApplicationModule(String appModuleId) throws RegistryServiceException, TException { - try { - return registryService.deleteApplicationModule(appModuleId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while deleting the application module"); - } + return registryService.deleteApplicationModule(appModuleId); } /** @@ -873,11 +654,7 @@ public boolean deleteApplicationModule(String appModuleId) throws RegistryServic @Override public ApplicationDeploymentDescription getApplicationDeployment(String appDeploymentId) throws RegistryServiceException, TException { - try { - return registryService.getApplicationDeployment(appDeploymentId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving application deployment"); - } + return registryService.getApplicationDeployment(appDeploymentId); } /** @@ -889,11 +666,7 @@ public ApplicationDeploymentDescription getApplicationDeployment(String appDeplo */ @Override public boolean deleteApplicationDeployment(String appDeploymentId) throws RegistryServiceException, TException { - try { - return registryService.deleteApplicationDeployment(appDeploymentId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while deleting application deployment"); - } + return registryService.deleteApplicationDeployment(appDeploymentId); } /** @@ -907,11 +680,7 @@ public boolean deleteApplicationDeployment(String appDeploymentId) throws Regist @Override public List getAllApplicationDeployments(String gatewayId) throws RegistryServiceException, TException { - try { - return registryService.getAllApplicationDeployments(gatewayId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving application deployments"); - } + return registryService.getAllApplicationDeployments(gatewayId); } /** @@ -926,12 +695,8 @@ public List getAllApplicationDeployments(Strin public List getAccessibleApplicationDeployments( String gatewayId, List accessibleAppDeploymentIds, List accessibleComputeResourceIds) throws RegistryServiceException, TException { - try { - return registryService.getAccessibleApplicationDeployments( + return registryService.getAccessibleApplicationDeployments( gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving application deployments"); - } } /** @@ -951,12 +716,8 @@ public List getAccessibleApplicationDeployment List accessibleAppDeploymentIds, List accessibleComputeResourceIds) throws RegistryServiceException, TException { - try { - return registryService.getAccessibleApplicationDeploymentsForAppModule( + return registryService.getAccessibleApplicationDeploymentsForAppModule( gatewayId, appModuleId, accessibleAppDeploymentIds, accessibleComputeResourceIds); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving application deployments"); - } } /** @@ -968,21 +729,13 @@ public List getAccessibleApplicationDeployment */ @Override public List getAppModuleDeployedResources(String appModuleId) throws RegistryServiceException, TException { - try { - return registryService.getAppModuleDeployedResources(appModuleId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving application deployment"); - } + return registryService.getAppModuleDeployedResources(appModuleId); } @Override public List getApplicationDeployments(String appModuleId) throws RegistryServiceException, TException { - try { - return registryService.getApplicationDeployments(appModuleId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving application deployment"); - } + return registryService.getApplicationDeployments(appModuleId); } /** @@ -995,11 +748,7 @@ public List getApplicationDeployments(String a @Override public ApplicationInterfaceDescription getApplicationInterface(String appInterfaceId) throws RegistryServiceException, TException { - try { - return registryService.getApplicationInterface(appInterfaceId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving application interface"); - } + return registryService.getApplicationInterface(appInterfaceId); } /** @@ -1011,11 +760,7 @@ public ApplicationInterfaceDescription getApplicationInterface(String appInterfa */ @Override public boolean deleteApplicationInterface(String appInterfaceId) throws RegistryServiceException, TException { - try { - return registryService.deleteApplicationInterface(appInterfaceId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while deleting application interface"); - } + return registryService.deleteApplicationInterface(appInterfaceId); } /** @@ -1028,11 +773,7 @@ public boolean deleteApplicationInterface(String appInterfaceId) throws Registry @Override public Map getAllApplicationInterfaceNames(String gatewayId) throws RegistryServiceException, TException { - try { - return registryService.getAllApplicationInterfaceNames(gatewayId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving application interfaces"); - } + return registryService.getAllApplicationInterfaceNames(gatewayId); } /** @@ -1045,11 +786,7 @@ public Map getAllApplicationInterfaceNames(String gatewayId) @Override public List getAllApplicationInterfaces(String gatewayId) throws RegistryServiceException, TException { - try { - return registryService.getAllApplicationInterfaces(gatewayId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving application interfaces"); - } + return registryService.getAllApplicationInterfaces(gatewayId); } /** @@ -1062,11 +799,7 @@ public List getAllApplicationInterfaces(String @Override public List getApplicationInputs(String appInterfaceId) throws RegistryServiceException, TException { - try { - return registryService.getApplicationInputs(appInterfaceId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving application inputs"); - } + return registryService.getApplicationInputs(appInterfaceId); } /** @@ -1079,11 +812,7 @@ public List getApplicationInputs(String appInterfaceId) @Override public List getApplicationOutputs(String appInterfaceId) throws RegistryServiceException, TException { - try { - return registryService.getApplicationOutputs(appInterfaceId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving application outputs"); - } + return registryService.getApplicationOutputs(appInterfaceId); } /** @@ -1097,11 +826,7 @@ public List getApplicationOutputs(String appInterfaceId) @Override public Map getAvailableAppInterfaceComputeResources(String appInterfaceId) throws RegistryServiceException, TException { - try { - return registryService.getAvailableAppInterfaceComputeResources(appInterfaceId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving available compute resources"); - } + return registryService.getAvailableAppInterfaceComputeResources(appInterfaceId); } /** @@ -1114,11 +839,7 @@ public Map getAvailableAppInterfaceComputeResources(String appIn @Override public ComputeResourceDescription getComputeResource(String computeResourceId) throws RegistryServiceException, TException { - try { - return registryService.getComputeResource(computeResourceId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving compute resource"); - } + return registryService.getComputeResource(computeResourceId); } /** @@ -1129,11 +850,7 @@ public ComputeResourceDescription getComputeResource(String computeResourceId) */ @Override public Map getAllComputeResourceNames() throws RegistryServiceException, TException { - try { - return registryService.getAllComputeResourceNames(); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving compute resource"); - } + return registryService.getAllComputeResourceNames(); } /** @@ -1145,11 +862,7 @@ public Map getAllComputeResourceNames() throws RegistryServiceEx */ @Override public boolean deleteComputeResource(String computeResourceId) throws RegistryServiceException, TException { - try { - return registryService.deleteComputeResource(computeResourceId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while deleting compute resource"); - } + return registryService.deleteComputeResource(computeResourceId); } /** @@ -1162,11 +875,7 @@ public boolean deleteComputeResource(String computeResourceId) throws RegistrySe @Override public StorageResourceDescription getStorageResource(String storageResourceId) throws RegistryServiceException, TException { - try { - return registryService.getStorageResource(storageResourceId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving storage resource"); - } + return registryService.getStorageResource(storageResourceId); } /** @@ -1177,11 +886,7 @@ public StorageResourceDescription getStorageResource(String storageResourceId) */ @Override public Map getAllStorageResourceNames() throws RegistryServiceException, TException { - try { - return registryService.getAllStorageResourceNames(); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving storage resource"); - } + return registryService.getAllStorageResourceNames(); } /** @@ -1193,11 +898,7 @@ public Map getAllStorageResourceNames() throws RegistryServiceEx */ @Override public boolean deleteStorageResource(String storageResourceId) throws RegistryServiceException, TException { - try { - return registryService.deleteStorageResource(storageResourceId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while deleting storage resource"); - } + return registryService.deleteStorageResource(storageResourceId); } /** @@ -1207,11 +908,7 @@ public boolean deleteStorageResource(String storageResourceId) throws RegistrySe */ @Override public LOCALSubmission getLocalJobSubmission(String jobSubmissionId) throws RegistryServiceException, TException { - try { - return registryService.getLocalJobSubmission(jobSubmissionId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving local job submission interface"); - } + return registryService.getLocalJobSubmission(jobSubmissionId); } /** @@ -1221,11 +918,7 @@ public LOCALSubmission getLocalJobSubmission(String jobSubmissionId) throws Regi */ @Override public SSHJobSubmission getSSHJobSubmission(String jobSubmissionId) throws RegistryServiceException, TException { - try { - return registryService.getSSHJobSubmission(jobSubmissionId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving SSH job submission interface"); - } + return registryService.getSSHJobSubmission(jobSubmissionId); } /** @@ -1243,11 +936,7 @@ public SSHJobSubmission getSSHJobSubmission(String jobSubmissionId) throws Regis @Override public UnicoreJobSubmission getUnicoreJobSubmission(String jobSubmissionId) throws RegistryServiceException, TException { - try { - return registryService.getUnicoreJobSubmission(jobSubmissionId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving Unicore job submission interface"); - } + return registryService.getUnicoreJobSubmission(jobSubmissionId); } /** @@ -1263,11 +952,7 @@ public UnicoreJobSubmission getUnicoreJobSubmission(String jobSubmissionId) @Override public CloudJobSubmission getCloudJobSubmission(String jobSubmissionId) throws RegistryServiceException, TException { - try { - return registryService.getCloudJobSubmission(jobSubmissionId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving Cloud job submission interface"); - } + return registryService.getCloudJobSubmission(jobSubmissionId); } /** @@ -1278,11 +963,7 @@ public CloudJobSubmission getCloudJobSubmission(String jobSubmissionId) */ @Override public LOCALDataMovement getLocalDataMovement(String dataMovementId) throws RegistryServiceException, TException { - try { - return registryService.getLocalDataMovement(dataMovementId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving local data movement interface"); - } + return registryService.getLocalDataMovement(dataMovementId); } /** @@ -1293,11 +974,7 @@ public LOCALDataMovement getLocalDataMovement(String dataMovementId) throws Regi */ @Override public SCPDataMovement getSCPDataMovement(String dataMovementId) throws RegistryServiceException, TException { - try { - return registryService.getSCPDataMovement(dataMovementId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving SCP data movement interface"); - } + return registryService.getSCPDataMovement(dataMovementId); } /** @@ -1309,11 +986,7 @@ public SCPDataMovement getSCPDataMovement(String dataMovementId) throws Registry @Override public UnicoreDataMovement getUnicoreDataMovement(String dataMovementId) throws RegistryServiceException, TException { - try { - return registryService.getUnicoreDataMovement(dataMovementId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving UNICORE data movement interface"); - } + return registryService.getUnicoreDataMovement(dataMovementId); } /** @@ -1325,11 +998,7 @@ public UnicoreDataMovement getUnicoreDataMovement(String dataMovementId) @Override public GridFTPDataMovement getGridFTPDataMovement(String dataMovementId) throws RegistryServiceException, TException { - try { - return registryService.getGridFTPDataMovement(dataMovementId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving GridFTP data movement interface"); - } + return registryService.getGridFTPDataMovement(dataMovementId); } /** @@ -1397,30 +1066,18 @@ public boolean changeDataMovementPriorities(Map dataMovementPri @Override public boolean deleteJobSubmissionInterface(String computeResourceId, String jobSubmissionInterfaceId) throws RegistryServiceException, TException { - try { - return registryService.deleteJobSubmissionInterface(computeResourceId, jobSubmissionInterfaceId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while deleting job submission interface"); - } + return registryService.deleteJobSubmissionInterface(computeResourceId, jobSubmissionInterfaceId); } @Override public ResourceJobManager getResourceJobManager(String resourceJobManagerId) throws RegistryServiceException, TException { - try { - return registryService.getResourceJobManager(resourceJobManagerId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving resource job manager"); - } + return registryService.getResourceJobManager(resourceJobManagerId); } @Override public boolean deleteResourceJobManager(String resourceJobManagerId) throws RegistryServiceException, TException { - try { - return registryService.deleteResourceJobManager(resourceJobManagerId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while deleting resource job manager"); - } + return registryService.deleteResourceJobManager(resourceJobManagerId); } /** @@ -1434,11 +1091,7 @@ public boolean deleteResourceJobManager(String resourceJobManagerId) throws Regi @Override public boolean deleteBatchQueue(String computeResourceId, String queueName) throws RegistryServiceException, TException { - try { - return registryService.deleteBatchQueue(computeResourceId, queueName); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while deleting batch queue"); - } + return registryService.deleteBatchQueue(computeResourceId, queueName); } /** @@ -1451,11 +1104,7 @@ public boolean deleteBatchQueue(String computeResourceId, String queueName) @Override public GatewayResourceProfile getGatewayResourceProfile(String gatewayID) throws RegistryServiceException, TException { - try { - return registryService.getGatewayResourceProfile(gatewayID); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving gateway resource profile"); - } + return registryService.getGatewayResourceProfile(gatewayID); } /** @@ -1467,11 +1116,7 @@ public GatewayResourceProfile getGatewayResourceProfile(String gatewayID) */ @Override public boolean deleteGatewayResourceProfile(String gatewayID) throws RegistryServiceException, TException { - try { - return registryService.deleteGatewayResourceProfile(gatewayID); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while removing gateway resource profile"); - } + return registryService.deleteGatewayResourceProfile(gatewayID); } /** @@ -1485,11 +1130,7 @@ public boolean deleteGatewayResourceProfile(String gatewayID) throws RegistrySer @Override public ComputeResourcePreference getGatewayComputeResourcePreference(String gatewayID, String computeResourceId) throws RegistryServiceException, TException { - try { - return registryService.getGatewayComputeResourcePreference(gatewayID, computeResourceId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while reading gateway compute resource preference"); - } + return registryService.getGatewayComputeResourcePreference(gatewayID, computeResourceId); } /** @@ -1503,11 +1144,7 @@ public ComputeResourcePreference getGatewayComputeResourcePreference(String gate @Override public StoragePreference getGatewayStoragePreference(String gatewayID, String storageId) throws RegistryServiceException, TException { - try { - return registryService.getGatewayStoragePreference(gatewayID, storageId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while reading gateway data storage preference"); - } + return registryService.getGatewayStoragePreference(gatewayID, storageId); } /** @@ -1520,11 +1157,7 @@ public StoragePreference getGatewayStoragePreference(String gatewayID, String st @Override public List getAllGatewayComputeResourcePreferences(String gatewayID) throws RegistryServiceException, TException { - try { - return registryService.getAllGatewayComputeResourcePreferences(gatewayID); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while reading gateway compute resource preferences"); - } + return registryService.getAllGatewayComputeResourcePreferences(gatewayID); } /** @@ -1537,11 +1170,7 @@ public List getAllGatewayComputeResourcePreferences(S @Override public List getAllGatewayStoragePreferences(String gatewayID) throws RegistryServiceException, TException { - try { - return registryService.getAllGatewayStoragePreferences(gatewayID); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while reading gateway data storage preferences"); - } + return registryService.getAllGatewayStoragePreferences(gatewayID); } /** @@ -1552,11 +1181,7 @@ public List getAllGatewayStoragePreferences(String gatewayID) */ @Override public List getAllGatewayResourceProfiles() throws RegistryServiceException, TException { - try { - return registryService.getAllGatewayResourceProfiles(); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while reading retrieving all gateway profiles"); - } + return registryService.getAllGatewayResourceProfiles(); } /** @@ -1570,11 +1195,7 @@ public List getAllGatewayResourceProfiles() throws Regis @Override public boolean deleteGatewayComputeResourcePreference(String gatewayID, String computeResourceId) throws RegistryServiceException, TException { - try { - return registryService.deleteGatewayComputeResourcePreference(gatewayID, computeResourceId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while updating gateway compute resource preference"); - } + return registryService.deleteGatewayComputeResourcePreference(gatewayID, computeResourceId); } /** @@ -1588,212 +1209,125 @@ public boolean deleteGatewayComputeResourcePreference(String gatewayID, String c @Override public boolean deleteGatewayStoragePreference(String gatewayID, String storageId) throws RegistryServiceException, TException { - try { - return registryService.deleteGatewayStoragePreference(gatewayID, storageId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while updating gateway data storage preference"); - } + return registryService.deleteGatewayStoragePreference(gatewayID, storageId); } @Override public DataProductModel getDataProduct(String productUri) throws RegistryServiceException, TException { - try { - return registryService.getDataProduct(productUri); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error in retreiving the data product " + productUri); - } + return registryService.getDataProduct(productUri); } @Override public DataProductModel getParentDataProduct(String productUri) throws RegistryServiceException, TException { - try { - return registryService.getParentDataProduct(productUri); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error in retreiving the parent data product for " + productUri); - } + return registryService.getParentDataProduct(productUri); } @Override public List getChildDataProducts(String productUri) throws RegistryServiceException, TException { - try { - return registryService.getChildDataProducts(productUri); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error in retreiving the child products for " + productUri); - } + return registryService.getChildDataProducts(productUri); } @Override public List searchDataProductsByName( String gatewayId, String userId, String productName, int limit, int offset) throws RegistryServiceException, TException { - try { - return registryService.searchDataProductsByName(gatewayId, userId, productName, limit, offset); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error in searching the data products for name " + productName); - } + return registryService.searchDataProductsByName(gatewayId, userId, productName, limit, offset); } @Override public String createGroupResourceProfile(GroupResourceProfile groupResourceProfile) throws RegistryServiceException, TException { - try { - return registryService.createGroupResourceProfile(groupResourceProfile); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while creating group resource profile"); - } + return registryService.createGroupResourceProfile(groupResourceProfile); } @Override public void updateGroupResourceProfile(GroupResourceProfile groupResourceProfile) throws RegistryServiceException, TException { - try { - registryService.updateGroupResourceProfile(groupResourceProfile); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while updating group resource profile"); - } + registryService.updateGroupResourceProfile(groupResourceProfile); } @Override public GroupResourceProfile getGroupResourceProfile(String groupResourceProfileId) throws RegistryServiceException, TException { - try { - return registryService.getGroupResourceProfile(groupResourceProfileId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving group resource profile"); - } + return registryService.getGroupResourceProfile(groupResourceProfileId); } @Override public boolean isGroupResourceProfileExists(String groupResourceProfileId) throws RegistryServiceException, TException { - try { - return registryService.isGroupResourceProfileExists(groupResourceProfileId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving group resource profile"); - } + return registryService.isGroupResourceProfileExists(groupResourceProfileId); } @Override public boolean removeGroupResourceProfile(String groupResourceProfileId) throws RegistryServiceException, TException { - try { - return registryService.removeGroupResourceProfile(groupResourceProfileId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while removing group resource profile"); - } + return registryService.removeGroupResourceProfile(groupResourceProfileId); } @Override public List getGroupResourceList(String gatewayId, List accessibleGroupResProfileIds) throws RegistryServiceException, TException { - try { - return registryService.getGroupResourceList(gatewayId, accessibleGroupResProfileIds); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving group resource list"); - } + return registryService.getGroupResourceList(gatewayId, accessibleGroupResProfileIds); } @Override public boolean removeGroupComputePrefs(String computeResourceId, String groupResourceProfileId) throws RegistryServiceException, TException { - try { - return registryService.removeGroupComputePrefs(computeResourceId, groupResourceProfileId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while removing group compute preference"); - } + return registryService.removeGroupComputePrefs(computeResourceId, groupResourceProfileId); } @Override public boolean removeGroupComputeResourcePolicy(String resourcePolicyId) throws RegistryServiceException, TException { - try { - return registryService.removeGroupComputeResourcePolicy(resourcePolicyId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while removing group compute resource policy"); - } + return registryService.removeGroupComputeResourcePolicy(resourcePolicyId); } @Override public boolean removeGroupBatchQueueResourcePolicy(String resourcePolicyId) throws RegistryServiceException, TException { - try { - return registryService.removeGroupBatchQueueResourcePolicy(resourcePolicyId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while removing group batch queue resource policy"); - } + return registryService.removeGroupBatchQueueResourcePolicy(resourcePolicyId); } @Override public GroupComputeResourcePreference getGroupComputeResourcePreference( String computeResourceId, String groupResourceProfileId) throws RegistryServiceException, TException { - try { - return registryService.getGroupComputeResourcePreference(computeResourceId, groupResourceProfileId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving group compute resource preference"); - } + return registryService.getGroupComputeResourcePreference(computeResourceId, groupResourceProfileId); } @Override public boolean isGroupComputeResourcePreferenceExists(String computeResourceId, String groupResourceProfileId) throws RegistryServiceException, TException { - try { - return registryService.isGroupComputeResourcePreferenceExists(computeResourceId, groupResourceProfileId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving group compute resource preference"); - } + return registryService.isGroupComputeResourcePreferenceExists(computeResourceId, groupResourceProfileId); } @Override public ComputeResourcePolicy getGroupComputeResourcePolicy(String resourcePolicyId) throws RegistryServiceException, TException { - try { - return registryService.getGroupComputeResourcePolicy(resourcePolicyId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving group compute resource policy"); - } + return registryService.getGroupComputeResourcePolicy(resourcePolicyId); } @Override public BatchQueueResourcePolicy getBatchQueueResourcePolicy(String resourcePolicyId) throws RegistryServiceException, TException { - try { - return registryService.getBatchQueueResourcePolicy(resourcePolicyId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving Batch Queue resource policy"); - } + return registryService.getBatchQueueResourcePolicy(resourcePolicyId); } @Override public List getGroupComputeResourcePrefList(String groupResourceProfileId) throws RegistryServiceException, TException { - try { - return registryService.getGroupComputeResourcePrefList(groupResourceProfileId); - } catch (Throwable e) { - throw convertToRegistryServiceException( - e, "Error while retrieving retrieving Group Compute Resource Preference list"); - } + return registryService.getGroupComputeResourcePrefList(groupResourceProfileId); } @Override public List getGroupBatchQueueResourcePolicyList(String groupResourceProfileId) throws RegistryServiceException, TException { - try { - return registryService.getGroupBatchQueueResourcePolicyList(groupResourceProfileId); - } catch (Throwable e) { - throw convertToRegistryServiceException( - e, "Error while retrieving retrieving Group Batch Queue Resource policy list"); - } + return registryService.getGroupBatchQueueResourcePolicyList(groupResourceProfileId); } @Override public List getGroupComputeResourcePolicyList(String groupResourceProfileId) throws RegistryServiceException, TException { - try { - return registryService.getGroupComputeResourcePolicyList(groupResourceProfileId); - } catch (Throwable e) { - throw convertToRegistryServiceException( - e, "Error while retrieving retrieving Group Compute Resource policy list"); - } + return registryService.getGroupComputeResourcePolicyList(groupResourceProfileId); } @Override @@ -1835,11 +1369,7 @@ public String registerDataProduct(DataProductModel dataProductModel) throws Regi public boolean updateGatewayStoragePreference( String gatewayID, String storageId, StoragePreference storagePreference) throws RegistryServiceException, TException { - try { - return registryService.updateGatewayStoragePreference(gatewayID, storageId, storagePreference); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while updating gateway data storage preference"); - } + return registryService.updateGatewayStoragePreference(gatewayID, storageId, storagePreference); } /** @@ -1855,12 +1385,8 @@ public boolean updateGatewayStoragePreference( public boolean updateGatewayComputeResourcePreference( String gatewayID, String computeResourceId, ComputeResourcePreference computeResourcePreference) throws RegistryServiceException, TException { - try { - return registryService.updateGatewayComputeResourcePreference( - gatewayID, computeResourceId, computeResourcePreference); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while updating gateway compute resource preference"); - } + return registryService.updateGatewayComputeResourcePreference( + gatewayID, computeResourceId, computeResourcePreference); } /** @@ -1877,11 +1403,7 @@ public boolean updateGatewayComputeResourcePreference( public boolean addGatewayStoragePreference( String gatewayID, String storageResourceId, StoragePreference dataStoragePreference) throws RegistryServiceException, TException { - try { - return registryService.addGatewayStoragePreference(gatewayID, storageResourceId, dataStoragePreference); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while registering gateway resource profile preference"); - } + return registryService.addGatewayStoragePreference(gatewayID, storageResourceId, dataStoragePreference); } /** @@ -1898,12 +1420,8 @@ public boolean addGatewayStoragePreference( public boolean addGatewayComputeResourcePreference( String gatewayID, String computeResourceId, ComputeResourcePreference computeResourcePreference) throws RegistryServiceException, TException { - try { - return registryService.addGatewayComputeResourcePreference( + return registryService.addGatewayComputeResourcePreference( gatewayID, computeResourceId, computeResourcePreference); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while registering gateway resource profile preference"); - } } /** @@ -1917,11 +1435,7 @@ public boolean addGatewayComputeResourcePreference( @Override public boolean updateGatewayResourceProfile(String gatewayID, GatewayResourceProfile gatewayResourceProfile) throws RegistryServiceException, TException { - try { - return registryService.updateGatewayResourceProfile(gatewayID, gatewayResourceProfile); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while updating gateway resource profile"); - } + return registryService.updateGatewayResourceProfile(gatewayID, gatewayResourceProfile); } /** @@ -1936,31 +1450,19 @@ public boolean updateGatewayResourceProfile(String gatewayID, GatewayResourcePro @Override public String registerGatewayResourceProfile(GatewayResourceProfile gatewayResourceProfile) throws RegistryServiceException, TException { - try { - return registryService.registerGatewayResourceProfile(gatewayResourceProfile); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while registering gateway resource profile"); - } + return registryService.registerGatewayResourceProfile(gatewayResourceProfile); } @Override public boolean updateResourceJobManager(String resourceJobManagerId, ResourceJobManager updatedResourceJobManager) throws RegistryServiceException, TException { - try { - return registryService.updateResourceJobManager(resourceJobManagerId, updatedResourceJobManager); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while updating resource job manager"); - } + return registryService.updateResourceJobManager(resourceJobManagerId, updatedResourceJobManager); } @Override public String registerResourceJobManager(ResourceJobManager resourceJobManager) throws RegistryServiceException, TException { - try { - return registryService.registerResourceJobManager(resourceJobManager); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while adding resource job manager"); - } + return registryService.registerResourceJobManager(resourceJobManager); } /** @@ -1974,11 +1476,7 @@ public String registerResourceJobManager(ResourceJobManager resourceJobManager) @Override public boolean deleteDataMovementInterface(String resourceId, String dataMovementInterfaceId, DMType dmType) throws RegistryServiceException, TException { - try { - return registryService.deleteDataMovementInterface(resourceId, dataMovementInterfaceId, dmType); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while deleting data movement interface"); - } + return registryService.deleteDataMovementInterface(resourceId, dataMovementInterfaceId, dmType); } /** @@ -2013,13 +1511,8 @@ public boolean updateGridFTPDataMovementDetails( public String addGridFTPDataMovementDetails( String computeResourceId, DMType dmType, int priorityOrder, GridFTPDataMovement gridFTPDataMovement) throws RegistryServiceException, TException { - try { - return registryService.addGridFTPDataMovementDetails( + return registryService.addGridFTPDataMovementDetails( computeResourceId, dmType, priorityOrder, gridFTPDataMovement); - } catch (Throwable e) { - throw convertToRegistryServiceException( - e, "Error while adding data movement interface to resource compute resource"); - } } /** @@ -2054,13 +1547,8 @@ public boolean updateUnicoreDataMovementDetails( public String addUnicoreDataMovementDetails( String resourceId, DMType dmType, int priorityOrder, UnicoreDataMovement unicoreDataMovement) throws RegistryServiceException, TException { - try { - return registryService.addUnicoreDataMovementDetails( + return registryService.addUnicoreDataMovementDetails( resourceId, dmType, priorityOrder, unicoreDataMovement); - } catch (Throwable e) { - throw convertToRegistryServiceException( - e, "Error while adding data movement interface to resource compute resource"); - } } /** @@ -2075,11 +1563,7 @@ public String addUnicoreDataMovementDetails( @Override public boolean updateSCPDataMovementDetails(String dataMovementInterfaceId, SCPDataMovement scpDataMovement) throws RegistryServiceException, TException { - try { - return registryService.updateSCPDataMovementDetails(dataMovementInterfaceId, scpDataMovement); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while updating SCP data movement"); - } + return registryService.updateSCPDataMovementDetails(dataMovementInterfaceId, scpDataMovement); } /** @@ -2098,12 +1582,7 @@ public boolean updateSCPDataMovementDetails(String dataMovementInterfaceId, SCPD public String addSCPDataMovementDetails( String resourceId, DMType dmType, int priorityOrder, SCPDataMovement scpDataMovement) throws RegistryServiceException, TException { - try { - return registryService.addSCPDataMovementDetails(resourceId, dmType, priorityOrder, scpDataMovement); - } catch (Throwable e) { - throw convertToRegistryServiceException( - e, "Error while adding data movement interface to resource compute resource"); - } + return registryService.addSCPDataMovementDetails(resourceId, dmType, priorityOrder, scpDataMovement); } /** @@ -2117,11 +1596,7 @@ public String addSCPDataMovementDetails( @Override public boolean updateLocalDataMovementDetails(String dataMovementInterfaceId, LOCALDataMovement localDataMovement) throws RegistryServiceException, TException { - try { - return registryService.updateLocalDataMovementDetails(dataMovementInterfaceId, localDataMovement); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while updating local data movement interface"); - } + return registryService.updateLocalDataMovementDetails(dataMovementInterfaceId, localDataMovement); } /** @@ -2140,12 +1615,8 @@ public boolean updateLocalDataMovementDetails(String dataMovementInterfaceId, LO public String addLocalDataMovementDetails( String resourceId, DMType dataMoveType, int priorityOrder, LOCALDataMovement localDataMovement) throws RegistryServiceException, TException { - try { - return registryService.addLocalDataMovementDetails( + return registryService.addLocalDataMovementDetails( resourceId, dataMoveType, priorityOrder, localDataMovement); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while adding data movement interface to resource"); - } } /** @@ -2174,11 +1645,7 @@ public boolean updateUnicoreJobSubmissionDetails( @Override public boolean updateCloudJobSubmissionDetails(String jobSubmissionInterfaceId, CloudJobSubmission sshJobSubmission) throws RegistryServiceException, TException { - try { - return registryService.updateCloudJobSubmissionDetails(jobSubmissionInterfaceId, sshJobSubmission); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while updating Cloud job submission"); - } + return registryService.updateCloudJobSubmissionDetails(jobSubmissionInterfaceId, sshJobSubmission); } /** @@ -2192,11 +1659,7 @@ public boolean updateCloudJobSubmissionDetails(String jobSubmissionInterfaceId, @Override public boolean updateSSHJobSubmissionDetails(String jobSubmissionInterfaceId, SSHJobSubmission sshJobSubmission) throws RegistryServiceException, TException { - try { - return registryService.updateSSHJobSubmissionDetails(jobSubmissionInterfaceId, sshJobSubmission); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while updating SSH job submission"); - } + return registryService.updateSSHJobSubmissionDetails(jobSubmissionInterfaceId, sshJobSubmission); } /** @@ -2226,12 +1689,7 @@ public boolean updateSSHJobSubmissionDetails(String jobSubmissionInterfaceId, SS public String addCloudJobSubmissionDetails( String computeResourceId, int priorityOrder, CloudJobSubmission cloudSubmission) throws RegistryServiceException, TException { - try { - return registryService.addCloudJobSubmissionDetails(computeResourceId, priorityOrder, cloudSubmission); - } catch (Throwable e) { - throw convertToRegistryServiceException( - e, "Error while adding job submission interface to resource compute resource"); - } + return registryService.addCloudJobSubmissionDetails(computeResourceId, priorityOrder, cloudSubmission); } /** @@ -2248,13 +1706,8 @@ public String addCloudJobSubmissionDetails( public String addUNICOREJobSubmissionDetails( String computeResourceId, int priorityOrder, UnicoreJobSubmission unicoreJobSubmission) throws RegistryServiceException, TException { - try { - return registryService.addUNICOREJobSubmissionDetails( + return registryService.addUNICOREJobSubmissionDetails( computeResourceId, priorityOrder, unicoreJobSubmission); - } catch (Throwable e) { - throw convertToRegistryServiceException( - e, "Error while adding job submission interface to resource compute resource"); - } } /** @@ -2271,12 +1724,7 @@ public String addUNICOREJobSubmissionDetails( public String addSSHForkJobSubmissionDetails( String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) throws RegistryServiceException, TException { - try { - return registryService.addSSHForkJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); - } catch (Throwable e) { - throw convertToRegistryServiceException( - e, "Error while adding job submission interface to resource compute resource"); - } + return registryService.addSSHForkJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); } /** @@ -2293,12 +1741,7 @@ public String addSSHForkJobSubmissionDetails( public String addSSHJobSubmissionDetails( String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) throws RegistryServiceException, TException { - try { - return registryService.addSSHJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); - } catch (Throwable e) { - throw convertToRegistryServiceException( - e, "Error while adding job submission interface to resource compute resource"); - } + return registryService.addSSHJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); } /** @@ -2312,11 +1755,7 @@ public String addSSHJobSubmissionDetails( @Override public boolean updateLocalSubmissionDetails(String jobSubmissionInterfaceId, LOCALSubmission localSubmission) throws RegistryServiceException, TException { - try { - return registryService.updateLocalSubmissionDetails(jobSubmissionInterfaceId, localSubmission); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while updating local job submission"); - } + return registryService.updateLocalSubmissionDetails(jobSubmissionInterfaceId, localSubmission); } /** @@ -2333,12 +1772,7 @@ public boolean updateLocalSubmissionDetails(String jobSubmissionInterfaceId, LOC public String addLocalSubmissionDetails( String computeResourceId, int priorityOrder, LOCALSubmission localSubmission) throws RegistryServiceException, TException { - try { - return registryService.addLocalSubmissionDetails(computeResourceId, priorityOrder, localSubmission); - } catch (Throwable e) { - throw convertToRegistryServiceException( - e, "Error while adding job submission interface to resource compute resource"); - } + return registryService.addLocalSubmissionDetails(computeResourceId, priorityOrder, localSubmission); } /** @@ -2353,11 +1787,7 @@ public String addLocalSubmissionDetails( public boolean updateStorageResource( String storageResourceId, StorageResourceDescription storageResourceDescription) throws RegistryServiceException, TException { - try { - return registryService.updateStorageResource(storageResourceId, storageResourceDescription); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while updating storage resource"); - } + return registryService.updateStorageResource(storageResourceId, storageResourceDescription); } /** @@ -2370,11 +1800,7 @@ public boolean updateStorageResource( @Override public String registerStorageResource(StorageResourceDescription storageResourceDescription) throws RegistryServiceException, TException { - try { - return registryService.registerStorageResource(storageResourceDescription); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while saving storage resource"); - } + return registryService.registerStorageResource(storageResourceDescription); } /** @@ -2389,11 +1815,7 @@ public String registerStorageResource(StorageResourceDescription storageResource public boolean updateComputeResource( String computeResourceId, ComputeResourceDescription computeResourceDescription) throws RegistryServiceException, TException { - try { - return registryService.updateComputeResource(computeResourceId, computeResourceDescription); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while updating compute resource"); - } + return registryService.updateComputeResource(computeResourceId, computeResourceDescription); } /** @@ -2406,11 +1828,7 @@ public boolean updateComputeResource( @Override public String registerComputeResource(ComputeResourceDescription computeResourceDescription) throws RegistryServiceException, TException { - try { - return registryService.registerComputeResource(computeResourceDescription); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while saving compute resource"); - } + return registryService.registerComputeResource(computeResourceDescription); } /** @@ -2425,11 +1843,7 @@ public String registerComputeResource(ComputeResourceDescription computeResource public boolean updateApplicationInterface( String appInterfaceId, ApplicationInterfaceDescription applicationInterface) throws RegistryServiceException, TException { - try { - return registryService.updateApplicationInterface(appInterfaceId, applicationInterface); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while updating application interface"); - } + return registryService.updateApplicationInterface(appInterfaceId, applicationInterface); } /** @@ -2443,11 +1857,7 @@ public boolean updateApplicationInterface( @Override public String registerApplicationInterface(String gatewayId, ApplicationInterfaceDescription applicationInterface) throws RegistryServiceException, TException { - try { - return registryService.registerApplicationInterface(gatewayId, applicationInterface); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while adding application interface"); - } + return registryService.registerApplicationInterface(gatewayId, applicationInterface); } /** @@ -2462,11 +1872,7 @@ public String registerApplicationInterface(String gatewayId, ApplicationInterfac public boolean updateApplicationDeployment( String appDeploymentId, ApplicationDeploymentDescription applicationDeployment) throws RegistryServiceException, TException { - try { - return registryService.updateApplicationDeployment(appDeploymentId, applicationDeployment); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while updating application deployment"); - } + return registryService.updateApplicationDeployment(appDeploymentId, applicationDeployment); } /** @@ -2481,11 +1887,7 @@ public boolean updateApplicationDeployment( public String registerApplicationDeployment( String gatewayId, ApplicationDeploymentDescription applicationDeployment) throws RegistryServiceException, TException { - try { - return registryService.registerApplicationDeployment(gatewayId, applicationDeployment); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while adding application deployment"); - } + return registryService.registerApplicationDeployment(gatewayId, applicationDeployment); } /** @@ -2499,11 +1901,7 @@ public String registerApplicationDeployment( @Override public boolean updateApplicationModule(String appModuleId, ApplicationModule applicationModule) throws RegistryServiceException, TException { - try { - return registryService.updateApplicationModule(appModuleId, applicationModule); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while updating application module"); - } + return registryService.updateApplicationModule(appModuleId, applicationModule); } /** @@ -2518,32 +1916,20 @@ public boolean updateApplicationModule(String appModuleId, ApplicationModule app @Override public String registerApplicationModule(String gatewayId, ApplicationModule applicationModule) throws RegistryServiceException, TException { - try { - return registryService.registerApplicationModule(gatewayId, applicationModule); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while adding application module"); - } + return registryService.registerApplicationModule(gatewayId, applicationModule); } @Override public void updateResourceScheduleing( String airavataExperimentId, ComputationalResourceSchedulingModel resourceScheduling) throws RegistryServiceException, TException { - try { - registryService.updateResourceScheduleing(airavataExperimentId, resourceScheduling); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while updating scheduling info"); - } + registryService.updateResourceScheduleing(airavataExperimentId, resourceScheduling); } @Override public void updateExperimentConfiguration(String airavataExperimentId, UserConfigurationDataModel userConfiguration) throws RegistryServiceException, TException { - try { - registryService.updateExperimentConfiguration(airavataExperimentId, userConfiguration); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while updating user configuration"); - } + registryService.updateExperimentConfiguration(airavataExperimentId, userConfiguration); } /** @@ -2573,11 +1959,7 @@ public void updateExperimentConfiguration(String airavataExperimentId, UserConfi @Override public void updateExperiment(String airavataExperimentId, ExperimentModel experiment) throws RegistryServiceException, TException { - try { - registryService.updateExperiment(airavataExperimentId, experiment); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while updating experiment"); - } + registryService.updateExperiment(airavataExperimentId, experiment); } /** @@ -2627,11 +2009,7 @@ public void updateExperiment(String airavataExperimentId, ExperimentModel experi @Override public String createExperiment(String gatewayId, ExperimentModel experiment) throws RegistryServiceException, TException { - try { - return registryService.createExperiment(gatewayId, experiment); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while creating the experiment"); - } + return registryService.createExperiment(gatewayId, experiment); } /** @@ -2655,11 +2033,7 @@ public List searchExperiments( int limit, int offset) throws RegistryServiceException, TException { - try { - return registryService.searchExperiments(gatewayId, userName, accessibleExpIds, filters, limit, offset); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving experiments"); - } + return registryService.searchExperiments(gatewayId, userName, accessibleExpIds, filters, limit, offset); } /** @@ -2682,11 +2056,7 @@ public List searchProjects( int limit, int offset) throws RegistryServiceException, TException { - try { - return registryService.searchProjects(gatewayId, userName, accessibleProjIds, filters, limit, offset); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving projects"); - } + return registryService.searchProjects(gatewayId, userName, accessibleProjIds, filters, limit, offset); } /** @@ -2699,11 +2069,7 @@ public List searchProjects( */ @Override public void updateProject(String projectId, Project updatedProject) throws RegistryServiceException, TException { - try { - registryService.updateProject(projectId, updatedProject); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while updating the project"); - } + registryService.updateProject(projectId, updatedProject); } /** @@ -2715,20 +2081,12 @@ public void updateProject(String projectId, Project updatedProject) throws Regis */ @Override public String createProject(String gatewayId, Project project) throws RegistryServiceException, TException { - try { - return registryService.createProject(gatewayId, project); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while creating the project"); - } + return registryService.createProject(gatewayId, project); } @Override public boolean updateNotification(Notification notification) throws RegistryServiceException, TException { - try { - return registryService.updateNotification(notification); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while updating notification"); - } + return registryService.updateNotification(notification); } /** @@ -2739,11 +2097,7 @@ public boolean updateNotification(Notification notification) throws RegistryServ */ @Override public String createNotification(Notification notification) throws RegistryServiceException, TException { - try { - return registryService.createNotification(notification); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while creating notification"); - } + return registryService.createNotification(notification); } /** @@ -2757,11 +2111,7 @@ public String createNotification(Notification notification) throws RegistryServi */ @Override public boolean updateGateway(String gatewayId, Gateway updatedGateway) throws RegistryServiceException, TException { - try { - return registryService.updateGateway(gatewayId, updatedGateway); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while updating the gateway"); - } + return registryService.updateGateway(gatewayId, updatedGateway); } /** @@ -2773,11 +2123,7 @@ public boolean updateGateway(String gatewayId, Gateway updatedGateway) throws Re */ @Override public String addGateway(Gateway gateway) throws RegistryServiceException, DuplicateEntryException, TException { - try { - return registryService.addGateway(gateway); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while adding gateway"); - } + return registryService.addGateway(gateway); } @@ -2808,21 +2154,13 @@ private ExperimentModel getExperimentInternal(String airavataExperimentId) @Override public String registerUserResourceProfile(UserResourceProfile userResourceProfile) throws RegistryServiceException, TException { - try { - return registryService.registerUserResourceProfile(userResourceProfile); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while registering user resource profile"); - } + return registryService.registerUserResourceProfile(userResourceProfile); } @Override public boolean isUserResourceProfileExists(String userId, String gatewayId) throws RegistryServiceException, TException { - try { - return registryService.isUserResourceProfileExists(userId, gatewayId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while checking existence of user resource profile"); - } + return registryService.isUserResourceProfileExists(userId, gatewayId); } /** @@ -2834,11 +2172,7 @@ public boolean isUserResourceProfileExists(String userId, String gatewayId) @Override public UserResourceProfile getUserResourceProfile(String userId, String gatewayId) throws RegistryServiceException, TException { - try { - return registryService.getUserResourceProfile(userId, gatewayId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving user resource profile"); - } + return registryService.getUserResourceProfile(userId, gatewayId); } /** @@ -2852,11 +2186,7 @@ public UserResourceProfile getUserResourceProfile(String userId, String gatewayI @Override public boolean updateUserResourceProfile(String userId, String gatewayID, UserResourceProfile userResourceProfile) throws RegistryServiceException, TException { - try { - return registryService.updateUserResourceProfile(userId, gatewayID, userResourceProfile); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while updating gateway resource profile"); - } + return registryService.updateUserResourceProfile(userId, gatewayID, userResourceProfile); } /** @@ -2870,21 +2200,13 @@ public boolean updateUserResourceProfile(String userId, String gatewayID, UserRe @Override public boolean deleteUserResourceProfile(String userId, String gatewayID) throws RegistryServiceException, TException { - try { - return registryService.deleteUserResourceProfile(userId, gatewayID); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while removing User resource profile"); - } + return registryService.deleteUserResourceProfile(userId, gatewayID); } @Override public String addUser(UserProfile userProfile) throws RegistryServiceException, DuplicateEntryException, TException { - try { - return registryService.addUser(userProfile); - } catch (Exception ex) { - throw convertToRegistryServiceException(ex, "Error while adding user in registry"); - } + return registryService.addUser(userProfile); } /** @@ -2905,12 +2227,8 @@ public boolean addUserComputeResourcePreference( String computeResourceId, UserComputeResourcePreference userComputeResourcePreference) throws RegistryServiceException, TException { - try { - return registryService.addUserComputeResourcePreference( + return registryService.addUserComputeResourcePreference( userId, gatewayID, computeResourceId, userComputeResourcePreference); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while registering user resource profile preference"); - } } /** @@ -2925,11 +2243,7 @@ public boolean addUserComputeResourcePreference( @Override public boolean isUserComputeResourcePreferenceExists(String userId, String gatewayID, String computeResourceId) throws RegistryServiceException, TException { - try { - return registryService.isUserComputeResourcePreferenceExists(userId, gatewayID, computeResourceId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while fetching compute resource preference"); - } + return registryService.isUserComputeResourcePreferenceExists(userId, gatewayID, computeResourceId); } /** @@ -2946,12 +2260,8 @@ public boolean isUserComputeResourcePreferenceExists(String userId, String gatew public boolean addUserStoragePreference( String userId, String gatewayID, String storageResourceId, UserStoragePreference dataStoragePreference) throws RegistryServiceException, TException { - try { - return registryService.addUserStoragePreference( + return registryService.addUserStoragePreference( userId, gatewayID, storageResourceId, dataStoragePreference); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while registering user resource profile preference"); - } } /** @@ -2966,11 +2276,7 @@ public boolean addUserStoragePreference( @Override public UserComputeResourcePreference getUserComputeResourcePreference( String userId, String gatewayID, String userComputeResourceId) throws RegistryServiceException, TException { - try { - return registryService.getUserComputeResourcePreference(userId, gatewayID, userComputeResourceId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while reading user compute resource preference"); - } + return registryService.getUserComputeResourcePreference(userId, gatewayID, userComputeResourceId); } /** @@ -2985,11 +2291,7 @@ public UserComputeResourcePreference getUserComputeResourcePreference( @Override public UserStoragePreference getUserStoragePreference(String userId, String gatewayID, String storageId) throws RegistryServiceException, TException { - try { - return registryService.getUserStoragePreference(userId, gatewayID, storageId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while reading gateway data storage preference"); - } + return registryService.getUserStoragePreference(userId, gatewayID, storageId); } /** @@ -3000,11 +2302,7 @@ public UserStoragePreference getUserStoragePreference(String userId, String gate */ @Override public List getAllUserResourceProfiles() throws RegistryServiceException, TException { - try { - return registryService.getAllUserResourceProfiles(); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while reading retrieving all gateway profiles"); - } + return registryService.getAllUserResourceProfiles(); } /** @@ -3024,12 +2322,8 @@ public boolean updateUserComputeResourcePreference( String computeResourceId, UserComputeResourcePreference userComputeResourcePreference) throws RegistryServiceException, TException { - try { - return registryService.updateUserComputeResourcePreference( + return registryService.updateUserComputeResourcePreference( userId, gatewayID, computeResourceId, userComputeResourcePreference); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while updating user compute resource preference"); - } } /** @@ -3046,11 +2340,7 @@ public boolean updateUserComputeResourcePreference( public boolean updateUserStoragePreference( String userId, String gatewayID, String storageId, UserStoragePreference userStoragePreference) throws RegistryServiceException, TException { - try { - return registryService.updateUserStoragePreference(userId, gatewayID, storageId, userStoragePreference); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while updating user data storage preference"); - } + return registryService.updateUserStoragePreference(userId, gatewayID, storageId, userStoragePreference); } /** @@ -3065,11 +2355,7 @@ public boolean updateUserStoragePreference( @Override public boolean deleteUserComputeResourcePreference(String userId, String gatewayID, String computeResourceId) throws RegistryServiceException, TException { - try { - return registryService.deleteUserComputeResourcePreference(userId, gatewayID, computeResourceId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while deleting user compute resource preference"); - } + return registryService.deleteUserComputeResourcePreference(userId, gatewayID, computeResourceId); } /** @@ -3084,11 +2370,7 @@ public boolean deleteUserComputeResourcePreference(String userId, String gateway @Override public boolean deleteUserStoragePreference(String userId, String gatewayID, String storageId) throws RegistryServiceException, TException { - try { - return registryService.deleteUserStoragePreference(userId, gatewayID, storageId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while deleting user storage preference"); - } + return registryService.deleteUserStoragePreference(userId, gatewayID, storageId); } /** @@ -3097,31 +2379,19 @@ public boolean deleteUserStoragePreference(String userId, String gatewayID, Stri */ @Override public List getLatestQueueStatuses() throws RegistryServiceException, TException { - try { - return registryService.getLatestQueueStatuses(); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while reading queue status models"); - } + return registryService.getLatestQueueStatuses(); } @Override public void registerQueueStatuses(List queueStatuses) throws RegistryServiceException, TException { - try { - registryService.registerQueueStatuses(queueStatuses); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while storing queue status models"); - } + registryService.registerQueueStatuses(queueStatuses); } @Override public QueueStatusModel getQueueStatus(String hostName, String queueName) throws RegistryServiceException, TException { - try { - return registryService.getQueueStatus(hostName, queueName); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving queue status"); - } + return registryService.getQueueStatus(hostName, queueName); } /** @@ -3135,12 +2405,7 @@ public QueueStatusModel getQueueStatus(String hostName, String queueName) @Override public List getAllUserComputeResourcePreferences(String userId, String gatewayID) throws RegistryServiceException, TException { - try { - return registryService.getAllUserComputeResourcePreferences(userId, gatewayID); - } catch (Throwable e) { - throw convertToRegistryServiceException( - e, "Error while reading User Resource Profile compute resource preferences"); - } + return registryService.getAllUserComputeResourcePreferences(userId, gatewayID); } /** @@ -3154,12 +2419,7 @@ public List getAllUserComputeResourcePreferences( @Override public List getAllUserStoragePreferences(String userId, String gatewayID) throws RegistryServiceException, TException { - try { - return registryService.getAllUserStoragePreferences(userId, gatewayID); - } catch (Throwable e) { - throw convertToRegistryServiceException( - e, "Error while reading user resource Profile data storage preferences"); - } + return registryService.getAllUserStoragePreferences(userId, gatewayID); } @Override @@ -3177,171 +2437,99 @@ public void createGatewayGroups(GatewayGroups gatewayGroups) @Override public void updateGatewayGroups(GatewayGroups gatewayGroups) throws RegistryServiceException, TException { - try { - registryService.updateGatewayGroups(gatewayGroups); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while updating GatewayGroups"); - } + registryService.updateGatewayGroups(gatewayGroups); } @Override public boolean isGatewayGroupsExists(String gatewayId) throws RegistryServiceException, TException { - try { - return registryService.isGatewayGroupsExists(gatewayId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error checking existence of GatewayGroups"); - } + return registryService.isGatewayGroupsExists(gatewayId); } @Override public GatewayGroups getGatewayGroups(String gatewayId) throws RegistryServiceException, TException { - try { - return registryService.getGatewayGroups(gatewayId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving GatewayGroups"); - } + return registryService.getGatewayGroups(gatewayId); } @Override public Parser getParser(String parserId, String gatewayId) throws RegistryServiceException, TException { - try { - return registryService.getParser(parserId, gatewayId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving parser"); - } + return registryService.getParser(parserId, gatewayId); } @Override public String saveParser(Parser parser) throws RegistryServiceException, TException { - try { - return registryService.saveParser(parser); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while saving parser"); - } + return registryService.saveParser(parser); } @Override public List listAllParsers(String gatewayId) throws RegistryServiceException, TException { - try { - return registryService.listAllParsers(gatewayId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while listing parsers"); - } + return registryService.listAllParsers(gatewayId); } @Override public void removeParser(String parserId, String gatewayId) throws RegistryServiceException, TException { - try { - registryService.removeParser(parserId, gatewayId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while removing parser"); - } + registryService.removeParser(parserId, gatewayId); } @Override public ParserInput getParserInput(String parserInputId, String gatewayId) throws RegistryServiceException, TException { - try { - return registryService.getParserInput(parserInputId, gatewayId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving parser input"); - } + return registryService.getParserInput(parserInputId, gatewayId); } @Override public ParserOutput getParserOutput(String parserOutputId, String gatewayId) throws RegistryServiceException, TException { - try { - return registryService.getParserOutput(parserOutputId, gatewayId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving parser output"); - } + return registryService.getParserOutput(parserOutputId, gatewayId); } @Override public ParsingTemplate getParsingTemplate(String templateId, String gatewayId) throws RegistryServiceException, TException { - try { - return registryService.getParsingTemplate(templateId, gatewayId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving parsing template"); - } + return registryService.getParsingTemplate(templateId, gatewayId); } @Override public List getParsingTemplatesForExperiment(String experimentId, String gatewayId) throws RegistryServiceException, TException { - try { - return registryService.getParsingTemplatesForExperiment(experimentId, gatewayId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving parsing templates for experiment"); - } + return registryService.getParsingTemplatesForExperiment(experimentId, gatewayId); } @Override public String saveParsingTemplate(ParsingTemplate parsingTemplate) throws RegistryServiceException, TException { - try { - return registryService.saveParsingTemplate(parsingTemplate); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while saving parsing template"); - } + return registryService.saveParsingTemplate(parsingTemplate); } @Override public List listAllParsingTemplates(String gatewayId) throws RegistryServiceException, TException { - try { - return registryService.listAllParsingTemplates(gatewayId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while listing parsing templates"); - } + return registryService.listAllParsingTemplates(gatewayId); } @Override public void removeParsingTemplate(String templateId, String gatewayId) throws RegistryServiceException, TException { - try { - registryService.removeParsingTemplate(templateId, gatewayId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while removing parsing template"); - } + registryService.removeParsingTemplate(templateId, gatewayId); } @Override public boolean isGatewayUsageReportingAvailable(String gatewayId, String computeResourceId) throws RegistryServiceException, TException { - try { - return registryService.isGatewayUsageReportingAvailable(gatewayId, computeResourceId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while checking gateway usage reporting availability"); - } + return registryService.isGatewayUsageReportingAvailable(gatewayId, computeResourceId); } @Override public GatewayUsageReportingCommand getGatewayReportingCommand(String gatewayId, String computeResourceId) throws RegistryServiceException, TException { - try { - return registryService.getGatewayReportingCommand(gatewayId, computeResourceId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while retrieving gateway reporting command"); - } + return registryService.getGatewayReportingCommand(gatewayId, computeResourceId); } @Override public void addGatewayUsageReportingCommand(GatewayUsageReportingCommand command) throws RegistryServiceException, TException { - try { - registryService.addGatewayUsageReportingCommand(command); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while adding gateway usage reporting command"); - } + registryService.addGatewayUsageReportingCommand(command); } @Override public void removeGatewayUsageReportingCommand(String gatewayId, String computeResourceId) throws RegistryServiceException, TException { - try { - registryService.removeGatewayUsageReportingCommand(gatewayId, computeResourceId); - } catch (Throwable e) { - throw convertToRegistryServiceException(e, "Error while removing gateway usage reporting command"); - } + registryService.removeGatewayUsageReportingCommand(gatewayId, computeResourceId); } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java b/airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java index f6070b6a0e..ba88c119eb 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java @@ -33,10 +33,12 @@ import java.util.UUID; import java.util.function.BiFunction; import java.util.stream.Collectors; +import org.apache.airavata.agents.api.AgentAdaptor; import org.apache.airavata.common.utils.AiravataUtils; import org.apache.airavata.common.utils.Constants; import org.apache.airavata.common.utils.ServerSettings; import org.apache.airavata.credential.store.store.CredentialStoreException; +import org.apache.airavata.helix.core.support.adaptor.AdaptorSupportImpl; import org.apache.airavata.messaging.core.MessageContext; import org.apache.airavata.messaging.core.Publisher; import org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription; @@ -58,7 +60,9 @@ import org.apache.airavata.model.appcatalog.groupresourceprofile.GroupResourceProfile; import org.apache.airavata.model.appcatalog.parser.Parser; import org.apache.airavata.model.appcatalog.parser.ParsingTemplate; +import org.apache.airavata.model.appcatalog.storageresource.StorageDirectoryInfo; import org.apache.airavata.model.appcatalog.storageresource.StorageResourceDescription; +import org.apache.airavata.model.appcatalog.storageresource.StorageVolumeInfo; import org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference; import org.apache.airavata.model.appcatalog.userresourceprofile.UserResourceProfile; import org.apache.airavata.model.appcatalog.userresourceprofile.UserStoragePreference; @@ -109,6 +113,8 @@ import org.apache.airavata.model.error.InvalidRequestException; import org.apache.airavata.model.error.ProjectNotFoundException; import org.apache.airavata.model.error.ExperimentNotFoundException; +import org.apache.airavata.model.error.AiravataErrorType; +import org.apache.airavata.model.commons.airavata_commonsConstants; import org.apache.airavata.registry.cpi.AppCatalogException; import org.apache.airavata.registry.cpi.RegistryException; import org.apache.airavata.service.security.GatewayGroupsInitializer; @@ -128,6 +134,42 @@ public class AiravataService { private static final Logger logger = LoggerFactory.getLogger(AiravataService.class); + private record StorageInfoContext(String loginUserName, String credentialToken, org.apache.airavata.agents.api.AgentAdaptor adaptor) {} + + private boolean validateString(String name) { + boolean valid = true; + if (name == null || name.equals("") || name.trim().length() == 0) { + valid = false; + } + return valid; + } + + private AiravataClientException clientException(AiravataErrorType errorType, String parameter) { + AiravataClientException exception = new AiravataClientException(); + exception.setAiravataErrorType(errorType); + exception.setParameter(parameter); + return exception; + } + + private boolean safeIsUserResourceProfileExists(AuthzToken authzToken, String userId, String gatewayId) { + try { + return isUserResourceProfileExists(userId, gatewayId); + } catch (Throwable e) { + logger.error("Error checking if user resource profile exists", e); + return false; + } + } + + private boolean isGatewayResourceProfileExists(String gatewayId) { + try { + GatewayResourceProfile profile = getGatewayResourceProfile(gatewayId); + return profile != null; + } catch (Throwable e) { + logger.error("Error while checking if gateway resource profile exists", e); + return false; + } + } + @SuppressWarnings("unchecked") private static RuntimeException sneakyThrow(Throwable e) throws E { throw (E) e; @@ -310,7 +352,7 @@ private void initSharingRegistry() throws Exception { } } - public List getAllUsersInGateway(String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + public List getAllUsersInGateway(String gatewayId) { try { return registryService.getAllUsersInGateway(gatewayId); } catch (Throwable e) { @@ -318,8 +360,7 @@ public List getAllUsersInGateway(String gatewayId) throws InvalidRequest } } - public boolean updateGateway(String gatewayId, Gateway updatedGateway) - throws RegistryException, AppCatalogException, TException { + public boolean updateGateway(String gatewayId, Gateway updatedGateway) { try { return registryService.updateGateway(gatewayId, updatedGateway); } catch (Throwable e) { @@ -327,15 +368,17 @@ public boolean updateGateway(String gatewayId, Gateway updatedGateway) } } - public Gateway getGateway(String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + public Gateway getGateway(String gatewayId) { try { - return registryService.getGateway(gatewayId); + Gateway result = registryService.getGateway(gatewayId); + logger.debug("Airavata found the gateway with " + gatewayId); + return result; } catch (Throwable e) { throw convertException(e, "Error while getting the gateway"); } } - public boolean deleteGateway(String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + public boolean deleteGateway(String gatewayId) { try { return registryService.deleteGateway(gatewayId); } catch (Throwable e) { @@ -343,23 +386,25 @@ public boolean deleteGateway(String gatewayId) throws InvalidRequestException, A } } - public List getAllGateways() throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + public List getAllGateways() { try { + logger.debug("Airavata searching for all gateways"); return registryService.getAllGateways(); } catch (Throwable e) { throw convertException(e, "Error while getting all the gateways"); } } - public boolean isGatewayExist(String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + public boolean isGatewayExist(String gatewayId) { try { + logger.debug("Airavata verifying if the gateway with " + gatewayId + "exits"); return registryService.isGatewayExist(gatewayId); } catch (Throwable e) { throw convertException(e, "Error while getting gateway"); } } - public String createNotification(Notification notification) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + public String createNotification(Notification notification) { try { return registryService.createNotification(notification); } catch (Throwable e) { @@ -367,7 +412,7 @@ public String createNotification(Notification notification) throws InvalidReques } } - public boolean updateNotification(Notification notification) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + public boolean updateNotification(Notification notification) { try { return registryService.updateNotification(notification); } catch (Throwable e) { @@ -375,7 +420,7 @@ public boolean updateNotification(Notification notification) throws InvalidReque } } - public boolean deleteNotification(String gatewayId, String notificationId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + public boolean deleteNotification(String gatewayId, String notificationId) { try { return registryService.deleteNotification(gatewayId, notificationId); } catch (Throwable e) { @@ -383,7 +428,7 @@ public boolean deleteNotification(String gatewayId, String notificationId) throw } } - public Notification getNotification(String gatewayId, String notificationId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + public Notification getNotification(String gatewayId, String notificationId) { try { return registryService.getNotification(gatewayId, notificationId); } catch (Throwable e) { @@ -391,7 +436,7 @@ public Notification getNotification(String gatewayId, String notificationId) thr } } - public List getAllNotifications(String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + public List getAllNotifications(String gatewayId) { try { return registryService.getAllNotifications(gatewayId); } catch (Throwable e) { @@ -399,15 +444,17 @@ public List getAllNotifications(String gatewayId) throws InvalidRe } } - public String registerDataProduct(DataProductModel dataProductModel) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + public String registerDataProduct(DataProductModel dataProductModel) { try { return registryService.registerDataProduct(dataProductModel); } catch (Throwable e) { - throw convertException(e, "Error while registering data product"); + String msg = "Error in registering the data resource" + dataProductModel.getProductName() + "."; + logger.error(msg, e); + throw convertException(e, msg); } } - public DataProductModel getDataProduct(String productUri) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + public DataProductModel getDataProduct(String productUri) { try { return registryService.getDataProduct(productUri); } catch (Throwable e) { @@ -415,39 +462,46 @@ public DataProductModel getDataProduct(String productUri) throws InvalidRequestE } } - public String registerReplicaLocation(DataReplicaLocationModel replicaLocationModel) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + public String registerReplicaLocation(DataReplicaLocationModel replicaLocationModel) { try { return registryService.registerReplicaLocation(replicaLocationModel); } catch (Throwable e) { - throw convertException(e, "Error while registering replica location"); + String msg = "Error in retreiving the replica " + replicaLocationModel.getReplicaName() + "."; + logger.error(msg, e); + throw convertException(e, msg); } } - public DataProductModel getParentDataProduct(String productUri) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + public DataProductModel getParentDataProduct(String productUri) { try { return registryService.getParentDataProduct(productUri); } catch (Throwable e) { - throw convertException(e, "Error while retrieving parent data product"); + String msg = "Error in retreiving the parent data product for " + productUri + "."; + logger.error(msg, e); + throw convertException(e, msg); } } - public List getChildDataProducts(String productUri) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + public List getChildDataProducts(String productUri) { try { return registryService.getChildDataProducts(productUri); } catch (Throwable e) { - throw convertException(e, "Error while retrieving child data products"); + String msg = "Error in retreiving the child products for " + productUri + "."; + logger.error(msg, e); + throw convertException(e, msg); } } - public boolean isUserExists(String gatewayId, String userName) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + public boolean isUserExists(String gatewayId, String userName) { try { + logger.debug("Checking if the user" + userName + "exists in the gateway" + gatewayId); return registryService.isUserExists(gatewayId, userName); } catch (Throwable e) { throw convertException(e, "Error while verifying user"); } } - public Project getProject(String projectId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + public Project getProject(String projectId) { try { return registryService.getProject(projectId); } catch (Throwable e) { @@ -455,7 +509,7 @@ public Project getProject(String projectId) throws InvalidRequestException, Aira } } - public String createProject(String gatewayId, Project project) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + public String createProject(String gatewayId, Project project) { try { return registryService.createProject(gatewayId, project); } catch (Throwable e) { @@ -463,7 +517,7 @@ public String createProject(String gatewayId, Project project) throws InvalidReq } } - public void updateProject(String projectId, Project updatedProject) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + public void updateProject(String projectId, Project updatedProject) { try { registryService.updateProject(projectId, updatedProject); } catch (Throwable e) { @@ -471,7 +525,7 @@ public void updateProject(String projectId, Project updatedProject) throws Inval } } - public boolean deleteProject(String projectId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + public boolean deleteProject(String projectId) { try { return registryService.deleteProject(projectId); } catch (Throwable e) { @@ -588,15 +642,23 @@ public ExperimentStatistics getExperimentStatistics( } } - public ExperimentModel getExperiment(String airavataExperimentId) throws RegistryException { - return registryService.getExperiment(airavataExperimentId); + public ExperimentModel getExperiment(String airavataExperimentId) { + try { + return registryService.getExperiment(airavataExperimentId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving experiment"); + } } - public String createExperiment(String gatewayId, ExperimentModel experiment) throws RegistryException { - return registryService.createExperiment(gatewayId, experiment); + public String createExperiment(String gatewayId, ExperimentModel experiment) { + try { + return registryService.createExperiment(gatewayId, experiment); + } catch (Throwable e) { + throw convertException(e, "Error while creating experiment"); + } } - public ExperimentModel getExperiment(AuthzToken authzToken, String airavataExperimentId) throws TException { + public ExperimentModel getExperiment(AuthzToken authzToken, String airavataExperimentId) throws AuthorizationException { try { ExperimentModel existingExperiment = getExperiment(airavataExperimentId); if (authzToken.getClaimsMap().get(Constants.USER_NAME).equals(existingExperiment.getUserName()) @@ -613,12 +675,14 @@ public ExperimentModel getExperiment(AuthzToken authzToken, String airavataExper } else { throw new AuthorizationException("User does not have permission to access this resource"); } + } catch (AuthorizationException e) { + throw e; } catch (Throwable e) { throw convertException(e, "Error while getting the experiment"); } } - public ExperimentModel getExperimentByAdmin(AuthzToken authzToken, String airavataExperimentId) throws TException { + public ExperimentModel getExperimentByAdmin(AuthzToken authzToken, String airavataExperimentId) throws AuthorizationException { try { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); ExperimentModel existingExperiment = getExperiment(airavataExperimentId); @@ -627,12 +691,14 @@ public ExperimentModel getExperimentByAdmin(AuthzToken authzToken, String airava } else { throw new AuthorizationException("User does not have permission to access this resource"); } + } catch (AuthorizationException e) { + throw e; } catch (Throwable e) { throw convertException(e, "Error while getting experiment by admin"); } } - public void updateExperiment(AuthzToken authzToken, String airavataExperimentId, ExperimentModel experiment) throws TException { + public void updateExperiment(AuthzToken authzToken, String airavataExperimentId, ExperimentModel experiment) throws AuthorizationException { try { ExperimentModel existingExperiment = getExperiment(airavataExperimentId); String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); @@ -664,12 +730,176 @@ public void updateExperiment(AuthzToken authzToken, String airavataExperimentId, } } - public void updateExperiment(String airavataExperimentId, ExperimentModel experiment) throws RegistryException { - registryService.updateExperiment(airavataExperimentId, experiment); + public void updateExperiment(String airavataExperimentId, ExperimentModel experiment) { + try { + registryService.updateExperiment(airavataExperimentId, experiment); + } catch (Throwable e) { + throw convertException(e, "Error while updating experiment"); + } + } + + public boolean deleteExperiment(String experimentId) { + try { + return registryService.deleteExperiment(experimentId); + } catch (Throwable e) { + throw convertException(e, "Error while deleting experiment"); + } + } + + public String cloneExperimentInternal( + AuthzToken authzToken, + String existingExperimentID, + String newExperimentName, + String newExperimentProjectId, + ExperimentModel existingExperiment) + throws ExperimentNotFoundException, ProjectNotFoundException, AuthorizationException { + try { + 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 = getProjectWithAuth(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 (!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) { + try { + List applicationOutputs = getApplicationOutputs(existingExperiment.getExecutionId()); + existingExperiment.setExperimentOutputs(applicationOutputs); + } catch (Throwable e) { + logger.warn("Error getting application outputs for experiment clone: " + e.getMessage()); + } + } + if (validateString(newExperimentName)) { + existingExperiment.setExperimentName(newExperimentName); + } + existingExperiment.unsetErrors(); + existingExperiment.unsetProcesses(); + existingExperiment.unsetExperimentStatus(); + if (existingExperiment.getUserConfigurationData() != null + && existingExperiment.getUserConfigurationData().getComputationalResourceScheduling() != null + && existingExperiment + .getUserConfigurationData() + .getComputationalResourceScheduling() + .getResourceHostId() + != null) { + String compResourceId = existingExperiment + .getUserConfigurationData() + .getComputationalResourceScheduling() + .getResourceHostId(); + + try { + ComputeResourceDescription computeResource = getComputeResource(compResourceId); + if (!computeResource.isEnabled()) { + existingExperiment.getUserConfigurationData().setComputationalResourceScheduling(null); + } + } catch (Throwable e) { + logger.warn("Error getting compute resource for experiment clone: " + e.getMessage()); + } + } + logger.debug("Airavata cloned experiment with experiment id : " + existingExperimentID); + existingExperiment.setUserName(userId); + + String expId = createExperiment(gatewayId, existingExperiment); + if (ServerSettings.isEnableSharing()) { + try { + Entity entity = new Entity(); + entity.setEntityId(expId); + final String domainId = existingExperiment.getGatewayId(); + entity.setDomainId(domainId); + entity.setEntityTypeId(domainId + ":" + "EXPERIMENT"); + entity.setOwnerId(existingExperiment.getUserName() + "@" + domainId); + entity.setName(existingExperiment.getExperimentName()); + entity.setDescription(existingExperiment.getDescription()); + createEntity(entity); + shareEntityWithAdminGatewayGroups(entity); + } catch (Throwable ex) { + logger.error(ex.getMessage(), ex); + logger.error("rolling back experiment creation Exp ID : " + expId); + try { + deleteExperiment(expId); + } catch (Throwable e) { + logger.error("Error deleting experiment during rollback: " + e.getMessage()); + } + throw convertException(ex, "Error while creating entity for cloned experiment"); + } + } + + return expId; + } catch (ExperimentNotFoundException | ProjectNotFoundException | AuthorizationException e) { + throw e; + } catch (Throwable e) { + throw convertException(e, "Error while cloning experiment"); + } } - public boolean deleteExperiment(String experimentId) throws RegistryException { - return registryService.deleteExperiment(experimentId); + public void terminateExperiment(Publisher experimentPublisher, String airavataExperimentId, String gatewayId) + throws ExperimentNotFoundException { + try { + ExperimentModel existingExperiment = getExperiment(airavataExperimentId); + ExperimentStatus experimentLastStatus = getExperimentStatus(airavataExperimentId); + if (existingExperiment == null) { + logger.error( + airavataExperimentId, + "Error while cancelling experiment {}, experiment doesn't exist.", + airavataExperimentId); + throw new ExperimentNotFoundException( + "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); + } + switch (experimentLastStatus.getState()) { + case COMPLETED: + case CANCELED: + case FAILED: + case CANCELING: + logger.warn( + "Can't terminate already {} experiment", + existingExperiment + .getExperimentStatus() + .get(0) + .getState() + .name()); + break; + case CREATED: + logger.warn("Experiment termination is only allowed for launched experiments."); + break; + default: + publishExperimentCancelEvent(experimentPublisher, gatewayId, airavataExperimentId); + logger.debug("Airavata cancelled experiment with experiment id : " + airavataExperimentId); + break; + } + } catch (ExperimentNotFoundException e) { + throw e; + } catch (Throwable e) { + logger.error(airavataExperimentId, "Error while cancelling the experiment...", e); + throw convertException(e, "Error occurred"); + } } public List searchExperiments( @@ -783,122 +1013,218 @@ public List searchExperimentsWithSharing( } } - public ExperimentStatus getExperimentStatus(String airavataExperimentId) throws RegistryException { - return registryService.getExperimentStatus(airavataExperimentId); + public ExperimentStatus getExperimentStatus(String airavataExperimentId) { + try { + return registryService.getExperimentStatus(airavataExperimentId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving experiment status"); + } } - public List getExperimentOutputs(String airavataExperimentId) throws RegistryException { - return registryService.getExperimentOutputs(airavataExperimentId); + public List getExperimentOutputs(String airavataExperimentId) { + try { + return registryService.getExperimentOutputs(airavataExperimentId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving experiment outputs"); + } } - public ExperimentModel getDetailedExperimentTree(String airavataExperimentId) throws RegistryException { - return registryService.getDetailedExperimentTree(airavataExperimentId); + public ExperimentModel getDetailedExperimentTree(String airavataExperimentId) { + try { + return registryService.getDetailedExperimentTree(airavataExperimentId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving detailed experiment tree"); + } } - public List getApplicationOutputs(String appInterfaceId) throws AppCatalogException { - return registryService.getApplicationOutputs(appInterfaceId); + public List getApplicationOutputs(String appInterfaceId) { + try { + return registryService.getApplicationOutputs(appInterfaceId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving application outputs"); + } } - public ComputeResourceDescription getComputeResource(String computeResourceId) throws AppCatalogException { - return registryService.getComputeResource(computeResourceId); + public ComputeResourceDescription getComputeResource(String computeResourceId) { + try { + return registryService.getComputeResource(computeResourceId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving compute resource"); + } } - public String registerComputeResource(ComputeResourceDescription computeResourceDescription) - throws AppCatalogException { - return registryService.registerComputeResource(computeResourceDescription); + public String registerComputeResource(ComputeResourceDescription computeResourceDescription) { + try { + return registryService.registerComputeResource(computeResourceDescription); + } catch (Throwable e) { + throw convertException(e, "Error while saving compute resource"); + } } public boolean updateComputeResource( - String computeResourceId, ComputeResourceDescription computeResourceDescription) - throws AppCatalogException { - return registryService.updateComputeResource(computeResourceId, computeResourceDescription); + String computeResourceId, ComputeResourceDescription computeResourceDescription) { + try { + return registryService.updateComputeResource(computeResourceId, computeResourceDescription); + } catch (Throwable e) { + throw convertException(e, "Error while updating compute resource"); + } } - public boolean deleteComputeResource(String computeResourceId) throws AppCatalogException { - return registryService.deleteComputeResource(computeResourceId); + public boolean deleteComputeResource(String computeResourceId) { + try { + return registryService.deleteComputeResource(computeResourceId); + } catch (Throwable e) { + throw convertException(e, "Error while deleting compute resource"); + } } - public Map getAllComputeResourceNames() throws AppCatalogException { - return registryService.getAllComputeResourceNames(); + public Map getAllComputeResourceNames() { + try { + return registryService.getAllComputeResourceNames(); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving compute resource names"); + } } - public String registerStorageResource(StorageResourceDescription storageResourceDescription) - throws AppCatalogException { - return registryService.registerStorageResource(storageResourceDescription); + public String registerStorageResource(StorageResourceDescription storageResourceDescription) { + try { + return registryService.registerStorageResource(storageResourceDescription); + } catch (Throwable e) { + throw convertException(e, "Error while saving storage resource"); + } } - public StorageResourceDescription getStorageResource(String storageResourceId) throws AppCatalogException { - return registryService.getStorageResource(storageResourceId); + public StorageResourceDescription getStorageResource(String storageResourceId) { + try { + return registryService.getStorageResource(storageResourceId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving storage resource"); + } } public boolean updateStorageResource( - String storageResourceId, StorageResourceDescription storageResourceDescription) - throws AppCatalogException { - return registryService.updateStorageResource(storageResourceId, storageResourceDescription); + String storageResourceId, StorageResourceDescription storageResourceDescription) { + try { + return registryService.updateStorageResource(storageResourceId, storageResourceDescription); + } catch (Throwable e) { + throw convertException(e, "Error while updating storage resource"); + } } - public boolean deleteStorageResource(String storageResourceId) throws AppCatalogException { - return registryService.deleteStorageResource(storageResourceId); + public boolean deleteStorageResource(String storageResourceId) { + try { + return registryService.deleteStorageResource(storageResourceId); + } catch (Throwable e) { + throw convertException(e, "Error while deleting storage resource"); + } } - public Map getAllStorageResourceNames() throws AppCatalogException { - return registryService.getAllStorageResourceNames(); + public Map getAllStorageResourceNames() { + try { + return registryService.getAllStorageResourceNames(); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving storage resource names"); + } } public String registerGatewayResourceProfile(GatewayResourceProfile gatewayResourceProfile) - throws AppCatalogException { - return registryService.registerGatewayResourceProfile(gatewayResourceProfile); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.registerGatewayResourceProfile(gatewayResourceProfile); + } catch (Throwable e) { + throw convertException(e, "Error while registering gateway resource profile"); + } } - public GatewayResourceProfile getGatewayResourceProfile(String gatewayID) throws AppCatalogException { - return registryService.getGatewayResourceProfile(gatewayID); + public GatewayResourceProfile getGatewayResourceProfile(String gatewayID) { + try { + return registryService.getGatewayResourceProfile(gatewayID); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving gateway resource profile"); + } } - public boolean updateGatewayResourceProfile(String gatewayID, GatewayResourceProfile gatewayResourceProfile) - throws AppCatalogException { - return registryService.updateGatewayResourceProfile(gatewayID, gatewayResourceProfile); + public boolean updateGatewayResourceProfile(String gatewayID, GatewayResourceProfile gatewayResourceProfile) { + try { + return registryService.updateGatewayResourceProfile(gatewayID, gatewayResourceProfile); + } catch (Throwable e) { + throw convertException(e, "Error while updating gateway resource profile"); + } } - public boolean deleteGatewayResourceProfile(String gatewayID) throws AppCatalogException { - return registryService.deleteGatewayResourceProfile(gatewayID); + public boolean deleteGatewayResourceProfile(String gatewayID) { + try { + return registryService.deleteGatewayResourceProfile(gatewayID); + } catch (Throwable e) { + throw convertException(e, "Error while removing gateway resource profile"); + } } - public UserResourceProfile getUserResourceProfile(String userId, String gatewayId) throws AppCatalogException { - return registryService.getUserResourceProfile(userId, gatewayId); + public UserResourceProfile getUserResourceProfile(String userId, String gatewayId) { + try { + return registryService.getUserResourceProfile(userId, gatewayId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving user resource profile"); + } } - public boolean updateUserResourceProfile(String userId, String gatewayID, UserResourceProfile userResourceProfile) - throws AppCatalogException { - return registryService.updateUserResourceProfile(userId, gatewayID, userResourceProfile); + public boolean updateUserResourceProfile(String userId, String gatewayID, UserResourceProfile userResourceProfile) { + try { + return registryService.updateUserResourceProfile(userId, gatewayID, userResourceProfile); + } catch (Throwable e) { + throw convertException(e, "Error while updating user resource profile"); + } } - public boolean deleteUserResourceProfile(String userId, String gatewayID) throws AppCatalogException { - return registryService.deleteUserResourceProfile(userId, gatewayID); + public boolean deleteUserResourceProfile(String userId, String gatewayID) { + try { + return registryService.deleteUserResourceProfile(userId, gatewayID); + } catch (Throwable e) { + throw convertException(e, "Error while removing user resource profile"); + } } - public GroupResourceProfile getGroupResourceProfile(String groupResourceProfileId) throws AppCatalogException { - return registryService.getGroupResourceProfile(groupResourceProfileId); + public GroupResourceProfile getGroupResourceProfile(String groupResourceProfileId) { + try { + return registryService.getGroupResourceProfile(groupResourceProfileId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving group resource profile"); + } } - public void updateGroupResourceProfile(GroupResourceProfile groupResourceProfile) throws AppCatalogException { - registryService.updateGroupResourceProfile(groupResourceProfile); + public void updateGroupResourceProfile(GroupResourceProfile groupResourceProfile) { + try { + registryService.updateGroupResourceProfile(groupResourceProfile); + } catch (Throwable e) { + throw convertException(e, "Error while updating group resource profile"); + } } - public List getGroupResourceList(String gatewayId, List accessibleGroupResProfileIds) - throws AppCatalogException { - return registryService.getGroupResourceList(gatewayId, accessibleGroupResProfileIds); + public List getGroupResourceList(String gatewayId, List accessibleGroupResProfileIds) { + try { + return registryService.getGroupResourceList(gatewayId, accessibleGroupResProfileIds); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving group resource list"); + } } - public GatewayGroups getGatewayGroups(String gatewayId) throws RegistryException { - return registryService.getGatewayGroups(gatewayId); + public GatewayGroups getGatewayGroups(String gatewayId) { + try { + return registryService.getGatewayGroups(gatewayId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving gateway groups"); + } } - public boolean isGatewayGroupsExists(String gatewayId) throws RegistryException { - return registryService.isGatewayGroupsExists(gatewayId); + public boolean isGatewayGroupsExists(String gatewayId) { + try { + return registryService.isGatewayGroupsExists(gatewayId); + } catch (Throwable e) { + throw convertException(e, "Error while checking if gateway groups exist"); + } } - public void updateExperimentConfiguration(String airavataExperimentId, UserConfigurationDataModel userConfiguration) - throws TException { + public void updateExperimentConfiguration(String airavataExperimentId, UserConfigurationDataModel userConfiguration) { try { registryService.updateExperimentConfiguration(airavataExperimentId, userConfiguration); } catch (Throwable e) { @@ -907,8 +1233,7 @@ public void updateExperimentConfiguration(String airavataExperimentId, UserConfi } public void updateResourceScheduleing( - String airavataExperimentId, ComputationalResourceSchedulingModel resourceScheduling) - throws TException { + String airavataExperimentId, ComputationalResourceSchedulingModel resourceScheduling) { try { registryService.updateResourceScheduleing(airavataExperimentId, resourceScheduling); } catch (Throwable e) { @@ -917,90 +1242,258 @@ public void updateResourceScheduleing( } public String registerApplicationDeployment( - String gatewayId, ApplicationDeploymentDescription applicationDeployment) throws AppCatalogException { - return registryService.registerApplicationDeployment(gatewayId, applicationDeployment); + String gatewayId, ApplicationDeploymentDescription applicationDeployment) { + try { + return registryService.registerApplicationDeployment(gatewayId, applicationDeployment); + } catch (Throwable e) { + throw convertException(e, "Error while registering application deployment"); + } } - public ApplicationDeploymentDescription getApplicationDeployment(String appDeploymentId) - throws AppCatalogException { - return registryService.getApplicationDeployment(appDeploymentId); + public String registerApplicationDeploymentWithSharing( + AuthzToken authzToken, String gatewayId, ApplicationDeploymentDescription applicationDeployment) { + try { + String result = registerApplicationDeployment(gatewayId, applicationDeployment); + if (ServerSettings.isEnableSharing()) { + Entity entity = new Entity(); + entity.setEntityId(result); + final String domainId = gatewayId; + entity.setDomainId(domainId); + entity.setEntityTypeId(domainId + ":" + ResourceType.APPLICATION_DEPLOYMENT.name()); + String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); + entity.setOwnerId(userName + "@" + domainId); + entity.setName(result); + entity.setDescription(applicationDeployment.getAppDeploymentDescription()); + createEntity(entity); + shareEntityWithAdminGatewayGroups(entity); + } + return result; + } catch (Throwable e) { + throw convertException(e, "Error while registering application deployment"); + } } - public boolean updateApplicationDeployment( - String appDeploymentId, ApplicationDeploymentDescription applicationDeployment) throws AppCatalogException { - return registryService.updateApplicationDeployment(appDeploymentId, applicationDeployment); + public ApplicationDeploymentDescription getApplicationDeployment(String appDeploymentId) { + try { + return registryService.getApplicationDeployment(appDeploymentId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving application deployment"); + } } - public boolean deleteApplicationDeployment(String appDeploymentId) throws AppCatalogException { - return registryService.deleteApplicationDeployment(appDeploymentId); + public ApplicationDeploymentDescription getApplicationDeploymentWithAuth(AuthzToken authzToken, String appDeploymentId) + throws AuthorizationException { + try { + if (ServerSettings.isEnableSharing()) { + final boolean hasAccess = userHasAccessInternal(authzToken, appDeploymentId, ResourcePermissionType.READ); + if (!hasAccess) { + throw new AuthorizationException( + "User does not have access to application deployment " + appDeploymentId); + } + } + return getApplicationDeployment(appDeploymentId); + } catch (AuthorizationException e) { + throw e; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving application deployment"); + } } - public ApplicationInterfaceDescription getApplicationInterface(String appInterfaceId) throws AppCatalogException { - return registryService.getApplicationInterface(appInterfaceId); + public boolean updateApplicationDeployment( + String appDeploymentId, ApplicationDeploymentDescription applicationDeployment) { + try { + return registryService.updateApplicationDeployment(appDeploymentId, applicationDeployment); + } catch (Throwable e) { + throw convertException(e, "Error while updating application deployment"); + } } - public List getApplicationDeployments(String appModuleId) - throws AppCatalogException { - return registryService.getApplicationDeployments(appModuleId); + public boolean updateApplicationDeploymentWithAuth( + AuthzToken authzToken, String appDeploymentId, ApplicationDeploymentDescription applicationDeployment) + throws AuthorizationException { + try { + if (ServerSettings.isEnableSharing()) { + final boolean hasAccess = userHasAccessInternal(authzToken, appDeploymentId, ResourcePermissionType.WRITE); + if (!hasAccess) { + throw new AuthorizationException( + "User does not have WRITE access to application deployment " + appDeploymentId); + } + } + return updateApplicationDeployment(appDeploymentId, applicationDeployment); + } catch (AuthorizationException e) { + throw e; + } catch (Throwable e) { + throw convertException(e, "Error while updating application deployment"); + } } - public String registerApplicationInterface(String gatewayId, ApplicationInterfaceDescription applicationInterface) - throws AppCatalogException { - return registryService.registerApplicationInterface(gatewayId, applicationInterface); + public boolean deleteApplicationDeployment(String appDeploymentId) { + try { + return registryService.deleteApplicationDeployment(appDeploymentId); + } catch (Throwable e) { + throw convertException(e, "Error while deleting application deployment"); + } } - public boolean updateApplicationInterface( - String appInterfaceId, ApplicationInterfaceDescription applicationInterface) throws AppCatalogException { - return registryService.updateApplicationInterface(appInterfaceId, applicationInterface); + public boolean deleteApplicationDeploymentWithAuth(AuthzToken authzToken, String appDeploymentId) + throws AuthorizationException { + try { + if (ServerSettings.isEnableSharing()) { + final boolean hasAccess = userHasAccessInternal(authzToken, appDeploymentId, ResourcePermissionType.WRITE); + if (!hasAccess) { + throw new AuthorizationException( + "User does not have WRITE access to application deployment " + appDeploymentId); + } + } + return deleteApplicationDeployment(appDeploymentId); + } catch (AuthorizationException e) { + throw e; + } catch (Throwable e) { + throw convertException(e, "Error while deleting application deployment"); + } } - public boolean deleteApplicationInterface(String appInterfaceId) throws AppCatalogException { - return registryService.deleteApplicationInterface(appInterfaceId); + public ApplicationInterfaceDescription getApplicationInterface(String appInterfaceId) { + try { + return registryService.getApplicationInterface(appInterfaceId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving application interface"); + } } - public Map getAllApplicationInterfaceNames(String gatewayId) throws AppCatalogException { - return registryService.getAllApplicationInterfaceNames(gatewayId); + public List getApplicationDeployments(String appModuleId) { + try { + return registryService.getApplicationDeployments(appModuleId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving application deployments"); + } } - public List getAllApplicationInterfaces(String gatewayId) - throws AppCatalogException { - return registryService.getAllApplicationInterfaces(gatewayId); + public String registerApplicationInterface(String gatewayId, ApplicationInterfaceDescription applicationInterface) { + try { + return registryService.registerApplicationInterface(gatewayId, applicationInterface); + } catch (Throwable e) { + throw convertException(e, "Error while adding application interface"); + } } - public List getApplicationInputs(String appInterfaceId) throws AppCatalogException { - return registryService.getApplicationInputs(appInterfaceId); + public String cloneApplicationInterface(String existingAppInterfaceID, String newApplicationName, String gatewayId) + throws AiravataSystemException { + try { + ApplicationInterfaceDescription existingInterface = getApplicationInterface(existingAppInterfaceID); + if (existingInterface == null) { + logger.error( + "Provided application interface does not exist.Please provide a valid application interface id..."); + throw new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); + } + + existingInterface.setApplicationName(newApplicationName); + existingInterface.setApplicationInterfaceId(airavata_commonsConstants.DEFAULT_ID); + String interfaceId = registerApplicationInterface(gatewayId, existingInterface); + logger.debug("Airavata cloned application interface : " + existingAppInterfaceID + " for gateway id : " + + gatewayId); + return interfaceId; + } catch (AiravataSystemException e) { + throw e; + } catch (Throwable e) { + throw convertException(e, "Provided application interface does not exist.Please provide a valid application interface id..."); + } } - public String registerApplicationModule(String gatewayId, ApplicationModule applicationModule) - throws AppCatalogException { - return registryService.registerApplicationModule(gatewayId, applicationModule); + public boolean updateApplicationInterface( + String appInterfaceId, ApplicationInterfaceDescription applicationInterface) { + try { + return registryService.updateApplicationInterface(appInterfaceId, applicationInterface); + } catch (Throwable e) { + throw convertException(e, "Error while updating application interface"); + } } - public ApplicationModule getApplicationModule(String appModuleId) throws AppCatalogException { - return registryService.getApplicationModule(appModuleId); + public boolean deleteApplicationInterface(String appInterfaceId) { + try { + return registryService.deleteApplicationInterface(appInterfaceId); + } catch (Throwable e) { + throw convertException(e, "Error while deleting application interface"); + } } - public boolean updateApplicationModule(String appModuleId, ApplicationModule applicationModule) - throws AppCatalogException { - return registryService.updateApplicationModule(appModuleId, applicationModule); + public Map getAllApplicationInterfaceNames(String gatewayId) { + try { + return registryService.getAllApplicationInterfaceNames(gatewayId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving application interfaces"); + } } - public List getAllAppModules(String gatewayId) throws AppCatalogException { - return registryService.getAllAppModules(gatewayId); + public List getAllApplicationInterfaces(String gatewayId) { + try { + return registryService.getAllApplicationInterfaces(gatewayId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving application interfaces"); + } } - public boolean deleteApplicationModule(String appModuleId) throws AppCatalogException { - return registryService.deleteApplicationModule(appModuleId); + public List getApplicationInputs(String appInterfaceId) + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.getApplicationInputs(appInterfaceId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving application inputs"); + } } - public List getAccessibleAppModules( - String gatewayId, List accessibleAppIds, List accessibleComputeResourceIds) - throws AppCatalogException { - return registryService.getAccessibleAppModules(gatewayId, accessibleAppIds, accessibleComputeResourceIds); + public String registerApplicationModule(String gatewayId, ApplicationModule applicationModule) + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.registerApplicationModule(gatewayId, applicationModule); + } catch (Throwable e) { + throw convertException(e, "Error while adding application module"); + } } - /** - * Get accessible app modules with sharing registry integration + public ApplicationModule getApplicationModule(String appModuleId) + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.getApplicationModule(appModuleId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving application module"); + } + } + + public boolean updateApplicationModule(String appModuleId, ApplicationModule applicationModule) + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.updateApplicationModule(appModuleId, applicationModule); + } catch (Throwable e) { + throw convertException(e, "Error while updating application module"); + } + } + + public List getAllAppModules(String gatewayId) + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.getAllAppModules(gatewayId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving all application modules"); + } + } + + public boolean deleteApplicationModule(String appModuleId) { + try { + return registryService.deleteApplicationModule(appModuleId); + } catch (Throwable e) { + throw convertException(e, "Error while deleting application module"); + } + } + + public List getAccessibleAppModules( + String gatewayId, List accessibleAppIds, List accessibleComputeResourceIds) + throws AppCatalogException { + return registryService.getAccessibleAppModules(gatewayId, accessibleAppIds, accessibleComputeResourceIds); + } + + /** + * Get accessible app modules with sharing registry integration */ public List getAccessibleAppModulesWithSharing( AuthzToken authzToken, String gatewayId) throws Exception { @@ -1040,97 +1533,180 @@ public List getAccessibleAppModulesWithSharing( return getAccessibleAppModules(gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); } - public Map getJobStatuses(String airavataExperimentId) throws RegistryException { - return registryService.getJobStatuses(airavataExperimentId); + public Map getJobStatuses(String airavataExperimentId) { + try { + return registryService.getJobStatuses(airavataExperimentId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving job statuses"); + } } - public List getJobDetails(String airavataExperimentId) throws RegistryException { - return registryService.getJobDetails(airavataExperimentId); + public List getJobDetails(String airavataExperimentId) { + try { + return registryService.getJobDetails(airavataExperimentId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving job details"); + } } public String addLocalSubmissionDetails( - String computeResourceId, int priorityOrder, LOCALSubmission localSubmission) throws AppCatalogException { - return registryService.addLocalSubmissionDetails(computeResourceId, priorityOrder, localSubmission); + String computeResourceId, int priorityOrder, LOCALSubmission localSubmission) { + try { + return registryService.addLocalSubmissionDetails(computeResourceId, priorityOrder, localSubmission); + } catch (Throwable e) { + throw convertException(e, "Error while adding local job submission interface"); + } } public String addSSHJobSubmissionDetails( - String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) throws AppCatalogException { - return registryService.addSSHJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); + String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) { + try { + return registryService.addSSHJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); + } catch (Throwable e) { + throw convertException(e, "Error while adding SSH job submission interface"); + } } public String addSSHForkJobSubmissionDetails( - String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) throws AppCatalogException { - return registryService.addSSHForkJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); + String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) { + try { + return registryService.addSSHForkJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); + } catch (Throwable e) { + throw convertException(e, "Error while adding SSH fork job submission interface"); + } } public String addCloudJobSubmissionDetails( - String computeResourceId, int priorityOrder, CloudJobSubmission cloudJobSubmission) - throws AppCatalogException { - return registryService.addCloudJobSubmissionDetails(computeResourceId, priorityOrder, cloudJobSubmission); + String computeResourceId, int priorityOrder, CloudJobSubmission cloudJobSubmission) { + try { + return registryService.addCloudJobSubmissionDetails(computeResourceId, priorityOrder, cloudJobSubmission); + } catch (Throwable e) { + throw convertException(e, "Error while adding cloud job submission interface"); + } } public String addUNICOREJobSubmissionDetails( - String computeResourceId, int priorityOrder, UnicoreJobSubmission unicoreJobSubmission) - throws AppCatalogException { - return registryService.addUNICOREJobSubmissionDetails(computeResourceId, priorityOrder, unicoreJobSubmission); + String computeResourceId, int priorityOrder, UnicoreJobSubmission unicoreJobSubmission) { + try { + return registryService.addUNICOREJobSubmissionDetails(computeResourceId, priorityOrder, unicoreJobSubmission); + } catch (Throwable e) { + throw convertException(e, "Error while adding UNICORE job submission interface"); + } } - public boolean updateLocalSubmissionDetails(String jobSubmissionInterfaceId, LOCALSubmission localSubmission) - throws AppCatalogException { - return registryService.updateLocalSubmissionDetails(jobSubmissionInterfaceId, localSubmission); + public boolean updateLocalSubmissionDetails(String jobSubmissionInterfaceId, LOCALSubmission localSubmission) { + try { + return registryService.updateLocalSubmissionDetails(jobSubmissionInterfaceId, localSubmission); + } catch (Throwable e) { + throw convertException(e, "Error while updating local job submission interface"); + } } - public LOCALSubmission getLocalJobSubmission(String jobSubmissionId) throws AppCatalogException { - return registryService.getLocalJobSubmission(jobSubmissionId); + public LOCALSubmission getLocalJobSubmission(String jobSubmissionId) + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.getLocalJobSubmission(jobSubmissionId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving local job submission interface"); + } } - public SSHJobSubmission getSSHJobSubmission(String jobSubmissionId) throws AppCatalogException { - return registryService.getSSHJobSubmission(jobSubmissionId); + public SSHJobSubmission getSSHJobSubmission(String jobSubmissionId) { + try { + return registryService.getSSHJobSubmission(jobSubmissionId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving SSH job submission"); + } } - public CloudJobSubmission getCloudJobSubmission(String jobSubmissionId) throws AppCatalogException { - return registryService.getCloudJobSubmission(jobSubmissionId); + public CloudJobSubmission getCloudJobSubmission(String jobSubmissionId) { + try { + return registryService.getCloudJobSubmission(jobSubmissionId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving cloud job submission"); + } } - public UnicoreJobSubmission getUnicoreJobSubmission(String jobSubmissionId) throws AppCatalogException { - return registryService.getUnicoreJobSubmission(jobSubmissionId); + public UnicoreJobSubmission getUnicoreJobSubmission(String jobSubmissionId) { + try { + return registryService.getUnicoreJobSubmission(jobSubmissionId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving UNICORE job submission"); + } } public boolean updateSSHJobSubmissionDetails(String jobSubmissionInterfaceId, SSHJobSubmission sshJobSubmission) - throws AppCatalogException { - return registryService.updateSSHJobSubmissionDetails(jobSubmissionInterfaceId, sshJobSubmission); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.updateSSHJobSubmissionDetails(jobSubmissionInterfaceId, sshJobSubmission); + } catch (Throwable e) { + throw convertException(e, "Error while updating job submission interface"); + } } public boolean updateCloudJobSubmissionDetails( - String jobSubmissionInterfaceId, CloudJobSubmission cloudJobSubmission) throws AppCatalogException { - return registryService.updateCloudJobSubmissionDetails(jobSubmissionInterfaceId, cloudJobSubmission); + String jobSubmissionInterfaceId, CloudJobSubmission cloudJobSubmission) + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.updateCloudJobSubmissionDetails(jobSubmissionInterfaceId, cloudJobSubmission); + } catch (Throwable e) { + throw convertException(e, "Error while updating job submission interface"); + } } public boolean updateUnicoreJobSubmissionDetails( - String jobSubmissionInterfaceId, UnicoreJobSubmission unicoreJobSubmission) throws AppCatalogException { - return registryService.updateUnicoreJobSubmissionDetails(jobSubmissionInterfaceId, unicoreJobSubmission); + String jobSubmissionInterfaceId, UnicoreJobSubmission unicoreJobSubmission) + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.updateUnicoreJobSubmissionDetails(jobSubmissionInterfaceId, unicoreJobSubmission); + } catch (Throwable e) { + throw convertException(e, "Error while updating job submission interface"); + } } public boolean deleteJobSubmissionInterface(String computeResourceId, String jobSubmissionInterfaceId) - throws AppCatalogException { - return registryService.deleteJobSubmissionInterface(computeResourceId, jobSubmissionInterfaceId); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.deleteJobSubmissionInterface(computeResourceId, jobSubmissionInterfaceId); + } catch (Throwable e) { + throw convertException(e, "Error while deleting job submission interface"); + } } - public String registerResourceJobManager(ResourceJobManager resourceJobManager) throws AppCatalogException { - return registryService.registerResourceJobManager(resourceJobManager); + public String registerResourceJobManager(ResourceJobManager resourceJobManager) + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.registerResourceJobManager(resourceJobManager); + } catch (Throwable e) { + throw convertException(e, "Error while adding resource job manager"); + } } public boolean updateResourceJobManager(String resourceJobManagerId, ResourceJobManager updatedResourceJobManager) - throws AppCatalogException { - return registryService.updateResourceJobManager(resourceJobManagerId, updatedResourceJobManager); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.updateResourceJobManager(resourceJobManagerId, updatedResourceJobManager); + } catch (Throwable e) { + throw convertException(e, "Error while updating resource job manager"); + } } - public ResourceJobManager getResourceJobManager(String resourceJobManagerId) throws AppCatalogException { - return registryService.getResourceJobManager(resourceJobManagerId); + public ResourceJobManager getResourceJobManager(String resourceJobManagerId) + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.getResourceJobManager(resourceJobManagerId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving resource job manager"); + } } - public boolean deleteResourceJobManager(String resourceJobManagerId) throws AppCatalogException { - return registryService.deleteResourceJobManager(resourceJobManagerId); + public boolean deleteResourceJobManager(String resourceJobManagerId) + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.deleteResourceJobManager(resourceJobManagerId); + } catch (Throwable e) { + throw convertException(e, "Error while deleting resource job manager"); + } } public String addPasswordCredential( PasswordCredential passwordCredential) @@ -1162,28 +1738,49 @@ public List getAllCredentialSummaries( public String addLocalDataMovementDetails( String resourceId, DMType dmType, int priorityOrder, LOCALDataMovement localDataMovement) - throws AppCatalogException { - return registryService.addLocalDataMovementDetails(resourceId, dmType, priorityOrder, localDataMovement); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.addLocalDataMovementDetails(resourceId, dmType, priorityOrder, localDataMovement); + } catch (Throwable e) { + throw convertException(e, "Error while adding data movement interface to resource"); + } } public boolean updateLocalDataMovementDetails(String dataMovementInterfaceId, LOCALDataMovement localDataMovement) - throws AppCatalogException { - return registryService.updateLocalDataMovementDetails(dataMovementInterfaceId, localDataMovement); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.updateLocalDataMovementDetails(dataMovementInterfaceId, localDataMovement); + } catch (Throwable e) { + throw convertException(e, "Error while updating local data movement interface"); + } } - public LOCALDataMovement getLocalDataMovement(String dataMovementId) throws AppCatalogException { - return registryService.getLocalDataMovement(dataMovementId); + public LOCALDataMovement getLocalDataMovement(String dataMovementId) + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.getLocalDataMovement(dataMovementId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving local data movement interface"); + } } public String addSCPDataMovementDetails( String resourceId, DMType dmType, int priorityOrder, SCPDataMovement scpDataMovement) - throws AppCatalogException { - return registryService.addSCPDataMovementDetails(resourceId, dmType, priorityOrder, scpDataMovement); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.addSCPDataMovementDetails(resourceId, dmType, priorityOrder, scpDataMovement); + } catch (Throwable e) { + throw convertException(e, "Error while adding SCP data movement interface"); + } } public boolean updateSCPDataMovementDetails(String dataMovementInterfaceId, SCPDataMovement scpDataMovement) - throws AppCatalogException { - return registryService.updateSCPDataMovementDetails(dataMovementInterfaceId, scpDataMovement); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.updateSCPDataMovementDetails(dataMovementInterfaceId, scpDataMovement); + } catch (Throwable e) { + throw convertException(e, "Error while updating SCP data movement interface"); + } } public List getUserProjects(String gatewayId, String userName, int limit, int offset) @@ -1287,8 +1884,13 @@ public List getAccessibleApplicationDeployment return getAccessibleApplicationDeployments(gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); } - public List getAppModuleDeployedResources(String appModuleId) throws AppCatalogException { - return registryService.getAppModuleDeployedResources(appModuleId); + public List getAppModuleDeployedResources(String appModuleId) + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.getAppModuleDeployedResources(appModuleId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving application deployment"); + } } public List getAccessibleApplicationDeploymentsForAppModule( @@ -1296,70 +1898,169 @@ public List getAccessibleApplicationDeployment String gatewayId, List accessibleAppDeploymentIds, List accessibleComputeResourceIds) - throws AppCatalogException { - return registryService.getAccessibleApplicationDeploymentsForAppModule( - gatewayId, appModuleId, accessibleAppDeploymentIds, accessibleComputeResourceIds); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.getAccessibleApplicationDeploymentsForAppModule( + gatewayId, appModuleId, accessibleAppDeploymentIds, accessibleComputeResourceIds); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving accessible application deployments"); + } } - public Map getAvailableAppInterfaceComputeResources(String appInterfaceId) - throws AppCatalogException { - return registryService.getAvailableAppInterfaceComputeResources(appInterfaceId); + public List getApplicationDeploymentsForAppModuleAndGroupResourceProfile( + AuthzToken authzToken, String appModuleId, String groupResourceProfileId) + throws AuthorizationException { + try { + String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + + // Get list of compute resources for this Group Resource Profile + if (!userHasAccessInternal(authzToken, groupResourceProfileId, ResourcePermissionType.READ)) { + throw new AuthorizationException( + "User is not authorized to access Group Resource Profile " + groupResourceProfileId); + } + GroupResourceProfile groupResourceProfile = getGroupResourceProfile(groupResourceProfileId); + List accessibleComputeResourceIds = groupResourceProfile.getComputePreferences().stream() + .map(compPref -> compPref.getComputeResourceId()) + .collect(Collectors.toList()); + + // Get list of accessible Application Deployments + List accessibleAppDeploymentIds = new ArrayList<>(); + List sharingFilters = new ArrayList<>(); + SearchCriteria entityTypeFilter = new SearchCriteria(); + entityTypeFilter.setSearchField(EntitySearchField.ENTITY_TYPE_ID); + entityTypeFilter.setSearchCondition(SearchCondition.EQUAL); + entityTypeFilter.setValue(gatewayId + ":" + ResourceType.APPLICATION_DEPLOYMENT.name()); + sharingFilters.add(entityTypeFilter); + SearchCriteria permissionTypeFilter = new SearchCriteria(); + permissionTypeFilter.setSearchField(EntitySearchField.PERMISSION_TYPE_ID); + permissionTypeFilter.setSearchCondition(SearchCondition.EQUAL); + permissionTypeFilter.setValue(gatewayId + ":" + ResourcePermissionType.READ); + sharingFilters.add(permissionTypeFilter); + searchEntities(gatewayId, userName + "@" + gatewayId, sharingFilters, 0, -1) + .forEach(a -> accessibleAppDeploymentIds.add(a.getEntityId())); + + return getAccessibleApplicationDeploymentsForAppModule( + appModuleId, gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); + } catch (AuthorizationException e) { + throw e; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving application deployments"); + } + } + + public Map getAvailableAppInterfaceComputeResources(String appInterfaceId) { + try { + return registryService.getAvailableAppInterfaceComputeResources(appInterfaceId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving available compute resources"); + } } - public SCPDataMovement getSCPDataMovement(String dataMovementId) throws AppCatalogException { - return registryService.getSCPDataMovement(dataMovementId); + public SCPDataMovement getSCPDataMovement(String dataMovementId) + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.getSCPDataMovement(dataMovementId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving SCP data movement interface"); + } } public String addUnicoreDataMovementDetails( String resourceId, DMType dmType, int priorityOrder, UnicoreDataMovement unicoreDataMovement) - throws AppCatalogException { - return registryService.addUnicoreDataMovementDetails(resourceId, dmType, priorityOrder, unicoreDataMovement); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.addUnicoreDataMovementDetails(resourceId, dmType, priorityOrder, unicoreDataMovement); + } catch (Throwable e) { + throw convertException(e, "Error while adding UNICORE data movement interface"); + } } public boolean updateUnicoreDataMovementDetails( - String dataMovementInterfaceId, UnicoreDataMovement unicoreDataMovement) throws AppCatalogException { - return registryService.updateUnicoreDataMovementDetails(dataMovementInterfaceId, unicoreDataMovement); + String dataMovementInterfaceId, UnicoreDataMovement unicoreDataMovement) + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.updateUnicoreDataMovementDetails(dataMovementInterfaceId, unicoreDataMovement); + } catch (Throwable e) { + throw convertException(e, "Error while updating unicore data movement interface"); + } } - public UnicoreDataMovement getUnicoreDataMovement(String dataMovementId) throws AppCatalogException { - return registryService.getUnicoreDataMovement(dataMovementId); + public UnicoreDataMovement getUnicoreDataMovement(String dataMovementId) + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.getUnicoreDataMovement(dataMovementId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving UNICORE data movement interface"); + } } public String addGridFTPDataMovementDetails( String resourceId, DMType dmType, int priorityOrder, GridFTPDataMovement gridFTPDataMovement) - throws AppCatalogException { - return registryService.addGridFTPDataMovementDetails(resourceId, dmType, priorityOrder, gridFTPDataMovement); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.addGridFTPDataMovementDetails(resourceId, dmType, priorityOrder, gridFTPDataMovement); + } catch (Throwable e) { + throw convertException(e, "Error while adding GridFTP data movement interface"); + } } public boolean updateGridFTPDataMovementDetails( - String dataMovementInterfaceId, GridFTPDataMovement gridFTPDataMovement) throws AppCatalogException { - return registryService.updateGridFTPDataMovementDetails(dataMovementInterfaceId, gridFTPDataMovement); + String dataMovementInterfaceId, GridFTPDataMovement gridFTPDataMovement) + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.updateGridFTPDataMovementDetails(dataMovementInterfaceId, gridFTPDataMovement); + } catch (Throwable e) { + throw convertException(e, "Error while updating GridFTP data movement interface"); + } } - public GridFTPDataMovement getGridFTPDataMovement(String dataMovementId) throws AppCatalogException { - return registryService.getGridFTPDataMovement(dataMovementId); + public GridFTPDataMovement getGridFTPDataMovement(String dataMovementId) + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.getGridFTPDataMovement(dataMovementId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving GridFTP data movement interface"); + } } public boolean deleteDataMovementInterface(String resourceId, String dataMovementInterfaceId, DMType dmType) - throws AppCatalogException { - return registryService.deleteDataMovementInterface(resourceId, dataMovementInterfaceId, dmType); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.deleteDataMovementInterface(resourceId, dataMovementInterfaceId, dmType); + } catch (Throwable e) { + throw convertException(e, "Error while deleting data movement interface"); + } } - public boolean deleteBatchQueue(String computeResourceId, String queueName) throws AppCatalogException { - return registryService.deleteBatchQueue(computeResourceId, queueName); + public boolean deleteBatchQueue(String computeResourceId, String queueName) + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.deleteBatchQueue(computeResourceId, queueName); + } catch (Throwable e) { + throw convertException(e, "Error while deleting batch queue"); + } } public boolean addGatewayComputeResourcePreference( String gatewayID, String computeResourceId, ComputeResourcePreference computeResourcePreference) - throws AppCatalogException { - return registryService.addGatewayComputeResourcePreference( - gatewayID, computeResourceId, computeResourcePreference); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.addGatewayComputeResourcePreference( + gatewayID, computeResourceId, computeResourcePreference); + } catch (Throwable e) { + throw convertException(e, "Error while registering gateway resource profile preference"); + } } public boolean addGatewayStoragePreference( String gatewayID, String storageResourceId, StoragePreference dataStoragePreference) - throws AppCatalogException { - return registryService.addGatewayStoragePreference(gatewayID, storageResourceId, dataStoragePreference); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.addGatewayStoragePreference(gatewayID, storageResourceId, dataStoragePreference); + } catch (Throwable e) { + throw convertException(e, "Error while registering gateway storage preference"); + } } public ComputeResourcePreference getGatewayComputeResourcePreference(String gatewayID, String computeResourceId) @@ -1377,41 +2078,78 @@ public List getAllGatewayComputeResourcePreferences(S return registryService.getAllGatewayComputeResourcePreferences(gatewayID); } - public List getAllGatewayStoragePreferences(String gatewayID) throws AppCatalogException { - return registryService.getAllGatewayStoragePreferences(gatewayID); + public List getAllGatewayStoragePreferences(String gatewayID) { + try { + return registryService.getAllGatewayStoragePreferences(gatewayID); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving all gateway storage preferences"); + } } - public List getAllGatewayResourceProfiles() throws AppCatalogException { - return registryService.getAllGatewayResourceProfiles(); + public List getAllGatewayResourceProfiles() { + try { + return registryService.getAllGatewayResourceProfiles(); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving all gateway resource profiles"); + } } public boolean updateGatewayComputeResourcePreference( String gatewayID, String computeResourceId, ComputeResourcePreference computeResourcePreference) - throws AppCatalogException { - return registryService.updateGatewayComputeResourcePreference( - gatewayID, computeResourceId, computeResourcePreference); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.updateGatewayComputeResourcePreference( + gatewayID, computeResourceId, computeResourcePreference); + } catch (Throwable e) { + throw convertException(e, "Error while updating gateway compute resource preference"); + } } public boolean updateGatewayStoragePreference( - String gatewayID, String storageId, StoragePreference dataStoragePreference) throws AppCatalogException { - return registryService.updateGatewayStoragePreference(gatewayID, storageId, dataStoragePreference); + String gatewayID, String storageId, StoragePreference dataStoragePreference) + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.updateGatewayStoragePreference(gatewayID, storageId, dataStoragePreference); + } catch (Throwable e) { + throw convertException(e, "Error while updating gateway data storage preference"); + } } public boolean deleteGatewayComputeResourcePreference(String gatewayID, String computeResourceId) - throws AppCatalogException { - return registryService.deleteGatewayComputeResourcePreference(gatewayID, computeResourceId); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.deleteGatewayComputeResourcePreference(gatewayID, computeResourceId); + } catch (Throwable e) { + logger.error(gatewayID, "Error while deleting gateway compute resource preference...", e); + throw convertException(e, "Error while deleting gateway compute resource preference"); + } } - public boolean deleteGatewayStoragePreference(String gatewayID, String storageId) throws AppCatalogException { - return registryService.deleteGatewayStoragePreference(gatewayID, storageId); + public boolean deleteGatewayStoragePreference(String gatewayID, String storageId) + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.deleteGatewayStoragePreference(gatewayID, storageId); + } catch (Throwable e) { + throw convertException(e, "Error while deleting gateway data storage preference"); + } } - public String registerUserResourceProfile(UserResourceProfile userResourceProfile) throws AppCatalogException { - return registryService.registerUserResourceProfile(userResourceProfile); + public String registerUserResourceProfile(UserResourceProfile userResourceProfile) + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.registerUserResourceProfile(userResourceProfile); + } catch (Throwable e) { + throw convertException(e, "Error while registering user resource profile"); + } } - public boolean isUserResourceProfileExists(String userId, String gatewayId) throws AppCatalogException { - return registryService.isUserResourceProfileExists(userId, gatewayId); + public boolean isUserResourceProfileExists(String userId, String gatewayId) + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.isUserResourceProfileExists(userId, gatewayId); + } catch (Throwable e) { + throw convertException(e, "Error while checking existence of user resource profile"); + } } public boolean addUserComputeResourcePreference( @@ -1419,40 +2157,71 @@ public boolean addUserComputeResourcePreference( String gatewayID, String computeResourceId, UserComputeResourcePreference userComputeResourcePreference) - throws AppCatalogException { - return registryService.addUserComputeResourcePreference( - userId, gatewayID, computeResourceId, userComputeResourcePreference); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.addUserComputeResourcePreference( + userId, gatewayID, computeResourceId, userComputeResourcePreference); + } catch (Throwable e) { + logger.error(userId, "Error while registering user resource profile preference...", e); + throw convertException(e, "Error while registering user resource profile preference"); + } } public boolean addUserStoragePreference( String userId, String gatewayID, String userStorageResourceId, UserStoragePreference dataStoragePreference) - throws AppCatalogException { - return registryService.addUserStoragePreference( - userId, gatewayID, userStorageResourceId, dataStoragePreference); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.addUserStoragePreference( + userId, gatewayID, userStorageResourceId, dataStoragePreference); + } catch (Throwable e) { + throw convertException(e, "Error while registering user storage preference"); + } } public UserComputeResourcePreference getUserComputeResourcePreference( - String userId, String gatewayID, String userComputeResourceId) throws AppCatalogException { - return registryService.getUserComputeResourcePreference(userId, gatewayID, userComputeResourceId); + String userId, String gatewayID, String userComputeResourceId) + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.getUserComputeResourcePreference(userId, gatewayID, userComputeResourceId); + } catch (Throwable e) { + throw convertException(e, "Error while reading user compute resource preference"); + } } public UserStoragePreference getUserStoragePreference(String userId, String gatewayID, String userStorageId) - throws AppCatalogException { - return registryService.getUserStoragePreference(userId, gatewayID, userStorageId); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.getUserStoragePreference(userId, gatewayID, userStorageId); + } catch (Throwable e) { + throw convertException(e, "Error while reading user data storage preference"); + } } public List getAllUserComputeResourcePreferences(String userId, String gatewayID) - throws AppCatalogException { - return registryService.getAllUserComputeResourcePreferences(userId, gatewayID); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.getAllUserComputeResourcePreferences(userId, gatewayID); + } catch (Throwable e) { + throw convertException(e, "Error while reading User compute resource preferences"); + } } public List getAllUserStoragePreferences(String userId, String gatewayID) - throws AppCatalogException { - return registryService.getAllUserStoragePreferences(userId, gatewayID); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.getAllUserStoragePreferences(userId, gatewayID); + } catch (Throwable e) { + throw convertException(e, "Error while reading User data storage preferences"); + } } - public List getAllUserResourceProfiles() throws AppCatalogException { - return registryService.getAllUserResourceProfiles(); + public List getAllUserResourceProfiles() + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.getAllUserResourceProfiles(); + } catch (Throwable e) { + throw convertException(e, "Error while reading retrieving all user resource profiles"); + } } public boolean updateUserComputeResourcePreference( @@ -1460,94 +2229,169 @@ public boolean updateUserComputeResourcePreference( String gatewayID, String computeResourceId, UserComputeResourcePreference userComputeResourcePreference) - throws AppCatalogException { - return registryService.updateUserComputeResourcePreference( - userId, gatewayID, computeResourceId, userComputeResourcePreference); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.updateUserComputeResourcePreference( + userId, gatewayID, computeResourceId, userComputeResourcePreference); + } catch (Throwable e) { + throw convertException(e, "Error while updating user compute resource preference"); + } } public boolean updateUserStoragePreference( String userId, String gatewayID, String userStorageId, UserStoragePreference userStoragePreference) - throws AppCatalogException { - return registryService.updateUserStoragePreference(userId, gatewayID, userStorageId, userStoragePreference); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.updateUserStoragePreference(userId, gatewayID, userStorageId, userStoragePreference); + } catch (Throwable e) { + throw convertException(e, "Error while updating user data storage preference"); + } } public boolean deleteUserComputeResourcePreference(String userId, String gatewayID, String userComputeResourceId) - throws AppCatalogException { - return registryService.deleteUserComputeResourcePreference(userId, gatewayID, userComputeResourceId); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.deleteUserComputeResourcePreference(userId, gatewayID, userComputeResourceId); + } catch (Throwable e) { + logger.error(userId, "Error while deleting user compute resource preference...", e); + throw convertException(e, "Error while deleting user compute resource preference"); + } } public boolean deleteUserStoragePreference(String userId, String gatewayID, String userStorageId) - throws AppCatalogException { - return registryService.deleteUserStoragePreference(userId, gatewayID, userStorageId); - } - - public List getLatestQueueStatuses() throws RegistryException { - return registryService.getLatestQueueStatuses(); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + return registryService.deleteUserStoragePreference(userId, gatewayID, userStorageId); + } catch (Throwable e) { + throw convertException(e, "Error while deleting user data storage preference"); + } } - public String createGroupResourceProfile(GroupResourceProfile groupResourceProfile) throws AppCatalogException { - return registryService.createGroupResourceProfile(groupResourceProfile); - } + public List getLatestQueueStatuses() { + try { + return registryService.getLatestQueueStatuses(); + } catch (Throwable e) { + String msg = "Error in retrieving queue statuses"; + logger.error(msg, e); + throw convertException(e, msg); + } + } - public boolean removeGroupResourceProfile(String groupResourceProfileId) throws AppCatalogException { - return registryService.removeGroupResourceProfile(groupResourceProfileId); + public String createGroupResourceProfile(GroupResourceProfile groupResourceProfile) { + try { + return registryService.createGroupResourceProfile(groupResourceProfile); + } catch (Throwable e) { + throw convertException(e, "Error while creating group resource profile"); + } } - public boolean removeGroupComputePrefs(String computeResourceId, String groupResourceProfileId) - throws AppCatalogException { - return registryService.removeGroupComputePrefs(computeResourceId, groupResourceProfileId); + public boolean removeGroupResourceProfile(String groupResourceProfileId) { + try { + return registryService.removeGroupResourceProfile(groupResourceProfileId); + } catch (Throwable e) { + throw convertException(e, "Error while removing group resource profile"); + } + } + + public boolean removeGroupComputePrefs(String computeResourceId, String groupResourceProfileId) { + try { + return registryService.removeGroupComputePrefs(computeResourceId, groupResourceProfileId); + } catch (Throwable e) { + throw convertException(e, "Error while removing group compute preferences"); + } } public GroupComputeResourcePreference getGroupComputeResourcePreference( - String computeResourceId, String groupResourceProfileId) throws AppCatalogException { - return registryService.getGroupComputeResourcePreference(computeResourceId, groupResourceProfileId); + String computeResourceId, String groupResourceProfileId) { + try { + return registryService.getGroupComputeResourcePreference(computeResourceId, groupResourceProfileId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving group compute resource preference"); + } } public ComputeResourcePolicy getGroupComputeResourcePolicy(String resourcePolicyId) throws AppCatalogException { return registryService.getGroupComputeResourcePolicy(resourcePolicyId); } - public boolean removeGroupComputeResourcePolicy(String resourcePolicyId) throws AppCatalogException { - return registryService.removeGroupComputeResourcePolicy(resourcePolicyId); + public boolean removeGroupComputeResourcePolicy(String resourcePolicyId) { + try { + return registryService.removeGroupComputeResourcePolicy(resourcePolicyId); + } catch (Throwable e) { + throw convertException(e, "Error while removing group compute resource policy"); + } } - public BatchQueueResourcePolicy getBatchQueueResourcePolicy(String resourcePolicyId) throws AppCatalogException { - return registryService.getBatchQueueResourcePolicy(resourcePolicyId); + public BatchQueueResourcePolicy getBatchQueueResourcePolicy(String resourcePolicyId) { + try { + return registryService.getBatchQueueResourcePolicy(resourcePolicyId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving batch queue resource policy"); + } } - public boolean removeGroupBatchQueueResourcePolicy(String resourcePolicyId) throws AppCatalogException { - return registryService.removeGroupBatchQueueResourcePolicy(resourcePolicyId); + public boolean removeGroupBatchQueueResourcePolicy(String resourcePolicyId) { + try { + return registryService.removeGroupBatchQueueResourcePolicy(resourcePolicyId); + } catch (Throwable e) { + throw convertException(e, "Error while removing group batch queue resource policy"); + } } - public List getGroupComputeResourcePrefList(String groupResourceProfileId) - throws AppCatalogException { - return registryService.getGroupComputeResourcePrefList(groupResourceProfileId); + public List getGroupComputeResourcePrefList(String groupResourceProfileId) { + try { + return registryService.getGroupComputeResourcePrefList(groupResourceProfileId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving group compute resource preference list"); + } } - public List getGroupBatchQueueResourcePolicyList(String groupResourceProfileId) - throws AppCatalogException { - return registryService.getGroupBatchQueueResourcePolicyList(groupResourceProfileId); + public List getGroupBatchQueueResourcePolicyList(String groupResourceProfileId) { + try { + return registryService.getGroupBatchQueueResourcePolicyList(groupResourceProfileId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving group batch queue resource policy list"); + } } - public List getGroupComputeResourcePolicyList(String groupResourceProfileId) - throws AppCatalogException { - return registryService.getGroupComputeResourcePolicyList(groupResourceProfileId); + public List getGroupComputeResourcePolicyList(String groupResourceProfileId) { + try { + return registryService.getGroupComputeResourcePolicyList(groupResourceProfileId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving group compute resource policy list"); + } } - public Parser getParser(String parserId, String gatewayId) throws RegistryException { - return registryService.getParser(parserId, gatewayId); + public Parser getParser(String parserId, String gatewayId) { + try { + return registryService.getParser(parserId, gatewayId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving parser"); + } } - public String saveParser(Parser parser) throws RegistryException { - return registryService.saveParser(parser); + public String saveParser(Parser parser) { + try { + return registryService.saveParser(parser); + } catch (Throwable e) { + throw convertException(e, "Error while saving parser"); + } } - public List listAllParsers(String gatewayId) throws RegistryException { - return registryService.listAllParsers(gatewayId); + public List listAllParsers(String gatewayId) { + try { + return registryService.listAllParsers(gatewayId); + } catch (Throwable e) { + throw convertException(e, "Error while listing all parsers"); + } } - public void removeParser(String parserId, String gatewayId) throws RegistryException { - registryService.removeParser(parserId, gatewayId); + public void removeParser(String parserId, String gatewayId) { + try { + registryService.removeParser(parserId, gatewayId); + } catch (Throwable e) { + throw convertException(e, "Error while removing parser"); + } } public ParsingTemplate getParsingTemplate(String templateId, String gatewayId) throws RegistryException { @@ -1937,19 +2781,24 @@ public String createExperimentWithSharingAndPublish( Publisher statusPublisher, String gatewayId, ExperimentModel experiment) - throws Exception { - String experimentId = createExperimentWithSharing( gatewayId, experiment); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + logger.info("Api server accepted experiment creation with name {}", experiment.getExperimentName()); + String experimentId = createExperimentWithSharing( gatewayId, experiment); + + if (statusPublisher != null) { + ExperimentStatusChangeEvent event = + new ExperimentStatusChangeEvent(ExperimentState.CREATED, experimentId, gatewayId); + String messageId = AiravataUtils.getId("EXPERIMENT"); + MessageContext messageContext = new MessageContext(event, MessageType.EXPERIMENT, messageId, gatewayId); + messageContext.setUpdatedTime(AiravataUtils.getCurrentTimestamp()); + statusPublisher.publish(messageContext); + } - if (statusPublisher != null) { - ExperimentStatusChangeEvent event = - new ExperimentStatusChangeEvent(ExperimentState.CREATED, experimentId, gatewayId); - String messageId = AiravataUtils.getId("EXPERIMENT"); - MessageContext messageContext = new MessageContext(event, MessageType.EXPERIMENT, messageId, gatewayId); - messageContext.setUpdatedTime(AiravataUtils.getCurrentTimestamp()); - statusPublisher.publish(messageContext); + return experimentId; + } catch (Throwable e) { + throw convertException(e, "Error while creating the experiment"); } - - return experimentId; } public void validateLaunchExperimentAccess( @@ -2035,35 +2884,44 @@ public void validateLaunchExperimentAccess( } public boolean deleteExperimentWithAuth( - AuthzToken authzToken, String experimentId) throws Exception { - ExperimentModel experimentModel = getExperiment(experimentId); + AuthzToken authzToken, String experimentId) throws AuthorizationException, InvalidRequestException { + try { + ExperimentModel experimentModel = getExperiment(experimentId); - if (ServerSettings.isEnableSharing() - && !authzToken.getClaimsMap().get(Constants.USER_NAME).equals(experimentModel.getUserName()) - || !authzToken.getClaimsMap().get(Constants.GATEWAY_ID).equals(experimentModel.getGatewayId())) { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!sharingRegistryService.userHasAccess(gatewayId, userId + "@" + gatewayId, experimentId, gatewayId + ":WRITE")) { - throw new AuthorizationException("User does not have permission to access this resource"); + if (ServerSettings.isEnableSharing() + && !authzToken.getClaimsMap().get(Constants.USER_NAME).equals(experimentModel.getUserName()) + || !authzToken.getClaimsMap().get(Constants.GATEWAY_ID).equals(experimentModel.getGatewayId())) { + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + if (!sharingRegistryService.userHasAccess(gatewayId, userId + "@" + gatewayId, experimentId, gatewayId + ":WRITE")) { + throw new AuthorizationException("User does not have permission to access this resource"); + } } - } - if (!(experimentModel.getExperimentStatus().get(0).getState() - == org.apache.airavata.model.status.ExperimentState.CREATED)) { - throw new Exception("Experiment is not in CREATED state. Hence cannot deleted. ID:" + experimentId); + if (!(experimentModel.getExperimentStatus().get(0).getState() + == org.apache.airavata.model.status.ExperimentState.CREATED)) { + throw new InvalidRequestException("Experiment is not in CREATED state. Hence cannot deleted. ID:" + experimentId); + } + return deleteExperiment(experimentId); + } catch (AuthorizationException | InvalidRequestException e) { + throw e; + } catch (Throwable e) { + throw convertException(e, "Error while deleting experiment"); } - return deleteExperiment(experimentId); } - public ResourceType getResourceType( String domainId, String entityId) - throws TException { - Entity entity = sharingRegistryService.getEntity(domainId, entityId); - for (ResourceType resourceType : ResourceType.values()) { - if (entity.getEntityTypeId().equals(domainId + ":" + resourceType.name())) { - return resourceType; + public ResourceType getResourceType( String domainId, String entityId) { + try { + Entity entity = sharingRegistryService.getEntity(domainId, entityId); + for (ResourceType resourceType : ResourceType.values()) { + if (entity.getEntityTypeId().equals(domainId + ":" + resourceType.name())) { + return resourceType; + } } + throw new RuntimeException("Unrecognized entity type id: " + entity.getEntityTypeId()); + } catch (Throwable e) { + throw convertException(e, "Error while getting resource type"); } - throw new RuntimeException("Unrecognized entity type id: " + entity.getEntityTypeId()); } // Gateway management methods with sharing registry integration @@ -2186,51 +3044,67 @@ public void validateAndFetchIntermediateOutputs( String airavataExperimentId, List outputNames, Publisher experimentPublisher) - throws Exception { - // Verify that user has WRITE access to experiment - final boolean hasAccess = - userHasAccessInternal( authzToken, airavataExperimentId, ResourcePermissionType.WRITE); - if (!hasAccess) { - throw new Exception("User does not have WRITE access to this experiment"); - } - - // Verify that the experiment's job is currently ACTIVE - ExperimentModel existingExperiment = getExperiment(airavataExperimentId); - List jobs = getJobDetails(airavataExperimentId); - boolean anyJobIsActive = jobs.stream().anyMatch(j -> { - if (j.getJobStatusesSize() > 0) { - return j.getJobStatuses().get(j.getJobStatusesSize() - 1).getJobState() == JobState.ACTIVE; - } else { - return false; - } - }); - if (!anyJobIsActive) { - throw new Exception("Experiment does not have currently ACTIVE job"); - } - - // Figure out if there are any currently running intermediate output fetching processes for outputNames - // First, find any existing intermediate output fetch processes for outputNames - List intermediateOutputFetchProcesses = existingExperiment.getProcesses().stream() - .filter(p -> { - // Filter out completed or failed processes - if (p.getProcessStatusesSize() > 0) { - ProcessStatus latestStatus = p.getProcessStatuses().get(p.getProcessStatusesSize() - 1); - if (latestStatus.getState() == ProcessState.COMPLETED - || latestStatus.getState() == ProcessState.FAILED) { - return false; + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + // Verify that user has WRITE access to experiment + final boolean hasAccess = + userHasAccessInternal( authzToken, airavataExperimentId, ResourcePermissionType.WRITE); + if (!hasAccess) { + String msg = "User does not have WRITE access to this experiment"; + logger.error(msg); + throw new AuthorizationException(msg); + } + + // Verify that the experiment's job is currently ACTIVE + ExperimentModel existingExperiment = getExperiment(airavataExperimentId); + List jobs = getJobDetails(airavataExperimentId); + boolean anyJobIsActive = jobs.stream().anyMatch(j -> { + if (j.getJobStatusesSize() > 0) { + return j.getJobStatuses().get(j.getJobStatusesSize() - 1).getJobState() == JobState.ACTIVE; + } else { + return false; + } + }); + if (!anyJobIsActive) { + String msg = "Experiment does not have currently ACTIVE job"; + logger.error(msg); + throw new InvalidRequestException(msg); + } + + // Figure out if there are any currently running intermediate output fetching processes for outputNames + // First, find any existing intermediate output fetch processes for outputNames + List intermediateOutputFetchProcesses = existingExperiment.getProcesses().stream() + .filter(p -> { + // Filter out completed or failed processes + if (p.getProcessStatusesSize() > 0) { + ProcessStatus latestStatus = p.getProcessStatuses().get(p.getProcessStatusesSize() - 1); + if (latestStatus.getState() == ProcessState.COMPLETED + || latestStatus.getState() == ProcessState.FAILED) { + return false; + } } - } - return true; - }) - .filter(p -> p.getTasks().stream().allMatch(t -> t.getTaskType() == TaskTypes.OUTPUT_FETCHING)) - .filter(p -> p.getProcessOutputs().stream().anyMatch(o -> outputNames.contains(o.getName()))) - .collect(Collectors.toList()); - if (!intermediateOutputFetchProcesses.isEmpty()) { - throw new Exception("There are already intermediate output fetching tasks running for those outputs."); - } + return true; + }) + .filter(p -> p.getTasks().stream().allMatch(t -> t.getTaskType() == TaskTypes.OUTPUT_FETCHING)) + .filter(p -> p.getProcessOutputs().stream().anyMatch(o -> outputNames.contains(o.getName()))) + .collect(Collectors.toList()); + if (!intermediateOutputFetchProcesses.isEmpty()) { + String msg = "There are already intermediate output fetching tasks running for those outputs."; + logger.error(msg); + throw new InvalidRequestException(msg); + } - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - publishExperimentIntermediateOutputsEvent(experimentPublisher, gatewayId, airavataExperimentId, outputNames); + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + publishExperimentIntermediateOutputsEvent(experimentPublisher, gatewayId, airavataExperimentId, outputNames); + } catch (AuthorizationException | InvalidRequestException e) { + throw e; + } catch (Throwable e) { + logger.error( + "Error while processing request to fetch intermediate outputs for experiment: " + + airavataExperimentId, + e); + throw convertException(e, "Error occurred"); + } } /** @@ -2241,44 +3115,58 @@ public ProcessStatus getIntermediateOutputProcessStatusInternal( AuthzToken authzToken, String airavataExperimentId, List outputNames) - throws Exception { - // Verify that user has READ access to experiment - final boolean hasAccess = - userHasAccessInternal( authzToken, airavataExperimentId, ResourcePermissionType.READ); - if (!hasAccess) { - throw new Exception("User does not have READ access to this experiment"); - } - - ExperimentModel existingExperiment = getExperiment(airavataExperimentId); - - // Find the most recent intermediate output fetching process for the outputNames - // Assumption: only one of these output fetching processes runs at a - // time so we only need to check the status of the most recent one - Optional mostRecentOutputFetchProcess = existingExperiment.getProcesses().stream() - .filter(p -> p.getTasks().stream().allMatch(t -> t.getTaskType() == TaskTypes.OUTPUT_FETCHING)) - .filter(p -> { - List names = - p.getProcessOutputs().stream().map(o -> o.getName()).collect(Collectors.toList()); - return new HashSet<>(names).equals(new HashSet<>(outputNames)); - }) - .sorted(Comparator.comparing(ProcessModel::getLastUpdateTime).reversed()) - .findFirst(); - - if (!mostRecentOutputFetchProcess.isPresent()) { - throw new Exception("No matching intermediate output fetching process found."); - } - - ProcessStatus result; - // Determine the most recent status for the most recent process - ProcessModel process = mostRecentOutputFetchProcess.get(); - if (process.getProcessStatusesSize() > 0) { - result = process.getProcessStatuses().get(process.getProcessStatusesSize() - 1); - } else { - // Process has no statuses so it must be created but not yet running - result = new ProcessStatus(ProcessState.CREATED); - } + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + // Verify that user has READ access to experiment + final boolean hasAccess = + userHasAccessInternal( authzToken, airavataExperimentId, ResourcePermissionType.READ); + if (!hasAccess) { + String msg = "User does not have READ access to this experiment"; + logger.debug(msg); + throw new AuthorizationException(msg); + } + + ExperimentModel existingExperiment = getExperiment(airavataExperimentId); + + // Find the most recent intermediate output fetching process for the outputNames + // Assumption: only one of these output fetching processes runs at a + // time so we only need to check the status of the most recent one + Optional mostRecentOutputFetchProcess = existingExperiment.getProcesses().stream() + .filter(p -> p.getTasks().stream().allMatch(t -> t.getTaskType() == TaskTypes.OUTPUT_FETCHING)) + .filter(p -> { + List names = + p.getProcessOutputs().stream().map(o -> o.getName()).collect(Collectors.toList()); + return new HashSet<>(names).equals(new HashSet<>(outputNames)); + }) + .sorted(Comparator.comparing(ProcessModel::getLastUpdateTime).reversed()) + .findFirst(); + + if (!mostRecentOutputFetchProcess.isPresent()) { + String msg = "No matching intermediate output fetching process found."; + logger.debug(msg); + throw new InvalidRequestException(msg); + } - return result; + ProcessStatus result; + // Determine the most recent status for the most recent process + ProcessModel process = mostRecentOutputFetchProcess.get(); + if (process.getProcessStatusesSize() > 0) { + result = process.getProcessStatuses().get(process.getProcessStatusesSize() - 1); + } else { + // Process has no statuses so it must be created but not yet running + result = new ProcessStatus(ProcessState.CREATED); + } + + return result; + } catch (AuthorizationException | InvalidRequestException e) { + throw e; + } catch (Throwable e) { + logger.error( + "Error while processing request to get intermediate output process status for experiment: " + + airavataExperimentId, + e); + throw convertException(e, "Error occurred"); + } } // Access control methods @@ -2423,7 +3311,7 @@ public String createGroupResourceProfileWithSharing( + groupResourceProfileId); try { removeGroupResourceProfile(groupResourceProfileId); - } catch (AppCatalogException rollbackEx) { + } catch (Throwable rollbackEx) { logger.error("Failed to rollback group resource profile deletion", rollbackEx); } throw new Exception("Failed to create sharing registry record", ex); @@ -2464,6 +3352,7 @@ public void launchExperimentWithValidation( Publisher experimentPublisher) throws TException { try { + logger.info("Launching experiment {}", airavataExperimentId); ExperimentModel experiment = getExperiment(airavataExperimentId); if (experiment == null) { @@ -2571,8 +3460,12 @@ public boolean shareEntityWithUsers(String domainId, String entityId, List groupResourceProfiles = getGroupResourceListWithSharing(authzToken, gatewayId); + for (GroupResourceProfile groupProfile : groupResourceProfiles) { + List groupComputePrefs = groupProfile.getComputePreferences(); + + if (groupComputePrefs != null && !groupComputePrefs.isEmpty()) { + for (GroupComputeResourcePreference groupPref : groupComputePrefs) { + if (resourceId.equals(groupPref.getComputeResourceId()) + && groupPref.getLoginUserName() != null + && !groupPref.getLoginUserName().trim().isEmpty()) { + loginUserName = groupPref.getLoginUserName(); + groupComputePref = groupPref; + groupResourceProfile = groupProfile; + logger.debug( + "Using login username from group compute resource preference for resource {}", + resourceId); + break; + } + } + } + if (loginUserName != null) { + break; + } + } + if (loginUserName == null) { + logger.debug("No login username found for compute resource {}", resourceId); + throw new InvalidRequestException("No login username found for compute resource " + resourceId); + } + } + + // Resolve credential token based on where login came from + String credentialToken; + if (loginFromUserPref) { + // Login username came from user preference. Use user preference token → user profile token + if (userComputePref != null + && userComputePref.getResourceSpecificCredentialStoreToken() != null + && !userComputePref + .getResourceSpecificCredentialStoreToken() + .trim() + .isEmpty()) { + credentialToken = userComputePref.getResourceSpecificCredentialStoreToken(); + } else { + UserResourceProfile userResourceProfile = getUserResourceProfile(userId, gatewayId); + if (userResourceProfile == null + || userResourceProfile.getCredentialStoreToken() == null + || userResourceProfile.getCredentialStoreToken().trim().isEmpty()) { + logger.error("No credential store token found for user {} in gateway {}", userId, gatewayId); + throw clientException( + AiravataErrorType.AUTHENTICATION_FAILURE, + "No credential store token found for user " + userId + " in gateway " + gatewayId); + } + credentialToken = userResourceProfile.getCredentialStoreToken(); + } + } else { + // Login username came from group preference. Use group preference token → group profile default token → + // user profile token (fallback) + if (groupComputePref != null + && groupComputePref.getResourceSpecificCredentialStoreToken() != null + && !groupComputePref + .getResourceSpecificCredentialStoreToken() + .trim() + .isEmpty()) { + credentialToken = groupComputePref.getResourceSpecificCredentialStoreToken(); + + } else if (groupResourceProfile != null + && groupResourceProfile.getDefaultCredentialStoreToken() != null + && !groupResourceProfile + .getDefaultCredentialStoreToken() + .trim() + .isEmpty()) { + credentialToken = groupResourceProfile.getDefaultCredentialStoreToken(); + + } else { + UserResourceProfile userResourceProfile = getUserResourceProfile(userId, gatewayId); + if (userResourceProfile == null + || userResourceProfile.getCredentialStoreToken() == null + || userResourceProfile.getCredentialStoreToken().trim().isEmpty()) { + logger.error("No credential store token found for user {} in gateway {}", userId, gatewayId); + throw clientException( + AiravataErrorType.AUTHENTICATION_FAILURE, + "No credential store token found for compute resource " + resourceId); + } + credentialToken = userResourceProfile.getCredentialStoreToken(); + } + } + + AgentAdaptor adaptor = AdaptorSupportImpl.getInstance() + .fetchComputeSSHAdaptor(gatewayId, resourceId, credentialToken, userId, loginUserName); + logger.info("Resolved resource {} as compute resource to fetch storage details", resourceId); + + return new StorageInfoContext(loginUserName, credentialToken, adaptor); + } + + /** + * Resolves storage resource storage info context (login username, credential token, and adaptor). + * Handles user preference → gateway preference fallback for both login and credentials. + */ + private StorageInfoContext resolveStorageStorageInfoContext( + AuthzToken authzToken, String gatewayId, String userId, String resourceId) + throws Exception { + UserStoragePreference userStoragePref = null; + if (safeIsUserResourceProfileExists(authzToken, userId, gatewayId)) { + userStoragePref = getUserStoragePreference(userId, gatewayId, resourceId); + } else { + logger.debug( + "User resource profile does not exist for user {} in gateway {}, will try gateway preferences", + userId, + gatewayId); + } + + StoragePreference storagePref = null; + if (isGatewayResourceProfileExists(gatewayId)) { + storagePref = getGatewayStoragePreference(gatewayId, resourceId); + } else { + logger.debug( + "Gateway resource profile does not exist for gateway {}, will check if user preference exists", + gatewayId); + } + + String loginUserName; + boolean loginFromUserPref; + + if (userStoragePref != null + && userStoragePref.getLoginUserName() != null + && !userStoragePref.getLoginUserName().trim().isEmpty()) { + loginUserName = userStoragePref.getLoginUserName(); + loginFromUserPref = true; + logger.debug("Using login username from user storage preference for resource {}", resourceId); + + } else if (storagePref != null + && storagePref.getLoginUserName() != null + && !storagePref.getLoginUserName().trim().isEmpty()) { + loginUserName = storagePref.getLoginUserName(); + loginFromUserPref = false; + logger.debug("Using login username from gateway storage preference for resource {}", resourceId); + + } else { + logger.error("No login username found for storage resource {}", resourceId); + throw new InvalidRequestException("No login username found for storage resource " + resourceId); + } + + // Resolve credential token based on where login came from + String credentialToken; + if (loginFromUserPref) { + // Login came from user preference. Use user preference token or user profile token + if (userStoragePref != null + && userStoragePref.getResourceSpecificCredentialStoreToken() != null + && !userStoragePref + .getResourceSpecificCredentialStoreToken() + .trim() + .isEmpty()) { + credentialToken = userStoragePref.getResourceSpecificCredentialStoreToken(); + logger.debug("Using login username from user preference for resource {}", resourceId); + + } else { + UserResourceProfile userResourceProfile = getUserResourceProfile(userId, gatewayId); + if (userResourceProfile == null + || userResourceProfile.getCredentialStoreToken() == null + || userResourceProfile.getCredentialStoreToken().trim().isEmpty()) { + logger.error("No credential store token found for user {} in gateway {}", userId, gatewayId); + throw clientException( + AiravataErrorType.AUTHENTICATION_FAILURE, + "No credential store token found for user " + userId + " in gateway " + gatewayId); + } + credentialToken = userResourceProfile.getCredentialStoreToken(); + } + } else { + // Login came from gateway preference. Use gateway preference token or gateway profile token + if (storagePref != null + && storagePref.getResourceSpecificCredentialStoreToken() != null + && !storagePref + .getResourceSpecificCredentialStoreToken() + .trim() + .isEmpty()) { + credentialToken = storagePref.getResourceSpecificCredentialStoreToken(); + + } else { + GatewayResourceProfile gatewayResourceProfile = getGatewayResourceProfile(gatewayId); + if (gatewayResourceProfile == null + || gatewayResourceProfile.getCredentialStoreToken() == null + || gatewayResourceProfile + .getCredentialStoreToken() + .trim() + .isEmpty()) { + logger.error("No credential store token found for gateway {}", gatewayId); + throw clientException( + AiravataErrorType.AUTHENTICATION_FAILURE, + "No credential store token found for gateway " + gatewayId); + } + credentialToken = gatewayResourceProfile.getCredentialStoreToken(); + } + } + + AgentAdaptor adaptor = AdaptorSupportImpl.getInstance() + .fetchStorageSSHAdaptor(gatewayId, resourceId, credentialToken, userId, loginUserName); + logger.info("Resolved resource {} as storage resource to fetch storage details", resourceId); + + return new StorageInfoContext(loginUserName, credentialToken, adaptor); + } + + public StorageVolumeInfo getResourceStorageInfo( + AuthzToken authzToken, String resourceId, String location) + throws InvalidRequestException { + try { + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + StorageInfoContext context; + + Optional computeResourceOp = Optional.empty(); + try { + ComputeResourceDescription computeResource = getComputeResource(resourceId); + if (computeResource != null) { + computeResourceOp = Optional.of(computeResource); + } + } catch (Throwable e) { + logger.debug("Compute resource {} not found: {}", resourceId, e.getMessage()); + } + + Optional storageResourceOp = Optional.empty(); + if (computeResourceOp.isEmpty()) { + try { + StorageResourceDescription storageResource = getStorageResource(resourceId); + if (storageResource != null) { + storageResourceOp = Optional.of(storageResource); + } + } catch (Throwable e) { + logger.debug("Storage resource {} not found: {}", resourceId, e.getMessage()); + } + } + + if (computeResourceOp.isEmpty() && storageResourceOp.isEmpty()) { + logger.error( + "Resource with ID {} not found as either compute resource or storage resource", resourceId); + throw new InvalidRequestException("Resource with ID '" + resourceId + + "' not found as either compute resource or storage resource"); + } + + if (computeResourceOp.isPresent()) { + logger.debug("Found compute resource with ID {}. Resolving login username and credentials", resourceId); + context = resolveComputeStorageInfoContext(authzToken, gatewayId, userId, resourceId); + } else { + logger.debug("Found storage resource with ID {}. Resolving login username and credentials", resourceId); + context = resolveStorageStorageInfoContext(authzToken, gatewayId, userId, resourceId); + } + + return context.adaptor().getStorageVolumeInfo(location); + } catch (InvalidRequestException e) { + logger.error("Error while retrieving storage resource.", e); + throw e; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving storage resource"); + } + } + + public StorageDirectoryInfo getStorageDirectoryInfo( + AuthzToken authzToken, String resourceId, String location) + throws InvalidRequestException { + try { + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + StorageInfoContext context; + + Optional computeResourceOp = Optional.empty(); + try { + ComputeResourceDescription computeResource = getComputeResource(resourceId); + if (computeResource != null) { + computeResourceOp = Optional.of(computeResource); + } + } catch (Throwable e) { + logger.debug("Compute resource {} not found: {}", resourceId, e.getMessage()); + } + + Optional storageResourceOp = Optional.empty(); + if (computeResourceOp.isEmpty()) { + try { + StorageResourceDescription storageResource = getStorageResource(resourceId); + if (storageResource != null) { + storageResourceOp = Optional.of(storageResource); + } + } catch (Throwable e) { + logger.debug("Storage resource {} not found: {}", resourceId, e.getMessage()); + } + } + + if (computeResourceOp.isEmpty() && storageResourceOp.isEmpty()) { + logger.error( + "Resource with ID {} not found as either compute resource or storage resource", resourceId); + throw new InvalidRequestException("Resource with ID '" + resourceId + + "' not found as either compute resource or storage resource"); + } + + if (computeResourceOp.isPresent()) { + logger.debug("Found compute resource with ID {}. Resolving login username and credentials", resourceId); + context = resolveComputeStorageInfoContext(authzToken, gatewayId, userId, resourceId); + } else { + logger.debug("Found storage resource with ID {}. Resolving login username and credentials", resourceId); + context = resolveStorageStorageInfoContext(authzToken, gatewayId, userId, resourceId); + } + + return context.adaptor().getStorageDirectoryInfo(location); + } catch (InvalidRequestException e) { + logger.error("Error while retrieving storage resource.", e); + throw e; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving storage directory info"); + } + } + + public boolean doesUserHaveSSHAccount(AuthzToken authzToken, String computeResourceId, String userId) { + try { + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + logger.debug("Checking if user {} has SSH account on compute resource {} in gateway {}", userId, computeResourceId, gatewayId); + return org.apache.airavata.accountprovisioning.SSHAccountManager.doesUserHaveSSHAccount(gatewayId, computeResourceId, userId); + } catch (Throwable e) { + throw convertException(e, "Error occurred while checking if user has an SSH Account"); + } + } + + public boolean isSSHAccountSetupComplete( + AuthzToken authzToken, String computeResourceId, String airavataCredStoreToken) { + try { + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + logger.debug("Checking if SSH account setup is complete for user {} on compute resource {} in gateway {}", userId, computeResourceId, gatewayId); + + SSHCredential sshCredential = getSSHCredential(airavataCredStoreToken, gatewayId); + return org.apache.airavata.accountprovisioning.SSHAccountManager.isSSHAccountSetupComplete(gatewayId, computeResourceId, userId, sshCredential); + } catch (Throwable e) { + throw convertException(e, "Error occurred while checking if setup of SSH account is complete"); + } + } + + public UserComputeResourcePreference setupSSHAccount( + AuthzToken authzToken, String computeResourceId, String userId, String airavataCredStoreToken) { + try { + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + logger.debug("Setting up SSH account for user {} on compute resource {} in gateway {}", userId, computeResourceId, gatewayId); + + SSHCredential sshCredential = getSSHCredential(airavataCredStoreToken, gatewayId); + return org.apache.airavata.accountprovisioning.SSHAccountManager.setupSSHAccount(gatewayId, computeResourceId, userId, sshCredential); + } catch (Throwable e) { + throw convertException(e, "Error occurred while automatically setting up SSH account for user"); + } + } + + public boolean shareResourceWithUsers( + AuthzToken authzToken, String resourceId, Map userPermissionList) + throws AuthorizationException, AiravataClientException { + try { + if (!userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.OWNER) + && !userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { + throw new AuthorizationException( + "User is not allowed to change sharing because the user is either not the resource owner or does not have access to share the resource"); + } + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + for (Map.Entry userPermission : userPermissionList.entrySet()) { + if (userPermission.getValue().equals(ResourcePermissionType.WRITE)) { + shareEntityWithUsers( + gatewayId, + resourceId, + Arrays.asList(userPermission.getKey()), + gatewayId + ":" + "WRITE", + true); + } else if (userPermission.getValue().equals(ResourcePermissionType.READ)) { + shareEntityWithUsers( + gatewayId, + resourceId, + Arrays.asList(userPermission.getKey()), + gatewayId + ":" + "READ", + true); + } else if (userPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING)) { + if (userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.OWNER)) { + createManageSharingPermissionTypeIfMissing(gatewayId); + shareEntityWithUsers( + gatewayId, + resourceId, + Arrays.asList(userPermission.getKey()), + gatewayId + ":" + "MANAGE_SHARING", + true); + } else { + throw new AuthorizationException( + "User is not allowed to grant sharing permission because the user is not the resource owner."); + } + } else { + logger.error("Invalid ResourcePermissionType : {}", userPermission.getValue().toString()); + throw new AiravataClientException(AiravataErrorType.UNSUPPORTED_OPERATION); + } + } + return true; + } catch (AuthorizationException | AiravataClientException e) { + throw e; + } catch (Throwable e) { + String msg = "Error in sharing resource with users. Resource ID : " + resourceId; + logger.error(msg, e); + throw convertException(e, msg); + } + } + + public boolean shareResourceWithGroups( + AuthzToken authzToken, String resourceId, Map groupPermissionList) + throws AuthorizationException, AiravataClientException { + try { + if (!userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.OWNER) + && !userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { + throw new AuthorizationException( + "User is not allowed to change sharing because the user is either not the resource owner or does not have access to share the resource"); + } + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + for (Map.Entry groupPermission : groupPermissionList.entrySet()) { + if (groupPermission.getValue().equals(ResourcePermissionType.WRITE)) { + shareEntityWithGroups( + gatewayId, + resourceId, + Arrays.asList(groupPermission.getKey()), + gatewayId + ":" + "WRITE", + true); + } else if (groupPermission.getValue().equals(ResourcePermissionType.READ)) { + shareEntityWithGroups( + gatewayId, + resourceId, + Arrays.asList(groupPermission.getKey()), + gatewayId + ":" + "READ", + true); + } else if (groupPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING)) { + if (userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.OWNER)) { + createManageSharingPermissionTypeIfMissing(gatewayId); + shareEntityWithGroups( + gatewayId, + resourceId, + Arrays.asList(groupPermission.getKey()), + gatewayId + ":" + "MANAGE_SHARING", + true); + } else { + throw new AuthorizationException( + "User is not allowed to grant sharing permission because the user is not the resource owner."); + } + } else { + logger.error("Invalid ResourcePermissionType : {}", groupPermission.getValue().toString()); + throw new AiravataClientException(AiravataErrorType.UNSUPPORTED_OPERATION); + } + } + return true; + } catch (AuthorizationException | AiravataClientException e) { + throw e; + } catch (Throwable e) { + String msg = "Error in sharing resource with groups. Resource ID : " + resourceId; + logger.error(msg, e); + throw convertException(e, msg); + } + } + + public boolean revokeSharingOfResourceFromUsers( + AuthzToken authzToken, String resourceId, Map userPermissionList) + throws AuthorizationException, AiravataClientException { + try { + if (!userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.OWNER) + && !userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { + throw new AuthorizationException( + "User is not allowed to change sharing because the user is either not the resource owner or does not have access to share the resource"); + } + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + for (Map.Entry userPermission : userPermissionList.entrySet()) { + if (userPermission.getValue().equals(ResourcePermissionType.WRITE)) { + revokeEntitySharingFromUsers( + gatewayId, + resourceId, + Arrays.asList(userPermission.getKey()), + gatewayId + ":" + "WRITE"); + } else if (userPermission.getValue().equals(ResourcePermissionType.READ)) { + revokeEntitySharingFromUsers( + gatewayId, + resourceId, + Arrays.asList(userPermission.getKey()), + gatewayId + ":" + "READ"); + } else if (userPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING)) { + if (userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.OWNER)) { + createManageSharingPermissionTypeIfMissing(gatewayId); + revokeEntitySharingFromUsers( + gatewayId, + resourceId, + Arrays.asList(userPermission.getKey()), + gatewayId + ":" + "MANAGE_SHARING"); + } else { + throw new AuthorizationException( + "User is not allowed to change sharing permission because the user is not the resource owner."); + } + } else { + logger.error("Invalid ResourcePermissionType : {}", userPermission.getValue().toString()); + throw new AiravataClientException(AiravataErrorType.UNSUPPORTED_OPERATION); + } + } + return true; + } catch (AuthorizationException | AiravataClientException e) { + throw e; + } catch (Throwable e) { + String msg = "Error in revoking access to resource from users. Resource ID : " + resourceId; + logger.error(msg, e); + throw convertException(e, msg); + } + } + + public boolean revokeSharingOfResourceFromGroups( + AuthzToken authzToken, String resourceId, Map groupPermissionList) + throws AuthorizationException, AiravataClientException, InvalidRequestException { + try { + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + if (!userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.OWNER) + && !userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { + throw new AuthorizationException( + "User is not allowed to change sharing because the user is either not the resource owner or does not have access to share the resource"); + } + // For certain resource types, restrict them from being unshared with admin groups + ResourceType resourceType = getResourceType(gatewayId, resourceId); + Set adminRestrictedResourceTypes = new HashSet<>(Arrays.asList( + ResourceType.EXPERIMENT, ResourceType.APPLICATION_DEPLOYMENT, ResourceType.GROUP_RESOURCE_PROFILE)); + if (adminRestrictedResourceTypes.contains(resourceType)) { + // Prevent removing Admins WRITE/MANAGE_SHARING access and Read Only Admins READ access + GatewayGroups gatewayGroups = retrieveGatewayGroups(gatewayId); + if (groupPermissionList.containsKey(gatewayGroups.getAdminsGroupId()) + && groupPermissionList + .get(gatewayGroups.getAdminsGroupId()) + .equals(ResourcePermissionType.WRITE)) { + throw new InvalidRequestException("Not allowed to remove Admins group's WRITE access."); + } + if (groupPermissionList.containsKey(gatewayGroups.getReadOnlyAdminsGroupId()) + && groupPermissionList + .get(gatewayGroups.getReadOnlyAdminsGroupId()) + .equals(ResourcePermissionType.READ)) { + throw new InvalidRequestException("Not allowed to remove Read Only Admins group's READ access."); + } + if (groupPermissionList.containsKey(gatewayGroups.getAdminsGroupId()) + && groupPermissionList + .get(gatewayGroups.getAdminsGroupId()) + .equals(ResourcePermissionType.READ)) { + throw new InvalidRequestException("Not allowed to remove Admins group's READ access."); + } + if (groupPermissionList.containsKey(gatewayGroups.getAdminsGroupId()) + && groupPermissionList + .get(gatewayGroups.getAdminsGroupId()) + .equals(ResourcePermissionType.MANAGE_SHARING)) { + throw new InvalidRequestException("Not allowed to remove Admins group's MANAGE_SHARING access."); + } + } + for (Map.Entry groupPermission : groupPermissionList.entrySet()) { + if (groupPermission.getValue().equals(ResourcePermissionType.WRITE)) { + revokeEntitySharingFromGroups( + gatewayId, resourceId, Arrays.asList(groupPermission.getKey()), gatewayId + ":" + "WRITE"); + } else if (groupPermission.getValue().equals(ResourcePermissionType.READ)) { + revokeEntitySharingFromGroups( + gatewayId, resourceId, Arrays.asList(groupPermission.getKey()), gatewayId + ":" + "READ"); + } else if (groupPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING)) { + if (userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.OWNER)) { + createManageSharingPermissionTypeIfMissing(gatewayId); + revokeEntitySharingFromGroups( + gatewayId, + resourceId, + Arrays.asList(groupPermission.getKey()), + gatewayId + ":" + "MANAGE_SHARING"); + } else { + throw new AuthorizationException( + "User is not allowed to change sharing because the user is not the resource owner"); + } + } else { + logger.error("Invalid ResourcePermissionType : {}", groupPermission.getValue().toString()); + throw new AiravataClientException(AiravataErrorType.UNSUPPORTED_OPERATION); + } + } + return true; + } catch (AuthorizationException | AiravataClientException | InvalidRequestException e) { + throw e; + } catch (Throwable e) { + String msg = "Error in revoking access to resource from groups. Resource ID : " + resourceId; + logger.error(msg, e); + throw convertException(e, msg); + } + } + + public GroupResourceProfile getGroupResourceProfileWithAuth(AuthzToken authzToken, String groupResourceProfileId) + throws AuthorizationException { + try { + if (ServerSettings.isEnableSharing()) { + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + if (!userHasAccess(gatewayId, userId + "@" + gatewayId, groupResourceProfileId, gatewayId + ":READ")) { + throw new AuthorizationException( + "User does not have permission to access group resource profile"); + } + } + return getGroupResourceProfile(groupResourceProfileId); + } catch (AuthorizationException e) { + logger.error( + "Error while retrieving group resource profile. groupResourceProfileId: " + groupResourceProfileId, + e); + throw e; + } catch (Throwable e) { + String msg = "Error retrieving group resource profile. groupResourceProfileId: " + groupResourceProfileId; + logger.error(msg, e); + throw convertException(e, msg); + } + } + + public boolean removeGroupResourceProfileWithAuth(AuthzToken authzToken, String groupResourceProfileId) + throws AuthorizationException { + try { + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + if (ServerSettings.isEnableSharing()) { + String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + if (!userHasAccess(gatewayId, userId + "@" + gatewayId, groupResourceProfileId, gatewayId + ":WRITE")) { + throw new AuthorizationException( + "User does not have permission to remove group resource profile"); + } + } + boolean result = removeGroupResourceProfile(groupResourceProfileId); + if (result) { + deleteEntity(gatewayId, groupResourceProfileId); + } + return result; + } catch (AuthorizationException e) { + throw e; + } catch (Throwable e) { + String msg = "Error removing group resource profile. groupResourceProfileId: " + groupResourceProfileId; + logger.error(msg, e); + throw convertException(e, msg); + } + } + + public boolean removeGroupComputePrefsWithAuth( + AuthzToken authzToken, String computeResourceId, String groupResourceProfileId) + throws AuthorizationException { + try { + if (ServerSettings.isEnableSharing()) { + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + if (!userHasAccess(gatewayId, userId + "@" + gatewayId, groupResourceProfileId, gatewayId + ":WRITE")) { + throw new AuthorizationException( + "User does not have permission to remove group compute preferences"); + } + } + return removeGroupComputePrefs(computeResourceId, groupResourceProfileId); + } catch (AuthorizationException e) { + throw e; + } catch (Throwable e) { + String msg = "Error removing group compute preferences. GroupResourceProfileId: " + groupResourceProfileId; + logger.error(msg, e); + throw convertException(e, msg); + } + } + + public boolean removeGroupComputeResourcePolicyWithAuth(AuthzToken authzToken, String resourcePolicyId) + throws AuthorizationException { + try { + if (ServerSettings.isEnableSharing()) { + ComputeResourcePolicy computeResourcePolicy = getGroupComputeResourcePolicy(resourcePolicyId); + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + if (!userHasAccess( + gatewayId, + userId + "@" + gatewayId, + computeResourcePolicy.getGroupResourceProfileId(), + gatewayId + ":WRITE")) { + throw new AuthorizationException( + "User does not have permission to remove group compute resource policy"); + } + } + return removeGroupComputeResourcePolicy(resourcePolicyId); + } catch (AuthorizationException e) { + throw e; + } catch (Throwable e) { + String msg = "Error removing group compute resource policy. ResourcePolicyId: " + resourcePolicyId; + logger.error(msg, e); + throw convertException(e, msg); + } + } + + public boolean removeGroupBatchQueueResourcePolicyWithAuth(AuthzToken authzToken, String resourcePolicyId) + throws AuthorizationException { + try { + if (ServerSettings.isEnableSharing()) { + BatchQueueResourcePolicy batchQueueResourcePolicy = getBatchQueueResourcePolicy(resourcePolicyId); + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + if (!userHasAccess( + gatewayId, + userId + "@" + gatewayId, + batchQueueResourcePolicy.getGroupResourceProfileId(), + gatewayId + ":WRITE")) { + throw new AuthorizationException( + "User does not have permission to remove batch queue resource policy"); + } + } + return removeGroupBatchQueueResourcePolicy(resourcePolicyId); + } catch (AuthorizationException e) { + throw e; + } catch (Throwable e) { + String msg = "Error removing batch queue resource policy. ResourcePolicyId: " + resourcePolicyId; + logger.error(msg, e); + throw convertException(e, msg); + } + } + + public GroupComputeResourcePreference getGroupComputeResourcePreferenceWithAuth( + AuthzToken authzToken, String computeResourceId, String groupResourceProfileId) + throws AuthorizationException { + try { + if (ServerSettings.isEnableSharing()) { + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + if (!userHasAccess(gatewayId, userId + "@" + gatewayId, groupResourceProfileId, gatewayId + ":READ")) { + throw new AuthorizationException( + "User does not have permission to access group resource profile"); + } + } + return getGroupComputeResourcePreference(computeResourceId, groupResourceProfileId); + } catch (AuthorizationException e) { + throw e; + } catch (Throwable e) { + String msg = "Error retrieving Group compute preference. GroupResourceProfileId: " + groupResourceProfileId; + logger.error(msg, e); + throw convertException(e, msg); + } + } + + public ComputeResourcePolicy getGroupComputeResourcePolicyWithAuth(AuthzToken authzToken, String resourcePolicyId) + throws AuthorizationException { + try { + if (ServerSettings.isEnableSharing()) { + ComputeResourcePolicy computeResourcePolicy = getGroupComputeResourcePolicy(resourcePolicyId); + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + if (!userHasAccess( + gatewayId, + userId + "@" + gatewayId, + computeResourcePolicy.getGroupResourceProfileId(), + gatewayId + ":READ")) { + throw new AuthorizationException( + "User does not have permission to access group resource profile"); + } + } + return getGroupComputeResourcePolicy(resourcePolicyId); + } catch (AuthorizationException e) { + throw e; + } catch (Throwable e) { + String msg = "Error retrieving Group compute resource policy. ResourcePolicyId: " + resourcePolicyId; + logger.error(msg, e); + throw convertException(e, msg); + } + } + + public BatchQueueResourcePolicy getBatchQueueResourcePolicyWithAuth(AuthzToken authzToken, String resourcePolicyId) + throws AuthorizationException { + try { + if (ServerSettings.isEnableSharing()) { + BatchQueueResourcePolicy batchQueueResourcePolicy = getBatchQueueResourcePolicy(resourcePolicyId); + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + if (!userHasAccess( + gatewayId, + userId + "@" + gatewayId, + batchQueueResourcePolicy.getGroupResourceProfileId(), + gatewayId + ":READ")) { + throw new AuthorizationException( + "User does not have permission to access group resource profile"); + } + } + return getBatchQueueResourcePolicy(resourcePolicyId); + } catch (AuthorizationException e) { + throw e; + } catch (Throwable e) { + String msg = "Error retrieving batch queue resource policy. ResourcePolicyId: " + resourcePolicyId; + logger.error(msg, e); + throw convertException(e, msg); + } + } + + public void updateGroupResourceProfileWithAuth(AuthzToken authzToken, GroupResourceProfile groupResourceProfile) + throws AuthorizationException { + try { + validateGroupResourceProfile(authzToken, groupResourceProfile); + if (!userHasAccessInternal( + authzToken, + groupResourceProfile.getGroupResourceProfileId(), + ResourcePermissionType.WRITE)) { + throw new AuthorizationException("User does not have permission to update group resource profile"); + } + updateGroupResourceProfile(groupResourceProfile); + } catch (AuthorizationException e) { + String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); + logger.info("User " + userName + " not allowed access to update GroupResourceProfile " + + groupResourceProfile.getGroupResourceProfileId() + ", reason: " + e.getMessage()); + throw e; + } catch (Throwable e) { + String msg = "Error updating group resource profile. groupResourceProfileId: " + + groupResourceProfile.getGroupResourceProfileId(); + logger.error(msg, e); + throw convertException(e, msg); + } + } + + public List getGroupComputeResourcePrefListWithAuth( + AuthzToken authzToken, String groupResourceProfileId) { + try { + if (ServerSettings.isEnableSharing()) { + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + if (!userHasAccess(gatewayId, userId + "@" + gatewayId, groupResourceProfileId, gatewayId + ":READ")) { + throw new AuthorizationException( + "User does not have permission to access group resource profile"); + } + } + return getGroupComputeResourcePrefList(groupResourceProfileId); + } catch (AuthorizationException e) { + throw e; + } catch (Throwable e) { + String msg = "Error retrieving Group compute resource preference. GroupResourceProfileId: " + + groupResourceProfileId; + logger.error(msg, e); + throw convertException(e, msg); + } + } + + public List getGroupBatchQueueResourcePolicyListWithAuth( + AuthzToken authzToken, String groupResourceProfileId) { + try { + if (ServerSettings.isEnableSharing()) { + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + if (!userHasAccess(gatewayId, userId + "@" + gatewayId, groupResourceProfileId, gatewayId + ":READ")) { + throw new AuthorizationException( + "User does not have permission to access group resource profile"); + } + } + return getGroupBatchQueueResourcePolicyList(groupResourceProfileId); + } catch (AuthorizationException e) { + throw e; + } catch (Throwable e) { + String msg = "Error retrieving Group batch queue resource policy list. GroupResourceProfileId: " + + groupResourceProfileId; + logger.error(msg, e); + throw convertException(e, msg); + } + } + + public List getGroupComputeResourcePolicyListWithAuth( + AuthzToken authzToken, String groupResourceProfileId) { + try { + if (ServerSettings.isEnableSharing()) { + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + if (!userHasAccess(gatewayId, userId + "@" + gatewayId, groupResourceProfileId, gatewayId + ":READ")) { + throw new AuthorizationException( + "User does not have permission to access group resource profile"); + } + } + return getGroupComputeResourcePolicyList(groupResourceProfileId); + } catch (AuthorizationException e) { + throw e; + } catch (Throwable e) { + String msg = "Error retrieving Group compute resource policy list. GroupResourceProfileId: " + + groupResourceProfileId; + logger.error(msg, e); + throw convertException(e, msg); + } + } + + public String createGroupResourceProfileWithAuth(AuthzToken authzToken, GroupResourceProfile groupResourceProfile) + throws AuthorizationException { + try { + String result = createGroupResourceProfileWithSharing(authzToken, groupResourceProfile); + return result; + } catch (AuthorizationException e) { + String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); + logger.info("User " + userName + + " not allowed access to resources referenced in this GroupResourceProfile. Reason: " + + e.getMessage()); + throw e; + } catch (Throwable e) { + String msg = "Error creating group resource profile."; + logger.error(msg, e); + throw convertException(e, msg); + } + } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/GroupManagerService.java b/airavata-api/src/main/java/org/apache/airavata/service/GroupManagerService.java index 78f3f8abb4..98c2438ab5 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/GroupManagerService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/GroupManagerService.java @@ -46,6 +46,13 @@ public class GroupManagerService { private static final Logger logger = LoggerFactory.getLogger(GroupManagerService.class); private UserProfileRepository userProfileRepository = new UserProfileRepository(); + private GroupManagerServiceException convertException(Throwable e, String msg) { + logger.error(msg, e); + GroupManagerServiceException exception = new GroupManagerServiceException(); + exception.setMessage(msg + ". More info : " + e.getMessage()); + return exception; + } + public String createGroup(AuthzToken authzToken, GroupModel groupModel) throws GroupManagerServiceException { try { // TODO Validations for authorization diff --git a/airavata-api/src/main/java/org/apache/airavata/service/IamAdminService.java b/airavata-api/src/main/java/org/apache/airavata/service/IamAdminService.java index 80e45c6138..8b3dbcf80e 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/IamAdminService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/IamAdminService.java @@ -52,6 +52,11 @@ public class IamAdminService { private UserProfileRepository userProfileRepository = new UserProfileRepository(); private DBEventPublisherUtils dbEventPublisherUtils = new DBEventPublisherUtils(DBEventService.IAM_ADMIN); + private IamAdminServicesException convertException(Throwable e, String msg) { + logger.error(msg, e); + return new IamAdminServicesException(msg + ". More info : " + e.getMessage()); + } + public Gateway setUpGateway(AuthzToken authzToken, Gateway gateway) throws IamAdminServicesException { TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl(); PasswordCredential isSuperAdminCredentials = getSuperAdminPasswordCredential(); @@ -78,9 +83,15 @@ public Gateway setUpGateway(AuthzToken authzToken, Gateway gateway) throws IamAd } public boolean isUsernameAvailable(AuthzToken authzToken, String username) throws IamAdminServicesException { - TenantManagementKeycloakImpl keycloakClient = new TenantManagementKeycloakImpl(); - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - return keycloakClient.isUsernameAvailable(authzToken.getAccessToken(), gatewayId, username); + try { + TenantManagementKeycloakImpl keycloakClient = new TenantManagementKeycloakImpl(); + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + return keycloakClient.isUsernameAvailable(authzToken.getAccessToken(), gatewayId, username); + } catch (IamAdminServicesException e) { + throw e; + } catch (Throwable ex) { + throw convertException(ex, "Error while checking username availability"); + } } public boolean registerUser( @@ -214,16 +225,28 @@ public List findUsers(AuthzToken authzToken, String email, String u } public void updateUserProfile(AuthzToken authzToken, UserProfile userDetails) throws IamAdminServicesException { - TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl(); - String username = userDetails.getUserId(); - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - keycloakclient.updateUserProfile(authzToken.getAccessToken(), gatewayId, username, userDetails); + try { + TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl(); + String username = userDetails.getUserId(); + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + keycloakclient.updateUserProfile(authzToken.getAccessToken(), gatewayId, username, userDetails); + } catch (IamAdminServicesException e) { + throw e; + } catch (Throwable ex) { + throw convertException(ex, "Error while updating user profile"); + } } public boolean deleteUser(AuthzToken authzToken, String username) throws IamAdminServicesException { - TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl(); - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - return keycloakclient.deleteUser(authzToken.getAccessToken(), gatewayId, username); + try { + TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl(); + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + return keycloakclient.deleteUser(authzToken.getAccessToken(), gatewayId, username); + } catch (IamAdminServicesException e) { + throw e; + } catch (Throwable ex) { + throw convertException(ex, "Error while deleting user"); + } } public boolean addRoleToUser(AuthzToken authzToken, String username, String roleName) diff --git a/airavata-api/src/main/java/org/apache/airavata/service/RegistryService.java b/airavata-api/src/main/java/org/apache/airavata/service/RegistryService.java index a66a269af4..4fb0be90e4 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/RegistryService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/RegistryService.java @@ -172,76 +172,112 @@ public boolean deleteGateway(String gatewayId) throws RegistryServiceException { } } - public List getAllGateways() throws RegistryException { - List gateways = gatewayRepository.getAllGateways(); - logger.debug("Airavata retrieved all available gateways..."); - return gateways; + public List getAllGateways() throws RegistryServiceException { + try { + List gateways = gatewayRepository.getAllGateways(); + logger.debug("Airavata retrieved all available gateways..."); + return gateways; + } catch (Throwable e) { + throw convertException(e, "Error while getting all the gateways"); + } } - public boolean isGatewayExist(String gatewayId) throws RegistryException { - return gatewayRepository.isGatewayExist(gatewayId); + public boolean isGatewayExist(String gatewayId) throws RegistryServiceException { + try { + return gatewayRepository.isGatewayExist(gatewayId); + } catch (Throwable e) { + throw convertException(e, "Error while checking if gateway exists"); + } } - public boolean deleteNotification(String gatewayId, String notificationId) throws RegistryException { - notificationRepository.deleteNotification(notificationId); - return true; + public boolean deleteNotification(String gatewayId, String notificationId) throws RegistryServiceException { + try { + notificationRepository.deleteNotification(notificationId); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while deleting notification"); + } } - public Notification getNotification(String gatewayId, String notificationId) throws RegistryException { - return notificationRepository.getNotification(notificationId); + public Notification getNotification(String gatewayId, String notificationId) throws RegistryServiceException { + try { + return notificationRepository.getNotification(notificationId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving notification"); + } } - public List getAllNotifications(String gatewayId) throws RegistryException { - List notifications = notificationRepository.getAllGatewayNotifications(gatewayId); - return notifications; + public List getAllNotifications(String gatewayId) throws RegistryServiceException { + try { + List notifications = notificationRepository.getAllGatewayNotifications(gatewayId); + return notifications; + } catch (Throwable e) { + throw convertException(e, "Error while getting all notifications"); + } } - public Project getProject(String projectId) throws RegistryException, ProjectNotFoundException { - if (!projectRepository.isProjectExist(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; + public Project getProject(String projectId) throws RegistryServiceException, ProjectNotFoundException { + try { + if (!projectRepository.isProjectExist(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 = projectRepository.getProject(projectId); + return project; + } catch (ProjectNotFoundException e) { + throw e; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving the project"); } - logger.debug("Airavata retrieved project with project Id : " + projectId); - Project project = projectRepository.getProject(projectId); - return project; } - public boolean deleteProject(String projectId) throws RegistryException, ProjectNotFoundException { - if (!projectRepository.isProjectExist(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; + public boolean deleteProject(String projectId) throws RegistryServiceException, ProjectNotFoundException { + try { + if (!projectRepository.isProjectExist(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; + } + projectRepository.removeProject(projectId); + logger.debug("Airavata deleted project with project Id : " + projectId); + return true; + } catch (ProjectNotFoundException e) { + throw e; + } catch (Throwable e) { + throw convertException(e, "Error while removing the project"); } - projectRepository.removeProject(projectId); - logger.debug("Airavata deleted project with project Id : " + projectId); - return true; } public List getUserProjects(String gatewayId, String userName, int limit, int offset) - throws RegistryException { - if (!validateString(userName)) { - logger.error("Username cannot be empty. Please provide a valid user.."); - throw new RegistryException("Username cannot be empty. Please provide a valid user.."); - } - if (!isGatewayExistInternal(gatewayId)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new RegistryException("Gateway does not exist.Please provide a valid gateway id..."); - } - List projects = new ArrayList<>(); - if (!userRepository.isUserExists(gatewayId, userName)) { - logger.warn("User does not exist in the system. Please provide a valid user.."); + throws RegistryServiceException { + try { + if (!validateString(userName)) { + logger.error("Username cannot be empty. Please provide a valid user.."); + throw new RegistryException("Username cannot be empty. Please provide a valid user.."); + } + if (!isGatewayExistInternal(gatewayId)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new RegistryException("Gateway does not exist.Please provide a valid gateway id..."); + } + List projects = new ArrayList<>(); + if (!userRepository.isUserExists(gatewayId, userName)) { + logger.warn("User does not exist in the system. Please provide a valid user.."); + return projects; + } + Map filters = new HashMap<>(); + filters.put(Constants.FieldConstants.ProjectConstants.OWNER, userName); + filters.put(Constants.FieldConstants.ProjectConstants.GATEWAY_ID, gatewayId); + projects = projectRepository.searchProjects( + filters, limit, offset, Constants.FieldConstants.ProjectConstants.CREATION_TIME, ResultOrderType.DESC); + logger.debug("Airavata retrieved projects for user : " + userName + " and gateway id : " + gatewayId); return projects; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving projects"); } - Map filters = new HashMap<>(); - filters.put(Constants.FieldConstants.ProjectConstants.OWNER, userName); - filters.put(Constants.FieldConstants.ProjectConstants.GATEWAY_ID, gatewayId); - projects = projectRepository.searchProjects( - filters, limit, offset, Constants.FieldConstants.ProjectConstants.CREATION_TIME, ResultOrderType.DESC); - logger.debug("Airavata retrieved projects for user : " + userName + " and gateway id : " + gatewayId); - return projects; } public ExperimentStatistics getExperimentStatistics( @@ -254,356 +290,484 @@ public ExperimentStatistics getExperimentStatistics( List accessibleExpIds, int limit, int offset) - throws RegistryException { - if (!isGatewayExistInternal(gatewayId)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new RegistryException("Gateway does not exist.Please provide a valid gateway id..."); - } - Map filters = new HashMap<>(); - filters.put(Constants.FieldConstants.ExperimentConstants.GATEWAY_ID, gatewayId); - filters.put(Constants.FieldConstants.ExperimentConstants.FROM_DATE, fromTime + ""); - filters.put(Constants.FieldConstants.ExperimentConstants.TO_DATE, toTime + ""); - if (userName != null) { - filters.put(Constants.FieldConstants.ExperimentConstants.USER_NAME, userName); - } - if (applicationName != null) { - filters.put(Constants.FieldConstants.ExperimentConstants.EXECUTION_ID, applicationName); - } - if (resourceHostName != null) { - filters.put(Constants.FieldConstants.ExperimentConstants.RESOURCE_HOST_ID, resourceHostName); + throws RegistryServiceException { + try { + if (!isGatewayExistInternal(gatewayId)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new RegistryException("Gateway does not exist.Please provide a valid gateway id..."); + } + Map filters = new HashMap<>(); + filters.put(Constants.FieldConstants.ExperimentConstants.GATEWAY_ID, gatewayId); + filters.put(Constants.FieldConstants.ExperimentConstants.FROM_DATE, fromTime + ""); + filters.put(Constants.FieldConstants.ExperimentConstants.TO_DATE, toTime + ""); + if (userName != null) { + filters.put(Constants.FieldConstants.ExperimentConstants.USER_NAME, userName); + } + if (applicationName != null) { + filters.put(Constants.FieldConstants.ExperimentConstants.EXECUTION_ID, applicationName); + } + if (resourceHostName != null) { + filters.put(Constants.FieldConstants.ExperimentConstants.RESOURCE_HOST_ID, resourceHostName); + } + limit = Math.min(limit, 1000); + ExperimentStatistics result = + experimentSummaryRepository.getAccessibleExperimentStatistics(accessibleExpIds, filters, limit, offset); + logger.debug("Airavata retrieved experiments for gateway id : " + gatewayId + " between : " + + org.apache.airavata.common.utils.AiravataUtils.getTime(fromTime) + " and " + + org.apache.airavata.common.utils.AiravataUtils.getTime(toTime)); + return result; + } catch (Throwable e) { + throw convertException(e, "Error while getting experiment statistics"); } - limit = Math.min(limit, 1000); - ExperimentStatistics result = - experimentSummaryRepository.getAccessibleExperimentStatistics(accessibleExpIds, filters, limit, offset); - logger.debug("Airavata retrieved experiments for gateway id : " + gatewayId + " between : " - + org.apache.airavata.common.utils.AiravataUtils.getTime(fromTime) + " and " - + org.apache.airavata.common.utils.AiravataUtils.getTime(toTime)); - return result; } public List getExperimentsInProject(String gatewayId, String projectId, int limit, int offset) - throws RegistryException { - if (!isGatewayExistInternal(gatewayId)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new RegistryException("Gateway does not exist.Please provide a valid gateway id..."); - } - if (!validateString(projectId)) { - logger.error("Project id cannot be empty. Please provide a valid project ID..."); - throw new RegistryException("Project id cannot be empty. Please provide a valid project ID..."); - } - if (!projectRepository.isProjectExist(projectId)) { - logger.error("Project does not exist in the system. Please provide a valid project ID..."); - throw new RegistryException("Project does not exist in the system. Please provide a valid project ID..."); - } - List experiments = experimentRepository.getExperimentList( - gatewayId, - Constants.FieldConstants.ExperimentConstants.PROJECT_ID, - projectId, - limit, - offset, - Constants.FieldConstants.ExperimentConstants.CREATION_TIME, - ResultOrderType.DESC); - logger.debug("Airavata retrieved experiments for project : " + projectId); - return experiments; + throws RegistryServiceException { + try { + if (!isGatewayExistInternal(gatewayId)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new RegistryException("Gateway does not exist.Please provide a valid gateway id..."); + } + if (!validateString(projectId)) { + logger.error("Project id cannot be empty. Please provide a valid project ID..."); + throw new RegistryException("Project id cannot be empty. Please provide a valid project ID..."); + } + if (!projectRepository.isProjectExist(projectId)) { + logger.error("Project does not exist in the system. Please provide a valid project ID..."); + throw new RegistryException("Project does not exist in the system. Please provide a valid project ID..."); + } + List experiments = experimentRepository.getExperimentList( + gatewayId, + Constants.FieldConstants.ExperimentConstants.PROJECT_ID, + projectId, + limit, + offset, + Constants.FieldConstants.ExperimentConstants.CREATION_TIME, + ResultOrderType.DESC); + logger.debug("Airavata retrieved experiments for project : " + projectId); + return experiments; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving the experiments"); + } } public List getUserExperiments(String gatewayId, String userName, int limit, int offset) - throws RegistryException { - if (!validateString(userName)) { - logger.error("Username cannot be empty. Please provide a valid user.."); - throw new RegistryException("Username cannot be empty. Please provide a valid user.."); - } - if (!isGatewayExistInternal(gatewayId)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new RegistryException("Gateway does not exist.Please provide a valid gateway id..."); - } - List experiments = new ArrayList(); - if (!userRepository.isUserExists(gatewayId, userName)) { - logger.warn("User does not exist in the system. Please provide a valid user.."); + throws RegistryServiceException { + try { + if (!validateString(userName)) { + logger.error("Username cannot be empty. Please provide a valid user.."); + throw new RegistryException("Username cannot be empty. Please provide a valid user.."); + } + if (!isGatewayExistInternal(gatewayId)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new RegistryException("Gateway does not exist.Please provide a valid gateway id..."); + } + List experiments = new ArrayList(); + if (!userRepository.isUserExists(gatewayId, userName)) { + logger.warn("User does not exist in the system. Please provide a valid user.."); + return experiments; + } + experiments = experimentRepository.getExperimentList( + gatewayId, + Constants.FieldConstants.ExperimentConstants.USER_NAME, + userName, + limit, + offset, + Constants.FieldConstants.ExperimentConstants.CREATION_TIME, + ResultOrderType.DESC); + logger.debug("Airavata retrieved experiments for user : " + userName); return experiments; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving the experiments"); } - experiments = experimentRepository.getExperimentList( - gatewayId, - Constants.FieldConstants.ExperimentConstants.USER_NAME, - userName, - limit, - offset, - Constants.FieldConstants.ExperimentConstants.CREATION_TIME, - ResultOrderType.DESC); - logger.debug("Airavata retrieved experiments for user : " + userName); - return experiments; } - public boolean deleteExperiment(String experimentId) throws RegistryException { - if (!experimentRepository.isExperimentExist(experimentId)) { - throw new RegistryException("Requested experiment id " + experimentId + " does not exist in the system.."); - } - ExperimentModel experimentModel = experimentRepository.getExperiment(experimentId); - if (!(experimentModel.getExperimentStatus().get(0).getState() == ExperimentState.CREATED)) { - logger.error("Error while deleting the experiment"); - throw new RegistryException("Experiment is not in CREATED state. Hence cannot deleted. ID:" + experimentId); + public boolean deleteExperiment(String experimentId) throws RegistryServiceException { + try { + if (!experimentRepository.isExperimentExist(experimentId)) { + throw new RegistryException("Requested experiment id " + experimentId + " does not exist in the system.."); + } + ExperimentModel experimentModel = experimentRepository.getExperiment(experimentId); + if (!(experimentModel.getExperimentStatus().get(0).getState() == ExperimentState.CREATED)) { + logger.error("Error while deleting the experiment"); + throw new RegistryException("Experiment is not in CREATED state. Hence cannot deleted. ID:" + experimentId); + } + experimentRepository.removeExperiment(experimentId); + logger.debug("Airavata removed experiment with experiment id : " + experimentId); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while deleting the experiment"); } - experimentRepository.removeExperiment(experimentId); - logger.debug("Airavata removed experiment with experiment id : " + experimentId); - return true; } - private ExperimentModel getExperimentInternal(String airavataExperimentId) throws RegistryException { - if (!experimentRepository.isExperimentExist(airavataExperimentId)) { - throw new RegistryException( - "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); + private ExperimentModel getExperimentInternal(String airavataExperimentId) throws RegistryServiceException { + try { + if (!experimentRepository.isExperimentExist(airavataExperimentId)) { + throw new RegistryException( + "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); + } + return experimentRepository.getExperiment(airavataExperimentId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving the experiment"); } - return experimentRepository.getExperiment(airavataExperimentId); } - public ExperimentModel getExperiment(String airavataExperimentId) throws RegistryException { + public ExperimentModel getExperiment(String airavataExperimentId) throws RegistryServiceException { return getExperimentInternal(airavataExperimentId); } - public ExperimentModel getDetailedExperimentTree(String airavataExperimentId) throws RegistryException { - ExperimentModel experimentModel = getExperimentInternal(airavataExperimentId); - List processList = processRepository.getProcessList( - Constants.FieldConstants.ExperimentConstants.EXPERIMENT_ID, experimentModel.getExperimentId()); - if (processList != null) { - processList.stream().forEach(p -> { - (p).getTasks().stream().forEach(t -> { - try { - List jobList = jobRepository.getJobList( - Constants.FieldConstants.JobConstants.TASK_ID, ((TaskModel) t).getTaskId()); - if (jobList != null) { - Collections.sort(jobList, new Comparator() { - @Override - public int compare(JobModel o1, JobModel o2) { - return (int) (o1.getCreationTime() - o2.getCreationTime()); - } - }); - t.setJobs(jobList); + public ExperimentModel getDetailedExperimentTree(String airavataExperimentId) throws RegistryServiceException { + try { + ExperimentModel experimentModel = getExperimentInternal(airavataExperimentId); + List processList = processRepository.getProcessList( + Constants.FieldConstants.ExperimentConstants.EXPERIMENT_ID, experimentModel.getExperimentId()); + if (processList != null) { + processList.stream().forEach(p -> { + (p).getTasks().stream().forEach(t -> { + try { + List jobList = jobRepository.getJobList( + Constants.FieldConstants.JobConstants.TASK_ID, ((TaskModel) t).getTaskId()); + if (jobList != null) { + Collections.sort(jobList, new Comparator() { + @Override + public int compare(JobModel o1, JobModel o2) { + return (int) (o1.getCreationTime() - o2.getCreationTime()); + } + }); + t.setJobs(jobList); + } + } catch (RegistryException e) { + logger.error(e.getMessage(), e); } - } catch (RegistryException e) { - logger.error(e.getMessage(), e); - } + }); }); - }); - experimentModel.setProcesses(processList); + experimentModel.setProcesses(processList); + } + logger.debug("Airavata retrieved detailed experiment with experiment id : " + airavataExperimentId); + return experimentModel; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving the experiment"); } - logger.debug("Airavata retrieved detailed experiment with experiment id : " + airavataExperimentId); - return experimentModel; } - private ExperimentStatus getExperimentStatusInternal(String airavataExperimentId) throws RegistryException { - if (!experimentRepository.isExperimentExist(airavataExperimentId)) { - logger.error( - airavataExperimentId, - "Error while retrieving experiment status, experiment {} doesn't exist.", - airavataExperimentId); - throw new RegistryException( - "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); + private ExperimentStatus getExperimentStatusInternal(String airavataExperimentId) throws RegistryServiceException { + try { + if (!experimentRepository.isExperimentExist(airavataExperimentId)) { + logger.error( + airavataExperimentId, + "Error while retrieving experiment status, experiment {} doesn't exist.", + airavataExperimentId); + throw new RegistryException( + "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); + } + return experimentStatusRepository.getExperimentStatus(airavataExperimentId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving experiment status"); } - return experimentStatusRepository.getExperimentStatus(airavataExperimentId); } - public ExperimentStatus getExperimentStatus(String airavataExperimentId) throws RegistryException { - ExperimentStatus experimentStatus = getExperimentStatusInternal(airavataExperimentId); - logger.debug("Airavata retrieved experiment status for experiment id : " + airavataExperimentId); - return experimentStatus; + public ExperimentStatus getExperimentStatus(String airavataExperimentId) throws RegistryServiceException { + try { + ExperimentStatus experimentStatus = getExperimentStatusInternal(airavataExperimentId); + logger.debug("Airavata retrieved experiment status for experiment id : " + airavataExperimentId); + return experimentStatus; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving experiment status"); + } } - public List getExperimentOutputs(String airavataExperimentId) throws RegistryException { - if (!experimentRepository.isExperimentExist(airavataExperimentId)) { - logger.error( - airavataExperimentId, - "Get experiment outputs failed, experiment {} doesn't exit.", - airavataExperimentId); - throw new RegistryException( - "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); + public List getExperimentOutputs(String airavataExperimentId) throws RegistryServiceException { + try { + if (!experimentRepository.isExperimentExist(airavataExperimentId)) { + logger.error( + airavataExperimentId, + "Get experiment outputs failed, experiment {} doesn't exit.", + airavataExperimentId); + throw new RegistryException( + "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); + } + logger.debug("Airavata retrieved experiment outputs for experiment id : " + airavataExperimentId); + return experimentOutputRepository.getExperimentOutputs(airavataExperimentId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving the experiment outputs"); } - logger.debug("Airavata retrieved experiment outputs for experiment id : " + airavataExperimentId); - return experimentOutputRepository.getExperimentOutputs(airavataExperimentId); } - public void updateJobStatus(JobStatus jobStatus, String taskId, String jobId) throws RegistryException { - org.apache.airavata.registry.core.entities.expcatalog.JobPK jobPK = - new org.apache.airavata.registry.core.entities.expcatalog.JobPK(); - jobPK.setTaskId(taskId); - jobPK.setJobId(jobId); - jobStatusRepository.updateJobStatus(jobStatus, jobPK); + public void updateJobStatus(JobStatus jobStatus, String taskId, String jobId) throws RegistryServiceException { + try { + org.apache.airavata.registry.core.entities.expcatalog.JobPK jobPK = + new org.apache.airavata.registry.core.entities.expcatalog.JobPK(); + jobPK.setTaskId(taskId); + jobPK.setJobId(jobId); + jobStatusRepository.updateJobStatus(jobStatus, jobPK); + } catch (Throwable e) { + throw convertException(e, "Error while updating job status"); + } } - public void addJob(JobModel jobModel, String processId) throws RegistryException { - jobRepository.addJob(jobModel, processId); + public void addJob(JobModel jobModel, String processId) throws RegistryServiceException { + try { + jobRepository.addJob(jobModel, processId); + } catch (Throwable e) { + throw convertException(e, "Error while adding job"); + } } // Note: deleteJobs method removed - JobRepository doesn't have this method // Jobs should be deleted individually using removeJob(jobPK) or removeJob(jobModel) - public String addProcess(ProcessModel processModel, String experimentId) throws RegistryException { - return processRepository.addProcess(processModel, experimentId); + public String addProcess(ProcessModel processModel, String experimentId) throws RegistryServiceException { + try { + return processRepository.addProcess(processModel, experimentId); + } catch (Throwable e) { + throw convertException(e, "Error while adding process"); + } } - public void updateProcess(ProcessModel processModel, String processId) throws RegistryException { - processRepository.updateProcess(processModel, processId); + public void updateProcess(ProcessModel processModel, String processId) throws RegistryServiceException { + try { + processRepository.updateProcess(processModel, processId); + } catch (Throwable e) { + throw convertException(e, "Error while updating process"); + } } - public String addTask(TaskModel taskModel, String processId) throws RegistryException { - return taskRepository.addTask(taskModel, processId); + public String addTask(TaskModel taskModel, String processId) throws RegistryServiceException { + try { + return taskRepository.addTask(taskModel, processId); + } catch (Throwable e) { + throw convertException(e, "Error while adding task"); + } } - public void deleteTasks(String processId) throws RegistryException { - taskRepository.deleteTasks(processId); + public void deleteTasks(String processId) throws RegistryServiceException { + try { + taskRepository.deleteTasks(processId); + } catch (Throwable e) { + throw convertException(e, "Error while deleting tasks"); + } } - public UserConfigurationDataModel getUserConfigurationData(String experimentId) throws RegistryException { - return experimentRepository.getUserConfigurationData(experimentId); + public UserConfigurationDataModel getUserConfigurationData(String experimentId) throws RegistryServiceException { + try { + return experimentRepository.getUserConfigurationData(experimentId); + } catch (Throwable e) { + throw convertException(e, "Error while getting user configuration"); + } } - public ProcessModel getProcess(String processId) throws RegistryException { - return processRepository.getProcess(processId); + public ProcessModel getProcess(String processId) throws RegistryServiceException { + try { + return processRepository.getProcess(processId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving process"); + } } - public List getProcessList(String experimentId) throws RegistryException { - List processModels = processRepository.getProcessList( - Constants.FieldConstants.ExperimentConstants.EXPERIMENT_ID, experimentId); - return processModels; + public List getProcessList(String experimentId) throws RegistryServiceException { + try { + List processModels = processRepository.getProcessList( + Constants.FieldConstants.ExperimentConstants.EXPERIMENT_ID, experimentId); + return processModels; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving process list"); + } } - public ProcessStatus getProcessStatus(String processId) throws RegistryException { - return processStatusRepository.getProcessStatus(processId); + public ProcessStatus getProcessStatus(String processId) throws RegistryServiceException { + try { + return processStatusRepository.getProcessStatus(processId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving process status"); + } } - public List getProcessListInState(ProcessState processState) throws RegistryException { - List finalProcessList = new ArrayList<>(); - int offset = 0; - int limit = 100; - int count = 0; - do { - List processStatusList = - processStatusRepository.getProcessStatusList(processState, offset, limit); - offset += processStatusList.size(); - count = processStatusList.size(); - for (ProcessStatus processStatus : processStatusList) { - ProcessStatus latestStatus = processStatusRepository.getProcessStatus(processStatus.getProcessId()); - if (latestStatus.getState().name().equals(processState.name())) { - finalProcessList.add(processRepository.getProcess(latestStatus.getProcessId())); + public List getProcessListInState(ProcessState processState) throws RegistryServiceException { + try { + List finalProcessList = new ArrayList<>(); + int offset = 0; + int limit = 100; + int count = 0; + do { + List processStatusList = + processStatusRepository.getProcessStatusList(processState, offset, limit); + offset += processStatusList.size(); + count = processStatusList.size(); + for (ProcessStatus processStatus : processStatusList) { + ProcessStatus latestStatus = processStatusRepository.getProcessStatus(processStatus.getProcessId()); + if (latestStatus.getState().name().equals(processState.name())) { + finalProcessList.add(processRepository.getProcess(latestStatus.getProcessId())); + } } - } - } while (count == limit); - return finalProcessList; + } while (count == limit); + return finalProcessList; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving process list with given status"); + } } - public List getProcessStatusList(String processId) throws RegistryException { - return processStatusRepository.getProcessStatusList(processId); + public List getProcessStatusList(String processId) throws RegistryServiceException { + try { + return processStatusRepository.getProcessStatusList(processId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving process status list for given process Id"); + } } - private JobModel fetchJobModel(String queryType, String id) throws RegistryException { - if (queryType.equals(Constants.FieldConstants.JobConstants.TASK_ID)) { - List jobs = jobRepository.getJobList(Constants.FieldConstants.JobConstants.TASK_ID, id); - if (jobs != null) { - for (JobModel jobModel : jobs) { - if (jobModel.getJobId() != null || !jobModel.equals("")) { - return jobModel; + private JobModel fetchJobModel(String queryType, String id) throws RegistryServiceException { + try { + if (queryType.equals(Constants.FieldConstants.JobConstants.TASK_ID)) { + List jobs = jobRepository.getJobList(Constants.FieldConstants.JobConstants.TASK_ID, id); + if (jobs != null) { + for (JobModel jobModel : jobs) { + if (jobModel.getJobId() != null || !jobModel.equals("")) { + return jobModel; + } } } - } - } else if (queryType.equals(Constants.FieldConstants.JobConstants.PROCESS_ID)) { - List jobs = jobRepository.getJobList(Constants.FieldConstants.JobConstants.PROCESS_ID, id); - if (jobs != null) { - for (JobModel jobModel : jobs) { - if (jobModel.getJobId() != null || !jobModel.equals("")) { - return jobModel; + } else if (queryType.equals(Constants.FieldConstants.JobConstants.PROCESS_ID)) { + List jobs = jobRepository.getJobList(Constants.FieldConstants.JobConstants.PROCESS_ID, id); + if (jobs != null) { + for (JobModel jobModel : jobs) { + if (jobModel.getJobId() != null || !jobModel.equals("")) { + return jobModel; + } } } } + return null; + } catch (Throwable e) { + throw convertException(e, "Error while fetching job model"); } - return null; } - private List fetchJobModels(String queryType, String id) throws RegistryException { - List jobs = new ArrayList<>(); - switch (queryType) { - case Constants.FieldConstants.JobConstants.TASK_ID: - jobs = jobRepository.getJobList(Constants.FieldConstants.JobConstants.TASK_ID, id); - break; - case Constants.FieldConstants.JobConstants.PROCESS_ID: - jobs = jobRepository.getJobList(Constants.FieldConstants.JobConstants.PROCESS_ID, id); - break; - case Constants.FieldConstants.JobConstants.JOB_ID: - jobs = jobRepository.getJobList(Constants.FieldConstants.JobConstants.JOB_ID, id); - break; + private List fetchJobModels(String queryType, String id) throws RegistryServiceException { + try { + List jobs = new ArrayList<>(); + switch (queryType) { + case Constants.FieldConstants.JobConstants.TASK_ID: + jobs = jobRepository.getJobList(Constants.FieldConstants.JobConstants.TASK_ID, id); + break; + case Constants.FieldConstants.JobConstants.PROCESS_ID: + jobs = jobRepository.getJobList(Constants.FieldConstants.JobConstants.PROCESS_ID, id); + break; + case Constants.FieldConstants.JobConstants.JOB_ID: + jobs = jobRepository.getJobList(Constants.FieldConstants.JobConstants.JOB_ID, id); + break; + } + return jobs; + } catch (Throwable e) { + throw convertException(e, "Error while fetching job models"); } - return jobs; } - public boolean isJobExist(String queryType, String id) throws RegistryException { + public boolean isJobExist(String queryType, String id) throws RegistryServiceException { JobModel jobModel = fetchJobModel(queryType, id); return jobModel != null; } - public JobModel getJob(String queryType, String id) throws RegistryException { - JobModel jobModel = fetchJobModel(queryType, id); - if (jobModel != null) return jobModel; - throw new RegistryException("Job not found for queryType: " + queryType + ", id: " + id); + public JobModel getJob(String queryType, String id) throws RegistryServiceException { + try { + JobModel jobModel = fetchJobModel(queryType, id); + if (jobModel != null) return jobModel; + throw new RegistryException("Job not found for queryType: " + queryType + ", id: " + id); + } catch (Throwable e) { + throw convertException(e, "Error while getting job"); + } } - public List getJobs(String queryType, String id) throws RegistryException { - return fetchJobModels(queryType, id); + public List getJobs(String queryType, String id) throws RegistryServiceException { + try { + return fetchJobModels(queryType, id); + } catch (Throwable e) { + throw convertException(e, "Error while getting jobs"); + } } public int getJobCount( org.apache.airavata.model.status.JobStatus jobStatus, String gatewayId, double searchBackTimeInMinutes) - throws RegistryException { - List jobStatusList = jobStatusRepository.getDistinctListofJobStatus( - gatewayId, jobStatus.getJobState().name(), searchBackTimeInMinutes); - return jobStatusList.size(); + throws RegistryServiceException { + try { + List jobStatusList = jobStatusRepository.getDistinctListofJobStatus( + gatewayId, jobStatus.getJobState().name(), searchBackTimeInMinutes); + return jobStatusList.size(); + } catch (Throwable e) { + throw convertException(e, "Error while getting job count"); + } } public Map getAVGTimeDistribution(String gatewayId, double searchBackTimeInMinutes) - throws RegistryException { - return processRepository.getAVGTimeDistribution(gatewayId, searchBackTimeInMinutes); + throws RegistryServiceException { + try { + return processRepository.getAVGTimeDistribution(gatewayId, searchBackTimeInMinutes); + } catch (Throwable e) { + throw convertException(e, "Error while getting average time distribution"); + } } - public List getProcessOutputs(String processId) throws RegistryException { - return processOutputRepository.getProcessOutputs(processId); + public List getProcessOutputs(String processId) throws RegistryServiceException { + try { + return processOutputRepository.getProcessOutputs(processId); + } catch (Throwable e) { + throw convertException(e, "Error while getting process outputs"); + } } - public List getProcessWorkflows(String processId) throws RegistryException { - return processWorkflowRepository.getProcessWorkflows(processId); + public List getProcessWorkflows(String processId) throws RegistryServiceException { + try { + return processWorkflowRepository.getProcessWorkflows(processId); + } catch (Throwable e) { + throw convertException(e, "Error while getting process workflows"); + } } - public void addProcessWorkflow(ProcessWorkflow processWorkflow) throws RegistryException { - processWorkflowRepository.addProcessWorkflow(processWorkflow, processWorkflow.getProcessId()); + public void addProcessWorkflow(ProcessWorkflow processWorkflow) throws RegistryServiceException { + try { + processWorkflowRepository.addProcessWorkflow(processWorkflow, processWorkflow.getProcessId()); + } catch (Throwable e) { + throw convertException(e, "Error while adding process workflow"); + } } - public List getProcessIds(String experimentId) throws RegistryException { - return processRepository.getProcessIds(DBConstants.Process.EXPERIMENT_ID, experimentId); + public List getProcessIds(String experimentId) throws RegistryServiceException { + try { + return processRepository.getProcessIds(DBConstants.Process.EXPERIMENT_ID, experimentId); + } catch (Throwable e) { + throw convertException(e, "Error while getting process ids"); + } } - public List getJobDetails(String airavataExperimentId) throws RegistryException { - if (!experimentRepository.isExperimentExist(airavataExperimentId)) { - logger.error( - airavataExperimentId, - "Error while retrieving job details, experiment {} doesn't exist.", - airavataExperimentId); - throw new RegistryException( - "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); - } - List processModels = processRepository.getProcessList( - Constants.FieldConstants.ProcessConstants.EXPERIMENT_ID, airavataExperimentId); - List jobList = new ArrayList<>(); - if (processModels != null && !processModels.isEmpty()) { - for (ProcessModel processModel : processModels) { - List tasks = processModel.getTasks(); - if (tasks != null && !tasks.isEmpty()) { - for (TaskModel taskModel : tasks) { - String taskId = taskModel.getTaskId(); - List taskJobs = - jobRepository.getJobList(Constants.FieldConstants.JobConstants.TASK_ID, taskId); - jobList.addAll(taskJobs); + public List getJobDetails(String airavataExperimentId) throws RegistryServiceException { + try { + if (!experimentRepository.isExperimentExist(airavataExperimentId)) { + logger.error( + airavataExperimentId, + "Error while retrieving job details, experiment {} doesn't exist.", + airavataExperimentId); + throw new RegistryException( + "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); + } + List processModels = processRepository.getProcessList( + Constants.FieldConstants.ProcessConstants.EXPERIMENT_ID, airavataExperimentId); + List jobList = new ArrayList<>(); + if (processModels != null && !processModels.isEmpty()) { + for (ProcessModel processModel : processModels) { + List tasks = processModel.getTasks(); + if (tasks != null && !tasks.isEmpty()) { + for (TaskModel taskModel : tasks) { + String taskId = taskModel.getTaskId(); + List taskJobs = + jobRepository.getJobList(Constants.FieldConstants.JobConstants.TASK_ID, taskId); + jobList.addAll(taskJobs); + } } } } + logger.debug("Airavata retrieved job models for experiment with experiment id : " + airavataExperimentId); + return jobList; + } catch (Throwable e) { + throw convertException(e, "Error while getting job details"); } - logger.debug("Airavata retrieved job models for experiment with experiment id : " + airavataExperimentId); - return jobList; } private boolean validateString(String name) { @@ -614,98 +778,118 @@ private boolean validateString(String name) { return valid; } - public boolean isGatewayExistInternal(String gatewayId) throws RegistryException { - return gatewayRepository.isGatewayExist(gatewayId); + public boolean isGatewayExistInternal(String gatewayId) throws RegistryServiceException { + try { + return gatewayRepository.isGatewayExist(gatewayId); + } catch (Throwable e) { + throw convertException(e, "Error while checking if gateway exists"); + } } - public ApplicationModule getApplicationModule(String appModuleId) throws AppCatalogException { - ApplicationModule module = applicationInterfaceRepository.getApplicationModule(appModuleId); - logger.debug("Airavata retrieved application module with module id : " + appModuleId); - return module; + public ApplicationModule getApplicationModule(String appModuleId) throws RegistryServiceException { + try { + ApplicationModule module = applicationInterfaceRepository.getApplicationModule(appModuleId); + logger.debug("Airavata retrieved application module with module id : " + appModuleId); + return module; + } catch (Throwable e) { + throw convertException(e, "Error while getting application module"); + } } - public List getAllAppModules(String gatewayId) throws AppCatalogException { + public List getAllAppModules(String gatewayId) throws RegistryServiceException { try { if (!isGatewayExistInternal(gatewayId)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); + List moduleList = applicationInterfaceRepository.getAllApplicationModules(gatewayId); + logger.debug("Airavata retrieved modules for gateway id : " + gatewayId); + return moduleList; + } catch (Throwable e) { + throw convertException(e, "Error while getting all app modules"); } - List moduleList = applicationInterfaceRepository.getAllApplicationModules(gatewayId); - logger.debug("Airavata retrieved modules for gateway id : " + gatewayId); - return moduleList; } public List getAccessibleAppModules( String gatewayId, List accessibleAppIds, List accessibleComputeResourceIds) - throws AppCatalogException { + throws RegistryServiceException { try { if (!isGatewayExistInternal(gatewayId)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); + List moduleList = applicationInterfaceRepository.getAccessibleApplicationModules( + gatewayId, accessibleAppIds, accessibleComputeResourceIds); + logger.debug("Airavata retrieved modules for gateway id : " + gatewayId); + return moduleList; + } catch (Throwable e) { + throw convertException(e, "Error while getting accessible app modules"); } - List moduleList = applicationInterfaceRepository.getAccessibleApplicationModules( - gatewayId, accessibleAppIds, accessibleComputeResourceIds); - logger.debug("Airavata retrieved modules for gateway id : " + gatewayId); - return moduleList; } - public boolean deleteApplicationModule(String appModuleId) throws AppCatalogException { - logger.debug("Airavata deleted application module with module id : " + appModuleId); - return applicationInterfaceRepository.removeApplicationModule(appModuleId); + public boolean deleteApplicationModule(String appModuleId) throws RegistryServiceException { + try { + logger.debug("Airavata deleted application module with module id : " + appModuleId); + return applicationInterfaceRepository.removeApplicationModule(appModuleId); + } catch (Throwable e) { + throw convertException(e, "Error while deleting application module"); + } } public ApplicationDeploymentDescription getApplicationDeployment(String appDeploymentId) - throws AppCatalogException { - ApplicationDeploymentDescription deployement = + throws RegistryServiceException { + try { + ApplicationDeploymentDescription deployement = applicationDeploymentRepository.getApplicationDeployement(appDeploymentId); - logger.debug("Airavata registered application deployment for deployment id : " + appDeploymentId); - return deployement; + logger.debug("Airavata registered application deployment for deployment id : " + appDeploymentId); + return deployement; + } catch (Throwable e) { + throw convertException(e, "Error while getting application deployment"); + } } - public boolean deleteApplicationDeployment(String appDeploymentId) throws AppCatalogException { - applicationDeploymentRepository.removeAppDeployment(appDeploymentId); - logger.debug("Airavata removed application deployment with deployment id : " + appDeploymentId); - return true; + public boolean deleteApplicationDeployment(String appDeploymentId) throws RegistryServiceException { + try { + applicationDeploymentRepository.removeAppDeployment(appDeploymentId); + logger.debug("Airavata removed application deployment with deployment id : " + appDeploymentId); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while deleting application deployment"); + } } public List getAllApplicationDeployments(String gatewayId) - throws AppCatalogException { + throws RegistryServiceException { try { if (!isGatewayExistInternal(gatewayId)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); + List deployements = + applicationDeploymentRepository.getAllApplicationDeployements(gatewayId); + logger.debug("Airavata retrieved application deployments for gateway id : " + gatewayId); + return deployements; + } catch (Throwable e) { + throw convertException(e, "Error while getting all application deployments"); } - List deployements = - applicationDeploymentRepository.getAllApplicationDeployements(gatewayId); - logger.debug("Airavata retrieved application deployments for gateway id : " + gatewayId); - return deployements; } public List getAccessibleApplicationDeployments( String gatewayId, List accessibleAppDeploymentIds, List accessibleComputeResourceIds) - throws AppCatalogException { + throws RegistryServiceException { try { if (!isGatewayExistInternal(gatewayId)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); - } - List deployements = - applicationDeploymentRepository.getAccessibleApplicationDeployments( + List deployements = + applicationDeploymentRepository.getAccessibleApplicationDeployments( gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); - logger.debug("Airavata retrieved application deployments for gateway id : " + gatewayId); - return deployements; + logger.debug("Airavata retrieved application deployments for gateway id : " + gatewayId); + return deployements; + } catch (Throwable e) { + throw convertException(e, "Error while getting accessible application deployments"); + } } public List getAccessibleApplicationDeploymentsForAppModule( @@ -713,655 +897,851 @@ public List getAccessibleApplicationDeployment String appModuleId, List accessibleAppDeploymentIds, List accessibleComputeResourceIds) - throws AppCatalogException { + throws RegistryServiceException { try { if (!isGatewayExistInternal(gatewayId)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); + List deployments = + applicationDeploymentRepository.getAccessibleApplicationDeployments( + gatewayId, appModuleId, accessibleAppDeploymentIds, accessibleComputeResourceIds); + return deployments; + } catch (Throwable e) { + throw convertException(e, "Error while getting accessible application deployments for app module"); } - List deployments = - applicationDeploymentRepository.getAccessibleApplicationDeployments( - gatewayId, appModuleId, accessibleAppDeploymentIds, accessibleComputeResourceIds); - return deployments; } - public List getAppModuleDeployedResources(String appModuleId) throws AppCatalogException { - List appDeployments = new ArrayList<>(); - Map filters = new HashMap<>(); - filters.put(DBConstants.ApplicationDeployment.APPLICATION_MODULE_ID, appModuleId); - List applicationDeployments = - applicationDeploymentRepository.getApplicationDeployments(filters); - for (ApplicationDeploymentDescription description : applicationDeployments) { - appDeployments.add(description.getAppDeploymentId()); + public List getAppModuleDeployedResources(String appModuleId) throws RegistryServiceException { + try { + List appDeployments = new ArrayList<>(); + Map filters = new HashMap<>(); + filters.put(DBConstants.ApplicationDeployment.APPLICATION_MODULE_ID, appModuleId); + List applicationDeployments = + applicationDeploymentRepository.getApplicationDeployments(filters); + for (ApplicationDeploymentDescription description : applicationDeployments) { + appDeployments.add(description.getAppDeploymentId()); + } + logger.debug("Airavata retrieved application deployments for module id : " + appModuleId); + return appDeployments; + } catch (Throwable e) { + throw convertException(e, "Error while getting app module deployed resources"); } - logger.debug("Airavata retrieved application deployments for module id : " + appModuleId); - return appDeployments; } public List getApplicationDeployments(String appModuleId) - throws AppCatalogException { - Map filters = new HashMap<>(); - filters.put(DBConstants.ApplicationDeployment.APPLICATION_MODULE_ID, appModuleId); - List applicationDeployments = - applicationDeploymentRepository.getApplicationDeployments(filters); - return applicationDeployments; + throws RegistryServiceException { + try { + Map filters = new HashMap<>(); + filters.put(DBConstants.ApplicationDeployment.APPLICATION_MODULE_ID, appModuleId); + List applicationDeployments = + applicationDeploymentRepository.getApplicationDeployments(filters); + return applicationDeployments; + } catch (Throwable e) { + throw convertException(e, "Error while getting application deployments"); + } } - public ApplicationInterfaceDescription getApplicationInterface(String appInterfaceId) throws AppCatalogException { - ApplicationInterfaceDescription interfaceDescription = - applicationInterfaceRepository.getApplicationInterface(appInterfaceId); - logger.debug("Airavata retrieved application interface with interface id : " + appInterfaceId); - return interfaceDescription; + public ApplicationInterfaceDescription getApplicationInterface(String appInterfaceId) throws RegistryServiceException { + try { + ApplicationInterfaceDescription interfaceDescription = + applicationInterfaceRepository.getApplicationInterface(appInterfaceId); + logger.debug("Airavata retrieved application interface with interface id : " + appInterfaceId); + return interfaceDescription; + } catch (Throwable e) { + throw convertException(e, "Error while getting application interface"); + } } - public boolean deleteApplicationInterface(String appInterfaceId) throws AppCatalogException { - boolean removeApplicationInterface = applicationInterfaceRepository.removeApplicationInterface(appInterfaceId); - logger.debug("Airavata removed application interface with interface id : " + appInterfaceId); - return removeApplicationInterface; + public boolean deleteApplicationInterface(String appInterfaceId) throws RegistryServiceException { + try { + boolean removeApplicationInterface = applicationInterfaceRepository.removeApplicationInterface(appInterfaceId); + logger.debug("Airavata removed application interface with interface id : " + appInterfaceId); + return removeApplicationInterface; + } catch (Throwable e) { + throw convertException(e, "Error while deleting application interface"); + } } - public Map getAllApplicationInterfaceNames(String gatewayId) throws AppCatalogException { + public Map getAllApplicationInterfaceNames(String gatewayId) throws RegistryServiceException { try { if (!isGatewayExistInternal(gatewayId)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); - } - List allApplicationInterfaces = - applicationInterfaceRepository.getAllApplicationInterfaces(gatewayId); - Map allApplicationInterfacesMap = new HashMap<>(); - if (allApplicationInterfaces != null && !allApplicationInterfaces.isEmpty()) { - for (ApplicationInterfaceDescription interfaceDescription : allApplicationInterfaces) { - allApplicationInterfacesMap.put( - interfaceDescription.getApplicationInterfaceId(), interfaceDescription.getApplicationName()); + List allApplicationInterfaces = + applicationInterfaceRepository.getAllApplicationInterfaces(gatewayId); + Map allApplicationInterfacesMap = new HashMap<>(); + if (allApplicationInterfaces != null && !allApplicationInterfaces.isEmpty()) { + for (ApplicationInterfaceDescription interfaceDescription : allApplicationInterfaces) { + allApplicationInterfacesMap.put( + interfaceDescription.getApplicationInterfaceId(), interfaceDescription.getApplicationName()); + } } + logger.debug("Airavata retrieved application interfaces for gateway id : " + gatewayId); + return allApplicationInterfacesMap; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving all application interface names"); } - logger.debug("Airavata retrieved application interfaces for gateway id : " + gatewayId); - return allApplicationInterfacesMap; } public List getAllApplicationInterfaces(String gatewayId) - throws AppCatalogException { + throws RegistryServiceException { try { if (!isGatewayExistInternal(gatewayId)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); + List interfaces = + applicationInterfaceRepository.getAllApplicationInterfaces(gatewayId); + logger.debug("Airavata retrieved application interfaces for gateway id : " + gatewayId); + return interfaces; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving all application interfaces"); } - List interfaces = - applicationInterfaceRepository.getAllApplicationInterfaces(gatewayId); - logger.debug("Airavata retrieved application interfaces for gateway id : " + gatewayId); - return interfaces; } - public List getApplicationInputs(String appInterfaceId) throws AppCatalogException { - List applicationInputs = - applicationInterfaceRepository.getApplicationInputs(appInterfaceId); - logger.debug("Airavata retrieved application inputs for application interface id : " + appInterfaceId); - return applicationInputs; + public List getApplicationInputs(String appInterfaceId) throws RegistryServiceException { + try { + List applicationInputs = + applicationInterfaceRepository.getApplicationInputs(appInterfaceId); + logger.debug("Airavata retrieved application inputs for application interface id : " + appInterfaceId); + return applicationInputs; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving application inputs"); + } } - private List getApplicationOutputsInternal(String appInterfaceId) throws AppCatalogException { - List applicationOutputs = - applicationInterfaceRepository.getApplicationOutputs(appInterfaceId); - logger.debug("Airavata retrieved application outputs for application interface id : " + appInterfaceId); - return applicationOutputs; + private List getApplicationOutputsInternal(String appInterfaceId) throws RegistryServiceException { + try { + List applicationOutputs = + applicationInterfaceRepository.getApplicationOutputs(appInterfaceId); + logger.debug("Airavata retrieved application outputs for application interface id : " + appInterfaceId); + return applicationOutputs; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving application outputs"); + } } - public List getApplicationOutputs(String appInterfaceId) throws AppCatalogException { - List list = getApplicationOutputsInternal(appInterfaceId); - logger.debug("Airavata retrieved application outputs for app interface id : " + appInterfaceId); - return list; + public List getApplicationOutputs(String appInterfaceId) throws RegistryServiceException { + try { + List list = getApplicationOutputsInternal(appInterfaceId); + logger.debug("Airavata retrieved application outputs for app interface id : " + appInterfaceId); + return list; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving application outputs"); + } } public Map getAvailableAppInterfaceComputeResources(String appInterfaceId) - throws AppCatalogException { - Map allComputeResources = new ComputeResourceRepository().getAvailableComputeResourceIdList(); - Map availableComputeResources = new HashMap(); - ApplicationInterfaceDescription applicationInterface = - applicationInterfaceRepository.getApplicationInterface(appInterfaceId); - HashMap filters = new HashMap<>(); - List applicationModules = applicationInterface.getApplicationModules(); - if (applicationModules != null && !applicationModules.isEmpty()) { - for (String moduleId : applicationModules) { - filters.put(DBConstants.ApplicationDeployment.APPLICATION_MODULE_ID, moduleId); - List applicationDeployments = - applicationDeploymentRepository.getApplicationDeployments(filters); - for (ApplicationDeploymentDescription deploymentDescription : applicationDeployments) { - if (allComputeResources.get(deploymentDescription.getComputeHostId()) != null) { - availableComputeResources.put( - deploymentDescription.getComputeHostId(), - allComputeResources.get(deploymentDescription.getComputeHostId())); + throws RegistryServiceException { + try { + Map allComputeResources = new ComputeResourceRepository().getAvailableComputeResourceIdList(); + Map availableComputeResources = new HashMap(); + ApplicationInterfaceDescription applicationInterface = + applicationInterfaceRepository.getApplicationInterface(appInterfaceId); + HashMap filters = new HashMap<>(); + List applicationModules = applicationInterface.getApplicationModules(); + if (applicationModules != null && !applicationModules.isEmpty()) { + for (String moduleId : applicationModules) { + filters.put(DBConstants.ApplicationDeployment.APPLICATION_MODULE_ID, moduleId); + List applicationDeployments = + applicationDeploymentRepository.getApplicationDeployments(filters); + for (ApplicationDeploymentDescription deploymentDescription : applicationDeployments) { + if (allComputeResources.get(deploymentDescription.getComputeHostId()) != null) { + availableComputeResources.put( + deploymentDescription.getComputeHostId(), + allComputeResources.get(deploymentDescription.getComputeHostId())); + } } } } + logger.debug("Airavata retrieved available compute resources for application interface id : " + appInterfaceId); + return availableComputeResources; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving available app interface compute resources"); } - logger.debug("Airavata retrieved available compute resources for application interface id : " + appInterfaceId); - return availableComputeResources; } - public ComputeResourceDescription getComputeResource(String computeResourceId) throws AppCatalogException { - ComputeResourceDescription computeResource = - new ComputeResourceRepository().getComputeResource(computeResourceId); - logger.debug("Airavata retrieved compute resource with compute resource Id : " + computeResourceId); - return computeResource; + public ComputeResourceDescription getComputeResource(String computeResourceId) throws RegistryServiceException { + try { + ComputeResourceDescription computeResource = + new ComputeResourceRepository().getComputeResource(computeResourceId); + logger.debug("Airavata retrieved compute resource with compute resource Id : " + computeResourceId); + return computeResource; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving compute resource"); + } } - public Map getAllComputeResourceNames() throws AppCatalogException { - Map computeResourceIdList = new ComputeResourceRepository().getAllComputeResourceIdList(); - logger.debug("Airavata retrieved all the available compute resources..."); - return computeResourceIdList; + public Map getAllComputeResourceNames() throws RegistryServiceException { + try { + Map computeResourceIdList = new ComputeResourceRepository().getAllComputeResourceIdList(); + logger.debug("Airavata retrieved all the available compute resources..."); + return computeResourceIdList; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving all compute resource names"); + } } - public boolean deleteComputeResource(String computeResourceId) throws AppCatalogException { - new ComputeResourceRepository().removeComputeResource(computeResourceId); - logger.debug("Airavata deleted compute resource with compute resource Id : " + computeResourceId); - return true; + public boolean deleteComputeResource(String computeResourceId) throws RegistryServiceException { + try { + new ComputeResourceRepository().removeComputeResource(computeResourceId); + logger.debug("Airavata deleted compute resource with compute resource Id : " + computeResourceId); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while deleting compute resource"); + } } - public StorageResourceDescription getStorageResource(String storageResourceId) throws AppCatalogException { - StorageResourceDescription storageResource = storageResourceRepository.getStorageResource(storageResourceId); - logger.debug("Airavata retrieved storage resource with storage resource Id : " + storageResourceId); - return storageResource; + public StorageResourceDescription getStorageResource(String storageResourceId) throws RegistryServiceException { + try { + StorageResourceDescription storageResource = storageResourceRepository.getStorageResource(storageResourceId); + logger.debug("Airavata retrieved storage resource with storage resource Id : " + storageResourceId); + return storageResource; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving storage resource"); + } } - public Map getAllStorageResourceNames() throws AppCatalogException { - Map resourceIdList = storageResourceRepository.getAllStorageResourceIdList(); - logger.debug("Airavata retrieved storage resources list..."); - return resourceIdList; + public Map getAllStorageResourceNames() throws RegistryServiceException { + try { + Map resourceIdList = storageResourceRepository.getAllStorageResourceIdList(); + logger.debug("Airavata retrieved storage resources list..."); + return resourceIdList; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving all storage resource names"); + } } - public boolean deleteStorageResource(String storageResourceId) throws AppCatalogException { - storageResourceRepository.removeStorageResource(storageResourceId); - logger.debug("Airavata deleted storage resource with storage resource Id : " + storageResourceId); - return true; + public boolean deleteStorageResource(String storageResourceId) throws RegistryServiceException { + try { + storageResourceRepository.removeStorageResource(storageResourceId); + logger.debug("Airavata deleted storage resource with storage resource Id : " + storageResourceId); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while deleting storage resource"); + } } - public LOCALSubmission getLocalJobSubmission(String jobSubmissionId) throws AppCatalogException { - LOCALSubmission localJobSubmission = new ComputeResourceRepository().getLocalJobSubmission(jobSubmissionId); - logger.debug("Airavata retrieved local job submission for job submission interface id: " + jobSubmissionId); - return localJobSubmission; + public LOCALSubmission getLocalJobSubmission(String jobSubmissionId) throws RegistryServiceException { + try { + LOCALSubmission localJobSubmission = new ComputeResourceRepository().getLocalJobSubmission(jobSubmissionId); + logger.debug("Airavata retrieved local job submission for job submission interface id: " + jobSubmissionId); + return localJobSubmission; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving local job submission"); + } } - public SSHJobSubmission getSSHJobSubmission(String jobSubmissionId) throws AppCatalogException { - SSHJobSubmission sshJobSubmission = new ComputeResourceRepository().getSSHJobSubmission(jobSubmissionId); - logger.debug("Airavata retrieved SSH job submission for job submission interface id: " + jobSubmissionId); - return sshJobSubmission; + public SSHJobSubmission getSSHJobSubmission(String jobSubmissionId) throws RegistryServiceException { + try { + SSHJobSubmission sshJobSubmission = new ComputeResourceRepository().getSSHJobSubmission(jobSubmissionId); + logger.debug("Airavata retrieved SSH job submission for job submission interface id: " + jobSubmissionId); + return sshJobSubmission; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving SSH job submission"); + } } - public UnicoreJobSubmission getUnicoreJobSubmission(String jobSubmissionId) throws AppCatalogException { - UnicoreJobSubmission unicoreJobSubmission = - new ComputeResourceRepository().getUNICOREJobSubmission(jobSubmissionId); - logger.debug("Airavata retrieved UNICORE job submission for job submission interface id: " + jobSubmissionId); - return unicoreJobSubmission; + public UnicoreJobSubmission getUnicoreJobSubmission(String jobSubmissionId) throws RegistryServiceException { + try { + UnicoreJobSubmission unicoreJobSubmission = + new ComputeResourceRepository().getUNICOREJobSubmission(jobSubmissionId); + logger.debug("Airavata retrieved UNICORE job submission for job submission interface id: " + jobSubmissionId); + return unicoreJobSubmission; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving UNICORE job submission"); + } } - public CloudJobSubmission getCloudJobSubmission(String jobSubmissionId) throws AppCatalogException { - CloudJobSubmission cloudJobSubmission = new ComputeResourceRepository().getCloudJobSubmission(jobSubmissionId); - logger.debug("Airavata retrieved cloud job submission for job submission interface id: " + jobSubmissionId); - return cloudJobSubmission; + public CloudJobSubmission getCloudJobSubmission(String jobSubmissionId) throws RegistryServiceException { + try { + CloudJobSubmission cloudJobSubmission = new ComputeResourceRepository().getCloudJobSubmission(jobSubmissionId); + logger.debug("Airavata retrieved cloud job submission for job submission interface id: " + jobSubmissionId); + return cloudJobSubmission; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving cloud job submission"); + } } public boolean changeJobSubmissionPriority(String jobSubmissionInterfaceId, int newPriorityOrder) - throws RegistryException { + throws RegistryServiceException { return false; } public boolean changeDataMovementPriority(String dataMovementInterfaceId, int newPriorityOrder) - throws RegistryException { + throws RegistryServiceException { return false; } public boolean changeJobSubmissionPriorities(Map jobSubmissionPriorityMap) - throws RegistryException { + throws RegistryServiceException { return false; } - public boolean changeDataMovementPriorities(Map dataMovementPriorityMap) throws RegistryException { + public boolean changeDataMovementPriorities(Map dataMovementPriorityMap) throws RegistryServiceException { return false; } public boolean deleteJobSubmissionInterface(String computeResourceId, String jobSubmissionInterfaceId) - throws AppCatalogException { - new ComputeResourceRepository().removeJobSubmissionInterface(computeResourceId, jobSubmissionInterfaceId); - logger.debug("Airavata deleted job submission interface with interface id : " + jobSubmissionInterfaceId); - return true; + throws RegistryServiceException { + try { + new ComputeResourceRepository().removeJobSubmissionInterface(computeResourceId, jobSubmissionInterfaceId); + logger.debug("Airavata deleted job submission interface with interface id : " + jobSubmissionInterfaceId); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while deleting job submission interface"); + } } - public ResourceJobManager getResourceJobManager(String resourceJobManagerId) throws AppCatalogException { - return new ComputeResourceRepository().getResourceJobManager(resourceJobManagerId); + public ResourceJobManager getResourceJobManager(String resourceJobManagerId) throws RegistryServiceException { + try { + return new ComputeResourceRepository().getResourceJobManager(resourceJobManagerId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving resource job manager"); + } } - public boolean deleteResourceJobManager(String resourceJobManagerId) throws AppCatalogException { - new ComputeResourceRepository().deleteResourceJobManager(resourceJobManagerId); - return true; + public boolean deleteResourceJobManager(String resourceJobManagerId) throws RegistryServiceException { + try { + new ComputeResourceRepository().deleteResourceJobManager(resourceJobManagerId); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while deleting resource job manager"); + } } - public boolean deleteBatchQueue(String computeResourceId, String queueName) throws AppCatalogException { - new ComputeResourceRepository().removeBatchQueue(computeResourceId, queueName); - return true; + public boolean deleteBatchQueue(String computeResourceId, String queueName) throws RegistryServiceException { + try { + new ComputeResourceRepository().removeBatchQueue(computeResourceId, queueName); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while deleting batch queue"); + } } - public GatewayResourceProfile getGatewayResourceProfile(String gatewayID) throws AppCatalogException { + public GatewayResourceProfile getGatewayResourceProfile(String gatewayID) throws RegistryServiceException { try { if (!isGatewayExistInternal(gatewayID)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); + GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); + GatewayResourceProfile gatewayResourceProfile = gwyResourceProfileRepository.getGatewayProfile(gatewayID); + logger.debug("Airavata retrieved gateway profile with gateway id : " + gatewayID); + return gatewayResourceProfile; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving gateway resource profile"); } - GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); - GatewayResourceProfile gatewayResourceProfile = gwyResourceProfileRepository.getGatewayProfile(gatewayID); - logger.debug("Airavata retrieved gateway profile with gateway id : " + gatewayID); - return gatewayResourceProfile; } - public boolean deleteGatewayResourceProfile(String gatewayID) throws AppCatalogException { + public boolean deleteGatewayResourceProfile(String gatewayID) throws RegistryServiceException { try { if (!isGatewayExistInternal(gatewayID)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); + GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); + gwyResourceProfileRepository.delete(gatewayID); + logger.debug("Airavata deleted gateway profile with gateway id : " + gatewayID); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while deleting gateway resource profile"); } - GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); - gwyResourceProfileRepository.delete(gatewayID); - logger.debug("Airavata deleted gateway profile with gateway id : " + gatewayID); - return true; } public ComputeResourcePreference getGatewayComputeResourcePreference(String gatewayID, String computeResourceId) - throws AppCatalogException { + throws RegistryServiceException { try { if (!isGatewayExistInternal(gatewayID)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); - } - GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); - ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); - if (!gwyResourceProfileRepository.isGatewayResourceProfileExists(gatewayID)) { - logger.error( - gatewayID, - "Given gateway profile does not exist in the system. Please provide a valid gateway id..."); - throw new AppCatalogException( - "Given gateway profile does not exist in the system. Please provide a valid gateway id..."); - } - if (!computeResourceRepository.isComputeResourceExists(computeResourceId)) { - logger.error( - computeResourceId, - "Given compute resource does not exist in the system. Please provide a valid compute resource id..."); - throw new AppCatalogException( - "Given compute resource does not exist in the system. Please provide a valid compute resource id..."); + GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); + ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); + if (!gwyResourceProfileRepository.isGatewayResourceProfileExists(gatewayID)) { + logger.error( + gatewayID, + "Given gateway profile does not exist in the system. Please provide a valid gateway id..."); + throw new AppCatalogException( + "Given gateway profile does not exist in the system. Please provide a valid gateway id..."); + } + if (!computeResourceRepository.isComputeResourceExists(computeResourceId)) { + logger.error( + computeResourceId, + "Given compute resource does not exist in the system. Please provide a valid compute resource id..."); + throw new AppCatalogException( + "Given compute resource does not exist in the system. Please provide a valid compute resource id..."); + } + ComputeResourcePreference computeResourcePreference = + gwyResourceProfileRepository.getComputeResourcePreference(gatewayID, computeResourceId); + logger.debug("Airavata retrieved gateway compute resource preference with gateway id : " + gatewayID + + " and for compute resoruce id : " + computeResourceId); + return computeResourcePreference; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving gateway compute resource preference"); } - ComputeResourcePreference computeResourcePreference = - gwyResourceProfileRepository.getComputeResourcePreference(gatewayID, computeResourceId); - logger.debug("Airavata retrieved gateway compute resource preference with gateway id : " + gatewayID - + " and for compute resoruce id : " + computeResourceId); - return computeResourcePreference; } public StoragePreference getGatewayStoragePreference(String gatewayID, String storageId) - throws AppCatalogException { + throws RegistryServiceException { try { if (!isGatewayExistInternal(gatewayID)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); - } - GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); - if (!gwyResourceProfileRepository.isGatewayResourceProfileExists(gatewayID)) { - logger.error( - gatewayID, - "Given gateway profile does not exist in the system. Please provide a valid gateway id..."); - throw new AppCatalogException( - "Given gateway profile does not exist in the system. Please provide a valid gateway id..."); + GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); + if (!gwyResourceProfileRepository.isGatewayResourceProfileExists(gatewayID)) { + logger.error( + gatewayID, + "Given gateway profile does not exist in the system. Please provide a valid gateway id..."); + throw new AppCatalogException( + "Given gateway profile does not exist in the system. Please provide a valid gateway id..."); + } + StoragePreference storagePreference = gwyResourceProfileRepository.getStoragePreference(gatewayID, storageId); + logger.debug("Airavata retrieved storage resource preference with gateway id : " + gatewayID + + " and for storage resource id : " + storageId); + return storagePreference; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving gateway storage preference"); } - StoragePreference storagePreference = gwyResourceProfileRepository.getStoragePreference(gatewayID, storageId); - logger.debug("Airavata retrieved storage resource preference with gateway id : " + gatewayID - + " and for storage resource id : " + storageId); - return storagePreference; } public List getAllGatewayComputeResourcePreferences(String gatewayID) - throws AppCatalogException { + throws RegistryServiceException { try { if (!isGatewayExistInternal(gatewayID)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); + GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); + return gwyResourceProfileRepository.getGatewayProfile(gatewayID).getComputeResourcePreferences(); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving all gateway compute resource preferences"); } - GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); - return gwyResourceProfileRepository.getGatewayProfile(gatewayID).getComputeResourcePreferences(); } - public List getAllGatewayStoragePreferences(String gatewayID) throws AppCatalogException { + public List getAllGatewayStoragePreferences(String gatewayID) throws RegistryServiceException { try { if (!isGatewayExistInternal(gatewayID)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); + GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); + return gwyResourceProfileRepository.getGatewayProfile(gatewayID).getStoragePreferences(); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving all gateway storage preferences"); } - GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); - return gwyResourceProfileRepository.getGatewayProfile(gatewayID).getStoragePreferences(); } - public List getAllGatewayResourceProfiles() throws AppCatalogException { - GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); - return gwyResourceProfileRepository.getAllGatewayProfiles(); + public List getAllGatewayResourceProfiles() throws RegistryServiceException { + try { + GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); + return gwyResourceProfileRepository.getAllGatewayProfiles(); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving all gateway resource profiles"); + } } public boolean deleteGatewayComputeResourcePreference(String gatewayID, String computeResourceId) - throws AppCatalogException { + throws RegistryServiceException { try { if (!isGatewayExistInternal(gatewayID)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); + GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); + return gwyResourceProfileRepository.removeComputeResourcePreferenceFromGateway(gatewayID, computeResourceId); + } catch (Throwable e) { + throw convertException(e, "Error while deleting gateway compute resource preference"); } - GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); - return gwyResourceProfileRepository.removeComputeResourcePreferenceFromGateway(gatewayID, computeResourceId); } - public boolean deleteGatewayStoragePreference(String gatewayID, String storageId) throws AppCatalogException { + public boolean deleteGatewayStoragePreference(String gatewayID, String storageId) throws RegistryServiceException { try { if (!isGatewayExistInternal(gatewayID)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); + GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); + return gwyResourceProfileRepository.removeDataStoragePreferenceFromGateway(gatewayID, storageId); + } catch (Throwable e) { + throw convertException(e, "Error while deleting gateway storage preference"); } - GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); - return gwyResourceProfileRepository.removeDataStoragePreferenceFromGateway(gatewayID, storageId); } - public DataProductModel getDataProduct(String productUri) throws RegistryException { - DataProductModel dataProductModel = dataProductRepository.getDataProduct(productUri); - return dataProductModel; + public DataProductModel getDataProduct(String productUri) throws RegistryServiceException { + try { + DataProductModel dataProductModel = dataProductRepository.getDataProduct(productUri); + return dataProductModel; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving data product"); + } } - public DataProductModel getParentDataProduct(String productUri) throws RegistryException { - DataProductModel dataProductModel = dataProductRepository.getParentDataProduct(productUri); - return dataProductModel; + public DataProductModel getParentDataProduct(String productUri) throws RegistryServiceException { + try { + DataProductModel dataProductModel = dataProductRepository.getParentDataProduct(productUri); + return dataProductModel; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving parent data product"); + } } - public List getChildDataProducts(String productUri) throws RegistryException { - List dataProductModels = dataProductRepository.getChildDataProducts(productUri); - return dataProductModels; + public List getChildDataProducts(String productUri) throws RegistryServiceException { + try { + List dataProductModels = dataProductRepository.getChildDataProducts(productUri); + return dataProductModels; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving child data products"); + } } public List searchDataProductsByName( - String gatewayId, String userId, String productName, int limit, int offset) throws RegistryException { - List dataProductModels = - dataProductRepository.searchDataProductsByName(gatewayId, userId, productName, limit, offset); - return dataProductModels; + String gatewayId, String userId, String productName, int limit, int offset) throws RegistryServiceException { + try { + List dataProductModels = + dataProductRepository.searchDataProductsByName(gatewayId, userId, productName, limit, offset); + return dataProductModels; + } catch (Throwable e) { + throw convertException(e, "Error while searching data products by name"); + } } - public String createGroupResourceProfile(GroupResourceProfile groupResourceProfile) throws AppCatalogException { + public String createGroupResourceProfile(GroupResourceProfile groupResourceProfile) throws RegistryServiceException { try { if (!isGatewayExistInternal(groupResourceProfile.getGatewayId())) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); + GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); + String groupResourceProfileId = groupResourceProfileRepository.addGroupResourceProfile(groupResourceProfile); + logger.debug("New Group Resource Profile Created: " + groupResourceProfileId); + return groupResourceProfileId; + } catch (Throwable e) { + throw convertException(e, "Error while creating group resource profile"); } - GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); - String groupResourceProfileId = groupResourceProfileRepository.addGroupResourceProfile(groupResourceProfile); - logger.debug("New Group Resource Profile Created: " + groupResourceProfileId); - return groupResourceProfileId; } - public void updateGroupResourceProfile(GroupResourceProfile groupResourceProfile) throws AppCatalogException { - GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); - if (!groupResourceProfileRepository.isGroupResourceProfileExists( - groupResourceProfile.getGroupResourceProfileId())) { - logger.error( - "Cannot update. No group resource profile found with matching gatewayId and groupResourceProfileId"); - throw new AppCatalogException( - "Cannot update. No group resource profile found with matching gatewayId and groupResourceProfileId"); + public void updateGroupResourceProfile(GroupResourceProfile groupResourceProfile) throws RegistryServiceException { + try { + GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); + if (!groupResourceProfileRepository.isGroupResourceProfileExists( + groupResourceProfile.getGroupResourceProfileId())) { + logger.error( + "Cannot update. No group resource profile found with matching gatewayId and groupResourceProfileId"); + throw new AppCatalogException( + "Cannot update. No group resource profile found with matching gatewayId and groupResourceProfileId"); + } + String groupResourceProfileId = groupResourceProfileRepository.updateGroupResourceProfile(groupResourceProfile); + logger.debug(" Group Resource Profile updated: " + groupResourceProfileId); + } catch (Throwable e) { + throw convertException(e, "Error while updating group resource profile"); } - String groupResourceProfileId = groupResourceProfileRepository.updateGroupResourceProfile(groupResourceProfile); - logger.debug(" Group Resource Profile updated: " + groupResourceProfileId); } - public GroupResourceProfile getGroupResourceProfile(String groupResourceProfileId) throws AppCatalogException { - GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); - if (!groupResourceProfileRepository.isGroupResourceProfileExists(groupResourceProfileId)) { - logger.error("No group resource profile found with matching gatewayId and groupResourceProfileId"); - throw new AppCatalogException( - "No group resource profile found with matching gatewayId and groupResourceProfileId"); + public GroupResourceProfile getGroupResourceProfile(String groupResourceProfileId) throws RegistryServiceException { + try { + GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); + if (!groupResourceProfileRepository.isGroupResourceProfileExists(groupResourceProfileId)) { + logger.error("No group resource profile found with matching gatewayId and groupResourceProfileId"); + throw new AppCatalogException( + "No group resource profile found with matching gatewayId and groupResourceProfileId"); + } + return groupResourceProfileRepository.getGroupResourceProfile(groupResourceProfileId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving group resource profile"); } - return groupResourceProfileRepository.getGroupResourceProfile(groupResourceProfileId); } - public boolean isGroupResourceProfileExists(String groupResourceProfileId) throws AppCatalogException { - GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); - return groupResourceProfileRepository.isGroupResourceProfileExists(groupResourceProfileId); + public boolean isGroupResourceProfileExists(String groupResourceProfileId) throws RegistryServiceException { + try { + GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); + return groupResourceProfileRepository.isGroupResourceProfileExists(groupResourceProfileId); + } catch (Throwable e) { + throw convertException(e, "Error while checking if group resource profile exists"); + } } - public boolean removeGroupResourceProfile(String groupResourceProfileId) throws AppCatalogException { - GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); - if (!groupResourceProfileRepository.isGroupResourceProfileExists(groupResourceProfileId)) { - logger.error( - "Cannot Remove. No group resource profile found with matching gatewayId and groupResourceProfileId"); - throw new AppCatalogException( - "Cannot Remove. No group resource profile found with matching gatewayId and groupResourceProfileId"); + public boolean removeGroupResourceProfile(String groupResourceProfileId) throws RegistryServiceException { + try { + GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); + if (!groupResourceProfileRepository.isGroupResourceProfileExists(groupResourceProfileId)) { + logger.error( + "Cannot Remove. No group resource profile found with matching gatewayId and groupResourceProfileId"); + throw new AppCatalogException( + "Cannot Remove. No group resource profile found with matching gatewayId and groupResourceProfileId"); + } + return groupResourceProfileRepository.removeGroupResourceProfile(groupResourceProfileId); + } catch (Throwable e) { + throw convertException(e, "Error while removing group resource profile"); } - return groupResourceProfileRepository.removeGroupResourceProfile(groupResourceProfileId); } public List getGroupResourceList(String gatewayId, List accessibleGroupResProfileIds) - throws AppCatalogException { - GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); - return groupResourceProfileRepository.getAllGroupResourceProfiles(gatewayId, accessibleGroupResProfileIds); + throws RegistryServiceException { + try { + GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); + return groupResourceProfileRepository.getAllGroupResourceProfiles(gatewayId, accessibleGroupResProfileIds); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving group resource list"); + } } public boolean removeGroupComputePrefs(String computeResourceId, String groupResourceProfileId) - throws AppCatalogException { - GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); - groupResourceProfileRepository.removeGroupComputeResourcePreference(computeResourceId, groupResourceProfileId); - logger.debug("Removed compute resource preferences with compute resource ID: " + computeResourceId); - return true; + throws RegistryServiceException { + try { + GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); + groupResourceProfileRepository.removeGroupComputeResourcePreference(computeResourceId, groupResourceProfileId); + logger.debug("Removed compute resource preferences with compute resource ID: " + computeResourceId); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while removing group compute preferences"); + } } - public boolean removeGroupComputeResourcePolicy(String resourcePolicyId) throws AppCatalogException { - GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); - groupResourceProfileRepository.removeComputeResourcePolicy(resourcePolicyId); - logger.debug("Removed compute resource policy with resource policy ID: " + resourcePolicyId); - return true; + public boolean removeGroupComputeResourcePolicy(String resourcePolicyId) throws RegistryServiceException { + try { + GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); + groupResourceProfileRepository.removeComputeResourcePolicy(resourcePolicyId); + logger.debug("Removed compute resource policy with resource policy ID: " + resourcePolicyId); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while removing group compute resource policy"); + } } - public boolean removeGroupBatchQueueResourcePolicy(String resourcePolicyId) throws AppCatalogException { - GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); - groupResourceProfileRepository.removeBatchQueueResourcePolicy(resourcePolicyId); - logger.debug("Removed batch resource policy with resource policy ID: " + resourcePolicyId); - return true; + public boolean removeGroupBatchQueueResourcePolicy(String resourcePolicyId) throws RegistryServiceException { + try { + GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); + groupResourceProfileRepository.removeBatchQueueResourcePolicy(resourcePolicyId); + logger.debug("Removed batch resource policy with resource policy ID: " + resourcePolicyId); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while removing group batch queue resource policy"); + } } public GroupComputeResourcePreference getGroupComputeResourcePreference( - String computeResourceId, String groupResourceProfileId) throws AppCatalogException { - GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); - GroupComputeResourcePreference groupComputeResourcePreference = - groupResourceProfileRepository.getGroupComputeResourcePreference( - computeResourceId, groupResourceProfileId); - if (!(groupComputeResourcePreference != null)) { - logger.error("GroupComputeResourcePreference not found"); - throw new AppCatalogException("GroupComputeResourcePreference not found "); + String computeResourceId, String groupResourceProfileId) throws RegistryServiceException { + try { + GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); + GroupComputeResourcePreference groupComputeResourcePreference = + groupResourceProfileRepository.getGroupComputeResourcePreference( + computeResourceId, groupResourceProfileId); + if (!(groupComputeResourcePreference != null)) { + logger.error("GroupComputeResourcePreference not found"); + throw new AppCatalogException("GroupComputeResourcePreference not found "); + } + return groupComputeResourcePreference; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving group compute resource preference"); } - return groupComputeResourcePreference; } public boolean isGroupComputeResourcePreferenceExists(String computeResourceId, String groupResourceProfileId) - throws AppCatalogException { - GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); - return groupResourceProfileRepository.isGroupComputeResourcePreferenceExists( - computeResourceId, groupResourceProfileId); + throws RegistryServiceException { + try { + GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); + return groupResourceProfileRepository.isGroupComputeResourcePreferenceExists( + computeResourceId, groupResourceProfileId); + } catch (Throwable e) { + throw convertException(e, "Error while checking if group compute resource preference exists"); + } } - public ComputeResourcePolicy getGroupComputeResourcePolicy(String resourcePolicyId) throws AppCatalogException { - GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); - ComputeResourcePolicy computeResourcePolicy = - groupResourceProfileRepository.getComputeResourcePolicy(resourcePolicyId); - if (!(computeResourcePolicy != null)) { - logger.error("Group Compute Resource policy not found"); - throw new AppCatalogException("Group Compute Resource policy not found "); + public ComputeResourcePolicy getGroupComputeResourcePolicy(String resourcePolicyId) throws RegistryServiceException { + try { + GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); + ComputeResourcePolicy computeResourcePolicy = + groupResourceProfileRepository.getComputeResourcePolicy(resourcePolicyId); + if (!(computeResourcePolicy != null)) { + logger.error("Group Compute Resource policy not found"); + throw new AppCatalogException("Group Compute Resource policy not found "); + } + return computeResourcePolicy; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving group compute resource policy"); } - return computeResourcePolicy; } - public BatchQueueResourcePolicy getBatchQueueResourcePolicy(String resourcePolicyId) throws AppCatalogException { - GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); - BatchQueueResourcePolicy batchQueueResourcePolicy = - groupResourceProfileRepository.getBatchQueueResourcePolicy(resourcePolicyId); - if (!(batchQueueResourcePolicy != null)) { - logger.error("Group Batch Queue Resource policy not found"); - throw new AppCatalogException("Group Batch Queue Resource policy not found "); + public BatchQueueResourcePolicy getBatchQueueResourcePolicy(String resourcePolicyId) throws RegistryServiceException { + try { + GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); + BatchQueueResourcePolicy batchQueueResourcePolicy = + groupResourceProfileRepository.getBatchQueueResourcePolicy(resourcePolicyId); + if (!(batchQueueResourcePolicy != null)) { + logger.error("Group Batch Queue Resource policy not found"); + throw new AppCatalogException("Group Batch Queue Resource policy not found "); + } + return batchQueueResourcePolicy; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving batch queue resource policy"); } - return batchQueueResourcePolicy; } public List getGroupComputeResourcePrefList(String groupResourceProfileId) - throws AppCatalogException { - GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); - return groupResourceProfileRepository.getAllGroupComputeResourcePreferences(groupResourceProfileId); + throws RegistryServiceException { + try { + GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); + return groupResourceProfileRepository.getAllGroupComputeResourcePreferences(groupResourceProfileId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving group compute resource preference list"); + } } public List getGroupBatchQueueResourcePolicyList(String groupResourceProfileId) - throws AppCatalogException { - GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); - return groupResourceProfileRepository.getAllGroupBatchQueueResourcePolicies(groupResourceProfileId); + throws RegistryServiceException { + try { + GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); + return groupResourceProfileRepository.getAllGroupBatchQueueResourcePolicies(groupResourceProfileId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving group batch queue resource policy list"); + } } public List getGroupComputeResourcePolicyList(String groupResourceProfileId) - throws AppCatalogException { - GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); - return groupResourceProfileRepository.getAllGroupComputeResourcePolicies(groupResourceProfileId); + throws RegistryServiceException { + try { + GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); + return groupResourceProfileRepository.getAllGroupComputeResourcePolicies(groupResourceProfileId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving group compute resource policy list"); + } } - public String registerReplicaLocation(DataReplicaLocationModel replicaLocationModel) throws RegistryException { - String replicaId = dataReplicaLocationRepository.registerReplicaLocation(replicaLocationModel); - return replicaId; + public String registerReplicaLocation(DataReplicaLocationModel replicaLocationModel) throws RegistryServiceException { + try { + String replicaId = dataReplicaLocationRepository.registerReplicaLocation(replicaLocationModel); + return replicaId; + } catch (Throwable e) { + throw convertException(e, "Error in retreiving the replica " + replicaLocationModel.getReplicaName()); + } } - public String registerDataProduct(DataProductModel dataProductModel) throws RegistryException { - String productUrl = dataProductRepository.registerDataProduct(dataProductModel); - return productUrl; + public String registerDataProduct(DataProductModel dataProductModel) throws RegistryServiceException { + try { + String productUrl = dataProductRepository.registerDataProduct(dataProductModel); + return productUrl; + } catch (Throwable e) { + throw convertException(e, "Error in registering the data resource" + dataProductModel.getProductName()); + } } - public LOCALDataMovement getLocalDataMovement(String dataMovementId) throws AppCatalogException { - LOCALDataMovement localDataMovement = new ComputeResourceRepository().getLocalDataMovement(dataMovementId); - logger.debug("Airavata retrieved local data movement with data movement id: " + dataMovementId); - return localDataMovement; + public LOCALDataMovement getLocalDataMovement(String dataMovementId) throws RegistryServiceException { + try { + LOCALDataMovement localDataMovement = new ComputeResourceRepository().getLocalDataMovement(dataMovementId); + logger.debug("Airavata retrieved local data movement with data movement id: " + dataMovementId); + return localDataMovement; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving local data movement"); + } } - public SCPDataMovement getSCPDataMovement(String dataMovementId) throws AppCatalogException { - SCPDataMovement scpDataMovement = new ComputeResourceRepository().getSCPDataMovement(dataMovementId); - logger.debug("Airavata retrieved SCP data movement with data movement id: " + dataMovementId); - return scpDataMovement; + public SCPDataMovement getSCPDataMovement(String dataMovementId) throws RegistryServiceException { + try { + SCPDataMovement scpDataMovement = new ComputeResourceRepository().getSCPDataMovement(dataMovementId); + logger.debug("Airavata retrieved SCP data movement with data movement id: " + dataMovementId); + return scpDataMovement; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving SCP data movement"); + } } - public UnicoreDataMovement getUnicoreDataMovement(String dataMovementId) throws AppCatalogException { - UnicoreDataMovement unicoreDataMovement = - new ComputeResourceRepository().getUNICOREDataMovement(dataMovementId); - logger.debug("Airavata retrieved UNICORE data movement with data movement id: " + dataMovementId); - return unicoreDataMovement; + public UnicoreDataMovement getUnicoreDataMovement(String dataMovementId) throws RegistryServiceException { + try { + UnicoreDataMovement unicoreDataMovement = + new ComputeResourceRepository().getUNICOREDataMovement(dataMovementId); + logger.debug("Airavata retrieved UNICORE data movement with data movement id: " + dataMovementId); + return unicoreDataMovement; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving UNICORE data movement"); + } } - public GridFTPDataMovement getGridFTPDataMovement(String dataMovementId) throws AppCatalogException { - GridFTPDataMovement gridFTPDataMovement = - new ComputeResourceRepository().getGridFTPDataMovement(dataMovementId); - logger.debug("Airavata retrieved GRIDFTP data movement with data movement id: " + dataMovementId); - return gridFTPDataMovement; + public GridFTPDataMovement getGridFTPDataMovement(String dataMovementId) throws RegistryServiceException { + try { + GridFTPDataMovement gridFTPDataMovement = + new ComputeResourceRepository().getGridFTPDataMovement(dataMovementId); + logger.debug("Airavata retrieved GRIDFTP data movement with data movement id: " + dataMovementId); + return gridFTPDataMovement; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving GRIDFTP data movement"); + } } // Experiment operations - public String createExperiment(String gatewayId, ExperimentModel experiment) throws RegistryException { - if (!validateString(experiment.getExperimentName())) { - logger.error("Cannot create experiments with empty experiment name"); - throw new RegistryException("Cannot create experiments with empty experiment name"); - } - logger.info("Creating experiment with name " + experiment.getExperimentName()); - if (!isGatewayExistInternal(gatewayId)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new RegistryException("Gateway does not exist.Please provide a valid gateway id..."); - } + public String createExperiment(String gatewayId, ExperimentModel experiment) throws RegistryServiceException { + try { + if (!validateString(experiment.getExperimentName())) { + logger.error("Cannot create experiments with empty experiment name"); + throw new RegistryException("Cannot create experiments with empty experiment name"); + } + logger.info("Creating experiment with name " + experiment.getExperimentName()); + if (!isGatewayExistInternal(gatewayId)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new RegistryException("Gateway does not exist.Please provide a valid gateway id..."); + } - if (experiment.getUserConfigurationData() != null - && experiment.getUserConfigurationData().getComputationalResourceScheduling() != null - && experiment.getUserConfigurationData() - .getComputationalResourceScheduling() - .getResourceHostId() - != null) { + if (experiment.getUserConfigurationData() != null + && experiment.getUserConfigurationData().getComputationalResourceScheduling() != null + && experiment.getUserConfigurationData() + .getComputationalResourceScheduling() + .getResourceHostId() + != null) { - String compResourceId = experiment - .getUserConfigurationData() - .getComputationalResourceScheduling() - .getResourceHostId(); - try { - ComputeResourceDescription computeResourceDescription = - new ComputeResourceRepository().getComputeResource(compResourceId); - if (!computeResourceDescription.isEnabled()) { - logger.error("Compute Resource is not enabled by the Admin!"); - throw new RegistryException("Compute Resource is not enabled by the Admin!"); - } - } catch (AppCatalogException e) { - throw new RegistryException("Error checking compute resource: " + e.getMessage(), e); - } - } else if (experiment.getUserConfigurationData() != null - && !experiment + String compResourceId = experiment .getUserConfigurationData() - .getAutoScheduledCompResourceSchedulingList() - .isEmpty()) { - for (ComputationalResourceSchedulingModel computationalResourceScheduling : - experiment.getUserConfigurationData().getAutoScheduledCompResourceSchedulingList()) { + .getComputationalResourceScheduling() + .getResourceHostId(); try { - ComputeResourceDescription computeResourceDescription = new ComputeResourceRepository() - .getComputeResource(computationalResourceScheduling.getResourceHostId()); + ComputeResourceDescription computeResourceDescription = + new ComputeResourceRepository().getComputeResource(compResourceId); if (!computeResourceDescription.isEnabled()) { - logger.error("Compute Resource with id" + computationalResourceScheduling.getResourceHostId() - + "" + " is not enabled by the Admin!"); - throw new RegistryException( - "Compute Resource with id" + computationalResourceScheduling.getResourceHostId() + "" - + " is not enabled by the Admin!"); + logger.error("Compute Resource is not enabled by the Admin!"); + throw new RegistryException("Compute Resource is not enabled by the Admin!"); } } catch (AppCatalogException e) { throw new RegistryException("Error checking compute resource: " + e.getMessage(), e); } + } else if (experiment.getUserConfigurationData() != null + && !experiment + .getUserConfigurationData() + .getAutoScheduledCompResourceSchedulingList() + .isEmpty()) { + for (ComputationalResourceSchedulingModel computationalResourceScheduling : + experiment.getUserConfigurationData().getAutoScheduledCompResourceSchedulingList()) { + try { + ComputeResourceDescription computeResourceDescription = new ComputeResourceRepository() + .getComputeResource(computationalResourceScheduling.getResourceHostId()); + if (!computeResourceDescription.isEnabled()) { + logger.error("Compute Resource with id" + computationalResourceScheduling.getResourceHostId() + + "" + " is not enabled by the Admin!"); + throw new RegistryException( + "Compute Resource with id" + computationalResourceScheduling.getResourceHostId() + "" + + " is not enabled by the Admin!"); + } + } catch (AppCatalogException e) { + throw new RegistryException("Error checking compute resource: " + e.getMessage(), e); + } + } } - } - experiment.setGatewayId(gatewayId); - String experimentId = experimentRepository.addExperiment(experiment); - if (experiment.getExperimentType() == ExperimentType.WORKFLOW) { - try { - workflowRepository.registerWorkflow(experiment.getWorkflow(), experimentId); - } catch (WorkflowCatalogException e) { - throw new RegistryException("Error registering workflow: " + e.getMessage(), e); + experiment.setGatewayId(gatewayId); + String experimentId = experimentRepository.addExperiment(experiment); + if (experiment.getExperimentType() == ExperimentType.WORKFLOW) { + try { + workflowRepository.registerWorkflow(experiment.getWorkflow(), experimentId); + } catch (WorkflowCatalogException e) { + throw new RegistryException("Error registering workflow: " + e.getMessage(), e); + } } + logger.debug(experimentId, "Created new experiment with experiment name {}", experiment.getExperimentName()); + return experimentId; + } catch (Throwable e) { + throw convertException(e, "Error while creating experiment"); } - logger.debug(experimentId, "Created new experiment with experiment name {}", experiment.getExperimentName()); - return experimentId; } public List searchExperiments( @@ -1371,303 +1751,363 @@ public List searchExperiments( Map filters, int limit, int offset) - throws RegistryException { - if (!validateString(userName)) { - logger.error("Username cannot be empty. Please provide a valid user.."); - throw new RegistryException("Username cannot be empty. Please provide a valid user.."); - } - if (!isGatewayExistInternal(gatewayId)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new RegistryException("Gateway does not exist.Please provide a valid gateway id..."); - } - if (!userRepository.isUserExists(gatewayId, userName)) { - logger.error("User does not exist in the system. Please provide a valid user.."); - throw new RegistryException("User does not exist in the system. Please provide a valid user.."); - } - List summaries = new ArrayList(); - Map regFilters = new HashMap(); - regFilters.put(Constants.FieldConstants.ExperimentConstants.GATEWAY_ID, gatewayId); - for (Map.Entry entry : filters.entrySet()) { - if (entry.getKey().equals(ExperimentSearchFields.EXPERIMENT_NAME)) { - regFilters.put(Constants.FieldConstants.ExperimentConstants.EXPERIMENT_NAME, entry.getValue()); - } else if (entry.getKey().equals(ExperimentSearchFields.EXPERIMENT_DESC)) { - regFilters.put(Constants.FieldConstants.ExperimentConstants.DESCRIPTION, entry.getValue()); - } else if (entry.getKey().equals(ExperimentSearchFields.APPLICATION_ID)) { - regFilters.put(Constants.FieldConstants.ExperimentConstants.EXECUTION_ID, entry.getValue()); - } else if (entry.getKey().equals(ExperimentSearchFields.STATUS)) { - regFilters.put(Constants.FieldConstants.ExperimentConstants.EXPERIMENT_STATUS, entry.getValue()); - } else if (entry.getKey().equals(ExperimentSearchFields.FROM_DATE)) { - regFilters.put(Constants.FieldConstants.ExperimentConstants.FROM_DATE, entry.getValue()); - } else if (entry.getKey().equals(ExperimentSearchFields.TO_DATE)) { - regFilters.put(Constants.FieldConstants.ExperimentConstants.TO_DATE, entry.getValue()); - } else if (entry.getKey().equals(ExperimentSearchFields.PROJECT_ID)) { - regFilters.put(Constants.FieldConstants.ExperimentConstants.PROJECT_ID, entry.getValue()); - } else if (entry.getKey().equals(ExperimentSearchFields.USER_NAME)) { - regFilters.put(Constants.FieldConstants.ExperimentConstants.USER_NAME, entry.getValue()); - } else if (entry.getKey().equals(ExperimentSearchFields.JOB_ID)) { - regFilters.put(Constants.FieldConstants.JobConstants.JOB_ID, entry.getValue()); - } - } - - try { - if (accessibleExpIds.size() == 0 && !ServerSettings.isEnableSharing()) { - if (!regFilters.containsKey(DBConstants.Experiment.USER_NAME)) { - regFilters.put(DBConstants.Experiment.USER_NAME, userName); + throws RegistryServiceException { + try { + if (!validateString(userName)) { + logger.error("Username cannot be empty. Please provide a valid user.."); + throw new RegistryException("Username cannot be empty. Please provide a valid user.."); + } + if (!isGatewayExistInternal(gatewayId)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new RegistryException("Gateway does not exist.Please provide a valid gateway id..."); + } + if (!userRepository.isUserExists(gatewayId, userName)) { + logger.error("User does not exist in the system. Please provide a valid user.."); + throw new RegistryException("User does not exist in the system. Please provide a valid user.."); + } + List summaries = new ArrayList(); + Map regFilters = new HashMap(); + regFilters.put(Constants.FieldConstants.ExperimentConstants.GATEWAY_ID, gatewayId); + for (Map.Entry entry : filters.entrySet()) { + if (entry.getKey().equals(ExperimentSearchFields.EXPERIMENT_NAME)) { + regFilters.put(Constants.FieldConstants.ExperimentConstants.EXPERIMENT_NAME, entry.getValue()); + } else if (entry.getKey().equals(ExperimentSearchFields.EXPERIMENT_DESC)) { + regFilters.put(Constants.FieldConstants.ExperimentConstants.DESCRIPTION, entry.getValue()); + } else if (entry.getKey().equals(ExperimentSearchFields.APPLICATION_ID)) { + regFilters.put(Constants.FieldConstants.ExperimentConstants.EXECUTION_ID, entry.getValue()); + } else if (entry.getKey().equals(ExperimentSearchFields.STATUS)) { + regFilters.put(Constants.FieldConstants.ExperimentConstants.EXPERIMENT_STATUS, entry.getValue()); + } else if (entry.getKey().equals(ExperimentSearchFields.FROM_DATE)) { + regFilters.put(Constants.FieldConstants.ExperimentConstants.FROM_DATE, entry.getValue()); + } else if (entry.getKey().equals(ExperimentSearchFields.TO_DATE)) { + regFilters.put(Constants.FieldConstants.ExperimentConstants.TO_DATE, entry.getValue()); + } else if (entry.getKey().equals(ExperimentSearchFields.PROJECT_ID)) { + regFilters.put(Constants.FieldConstants.ExperimentConstants.PROJECT_ID, entry.getValue()); + } else if (entry.getKey().equals(ExperimentSearchFields.USER_NAME)) { + regFilters.put(Constants.FieldConstants.ExperimentConstants.USER_NAME, entry.getValue()); + } else if (entry.getKey().equals(ExperimentSearchFields.JOB_ID)) { + regFilters.put(Constants.FieldConstants.JobConstants.JOB_ID, entry.getValue()); } } - } catch (Exception e) { - logger.warn("Error checking sharing settings, continuing without filter", e); - } - summaries = experimentSummaryRepository.searchAllAccessibleExperiments( - accessibleExpIds, - regFilters, - limit, - offset, - Constants.FieldConstants.ExperimentConstants.CREATION_TIME, - ResultOrderType.DESC); - logger.debug("Airavata retrieved experiments for user : " + userName + " and gateway id : " + gatewayId); - return summaries; - } - - public void updateExperiment(String airavataExperimentId, ExperimentModel experiment) throws RegistryException { - if (!experimentRepository.isExperimentExist(airavataExperimentId)) { - logger.error( - airavataExperimentId, "Update request failed, Experiment {} doesn't exist.", airavataExperimentId); - throw new RegistryException( - "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); - } - - ExperimentStatus experimentStatus = getExperimentStatusInternal(airavataExperimentId); - if (experimentStatus != null) { - ExperimentState experimentState = experimentStatus.getState(); - switch (experimentState) { - case CREATED: - case SCHEDULED: - case VALIDATED: - if (experiment.getUserConfigurationData() != null - && experiment.getUserConfigurationData().getComputationalResourceScheduling() != null - && experiment.getUserConfigurationData() + + try { + if (accessibleExpIds.size() == 0 && !ServerSettings.isEnableSharing()) { + if (!regFilters.containsKey(DBConstants.Experiment.USER_NAME)) { + regFilters.put(DBConstants.Experiment.USER_NAME, userName); + } + } + } catch (Exception e) { + logger.warn("Error checking sharing settings, continuing without filter", e); + } + summaries = experimentSummaryRepository.searchAllAccessibleExperiments( + accessibleExpIds, + regFilters, + limit, + offset, + Constants.FieldConstants.ExperimentConstants.CREATION_TIME, + ResultOrderType.DESC); + logger.debug("Airavata retrieved experiments for user : " + userName + " and gateway id : " + gatewayId); + return summaries; + } catch (Throwable e) { + throw convertException(e, "Error while searching experiments"); + } + } + + public void updateExperiment(String airavataExperimentId, ExperimentModel experiment) throws RegistryServiceException { + try { + if (!experimentRepository.isExperimentExist(airavataExperimentId)) { + logger.error( + airavataExperimentId, "Update request failed, Experiment {} doesn't exist.", airavataExperimentId); + throw new RegistryException( + "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); + } + + ExperimentStatus experimentStatus = getExperimentStatusInternal(airavataExperimentId); + if (experimentStatus != null) { + ExperimentState experimentState = experimentStatus.getState(); + switch (experimentState) { + case CREATED: + case SCHEDULED: + case VALIDATED: + if (experiment.getUserConfigurationData() != null + && experiment.getUserConfigurationData().getComputationalResourceScheduling() != null + && experiment.getUserConfigurationData() + .getComputationalResourceScheduling() + .getResourceHostId() + != null) { + String compResourceId = experiment + .getUserConfigurationData() .getComputationalResourceScheduling() - .getResourceHostId() - != null) { - String compResourceId = experiment - .getUserConfigurationData() - .getComputationalResourceScheduling() - .getResourceHostId(); - try { - ComputeResourceDescription computeResourceDescription = - new ComputeResourceRepository().getComputeResource(compResourceId); - if (!computeResourceDescription.isEnabled()) { - logger.error("Compute Resource is not enabled by the Admin!"); - throw new RegistryException("Compute Resource is not enabled by the Admin!"); + .getResourceHostId(); + try { + ComputeResourceDescription computeResourceDescription = + new ComputeResourceRepository().getComputeResource(compResourceId); + if (!computeResourceDescription.isEnabled()) { + logger.error("Compute Resource is not enabled by the Admin!"); + throw new RegistryException("Compute Resource is not enabled by the Admin!"); + } + } catch (AppCatalogException e) { + throw new RegistryException("Error checking compute resource: " + e.getMessage(), e); } - } catch (AppCatalogException e) { - throw new RegistryException("Error checking compute resource: " + e.getMessage(), e); } - } - experimentRepository.updateExperiment(experiment, airavataExperimentId); - logger.debug( - airavataExperimentId, - "Successfully updated experiment {} ", - experiment.getExperimentName()); - break; - default: - logger.error( - airavataExperimentId, - "Error while updating experiment. Update experiment is only valid for experiments " - + "with status CREATED, VALIDATED, CANCELLED, FAILED and UNKNOWN. Make sure the given " - + "experiment is in one of above statuses... "); - throw new RegistryException( - "Error while updating experiment. Update experiment is only valid for experiments " - + "with status CREATED, VALIDATED, CANCELLED, FAILED and UNKNOWN. Make sure the given " - + "experiment is in one of above statuses... "); + experimentRepository.updateExperiment(experiment, airavataExperimentId); + logger.debug( + airavataExperimentId, + "Successfully updated experiment {} ", + experiment.getExperimentName()); + break; + default: + logger.error( + airavataExperimentId, + "Error while updating experiment. Update experiment is only valid for experiments " + + "with status CREATED, VALIDATED, CANCELLED, FAILED and UNKNOWN. Make sure the given " + + "experiment is in one of above statuses... "); + throw new RegistryException( + "Error while updating experiment. Update experiment is only valid for experiments " + + "with status CREATED, VALIDATED, CANCELLED, FAILED and UNKNOWN. Make sure the given " + + "experiment is in one of above statuses... "); + } } + } catch (Throwable e) { + throw convertException(e, "Error while updating experiment"); } } public void updateExperimentConfiguration(String airavataExperimentId, UserConfigurationDataModel userConfiguration) - throws RegistryException { - if (!experimentRepository.isExperimentExist(airavataExperimentId)) { - logger.error( - airavataExperimentId, - "Update experiment configuration failed, experiment {} doesn't exist.", - airavataExperimentId); - throw new RegistryException( - "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); - } - ExperimentStatus experimentStatus = getExperimentStatusInternal(airavataExperimentId); - if (experimentStatus != null) { - ExperimentState experimentState = experimentStatus.getState(); - switch (experimentState) { - case CREATED: - case VALIDATED: - case CANCELED: - case FAILED: - experimentRepository.addUserConfigurationData(userConfiguration, airavataExperimentId); - logger.debug( - airavataExperimentId, - "Successfully updated experiment configuration for experiment {}.", - airavataExperimentId); - break; - default: - logger.error( - airavataExperimentId, - "Error while updating experiment {}. Update experiment is only valid for experiments " - + "with status CREATED, VALIDATED, CANCELLED, FAILED and UNKNOWN. Make sure the given " - + "experiment is in one of above statuses... ", - airavataExperimentId); - throw new RegistryException( - "Error while updating experiment. Update experiment is only valid for experiments " - + "with status CREATED, VALIDATED, CANCELLED, FAILED and UNKNOWN. Make sure the given " - + "experiment is in one of above statuses... "); - } - } - } - - public List getIntermediateOutputs(String airavataExperimentId) throws RegistryException { - if (!experimentRepository.isExperimentExist(airavataExperimentId)) { - logger.error( - airavataExperimentId, - "Error while retrieving intermediate outputs, experiment {} doesn't exist.", - airavataExperimentId); - throw new RegistryException( - "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); - } - List processModels = processRepository.getProcessList( - Constants.FieldConstants.ExperimentConstants.EXPERIMENT_ID, airavataExperimentId); - List intermediateOutputs = new ArrayList<>(); - if (processModels != null && !processModels.isEmpty()) { - for (ProcessModel processModel : processModels) { - List processOutputs = - processOutputRepository.getProcessOutputs(processModel.getProcessId()); - if (processOutputs != null && !processOutputs.isEmpty()) { - intermediateOutputs.addAll(processOutputs); + throws RegistryServiceException { + try { + if (!experimentRepository.isExperimentExist(airavataExperimentId)) { + logger.error( + airavataExperimentId, + "Update experiment configuration failed, experiment {} doesn't exist.", + airavataExperimentId); + throw new RegistryException( + "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); + } + ExperimentStatus experimentStatus = getExperimentStatusInternal(airavataExperimentId); + if (experimentStatus != null) { + ExperimentState experimentState = experimentStatus.getState(); + switch (experimentState) { + case CREATED: + case VALIDATED: + case CANCELED: + case FAILED: + experimentRepository.addUserConfigurationData(userConfiguration, airavataExperimentId); + logger.debug( + airavataExperimentId, + "Successfully updated experiment configuration for experiment {}.", + airavataExperimentId); + break; + default: + logger.error( + airavataExperimentId, + "Error while updating experiment {}. Update experiment is only valid for experiments " + + "with status CREATED, VALIDATED, CANCELLED, FAILED and UNKNOWN. Make sure the given " + + "experiment is in one of above statuses... ", + airavataExperimentId); + throw new RegistryException( + "Error while updating experiment. Update experiment is only valid for experiments " + + "with status CREATED, VALIDATED, CANCELLED, FAILED and UNKNOWN. Make sure the given " + + "experiment is in one of above statuses... "); } } + } catch (Throwable e) { + throw convertException(e, "Error while updating experiment configuration"); } - logger.debug( - "Airavata retrieved intermediate outputs for experiment with experiment id : " + airavataExperimentId); - return intermediateOutputs; - } - - public Map getJobStatuses(String airavataExperimentId) throws RegistryException { - if (!experimentRepository.isExperimentExist(airavataExperimentId)) { - logger.error( - airavataExperimentId, - "Error while retrieving job statuses, experiment {} doesn't exist.", - airavataExperimentId); - throw new RegistryException( - "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); - } - Map jobStatus = new HashMap<>(); - List processModels = processRepository.getProcessList( - Constants.FieldConstants.ExperimentConstants.EXPERIMENT_ID, airavataExperimentId); - if (processModels != null && !processModels.isEmpty()) { - for (ProcessModel processModel : processModels) { - List tasks = processModel.getTasks(); - if (tasks != null && !tasks.isEmpty()) { - for (TaskModel taskModel : tasks) { - String taskId = taskModel.getTaskId(); - List taskJobs = - jobRepository.getJobList(Constants.FieldConstants.JobConstants.TASK_ID, taskId); - if (taskJobs != null && !taskJobs.isEmpty()) { - for (JobModel jobModel : taskJobs) { - JobPK jobPK = new JobPK(); - jobPK.setJobId(jobModel.getJobId()); - jobPK.setTaskId(taskId); - JobStatus status = jobStatusRepository.getJobStatus(jobPK); - if (status != null) { - jobStatus.put(jobModel.getJobId(), status); + } + + public List getIntermediateOutputs(String airavataExperimentId) throws RegistryServiceException { + try { + if (!experimentRepository.isExperimentExist(airavataExperimentId)) { + logger.error( + airavataExperimentId, + "Error while retrieving intermediate outputs, experiment {} doesn't exist.", + airavataExperimentId); + throw new RegistryException( + "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); + } + List processModels = processRepository.getProcessList( + Constants.FieldConstants.ExperimentConstants.EXPERIMENT_ID, airavataExperimentId); + List intermediateOutputs = new ArrayList<>(); + if (processModels != null && !processModels.isEmpty()) { + for (ProcessModel processModel : processModels) { + List processOutputs = + processOutputRepository.getProcessOutputs(processModel.getProcessId()); + if (processOutputs != null && !processOutputs.isEmpty()) { + intermediateOutputs.addAll(processOutputs); + } + } + } + logger.debug( + "Airavata retrieved intermediate outputs for experiment with experiment id : " + airavataExperimentId); + return intermediateOutputs; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving intermediate outputs"); + } + } + + public Map getJobStatuses(String airavataExperimentId) throws RegistryServiceException { + try { + if (!experimentRepository.isExperimentExist(airavataExperimentId)) { + logger.error( + airavataExperimentId, + "Error while retrieving job statuses, experiment {} doesn't exist.", + airavataExperimentId); + throw new RegistryException( + "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); + } + Map jobStatus = new HashMap<>(); + List processModels = processRepository.getProcessList( + Constants.FieldConstants.ExperimentConstants.EXPERIMENT_ID, airavataExperimentId); + if (processModels != null && !processModels.isEmpty()) { + for (ProcessModel processModel : processModels) { + List tasks = processModel.getTasks(); + if (tasks != null && !tasks.isEmpty()) { + for (TaskModel taskModel : tasks) { + String taskId = taskModel.getTaskId(); + List taskJobs = + jobRepository.getJobList(Constants.FieldConstants.JobConstants.TASK_ID, taskId); + if (taskJobs != null && !taskJobs.isEmpty()) { + for (JobModel jobModel : taskJobs) { + JobPK jobPK = new JobPK(); + jobPK.setJobId(jobModel.getJobId()); + jobPK.setTaskId(taskId); + JobStatus status = jobStatusRepository.getJobStatus(jobPK); + if (status != null) { + jobStatus.put(jobModel.getJobId(), status); + } } } } } } } + logger.debug("Airavata retrieved job statuses for experiment with experiment id : " + airavataExperimentId); + return jobStatus; + } catch (Throwable e) { + throw convertException(e, "Error while retrieving the job statuses"); } - logger.debug("Airavata retrieved job statuses for experiment with experiment id : " + airavataExperimentId); - return jobStatus; } public void addExperimentProcessOutputs(String outputType, List outputs, String id) - throws RegistryException { - if (ExpCatChildDataType.PROCESS_OUTPUT.equals(ExpCatChildDataType.valueOf(outputType))) { - processOutputRepository.addProcessOutputs(outputs, id); - } else if (ExpCatChildDataType.EXPERIMENT_OUTPUT.equals(ExpCatChildDataType.valueOf(outputType))) { - experimentOutputRepository.addExperimentOutputs(outputs, id); + throws RegistryServiceException { + try { + if (ExpCatChildDataType.PROCESS_OUTPUT.equals(ExpCatChildDataType.valueOf(outputType))) { + processOutputRepository.addProcessOutputs(outputs, id); + } else if (ExpCatChildDataType.EXPERIMENT_OUTPUT.equals(ExpCatChildDataType.valueOf(outputType))) { + experimentOutputRepository.addExperimentOutputs(outputs, id); + } + } catch (Throwable e) { + throw convertException(e, "Error while adding outputs"); } } - public void addErrors(String errorType, ErrorModel errorModel, String id) throws RegistryException { - if (ExpCatChildDataType.EXPERIMENT_ERROR.equals(ExpCatChildDataType.valueOf(errorType))) { - experimentErrorRepository.addExperimentError(errorModel, id); - } else if (ExpCatChildDataType.TASK_ERROR.equals(ExpCatChildDataType.valueOf(errorType))) { - taskErrorRepository.addTaskError(errorModel, id); - } else if (ExpCatChildDataType.PROCESS_ERROR.equals(ExpCatChildDataType.valueOf(errorType))) { - processErrorRepository.addProcessError(errorModel, id); + public void addErrors(String errorType, ErrorModel errorModel, String id) throws RegistryServiceException { + try { + if (ExpCatChildDataType.EXPERIMENT_ERROR.equals(ExpCatChildDataType.valueOf(errorType))) { + experimentErrorRepository.addExperimentError(errorModel, id); + } else if (ExpCatChildDataType.TASK_ERROR.equals(ExpCatChildDataType.valueOf(errorType))) { + taskErrorRepository.addTaskError(errorModel, id); + } else if (ExpCatChildDataType.PROCESS_ERROR.equals(ExpCatChildDataType.valueOf(errorType))) { + processErrorRepository.addProcessError(errorModel, id); + } + } catch (Throwable e) { + throw convertException(e, "Error while adding errors"); } } - public void addTaskStatus(TaskStatus taskStatus, String taskId) throws RegistryException { - taskStatusRepository.addTaskStatus(taskStatus, taskId); + public void addTaskStatus(TaskStatus taskStatus, String taskId) throws RegistryServiceException { + try { + taskStatusRepository.addTaskStatus(taskStatus, taskId); + } catch (Throwable e) { + throw convertException(e, "Error while adding task status"); + } } - public void addProcessStatus(ProcessStatus processStatus, String processId) throws RegistryException { - processStatusRepository.addProcessStatus(processStatus, processId); + public void addProcessStatus(ProcessStatus processStatus, String processId) throws RegistryServiceException { + try { + processStatusRepository.addProcessStatus(processStatus, processId); + } catch (Throwable e) { + throw convertException(e, "Error while adding process status"); + } } - public void updateProcessStatus(ProcessStatus processStatus, String processId) throws RegistryException { - processStatusRepository.updateProcessStatus(processStatus, processId); + public void updateProcessStatus(ProcessStatus processStatus, String processId) throws RegistryServiceException { + try { + processStatusRepository.updateProcessStatus(processStatus, processId); + } catch (Throwable e) { + throw convertException(e, "Error while updating process status"); + } } public void updateExperimentStatus(ExperimentStatus experimentStatus, String experimentId) - throws RegistryException { - experimentStatusRepository.updateExperimentStatus(experimentStatus, experimentId); + throws RegistryServiceException { + try { + experimentStatusRepository.updateExperimentStatus(experimentStatus, experimentId); + } catch (Throwable e) { + throw convertException(e, "Error while updating experiment status"); + } } - public void addJobStatus(JobStatus jobStatus, String taskId, String jobId) throws RegistryException { - JobPK jobPK = new JobPK(); - jobPK.setJobId(jobId); - jobPK.setTaskId(taskId); - jobStatusRepository.addJobStatus(jobStatus, jobPK); + public void addJobStatus(JobStatus jobStatus, String taskId, String jobId) throws RegistryServiceException { + try { + JobPK jobPK = new JobPK(); + jobPK.setJobId(jobId); + jobPK.setTaskId(taskId); + jobStatusRepository.addJobStatus(jobStatus, jobPK); + } catch (Throwable e) { + throw convertException(e, "Error while adding job status"); + } } - public void deleteJobs(String processId) throws RegistryException { - List jobs = jobRepository.getJobList(Constants.FieldConstants.JobConstants.PROCESS_ID, processId); - for (JobModel jobModel : jobs) { - jobRepository.removeJob(jobModel); + public void deleteJobs(String processId) throws RegistryServiceException { + try { + List jobs = jobRepository.getJobList(Constants.FieldConstants.JobConstants.PROCESS_ID, processId); + for (JobModel jobModel : jobs) { + jobRepository.removeJob(jobModel); + } + } catch (Throwable e) { + throw convertException(e, "Error while deleting jobs"); } } // Project operations - public String createProject(String gatewayId, Project project) throws RegistryException { - if (!validateString(project.getName()) || !validateString(project.getOwner())) { - logger.error("Project name and owner cannot be empty..."); - throw new RegistryException("Project name and owner cannot be empty..."); - } - if (!validateString(gatewayId)) { - logger.error("Gateway ID cannot be empty..."); - throw new RegistryException("Gateway ID cannot be empty..."); - } - if (!isGatewayExistInternal(gatewayId)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new RegistryException("Gateway does not exist.Please provide a valid gateway id..."); + public String createProject(String gatewayId, Project project) throws RegistryServiceException { + try { + if (!validateString(project.getName()) || !validateString(project.getOwner())) { + logger.error("Project name and owner cannot be empty..."); + throw new RegistryException("Project name and owner cannot be empty..."); + } + if (!validateString(gatewayId)) { + logger.error("Gateway ID cannot be empty..."); + throw new RegistryException("Gateway ID cannot be empty..."); + } + if (!isGatewayExistInternal(gatewayId)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new RegistryException("Gateway does not exist.Please provide a valid gateway id..."); + } + String projectId = projectRepository.addProject(project, gatewayId); + return projectId; + } catch (Throwable e) { + throw convertException(e, "Error while creating project"); } - String projectId = projectRepository.addProject(project, gatewayId); - return projectId; } - public void updateProject(String projectId, Project updatedProject) throws RegistryException { - if (!validateString(projectId)) { - logger.error("Project id cannot be empty..."); - throw new RegistryException("Project id cannot be empty..."); - } - if (!projectRepository.isProjectExist(projectId)) { - logger.error("Project does not exist in the system. Please provide a valid project ID..."); - throw new RegistryException("Project does not exist in the system. Please provide a valid project ID..."); + public void updateProject(String projectId, Project updatedProject) throws RegistryServiceException { + try { + if (!validateString(projectId)) { + logger.error("Project id cannot be empty..."); + throw new RegistryException("Project id cannot be empty..."); + } + if (!projectRepository.isProjectExist(projectId)) { + logger.error("Project does not exist in the system. Please provide a valid project ID..."); + throw new RegistryException("Project does not exist in the system. Please provide a valid project ID..."); + } + projectRepository.updateProject(updatedProject, projectId); + logger.debug("Airavata updated project with project Id : " + projectId); + } catch (Throwable e) { + throw convertException(e, "Error while updating project"); } - projectRepository.updateProject(updatedProject, projectId); - logger.debug("Airavata updated project with project Id : " + projectId); } public List searchProjects( @@ -1677,338 +2117,402 @@ public List searchProjects( Map filters, int limit, int offset) - throws RegistryException { - if (!validateString(userName)) { - logger.error("Username cannot be empty. Please provide a valid user.."); - throw new RegistryException("Username cannot be empty. Please provide a valid user.."); - } - if (!isGatewayExistInternal(gatewayId)) { - logger.error("Gateway does not exist.Please provide a valid gateway id..."); - throw new RegistryException("Gateway does not exist.Please provide a valid gateway id..."); - } - if (!userRepository.isUserExists(gatewayId, userName)) { - logger.error("User does not exist in the system. Please provide a valid user.."); - throw new RegistryException("User does not exist in the system. Please provide a valid user.."); - } - List projects = new ArrayList<>(); - Map regFilters = new HashMap<>(); - regFilters.put(Constants.FieldConstants.ProjectConstants.GATEWAY_ID, gatewayId); - for (Map.Entry entry : filters.entrySet()) { - if (entry.getKey().equals(ProjectSearchFields.PROJECT_NAME)) { - regFilters.put(Constants.FieldConstants.ProjectConstants.PROJECT_NAME, entry.getValue()); - } else if (entry.getKey().equals(ProjectSearchFields.PROJECT_DESCRIPTION)) { - regFilters.put(Constants.FieldConstants.ProjectConstants.DESCRIPTION, entry.getValue()); - } - } - + throws RegistryServiceException { try { - if (accessibleProjIds.size() == 0 && !ServerSettings.isEnableSharing()) { - if (!regFilters.containsKey(DBConstants.Project.OWNER)) { - regFilters.put(DBConstants.Project.OWNER, userName); + if (!validateString(userName)) { + logger.error("Username cannot be empty. Please provide a valid user.."); + throw new RegistryException("Username cannot be empty. Please provide a valid user.."); + } + if (!isGatewayExistInternal(gatewayId)) { + logger.error("Gateway does not exist.Please provide a valid gateway id..."); + throw new RegistryException("Gateway does not exist.Please provide a valid gateway id..."); + } + if (!userRepository.isUserExists(gatewayId, userName)) { + logger.error("User does not exist in the system. Please provide a valid user.."); + throw new RegistryException("User does not exist in the system. Please provide a valid user.."); + } + List projects = new ArrayList<>(); + Map regFilters = new HashMap<>(); + regFilters.put(Constants.FieldConstants.ProjectConstants.GATEWAY_ID, gatewayId); + for (Map.Entry entry : filters.entrySet()) { + if (entry.getKey().equals(ProjectSearchFields.PROJECT_NAME)) { + regFilters.put(Constants.FieldConstants.ProjectConstants.PROJECT_NAME, entry.getValue()); + } else if (entry.getKey().equals(ProjectSearchFields.PROJECT_DESCRIPTION)) { + regFilters.put(Constants.FieldConstants.ProjectConstants.DESCRIPTION, entry.getValue()); } } - } catch (Exception e) { - logger.warn("Error checking sharing settings, continuing without filter", e); - } - projects = projectRepository.searchAllAccessibleProjects( - accessibleProjIds, - regFilters, - limit, - offset, - Constants.FieldConstants.ProjectConstants.CREATION_TIME, - ResultOrderType.DESC); - logger.debug("Airavata retrieved projects for user : " + userName + " and gateway id : " + gatewayId); - return projects; + try { + if (accessibleProjIds.size() == 0 && !ServerSettings.isEnableSharing()) { + if (!regFilters.containsKey(DBConstants.Project.OWNER)) { + regFilters.put(DBConstants.Project.OWNER, userName); + } + } + } catch (Exception e) { + logger.warn("Error checking sharing settings, continuing without filter", e); + } + + projects = projectRepository.searchAllAccessibleProjects( + accessibleProjIds, + regFilters, + limit, + offset, + Constants.FieldConstants.ProjectConstants.CREATION_TIME, + ResultOrderType.DESC); + logger.debug("Airavata retrieved projects for user : " + userName + " and gateway id : " + gatewayId); + return projects; + } catch (Throwable e) { + throw convertException(e, "Error while searching projects"); + } } // Gateway Resource Profile operations public String registerGatewayResourceProfile(GatewayResourceProfile gatewayResourceProfile) - throws AppCatalogException { - if (!validateString(gatewayResourceProfile.getGatewayID())) { - logger.error("Cannot create gateway profile with empty gateway id"); - throw new AppCatalogException("Cannot create gateway profile with empty gateway id"); - } + throws RegistryServiceException { try { + if (!validateString(gatewayResourceProfile.getGatewayID())) { + logger.error("Cannot create gateway profile with empty gateway id"); + throw new AppCatalogException("Cannot create gateway profile with empty gateway id"); + } if (!isGatewayExistInternal(gatewayResourceProfile.getGatewayID())) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); + GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); + String resourceProfile = gwyResourceProfileRepository.addGatewayResourceProfile(gatewayResourceProfile); + logger.debug("Airavata registered gateway profile with gateway id : " + gatewayResourceProfile.getGatewayID()); + return resourceProfile; + } catch (Throwable e) { + throw convertException(e, "Error while registering gateway resource profile"); } - GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); - String resourceProfile = gwyResourceProfileRepository.addGatewayResourceProfile(gatewayResourceProfile); - logger.debug("Airavata registered gateway profile with gateway id : " + gatewayResourceProfile.getGatewayID()); - return resourceProfile; } public boolean updateGatewayResourceProfile(String gatewayID, GatewayResourceProfile gatewayResourceProfile) - throws AppCatalogException { + throws RegistryServiceException { try { if (!isGatewayExistInternal(gatewayID)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); + GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); + gwyResourceProfileRepository.updateGatewayResourceProfile(gatewayResourceProfile); + logger.debug("Airavata updated gateway profile with gateway id : " + gatewayID); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while updating gateway resource profile"); } - GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); - gwyResourceProfileRepository.updateGatewayResourceProfile(gatewayResourceProfile); - logger.debug("Airavata updated gateway profile with gateway id : " + gatewayID); - return true; } public boolean addGatewayComputeResourcePreference( String gatewayID, String computeResourceId, ComputeResourcePreference computeResourcePreference) - throws AppCatalogException { + throws RegistryServiceException { try { if (!isGatewayExistInternal(gatewayID)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); - } - GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); - if (!(gwyResourceProfileRepository.isExists(gatewayID))) { - throw new AppCatalogException("Gateway resource profile '" + gatewayID + "' does not exist!!!"); + GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); + if (!(gwyResourceProfileRepository.isExists(gatewayID))) { + throw new AppCatalogException("Gateway resource profile '" + gatewayID + "' does not exist!!!"); + } + GatewayResourceProfile profile = gwyResourceProfileRepository.getGatewayProfile(gatewayID); + profile.addToComputeResourcePreferences(computeResourcePreference); + gwyResourceProfileRepository.updateGatewayResourceProfile(profile); + logger.debug("Airavata added gateway compute resource preference with gateway id : " + gatewayID + + " and for compute resource id : " + computeResourceId); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while adding gateway compute resource preference"); } - GatewayResourceProfile profile = gwyResourceProfileRepository.getGatewayProfile(gatewayID); - profile.addToComputeResourcePreferences(computeResourcePreference); - gwyResourceProfileRepository.updateGatewayResourceProfile(profile); - logger.debug("Airavata added gateway compute resource preference with gateway id : " + gatewayID - + " and for compute resource id : " + computeResourceId); - return true; } public boolean updateGatewayComputeResourcePreference( String gatewayID, String computeResourceId, ComputeResourcePreference computeResourcePreference) - throws AppCatalogException { + throws RegistryServiceException { try { if (!isGatewayExistInternal(gatewayID)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); - } - GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); - GatewayResourceProfile profile = gwyResourceProfileRepository.getGatewayProfile(gatewayID); - List computeResourcePreferences = profile.getComputeResourcePreferences(); - ComputeResourcePreference preferenceToRemove = null; - for (ComputeResourcePreference preference : computeResourcePreferences) { - if (preference.getComputeResourceId().equals(computeResourceId)) { - preferenceToRemove = preference; - break; + GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); + GatewayResourceProfile profile = gwyResourceProfileRepository.getGatewayProfile(gatewayID); + List computeResourcePreferences = profile.getComputeResourcePreferences(); + ComputeResourcePreference preferenceToRemove = null; + for (ComputeResourcePreference preference : computeResourcePreferences) { + if (preference.getComputeResourceId().equals(computeResourceId)) { + preferenceToRemove = preference; + break; + } } + if (preferenceToRemove != null) { + profile.getComputeResourcePreferences().remove(preferenceToRemove); + } + profile.getComputeResourcePreferences().add(computeResourcePreference); + gwyResourceProfileRepository.updateGatewayResourceProfile(profile); + logger.debug("Airavata updated compute resource preference with gateway id : " + gatewayID + + " and for compute resource id : " + computeResourceId); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while updating gateway compute resource preference"); } - if (preferenceToRemove != null) { - profile.getComputeResourcePreferences().remove(preferenceToRemove); - } - profile.getComputeResourcePreferences().add(computeResourcePreference); - gwyResourceProfileRepository.updateGatewayResourceProfile(profile); - logger.debug("Airavata updated compute resource preference with gateway id : " + gatewayID - + " and for compute resource id : " + computeResourceId); - return true; } public boolean addGatewayStoragePreference( String gatewayID, String storageResourceId, StoragePreference dataStoragePreference) - throws AppCatalogException { + throws RegistryServiceException { try { if (!isGatewayExistInternal(gatewayID)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); - } - GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); - if (!(gwyResourceProfileRepository.isExists(gatewayID))) { - throw new AppCatalogException("Gateway resource profile '" + gatewayID + "' does not exist!!!"); + GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); + if (!(gwyResourceProfileRepository.isExists(gatewayID))) { + throw new AppCatalogException("Gateway resource profile '" + gatewayID + "' does not exist!!!"); + } + GatewayResourceProfile profile = gwyResourceProfileRepository.getGatewayProfile(gatewayID); + dataStoragePreference.setStorageResourceId(storageResourceId); + profile.addToStoragePreferences(dataStoragePreference); + gwyResourceProfileRepository.updateGatewayResourceProfile(profile); + logger.debug("Airavata added storage resource preference with gateway id : " + gatewayID + + " and for storage resource id : " + storageResourceId); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while adding gateway storage preference"); } - GatewayResourceProfile profile = gwyResourceProfileRepository.getGatewayProfile(gatewayID); - dataStoragePreference.setStorageResourceId(storageResourceId); - profile.addToStoragePreferences(dataStoragePreference); - gwyResourceProfileRepository.updateGatewayResourceProfile(profile); - logger.debug("Airavata added storage resource preference with gateway id : " + gatewayID - + " and for storage resource id : " + storageResourceId); - return true; } public boolean updateGatewayStoragePreference( - String gatewayID, String storageId, StoragePreference storagePreference) throws AppCatalogException { + String gatewayID, String storageId, StoragePreference storagePreference) throws RegistryServiceException { try { if (!isGatewayExistInternal(gatewayID)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); - } - GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); - GatewayResourceProfile profile = gwyResourceProfileRepository.getGatewayProfile(gatewayID); - List dataStoragePreferences = profile.getStoragePreferences(); - StoragePreference preferenceToRemove = null; - for (StoragePreference preference : dataStoragePreferences) { - if (preference.getStorageResourceId().equals(storageId)) { - preferenceToRemove = preference; - break; + GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); + GatewayResourceProfile profile = gwyResourceProfileRepository.getGatewayProfile(gatewayID); + List dataStoragePreferences = profile.getStoragePreferences(); + StoragePreference preferenceToRemove = null; + for (StoragePreference preference : dataStoragePreferences) { + if (preference.getStorageResourceId().equals(storageId)) { + preferenceToRemove = preference; + break; + } } + if (preferenceToRemove != null) { + profile.getStoragePreferences().remove(preferenceToRemove); + } + profile.getStoragePreferences().add(storagePreference); + gwyResourceProfileRepository.updateGatewayResourceProfile(profile); + logger.debug("Airavata updated storage resource preference with gateway id : " + gatewayID + + " and for storage resource id : " + storageId); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while updating gateway storage preference"); } - if (preferenceToRemove != null) { - profile.getStoragePreferences().remove(preferenceToRemove); - } - profile.getStoragePreferences().add(storagePreference); - gwyResourceProfileRepository.updateGatewayResourceProfile(profile); - logger.debug("Airavata updated storage resource preference with gateway id : " + gatewayID - + " and for storage resource id : " + storageId); - return true; } // Compute Resource operations public String registerComputeResource(ComputeResourceDescription computeResourceDescription) - throws AppCatalogException { - String computeResource = new ComputeResourceRepository().addComputeResource(computeResourceDescription); - logger.debug("Airavata registered compute resource with compute resource Id : " + computeResource); - return computeResource; + throws RegistryServiceException { + try { + String computeResource = new ComputeResourceRepository().addComputeResource(computeResourceDescription); + logger.debug("Airavata registered compute resource with compute resource Id : " + computeResource); + return computeResource; + } catch (Throwable e) { + throw convertException(e, "Error while registering compute resource"); + } } public boolean updateComputeResource( String computeResourceId, ComputeResourceDescription computeResourceDescription) - throws AppCatalogException { - new ComputeResourceRepository().updateComputeResource(computeResourceId, computeResourceDescription); - logger.debug("Airavata updated compute resource with compute resource Id : " + computeResourceId); - return true; + throws RegistryServiceException { + try { + new ComputeResourceRepository().updateComputeResource(computeResourceId, computeResourceDescription); + logger.debug("Airavata updated compute resource with compute resource Id : " + computeResourceId); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while updating compute resource"); + } } - public String registerResourceJobManager(ResourceJobManager resourceJobManager) throws AppCatalogException { - return new ComputeResourceRepository().addResourceJobManager(resourceJobManager); + public String registerResourceJobManager(ResourceJobManager resourceJobManager) throws RegistryServiceException { + try { + return new ComputeResourceRepository().addResourceJobManager(resourceJobManager); + } catch (Throwable e) { + throw convertException(e, "Error while registering resource job manager"); + } } public boolean updateResourceJobManager(String resourceJobManagerId, ResourceJobManager updatedResourceJobManager) - throws AppCatalogException { - new ComputeResourceRepository().updateResourceJobManager(resourceJobManagerId, updatedResourceJobManager); - return true; + throws RegistryServiceException { + try { + new ComputeResourceRepository().updateResourceJobManager(resourceJobManagerId, updatedResourceJobManager); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while updating resource job manager"); + } } public boolean deleteDataMovementInterface(String resourceId, String dataMovementInterfaceId, DMType dmType) - throws AppCatalogException { - switch (dmType) { - case COMPUTE_RESOURCE: - new ComputeResourceRepository().removeDataMovementInterface(resourceId, dataMovementInterfaceId); - logger.debug("Airavata deleted data movement interface with interface id : " + dataMovementInterfaceId); - return true; - case STORAGE_RESOURCE: - storageResourceRepository.removeDataMovementInterface(resourceId, dataMovementInterfaceId); - logger.debug("Airavata deleted data movement interface with interface id : " + dataMovementInterfaceId); - return true; - default: - logger.error( - "Unsupported data movement type specifies.. Please provide the correct data movement type... "); - return false; + throws RegistryServiceException { + try { + switch (dmType) { + case COMPUTE_RESOURCE: + new ComputeResourceRepository().removeDataMovementInterface(resourceId, dataMovementInterfaceId); + logger.debug("Airavata deleted data movement interface with interface id : " + dataMovementInterfaceId); + return true; + case STORAGE_RESOURCE: + storageResourceRepository.removeDataMovementInterface(resourceId, dataMovementInterfaceId); + logger.debug("Airavata deleted data movement interface with interface id : " + dataMovementInterfaceId); + return true; + default: + logger.error( + "Unsupported data movement type specifies.. Please provide the correct data movement type... "); + return false; + } + } catch (Throwable e) { + throw convertException(e, "Error while deleting data movement interface"); } } public boolean updateGridFTPDataMovementDetails( - String dataMovementInterfaceId, GridFTPDataMovement gridFTPDataMovement) throws AppCatalogException { - throw new AppCatalogException("updateGridFTPDataMovementDetails is not yet implemented"); + String dataMovementInterfaceId, GridFTPDataMovement gridFTPDataMovement) throws RegistryServiceException { + try { + throw new AppCatalogException("updateGridFTPDataMovementDetails is not yet implemented"); + } catch (Throwable e) { + throw convertException(e, "Error while updating GridFTP data movement details"); + } } public String addGridFTPDataMovementDetails( String computeResourceId, DMType dmType, int priorityOrder, GridFTPDataMovement gridFTPDataMovement) - throws AppCatalogException { - ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); - String addDataMovementInterface = addDataMovementInterface( - computeResourceRepository, - computeResourceId, - dmType, - computeResourceRepository.addGridFTPDataMovement(gridFTPDataMovement), - DataMovementProtocol.GridFTP, - priorityOrder); - logger.debug("Airavata registered GridFTP data movement for resource Id: " + computeResourceId); - return addDataMovementInterface; + throws RegistryServiceException { + try { + ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); + String addDataMovementInterface = addDataMovementInterface( + computeResourceRepository, + computeResourceId, + dmType, + computeResourceRepository.addGridFTPDataMovement(gridFTPDataMovement), + DataMovementProtocol.GridFTP, + priorityOrder); + logger.debug("Airavata registered GridFTP data movement for resource Id: " + computeResourceId); + return addDataMovementInterface; + } catch (Throwable e) { + throw convertException(e, "Error while adding GridFTP data movement details"); + } } public boolean updateUnicoreDataMovementDetails( - String dataMovementInterfaceId, UnicoreDataMovement unicoreDataMovement) throws AppCatalogException { - throw new AppCatalogException("updateUnicoreDataMovementDetails is not yet implemented"); + String dataMovementInterfaceId, UnicoreDataMovement unicoreDataMovement) throws RegistryServiceException { + try { + throw new AppCatalogException("updateUnicoreDataMovementDetails is not yet implemented"); + } catch (Throwable e) { + throw convertException(e, "Error while updating Unicore data movement details"); + } } public String addUnicoreDataMovementDetails( String resourceId, DMType dmType, int priorityOrder, UnicoreDataMovement unicoreDataMovement) - throws AppCatalogException { - ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); - String movementInterface = addDataMovementInterface( - computeResourceRepository, - resourceId, - dmType, - computeResourceRepository.addUnicoreDataMovement(unicoreDataMovement), - DataMovementProtocol.UNICORE_STORAGE_SERVICE, - priorityOrder); - logger.debug("Airavata registered UNICORE data movement for resource Id: " + resourceId); - return movementInterface; + throws RegistryServiceException { + try { + ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); + String movementInterface = addDataMovementInterface( + computeResourceRepository, + resourceId, + dmType, + computeResourceRepository.addUnicoreDataMovement(unicoreDataMovement), + DataMovementProtocol.UNICORE_STORAGE_SERVICE, + priorityOrder); + logger.debug("Airavata registered UNICORE data movement for resource Id: " + resourceId); + return movementInterface; + } catch (Throwable e) { + throw convertException(e, "Error while adding Unicore data movement details"); + } } public boolean updateSCPDataMovementDetails(String dataMovementInterfaceId, SCPDataMovement scpDataMovement) - throws AppCatalogException { - new ComputeResourceRepository().updateScpDataMovement(scpDataMovement); - logger.debug("Airavata updated SCP data movement with data movement id: " + dataMovementInterfaceId); - return true; + throws RegistryServiceException { + try { + new ComputeResourceRepository().updateScpDataMovement(scpDataMovement); + logger.debug("Airavata updated SCP data movement with data movement id: " + dataMovementInterfaceId); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while updating SCP data movement details"); + } } public String addSCPDataMovementDetails( String resourceId, DMType dmType, int priorityOrder, SCPDataMovement scpDataMovement) - throws AppCatalogException { - ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); - String movementInterface = addDataMovementInterface( - computeResourceRepository, - resourceId, - dmType, - computeResourceRepository.addScpDataMovement(scpDataMovement), - DataMovementProtocol.SCP, - priorityOrder); - logger.debug("Airavata registered SCP data movement for resource Id: " + resourceId); - return movementInterface; + throws RegistryServiceException { + try { + ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); + String movementInterface = addDataMovementInterface( + computeResourceRepository, + resourceId, + dmType, + computeResourceRepository.addScpDataMovement(scpDataMovement), + DataMovementProtocol.SCP, + priorityOrder); + logger.debug("Airavata registered SCP data movement for resource Id: " + resourceId); + return movementInterface; + } catch (Throwable e) { + throw convertException(e, "Error while adding SCP data movement details"); + } } public boolean updateLocalDataMovementDetails(String dataMovementInterfaceId, LOCALDataMovement localDataMovement) - throws AppCatalogException { - new ComputeResourceRepository().updateLocalDataMovement(localDataMovement); - logger.debug("Airavata updated local data movement with data movement id: " + dataMovementInterfaceId); - return true; + throws RegistryServiceException { + try { + new ComputeResourceRepository().updateLocalDataMovement(localDataMovement); + logger.debug("Airavata updated local data movement with data movement id: " + dataMovementInterfaceId); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while updating local data movement details"); + } } public String addLocalDataMovementDetails( String resourceId, DMType dataMoveType, int priorityOrder, LOCALDataMovement localDataMovement) - throws AppCatalogException { - ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); - String movementInterface = addDataMovementInterface( - computeResourceRepository, - resourceId, - dataMoveType, - computeResourceRepository.addLocalDataMovement(localDataMovement), - DataMovementProtocol.LOCAL, - priorityOrder); - logger.debug("Airavata registered local data movement for resource Id: " + resourceId); - return movementInterface; + throws RegistryServiceException { + try { + ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); + String movementInterface = addDataMovementInterface( + computeResourceRepository, + resourceId, + dataMoveType, + computeResourceRepository.addLocalDataMovement(localDataMovement), + DataMovementProtocol.LOCAL, + priorityOrder); + logger.debug("Airavata registered local data movement for resource Id: " + resourceId); + return movementInterface; + } catch (Throwable e) { + throw convertException(e, "Error while adding local data movement details"); + } } // Storage Resource operations public String registerStorageResource(StorageResourceDescription storageResourceDescription) - throws AppCatalogException { - String storageResource = storageResourceRepository.addStorageResource(storageResourceDescription); - logger.debug("Airavata registered storage resource with storage resource Id : " + storageResource); - return storageResource; + throws RegistryServiceException { + try { + String storageResource = storageResourceRepository.addStorageResource(storageResourceDescription); + logger.debug("Airavata registered storage resource with storage resource Id : " + storageResource); + return storageResource; + } catch (Throwable e) { + throw convertException(e, "Error while registering storage resource"); + } } public boolean updateStorageResource( String storageResourceId, StorageResourceDescription storageResourceDescription) - throws AppCatalogException { - storageResourceRepository.updateStorageResource(storageResourceId, storageResourceDescription); - logger.debug("Airavata updated storage resource with storage resource Id : " + storageResourceId); - return true; + throws RegistryServiceException { + try { + storageResourceRepository.updateStorageResource(storageResourceId, storageResourceDescription); + logger.debug("Airavata updated storage resource with storage resource Id : " + storageResourceId); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while updating storage resource"); + } } // Helper methods for job submission and data movement interfaces @@ -2018,12 +2522,16 @@ private String addJobSubmissionInterface( String jobSubmissionInterfaceId, JobSubmissionProtocol protocolType, int priorityOrder) - throws AppCatalogException { - JobSubmissionInterface jobSubmissionInterface = new JobSubmissionInterface(); - jobSubmissionInterface.setJobSubmissionInterfaceId(jobSubmissionInterfaceId); - jobSubmissionInterface.setPriorityOrder(priorityOrder); - jobSubmissionInterface.setJobSubmissionProtocol(protocolType); - return computeResourceRepository.addJobSubmissionProtocol(computeResourceId, jobSubmissionInterface); + throws RegistryServiceException { + try { + JobSubmissionInterface jobSubmissionInterface = new JobSubmissionInterface(); + jobSubmissionInterface.setJobSubmissionInterfaceId(jobSubmissionInterfaceId); + jobSubmissionInterface.setPriorityOrder(priorityOrder); + jobSubmissionInterface.setJobSubmissionProtocol(protocolType); + return computeResourceRepository.addJobSubmissionProtocol(computeResourceId, jobSubmissionInterface); + } catch (Throwable e) { + throw convertException(e, "Error while adding job submission interface"); + } } private String addDataMovementInterface( @@ -2033,292 +2541,340 @@ private String addDataMovementInterface( String dataMovementInterfaceId, DataMovementProtocol protocolType, int priorityOrder) - throws AppCatalogException { - DataMovementInterface dataMovementInterface = new DataMovementInterface(); - dataMovementInterface.setDataMovementInterfaceId(dataMovementInterfaceId); - dataMovementInterface.setPriorityOrder(priorityOrder); - dataMovementInterface.setDataMovementProtocol(protocolType); - if (dmType.equals(DMType.COMPUTE_RESOURCE)) { - return computeResourceRepository.addDataMovementProtocol(computeResourceId, dmType, dataMovementInterface); - } else if (dmType.equals(DMType.STORAGE_RESOURCE)) { - dataMovementInterface.setStorageResourceId(computeResourceId); - return storageResourceRepository.addDataMovementInterface(dataMovementInterface); + throws RegistryServiceException { + try { + DataMovementInterface dataMovementInterface = new DataMovementInterface(); + dataMovementInterface.setDataMovementInterfaceId(dataMovementInterfaceId); + dataMovementInterface.setPriorityOrder(priorityOrder); + dataMovementInterface.setDataMovementProtocol(protocolType); + if (dmType.equals(DMType.COMPUTE_RESOURCE)) { + return computeResourceRepository.addDataMovementProtocol(computeResourceId, dmType, dataMovementInterface); + } else if (dmType.equals(DMType.STORAGE_RESOURCE)) { + dataMovementInterface.setStorageResourceId(computeResourceId); + return storageResourceRepository.addDataMovementInterface(dataMovementInterface); + } + return null; + } catch (Throwable e) { + throw convertException(e, "Error while adding data movement interface"); } - return null; } // Job Submission Interface operations public String addSSHJobSubmissionDetails( - String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) throws AppCatalogException { - ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); - String submissionInterface = addJobSubmissionInterface( - computeResourceRepository, - computeResourceId, - computeResourceRepository.addSSHJobSubmission(sshJobSubmission), - JobSubmissionProtocol.SSH, - priorityOrder); - logger.debug("Airavata registered SSH job submission for compute resource id: " + computeResourceId); - return submissionInterface; + String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) throws RegistryServiceException { + try { + ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); + String submissionInterface = addJobSubmissionInterface( + computeResourceRepository, + computeResourceId, + computeResourceRepository.addSSHJobSubmission(sshJobSubmission), + JobSubmissionProtocol.SSH, + priorityOrder); + logger.debug("Airavata registered SSH job submission for compute resource id: " + computeResourceId); + return submissionInterface; + } catch (Throwable e) { + throw convertException(e, "Error while adding SSH job submission details"); + } } public String addSSHForkJobSubmissionDetails( - String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) throws AppCatalogException { - ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); - String submissionDetails = addJobSubmissionInterface( - computeResourceRepository, - computeResourceId, - computeResourceRepository.addSSHJobSubmission(sshJobSubmission), - JobSubmissionProtocol.SSH_FORK, - priorityOrder); - logger.debug("Airavata registered Fork job submission for compute resource id: " + computeResourceId); - return submissionDetails; + String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) throws RegistryServiceException { + try { + ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); + String submissionDetails = addJobSubmissionInterface( + computeResourceRepository, + computeResourceId, + computeResourceRepository.addSSHJobSubmission(sshJobSubmission), + JobSubmissionProtocol.SSH_FORK, + priorityOrder); + logger.debug("Airavata registered Fork job submission for compute resource id: " + computeResourceId); + return submissionDetails; + } catch (Throwable e) { + throw convertException(e, "Error while adding SSH Fork job submission details"); + } } public String addLocalSubmissionDetails( - String computeResourceId, int priorityOrder, LOCALSubmission localSubmission) throws AppCatalogException { - ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); - String submissionInterface = addJobSubmissionInterface( - computeResourceRepository, - computeResourceId, - computeResourceRepository.addLocalJobSubmission(localSubmission), - JobSubmissionProtocol.LOCAL, - priorityOrder); - logger.debug("Airavata added local job submission for compute resource id: " + computeResourceId); - return submissionInterface; + String computeResourceId, int priorityOrder, LOCALSubmission localSubmission) throws RegistryServiceException { + try { + ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); + String submissionInterface = addJobSubmissionInterface( + computeResourceRepository, + computeResourceId, + computeResourceRepository.addLocalJobSubmission(localSubmission), + JobSubmissionProtocol.LOCAL, + priorityOrder); + logger.debug("Airavata added local job submission for compute resource id: " + computeResourceId); + return submissionInterface; + } catch (Throwable e) { + throw convertException(e, "Error while adding local submission details"); + } } public boolean updateLocalSubmissionDetails(String jobSubmissionInterfaceId, LOCALSubmission localSubmission) - throws AppCatalogException { - new ComputeResourceRepository().updateLocalJobSubmission(localSubmission); - logger.debug( - "Airavata updated local job submission for job submission interface id: " + jobSubmissionInterfaceId); - return true; + throws RegistryServiceException { + try { + new ComputeResourceRepository().updateLocalJobSubmission(localSubmission); + logger.debug( + "Airavata updated local job submission for job submission interface id: " + jobSubmissionInterfaceId); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while updating local submission details"); + } } public String addCloudJobSubmissionDetails( String computeResourceId, int priorityOrder, CloudJobSubmission cloudSubmission) - throws AppCatalogException { - ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); - String submissionInterface = addJobSubmissionInterface( - computeResourceRepository, - computeResourceId, - computeResourceRepository.addCloudJobSubmission(cloudSubmission), - JobSubmissionProtocol.CLOUD, - priorityOrder); - logger.debug("Airavata registered Cloud job submission for compute resource id: " + computeResourceId); - return submissionInterface; + throws RegistryServiceException { + try { + ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); + String submissionInterface = addJobSubmissionInterface( + computeResourceRepository, + computeResourceId, + computeResourceRepository.addCloudJobSubmission(cloudSubmission), + JobSubmissionProtocol.CLOUD, + priorityOrder); + logger.debug("Airavata registered Cloud job submission for compute resource id: " + computeResourceId); + return submissionInterface; + } catch (Throwable e) { + throw convertException(e, "Error while adding cloud job submission details"); + } } public String addUNICOREJobSubmissionDetails( String computeResourceId, int priorityOrder, UnicoreJobSubmission unicoreJobSubmission) - throws AppCatalogException { - ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); - String submissionInterface = addJobSubmissionInterface( - computeResourceRepository, - computeResourceId, - computeResourceRepository.addUNICOREJobSubmission(unicoreJobSubmission), - JobSubmissionProtocol.UNICORE, - priorityOrder); - logger.debug("Airavata registered UNICORE job submission for compute resource id: " + computeResourceId); - return submissionInterface; + throws RegistryServiceException { + try { + ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); + String submissionInterface = addJobSubmissionInterface( + computeResourceRepository, + computeResourceId, + computeResourceRepository.addUNICOREJobSubmission(unicoreJobSubmission), + JobSubmissionProtocol.UNICORE, + priorityOrder); + logger.debug("Airavata registered UNICORE job submission for compute resource id: " + computeResourceId); + return submissionInterface; + } catch (Throwable e) { + throw convertException(e, "Error while adding UNICORE job submission details"); + } } // Application Interface/Module/Deployment operations public String registerApplicationInterface(String gatewayId, ApplicationInterfaceDescription applicationInterface) - throws AppCatalogException { + throws RegistryServiceException { try { if (!isGatewayExistInternal(gatewayId)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); + String interfaceId = applicationInterfaceRepository.addApplicationInterface(applicationInterface, gatewayId); + logger.debug("Airavata registered application interface for gateway id : " + gatewayId); + return interfaceId; + } catch (Throwable e) { + throw convertException(e, "Error while registering application interface"); } - String interfaceId = applicationInterfaceRepository.addApplicationInterface(applicationInterface, gatewayId); - logger.debug("Airavata registered application interface for gateway id : " + gatewayId); - return interfaceId; } public boolean updateApplicationInterface( - String appInterfaceId, ApplicationInterfaceDescription applicationInterface) throws AppCatalogException { - applicationInterfaceRepository.updateApplicationInterface(appInterfaceId, applicationInterface); - logger.debug("Airavata updated application interface with interface id : " + appInterfaceId); - return true; + String appInterfaceId, ApplicationInterfaceDescription applicationInterface) throws RegistryServiceException { + try { + applicationInterfaceRepository.updateApplicationInterface(appInterfaceId, applicationInterface); + logger.debug("Airavata updated application interface with interface id : " + appInterfaceId); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while updating application interface"); + } } public String registerApplicationModule(String gatewayId, ApplicationModule applicationModule) - throws AppCatalogException { + throws RegistryServiceException { try { if (!isGatewayExistInternal(gatewayId)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); + String module = applicationInterfaceRepository.addApplicationModule(applicationModule, gatewayId); + logger.debug("Airavata registered application module for gateway id : " + gatewayId); + return module; + } catch (Throwable e) { + throw convertException(e, "Error while registering application module"); } - String module = applicationInterfaceRepository.addApplicationModule(applicationModule, gatewayId); - logger.debug("Airavata registered application module for gateway id : " + gatewayId); - return module; } public boolean updateApplicationModule(String appModuleId, ApplicationModule applicationModule) - throws AppCatalogException { - applicationInterfaceRepository.updateApplicationModule(appModuleId, applicationModule); - logger.debug("Airavata updated application module with module id: " + appModuleId); - return true; + throws RegistryServiceException { + try { + applicationInterfaceRepository.updateApplicationModule(appModuleId, applicationModule); + logger.debug("Airavata updated application module with module id: " + appModuleId); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while updating application module"); + } } public String registerApplicationDeployment( - String gatewayId, ApplicationDeploymentDescription applicationDeployment) throws AppCatalogException { + String gatewayId, ApplicationDeploymentDescription applicationDeployment) throws RegistryServiceException { try { if (!isGatewayExistInternal(gatewayId)) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); + String deployment = applicationDeploymentRepository.addApplicationDeployment(applicationDeployment, gatewayId); + logger.debug("Airavata registered application deployment for gateway id : " + gatewayId); + return deployment; + } catch (Throwable e) { + throw convertException(e, "Error while registering application deployment"); } - String deployment = applicationDeploymentRepository.addApplicationDeployment(applicationDeployment, gatewayId); - logger.debug("Airavata registered application deployment for gateway id : " + gatewayId); - return deployment; } public boolean updateApplicationDeployment( - String appDeploymentId, ApplicationDeploymentDescription applicationDeployment) throws AppCatalogException { - applicationDeploymentRepository.updateApplicationDeployment(appDeploymentId, applicationDeployment); - logger.debug("Airavata updated application deployment for deployment id : " + appDeploymentId); - return true; + String appDeploymentId, ApplicationDeploymentDescription applicationDeployment) throws RegistryServiceException { + try { + applicationDeploymentRepository.updateApplicationDeployment(appDeploymentId, applicationDeployment); + logger.debug("Airavata updated application deployment for deployment id : " + appDeploymentId); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while updating application deployment"); + } } // User Resource Profile operations - public String registerUserResourceProfile(UserResourceProfile userResourceProfile) throws AppCatalogException { - if (!validateString(userResourceProfile.getUserId())) { - logger.error("Cannot create user resource profile with empty user id"); - throw new AppCatalogException("Cannot create user resource profile with empty user id"); - } - if (!validateString(userResourceProfile.getGatewayID())) { - logger.error("Cannot create user resource profile with empty gateway id"); - throw new AppCatalogException("Cannot create user resource profile with empty gateway id"); - } + public String registerUserResourceProfile(UserResourceProfile userResourceProfile) throws RegistryServiceException { try { + if (!validateString(userResourceProfile.getUserId())) { + logger.error("Cannot create user resource profile with empty user id"); + throw new AppCatalogException("Cannot create user resource profile with empty user id"); + } + if (!validateString(userResourceProfile.getGatewayID())) { + logger.error("Cannot create user resource profile with empty gateway id"); + throw new AppCatalogException("Cannot create user resource profile with empty gateway id"); + } if (!userRepository.isUserExists(userResourceProfile.getGatewayID(), userResourceProfile.getUserId())) { logger.error("User does not exist.Please provide a valid user ID..."); throw new AppCatalogException("User does not exist.Please provide a valid user ID..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); + String resourceProfile = userResourceProfileRepository.addUserResourceProfile(userResourceProfile); + logger.debug("Airavata registered user resource profile with gateway id : " + userResourceProfile.getGatewayID() + + "and user id : " + userResourceProfile.getUserId()); + return resourceProfile; + } catch (Throwable e) { + throw convertException(e, "Error while registering user resource profile"); } - String resourceProfile = userResourceProfileRepository.addUserResourceProfile(userResourceProfile); - logger.debug("Airavata registered user resource profile with gateway id : " + userResourceProfile.getGatewayID() - + "and user id : " + userResourceProfile.getUserId()); - return resourceProfile; } - public boolean isUserResourceProfileExists(String userId, String gatewayId) throws AppCatalogException { + public boolean isUserResourceProfileExists(String userId, String gatewayId) throws RegistryServiceException { try { if (!userRepository.isUserExists(gatewayId, userId)) { logger.error("user does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("user does not exist.Please provide a valid gateway id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); + return userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayId); + } catch (Throwable e) { + throw convertException(e, "Error while checking if user resource profile exists"); } - return userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayId); } - public UserResourceProfile getUserResourceProfile(String userId, String gatewayId) throws AppCatalogException { + public UserResourceProfile getUserResourceProfile(String userId, String gatewayId) throws RegistryServiceException { try { if (!userRepository.isUserExists(gatewayId, userId)) { logger.error("user does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("user does not exist.Please provide a valid gateway id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); + UserResourceProfile userResourceProfile = + userResourceProfileRepository.getUserResourceProfile(userId, gatewayId); + logger.debug("Airavata retrieved User resource profile with user id : " + userId); + return userResourceProfile; + } catch (Throwable e) { + throw convertException(e, "Error while getting user resource profile"); } - UserResourceProfile userResourceProfile = - userResourceProfileRepository.getUserResourceProfile(userId, gatewayId); - logger.debug("Airavata retrieved User resource profile with user id : " + userId); - return userResourceProfile; } public boolean updateUserResourceProfile(String userId, String gatewayID, UserResourceProfile userResourceProfile) - throws AppCatalogException { + throws RegistryServiceException { try { if (!userRepository.isUserExists(gatewayID, userId)) { logger.error("User does not exist.Please provide a valid user id..."); throw new AppCatalogException("user does not exist.Please provide a valid user id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); + userResourceProfileRepository.updateUserResourceProfile(userId, gatewayID, userResourceProfile); + logger.debug("Airavata updated gateway profile with gateway id : " + userId); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while updating user resource profile"); } - userResourceProfileRepository.updateUserResourceProfile(userId, gatewayID, userResourceProfile); - logger.debug("Airavata updated gateway profile with gateway id : " + userId); - return true; } - public boolean deleteUserResourceProfile(String userId, String gatewayID) throws AppCatalogException { + public boolean deleteUserResourceProfile(String userId, String gatewayID) throws RegistryServiceException { try { if (!userRepository.isUserExists(gatewayID, userId)) { logger.error("user does not exist.Please provide a valid user id..."); throw new AppCatalogException("user does not exist.Please provide a valid user id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); + userResourceProfileRepository.removeUserResourceProfile(userId, gatewayID); + logger.debug("Airavata deleted User profile with gateway id : " + gatewayID + " and user id : " + userId); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while deleting user resource profile"); } - userResourceProfileRepository.removeUserResourceProfile(userId, gatewayID); - logger.debug("Airavata deleted User profile with gateway id : " + gatewayID + " and user id : " + userId); - return true; } // Resource Scheduling operations public void updateResourceScheduleing( String airavataExperimentId, ComputationalResourceSchedulingModel resourceScheduling) - throws RegistryException { - if (!experimentRepository.isExperimentExist(airavataExperimentId)) { - logger.debug( - airavataExperimentId, - "Update resource scheduling failed, experiment {} doesn't exist.", - airavataExperimentId); - throw new RegistryException( - "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); - } - ExperimentStatus experimentStatus = getExperimentStatusInternal(airavataExperimentId); - if (experimentStatus != null) { - ExperimentState experimentState = experimentStatus.getState(); - switch (experimentState) { - case CREATED: - case VALIDATED: - case CANCELED: - case FAILED: - processRepository.addProcessResourceSchedule(resourceScheduling, airavataExperimentId); - logger.debug( - airavataExperimentId, - "Successfully updated resource scheduling for the experiment {}.", - airavataExperimentId); - break; - default: - logger.error( - airavataExperimentId, - "Error while updating scheduling info. Update experiment is only valid for experiments " - + "with status CREATED, VALIDATED, CANCELLED, FAILED and UNKNOWN. Make sure the given " - + "experiment is in one of above statuses... "); - throw new RegistryException( - "Error while updating experiment. Update experiment is only valid for experiments " - + "with status CREATED, VALIDATED, CANCELLED, FAILED and UNKNOWN. Make sure the given " - + "experiment is in one of above statuses... "); + throws RegistryServiceException { + try { + if (!experimentRepository.isExperimentExist(airavataExperimentId)) { + logger.debug( + airavataExperimentId, + "Update resource scheduling failed, experiment {} doesn't exist.", + airavataExperimentId); + throw new RegistryException( + "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); + } + ExperimentStatus experimentStatus = getExperimentStatusInternal(airavataExperimentId); + if (experimentStatus != null) { + ExperimentState experimentState = experimentStatus.getState(); + switch (experimentState) { + case CREATED: + case VALIDATED: + case CANCELED: + case FAILED: + processRepository.addProcessResourceSchedule(resourceScheduling, airavataExperimentId); + logger.debug( + airavataExperimentId, + "Successfully updated resource scheduling for the experiment {}.", + airavataExperimentId); + break; + default: + logger.error( + airavataExperimentId, + "Error while updating scheduling info. Update experiment is only valid for experiments " + + "with status CREATED, VALIDATED, CANCELLED, FAILED and UNKNOWN. Make sure the given " + + "experiment is in one of above statuses... "); + throw new RegistryException( + "Error while updating experiment. Update experiment is only valid for experiments " + + "with status CREATED, VALIDATED, CANCELLED, FAILED and UNKNOWN. Make sure the given " + + "experiment is in one of above statuses... "); + } } + } catch (Throwable e) { + throw convertException(e, "Error while updating resource scheduling"); } } // User operations - public String addUser(UserProfile userProfile) throws RegistryException { - logger.info("Adding User in Registry: " + userProfile); - if (userRepository.isUserExists(userProfile.getGatewayId(), userProfile.getUserId())) { - throw new RegistryException("User already exists, with userId: " + userProfile.getUserId() - + ", and gatewayId: " + userProfile.getGatewayId()); + public String addUser(UserProfile userProfile) throws RegistryServiceException { + try { + logger.info("Adding User in Registry: " + userProfile); + if (userRepository.isUserExists(userProfile.getGatewayId(), userProfile.getUserId())) { + throw new RegistryException("User already exists, with userId: " + userProfile.getUserId() + + ", and gatewayId: " + userProfile.getGatewayId()); + } + UserProfile savedUser = userRepository.addUser(userProfile); + return savedUser.getUserId(); + } catch (Throwable e) { + throw convertException(e, "Error while adding user"); } - UserProfile savedUser = userRepository.addUser(userProfile); - return savedUser.getUserId(); } // User Compute/Storage Preference operations @@ -2327,69 +2883,69 @@ public boolean addUserComputeResourcePreference( String gatewayID, String computeResourceId, UserComputeResourcePreference userComputeResourcePreference) - throws AppCatalogException { + throws RegistryServiceException { try { if (!userRepository.isUserExists(gatewayID, userId)) { logger.error("user does not exist.Please provide a valid user id..."); throw new AppCatalogException("user does not exist.Please provide a valid user id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); - } - if (!userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayID)) { - throw new AppCatalogException("User resource profile with user id'" + userId + " & gateway Id" + gatewayID - + "' does not exist!!!"); + if (!userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayID)) { + throw new AppCatalogException("User resource profile with user id'" + userId + " & gateway Id" + gatewayID + + "' does not exist!!!"); + } + UserResourceProfile profile = userResourceProfileRepository.getUserResourceProfile(userId, gatewayID); + profile.addToUserComputeResourcePreferences(userComputeResourcePreference); + userResourceProfileRepository.updateUserResourceProfile(userId, gatewayID, profile); + logger.debug("Airavata added User compute resource preference with gateway id : " + gatewayID + + " and for compute resource id : " + computeResourceId); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while adding user compute resource preference"); } - UserResourceProfile profile = userResourceProfileRepository.getUserResourceProfile(userId, gatewayID); - profile.addToUserComputeResourcePreferences(userComputeResourcePreference); - userResourceProfileRepository.updateUserResourceProfile(userId, gatewayID, profile); - logger.debug("Airavata added User compute resource preference with gateway id : " + gatewayID - + " and for compute resource id : " + computeResourceId); - return true; } public boolean isUserComputeResourcePreferenceExists(String userId, String gatewayID, String computeResourceId) - throws AppCatalogException { + throws RegistryServiceException { try { if (userRepository.isUserExists(gatewayID, userId) && userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayID)) { return userResourceProfileRepository.isUserComputeResourcePreferenceExists( userId, gatewayID, computeResourceId); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); + return false; + } catch (Throwable e) { + throw convertException(e, "Error while checking if user compute resource preference exists"); } - return false; } public UserComputeResourcePreference getUserComputeResourcePreference( - String userId, String gatewayID, String userComputeResourceId) throws AppCatalogException { + String userId, String gatewayID, String userComputeResourceId) throws RegistryServiceException { try { if (!userRepository.isUserExists(gatewayID, userId)) { logger.error("user does not exist.Please provide a valid user id..."); throw new AppCatalogException("user does not exist.Please provide a valid user id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); - } - if (!userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayID)) { - throw new AppCatalogException("User resource profile with user id'" + userId + " & gateway Id" + gatewayID - + "' does not exist!!!"); - } - ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); - if (!computeResourceRepository.isComputeResourceExists(userComputeResourceId)) { - logger.error( - userComputeResourceId, - "Given compute resource does not exist in the system. Please provide a valid compute resource id..."); - throw new AppCatalogException( - "Given compute resource does not exist in the system. Please provide a valid compute resource id..."); + if (!userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayID)) { + throw new AppCatalogException("User resource profile with user id'" + userId + " & gateway Id" + gatewayID + + "' does not exist!!!"); + } + ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); + if (!computeResourceRepository.isComputeResourceExists(userComputeResourceId)) { + logger.error( + userComputeResourceId, + "Given compute resource does not exist in the system. Please provide a valid compute resource id..."); + throw new AppCatalogException( + "Given compute resource does not exist in the system. Please provide a valid compute resource id..."); + } + UserComputeResourcePreference userComputeResourcePreference = + userResourceProfileRepository.getUserComputeResourcePreference( + userId, gatewayID, userComputeResourceId); + logger.debug("Airavata retrieved user compute resource preference with gateway id : " + gatewayID + + " and for compute resoruce id : " + userComputeResourceId); + return userComputeResourcePreference; + } catch (Throwable e) { + throw convertException(e, "Error while getting user compute resource preference"); } - UserComputeResourcePreference userComputeResourcePreference = - userResourceProfileRepository.getUserComputeResourcePreference( - userId, gatewayID, userComputeResourceId); - logger.debug("Airavata retrieved user compute resource preference with gateway id : " + gatewayID - + " and for compute resoruce id : " + userComputeResourceId); - return userComputeResourcePreference; } public boolean updateUserComputeResourcePreference( @@ -2397,456 +2953,580 @@ public boolean updateUserComputeResourcePreference( String gatewayID, String computeResourceId, UserComputeResourcePreference userComputeResourcePreference) - throws AppCatalogException { + throws RegistryServiceException { try { if (!userRepository.isUserExists(gatewayID, userId)) { logger.error("user does not exist.Please provide a valid user id..."); throw new AppCatalogException("user does not exist.Please provide a valid user id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); - } - UserResourceProfile profile = userResourceProfileRepository.getUserResourceProfile(userId, gatewayID); - List userComputeResourcePreferences = - profile.getUserComputeResourcePreferences(); - UserComputeResourcePreference preferenceToRemove = null; - for (UserComputeResourcePreference preference : userComputeResourcePreferences) { - if (preference.getComputeResourceId().equals(computeResourceId)) { - preferenceToRemove = preference; - break; + UserResourceProfile profile = userResourceProfileRepository.getUserResourceProfile(userId, gatewayID); + List userComputeResourcePreferences = + profile.getUserComputeResourcePreferences(); + UserComputeResourcePreference preferenceToRemove = null; + for (UserComputeResourcePreference preference : userComputeResourcePreferences) { + if (preference.getComputeResourceId().equals(computeResourceId)) { + preferenceToRemove = preference; + break; + } } + if (preferenceToRemove != null) { + profile.getUserComputeResourcePreferences().remove(preferenceToRemove); + } + profile.getUserComputeResourcePreferences().add(userComputeResourcePreference); + userResourceProfileRepository.updateUserResourceProfile(userId, gatewayID, profile); + logger.debug("Airavata updated compute resource preference with gateway id : " + gatewayID + + " and for compute resource id : " + computeResourceId); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while updating user compute resource preference"); } - if (preferenceToRemove != null) { - profile.getUserComputeResourcePreferences().remove(preferenceToRemove); - } - profile.getUserComputeResourcePreferences().add(userComputeResourcePreference); - userResourceProfileRepository.updateUserResourceProfile(userId, gatewayID, profile); - logger.debug("Airavata updated compute resource preference with gateway id : " + gatewayID - + " and for compute resource id : " + computeResourceId); - return true; } public boolean addUserStoragePreference( String userId, String gatewayID, String storageResourceId, UserStoragePreference dataStoragePreference) - throws AppCatalogException { + throws RegistryServiceException { try { if (!userRepository.isUserExists(gatewayID, userId)) { logger.error("user does not exist.Please provide a valid user id..."); throw new AppCatalogException("user does not exist.Please provide a valid user id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); - } - if (!userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayID)) { - throw new AppCatalogException("User resource profile with user id'" + userId + " & gateway Id" + gatewayID - + "' does not exist!!!"); + if (!userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayID)) { + throw new AppCatalogException("User resource profile with user id'" + userId + " & gateway Id" + gatewayID + + "' does not exist!!!"); + } + UserResourceProfile profile = userResourceProfileRepository.getUserResourceProfile(userId, gatewayID); + dataStoragePreference.setStorageResourceId(storageResourceId); + profile.addToUserStoragePreferences(dataStoragePreference); + userResourceProfileRepository.updateUserResourceProfile(userId, gatewayID, profile); + logger.debug("Airavata added storage resource preference with gateway id : " + gatewayID + + " and for storage resource id : " + storageResourceId); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while adding user storage preference"); } - UserResourceProfile profile = userResourceProfileRepository.getUserResourceProfile(userId, gatewayID); - dataStoragePreference.setStorageResourceId(storageResourceId); - profile.addToUserStoragePreferences(dataStoragePreference); - userResourceProfileRepository.updateUserResourceProfile(userId, gatewayID, profile); - logger.debug("Airavata added storage resource preference with gateway id : " + gatewayID - + " and for storage resource id : " + storageResourceId); - return true; } public UserStoragePreference getUserStoragePreference(String userId, String gatewayID, String storageId) - throws AppCatalogException { + throws RegistryServiceException { try { if (!userRepository.isUserExists(gatewayID, userId)) { logger.error("user does not exist.Please provide a valid user id..."); throw new AppCatalogException("user does not exist.Please provide a valid user id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); - } - if (!userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayID)) { - throw new AppCatalogException("User resource profile with user id'" + userId + " & gateway Id" + gatewayID - + "' does not exist!!!"); - } + if (!userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayID)) { + throw new AppCatalogException("User resource profile with user id'" + userId + " & gateway Id" + gatewayID + + "' does not exist!!!"); + } - UserStoragePreference storagePreference = - userResourceProfileRepository.getUserStoragePreference(userId, gatewayID, storageId); - logger.debug("Airavata retrieved user storage resource preference with gateway id : " + gatewayID - + " and for storage resource id : " + storageId); - return storagePreference; + UserStoragePreference storagePreference = + userResourceProfileRepository.getUserStoragePreference(userId, gatewayID, storageId); + logger.debug("Airavata retrieved user storage resource preference with gateway id : " + gatewayID + + " and for storage resource id : " + storageId); + return storagePreference; + } catch (Throwable e) { + throw convertException(e, "Error while getting user storage preference"); + } } - public List getAllUserResourceProfiles() throws AppCatalogException { - return userResourceProfileRepository.getAllUserResourceProfiles(); + public List getAllUserResourceProfiles() throws RegistryServiceException { + try { + return userResourceProfileRepository.getAllUserResourceProfiles(); + } catch (Throwable e) { + throw convertException(e, "Error while getting all user resource profiles"); + } } // Gateway Groups operations - public GatewayGroups getGatewayGroups(String gatewayId) throws RegistryException { - if (!gatewayGroupsRepository.isExists(gatewayId)) { - final String message = "No GatewayGroups entry exists for " + gatewayId; - logger.error(message); - throw new RegistryException(message); + public GatewayGroups getGatewayGroups(String gatewayId) throws RegistryServiceException { + try { + if (!gatewayGroupsRepository.isExists(gatewayId)) { + final String message = "No GatewayGroups entry exists for " + gatewayId; + logger.error(message); + throw new RegistryException(message); + } + return gatewayGroupsRepository.get(gatewayId); + } catch (Throwable e) { + throw convertException(e, "Error while getting gateway groups"); } - return gatewayGroupsRepository.get(gatewayId); } // Parser operations - public Parser getParser(String parserId, String gatewayId) throws RegistryException { - if (!parserRepository.isExists(parserId)) { - final String message = "No Parser Info entry exists for " + parserId; - logger.error(message); - throw new RegistryException(message); + public Parser getParser(String parserId, String gatewayId) throws RegistryServiceException { + try { + if (!parserRepository.isExists(parserId)) { + final String message = "No Parser Info entry exists for " + parserId; + logger.error(message); + throw new RegistryException(message); + } + return parserRepository.get(parserId); + } catch (Throwable e) { + throw convertException(e, "Error while getting parser"); } - return parserRepository.get(parserId); } - public String saveParser(Parser parser) throws RegistryException { + public String saveParser(Parser parser) throws RegistryServiceException { try { Parser saved = parserRepository.saveParser(parser); return saved.getId(); - } catch (AppCatalogException e) { - throw new RegistryException("Error saving parser: " + e.getMessage(), e); + } catch (Throwable e) { + throw convertException(e, "Error while saving parser"); } } - public void removeParser(String parserId, String gatewayId) throws RegistryException { - boolean exists = parserRepository.isExists(parserId); - if (exists && !gatewayId.equals(parserRepository.get(parserId).getGatewayId())) { + public void removeParser(String parserId, String gatewayId) throws RegistryServiceException { + try { + boolean exists = parserRepository.isExists(parserId); + if (!exists || gatewayId.equals(parserRepository.get(parserId).getGatewayId())) { + throw new RegistryException("Parser " + parserId + " does not exist"); + } parserRepository.delete(parserId); - } else { - throw new RegistryException("Parser " + parserId + " does not exist"); + } catch (Throwable e) { + throw convertException(e, "Error while removing parser"); } } - public ParserInput getParserInput(String parserInputId, String gatewayId) throws RegistryException { + public ParserInput getParserInput(String parserInputId, String gatewayId) throws RegistryServiceException { if (!parserInputRepository.isExists(parserInputId)) { - final String message = "No ParserInput entry exists for " + parserInputId; - logger.error(message); - throw new RegistryException(message); + try { + final String message = "No ParserInput entry exists for " + parserInputId; + logger.error(message); + throw new RegistryException(message); + } catch (Throwable e) { + throw convertException(e, "Error in getParserInput"); + } } return parserInputRepository.get(parserInputId); } - public String saveParserInput(ParserInput parserInput) throws RegistryException { + public String saveParserInput(ParserInput parserInput) throws RegistryServiceException { ParserInput saved = parserInputRepository.create(parserInput); return saved.getId(); } - public void removeParserInput(String parserInputId, String gatewayId) throws RegistryException { - boolean exists = parserInputRepository.isExists(parserInputId); - if (exists) { + public void removeParserInput(String parserInputId, String gatewayId) throws RegistryServiceException { + try { + boolean exists = parserInputRepository.isExists(parserInputId); + if (!exists) { + throw new RegistryException("ParserInput " + parserInputId + " does not exist"); + } ParserInput parserInput = parserInputRepository.get(parserInputId); Parser parser = parserRepository.get(parserInput.getParserId()); - if (gatewayId.equals(parser.getGatewayId())) { - parserInputRepository.delete(parserInputId); - } else { + if (!gatewayId.equals(parser.getGatewayId())) { throw new RegistryException( "ParserInput " + parserInputId + " does not belong to gateway " + gatewayId); } - } else { - throw new RegistryException("ParserInput " + parserInputId + " does not exist"); + parserInputRepository.delete(parserInputId); + } catch (Throwable e) { + throw convertException(e, "Error in removeParserInput"); } } - public ParserOutput getParserOutput(String parserOutputId, String gatewayId) throws RegistryException { - if (!parserOutputRepository.isExists(parserOutputId)) { - final String message = "No ParserOutput entry exists for " + parserOutputId; - logger.error(message); - throw new RegistryException(message); + public ParserOutput getParserOutput(String parserOutputId, String gatewayId) throws RegistryServiceException { + try { + if (!parserOutputRepository.isExists(parserOutputId)) { + final String message = "No ParserOutput entry exists for " + parserOutputId; + logger.error(message); + throw new RegistryException(message); + } + return parserOutputRepository.get(parserOutputId); + } catch (Throwable e) { + throw convertException(e, "Error in getParserOutput"); } - return parserOutputRepository.get(parserOutputId); } - public String saveParserOutput(ParserOutput parserOutput) throws RegistryException { - ParserOutput saved = parserOutputRepository.create(parserOutput); - return saved.getId(); + public String saveParserOutput(ParserOutput parserOutput) throws RegistryServiceException { + try { + ParserOutput saved = parserOutputRepository.create(parserOutput); + return saved.getId(); + } catch (Throwable e) { + throw convertException(e, "Error while saving parser output"); + } } - public void removeParserOutput(String parserOutputId, String gatewayId) throws RegistryException { - boolean exists = parserOutputRepository.isExists(parserOutputId); - if (exists) { + public void removeParserOutput(String parserOutputId, String gatewayId) throws RegistryServiceException { + try { + boolean exists = parserOutputRepository.isExists(parserOutputId); + if (!exists) { + throw new RegistryException("ParserOutput " + parserOutputId + " does not exist"); + } ParserOutput parserOutput = parserOutputRepository.get(parserOutputId); Parser parser = parserRepository.get(parserOutput.getParserId()); - if (gatewayId.equals(parser.getGatewayId())) { - parserOutputRepository.delete(parserOutputId); - } else { + if (!gatewayId.equals(parser.getGatewayId())) { throw new RegistryException( "ParserOutput " + parserOutputId + " does not belong to gateway " + gatewayId); } - } else { - throw new RegistryException("ParserOutput " + parserOutputId + " does not exist"); + parserOutputRepository.delete(parserOutputId); + } catch (Throwable e) { + throw convertException(e, "Error in removeParserOutput"); } } - public ParsingTemplate getParsingTemplate(String templateId, String gatewayId) throws RegistryException { - if (!parsingTemplateRepository.isExists(templateId)) { - final String message = "No ParsingTemplate entry exists for " + templateId; - logger.error(message); - throw new RegistryException(message); + public ParsingTemplate getParsingTemplate(String templateId, String gatewayId) throws RegistryServiceException { + try { + if (!parsingTemplateRepository.isExists(templateId)) { + final String message = "No ParsingTemplate entry exists for " + templateId; + logger.error(message); + throw new RegistryException(message); + } + return parsingTemplateRepository.get(templateId); + } catch (Throwable e) { + throw convertException(e, "Error in getParsingTemplate"); } - return parsingTemplateRepository.get(templateId); } - public String saveParsingTemplate(ParsingTemplate parsingTemplate) throws RegistryException { - ParsingTemplate saved = parsingTemplateRepository.create(parsingTemplate); - return saved.getId(); + public String saveParsingTemplate(ParsingTemplate parsingTemplate) throws RegistryServiceException { + try { + ParsingTemplate saved = parsingTemplateRepository.create(parsingTemplate); + return saved.getId(); + } catch (Throwable e) { + throw convertException(e, "Error while saving parsing template"); + } } - public void removeParsingTemplate(String templateId, String gatewayId) throws RegistryException { - boolean exists = parsingTemplateRepository.isExists(templateId); - if (exists - && !gatewayId.equals(parsingTemplateRepository.get(templateId).getGatewayId())) { + public void removeParsingTemplate(String templateId, String gatewayId) throws RegistryServiceException { + try { + boolean exists = parsingTemplateRepository.isExists(templateId); + if (!exists || gatewayId.equals(parsingTemplateRepository.get(templateId).getGatewayId())) { + throw new RegistryException("Parsing template " + templateId + " does not exist"); + } parsingTemplateRepository.delete(templateId); - } else { - throw new RegistryException("Parsing template " + templateId + " does not exist"); + } catch (Throwable e) { + throw convertException(e, "Error in removeParsingTemplate"); } } // Gateway Usage Reporting operations public boolean isGatewayUsageReportingAvailable(String gatewayId, String computeResourceId) - throws RegistryException { - return usageReportingCommandRepository.isGatewayUsageReportingCommandExists(gatewayId, computeResourceId); + throws RegistryServiceException { + try { + return usageReportingCommandRepository.isGatewayUsageReportingCommandExists(gatewayId, computeResourceId); + } catch (Throwable e) { + throw convertException(e, "Error while checking if gateway usage reporting is available"); + } } public GatewayUsageReportingCommand getGatewayReportingCommand(String gatewayId, String computeResourceId) - throws RegistryException { - if (usageReportingCommandRepository.isGatewayUsageReportingCommandExists(gatewayId, computeResourceId)) { + throws RegistryServiceException { + try { + if (!usageReportingCommandRepository.isGatewayUsageReportingCommandExists(gatewayId, computeResourceId)) { + String message = "No usage reporting information for the gateway " + gatewayId + " and compute resource " + + computeResourceId; + logger.error(message); + throw new RegistryException(message); + } return usageReportingCommandRepository.getGatewayUsageReportingCommand(gatewayId, computeResourceId); - } else { - String message = "No usage reporting information for the gateway " + gatewayId + " and compute resource " - + computeResourceId; - logger.error(message); - throw new RegistryException(message); + } catch (Throwable e) { + throw convertException(e, "Error while getting gateway reporting command"); } } - public void addGatewayUsageReportingCommand(GatewayUsageReportingCommand command) throws RegistryException { - usageReportingCommandRepository.addGatewayUsageReportingCommand(command); + public void addGatewayUsageReportingCommand(GatewayUsageReportingCommand command) throws RegistryServiceException { + try { + usageReportingCommandRepository.addGatewayUsageReportingCommand(command); + } catch (Throwable e) { + throw convertException(e, "Error while adding gateway usage reporting command"); + } } public void removeGatewayUsageReportingCommand(String gatewayId, String computeResourceId) - throws RegistryException { - usageReportingCommandRepository.removeGatewayUsageReportingCommand(gatewayId, computeResourceId); + throws RegistryServiceException { + try { + usageReportingCommandRepository.removeGatewayUsageReportingCommand(gatewayId, computeResourceId); + } catch (Throwable e) { + throw convertException(e, "Error while removing gateway usage reporting command"); + } } public boolean updateCloudJobSubmissionDetails( - String jobSubmissionInterfaceId, CloudJobSubmission cloudJobSubmission) throws AppCatalogException { - cloudJobSubmission.setJobSubmissionInterfaceId(jobSubmissionInterfaceId); - computeResourceRepository.updateCloudJobSubmission(cloudJobSubmission); - logger.debug( - "Airavata updated Cloud job submission for job submission interface id: " + jobSubmissionInterfaceId); - return true; + String jobSubmissionInterfaceId, CloudJobSubmission cloudJobSubmission) throws RegistryServiceException { + try { + cloudJobSubmission.setJobSubmissionInterfaceId(jobSubmissionInterfaceId); + computeResourceRepository.updateCloudJobSubmission(cloudJobSubmission); + logger.debug( + "Airavata updated Cloud job submission for job submission interface id: " + jobSubmissionInterfaceId); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while updating cloud job submission details"); + } } public boolean updateSSHJobSubmissionDetails(String jobSubmissionInterfaceId, SSHJobSubmission sshJobSubmission) - throws AppCatalogException { - sshJobSubmission.setJobSubmissionInterfaceId(jobSubmissionInterfaceId); - computeResourceRepository.updateSSHJobSubmission(sshJobSubmission); - logger.debug( - "Airavata updated SSH job submission for job submission interface id: " + jobSubmissionInterfaceId); - return true; + throws RegistryServiceException { + try { + sshJobSubmission.setJobSubmissionInterfaceId(jobSubmissionInterfaceId); + computeResourceRepository.updateSSHJobSubmission(sshJobSubmission); + logger.debug( + "Airavata updated SSH job submission for job submission interface id: " + jobSubmissionInterfaceId); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while updating SSH job submission details"); + } } public boolean updateUnicoreJobSubmissionDetails( - String jobSubmissionInterfaceId, UnicoreJobSubmission unicoreJobSubmission) throws AppCatalogException { - unicoreJobSubmission.setJobSubmissionInterfaceId(jobSubmissionInterfaceId); - computeResourceRepository.updateUNICOREJobSubmission(unicoreJobSubmission); - logger.debug( - "Airavata updated UNICORE job submission for job submission interface id: " + jobSubmissionInterfaceId); - return true; + String jobSubmissionInterfaceId, UnicoreJobSubmission unicoreJobSubmission) throws RegistryServiceException { + try { + unicoreJobSubmission.setJobSubmissionInterfaceId(jobSubmissionInterfaceId); + computeResourceRepository.updateUNICOREJobSubmission(unicoreJobSubmission); + logger.debug( + "Airavata updated UNICORE job submission for job submission interface id: " + jobSubmissionInterfaceId); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while updating Unicore job submission details"); + } } - public boolean updateNotification(Notification notification) throws RegistryException { - notificationRepository.updateNotification(notification); - logger.debug("Airavata updated notification with notification id: " + notification.getNotificationId()); - return true; + public boolean updateNotification(Notification notification) throws RegistryServiceException { + try { + notificationRepository.updateNotification(notification); + logger.debug("Airavata updated notification with notification id: " + notification.getNotificationId()); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while updating notification"); + } } - public String createNotification(Notification notification) throws RegistryException { - String notificationId = notificationRepository.createNotification(notification); - logger.debug("Airavata created notification with notification id: " + notificationId); - return notificationId; + public String createNotification(Notification notification) throws RegistryServiceException { + try { + String notificationId = notificationRepository.createNotification(notification); + logger.debug("Airavata created notification with notification id: " + notificationId); + return notificationId; + } catch (Throwable e) { + throw convertException(e, "Error while creating notification"); + } } public boolean updateGateway(String gatewayId, Gateway updatedGateway) - throws RegistryException, AppCatalogException { - if (!gatewayRepository.isGatewayExist(gatewayId)) { - logger.error("Gateway does not exist in the system. Please provide a valid gateway ID..."); - throw new RegistryException("Gateway does not exist in the system. Please provide a valid gateway ID..."); + throws RegistryServiceException { + try { + if (!gatewayRepository.isGatewayExist(gatewayId)) { + logger.error("Gateway does not exist in the system. Please provide a valid gateway ID..."); + throw new RegistryException("Gateway does not exist in the system. Please provide a valid gateway ID..."); + } + updatedGateway.setGatewayId(gatewayId); + gatewayRepository.updateGateway(gatewayId, updatedGateway); + logger.debug("Airavata updated gateway with gateway id: " + gatewayId); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while updating gateway"); } - updatedGateway.setGatewayId(gatewayId); - gatewayRepository.updateGateway(gatewayId, updatedGateway); - logger.debug("Airavata updated gateway with gateway id: " + gatewayId); - return true; } - public String addGateway(Gateway gateway) throws RegistryException, AppCatalogException { - if (gatewayRepository.isGatewayExist(gateway.getGatewayId())) { - logger.error("Gateway already exists in the system. Please provide a different gateway ID..."); - throw new AppCatalogException( - "Gateway already exists in the system. Please provide a different gateway ID..."); + public String addGateway(Gateway gateway) throws RegistryServiceException { + try { + if (gatewayRepository.isGatewayExist(gateway.getGatewayId())) { + logger.error("Gateway already exists in the system. Please provide a different gateway ID..."); + throw new AppCatalogException( + "Gateway already exists in the system. Please provide a different gateway ID..."); + } + String gatewayId = gatewayRepository.addGateway(gateway); + logger.debug("Airavata registered gateway with gateway id: " + gatewayId); + return gatewayId; + } catch (Throwable e) { + throw convertException(e, "Error while adding gateway"); } - String gatewayId = gatewayRepository.addGateway(gateway); - logger.debug("Airavata registered gateway with gateway id: " + gatewayId); - return gatewayId; } public boolean updateUserStoragePreference( String userId, String gatewayID, String storageId, UserStoragePreference userStoragePreference) - throws AppCatalogException { + throws RegistryServiceException { try { if (!userRepository.isUserExists(gatewayID, userId)) { logger.error("user does not exist.Please provide a valid user id..."); throw new AppCatalogException("user does not exist.Please provide a valid user id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); - } - if (!userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayID)) { - throw new AppCatalogException("User resource profile with user id'" + userId + " & gateway Id" + gatewayID - + "' does not exist!!!"); - } - UserResourceProfile profile = userResourceProfileRepository.getUserResourceProfile(userId, gatewayID); - List userStoragePreferences = profile.getUserStoragePreferences(); - UserStoragePreference preferenceToRemove = null; - for (UserStoragePreference preference : userStoragePreferences) { - if (preference.getStorageResourceId().equals(storageId)) { - preferenceToRemove = preference; - break; + if (!userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayID)) { + throw new AppCatalogException("User resource profile with user id'" + userId + " & gateway Id" + gatewayID + + "' does not exist!!!"); } + UserResourceProfile profile = userResourceProfileRepository.getUserResourceProfile(userId, gatewayID); + List userStoragePreferences = profile.getUserStoragePreferences(); + UserStoragePreference preferenceToRemove = null; + for (UserStoragePreference preference : userStoragePreferences) { + if (preference.getStorageResourceId().equals(storageId)) { + preferenceToRemove = preference; + break; + } + } + if (preferenceToRemove != null) { + profile.getUserStoragePreferences().remove(preferenceToRemove); + } + userStoragePreference.setStorageResourceId(storageId); + profile.getUserStoragePreferences().add(userStoragePreference); + userResourceProfileRepository.updateUserResourceProfile(userId, gatewayID, profile); + logger.debug("Airavata updated storage resource preference with gateway id : " + gatewayID + + " and for storage resource id : " + storageId); + return true; + } catch (Throwable e) { + throw convertException(e, "Error while updating user storage preference"); } - if (preferenceToRemove != null) { - profile.getUserStoragePreferences().remove(preferenceToRemove); - } - userStoragePreference.setStorageResourceId(storageId); - profile.getUserStoragePreferences().add(userStoragePreference); - userResourceProfileRepository.updateUserResourceProfile(userId, gatewayID, profile); - logger.debug("Airavata updated storage resource preference with gateway id : " + gatewayID - + " and for storage resource id : " + storageId); - return true; } public boolean deleteUserComputeResourcePreference(String userId, String gatewayID, String computeResourceId) - throws AppCatalogException { + throws RegistryServiceException { try { if (!userRepository.isUserExists(gatewayID, userId)) { logger.error("user does not exist.Please provide a valid user id..."); throw new AppCatalogException("user does not exist.Please provide a valid user id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); + return userResourceProfileRepository.removeUserComputeResourcePreferenceFromGateway( + userId, gatewayID, computeResourceId); + } catch (Throwable e) { + throw convertException(e, "Error while deleting user compute resource preference"); } - return userResourceProfileRepository.removeUserComputeResourcePreferenceFromGateway( - userId, gatewayID, computeResourceId); } public boolean deleteUserStoragePreference(String userId, String gatewayID, String storageId) - throws AppCatalogException { + throws RegistryServiceException { try { if (!userRepository.isUserExists(gatewayID, userId)) { logger.error("user does not exist.Please provide a valid user id..."); throw new AppCatalogException("user does not exist.Please provide a valid user id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); + return userResourceProfileRepository.removeUserDataStoragePreferenceFromGateway(userId, gatewayID, storageId); + } catch (Throwable e) { + throw convertException(e, "Error while deleting user storage preference"); } - return userResourceProfileRepository.removeUserDataStoragePreferenceFromGateway(userId, gatewayID, storageId); } - public List getLatestQueueStatuses() throws RegistryException { - return queueStatusRepository.getLatestQueueStatuses(); + public List getLatestQueueStatuses() throws RegistryServiceException { + try { + return queueStatusRepository.getLatestQueueStatuses(); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving latest queue statuses"); + } } - public void registerQueueStatuses(List queueStatuses) throws RegistryException { - queueStatusRepository.createQueueStatuses(queueStatuses); + public void registerQueueStatuses(List queueStatuses) throws RegistryServiceException { + try { + queueStatusRepository.createQueueStatuses(queueStatuses); + } catch (Throwable e) { + throw convertException(e, "Error while registering queue statuses"); + } } - public QueueStatusModel getQueueStatus(String hostName, String queueName) throws RegistryException { - Optional optionalQueueStatusModel = queueStatusRepository.getQueueStatus(hostName, queueName); - if (optionalQueueStatusModel.isPresent()) { - return optionalQueueStatusModel.get(); - } else { - QueueStatusModel queueStatusModel = new QueueStatusModel(); - queueStatusModel.setHostName(hostName); - queueStatusModel.setQueueName(queueName); - queueStatusModel.setQueueUp(false); - queueStatusModel.setRunningJobs(0); - queueStatusModel.setQueuedJobs(0); - queueStatusModel.setTime(0); - return queueStatusModel; + public QueueStatusModel getQueueStatus(String hostName, String queueName) throws RegistryServiceException { + try { + Optional optionalQueueStatusModel = queueStatusRepository.getQueueStatus(hostName, queueName); + if (optionalQueueStatusModel.isPresent()) { + return optionalQueueStatusModel.get(); + } else { + QueueStatusModel queueStatusModel = new QueueStatusModel(); + queueStatusModel.setHostName(hostName); + queueStatusModel.setQueueName(queueName); + queueStatusModel.setQueueUp(false); + queueStatusModel.setRunningJobs(0); + queueStatusModel.setQueuedJobs(0); + queueStatusModel.setTime(0); + return queueStatusModel; + } + } catch (Throwable e) { + throw convertException(e, "Error while retrieving queue status"); } } - public void createGatewayGroups(GatewayGroups gatewayGroups) throws RegistryException { - if (gatewayGroupsRepository.isExists(gatewayGroups.getGatewayId())) { - logger.error("GatewayGroups already exists for " + gatewayGroups.getGatewayId()); - throw new RegistryException( - "GatewayGroups for gatewayId: " + gatewayGroups.getGatewayId() + " already exists."); + public void createGatewayGroups(GatewayGroups gatewayGroups) throws RegistryServiceException { + try { + if (gatewayGroupsRepository.isExists(gatewayGroups.getGatewayId())) { + logger.error("GatewayGroups already exists for " + gatewayGroups.getGatewayId()); + throw new RegistryException( + "GatewayGroups for gatewayId: " + gatewayGroups.getGatewayId() + " already exists."); + } + gatewayGroupsRepository.create(gatewayGroups); + } catch (Throwable e) { + throw convertException(e, "Error while creating gateway groups"); } - gatewayGroupsRepository.create(gatewayGroups); } - public void updateGatewayGroups(GatewayGroups gatewayGroups) throws RegistryException { - if (!gatewayGroupsRepository.isExists(gatewayGroups.getGatewayId())) { - final String message = "No GatewayGroups entry exists for " + gatewayGroups.getGatewayId(); - logger.error(message); - throw new RegistryException(message); + public void updateGatewayGroups(GatewayGroups gatewayGroups) throws RegistryServiceException { + try { + if (!gatewayGroupsRepository.isExists(gatewayGroups.getGatewayId())) { + final String message = "No GatewayGroups entry exists for " + gatewayGroups.getGatewayId(); + logger.error(message); + throw new RegistryException(message); + } + gatewayGroupsRepository.update(gatewayGroups); + } catch (Throwable e) { + throw convertException(e, "Error while updating gateway groups"); } - gatewayGroupsRepository.update(gatewayGroups); } - public boolean isGatewayGroupsExists(String gatewayId) throws RegistryException { - return gatewayGroupsRepository.isExists(gatewayId); + public boolean isGatewayGroupsExists(String gatewayId) throws RegistryServiceException { + try { + return gatewayGroupsRepository.isExists(gatewayId); + } catch (Throwable e) { + throw convertException(e, "Error while checking if gateway groups exist"); + } } - public List listAllParsers(String gatewayId) throws RegistryException { - return parserRepository.getAllParsers(gatewayId); + public List listAllParsers(String gatewayId) throws RegistryServiceException { + try { + return parserRepository.getAllParsers(gatewayId); + } catch (Throwable e) { + throw convertException(e, "Error while listing all parsers"); + } } public List getParsingTemplatesForApplication(String applicationInterfaceId) - throws RegistryException { - return parsingTemplateRepository.getParsingTemplatesForApplication(applicationInterfaceId); + throws RegistryServiceException { + try { + return parsingTemplateRepository.getParsingTemplatesForApplication(applicationInterfaceId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving parsing templates for application"); + } } public List getParsingTemplatesForExperiment(String experimentId, String gatewayId) - throws RegistryException { - ExperimentModel experiment = experimentRepository.getExperiment(experimentId); - List processes = experiment.getProcesses(); - if (processes != null && processes.size() > 0) { - return parsingTemplateRepository.getParsingTemplatesForApplication( - processes.get(processes.size() - 1).getApplicationInterfaceId()); + throws RegistryServiceException { + try { + ExperimentModel experiment = experimentRepository.getExperiment(experimentId); + List processes = experiment.getProcesses(); + if (processes != null && processes.size() > 0) { + return parsingTemplateRepository.getParsingTemplatesForApplication( + processes.get(processes.size() - 1).getApplicationInterfaceId()); + } + return Collections.emptyList(); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving parsing templates for experiment"); } - return Collections.emptyList(); } - public List listAllParsingTemplates(String gatewayId) throws RegistryException { - return parsingTemplateRepository.getAllParsingTemplates(gatewayId); + public List listAllParsingTemplates(String gatewayId) throws RegistryServiceException { + try { + return parsingTemplateRepository.getAllParsingTemplates(gatewayId); + } catch (Throwable e) { + throw convertException(e, "Error while listing all parsing templates"); + } } public List getAllUserComputeResourcePreferences(String userId, String gatewayID) - throws AppCatalogException { + throws RegistryServiceException { try { if (!userRepository.isUserExists(gatewayID, userId)) { logger.error("User Resource Profile does not exist.Please provide a valid gateway id..."); throw new AppCatalogException( "User Resource Profile does not exist.Please provide a valid gateway id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); + return userResourceProfileRepository + .getUserResourceProfile(userId, gatewayID) + .getUserComputeResourcePreferences(); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving all user compute resource preferences"); } - return userResourceProfileRepository - .getUserResourceProfile(userId, gatewayID) - .getUserComputeResourcePreferences(); } public List getAllUserStoragePreferences(String userId, String gatewayID) - throws AppCatalogException { + throws RegistryServiceException { try { if (!userRepository.isUserExists(gatewayID, userId)) { logger.error("User does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - } catch (RegistryException e) { - throw new AppCatalogException(e.getMessage(), e); + return userResourceProfileRepository + .getUserResourceProfile(userId, gatewayID) + .getUserStoragePreferences(); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving all user storage preferences"); } - return userResourceProfileRepository - .getUserResourceProfile(userId, gatewayID) - .getUserStoragePreferences(); } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/SharingRegistryService.java b/airavata-api/src/main/java/org/apache/airavata/service/SharingRegistryService.java index 583e11c9d8..04001dee9a 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/SharingRegistryService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/SharingRegistryService.java @@ -26,6 +26,7 @@ import org.apache.airavata.sharing.registry.db.repositories.*; import org.apache.airavata.sharing.registry.db.utils.DBConstants; import org.apache.airavata.sharing.registry.models.*; +import org.apache.commons.lang3.exception.ExceptionUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,55 +35,100 @@ public class SharingRegistryService { public static String OWNER_PERMISSION_NAME = "OWNER"; + private SharingRegistryException convertException(Throwable ex, String context) { + logger.error(context + ": " + ex.getMessage(), ex); + return new SharingRegistryException(context + ": " + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + } + /** * * Domain Operations * * */ public String createDomain(Domain domain) throws SharingRegistryException, DuplicateEntryException { - if ((new DomainRepository()).get(domain.getDomainId()) != null) - throw new DuplicateEntryException("There exist domain with given domain id"); - - domain.setCreatedTime(System.currentTimeMillis()); - domain.setUpdatedTime(System.currentTimeMillis()); - (new DomainRepository()).create(domain); - - // create the global permission for the domain - PermissionType permissionType = new PermissionType(); - permissionType.setPermissionTypeId(domain.getDomainId() + ":" + OWNER_PERMISSION_NAME); - permissionType.setDomainId(domain.getDomainId()); - permissionType.setName(OWNER_PERMISSION_NAME); - permissionType.setDescription("GLOBAL permission to " + domain.getDomainId()); - permissionType.setCreatedTime(System.currentTimeMillis()); - permissionType.setUpdatedTime(System.currentTimeMillis()); - (new PermissionTypeRepository()).create(permissionType); - - return domain.getDomainId(); + try { + if ((new DomainRepository()).get(domain.getDomainId()) != null) + throw new DuplicateEntryException("There exist domain with given domain id"); + + domain.setCreatedTime(System.currentTimeMillis()); + domain.setUpdatedTime(System.currentTimeMillis()); + (new DomainRepository()).create(domain); + + // create the global permission for the domain + PermissionType permissionType = new PermissionType(); + permissionType.setPermissionTypeId(domain.getDomainId() + ":" + OWNER_PERMISSION_NAME); + permissionType.setDomainId(domain.getDomainId()); + permissionType.setName(OWNER_PERMISSION_NAME); + permissionType.setDescription("GLOBAL permission to " + domain.getDomainId()); + permissionType.setCreatedTime(System.currentTimeMillis()); + permissionType.setUpdatedTime(System.currentTimeMillis()); + (new PermissionTypeRepository()).create(permissionType); + + return domain.getDomainId(); + } catch (SharingRegistryException | DuplicateEntryException e) { + throw e; + } catch (Throwable ex) { + logger.error(ex.getMessage(), ex); + throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + } } public boolean updateDomain(Domain domain) throws SharingRegistryException { - Domain oldDomain = (new DomainRepository()).get(domain.getDomainId()); - domain.setCreatedTime(oldDomain.getCreatedTime()); - domain.setUpdatedTime(System.currentTimeMillis()); - domain = getUpdatedObject(oldDomain, domain); - (new DomainRepository()).update(domain); - return true; + try { + Domain oldDomain = (new DomainRepository()).get(domain.getDomainId()); + domain.setCreatedTime(oldDomain.getCreatedTime()); + domain.setUpdatedTime(System.currentTimeMillis()); + domain = getUpdatedObject(oldDomain, domain); + (new DomainRepository()).update(domain); + return true; + } catch (SharingRegistryException e) { + throw e; + } catch (Throwable ex) { + logger.error(ex.getMessage(), ex); + throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + } } public boolean isDomainExists(String domainId) throws SharingRegistryException { - return (new DomainRepository()).isExists(domainId); + try { + return (new DomainRepository()).isExists(domainId); + } catch (SharingRegistryException e) { + throw e; + } catch (Throwable ex) { + logger.error(ex.getMessage(), ex); + throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + } } public boolean deleteDomain(String domainId) throws SharingRegistryException { - (new DomainRepository()).delete(domainId); - return true; + try { + (new DomainRepository()).delete(domainId); + return true; + } catch (SharingRegistryException e) { + throw e; + } catch (Throwable ex) { + logger.error(ex.getMessage(), ex); + throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + } } public Domain getDomain(String domainId) throws SharingRegistryException { - return (new DomainRepository()).get(domainId); + try { + return (new DomainRepository()).get(domainId); + } catch (SharingRegistryException e) { + throw e; + } catch (Throwable ex) { + throw convertException(ex, "Error while getting domain"); + } } public List getDomains(int offset, int limit) throws SharingRegistryException { - return (new DomainRepository()).select(new HashMap<>(), offset, limit); + try { + return (new DomainRepository()).select(new HashMap<>(), offset, limit); + } catch (SharingRegistryException e) { + throw e; + } catch (Throwable ex) { + throw convertException(ex, "Error while getting domains"); + } } /** @@ -90,86 +136,120 @@ public List getDomains(int offset, int limit) throws SharingRegistryExce * * */ public String createUser(User user) throws SharingRegistryException, DuplicateEntryException { - UserPK userPK = new UserPK(); - userPK.setUserId(user.getUserId()); - userPK.setDomainId(user.getDomainId()); - if ((new UserRepository()).get(userPK) != null) - throw new DuplicateEntryException("There exist user with given user id"); - - user.setCreatedTime(System.currentTimeMillis()); - user.setUpdatedTime(System.currentTimeMillis()); - (new UserRepository()).create(user); - - UserGroup userGroup = new UserGroup(); - userGroup.setGroupId(user.getUserId()); - userGroup.setDomainId(user.getDomainId()); - userGroup.setName(user.getUserName()); - userGroup.setDescription("user " + user.getUserName() + " group"); - userGroup.setOwnerId(user.getUserId()); - userGroup.setGroupType(GroupType.USER_LEVEL_GROUP); - userGroup.setGroupCardinality(GroupCardinality.SINGLE_USER); - (new UserGroupRepository()).create(userGroup); + try { + UserPK userPK = new UserPK(); + userPK.setUserId(user.getUserId()); + userPK.setDomainId(user.getDomainId()); + if ((new UserRepository()).get(userPK) != null) + throw new DuplicateEntryException("There exist user with given user id"); + + user.setCreatedTime(System.currentTimeMillis()); + user.setUpdatedTime(System.currentTimeMillis()); + (new UserRepository()).create(user); + + UserGroup userGroup = new UserGroup(); + userGroup.setGroupId(user.getUserId()); + userGroup.setDomainId(user.getDomainId()); + userGroup.setName(user.getUserName()); + userGroup.setDescription("user " + user.getUserName() + " group"); + userGroup.setOwnerId(user.getUserId()); + userGroup.setGroupType(GroupType.USER_LEVEL_GROUP); + userGroup.setGroupCardinality(GroupCardinality.SINGLE_USER); + (new UserGroupRepository()).create(userGroup); + + Domain domain = new DomainRepository().get(user.getDomainId()); + if (domain.getInitialUserGroupId() != null) { + addUsersToGroup( + user.getDomainId(), Collections.singletonList(user.getUserId()), domain.getInitialUserGroupId()); + } - Domain domain = new DomainRepository().get(user.getDomainId()); - if (domain.getInitialUserGroupId() != null) { - addUsersToGroup( - user.getDomainId(), Collections.singletonList(user.getUserId()), domain.getInitialUserGroupId()); + return user.getUserId(); + } catch (SharingRegistryException | DuplicateEntryException e) { + throw e; + } catch (Throwable ex) { + throw convertException(ex, "Error while creating user"); } - - return user.getUserId(); } public boolean updatedUser(User user) throws SharingRegistryException { - UserPK userPK = new UserPK(); - userPK.setUserId(user.getUserId()); - userPK.setDomainId(user.getDomainId()); - User oldUser = (new UserRepository()).get(userPK); - user.setCreatedTime(oldUser.getCreatedTime()); - user.setUpdatedTime(System.currentTimeMillis()); - user = getUpdatedObject(oldUser, user); - (new UserRepository()).update(user); - - UserGroupPK userGroupPK = new UserGroupPK(); - userGroupPK.setGroupId(user.getUserId()); - userGroupPK.setDomainId(user.getDomainId()); - UserGroup userGroup = (new UserGroupRepository()).get(userGroupPK); - userGroup.setName(user.getUserName()); - userGroup.setDescription("user " + user.getUserName() + " group"); - updateGroup(userGroup); - return true; + try { + UserPK userPK = new UserPK(); + userPK.setUserId(user.getUserId()); + userPK.setDomainId(user.getDomainId()); + User oldUser = (new UserRepository()).get(userPK); + user.setCreatedTime(oldUser.getCreatedTime()); + user.setUpdatedTime(System.currentTimeMillis()); + user = getUpdatedObject(oldUser, user); + (new UserRepository()).update(user); + + UserGroupPK userGroupPK = new UserGroupPK(); + userGroupPK.setGroupId(user.getUserId()); + userGroupPK.setDomainId(user.getDomainId()); + UserGroup userGroup = (new UserGroupRepository()).get(userGroupPK); + userGroup.setName(user.getUserName()); + userGroup.setDescription("user " + user.getUserName() + " group"); + updateGroup(userGroup); + return true; + } catch (SharingRegistryException e) { + throw e; + } catch (Throwable ex) { + throw convertException(ex, "Error while updating user"); + } } public boolean isUserExists(String domainId, String userId) throws SharingRegistryException { - UserPK userPK = new UserPK(); - userPK.setDomainId(domainId); - userPK.setUserId(userId); - return (new UserRepository()).isExists(userPK); + try { + UserPK userPK = new UserPK(); + userPK.setDomainId(domainId); + userPK.setUserId(userId); + return (new UserRepository()).isExists(userPK); + } catch (SharingRegistryException e) { + throw e; + } catch (Throwable ex) { + throw convertException(ex, "Error while checking if user exists"); + } } public boolean deleteUser(String domainId, String userId) throws SharingRegistryException { - UserPK userPK = new UserPK(); - userPK.setUserId(userId); - userPK.setDomainId(domainId); - (new UserRepository()).delete(userPK); - - UserGroupPK userGroupPK = new UserGroupPK(); - userGroupPK.setGroupId(userId); - userGroupPK.setDomainId(domainId); - (new UserGroupRepository()).delete(userGroupPK); - return true; + try { + UserPK userPK = new UserPK(); + userPK.setUserId(userId); + userPK.setDomainId(domainId); + (new UserRepository()).delete(userPK); + + UserGroupPK userGroupPK = new UserGroupPK(); + userGroupPK.setGroupId(userId); + userGroupPK.setDomainId(domainId); + (new UserGroupRepository()).delete(userGroupPK); + return true; + } catch (SharingRegistryException e) { + throw e; + } catch (Throwable ex) { + throw convertException(ex, "Error while deleting user"); + } } public User getUser(String domainId, String userId) throws SharingRegistryException { - UserPK userPK = new UserPK(); - userPK.setUserId(userId); - userPK.setDomainId(domainId); - return (new UserRepository()).get(userPK); + try { + UserPK userPK = new UserPK(); + userPK.setUserId(userId); + userPK.setDomainId(domainId); + return (new UserRepository()).get(userPK); + } catch (SharingRegistryException e) { + throw e; + } catch (Throwable ex) { + throw convertException(ex, "Error while getting user"); + } } public List getUsers(String domain, int offset, int limit) throws SharingRegistryException { - HashMap filters = new HashMap<>(); - filters.put(DBConstants.UserTable.DOMAIN_ID, domain); - return (new UserRepository()).select(filters, offset, limit); + try { + HashMap filters = new HashMap<>(); + filters.put(DBConstants.UserTable.DOMAIN_ID, domain); + return (new UserRepository()).select(filters, offset, limit); + } catch (Throwable ex) { + throw convertException(ex, "Error while getting users"); + } } /** @@ -177,134 +257,178 @@ public List getUsers(String domain, int offset, int limit) throws SharingR * * */ public String createGroup(UserGroup group) throws SharingRegistryException { - UserGroupPK userGroupPK = new UserGroupPK(); - userGroupPK.setGroupId(group.getGroupId()); - userGroupPK.setDomainId(group.getDomainId()); - if ((new UserGroupRepository()).get(userGroupPK) != null) - throw new SharingRegistryException("There exist group with given group id"); - // Client created groups are always of type MULTI_USER - group.setGroupCardinality(GroupCardinality.MULTI_USER); - group.setCreatedTime(System.currentTimeMillis()); - group.setUpdatedTime(System.currentTimeMillis()); - // Add group admins once the group is created - group.unsetGroupAdmins(); - (new UserGroupRepository()).create(group); - - addUsersToGroup(group.getDomainId(), Arrays.asList(group.getOwnerId()), group.getGroupId()); - return group.getGroupId(); + try { + UserGroupPK userGroupPK = new UserGroupPK(); + userGroupPK.setGroupId(group.getGroupId()); + userGroupPK.setDomainId(group.getDomainId()); + if ((new UserGroupRepository()).get(userGroupPK) != null) + throw new SharingRegistryException("There exist group with given group id"); + // Client created groups are always of type MULTI_USER + group.setGroupCardinality(GroupCardinality.MULTI_USER); + group.setCreatedTime(System.currentTimeMillis()); + group.setUpdatedTime(System.currentTimeMillis()); + // Add group admins once the group is created + group.unsetGroupAdmins(); + (new UserGroupRepository()).create(group); + + addUsersToGroup(group.getDomainId(), Arrays.asList(group.getOwnerId()), group.getGroupId()); + return group.getGroupId(); + } catch (SharingRegistryException e) { + throw e; + } catch (Throwable ex) { + throw convertException(ex, "Error while creating group"); + } } public boolean updateGroup(UserGroup group) throws SharingRegistryException { - group.setUpdatedTime(System.currentTimeMillis()); - UserGroupPK userGroupPK = new UserGroupPK(); - userGroupPK.setGroupId(group.getGroupId()); - userGroupPK.setDomainId(group.getDomainId()); - UserGroup oldGroup = (new UserGroupRepository()).get(userGroupPK); - group.setGroupCardinality(oldGroup.getGroupCardinality()); - group.setCreatedTime(oldGroup.getCreatedTime()); - group = getUpdatedObject(oldGroup, group); - - if (!group.getOwnerId().equals(oldGroup.getOwnerId())) - throw new SharingRegistryException("Group owner cannot be changed"); - - (new UserGroupRepository()).update(group); - return true; + try { + group.setUpdatedTime(System.currentTimeMillis()); + UserGroupPK userGroupPK = new UserGroupPK(); + userGroupPK.setGroupId(group.getGroupId()); + userGroupPK.setDomainId(group.getDomainId()); + UserGroup oldGroup = (new UserGroupRepository()).get(userGroupPK); + group.setGroupCardinality(oldGroup.getGroupCardinality()); + group.setCreatedTime(oldGroup.getCreatedTime()); + group = getUpdatedObject(oldGroup, group); + + if (!group.getOwnerId().equals(oldGroup.getOwnerId())) + throw new SharingRegistryException("Group owner cannot be changed"); + + (new UserGroupRepository()).update(group); + return true; + } catch (SharingRegistryException e) { + throw e; + } catch (Throwable ex) { + throw convertException(ex, "Error while updating group"); + } } public boolean isGroupExists(String domainId, String groupId) throws SharingRegistryException { - UserGroupPK userGroupPK = new UserGroupPK(); - userGroupPK.setDomainId(domainId); - userGroupPK.setGroupId(groupId); - return (new UserGroupRepository()).isExists(userGroupPK); + try { + UserGroupPK userGroupPK = new UserGroupPK(); + userGroupPK.setDomainId(domainId); + userGroupPK.setGroupId(groupId); + return (new UserGroupRepository()).isExists(userGroupPK); + } catch (Throwable ex) { + throw convertException(ex, "Error while checking if group exists"); + } } public boolean deleteGroup(String domainId, String groupId) throws SharingRegistryException { - UserGroupPK userGroupPK = new UserGroupPK(); - userGroupPK.setGroupId(groupId); - userGroupPK.setDomainId(domainId); - (new UserGroupRepository()).delete(userGroupPK); - return true; + try { + UserGroupPK userGroupPK = new UserGroupPK(); + userGroupPK.setGroupId(groupId); + userGroupPK.setDomainId(domainId); + (new UserGroupRepository()).delete(userGroupPK); + return true; + } catch (Throwable ex) { + throw convertException(ex, "Error while deleting group"); + } } public UserGroup getGroup(String domainId, String groupId) throws SharingRegistryException { - UserGroupPK userGroupPK = new UserGroupPK(); - userGroupPK.setGroupId(groupId); - userGroupPK.setDomainId(domainId); - return (new UserGroupRepository()).get(userGroupPK); + try { + UserGroupPK userGroupPK = new UserGroupPK(); + userGroupPK.setGroupId(groupId); + userGroupPK.setDomainId(domainId); + return (new UserGroupRepository()).get(userGroupPK); + } catch (Throwable ex) { + throw convertException(ex, "Error while getting group"); + } } public List getGroups(String domain, int offset, int limit) throws SharingRegistryException { - HashMap filters = new HashMap<>(); - filters.put(DBConstants.UserGroupTable.DOMAIN_ID, domain); - // Only return groups with MULTI_USER cardinality which is the only type of cardinality allowed for client - // created groups - filters.put(DBConstants.UserGroupTable.GROUP_CARDINALITY, GroupCardinality.MULTI_USER.name()); - return (new UserGroupRepository()).select(filters, offset, limit); + try { + HashMap filters = new HashMap<>(); + filters.put(DBConstants.UserGroupTable.DOMAIN_ID, domain); + // Only return groups with MULTI_USER cardinality which is the only type of cardinality allowed for client + // created groups + filters.put(DBConstants.UserGroupTable.GROUP_CARDINALITY, GroupCardinality.MULTI_USER.name()); + return (new UserGroupRepository()).select(filters, offset, limit); + } catch (Throwable ex) { + throw convertException(ex, "Error while getting groups"); + } } public boolean addUsersToGroup(String domainId, List userIds, String groupId) throws SharingRegistryException { - for (int i = 0; i < userIds.size(); i++) { - GroupMembership groupMembership = new GroupMembership(); - groupMembership.setParentId(groupId); - groupMembership.setChildId(userIds.get(i)); - groupMembership.setChildType(GroupChildType.USER); - groupMembership.setDomainId(domainId); - groupMembership.setCreatedTime(System.currentTimeMillis()); - groupMembership.setUpdatedTime(System.currentTimeMillis()); - (new GroupMembershipRepository()).create(groupMembership); + try { + for (int i = 0; i < userIds.size(); i++) { + GroupMembership groupMembership = new GroupMembership(); + groupMembership.setParentId(groupId); + groupMembership.setChildId(userIds.get(i)); + groupMembership.setChildType(GroupChildType.USER); + groupMembership.setDomainId(domainId); + groupMembership.setCreatedTime(System.currentTimeMillis()); + groupMembership.setUpdatedTime(System.currentTimeMillis()); + (new GroupMembershipRepository()).create(groupMembership); + } + return true; + } catch (Throwable ex) { + throw convertException(ex, "Error while adding users to group"); } - return true; } public boolean removeUsersFromGroup(String domainId, List userIds, String groupId) throws SharingRegistryException { - for (String userId : userIds) { - if (hasOwnerAccess(domainId, groupId, userId)) { - throw new SharingRegistryException( - "List of User Ids contains Owner Id. Cannot remove owner from the group"); + try { + for (String userId : userIds) { + if (hasOwnerAccess(domainId, groupId, userId)) { + throw new SharingRegistryException( + "List of User Ids contains Owner Id. Cannot remove owner from the group"); + } } - } - for (int i = 0; i < userIds.size(); i++) { - GroupMembershipPK groupMembershipPK = new GroupMembershipPK(); - groupMembershipPK.setParentId(groupId); - groupMembershipPK.setChildId(userIds.get(i)); - groupMembershipPK.setDomainId(domainId); - (new GroupMembershipRepository()).delete(groupMembershipPK); + for (int i = 0; i < userIds.size(); i++) { + GroupMembershipPK groupMembershipPK = new GroupMembershipPK(); + groupMembershipPK.setParentId(groupId); + groupMembershipPK.setChildId(userIds.get(i)); + groupMembershipPK.setDomainId(domainId); + (new GroupMembershipRepository()).delete(groupMembershipPK); + } + return true; + } catch (SharingRegistryException e) { + throw e; + } catch (Throwable ex) { + throw convertException(ex, "Error while removing users from group"); } - return true; } public boolean transferGroupOwnership(String domainId, String groupId, String newOwnerId) throws SharingRegistryException, DuplicateEntryException { - List groupUser = getGroupMembersOfTypeUser(domainId, groupId, 0, -1); - if (!isUserBelongsToGroup(groupUser, newOwnerId)) { - throw new SharingRegistryException("New group owner is not part of the group"); - } - - if (hasOwnerAccess(domainId, groupId, newOwnerId)) { - throw new DuplicateEntryException("User already the current owner of the group"); - } - // remove the new owner as Admin if present - if (hasAdminAccess(domainId, groupId, newOwnerId)) { - removeGroupAdmins(domainId, groupId, Arrays.asList(newOwnerId)); - } - - UserGroupPK userGroupPK = new UserGroupPK(); - userGroupPK.setGroupId(groupId); - userGroupPK.setDomainId(domainId); - UserGroup userGroup = (new UserGroupRepository()).get(userGroupPK); - UserGroup newUserGroup = new UserGroup(); - newUserGroup.setUpdatedTime(System.currentTimeMillis()); - newUserGroup.setOwnerId(newOwnerId); - newUserGroup.setGroupCardinality(GroupCardinality.MULTI_USER); - newUserGroup.setCreatedTime(userGroup.getCreatedTime()); - newUserGroup = getUpdatedObject(userGroup, newUserGroup); + try { + List groupUser = getGroupMembersOfTypeUser(domainId, groupId, 0, -1); + if (!isUserBelongsToGroup(groupUser, newOwnerId)) { + throw new SharingRegistryException("New group owner is not part of the group"); + } - (new UserGroupRepository()).update(newUserGroup); + if (hasOwnerAccess(domainId, groupId, newOwnerId)) { + throw new DuplicateEntryException("User already the current owner of the group"); + } + // remove the new owner as Admin if present + if (hasAdminAccess(domainId, groupId, newOwnerId)) { + removeGroupAdmins(domainId, groupId, Arrays.asList(newOwnerId)); + } - return true; + UserGroupPK userGroupPK = new UserGroupPK(); + userGroupPK.setGroupId(groupId); + userGroupPK.setDomainId(domainId); + UserGroup userGroup = (new UserGroupRepository()).get(userGroupPK); + UserGroup newUserGroup = new UserGroup(); + newUserGroup.setUpdatedTime(System.currentTimeMillis()); + newUserGroup.setOwnerId(newOwnerId); + newUserGroup.setGroupCardinality(GroupCardinality.MULTI_USER); + newUserGroup.setCreatedTime(userGroup.getCreatedTime()); + newUserGroup = getUpdatedObject(userGroup, newUserGroup); + + (new UserGroupRepository()).update(newUserGroup); + + return true; + } catch (SharingRegistryException | DuplicateEntryException e) { + throw e; + } catch (Throwable ex) { + throw convertException(ex, "Error while transferring group ownership"); + } } private boolean isUserBelongsToGroup(List groupUser, String newOwnerId) { @@ -318,105 +442,143 @@ private boolean isUserBelongsToGroup(List groupUser, String newOwnerId) { public boolean addGroupAdmins(String domainId, String groupId, List adminIds) throws SharingRegistryException, DuplicateEntryException { - List groupUser = getGroupMembersOfTypeUser(domainId, groupId, 0, -1); + try { + List groupUser = getGroupMembersOfTypeUser(domainId, groupId, 0, -1); - for (String adminId : adminIds) { - if (!isUserBelongsToGroup(groupUser, adminId)) { - throw new SharingRegistryException( - "Admin not the user of the group. GroupId : " + groupId + ", AdminId : " + adminId); + for (String adminId : adminIds) { + if (!isUserBelongsToGroup(groupUser, adminId)) { + throw new SharingRegistryException( + "Admin not the user of the group. GroupId : " + groupId + ", AdminId : " + adminId); + } + GroupAdminPK groupAdminPK = new GroupAdminPK(); + groupAdminPK.setGroupId(groupId); + groupAdminPK.setAdminId(adminId); + groupAdminPK.setDomainId(domainId); + + if ((new GroupAdminRepository()).get(groupAdminPK) != null) + throw new DuplicateEntryException("User already an admin for the group"); + + GroupAdmin admin = new GroupAdmin(); + admin.setAdminId(adminId); + admin.setDomainId(domainId); + admin.setGroupId(groupId); + (new GroupAdminRepository()).create(admin); } - GroupAdminPK groupAdminPK = new GroupAdminPK(); - groupAdminPK.setGroupId(groupId); - groupAdminPK.setAdminId(adminId); - groupAdminPK.setDomainId(domainId); - - if ((new GroupAdminRepository()).get(groupAdminPK) != null) - throw new DuplicateEntryException("User already an admin for the group"); - - GroupAdmin admin = new GroupAdmin(); - admin.setAdminId(adminId); - admin.setDomainId(domainId); - admin.setGroupId(groupId); - (new GroupAdminRepository()).create(admin); + return true; + } catch (SharingRegistryException | DuplicateEntryException e) { + throw e; + } catch (Throwable ex) { + throw convertException(ex, "Error while adding group admins"); } - return true; } public boolean removeGroupAdmins(String domainId, String groupId, List adminIds) throws SharingRegistryException { - for (String adminId : adminIds) { - GroupAdminPK groupAdminPK = new GroupAdminPK(); - groupAdminPK.setAdminId(adminId); - groupAdminPK.setDomainId(domainId); - groupAdminPK.setGroupId(groupId); - (new GroupAdminRepository()).delete(groupAdminPK); + try { + for (String adminId : adminIds) { + GroupAdminPK groupAdminPK = new GroupAdminPK(); + groupAdminPK.setAdminId(adminId); + groupAdminPK.setDomainId(domainId); + groupAdminPK.setGroupId(groupId); + (new GroupAdminRepository()).delete(groupAdminPK); + } + return true; + } catch (Throwable ex) { + throw convertException(ex, "Error while removing group admins"); } - return true; } public boolean hasAdminAccess(String domainId, String groupId, String adminId) throws SharingRegistryException { - GroupAdminPK groupAdminPK = new GroupAdminPK(); - groupAdminPK.setGroupId(groupId); - groupAdminPK.setAdminId(adminId); - groupAdminPK.setDomainId(domainId); + try { + GroupAdminPK groupAdminPK = new GroupAdminPK(); + groupAdminPK.setGroupId(groupId); + groupAdminPK.setAdminId(adminId); + groupAdminPK.setDomainId(domainId); - if ((new GroupAdminRepository()).get(groupAdminPK) != null) return true; - return false; + if ((new GroupAdminRepository()).get(groupAdminPK) != null) return true; + return false; + } catch (Throwable ex) { + throw convertException(ex, "Error while checking admin access"); + } } public boolean hasOwnerAccess(String domainId, String groupId, String ownerId) throws SharingRegistryException { - UserGroupPK userGroupPK = new UserGroupPK(); - userGroupPK.setGroupId(groupId); - userGroupPK.setDomainId(domainId); - UserGroup getGroup = (new UserGroupRepository()).get(userGroupPK); - - if (getGroup.getOwnerId().equals(ownerId)) return true; - return false; + try { + UserGroupPK userGroupPK = new UserGroupPK(); + userGroupPK.setGroupId(groupId); + userGroupPK.setDomainId(domainId); + UserGroup getGroup = (new UserGroupRepository()).get(userGroupPK); + + if (getGroup.getOwnerId().equals(ownerId)) return true; + return false; + } catch (Throwable ex) { + throw convertException(ex, "Error while checking owner access"); + } } public List getGroupMembersOfTypeUser(String domainId, String groupId, int offset, int limit) throws SharingRegistryException { - // TODO limit offset - List groupMemberUsers = (new GroupMembershipRepository()).getAllChildUsers(domainId, groupId); - return groupMemberUsers; + try { + // TODO limit offset + List groupMemberUsers = (new GroupMembershipRepository()).getAllChildUsers(domainId, groupId); + return groupMemberUsers; + } catch (Throwable ex) { + throw convertException(ex, "Error while getting group members of type user"); + } } public List getGroupMembersOfTypeGroup(String domainId, String groupId, int offset, int limit) throws SharingRegistryException { - // TODO limit offset - List groupMemberGroups = (new GroupMembershipRepository()).getAllChildGroups(domainId, groupId); - return groupMemberGroups; + try { + // TODO limit offset + List groupMemberGroups = (new GroupMembershipRepository()).getAllChildGroups(domainId, groupId); + return groupMemberGroups; + } catch (Throwable ex) { + throw convertException(ex, "Error while getting group members of type group"); + } } public boolean addChildGroupsToParentGroup(String domainId, List childIds, String groupId) throws SharingRegistryException { - for (String childId : childIds) { - // Todo check for cyclic dependencies - GroupMembership groupMembership = new GroupMembership(); - groupMembership.setParentId(groupId); - groupMembership.setChildId(childId); - groupMembership.setChildType(GroupChildType.GROUP); - groupMembership.setDomainId(domainId); - groupMembership.setCreatedTime(System.currentTimeMillis()); - groupMembership.setUpdatedTime(System.currentTimeMillis()); - (new GroupMembershipRepository()).create(groupMembership); + try { + for (String childId : childIds) { + // Todo check for cyclic dependencies + GroupMembership groupMembership = new GroupMembership(); + groupMembership.setParentId(groupId); + groupMembership.setChildId(childId); + groupMembership.setChildType(GroupChildType.GROUP); + groupMembership.setDomainId(domainId); + groupMembership.setCreatedTime(System.currentTimeMillis()); + groupMembership.setUpdatedTime(System.currentTimeMillis()); + (new GroupMembershipRepository()).create(groupMembership); + } + return true; + } catch (Throwable ex) { + throw convertException(ex, "Error while adding child groups to parent group"); } - return true; } public boolean removeChildGroupFromParentGroup(String domainId, String childId, String groupId) throws SharingRegistryException { - GroupMembershipPK groupMembershipPK = new GroupMembershipPK(); - groupMembershipPK.setParentId(groupId); - groupMembershipPK.setChildId(childId); - groupMembershipPK.setDomainId(domainId); - (new GroupMembershipRepository()).delete(groupMembershipPK); - return true; + try { + GroupMembershipPK groupMembershipPK = new GroupMembershipPK(); + groupMembershipPK.setParentId(groupId); + groupMembershipPK.setChildId(childId); + groupMembershipPK.setDomainId(domainId); + (new GroupMembershipRepository()).delete(groupMembershipPK); + return true; + } catch (Throwable ex) { + throw convertException(ex, "Error while removing child group from parent group"); + } } public List getAllMemberGroupsForUser(String domainId, String userId) throws SharingRegistryException { - GroupMembershipRepository groupMembershipRepository = new GroupMembershipRepository(); - return groupMembershipRepository.getAllMemberGroupsForUser(domainId, userId); + try { + GroupMembershipRepository groupMembershipRepository = new GroupMembershipRepository(); + return groupMembershipRepository.getAllMemberGroupsForUser(domainId, userId); + } catch (Throwable ex) { + throw convertException(ex, "Error while getting all member groups for user"); + } } /** @@ -424,56 +586,84 @@ public List getAllMemberGroupsForUser(String domainId, String userId) * * */ public String createEntityType(EntityType entityType) throws SharingRegistryException, DuplicateEntryException { - EntityTypePK entityTypePK = new EntityTypePK(); - entityTypePK.setDomainId(entityType.getDomainId()); - entityTypePK.setEntityTypeId(entityType.getEntityTypeId()); - if ((new EntityTypeRepository()).get(entityTypePK) != null) - throw new DuplicateEntryException("There exist EntityType with given EntityType id"); - - entityType.setCreatedTime(System.currentTimeMillis()); - entityType.setUpdatedTime(System.currentTimeMillis()); - (new EntityTypeRepository()).create(entityType); - return entityType.getEntityTypeId(); + try { + EntityTypePK entityTypePK = new EntityTypePK(); + entityTypePK.setDomainId(entityType.getDomainId()); + entityTypePK.setEntityTypeId(entityType.getEntityTypeId()); + if ((new EntityTypeRepository()).get(entityTypePK) != null) + throw new DuplicateEntryException("There exist EntityType with given EntityType id"); + + entityType.setCreatedTime(System.currentTimeMillis()); + entityType.setUpdatedTime(System.currentTimeMillis()); + (new EntityTypeRepository()).create(entityType); + return entityType.getEntityTypeId(); + } catch (SharingRegistryException | DuplicateEntryException e) { + throw e; + } catch (Throwable ex) { + throw convertException(ex, "Error while creating entity type"); + } } public boolean updateEntityType(EntityType entityType) throws SharingRegistryException { - entityType.setUpdatedTime(System.currentTimeMillis()); - EntityTypePK entityTypePK = new EntityTypePK(); - entityTypePK.setDomainId(entityType.getDomainId()); - entityTypePK.setEntityTypeId(entityType.getEntityTypeId()); - EntityType oldEntityType = (new EntityTypeRepository()).get(entityTypePK); - entityType.setCreatedTime(oldEntityType.getCreatedTime()); - entityType = getUpdatedObject(oldEntityType, entityType); - (new EntityTypeRepository()).update(entityType); - return true; + try { + entityType.setUpdatedTime(System.currentTimeMillis()); + EntityTypePK entityTypePK = new EntityTypePK(); + entityTypePK.setDomainId(entityType.getDomainId()); + entityTypePK.setEntityTypeId(entityType.getEntityTypeId()); + EntityType oldEntityType = (new EntityTypeRepository()).get(entityTypePK); + entityType.setCreatedTime(oldEntityType.getCreatedTime()); + entityType = getUpdatedObject(oldEntityType, entityType); + (new EntityTypeRepository()).update(entityType); + return true; + } catch (SharingRegistryException e) { + throw e; + } catch (Throwable ex) { + throw convertException(ex, "Error while updating entity type"); + } } public boolean isEntityTypeExists(String domainId, String entityTypeId) throws SharingRegistryException { - EntityTypePK entityTypePK = new EntityTypePK(); - entityTypePK.setDomainId(domainId); - entityTypePK.setEntityTypeId(entityTypeId); - return (new EntityTypeRepository()).isExists(entityTypePK); + try { + EntityTypePK entityTypePK = new EntityTypePK(); + entityTypePK.setDomainId(domainId); + entityTypePK.setEntityTypeId(entityTypeId); + return (new EntityTypeRepository()).isExists(entityTypePK); + } catch (Throwable ex) { + throw convertException(ex, "Error while checking if entity type exists"); + } } public boolean deleteEntityType(String domainId, String entityTypeId) throws SharingRegistryException { - EntityTypePK entityTypePK = new EntityTypePK(); - entityTypePK.setDomainId(domainId); - entityTypePK.setEntityTypeId(entityTypeId); - (new EntityTypeRepository()).delete(entityTypePK); - return true; + try { + EntityTypePK entityTypePK = new EntityTypePK(); + entityTypePK.setDomainId(domainId); + entityTypePK.setEntityTypeId(entityTypeId); + (new EntityTypeRepository()).delete(entityTypePK); + return true; + } catch (Throwable ex) { + throw convertException(ex, "Error while deleting entity type"); + } } public EntityType getEntityType(String domainId, String entityTypeId) throws SharingRegistryException { - EntityTypePK entityTypePK = new EntityTypePK(); - entityTypePK.setDomainId(domainId); - entityTypePK.setEntityTypeId(entityTypeId); - return (new EntityTypeRepository()).get(entityTypePK); + try { + EntityTypePK entityTypePK = new EntityTypePK(); + entityTypePK.setDomainId(domainId); + entityTypePK.setEntityTypeId(entityTypeId); + return (new EntityTypeRepository()).get(entityTypePK); + } catch (Throwable ex) { + throw convertException(ex, "Error while getting entity type"); + } } public List getEntityTypes(String domain, int offset, int limit) throws SharingRegistryException { - HashMap filters = new HashMap<>(); - filters.put(DBConstants.EntityTypeTable.DOMAIN_ID, domain); - return (new EntityTypeRepository()).select(filters, offset, limit); + try { + HashMap filters = new HashMap<>(); + filters.put(DBConstants.EntityTypeTable.DOMAIN_ID, domain); + return (new EntityTypeRepository()).select(filters, offset, limit); + } catch (Throwable ex) { + throw convertException(ex, "Error while getting entity types"); + } } /** @@ -482,55 +672,83 @@ public List getEntityTypes(String domain, int offset, int limit) thr */ public String createPermissionType(PermissionType permissionType) throws SharingRegistryException, DuplicateEntryException { - PermissionTypePK permissionTypePK = new PermissionTypePK(); - permissionTypePK.setDomainId(permissionType.getDomainId()); - permissionTypePK.setPermissionTypeId(permissionType.getPermissionTypeId()); - if ((new PermissionTypeRepository()).get(permissionTypePK) != null) - throw new DuplicateEntryException("There exist PermissionType with given PermissionType id"); - permissionType.setCreatedTime(System.currentTimeMillis()); - permissionType.setUpdatedTime(System.currentTimeMillis()); - (new PermissionTypeRepository()).create(permissionType); - return permissionType.getPermissionTypeId(); + try { + PermissionTypePK permissionTypePK = new PermissionTypePK(); + permissionTypePK.setDomainId(permissionType.getDomainId()); + permissionTypePK.setPermissionTypeId(permissionType.getPermissionTypeId()); + if ((new PermissionTypeRepository()).get(permissionTypePK) != null) + throw new DuplicateEntryException("There exist PermissionType with given PermissionType id"); + permissionType.setCreatedTime(System.currentTimeMillis()); + permissionType.setUpdatedTime(System.currentTimeMillis()); + (new PermissionTypeRepository()).create(permissionType); + return permissionType.getPermissionTypeId(); + } catch (SharingRegistryException | DuplicateEntryException e) { + throw e; + } catch (Throwable ex) { + throw convertException(ex, "Error while creating permission type"); + } } public boolean updatePermissionType(PermissionType permissionType) throws SharingRegistryException { - permissionType.setUpdatedTime(System.currentTimeMillis()); - PermissionTypePK permissionTypePK = new PermissionTypePK(); - permissionTypePK.setDomainId(permissionType.getDomainId()); - permissionTypePK.setPermissionTypeId(permissionType.getPermissionTypeId()); - PermissionType oldPermissionType = (new PermissionTypeRepository()).get(permissionTypePK); - permissionType = getUpdatedObject(oldPermissionType, permissionType); - (new PermissionTypeRepository()).update(permissionType); - return true; + try { + permissionType.setUpdatedTime(System.currentTimeMillis()); + PermissionTypePK permissionTypePK = new PermissionTypePK(); + permissionTypePK.setDomainId(permissionType.getDomainId()); + permissionTypePK.setPermissionTypeId(permissionType.getPermissionTypeId()); + PermissionType oldPermissionType = (new PermissionTypeRepository()).get(permissionTypePK); + permissionType = getUpdatedObject(oldPermissionType, permissionType); + (new PermissionTypeRepository()).update(permissionType); + return true; + } catch (SharingRegistryException e) { + throw e; + } catch (Throwable ex) { + throw convertException(ex, "Error while updating permission type"); + } } public boolean isPermissionExists(String domainId, String permissionId) throws SharingRegistryException { - PermissionTypePK permissionTypePK = new PermissionTypePK(); - permissionTypePK.setDomainId(domainId); - permissionTypePK.setPermissionTypeId(permissionId); - return (new PermissionTypeRepository()).isExists(permissionTypePK); + try { + PermissionTypePK permissionTypePK = new PermissionTypePK(); + permissionTypePK.setDomainId(domainId); + permissionTypePK.setPermissionTypeId(permissionId); + return (new PermissionTypeRepository()).isExists(permissionTypePK); + } catch (Throwable ex) { + throw convertException(ex, "Error while checking if permission exists"); + } } public boolean deletePermissionType(String domainId, String permissionTypeId) throws SharingRegistryException { - PermissionTypePK permissionTypePK = new PermissionTypePK(); - permissionTypePK.setDomainId(domainId); - permissionTypePK.setPermissionTypeId(permissionTypeId); - (new PermissionTypeRepository()).delete(permissionTypePK); - return true; + try { + PermissionTypePK permissionTypePK = new PermissionTypePK(); + permissionTypePK.setDomainId(domainId); + permissionTypePK.setPermissionTypeId(permissionTypeId); + (new PermissionTypeRepository()).delete(permissionTypePK); + return true; + } catch (Throwable ex) { + throw convertException(ex, "Error while deleting permission type"); + } } public PermissionType getPermissionType(String domainId, String permissionTypeId) throws SharingRegistryException { - PermissionTypePK permissionTypePK = new PermissionTypePK(); - permissionTypePK.setDomainId(domainId); - permissionTypePK.setPermissionTypeId(permissionTypeId); - return (new PermissionTypeRepository()).get(permissionTypePK); + try { + PermissionTypePK permissionTypePK = new PermissionTypePK(); + permissionTypePK.setDomainId(domainId); + permissionTypePK.setPermissionTypeId(permissionTypeId); + return (new PermissionTypeRepository()).get(permissionTypePK); + } catch (Throwable ex) { + throw convertException(ex, "Error while getting permission type"); + } } public List getPermissionTypes(String domain, int offset, int limit) throws SharingRegistryException { - HashMap filters = new HashMap<>(); - filters.put(DBConstants.PermissionTypeTable.DOMAIN_ID, domain); - return (new PermissionTypeRepository()).select(filters, offset, limit); + try { + HashMap filters = new HashMap<>(); + filters.put(DBConstants.PermissionTypeTable.DOMAIN_ID, domain); + return (new PermissionTypeRepository()).select(filters, offset, limit); + } catch (Throwable ex) { + throw convertException(ex, "Error while getting permission types"); + } } /** @@ -538,165 +756,221 @@ public List getPermissionTypes(String domain, int offset, int li * * */ public String createEntity(Entity entity) throws SharingRegistryException, DuplicateEntryException { - EntityPK entityPK = new EntityPK(); - entityPK.setDomainId(entity.getDomainId()); - entityPK.setEntityId(entity.getEntityId()); - if ((new EntityRepository()).get(entityPK) != null) - throw new DuplicateEntryException("There exist Entity with given Entity id"); - - UserPK userPK = new UserPK(); - userPK.setDomainId(entity.getDomainId()); - userPK.setUserId(entity.getOwnerId()); - if (!(new UserRepository()).isExists(userPK)) { - // Todo this is for Airavata easy integration. Proper thing is to throw an exception here - User user = new User(); - user.setUserId(entity.getOwnerId()); - user.setDomainId(entity.getDomainId()); - user.setUserName(user.getUserId().split("@")[0]); + try { + EntityPK entityPK = new EntityPK(); + entityPK.setDomainId(entity.getDomainId()); + entityPK.setEntityId(entity.getEntityId()); + if ((new EntityRepository()).get(entityPK) != null) + throw new DuplicateEntryException("There exist Entity with given Entity id"); + + UserPK userPK = new UserPK(); + userPK.setDomainId(entity.getDomainId()); + userPK.setUserId(entity.getOwnerId()); + if (!(new UserRepository()).isExists(userPK)) { + // Todo this is for Airavata easy integration. Proper thing is to throw an exception here + User user = new User(); + user.setUserId(entity.getOwnerId()); + user.setDomainId(entity.getDomainId()); + user.setUserName(user.getUserId().split("@")[0]); + + createUser(user); + } + entity.setCreatedTime(System.currentTimeMillis()); + entity.setUpdatedTime(System.currentTimeMillis()); - createUser(user); - } - entity.setCreatedTime(System.currentTimeMillis()); - entity.setUpdatedTime(System.currentTimeMillis()); + if (entity.getOriginalEntityCreationTime() == 0) { + entity.setOriginalEntityCreationTime(entity.getCreatedTime()); + } + (new EntityRepository()).create(entity); - if (entity.getOriginalEntityCreationTime() == 0) { - entity.setOriginalEntityCreationTime(entity.getCreatedTime()); - } - (new EntityRepository()).create(entity); + // Assigning global permission for the owner + Sharing newSharing = new Sharing(); + newSharing.setPermissionTypeId( + (new PermissionTypeRepository()).getOwnerPermissionTypeIdForDomain(entity.getDomainId())); + newSharing.setEntityId(entity.getEntityId()); + newSharing.setGroupId(entity.getOwnerId()); + newSharing.setSharingType(SharingType.DIRECT_CASCADING); + newSharing.setInheritedParentId(entity.getEntityId()); + newSharing.setDomainId(entity.getDomainId()); + newSharing.setCreatedTime(System.currentTimeMillis()); + newSharing.setUpdatedTime(System.currentTimeMillis()); - // Assigning global permission for the owner - Sharing newSharing = new Sharing(); - newSharing.setPermissionTypeId( - (new PermissionTypeRepository()).getOwnerPermissionTypeIdForDomain(entity.getDomainId())); - newSharing.setEntityId(entity.getEntityId()); - newSharing.setGroupId(entity.getOwnerId()); - newSharing.setSharingType(SharingType.DIRECT_CASCADING); - newSharing.setInheritedParentId(entity.getEntityId()); - newSharing.setDomainId(entity.getDomainId()); - newSharing.setCreatedTime(System.currentTimeMillis()); - newSharing.setUpdatedTime(System.currentTimeMillis()); + (new SharingRepository()).create(newSharing); - (new SharingRepository()).create(newSharing); + // creating records for inherited permissions + if (entity.getParentEntityId() != null && entity.getParentEntityId() != "") { + addCascadingPermissionsForEntity(entity); + } - // creating records for inherited permissions - if (entity.getParentEntityId() != null && entity.getParentEntityId() != "") { - addCascadingPermissionsForEntity(entity); + return entity.getEntityId(); + } catch (SharingRegistryException | DuplicateEntryException e) { + throw e; + } catch (Throwable ex) { + throw convertException(ex, "Error while creating entity"); } - - return entity.getEntityId(); } private void addCascadingPermissionsForEntity(Entity entity) throws SharingRegistryException { - Sharing newSharing; - List sharings = (new SharingRepository()) - .getCascadingPermissionsForEntity(entity.getDomainId(), entity.getParentEntityId()); - for (Sharing sharing : sharings) { - newSharing = new Sharing(); - newSharing.setPermissionTypeId(sharing.getPermissionTypeId()); - newSharing.setEntityId(entity.getEntityId()); - newSharing.setGroupId(sharing.getGroupId()); - newSharing.setInheritedParentId(sharing.getInheritedParentId()); - newSharing.setSharingType(SharingType.INDIRECT_CASCADING); - newSharing.setDomainId(entity.getDomainId()); - newSharing.setCreatedTime(System.currentTimeMillis()); - newSharing.setUpdatedTime(System.currentTimeMillis()); - - (new SharingRepository()).create(newSharing); + try { + Sharing newSharing; + List sharings = (new SharingRepository()) + .getCascadingPermissionsForEntity(entity.getDomainId(), entity.getParentEntityId()); + for (Sharing sharing : sharings) { + newSharing = new Sharing(); + newSharing.setPermissionTypeId(sharing.getPermissionTypeId()); + newSharing.setEntityId(entity.getEntityId()); + newSharing.setGroupId(sharing.getGroupId()); + newSharing.setInheritedParentId(sharing.getInheritedParentId()); + newSharing.setSharingType(SharingType.INDIRECT_CASCADING); + newSharing.setDomainId(entity.getDomainId()); + newSharing.setCreatedTime(System.currentTimeMillis()); + newSharing.setUpdatedTime(System.currentTimeMillis()); + + (new SharingRepository()).create(newSharing); + } + } catch (SharingRegistryException e) { + throw e; + } catch (Throwable ex) { + throw convertException(ex, "Error while adding cascading permissions for entity"); } } public boolean updateEntity(Entity entity) throws SharingRegistryException { - // TODO Check for permission changes - entity.setUpdatedTime(System.currentTimeMillis()); - EntityPK entityPK = new EntityPK(); - entityPK.setDomainId(entity.getDomainId()); - entityPK.setEntityId(entity.getEntityId()); - Entity oldEntity = (new EntityRepository()).get(entityPK); - entity.setCreatedTime(oldEntity.getCreatedTime()); - // check if parent entity changed and re-add inherited permissions - if (!Objects.equals(oldEntity.getParentEntityId(), entity.getParentEntityId())) { - logger.debug("Parent entity changed for {}, updating inherited permissions", entity.getEntityId()); - if (oldEntity.getParentEntityId() != null && oldEntity.getParentEntityId() != "") { - logger.debug( - "Removing inherited permissions from {} that were inherited from parent {}", - entity.getEntityId(), - oldEntity.getParentEntityId()); - (new SharingRepository()) - .removeAllIndirectCascadingPermissionsForEntity(entity.getDomainId(), entity.getEntityId()); - } - if (entity.getParentEntityId() != null && entity.getParentEntityId() != "") { - // re-add INDIRECT_CASCADING permissions - logger.debug( - "Adding inherited permissions to {} that are inherited from parent {}", - entity.getEntityId(), - entity.getParentEntityId()); - addCascadingPermissionsForEntity(entity); + try { + // TODO Check for permission changes + entity.setUpdatedTime(System.currentTimeMillis()); + EntityPK entityPK = new EntityPK(); + entityPK.setDomainId(entity.getDomainId()); + entityPK.setEntityId(entity.getEntityId()); + Entity oldEntity = (new EntityRepository()).get(entityPK); + entity.setCreatedTime(oldEntity.getCreatedTime()); + // check if parent entity changed and re-add inherited permissions + if (!Objects.equals(oldEntity.getParentEntityId(), entity.getParentEntityId())) { + logger.debug("Parent entity changed for {}, updating inherited permissions", entity.getEntityId()); + if (oldEntity.getParentEntityId() != null && oldEntity.getParentEntityId() != "") { + logger.debug( + "Removing inherited permissions from {} that were inherited from parent {}", + entity.getEntityId(), + oldEntity.getParentEntityId()); + (new SharingRepository()) + .removeAllIndirectCascadingPermissionsForEntity(entity.getDomainId(), entity.getEntityId()); + } + if (entity.getParentEntityId() != null && entity.getParentEntityId() != "") { + // re-add INDIRECT_CASCADING permissions + logger.debug( + "Adding inherited permissions to {} that are inherited from parent {}", + entity.getEntityId(), + entity.getParentEntityId()); + addCascadingPermissionsForEntity(entity); + } } + entity = getUpdatedObject(oldEntity, entity); + entity.setSharedCount((new SharingRepository()).getSharedCount(entity.getDomainId(), entity.getEntityId())); + (new EntityRepository()).update(entity); + return true; + } catch (SharingRegistryException e) { + throw e; + } catch (Throwable ex) { + throw convertException(ex, "Error while updating entity"); } - entity = getUpdatedObject(oldEntity, entity); - entity.setSharedCount((new SharingRepository()).getSharedCount(entity.getDomainId(), entity.getEntityId())); - (new EntityRepository()).update(entity); - return true; } public boolean isEntityExists(String domainId, String entityId) throws SharingRegistryException { - EntityPK entityPK = new EntityPK(); - entityPK.setDomainId(domainId); - entityPK.setEntityId(entityId); - return (new EntityRepository()).isExists(entityPK); + try { + EntityPK entityPK = new EntityPK(); + entityPK.setDomainId(domainId); + entityPK.setEntityId(entityId); + return (new EntityRepository()).isExists(entityPK); + } catch (Throwable ex) { + throw convertException(ex, "Error while checking if entity exists"); + } } public boolean deleteEntity(String domainId, String entityId) throws SharingRegistryException { - // TODO Check for permission changes - EntityPK entityPK = new EntityPK(); - entityPK.setDomainId(domainId); - entityPK.setEntityId(entityId); - (new EntityRepository()).delete(entityPK); - return true; + try { + // TODO Check for permission changes + EntityPK entityPK = new EntityPK(); + entityPK.setDomainId(domainId); + entityPK.setEntityId(entityId); + (new EntityRepository()).delete(entityPK); + return true; + } catch (Throwable ex) { + throw convertException(ex, "Error while deleting entity"); + } } public Entity getEntity(String domainId, String entityId) throws SharingRegistryException { - EntityPK entityPK = new EntityPK(); - entityPK.setDomainId(domainId); - entityPK.setEntityId(entityId); - return (new EntityRepository()).get(entityPK); + try { + EntityPK entityPK = new EntityPK(); + entityPK.setDomainId(domainId); + entityPK.setEntityId(entityId); + return (new EntityRepository()).get(entityPK); + } catch (Throwable ex) { + throw convertException(ex, "Error while getting entity"); + } } public List searchEntities( String domainId, String userId, List filters, int offset, int limit) throws SharingRegistryException { - List groupIds = new ArrayList<>(); - groupIds.add(userId); - (new GroupMembershipRepository()) - .getAllParentMembershipsForChild(domainId, userId).stream() - .forEach(gm -> groupIds.add(gm.getParentId())); - return (new EntityRepository()).searchEntities(domainId, groupIds, filters, offset, limit); + try { + List groupIds = new ArrayList<>(); + groupIds.add(userId); + (new GroupMembershipRepository()) + .getAllParentMembershipsForChild(domainId, userId).stream() + .forEach(gm -> groupIds.add(gm.getParentId())); + return (new EntityRepository()).searchEntities(domainId, groupIds, filters, offset, limit); + } catch (Throwable ex) { + throw convertException(ex, "Error while searching entities"); + } } public List getListOfSharedUsers(String domainId, String entityId, String permissionTypeId) throws SharingRegistryException { - return (new UserRepository()).getAccessibleUsers(domainId, entityId, permissionTypeId); + try { + return (new UserRepository()).getAccessibleUsers(domainId, entityId, permissionTypeId); + } catch (Throwable ex) { + throw convertException(ex, "Error while getting list of shared users"); + } } public List getListOfDirectlySharedUsers(String domainId, String entityId, String permissionTypeId) throws SharingRegistryException { - return (new UserRepository()).getDirectlyAccessibleUsers(domainId, entityId, permissionTypeId); + try { + return (new UserRepository()).getDirectlyAccessibleUsers(domainId, entityId, permissionTypeId); + } catch (Throwable ex) { + throw convertException(ex, "Error while getting list of directly shared users"); + } } public List getListOfSharedGroups(String domainId, String entityId, String permissionTypeId) throws SharingRegistryException { - return (new UserGroupRepository()).getAccessibleGroups(domainId, entityId, permissionTypeId); + try { + return (new UserGroupRepository()).getAccessibleGroups(domainId, entityId, permissionTypeId); + } catch (Throwable ex) { + throw convertException(ex, "Error while getting list of shared groups"); + } } public List getListOfDirectlySharedGroups(String domainId, String entityId, String permissionTypeId) throws SharingRegistryException { - return (new UserGroupRepository()).getDirectlyAccessibleGroups(domainId, entityId, permissionTypeId); + try { + return (new UserGroupRepository()).getDirectlyAccessibleGroups(domainId, entityId, permissionTypeId); + } catch (Throwable ex) { + throw convertException(ex, "Error while getting list of directly shared groups"); + } } public boolean shareEntityWithUsers( String domainId, String entityId, List userList, String permissionTypeId, boolean cascadePermission) throws SharingRegistryException { - return shareEntity(domainId, entityId, userList, permissionTypeId, cascadePermission); + try { + return shareEntity(domainId, entityId, userList, permissionTypeId, cascadePermission); + } catch (SharingRegistryException e) { + throw e; + } catch (Throwable ex) { + throw convertException(ex, "Error while sharing entity with users"); + } } public boolean shareEntityWithGroups( @@ -706,7 +980,13 @@ public boolean shareEntityWithGroups( String permissionTypeId, boolean cascadePermission) throws SharingRegistryException { - return shareEntity(domainId, entityId, groupList, permissionTypeId, cascadePermission); + try { + return shareEntity(domainId, entityId, groupList, permissionTypeId, cascadePermission); + } catch (SharingRegistryException e) { + throw e; + } catch (Throwable ex) { + throw convertException(ex, "Error while sharing entity with groups"); + } } private boolean shareEntity( @@ -716,132 +996,137 @@ private boolean shareEntity( String permissionTypeId, boolean cascadePermission) throws SharingRegistryException { - if (permissionTypeId.equals((new PermissionTypeRepository()).getOwnerPermissionTypeIdForDomain(domainId))) { - throw new SharingRegistryException(OWNER_PERMISSION_NAME + " permission cannot be assigned or removed"); - } + try { + if (permissionTypeId.equals((new PermissionTypeRepository()).getOwnerPermissionTypeIdForDomain(domainId))) { + throw new SharingRegistryException(OWNER_PERMISSION_NAME + " permission cannot be assigned or removed"); + } + + List sharings = new ArrayList<>(); + + // Adding permission for the specified users/groups for the specified entity + LinkedList temp = new LinkedList<>(); + for (String userId : groupOrUserList) { + Sharing sharing = new Sharing(); + sharing.setPermissionTypeId(permissionTypeId); + sharing.setEntityId(entityId); + sharing.setGroupId(userId); + sharing.setInheritedParentId(entityId); + sharing.setDomainId(domainId); + if (cascadePermission) { + sharing.setSharingType(SharingType.DIRECT_CASCADING); + } else { + sharing.setSharingType(SharingType.DIRECT_NON_CASCADING); + } + sharing.setCreatedTime(System.currentTimeMillis()); + sharing.setUpdatedTime(System.currentTimeMillis()); - List sharings = new ArrayList<>(); + sharings.add(sharing); + } - // Adding permission for the specified users/groups for the specified entity - LinkedList temp = new LinkedList<>(); - for (String userId : groupOrUserList) { - Sharing sharing = new Sharing(); - sharing.setPermissionTypeId(permissionTypeId); - sharing.setEntityId(entityId); - sharing.setGroupId(userId); - sharing.setInheritedParentId(entityId); - sharing.setDomainId(domainId); if (cascadePermission) { - sharing.setSharingType(SharingType.DIRECT_CASCADING); - } else { - sharing.setSharingType(SharingType.DIRECT_NON_CASCADING); - } - sharing.setCreatedTime(System.currentTimeMillis()); - sharing.setUpdatedTime(System.currentTimeMillis()); - - sharings.add(sharing); - } - - if (cascadePermission) { - // Adding permission for the specified users/groups for all child entities - (new EntityRepository()) - .getChildEntities(domainId, entityId).stream().forEach(e -> temp.addLast(e)); - while (temp.size() > 0) { - Entity entity = temp.pop(); - String childEntityId = entity.getEntityId(); - for (String userId : groupOrUserList) { - Sharing sharing = new Sharing(); - sharing.setPermissionTypeId(permissionTypeId); - sharing.setEntityId(childEntityId); - sharing.setGroupId(userId); - sharing.setInheritedParentId(entityId); - sharing.setSharingType(SharingType.INDIRECT_CASCADING); - sharing.setInheritedParentId(entityId); - sharing.setDomainId(domainId); - sharing.setCreatedTime(System.currentTimeMillis()); - sharing.setUpdatedTime(System.currentTimeMillis()); - sharings.add(sharing); - (new EntityRepository()) - .getChildEntities(domainId, childEntityId).stream().forEach(e -> temp.addLast(e)); + // Adding permission for the specified users/groups for all child entities + (new EntityRepository()) + .getChildEntities(domainId, entityId).stream().forEach(e -> temp.addLast(e)); + while (temp.size() > 0) { + Entity entity = temp.pop(); + String childEntityId = entity.getEntityId(); + for (String userId : groupOrUserList) { + Sharing sharing = new Sharing(); + sharing.setPermissionTypeId(permissionTypeId); + sharing.setEntityId(childEntityId); + sharing.setGroupId(userId); + sharing.setInheritedParentId(entityId); + sharing.setSharingType(SharingType.INDIRECT_CASCADING); + sharing.setInheritedParentId(entityId); + sharing.setDomainId(domainId); + sharing.setCreatedTime(System.currentTimeMillis()); + sharing.setUpdatedTime(System.currentTimeMillis()); + sharings.add(sharing); + (new EntityRepository()) + .getChildEntities(domainId, childEntityId).stream().forEach(e -> temp.addLast(e)); + } } } + (new SharingRepository()).create(sharings); + + EntityPK entityPK = new EntityPK(); + entityPK.setDomainId(domainId); + entityPK.setEntityId(entityId); + Entity entity = (new EntityRepository()).get(entityPK); + entity.setSharedCount((new SharingRepository()).getSharedCount(domainId, entityId)); + (new EntityRepository()).update(entity); + return true; + } catch (SharingRegistryException e) { + throw e; + } catch (Throwable ex) { + throw convertException(ex, "Error while sharing entity"); } - (new SharingRepository()).create(sharings); - - EntityPK entityPK = new EntityPK(); - entityPK.setDomainId(domainId); - entityPK.setEntityId(entityId); - Entity entity = (new EntityRepository()).get(entityPK); - entity.setSharedCount((new SharingRepository()).getSharedCount(domainId, entityId)); - (new EntityRepository()).update(entity); - return true; } public boolean revokeEntitySharingFromUsers( String domainId, String entityId, List userList, String permissionTypeId) throws SharingRegistryException { - if (permissionTypeId.equals((new PermissionTypeRepository()).getOwnerPermissionTypeIdForDomain(domainId))) { - throw new SharingRegistryException(OWNER_PERMISSION_NAME + " permission cannot be assigned or removed"); + try { + if (permissionTypeId.equals((new PermissionTypeRepository()).getOwnerPermissionTypeIdForDomain(domainId))) { + throw new SharingRegistryException(OWNER_PERMISSION_NAME + " permission cannot be assigned or removed"); + } + return revokeEntitySharing(domainId, entityId, userList, permissionTypeId); + } catch (SharingRegistryException e) { + throw e; + } catch (Throwable ex) { + throw convertException(ex, "Error while revoking entity sharing from users"); } - return revokeEntitySharing(domainId, entityId, userList, permissionTypeId); } public boolean revokeEntitySharingFromGroups( String domainId, String entityId, List groupList, String permissionTypeId) throws SharingRegistryException { - if (permissionTypeId.equals((new PermissionTypeRepository()).getOwnerPermissionTypeIdForDomain(domainId))) { - throw new SharingRegistryException(OWNER_PERMISSION_NAME + " permission cannot be assigned or removed"); + try { + if (permissionTypeId.equals((new PermissionTypeRepository()).getOwnerPermissionTypeIdForDomain(domainId))) { + throw new SharingRegistryException(OWNER_PERMISSION_NAME + " permission cannot be assigned or removed"); + } + return revokeEntitySharing(domainId, entityId, groupList, permissionTypeId); + } catch (SharingRegistryException e) { + throw e; + } catch (Throwable ex) { + throw convertException(ex, "Error while revoking entity sharing from groups"); } - return revokeEntitySharing(domainId, entityId, groupList, permissionTypeId); } public boolean userHasAccess(String domainId, String userId, String entityId, String permissionTypeId) throws SharingRegistryException { - // check whether the user has permission directly or indirectly - List parentMemberships = - (new GroupMembershipRepository()).getAllParentMembershipsForChild(domainId, userId); - List groupIds = new ArrayList<>(); - parentMemberships.stream().forEach(pm -> groupIds.add(pm.getParentId())); - groupIds.add(userId); - return (new SharingRepository()) - .hasAccess( + try { + // check whether the user has permission directly or indirectly + List parentMemberships = + (new GroupMembershipRepository()).getAllParentMembershipsForChild(domainId, userId); + List groupIds = new ArrayList<>(); + parentMemberships.stream().forEach(pm -> groupIds.add(pm.getParentId())); + groupIds.add(userId); + return (new SharingRepository()) + .hasAccess( domainId, entityId, groupIds, Arrays.asList( permissionTypeId, (new PermissionTypeRepository()).getOwnerPermissionTypeIdForDomain(domainId))); + } catch (Throwable ex) { + throw convertException(ex, "Error while checking user access"); + } } public boolean revokeEntitySharing( String domainId, String entityId, List groupOrUserList, String permissionTypeId) throws SharingRegistryException { - if (permissionTypeId.equals((new PermissionTypeRepository()).getOwnerPermissionTypeIdForDomain(domainId))) { - throw new SharingRegistryException(OWNER_PERMISSION_NAME + " permission cannot be removed"); - } - - // revoking permission for the entity - for (String groupId : groupOrUserList) { - SharingPK sharingPK = new SharingPK(); - sharingPK.setEntityId(entityId); - sharingPK.setGroupId(groupId); - sharingPK.setPermissionTypeId(permissionTypeId); - sharingPK.setInheritedParentId(entityId); - sharingPK.setDomainId(domainId); - - (new SharingRepository()).delete(sharingPK); - } + try { + if (permissionTypeId.equals((new PermissionTypeRepository()).getOwnerPermissionTypeIdForDomain(domainId))) { + throw new SharingRegistryException(OWNER_PERMISSION_NAME + " permission cannot be removed"); + } - // revoking permission from inheritance - List temp = new ArrayList<>(); - (new SharingRepository()) - .getIndirectSharedChildren(domainId, entityId, permissionTypeId).stream() - .forEach(s -> temp.add(s)); - for (Sharing sharing : temp) { - String childEntityId = sharing.getEntityId(); + // revoking permission for the entity for (String groupId : groupOrUserList) { SharingPK sharingPK = new SharingPK(); - sharingPK.setEntityId(childEntityId); + sharingPK.setEntityId(entityId); sharingPK.setGroupId(groupId); sharingPK.setPermissionTypeId(permissionTypeId); sharingPK.setInheritedParentId(entityId); @@ -849,15 +1134,38 @@ public boolean revokeEntitySharing( (new SharingRepository()).delete(sharingPK); } - } - EntityPK entityPK = new EntityPK(); - entityPK.setDomainId(domainId); - entityPK.setEntityId(entityId); - Entity entity = (new EntityRepository()).get(entityPK); - entity.setSharedCount((new SharingRepository()).getSharedCount(domainId, entityId)); - (new EntityRepository()).update(entity); - return true; + // revoking permission from inheritance + List temp = new ArrayList<>(); + (new SharingRepository()) + .getIndirectSharedChildren(domainId, entityId, permissionTypeId).stream() + .forEach(s -> temp.add(s)); + for (Sharing sharing : temp) { + String childEntityId = sharing.getEntityId(); + for (String groupId : groupOrUserList) { + SharingPK sharingPK = new SharingPK(); + sharingPK.setEntityId(childEntityId); + sharingPK.setGroupId(groupId); + sharingPK.setPermissionTypeId(permissionTypeId); + sharingPK.setInheritedParentId(entityId); + sharingPK.setDomainId(domainId); + + (new SharingRepository()).delete(sharingPK); + } + } + + EntityPK entityPK = new EntityPK(); + entityPK.setDomainId(domainId); + entityPK.setEntityId(entityId); + Entity entity = (new EntityRepository()).get(entityPK); + entity.setSharedCount((new SharingRepository()).getSharedCount(domainId, entityId)); + (new EntityRepository()).update(entity); + return true; + } catch (SharingRegistryException e) { + throw e; + } catch (Throwable ex) { + throw convertException(ex, "Error while revoking entity sharing"); + } } private T getUpdatedObject(T oldEntity, T newEntity) throws SharingRegistryException { diff --git a/airavata-api/src/main/java/org/apache/airavata/service/TenantProfileService.java b/airavata-api/src/main/java/org/apache/airavata/service/TenantProfileService.java index e730bdd457..ae36673c8d 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/TenantProfileService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/TenantProfileService.java @@ -48,6 +48,13 @@ public class TenantProfileService { private TenantProfileRepository tenantProfileRepository; private DBEventPublisherUtils dbEventPublisherUtils = new DBEventPublisherUtils(DBEventService.TENANT); + private TenantProfileServiceException convertException(Throwable e, String msg) { + logger.error(msg, e); + TenantProfileServiceException exception = new TenantProfileServiceException(); + exception.setMessage(msg + ". More info : " + e.getMessage()); + return exception; + } + public TenantProfileService() { logger.debug("Initializing TenantProfileService"); this.tenantProfileRepository = new TenantProfileRepository(Gateway.class, GatewayEntity.class); diff --git a/airavata-api/src/main/java/org/apache/airavata/service/UserProfileService.java b/airavata-api/src/main/java/org/apache/airavata/service/UserProfileService.java index 530dcc4284..26df5f561c 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/UserProfileService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/UserProfileService.java @@ -49,6 +49,13 @@ public class UserProfileService { private UserProfileRepository userProfileRepository; private DBEventPublisherUtils dbEventPublisherUtils = new DBEventPublisherUtils(DBEventService.USER_PROFILE); + private UserProfileServiceException convertException(Throwable e, String msg) { + logger.error(msg, e); + UserProfileServiceException exception = new UserProfileServiceException(); + exception.setMessage(msg + ". More info : " + e.getMessage()); + return exception; + } + public UserProfileService() { userProfileRepository = new UserProfileRepository(); } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/IamAdminServicesHandler.java b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/IamAdminServicesHandler.java index 13191d832e..da12bb8ca0 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/IamAdminServicesHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/IamAdminServicesHandler.java @@ -29,12 +29,9 @@ import org.apache.airavata.service.profile.iam.admin.services.cpi.iam_admin_services_cpiConstants; import org.apache.airavata.service.security.interceptor.SecurityCheck; import org.apache.thrift.TException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class IamAdminServicesHandler implements IamAdminServices.Iface { - private static final Logger logger = LoggerFactory.getLogger(IamAdminServicesHandler.class); private org.apache.airavata.service.IamAdminService iamAdminService; public IamAdminServicesHandler() { @@ -50,30 +47,14 @@ public String getAPIVersion() throws TException { @SecurityCheck public Gateway setUpGateway(AuthzToken authzToken, Gateway gateway) throws IamAdminServicesException, AuthorizationException { - try { - return iamAdminService.setUpGateway(authzToken, gateway); - } catch (IamAdminServicesException e) { - throw e; - } catch (Throwable ex) { - logger.error("Gateway Setup Failed, reason: " + ex.getMessage(), ex); - IamAdminServicesException iamAdminServicesException = new IamAdminServicesException(ex.getMessage()); - throw iamAdminServicesException; - } + return iamAdminService.setUpGateway(authzToken, gateway); } @Override @SecurityCheck public boolean isUsernameAvailable(AuthzToken authzToken, String username) throws IamAdminServicesException, AuthorizationException, TException { - try { - return iamAdminService.isUsernameAvailable(authzToken, username); - } catch (IamAdminServicesException e) { - throw e; - } catch (Throwable ex) { - String msg = "Error while checking username availability, reason: " + ex.getMessage(); - logger.error(msg, ex); - throw new IamAdminServicesException(msg); - } + return iamAdminService.isUsernameAvailable(authzToken, username); } @Override @@ -86,150 +67,70 @@ public boolean registerUser( String lastName, String newPassword) throws IamAdminServicesException, AuthorizationException { - try { - return iamAdminService.registerUser(authzToken, username, emailAddress, firstName, lastName, newPassword); - } catch (IamAdminServicesException e) { - throw e; - } catch (Throwable ex) { - String msg = "Error while registering user into Identity Server, reason: " + ex.getMessage(); - logger.error(msg, ex); - throw new IamAdminServicesException(msg); - } + return iamAdminService.registerUser(authzToken, username, emailAddress, firstName, lastName, newPassword); } @Override @SecurityCheck public boolean enableUser(AuthzToken authzToken, String username) throws IamAdminServicesException, AuthorizationException { - try { - return iamAdminService.enableUser(authzToken, username); - } catch (IamAdminServicesException e) { - throw e; - } catch (Throwable ex) { - String msg = "Error while enabling user account, reason: " + ex.getMessage(); - logger.error(msg, ex); - throw new IamAdminServicesException(msg); - } + return iamAdminService.enableUser(authzToken, username); } @Override @SecurityCheck public boolean isUserEnabled(AuthzToken authzToken, String username) throws IamAdminServicesException, AuthorizationException, TException { - try { - return iamAdminService.isUserEnabled(authzToken, username); - } catch (IamAdminServicesException e) { - throw e; - } catch (Throwable ex) { - String msg = "Error while checking if user account is enabled, reason: " + ex.getMessage(); - logger.error(msg, ex); - throw new IamAdminServicesException(msg); - } + return iamAdminService.isUserEnabled(authzToken, username); } @Override @SecurityCheck public boolean isUserExist(AuthzToken authzToken, String username) throws IamAdminServicesException, AuthorizationException, TException { - try { - return iamAdminService.isUserExist(authzToken, username); - } catch (IamAdminServicesException e) { - throw e; - } catch (Throwable ex) { - String msg = "Error while checking if user account exists, reason: " + ex.getMessage(); - logger.error(msg, ex); - throw new IamAdminServicesException(msg); - } + return iamAdminService.isUserExist(authzToken, username); } @Override @SecurityCheck public UserProfile getUser(AuthzToken authzToken, String username) throws IamAdminServicesException, AuthorizationException, TException { - try { - return iamAdminService.getUser(authzToken, username); - } catch (IamAdminServicesException e) { - throw e; - } catch (Throwable ex) { - String msg = "Error while retrieving user profile from IAM backend, reason: " + ex.getMessage(); - logger.error(msg, ex); - throw new IamAdminServicesException(msg); - } + return iamAdminService.getUser(authzToken, username); } @Override @SecurityCheck public List getUsers(AuthzToken authzToken, int offset, int limit, String search) throws IamAdminServicesException, AuthorizationException, TException { - try { - return iamAdminService.getUsers(authzToken, offset, limit, search); - } catch (IamAdminServicesException e) { - throw e; - } catch (Throwable ex) { - String msg = "Error while retrieving user profile from IAM backend, reason: " + ex.getMessage(); - logger.error(msg, ex); - throw new IamAdminServicesException(msg); - } + return iamAdminService.getUsers(authzToken, offset, limit, search); } @Override @SecurityCheck public boolean resetUserPassword(AuthzToken authzToken, String username, String newPassword) throws IamAdminServicesException, AuthorizationException, TException { - try { - return iamAdminService.resetUserPassword(authzToken, username, newPassword); - } catch (IamAdminServicesException e) { - throw e; - } catch (Throwable ex) { - String msg = "Error while resetting user password in Identity Server, reason: " + ex.getMessage(); - logger.error(msg, ex); - throw new IamAdminServicesException(msg); - } + return iamAdminService.resetUserPassword(authzToken, username, newPassword); } @Override @SecurityCheck public List findUsers(AuthzToken authzToken, String email, String userId) throws IamAdminServicesException, AuthorizationException, TException { - try { - return iamAdminService.findUsers(authzToken, email, userId); - } catch (IamAdminServicesException e) { - throw e; - } catch (Throwable ex) { - String msg = "Error while retrieving users from Identity Server, reason: " + ex.getMessage(); - logger.error(msg, ex); - throw new IamAdminServicesException(msg); - } + return iamAdminService.findUsers(authzToken, email, userId); } @Override @SecurityCheck public void updateUserProfile(AuthzToken authzToken, UserProfile userDetails) throws IamAdminServicesException, AuthorizationException, TException { - try { - iamAdminService.updateUserProfile(authzToken, userDetails); - } catch (IamAdminServicesException e) { - throw e; - } catch (Throwable ex) { - String msg = "Error while updating user profile, reason: " + ex.getMessage(); - logger.error(msg, ex); - throw new IamAdminServicesException(msg); - } + iamAdminService.updateUserProfile(authzToken, userDetails); } @Override @SecurityCheck public boolean deleteUser(AuthzToken authzToken, String username) throws IamAdminServicesException, AuthorizationException, TException { - try { - return iamAdminService.deleteUser(authzToken, username); - } catch (IamAdminServicesException e) { - throw e; - } catch (Throwable ex) { - String msg = "Error while deleting user, reason: " + ex.getMessage(); - logger.error(msg, ex); - throw new IamAdminServicesException(msg); - } + return iamAdminService.deleteUser(authzToken, username); } @Override @@ -237,15 +138,7 @@ public boolean deleteUser(AuthzToken authzToken, String username) @Deprecated public boolean addRoleToUser(AuthzToken authzToken, String username, String roleName) throws IamAdminServicesException, AuthorizationException, TException { - try { - return iamAdminService.addRoleToUser(authzToken, username, roleName); - } catch (IamAdminServicesException e) { - throw e; - } catch (Throwable ex) { - String msg = "Error while adding role to user, reason: " + ex.getMessage(); - logger.error(msg, ex); - throw new IamAdminServicesException(msg); - } + return iamAdminService.addRoleToUser(authzToken, username, roleName); } @Override @@ -253,15 +146,7 @@ public boolean addRoleToUser(AuthzToken authzToken, String username, String role @Deprecated public boolean removeRoleFromUser(AuthzToken authzToken, String username, String roleName) throws IamAdminServicesException, AuthorizationException, TException { - try { - return iamAdminService.removeRoleFromUser(authzToken, username, roleName); - } catch (IamAdminServicesException e) { - throw e; - } catch (Throwable ex) { - String msg = "Error while removing role from user, reason: " + ex.getMessage(); - logger.error(msg, ex); - throw new IamAdminServicesException(msg); - } + return iamAdminService.removeRoleFromUser(authzToken, username, roleName); } @Override @@ -269,14 +154,6 @@ public boolean removeRoleFromUser(AuthzToken authzToken, String username, String @Deprecated public List getUsersWithRole(AuthzToken authzToken, String roleName) throws IamAdminServicesException, AuthorizationException, TException { - try { - return iamAdminService.getUsersWithRole(authzToken, roleName); - } catch (IamAdminServicesException e) { - throw e; - } catch (Throwable ex) { - String msg = "Error while retrieving users with role, reason: " + ex.getMessage(); - logger.error(msg, ex); - throw new IamAdminServicesException(msg); - } + return iamAdminService.getUsersWithRole(authzToken, roleName); } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/TenantProfileServiceHandler.java b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/TenantProfileServiceHandler.java index 75b6d9413e..6238d7cc6d 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/TenantProfileServiceHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/TenantProfileServiceHandler.java @@ -53,111 +53,48 @@ public String getAPIVersion() throws TException { @SecurityCheck public String addGateway(AuthzToken authzToken, Gateway gateway) throws TenantProfileServiceException, AuthorizationException, TException { - try { - return tenantProfileService.addGateway(authzToken, gateway); - } catch (TenantProfileServiceException e) { - throw e; - } catch (Throwable ex) { - logger.error("Error adding gateway-profile, reason: " + ex.getMessage(), ex); - TenantProfileServiceException exception = new TenantProfileServiceException(); - exception.setMessage("Error adding gateway-profile, reason: " + ex.getMessage()); - throw exception; - } + return tenantProfileService.addGateway(authzToken, gateway); } @Override @SecurityCheck public boolean updateGateway(AuthzToken authzToken, Gateway updatedGateway) throws TenantProfileServiceException, AuthorizationException, TException { - try { - return tenantProfileService.updateGateway(authzToken, updatedGateway); - } catch (TenantProfileServiceException e) { - throw e; - } catch (Throwable ex) { - logger.error("Error updating gateway-profile, reason: " + ex.getMessage(), ex); - TenantProfileServiceException exception = new TenantProfileServiceException(); - exception.setMessage("Error updating gateway-profile, reason: " + ex.getMessage()); - return false; - } + return tenantProfileService.updateGateway(authzToken, updatedGateway); } @Override @SecurityCheck public Gateway getGateway(AuthzToken authzToken, String airavataInternalGatewayId) throws TenantProfileServiceException, AuthorizationException, TException { - try { - return tenantProfileService.getGateway(authzToken, airavataInternalGatewayId); - } catch (TenantProfileServiceException e) { - throw e; - } catch (Throwable ex) { - logger.error("Error getting gateway-profile, reason: " + ex.getMessage(), ex); - TenantProfileServiceException exception = new TenantProfileServiceException(); - exception.setMessage("Error getting gateway-profile, reason: " + ex.getMessage()); - throw exception; - } + return tenantProfileService.getGateway(authzToken, airavataInternalGatewayId); } @Override @SecurityCheck public boolean deleteGateway(AuthzToken authzToken, String airavataInternalGatewayId, String gatewayId) throws TenantProfileServiceException, AuthorizationException, TException { - try { - return tenantProfileService.deleteGateway(authzToken, airavataInternalGatewayId, gatewayId); - } catch (TenantProfileServiceException e) { - throw e; - } catch (Throwable ex) { - logger.error("Error deleting gateway-profile, reason: " + ex.getMessage(), ex); - TenantProfileServiceException exception = new TenantProfileServiceException(); - exception.setMessage("Error deleting gateway-profile, reason: " + ex.getMessage()); - throw exception; - } + return tenantProfileService.deleteGateway(authzToken, airavataInternalGatewayId, gatewayId); } @Override @SecurityCheck public List getAllGateways(AuthzToken authzToken) throws TenantProfileServiceException, AuthorizationException, TException { - try { - return tenantProfileService.getAllGateways(authzToken); - } catch (TenantProfileServiceException e) { - throw e; - } catch (Throwable ex) { - logger.error("Error getting all gateway-profiles, reason: " + ex.getMessage(), ex); - TenantProfileServiceException exception = new TenantProfileServiceException(); - exception.setMessage("Error getting all gateway-profiles, reason: " + ex.getMessage()); - throw exception; - } + return tenantProfileService.getAllGateways(authzToken); } @Override @SecurityCheck public boolean isGatewayExist(AuthzToken authzToken, String gatewayId) throws TenantProfileServiceException, AuthorizationException, TException { - try { - return tenantProfileService.isGatewayExist(authzToken, gatewayId); - } catch (TenantProfileServiceException e) { - throw e; - } catch (Throwable ex) { - logger.error("Error checking if gateway-profile exists, reason: " + ex.getMessage(), ex); - TenantProfileServiceException exception = new TenantProfileServiceException(); - exception.setMessage("Error checking if gateway-profile exists, reason: " + ex.getMessage()); - throw exception; - } + return tenantProfileService.isGatewayExist(authzToken, gatewayId); } @Override @SecurityCheck public List getAllGatewaysForUser(AuthzToken authzToken, String requesterUsername) throws TenantProfileServiceException, AuthorizationException, TException { - try { - return tenantProfileService.getAllGatewaysForUser(authzToken, requesterUsername); - } catch (TenantProfileServiceException e) { - throw e; - } catch (Throwable ex) { - logger.error("Error getting user's gateway-profiles, reason: " + ex.getMessage(), ex); - TenantProfileServiceException exception = new TenantProfileServiceException(); - exception.setMessage("Error getting user's gateway-profiles, reason: " + ex.getMessage()); - throw exception; - } + return tenantProfileService.getAllGatewaysForUser(authzToken, requesterUsername); } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/UserProfileServiceHandler.java b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/UserProfileServiceHandler.java index 91fb2df49f..5f2432ea03 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/UserProfileServiceHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/UserProfileServiceHandler.java @@ -28,12 +28,9 @@ import org.apache.airavata.service.profile.user.cpi.profile_user_cpiConstants; import org.apache.airavata.service.security.interceptor.SecurityCheck; import org.apache.thrift.TException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class UserProfileServiceHandler implements UserProfileService.Iface { - private static final Logger logger = LoggerFactory.getLogger(UserProfileServiceHandler.class); private org.apache.airavata.service.UserProfileService userProfileService; public UserProfileServiceHandler() { @@ -49,110 +46,47 @@ public String getAPIVersion() throws TException { @SecurityCheck public String initializeUserProfile(AuthzToken authzToken) throws UserProfileServiceException, AuthorizationException, TException { - try { - return userProfileService.initializeUserProfile(authzToken); - } catch (UserProfileServiceException e) { - throw e; - } catch (Throwable e) { - logger.error("Error while initializing user profile", e); - UserProfileServiceException exception = new UserProfileServiceException(); - exception.setMessage("Error while initializing user profile. More info : " + e.getMessage()); - throw exception; - } + return userProfileService.initializeUserProfile(authzToken); } @Override @SecurityCheck public String addUserProfile(AuthzToken authzToken, UserProfile userProfile) throws UserProfileServiceException, AuthorizationException, TException { - try { - return userProfileService.addUserProfile(authzToken, userProfile); - } catch (UserProfileServiceException e) { - throw e; - } catch (Throwable e) { - logger.error("Error while creating user profile", e); - UserProfileServiceException exception = new UserProfileServiceException(); - exception.setMessage("Error while creating user profile. More info : " + e.getMessage()); - throw exception; - } + return userProfileService.addUserProfile(authzToken, userProfile); } @Override @SecurityCheck public boolean updateUserProfile(AuthzToken authzToken, UserProfile userProfile) throws UserProfileServiceException, AuthorizationException, TException { - try { - return userProfileService.updateUserProfile(authzToken, userProfile); - } catch (UserProfileServiceException e) { - throw e; - } catch (Throwable e) { - logger.error("Error while Updating user profile", e); - UserProfileServiceException exception = new UserProfileServiceException(); - exception.setMessage("Error while Updating user profile. More info : " + e.getMessage()); - throw exception; - } + return userProfileService.updateUserProfile(authzToken, userProfile); } @Override @SecurityCheck public UserProfile getUserProfileById(AuthzToken authzToken, String userId, String gatewayId) throws UserProfileServiceException, AuthorizationException, TException { - try { - return userProfileService.getUserProfileById(authzToken, userId, gatewayId); - } catch (UserProfileServiceException e) { - throw e; - } catch (Throwable e) { - logger.error("Error retrieving user profile by ID", e); - UserProfileServiceException exception = new UserProfileServiceException(); - exception.setMessage("Error retrieving user profile by ID. More info : " + e.getMessage()); - throw exception; - } + return userProfileService.getUserProfileById(authzToken, userId, gatewayId); } @Override @SecurityCheck public boolean deleteUserProfile(AuthzToken authzToken, String userId, String gatewayId) throws UserProfileServiceException, AuthorizationException, TException { - try { - return userProfileService.deleteUserProfile(authzToken, userId, gatewayId); - } catch (UserProfileServiceException e) { - throw e; - } catch (Throwable e) { - logger.error("Error while deleting user profile", e); - UserProfileServiceException exception = new UserProfileServiceException(); - exception.setMessage("Error while deleting user profile. More info : " + e.getMessage()); - throw exception; - } + return userProfileService.deleteUserProfile(authzToken, userId, gatewayId); } @Override @SecurityCheck public List getAllUserProfilesInGateway(AuthzToken authzToken, String gatewayId, int offset, int limit) throws UserProfileServiceException, AuthorizationException, TException { - try { - return userProfileService.getAllUserProfilesInGateway(authzToken, gatewayId, offset, limit); - } catch (UserProfileServiceException e) { - throw e; - } catch (Throwable e) { - logger.error("Error while retrieving user profile List", e); - UserProfileServiceException exception = new UserProfileServiceException(); - exception.setMessage("Error while retrieving user profile List. More info : " + e.getMessage()); - throw exception; - } + return userProfileService.getAllUserProfilesInGateway(authzToken, gatewayId, offset, limit); } @Override public boolean doesUserExist(AuthzToken authzToken, String userId, String gatewayId) throws UserProfileServiceException, AuthorizationException, TException { - try { - return userProfileService.doesUserExist(authzToken, userId, gatewayId); - } catch (UserProfileServiceException e) { - throw e; - } catch (Throwable e) { - logger.error("Error while finding user profile", e); - UserProfileServiceException exception = new UserProfileServiceException(); - exception.setMessage("Error while finding user profile. More info : " + e.getMessage()); - throw exception; - } + return userProfileService.doesUserExist(authzToken, userId, gatewayId); } } diff --git a/airavata-api/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java index b9b30e05f0..79928ba624 100644 --- a/airavata-api/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java @@ -26,13 +26,9 @@ import org.apache.airavata.sharing.registry.models.*; import org.apache.airavata.sharing.registry.service.cpi.SharingRegistryService; import org.apache.airavata.sharing.registry.service.cpi.sharing_cpiConstants; -import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.thrift.TException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class SharingRegistryServerHandler implements SharingRegistryService.Iface { - private static final Logger logger = LoggerFactory.getLogger(SharingRegistryServerHandler.class); private org.apache.airavata.service.SharingRegistryService sharingRegistryService; public static String OWNER_PERMISSION_NAME = @@ -59,26 +55,12 @@ public String getAPIVersion() throws TException { */ @Override public String createDomain(Domain domain) throws SharingRegistryException, DuplicateEntryException, TException { - try { - return sharingRegistryService.createDomain(domain); - } catch (SharingRegistryException | DuplicateEntryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.createDomain(domain); } @Override public boolean updateDomain(Domain domain) throws SharingRegistryException, TException { - try { - return sharingRegistryService.updateDomain(domain); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.updateDomain(domain); } /** @@ -88,50 +70,22 @@ public boolean updateDomain(Domain domain) throws SharingRegistryException, TExc */ @Override public boolean isDomainExists(String domainId) throws SharingRegistryException, TException { - try { - return sharingRegistryService.isDomainExists(domainId); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.isDomainExists(domainId); } @Override public boolean deleteDomain(String domainId) throws SharingRegistryException, TException { - try { - return sharingRegistryService.deleteDomain(domainId); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.deleteDomain(domainId); } @Override public Domain getDomain(String domainId) throws SharingRegistryException, TException { - try { - return sharingRegistryService.getDomain(domainId); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.getDomain(domainId); } @Override public List getDomains(int offset, int limit) throws TException { - try { - return sharingRegistryService.getDomains(offset, limit); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.getDomains(offset, limit); } /** @@ -140,26 +94,12 @@ public List getDomains(int offset, int limit) throws TException { */ @Override public String createUser(User user) throws SharingRegistryException, DuplicateEntryException, TException { - try { - return sharingRegistryService.createUser(user); - } catch (SharingRegistryException | DuplicateEntryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.createUser(user); } @Override public boolean updatedUser(User user) throws SharingRegistryException, TException { - try { - return sharingRegistryService.updatedUser(user); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.updatedUser(user); } /** @@ -169,50 +109,22 @@ public boolean updatedUser(User user) throws SharingRegistryException, TExceptio */ @Override public boolean isUserExists(String domainId, String userId) throws SharingRegistryException, TException { - try { - return sharingRegistryService.isUserExists(domainId, userId); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.isUserExists(domainId, userId); } @Override public boolean deleteUser(String domainId, String userId) throws SharingRegistryException, TException { - try { - return sharingRegistryService.deleteUser(domainId, userId); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.deleteUser(domainId, userId); } @Override public User getUser(String domainId, String userId) throws SharingRegistryException, TException { - try { - return sharingRegistryService.getUser(domainId, userId); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.getUser(domainId, userId); } @Override public List getUsers(String domain, int offset, int limit) throws SharingRegistryException, TException { - try { - return sharingRegistryService.getUsers(domain, offset, limit); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.getUsers(domain, offset, limit); } /** @@ -221,26 +133,12 @@ public List getUsers(String domain, int offset, int limit) throws SharingR */ @Override public String createGroup(UserGroup group) throws SharingRegistryException, TException { - try { - return sharingRegistryService.createGroup(group); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.createGroup(group); } @Override public boolean updateGroup(UserGroup group) throws SharingRegistryException, TException { - try { - return sharingRegistryService.updateGroup(group); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.updateGroup(group); } /** @@ -253,206 +151,94 @@ public boolean updateGroup(UserGroup group) throws SharingRegistryException, TEx */ @Override public boolean isGroupExists(String domainId, String groupId) throws SharingRegistryException, TException { - try { - return sharingRegistryService.isGroupExists(domainId, groupId); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.isGroupExists(domainId, groupId); } @Override public boolean deleteGroup(String domainId, String groupId) throws SharingRegistryException, TException { - try { - return sharingRegistryService.deleteGroup(domainId, groupId); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.deleteGroup(domainId, groupId); } @Override public UserGroup getGroup(String domainId, String groupId) throws SharingRegistryException, TException { - try { - return sharingRegistryService.getGroup(domainId, groupId); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.getGroup(domainId, groupId); } @Override public List getGroups(String domain, int offset, int limit) throws TException { - try { - return sharingRegistryService.getGroups(domain, offset, limit); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.getGroups(domain, offset, limit); } @Override public boolean addUsersToGroup(String domainId, List userIds, String groupId) throws SharingRegistryException, TException { - try { - return sharingRegistryService.addUsersToGroup(domainId, userIds, groupId); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.addUsersToGroup(domainId, userIds, groupId); } @Override public boolean removeUsersFromGroup(String domainId, List userIds, String groupId) throws SharingRegistryException, TException { - try { - return sharingRegistryService.removeUsersFromGroup(domainId, userIds, groupId); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.removeUsersFromGroup(domainId, userIds, groupId); } @Override public boolean transferGroupOwnership(String domainId, String groupId, String newOwnerId) throws SharingRegistryException, TException { - try { - return sharingRegistryService.transferGroupOwnership(domainId, groupId, newOwnerId); - } catch (SharingRegistryException | DuplicateEntryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.transferGroupOwnership(domainId, groupId, newOwnerId); } @Override public boolean addGroupAdmins(String domainId, String groupId, List adminIds) throws SharingRegistryException, TException { - try { - return sharingRegistryService.addGroupAdmins(domainId, groupId, adminIds); - } catch (SharingRegistryException | DuplicateEntryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.addGroupAdmins(domainId, groupId, adminIds); } @Override public boolean removeGroupAdmins(String domainId, String groupId, List adminIds) throws SharingRegistryException, TException { - try { - return sharingRegistryService.removeGroupAdmins(domainId, groupId, adminIds); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.removeGroupAdmins(domainId, groupId, adminIds); } @Override public boolean hasAdminAccess(String domainId, String groupId, String adminId) throws SharingRegistryException, TException { - try { - return sharingRegistryService.hasAdminAccess(domainId, groupId, adminId); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.hasAdminAccess(domainId, groupId, adminId); } @Override public boolean hasOwnerAccess(String domainId, String groupId, String ownerId) throws SharingRegistryException, TException { - try { - return sharingRegistryService.hasOwnerAccess(domainId, groupId, ownerId); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.hasOwnerAccess(domainId, groupId, ownerId); } @Override public List getGroupMembersOfTypeUser(String domainId, String groupId, int offset, int limit) throws SharingRegistryException, TException { - try { - return sharingRegistryService.getGroupMembersOfTypeUser(domainId, groupId, offset, limit); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.getGroupMembersOfTypeUser(domainId, groupId, offset, limit); } @Override public List getGroupMembersOfTypeGroup(String domainId, String groupId, int offset, int limit) throws SharingRegistryException, TException { - try { - return sharingRegistryService.getGroupMembersOfTypeGroup(domainId, groupId, offset, limit); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.getGroupMembersOfTypeGroup(domainId, groupId, offset, limit); } @Override public boolean addChildGroupsToParentGroup(String domainId, List childIds, String groupId) throws SharingRegistryException, TException { - try { - return sharingRegistryService.addChildGroupsToParentGroup(domainId, childIds, groupId); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.addChildGroupsToParentGroup(domainId, childIds, groupId); } @Override public boolean removeChildGroupFromParentGroup(String domainId, String childId, String groupId) throws SharingRegistryException, TException { - try { - return sharingRegistryService.removeChildGroupFromParentGroup(domainId, childId, groupId); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.removeChildGroupFromParentGroup(domainId, childId, groupId); } @Override public List getAllMemberGroupsForUser(String domainId, String userId) throws SharingRegistryException, TException { - try { - return sharingRegistryService.getAllMemberGroupsForUser(domainId, userId); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.getAllMemberGroupsForUser(domainId, userId); } /** @@ -462,26 +248,12 @@ public List getAllMemberGroupsForUser(String domainId, String userId) @Override public String createEntityType(EntityType entityType) throws SharingRegistryException, DuplicateEntryException, TException { - try { - return sharingRegistryService.createEntityType(entityType); - } catch (SharingRegistryException | DuplicateEntryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.createEntityType(entityType); } @Override public boolean updateEntityType(EntityType entityType) throws SharingRegistryException, TException { - try { - return sharingRegistryService.updateEntityType(entityType); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.updateEntityType(entityType); } /** @@ -492,50 +264,22 @@ public boolean updateEntityType(EntityType entityType) throws SharingRegistryExc @Override public boolean isEntityTypeExists(String domainId, String entityTypeId) throws SharingRegistryException, TException { - try { - return sharingRegistryService.isEntityTypeExists(domainId, entityTypeId); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.isEntityTypeExists(domainId, entityTypeId); } @Override public boolean deleteEntityType(String domainId, String entityTypeId) throws SharingRegistryException, TException { - try { - return sharingRegistryService.deleteEntityType(domainId, entityTypeId); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.deleteEntityType(domainId, entityTypeId); } @Override public EntityType getEntityType(String domainId, String entityTypeId) throws SharingRegistryException, TException { - try { - return sharingRegistryService.getEntityType(domainId, entityTypeId); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.getEntityType(domainId, entityTypeId); } @Override public List getEntityTypes(String domain, int offset, int limit) throws TException { - try { - return sharingRegistryService.getEntityTypes(domain, offset, limit); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.getEntityTypes(domain, offset, limit); } /** @@ -545,26 +289,12 @@ public List getEntityTypes(String domain, int offset, int limit) thr @Override public String createPermissionType(PermissionType permissionType) throws SharingRegistryException, DuplicateEntryException, TException { - try { - return sharingRegistryService.createPermissionType(permissionType); - } catch (SharingRegistryException | DuplicateEntryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.createPermissionType(permissionType); } @Override public boolean updatePermissionType(PermissionType permissionType) throws SharingRegistryException, TException { - try { - return sharingRegistryService.updatePermissionType(permissionType); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.updatePermissionType(permissionType); } /** @@ -575,53 +305,25 @@ public boolean updatePermissionType(PermissionType permissionType) throws Sharin @Override public boolean isPermissionExists(String domainId, String permissionId) throws SharingRegistryException, TException { - try { - return sharingRegistryService.isPermissionExists(domainId, permissionId); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.isPermissionExists(domainId, permissionId); } @Override public boolean deletePermissionType(String domainId, String permissionTypeId) throws SharingRegistryException, TException { - try { - return sharingRegistryService.deletePermissionType(domainId, permissionTypeId); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.deletePermissionType(domainId, permissionTypeId); } @Override public PermissionType getPermissionType(String domainId, String permissionTypeId) throws SharingRegistryException, TException { - try { - return sharingRegistryService.getPermissionType(domainId, permissionTypeId); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.getPermissionType(domainId, permissionTypeId); } @Override public List getPermissionTypes(String domain, int offset, int limit) throws SharingRegistryException, TException { - try { - return sharingRegistryService.getPermissionTypes(domain, offset, limit); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.getPermissionTypes(domain, offset, limit); } /** @@ -630,28 +332,12 @@ public List getPermissionTypes(String domain, int offset, int li */ @Override public String createEntity(Entity entity) throws SharingRegistryException, DuplicateEntryException, TException { - try { - return sharingRegistryService.createEntity(entity); - } catch (SharingRegistryException | DuplicateEntryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - SharingRegistryException sharingRegistryException = new SharingRegistryException(); - sharingRegistryException.setMessage(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - throw sharingRegistryException; - } + return sharingRegistryService.createEntity(entity); } @Override public boolean updateEntity(Entity entity) throws SharingRegistryException, TException { - try { - return sharingRegistryService.updateEntity(entity); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.updateEntity(entity); } /** @@ -661,108 +347,48 @@ public boolean updateEntity(Entity entity) throws SharingRegistryException, TExc */ @Override public boolean isEntityExists(String domainId, String entityId) throws SharingRegistryException, TException { - try { - return sharingRegistryService.isEntityExists(domainId, entityId); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.isEntityExists(domainId, entityId); } @Override public boolean deleteEntity(String domainId, String entityId) throws SharingRegistryException, TException { - try { - return sharingRegistryService.deleteEntity(domainId, entityId); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.deleteEntity(domainId, entityId); } @Override public Entity getEntity(String domainId, String entityId) throws SharingRegistryException, TException { - try { - return sharingRegistryService.getEntity(domainId, entityId); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.getEntity(domainId, entityId); } @Override public List searchEntities( String domainId, String userId, List filters, int offset, int limit) throws SharingRegistryException, TException { - try { - return sharingRegistryService.searchEntities(domainId, userId, filters, offset, limit); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.searchEntities(domainId, userId, filters, offset, limit); } @Override public List getListOfSharedUsers(String domainId, String entityId, String permissionTypeId) throws SharingRegistryException, TException { - try { - return sharingRegistryService.getListOfSharedUsers(domainId, entityId, permissionTypeId); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.getListOfSharedUsers(domainId, entityId, permissionTypeId); } @Override public List getListOfDirectlySharedUsers(String domainId, String entityId, String permissionTypeId) throws SharingRegistryException, TException { - try { - return sharingRegistryService.getListOfDirectlySharedUsers(domainId, entityId, permissionTypeId); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - SharingRegistryException sharingRegistryException = new SharingRegistryException(); - sharingRegistryException.setMessage(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - throw sharingRegistryException; - } + return sharingRegistryService.getListOfDirectlySharedUsers(domainId, entityId, permissionTypeId); } @Override public List getListOfSharedGroups(String domainId, String entityId, String permissionTypeId) throws SharingRegistryException, TException { - try { - return sharingRegistryService.getListOfSharedGroups(domainId, entityId, permissionTypeId); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.getListOfSharedGroups(domainId, entityId, permissionTypeId); } @Override public List getListOfDirectlySharedGroups(String domainId, String entityId, String permissionTypeId) throws SharingRegistryException, TException { - try { - return sharingRegistryService.getListOfDirectlySharedGroups(domainId, entityId, permissionTypeId); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - SharingRegistryException sharingRegistryException = new SharingRegistryException(); - sharingRegistryException.setMessage(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - throw sharingRegistryException; - } + return sharingRegistryService.getListOfDirectlySharedGroups(domainId, entityId, permissionTypeId); } /** @@ -780,15 +406,8 @@ public List getListOfDirectlySharedGroups(String domainId, String ent public boolean shareEntityWithUsers( String domainId, String entityId, List userList, String permissionTypeId, boolean cascadePermission) throws SharingRegistryException, TException { - try { - return sharingRegistryService.shareEntityWithUsers( + return sharingRegistryService.shareEntityWithUsers( domainId, entityId, userList, permissionTypeId, cascadePermission); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } } @Override @@ -799,56 +418,28 @@ public boolean shareEntityWithGroups( String permissionTypeId, boolean cascadePermission) throws SharingRegistryException, TException { - try { - return sharingRegistryService.shareEntityWithGroups( + return sharingRegistryService.shareEntityWithGroups( domainId, entityId, groupList, permissionTypeId, cascadePermission); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } } @Override public boolean revokeEntitySharingFromUsers( String domainId, String entityId, List userList, String permissionTypeId) throws SharingRegistryException, TException { - try { - return sharingRegistryService.revokeEntitySharingFromUsers(domainId, entityId, userList, permissionTypeId); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.revokeEntitySharingFromUsers(domainId, entityId, userList, permissionTypeId); } @Override public boolean revokeEntitySharingFromGroups( String domainId, String entityId, List groupList, String permissionTypeId) throws SharingRegistryException, TException { - try { - return sharingRegistryService.revokeEntitySharingFromGroups( + return sharingRegistryService.revokeEntitySharingFromGroups( domainId, entityId, groupList, permissionTypeId); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } } @Override public boolean userHasAccess(String domainId, String userId, String entityId, String permissionTypeId) throws SharingRegistryException, TException { - try { - return sharingRegistryService.userHasAccess(domainId, userId, entityId, permissionTypeId); - } catch (SharingRegistryException e) { - throw e; - } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - } + return sharingRegistryService.userHasAccess(domainId, userId, entityId, permissionTypeId); } } From 96d37776d7f6e7b1b08f3e2642f6dd1a59d6e2a7 Mon Sep 17 00:00:00 2001 From: yasithdev Date: Tue, 25 Nov 2025 15:41:48 -0600 Subject: [PATCH 20/26] preserve stack trace of exceptions --- .../handler/ThriftExceptionHandler.java | 2 + .../airavata/service/AiravataService.java | 2 + .../service/CredentialStoreService.java | 26 +++++----- .../airavata/service/GroupManagerService.java | 14 +++++ .../airavata/service/IamAdminService.java | 51 ++++++++++++++----- .../airavata/service/RegistryService.java | 1 + .../service/SharingRegistryService.java | 20 ++++++-- .../service/TenantProfileService.java | 11 +++- .../airavata/service/UserProfileService.java | 9 ++++ .../security/SecurityManagerFactory.java | 6 +-- .../authzcache/AuthzCacheManagerFactory.java | 8 +-- .../authzcache/DefaultAuthzCacheManager.java | 10 ++-- .../interceptor/SecurityInterceptor.java | 8 ++- 13 files changed, 122 insertions(+), 46 deletions(-) diff --git a/airavata-api/src/main/java/org/apache/airavata/api/server/handler/ThriftExceptionHandler.java b/airavata-api/src/main/java/org/apache/airavata/api/server/handler/ThriftExceptionHandler.java index 63ab0dc7ca..662d8aa1b7 100644 --- a/airavata-api/src/main/java/org/apache/airavata/api/server/handler/ThriftExceptionHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/api/server/handler/ThriftExceptionHandler.java @@ -32,6 +32,7 @@ public static RuntimeException convertException(Throwable e, String context) { org.apache.airavata.model.error.AiravataSystemException exception = new org.apache.airavata.model.error.AiravataSystemException(); exception.setAiravataErrorType(org.apache.airavata.model.error.AiravataErrorType.INTERNAL_ERROR); exception.setMessage(context + ". More info : " + e.getMessage()); + exception.initCause(e); throw sneakyThrow(exception); } @@ -40,6 +41,7 @@ public static RuntimeException convertException(Throwable e, String context) { org.apache.airavata.model.error.AiravataSystemException exception = new org.apache.airavata.model.error.AiravataSystemException(); exception.setAiravataErrorType(org.apache.airavata.model.error.AiravataErrorType.INTERNAL_ERROR); exception.setMessage(context + ". More info : " + e.getMessage()); + exception.initCause(e); throw sneakyThrow(exception); } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java b/airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java index ba88c119eb..ab13bc4216 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java @@ -191,12 +191,14 @@ private RuntimeException convertException(Throwable e, String msg) { org.apache.airavata.model.error.AiravataSystemException exception = new org.apache.airavata.model.error.AiravataSystemException(); exception.setAiravataErrorType(org.apache.airavata.model.error.AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + ". More info : " + e.getMessage()); + exception.initCause(e); throw sneakyThrow(exception); } logger.error(msg, e); org.apache.airavata.model.error.AiravataSystemException exception = new org.apache.airavata.model.error.AiravataSystemException(); exception.setAiravataErrorType(org.apache.airavata.model.error.AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + ". More info : " + e.getMessage()); + exception.initCause(e); throw sneakyThrow(exception); } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/CredentialStoreService.java b/airavata-api/src/main/java/org/apache/airavata/service/CredentialStoreService.java index f249231de5..6d07d279a1 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/CredentialStoreService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/CredentialStoreService.java @@ -134,10 +134,10 @@ public String addCertificateCredential(CertificateCredential certificateCredenti return token; } catch (CredentialStoreException e) { logger.error("Error occurred while saving Certificate Credentials.", e); - throw new CredentialStoreException("Error occurred while saving Certificate Credentials."); + throw new CredentialStoreException("Error occurred while saving Certificate Credentials.", e); } catch (Exception e) { logger.error("Error occurred while converting to X509 certificate.", e); - throw new CredentialStoreException("Error occurred while converting to X509 certificate.."); + throw new CredentialStoreException("Error occurred while converting to X509 certificate..", e); } } @@ -156,10 +156,10 @@ public String addPasswordCredential(PasswordCredential passwordCredential) throw return token; } catch (CredentialStoreException e) { logger.error("Error occurred while saving PWD Credentials.", e); - throw new CredentialStoreException("Error occurred while saving PWD Credentials."); + throw new CredentialStoreException("Error occurred while saving PWD Credentials.", e); } catch (Exception e) { logger.error("Error occurred while registering PWD Credentials.", e); - throw new CredentialStoreException("Error occurred while registering PWD Credentials.."); + throw new CredentialStoreException("Error occurred while registering PWD Credentials..", e); } } @@ -194,7 +194,7 @@ public SSHCredential getSSHCredential(String tokenId, String gatewayId) throws C + gatewayId, e); throw new CredentialStoreException("Error occurred while retrieving SSH credential for token - " + tokenId - + " and gateway id - " + gatewayId); + + " and gateway id - " + gatewayId, e); } } @@ -254,7 +254,7 @@ public List getAllCredentialSummaries( final String msg = "Error occurred while retrieving " + type + " credential Summary for tokens - " + accessibleTokenIds + " and gateway id - " + gatewayId; logger.error(msg, e); - throw new CredentialStoreException(msg); + throw new CredentialStoreException(msg, e); } } @@ -350,7 +350,7 @@ public CertificateCredential getCertificateCredential(String tokenId, String gat + " and gateway id - " + gatewayId, e); throw new CredentialStoreException("Error occurred while retrieving Certificate credential for token - " - + tokenId + " and gateway id - " + gatewayId); + + tokenId + " and gateway id - " + gatewayId, e); } } @@ -382,7 +382,7 @@ public PasswordCredential getPasswordCredential(String tokenId, String gatewayId + gatewayId, e); throw new CredentialStoreException("Error occurred while retrieving PWD credential for token - " + tokenId - + " and gateway id - " + gatewayId); + + " and gateway id - " + gatewayId, e); } } @@ -417,7 +417,7 @@ public List getAllCredentialSummaryForGateway(SummaryType typ } } catch (CredentialStoreException e) { logger.error("Error occurred while retrieving credential Summary", e); - throw new CredentialStoreException("Error occurred while retrieving credential Summary"); + throw new CredentialStoreException("Error occurred while retrieving credential Summary", e); } return summaryList; } else { @@ -469,7 +469,7 @@ public List getAllCredentialSummaryForUserInGateway( } } catch (CredentialStoreException e) { logger.error("Error occurred while retrieving credential Summary", e); - throw new CredentialStoreException("Error occurred while retrieving credential Summary"); + throw new CredentialStoreException("Error occurred while retrieving credential Summary", e); } return summaryList; } else { @@ -500,7 +500,7 @@ public Map getAllPWDCredentialsForGateway(String gatewayId) thro } } catch (CredentialStoreException e) { logger.error("Error occurred while retrieving credentials", e); - throw new CredentialStoreException("Error occurred while retrieving credentials"); + throw new CredentialStoreException("Error occurred while retrieving credentials", e); } return pwdCredMap; } @@ -515,7 +515,7 @@ public boolean deleteSSHCredential(String tokenId, String gatewayId) throws Cred + gatewayId, e); throw new CredentialStoreException("Error occurred while deleting SSH credential for token - " + tokenId - + " and gateway id - " + gatewayId); + + " and gateway id - " + gatewayId, e); } } @@ -529,7 +529,7 @@ public boolean deletePWDCredential(String tokenId, String gatewayId) throws Cred + gatewayId, e); throw new CredentialStoreException("Error occurred while deleting PWD credential for token - " + tokenId - + " and gateway id - " + gatewayId); + + " and gateway id - " + gatewayId, e); } } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/GroupManagerService.java b/airavata-api/src/main/java/org/apache/airavata/service/GroupManagerService.java index 98c2438ab5..5989f072d5 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/GroupManagerService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/GroupManagerService.java @@ -50,6 +50,7 @@ private GroupManagerServiceException convertException(Throwable e, String msg) { logger.error(msg, e); GroupManagerServiceException exception = new GroupManagerServiceException(); exception.setMessage(msg + ". More info : " + e.getMessage()); + exception.initCause(e); return exception; } @@ -79,6 +80,7 @@ public String createGroup(AuthzToken authzToken, GroupModel groupModel) throws G logger.error(msg, e); GroupManagerServiceException exception = new GroupManagerServiceException(); exception.setMessage(msg + " More info : " + e.getMessage()); + exception.initCause(e); throw exception; } } @@ -108,6 +110,7 @@ public boolean updateGroup(AuthzToken authzToken, GroupModel groupModel) throws logger.error(msg, e); GroupManagerServiceException exception = new GroupManagerServiceException(); exception.setMessage(msg + " More info : " + e.getMessage()); + exception.initCause(e); throw exception; } } @@ -129,6 +132,7 @@ public boolean deleteGroup(AuthzToken authzToken, String groupId, String ownerId logger.error(msg, e); GroupManagerServiceException exception = new GroupManagerServiceException(); exception.setMessage(msg + " More info : " + e.getMessage()); + exception.initCause(e); throw exception; } } @@ -147,6 +151,7 @@ public GroupModel getGroup(AuthzToken authzToken, String groupId) throws GroupMa logger.error(msg, e); GroupManagerServiceException exception = new GroupManagerServiceException(); exception.setMessage(msg + " More info : " + e.getMessage()); + exception.initCause(e); throw exception; } } @@ -164,6 +169,7 @@ public List getGroups(AuthzToken authzToken) throws GroupManagerServ logger.error(msg, e); GroupManagerServiceException exception = new GroupManagerServiceException(); exception.setMessage(msg + " More info : " + e.getMessage()); + exception.initCause(e); throw exception; } finally { closeSharingClient(sharingClient); @@ -184,6 +190,7 @@ public List getAllGroupsUserBelongs(AuthzToken authzToken, String us logger.error(msg, e); GroupManagerServiceException exception = new GroupManagerServiceException(); exception.setMessage(msg + " More info : " + e.getMessage()); + exception.initCause(e); throw exception; } } @@ -205,6 +212,7 @@ public boolean addUsersToGroup(AuthzToken authzToken, List userIds, Stri logger.error(msg, e); GroupManagerServiceException exception = new GroupManagerServiceException(); exception.setMessage(msg + " More info : " + e.getMessage()); + exception.initCause(e); throw exception; } } @@ -225,6 +233,7 @@ public boolean removeUsersFromGroup(AuthzToken authzToken, List userIds, logger.error(msg, e); GroupManagerServiceException exception = new GroupManagerServiceException(); exception.setMessage(msg + " More info : " + e.getMessage()); + exception.initCause(e); throw exception; } } @@ -245,6 +254,7 @@ public boolean transferGroupOwnership(AuthzToken authzToken, String groupId, Str logger.error(msg, e); GroupManagerServiceException exception = new GroupManagerServiceException(); exception.setMessage(msg + " More info : " + e.getMessage()); + exception.initCause(e); throw exception; } } @@ -264,6 +274,7 @@ public boolean addGroupAdmins(AuthzToken authzToken, String groupId, List getUsers(AuthzToken authzToken, int offset, int limit, } catch (Exception ex) { String msg = "Error while retrieving user profile from IAM backend, reason: " + ex.getMessage(); logger.error(msg, ex); - throw new IamAdminServicesException(msg); + IamAdminServicesException exception = new IamAdminServicesException(msg); + exception.initCause(ex); + throw exception; } } @@ -207,7 +222,9 @@ public boolean resetUserPassword(AuthzToken authzToken, String username, String } catch (TException ex) { String msg = "Error while resetting user password in Identity Server, reason: " + ex.getMessage(); logger.error(msg, ex); - throw new IamAdminServicesException(msg); + IamAdminServicesException exception = new IamAdminServicesException(msg); + exception.initCause(ex); + throw exception; } } @@ -220,7 +237,9 @@ public List findUsers(AuthzToken authzToken, String email, String u } catch (TException ex) { String msg = "Error while retrieving users from Identity Server, reason: " + ex.getMessage(); logger.error(msg, ex); - throw new IamAdminServicesException(msg); + IamAdminServicesException exception = new IamAdminServicesException(msg); + exception.initCause(ex); + throw exception; } } @@ -259,7 +278,9 @@ public boolean addRoleToUser(AuthzToken authzToken, String username, String role } catch (TException | ApplicationSettingsException ex) { String msg = "Error while adding role to user, reason: " + ex.getMessage(); logger.error(msg, ex); - throw new IamAdminServicesException(msg); + IamAdminServicesException exception = new IamAdminServicesException(msg); + exception.initCause(ex); + throw exception; } } @@ -273,7 +294,9 @@ public boolean removeRoleFromUser(AuthzToken authzToken, String username, String } catch (TException | ApplicationSettingsException ex) { String msg = "Error while removing role from user, reason: " + ex.getMessage(); logger.error(msg, ex); - throw new IamAdminServicesException(msg); + IamAdminServicesException exception = new IamAdminServicesException(msg); + exception.initCause(ex); + throw exception; } } @@ -286,7 +309,9 @@ public List getUsersWithRole(AuthzToken authzToken, String roleName } catch (Exception ex) { String msg = "Error while retrieving users with role, reason: " + ex.getMessage(); logger.error(msg, ex); - throw new IamAdminServicesException(msg); + IamAdminServicesException exception = new IamAdminServicesException(msg); + exception.initCause(ex); + throw exception; } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/RegistryService.java b/airavata-api/src/main/java/org/apache/airavata/service/RegistryService.java index 4fb0be90e4..76902eb02c 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/RegistryService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/RegistryService.java @@ -85,6 +85,7 @@ private RegistryServiceException convertException(Throwable e, String msg) { logger.error(msg, e); RegistryServiceException exception = new RegistryServiceException(); exception.setMessage(msg + " More info : " + e.getMessage()); + exception.initCause(e); return exception; } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/SharingRegistryService.java b/airavata-api/src/main/java/org/apache/airavata/service/SharingRegistryService.java index 04001dee9a..11d6b65ba5 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/SharingRegistryService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/SharingRegistryService.java @@ -37,7 +37,9 @@ public class SharingRegistryService { private SharingRegistryException convertException(Throwable ex, String context) { logger.error(context + ": " + ex.getMessage(), ex); - return new SharingRegistryException(context + ": " + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + SharingRegistryException exception = new SharingRegistryException(context + ": " + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + return exception; } /** @@ -68,7 +70,9 @@ public String createDomain(Domain domain) throws SharingRegistryException, Dupli throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + SharingRegistryException exception = new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -84,7 +88,9 @@ public boolean updateDomain(Domain domain) throws SharingRegistryException { throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + SharingRegistryException exception = new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -95,7 +101,9 @@ public boolean isDomainExists(String domainId) throws SharingRegistryException { throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + SharingRegistryException exception = new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -107,7 +115,9 @@ public boolean deleteDomain(String domainId) throws SharingRegistryException { throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); - throw new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + SharingRegistryException exception = new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/TenantProfileService.java b/airavata-api/src/main/java/org/apache/airavata/service/TenantProfileService.java index ae36673c8d..2ceb1cac62 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/TenantProfileService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/TenantProfileService.java @@ -52,6 +52,7 @@ private TenantProfileServiceException convertException(Throwable e, String msg) logger.error(msg, e); TenantProfileServiceException exception = new TenantProfileServiceException(); exception.setMessage(msg + ". More info : " + e.getMessage()); + exception.initCause(e); return exception; } @@ -92,6 +93,7 @@ public String addGateway(AuthzToken authzToken, Gateway gateway) throws TenantPr logger.error("Error adding gateway-profile, reason: " + ex.getMessage(), ex); TenantProfileServiceException exception = new TenantProfileServiceException(); exception.setMessage("Error adding gateway-profile, reason: " + ex.getMessage()); + exception.initCause(ex); throw exception; } } @@ -122,7 +124,8 @@ public boolean updateGateway(AuthzToken authzToken, Gateway updatedGateway) thro logger.error("Error updating gateway-profile, reason: " + ex.getMessage(), ex); TenantProfileServiceException exception = new TenantProfileServiceException(); exception.setMessage("Error updating gateway-profile, reason: " + ex.getMessage()); - return false; + exception.initCause(ex); + throw exception; } } @@ -138,6 +141,7 @@ public Gateway getGateway(AuthzToken authzToken, String airavataInternalGatewayI logger.error("Error getting gateway-profile, reason: " + ex.getMessage(), ex); TenantProfileServiceException exception = new TenantProfileServiceException(); exception.setMessage("Error getting gateway-profile, reason: " + ex.getMessage()); + exception.initCause(ex); throw exception; } } @@ -162,6 +166,7 @@ public boolean deleteGateway(AuthzToken authzToken, String airavataInternalGatew logger.error("Error deleting gateway-profile, reason: " + ex.getMessage(), ex); TenantProfileServiceException exception = new TenantProfileServiceException(); exception.setMessage("Error deleting gateway-profile, reason: " + ex.getMessage()); + exception.initCause(ex); throw exception; } } @@ -173,6 +178,7 @@ public List getAllGateways(AuthzToken authzToken) throws TenantProfileS logger.error("Error getting all gateway-profiles, reason: " + ex.getMessage(), ex); TenantProfileServiceException exception = new TenantProfileServiceException(); exception.setMessage("Error getting all gateway-profiles, reason: " + ex.getMessage()); + exception.initCause(ex); throw exception; } } @@ -185,6 +191,7 @@ public boolean isGatewayExist(AuthzToken authzToken, String gatewayId) throws Te logger.error("Error checking if gateway-profile exists, reason: " + ex.getMessage(), ex); TenantProfileServiceException exception = new TenantProfileServiceException(); exception.setMessage("Error checking if gateway-profile exists, reason: " + ex.getMessage()); + exception.initCause(ex); throw exception; } } @@ -197,6 +204,7 @@ public List getAllGatewaysForUser(AuthzToken authzToken, String request logger.error("Error getting user's gateway-profiles, reason: " + ex.getMessage(), ex); TenantProfileServiceException exception = new TenantProfileServiceException(); exception.setMessage("Error getting user's gateway-profiles, reason: " + ex.getMessage()); + exception.initCause(ex); throw exception; } } @@ -210,6 +218,7 @@ private boolean checkDuplicateGateway(Gateway gateway) throws TenantProfileServi logger.error("Error checking if duplicate gateway-profile exists, reason: " + ex.getMessage(), ex); TenantProfileServiceException exception = new TenantProfileServiceException(); exception.setMessage("Error checking if duplicate gateway-profiles exists, reason: " + ex.getMessage()); + exception.initCause(ex); throw exception; } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/UserProfileService.java b/airavata-api/src/main/java/org/apache/airavata/service/UserProfileService.java index 26df5f561c..74aeb6c5d3 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/UserProfileService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/UserProfileService.java @@ -53,6 +53,7 @@ private UserProfileServiceException convertException(Throwable e, String msg) { logger.error(msg, e); UserProfileServiceException exception = new UserProfileServiceException(); exception.setMessage(msg + ". More info : " + e.getMessage()); + exception.initCause(e); return exception; } @@ -96,6 +97,7 @@ public String initializeUserProfile(AuthzToken authzToken) throws UserProfileSer logger.error("Error while initializing user profile", e); UserProfileServiceException exception = new UserProfileServiceException(); exception.setMessage("Error while initializing user profile. More info : " + e.getMessage()); + exception.initCause(e); throw exception; } } @@ -120,6 +122,7 @@ public String addUserProfile(AuthzToken authzToken, UserProfile userProfile) thr logger.error("Error while creating user profile", e); UserProfileServiceException exception = new UserProfileServiceException(); exception.setMessage("Error while creating user profile. More info : " + e.getMessage()); + exception.initCause(e); throw exception; } } @@ -142,6 +145,7 @@ public boolean updateUserProfile(AuthzToken authzToken, UserProfile userProfile) logger.error("Error while Updating user profile", e); UserProfileServiceException exception = new UserProfileServiceException(); exception.setMessage("Error while Updating user profile. More info : " + e.getMessage()); + exception.initCause(e); throw exception; } } @@ -173,6 +177,7 @@ public UserProfile getUserProfileById(AuthzToken authzToken, String userId, Stri logger.error("Error retrieving user profile by ID", e); UserProfileServiceException exception = new UserProfileServiceException(); exception.setMessage("Error retrieving user profile by ID. More info : " + e.getMessage()); + exception.initCause(e); throw exception; } } @@ -196,6 +201,7 @@ public boolean deleteUserProfile(AuthzToken authzToken, String userId, String ga logger.error("Error while deleting user profile", e); UserProfileServiceException exception = new UserProfileServiceException(); exception.setMessage("Error while deleting user profile. More info : " + e.getMessage()); + exception.initCause(e); throw exception; } } @@ -211,6 +217,7 @@ public List getAllUserProfilesInGateway(AuthzToken authzToken, Stri logger.error("Error while retrieving user profile List", e); UserProfileServiceException exception = new UserProfileServiceException(); exception.setMessage("Error while retrieving user profile List. More info : " + e.getMessage()); + exception.initCause(e); throw exception; } } @@ -224,6 +231,7 @@ public boolean doesUserExist(AuthzToken authzToken, String userId, String gatewa logger.error("Error while finding user profile", e); UserProfileServiceException exception = new UserProfileServiceException(); exception.setMessage("Error while finding user profile. More info : " + e.getMessage()); + exception.initCause(e); throw exception; } } @@ -237,6 +245,7 @@ private IamAdminServices.Client getIamAdminServicesClient() throws UserProfileSe logger.error("Failed to create IAM Admin Services client", e); UserProfileServiceException ex = new UserProfileServiceException("Failed to create IAM Admin Services client"); + ex.initCause(e); throw ex; } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/security/SecurityManagerFactory.java b/airavata-api/src/main/java/org/apache/airavata/service/security/SecurityManagerFactory.java index 4d0e46dc06..b0ce1b8479 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/security/SecurityManagerFactory.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/security/SecurityManagerFactory.java @@ -39,15 +39,15 @@ public static AiravataSecurityManager getSecurityManager() throws AiravataSecuri } catch (ClassNotFoundException e) { String error = "Security Manager class could not be found."; logger.error(e.getMessage(), e); - throw new AiravataSecurityException(error); + throw new AiravataSecurityException(error, e); } catch (ApplicationSettingsException e) { String error = "Error in reading the configuration related to Security Manager class."; logger.error(e.getMessage(), e); - throw new AiravataSecurityException(error); + throw new AiravataSecurityException(error, e); } catch (InstantiationException | IllegalAccessException e) { String error = "Error in instantiating the Security Manager class."; logger.error(e.getMessage(), e); - throw new AiravataSecurityException(error); + throw new AiravataSecurityException(error, e); } } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/security/authzcache/AuthzCacheManagerFactory.java b/airavata-api/src/main/java/org/apache/airavata/service/security/authzcache/AuthzCacheManagerFactory.java index d14ce5b02c..4404d6fb9a 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/security/authzcache/AuthzCacheManagerFactory.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/security/authzcache/AuthzCacheManagerFactory.java @@ -39,19 +39,19 @@ public static AuthzCacheManager getAuthzCacheManager() throws AiravataSecurityEx } catch (ClassNotFoundException e) { String error = "Authorization Cache Manager class could not be found."; logger.error(e.getMessage(), e); - throw new AiravataSecurityException(error); + throw new AiravataSecurityException(error, e); } catch (ApplicationSettingsException e) { String error = "Error in reading the configuration related to Authorization Cache Manager class."; logger.error(e.getMessage(), e); - throw new AiravataSecurityException(error); + throw new AiravataSecurityException(error, e); } catch (InstantiationException e) { String error = "Error in instantiating the Authorization Cache Manager class."; logger.error(e.getMessage(), e); - throw new AiravataSecurityException(error); + throw new AiravataSecurityException(error, e); } catch (IllegalAccessException e) { String error = "Error in instantiating the Authorization Cache Manager class."; logger.error(e.getMessage(), e); - throw new AiravataSecurityException(error); + throw new AiravataSecurityException(error, e); } } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/security/authzcache/DefaultAuthzCacheManager.java b/airavata-api/src/main/java/org/apache/airavata/service/security/authzcache/DefaultAuthzCacheManager.java index 1a2ea0ff53..969f160165 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/security/authzcache/DefaultAuthzCacheManager.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/security/authzcache/DefaultAuthzCacheManager.java @@ -59,7 +59,7 @@ public void addToAuthzCache(AuthzCacheIndex authzCacheIndex, AuthzCacheEntry aut AuthzCache.getInstance().put(authzCacheIndex, authzCacheEntry); } catch (ApplicationSettingsException e) { logger.error(e.getMessage(), e); - throw new AiravataSecurityException("Error in obtaining the authorization cache instance."); + throw new AiravataSecurityException("Error in obtaining the authorization cache instance.", e); } } @@ -69,7 +69,7 @@ public boolean isAuthzDecisionCached(AuthzCacheIndex authzCacheIndex) throws Air return AuthzCache.getInstance().containsKey(authzCacheIndex); } catch (ApplicationSettingsException e) { logger.error(e.getMessage(), e); - throw new AiravataSecurityException("Error in obtaining the authorization cache instance."); + throw new AiravataSecurityException("Error in obtaining the authorization cache instance.", e); } } @@ -79,7 +79,7 @@ public AuthzCacheEntry getAuthzCacheEntry(AuthzCacheIndex authzCacheIndex) throw return AuthzCache.getInstance().get(authzCacheIndex); } catch (ApplicationSettingsException e) { logger.error(e.getMessage(), e); - throw new AiravataSecurityException("Error in obtaining the authorization cache instance."); + throw new AiravataSecurityException("Error in obtaining the authorization cache instance.", e); } } @@ -89,7 +89,7 @@ public void removeAuthzCacheEntry(AuthzCacheIndex authzCacheIndex) throws Airava AuthzCache.getInstance().remove(authzCacheIndex); } catch (ApplicationSettingsException e) { logger.error(e.getMessage(), e); - throw new AiravataSecurityException("Error in obtaining the authorization cache instance."); + throw new AiravataSecurityException("Error in obtaining the authorization cache instance.", e); } } @@ -99,7 +99,7 @@ public void clearCache() throws AiravataSecurityException { AuthzCache.getInstance().clear(); } catch (ApplicationSettingsException e) { logger.error(e.getMessage(), e); - throw new AiravataSecurityException("Error in obtaining the authorization cache instance."); + throw new AiravataSecurityException("Error in obtaining the authorization cache instance.", e); } } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/security/interceptor/SecurityInterceptor.java b/airavata-api/src/main/java/org/apache/airavata/service/security/interceptor/SecurityInterceptor.java index eb328c5cf1..74d735c5d3 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/security/interceptor/SecurityInterceptor.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/security/interceptor/SecurityInterceptor.java @@ -74,10 +74,14 @@ private void authorize(AuthzToken authzToken, Map metaData) thro } } catch (AiravataSecurityException e) { logger.error(e.getMessage(), e); - throw new AuthorizationException("Error in authenticating or authorizing user."); + AuthorizationException exception = new AuthorizationException("Error in authenticating or authorizing user."); + exception.initCause(e); + throw exception; } catch (ApplicationSettingsException e) { logger.error(e.getMessage(), e); - throw new AuthorizationException("Internal error in authenticating or authorizing user."); + AuthorizationException exception = new AuthorizationException("Internal error in authenticating or authorizing user."); + exception.initCause(e); + throw exception; } } } From 0f889f3b6ab4f52eeee69dde2f8cb9beb411d820 Mon Sep 17 00:00:00 2001 From: yasithdev Date: Tue, 25 Nov 2025 23:10:54 -0600 Subject: [PATCH 21/26] partially update the services with right exception types --- .../server/handler/AiravataServerHandler.java | 4 +- .../server/CredentialStoreServerHandler.java | 1 - .../server/OrchestratorServerHandler.java | 19 +- .../orchestrator/util/OrchestratorUtils.java | 99 -- .../airavata/service/AiravataService.java | 1021 +++++++++-------- .../service/CredentialStoreService.java | 131 +-- .../airavata/service/GroupManagerService.java | 22 +- .../airavata/service/IamAdminService.java | 18 +- .../service/OrchestratorRegistryService.java | 4 + .../airavata/service/OrchestratorService.java | 259 +++-- .../airavata/service/RegistryService.java | 73 +- 11 files changed, 827 insertions(+), 824 deletions(-) delete mode 100644 airavata-api/src/main/java/org/apache/airavata/orchestrator/util/OrchestratorUtils.java diff --git a/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java index cdea1d8f48..40347a9e8d 100644 --- a/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java @@ -862,7 +862,7 @@ public String cloneExperiment( throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException, ProjectNotFoundException { // getExperiment will apply sharing permissions - ExperimentModel existingExperiment = this.getExperiment(authzToken, existingExperimentID); + ExperimentModel existingExperiment = airavataService.getExperiment(authzToken, existingExperimentID); return airavataService.cloneExperimentInternal( authzToken, existingExperimentID, @@ -878,7 +878,7 @@ public String cloneExperimentByAdmin( throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException, ProjectNotFoundException { // get existing experiment by bypassing normal sharing permissions for the admin user - ExperimentModel existingExperiment = this.getExperimentByAdmin(authzToken, existingExperimentID); + ExperimentModel existingExperiment = airavataService.getExperimentByAdmin(authzToken, existingExperimentID); return airavataService.cloneExperimentInternal( authzToken, existingExperimentID, diff --git a/airavata-api/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java index 7f2a11bfc3..72b732808c 100644 --- a/airavata-api/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java @@ -25,7 +25,6 @@ import java.util.Map; import org.apache.airavata.common.exception.ApplicationSettingsException; import org.apache.airavata.credential.store.cpi.credential_store_cpiConstants; -import org.apache.airavata.credential.store.store.CredentialStoreException; import org.apache.airavata.model.credential.store.*; import org.apache.thrift.TException; import org.slf4j.Logger; diff --git a/airavata-api/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java index acabc1e2e7..65b5d16e18 100644 --- a/airavata-api/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java @@ -20,12 +20,11 @@ package org.apache.airavata.orchestrator.server; import java.util.*; -import org.apache.airavata.common.exception.AiravataException; -import org.apache.airavata.common.exception.ApplicationSettingsException; import org.apache.airavata.model.error.LaunchValidationException; import org.apache.airavata.model.process.ProcessModel; import org.apache.airavata.orchestrator.core.exception.OrchestratorException; import org.apache.airavata.orchestrator.cpi.OrchestratorService; +import org.apache.airavata.registry.core.RegistryException; import org.apache.thrift.TException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -59,7 +58,7 @@ public OrchestratorServerHandler() throws OrchestratorException, TException { * * @param experimentId */ - public boolean launchExperiment(String experimentId, String gatewayId) throws TException { + public boolean launchExperiment(String experimentId, String gatewayId) throws OrchestratorException { return orchestratorService.launchExperimentWithErrorHandling( experimentId, gatewayId, org.apache.airavata.orchestrator.util.OrchestratorServerThreadPoolExecutor.getCachedThreadPool()); } @@ -71,15 +70,17 @@ public boolean launchExperiment(String experimentId, String gatewayId) throws TE * * @param experimentId * @return - * @throws TException + * @throws RegistryException + * @throws LaunchValidationException + * @throws OrchestratorException */ - public boolean validateExperiment(String experimentId) throws TException, LaunchValidationException { + public boolean validateExperiment(String experimentId) throws RegistryException, LaunchValidationException, OrchestratorException { return orchestratorService.validateExperiment(experimentId); } @Override public boolean validateProcess(String experimentId, List processes) - throws LaunchValidationException, TException { + throws LaunchValidationException, RegistryException, OrchestratorException { return orchestratorService.validateProcess(experimentId, processes); } @@ -91,18 +92,18 @@ public boolean validateProcess(String experimentId, List processes * @return * @throws TException */ - public boolean terminateExperiment(String experimentId, String gatewayId) throws TException { + public boolean terminateExperiment(String experimentId, String gatewayId) throws RegistryException, OrchestratorException, AppCatalogException { log.info(experimentId, "Experiment: {} is cancelling !!!!!", experimentId); return orchestratorService.terminateExperiment(experimentId, gatewayId); } public void fetchIntermediateOutputs(String experimentId, String gatewayId, List outputNames) - throws TException { + throws RegistryException, OrchestratorException, AppCatalogException { orchestratorService.fetchIntermediateOutputs(experimentId, gatewayId, outputNames); } @Override - public boolean launchProcess(String processId, String airavataCredStoreToken, String gatewayId) throws TException { + public boolean launchProcess(String processId, String airavataCredStoreToken, String gatewayId) throws RegistryException, OrchestratorException, AppCatalogException { return orchestratorService.launchProcess(processId, airavataCredStoreToken, gatewayId); } } diff --git a/airavata-api/src/main/java/org/apache/airavata/orchestrator/util/OrchestratorUtils.java b/airavata-api/src/main/java/org/apache/airavata/orchestrator/util/OrchestratorUtils.java deleted file mode 100644 index 25c5dcc932..0000000000 --- a/airavata-api/src/main/java/org/apache/airavata/orchestrator/util/OrchestratorUtils.java +++ /dev/null @@ -1,99 +0,0 @@ -/** -* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you under the Apache License, Version 2.0 (the -* "License"); you may not use this file except in compliance -* with the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, -* software distributed under the License is distributed on an -* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -* KIND, either express or implied. See the License for the -* specific language governing permissions and limitations -* under the License. -*/ -package org.apache.airavata.orchestrator.util; - -import org.apache.airavata.common.exception.AiravataException; -import org.apache.airavata.common.exception.ApplicationSettingsException; -import org.apache.airavata.common.utils.AiravataUtils; -import org.apache.airavata.common.utils.ServerSettings; -import org.apache.airavata.common.utils.ThriftUtils; -import org.apache.airavata.messaging.core.MessageContext; -import org.apache.airavata.messaging.core.Publisher; -import org.apache.airavata.model.messaging.event.ExperimentStatusChangeEvent; -import org.apache.airavata.model.messaging.event.MessageType; -import org.apache.airavata.model.process.ProcessModel; -import org.apache.airavata.model.status.ExperimentStatus; -import org.apache.airavata.registry.api.RegistryService; -import org.apache.airavata.registry.api.client.RegistryServiceClientFactory; -import org.apache.airavata.registry.api.exception.RegistryServiceException; -import org.apache.thrift.TException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class OrchestratorUtils { - private static final Logger log = LoggerFactory.getLogger(OrchestratorUtils.class); - - public static void updateAndPublishExperimentStatus( - String experimentId, ExperimentStatus status, Publisher publisher, String gatewayId) throws TException { - RegistryService.Client registryClient = null; - try { - registryClient = getRegistryServiceClient(); - registryClient.updateExperimentStatus(status, experimentId); - ExperimentStatusChangeEvent event = - new ExperimentStatusChangeEvent(status.getState(), experimentId, gatewayId); - String messageId = AiravataUtils.getId("EXPERIMENT"); - MessageContext messageContext = new MessageContext(event, MessageType.EXPERIMENT, messageId, gatewayId); - messageContext.setUpdatedTime(AiravataUtils.getCurrentTimestamp()); - publisher.publish(messageContext); - } catch (AiravataException e) { - log.error( - "expId : " + experimentId + " Error while publishing experiment status to " + status.toString(), e); - } finally { - if (registryClient != null) { - ThriftUtils.close(registryClient); - } - } - } - - public static ExperimentStatus getExperimentStatus(String experimentId) - throws TException, ApplicationSettingsException { - RegistryService.Client registryClient = null; - try { - registryClient = getRegistryServiceClient(); - return registryClient.getExperimentStatus(experimentId); - } finally { - if (registryClient != null) { - ThriftUtils.close(registryClient); - } - } - } - - public static ProcessModel getProcess(String processId) throws TException, ApplicationSettingsException { - RegistryService.Client registryClient = null; - try { - registryClient = getRegistryServiceClient(); - return registryClient.getProcess(processId); - } finally { - if (registryClient != null) { - ThriftUtils.close(registryClient); - } - } - } - - private static RegistryService.Client getRegistryServiceClient() throws ApplicationSettingsException { - final int serverPort = Integer.parseInt(ServerSettings.getRegistryServerPort()); - final String serverHost = ServerSettings.getRegistryServerHost(); - try { - return RegistryServiceClientFactory.createRegistryClient(serverHost, serverPort); - } catch (RegistryServiceException e) { - throw new RuntimeException("Unable to create registry client...", e); - } - } -} diff --git a/airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java b/airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java index ab13bc4216..1608175fba 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java @@ -106,7 +106,6 @@ import org.apache.airavata.model.workspace.Gateway; import org.apache.airavata.model.workspace.Notification; import org.apache.airavata.model.workspace.Project; -import org.apache.airavata.registry.api.RegistryService; import org.apache.airavata.model.error.AiravataClientException; import org.apache.airavata.model.error.AiravataSystemException; import org.apache.airavata.model.error.AuthorizationException; @@ -115,6 +114,7 @@ import org.apache.airavata.model.error.ExperimentNotFoundException; import org.apache.airavata.model.error.AiravataErrorType; import org.apache.airavata.model.commons.airavata_commonsConstants; +import org.apache.airavata.registry.api.exception.RegistryServiceException; import org.apache.airavata.registry.cpi.AppCatalogException; import org.apache.airavata.registry.cpi.RegistryException; import org.apache.airavata.service.security.GatewayGroupsInitializer; @@ -134,7 +134,7 @@ public class AiravataService { private static final Logger logger = LoggerFactory.getLogger(AiravataService.class); - private record StorageInfoContext(String loginUserName, String credentialToken, org.apache.airavata.agents.api.AgentAdaptor adaptor) {} + private record StorageInfoContext(String loginUserName, String credentialToken, AgentAdaptor adaptor) {} private boolean validateString(String name) { boolean valid = true; @@ -145,7 +145,7 @@ private boolean validateString(String name) { } private AiravataClientException clientException(AiravataErrorType errorType, String parameter) { - AiravataClientException exception = new AiravataClientException(); + var exception = new AiravataClientException(); exception.setAiravataErrorType(errorType); exception.setParameter(parameter); return exception; @@ -162,7 +162,7 @@ private boolean safeIsUserResourceProfileExists(AuthzToken authzToken, String us private boolean isGatewayResourceProfileExists(String gatewayId) { try { - GatewayResourceProfile profile = getGatewayResourceProfile(gatewayId); + var profile = getGatewayResourceProfile(gatewayId); return profile != null; } catch (Throwable e) { logger.error("Error while checking if gateway resource profile exists", e); @@ -176,43 +176,43 @@ private static RuntimeException sneakyThrow(Throwable e) t } private RuntimeException convertException(Throwable e, String msg) { - if (e instanceof org.apache.airavata.model.error.InvalidRequestException || - e instanceof org.apache.airavata.model.error.AiravataClientException || - e instanceof org.apache.airavata.model.error.AiravataSystemException || - e instanceof org.apache.airavata.model.error.AuthorizationException || - e instanceof org.apache.airavata.model.error.ExperimentNotFoundException || - e instanceof org.apache.airavata.model.error.ProjectNotFoundException) { + if (e instanceof InvalidRequestException || + e instanceof AiravataClientException || + e instanceof AiravataSystemException || + e instanceof AuthorizationException || + e instanceof ExperimentNotFoundException || + e instanceof ProjectNotFoundException) { throw sneakyThrow(e); } if (e instanceof RegistryException || e instanceof AppCatalogException || - e instanceof org.apache.airavata.credential.store.store.CredentialStoreException || + e instanceof CredentialStoreException || e instanceof org.apache.airavata.sharing.registry.models.SharingRegistryException) { logger.error(msg, e); - org.apache.airavata.model.error.AiravataSystemException exception = new org.apache.airavata.model.error.AiravataSystemException(); - exception.setAiravataErrorType(org.apache.airavata.model.error.AiravataErrorType.INTERNAL_ERROR); + var exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + ". More info : " + e.getMessage()); exception.initCause(e); throw sneakyThrow(exception); } logger.error(msg, e); - org.apache.airavata.model.error.AiravataSystemException exception = new org.apache.airavata.model.error.AiravataSystemException(); - exception.setAiravataErrorType(org.apache.airavata.model.error.AiravataErrorType.INTERNAL_ERROR); + var exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); exception.setMessage(msg + ". More info : " + e.getMessage()); exception.initCause(e); throw sneakyThrow(exception); } - private org.apache.airavata.service.RegistryService registryService = - new org.apache.airavata.service.RegistryService(); + private RegistryService registryService = + new RegistryService(); - private org.apache.airavata.service.SharingRegistryService sharingRegistryService = - new org.apache.airavata.service.SharingRegistryService(); + private SharingRegistryService sharingRegistryService = + new SharingRegistryService(); - private org.apache.airavata.service.CredentialStoreService credentialStoreService; + private CredentialStoreService credentialStoreService; public AiravataService() { try { - credentialStoreService = new org.apache.airavata.service.CredentialStoreService(); + credentialStoreService = new CredentialStoreService(); } catch (Exception e) { logger.error("Failed to initialize CredentialStoreService", e); throw new RuntimeException("Failed to initialize CredentialStoreService", e); @@ -232,13 +232,13 @@ public void init() { private void postInitDefaultGateway() { try { - GatewayResourceProfile gatewayResourceProfile = getGatewayResourceProfile(ServerSettings.getDefaultUserGateway()); + var gatewayResourceProfile = getGatewayResourceProfile(ServerSettings.getDefaultUserGateway()); if (gatewayResourceProfile != null && gatewayResourceProfile.getIdentityServerPwdCredToken() == null) { logger.debug("Starting to add the password credential for default gateway : " + ServerSettings.getDefaultUserGateway()); - PasswordCredential passwordCredential = new PasswordCredential(); + var passwordCredential = new PasswordCredential(); passwordCredential.setPortalUserName(ServerSettings.getDefaultUser()); passwordCredential.setGatewayId(ServerSettings.getDefaultUserGateway()); passwordCredential.setLoginUserName(ServerSettings.getDefaultUser()); @@ -272,20 +272,20 @@ private void postInitDefaultGateway() { private void initSharingRegistry() throws Exception { try { if (!isDomainExists(ServerSettings.getDefaultUserGateway())) { - Domain domain = new Domain(); + var domain = new Domain(); domain.setDomainId(ServerSettings.getDefaultUserGateway()); domain.setName(ServerSettings.getDefaultUserGateway()); domain.setDescription("Domain entry for " + domain.getName()); createDomain(domain); - User user = new User(); + var user = new User(); user.setDomainId(domain.getDomainId()); user.setUserId(ServerSettings.getDefaultUser() + "@" + ServerSettings.getDefaultUserGateway()); user.setUserName(ServerSettings.getDefaultUser()); createUser(user); // Creating Entity Types for each domain - EntityType entityType = new EntityType(); + var entityType = new EntityType(); entityType.setEntityTypeId(domain.getDomainId() + ":PROJECT"); entityType.setDomainId(domain.getDomainId()); entityType.setName("PROJECT"); @@ -328,7 +328,7 @@ private void initSharingRegistry() throws Exception { createEntityType(entityType); // Creating Permission Types for each domain - PermissionType permissionType = new PermissionType(); + var permissionType = new PermissionType(); permissionType.setPermissionTypeId(domain.getDomainId() + ":READ"); permissionType.setDomainId(domain.getDomainId()); permissionType.setName("READ"); @@ -372,7 +372,7 @@ public boolean updateGateway(String gatewayId, Gateway updatedGateway) { public Gateway getGateway(String gatewayId) { try { - Gateway result = registryService.getGateway(gatewayId); + var result = registryService.getGateway(gatewayId); logger.debug("Airavata found the gateway with " + gatewayId); return result; } catch (Throwable e) { @@ -450,7 +450,7 @@ public String registerDataProduct(DataProductModel dataProductModel) { try { return registryService.registerDataProduct(dataProductModel); } catch (Throwable e) { - String msg = "Error in registering the data resource" + dataProductModel.getProductName() + "."; + var msg = "Error in registering the data resource" + dataProductModel.getProductName() + "."; logger.error(msg, e); throw convertException(e, msg); } @@ -468,7 +468,7 @@ public String registerReplicaLocation(DataReplicaLocationModel replicaLocationMo try { return registryService.registerReplicaLocation(replicaLocationModel); } catch (Throwable e) { - String msg = "Error in retreiving the replica " + replicaLocationModel.getReplicaName() + "."; + var msg = "Error in retreiving the replica " + replicaLocationModel.getReplicaName() + "."; logger.error(msg, e); throw convertException(e, msg); } @@ -478,7 +478,7 @@ public DataProductModel getParentDataProduct(String productUri) { try { return registryService.getParentDataProduct(productUri); } catch (Throwable e) { - String msg = "Error in retreiving the parent data product for " + productUri + "."; + var msg = "Error in retreiving the parent data product for " + productUri + "."; logger.error(msg, e); throw convertException(e, msg); } @@ -488,7 +488,7 @@ public List getChildDataProducts(String productUri) { try { return registryService.getChildDataProducts(productUri); } catch (Throwable e) { - String msg = "Error in retreiving the child products for " + productUri + "."; + var msg = "Error in retreiving the child products for " + productUri + "."; logger.error(msg, e); throw convertException(e, msg); } @@ -541,13 +541,13 @@ public List searchProjectsWithSharing( String userName, Map filters, int limit, - int offset) throws TException { + int offset) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - List accessibleProjIds = new ArrayList<>(); + var accessibleProjIds = new ArrayList(); List result; if (ServerSettings.isEnableSharing()) { - List sharingFilters = new ArrayList<>(); - SearchCriteria searchCriteria = new SearchCriteria(); + var sharingFilters = new ArrayList(); + var searchCriteria = new SearchCriteria(); searchCriteria.setSearchField(EntitySearchField.ENTITY_TYPE_ID); searchCriteria.setSearchCondition(SearchCondition.EQUAL); searchCriteria.setValue(gatewayId + ":PROJECT"); @@ -581,31 +581,36 @@ public List searchProjects( List accessibleProjectIds, Map filters, int limit, - int offset) - throws RegistryException { + int offset) throws RegistryServiceException { return registryService.searchProjects(gatewayId, userName, accessibleProjectIds, filters, limit, offset); } - public List getUserExperiments(String gatewayId, String userName, int limit, int offset) - throws RegistryException { - return registryService.getUserExperiments(gatewayId, userName, limit, offset); + public List getUserExperiments(String gatewayId, String userName, int limit, int offset) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + try { + return registryService.getUserExperiments(gatewayId, userName, limit, offset); + } catch (Throwable e) { + throw convertException(e, "Error occurred while getting user experiments"); + } } - public List getExperimentsInProject(String gatewayId, String projectId, int limit, int offset) - throws RegistryException { - return registryService.getExperimentsInProject(gatewayId, projectId, limit, offset); + public List getExperimentsInProject(String gatewayId, String projectId, int limit, int offset) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + try { + return registryService.getExperimentsInProject(gatewayId, projectId, limit, offset); + } catch (Throwable e) { + throw convertException(e, "Error occurred while getting experiments in project"); + } } public List getExperimentsInProject( AuthzToken authzToken, String projectId, int limit, int offset) - throws TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - Project project = getProject(projectId); - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + var project = getProject(projectId); + var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); if (ServerSettings.isEnableSharing() && (!authzToken.getClaimsMap().get(Constants.USER_NAME).equals(project.getOwner()) || !authzToken.getClaimsMap().get(Constants.GATEWAY_ID).equals(project.getGatewayId()))) { - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); if (!userHasAccess( gatewayId, userId + "@" + gatewayId, projectId, gatewayId + ":READ")) { throw new AuthorizationException("User does not have permission to access this resource"); @@ -627,7 +632,7 @@ public ExperimentStatistics getExperimentStatistics( List accessibleExpIds, int limit, int offset) - throws TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.getExperimentStatistics( gatewayId, @@ -662,13 +667,13 @@ public String createExperiment(String gatewayId, ExperimentModel experiment) { public ExperimentModel getExperiment(AuthzToken authzToken, String airavataExperimentId) throws AuthorizationException { try { - ExperimentModel existingExperiment = getExperiment(airavataExperimentId); + var existingExperiment = getExperiment(airavataExperimentId); if (authzToken.getClaimsMap().get(Constants.USER_NAME).equals(existingExperiment.getUserName()) && authzToken.getClaimsMap().get(Constants.GATEWAY_ID).equals(existingExperiment.getGatewayId())) { return existingExperiment; } else if (ServerSettings.isEnableSharing()) { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); if (!userHasAccess( gatewayId, userId + "@" + gatewayId, airavataExperimentId, gatewayId + ":READ")) { throw new AuthorizationException("User does not have permission to access this resource"); @@ -686,8 +691,8 @@ public ExperimentModel getExperiment(AuthzToken authzToken, String airavataExper public ExperimentModel getExperimentByAdmin(AuthzToken authzToken, String airavataExperimentId) throws AuthorizationException { try { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - ExperimentModel existingExperiment = getExperiment(airavataExperimentId); + var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + var existingExperiment = getExperiment(airavataExperimentId); if (gatewayId.equals(existingExperiment.getGatewayId())) { return existingExperiment; } else { @@ -702,12 +707,12 @@ public ExperimentModel getExperimentByAdmin(AuthzToken authzToken, String airava public void updateExperiment(AuthzToken authzToken, String airavataExperimentId, ExperimentModel experiment) throws AuthorizationException { try { - ExperimentModel existingExperiment = getExperiment(airavataExperimentId); - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + var existingExperiment = getExperiment(airavataExperimentId); + var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); if (ServerSettings.isEnableSharing() && (!authzToken.getClaimsMap().get(Constants.USER_NAME).equals(existingExperiment.getUserName()) || !authzToken.getClaimsMap().get(Constants.GATEWAY_ID).equals(existingExperiment.getGatewayId()))) { - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); if (!userHasAccess( gatewayId, userId + "@" + gatewayId, airavataExperimentId, gatewayId + ":WRITE")) { throw new AuthorizationException("User does not have permission to access this resource"); @@ -717,7 +722,7 @@ public void updateExperiment(AuthzToken authzToken, String airavataExperimentId, try { // Update name, description and parent on Entity // TODO: update the experiment via a DB event - Entity entity = getEntity(gatewayId, airavataExperimentId); + var entity = getEntity(gatewayId, airavataExperimentId); entity.setName(experiment.getExperimentName()); entity.setDescription(experiment.getDescription()); entity.setParentEntityId(experiment.getProjectId()); @@ -766,7 +771,7 @@ public String cloneExperimentInternal( } if (newExperimentProjectId != null) { // getProject will apply sharing permissions - Project project = getProjectWithAuth(authzToken, newExperimentProjectId); + var project = getProjectWithAuth(authzToken, newExperimentProjectId); if (project == null) { logger.error( "Error while cloning experiment {}, project {} doesn't exist.", @@ -779,8 +784,8 @@ public String cloneExperimentInternal( } // 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); + var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); if (!userHasAccess( gatewayId, userId + "@" + gatewayId, existingExperiment.getProjectId(), gatewayId + ":WRITE")) { logger.error( @@ -793,7 +798,7 @@ public String cloneExperimentInternal( existingExperiment.setCreationTime(AiravataUtils.getCurrentTimestamp().getTime()); if (existingExperiment.getExecutionId() != null) { try { - List applicationOutputs = getApplicationOutputs(existingExperiment.getExecutionId()); + var applicationOutputs = getApplicationOutputs(existingExperiment.getExecutionId()); existingExperiment.setExperimentOutputs(applicationOutputs); } catch (Throwable e) { logger.warn("Error getting application outputs for experiment clone: " + e.getMessage()); @@ -812,13 +817,13 @@ public String cloneExperimentInternal( .getComputationalResourceScheduling() .getResourceHostId() != null) { - String compResourceId = existingExperiment + var compResourceId = existingExperiment .getUserConfigurationData() .getComputationalResourceScheduling() .getResourceHostId(); try { - ComputeResourceDescription computeResource = getComputeResource(compResourceId); + var computeResource = getComputeResource(compResourceId); if (!computeResource.isEnabled()) { existingExperiment.getUserConfigurationData().setComputationalResourceScheduling(null); } @@ -829,10 +834,10 @@ public String cloneExperimentInternal( logger.debug("Airavata cloned experiment with experiment id : " + existingExperimentID); existingExperiment.setUserName(userId); - String expId = createExperiment(gatewayId, existingExperiment); + var expId = createExperiment(gatewayId, existingExperiment); if (ServerSettings.isEnableSharing()) { try { - Entity entity = new Entity(); + var entity = new Entity(); entity.setEntityId(expId); final String domainId = existingExperiment.getGatewayId(); entity.setDomainId(domainId); @@ -865,8 +870,8 @@ public String cloneExperimentInternal( public void terminateExperiment(Publisher experimentPublisher, String airavataExperimentId, String gatewayId) throws ExperimentNotFoundException { try { - ExperimentModel existingExperiment = getExperiment(airavataExperimentId); - ExperimentStatus experimentLastStatus = getExperimentStatus(airavataExperimentId); + var existingExperiment = getExperiment(airavataExperimentId); + var experimentLastStatus = getExperimentStatus(airavataExperimentId); if (existingExperiment == null) { logger.error( airavataExperimentId, @@ -910,8 +915,7 @@ public List searchExperiments( List accessibleExpIds, Map filters, int limit, - int offset) - throws RegistryException { + int offset) throws RegistryServiceException { return registryService.searchExperiments(gatewayId, userName, accessibleExpIds, filters, limit, offset); } @@ -926,12 +930,12 @@ public List searchExperimentsWithSharing( Map filters, int limit, int offset) - throws TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - List accessibleExpIds = new ArrayList<>(); - Map filtersCopy = new HashMap<>(filters); - List sharingFilters = new ArrayList<>(); - SearchCriteria searchCriteria = new SearchCriteria(); + var accessibleExpIds = new ArrayList(); + var filtersCopy = new HashMap(filters); + var sharingFilters = new ArrayList(); + var searchCriteria = new SearchCriteria(); searchCriteria.setSearchField(EntitySearchField.ENTITY_TYPE_ID); searchCriteria.setSearchCondition(SearchCondition.EQUAL); searchCriteria.setValue(gatewayId + ":EXPERIMENT"); @@ -940,48 +944,48 @@ public List searchExperimentsWithSharing( // Apply as much of the filters in the sharing API as possible, // removing each filter that can be filtered via the sharing API if (filtersCopy.containsKey(ExperimentSearchFields.FROM_DATE)) { - String fromTime = filtersCopy.remove(ExperimentSearchFields.FROM_DATE); - SearchCriteria fromCreatedTimeCriteria = new SearchCriteria(); + var fromTime = filtersCopy.remove(ExperimentSearchFields.FROM_DATE); + var fromCreatedTimeCriteria = new SearchCriteria(); fromCreatedTimeCriteria.setSearchField(EntitySearchField.CREATED_TIME); fromCreatedTimeCriteria.setSearchCondition(SearchCondition.GTE); fromCreatedTimeCriteria.setValue(fromTime); sharingFilters.add(fromCreatedTimeCriteria); } if (filtersCopy.containsKey(ExperimentSearchFields.TO_DATE)) { - String toTime = filtersCopy.remove(ExperimentSearchFields.TO_DATE); - SearchCriteria toCreatedTimeCriteria = new SearchCriteria(); + var toTime = filtersCopy.remove(ExperimentSearchFields.TO_DATE); + var toCreatedTimeCriteria = new SearchCriteria(); toCreatedTimeCriteria.setSearchField(EntitySearchField.CREATED_TIME); toCreatedTimeCriteria.setSearchCondition(SearchCondition.LTE); toCreatedTimeCriteria.setValue(toTime); sharingFilters.add(toCreatedTimeCriteria); } if (filtersCopy.containsKey(ExperimentSearchFields.PROJECT_ID)) { - String projectId = filtersCopy.remove(ExperimentSearchFields.PROJECT_ID); - SearchCriteria projectParentEntityCriteria = new SearchCriteria(); + var projectId = filtersCopy.remove(ExperimentSearchFields.PROJECT_ID); + var projectParentEntityCriteria = new SearchCriteria(); projectParentEntityCriteria.setSearchField(EntitySearchField.PARRENT_ENTITY_ID); projectParentEntityCriteria.setSearchCondition(SearchCondition.EQUAL); projectParentEntityCriteria.setValue(projectId); sharingFilters.add(projectParentEntityCriteria); } if (filtersCopy.containsKey(ExperimentSearchFields.USER_NAME)) { - String username = filtersCopy.remove(ExperimentSearchFields.USER_NAME); - SearchCriteria usernameOwnerCriteria = new SearchCriteria(); + var username = filtersCopy.remove(ExperimentSearchFields.USER_NAME); + var usernameOwnerCriteria = new SearchCriteria(); usernameOwnerCriteria.setSearchField(EntitySearchField.OWNER_ID); usernameOwnerCriteria.setSearchCondition(SearchCondition.EQUAL); usernameOwnerCriteria.setValue(username + "@" + gatewayId); sharingFilters.add(usernameOwnerCriteria); } if (filtersCopy.containsKey(ExperimentSearchFields.EXPERIMENT_NAME)) { - String experimentName = filtersCopy.remove(ExperimentSearchFields.EXPERIMENT_NAME); - SearchCriteria experimentNameCriteria = new SearchCriteria(); + var experimentName = filtersCopy.remove(ExperimentSearchFields.EXPERIMENT_NAME); + var experimentNameCriteria = new SearchCriteria(); experimentNameCriteria.setSearchField(EntitySearchField.NAME); experimentNameCriteria.setSearchCondition(SearchCondition.LIKE); experimentNameCriteria.setValue(experimentName); sharingFilters.add(experimentNameCriteria); } if (filtersCopy.containsKey(ExperimentSearchFields.EXPERIMENT_DESC)) { - String experimentDescription = filtersCopy.remove(ExperimentSearchFields.EXPERIMENT_DESC); - SearchCriteria experimentDescriptionCriteria = new SearchCriteria(); + var experimentDescription = filtersCopy.remove(ExperimentSearchFields.EXPERIMENT_DESC); + var experimentDescriptionCriteria = new SearchCriteria(); experimentDescriptionCriteria.setSearchField(EntitySearchField.DESCRIPTION); experimentDescriptionCriteria.setSearchCondition(SearchCondition.LIKE); experimentDescriptionCriteria.setValue(experimentDescription); @@ -1130,7 +1134,7 @@ public Map getAllStorageResourceNames() { } public String registerGatewayResourceProfile(GatewayResourceProfile gatewayResourceProfile) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.registerGatewayResourceProfile(gatewayResourceProfile); } catch (Throwable e) { @@ -1257,12 +1261,12 @@ public String registerApplicationDeploymentWithSharing( try { String result = registerApplicationDeployment(gatewayId, applicationDeployment); if (ServerSettings.isEnableSharing()) { - Entity entity = new Entity(); + var entity = new Entity(); entity.setEntityId(result); final String domainId = gatewayId; entity.setDomainId(domainId); entity.setEntityTypeId(domainId + ":" + ResourceType.APPLICATION_DEPLOYMENT.name()); - String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); + var userName = authzToken.getClaimsMap().get(Constants.USER_NAME); entity.setOwnerId(userName + "@" + domainId); entity.setName(result); entity.setDescription(applicationDeployment.getAppDeploymentDescription()); @@ -1382,7 +1386,7 @@ public String registerApplicationInterface(String gatewayId, ApplicationInterfac public String cloneApplicationInterface(String existingAppInterfaceID, String newApplicationName, String gatewayId) throws AiravataSystemException { try { - ApplicationInterfaceDescription existingInterface = getApplicationInterface(existingAppInterfaceID); + var existingInterface = getApplicationInterface(existingAppInterfaceID); if (existingInterface == null) { logger.error( "Provided application interface does not exist.Please provide a valid application interface id..."); @@ -1391,7 +1395,7 @@ public String cloneApplicationInterface(String existingAppInterfaceID, String ne existingInterface.setApplicationName(newApplicationName); existingInterface.setApplicationInterfaceId(airavata_commonsConstants.DEFAULT_ID); - String interfaceId = registerApplicationInterface(gatewayId, existingInterface); + var interfaceId = registerApplicationInterface(gatewayId, existingInterface); logger.debug("Airavata cloned application interface : " + existingAppInterfaceID + " for gateway id : " + gatewayId); return interfaceId; @@ -1436,7 +1440,7 @@ public List getAllApplicationInterfaces(String } public List getApplicationInputs(String appInterfaceId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.getApplicationInputs(appInterfaceId); } catch (Throwable e) { @@ -1445,7 +1449,7 @@ public List getApplicationInputs(String appInterfaceId) } public String registerApplicationModule(String gatewayId, ApplicationModule applicationModule) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.registerApplicationModule(gatewayId, applicationModule); } catch (Throwable e) { @@ -1454,7 +1458,7 @@ public String registerApplicationModule(String gatewayId, ApplicationModule appl } public ApplicationModule getApplicationModule(String appModuleId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.getApplicationModule(appModuleId); } catch (Throwable e) { @@ -1463,7 +1467,7 @@ public ApplicationModule getApplicationModule(String appModuleId) } public boolean updateApplicationModule(String appModuleId, ApplicationModule applicationModule) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.updateApplicationModule(appModuleId, applicationModule); } catch (Throwable e) { @@ -1472,7 +1476,7 @@ public boolean updateApplicationModule(String appModuleId, ApplicationModule app } public List getAllAppModules(String gatewayId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.getAllAppModules(gatewayId); } catch (Throwable e) { @@ -1489,8 +1493,7 @@ public boolean deleteApplicationModule(String appModuleId) { } public List getAccessibleAppModules( - String gatewayId, List accessibleAppIds, List accessibleComputeResourceIds) - throws AppCatalogException { + String gatewayId, List accessibleAppIds, List accessibleComputeResourceIds) throws RegistryServiceException { return registryService.getAccessibleAppModules(gatewayId, accessibleAppIds, accessibleComputeResourceIds); } @@ -1498,41 +1501,45 @@ public List getAccessibleAppModules( * Get accessible app modules with sharing registry integration */ public List getAccessibleAppModulesWithSharing( - AuthzToken authzToken, String gatewayId) throws Exception { - String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); - List accessibleAppDeploymentIds = new ArrayList<>(); - if (ServerSettings.isEnableSharing()) { - List sharingFilters = new ArrayList<>(); - SearchCriteria entityTypeFilter = new SearchCriteria(); - entityTypeFilter.setSearchField(EntitySearchField.ENTITY_TYPE_ID); - entityTypeFilter.setSearchCondition(SearchCondition.EQUAL); - entityTypeFilter.setValue(gatewayId + ":" + ResourceType.APPLICATION_DEPLOYMENT.name()); - sharingFilters.add(entityTypeFilter); - SearchCriteria permissionTypeFilter = new SearchCriteria(); - permissionTypeFilter.setSearchField(EntitySearchField.PERMISSION_TYPE_ID); - permissionTypeFilter.setSearchCondition(SearchCondition.EQUAL); - permissionTypeFilter.setValue(gatewayId + ":" + ResourcePermissionType.READ); - sharingFilters.add(permissionTypeFilter); - sharingRegistryService - .searchEntities( - authzToken.getClaimsMap().get(Constants.GATEWAY_ID), - userName + "@" + gatewayId, - sharingFilters, - 0, - -1) - .forEach(a -> accessibleAppDeploymentIds.add(a.getEntityId())); - } - List accessibleComputeResourceIds = new ArrayList<>(); - List groupResourceProfileList = - getGroupResourceListWithSharing( authzToken, gatewayId); - for (GroupResourceProfile groupResourceProfile : groupResourceProfileList) { - List groupComputeResourcePreferenceList = - groupResourceProfile.getComputePreferences(); - for (GroupComputeResourcePreference groupComputeResourcePreference : groupComputeResourcePreferenceList) { - accessibleComputeResourceIds.add(groupComputeResourcePreference.getComputeResourceId()); + AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + try { + var userName = authzToken.getClaimsMap().get(Constants.USER_NAME); + var accessibleAppDeploymentIds = new ArrayList(); + if (ServerSettings.isEnableSharing()) { + List sharingFilters = new ArrayList<>(); + var entityTypeFilter = new SearchCriteria(); + entityTypeFilter.setSearchField(EntitySearchField.ENTITY_TYPE_ID); + entityTypeFilter.setSearchCondition(SearchCondition.EQUAL); + entityTypeFilter.setValue(gatewayId + ":" + ResourceType.APPLICATION_DEPLOYMENT.name()); + sharingFilters.add(entityTypeFilter); + var permissionTypeFilter = new SearchCriteria(); + permissionTypeFilter.setSearchField(EntitySearchField.PERMISSION_TYPE_ID); + permissionTypeFilter.setSearchCondition(SearchCondition.EQUAL); + permissionTypeFilter.setValue(gatewayId + ":" + ResourcePermissionType.READ); + sharingFilters.add(permissionTypeFilter); + sharingRegistryService + .searchEntities( + authzToken.getClaimsMap().get(Constants.GATEWAY_ID), + userName + "@" + gatewayId, + sharingFilters, + 0, + -1) + .forEach(a -> accessibleAppDeploymentIds.add(a.getEntityId())); + } + var accessibleComputeResourceIds = new ArrayList(); + List groupResourceProfileList = + getGroupResourceListWithSharing( authzToken, gatewayId); + for (GroupResourceProfile groupResourceProfile : groupResourceProfileList) { + List groupComputeResourcePreferenceList = + groupResourceProfile.getComputePreferences(); + for (GroupComputeResourcePreference groupComputeResourcePreference : groupComputeResourcePreferenceList) { + accessibleComputeResourceIds.add(groupComputeResourcePreference.getComputeResourceId()); + } } + return getAccessibleAppModules(gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); + } catch (Throwable e) { + throw convertException(e, "Error occurred while getting accessible app modules"); } - return getAccessibleAppModules(gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); } public Map getJobStatuses(String airavataExperimentId) { @@ -1605,7 +1612,7 @@ public boolean updateLocalSubmissionDetails(String jobSubmissionInterfaceId, LOC } public LOCALSubmission getLocalJobSubmission(String jobSubmissionId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.getLocalJobSubmission(jobSubmissionId); } catch (Throwable e) { @@ -1638,7 +1645,7 @@ public UnicoreJobSubmission getUnicoreJobSubmission(String jobSubmissionId) { } public boolean updateSSHJobSubmissionDetails(String jobSubmissionInterfaceId, SSHJobSubmission sshJobSubmission) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.updateSSHJobSubmissionDetails(jobSubmissionInterfaceId, sshJobSubmission); } catch (Throwable e) { @@ -1648,7 +1655,7 @@ public boolean updateSSHJobSubmissionDetails(String jobSubmissionInterfaceId, SS public boolean updateCloudJobSubmissionDetails( String jobSubmissionInterfaceId, CloudJobSubmission cloudJobSubmission) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.updateCloudJobSubmissionDetails(jobSubmissionInterfaceId, cloudJobSubmission); } catch (Throwable e) { @@ -1658,7 +1665,7 @@ public boolean updateCloudJobSubmissionDetails( public boolean updateUnicoreJobSubmissionDetails( String jobSubmissionInterfaceId, UnicoreJobSubmission unicoreJobSubmission) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.updateUnicoreJobSubmissionDetails(jobSubmissionInterfaceId, unicoreJobSubmission); } catch (Throwable e) { @@ -1667,7 +1674,7 @@ public boolean updateUnicoreJobSubmissionDetails( } public boolean deleteJobSubmissionInterface(String computeResourceId, String jobSubmissionInterfaceId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.deleteJobSubmissionInterface(computeResourceId, jobSubmissionInterfaceId); } catch (Throwable e) { @@ -1676,7 +1683,7 @@ public boolean deleteJobSubmissionInterface(String computeResourceId, String job } public String registerResourceJobManager(ResourceJobManager resourceJobManager) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.registerResourceJobManager(resourceJobManager); } catch (Throwable e) { @@ -1685,7 +1692,7 @@ public String registerResourceJobManager(ResourceJobManager resourceJobManager) } public boolean updateResourceJobManager(String resourceJobManagerId, ResourceJobManager updatedResourceJobManager) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.updateResourceJobManager(resourceJobManagerId, updatedResourceJobManager); } catch (Throwable e) { @@ -1694,7 +1701,7 @@ public boolean updateResourceJobManager(String resourceJobManagerId, ResourceJob } public ResourceJobManager getResourceJobManager(String resourceJobManagerId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.getResourceJobManager(resourceJobManagerId); } catch (Throwable e) { @@ -1703,7 +1710,7 @@ public ResourceJobManager getResourceJobManager(String resourceJobManagerId) } public boolean deleteResourceJobManager(String resourceJobManagerId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.deleteResourceJobManager(resourceJobManagerId); } catch (Throwable e) { @@ -1740,7 +1747,7 @@ public List getAllCredentialSummaries( public String addLocalDataMovementDetails( String resourceId, DMType dmType, int priorityOrder, LOCALDataMovement localDataMovement) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.addLocalDataMovementDetails(resourceId, dmType, priorityOrder, localDataMovement); } catch (Throwable e) { @@ -1749,7 +1756,7 @@ public String addLocalDataMovementDetails( } public boolean updateLocalDataMovementDetails(String dataMovementInterfaceId, LOCALDataMovement localDataMovement) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.updateLocalDataMovementDetails(dataMovementInterfaceId, localDataMovement); } catch (Throwable e) { @@ -1758,7 +1765,7 @@ public boolean updateLocalDataMovementDetails(String dataMovementInterfaceId, LO } public LOCALDataMovement getLocalDataMovement(String dataMovementId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.getLocalDataMovement(dataMovementId); } catch (Throwable e) { @@ -1768,7 +1775,7 @@ public LOCALDataMovement getLocalDataMovement(String dataMovementId) public String addSCPDataMovementDetails( String resourceId, DMType dmType, int priorityOrder, SCPDataMovement scpDataMovement) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.addSCPDataMovementDetails(resourceId, dmType, priorityOrder, scpDataMovement); } catch (Throwable e) { @@ -1777,7 +1784,7 @@ public String addSCPDataMovementDetails( } public boolean updateSCPDataMovementDetails(String dataMovementInterfaceId, SCPDataMovement scpDataMovement) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.updateSCPDataMovementDetails(dataMovementInterfaceId, scpDataMovement); } catch (Throwable e) { @@ -1785,8 +1792,7 @@ public boolean updateSCPDataMovementDetails(String dataMovementInterfaceId, SCPD } } - public List getUserProjects(String gatewayId, String userName, int limit, int offset) - throws RegistryException { + public List getUserProjects(String gatewayId, String userName, int limit, int offset) throws RegistryServiceException { return registryService.getUserProjects(gatewayId, userName, limit, offset); } @@ -1803,9 +1809,9 @@ public List getUserProjectsWithSharing( try { if (ServerSettings.isEnableSharing()) { // user projects + user accessible projects - List accessibleProjectIds = new ArrayList<>(); - List filters = new ArrayList<>(); - SearchCriteria searchCriteria = new SearchCriteria(); + var accessibleProjectIds = new ArrayList(); + var filters = new ArrayList(); + var searchCriteria = new SearchCriteria(); searchCriteria.setSearchField(EntitySearchField.ENTITY_TYPE_ID); searchCriteria.setSearchCondition(SearchCondition.EQUAL); searchCriteria.setValue(gatewayId + ":PROJECT"); @@ -1835,8 +1841,7 @@ public List getUserProjectsWithSharing( } public List getAccessibleApplicationDeployments( - String gatewayId, List accessibleAppDeploymentIds, List accessibleComputeResourceIds) - throws AppCatalogException { + String gatewayId, List accessibleAppDeploymentIds, List accessibleComputeResourceIds) throws RegistryServiceException { return registryService.getAccessibleApplicationDeployments( gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); } @@ -1849,17 +1854,18 @@ public List getAccessibleApplicationDeployment AuthzToken authzToken, String gatewayId, ResourcePermissionType permissionType) - throws Exception { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + try { String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); List accessibleAppDeploymentIds = new ArrayList<>(); if (ServerSettings.isEnableSharing()) { List sharingFilters = new ArrayList<>(); - SearchCriteria entityTypeFilter = new SearchCriteria(); + var entityTypeFilter = new SearchCriteria(); entityTypeFilter.setSearchField(EntitySearchField.ENTITY_TYPE_ID); entityTypeFilter.setSearchCondition(SearchCondition.EQUAL); entityTypeFilter.setValue(gatewayId + ":" + ResourceType.APPLICATION_DEPLOYMENT.name()); sharingFilters.add(entityTypeFilter); - SearchCriteria permissionTypeFilter = new SearchCriteria(); + var permissionTypeFilter = new SearchCriteria(); permissionTypeFilter.setSearchField(EntitySearchField.PERMISSION_TYPE_ID); permissionTypeFilter.setSearchCondition(SearchCondition.EQUAL); permissionTypeFilter.setValue(gatewayId + ":" + permissionType.name()); @@ -1873,7 +1879,7 @@ public List getAccessibleApplicationDeployment -1) .forEach(a -> accessibleAppDeploymentIds.add(a.getEntityId())); } - List accessibleComputeResourceIds = new ArrayList<>(); + var accessibleComputeResourceIds = new ArrayList(); List groupResourceProfileList = getGroupResourceListWithSharing( authzToken, gatewayId); for (GroupResourceProfile groupResourceProfile : groupResourceProfileList) { @@ -1884,10 +1890,13 @@ public List getAccessibleApplicationDeployment } } return getAccessibleApplicationDeployments(gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); + } catch (Throwable e) { + throw convertException(e, "Error occurred while getting accessible application deployments"); + } } public List getAppModuleDeployedResources(String appModuleId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.getAppModuleDeployedResources(appModuleId); } catch (Throwable e) { @@ -1913,28 +1922,28 @@ public List getApplicationDeploymentsForAppMod AuthzToken authzToken, String appModuleId, String groupResourceProfileId) throws AuthorizationException { try { - String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + var userName = authzToken.getClaimsMap().get(Constants.USER_NAME); + var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); // Get list of compute resources for this Group Resource Profile if (!userHasAccessInternal(authzToken, groupResourceProfileId, ResourcePermissionType.READ)) { throw new AuthorizationException( "User is not authorized to access Group Resource Profile " + groupResourceProfileId); } - GroupResourceProfile groupResourceProfile = getGroupResourceProfile(groupResourceProfileId); - List accessibleComputeResourceIds = groupResourceProfile.getComputePreferences().stream() + var groupResourceProfile = getGroupResourceProfile(groupResourceProfileId); + var accessibleComputeResourceIds = groupResourceProfile.getComputePreferences().stream() .map(compPref -> compPref.getComputeResourceId()) .collect(Collectors.toList()); // Get list of accessible Application Deployments - List accessibleAppDeploymentIds = new ArrayList<>(); - List sharingFilters = new ArrayList<>(); - SearchCriteria entityTypeFilter = new SearchCriteria(); + var accessibleAppDeploymentIds = new ArrayList(); + var sharingFilters = new ArrayList(); + var entityTypeFilter = new SearchCriteria(); entityTypeFilter.setSearchField(EntitySearchField.ENTITY_TYPE_ID); entityTypeFilter.setSearchCondition(SearchCondition.EQUAL); entityTypeFilter.setValue(gatewayId + ":" + ResourceType.APPLICATION_DEPLOYMENT.name()); sharingFilters.add(entityTypeFilter); - SearchCriteria permissionTypeFilter = new SearchCriteria(); + var permissionTypeFilter = new SearchCriteria(); permissionTypeFilter.setSearchField(EntitySearchField.PERMISSION_TYPE_ID); permissionTypeFilter.setSearchCondition(SearchCondition.EQUAL); permissionTypeFilter.setValue(gatewayId + ":" + ResourcePermissionType.READ); @@ -1960,7 +1969,7 @@ public Map getAvailableAppInterfaceComputeResources(String appIn } public SCPDataMovement getSCPDataMovement(String dataMovementId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.getSCPDataMovement(dataMovementId); } catch (Throwable e) { @@ -1970,7 +1979,7 @@ public SCPDataMovement getSCPDataMovement(String dataMovementId) public String addUnicoreDataMovementDetails( String resourceId, DMType dmType, int priorityOrder, UnicoreDataMovement unicoreDataMovement) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.addUnicoreDataMovementDetails(resourceId, dmType, priorityOrder, unicoreDataMovement); } catch (Throwable e) { @@ -1980,7 +1989,7 @@ public String addUnicoreDataMovementDetails( public boolean updateUnicoreDataMovementDetails( String dataMovementInterfaceId, UnicoreDataMovement unicoreDataMovement) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.updateUnicoreDataMovementDetails(dataMovementInterfaceId, unicoreDataMovement); } catch (Throwable e) { @@ -1989,7 +1998,7 @@ public boolean updateUnicoreDataMovementDetails( } public UnicoreDataMovement getUnicoreDataMovement(String dataMovementId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.getUnicoreDataMovement(dataMovementId); } catch (Throwable e) { @@ -1999,7 +2008,7 @@ public UnicoreDataMovement getUnicoreDataMovement(String dataMovementId) public String addGridFTPDataMovementDetails( String resourceId, DMType dmType, int priorityOrder, GridFTPDataMovement gridFTPDataMovement) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.addGridFTPDataMovementDetails(resourceId, dmType, priorityOrder, gridFTPDataMovement); } catch (Throwable e) { @@ -2009,7 +2018,7 @@ public String addGridFTPDataMovementDetails( public boolean updateGridFTPDataMovementDetails( String dataMovementInterfaceId, GridFTPDataMovement gridFTPDataMovement) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.updateGridFTPDataMovementDetails(dataMovementInterfaceId, gridFTPDataMovement); } catch (Throwable e) { @@ -2018,7 +2027,7 @@ public boolean updateGridFTPDataMovementDetails( } public GridFTPDataMovement getGridFTPDataMovement(String dataMovementId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.getGridFTPDataMovement(dataMovementId); } catch (Throwable e) { @@ -2027,7 +2036,7 @@ public GridFTPDataMovement getGridFTPDataMovement(String dataMovementId) } public boolean deleteDataMovementInterface(String resourceId, String dataMovementInterfaceId, DMType dmType) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.deleteDataMovementInterface(resourceId, dataMovementInterfaceId, dmType); } catch (Throwable e) { @@ -2036,7 +2045,7 @@ public boolean deleteDataMovementInterface(String resourceId, String dataMovemen } public boolean deleteBatchQueue(String computeResourceId, String queueName) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.deleteBatchQueue(computeResourceId, queueName); } catch (Throwable e) { @@ -2046,7 +2055,7 @@ public boolean deleteBatchQueue(String computeResourceId, String queueName) public boolean addGatewayComputeResourcePreference( String gatewayID, String computeResourceId, ComputeResourcePreference computeResourcePreference) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.addGatewayComputeResourcePreference( gatewayID, computeResourceId, computeResourcePreference); @@ -2057,7 +2066,7 @@ public boolean addGatewayComputeResourcePreference( public boolean addGatewayStoragePreference( String gatewayID, String storageResourceId, StoragePreference dataStoragePreference) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.addGatewayStoragePreference(gatewayID, storageResourceId, dataStoragePreference); } catch (Throwable e) { @@ -2065,19 +2074,28 @@ public boolean addGatewayStoragePreference( } } - public ComputeResourcePreference getGatewayComputeResourcePreference(String gatewayID, String computeResourceId) - throws AppCatalogException { - return registryService.getGatewayComputeResourcePreference(gatewayID, computeResourceId); + public ComputeResourcePreference getGatewayComputeResourcePreference(String gatewayID, String computeResourceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + try { + return registryService.getGatewayComputeResourcePreference(gatewayID, computeResourceId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving gateway compute resource preference"); + } } - public StoragePreference getGatewayStoragePreference(String gatewayID, String storageId) - throws AppCatalogException { - return registryService.getGatewayStoragePreference(gatewayID, storageId); + public StoragePreference getGatewayStoragePreference(String gatewayID, String storageId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + try { + return registryService.getGatewayStoragePreference(gatewayID, storageId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving gateway storage preference"); + } } - public List getAllGatewayComputeResourcePreferences(String gatewayID) - throws AppCatalogException { - return registryService.getAllGatewayComputeResourcePreferences(gatewayID); + public List getAllGatewayComputeResourcePreferences(String gatewayID) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + try { + return registryService.getAllGatewayComputeResourcePreferences(gatewayID); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving all gateway compute resource preferences"); + } } public List getAllGatewayStoragePreferences(String gatewayID) { @@ -2098,7 +2116,7 @@ public List getAllGatewayResourceProfiles() { public boolean updateGatewayComputeResourcePreference( String gatewayID, String computeResourceId, ComputeResourcePreference computeResourcePreference) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.updateGatewayComputeResourcePreference( gatewayID, computeResourceId, computeResourcePreference); @@ -2109,7 +2127,7 @@ public boolean updateGatewayComputeResourcePreference( public boolean updateGatewayStoragePreference( String gatewayID, String storageId, StoragePreference dataStoragePreference) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.updateGatewayStoragePreference(gatewayID, storageId, dataStoragePreference); } catch (Throwable e) { @@ -2118,7 +2136,7 @@ public boolean updateGatewayStoragePreference( } public boolean deleteGatewayComputeResourcePreference(String gatewayID, String computeResourceId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.deleteGatewayComputeResourcePreference(gatewayID, computeResourceId); } catch (Throwable e) { @@ -2128,7 +2146,7 @@ public boolean deleteGatewayComputeResourcePreference(String gatewayID, String c } public boolean deleteGatewayStoragePreference(String gatewayID, String storageId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.deleteGatewayStoragePreference(gatewayID, storageId); } catch (Throwable e) { @@ -2137,7 +2155,7 @@ public boolean deleteGatewayStoragePreference(String gatewayID, String storageId } public String registerUserResourceProfile(UserResourceProfile userResourceProfile) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.registerUserResourceProfile(userResourceProfile); } catch (Throwable e) { @@ -2146,7 +2164,7 @@ public String registerUserResourceProfile(UserResourceProfile userResourceProfil } public boolean isUserResourceProfileExists(String userId, String gatewayId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.isUserResourceProfileExists(userId, gatewayId); } catch (Throwable e) { @@ -2159,7 +2177,7 @@ public boolean addUserComputeResourcePreference( String gatewayID, String computeResourceId, UserComputeResourcePreference userComputeResourcePreference) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.addUserComputeResourcePreference( userId, gatewayID, computeResourceId, userComputeResourcePreference); @@ -2171,7 +2189,7 @@ public boolean addUserComputeResourcePreference( public boolean addUserStoragePreference( String userId, String gatewayID, String userStorageResourceId, UserStoragePreference dataStoragePreference) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.addUserStoragePreference( userId, gatewayID, userStorageResourceId, dataStoragePreference); @@ -2182,7 +2200,7 @@ public boolean addUserStoragePreference( public UserComputeResourcePreference getUserComputeResourcePreference( String userId, String gatewayID, String userComputeResourceId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.getUserComputeResourcePreference(userId, gatewayID, userComputeResourceId); } catch (Throwable e) { @@ -2191,7 +2209,7 @@ public UserComputeResourcePreference getUserComputeResourcePreference( } public UserStoragePreference getUserStoragePreference(String userId, String gatewayID, String userStorageId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.getUserStoragePreference(userId, gatewayID, userStorageId); } catch (Throwable e) { @@ -2200,7 +2218,7 @@ public UserStoragePreference getUserStoragePreference(String userId, String gate } public List getAllUserComputeResourcePreferences(String userId, String gatewayID) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.getAllUserComputeResourcePreferences(userId, gatewayID); } catch (Throwable e) { @@ -2209,7 +2227,7 @@ public List getAllUserComputeResourcePreferences( } public List getAllUserStoragePreferences(String userId, String gatewayID) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.getAllUserStoragePreferences(userId, gatewayID); } catch (Throwable e) { @@ -2218,7 +2236,7 @@ public List getAllUserStoragePreferences(String userId, S } public List getAllUserResourceProfiles() - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.getAllUserResourceProfiles(); } catch (Throwable e) { @@ -2231,7 +2249,7 @@ public boolean updateUserComputeResourcePreference( String gatewayID, String computeResourceId, UserComputeResourcePreference userComputeResourcePreference) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.updateUserComputeResourcePreference( userId, gatewayID, computeResourceId, userComputeResourcePreference); @@ -2242,7 +2260,7 @@ public boolean updateUserComputeResourcePreference( public boolean updateUserStoragePreference( String userId, String gatewayID, String userStorageId, UserStoragePreference userStoragePreference) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.updateUserStoragePreference(userId, gatewayID, userStorageId, userStoragePreference); } catch (Throwable e) { @@ -2251,7 +2269,7 @@ public boolean updateUserStoragePreference( } public boolean deleteUserComputeResourcePreference(String userId, String gatewayID, String userComputeResourceId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.deleteUserComputeResourcePreference(userId, gatewayID, userComputeResourceId); } catch (Throwable e) { @@ -2261,7 +2279,7 @@ public boolean deleteUserComputeResourcePreference(String userId, String gateway } public boolean deleteUserStoragePreference(String userId, String gatewayID, String userStorageId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { return registryService.deleteUserStoragePreference(userId, gatewayID, userStorageId); } catch (Throwable e) { @@ -2273,7 +2291,7 @@ public List getLatestQueueStatuses() { try { return registryService.getLatestQueueStatuses(); } catch (Throwable e) { - String msg = "Error in retrieving queue statuses"; + var msg = "Error in retrieving queue statuses"; logger.error(msg, e); throw convertException(e, msg); } @@ -2312,8 +2330,12 @@ public GroupComputeResourcePreference getGroupComputeResourcePreference( } } - public ComputeResourcePolicy getGroupComputeResourcePolicy(String resourcePolicyId) throws AppCatalogException { - return registryService.getGroupComputeResourcePolicy(resourcePolicyId); + public ComputeResourcePolicy getGroupComputeResourcePolicy(String resourcePolicyId) { + try { + return registryService.getGroupComputeResourcePolicy(resourcePolicyId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving group compute resource policy"); + } } public boolean removeGroupComputeResourcePolicy(String resourcePolicyId) { @@ -2396,47 +2418,66 @@ public void removeParser(String parserId, String gatewayId) { } } - public ParsingTemplate getParsingTemplate(String templateId, String gatewayId) throws RegistryException { - return registryService.getParsingTemplate(templateId, gatewayId); + public ParsingTemplate getParsingTemplate(String templateId, String gatewayId) { + try { + return registryService.getParsingTemplate(templateId, gatewayId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving parsing template"); + } } - public List getParsingTemplatesForExperiment(String experimentId, String gatewayId) - throws RegistryException { - return registryService.getParsingTemplatesForExperiment(experimentId, gatewayId); + public List getParsingTemplatesForExperiment(String experimentId, String gatewayId) { + try { + return registryService.getParsingTemplatesForExperiment(experimentId, gatewayId); + } catch (Throwable e) { + throw convertException(e, "Error while retrieving parsing templates for experiment"); + } } - public String saveParsingTemplate(ParsingTemplate parsingTemplate) throws RegistryException { - return registryService.saveParsingTemplate(parsingTemplate); + public String saveParsingTemplate(ParsingTemplate parsingTemplate) { + try { + return registryService.saveParsingTemplate(parsingTemplate); + } catch (Throwable e) { + throw convertException(e, "Error while saving parsing template"); + } } - public void removeParsingTemplate(String templateId, String gatewayId) throws RegistryException { - registryService.removeParsingTemplate(templateId, gatewayId); + public void removeParsingTemplate(String templateId, String gatewayId) { + try { + registryService.removeParsingTemplate(templateId, gatewayId); + } catch (Throwable e) { + throw convertException(e, "Error while removing parsing template"); + } } - public List listAllParsingTemplates(String gatewayId) throws RegistryException { - return registryService.listAllParsingTemplates(gatewayId); + public List listAllParsingTemplates(String gatewayId) { + try { + return registryService.listAllParsingTemplates(gatewayId); + } catch (Throwable e) { + throw convertException(e, "Error while listing all parsing templates"); + } } // Helper methods for sharing registry and authorization - public GatewayGroups retrieveGatewayGroups(String gatewayId) throws TException { + public GatewayGroups retrieveGatewayGroups(String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { if (isGatewayGroupsExists(gatewayId)) { return getGatewayGroups(gatewayId); } else { return GatewayGroupsInitializer.initializeGatewayGroups(gatewayId); } - } catch (Exception e) { - throw new TException("Error retrieving gateway groups: " + e.getMessage(), e); + } catch (Throwable e) { + throw convertException(e, "Error retrieving gateway groups"); } } public void createManageSharingPermissionTypeIfMissing( String domainId) throws TException { // AIRAVATA-3297 Some gateways were created without the MANAGE_SHARING permission, so add it if missing - String permissionTypeId = domainId + ":MANAGE_SHARING"; + var permissionTypeId = domainId + ":MANAGE_SHARING"; try { if (!sharingRegistryService.isPermissionExists(domainId, permissionTypeId)) { - PermissionType permissionType = new PermissionType(); + var permissionType = new PermissionType(); permissionType.setPermissionTypeId(permissionTypeId); permissionType.setDomainId(domainId); permissionType.setName("MANAGE_SHARING"); @@ -2511,16 +2552,16 @@ public String generateAndRegisterSSHKeys( String gatewayId, String userName, String description) - throws TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException { try { - SSHCredential sshCredential = new SSHCredential(); + var sshCredential = new SSHCredential(); sshCredential.setUsername(userName); sshCredential.setGatewayId(gatewayId); sshCredential.setDescription(description); - String key = credentialStoreService.addSSHCredential(sshCredential); + var key = credentialStoreService.addSSHCredential(sshCredential); try { - Entity entity = new Entity(); + var entity = new Entity(); entity.setEntityId(key); entity.setDomainId(gatewayId); entity.setEntityTypeId(gatewayId + ":" + ResourceType.CREDENTIAL_TOKEN); @@ -2533,7 +2574,7 @@ public String generateAndRegisterSSHKeys( logger.error( "Rolling back ssh key creation for user " + userName + " and description [" + description + "]"); credentialStoreService.deleteSSHCredential(key, gatewayId); - throw new Exception("Failed to create sharing registry record", ex); + throw convertException(ex, "Failed to create sharing registry record"); } logger.debug("Airavata generated SSH keys for gateway : " + gatewayId + " and for user : " + userName); return key; @@ -2550,37 +2591,41 @@ public String registerPwdCredential( String loginUserName, String password, String description) - throws Exception { - PasswordCredential pwdCredential = new PasswordCredential(); - pwdCredential.setPortalUserName(userName); - pwdCredential.setLoginUserName(loginUserName); - pwdCredential.setPassword(password); - pwdCredential.setDescription(description); - pwdCredential.setGatewayId(gatewayId); - String key = addPasswordCredential( pwdCredential); - try { - Entity entity = new Entity(); - entity.setEntityId(key); - entity.setDomainId(gatewayId); - entity.setEntityTypeId(gatewayId + ":" + ResourceType.CREDENTIAL_TOKEN); - entity.setOwnerId(userName + "@" + gatewayId); - entity.setName(key); - entity.setDescription(description); - sharingRegistryService.createEntity(entity); - } catch (Exception ex) { - logger.error(ex.getMessage(), ex); - logger.error("Rolling back password registration for user " + userName + " and description [" + description - + "]"); + throws InvalidRequestException, AiravataClientException, AiravataSystemException { + try { + var pwdCredential = new PasswordCredential(); + pwdCredential.setPortalUserName(userName); + pwdCredential.setLoginUserName(loginUserName); + pwdCredential.setPassword(password); + pwdCredential.setDescription(description); + pwdCredential.setGatewayId(gatewayId); + var key = addPasswordCredential( pwdCredential); try { - deletePWDCredential( key, gatewayId); - } catch (Exception rollbackEx) { - logger.error("Failed to rollback password credential deletion", rollbackEx); + var entity = new Entity(); + entity.setEntityId(key); + entity.setDomainId(gatewayId); + entity.setEntityTypeId(gatewayId + ":" + ResourceType.CREDENTIAL_TOKEN); + entity.setOwnerId(userName + "@" + gatewayId); + entity.setName(key); + entity.setDescription(description); + sharingRegistryService.createEntity(entity); + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + logger.error("Rolling back password registration for user " + userName + " and description [" + description + + "]"); + try { + deletePWDCredential( key, gatewayId); + } catch (Exception rollbackEx) { + logger.error("Failed to rollback password credential deletion", rollbackEx); + } + throw convertException(ex, "Failed to create sharing registry record"); } - throw new Exception("Failed to create sharing registry record", ex); + logger.debug( + "Airavata generated PWD credential for gateway : " + gatewayId + " and for user : " + loginUserName); + return key; + } catch (Throwable e) { + throw convertException(e, "Error occurred while registering password credential"); } - logger.debug( - "Airavata generated PWD credential for gateway : " + gatewayId + " and for user : " + loginUserName); - return key; } public CredentialSummary getCredentialSummaryWithAuth( @@ -2589,13 +2634,17 @@ public CredentialSummary getCredentialSummaryWithAuth( AuthzToken authzToken, String tokenId, String gatewayId) - throws AuthorizationException, Exception { - if (!userHasAccessInternal( authzToken, tokenId, ResourcePermissionType.READ)) { - throw new AuthorizationException("User does not have permission to access this resource"); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + try { + if (!userHasAccessInternal( authzToken, tokenId, ResourcePermissionType.READ)) { + throw new AuthorizationException("User does not have permission to access this resource"); + } + var credentialSummary = getCredentialSummary( tokenId, gatewayId); + logger.debug("Airavata retrived the credential summary for token " + tokenId + "GatewayId: " + gatewayId); + return credentialSummary; + } catch (Throwable e) { + throw convertException(e, "Error occurred while getting credential summary"); } - CredentialSummary credentialSummary = getCredentialSummary( tokenId, gatewayId); - logger.debug("Airavata retrived the credential summary for token " + tokenId + "GatewayId: " + gatewayId); - return credentialSummary; } public List getAllCredentialSummariesWithAuth( @@ -2605,22 +2654,26 @@ public List getAllCredentialSummariesWithAuth( SummaryType type, String gatewayId, String userName) - throws Exception { - List filters = new ArrayList<>(); - SearchCriteria searchCriteria = new SearchCriteria(); - searchCriteria.setSearchField(EntitySearchField.ENTITY_TYPE_ID); - searchCriteria.setSearchCondition(SearchCondition.EQUAL); - searchCriteria.setValue(gatewayId + ":" + ResourceType.CREDENTIAL_TOKEN.name()); - filters.add(searchCriteria); - List accessibleTokenIds = - sharingRegistryService.searchEntities(gatewayId, userName + "@" + gatewayId, filters, 0, -1).stream() - .map(p -> p.getEntityId()) - .collect(Collectors.toList()); - List credentialSummaries = - getAllCredentialSummaries( type, accessibleTokenIds, gatewayId); - logger.debug( - "Airavata successfully retrived credential summaries of type " + type + " GatewayId: " + gatewayId); - return credentialSummaries; + throws InvalidRequestException, AiravataClientException, AiravataSystemException { + try { + List filters = new ArrayList<>(); + SearchCriteria searchCriteria = new SearchCriteria(); + searchCriteria.setSearchField(EntitySearchField.ENTITY_TYPE_ID); + searchCriteria.setSearchCondition(SearchCondition.EQUAL); + searchCriteria.setValue(gatewayId + ":" + ResourceType.CREDENTIAL_TOKEN.name()); + filters.add(searchCriteria); + List accessibleTokenIds = + sharingRegistryService.searchEntities(gatewayId, userName + "@" + gatewayId, filters, 0, -1).stream() + .map(p -> p.getEntityId()) + .collect(Collectors.toList()); + List credentialSummaries = + getAllCredentialSummaries( type, accessibleTokenIds, gatewayId); + logger.debug( + "Airavata successfully retrived credential summaries of type " + type + " GatewayId: " + gatewayId); + return credentialSummaries; + } catch (Throwable e) { + throw convertException(e, "Error occurred while getting all credential summaries"); + } } public boolean deleteSSHPubKey( @@ -2629,13 +2682,17 @@ public boolean deleteSSHPubKey( AuthzToken authzToken, String airavataCredStoreToken, String gatewayId) - throws AuthorizationException, Exception { - if (!userHasAccessInternal( authzToken, airavataCredStoreToken, ResourcePermissionType.WRITE)) { - throw new AuthorizationException("User does not have permission to delete this resource."); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + try { + if (!userHasAccessInternal( authzToken, airavataCredStoreToken, ResourcePermissionType.WRITE)) { + throw new AuthorizationException("User does not have permission to delete this resource."); + } + logger.debug("Airavata deleted SSH pub key for gateway Id : " + gatewayId + " and with token id : " + + airavataCredStoreToken); + return deleteSSHCredential( airavataCredStoreToken, gatewayId); + } catch (Throwable e) { + throw convertException(e, "Error occurred while deleting SSH pub key"); } - logger.debug("Airavata deleted SSH pub key for gateway Id : " + gatewayId + " and with token id : " - + airavataCredStoreToken); - return deleteSSHCredential( airavataCredStoreToken, gatewayId); } public boolean deletePWDCredentialWithAuth( @@ -2644,41 +2701,49 @@ public boolean deletePWDCredentialWithAuth( AuthzToken authzToken, String airavataCredStoreToken, String gatewayId) - throws AuthorizationException, Exception { - if (!userHasAccessInternal( authzToken, airavataCredStoreToken, ResourcePermissionType.WRITE)) { - throw new AuthorizationException("User does not have permission to delete this resource."); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + try { + if (!userHasAccessInternal( authzToken, airavataCredStoreToken, ResourcePermissionType.WRITE)) { + throw new AuthorizationException("User does not have permission to delete this resource."); + } + logger.debug("Airavata deleted PWD credential for gateway Id : " + gatewayId + " and with token id : " + + airavataCredStoreToken); + deletePWDCredential( airavataCredStoreToken, gatewayId); + return true; + } catch (Throwable e) { + throw convertException(e, "Error occurred while deleting PWD credential"); } - logger.debug("Airavata deleted PWD credential for gateway Id : " + gatewayId + " and with token id : " - + airavataCredStoreToken); - deletePWDCredential( airavataCredStoreToken, gatewayId); - return true; } // Project management methods with sharing registry integration public String createProjectWithSharing( - String gatewayId, Project project) throws Exception { - String projectId = createProject(gatewayId, project); - // TODO: verify that gatewayId and project.gatewayId match authzToken - if (ServerSettings.isEnableSharing()) { - try { - Entity entity = new Entity(); - entity.setEntityId(projectId); - final String domainId = project.getGatewayId(); - entity.setDomainId(domainId); - entity.setEntityTypeId(domainId + ":" + "PROJECT"); - entity.setOwnerId(project.getOwner() + "@" + domainId); - entity.setName(project.getName()); - entity.setDescription(project.getDescription()); - sharingRegistryService.createEntity(entity); - } catch (Exception ex) { - logger.error(ex.getMessage(), ex); - logger.error("Rolling back project creation Proj ID : " + projectId); - deleteProject(projectId); - throw new Exception("Failed to create entry for project in Sharing Registry", ex); + String gatewayId, Project project) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + try { + var projectId = createProject(gatewayId, project); + // TODO: verify that gatewayId and project.gatewayId match authzToken + if (ServerSettings.isEnableSharing()) { + try { + var entity = new Entity(); + entity.setEntityId(projectId); + final String domainId = project.getGatewayId(); + entity.setDomainId(domainId); + entity.setEntityTypeId(domainId + ":" + "PROJECT"); + entity.setOwnerId(project.getOwner() + "@" + domainId); + entity.setName(project.getName()); + entity.setDescription(project.getDescription()); + sharingRegistryService.createEntity(entity); + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + logger.error("Rolling back project creation Proj ID : " + projectId); + deleteProject(projectId); + throw convertException(ex, "Failed to create entry for project in Sharing Registry"); + } } + logger.debug("Airavata created project with project Id : " + projectId + " for gateway Id : " + gatewayId); + return projectId; + } catch (Throwable e) { + throw convertException(e, "Error occurred while creating project"); } - logger.debug("Airavata created project with project Id : " + projectId + " for gateway Id : " + gatewayId); - return projectId; } public void updateProjectWithAuth( @@ -2686,59 +2751,71 @@ public void updateProjectWithAuth( AuthzToken authzToken, String projectId, Project updatedProject) - throws Exception { - Project existingProject = getProject(projectId); - if (ServerSettings.isEnableSharing() - && !authzToken.getClaimsMap().get(Constants.USER_NAME).equals(existingProject.getOwner()) - || !authzToken.getClaimsMap().get(Constants.GATEWAY_ID).equals(existingProject.getGatewayId())) { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!sharingRegistryService.userHasAccess(gatewayId, userId + "@" + gatewayId, projectId, gatewayId + ":WRITE")) { - throw new AuthorizationException("User does not have permission to access this resource"); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, ProjectNotFoundException, AuthorizationException { + try { + var existingProject = getProject(projectId); + if (ServerSettings.isEnableSharing() + && !authzToken.getClaimsMap().get(Constants.USER_NAME).equals(existingProject.getOwner()) + || !authzToken.getClaimsMap().get(Constants.GATEWAY_ID).equals(existingProject.getGatewayId())) { + var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + if (!sharingRegistryService.userHasAccess(gatewayId, userId + "@" + gatewayId, projectId, gatewayId + ":WRITE")) { + 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"); + } + updateProject(projectId, updatedProject); + logger.debug("Airavata updated project with project Id : " + projectId); + } catch (Throwable e) { + throw convertException(e, "Error occurred while updating project"); } - 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"); - } - updateProject(projectId, updatedProject); - logger.debug("Airavata updated project with project Id : " + projectId); } public boolean deleteProjectWithAuth( - AuthzToken authzToken, String projectId) throws ProjectNotFoundException, AuthorizationException, Exception { - Project existingProject = getProject(projectId); - if (ServerSettings.isEnableSharing() - && !authzToken.getClaimsMap().get(Constants.USER_NAME).equals(existingProject.getOwner()) - || !authzToken.getClaimsMap().get(Constants.GATEWAY_ID).equals(existingProject.getGatewayId())) { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!sharingRegistryService.userHasAccess(gatewayId, userId + "@" + gatewayId, projectId, gatewayId + ":WRITE")) { - throw new AuthorizationException("User does not have permission to access this resource"); + AuthzToken authzToken, String projectId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, ProjectNotFoundException, AuthorizationException { + try { + var existingProject = getProject(projectId); + if (ServerSettings.isEnableSharing() + && !authzToken.getClaimsMap().get(Constants.USER_NAME).equals(existingProject.getOwner()) + || !authzToken.getClaimsMap().get(Constants.GATEWAY_ID).equals(existingProject.getGatewayId())) { + var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + if (!sharingRegistryService.userHasAccess(gatewayId, userId + "@" + gatewayId, projectId, gatewayId + ":WRITE")) { + throw new AuthorizationException("User does not have permission to access this resource"); + } } + boolean ret = deleteProject(projectId); + logger.debug("Airavata deleted project with project Id : " + projectId); + return ret; + } catch (Throwable e) { + throw convertException(e, "Error occurred while deleting project"); } - boolean ret = deleteProject(projectId); - logger.debug("Airavata deleted project with project Id : " + projectId); - return ret; } public Project getProjectWithAuth( - AuthzToken authzToken, String projectId) throws ProjectNotFoundException, AuthorizationException, Exception { - Project project = getProject(projectId); - if (authzToken.getClaimsMap().get(Constants.USER_NAME).equals(project.getOwner()) - && authzToken.getClaimsMap().get(Constants.GATEWAY_ID).equals(project.getGatewayId())) { - return project; - } else if (ServerSettings.isEnableSharing()) { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!sharingRegistryService.userHasAccess(gatewayId, userId + "@" + gatewayId, projectId, gatewayId + ":READ")) { - throw new AuthorizationException("User does not have permission to access this resource"); + AuthzToken authzToken, String projectId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, ProjectNotFoundException, AuthorizationException { + try { + var project = getProject(projectId); + if (authzToken.getClaimsMap().get(Constants.USER_NAME).equals(project.getOwner()) + && authzToken.getClaimsMap().get(Constants.GATEWAY_ID).equals(project.getGatewayId())) { + return project; + } else if (ServerSettings.isEnableSharing()) { + var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + if (!sharingRegistryService.userHasAccess(gatewayId, userId + "@" + gatewayId, projectId, gatewayId + ":READ")) { + throw new AuthorizationException("User does not have permission to access this resource"); + } + return project; + } else { + return null; } - return project; - } else { - return null; + } catch (Throwable e) { + throw convertException(e, "Error occurred while getting project"); } } @@ -2746,11 +2823,11 @@ public Project getProjectWithAuth( public String createExperimentWithSharing( String gatewayId, ExperimentModel experiment) throws Exception { - String experimentId = createExperiment(gatewayId, experiment); + var experimentId = createExperiment(gatewayId, experiment); if (ServerSettings.isEnableSharing()) { try { - Entity entity = new Entity(); + var entity = new Entity(); entity.setEntityId(experimentId); final String domainId = experiment.getGatewayId(); entity.setDomainId(domainId); @@ -2783,16 +2860,16 @@ public String createExperimentWithSharingAndPublish( Publisher statusPublisher, String gatewayId, ExperimentModel experiment) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { logger.info("Api server accepted experiment creation with name {}", experiment.getExperimentName()); - String experimentId = createExperimentWithSharing( gatewayId, experiment); + var experimentId = createExperimentWithSharing( gatewayId, experiment); if (statusPublisher != null) { - ExperimentStatusChangeEvent event = + var event = new ExperimentStatusChangeEvent(ExperimentState.CREATED, experimentId, gatewayId); - String messageId = AiravataUtils.getId("EXPERIMENT"); - MessageContext messageContext = new MessageContext(event, MessageType.EXPERIMENT, messageId, gatewayId); + var messageId = AiravataUtils.getId("EXPERIMENT"); + var messageContext = new MessageContext(event, MessageType.EXPERIMENT, messageId, gatewayId); messageContext.setUpdatedTime(AiravataUtils.getCurrentTimestamp()); statusPublisher.publish(messageContext); } @@ -2830,11 +2907,11 @@ public void validateLaunchExperimentAccess( // Verify user has READ access to Application Deployment final String appInterfaceId = experiment.getExecutionId(); - ApplicationInterfaceDescription applicationInterfaceDescription = getApplicationInterface(appInterfaceId); + var applicationInterfaceDescription = getApplicationInterface(appInterfaceId); List appModuleIds = applicationInterfaceDescription.getApplicationModules(); // Assume that there is only one app module for this interface - String appModuleId = appModuleIds.get(0); + var appModuleId = appModuleIds.get(0); List applicationDeploymentDescriptions = getApplicationDeployments(appModuleId); @@ -2888,13 +2965,13 @@ public void validateLaunchExperimentAccess( public boolean deleteExperimentWithAuth( AuthzToken authzToken, String experimentId) throws AuthorizationException, InvalidRequestException { try { - ExperimentModel experimentModel = getExperiment(experimentId); + var experimentModel = getExperiment(experimentId); if (ServerSettings.isEnableSharing() && !authzToken.getClaimsMap().get(Constants.USER_NAME).equals(experimentModel.getUserName()) || !authzToken.getClaimsMap().get(Constants.GATEWAY_ID).equals(experimentModel.getGatewayId())) { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); if (!sharingRegistryService.userHasAccess(gatewayId, userId + "@" + gatewayId, experimentId, gatewayId + ":WRITE")) { throw new AuthorizationException("User does not have permission to access this resource"); } @@ -2914,7 +2991,7 @@ public boolean deleteExperimentWithAuth( public ResourceType getResourceType( String domainId, String entityId) { try { - Entity entity = sharingRegistryService.getEntity(domainId, entityId); + var entity = sharingRegistryService.getEntity(domainId, entityId); for (ResourceType resourceType : ResourceType.values()) { if (entity.getEntityTypeId().equals(domainId + ":" + resourceType.name())) { return resourceType; @@ -2927,9 +3004,9 @@ public ResourceType getResourceType( String domainId, String entityId) { } // Gateway management methods with sharing registry integration - public String addGatewayWithSharing(Gateway gateway) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + public String addGatewayWithSharing(Gateway gateway) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { - String gatewayId = registryService.addGateway(gateway); + var gatewayId = registryService.addGateway(gateway); Domain domain = new Domain(); domain.setDomainId(gateway.getGatewayId()); domain.setName(gateway.getGatewayName()); @@ -3004,8 +3081,8 @@ public String addGatewayWithSharing(Gateway gateway) throws InvalidRequestExcept // Event publishing methods public void publishExperimentSubmitEvent(Publisher experimentPublisher, String gatewayId, String experimentId) throws Exception { - ExperimentSubmitEvent event = new ExperimentSubmitEvent(experimentId, gatewayId); - MessageContext messageContext = new MessageContext( + var event = new ExperimentSubmitEvent(experimentId, gatewayId); + var messageContext = new MessageContext( event, MessageType.EXPERIMENT, "LAUNCH.EXP-" + UUID.randomUUID().toString(), gatewayId); messageContext.setUpdatedTime(AiravataUtils.getCurrentTimestamp()); experimentPublisher.publish(messageContext); @@ -3013,8 +3090,8 @@ public void publishExperimentSubmitEvent(Publisher experimentPublisher, String g public void publishExperimentCancelEvent(Publisher experimentPublisher, String gatewayId, String experimentId) throws Exception { - ExperimentSubmitEvent event = new ExperimentSubmitEvent(experimentId, gatewayId); - MessageContext messageContext = new MessageContext( + var event = new ExperimentSubmitEvent(experimentId, gatewayId); + var messageContext = new MessageContext( event, MessageType.EXPERIMENT_CANCEL, "CANCEL.EXP-" + UUID.randomUUID().toString(), @@ -3026,9 +3103,9 @@ public void publishExperimentCancelEvent(Publisher experimentPublisher, String g public void publishExperimentIntermediateOutputsEvent( Publisher experimentPublisher, String gatewayId, String experimentId, List outputNames) throws Exception { - ExperimentIntermediateOutputsEvent event = + var event = new ExperimentIntermediateOutputsEvent(experimentId, gatewayId, outputNames); - MessageContext messageContext = new MessageContext( + var messageContext = new MessageContext( event, MessageType.INTERMEDIATE_OUTPUTS, "INTERMEDIATE_OUTPUTS.EXP-" + UUID.randomUUID().toString(), @@ -3046,20 +3123,20 @@ public void validateAndFetchIntermediateOutputs( String airavataExperimentId, List outputNames, Publisher experimentPublisher) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { // Verify that user has WRITE access to experiment final boolean hasAccess = userHasAccessInternal( authzToken, airavataExperimentId, ResourcePermissionType.WRITE); if (!hasAccess) { - String msg = "User does not have WRITE access to this experiment"; + var msg = "User does not have WRITE access to this experiment"; logger.error(msg); throw new AuthorizationException(msg); } // Verify that the experiment's job is currently ACTIVE ExperimentModel existingExperiment = getExperiment(airavataExperimentId); - List jobs = getJobDetails(airavataExperimentId); + var jobs = getJobDetails(airavataExperimentId); boolean anyJobIsActive = jobs.stream().anyMatch(j -> { if (j.getJobStatusesSize() > 0) { return j.getJobStatuses().get(j.getJobStatusesSize() - 1).getJobState() == JobState.ACTIVE; @@ -3068,18 +3145,18 @@ public void validateAndFetchIntermediateOutputs( } }); if (!anyJobIsActive) { - String msg = "Experiment does not have currently ACTIVE job"; + var msg = "Experiment does not have currently ACTIVE job"; logger.error(msg); throw new InvalidRequestException(msg); } // Figure out if there are any currently running intermediate output fetching processes for outputNames // First, find any existing intermediate output fetch processes for outputNames - List intermediateOutputFetchProcesses = existingExperiment.getProcesses().stream() + var intermediateOutputFetchProcesses = existingExperiment.getProcesses().stream() .filter(p -> { // Filter out completed or failed processes if (p.getProcessStatusesSize() > 0) { - ProcessStatus latestStatus = p.getProcessStatuses().get(p.getProcessStatusesSize() - 1); + var latestStatus = p.getProcessStatuses().get(p.getProcessStatusesSize() - 1); if (latestStatus.getState() == ProcessState.COMPLETED || latestStatus.getState() == ProcessState.FAILED) { return false; @@ -3091,12 +3168,12 @@ public void validateAndFetchIntermediateOutputs( .filter(p -> p.getProcessOutputs().stream().anyMatch(o -> outputNames.contains(o.getName()))) .collect(Collectors.toList()); if (!intermediateOutputFetchProcesses.isEmpty()) { - String msg = "There are already intermediate output fetching tasks running for those outputs."; + var msg = "There are already intermediate output fetching tasks running for those outputs."; logger.error(msg); throw new InvalidRequestException(msg); } - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); publishExperimentIntermediateOutputsEvent(experimentPublisher, gatewayId, airavataExperimentId, outputNames); } catch (AuthorizationException | InvalidRequestException e) { throw e; @@ -3117,13 +3194,13 @@ public ProcessStatus getIntermediateOutputProcessStatusInternal( AuthzToken authzToken, String airavataExperimentId, List outputNames) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { try { // Verify that user has READ access to experiment final boolean hasAccess = userHasAccessInternal( authzToken, airavataExperimentId, ResourcePermissionType.READ); if (!hasAccess) { - String msg = "User does not have READ access to this experiment"; + var msg = "User does not have READ access to this experiment"; logger.debug(msg); throw new AuthorizationException(msg); } @@ -3144,7 +3221,7 @@ public ProcessStatus getIntermediateOutputProcessStatusInternal( .findFirst(); if (!mostRecentOutputFetchProcess.isPresent()) { - String msg = "No matching intermediate output fetching process found."; + var msg = "No matching intermediate output fetching process found."; logger.debug(msg); throw new InvalidRequestException(msg); } @@ -3232,7 +3309,8 @@ public List getAllAccessibleUsersWithSharing( String resourceId, ResourcePermissionType permissionType, boolean directlySharedOnly) - throws Exception { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + try { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); BiFunction> userListFunction; if (directlySharedOnly) { @@ -3253,6 +3331,9 @@ public List getAllAccessibleUsersWithSharing( }; } return getAllAccessibleUsers( gatewayId, resourceId, permissionType, userListFunction); + } catch (Throwable e) { + throw convertException(e, "Error occurred while getting all accessible users"); + } } /** @@ -3264,7 +3345,8 @@ public List getAllAccessibleGroupsWithSharing( String resourceId, ResourcePermissionType permissionType, boolean directlySharedOnly) - throws Exception { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + try { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); BiFunction> groupListFunction; if (directlySharedOnly) { @@ -3285,6 +3367,9 @@ public List getAllAccessibleGroupsWithSharing( }; } return getAllAccessibleGroups( gatewayId, resourceId, permissionType, groupListFunction); + } catch (Throwable e) { + throw convertException(e, "Error occurred while getting all accessible groups"); + } } // Group resource profile management with sharing registry integration @@ -3298,7 +3383,7 @@ public String createGroupResourceProfileWithSharing( String groupResourceProfileId = createGroupResourceProfile(groupResourceProfile); if (ServerSettings.isEnableSharing()) { try { - Entity entity = new Entity(); + var entity = new Entity(); entity.setEntityId(groupResourceProfileId); entity.setDomainId(groupResourceProfile.getGatewayId()); entity.setEntityTypeId(groupResourceProfile.getGatewayId() + ":" + "GROUP_RESOURCE_PROFILE"); @@ -3394,27 +3479,31 @@ public void launchExperimentWithValidation( * Get group resource list with sharing registry integration */ public List getGroupResourceListWithSharing( - AuthzToken authzToken, String gatewayId) throws Exception { - String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); - List accessibleGroupResProfileIds = new ArrayList<>(); - if (ServerSettings.isEnableSharing()) { - List filters = new ArrayList<>(); - SearchCriteria searchCriteria = new SearchCriteria(); - searchCriteria.setSearchField(EntitySearchField.ENTITY_TYPE_ID); - searchCriteria.setSearchCondition(SearchCondition.EQUAL); - searchCriteria.setValue(gatewayId + ":" + ResourceType.GROUP_RESOURCE_PROFILE.name()); - filters.add(searchCriteria); - sharingRegistryService - .searchEntities( - authzToken.getClaimsMap().get(Constants.GATEWAY_ID), - userName + "@" + gatewayId, - filters, - 0, - -1) - .stream() - .forEach(p -> accessibleGroupResProfileIds.add(p.getEntityId())); + AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + try { + String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); + var accessibleGroupResProfileIds = new ArrayList(); + if (ServerSettings.isEnableSharing()) { + var filters = new ArrayList(); + SearchCriteria searchCriteria = new SearchCriteria(); + searchCriteria.setSearchField(EntitySearchField.ENTITY_TYPE_ID); + searchCriteria.setSearchCondition(SearchCondition.EQUAL); + searchCriteria.setValue(gatewayId + ":" + ResourceType.GROUP_RESOURCE_PROFILE.name()); + filters.add(searchCriteria); + sharingRegistryService + .searchEntities( + authzToken.getClaimsMap().get(Constants.GATEWAY_ID), + userName + "@" + gatewayId, + filters, + 0, + -1) + .stream() + .forEach(p -> accessibleGroupResProfileIds.add(p.getEntityId())); + } + return getGroupResourceList(gatewayId, accessibleGroupResProfileIds); + } catch (Throwable e) { + throw convertException(e, "Error occurred while getting group resource list"); } - return getGroupResourceList(gatewayId, accessibleGroupResProfileIds); } // Sharing Registry Delegation Methods for ServerHandler @@ -3525,7 +3614,7 @@ private StorageInfoContext resolveComputeStorageInfoContext( } else { // Fallback to GroupComputeResourcePreference - List groupResourceProfiles = getGroupResourceListWithSharing(authzToken, gatewayId); + var groupResourceProfiles = getGroupResourceListWithSharing(authzToken, gatewayId); for (GroupResourceProfile groupProfile : groupResourceProfiles) { List groupComputePrefs = groupProfile.getComputePreferences(); @@ -3728,8 +3817,8 @@ public StorageVolumeInfo getResourceStorageInfo( AuthzToken authzToken, String resourceId, String location) throws InvalidRequestException { try { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); StorageInfoContext context; Optional computeResourceOp = Optional.empty(); @@ -3782,8 +3871,8 @@ public StorageDirectoryInfo getStorageDirectoryInfo( AuthzToken authzToken, String resourceId, String location) throws InvalidRequestException { try { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); StorageInfoContext context; Optional computeResourceOp = Optional.empty(); @@ -3834,7 +3923,7 @@ public StorageDirectoryInfo getStorageDirectoryInfo( public boolean doesUserHaveSSHAccount(AuthzToken authzToken, String computeResourceId, String userId) { try { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); logger.debug("Checking if user {} has SSH account on compute resource {} in gateway {}", userId, computeResourceId, gatewayId); return org.apache.airavata.accountprovisioning.SSHAccountManager.doesUserHaveSSHAccount(gatewayId, computeResourceId, userId); } catch (Throwable e) { @@ -3845,8 +3934,8 @@ public boolean doesUserHaveSSHAccount(AuthzToken authzToken, String computeResou public boolean isSSHAccountSetupComplete( AuthzToken authzToken, String computeResourceId, String airavataCredStoreToken) { try { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); logger.debug("Checking if SSH account setup is complete for user {} on compute resource {} in gateway {}", userId, computeResourceId, gatewayId); SSHCredential sshCredential = getSSHCredential(airavataCredStoreToken, gatewayId); @@ -3859,7 +3948,7 @@ public boolean isSSHAccountSetupComplete( public UserComputeResourcePreference setupSSHAccount( AuthzToken authzToken, String computeResourceId, String userId, String airavataCredStoreToken) { try { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); logger.debug("Setting up SSH account for user {} on compute resource {} in gateway {}", userId, computeResourceId, gatewayId); SSHCredential sshCredential = getSSHCredential(airavataCredStoreToken, gatewayId); @@ -3878,7 +3967,7 @@ public boolean shareResourceWithUsers( throw new AuthorizationException( "User is not allowed to change sharing because the user is either not the resource owner or does not have access to share the resource"); } - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); for (Map.Entry userPermission : userPermissionList.entrySet()) { if (userPermission.getValue().equals(ResourcePermissionType.WRITE)) { shareEntityWithUsers( @@ -3916,7 +4005,7 @@ public boolean shareResourceWithUsers( } catch (AuthorizationException | AiravataClientException e) { throw e; } catch (Throwable e) { - String msg = "Error in sharing resource with users. Resource ID : " + resourceId; + var msg = "Error in sharing resource with users. Resource ID : " + resourceId; logger.error(msg, e); throw convertException(e, msg); } @@ -3931,7 +4020,7 @@ public boolean shareResourceWithGroups( throw new AuthorizationException( "User is not allowed to change sharing because the user is either not the resource owner or does not have access to share the resource"); } - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); for (Map.Entry groupPermission : groupPermissionList.entrySet()) { if (groupPermission.getValue().equals(ResourcePermissionType.WRITE)) { shareEntityWithGroups( @@ -3969,7 +4058,7 @@ public boolean shareResourceWithGroups( } catch (AuthorizationException | AiravataClientException e) { throw e; } catch (Throwable e) { - String msg = "Error in sharing resource with groups. Resource ID : " + resourceId; + var msg = "Error in sharing resource with groups. Resource ID : " + resourceId; logger.error(msg, e); throw convertException(e, msg); } @@ -3984,7 +4073,7 @@ public boolean revokeSharingOfResourceFromUsers( throw new AuthorizationException( "User is not allowed to change sharing because the user is either not the resource owner or does not have access to share the resource"); } - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); for (Map.Entry userPermission : userPermissionList.entrySet()) { if (userPermission.getValue().equals(ResourcePermissionType.WRITE)) { revokeEntitySharingFromUsers( @@ -4019,7 +4108,7 @@ public boolean revokeSharingOfResourceFromUsers( } catch (AuthorizationException | AiravataClientException e) { throw e; } catch (Throwable e) { - String msg = "Error in revoking access to resource from users. Resource ID : " + resourceId; + var msg = "Error in revoking access to resource from users. Resource ID : " + resourceId; logger.error(msg, e); throw convertException(e, msg); } @@ -4029,7 +4118,7 @@ public boolean revokeSharingOfResourceFromGroups( AuthzToken authzToken, String resourceId, Map groupPermissionList) throws AuthorizationException, AiravataClientException, InvalidRequestException { try { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); if (!userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.OWNER) && !userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { throw new AuthorizationException( @@ -4095,7 +4184,7 @@ public boolean revokeSharingOfResourceFromGroups( } catch (AuthorizationException | AiravataClientException | InvalidRequestException e) { throw e; } catch (Throwable e) { - String msg = "Error in revoking access to resource from groups. Resource ID : " + resourceId; + var msg = "Error in revoking access to resource from groups. Resource ID : " + resourceId; logger.error(msg, e); throw convertException(e, msg); } @@ -4105,8 +4194,8 @@ public GroupResourceProfile getGroupResourceProfileWithAuth(AuthzToken authzToke throws AuthorizationException { try { if (ServerSettings.isEnableSharing()) { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); if (!userHasAccess(gatewayId, userId + "@" + gatewayId, groupResourceProfileId, gatewayId + ":READ")) { throw new AuthorizationException( "User does not have permission to access group resource profile"); @@ -4119,7 +4208,7 @@ public GroupResourceProfile getGroupResourceProfileWithAuth(AuthzToken authzToke e); throw e; } catch (Throwable e) { - String msg = "Error retrieving group resource profile. groupResourceProfileId: " + groupResourceProfileId; + var msg = "Error retrieving group resource profile. groupResourceProfileId: " + groupResourceProfileId; logger.error(msg, e); throw convertException(e, msg); } @@ -4128,9 +4217,9 @@ public GroupResourceProfile getGroupResourceProfileWithAuth(AuthzToken authzToke public boolean removeGroupResourceProfileWithAuth(AuthzToken authzToken, String groupResourceProfileId) throws AuthorizationException { try { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); if (ServerSettings.isEnableSharing()) { - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); if (!userHasAccess(gatewayId, userId + "@" + gatewayId, groupResourceProfileId, gatewayId + ":WRITE")) { throw new AuthorizationException( "User does not have permission to remove group resource profile"); @@ -4144,7 +4233,7 @@ public boolean removeGroupResourceProfileWithAuth(AuthzToken authzToken, String } catch (AuthorizationException e) { throw e; } catch (Throwable e) { - String msg = "Error removing group resource profile. groupResourceProfileId: " + groupResourceProfileId; + var msg = "Error removing group resource profile. groupResourceProfileId: " + groupResourceProfileId; logger.error(msg, e); throw convertException(e, msg); } @@ -4155,8 +4244,8 @@ public boolean removeGroupComputePrefsWithAuth( throws AuthorizationException { try { if (ServerSettings.isEnableSharing()) { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); if (!userHasAccess(gatewayId, userId + "@" + gatewayId, groupResourceProfileId, gatewayId + ":WRITE")) { throw new AuthorizationException( "User does not have permission to remove group compute preferences"); @@ -4166,7 +4255,7 @@ public boolean removeGroupComputePrefsWithAuth( } catch (AuthorizationException e) { throw e; } catch (Throwable e) { - String msg = "Error removing group compute preferences. GroupResourceProfileId: " + groupResourceProfileId; + var msg = "Error removing group compute preferences. GroupResourceProfileId: " + groupResourceProfileId; logger.error(msg, e); throw convertException(e, msg); } @@ -4177,8 +4266,8 @@ public boolean removeGroupComputeResourcePolicyWithAuth(AuthzToken authzToken, S try { if (ServerSettings.isEnableSharing()) { ComputeResourcePolicy computeResourcePolicy = getGroupComputeResourcePolicy(resourcePolicyId); - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); if (!userHasAccess( gatewayId, userId + "@" + gatewayId, @@ -4192,7 +4281,7 @@ public boolean removeGroupComputeResourcePolicyWithAuth(AuthzToken authzToken, S } catch (AuthorizationException e) { throw e; } catch (Throwable e) { - String msg = "Error removing group compute resource policy. ResourcePolicyId: " + resourcePolicyId; + var msg = "Error removing group compute resource policy. ResourcePolicyId: " + resourcePolicyId; logger.error(msg, e); throw convertException(e, msg); } @@ -4203,8 +4292,8 @@ public boolean removeGroupBatchQueueResourcePolicyWithAuth(AuthzToken authzToken try { if (ServerSettings.isEnableSharing()) { BatchQueueResourcePolicy batchQueueResourcePolicy = getBatchQueueResourcePolicy(resourcePolicyId); - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); if (!userHasAccess( gatewayId, userId + "@" + gatewayId, @@ -4218,7 +4307,7 @@ public boolean removeGroupBatchQueueResourcePolicyWithAuth(AuthzToken authzToken } catch (AuthorizationException e) { throw e; } catch (Throwable e) { - String msg = "Error removing batch queue resource policy. ResourcePolicyId: " + resourcePolicyId; + var msg = "Error removing batch queue resource policy. ResourcePolicyId: " + resourcePolicyId; logger.error(msg, e); throw convertException(e, msg); } @@ -4229,8 +4318,8 @@ public GroupComputeResourcePreference getGroupComputeResourcePreferenceWithAuth( throws AuthorizationException { try { if (ServerSettings.isEnableSharing()) { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); if (!userHasAccess(gatewayId, userId + "@" + gatewayId, groupResourceProfileId, gatewayId + ":READ")) { throw new AuthorizationException( "User does not have permission to access group resource profile"); @@ -4240,7 +4329,7 @@ public GroupComputeResourcePreference getGroupComputeResourcePreferenceWithAuth( } catch (AuthorizationException e) { throw e; } catch (Throwable e) { - String msg = "Error retrieving Group compute preference. GroupResourceProfileId: " + groupResourceProfileId; + var msg = "Error retrieving Group compute preference. GroupResourceProfileId: " + groupResourceProfileId; logger.error(msg, e); throw convertException(e, msg); } @@ -4251,8 +4340,8 @@ public ComputeResourcePolicy getGroupComputeResourcePolicyWithAuth(AuthzToken au try { if (ServerSettings.isEnableSharing()) { ComputeResourcePolicy computeResourcePolicy = getGroupComputeResourcePolicy(resourcePolicyId); - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); if (!userHasAccess( gatewayId, userId + "@" + gatewayId, @@ -4266,7 +4355,7 @@ public ComputeResourcePolicy getGroupComputeResourcePolicyWithAuth(AuthzToken au } catch (AuthorizationException e) { throw e; } catch (Throwable e) { - String msg = "Error retrieving Group compute resource policy. ResourcePolicyId: " + resourcePolicyId; + var msg = "Error retrieving Group compute resource policy. ResourcePolicyId: " + resourcePolicyId; logger.error(msg, e); throw convertException(e, msg); } @@ -4277,8 +4366,8 @@ public BatchQueueResourcePolicy getBatchQueueResourcePolicyWithAuth(AuthzToken a try { if (ServerSettings.isEnableSharing()) { BatchQueueResourcePolicy batchQueueResourcePolicy = getBatchQueueResourcePolicy(resourcePolicyId); - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); if (!userHasAccess( gatewayId, userId + "@" + gatewayId, @@ -4292,7 +4381,7 @@ public BatchQueueResourcePolicy getBatchQueueResourcePolicyWithAuth(AuthzToken a } catch (AuthorizationException e) { throw e; } catch (Throwable e) { - String msg = "Error retrieving batch queue resource policy. ResourcePolicyId: " + resourcePolicyId; + var msg = "Error retrieving batch queue resource policy. ResourcePolicyId: " + resourcePolicyId; logger.error(msg, e); throw convertException(e, msg); } @@ -4310,12 +4399,12 @@ public void updateGroupResourceProfileWithAuth(AuthzToken authzToken, GroupResou } updateGroupResourceProfile(groupResourceProfile); } catch (AuthorizationException e) { - String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); + var userName = authzToken.getClaimsMap().get(Constants.USER_NAME); logger.info("User " + userName + " not allowed access to update GroupResourceProfile " + groupResourceProfile.getGroupResourceProfileId() + ", reason: " + e.getMessage()); throw e; } catch (Throwable e) { - String msg = "Error updating group resource profile. groupResourceProfileId: " + var msg = "Error updating group resource profile. groupResourceProfileId: " + groupResourceProfile.getGroupResourceProfileId(); logger.error(msg, e); throw convertException(e, msg); @@ -4323,11 +4412,11 @@ public void updateGroupResourceProfileWithAuth(AuthzToken authzToken, GroupResou } public List getGroupComputeResourcePrefListWithAuth( - AuthzToken authzToken, String groupResourceProfileId) { + AuthzToken authzToken, String groupResourceProfileId) throws AuthorizationException { try { if (ServerSettings.isEnableSharing()) { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); if (!userHasAccess(gatewayId, userId + "@" + gatewayId, groupResourceProfileId, gatewayId + ":READ")) { throw new AuthorizationException( "User does not have permission to access group resource profile"); @@ -4337,7 +4426,7 @@ public List getGroupComputeResourcePrefListWithA } catch (AuthorizationException e) { throw e; } catch (Throwable e) { - String msg = "Error retrieving Group compute resource preference. GroupResourceProfileId: " + var msg = "Error retrieving Group compute resource preference. GroupResourceProfileId: " + groupResourceProfileId; logger.error(msg, e); throw convertException(e, msg); @@ -4345,11 +4434,11 @@ public List getGroupComputeResourcePrefListWithA } public List getGroupBatchQueueResourcePolicyListWithAuth( - AuthzToken authzToken, String groupResourceProfileId) { + AuthzToken authzToken, String groupResourceProfileId) throws AuthorizationException { try { if (ServerSettings.isEnableSharing()) { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); if (!userHasAccess(gatewayId, userId + "@" + gatewayId, groupResourceProfileId, gatewayId + ":READ")) { throw new AuthorizationException( "User does not have permission to access group resource profile"); @@ -4359,7 +4448,7 @@ public List getGroupBatchQueueResourcePolicyListWithAu } catch (AuthorizationException e) { throw e; } catch (Throwable e) { - String msg = "Error retrieving Group batch queue resource policy list. GroupResourceProfileId: " + var msg = "Error retrieving Group batch queue resource policy list. GroupResourceProfileId: " + groupResourceProfileId; logger.error(msg, e); throw convertException(e, msg); @@ -4367,11 +4456,11 @@ public List getGroupBatchQueueResourcePolicyListWithAu } public List getGroupComputeResourcePolicyListWithAuth( - AuthzToken authzToken, String groupResourceProfileId) { + AuthzToken authzToken, String groupResourceProfileId) throws AuthorizationException { try { if (ServerSettings.isEnableSharing()) { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - String userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); if (!userHasAccess(gatewayId, userId + "@" + gatewayId, groupResourceProfileId, gatewayId + ":READ")) { throw new AuthorizationException( "User does not have permission to access group resource profile"); @@ -4381,7 +4470,7 @@ public List getGroupComputeResourcePolicyListWithAuth( } catch (AuthorizationException e) { throw e; } catch (Throwable e) { - String msg = "Error retrieving Group compute resource policy list. GroupResourceProfileId: " + var msg = "Error retrieving Group compute resource policy list. GroupResourceProfileId: " + groupResourceProfileId; logger.error(msg, e); throw convertException(e, msg); @@ -4391,16 +4480,16 @@ public List getGroupComputeResourcePolicyListWithAuth( public String createGroupResourceProfileWithAuth(AuthzToken authzToken, GroupResourceProfile groupResourceProfile) throws AuthorizationException { try { - String result = createGroupResourceProfileWithSharing(authzToken, groupResourceProfile); + var result = createGroupResourceProfileWithSharing(authzToken, groupResourceProfile); return result; } catch (AuthorizationException e) { - String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); + var userName = authzToken.getClaimsMap().get(Constants.USER_NAME); logger.info("User " + userName + " not allowed access to resources referenced in this GroupResourceProfile. Reason: " + e.getMessage()); throw e; } catch (Throwable e) { - String msg = "Error creating group resource profile."; + var msg = "Error creating group resource profile."; logger.error(msg, e); throw convertException(e, msg); } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/CredentialStoreService.java b/airavata-api/src/main/java/org/apache/airavata/service/CredentialStoreService.java index 6d07d279a1..6e0e5a5172 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/CredentialStoreService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/CredentialStoreService.java @@ -33,7 +33,6 @@ import org.apache.airavata.credential.store.credential.CommunityUser; import org.apache.airavata.credential.store.credential.Credential; import org.apache.airavata.credential.store.credential.CredentialOwnerType; -import org.apache.airavata.credential.store.store.CredentialStoreException; import org.apache.airavata.credential.store.store.impl.CertificateCredentialWriter; import org.apache.airavata.credential.store.store.impl.CredentialReaderImpl; import org.apache.airavata.credential.store.store.impl.SSHCredentialWriter; @@ -73,7 +72,10 @@ public CredentialStoreService() private org.apache.airavata.credential.store.exception.CredentialStoreException convertException(Throwable e, String msg) { logger.error(msg, e); - return new org.apache.airavata.credential.store.exception.CredentialStoreException(msg); + org.apache.airavata.credential.store.exception.CredentialStoreException exception = + new org.apache.airavata.credential.store.exception.CredentialStoreException(msg); + exception.initCause(e); + return exception; } public String addSSHCredential(SSHCredential sshCredential) throws org.apache.airavata.credential.store.exception.CredentialStoreException { @@ -107,7 +109,7 @@ public String addSSHCredential(SSHCredential sshCredential) throws org.apache.ai } public String addCertificateCredential(CertificateCredential certificateCredential) - throws CredentialStoreException { + throws org.apache.airavata.credential.store.exception.CredentialStoreException { try { org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential credential = new org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential(); @@ -132,16 +134,12 @@ public String addCertificateCredential(CertificateCredential certificateCredenti credential.setCertificates(certificates); certificateCredentialWriter.writeCredentials(credential); return token; - } catch (CredentialStoreException e) { - logger.error("Error occurred while saving Certificate Credentials.", e); - throw new CredentialStoreException("Error occurred while saving Certificate Credentials.", e); - } catch (Exception e) { - logger.error("Error occurred while converting to X509 certificate.", e); - throw new CredentialStoreException("Error occurred while converting to X509 certificate..", e); + } catch (Throwable e) { + throw convertException(e, "Error occurred while saving Certificate Credentials."); } } - public String addPasswordCredential(PasswordCredential passwordCredential) throws CredentialStoreException { + public String addPasswordCredential(PasswordCredential passwordCredential) throws org.apache.airavata.credential.store.exception.CredentialStoreException { try { org.apache.airavata.credential.store.credential.impl.password.PasswordCredential credential = new org.apache.airavata.credential.store.credential.impl.password.PasswordCredential(); @@ -154,16 +152,12 @@ public String addPasswordCredential(PasswordCredential passwordCredential) throw credential.setToken(token); sshCredentialWriter.writeCredentials(credential); return token; - } catch (CredentialStoreException e) { - logger.error("Error occurred while saving PWD Credentials.", e); - throw new CredentialStoreException("Error occurred while saving PWD Credentials.", e); - } catch (Exception e) { - logger.error("Error occurred while registering PWD Credentials.", e); - throw new CredentialStoreException("Error occurred while registering PWD Credentials..", e); + } catch (Throwable e) { + throw convertException(e, "Error occurred while saving PWD Credentials."); } } - public SSHCredential getSSHCredential(String tokenId, String gatewayId) throws CredentialStoreException { + public SSHCredential getSSHCredential(String tokenId, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException { try { Credential credential = credentialReader.getCredential(gatewayId, tokenId); if (credential instanceof org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential @@ -188,17 +182,13 @@ public SSHCredential getSSHCredential(String tokenId, String gatewayId) throws C + gatewayId); return null; } - } catch (CredentialStoreException e) { - logger.error( - "Error occurred while retrieving SSH credentialfor token - " + tokenId + " and gateway id - " - + gatewayId, - e); - throw new CredentialStoreException("Error occurred while retrieving SSH credential for token - " + tokenId - + " and gateway id - " + gatewayId, e); + } catch (Throwable e) { + throw convertException(e, "Error occurred while retrieving SSH credential for token - " + tokenId + + " and gateway id - " + gatewayId); } } - public CredentialSummary getCredentialSummary(String tokenId, String gatewayId) throws CredentialStoreException { + public CredentialSummary getCredentialSummary(String tokenId, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException { try { Credential credential = credentialReader.getCredential(gatewayId, tokenId); if (isSSHCredential(credential)) { @@ -212,17 +202,19 @@ public CredentialSummary getCredentialSummary(String tokenId, String gatewayId) return convertToCredentialSummary( (org.apache.airavata.credential.store.credential.impl.password.PasswordCredential) credential); } - throw new CredentialStoreException("Unrecognized type of credential for token: " + tokenId); - } catch (CredentialStoreException e) { + throw convertException(new RuntimeException("Unrecognized type of credential for token: " + tokenId), + "Unrecognized type of credential for token: " + tokenId); + } catch (org.apache.airavata.credential.store.exception.CredentialStoreException e) { + throw e; + } catch (Throwable e) { final String msg = "Error occurred while retrieving credential summary for token - " + tokenId + " and gateway id - " + gatewayId; - logger.error(msg, e); - throw new CredentialStoreException(msg); + throw convertException(e, msg); } } public List getAllCredentialSummaries( - SummaryType type, List accessibleTokenIds, String gatewayId) throws CredentialStoreException { + SummaryType type, List accessibleTokenIds, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException { try { List credentials = credentialReader.getAllAccessibleCredentialsPerGateway(gatewayId, accessibleTokenIds); @@ -248,13 +240,15 @@ public List getAllCredentialSummaries( .map(cred -> convertToCredentialSummary(cred)) .collect(Collectors.toList()); } else { - throw new RuntimeException("Summary Type " + type + " is not supported."); + throw convertException(new RuntimeException("Summary Type " + type + " is not supported."), + "Summary Type " + type + " is not supported."); } - } catch (CredentialStoreException e) { + } catch (org.apache.airavata.credential.store.exception.CredentialStoreException e) { + throw e; + } catch (Throwable e) { final String msg = "Error occurred while retrieving " + type + " credential Summary for tokens - " + accessibleTokenIds + " and gateway id - " + gatewayId; - logger.error(msg, e); - throw new CredentialStoreException(msg, e); + throw convertException(e, msg); } } @@ -312,7 +306,7 @@ private CredentialSummary convertToCredentialSummary( } public CertificateCredential getCertificateCredential(String tokenId, String gatewayId) - throws CredentialStoreException { + throws org.apache.airavata.credential.store.exception.CredentialStoreException { try { Credential credential = credentialReader.getCredential(gatewayId, tokenId); if (credential @@ -344,17 +338,13 @@ public CertificateCredential getCertificateCredential(String tokenId, String gat + gatewayId); return null; } - } catch (CredentialStoreException e) { - logger.error( - "Error occurred while retrieving Certificate credential for token - " + tokenId - + " and gateway id - " + gatewayId, - e); - throw new CredentialStoreException("Error occurred while retrieving Certificate credential for token - " - + tokenId + " and gateway id - " + gatewayId, e); + } catch (Throwable e) { + throw convertException(e, "Error occurred while retrieving Certificate credential for token - " + + tokenId + " and gateway id - " + gatewayId); } } - public PasswordCredential getPasswordCredential(String tokenId, String gatewayId) throws CredentialStoreException { + public PasswordCredential getPasswordCredential(String tokenId, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException { try { Credential credential = credentialReader.getCredential(gatewayId, tokenId); if (credential @@ -376,19 +366,15 @@ public PasswordCredential getPasswordCredential(String tokenId, String gatewayId + gatewayId); return null; } - } catch (CredentialStoreException e) { - logger.error( - "Error occurred while retrieving PWD credentialfor token - " + tokenId + " and gateway id - " - + gatewayId, - e); - throw new CredentialStoreException("Error occurred while retrieving PWD credential for token - " + tokenId - + " and gateway id - " + gatewayId, e); + } catch (Throwable e) { + throw convertException(e, "Error occurred while retrieving PWD credential for token - " + tokenId + + " and gateway id - " + gatewayId); } } @Deprecated public List getAllCredentialSummaryForGateway(SummaryType type, String gatewayId) - throws CredentialStoreException { + throws org.apache.airavata.credential.store.exception.CredentialStoreException { if (type.equals(SummaryType.SSH)) { Map sshKeyMap = new HashMap<>(); List summaryList = new ArrayList<>(); @@ -415,9 +401,8 @@ public List getAllCredentialSummaryForGateway(SummaryType typ } } } - } catch (CredentialStoreException e) { - logger.error("Error occurred while retrieving credential Summary", e); - throw new CredentialStoreException("Error occurred while retrieving credential Summary", e); + } catch (Throwable e) { + throw convertException(e, "Error occurred while retrieving credential Summary"); } return summaryList; } else { @@ -428,7 +413,7 @@ public List getAllCredentialSummaryForGateway(SummaryType typ @Deprecated public List getAllCredentialSummaryForUserInGateway( - SummaryType type, String gatewayId, String userId) throws CredentialStoreException { + SummaryType type, String gatewayId, String userId) throws org.apache.airavata.credential.store.exception.CredentialStoreException { if (type.equals(SummaryType.SSH)) { Map sshKeyMap = new HashMap<>(); List summaryList = new ArrayList<>(); @@ -467,9 +452,8 @@ public List getAllCredentialSummaryForUserInGateway( } } } - } catch (CredentialStoreException e) { - logger.error("Error occurred while retrieving credential Summary", e); - throw new CredentialStoreException("Error occurred while retrieving credential Summary", e); + } catch (Throwable e) { + throw convertException(e, "Error occurred while retrieving credential Summary"); } return summaryList; } else { @@ -480,7 +464,7 @@ public List getAllCredentialSummaryForUserInGateway( } @Deprecated - public Map getAllPWDCredentialsForGateway(String gatewayId) throws CredentialStoreException { + public Map getAllPWDCredentialsForGateway(String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException { Map pwdCredMap = new HashMap<>(); try { List allCredentials = credentialReader.getAllCredentialsPerGateway(gatewayId); @@ -498,38 +482,29 @@ public Map getAllPWDCredentialsForGateway(String gatewayId) thro } } } - } catch (CredentialStoreException e) { - logger.error("Error occurred while retrieving credentials", e); - throw new CredentialStoreException("Error occurred while retrieving credentials", e); + } catch (Throwable e) { + throw convertException(e, "Error occurred while retrieving credentials"); } return pwdCredMap; } - public boolean deleteSSHCredential(String tokenId, String gatewayId) throws CredentialStoreException { + public boolean deleteSSHCredential(String tokenId, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException { try { credentialReader.removeCredentials(gatewayId, tokenId); return true; - } catch (CredentialStoreException e) { - logger.error( - "Error occurred while deleting SSH credential for token - " + tokenId + " and gateway id - " - + gatewayId, - e); - throw new CredentialStoreException("Error occurred while deleting SSH credential for token - " + tokenId - + " and gateway id - " + gatewayId, e); + } catch (Throwable e) { + throw convertException(e, "Error occurred while deleting SSH credential for token - " + tokenId + + " and gateway id - " + gatewayId); } } - public boolean deletePWDCredential(String tokenId, String gatewayId) throws CredentialStoreException { + public boolean deletePWDCredential(String tokenId, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException { try { credentialReader.removeCredentials(gatewayId, tokenId); return true; - } catch (CredentialStoreException e) { - logger.error( - "Error occurred while deleting PWD credential for token - " + tokenId + " and gateway id - " - + gatewayId, - e); - throw new CredentialStoreException("Error occurred while deleting PWD credential for token - " + tokenId - + " and gateway id - " + gatewayId, e); + } catch (Throwable e) { + throw convertException(e, "Error occurred while deleting PWD credential for token - " + tokenId + + " and gateway id - " + gatewayId); } } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/GroupManagerService.java b/airavata-api/src/main/java/org/apache/airavata/service/GroupManagerService.java index 5989f072d5..c76dbffe55 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/GroupManagerService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/GroupManagerService.java @@ -48,7 +48,7 @@ public class GroupManagerService { private GroupManagerServiceException convertException(Throwable e, String msg) { logger.error(msg, e); - GroupManagerServiceException exception = new GroupManagerServiceException(); + var exception = new GroupManagerServiceException(); exception.setMessage(msg + ". More info : " + e.getMessage()); exception.initCause(e); return exception; @@ -57,28 +57,28 @@ private GroupManagerServiceException convertException(Throwable e, String msg) { public String createGroup(AuthzToken authzToken, GroupModel groupModel) throws GroupManagerServiceException { try { // TODO Validations for authorization - SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); + var sharingClient = getSharingRegistryServiceClient(); - UserGroup sharingUserGroup = new UserGroup(); + var sharingUserGroup = new UserGroup(); sharingUserGroup.setGroupId(UUID.randomUUID().toString()); sharingUserGroup.setName(groupModel.getName()); sharingUserGroup.setDescription(groupModel.getDescription()); sharingUserGroup.setGroupType(GroupType.USER_LEVEL_GROUP); sharingUserGroup.setGroupCardinality(GroupCardinality.MULTI_USER); - String gatewayId = getDomainId(authzToken); + var gatewayId = getDomainId(authzToken); sharingUserGroup.setDomainId(gatewayId); sharingUserGroup.setOwnerId(getUserId(authzToken)); - String groupId = sharingClient.createGroup(sharingUserGroup); + var groupId = sharingClient.createGroup(sharingUserGroup); internalAddUsersToGroup(sharingClient, gatewayId, groupModel.getMembers(), groupId); if (groupModel.getAdmins() != null && !groupModel.getAdmins().isEmpty()) { sharingClient.addGroupAdmins(gatewayId, groupId, groupModel.getAdmins()); } return groupId; } catch (Exception e) { - String msg = "Error Creating Group"; + var msg = "Error Creating Group"; logger.error(msg, e); - GroupManagerServiceException exception = new GroupManagerServiceException(); + var exception = new GroupManagerServiceException(); exception.setMessage(msg + " More info : " + e.getMessage()); exception.initCause(e); throw exception; @@ -87,15 +87,15 @@ public String createGroup(AuthzToken authzToken, GroupModel groupModel) throws G public boolean updateGroup(AuthzToken authzToken, GroupModel groupModel) throws GroupManagerServiceException { try { - SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); - String userId = getUserId(authzToken); - String domainId = getDomainId(authzToken); + var sharingClient = getSharingRegistryServiceClient(); + var userId = getUserId(authzToken); + var domainId = getDomainId(authzToken); if (!(sharingClient.hasOwnerAccess(domainId, groupModel.getId(), userId) || sharingClient.hasAdminAccess(domainId, groupModel.getId(), userId))) { throw new GroupManagerServiceException("User does not have permission to update group"); } - UserGroup sharingUserGroup = new UserGroup(); + var sharingUserGroup = new UserGroup(); sharingUserGroup.setGroupId(groupModel.getId()); sharingUserGroup.setName(groupModel.getName()); sharingUserGroup.setDescription(groupModel.getDescription()); diff --git a/airavata-api/src/main/java/org/apache/airavata/service/IamAdminService.java b/airavata-api/src/main/java/org/apache/airavata/service/IamAdminService.java index a120204a9a..9c89f5bb2a 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/IamAdminService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/IamAdminService.java @@ -54,32 +54,32 @@ public class IamAdminService { private IamAdminServicesException convertException(Throwable e, String msg) { logger.error(msg, e); - IamAdminServicesException exception = new IamAdminServicesException(msg + ". More info : " + e.getMessage()); + var exception = new IamAdminServicesException(msg + ". More info : " + e.getMessage()); exception.initCause(e); return exception; } public Gateway setUpGateway(AuthzToken authzToken, Gateway gateway) throws IamAdminServicesException { - TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl(); - PasswordCredential isSuperAdminCredentials = getSuperAdminPasswordCredential(); + var keycloakclient = new TenantManagementKeycloakImpl(); + var isSuperAdminCredentials = getSuperAdminPasswordCredential(); try { keycloakclient.addTenant(isSuperAdminCredentials, gateway); // Load the tenant admin password stored in gateway request - CredentialStoreService.Client credentialStoreClient = getCredentialStoreServiceClient(); + var credentialStoreClient = getCredentialStoreServiceClient(); // Admin password token should already be stored under requested gateway's gatewayId - PasswordCredential tenantAdminPasswordCredential = credentialStoreClient.getPasswordCredential( + var tenantAdminPasswordCredential = credentialStoreClient.getPasswordCredential( gateway.getIdentityServerPasswordToken(), gateway.getGatewayId()); if (!keycloakclient.createTenantAdminAccount( isSuperAdminCredentials, gateway, tenantAdminPasswordCredential.getPassword())) { logger.error("Admin account creation failed !!, please refer error logs for reason"); } - Gateway gatewayWithIdAndSecret = keycloakclient.configureClient(isSuperAdminCredentials, gateway); + var gatewayWithIdAndSecret = keycloakclient.configureClient(isSuperAdminCredentials, gateway); return gatewayWithIdAndSecret; } catch (TException | ApplicationSettingsException ex) { logger.error("Gateway Setup Failed, reason: " + ex.getMessage(), ex); - IamAdminServicesException iamAdminServicesException = new IamAdminServicesException("Gateway Setup Failed, reason: " + ex.getMessage()); + var iamAdminServicesException = new IamAdminServicesException("Gateway Setup Failed, reason: " + ex.getMessage()); iamAdminServicesException.initCause(ex); throw iamAdminServicesException; } @@ -87,8 +87,8 @@ public Gateway setUpGateway(AuthzToken authzToken, Gateway gateway) throws IamAd public boolean isUsernameAvailable(AuthzToken authzToken, String username) throws IamAdminServicesException { try { - TenantManagementKeycloakImpl keycloakClient = new TenantManagementKeycloakImpl(); - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + var keycloakClient = new TenantManagementKeycloakImpl(); + var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); return keycloakClient.isUsernameAvailable(authzToken.getAccessToken(), gatewayId, username); } catch (IamAdminServicesException e) { throw e; diff --git a/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorRegistryService.java b/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorRegistryService.java index c734011a72..db01ca82a2 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorRegistryService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorRegistryService.java @@ -73,6 +73,10 @@ public ExperimentStatus getExperimentStatus(String airavataExperimentId) throws return registryService.getExperimentStatus(airavataExperimentId); } + public void updateExperimentStatus(ExperimentStatus experimentStatus, String experimentId) throws RegistryException { + registryService.updateExperimentStatus(experimentStatus, experimentId); + } + public String addProcess(ProcessModel processModel, String experimentId) throws RegistryException { return registryService.addProcess(processModel, experimentId); } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorService.java b/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorService.java index d1af731fea..84e4f6fdc3 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorService.java @@ -19,6 +19,7 @@ */ package org.apache.airavata.service; +import java.lang.reflect.InvocationTargetException; import java.text.MessageFormat; import java.util.*; import org.apache.airavata.common.logging.MDCUtil; @@ -46,10 +47,6 @@ import org.apache.airavata.model.experiment.ExperimentModel; import org.apache.airavata.model.experiment.ExperimentType; import org.apache.airavata.model.experiment.UserConfigurationDataModel; -import org.apache.airavata.model.messaging.event.ExperimentIntermediateOutputsEvent; -import org.apache.airavata.model.messaging.event.ExperimentSubmitEvent; -import org.apache.airavata.model.messaging.event.ProcessIdentifier; -import org.apache.airavata.model.messaging.event.ProcessStatusChangeEvent; import org.apache.airavata.model.process.ProcessModel; import org.apache.airavata.model.scheduling.ComputationalResourceSchedulingModel; import org.apache.airavata.model.status.ExperimentState; @@ -63,7 +60,7 @@ import org.apache.airavata.orchestrator.core.schedule.HostScheduler; import org.apache.airavata.orchestrator.core.utils.OrchestratorConstants; import org.apache.airavata.orchestrator.cpi.impl.SimpleOrchestratorImpl; -import org.apache.airavata.orchestrator.util.OrchestratorUtils; +import org.apache.airavata.registry.cpi.AppCatalogException; import org.apache.airavata.registry.cpi.RegistryException; import org.apache.commons.lang3.StringUtils; import org.apache.curator.framework.CuratorFramework; @@ -78,14 +75,12 @@ import org.apache.airavata.common.logging.MDCConstants; import org.apache.airavata.messaging.core.MessageHandler; import org.apache.airavata.messaging.core.MessagingFactory; -import org.apache.airavata.messaging.core.Publisher; import org.apache.airavata.messaging.core.Subscriber; import org.apache.airavata.messaging.core.Type; import org.apache.airavata.model.messaging.event.*; import org.apache.curator.RetryPolicy; import org.apache.curator.framework.CuratorFrameworkFactory; import org.apache.curator.retry.ExponentialBackoffRetry; -import org.apache.thrift.TBase; import org.slf4j.MDC; public class OrchestratorService { @@ -95,21 +90,19 @@ public class OrchestratorService { private SimpleOrchestratorImpl orchestrator; private CuratorFramework curatorClient; private Publisher publisher; - private Subscriber statusSubscribe; private Subscriber experimentSubscriber; - private String airavataUserName; - private String gatewayName; + // private String airavataUserName; + // private String gatewayName; public OrchestratorService() throws OrchestratorException { try { this.orchestratorRegistryService = new OrchestratorRegistryService(); - setAiravataUserName(ServerSettings.getDefaultUser()); + // setAiravataUserName(ServerSettings.getDefaultUser()); this.orchestrator = new SimpleOrchestratorImpl(); this.publisher = MessagingFactory.getPublisher(Type.STATUS); this.orchestrator.initialize(); this.orchestrator.getOrchestratorContext().setPublisher(this.publisher); startCurator(); - this.statusSubscribe = getStatusSubscriber(); this.experimentSubscriber = getExperimentSubscriber(); } catch (Exception e) { throw new OrchestratorException("Error initializing OrchestratorService", e); @@ -152,7 +145,7 @@ public boolean launchExperiment(String experimentId, String gatewayId) throws Ex experimentId, "Couldn't identify experiment type, experiment {} is neither single application nor workflow.", experimentId); - throw new TException("Experiment '" + experimentId + throw new OrchestratorException("Experiment '" + experimentId + "' launch failed. Unable to figureout execution type for application " + experiment.getExecutionId()); } @@ -186,7 +179,7 @@ private boolean launchSingleAppExperiment( ExperimentStatus status = new ExperimentStatus(ExperimentState.SCHEDULED); status.setReason("Compute resources are not ready"); status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime()); - OrchestratorUtils.updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); + updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); logger.info("expId: {}, Scheduled experiment ", experimentId); return false; } @@ -244,11 +237,11 @@ private void resolveInputReplicas(ProcessModel processModel) throws Exception { } public String getCredentialToken(ExperimentModel experiment, UserConfigurationDataModel userConfigurationData) - throws Exception { + throws OrchestratorException, AppCatalogException { String token = null; final String groupResourceProfileId = userConfigurationData.getGroupResourceProfileId(); if (groupResourceProfileId == null) { - throw new Exception( + throw new OrchestratorException( "Experiment not configured with a Group Resource Profile: " + experiment.getExperimentId()); } @@ -273,7 +266,7 @@ public String getCredentialToken(ExperimentModel experiment, UserConfigurationDa token = groupResourceProfile.getDefaultCredentialStoreToken(); } if (token == null || token.isEmpty()) { - throw new Exception( + throw new OrchestratorException( "You have not configured credential store token at group resource profile or compute resource preference." + " Please provide the correct token at group resource profile or compute resource preference."); } @@ -281,13 +274,13 @@ public String getCredentialToken(ExperimentModel experiment, UserConfigurationDa } public boolean validateExperiment(String experimentId) - throws TException, LaunchValidationException, RegistryException, OrchestratorException { + throws LaunchValidationException, RegistryException, OrchestratorException { ExperimentModel experimentModel = orchestratorRegistryService.getExperiment(experimentId); return orchestrator.validateExperiment(experimentModel).isValidationState(); } public boolean validateProcess(String experimentId, List processes) - throws LaunchValidationException, TException, RegistryException, OrchestratorException { + throws LaunchValidationException, RegistryException, OrchestratorException { ExperimentModel experimentModel = orchestratorRegistryService.getExperiment(experimentId); for (ProcessModel processModel : processes) { boolean state = @@ -299,12 +292,12 @@ public boolean validateProcess(String experimentId, List processes return true; } - public boolean terminateExperiment(String experimentId, String gatewayId) throws Exception { + public boolean terminateExperiment(String experimentId, String gatewayId) throws RegistryException, OrchestratorException, AppCatalogException { logger.info(experimentId, "Experiment: {} is cancelling !!!!!", experimentId); return validateStatesAndCancel(experimentId, gatewayId); } - private boolean validateStatesAndCancel(String experimentId, String gatewayId) throws Exception { + private boolean validateStatesAndCancel(String experimentId, String gatewayId) throws RegistryException, OrchestratorException, AppCatalogException { ExperimentStatus experimentStatus = orchestratorRegistryService.getExperimentStatus(experimentId); switch (experimentStatus.getState()) { case COMPLETED: @@ -346,17 +339,28 @@ private boolean validateStatesAndCancel(String experimentId, String gatewayId) t String expCancelNodePath = ZKPaths.makePath( ZKPaths.makePath(ZkConstants.ZOOKEEPER_EXPERIMENT_NODE, experimentId), ZkConstants.ZOOKEEPER_CANCEL_LISTENER_NODE); - Stat stat = curatorClient.checkExists().forPath(expCancelNodePath); + Stat stat; + try { + stat = curatorClient.checkExists().forPath(expCancelNodePath); + } catch (Exception e) { + logger.error("Error checking existence of Zookeeper node: " + expCancelNodePath, e); + throw new OrchestratorException("Error checking existence of Zookeeper node: " + expCancelNodePath, e); + } if (stat != null) { - curatorClient - .setData() - .withVersion(-1) - .forPath(expCancelNodePath, ZkConstants.ZOOKEEPER_CANCEL_REQEUST.getBytes()); + try { + curatorClient + .setData() + .withVersion(-1) + .forPath(expCancelNodePath, ZkConstants.ZOOKEEPER_CANCEL_REQEUST.getBytes()); + } catch (Exception e) { + logger.error("Error setting data for Zookeeper node: " + expCancelNodePath, e); + throw new OrchestratorException("Error setting data for Zookeeper node: " + expCancelNodePath, e); + } ExperimentStatus status = new ExperimentStatus(ExperimentState.CANCELING); status.setReason("Experiment cancel request processed"); status.setTimeOfStateChange( AiravataUtils.getCurrentTimestamp().getTime()); - OrchestratorUtils.updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); + updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); logger.info("expId : " + experimentId + " :- Experiment status updated to " + status.getState()); } return true; @@ -364,12 +368,12 @@ private boolean validateStatesAndCancel(String experimentId, String gatewayId) t } public void fetchIntermediateOutputs(String experimentId, String gatewayId, List outputNames) - throws Exception { + throws RegistryException, OrchestratorException, AppCatalogException { submitIntermediateOutputsProcess(experimentId, gatewayId, outputNames); } private void submitIntermediateOutputsProcess(String experimentId, String gatewayId, List outputNames) - throws Exception { + throws RegistryException, OrchestratorException, AppCatalogException { ExperimentModel experimentModel = orchestratorRegistryService.getExperiment(experimentId); ProcessModel processModel = ExperimentModelUtil.cloneProcessFromExperiment(experimentModel); @@ -393,7 +397,7 @@ private void submitIntermediateOutputsProcess(String experimentId, String gatewa .filter(p -> p.getTasks().stream().anyMatch(t -> t.getTaskType() == TaskTypes.JOB_SUBMISSION)) .findFirst(); if (!jobSubmissionProcess.isPresent()) { - throw new Exception(MessageFormat.format( + throw new OrchestratorException(MessageFormat.format( "Could not find job submission process for experiment {0}, unable to fetch intermediate outputs {1}", experimentId, outputNames)); } @@ -405,7 +409,7 @@ private void submitIntermediateOutputsProcess(String experimentId, String gatewa String token = getCredentialToken(experimentModel, experimentModel.getUserConfigurationData()); orchestrator.launchProcess(processModel, token); - } catch (Exception e) { + } catch (RegistryException | OrchestratorException | AppCatalogException e) { logger.error("Failed to launch process for intermediate output fetching", e); ProcessStatus status = new ProcessStatus(ProcessState.FAILED); @@ -417,7 +421,7 @@ private void submitIntermediateOutputsProcess(String experimentId, String gatewa } } - public boolean launchProcess(String processId, String airavataCredStoreToken, String gatewayId) throws Exception { + public boolean launchProcess(String processId, String airavataCredStoreToken, String gatewayId) throws RegistryException, OrchestratorException, AppCatalogException { ProcessStatus processStatus = orchestratorRegistryService.getProcessStatus(processId); switch (processStatus.getState()) { @@ -452,13 +456,13 @@ public boolean launchProcess(String processId, String airavataCredStoreToken, St } private ApplicationDeploymentDescription getAppDeployment(ProcessModel processModel, String applicationId) - throws Exception { + throws OrchestratorException, AppCatalogException { String selectedModuleId = getModuleId(applicationId); return getAppDeploymentForModule(processModel, selectedModuleId); } private ApplicationDeploymentDescription getAppDeploymentForModule( - ProcessModel processModel, String selectedModuleId) throws Exception { + ProcessModel processModel, String selectedModuleId) throws OrchestratorException, AppCatalogException { List applicationDeployements = orchestratorRegistryService.getApplicationDeployments(selectedModuleId); @@ -473,14 +477,19 @@ private ApplicationDeploymentDescription getAppDeploymentForModule( } List computeHostList = Arrays.asList(deploymentMap.keySet().toArray(new ComputeResourceDescription[] {})); - Class aClass = - Class.forName(ServerSettings.getHostScheduler()).asSubclass(HostScheduler.class); - HostScheduler hostScheduler = aClass.newInstance(); + HostScheduler hostScheduler; + try { + var schedulerClass = Class.forName(ServerSettings.getHostScheduler()).asSubclass(HostScheduler.class); + hostScheduler = schedulerClass.getDeclaredConstructor().newInstance(); + } catch (ClassNotFoundException | ApplicationSettingsException | NoSuchMethodException + | InstantiationException | IllegalAccessException | InvocationTargetException e) { + throw new OrchestratorException("Failed to instantiate HostScheduler", e); + } ComputeResourceDescription ComputeResourceDescription = hostScheduler.schedule(computeHostList); return deploymentMap.get(ComputeResourceDescription); } - private String getModuleId(String applicationId) throws Exception { + private String getModuleId(String applicationId) throws OrchestratorException, AppCatalogException { ApplicationInterfaceDescription applicationInterface = orchestratorRegistryService.getApplicationInterface(applicationId); List applicationModules = applicationInterface.getApplicationModules(); @@ -492,7 +501,7 @@ private String getModuleId(String applicationId) throws Exception { } private void launchWorkflowExperiment(String experimentId, String airavataCredStoreToken, String gatewayId) - throws TException { + throws OrchestratorException { throw new UnsupportedOperationException("Workflow support not implemented"); } @@ -530,16 +539,16 @@ public boolean launchSingleAppExperimentInternal( launchProcess(processId, airavataCredStoreToken, gatewayId); } return true; - } catch (org.apache.airavata.registry.cpi.RegistryException e) { + } catch (RegistryException e) { ExperimentStatus status = new ExperimentStatus(ExperimentState.FAILED); status.setReason("Error while retrieving process IDs"); - OrchestratorUtils.updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); + updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); logger.error("expId: " + experimentId + ", Error while retrieving process IDs", e); throw new Exception("Error while retrieving process IDs", e); } catch (Exception e) { ExperimentStatus status = new ExperimentStatus(ExperimentState.FAILED); status.setReason("Error while launching processes"); - OrchestratorUtils.updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); + updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); logger.error("expId: " + experimentId + ", Error while launching processes", e); throw e; } @@ -559,7 +568,7 @@ public void launchQueuedExperiment(String experimentId) throws Exception { ExperimentStatus status = new ExperimentStatus(ExperimentState.LAUNCHED); status.setReason("submitted all processes"); status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime()); - OrchestratorUtils.updateAndPublishExperimentStatus(experimentId, status, publisher, experiment.getGatewayId()); + updateAndPublishExperimentStatus(experimentId, status, publisher, experiment.getGatewayId()); logger.info("expId: {}, Launched experiment ", experimentId); // Launch processes @@ -640,7 +649,7 @@ public void handleProcessStatusChange( if (status.getState() != null) { status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime()); - OrchestratorUtils.updateAndPublishExperimentStatus( + updateAndPublishExperimentStatus( processIdentity.getExperimentId(), status, publisher, processIdentity.getGatewayId()); logger.info("expId : " + processIdentity.getExperimentId() + " :- Experiment status updated to " + status.getState()); @@ -671,9 +680,9 @@ private void registerQueueStatusForRequeue(String experimentId) { orchestratorRegistryService.registerQueueStatuses(queueStatusModels); } } - } catch (org.apache.airavata.registry.cpi.RegistryException e) { + } catch (RegistryException e) { logger.error("Error while registering queue statuses", e); - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + } catch (AppCatalogException e) { logger.error("Error while getting compute resource for queue status", e); } } @@ -708,13 +717,45 @@ public void handleCancelExperiment(ExperimentSubmitEvent expEvent) throws Except terminateExperiment(expEvent.getExperimentId(), expEvent.getGatewayId()); } - public void handleIntermediateOutputsEvent(ExperimentIntermediateOutputsEvent event) throws Exception { - fetchIntermediateOutputs(event.getExperimentId(), event.getGatewayId(), event.getOutputNames()); + public void handleIntermediateOutputsEvent(ExperimentIntermediateOutputsEvent event) { + try { + fetchIntermediateOutputs(event.getExperimentId(), event.getGatewayId(), event.getOutputNames()); + } catch (Exception e) { + logger.error("Error handling intermediate outputs event", e); + throw new RuntimeException("Error handling intermediate outputs event", e); + } + } + + private void updateAndPublishExperimentStatus( + String experimentId, ExperimentStatus status, Publisher publisher, String gatewayId) { + try { + orchestratorRegistryService.updateExperimentStatus(status, experimentId); + ExperimentStatusChangeEvent event = + new ExperimentStatusChangeEvent(status.getState(), experimentId, gatewayId); + String messageId = AiravataUtils.getId("EXPERIMENT"); + MessageContext messageContext = new MessageContext(event, MessageType.EXPERIMENT, messageId, gatewayId); + messageContext.setUpdatedTime(AiravataUtils.getCurrentTimestamp()); + publisher.publish(messageContext); + } catch (AiravataException e) { + logger.error( + "expId : " + experimentId + " Error while publishing experiment status to " + status.toString(), e); + } catch (RegistryException e) { + logger.error( + "expId : " + experimentId + " Error while updating experiment status to " + status.toString(), e); + } + } + + public ExperimentStatus getExperimentStatus(String experimentId) throws RegistryException { + return orchestratorRegistryService.getExperimentStatus(experimentId); + } + + public ProcessModel getProcess(String processId) throws RegistryException { + return orchestratorRegistryService.getProcess(processId); } public boolean launchExperimentWithErrorHandling( String experimentId, String gatewayId, java.util.concurrent.ExecutorService executorService) - throws TException { + throws OrchestratorException { try { boolean result = launchExperiment(experimentId, gatewayId); if (result) { @@ -723,7 +764,7 @@ public boolean launchExperimentWithErrorHandling( ExperimentStatus status = new ExperimentStatus(ExperimentState.LAUNCHED); status.setReason("submitted all processes"); status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime()); - OrchestratorUtils.updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); + updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); logger.info("expId: {}, Launched experiment ", experimentId); // Execute the single app experiment runner in the provided thread pool @@ -743,29 +784,29 @@ public boolean launchExperimentWithErrorHandling( ExperimentStatus status = new ExperimentStatus(ExperimentState.FAILED); status.setReason("Validation failed: " + launchValidationException.getErrorMessage()); status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime()); - OrchestratorUtils.updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); - throw new TException( + updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); + throw new OrchestratorException( "Experiment '" + experimentId + "' launch failed. Experiment failed to validate: " + launchValidationException.getErrorMessage(), launchValidationException); - } catch (org.apache.airavata.registry.cpi.RegistryException e) { + } catch (RegistryException e) { ExperimentStatus status = new ExperimentStatus(ExperimentState.FAILED); status.setReason("Registry error: " + e.getMessage()); status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime()); - OrchestratorUtils.updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); - throw new TException("Experiment '" + experimentId + "' launch failed.", e); - } catch (org.apache.airavata.registry.cpi.AppCatalogException e) { + updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); + throw new OrchestratorException("Experiment '" + experimentId + "' launch failed.", e); + } catch (AppCatalogException e) { ExperimentStatus status = new ExperimentStatus(ExperimentState.FAILED); status.setReason("App catalog error: " + e.getMessage()); status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime()); - OrchestratorUtils.updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); - throw new TException("Experiment '" + experimentId + "' launch failed.", e); + updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); + throw new OrchestratorException("Experiment '" + experimentId + "' launch failed.", e); } catch (Exception e) { ExperimentStatus status = new ExperimentStatus(ExperimentState.FAILED); status.setReason("Unexpected error occurred: " + e.getMessage()); status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime()); - OrchestratorUtils.updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); - throw new TException("Experiment '" + experimentId + "' launch failed.", e); + updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); + throw new OrchestratorException("Experiment '" + experimentId + "' launch failed.", e); } } @@ -776,15 +817,11 @@ private void startCurator() throws ApplicationSettingsException { curatorClient.start(); } - public String getExperimentNodePath(String experimentId) { - return ZKPaths.makePath(ZkConstants.ZOOKEEPER_EXPERIMENT_NODE, experimentId); - } - - private Subscriber getStatusSubscriber() throws AiravataException { - List routingKeys = new ArrayList<>(); - routingKeys.add("*.*.*"); - return MessagingFactory.getSubscriber(new ProcessStatusHandler(), routingKeys, Type.STATUS); - } + // private Subscriber getStatusSubscriber() throws AiravataException { + // List routingKeys = new ArrayList<>(); + // routingKeys.add("*.*.*"); + // return MessagingFactory.getSubscriber(new ProcessStatusHandler(), routingKeys, Type.STATUS); + // } private Subscriber getExperimentSubscriber() throws AiravataException { List routingKeys = new ArrayList<>(); @@ -792,43 +829,43 @@ private Subscriber getExperimentSubscriber() throws AiravataException { return MessagingFactory.getSubscriber(new ExperimentHandler(), routingKeys, Type.EXPERIMENT_LAUNCH); } - private void setAiravataUserName(String airavataUserName) { - this.airavataUserName = airavataUserName; - } - - private class ProcessStatusHandler implements MessageHandler { - @Override - public void onMessage(MessageContext message) { - if (message.getType().equals(MessageType.PROCESS)) { - try { - ProcessStatusChangeEvent processStatusChangeEvent = new ProcessStatusChangeEvent(); - TBase event = message.getEvent(); - byte[] bytes = ThriftUtils.serializeThriftObject(event); - ThriftUtils.createThriftFromBytes(bytes, processStatusChangeEvent); - ProcessIdentifier processIdentity = processStatusChangeEvent.getProcessIdentity(); - logger.info( - "expId: {}, processId: {} :- Process status changed event received for status {}", - processIdentity.getExperimentId(), - processIdentity.getProcessId(), - processStatusChangeEvent.getState().name()); - handleProcessStatusChange(processStatusChangeEvent, processIdentity); - } catch (TException e) { - logger.error("Message Id : " + message.getMessageId() + ", Message type : " + message.getType() - + "Error" + " while prcessing process status change event"); - throw new RuntimeException("Error while updating experiment status", e); - } catch (Throwable e) { - logger.error( - "Message Id : " + message.getMessageId() + ", Message type : " + message.getType() + "Error" - + " while prcessing process status change event", - e); - throw new RuntimeException("Error while updating experiment status", e); - } - } else { - System.out.println("Message Recieved with message id " + message.getMessageId() + " and with message " - + "type " + message.getType().name()); - } - } - } + // private void setAiravataUserName(String airavataUserName) { + // this.airavataUserName = airavataUserName; + // } + + // private class ProcessStatusHandler implements MessageHandler { + // @Override + // public void onMessage(MessageContext message) { + // if (message.getType().equals(MessageType.PROCESS)) { + // try { + // ProcessStatusChangeEvent processStatusChangeEvent = new ProcessStatusChangeEvent(); + // TBase event = message.getEvent(); + // byte[] bytes = ThriftUtils.serializeThriftObject(event); + // ThriftUtils.createThriftFromBytes(bytes, processStatusChangeEvent); + // ProcessIdentifier processIdentity = processStatusChangeEvent.getProcessIdentity(); + // logger.info( + // "expId: {}, processId: {} :- Process status changed event received for status {}", + // processIdentity.getExperimentId(), + // processIdentity.getProcessId(), + // processStatusChangeEvent.getState().name()); + // handleProcessStatusChange(processStatusChangeEvent, processIdentity); + // } catch (OrchestratorException e) { + // logger.error("Message Id : " + message.getMessageId() + ", Message type : " + message.getType() + // + "Error" + " while prcessing process status change event"); + // throw new RuntimeException("Error while updating experiment status", e); + // } catch (Throwable e) { + // logger.error( + // "Message Id : " + message.getMessageId() + ", Message type : " + message.getType() + "Error" + // + " while prcessing process status change event", + // e); + // throw new RuntimeException("Error while updating experiment status", e); + // } + // } else { + // System.out.println("Message Recieved with message id " + message.getMessageId() + " and with message " + // + "type " + message.getType().name()); + // } + // } + // } private class ExperimentHandler implements MessageHandler { @@ -863,9 +900,6 @@ private void cancelExperiment(MessageContext messageContext) { expEvent.getExperimentId(), expEvent.getGatewayId()); handleCancelExperiment(expEvent); - } catch (TException e) { - logger.error("Error while cancelling experiment", e); - throw new RuntimeException("Error while cancelling experiment", e); } catch (Throwable e) { logger.error("Error while cancelling experiment", e); throw new RuntimeException("Error while cancelling experiment", e); @@ -884,10 +918,7 @@ private void handleIntermediateOutputsEvent(MessageContext messageContext) { event.getExperimentId(), event.getGatewayId(), event.getOutputNames()); - handleIntermediateOutputsEvent(event); - } catch (TException e) { - logger.error("Error while fetching intermediate outputs", e); - throw new RuntimeException("Error while fetching intermediate outputs", e); + OrchestratorService.this.handleIntermediateOutputsEvent(event); } catch (Throwable e) { logger.error("Error while fetching intermediate outputs", e); throw new RuntimeException("Error while fetching intermediate outputs", e); @@ -901,7 +932,7 @@ private void launchExperiment(MessageContext messageContext) { handleLaunchExperimentFromMessage(messageContext); } catch (TException e) { logger.error("Experiment launch failed due to Thrift conversion error", e); - } catch (org.apache.airavata.registry.cpi.RegistryException e) { + } catch (RegistryException e) { logger.error("Experiment launch failed due to registry error", e); } catch (Throwable e) { logger.error("An unknown issue while launching experiment", e); diff --git a/airavata-api/src/main/java/org/apache/airavata/service/RegistryService.java b/airavata-api/src/main/java/org/apache/airavata/service/RegistryService.java index 76902eb02c..419fc6f2b0 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/RegistryService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/RegistryService.java @@ -83,7 +83,7 @@ public class RegistryService { private RegistryServiceException convertException(Throwable e, String msg) { logger.error(msg, e); - RegistryServiceException exception = new RegistryServiceException(); + var exception = new RegistryServiceException(); exception.setMessage(msg + " More info : " + e.getMessage()); exception.initCause(e); return exception; @@ -151,7 +151,7 @@ public Gateway getGateway(String gatewayId) throws RegistryServiceException { logger.error("Gateway does not exist in the system. Please provide a valid gateway ID..."); throw new RegistryException("Gateway does not exist in the system. Please provide a valid gateway ID..."); } - Gateway gateway = gatewayRepository.getGateway(gatewayId); + var gateway = gatewayRepository.getGateway(gatewayId); logger.debug("Airavata retrieved gateway with gateway id : " + gateway.getGatewayId()); return gateway; } catch (Throwable e) { @@ -175,7 +175,7 @@ public boolean deleteGateway(String gatewayId) throws RegistryServiceException { public List getAllGateways() throws RegistryServiceException { try { - List gateways = gatewayRepository.getAllGateways(); + var gateways = gatewayRepository.getAllGateways(); logger.debug("Airavata retrieved all available gateways..."); return gateways; } catch (Throwable e) { @@ -226,7 +226,7 @@ public Project getProject(String projectId) throws RegistryServiceException, Pro throw exception; } logger.debug("Airavata retrieved project with project Id : " + projectId); - Project project = projectRepository.getProject(projectId); + var project = projectRepository.getProject(projectId); return project; } catch (ProjectNotFoundException e) { throw e; @@ -419,14 +419,14 @@ public ExperimentModel getExperiment(String airavataExperimentId) throws Registr public ExperimentModel getDetailedExperimentTree(String airavataExperimentId) throws RegistryServiceException { try { - ExperimentModel experimentModel = getExperimentInternal(airavataExperimentId); - List processList = processRepository.getProcessList( + var experimentModel = getExperimentInternal(airavataExperimentId); + var processList = processRepository.getProcessList( Constants.FieldConstants.ExperimentConstants.EXPERIMENT_ID, experimentModel.getExperimentId()); if (processList != null) { processList.stream().forEach(p -> { (p).getTasks().stream().forEach(t -> { try { - List jobList = jobRepository.getJobList( + var jobList = jobRepository.getJobList( Constants.FieldConstants.JobConstants.TASK_ID, ((TaskModel) t).getTaskId()); if (jobList != null) { Collections.sort(jobList, new Comparator() { @@ -496,7 +496,7 @@ public List getExperimentOutputs(String airavataExperiment public void updateJobStatus(JobStatus jobStatus, String taskId, String jobId) throws RegistryServiceException { try { - org.apache.airavata.registry.core.entities.expcatalog.JobPK jobPK = + var jobPK = new org.apache.airavata.registry.core.entities.expcatalog.JobPK(); jobPK.setTaskId(taskId); jobPK.setJobId(jobId); @@ -567,7 +567,7 @@ public ProcessModel getProcess(String processId) throws RegistryServiceException public List getProcessList(String experimentId) throws RegistryServiceException { try { - List processModels = processRepository.getProcessList( + var processModels = processRepository.getProcessList( Constants.FieldConstants.ExperimentConstants.EXPERIMENT_ID, experimentId); return processModels; } catch (Throwable e) { @@ -585,17 +585,17 @@ public ProcessStatus getProcessStatus(String processId) throws RegistryServiceEx public List getProcessListInState(ProcessState processState) throws RegistryServiceException { try { - List finalProcessList = new ArrayList<>(); + var finalProcessList = new ArrayList(); int offset = 0; int limit = 100; int count = 0; do { - List processStatusList = + var processStatusList = processStatusRepository.getProcessStatusList(processState, offset, limit); offset += processStatusList.size(); count = processStatusList.size(); for (ProcessStatus processStatus : processStatusList) { - ProcessStatus latestStatus = processStatusRepository.getProcessStatus(processStatus.getProcessId()); + var latestStatus = processStatusRepository.getProcessStatus(processStatus.getProcessId()); if (latestStatus.getState().name().equals(processState.name())) { finalProcessList.add(processRepository.getProcess(latestStatus.getProcessId())); } @@ -618,7 +618,7 @@ public List getProcessStatusList(String processId) throws Registr private JobModel fetchJobModel(String queryType, String id) throws RegistryServiceException { try { if (queryType.equals(Constants.FieldConstants.JobConstants.TASK_ID)) { - List jobs = jobRepository.getJobList(Constants.FieldConstants.JobConstants.TASK_ID, id); + var jobs = jobRepository.getJobList(Constants.FieldConstants.JobConstants.TASK_ID, id); if (jobs != null) { for (JobModel jobModel : jobs) { if (jobModel.getJobId() != null || !jobModel.equals("")) { @@ -627,7 +627,7 @@ private JobModel fetchJobModel(String queryType, String id) throws RegistryServi } } } else if (queryType.equals(Constants.FieldConstants.JobConstants.PROCESS_ID)) { - List jobs = jobRepository.getJobList(Constants.FieldConstants.JobConstants.PROCESS_ID, id); + var jobs = jobRepository.getJobList(Constants.FieldConstants.JobConstants.PROCESS_ID, id); if (jobs != null) { for (JobModel jobModel : jobs) { if (jobModel.getJobId() != null || !jobModel.equals("")) { @@ -644,7 +644,7 @@ private JobModel fetchJobModel(String queryType, String id) throws RegistryServi private List fetchJobModels(String queryType, String id) throws RegistryServiceException { try { - List jobs = new ArrayList<>(); + List jobs; switch (queryType) { case Constants.FieldConstants.JobConstants.TASK_ID: jobs = jobRepository.getJobList(Constants.FieldConstants.JobConstants.TASK_ID, id); @@ -655,6 +655,9 @@ private List fetchJobModels(String queryType, String id) throws Regist case Constants.FieldConstants.JobConstants.JOB_ID: jobs = jobRepository.getJobList(Constants.FieldConstants.JobConstants.JOB_ID, id); break; + default: + jobs = new ArrayList<>(); + break; } return jobs; } catch (Throwable e) { @@ -669,7 +672,7 @@ public boolean isJobExist(String queryType, String id) throws RegistryServiceExc public JobModel getJob(String queryType, String id) throws RegistryServiceException { try { - JobModel jobModel = fetchJobModel(queryType, id); + var jobModel = fetchJobModel(queryType, id); if (jobModel != null) return jobModel; throw new RegistryException("Job not found for queryType: " + queryType + ", id: " + id); } catch (Throwable e) { @@ -689,7 +692,7 @@ public int getJobCount( org.apache.airavata.model.status.JobStatus jobStatus, String gatewayId, double searchBackTimeInMinutes) throws RegistryServiceException { try { - List jobStatusList = jobStatusRepository.getDistinctListofJobStatus( + var jobStatusList = jobStatusRepository.getDistinctListofJobStatus( gatewayId, jobStatus.getJobState().name(), searchBackTimeInMinutes); return jobStatusList.size(); } catch (Throwable e) { @@ -748,16 +751,16 @@ public List getJobDetails(String airavataExperimentId) throws Registry throw new RegistryException( "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); } - List processModels = processRepository.getProcessList( + var processModels = processRepository.getProcessList( Constants.FieldConstants.ProcessConstants.EXPERIMENT_ID, airavataExperimentId); - List jobList = new ArrayList<>(); + var jobList = new ArrayList(); if (processModels != null && !processModels.isEmpty()) { for (ProcessModel processModel : processModels) { - List tasks = processModel.getTasks(); + var tasks = processModel.getTasks(); if (tasks != null && !tasks.isEmpty()) { for (TaskModel taskModel : tasks) { - String taskId = taskModel.getTaskId(); - List taskJobs = + var taskId = taskModel.getTaskId(); + var taskJobs = jobRepository.getJobList(Constants.FieldConstants.JobConstants.TASK_ID, taskId); jobList.addAll(taskJobs); } @@ -789,7 +792,7 @@ public boolean isGatewayExistInternal(String gatewayId) throws RegistryServiceEx public ApplicationModule getApplicationModule(String appModuleId) throws RegistryServiceException { try { - ApplicationModule module = applicationInterfaceRepository.getApplicationModule(appModuleId); + var module = applicationInterfaceRepository.getApplicationModule(appModuleId); logger.debug("Airavata retrieved application module with module id : " + appModuleId); return module; } catch (Throwable e) { @@ -803,7 +806,7 @@ public List getAllAppModules(String gatewayId) throws Registr logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - List moduleList = applicationInterfaceRepository.getAllApplicationModules(gatewayId); + var moduleList = applicationInterfaceRepository.getAllApplicationModules(gatewayId); logger.debug("Airavata retrieved modules for gateway id : " + gatewayId); return moduleList; } catch (Throwable e) { @@ -819,7 +822,7 @@ public List getAccessibleAppModules( logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - List moduleList = applicationInterfaceRepository.getAccessibleApplicationModules( + var moduleList = applicationInterfaceRepository.getAccessibleApplicationModules( gatewayId, accessibleAppIds, accessibleComputeResourceIds); logger.debug("Airavata retrieved modules for gateway id : " + gatewayId); return moduleList; @@ -840,7 +843,7 @@ public boolean deleteApplicationModule(String appModuleId) throws RegistryServic public ApplicationDeploymentDescription getApplicationDeployment(String appDeploymentId) throws RegistryServiceException { try { - ApplicationDeploymentDescription deployement = + var deployement = applicationDeploymentRepository.getApplicationDeployement(appDeploymentId); logger.debug("Airavata registered application deployment for deployment id : " + appDeploymentId); return deployement; @@ -866,7 +869,7 @@ public List getAllApplicationDeployments(Strin logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - List deployements = + var deployements = applicationDeploymentRepository.getAllApplicationDeployements(gatewayId); logger.debug("Airavata retrieved application deployments for gateway id : " + gatewayId); return deployements; @@ -883,7 +886,7 @@ public List getAccessibleApplicationDeployment logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - List deployements = + var deployements = applicationDeploymentRepository.getAccessibleApplicationDeployments( gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); logger.debug("Airavata retrieved application deployments for gateway id : " + gatewayId); @@ -904,7 +907,7 @@ public List getAccessibleApplicationDeployment logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - List deployments = + var deployments = applicationDeploymentRepository.getAccessibleApplicationDeployments( gatewayId, appModuleId, accessibleAppDeploymentIds, accessibleComputeResourceIds); return deployments; @@ -915,10 +918,10 @@ public List getAccessibleApplicationDeployment public List getAppModuleDeployedResources(String appModuleId) throws RegistryServiceException { try { - List appDeployments = new ArrayList<>(); - Map filters = new HashMap<>(); + var appDeployments = new ArrayList(); + var filters = new HashMap(); filters.put(DBConstants.ApplicationDeployment.APPLICATION_MODULE_ID, appModuleId); - List applicationDeployments = + var applicationDeployments = applicationDeploymentRepository.getApplicationDeployments(filters); for (ApplicationDeploymentDescription description : applicationDeployments) { appDeployments.add(description.getAppDeploymentId()); @@ -933,9 +936,9 @@ public List getAppModuleDeployedResources(String appModuleId) throws Reg public List getApplicationDeployments(String appModuleId) throws RegistryServiceException { try { - Map filters = new HashMap<>(); + var filters = new HashMap(); filters.put(DBConstants.ApplicationDeployment.APPLICATION_MODULE_ID, appModuleId); - List applicationDeployments = + var applicationDeployments = applicationDeploymentRepository.getApplicationDeployments(filters); return applicationDeployments; } catch (Throwable e) { @@ -945,7 +948,7 @@ public List getApplicationDeployments(String a public ApplicationInterfaceDescription getApplicationInterface(String appInterfaceId) throws RegistryServiceException { try { - ApplicationInterfaceDescription interfaceDescription = + var interfaceDescription = applicationInterfaceRepository.getApplicationInterface(appInterfaceId); logger.debug("Airavata retrieved application interface with interface id : " + appInterfaceId); return interfaceDescription; From e07b4876204e69cf605b221cb21e2934cff80715 Mon Sep 17 00:00:00 2001 From: yasithdev Date: Wed, 26 Nov 2025 09:37:30 -0600 Subject: [PATCH 22/26] get code to compile. add AiravataSystemException clause to thrift services that didnt have exception clause --- .../server/handler/AiravataServerHandler.java | 2 +- .../handler/ThriftExceptionHandler.java | 4 +- .../server/CredentialStoreServerHandler.java | 3 +- .../server/OrchestratorServerHandler.java | 89 +++++++++++++------ .../handler/RegistryServerHandler.java | 4 +- .../service/OrchestratorRegistryService.java | 43 +++++---- .../airavata/service/OrchestratorService.java | 57 +++++------- .../handlers/GroupManagerServiceHandler.java | 3 +- .../handlers/IamAdminServicesHandler.java | 3 +- .../handlers/TenantProfileServiceHandler.java | 3 +- .../handlers/UserProfileServiceHandler.java | 3 +- .../server/SharingRegistryServerHandler.java | 5 +- .../base-api/base_api.thrift | 4 +- .../service-cpis/orchestrator-cpi.thrift | 6 +- .../service-cpis/sharing_cpi.thrift | 2 +- 15 files changed, 130 insertions(+), 101 deletions(-) diff --git a/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java index 40347a9e8d..902e6fd790 100644 --- a/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java @@ -118,7 +118,7 @@ public AiravataServerHandler() { * Query Airavata to fetch the API version */ @Override - public String getAPIVersion() { + public String getAPIVersion() throws AiravataSystemException { return airavata_apiConstants.AIRAVATA_API_VERSION; } diff --git a/airavata-api/src/main/java/org/apache/airavata/api/server/handler/ThriftExceptionHandler.java b/airavata-api/src/main/java/org/apache/airavata/api/server/handler/ThriftExceptionHandler.java index 662d8aa1b7..803b164a6a 100644 --- a/airavata-api/src/main/java/org/apache/airavata/api/server/handler/ThriftExceptionHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/api/server/handler/ThriftExceptionHandler.java @@ -2,7 +2,6 @@ import org.apache.airavata.registry.cpi.AppCatalogException; import org.apache.airavata.registry.cpi.RegistryException; -import org.apache.thrift.TException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -27,7 +26,8 @@ public static RuntimeException convertException(Throwable e, String context) { // Convert service exceptions to AiravataSystemException if (e instanceof RegistryException || e instanceof AppCatalogException || e instanceof org.apache.airavata.credential.store.store.CredentialStoreException || - e instanceof org.apache.airavata.sharing.registry.models.SharingRegistryException) { + e instanceof org.apache.airavata.sharing.registry.models.SharingRegistryException || + e instanceof org.apache.airavata.orchestrator.core.exception.OrchestratorException) { logger.error(context, e); org.apache.airavata.model.error.AiravataSystemException exception = new org.apache.airavata.model.error.AiravataSystemException(); exception.setAiravataErrorType(org.apache.airavata.model.error.AiravataErrorType.INTERNAL_ERROR); diff --git a/airavata-api/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java index 72b732808c..cb702ebbc4 100644 --- a/airavata-api/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java @@ -26,6 +26,7 @@ import org.apache.airavata.common.exception.ApplicationSettingsException; import org.apache.airavata.credential.store.cpi.credential_store_cpiConstants; import org.apache.airavata.model.credential.store.*; +import org.apache.airavata.model.error.AiravataSystemException; import org.apache.thrift.TException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,7 +44,7 @@ public CredentialStoreServerHandler() } @Override - public String getAPIVersion() throws TException { + public String getAPIVersion() throws AiravataSystemException { return credential_store_cpiConstants.CS_CPI_VERSION; } diff --git a/airavata-api/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java index 65b5d16e18..4872bdfbff 100644 --- a/airavata-api/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java @@ -20,12 +20,12 @@ package org.apache.airavata.orchestrator.server; import java.util.*; +import org.apache.airavata.api.server.handler.ThriftExceptionHandler; +import org.apache.airavata.model.error.AiravataSystemException; import org.apache.airavata.model.error.LaunchValidationException; import org.apache.airavata.model.process.ProcessModel; -import org.apache.airavata.orchestrator.core.exception.OrchestratorException; import org.apache.airavata.orchestrator.cpi.OrchestratorService; -import org.apache.airavata.registry.core.RegistryException; -import org.apache.thrift.TException; +import org.apache.airavata.orchestrator.cpi.orchestrator_cpiConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -37,16 +37,16 @@ public class OrchestratorServerHandler implements OrchestratorService.Iface { * Query orchestrator server to fetch the CPI version */ @Override - public String getAPIVersion() throws TException { - return null; + public String getAPIVersion() throws AiravataSystemException { + return orchestrator_cpiConstants.ORCHESTRATOR_CPI_VERSION; } - public OrchestratorServerHandler() throws OrchestratorException, TException { + public OrchestratorServerHandler() { try { orchestratorService = new org.apache.airavata.service.OrchestratorService(); - } catch (OrchestratorException e) { - log.error(e.getMessage(), e); - throw new OrchestratorException("Error while initializing orchestrator service", e); + } catch (Exception e) { + log.error("Error while initializing orchestrator service", e); + throw new RuntimeException("Error while initializing orchestrator service", e); } } @@ -58,9 +58,15 @@ public OrchestratorServerHandler() throws OrchestratorException, TException { * * @param experimentId */ - public boolean launchExperiment(String experimentId, String gatewayId) throws OrchestratorException { - return orchestratorService.launchExperimentWithErrorHandling( - experimentId, gatewayId, org.apache.airavata.orchestrator.util.OrchestratorServerThreadPoolExecutor.getCachedThreadPool()); + @Override + public boolean launchExperiment(String experimentId, String gatewayId) throws AiravataSystemException { + try { + return orchestratorService.launchExperimentWithErrorHandling( + experimentId, gatewayId, org.apache.airavata.orchestrator.util.OrchestratorServerThreadPoolExecutor.getCachedThreadPool()); + } catch (Throwable e) { + ThriftExceptionHandler.convertException(e, "Error launching experiment: " + experimentId); + return false; // unreachable + } } /** @@ -70,18 +76,29 @@ public boolean launchExperiment(String experimentId, String gatewayId) throws Or * * @param experimentId * @return - * @throws RegistryException - * @throws LaunchValidationException - * @throws OrchestratorException */ - public boolean validateExperiment(String experimentId) throws RegistryException, LaunchValidationException, OrchestratorException { - return orchestratorService.validateExperiment(experimentId); + @Override + public boolean validateExperiment(String experimentId) throws LaunchValidationException { + try { + return orchestratorService.validateExperiment(experimentId); + } catch (LaunchValidationException e) { + throw e; + } catch (Throwable e) { + ThriftExceptionHandler.convertException(e, "Error validating experiment: " + experimentId); + return false; // unreachable + } } @Override - public boolean validateProcess(String experimentId, List processes) - throws LaunchValidationException, RegistryException, OrchestratorException { - return orchestratorService.validateProcess(experimentId, processes); + public boolean validateProcess(String experimentId, List processes) throws LaunchValidationException { + try { + return orchestratorService.validateProcess(experimentId, processes); + } catch (LaunchValidationException e) { + throw e; + } catch (Throwable e) { + ThriftExceptionHandler.convertException(e, "Error validating process: " + experimentId); + return false; // unreachable + } } /** @@ -90,20 +107,34 @@ public boolean validateProcess(String experimentId, List processes * * @param experimentId * @return - * @throws TException */ - public boolean terminateExperiment(String experimentId, String gatewayId) throws RegistryException, OrchestratorException, AppCatalogException { - log.info(experimentId, "Experiment: {} is cancelling !!!!!", experimentId); - return orchestratorService.terminateExperiment(experimentId, gatewayId); + @Override + public boolean terminateExperiment(String experimentId, String gatewayId) throws AiravataSystemException { + log.info("Experiment: {} is cancelling !!!!!", experimentId); + try { + return orchestratorService.terminateExperiment(experimentId, gatewayId); + } catch (Throwable e) { + ThriftExceptionHandler.convertException(e, "Error terminating experiment: " + experimentId); + return false; // unreachable + } } - public void fetchIntermediateOutputs(String experimentId, String gatewayId, List outputNames) - throws RegistryException, OrchestratorException, AppCatalogException { - orchestratorService.fetchIntermediateOutputs(experimentId, gatewayId, outputNames); + public void fetchIntermediateOutputs(String experimentId, String gatewayId, List outputNames) { + try { + orchestratorService.fetchIntermediateOutputs(experimentId, gatewayId, outputNames); + } catch (Throwable e) { + log.error("Error fetching intermediate outputs for experiment: " + experimentId, e); + ThriftExceptionHandler.convertException(e, "Error fetching intermediate outputs: " + experimentId); + } } @Override - public boolean launchProcess(String processId, String airavataCredStoreToken, String gatewayId) throws RegistryException, OrchestratorException, AppCatalogException { - return orchestratorService.launchProcess(processId, airavataCredStoreToken, gatewayId); + public boolean launchProcess(String processId, String airavataCredStoreToken, String gatewayId) throws AiravataSystemException { + try { + return orchestratorService.launchProcess(processId, airavataCredStoreToken, gatewayId); + } catch (Throwable e) { + ThriftExceptionHandler.convertException(e, "Error launching process: " + processId); + return false; // unreachable + } } } diff --git a/airavata-api/src/main/java/org/apache/airavata/registry/api/service/handler/RegistryServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/registry/api/service/handler/RegistryServerHandler.java index da76b54cad..50028a75f8 100644 --- a/airavata-api/src/main/java/org/apache/airavata/registry/api/service/handler/RegistryServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/registry/api/service/handler/RegistryServerHandler.java @@ -47,6 +47,7 @@ import org.apache.airavata.model.data.movement.DMType; import org.apache.airavata.model.data.replica.DataProductModel; import org.apache.airavata.model.data.replica.DataReplicaLocationModel; +import org.apache.airavata.model.error.AiravataSystemException; import org.apache.airavata.model.error.*; import org.apache.airavata.model.experiment.*; import org.apache.airavata.model.job.JobModel; @@ -63,7 +64,6 @@ import org.apache.airavata.registry.api.RegistryService; import org.apache.airavata.registry.api.exception.RegistryServiceException; import org.apache.airavata.registry.api.registry_apiConstants; -import org.apache.airavata.registry.cpi.RegistryException; import org.apache.thrift.TException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -86,7 +86,7 @@ private RegistryServiceException convertToRegistryServiceException(Throwable e, * Fetch Apache Registry API version */ @Override - public String getAPIVersion() throws TException { + public String getAPIVersion() throws AiravataSystemException { return registry_apiConstants.REGISTRY_API_VERSION; } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorRegistryService.java b/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorRegistryService.java index db01ca82a2..b6bd6bfd8d 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorRegistryService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorRegistryService.java @@ -33,8 +33,7 @@ import org.apache.airavata.model.status.ExperimentStatus; import org.apache.airavata.model.status.ProcessStatus; import org.apache.airavata.model.status.QueueStatusModel; -import org.apache.airavata.registry.cpi.AppCatalogException; -import org.apache.airavata.registry.cpi.RegistryException; +import org.apache.airavata.registry.api.exception.RegistryServiceException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,85 +43,85 @@ public class OrchestratorRegistryService { private org.apache.airavata.service.RegistryService registryService = new org.apache.airavata.service.RegistryService(); - public ExperimentModel getExperiment(String airavataExperimentId) throws RegistryException { + public ExperimentModel getExperiment(String airavataExperimentId) throws RegistryServiceException { return registryService.getExperiment(airavataExperimentId); } public GroupComputeResourcePreference getGroupComputeResourcePreference( - String computeResourceId, String groupResourceProfileId) throws AppCatalogException { + String computeResourceId, String groupResourceProfileId) throws RegistryServiceException { return registryService.getGroupComputeResourcePreference(computeResourceId, groupResourceProfileId); } - public GroupResourceProfile getGroupResourceProfile(String groupResourceProfileId) throws AppCatalogException { + public GroupResourceProfile getGroupResourceProfile(String groupResourceProfileId) throws RegistryServiceException { return registryService.getGroupResourceProfile(groupResourceProfileId); } - public DataProductModel getDataProduct(String productUri) throws RegistryException { + public DataProductModel getDataProduct(String productUri) throws RegistryServiceException { return registryService.getDataProduct(productUri); } - public void updateProcess(ProcessModel processModel, String processId) throws RegistryException { + public void updateProcess(ProcessModel processModel, String processId) throws RegistryServiceException { registryService.updateProcess(processModel, processId); } - public void addErrors(String errorType, ErrorModel errorModel, String id) throws RegistryException { + public void addErrors(String errorType, ErrorModel errorModel, String id) throws RegistryServiceException { registryService.addErrors(errorType, errorModel, id); } - public ExperimentStatus getExperimentStatus(String airavataExperimentId) throws RegistryException { + public ExperimentStatus getExperimentStatus(String airavataExperimentId) throws RegistryServiceException { return registryService.getExperimentStatus(airavataExperimentId); } - public void updateExperimentStatus(ExperimentStatus experimentStatus, String experimentId) throws RegistryException { + public void updateExperimentStatus(ExperimentStatus experimentStatus, String experimentId) throws RegistryServiceException { registryService.updateExperimentStatus(experimentStatus, experimentId); } - public String addProcess(ProcessModel processModel, String experimentId) throws RegistryException { + public String addProcess(ProcessModel processModel, String experimentId) throws RegistryServiceException { return registryService.addProcess(processModel, experimentId); } - public ProcessModel getProcess(String processId) throws RegistryException { + public ProcessModel getProcess(String processId) throws RegistryServiceException { return registryService.getProcess(processId); } - public List getProcessList(String experimentId) throws RegistryException { + public List getProcessList(String experimentId) throws RegistryServiceException { return registryService.getProcessList(experimentId); } - public ProcessStatus getProcessStatus(String processId) throws RegistryException { + public ProcessStatus getProcessStatus(String processId) throws RegistryServiceException { return registryService.getProcessStatus(processId); } - public List getProcessIds(String experimentId) throws RegistryException { + public List getProcessIds(String experimentId) throws RegistryServiceException { return registryService.getProcessIds(experimentId); } - public void addProcessStatus(ProcessStatus processStatus, String processId) throws RegistryException { + public void addProcessStatus(ProcessStatus processStatus, String processId) throws RegistryServiceException { registryService.addProcessStatus(processStatus, processId); } - public List getApplicationOutputs(String appInterfaceId) throws AppCatalogException { + public List getApplicationOutputs(String appInterfaceId) throws RegistryServiceException { return registryService.getApplicationOutputs(appInterfaceId); } - public ApplicationInterfaceDescription getApplicationInterface(String appInterfaceId) throws AppCatalogException { + public ApplicationInterfaceDescription getApplicationInterface(String appInterfaceId) throws RegistryServiceException { return registryService.getApplicationInterface(appInterfaceId); } public List getApplicationDeployments(String appModuleId) - throws AppCatalogException { + throws RegistryServiceException { return registryService.getApplicationDeployments(appModuleId); } - public ComputeResourceDescription getComputeResource(String computeResourceId) throws AppCatalogException { + public ComputeResourceDescription getComputeResource(String computeResourceId) throws RegistryServiceException { return registryService.getComputeResource(computeResourceId); } - public void deleteTasks(String processId) throws RegistryException { + public void deleteTasks(String processId) throws RegistryServiceException { registryService.deleteTasks(processId); } - public void registerQueueStatuses(List queueStatuses) throws RegistryException { + public void registerQueueStatuses(List queueStatuses) throws RegistryServiceException { registryService.registerQueueStatuses(queueStatuses); } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorService.java b/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorService.java index 84e4f6fdc3..409890a74f 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorService.java @@ -60,8 +60,7 @@ import org.apache.airavata.orchestrator.core.schedule.HostScheduler; import org.apache.airavata.orchestrator.core.utils.OrchestratorConstants; import org.apache.airavata.orchestrator.cpi.impl.SimpleOrchestratorImpl; -import org.apache.airavata.registry.cpi.AppCatalogException; -import org.apache.airavata.registry.cpi.RegistryException; +import org.apache.airavata.registry.api.exception.RegistryServiceException; import org.apache.commons.lang3.StringUtils; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.utils.ZKPaths; @@ -202,7 +201,7 @@ private void resolveInputReplicas(ProcessModel processModel) throws Exception { } else { logger.error("Could not find a replica for the URI " + pi.getValue()); } - } catch (RegistryException e) { + } catch (RegistryServiceException e) { throw new Exception("Error while launching experiment", e); } } else if (pi.getType().equals(DataType.URI_COLLECTION) @@ -229,7 +228,7 @@ private void resolveInputReplicas(ProcessModel processModel) throws Exception { } } pi.setValue(StringUtils.join(filePathList, ',')); - } catch (RegistryException e) { + } catch (RegistryServiceException e) { throw new Exception("Error while launching experiment", e); } } @@ -237,7 +236,7 @@ private void resolveInputReplicas(ProcessModel processModel) throws Exception { } public String getCredentialToken(ExperimentModel experiment, UserConfigurationDataModel userConfigurationData) - throws OrchestratorException, AppCatalogException { + throws OrchestratorException, RegistryServiceException { String token = null; final String groupResourceProfileId = userConfigurationData.getGroupResourceProfileId(); if (groupResourceProfileId == null) { @@ -274,13 +273,13 @@ public String getCredentialToken(ExperimentModel experiment, UserConfigurationDa } public boolean validateExperiment(String experimentId) - throws LaunchValidationException, RegistryException, OrchestratorException { + throws LaunchValidationException, RegistryServiceException, OrchestratorException { ExperimentModel experimentModel = orchestratorRegistryService.getExperiment(experimentId); return orchestrator.validateExperiment(experimentModel).isValidationState(); } public boolean validateProcess(String experimentId, List processes) - throws LaunchValidationException, RegistryException, OrchestratorException { + throws LaunchValidationException, RegistryServiceException, OrchestratorException { ExperimentModel experimentModel = orchestratorRegistryService.getExperiment(experimentId); for (ProcessModel processModel : processes) { boolean state = @@ -292,12 +291,12 @@ public boolean validateProcess(String experimentId, List processes return true; } - public boolean terminateExperiment(String experimentId, String gatewayId) throws RegistryException, OrchestratorException, AppCatalogException { + public boolean terminateExperiment(String experimentId, String gatewayId) throws RegistryServiceException, OrchestratorException { logger.info(experimentId, "Experiment: {} is cancelling !!!!!", experimentId); return validateStatesAndCancel(experimentId, gatewayId); } - private boolean validateStatesAndCancel(String experimentId, String gatewayId) throws RegistryException, OrchestratorException, AppCatalogException { + private boolean validateStatesAndCancel(String experimentId, String gatewayId) throws RegistryServiceException, OrchestratorException { ExperimentStatus experimentStatus = orchestratorRegistryService.getExperimentStatus(experimentId); switch (experimentStatus.getState()) { case COMPLETED: @@ -368,12 +367,12 @@ private boolean validateStatesAndCancel(String experimentId, String gatewayId) t } public void fetchIntermediateOutputs(String experimentId, String gatewayId, List outputNames) - throws RegistryException, OrchestratorException, AppCatalogException { + throws RegistryServiceException, OrchestratorException { submitIntermediateOutputsProcess(experimentId, gatewayId, outputNames); } private void submitIntermediateOutputsProcess(String experimentId, String gatewayId, List outputNames) - throws RegistryException, OrchestratorException, AppCatalogException { + throws RegistryServiceException, OrchestratorException { ExperimentModel experimentModel = orchestratorRegistryService.getExperiment(experimentId); ProcessModel processModel = ExperimentModelUtil.cloneProcessFromExperiment(experimentModel); @@ -409,7 +408,7 @@ private void submitIntermediateOutputsProcess(String experimentId, String gatewa String token = getCredentialToken(experimentModel, experimentModel.getUserConfigurationData()); orchestrator.launchProcess(processModel, token); - } catch (RegistryException | OrchestratorException | AppCatalogException e) { + } catch (RegistryServiceException | OrchestratorException e) { logger.error("Failed to launch process for intermediate output fetching", e); ProcessStatus status = new ProcessStatus(ProcessState.FAILED); @@ -421,7 +420,7 @@ private void submitIntermediateOutputsProcess(String experimentId, String gatewa } } - public boolean launchProcess(String processId, String airavataCredStoreToken, String gatewayId) throws RegistryException, OrchestratorException, AppCatalogException { + public boolean launchProcess(String processId, String airavataCredStoreToken, String gatewayId) throws RegistryServiceException, OrchestratorException { ProcessStatus processStatus = orchestratorRegistryService.getProcessStatus(processId); switch (processStatus.getState()) { @@ -456,13 +455,13 @@ public boolean launchProcess(String processId, String airavataCredStoreToken, St } private ApplicationDeploymentDescription getAppDeployment(ProcessModel processModel, String applicationId) - throws OrchestratorException, AppCatalogException { + throws OrchestratorException, RegistryServiceException { String selectedModuleId = getModuleId(applicationId); return getAppDeploymentForModule(processModel, selectedModuleId); } private ApplicationDeploymentDescription getAppDeploymentForModule( - ProcessModel processModel, String selectedModuleId) throws OrchestratorException, AppCatalogException { + ProcessModel processModel, String selectedModuleId) throws OrchestratorException, RegistryServiceException { List applicationDeployements = orchestratorRegistryService.getApplicationDeployments(selectedModuleId); @@ -489,7 +488,7 @@ private ApplicationDeploymentDescription getAppDeploymentForModule( return deploymentMap.get(ComputeResourceDescription); } - private String getModuleId(String applicationId) throws OrchestratorException, AppCatalogException { + private String getModuleId(String applicationId) throws OrchestratorException, RegistryServiceException { ApplicationInterfaceDescription applicationInterface = orchestratorRegistryService.getApplicationInterface(applicationId); List applicationModules = applicationInterface.getApplicationModules(); @@ -523,7 +522,7 @@ public void createAndValidateTasks(ExperimentModel experiment, boolean recreateT } } - public void addProcessValidationErrors(String experimentId, ErrorModel details) throws RegistryException { + public void addProcessValidationErrors(String experimentId, ErrorModel details) throws RegistryServiceException { orchestratorRegistryService.addErrors(OrchestratorConstants.EXPERIMENT_ERROR, details, experimentId); } @@ -539,7 +538,7 @@ public boolean launchSingleAppExperimentInternal( launchProcess(processId, airavataCredStoreToken, gatewayId); } return true; - } catch (RegistryException e) { + } catch (RegistryServiceException e) { ExperimentStatus status = new ExperimentStatus(ExperimentState.FAILED); status.setReason("Error while retrieving process IDs"); updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); @@ -680,10 +679,8 @@ private void registerQueueStatusForRequeue(String experimentId) { orchestratorRegistryService.registerQueueStatuses(queueStatusModels); } } - } catch (RegistryException e) { + } catch (RegistryServiceException e) { logger.error("Error while registering queue statuses", e); - } catch (AppCatalogException e) { - logger.error("Error while getting compute resource for queue status", e); } } @@ -739,17 +736,17 @@ private void updateAndPublishExperimentStatus( } catch (AiravataException e) { logger.error( "expId : " + experimentId + " Error while publishing experiment status to " + status.toString(), e); - } catch (RegistryException e) { + } catch (RegistryServiceException e) { logger.error( "expId : " + experimentId + " Error while updating experiment status to " + status.toString(), e); } } - public ExperimentStatus getExperimentStatus(String experimentId) throws RegistryException { + public ExperimentStatus getExperimentStatus(String experimentId) throws RegistryServiceException { return orchestratorRegistryService.getExperimentStatus(experimentId); } - public ProcessModel getProcess(String processId) throws RegistryException { + public ProcessModel getProcess(String processId) throws RegistryServiceException { return orchestratorRegistryService.getProcess(processId); } @@ -789,18 +786,12 @@ public boolean launchExperimentWithErrorHandling( "Experiment '" + experimentId + "' launch failed. Experiment failed to validate: " + launchValidationException.getErrorMessage(), launchValidationException); - } catch (RegistryException e) { + } catch (RegistryServiceException e) { ExperimentStatus status = new ExperimentStatus(ExperimentState.FAILED); status.setReason("Registry error: " + e.getMessage()); status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime()); updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); throw new OrchestratorException("Experiment '" + experimentId + "' launch failed.", e); - } catch (AppCatalogException e) { - ExperimentStatus status = new ExperimentStatus(ExperimentState.FAILED); - status.setReason("App catalog error: " + e.getMessage()); - status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime()); - updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); - throw new OrchestratorException("Experiment '" + experimentId + "' launch failed.", e); } catch (Exception e) { ExperimentStatus status = new ExperimentStatus(ExperimentState.FAILED); status.setReason("Unexpected error occurred: " + e.getMessage()); @@ -930,10 +921,10 @@ private void handleIntermediateOutputsEvent(MessageContext messageContext) { private void launchExperiment(MessageContext messageContext) { try { handleLaunchExperimentFromMessage(messageContext); + } catch (RegistryServiceException e) { + logger.error("Experiment launch failed due to registry error", e); } catch (TException e) { logger.error("Experiment launch failed due to Thrift conversion error", e); - } catch (RegistryException e) { - logger.error("Experiment launch failed due to registry error", e); } catch (Throwable e) { logger.error("An unknown issue while launching experiment", e); } finally { diff --git a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/GroupManagerServiceHandler.java b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/GroupManagerServiceHandler.java index 5bbc22f794..374d338fe9 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/GroupManagerServiceHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/GroupManagerServiceHandler.java @@ -20,6 +20,7 @@ package org.apache.airavata.service.profile.handlers; import java.util.List; +import org.apache.airavata.model.error.AiravataSystemException; import org.apache.airavata.model.error.AuthorizationException; import org.apache.airavata.model.group.GroupModel; import org.apache.airavata.model.security.AuthzToken; @@ -41,7 +42,7 @@ public GroupManagerServiceHandler() { } @Override - public String getAPIVersion() throws TException { + public String getAPIVersion() throws AiravataSystemException { return group_manager_cpiConstants.GROUP_MANAGER_CPI_VERSION; } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/IamAdminServicesHandler.java b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/IamAdminServicesHandler.java index da12bb8ca0..7833060862 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/IamAdminServicesHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/IamAdminServicesHandler.java @@ -20,6 +20,7 @@ package org.apache.airavata.service.profile.handlers; import java.util.List; +import org.apache.airavata.model.error.AiravataSystemException; import org.apache.airavata.model.error.AuthorizationException; import org.apache.airavata.model.security.AuthzToken; import org.apache.airavata.model.user.UserProfile; @@ -39,7 +40,7 @@ public IamAdminServicesHandler() { } @Override - public String getAPIVersion() throws TException { + public String getAPIVersion() throws AiravataSystemException { return iam_admin_services_cpiConstants.IAM_ADMIN_SERVICES_CPI_VERSION; } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/TenantProfileServiceHandler.java b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/TenantProfileServiceHandler.java index 6238d7cc6d..13e97c812c 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/TenantProfileServiceHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/TenantProfileServiceHandler.java @@ -20,6 +20,7 @@ package org.apache.airavata.service.profile.handlers; import java.util.List; +import org.apache.airavata.model.error.AiravataSystemException; import org.apache.airavata.model.error.AuthorizationException; import org.apache.airavata.model.security.AuthzToken; import org.apache.airavata.model.workspace.Gateway; @@ -45,7 +46,7 @@ public TenantProfileServiceHandler() { } @Override - public String getAPIVersion() throws TException { + public String getAPIVersion() throws AiravataSystemException { return profile_tenant_cpiConstants.TENANT_PROFILE_CPI_VERSION; } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/UserProfileServiceHandler.java b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/UserProfileServiceHandler.java index 5f2432ea03..c2189db320 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/UserProfileServiceHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/UserProfileServiceHandler.java @@ -20,6 +20,7 @@ package org.apache.airavata.service.profile.handlers; import java.util.List; +import org.apache.airavata.model.error.AiravataSystemException; import org.apache.airavata.model.error.AuthorizationException; import org.apache.airavata.model.security.AuthzToken; import org.apache.airavata.model.user.UserProfile; @@ -38,7 +39,7 @@ public UserProfileServiceHandler() { } @Override - public String getAPIVersion() throws TException { + public String getAPIVersion() throws AiravataSystemException { return profile_user_cpiConstants.USER_PROFILE_CPI_VERSION; } diff --git a/airavata-api/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java index 79928ba624..d897ead261 100644 --- a/airavata-api/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java @@ -22,6 +22,7 @@ import java.util.List; import org.apache.airavata.common.exception.ApplicationSettingsException; import org.apache.airavata.common.utils.DBInitializer; +import org.apache.airavata.model.error.AiravataSystemException; import org.apache.airavata.sharing.registry.db.utils.SharingRegistryDBInitConfig; import org.apache.airavata.sharing.registry.models.*; import org.apache.airavata.sharing.registry.service.cpi.SharingRegistryService; @@ -45,7 +46,7 @@ public SharingRegistryServerHandler(SharingRegistryDBInitConfig sharingRegistryD } @Override - public String getAPIVersion() throws TException { + public String getAPIVersion() throws AiravataSystemException { return sharing_cpiConstants.SHARING_CPI_VERSION; } @@ -165,7 +166,7 @@ public UserGroup getGroup(String domainId, String groupId) throws SharingRegistr } @Override - public List getGroups(String domain, int offset, int limit) throws TException { + public List getGroups(String domain, int offset, int limit) throws SharingRegistryException { return sharingRegistryService.getGroups(domain, offset, limit); } diff --git a/thrift-interface-descriptions/base-api/base_api.thrift b/thrift-interface-descriptions/base-api/base_api.thrift index 317f97b18a..583f6d1b69 100644 --- a/thrift-interface-descriptions/base-api/base_api.thrift +++ b/thrift-interface-descriptions/base-api/base_api.thrift @@ -5,6 +5,8 @@ namespace perl ApacheAiravataBaseAPI namespace py airavata.base.api namespace js ApacheAiravataBaseAPI +include "../airavata-apis/airavata_errors.thrift" + service BaseAPI { - string getAPIVersion() + string getAPIVersion() throws (1: airavata_errors.AiravataSystemException ase) } \ No newline at end of file diff --git a/thrift-interface-descriptions/service-cpis/orchestrator-cpi.thrift b/thrift-interface-descriptions/service-cpis/orchestrator-cpi.thrift index 7eb90de20c..0e5a021223 100644 --- a/thrift-interface-descriptions/service-cpis/orchestrator-cpi.thrift +++ b/thrift-interface-descriptions/service-cpis/orchestrator-cpi.thrift @@ -42,7 +42,7 @@ service OrchestratorService extends base_api.BaseAPI { * @return sucess/failure * **/ - bool launchExperiment (1: required string experimentId, 2: required string gatewayId), + bool launchExperiment (1: required string experimentId, 2: required string gatewayId) throws (1: airavata_errors.AiravataSystemException ase), /** * In order to run single applications users should create an associating @@ -54,7 +54,7 @@ service OrchestratorService extends base_api.BaseAPI { * @return sucess/failure * **/ - bool launchProcess (1: required string processId, 2: required string airavataCredStoreToken, 3: required string gatewayId), + bool launchProcess (1: required string processId, 2: required string airavataCredStoreToken, 3: required string gatewayId) throws (1: airavata_errors.AiravataSystemException ase), /** * @@ -75,5 +75,5 @@ service OrchestratorService extends base_api.BaseAPI { * @return sucess/failure * **/ - bool terminateExperiment (1: required string experimentId, 2: required string gatewayId) + bool terminateExperiment (1: required string experimentId, 2: required string gatewayId) throws (1: airavata_errors.AiravataSystemException ase) } diff --git a/thrift-interface-descriptions/service-cpis/sharing_cpi.thrift b/thrift-interface-descriptions/service-cpis/sharing_cpi.thrift index d76012219d..e608ee7873 100644 --- a/thrift-interface-descriptions/service-cpis/sharing_cpi.thrift +++ b/thrift-interface-descriptions/service-cpis/sharing_cpi.thrift @@ -105,7 +105,7 @@ service SharingRegistryService extends base_api.BaseAPI { /**

API method to get groups in a domainId.

*/ - list getGroups(1: required string domainId, 2: required i32 offset, 3: required i32 limit) + list getGroups(1: required string domainId, 2: required i32 offset, 3: required i32 limit) throws (1: sharing_models.SharingRegistryException sre) /**

API method to add list of users to a group

From 8a8986d87b00b0959ddcb03563f1342b7e787995 Mon Sep 17 00:00:00 2001 From: yasithdev Date: Wed, 26 Nov 2025 16:06:34 -0600 Subject: [PATCH 23/26] update service classes to throw only the exceptions that get created. partially fixed the thrift handlers --- .../server/handler/AiravataServerHandler.java | 415 +- .../handler/ThriftExceptionHandler.java | 52 - .../server/CredentialStoreServerHandler.java | 38 +- .../server/OrchestratorServerHandler.java | 56 +- .../handler/RegistryServerHandler.java | 514 ++- .../airavata/service/AiravataService.java | 3721 +++++++++++------ .../service/CredentialStoreService.java | 161 +- .../airavata/service/GroupManagerService.java | 8 - .../airavata/service/IamAdminService.java | 27 +- .../service/OrchestratorRegistryService.java | 6 +- .../airavata/service/OrchestratorService.java | 186 +- .../airavata/service/RegistryService.java | 1598 +++++-- .../service/SharingRegistryService.java | 397 +- .../service/TenantProfileService.java | 8 - .../airavata/service/UserProfileService.java | 11 +- .../handlers/GroupManagerServiceHandler.java | 27 +- .../handlers/IamAdminServicesHandler.java | 25 +- .../handlers/TenantProfileServiceHandler.java | 15 +- .../handlers/UserProfileServiceHandler.java | 19 +- .../interceptor/SecurityInterceptor.java | 6 +- .../SharingServiceDBEventHandler.java | 4 +- .../server/SharingRegistryServerHandler.java | 138 +- 22 files changed, 4950 insertions(+), 2482 deletions(-) delete mode 100644 airavata-api/src/main/java/org/apache/airavata/api/server/handler/ThriftExceptionHandler.java diff --git a/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java index 902e6fd790..e0d3c96e13 100644 --- a/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java @@ -20,22 +20,14 @@ package org.apache.airavata.api.server.handler; import java.util.*; -import java.util.stream.Collectors; import org.apache.airavata.accountprovisioning.ConfigParam; -import org.apache.airavata.accountprovisioning.SSHAccountManager; +import org.apache.airavata.accountprovisioning.InvalidSetupException; import org.apache.airavata.accountprovisioning.SSHAccountProvisionerFactory; import org.apache.airavata.accountprovisioning.SSHAccountProvisionerProvider; -import org.apache.airavata.agents.api.AgentAdaptor; - import org.apache.airavata.api.Airavata; import org.apache.airavata.api.airavata_apiConstants; - import org.apache.airavata.common.exception.ApplicationSettingsException; -import org.apache.airavata.common.utils.AiravataUtils; import org.apache.airavata.common.utils.Constants; -import org.apache.airavata.common.utils.ServerSettings; - -import org.apache.airavata.helix.core.support.adaptor.AdaptorSupportImpl; import org.apache.airavata.messaging.core.MessagingFactory; import org.apache.airavata.messaging.core.Publisher; import org.apache.airavata.messaging.core.Type; @@ -64,7 +56,6 @@ import org.apache.airavata.model.appcatalog.userresourceprofile.UserStoragePreference; import org.apache.airavata.model.application.io.InputDataObjectType; import org.apache.airavata.model.application.io.OutputDataObjectType; -import org.apache.airavata.model.commons.airavata_commonsConstants; import org.apache.airavata.model.credential.store.*; import org.apache.airavata.model.data.movement.*; import org.apache.airavata.model.data.movement.DMType; @@ -84,12 +75,7 @@ import org.apache.airavata.model.workspace.Gateway; import org.apache.airavata.model.workspace.Notification; import org.apache.airavata.model.workspace.Project; - import org.apache.airavata.service.security.interceptor.SecurityCheck; -import org.apache.airavata.sharing.registry.models.*; - -import org.apache.thrift.TException; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -113,7 +99,6 @@ public AiravataServerHandler() { } } - /** * Query Airavata to fetch the API version */ @@ -133,14 +118,14 @@ public String getAPIVersion() throws AiravataSystemException { @Override @SecurityCheck public boolean isUserExists(AuthzToken authzToken, String gatewayId, String userName) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { return airavataService.isUserExists(gatewayId, userName); } @Override @SecurityCheck public String addGateway(AuthzToken authzToken, Gateway gateway) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { return airavataService.addGatewayWithSharing(gateway); } @@ -155,7 +140,7 @@ public String addGateway(AuthzToken authzToken, Gateway gateway) @Override @SecurityCheck public List getAllUsersInGateway(AuthzToken authzToken, String gatewayId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { return airavataService.getAllUsersInGateway(gatewayId); } @@ -163,7 +148,7 @@ public List getAllUsersInGateway(AuthzToken authzToken, String gatewayId @SecurityCheck public boolean updateGateway(AuthzToken authzToken, String gatewayId, Gateway updatedGateway) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.updateGateway(gatewayId, updatedGateway); + return airavataService.updateGateway(gatewayId, updatedGateway); } @Override @@ -177,21 +162,21 @@ public Gateway getGateway(AuthzToken authzToken, String gatewayId) @SecurityCheck public boolean deleteGateway(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.deleteGateway(gatewayId); + return airavataService.deleteGateway(gatewayId); } @Override @SecurityCheck public List getAllGateways(AuthzToken authzToken) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getAllGateways(); + return airavataService.getAllGateways(); } @Override @SecurityCheck public boolean isGatewayExist(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.isGatewayExist(gatewayId); + return airavataService.isGatewayExist(gatewayId); } /** @@ -205,35 +190,35 @@ public boolean isGatewayExist(AuthzToken authzToken, String gatewayId) @SecurityCheck public String createNotification(AuthzToken authzToken, Notification notification) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.createNotification(notification); + return airavataService.createNotification(notification); } @Override @SecurityCheck public boolean updateNotification(AuthzToken authzToken, Notification notification) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.updateNotification(notification); + return airavataService.updateNotification(notification); } @Override @SecurityCheck public boolean deleteNotification(AuthzToken authzToken, String gatewayId, String notificationId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.deleteNotification(gatewayId, notificationId); + return airavataService.deleteNotification(gatewayId, notificationId); } // No security check @Override public Notification getNotification(AuthzToken authzToken, String gatewayId, String notificationId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getNotification(gatewayId, notificationId); + return airavataService.getNotification(gatewayId, notificationId); } // No security check @Override public List getAllNotifications(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getAllNotifications(gatewayId); + return airavataService.getAllNotifications(gatewayId); } @Override @@ -242,7 +227,7 @@ public String generateAndRegisterSSHKeys(AuthzToken authzToken, String descripti throws InvalidRequestException, AiravataClientException, AiravataSystemException { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); - return airavataService.generateAndRegisterSSHKeys( gatewayId, userName, description); + return airavataService.generateAndRegisterSSHKeys(gatewayId, userName, description); } /** @@ -261,7 +246,7 @@ public String registerPwdCredential( throws AiravataClientException, AiravataSystemException, AuthorizationException, InvalidRequestException { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); - return airavataService.registerPwdCredential( gatewayId, userName, loginUserName, password, description); + return airavataService.registerPwdCredential(gatewayId, userName, loginUserName, password, description); } @Override @@ -269,7 +254,7 @@ public String registerPwdCredential( public CredentialSummary getCredentialSummary(AuthzToken authzToken, String tokenId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - return airavataService.getCredentialSummaryWithAuth( authzToken, tokenId, gatewayId); + return airavataService.getCredentialSummaryWithAuth(authzToken, tokenId, gatewayId); } @Override @@ -278,7 +263,7 @@ public List getAllCredentialSummaries(AuthzToken authzToken, throws InvalidRequestException, AiravataClientException, AiravataSystemException { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); - return airavataService.getAllCredentialSummariesWithAuth( authzToken, type, gatewayId, userName); + return airavataService.getAllCredentialSummariesWithAuth(authzToken, type, gatewayId, userName); } @Override @@ -286,7 +271,7 @@ public List getAllCredentialSummaries(AuthzToken authzToken, public boolean deleteSSHPubKey(AuthzToken authzToken, String airavataCredStoreToken) throws AiravataClientException, AiravataSystemException, AuthorizationException, InvalidRequestException { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - return airavataService.deleteSSHPubKey( authzToken, airavataCredStoreToken, gatewayId); + return airavataService.deleteSSHPubKey(authzToken, airavataCredStoreToken, gatewayId); } @Override @@ -294,7 +279,7 @@ public boolean deleteSSHPubKey(AuthzToken authzToken, String airavataCredStoreTo public boolean deletePWDCredential(AuthzToken authzToken, String airavataCredStoreToken) throws AiravataClientException, AiravataSystemException, AuthorizationException, InvalidRequestException { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - return airavataService.deletePWDCredentialWithAuth( authzToken, airavataCredStoreToken, gatewayId); + return airavataService.deletePWDCredentialWithAuth(authzToken, airavataCredStoreToken, gatewayId); } /** @@ -306,7 +291,7 @@ public boolean deletePWDCredential(AuthzToken authzToken, String airavataCredSto @SecurityCheck public String createProject(AuthzToken authzToken, String gatewayId, Project project) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.createProjectWithSharing( gatewayId, project); + return airavataService.createProjectWithSharing(gatewayId, project); } @Override @@ -314,7 +299,7 @@ public String createProject(AuthzToken authzToken, String gatewayId, Project pro public void updateProject(AuthzToken authzToken, String projectId, Project updatedProject) throws InvalidRequestException, AiravataClientException, AiravataSystemException, ProjectNotFoundException, AuthorizationException { - airavataService.updateProjectWithAuth( authzToken, projectId, updatedProject); + airavataService.updateProjectWithAuth(authzToken, projectId, updatedProject); } @Override @@ -322,15 +307,7 @@ public void updateProject(AuthzToken authzToken, String projectId, Project updat public boolean deleteProject(AuthzToken authzToken, String projectId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, ProjectNotFoundException, AuthorizationException { - return airavataService.deleteProjectWithAuth( authzToken, projectId); - } - - private boolean validateString(String name) { - boolean valid = true; - if (name == null || name.equals("") || name.trim().length() == 0) { - valid = false; - } - return valid; + return airavataService.deleteProjectWithAuth(authzToken, projectId); } /** @@ -343,7 +320,7 @@ private boolean validateString(String name) { public Project getProject(AuthzToken authzToken, String projectId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, ProjectNotFoundException, AuthorizationException { - return airavataService.getProjectWithAuth( authzToken, projectId); + return airavataService.getProjectWithAuth(authzToken, projectId); } /** @@ -363,8 +340,8 @@ public Project getProject(AuthzToken authzToken, String projectId) @SecurityCheck public List getUserProjects( AuthzToken authzToken, String gatewayId, String userName, int limit, int offset) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - return airavataService.getUserProjectsWithSharing( authzToken, gatewayId, userName, limit, offset); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + return airavataService.getUserProjectsWithSharing(authzToken, gatewayId, userName, limit, offset); } /** @@ -398,7 +375,7 @@ public List searchProjects( Map filters, int limit, int offset) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { return airavataService.searchProjectsWithSharing(authzToken, gatewayId, userName, filters, limit, offset); } @@ -426,8 +403,8 @@ public List searchExperiments( Map filters, int limit, int offset) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - return airavataService.searchExperimentsWithSharing( authzToken, gatewayId, userName, filters, limit, offset); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + return airavataService.searchExperimentsWithSharing(authzToken, gatewayId, userName, filters, limit, offset); } /** @@ -441,7 +418,6 @@ public List searchExperiments( * @throws InvalidRequestException * @throws AiravataClientException * @throws AiravataSystemException - * @throws TException */ @Override @SecurityCheck @@ -455,10 +431,18 @@ public ExperimentStatistics getExperimentStatistics( String resourceHostName, int limit, int offset) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { - List accessibleExpIds = null; - return airavataService.getExperimentStatistics( - gatewayId, fromTime, toTime, userName, applicationName, resourceHostName, accessibleExpIds, limit, offset); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + List accessibleExpIds = null; + return airavataService.getExperimentStatistics( + gatewayId, + fromTime, + toTime, + userName, + applicationName, + resourceHostName, + accessibleExpIds, + limit, + offset); } /** @@ -476,7 +460,7 @@ public ExperimentStatistics getExperimentStatistics( @SecurityCheck public List getExperimentsInProject(AuthzToken authzToken, String projectId, int limit, int offset) throws InvalidRequestException, AiravataClientException, AiravataSystemException, ProjectNotFoundException, - AuthorizationException, TException { + AuthorizationException { return airavataService.getExperimentsInProject(authzToken, projectId, limit, offset); } @@ -498,7 +482,7 @@ public List getExperimentsInProject(AuthzToken authzToken, Stri public List getUserExperiments( AuthzToken authzToken, String gatewayId, String userName, int limit, int offset) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getUserExperiments(gatewayId, userName, limit, offset); + return airavataService.getUserExperiments(gatewayId, userName, limit, offset); } /** @@ -527,7 +511,7 @@ public List getUserExperiments( @SecurityCheck public String createExperiment(AuthzToken authzToken, String gatewayId, ExperimentModel experiment) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.createExperimentWithSharingAndPublish( statusPublisher, gatewayId, experiment); + return airavataService.createExperimentWithSharingAndPublish(statusPublisher, gatewayId, experiment); } /** @@ -539,13 +523,13 @@ public String createExperiment(AuthzToken authzToken, String gatewayId, Experime * @throws AiravataClientException * @throws AiravataSystemException * @throws AuthorizationException - * @throws TException */ @Override @SecurityCheck public boolean deleteExperiment(AuthzToken authzToken, String experimentId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.deleteExperimentWithAuth( authzToken, experimentId); + throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, + ExperimentNotFoundException, ProjectNotFoundException { + return airavataService.deleteExperimentWithAuth(authzToken, experimentId); } /** @@ -574,7 +558,7 @@ public boolean deleteExperiment(AuthzToken authzToken, String experimentId) @SecurityCheck public ExperimentModel getExperiment(AuthzToken authzToken, String airavataExperimentId) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, - AiravataSystemException, AuthorizationException, TException { + AiravataSystemException, AuthorizationException { return airavataService.getExperiment(authzToken, airavataExperimentId); } @@ -582,7 +566,7 @@ public ExperimentModel getExperiment(AuthzToken authzToken, String airavataExper @SecurityCheck public ExperimentModel getExperimentByAdmin(AuthzToken authzToken, String airavataExperimentId) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, - AiravataSystemException, AuthorizationException, TException { + AiravataSystemException, AuthorizationException { return airavataService.getExperimentByAdmin(authzToken, airavataExperimentId); } /** @@ -644,7 +628,7 @@ public ExperimentModel getDetailedExperimentTree(AuthzToken authzToken, String a @SecurityCheck public void updateExperiment(AuthzToken authzToken, String airavataExperimentId, ExperimentModel experiment) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, - AiravataSystemException, AuthorizationException, TException { + AiravataSystemException, AuthorizationException { airavataService.updateExperiment(authzToken, airavataExperimentId, experiment); } @@ -652,7 +636,7 @@ public void updateExperiment(AuthzToken authzToken, String airavataExperimentId, @SecurityCheck public void updateExperimentConfiguration( AuthzToken authzToken, String airavataExperimentId, UserConfigurationDataModel userConfiguration) - throws AuthorizationException, TException { + throws AuthorizationException, AiravataSystemException { airavataService.updateExperimentConfiguration(airavataExperimentId, userConfiguration); } @@ -660,7 +644,7 @@ public void updateExperimentConfiguration( @SecurityCheck public void updateResourceScheduleing( AuthzToken authzToken, String airavataExperimentId, ComputationalResourceSchedulingModel resourceScheduling) - throws AuthorizationException, TException { + throws AuthorizationException, AiravataSystemException { airavataService.updateResourceScheduleing(airavataExperimentId, resourceScheduling); } @@ -678,7 +662,8 @@ public void updateResourceScheduleing( @Override @SecurityCheck public boolean validateExperiment(AuthzToken authzToken, String airavataExperimentId) - throws AiravataClientException, AiravataSystemException, AuthorizationException, ExperimentNotFoundException, InvalidRequestException { + throws AiravataClientException, AiravataSystemException, AuthorizationException, + ExperimentNotFoundException, InvalidRequestException { // TODO - call validation module and validate experiment /* try { ExperimentModel existingExperiment = airavataService.getExperiment(airavataExperimentId); @@ -688,7 +673,7 @@ public boolean validateExperiment(AuthzToken authzToken, String airavataExperime } } catch (RegistryServiceException | ApplicationSettingsException e1) { logger.error(airavataExperimentId, "Error while retrieving projects", e1); - throw ThriftExceptionHandler.convertException(e, "Error occurred"); + // Commented out code - not used } Client orchestratorClient = getOrchestratorClient(); @@ -730,15 +715,16 @@ public boolean validateExperiment(AuthzToken authzToken, String airavataExperime */ @Override @SecurityCheck - public ExperimentStatus getExperimentStatus(AuthzToken authzToken, String airavataExperimentId) { - return airavataService.getExperimentStatus(airavataExperimentId); + public ExperimentStatus getExperimentStatus(AuthzToken authzToken, String airavataExperimentId) + throws AiravataSystemException { + return airavataService.getExperimentStatus(airavataExperimentId); } @Override @SecurityCheck public List getExperimentOutputs(AuthzToken authzToken, String airavataExperimentId) - throws AuthorizationException { - return airavataService.getExperimentOutputs(airavataExperimentId); + throws AuthorizationException, AiravataSystemException { + return airavataService.getExperimentOutputs(airavataExperimentId); } @Override @@ -754,7 +740,8 @@ public List getIntermediateOutputs(AuthzToken authzToken, public void fetchIntermediateOutputs(AuthzToken authzToken, String airavataExperimentId, List outputNames) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException { - airavataService.validateAndFetchIntermediateOutputs( authzToken, airavataExperimentId, outputNames, experimentPublisher); + airavataService.validateAndFetchIntermediateOutputs( + authzToken, airavataExperimentId, outputNames, experimentPublisher); } @Override @@ -763,13 +750,14 @@ public ProcessStatus getIntermediateOutputProcessStatus( AuthzToken authzToken, String airavataExperimentId, List outputNames) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getIntermediateOutputProcessStatusInternal( authzToken, airavataExperimentId, outputNames); + return airavataService.getIntermediateOutputProcessStatusInternal( + authzToken, airavataExperimentId, outputNames); } @SecurityCheck public Map getJobStatuses(AuthzToken authzToken, String airavataExperimentId) - throws AuthorizationException { - return airavataService.getJobStatuses(airavataExperimentId); + throws AuthorizationException, AiravataSystemException { + return airavataService.getJobStatuses(airavataExperimentId); } @Override @@ -777,7 +765,7 @@ public Map getJobStatuses(AuthzToken authzToken, String airav public List getJobDetails(AuthzToken authzToken, String airavataExperimentId) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getJobDetails(airavataExperimentId); + return airavataService.getJobDetails(airavataExperimentId); } /** @@ -810,8 +798,10 @@ public List getJobDetails(AuthzToken authzToken, String airavataExperi @Override @SecurityCheck public void launchExperiment(AuthzToken authzToken, final String airavataExperimentId, String gatewayId) - throws AiravataClientException, AiravataSystemException, AuthorizationException, ExperimentNotFoundException, InvalidRequestException, TException { - airavataService.launchExperimentWithValidation( authzToken, gatewayId, airavataExperimentId, experimentPublisher); + throws AiravataClientException, AiravataSystemException, AuthorizationException, + ExperimentNotFoundException, InvalidRequestException, ProjectNotFoundException { + airavataService.launchExperimentWithValidation( + authzToken, gatewayId, airavataExperimentId, experimentPublisher); } /** @@ -861,14 +851,10 @@ public String cloneExperiment( AuthzToken authzToken, String existingExperimentID, String newExperimentName, String newExperimentProjectId) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException, ProjectNotFoundException { - // getExperiment will apply sharing permissions - ExperimentModel existingExperiment = airavataService.getExperiment(authzToken, existingExperimentID); + // getExperiment will apply sharing permissions + ExperimentModel existingExperiment = airavataService.getExperiment(authzToken, existingExperimentID); return airavataService.cloneExperimentInternal( - authzToken, - existingExperimentID, - newExperimentName, - newExperimentProjectId, - existingExperiment); + authzToken, existingExperimentID, newExperimentName, newExperimentProjectId, existingExperiment); } @Override @@ -877,14 +863,10 @@ public String cloneExperimentByAdmin( AuthzToken authzToken, String existingExperimentID, String newExperimentName, String newExperimentProjectId) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException, ProjectNotFoundException { - // get existing experiment by bypassing normal sharing permissions for the admin user - ExperimentModel existingExperiment = airavataService.getExperimentByAdmin(authzToken, existingExperimentID); + // get existing experiment by bypassing normal sharing permissions for the admin user + ExperimentModel existingExperiment = airavataService.getExperimentByAdmin(authzToken, existingExperimentID); return airavataService.cloneExperimentInternal( - authzToken, - existingExperimentID, - newExperimentName, - newExperimentProjectId, - existingExperiment); + authzToken, existingExperimentID, newExperimentName, newExperimentProjectId, existingExperiment); } /** @@ -928,7 +910,7 @@ public void terminateExperiment(AuthzToken authzToken, String airavataExperiment public String registerApplicationModule( AuthzToken authzToken, String gatewayId, ApplicationModule applicationModule) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.registerApplicationModule(gatewayId, applicationModule); + return airavataService.registerApplicationModule(gatewayId, applicationModule); } /** @@ -942,7 +924,7 @@ public String registerApplicationModule( @SecurityCheck public ApplicationModule getApplicationModule(AuthzToken authzToken, String appModuleId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getApplicationModule(appModuleId); + return airavataService.getApplicationModule(appModuleId); } /** @@ -958,7 +940,7 @@ public ApplicationModule getApplicationModule(AuthzToken authzToken, String appM public boolean updateApplicationModule( AuthzToken authzToken, String appModuleId, ApplicationModule applicationModule) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.updateApplicationModule(appModuleId, applicationModule); + return airavataService.updateApplicationModule(appModuleId, applicationModule); } /** @@ -971,7 +953,7 @@ public boolean updateApplicationModule( @SecurityCheck public List getAllAppModules(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getAllAppModules(gatewayId); + return airavataService.getAllAppModules(gatewayId); } /** @@ -984,7 +966,7 @@ public List getAllAppModules(AuthzToken authzToken, String ga @SecurityCheck public List getAccessibleAppModules(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getAccessibleAppModulesWithSharing( authzToken, gatewayId); + return airavataService.getAccessibleAppModulesWithSharing(authzToken, gatewayId); } /** @@ -998,7 +980,7 @@ public List getAccessibleAppModules(AuthzToken authzToken, St @SecurityCheck public boolean deleteApplicationModule(AuthzToken authzToken, String appModuleId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.deleteApplicationModule(appModuleId); + return airavataService.deleteApplicationModule(appModuleId); } /** @@ -1083,7 +1065,7 @@ public List getAllApplicationDeployments(Authz public List getAccessibleApplicationDeployments( AuthzToken authzToken, String gatewayId, ResourcePermissionType permissionType) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getAccessibleApplicationDeploymentsWithSharing( authzToken, gatewayId, permissionType); + return airavataService.getAccessibleApplicationDeploymentsWithSharing(authzToken, gatewayId, permissionType); } /** @@ -1098,7 +1080,7 @@ public List getAccessibleApplicationDeployment @Deprecated public List getAppModuleDeployedResources(AuthzToken authzToken, String appModuleId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getAppModuleDeployedResources(appModuleId); + return airavataService.getAppModuleDeployedResources(appModuleId); } /** @@ -1134,7 +1116,7 @@ public List getApplicationDeploymentsForAppMod public String registerApplicationInterface( AuthzToken authzToken, String gatewayId, ApplicationInterfaceDescription applicationInterface) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.registerApplicationInterface(gatewayId, applicationInterface); + return airavataService.registerApplicationInterface(gatewayId, applicationInterface); } @Override @@ -1172,7 +1154,7 @@ public ApplicationInterfaceDescription getApplicationInterface(AuthzToken authzT public boolean updateApplicationInterface( AuthzToken authzToken, String appInterfaceId, ApplicationInterfaceDescription applicationInterface) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.updateApplicationInterface(appInterfaceId, applicationInterface); + return airavataService.updateApplicationInterface(appInterfaceId, applicationInterface); } /** @@ -1186,7 +1168,7 @@ public boolean updateApplicationInterface( @SecurityCheck public boolean deleteApplicationInterface(AuthzToken authzToken, String appInterfaceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.deleteApplicationInterface(appInterfaceId); + return airavataService.deleteApplicationInterface(appInterfaceId); } /** @@ -1199,7 +1181,7 @@ public boolean deleteApplicationInterface(AuthzToken authzToken, String appInter @SecurityCheck public Map getAllApplicationInterfaceNames(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getAllApplicationInterfaceNames(gatewayId); + return airavataService.getAllApplicationInterfaceNames(gatewayId); } /** @@ -1212,7 +1194,7 @@ public Map getAllApplicationInterfaceNames(AuthzToken authzToken @SecurityCheck public List getAllApplicationInterfaces(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getAllApplicationInterfaces(gatewayId); + return airavataService.getAllApplicationInterfaces(gatewayId); } /** @@ -1226,7 +1208,7 @@ public List getAllApplicationInterfaces(AuthzTo @SecurityCheck public List getApplicationInputs(AuthzToken authzToken, String appInterfaceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getApplicationInputs(appInterfaceId); + return airavataService.getApplicationInputs(appInterfaceId); } /** @@ -1256,7 +1238,7 @@ public List getApplicationOutputs(AuthzToken authzToken, S @Deprecated public Map getAvailableAppInterfaceComputeResources(AuthzToken authzToken, String appInterfaceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getAvailableAppInterfaceComputeResources(appInterfaceId); + return airavataService.getAvailableAppInterfaceComputeResources(appInterfaceId); } /** @@ -1270,7 +1252,7 @@ public Map getAvailableAppInterfaceComputeResources(AuthzToken a @SecurityCheck public String registerComputeResource(AuthzToken authzToken, ComputeResourceDescription computeResourceDescription) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.registerComputeResource(computeResourceDescription); + return airavataService.registerComputeResource(computeResourceDescription); } /** @@ -1284,7 +1266,7 @@ public String registerComputeResource(AuthzToken authzToken, ComputeResourceDesc @SecurityCheck public ComputeResourceDescription getComputeResource(AuthzToken authzToken, String computeResourceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getComputeResource(computeResourceId); + return airavataService.getComputeResource(computeResourceId); } /** @@ -1297,7 +1279,7 @@ public ComputeResourceDescription getComputeResource(AuthzToken authzToken, Stri @SecurityCheck public Map getAllComputeResourceNames(AuthzToken authzToken) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getAllComputeResourceNames(); + return airavataService.getAllComputeResourceNames(); } /** @@ -1313,7 +1295,7 @@ public Map getAllComputeResourceNames(AuthzToken authzToken) public boolean updateComputeResource( AuthzToken authzToken, String computeResourceId, ComputeResourceDescription computeResourceDescription) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.updateComputeResource(computeResourceId, computeResourceDescription); + return airavataService.updateComputeResource(computeResourceId, computeResourceDescription); } /** @@ -1327,7 +1309,7 @@ public boolean updateComputeResource( @SecurityCheck public boolean deleteComputeResource(AuthzToken authzToken, String computeResourceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.deleteComputeResource(computeResourceId); + return airavataService.deleteComputeResource(computeResourceId); } /** @@ -1342,7 +1324,7 @@ public boolean deleteComputeResource(AuthzToken authzToken, String computeResour @SecurityCheck public String registerStorageResource(AuthzToken authzToken, StorageResourceDescription storageResourceDescription) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.registerStorageResource(storageResourceDescription); + return airavataService.registerStorageResource(storageResourceDescription); } /** @@ -1357,7 +1339,7 @@ public String registerStorageResource(AuthzToken authzToken, StorageResourceDesc @SecurityCheck public StorageResourceDescription getStorageResource(AuthzToken authzToken, String storageResourceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getStorageResource(storageResourceId); + return airavataService.getStorageResource(storageResourceId); } /** @@ -1371,7 +1353,7 @@ public StorageResourceDescription getStorageResource(AuthzToken authzToken, Stri @SecurityCheck public Map getAllStorageResourceNames(AuthzToken authzToken) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getAllStorageResourceNames(); + return airavataService.getAllStorageResourceNames(); } /** @@ -1388,7 +1370,7 @@ public Map getAllStorageResourceNames(AuthzToken authzToken) public boolean updateStorageResource( AuthzToken authzToken, String storageResourceId, StorageResourceDescription storageResourceDescription) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.updateStorageResource(storageResourceId, storageResourceDescription); + return airavataService.updateStorageResource(storageResourceId, storageResourceDescription); } /** @@ -1403,7 +1385,7 @@ public boolean updateStorageResource( @SecurityCheck public boolean deleteStorageResource(AuthzToken authzToken, String storageResourceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.deleteStorageResource(storageResourceId); + return airavataService.deleteStorageResource(storageResourceId); } @Override @@ -1433,8 +1415,9 @@ public StorageDirectoryInfo getStorageDirectoryInfo(AuthzToken authzToken, Strin @Override @SecurityCheck public String addLocalSubmissionDetails( - AuthzToken authzToken, String computeResourceId, int priorityOrder, LOCALSubmission localSubmission){ - return airavataService.addLocalSubmissionDetails(computeResourceId, priorityOrder, localSubmission); + AuthzToken authzToken, String computeResourceId, int priorityOrder, LOCALSubmission localSubmission) + throws AiravataSystemException { + return airavataService.addLocalSubmissionDetails(computeResourceId, priorityOrder, localSubmission); } /** @@ -1450,14 +1433,14 @@ public String addLocalSubmissionDetails( public boolean updateLocalSubmissionDetails( AuthzToken authzToken, String jobSubmissionInterfaceId, LOCALSubmission localSubmission) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.updateLocalSubmissionDetails(jobSubmissionInterfaceId, localSubmission); + return airavataService.updateLocalSubmissionDetails(jobSubmissionInterfaceId, localSubmission); } @Override @SecurityCheck public LOCALSubmission getLocalJobSubmission(AuthzToken authzToken, String jobSubmissionId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getLocalJobSubmission(jobSubmissionId); + return airavataService.getLocalJobSubmission(jobSubmissionId); } /** @@ -1475,7 +1458,7 @@ public LOCALSubmission getLocalJobSubmission(AuthzToken authzToken, String jobSu public String addSSHJobSubmissionDetails( AuthzToken authzToken, String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.addSSHJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); + return airavataService.addSSHJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); } /** @@ -1493,14 +1476,14 @@ public String addSSHJobSubmissionDetails( public String addSSHForkJobSubmissionDetails( AuthzToken authzToken, String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.addSSHForkJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); + return airavataService.addSSHForkJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); } @Override @SecurityCheck public SSHJobSubmission getSSHJobSubmission(AuthzToken authzToken, String jobSubmissionId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getSSHJobSubmission(jobSubmissionId); + return airavataService.getSSHJobSubmission(jobSubmissionId); } /** @@ -1518,14 +1501,14 @@ public SSHJobSubmission getSSHJobSubmission(AuthzToken authzToken, String jobSub public String addCloudJobSubmissionDetails( AuthzToken authzToken, String computeResourceId, int priorityOrder, CloudJobSubmission cloudJobSubmission) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.addCloudJobSubmissionDetails(computeResourceId, priorityOrder, cloudJobSubmission); + return airavataService.addCloudJobSubmissionDetails(computeResourceId, priorityOrder, cloudJobSubmission); } @Override @SecurityCheck public CloudJobSubmission getCloudJobSubmission(AuthzToken authzToken, String jobSubmissionId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getCloudJobSubmission(jobSubmissionId); + return airavataService.getCloudJobSubmission(jobSubmissionId); } @Override @@ -1536,15 +1519,14 @@ public String addUNICOREJobSubmissionDetails( int priorityOrder, UnicoreJobSubmission unicoreJobSubmission) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.addUNICOREJobSubmissionDetails( - computeResourceId, priorityOrder, unicoreJobSubmission); + return airavataService.addUNICOREJobSubmissionDetails(computeResourceId, priorityOrder, unicoreJobSubmission); } @Override @SecurityCheck public UnicoreJobSubmission getUnicoreJobSubmission(AuthzToken authzToken, String jobSubmissionId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getUnicoreJobSubmission(jobSubmissionId); + return airavataService.getUnicoreJobSubmission(jobSubmissionId); } /** @@ -1560,7 +1542,7 @@ public UnicoreJobSubmission getUnicoreJobSubmission(AuthzToken authzToken, Strin public boolean updateSSHJobSubmissionDetails( AuthzToken authzToken, String jobSubmissionInterfaceId, SSHJobSubmission sshJobSubmission) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.updateSSHJobSubmissionDetails(jobSubmissionInterfaceId, sshJobSubmission); + return airavataService.updateSSHJobSubmissionDetails(jobSubmissionInterfaceId, sshJobSubmission); } /** @@ -1576,7 +1558,7 @@ public boolean updateSSHJobSubmissionDetails( public boolean updateCloudJobSubmissionDetails( AuthzToken authzToken, String jobSubmissionInterfaceId, CloudJobSubmission cloudJobSubmission) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.updateCloudJobSubmissionDetails(jobSubmissionInterfaceId, cloudJobSubmission); + return airavataService.updateCloudJobSubmissionDetails(jobSubmissionInterfaceId, cloudJobSubmission); } @Override @@ -1584,7 +1566,7 @@ public boolean updateCloudJobSubmissionDetails( public boolean updateUnicoreJobSubmissionDetails( AuthzToken authzToken, String jobSubmissionInterfaceId, UnicoreJobSubmission unicoreJobSubmission) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.updateUnicoreJobSubmissionDetails(jobSubmissionInterfaceId, unicoreJobSubmission); + return airavataService.updateUnicoreJobSubmissionDetails(jobSubmissionInterfaceId, unicoreJobSubmission); } /** @@ -1606,7 +1588,7 @@ public String addLocalDataMovementDetails( int priorityOrder, LOCALDataMovement localDataMovement) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.addLocalDataMovementDetails(resourceId, dmType, priorityOrder, localDataMovement); + return airavataService.addLocalDataMovementDetails(resourceId, dmType, priorityOrder, localDataMovement); } /** @@ -1622,7 +1604,7 @@ public String addLocalDataMovementDetails( public boolean updateLocalDataMovementDetails( AuthzToken authzToken, String dataMovementInterfaceId, LOCALDataMovement localDataMovement) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.updateLocalDataMovementDetails(dataMovementInterfaceId, localDataMovement); + return airavataService.updateLocalDataMovementDetails(dataMovementInterfaceId, localDataMovement); } /** @@ -1640,7 +1622,7 @@ public boolean updateLocalDataMovementDetails( public String addSCPDataMovementDetails( AuthzToken authzToken, String resourceId, DMType dmType, int priorityOrder, SCPDataMovement scpDataMovement) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.addSCPDataMovementDetails(resourceId, dmType, priorityOrder, scpDataMovement); + return airavataService.addSCPDataMovementDetails(resourceId, dmType, priorityOrder, scpDataMovement); } /** @@ -1657,14 +1639,14 @@ public String addSCPDataMovementDetails( public boolean updateSCPDataMovementDetails( AuthzToken authzToken, String dataMovementInterfaceId, SCPDataMovement scpDataMovement) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.updateSCPDataMovementDetails(dataMovementInterfaceId, scpDataMovement); + return airavataService.updateSCPDataMovementDetails(dataMovementInterfaceId, scpDataMovement); } @Override @SecurityCheck public SCPDataMovement getSCPDataMovement(AuthzToken authzToken, String dataMovementId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getSCPDataMovement(dataMovementId); + return airavataService.getSCPDataMovement(dataMovementId); } @Override @@ -1676,7 +1658,7 @@ public String addUnicoreDataMovementDetails( int priorityOrder, UnicoreDataMovement unicoreDataMovement) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.addUnicoreDataMovementDetails(resourceId, dmType, priorityOrder, unicoreDataMovement); + return airavataService.addUnicoreDataMovementDetails(resourceId, dmType, priorityOrder, unicoreDataMovement); } @Override @@ -1684,21 +1666,21 @@ public String addUnicoreDataMovementDetails( public boolean updateUnicoreDataMovementDetails( AuthzToken authzToken, String dataMovementInterfaceId, UnicoreDataMovement unicoreDataMovement) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.updateUnicoreDataMovementDetails(dataMovementInterfaceId, unicoreDataMovement); + return airavataService.updateUnicoreDataMovementDetails(dataMovementInterfaceId, unicoreDataMovement); } @Override @SecurityCheck public LOCALDataMovement getLocalDataMovement(AuthzToken authzToken, String dataMovementId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getLocalDataMovement(dataMovementId); + return airavataService.getLocalDataMovement(dataMovementId); } @Override @SecurityCheck public UnicoreDataMovement getUnicoreDataMovement(AuthzToken authzToken, String dataMovementId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getUnicoreDataMovement(dataMovementId); + return airavataService.getUnicoreDataMovement(dataMovementId); } /** @@ -1720,7 +1702,8 @@ public String addGridFTPDataMovementDetails( int priorityOrder, GridFTPDataMovement gridFTPDataMovement) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.addGridFTPDataMovementDetails(computeResourceId, dmType, priorityOrder, gridFTPDataMovement); + return airavataService.addGridFTPDataMovementDetails( + computeResourceId, dmType, priorityOrder, gridFTPDataMovement); } /** @@ -1737,14 +1720,14 @@ public String addGridFTPDataMovementDetails( public boolean updateGridFTPDataMovementDetails( AuthzToken authzToken, String dataMovementInterfaceId, GridFTPDataMovement gridFTPDataMovement) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.updateGridFTPDataMovementDetails(dataMovementInterfaceId, gridFTPDataMovement); + return airavataService.updateGridFTPDataMovementDetails(dataMovementInterfaceId, gridFTPDataMovement); } @Override @SecurityCheck public GridFTPDataMovement getGridFTPDataMovement(AuthzToken authzToken, String dataMovementId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getGridFTPDataMovement(dataMovementId); + return airavataService.getGridFTPDataMovement(dataMovementId); } /** @@ -1819,7 +1802,7 @@ public boolean changeDataMovementPriorities(AuthzToken authzToken, Map getAllGatewayComputeResourcePreferences( AuthzToken authzToken, String gatewayID) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getAllGatewayComputeResourcePreferences(gatewayID); + return airavataService.getAllGatewayComputeResourcePreferences(gatewayID); } @Override @SecurityCheck public List getAllGatewayStoragePreferences(AuthzToken authzToken, String gatewayID) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getAllGatewayStoragePreferences(gatewayID); + return airavataService.getAllGatewayStoragePreferences(gatewayID); } @Override @SecurityCheck public List getAllGatewayResourceProfiles(AuthzToken authzToken) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getAllGatewayResourceProfiles(); + return airavataService.getAllGatewayResourceProfiles(); } /** @@ -2031,7 +2015,8 @@ public boolean updateGatewayComputeResourcePreference( String computeResourceId, ComputeResourcePreference computeResourcePreference) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.updateGatewayComputeResourcePreference(gatewayID, computeResourceId, computeResourcePreference); + return airavataService.updateGatewayComputeResourcePreference( + gatewayID, computeResourceId, computeResourcePreference); } @Override @@ -2039,7 +2024,7 @@ public boolean updateGatewayComputeResourcePreference( public boolean updateGatewayStoragePreference( AuthzToken authzToken, String gatewayID, String storageId, StoragePreference dataStoragePreference) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.updateGatewayStoragePreference(gatewayID, storageId, dataStoragePreference); + return airavataService.updateGatewayStoragePreference(gatewayID, storageId, dataStoragePreference); } /** @@ -2055,14 +2040,14 @@ public boolean updateGatewayStoragePreference( public boolean deleteGatewayComputeResourcePreference( AuthzToken authzToken, String gatewayID, String computeResourceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.deleteGatewayComputeResourcePreference(gatewayID, computeResourceId); + return airavataService.deleteGatewayComputeResourcePreference(gatewayID, computeResourceId); } @Override @SecurityCheck public boolean deleteGatewayStoragePreference(AuthzToken authzToken, String gatewayID, String storageId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.deleteGatewayStoragePreference(gatewayID, storageId); + return airavataService.deleteGatewayStoragePreference(gatewayID, storageId); } @Override @@ -2114,7 +2099,7 @@ public boolean doesUserHaveSSHAccount(AuthzToken authzToken, String computeResou @SecurityCheck public boolean isSSHSetupCompleteForUserComputeResourcePreference( AuthzToken authzToken, String computeResourceId, String airavataCredStoreToken) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + throws AiravataClientException, AiravataSystemException, AuthorizationException { return airavataService.isSSHAccountSetupComplete(authzToken, computeResourceId, airavataCredStoreToken); } @@ -2139,14 +2124,14 @@ public UserComputeResourcePreference setupUserComputeResourcePreferencesForSSH( @SecurityCheck public String registerUserResourceProfile(AuthzToken authzToken, UserResourceProfile userResourceProfile) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.registerUserResourceProfile(userResourceProfile); + return airavataService.registerUserResourceProfile(userResourceProfile); } @Override @SecurityCheck public boolean isUserResourceProfileExists(AuthzToken authzToken, String userId, String gatewayID) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.isUserResourceProfileExists(userId, gatewayID); + return airavataService.isUserResourceProfileExists(userId, gatewayID); } /** @@ -2163,7 +2148,7 @@ public boolean isUserResourceProfileExists(AuthzToken authzToken, String userId, @SecurityCheck public UserResourceProfile getUserResourceProfile(AuthzToken authzToken, String userId, String gatewayID) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getUserResourceProfile(userId, gatewayID); + return airavataService.getUserResourceProfile(userId, gatewayID); } /** @@ -2180,7 +2165,7 @@ public UserResourceProfile getUserResourceProfile(AuthzToken authzToken, String public boolean updateUserResourceProfile( AuthzToken authzToken, String userId, String gatewayID, UserResourceProfile userResourceProfile) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.updateUserResourceProfile(userId, gatewayID, userResourceProfile); + return airavataService.updateUserResourceProfile(userId, gatewayID, userResourceProfile); } /** @@ -2195,7 +2180,7 @@ public boolean updateUserResourceProfile( @SecurityCheck public boolean deleteUserResourceProfile(AuthzToken authzToken, String userId, String gatewayID) throws AiravataClientException, AiravataSystemException, AuthorizationException, InvalidRequestException { - return airavataService.deleteUserResourceProfile(userId, gatewayID); + return airavataService.deleteUserResourceProfile(userId, gatewayID); } /** @@ -2218,8 +2203,8 @@ public boolean addUserComputeResourcePreference( String userComputeResourceId, UserComputeResourcePreference userComputeResourcePreference) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.addUserComputeResourcePreference( - userId, gatewayID, userComputeResourceId, userComputeResourcePreference); + return airavataService.addUserComputeResourcePreference( + userId, gatewayID, userComputeResourceId, userComputeResourcePreference); } @Override @@ -2231,7 +2216,8 @@ public boolean addUserStoragePreference( String userStorageResourceId, UserStoragePreference dataStoragePreference) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.addUserStoragePreference(userId, gatewayID, userStorageResourceId, dataStoragePreference); + return airavataService.addUserStoragePreference( + userId, gatewayID, userStorageResourceId, dataStoragePreference); } /** @@ -2248,7 +2234,7 @@ public boolean addUserStoragePreference( public UserComputeResourcePreference getUserComputeResourcePreference( AuthzToken authzToken, String userId, String gatewayID, String userComputeResourceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getUserComputeResourcePreference(userId, gatewayID, userComputeResourceId); + return airavataService.getUserComputeResourcePreference(userId, gatewayID, userComputeResourceId); } @Override @@ -2256,7 +2242,7 @@ public UserComputeResourcePreference getUserComputeResourcePreference( public UserStoragePreference getUserStoragePreference( AuthzToken authzToken, String userId, String gatewayID, String userStorageId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getUserStoragePreference(userId, gatewayID, userStorageId); + return airavataService.getUserStoragePreference(userId, gatewayID, userStorageId); } /** @@ -2272,7 +2258,7 @@ public UserStoragePreference getUserStoragePreference( public List getAllUserComputeResourcePreferences( AuthzToken authzToken, String userId, String gatewayID) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getAllUserComputeResourcePreferences(userId, gatewayID); + return airavataService.getAllUserComputeResourcePreferences(userId, gatewayID); } @Override @@ -2280,14 +2266,14 @@ public List getAllUserComputeResourcePreferences( public List getAllUserStoragePreferences( AuthzToken authzToken, String userId, String gatewayID) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getAllUserStoragePreferences(userId, gatewayID); + return airavataService.getAllUserStoragePreferences(userId, gatewayID); } @Override @SecurityCheck public List getAllUserResourceProfiles(AuthzToken authzToken) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getAllUserResourceProfiles(); + return airavataService.getAllUserResourceProfiles(); } /** @@ -2309,7 +2295,8 @@ public boolean updateUserComputeResourcePreference( String userComputeResourceId, UserComputeResourcePreference userComputeResourcePreference) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.updateUserComputeResourcePreference(userId, gatewayID, userComputeResourceId, userComputeResourcePreference); + return airavataService.updateUserComputeResourcePreference( + userId, gatewayID, userComputeResourceId, userComputeResourcePreference); } @Override @@ -2321,7 +2308,7 @@ public boolean updateUserStoragePreference( String userStorageId, UserStoragePreference dataStoragePreference) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.updateUserStoragePreference(userId, gatewayID, userStorageId, dataStoragePreference); + return airavataService.updateUserStoragePreference(userId, gatewayID, userStorageId, dataStoragePreference); } /** @@ -2338,7 +2325,7 @@ public boolean updateUserStoragePreference( public boolean deleteUserComputeResourcePreference( AuthzToken authzToken, String userId, String gatewayID, String userComputeResourceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.deleteUserComputeResourcePreference(userId, gatewayID, userComputeResourceId); + return airavataService.deleteUserComputeResourcePreference(userId, gatewayID, userComputeResourceId); } @Override @@ -2346,55 +2333,54 @@ public boolean deleteUserComputeResourcePreference( public boolean deleteUserStoragePreference( AuthzToken authzToken, String userId, String gatewayID, String userStorageId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.deleteUserStoragePreference(userId, gatewayID, userStorageId); + return airavataService.deleteUserStoragePreference(userId, gatewayID, userStorageId); } @Override @SecurityCheck public List getLatestQueueStatuses(AuthzToken authzToken) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getLatestQueueStatuses(); + return airavataService.getLatestQueueStatuses(); } /** * ReplicaCatalog Related Methods * @return - * @throws TException * @throws ApplicationSettingsException */ @Override @SecurityCheck public String registerDataProduct(AuthzToken authzToken, DataProductModel dataProductModel) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.registerDataProduct(dataProductModel); + return airavataService.registerDataProduct(dataProductModel); } @Override @SecurityCheck public DataProductModel getDataProduct(AuthzToken authzToken, String productUri) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getDataProduct(productUri); + return airavataService.getDataProduct(productUri); } @Override @SecurityCheck public String registerReplicaLocation(AuthzToken authzToken, DataReplicaLocationModel replicaLocationModel) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.registerReplicaLocation(replicaLocationModel); + return airavataService.registerReplicaLocation(replicaLocationModel); } @Override @SecurityCheck public DataProductModel getParentDataProduct(AuthzToken authzToken, String productUri) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getParentDataProduct(productUri); + return airavataService.getParentDataProduct(productUri); } @Override @SecurityCheck public List getChildDataProducts(AuthzToken authzToken, String productUri) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getChildDataProducts(productUri); + return airavataService.getChildDataProducts(productUri); } /** @@ -2435,13 +2421,14 @@ public boolean revokeSharingOfResourceFromGroups( throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { final String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); try { - if (!airavataService.userHasAccessInternal( authzToken, resourceId, ResourcePermissionType.OWNER) - && !airavataService.userHasAccessInternal( authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { + if (!airavataService.userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.OWNER) + && !airavataService.userHasAccessInternal( + authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { throw new AuthorizationException( "User is not allowed to change sharing because the user is either not the resource owner or does not have access to share the resource"); } // For certain resource types, restrict them from being unshared with admin groups - ResourceType resourceType = airavataService.getResourceType( gatewayId, resourceId); + ResourceType resourceType = airavataService.getResourceType(gatewayId, resourceId); Set adminRestrictedResourceTypes = new HashSet<>(Arrays.asList( ResourceType.EXPERIMENT, ResourceType.APPLICATION_DEPLOYMENT, ResourceType.GROUP_RESOURCE_PROFILE)); if (adminRestrictedResourceTypes.contains(resourceType)) { @@ -2480,8 +2467,8 @@ else if (groupPermission.getValue().equals(ResourcePermissionType.READ)) airavataService.revokeEntitySharingFromUsers( gatewayId, resourceId, Arrays.asList(groupPermission.getKey()), gatewayId + ":" + "READ"); else if (groupPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING)) { - if (airavataService.userHasAccessInternal( authzToken, resourceId, ResourcePermissionType.OWNER)) { - airavataService.createManageSharingPermissionTypeIfMissing( gatewayId); + if (airavataService.userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.OWNER)) { + airavataService.createManageSharingPermissionTypeIfMissing(gatewayId); airavataService.revokeEntitySharingFromUsers( gatewayId, resourceId, @@ -2497,10 +2484,19 @@ else if (groupPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING } } return true; - } catch (Throwable e) { + } catch (InvalidRequestException + | AiravataClientException + | AiravataSystemException + | AuthorizationException e) { + throw e; + } catch (Exception e) { String msg = "Error in revoking access to resource from groups. Resource ID : " + resourceId; logger.error(msg, e); - throw ThriftExceptionHandler.convertException(e, msg); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + ". More info: " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2509,7 +2505,7 @@ else if (groupPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING public List getAllAccessibleUsers( AuthzToken authzToken, String resourceId, ResourcePermissionType permissionType) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getAllAccessibleUsersWithSharing( authzToken, resourceId, permissionType, false); + return airavataService.getAllAccessibleUsersWithSharing(authzToken, resourceId, permissionType, false); } @Override @@ -2517,7 +2513,7 @@ public List getAllAccessibleUsers( public List getAllDirectlyAccessibleUsers( AuthzToken authzToken, String resourceId, ResourcePermissionType permissionType) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getAllAccessibleUsersWithSharing( authzToken, resourceId, permissionType, true); + return airavataService.getAllAccessibleUsersWithSharing(authzToken, resourceId, permissionType, true); } @Override @@ -2525,7 +2521,7 @@ public List getAllDirectlyAccessibleUsers( public List getAllAccessibleGroups( AuthzToken authzToken, String resourceId, ResourcePermissionType permissionType) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getAllAccessibleGroupsWithSharing( authzToken, resourceId, permissionType, false); + return airavataService.getAllAccessibleGroupsWithSharing(authzToken, resourceId, permissionType, false); } @Override @@ -2533,7 +2529,7 @@ public List getAllAccessibleGroups( public List getAllDirectlyAccessibleGroups( AuthzToken authzToken, String resourceId, ResourcePermissionType permissionType) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getAllAccessibleGroupsWithSharing( authzToken, resourceId, permissionType, true); + return airavataService.getAllAccessibleGroupsWithSharing(authzToken, resourceId, permissionType, true); } @Override @@ -2575,7 +2571,7 @@ public boolean removeGroupResourceProfile(AuthzToken authzToken, String groupRes @SecurityCheck public List getGroupResourceList(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getGroupResourceListWithSharing( authzToken, gatewayId); + return airavataService.getGroupResourceListWithSharing(authzToken, gatewayId); } @Override @@ -2605,7 +2601,8 @@ public boolean removeGroupBatchQueueResourcePolicy(AuthzToken authzToken, String public GroupComputeResourcePreference getGroupComputeResourcePreference( AuthzToken authzToken, String computeResourceId, String groupResourceProfileId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getGroupComputeResourcePreferenceWithAuth(authzToken, computeResourceId, groupResourceProfileId); + return airavataService.getGroupComputeResourcePreferenceWithAuth( + authzToken, computeResourceId, groupResourceProfileId); } @Override @@ -2677,7 +2674,8 @@ public List listAllParsers(AuthzToken authzToken, String gatewayId) @Override @SecurityCheck - public boolean removeParser(AuthzToken authzToken, String parserId, String gatewayId){ + public boolean removeParser(AuthzToken authzToken, String parserId, String gatewayId) + throws AiravataSystemException { airavataService.removeParser(parserId, gatewayId); return true; } @@ -2722,5 +2720,4 @@ public List listAllParsingTemplates(AuthzToken authzToken, Stri /** * To hold storage info context (login username, credential token, and adaptor) */ - -} \ No newline at end of file +} diff --git a/airavata-api/src/main/java/org/apache/airavata/api/server/handler/ThriftExceptionHandler.java b/airavata-api/src/main/java/org/apache/airavata/api/server/handler/ThriftExceptionHandler.java deleted file mode 100644 index 803b164a6a..0000000000 --- a/airavata-api/src/main/java/org/apache/airavata/api/server/handler/ThriftExceptionHandler.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.apache.airavata.api.server.handler; - -import org.apache.airavata.registry.cpi.AppCatalogException; -import org.apache.airavata.registry.cpi.RegistryException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Global exception handler for Thrift server handlers. - * Converts service layer exceptions to appropriate Thrift exceptions. - */ -public class ThriftExceptionHandler { - private static final Logger logger = LoggerFactory.getLogger(ThriftExceptionHandler.class); - - public static RuntimeException convertException(Throwable e, String context) { - // Re-throw Thrift exceptions as-is - if (e instanceof org.apache.airavata.model.error.InvalidRequestException || - e instanceof org.apache.airavata.model.error.AiravataClientException || - e instanceof org.apache.airavata.model.error.AiravataSystemException || - e instanceof org.apache.airavata.model.error.AuthorizationException || - e instanceof org.apache.airavata.model.error.ExperimentNotFoundException || - e instanceof org.apache.airavata.model.error.ProjectNotFoundException) { - throw sneakyThrow(e); - } - - // Convert service exceptions to AiravataSystemException - if (e instanceof RegistryException || e instanceof AppCatalogException || - e instanceof org.apache.airavata.credential.store.store.CredentialStoreException || - e instanceof org.apache.airavata.sharing.registry.models.SharingRegistryException || - e instanceof org.apache.airavata.orchestrator.core.exception.OrchestratorException) { - logger.error(context, e); - org.apache.airavata.model.error.AiravataSystemException exception = new org.apache.airavata.model.error.AiravataSystemException(); - exception.setAiravataErrorType(org.apache.airavata.model.error.AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(context + ". More info : " + e.getMessage()); - exception.initCause(e); - throw sneakyThrow(exception); - } - - // Handle any other exception - logger.error(context, e); - org.apache.airavata.model.error.AiravataSystemException exception = new org.apache.airavata.model.error.AiravataSystemException(); - exception.setAiravataErrorType(org.apache.airavata.model.error.AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(context + ". More info : " + e.getMessage()); - exception.initCause(e); - throw sneakyThrow(exception); - } - - @SuppressWarnings("unchecked") - private static RuntimeException sneakyThrow(Throwable e) throws E { - throw (E) e; - } -} diff --git a/airavata-api/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java index cb702ebbc4..c6f0805930 100644 --- a/airavata-api/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java @@ -25,9 +25,9 @@ import java.util.Map; import org.apache.airavata.common.exception.ApplicationSettingsException; import org.apache.airavata.credential.store.cpi.credential_store_cpiConstants; +import org.apache.airavata.credential.store.exception.CredentialStoreException; import org.apache.airavata.model.credential.store.*; import org.apache.airavata.model.error.AiravataSystemException; -import org.apache.thrift.TException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; // import sun.security.provider.X509Factory; @@ -49,85 +49,75 @@ public String getAPIVersion() throws AiravataSystemException { } @Override - public String addSSHCredential(SSHCredential sshCredential) - throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { + public String addSSHCredential(SSHCredential sshCredential) throws CredentialStoreException { return credentialStoreService.addSSHCredential(sshCredential); } @Override public String addCertificateCredential(CertificateCredential certificateCredential) - throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { + throws CredentialStoreException { return credentialStoreService.addCertificateCredential(certificateCredential); } @Override - public String addPasswordCredential(PasswordCredential passwordCredential) - throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { + public String addPasswordCredential(PasswordCredential passwordCredential) throws CredentialStoreException { return credentialStoreService.addPasswordCredential(passwordCredential); } @Override - public SSHCredential getSSHCredential(String tokenId, String gatewayId) - throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { + public SSHCredential getSSHCredential(String tokenId, String gatewayId) throws CredentialStoreException { return credentialStoreService.getSSHCredential(tokenId, gatewayId); } @Override - public CredentialSummary getCredentialSummary(String tokenId, String gatewayId) - throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { + public CredentialSummary getCredentialSummary(String tokenId, String gatewayId) throws CredentialStoreException { return credentialStoreService.getCredentialSummary(tokenId, gatewayId); } @Override public List getAllCredentialSummaries( - SummaryType type, List accessibleTokenIds, String gatewayId) - throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { + SummaryType type, List accessibleTokenIds, String gatewayId) throws CredentialStoreException { return credentialStoreService.getAllCredentialSummaries(type, accessibleTokenIds, gatewayId); } @Override public CertificateCredential getCertificateCredential(String tokenId, String gatewayId) - throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { + throws CredentialStoreException { return credentialStoreService.getCertificateCredential(tokenId, gatewayId); } @Override - public PasswordCredential getPasswordCredential(String tokenId, String gatewayId) - throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { + public PasswordCredential getPasswordCredential(String tokenId, String gatewayId) throws CredentialStoreException { return credentialStoreService.getPasswordCredential(tokenId, gatewayId); } @Override @Deprecated public List getAllCredentialSummaryForGateway(SummaryType type, String gatewayId) - throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { + throws CredentialStoreException { return credentialStoreService.getAllCredentialSummaryForGateway(type, gatewayId); } @Override @Deprecated public List getAllCredentialSummaryForUserInGateway( - SummaryType type, String gatewayId, String userId) - throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { + SummaryType type, String gatewayId, String userId) throws CredentialStoreException { return credentialStoreService.getAllCredentialSummaryForUserInGateway(type, gatewayId, userId); } @Override @Deprecated - public Map getAllPWDCredentialsForGateway(String gatewayId) - throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { + public Map getAllPWDCredentialsForGateway(String gatewayId) throws CredentialStoreException { return credentialStoreService.getAllPWDCredentialsForGateway(gatewayId); } @Override - public boolean deleteSSHCredential(String tokenId, String gatewayId) - throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { + public boolean deleteSSHCredential(String tokenId, String gatewayId) throws CredentialStoreException { return credentialStoreService.deleteSSHCredential(tokenId, gatewayId); } @Override - public boolean deletePWDCredential(String tokenId, String gatewayId) - throws org.apache.airavata.credential.store.exception.CredentialStoreException, TException { + public boolean deletePWDCredential(String tokenId, String gatewayId) throws CredentialStoreException { return credentialStoreService.deletePWDCredential(tokenId, gatewayId); } } diff --git a/airavata-api/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java index 4872bdfbff..0eed4c532d 100644 --- a/airavata-api/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java @@ -20,7 +20,7 @@ package org.apache.airavata.orchestrator.server; import java.util.*; -import org.apache.airavata.api.server.handler.ThriftExceptionHandler; +import org.apache.airavata.model.error.AiravataErrorType; import org.apache.airavata.model.error.AiravataSystemException; import org.apache.airavata.model.error.LaunchValidationException; import org.apache.airavata.model.process.ProcessModel; @@ -62,10 +62,16 @@ public OrchestratorServerHandler() { public boolean launchExperiment(String experimentId, String gatewayId) throws AiravataSystemException { try { return orchestratorService.launchExperimentWithErrorHandling( - experimentId, gatewayId, org.apache.airavata.orchestrator.util.OrchestratorServerThreadPoolExecutor.getCachedThreadPool()); + experimentId, + gatewayId, + org.apache.airavata.orchestrator.util.OrchestratorServerThreadPoolExecutor.getCachedThreadPool()); } catch (Throwable e) { - ThriftExceptionHandler.convertException(e, "Error launching experiment: " + experimentId); - return false; // unreachable + log.error("Error launching experiment: " + experimentId, e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error launching experiment: " + experimentId + ". More info: " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -84,8 +90,11 @@ public boolean validateExperiment(String experimentId) throws LaunchValidationEx } catch (LaunchValidationException e) { throw e; } catch (Throwable e) { - ThriftExceptionHandler.convertException(e, "Error validating experiment: " + experimentId); - return false; // unreachable + log.error("Error validating experiment: " + experimentId, e); + LaunchValidationException exception = new LaunchValidationException(); + exception.setErrorMessage( + "Error validating experiment: " + experimentId + ". More info: " + e.getMessage()); + throw exception; } } @@ -96,8 +105,10 @@ public boolean validateProcess(String experimentId, List processes } catch (LaunchValidationException e) { throw e; } catch (Throwable e) { - ThriftExceptionHandler.convertException(e, "Error validating process: " + experimentId); - return false; // unreachable + log.error("Error validating process: " + experimentId, e); + LaunchValidationException exception = new LaunchValidationException(); + exception.setErrorMessage("Error validating process: " + experimentId + ". More info: " + e.getMessage()); + throw exception; } } @@ -114,27 +125,42 @@ public boolean terminateExperiment(String experimentId, String gatewayId) throws try { return orchestratorService.terminateExperiment(experimentId, gatewayId); } catch (Throwable e) { - ThriftExceptionHandler.convertException(e, "Error terminating experiment: " + experimentId); - return false; // unreachable + log.error("Error terminating experiment: " + experimentId, e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error terminating experiment: " + experimentId + ". More info: " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public void fetchIntermediateOutputs(String experimentId, String gatewayId, List outputNames) { + public void fetchIntermediateOutputs(String experimentId, String gatewayId, List outputNames) + throws AiravataSystemException { try { orchestratorService.fetchIntermediateOutputs(experimentId, gatewayId, outputNames); } catch (Throwable e) { log.error("Error fetching intermediate outputs for experiment: " + experimentId, e); - ThriftExceptionHandler.convertException(e, "Error fetching intermediate outputs: " + experimentId); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error fetching intermediate outputs for experiment: " + experimentId + ". More info: " + + e.getMessage()); + exception.initCause(e); + throw exception; } } @Override - public boolean launchProcess(String processId, String airavataCredStoreToken, String gatewayId) throws AiravataSystemException { + public boolean launchProcess(String processId, String airavataCredStoreToken, String gatewayId) + throws AiravataSystemException { try { return orchestratorService.launchProcess(processId, airavataCredStoreToken, gatewayId); } catch (Throwable e) { - ThriftExceptionHandler.convertException(e, "Error launching process: " + processId); - return false; // unreachable + log.error("Error launching process: " + processId, e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error launching process: " + processId + ". More info: " + e.getMessage()); + exception.initCause(e); + throw exception; } } } diff --git a/airavata-api/src/main/java/org/apache/airavata/registry/api/service/handler/RegistryServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/registry/api/service/handler/RegistryServerHandler.java index 50028a75f8..e04a340f40 100644 --- a/airavata-api/src/main/java/org/apache/airavata/registry/api/service/handler/RegistryServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/registry/api/service/handler/RegistryServerHandler.java @@ -47,8 +47,8 @@ import org.apache.airavata.model.data.movement.DMType; import org.apache.airavata.model.data.replica.DataProductModel; import org.apache.airavata.model.data.replica.DataReplicaLocationModel; -import org.apache.airavata.model.error.AiravataSystemException; import org.apache.airavata.model.error.*; +import org.apache.airavata.model.error.AiravataSystemException; import org.apache.airavata.model.experiment.*; import org.apache.airavata.model.job.JobModel; import org.apache.airavata.model.process.ProcessModel; @@ -64,7 +64,6 @@ import org.apache.airavata.registry.api.RegistryService; import org.apache.airavata.registry.api.exception.RegistryServiceException; import org.apache.airavata.registry.api.registry_apiConstants; -import org.apache.thrift.TException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -98,7 +97,7 @@ public String getAPIVersion() throws AiravataSystemException { * @return true/false */ @Override - public boolean isUserExists(String gatewayId, String userName) throws RegistryServiceException, TException { + public boolean isUserExists(String gatewayId, String userName) throws RegistryServiceException { return registryService.isUserExists(gatewayId, userName); } @@ -110,7 +109,7 @@ public boolean isUserExists(String gatewayId, String userName) throws RegistrySe * list of usernames of the users in the gateway */ @Override - public List getAllUsersInGateway(String gatewayId) throws RegistryServiceException, TException { + public List getAllUsersInGateway(String gatewayId) throws RegistryServiceException { return registryService.getAllUsersInGateway(gatewayId); } @@ -122,7 +121,7 @@ public List getAllUsersInGateway(String gatewayId) throws RegistryServic * Gateway obejct. */ @Override - public Gateway getGateway(String gatewayId) throws RegistryServiceException, TException { + public Gateway getGateway(String gatewayId) throws RegistryServiceException { return registryService.getGateway(gatewayId); } @@ -134,7 +133,7 @@ public Gateway getGateway(String gatewayId) throws RegistryServiceException, TEx * Boolean identifier for the success or failure of the deletion operation. */ @Override - public boolean deleteGateway(String gatewayId) throws RegistryServiceException, TException { + public boolean deleteGateway(String gatewayId) throws RegistryServiceException { return registryService.deleteGateway(gatewayId); } @@ -142,7 +141,7 @@ public boolean deleteGateway(String gatewayId) throws RegistryServiceException, * Get All the Gateways Connected to Airavata. */ @Override - public List getAllGateways() throws RegistryServiceException, TException { + public List getAllGateways() throws RegistryServiceException { return registryService.getAllGateways(); } @@ -154,24 +153,22 @@ public List getAllGateways() throws RegistryServiceException, TExceptio * return the gatewayId of the existing gateway. */ @Override - public boolean isGatewayExist(String gatewayId) throws RegistryServiceException, TException { + public boolean isGatewayExist(String gatewayId) throws RegistryServiceException { return registryService.isGatewayExist(gatewayId); } @Override - public boolean deleteNotification(String gatewayId, String notificationId) - throws RegistryServiceException, TException { + public boolean deleteNotification(String gatewayId, String notificationId) throws RegistryServiceException { return registryService.deleteNotification(gatewayId, notificationId); } @Override - public Notification getNotification(String gatewayId, String notificationId) - throws RegistryServiceException, TException { + public Notification getNotification(String gatewayId, String notificationId) throws RegistryServiceException { return registryService.getNotification(gatewayId, notificationId); } @Override - public List getAllNotifications(String gatewayId) throws RegistryServiceException, TException { + public List getAllNotifications(String gatewayId) throws RegistryServiceException { return registryService.getAllNotifications(gatewayId); } @@ -184,7 +181,7 @@ public List getAllNotifications(String gatewayId) throws RegistryS * project data model will be returned. */ @Override - public Project getProject(String projectId) throws RegistryServiceException, TException { + public Project getProject(String projectId) throws RegistryServiceException, ProjectNotFoundException { return registryService.getProject(projectId); } @@ -199,7 +196,7 @@ public Project getProject(String projectId) throws RegistryServiceException, TEx * NOTE: This method is not used within gateways connected with Airavata. */ @Override - public boolean deleteProject(String projectId) throws RegistryServiceException, TException { + public boolean deleteProject(String projectId) throws RegistryServiceException, ProjectNotFoundException { return registryService.deleteProject(projectId); } @@ -214,7 +211,7 @@ public boolean deleteProject(String projectId) throws RegistryServiceException, */ @Override public List getUserProjects(String gatewayId, String userName, int limit, int offset) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.getUserProjects(gatewayId, userName, limit, offset); } @@ -237,7 +234,7 @@ public ExperimentStatistics getExperimentStatistics( List accessibleExpIds, int limit, int offset) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.getExperimentStatistics( gatewayId, fromTime, @@ -261,7 +258,7 @@ public ExperimentStatistics getExperimentStatistics( */ @Override public List getExperimentsInProject(String gatewayId, String projectId, int limit, int offset) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.getExperimentsInProject(gatewayId, projectId, limit, offset); } @@ -276,7 +273,7 @@ public List getExperimentsInProject(String gatewayId, String pr */ @Override public List getUserExperiments(String gatewayId, String userName, int limit, int offset) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.getUserExperiments(gatewayId, userName, limit, offset); } @@ -288,7 +285,7 @@ public List getUserExperiments(String gatewayId, String userNam * Identifier for the success or failure of the deletion operation. */ @Override - public boolean deleteExperiment(String experimentId) throws RegistryServiceException, TException { + public boolean deleteExperiment(String experimentId) throws RegistryServiceException { return registryService.deleteExperiment(experimentId); } @@ -331,7 +328,8 @@ public boolean deleteExperiment(String experimentId) throws RegistryServiceExcep * @param airavataExperimentId */ @Override - public ExperimentModel getExperiment(String airavataExperimentId) throws RegistryServiceException, TException { + public ExperimentModel getExperiment(String airavataExperimentId) + throws RegistryServiceException, ExperimentNotFoundException { ExperimentModel experimentModel = getExperimentInternal(airavataExperimentId); return experimentModel; } @@ -362,8 +360,7 @@ public ExperimentModel getExperiment(String airavataExperimentId) throws Registr * rather an Airavata Administrator will be notified to take corrective action. */ @Override - public ExperimentModel getDetailedExperimentTree(String airavataExperimentId) - throws RegistryServiceException, TException { + public ExperimentModel getDetailedExperimentTree(String airavataExperimentId) throws RegistryServiceException { return registryService.getDetailedExperimentTree(airavataExperimentId); } @@ -377,8 +374,7 @@ public ExperimentModel getDetailedExperimentTree(String airavataExperimentId) * ExperimentStatus model with the current status will be returned. */ @Override - public ExperimentStatus getExperimentStatus(String airavataExperimentId) - throws RegistryServiceException, TException { + public ExperimentStatus getExperimentStatus(String airavataExperimentId) throws RegistryServiceException { return registryService.getExperimentStatus(airavataExperimentId); } @@ -392,7 +388,7 @@ public ExperimentStatus getExperimentStatus(String airavataExperimentId) */ @Override public List getExperimentOutputs(String airavataExperimentId) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.getExperimentOutputs(airavataExperimentId); } @@ -406,7 +402,7 @@ public List getExperimentOutputs(String airavataExperiment */ @Override public List getIntermediateOutputs(String airavataExperimentId) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.getIntermediateOutputs(airavataExperimentId); } @@ -418,112 +414,104 @@ public List getIntermediateOutputs(String airavataExperime * Job status (string) for all all the existing jobs for the experiment will be returned in the form of a map */ @Override - public Map getJobStatuses(String airavataExperimentId) - throws RegistryServiceException, TException { + public Map getJobStatuses(String airavataExperimentId) throws RegistryServiceException { return registryService.getJobStatuses(airavataExperimentId); } @Override public void addExperimentProcessOutputs(String outputType, List outputs, String id) - throws RegistryServiceException, TException { + throws RegistryServiceException { registryService.addExperimentProcessOutputs(outputType, outputs, id); } @Override - public void addErrors(String errorType, ErrorModel errorModel, String id) - throws RegistryServiceException, TException { + public void addErrors(String errorType, ErrorModel errorModel, String id) throws RegistryServiceException { registryService.addErrors(errorType, errorModel, id); } @Override - public void addTaskStatus(TaskStatus taskStatus, String taskId) throws RegistryServiceException, TException { + public void addTaskStatus(TaskStatus taskStatus, String taskId) throws RegistryServiceException { registryService.addTaskStatus(taskStatus, taskId); } @Override - public void addProcessStatus(ProcessStatus processStatus, String processId) - throws RegistryServiceException, TException { + public void addProcessStatus(ProcessStatus processStatus, String processId) throws RegistryServiceException { registryService.addProcessStatus(processStatus, processId); } @Override - public void updateProcessStatus(ProcessStatus processStatus, String processId) - throws RegistryServiceException, TException { + public void updateProcessStatus(ProcessStatus processStatus, String processId) throws RegistryServiceException { registryService.updateProcessStatus(processStatus, processId); } @Override public void updateExperimentStatus(ExperimentStatus experimentStatus, String experimentId) - throws RegistryServiceException, TException { + throws RegistryServiceException { registryService.updateExperimentStatus(experimentStatus, experimentId); } @Override - public void addJobStatus(JobStatus jobStatus, String taskId, String jobId) - throws RegistryServiceException, TException { + public void addJobStatus(JobStatus jobStatus, String taskId, String jobId) throws RegistryServiceException { registryService.addJobStatus(jobStatus, taskId, jobId); } @Override - public void addJob(JobModel jobModel, String processId) throws RegistryServiceException, TException { + public void addJob(JobModel jobModel, String processId) throws RegistryServiceException { registryService.addJob(jobModel, processId); } @Override - public void deleteJobs(String processId) throws RegistryServiceException, TException { + public void deleteJobs(String processId) throws RegistryServiceException { registryService.deleteJobs(processId); } @Override - public String addProcess(ProcessModel processModel, String experimentId) - throws RegistryServiceException, TException { + public String addProcess(ProcessModel processModel, String experimentId) throws RegistryServiceException { return registryService.addProcess(processModel, experimentId); } @Override - public void updateProcess(ProcessModel processModel, String processId) throws RegistryServiceException, TException { + public void updateProcess(ProcessModel processModel, String processId) throws RegistryServiceException { registryService.updateProcess(processModel, processId); } @Override - public String addTask(TaskModel taskModel, String processId) throws RegistryServiceException, TException { + public String addTask(TaskModel taskModel, String processId) throws RegistryServiceException { return registryService.addTask(taskModel, processId); } @Override - public void deleteTasks(String processId) throws RegistryServiceException, TException { + public void deleteTasks(String processId) throws RegistryServiceException { registryService.deleteTasks(processId); } @Override - public UserConfigurationDataModel getUserConfigurationData(String experimentId) - throws RegistryServiceException, TException { + public UserConfigurationDataModel getUserConfigurationData(String experimentId) throws RegistryServiceException { return registryService.getUserConfigurationData(experimentId); } @Override - public ProcessModel getProcess(String processId) throws RegistryServiceException, TException { + public ProcessModel getProcess(String processId) throws RegistryServiceException { return registryService.getProcess(processId); } @Override - public List getProcessList(String experimentId) throws RegistryServiceException, TException { + public List getProcessList(String experimentId) throws RegistryServiceException { return registryService.getProcessList(experimentId); } @Override - public ProcessStatus getProcessStatus(String processId) throws RegistryServiceException, TException { + public ProcessStatus getProcessStatus(String processId) throws RegistryServiceException { return registryService.getProcessStatus(processId); } @Override - public List getProcessListInState(ProcessState processState) - throws RegistryServiceException, TException { + public List getProcessListInState(ProcessState processState) throws RegistryServiceException { return registryService.getProcessListInState(processState); } @Override - public List getProcessStatusList(String processId) throws RegistryServiceException, TException { + public List getProcessStatusList(String processId) throws RegistryServiceException { return registryService.getProcessStatusList(processId); } @@ -531,7 +519,7 @@ public List getProcessStatusList(String processId) throws Registr * queryType can be PROCESS_ID or TASK_ID */ @Override - public boolean isJobExist(String queryType, String id) throws RegistryServiceException, TException { + public boolean isJobExist(String queryType, String id) throws RegistryServiceException { return registryService.isJobExist(queryType, id); } @@ -539,45 +527,45 @@ public boolean isJobExist(String queryType, String id) throws RegistryServiceExc * queryType can be PROCESS_ID or TASK_ID */ @Override - public JobModel getJob(String queryType, String id) throws RegistryServiceException, TException { + public JobModel getJob(String queryType, String id) throws RegistryServiceException { return registryService.getJob(queryType, id); } @Override - public List getJobs(String queryType, String id) throws RegistryServiceException, TException { + public List getJobs(String queryType, String id) throws RegistryServiceException { return registryService.getJobs(queryType, id); } @Override public int getJobCount( org.apache.airavata.model.status.JobStatus jobStatus, String gatewayId, double searchBackTimeInMinutes) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.getJobCount(jobStatus, gatewayId, searchBackTimeInMinutes); } @Override public Map getAVGTimeDistribution(String gatewayId, double searchBackTimeInMinutes) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.getAVGTimeDistribution(gatewayId, searchBackTimeInMinutes); } @Override - public List getProcessOutputs(String processId) throws RegistryServiceException, TException { + public List getProcessOutputs(String processId) throws RegistryServiceException { return registryService.getProcessOutputs(processId); } @Override - public List getProcessWorkflows(String processId) throws RegistryServiceException, TException { + public List getProcessWorkflows(String processId) throws RegistryServiceException { return registryService.getProcessWorkflows(processId); } @Override - public void addProcessWorkflow(ProcessWorkflow processWorkflow) throws RegistryServiceException, TException { + public void addProcessWorkflow(ProcessWorkflow processWorkflow) throws RegistryServiceException { registryService.addProcessWorkflow(processWorkflow); } @Override - public List getProcessIds(String experimentId) throws RegistryServiceException, TException { + public List getProcessIds(String experimentId) throws RegistryServiceException { return registryService.getProcessIds(experimentId); } @@ -589,7 +577,7 @@ public List getProcessIds(String experimentId) throws RegistryServiceExc * Job details. */ @Override - public List getJobDetails(String airavataExperimentId) throws RegistryServiceException, TException { + public List getJobDetails(String airavataExperimentId) throws RegistryServiceException { return registryService.getJobDetails(airavataExperimentId); } @@ -601,7 +589,7 @@ public List getJobDetails(String airavataExperimentId) throws Registry * Returns an Application Module Object. */ @Override - public ApplicationModule getApplicationModule(String appModuleId) throws RegistryServiceException, TException { + public ApplicationModule getApplicationModule(String appModuleId) throws RegistryServiceException { return registryService.getApplicationModule(appModuleId); } @@ -613,7 +601,7 @@ public ApplicationModule getApplicationModule(String appModuleId) throws Registr * Returns the list of all Application Module Objects. */ @Override - public List getAllAppModules(String gatewayId) throws RegistryServiceException, TException { + public List getAllAppModules(String gatewayId) throws RegistryServiceException { return registryService.getAllAppModules(gatewayId); } @@ -628,7 +616,7 @@ public List getAllAppModules(String gatewayId) throws Registr @Override public List getAccessibleAppModules( String gatewayId, List accessibleAppIds, List accessibleComputeResourceIds) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.getAccessibleAppModules(gatewayId, accessibleAppIds, accessibleComputeResourceIds); } @@ -640,7 +628,7 @@ public List getAccessibleAppModules( * Returns a success/failure of the deletion. */ @Override - public boolean deleteApplicationModule(String appModuleId) throws RegistryServiceException, TException { + public boolean deleteApplicationModule(String appModuleId) throws RegistryServiceException { return registryService.deleteApplicationModule(appModuleId); } @@ -653,7 +641,7 @@ public boolean deleteApplicationModule(String appModuleId) throws RegistryServic */ @Override public ApplicationDeploymentDescription getApplicationDeployment(String appDeploymentId) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.getApplicationDeployment(appDeploymentId); } @@ -665,7 +653,7 @@ public ApplicationDeploymentDescription getApplicationDeployment(String appDeplo * Returns a success/failure of the deletion. */ @Override - public boolean deleteApplicationDeployment(String appDeploymentId) throws RegistryServiceException, TException { + public boolean deleteApplicationDeployment(String appDeploymentId) throws RegistryServiceException { return registryService.deleteApplicationDeployment(appDeploymentId); } @@ -679,7 +667,7 @@ public boolean deleteApplicationDeployment(String appDeploymentId) throws Regist */ @Override public List getAllApplicationDeployments(String gatewayId) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.getAllApplicationDeployments(gatewayId); } @@ -694,9 +682,9 @@ public List getAllApplicationDeployments(Strin @Override public List getAccessibleApplicationDeployments( String gatewayId, List accessibleAppDeploymentIds, List accessibleComputeResourceIds) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.getAccessibleApplicationDeployments( - gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); + gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); } /** @@ -715,9 +703,9 @@ public List getAccessibleApplicationDeployment String appModuleId, List accessibleAppDeploymentIds, List accessibleComputeResourceIds) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.getAccessibleApplicationDeploymentsForAppModule( - gatewayId, appModuleId, accessibleAppDeploymentIds, accessibleComputeResourceIds); + gatewayId, appModuleId, accessibleAppDeploymentIds, accessibleComputeResourceIds); } /** @@ -728,13 +716,13 @@ public List getAccessibleApplicationDeployment * Returns a list of Deployed Resources. */ @Override - public List getAppModuleDeployedResources(String appModuleId) throws RegistryServiceException, TException { + public List getAppModuleDeployedResources(String appModuleId) throws RegistryServiceException { return registryService.getAppModuleDeployedResources(appModuleId); } @Override public List getApplicationDeployments(String appModuleId) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.getApplicationDeployments(appModuleId); } @@ -747,7 +735,7 @@ public List getApplicationDeployments(String a */ @Override public ApplicationInterfaceDescription getApplicationInterface(String appInterfaceId) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.getApplicationInterface(appInterfaceId); } @@ -759,7 +747,7 @@ public ApplicationInterfaceDescription getApplicationInterface(String appInterfa * Returns a success/failure of the deletion. */ @Override - public boolean deleteApplicationInterface(String appInterfaceId) throws RegistryServiceException, TException { + public boolean deleteApplicationInterface(String appInterfaceId) throws RegistryServiceException { return registryService.deleteApplicationInterface(appInterfaceId); } @@ -771,8 +759,7 @@ public boolean deleteApplicationInterface(String appInterfaceId) throws Registry * Returns a list of application interfaces with corresponsing ID's */ @Override - public Map getAllApplicationInterfaceNames(String gatewayId) - throws RegistryServiceException, TException { + public Map getAllApplicationInterfaceNames(String gatewayId) throws RegistryServiceException { return registryService.getAllApplicationInterfaceNames(gatewayId); } @@ -785,7 +772,7 @@ public Map getAllApplicationInterfaceNames(String gatewayId) */ @Override public List getAllApplicationInterfaces(String gatewayId) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.getAllApplicationInterfaces(gatewayId); } @@ -797,8 +784,7 @@ public List getAllApplicationInterfaces(String * Returns a list of application inputs. */ @Override - public List getApplicationInputs(String appInterfaceId) - throws RegistryServiceException, TException { + public List getApplicationInputs(String appInterfaceId) throws RegistryServiceException { return registryService.getApplicationInputs(appInterfaceId); } @@ -810,8 +796,7 @@ public List getApplicationInputs(String appInterfaceId) * Returns a list of application outputs. */ @Override - public List getApplicationOutputs(String appInterfaceId) - throws RegistryServiceException, TException { + public List getApplicationOutputs(String appInterfaceId) throws RegistryServiceException { return registryService.getApplicationOutputs(appInterfaceId); } @@ -825,7 +810,7 @@ public List getApplicationOutputs(String appInterfaceId) */ @Override public Map getAvailableAppInterfaceComputeResources(String appInterfaceId) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.getAvailableAppInterfaceComputeResources(appInterfaceId); } @@ -837,8 +822,7 @@ public Map getAvailableAppInterfaceComputeResources(String appIn * Compute Resource Object created from the datamodel.. */ @Override - public ComputeResourceDescription getComputeResource(String computeResourceId) - throws RegistryServiceException, TException { + public ComputeResourceDescription getComputeResource(String computeResourceId) throws RegistryServiceException { return registryService.getComputeResource(computeResourceId); } @@ -849,7 +833,7 @@ public ComputeResourceDescription getComputeResource(String computeResourceId) * Compute Resource Object created from the datamodel.. */ @Override - public Map getAllComputeResourceNames() throws RegistryServiceException, TException { + public Map getAllComputeResourceNames() throws RegistryServiceException { return registryService.getAllComputeResourceNames(); } @@ -861,7 +845,7 @@ public Map getAllComputeResourceNames() throws RegistryServiceEx * Returns a success/failure of the deletion. */ @Override - public boolean deleteComputeResource(String computeResourceId) throws RegistryServiceException, TException { + public boolean deleteComputeResource(String computeResourceId) throws RegistryServiceException { return registryService.deleteComputeResource(computeResourceId); } @@ -873,8 +857,7 @@ public boolean deleteComputeResource(String computeResourceId) throws RegistrySe * Storage Resource Object created from the datamodel.. */ @Override - public StorageResourceDescription getStorageResource(String storageResourceId) - throws RegistryServiceException, TException { + public StorageResourceDescription getStorageResource(String storageResourceId) throws RegistryServiceException { return registryService.getStorageResource(storageResourceId); } @@ -885,7 +868,7 @@ public StorageResourceDescription getStorageResource(String storageResourceId) * Compute Resource Object created from the datamodel.. */ @Override - public Map getAllStorageResourceNames() throws RegistryServiceException, TException { + public Map getAllStorageResourceNames() throws RegistryServiceException { return registryService.getAllStorageResourceNames(); } @@ -897,7 +880,7 @@ public Map getAllStorageResourceNames() throws RegistryServiceEx * Returns a success/failure of the deletion. */ @Override - public boolean deleteStorageResource(String storageResourceId) throws RegistryServiceException, TException { + public boolean deleteStorageResource(String storageResourceId) throws RegistryServiceException { return registryService.deleteStorageResource(storageResourceId); } @@ -907,7 +890,7 @@ public boolean deleteStorageResource(String storageResourceId) throws RegistrySe * @param jobSubmissionId@return LOCALSubmission instance */ @Override - public LOCALSubmission getLocalJobSubmission(String jobSubmissionId) throws RegistryServiceException, TException { + public LOCALSubmission getLocalJobSubmission(String jobSubmissionId) throws RegistryServiceException { return registryService.getLocalJobSubmission(jobSubmissionId); } @@ -917,7 +900,7 @@ public LOCALSubmission getLocalJobSubmission(String jobSubmissionId) throws Regi * @param jobSubmissionId@return SSHJobSubmission instance */ @Override - public SSHJobSubmission getSSHJobSubmission(String jobSubmissionId) throws RegistryServiceException, TException { + public SSHJobSubmission getSSHJobSubmission(String jobSubmissionId) throws RegistryServiceException { return registryService.getSSHJobSubmission(jobSubmissionId); } @@ -934,8 +917,7 @@ public SSHJobSubmission getSSHJobSubmission(String jobSubmissionId) throws Regis * @param jobSubmissionId */ @Override - public UnicoreJobSubmission getUnicoreJobSubmission(String jobSubmissionId) - throws RegistryServiceException, TException { + public UnicoreJobSubmission getUnicoreJobSubmission(String jobSubmissionId) throws RegistryServiceException { return registryService.getUnicoreJobSubmission(jobSubmissionId); } @@ -950,8 +932,7 @@ public UnicoreJobSubmission getUnicoreJobSubmission(String jobSubmissionId) * @param jobSubmissionId */ @Override - public CloudJobSubmission getCloudJobSubmission(String jobSubmissionId) - throws RegistryServiceException, TException { + public CloudJobSubmission getCloudJobSubmission(String jobSubmissionId) throws RegistryServiceException { return registryService.getCloudJobSubmission(jobSubmissionId); } @@ -962,7 +943,7 @@ public CloudJobSubmission getCloudJobSubmission(String jobSubmissionId) * @return LOCALDataMovement instance */ @Override - public LOCALDataMovement getLocalDataMovement(String dataMovementId) throws RegistryServiceException, TException { + public LOCALDataMovement getLocalDataMovement(String dataMovementId) throws RegistryServiceException { return registryService.getLocalDataMovement(dataMovementId); } @@ -973,7 +954,7 @@ public LOCALDataMovement getLocalDataMovement(String dataMovementId) throws Regi * @return SCPDataMovement instance */ @Override - public SCPDataMovement getSCPDataMovement(String dataMovementId) throws RegistryServiceException, TException { + public SCPDataMovement getSCPDataMovement(String dataMovementId) throws RegistryServiceException { return registryService.getSCPDataMovement(dataMovementId); } @@ -984,8 +965,7 @@ public SCPDataMovement getSCPDataMovement(String dataMovementId) throws Registry * @return UnicoreDataMovement instance */ @Override - public UnicoreDataMovement getUnicoreDataMovement(String dataMovementId) - throws RegistryServiceException, TException { + public UnicoreDataMovement getUnicoreDataMovement(String dataMovementId) throws RegistryServiceException { return registryService.getUnicoreDataMovement(dataMovementId); } @@ -996,8 +976,7 @@ public UnicoreDataMovement getUnicoreDataMovement(String dataMovementId) * @return GridFTPDataMovement instance */ @Override - public GridFTPDataMovement getGridFTPDataMovement(String dataMovementId) - throws RegistryServiceException, TException { + public GridFTPDataMovement getGridFTPDataMovement(String dataMovementId) throws RegistryServiceException { return registryService.getGridFTPDataMovement(dataMovementId); } @@ -1011,7 +990,7 @@ public GridFTPDataMovement getGridFTPDataMovement(String dataMovementId) */ @Override public boolean changeJobSubmissionPriority(String jobSubmissionInterfaceId, int newPriorityOrder) - throws RegistryServiceException, TException { + throws RegistryServiceException { return false; } @@ -1025,7 +1004,7 @@ public boolean changeJobSubmissionPriority(String jobSubmissionInterfaceId, int */ @Override public boolean changeDataMovementPriority(String dataMovementInterfaceId, int newPriorityOrder) - throws RegistryServiceException, TException { + throws RegistryServiceException { return false; } @@ -1038,7 +1017,7 @@ public boolean changeDataMovementPriority(String dataMovementInterfaceId, int ne */ @Override public boolean changeJobSubmissionPriorities(Map jobSubmissionPriorityMap) - throws RegistryServiceException, TException { + throws RegistryServiceException { return false; } @@ -1051,7 +1030,7 @@ public boolean changeJobSubmissionPriorities(Map jobSubmissionP */ @Override public boolean changeDataMovementPriorities(Map dataMovementPriorityMap) - throws RegistryServiceException, TException { + throws RegistryServiceException { return false; } @@ -1065,18 +1044,17 @@ public boolean changeDataMovementPriorities(Map dataMovementPri */ @Override public boolean deleteJobSubmissionInterface(String computeResourceId, String jobSubmissionInterfaceId) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.deleteJobSubmissionInterface(computeResourceId, jobSubmissionInterfaceId); } @Override - public ResourceJobManager getResourceJobManager(String resourceJobManagerId) - throws RegistryServiceException, TException { + public ResourceJobManager getResourceJobManager(String resourceJobManagerId) throws RegistryServiceException { return registryService.getResourceJobManager(resourceJobManagerId); } @Override - public boolean deleteResourceJobManager(String resourceJobManagerId) throws RegistryServiceException, TException { + public boolean deleteResourceJobManager(String resourceJobManagerId) throws RegistryServiceException { return registryService.deleteResourceJobManager(resourceJobManagerId); } @@ -1089,8 +1067,7 @@ public boolean deleteResourceJobManager(String resourceJobManagerId) throws Regi * Returns a success/failure of the deletion. */ @Override - public boolean deleteBatchQueue(String computeResourceId, String queueName) - throws RegistryServiceException, TException { + public boolean deleteBatchQueue(String computeResourceId, String queueName) throws RegistryServiceException { return registryService.deleteBatchQueue(computeResourceId, queueName); } @@ -1102,8 +1079,7 @@ public boolean deleteBatchQueue(String computeResourceId, String queueName) * Gateway Resource Profile Object. */ @Override - public GatewayResourceProfile getGatewayResourceProfile(String gatewayID) - throws RegistryServiceException, TException { + public GatewayResourceProfile getGatewayResourceProfile(String gatewayID) throws RegistryServiceException { return registryService.getGatewayResourceProfile(gatewayID); } @@ -1115,7 +1091,7 @@ public GatewayResourceProfile getGatewayResourceProfile(String gatewayID) * Returns a success/failure of the deletion. */ @Override - public boolean deleteGatewayResourceProfile(String gatewayID) throws RegistryServiceException, TException { + public boolean deleteGatewayResourceProfile(String gatewayID) throws RegistryServiceException { return registryService.deleteGatewayResourceProfile(gatewayID); } @@ -1129,7 +1105,7 @@ public boolean deleteGatewayResourceProfile(String gatewayID) throws RegistrySer */ @Override public ComputeResourcePreference getGatewayComputeResourcePreference(String gatewayID, String computeResourceId) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.getGatewayComputeResourcePreference(gatewayID, computeResourceId); } @@ -1143,7 +1119,7 @@ public ComputeResourcePreference getGatewayComputeResourcePreference(String gate */ @Override public StoragePreference getGatewayStoragePreference(String gatewayID, String storageId) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.getGatewayStoragePreference(gatewayID, storageId); } @@ -1156,7 +1132,7 @@ public StoragePreference getGatewayStoragePreference(String gatewayID, String st */ @Override public List getAllGatewayComputeResourcePreferences(String gatewayID) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.getAllGatewayComputeResourcePreferences(gatewayID); } @@ -1168,8 +1144,7 @@ public List getAllGatewayComputeResourcePreferences(S * Returns the StoragePreference object. */ @Override - public List getAllGatewayStoragePreferences(String gatewayID) - throws RegistryServiceException, TException { + public List getAllGatewayStoragePreferences(String gatewayID) throws RegistryServiceException { return registryService.getAllGatewayStoragePreferences(gatewayID); } @@ -1180,7 +1155,7 @@ public List getAllGatewayStoragePreferences(String gatewayID) * Returns all the GatewayResourcePrifle list object. */ @Override - public List getAllGatewayResourceProfiles() throws RegistryServiceException, TException { + public List getAllGatewayResourceProfiles() throws RegistryServiceException { return registryService.getAllGatewayResourceProfiles(); } @@ -1194,7 +1169,7 @@ public List getAllGatewayResourceProfiles() throws Regis */ @Override public boolean deleteGatewayComputeResourcePreference(String gatewayID, String computeResourceId) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.deleteGatewayComputeResourcePreference(gatewayID, computeResourceId); } @@ -1207,132 +1182,125 @@ public boolean deleteGatewayComputeResourcePreference(String gatewayID, String c * Returns a success/failure of the deletion. */ @Override - public boolean deleteGatewayStoragePreference(String gatewayID, String storageId) - throws RegistryServiceException, TException { + public boolean deleteGatewayStoragePreference(String gatewayID, String storageId) throws RegistryServiceException { return registryService.deleteGatewayStoragePreference(gatewayID, storageId); } @Override - public DataProductModel getDataProduct(String productUri) throws RegistryServiceException, TException { + public DataProductModel getDataProduct(String productUri) throws RegistryServiceException { return registryService.getDataProduct(productUri); } @Override - public DataProductModel getParentDataProduct(String productUri) throws RegistryServiceException, TException { + public DataProductModel getParentDataProduct(String productUri) throws RegistryServiceException { return registryService.getParentDataProduct(productUri); } @Override - public List getChildDataProducts(String productUri) throws RegistryServiceException, TException { + public List getChildDataProducts(String productUri) throws RegistryServiceException { return registryService.getChildDataProducts(productUri); } @Override public List searchDataProductsByName( String gatewayId, String userId, String productName, int limit, int offset) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.searchDataProductsByName(gatewayId, userId, productName, limit, offset); } @Override public String createGroupResourceProfile(GroupResourceProfile groupResourceProfile) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.createGroupResourceProfile(groupResourceProfile); } @Override - public void updateGroupResourceProfile(GroupResourceProfile groupResourceProfile) - throws RegistryServiceException, TException { + public void updateGroupResourceProfile(GroupResourceProfile groupResourceProfile) throws RegistryServiceException { registryService.updateGroupResourceProfile(groupResourceProfile); } @Override - public GroupResourceProfile getGroupResourceProfile(String groupResourceProfileId) - throws RegistryServiceException, TException { + public GroupResourceProfile getGroupResourceProfile(String groupResourceProfileId) throws RegistryServiceException { return registryService.getGroupResourceProfile(groupResourceProfileId); } @Override - public boolean isGroupResourceProfileExists(String groupResourceProfileId) - throws RegistryServiceException, TException { + public boolean isGroupResourceProfileExists(String groupResourceProfileId) throws RegistryServiceException { return registryService.isGroupResourceProfileExists(groupResourceProfileId); } @Override - public boolean removeGroupResourceProfile(String groupResourceProfileId) - throws RegistryServiceException, TException { + public boolean removeGroupResourceProfile(String groupResourceProfileId) throws RegistryServiceException { return registryService.removeGroupResourceProfile(groupResourceProfileId); } @Override public List getGroupResourceList(String gatewayId, List accessibleGroupResProfileIds) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.getGroupResourceList(gatewayId, accessibleGroupResProfileIds); } @Override public boolean removeGroupComputePrefs(String computeResourceId, String groupResourceProfileId) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.removeGroupComputePrefs(computeResourceId, groupResourceProfileId); } @Override - public boolean removeGroupComputeResourcePolicy(String resourcePolicyId) - throws RegistryServiceException, TException { + public boolean removeGroupComputeResourcePolicy(String resourcePolicyId) throws RegistryServiceException { return registryService.removeGroupComputeResourcePolicy(resourcePolicyId); } @Override - public boolean removeGroupBatchQueueResourcePolicy(String resourcePolicyId) - throws RegistryServiceException, TException { + public boolean removeGroupBatchQueueResourcePolicy(String resourcePolicyId) throws RegistryServiceException { return registryService.removeGroupBatchQueueResourcePolicy(resourcePolicyId); } @Override public GroupComputeResourcePreference getGroupComputeResourcePreference( - String computeResourceId, String groupResourceProfileId) throws RegistryServiceException, TException { + String computeResourceId, String groupResourceProfileId) throws RegistryServiceException { return registryService.getGroupComputeResourcePreference(computeResourceId, groupResourceProfileId); } @Override public boolean isGroupComputeResourcePreferenceExists(String computeResourceId, String groupResourceProfileId) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.isGroupComputeResourcePreferenceExists(computeResourceId, groupResourceProfileId); } @Override public ComputeResourcePolicy getGroupComputeResourcePolicy(String resourcePolicyId) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.getGroupComputeResourcePolicy(resourcePolicyId); } @Override public BatchQueueResourcePolicy getBatchQueueResourcePolicy(String resourcePolicyId) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.getBatchQueueResourcePolicy(resourcePolicyId); } @Override public List getGroupComputeResourcePrefList(String groupResourceProfileId) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.getGroupComputeResourcePrefList(groupResourceProfileId); } @Override public List getGroupBatchQueueResourcePolicyList(String groupResourceProfileId) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.getGroupBatchQueueResourcePolicyList(groupResourceProfileId); } @Override public List getGroupComputeResourcePolicyList(String groupResourceProfileId) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.getGroupComputeResourcePolicyList(groupResourceProfileId); } @Override public String registerReplicaLocation(DataReplicaLocationModel replicaLocationModel) - throws RegistryServiceException, TException { + throws RegistryServiceException { try { return registryService.registerReplicaLocation(replicaLocationModel); } catch (Throwable e) { @@ -1347,7 +1315,7 @@ public String registerReplicaLocation(DataReplicaLocationModel replicaLocationMo * @param dataProductModel */ @Override - public String registerDataProduct(DataProductModel dataProductModel) throws RegistryServiceException, TException { + public String registerDataProduct(DataProductModel dataProductModel) throws RegistryServiceException { try { return registryService.registerDataProduct(dataProductModel); } catch (Throwable e) { @@ -1367,8 +1335,7 @@ public String registerDataProduct(DataProductModel dataProductModel) throws Regi */ @Override public boolean updateGatewayStoragePreference( - String gatewayID, String storageId, StoragePreference storagePreference) - throws RegistryServiceException, TException { + String gatewayID, String storageId, StoragePreference storagePreference) throws RegistryServiceException { return registryService.updateGatewayStoragePreference(gatewayID, storageId, storagePreference); } @@ -1384,9 +1351,9 @@ public boolean updateGatewayStoragePreference( @Override public boolean updateGatewayComputeResourcePreference( String gatewayID, String computeResourceId, ComputeResourcePreference computeResourcePreference) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.updateGatewayComputeResourcePreference( - gatewayID, computeResourceId, computeResourcePreference); + gatewayID, computeResourceId, computeResourcePreference); } /** @@ -1402,7 +1369,7 @@ public boolean updateGatewayComputeResourcePreference( @Override public boolean addGatewayStoragePreference( String gatewayID, String storageResourceId, StoragePreference dataStoragePreference) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.addGatewayStoragePreference(gatewayID, storageResourceId, dataStoragePreference); } @@ -1419,9 +1386,9 @@ public boolean addGatewayStoragePreference( @Override public boolean addGatewayComputeResourcePreference( String gatewayID, String computeResourceId, ComputeResourcePreference computeResourcePreference) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.addGatewayComputeResourcePreference( - gatewayID, computeResourceId, computeResourcePreference); + gatewayID, computeResourceId, computeResourcePreference); } /** @@ -1434,7 +1401,7 @@ public boolean addGatewayComputeResourcePreference( */ @Override public boolean updateGatewayResourceProfile(String gatewayID, GatewayResourceProfile gatewayResourceProfile) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.updateGatewayResourceProfile(gatewayID, gatewayResourceProfile); } @@ -1449,19 +1416,18 @@ public boolean updateGatewayResourceProfile(String gatewayID, GatewayResourcePro */ @Override public String registerGatewayResourceProfile(GatewayResourceProfile gatewayResourceProfile) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.registerGatewayResourceProfile(gatewayResourceProfile); } @Override public boolean updateResourceJobManager(String resourceJobManagerId, ResourceJobManager updatedResourceJobManager) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.updateResourceJobManager(resourceJobManagerId, updatedResourceJobManager); } @Override - public String registerResourceJobManager(ResourceJobManager resourceJobManager) - throws RegistryServiceException, TException { + public String registerResourceJobManager(ResourceJobManager resourceJobManager) throws RegistryServiceException { return registryService.registerResourceJobManager(resourceJobManager); } @@ -1475,7 +1441,7 @@ public String registerResourceJobManager(ResourceJobManager resourceJobManager) */ @Override public boolean deleteDataMovementInterface(String resourceId, String dataMovementInterfaceId, DMType dmType) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.deleteDataMovementInterface(resourceId, dataMovementInterfaceId, dmType); } @@ -1490,8 +1456,7 @@ public boolean deleteDataMovementInterface(String resourceId, String dataMovemen */ @Override public boolean updateGridFTPDataMovementDetails( - String dataMovementInterfaceId, GridFTPDataMovement gridFTPDataMovement) - throws RegistryServiceException, TException { + String dataMovementInterfaceId, GridFTPDataMovement gridFTPDataMovement) throws RegistryServiceException { throw new RegistryServiceException("updateGridFTPDataMovementDetails is not yet implemented"); } @@ -1510,9 +1475,9 @@ public boolean updateGridFTPDataMovementDetails( @Override public String addGridFTPDataMovementDetails( String computeResourceId, DMType dmType, int priorityOrder, GridFTPDataMovement gridFTPDataMovement) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.addGridFTPDataMovementDetails( - computeResourceId, dmType, priorityOrder, gridFTPDataMovement); + computeResourceId, dmType, priorityOrder, gridFTPDataMovement); } /** @@ -1526,8 +1491,7 @@ public String addGridFTPDataMovementDetails( */ @Override public boolean updateUnicoreDataMovementDetails( - String dataMovementInterfaceId, UnicoreDataMovement unicoreDataMovement) - throws RegistryServiceException, TException { + String dataMovementInterfaceId, UnicoreDataMovement unicoreDataMovement) throws RegistryServiceException { throw new RegistryServiceException("updateUnicoreDataMovementDetails is not yet implemented"); } @@ -1546,9 +1510,8 @@ public boolean updateUnicoreDataMovementDetails( @Override public String addUnicoreDataMovementDetails( String resourceId, DMType dmType, int priorityOrder, UnicoreDataMovement unicoreDataMovement) - throws RegistryServiceException, TException { - return registryService.addUnicoreDataMovementDetails( - resourceId, dmType, priorityOrder, unicoreDataMovement); + throws RegistryServiceException { + return registryService.addUnicoreDataMovementDetails(resourceId, dmType, priorityOrder, unicoreDataMovement); } /** @@ -1562,7 +1525,7 @@ public String addUnicoreDataMovementDetails( */ @Override public boolean updateSCPDataMovementDetails(String dataMovementInterfaceId, SCPDataMovement scpDataMovement) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.updateSCPDataMovementDetails(dataMovementInterfaceId, scpDataMovement); } @@ -1581,7 +1544,7 @@ public boolean updateSCPDataMovementDetails(String dataMovementInterfaceId, SCPD @Override public String addSCPDataMovementDetails( String resourceId, DMType dmType, int priorityOrder, SCPDataMovement scpDataMovement) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.addSCPDataMovementDetails(resourceId, dmType, priorityOrder, scpDataMovement); } @@ -1595,7 +1558,7 @@ public String addSCPDataMovementDetails( */ @Override public boolean updateLocalDataMovementDetails(String dataMovementInterfaceId, LOCALDataMovement localDataMovement) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.updateLocalDataMovementDetails(dataMovementInterfaceId, localDataMovement); } @@ -1614,9 +1577,8 @@ public boolean updateLocalDataMovementDetails(String dataMovementInterfaceId, LO @Override public String addLocalDataMovementDetails( String resourceId, DMType dataMoveType, int priorityOrder, LOCALDataMovement localDataMovement) - throws RegistryServiceException, TException { - return registryService.addLocalDataMovementDetails( - resourceId, dataMoveType, priorityOrder, localDataMovement); + throws RegistryServiceException { + return registryService.addLocalDataMovementDetails(resourceId, dataMoveType, priorityOrder, localDataMovement); } /** @@ -1630,7 +1592,7 @@ public String addLocalDataMovementDetails( @Override public boolean updateUnicoreJobSubmissionDetails( String jobSubmissionInterfaceId, UnicoreJobSubmission unicoreJobSubmission) - throws RegistryServiceException, TException { + throws RegistryServiceException { throw new RegistryServiceException("updateUnicoreJobSubmissionDetails is not yet implemented"); } @@ -1644,7 +1606,7 @@ public boolean updateUnicoreJobSubmissionDetails( */ @Override public boolean updateCloudJobSubmissionDetails(String jobSubmissionInterfaceId, CloudJobSubmission sshJobSubmission) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.updateCloudJobSubmissionDetails(jobSubmissionInterfaceId, sshJobSubmission); } @@ -1658,7 +1620,7 @@ public boolean updateCloudJobSubmissionDetails(String jobSubmissionInterfaceId, */ @Override public boolean updateSSHJobSubmissionDetails(String jobSubmissionInterfaceId, SSHJobSubmission sshJobSubmission) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.updateSSHJobSubmissionDetails(jobSubmissionInterfaceId, sshJobSubmission); } @@ -1688,7 +1650,7 @@ public boolean updateSSHJobSubmissionDetails(String jobSubmissionInterfaceId, SS @Override public String addCloudJobSubmissionDetails( String computeResourceId, int priorityOrder, CloudJobSubmission cloudSubmission) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.addCloudJobSubmissionDetails(computeResourceId, priorityOrder, cloudSubmission); } @@ -1705,9 +1667,8 @@ public String addCloudJobSubmissionDetails( @Override public String addUNICOREJobSubmissionDetails( String computeResourceId, int priorityOrder, UnicoreJobSubmission unicoreJobSubmission) - throws RegistryServiceException, TException { - return registryService.addUNICOREJobSubmissionDetails( - computeResourceId, priorityOrder, unicoreJobSubmission); + throws RegistryServiceException { + return registryService.addUNICOREJobSubmissionDetails(computeResourceId, priorityOrder, unicoreJobSubmission); } /** @@ -1723,7 +1684,7 @@ public String addUNICOREJobSubmissionDetails( @Override public String addSSHForkJobSubmissionDetails( String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.addSSHForkJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); } @@ -1740,7 +1701,7 @@ public String addSSHForkJobSubmissionDetails( @Override public String addSSHJobSubmissionDetails( String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.addSSHJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); } @@ -1754,7 +1715,7 @@ public String addSSHJobSubmissionDetails( */ @Override public boolean updateLocalSubmissionDetails(String jobSubmissionInterfaceId, LOCALSubmission localSubmission) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.updateLocalSubmissionDetails(jobSubmissionInterfaceId, localSubmission); } @@ -1771,7 +1732,7 @@ public boolean updateLocalSubmissionDetails(String jobSubmissionInterfaceId, LOC @Override public String addLocalSubmissionDetails( String computeResourceId, int priorityOrder, LOCALSubmission localSubmission) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.addLocalSubmissionDetails(computeResourceId, priorityOrder, localSubmission); } @@ -1786,7 +1747,7 @@ public String addLocalSubmissionDetails( @Override public boolean updateStorageResource( String storageResourceId, StorageResourceDescription storageResourceDescription) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.updateStorageResource(storageResourceId, storageResourceDescription); } @@ -1799,7 +1760,7 @@ public boolean updateStorageResource( */ @Override public String registerStorageResource(StorageResourceDescription storageResourceDescription) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.registerStorageResource(storageResourceDescription); } @@ -1814,7 +1775,7 @@ public String registerStorageResource(StorageResourceDescription storageResource @Override public boolean updateComputeResource( String computeResourceId, ComputeResourceDescription computeResourceDescription) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.updateComputeResource(computeResourceId, computeResourceDescription); } @@ -1827,7 +1788,7 @@ public boolean updateComputeResource( */ @Override public String registerComputeResource(ComputeResourceDescription computeResourceDescription) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.registerComputeResource(computeResourceDescription); } @@ -1842,7 +1803,7 @@ public String registerComputeResource(ComputeResourceDescription computeResource @Override public boolean updateApplicationInterface( String appInterfaceId, ApplicationInterfaceDescription applicationInterface) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.updateApplicationInterface(appInterfaceId, applicationInterface); } @@ -1856,7 +1817,7 @@ public boolean updateApplicationInterface( */ @Override public String registerApplicationInterface(String gatewayId, ApplicationInterfaceDescription applicationInterface) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.registerApplicationInterface(gatewayId, applicationInterface); } @@ -1871,7 +1832,7 @@ public String registerApplicationInterface(String gatewayId, ApplicationInterfac @Override public boolean updateApplicationDeployment( String appDeploymentId, ApplicationDeploymentDescription applicationDeployment) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.updateApplicationDeployment(appDeploymentId, applicationDeployment); } @@ -1885,8 +1846,7 @@ public boolean updateApplicationDeployment( */ @Override public String registerApplicationDeployment( - String gatewayId, ApplicationDeploymentDescription applicationDeployment) - throws RegistryServiceException, TException { + String gatewayId, ApplicationDeploymentDescription applicationDeployment) throws RegistryServiceException { return registryService.registerApplicationDeployment(gatewayId, applicationDeployment); } @@ -1900,7 +1860,7 @@ public String registerApplicationDeployment( */ @Override public boolean updateApplicationModule(String appModuleId, ApplicationModule applicationModule) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.updateApplicationModule(appModuleId, applicationModule); } @@ -1915,20 +1875,20 @@ public boolean updateApplicationModule(String appModuleId, ApplicationModule app */ @Override public String registerApplicationModule(String gatewayId, ApplicationModule applicationModule) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.registerApplicationModule(gatewayId, applicationModule); } @Override public void updateResourceScheduleing( String airavataExperimentId, ComputationalResourceSchedulingModel resourceScheduling) - throws RegistryServiceException, TException { + throws RegistryServiceException { registryService.updateResourceScheduleing(airavataExperimentId, resourceScheduling); } @Override public void updateExperimentConfiguration(String airavataExperimentId, UserConfigurationDataModel userConfiguration) - throws RegistryServiceException, TException { + throws RegistryServiceException { registryService.updateExperimentConfiguration(airavataExperimentId, userConfiguration); } @@ -1958,7 +1918,7 @@ public void updateExperimentConfiguration(String airavataExperimentId, UserConfi */ @Override public void updateExperiment(String airavataExperimentId, ExperimentModel experiment) - throws RegistryServiceException, TException { + throws RegistryServiceException { registryService.updateExperiment(airavataExperimentId, experiment); } @@ -2007,8 +1967,7 @@ public void updateExperiment(String airavataExperimentId, ExperimentModel experi * @param experiment */ @Override - public String createExperiment(String gatewayId, ExperimentModel experiment) - throws RegistryServiceException, TException { + public String createExperiment(String gatewayId, ExperimentModel experiment) throws RegistryServiceException { return registryService.createExperiment(gatewayId, experiment); } @@ -2032,7 +1991,7 @@ public List searchExperiments( Map filters, int limit, int offset) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.searchExperiments(gatewayId, userName, accessibleExpIds, filters, limit, offset); } @@ -2055,7 +2014,7 @@ public List searchProjects( Map filters, int limit, int offset) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.searchProjects(gatewayId, userName, accessibleProjIds, filters, limit, offset); } @@ -2068,7 +2027,7 @@ public List searchProjects( * Currently this does not return any value. */ @Override - public void updateProject(String projectId, Project updatedProject) throws RegistryServiceException, TException { + public void updateProject(String projectId, Project updatedProject) throws RegistryServiceException { registryService.updateProject(projectId, updatedProject); } @@ -2080,12 +2039,12 @@ public void updateProject(String projectId, Project updatedProject) throws Regis * @param project */ @Override - public String createProject(String gatewayId, Project project) throws RegistryServiceException, TException { + public String createProject(String gatewayId, Project project) throws RegistryServiceException { return registryService.createProject(gatewayId, project); } @Override - public boolean updateNotification(Notification notification) throws RegistryServiceException, TException { + public boolean updateNotification(Notification notification) throws RegistryServiceException { return registryService.updateNotification(notification); } @@ -2096,7 +2055,7 @@ public boolean updateNotification(Notification notification) throws RegistryServ * @param notification */ @Override - public String createNotification(Notification notification) throws RegistryServiceException, TException { + public String createNotification(Notification notification) throws RegistryServiceException { return registryService.createNotification(notification); } @@ -2110,7 +2069,7 @@ public String createNotification(Notification notification) throws RegistryServi * @throws AiravataClientException */ @Override - public boolean updateGateway(String gatewayId, Gateway updatedGateway) throws RegistryServiceException, TException { + public boolean updateGateway(String gatewayId, Gateway updatedGateway) throws RegistryServiceException { return registryService.updateGateway(gatewayId, updatedGateway); } @@ -2122,18 +2081,25 @@ public boolean updateGateway(String gatewayId, Gateway updatedGateway) throws Re * Th unique identifier of the newly registered gateway. */ @Override - public String addGateway(Gateway gateway) throws RegistryServiceException, DuplicateEntryException, TException { + public String addGateway(Gateway gateway) throws RegistryServiceException, DuplicateEntryException { return registryService.addGateway(gateway); } - - /*This private method wraps the logic of getExperiment method as this method is called internally in the API.*/ private ExperimentModel getExperimentInternal(String airavataExperimentId) - throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, - AiravataSystemException, TException { + throws RegistryServiceException, ExperimentNotFoundException { try { return registryService.getExperiment(airavataExperimentId); + } catch (RegistryServiceException e) { + // Check if this is a "not found" error based on the message + if (e.getMessage() != null && e.getMessage().contains("does not exist")) { + logger.error("Experiment not found: " + airavataExperimentId, e); + ExperimentNotFoundException exception = new ExperimentNotFoundException(); + exception.setMessage( + "Requested experiment id " + airavataExperimentId + " does not exist in the system."); + throw exception; + } + throw e; } catch (Throwable e) { logger.error("Error while retrieving the experiment", e); RegistryServiceException exception = new RegistryServiceException(); @@ -2152,14 +2118,12 @@ private ExperimentModel getExperimentInternal(String airavataExperimentId) * Returns a success/failure of the update. */ @Override - public String registerUserResourceProfile(UserResourceProfile userResourceProfile) - throws RegistryServiceException, TException { + public String registerUserResourceProfile(UserResourceProfile userResourceProfile) throws RegistryServiceException { return registryService.registerUserResourceProfile(userResourceProfile); } @Override - public boolean isUserResourceProfileExists(String userId, String gatewayId) - throws RegistryServiceException, TException { + public boolean isUserResourceProfileExists(String userId, String gatewayId) throws RegistryServiceException { return registryService.isUserResourceProfileExists(userId, gatewayId); } @@ -2170,8 +2134,7 @@ public boolean isUserResourceProfileExists(String userId, String gatewayId) * @return UserResourceProfile object */ @Override - public UserResourceProfile getUserResourceProfile(String userId, String gatewayId) - throws RegistryServiceException, TException { + public UserResourceProfile getUserResourceProfile(String userId, String gatewayId) throws RegistryServiceException { return registryService.getUserResourceProfile(userId, gatewayId); } @@ -2185,7 +2148,7 @@ public UserResourceProfile getUserResourceProfile(String userId, String gatewayI */ @Override public boolean updateUserResourceProfile(String userId, String gatewayID, UserResourceProfile userResourceProfile) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.updateUserResourceProfile(userId, gatewayID, userResourceProfile); } @@ -2198,14 +2161,12 @@ public boolean updateUserResourceProfile(String userId, String gatewayID, UserRe * Returns a success/failure of the deletion. */ @Override - public boolean deleteUserResourceProfile(String userId, String gatewayID) - throws RegistryServiceException, TException { + public boolean deleteUserResourceProfile(String userId, String gatewayID) throws RegistryServiceException { return registryService.deleteUserResourceProfile(userId, gatewayID); } @Override - public String addUser(UserProfile userProfile) - throws RegistryServiceException, DuplicateEntryException, TException { + public String addUser(UserProfile userProfile) throws RegistryServiceException, DuplicateEntryException { return registryService.addUser(userProfile); } @@ -2226,9 +2187,9 @@ public boolean addUserComputeResourcePreference( String gatewayID, String computeResourceId, UserComputeResourcePreference userComputeResourcePreference) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.addUserComputeResourcePreference( - userId, gatewayID, computeResourceId, userComputeResourcePreference); + userId, gatewayID, computeResourceId, userComputeResourcePreference); } /** @@ -2242,7 +2203,7 @@ public boolean addUserComputeResourcePreference( */ @Override public boolean isUserComputeResourcePreferenceExists(String userId, String gatewayID, String computeResourceId) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.isUserComputeResourcePreferenceExists(userId, gatewayID, computeResourceId); } @@ -2259,9 +2220,8 @@ public boolean isUserComputeResourcePreferenceExists(String userId, String gatew @Override public boolean addUserStoragePreference( String userId, String gatewayID, String storageResourceId, UserStoragePreference dataStoragePreference) - throws RegistryServiceException, TException { - return registryService.addUserStoragePreference( - userId, gatewayID, storageResourceId, dataStoragePreference); + throws RegistryServiceException { + return registryService.addUserStoragePreference(userId, gatewayID, storageResourceId, dataStoragePreference); } /** @@ -2275,7 +2235,7 @@ public boolean addUserStoragePreference( */ @Override public UserComputeResourcePreference getUserComputeResourcePreference( - String userId, String gatewayID, String userComputeResourceId) throws RegistryServiceException, TException { + String userId, String gatewayID, String userComputeResourceId) throws RegistryServiceException { return registryService.getUserComputeResourcePreference(userId, gatewayID, userComputeResourceId); } @@ -2290,7 +2250,7 @@ public UserComputeResourcePreference getUserComputeResourcePreference( */ @Override public UserStoragePreference getUserStoragePreference(String userId, String gatewayID, String storageId) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.getUserStoragePreference(userId, gatewayID, storageId); } @@ -2301,7 +2261,7 @@ public UserStoragePreference getUserStoragePreference(String userId, String gate * Returns all the UserResourceProfile list object. */ @Override - public List getAllUserResourceProfiles() throws RegistryServiceException, TException { + public List getAllUserResourceProfiles() throws RegistryServiceException { return registryService.getAllUserResourceProfiles(); } @@ -2321,9 +2281,9 @@ public boolean updateUserComputeResourcePreference( String gatewayID, String computeResourceId, UserComputeResourcePreference userComputeResourcePreference) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.updateUserComputeResourcePreference( - userId, gatewayID, computeResourceId, userComputeResourcePreference); + userId, gatewayID, computeResourceId, userComputeResourcePreference); } /** @@ -2339,7 +2299,7 @@ public boolean updateUserComputeResourcePreference( @Override public boolean updateUserStoragePreference( String userId, String gatewayID, String storageId, UserStoragePreference userStoragePreference) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.updateUserStoragePreference(userId, gatewayID, storageId, userStoragePreference); } @@ -2354,7 +2314,7 @@ public boolean updateUserStoragePreference( */ @Override public boolean deleteUserComputeResourcePreference(String userId, String gatewayID, String computeResourceId) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.deleteUserComputeResourcePreference(userId, gatewayID, computeResourceId); } @@ -2369,7 +2329,7 @@ public boolean deleteUserComputeResourcePreference(String userId, String gateway */ @Override public boolean deleteUserStoragePreference(String userId, String gatewayID, String storageId) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.deleteUserStoragePreference(userId, gatewayID, storageId); } @@ -2378,19 +2338,17 @@ public boolean deleteUserStoragePreference(String userId, String gatewayID, Stri * * */ @Override - public List getLatestQueueStatuses() throws RegistryServiceException, TException { + public List getLatestQueueStatuses() throws RegistryServiceException { return registryService.getLatestQueueStatuses(); } @Override - public void registerQueueStatuses(List queueStatuses) - throws RegistryServiceException, TException { + public void registerQueueStatuses(List queueStatuses) throws RegistryServiceException { registryService.registerQueueStatuses(queueStatuses); } @Override - public QueueStatusModel getQueueStatus(String hostName, String queueName) - throws RegistryServiceException, TException { + public QueueStatusModel getQueueStatus(String hostName, String queueName) throws RegistryServiceException { return registryService.getQueueStatus(hostName, queueName); } @@ -2404,7 +2362,7 @@ public QueueStatusModel getQueueStatus(String hostName, String queueName) */ @Override public List getAllUserComputeResourcePreferences(String userId, String gatewayID) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.getAllUserComputeResourcePreferences(userId, gatewayID); } @@ -2418,13 +2376,13 @@ public List getAllUserComputeResourcePreferences( */ @Override public List getAllUserStoragePreferences(String userId, String gatewayID) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.getAllUserStoragePreferences(userId, gatewayID); } @Override public void createGatewayGroups(GatewayGroups gatewayGroups) - throws RegistryServiceException, DuplicateEntryException, TException { + throws RegistryServiceException, DuplicateEntryException { try { registryService.createGatewayGroups(gatewayGroups); } catch (Throwable e) { @@ -2436,100 +2394,96 @@ public void createGatewayGroups(GatewayGroups gatewayGroups) } @Override - public void updateGatewayGroups(GatewayGroups gatewayGroups) throws RegistryServiceException, TException { + public void updateGatewayGroups(GatewayGroups gatewayGroups) throws RegistryServiceException { registryService.updateGatewayGroups(gatewayGroups); } @Override - public boolean isGatewayGroupsExists(String gatewayId) throws RegistryServiceException, TException { + public boolean isGatewayGroupsExists(String gatewayId) throws RegistryServiceException { return registryService.isGatewayGroupsExists(gatewayId); } @Override - public GatewayGroups getGatewayGroups(String gatewayId) throws RegistryServiceException, TException { + public GatewayGroups getGatewayGroups(String gatewayId) throws RegistryServiceException { return registryService.getGatewayGroups(gatewayId); } @Override - public Parser getParser(String parserId, String gatewayId) throws RegistryServiceException, TException { + public Parser getParser(String parserId, String gatewayId) throws RegistryServiceException { return registryService.getParser(parserId, gatewayId); } @Override - public String saveParser(Parser parser) throws RegistryServiceException, TException { + public String saveParser(Parser parser) throws RegistryServiceException { return registryService.saveParser(parser); } @Override - public List listAllParsers(String gatewayId) throws RegistryServiceException, TException { + public List listAllParsers(String gatewayId) throws RegistryServiceException { return registryService.listAllParsers(gatewayId); } @Override - public void removeParser(String parserId, String gatewayId) throws RegistryServiceException, TException { + public void removeParser(String parserId, String gatewayId) throws RegistryServiceException { registryService.removeParser(parserId, gatewayId); } @Override - public ParserInput getParserInput(String parserInputId, String gatewayId) - throws RegistryServiceException, TException { + public ParserInput getParserInput(String parserInputId, String gatewayId) throws RegistryServiceException { return registryService.getParserInput(parserInputId, gatewayId); } @Override - public ParserOutput getParserOutput(String parserOutputId, String gatewayId) - throws RegistryServiceException, TException { + public ParserOutput getParserOutput(String parserOutputId, String gatewayId) throws RegistryServiceException { return registryService.getParserOutput(parserOutputId, gatewayId); } @Override - public ParsingTemplate getParsingTemplate(String templateId, String gatewayId) - throws RegistryServiceException, TException { + public ParsingTemplate getParsingTemplate(String templateId, String gatewayId) throws RegistryServiceException { return registryService.getParsingTemplate(templateId, gatewayId); } @Override public List getParsingTemplatesForExperiment(String experimentId, String gatewayId) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.getParsingTemplatesForExperiment(experimentId, gatewayId); } @Override - public String saveParsingTemplate(ParsingTemplate parsingTemplate) throws RegistryServiceException, TException { + public String saveParsingTemplate(ParsingTemplate parsingTemplate) throws RegistryServiceException { return registryService.saveParsingTemplate(parsingTemplate); } @Override - public List listAllParsingTemplates(String gatewayId) throws RegistryServiceException, TException { + public List listAllParsingTemplates(String gatewayId) throws RegistryServiceException { return registryService.listAllParsingTemplates(gatewayId); } @Override - public void removeParsingTemplate(String templateId, String gatewayId) throws RegistryServiceException, TException { + public void removeParsingTemplate(String templateId, String gatewayId) throws RegistryServiceException { registryService.removeParsingTemplate(templateId, gatewayId); } @Override public boolean isGatewayUsageReportingAvailable(String gatewayId, String computeResourceId) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.isGatewayUsageReportingAvailable(gatewayId, computeResourceId); } @Override public GatewayUsageReportingCommand getGatewayReportingCommand(String gatewayId, String computeResourceId) - throws RegistryServiceException, TException { + throws RegistryServiceException { return registryService.getGatewayReportingCommand(gatewayId, computeResourceId); } @Override - public void addGatewayUsageReportingCommand(GatewayUsageReportingCommand command) - throws RegistryServiceException, TException { + public void addGatewayUsageReportingCommand(GatewayUsageReportingCommand command) throws RegistryServiceException { registryService.addGatewayUsageReportingCommand(command); } @Override public void removeGatewayUsageReportingCommand(String gatewayId, String computeResourceId) - throws RegistryServiceException, TException { + throws RegistryServiceException { registryService.removeGatewayUsageReportingCommand(gatewayId, computeResourceId); } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java b/airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java index 1608175fba..2eae99b773 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java @@ -33,11 +33,15 @@ import java.util.UUID; import java.util.function.BiFunction; import java.util.stream.Collectors; +import org.apache.airavata.accountprovisioning.InvalidSetupException; +import org.apache.airavata.accountprovisioning.SSHAccountManager; import org.apache.airavata.agents.api.AgentAdaptor; +import org.apache.airavata.agents.api.AgentException; +import org.apache.airavata.common.exception.ApplicationSettingsException; import org.apache.airavata.common.utils.AiravataUtils; import org.apache.airavata.common.utils.Constants; import org.apache.airavata.common.utils.ServerSettings; -import org.apache.airavata.credential.store.store.CredentialStoreException; +import org.apache.airavata.credential.store.exception.CredentialStoreException; import org.apache.airavata.helix.core.support.adaptor.AdaptorSupportImpl; import org.apache.airavata.messaging.core.MessageContext; import org.apache.airavata.messaging.core.Publisher; @@ -68,6 +72,7 @@ import org.apache.airavata.model.appcatalog.userresourceprofile.UserStoragePreference; import org.apache.airavata.model.application.io.InputDataObjectType; import org.apache.airavata.model.application.io.OutputDataObjectType; +import org.apache.airavata.model.commons.airavata_commonsConstants; import org.apache.airavata.model.credential.store.CredentialSummary; import org.apache.airavata.model.credential.store.PasswordCredential; import org.apache.airavata.model.credential.store.SSHCredential; @@ -79,6 +84,12 @@ import org.apache.airavata.model.data.movement.UnicoreDataMovement; import org.apache.airavata.model.data.replica.DataProductModel; import org.apache.airavata.model.data.replica.DataReplicaLocationModel; +import org.apache.airavata.model.error.AiravataErrorType; +import org.apache.airavata.model.error.AiravataSystemException; +import org.apache.airavata.model.error.AuthorizationException; +import org.apache.airavata.model.error.ExperimentNotFoundException; +import org.apache.airavata.model.error.InvalidRequestException; +import org.apache.airavata.model.error.ProjectNotFoundException; import org.apache.airavata.model.experiment.ExperimentModel; import org.apache.airavata.model.experiment.ExperimentSearchFields; import org.apache.airavata.model.experiment.ExperimentStatistics; @@ -106,28 +117,21 @@ import org.apache.airavata.model.workspace.Gateway; import org.apache.airavata.model.workspace.Notification; import org.apache.airavata.model.workspace.Project; -import org.apache.airavata.model.error.AiravataClientException; -import org.apache.airavata.model.error.AiravataSystemException; -import org.apache.airavata.model.error.AuthorizationException; -import org.apache.airavata.model.error.InvalidRequestException; -import org.apache.airavata.model.error.ProjectNotFoundException; -import org.apache.airavata.model.error.ExperimentNotFoundException; -import org.apache.airavata.model.error.AiravataErrorType; -import org.apache.airavata.model.commons.airavata_commonsConstants; import org.apache.airavata.registry.api.exception.RegistryServiceException; import org.apache.airavata.registry.cpi.AppCatalogException; import org.apache.airavata.registry.cpi.RegistryException; import org.apache.airavata.service.security.GatewayGroupsInitializer; import org.apache.airavata.sharing.registry.models.Domain; +import org.apache.airavata.sharing.registry.models.DuplicateEntryException; import org.apache.airavata.sharing.registry.models.Entity; import org.apache.airavata.sharing.registry.models.EntitySearchField; import org.apache.airavata.sharing.registry.models.EntityType; import org.apache.airavata.sharing.registry.models.PermissionType; import org.apache.airavata.sharing.registry.models.SearchCondition; import org.apache.airavata.sharing.registry.models.SearchCriteria; +import org.apache.airavata.sharing.registry.models.SharingRegistryException; import org.apache.airavata.sharing.registry.models.User; import org.apache.airavata.sharing.registry.models.UserGroup; -import org.apache.thrift.TException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -136,6 +140,9 @@ public class AiravataService { private record StorageInfoContext(String loginUserName, String credentialToken, AgentAdaptor adaptor) {} + // Record aliases for sharing registry models to avoid name clashes + private record SharingEntity(org.apache.airavata.sharing.registry.models.Entity delegate) {} + private boolean validateString(String name) { boolean valid = true; if (name == null || name.equals("") || name.trim().length() == 0) { @@ -144,10 +151,10 @@ private boolean validateString(String name) { return valid; } - private AiravataClientException clientException(AiravataErrorType errorType, String parameter) { - var exception = new AiravataClientException(); + private AiravataSystemException airavataSystemException(AiravataErrorType errorType, String message) { + var exception = new AiravataSystemException(); exception.setAiravataErrorType(errorType); - exception.setParameter(parameter); + exception.setMessage(message); return exception; } @@ -170,43 +177,9 @@ private boolean isGatewayResourceProfileExists(String gatewayId) { } } - @SuppressWarnings("unchecked") - private static RuntimeException sneakyThrow(Throwable e) throws E { - throw (E) e; - } - - private RuntimeException convertException(Throwable e, String msg) { - if (e instanceof InvalidRequestException || - e instanceof AiravataClientException || - e instanceof AiravataSystemException || - e instanceof AuthorizationException || - e instanceof ExperimentNotFoundException || - e instanceof ProjectNotFoundException) { - throw sneakyThrow(e); - } - if (e instanceof RegistryException || e instanceof AppCatalogException || - e instanceof CredentialStoreException || - e instanceof org.apache.airavata.sharing.registry.models.SharingRegistryException) { - logger.error(msg, e); - var exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + ". More info : " + e.getMessage()); - exception.initCause(e); - throw sneakyThrow(exception); - } - logger.error(msg, e); - var exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + ". More info : " + e.getMessage()); - exception.initCause(e); - throw sneakyThrow(exception); - } - - private RegistryService registryService = - new RegistryService(); + private RegistryService registryService = new RegistryService(); - private SharingRegistryService sharingRegistryService = - new SharingRegistryService(); + private SharingRegistryService sharingRegistryService = new SharingRegistryService(); private CredentialStoreService credentialStoreService; @@ -229,7 +202,6 @@ public void init() { } } - private void postInitDefaultGateway() { try { var gatewayResourceProfile = getGatewayResourceProfile(ServerSettings.getDefaultUserGateway()); @@ -260,8 +232,7 @@ private void postInitDefaultGateway() { + ServerSettings.getDefaultUserGateway()); gatewayResourceProfile.setIdentityServerPwdCredToken(token); gatewayResourceProfile.setIdentityServerTenant(ServerSettings.getDefaultUserGateway()); - updateGatewayResourceProfile( - ServerSettings.getDefaultUserGateway(), gatewayResourceProfile); + updateGatewayResourceProfile(ServerSettings.getDefaultUserGateway(), gatewayResourceProfile); } } } catch (Throwable e) { @@ -269,7 +240,8 @@ private void postInitDefaultGateway() { } } - private void initSharingRegistry() throws Exception { + private void initSharingRegistry() + throws ApplicationSettingsException, SharingRegistryException, DuplicateEntryException { try { if (!isDomainExists(ServerSettings.getDefaultUserGateway())) { var domain = new Domain(); @@ -354,184 +326,294 @@ private void initSharingRegistry() throws Exception { } } - public List getAllUsersInGateway(String gatewayId) { + public List getAllUsersInGateway(String gatewayId) throws AiravataSystemException { try { return registryService.getAllUsersInGateway(gatewayId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving users"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving users", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving users. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public boolean updateGateway(String gatewayId, Gateway updatedGateway) { + public boolean updateGateway(String gatewayId, Gateway updatedGateway) throws AiravataSystemException { try { return registryService.updateGateway(gatewayId, updatedGateway); - } catch (Throwable e) { - throw convertException(e, "Error while updating gateway"); + } catch (RegistryServiceException e) { + logger.error("Error while updating gateway", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while updating gateway. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public Gateway getGateway(String gatewayId) { + public Gateway getGateway(String gatewayId) throws AiravataSystemException { try { var result = registryService.getGateway(gatewayId); logger.debug("Airavata found the gateway with " + gatewayId); return result; - } catch (Throwable e) { - throw convertException(e, "Error while getting the gateway"); + } catch (RegistryServiceException e) { + logger.error("Error while getting the gateway", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while getting the gateway. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public boolean deleteGateway(String gatewayId) { + public boolean deleteGateway(String gatewayId) throws AiravataSystemException { try { return registryService.deleteGateway(gatewayId); - } catch (Throwable e) { - throw convertException(e, "Error while deleting the gateway"); + } catch (RegistryServiceException e) { + logger.error("Error while deleting the gateway", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while deleting the gateway. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public List getAllGateways() { + public List getAllGateways() throws AiravataSystemException { try { logger.debug("Airavata searching for all gateways"); return registryService.getAllGateways(); - } catch (Throwable e) { - throw convertException(e, "Error while getting all the gateways"); + } catch (RegistryServiceException e) { + logger.error("Error while getting all the gateways", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while getting all the gateways. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public boolean isGatewayExist(String gatewayId) { + public boolean isGatewayExist(String gatewayId) throws AiravataSystemException { try { logger.debug("Airavata verifying if the gateway with " + gatewayId + "exits"); return registryService.isGatewayExist(gatewayId); - } catch (Throwable e) { - throw convertException(e, "Error while getting gateway"); + } catch (RegistryServiceException e) { + logger.error("Error while getting gateway", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while getting gateway. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public String createNotification(Notification notification) { + public String createNotification(Notification notification) throws AiravataSystemException { try { return registryService.createNotification(notification); - } catch (Throwable e) { - throw convertException(e, "Error while creating notification"); + } catch (RegistryServiceException e) { + logger.error("Error while creating notification", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while creating notification. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public boolean updateNotification(Notification notification) { + public boolean updateNotification(Notification notification) throws AiravataSystemException { try { return registryService.updateNotification(notification); - } catch (Throwable e) { - throw convertException(e, "Error while updating notification"); + } catch (RegistryServiceException e) { + logger.error("Error while updating notification", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while updating notification. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public boolean deleteNotification(String gatewayId, String notificationId) { + public boolean deleteNotification(String gatewayId, String notificationId) throws AiravataSystemException { try { return registryService.deleteNotification(gatewayId, notificationId); - } catch (Throwable e) { - throw convertException(e, "Error while deleting notification"); + } catch (RegistryServiceException e) { + logger.error("Error while deleting notification", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while deleting notification. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public Notification getNotification(String gatewayId, String notificationId) { + public Notification getNotification(String gatewayId, String notificationId) throws AiravataSystemException { try { return registryService.getNotification(gatewayId, notificationId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving notification"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving notification", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving notification. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public List getAllNotifications(String gatewayId) { + public List getAllNotifications(String gatewayId) throws AiravataSystemException { try { return registryService.getAllNotifications(gatewayId); - } catch (Throwable e) { - throw convertException(e, "Error while getting all notifications"); + } catch (RegistryServiceException e) { + logger.error("Error while getting all notifications", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while getting all notifications. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public String registerDataProduct(DataProductModel dataProductModel) { + public String registerDataProduct(DataProductModel dataProductModel) throws AiravataSystemException { try { return registryService.registerDataProduct(dataProductModel); } catch (Throwable e) { var msg = "Error in registering the data resource" + dataProductModel.getProductName() + "."; logger.error(msg, e); - throw convertException(e, msg); + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + ". More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public DataProductModel getDataProduct(String productUri) { + public DataProductModel getDataProduct(String productUri) throws AiravataSystemException { try { return registryService.getDataProduct(productUri); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving data product"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving data product", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving data product. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public String registerReplicaLocation(DataReplicaLocationModel replicaLocationModel) { + public String registerReplicaLocation(DataReplicaLocationModel replicaLocationModel) + throws AiravataSystemException { try { return registryService.registerReplicaLocation(replicaLocationModel); } catch (Throwable e) { var msg = "Error in retreiving the replica " + replicaLocationModel.getReplicaName() + "."; logger.error(msg, e); - throw convertException(e, msg); + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + ". More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public DataProductModel getParentDataProduct(String productUri) { + public DataProductModel getParentDataProduct(String productUri) throws AiravataSystemException { try { return registryService.getParentDataProduct(productUri); } catch (Throwable e) { var msg = "Error in retreiving the parent data product for " + productUri + "."; logger.error(msg, e); - throw convertException(e, msg); + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + ". More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public List getChildDataProducts(String productUri) { + public List getChildDataProducts(String productUri) throws AiravataSystemException { try { return registryService.getChildDataProducts(productUri); } catch (Throwable e) { var msg = "Error in retreiving the child products for " + productUri + "."; logger.error(msg, e); - throw convertException(e, msg); + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + ". More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public boolean isUserExists(String gatewayId, String userName) { + public boolean isUserExists(String gatewayId, String userName) throws AiravataSystemException { try { logger.debug("Checking if the user" + userName + "exists in the gateway" + gatewayId); return registryService.isUserExists(gatewayId, userName); - } catch (Throwable e) { - throw convertException(e, "Error while verifying user"); + } catch (RegistryServiceException e) { + logger.error("Error while verifying user", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while verifying user. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public Project getProject(String projectId) { + public Project getProject(String projectId) throws AiravataSystemException, ProjectNotFoundException { try { return registryService.getProject(projectId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving the project"); + } catch (ProjectNotFoundException e) { + throw e; + } catch (RegistryServiceException e) { + logger.error("Error while retrieving the project", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving the project. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public String createProject(String gatewayId, Project project) { + public String createProject(String gatewayId, Project project) throws AiravataSystemException { try { return registryService.createProject(gatewayId, project); - } catch (Throwable e) { - throw convertException(e, "Error while creating project"); + } catch (RegistryServiceException e) { + logger.error("Error while creating project", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while creating project. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public void updateProject(String projectId, Project updatedProject) { + public void updateProject(String projectId, Project updatedProject) throws AiravataSystemException { try { registryService.updateProject(projectId, updatedProject); - } catch (Throwable e) { - throw convertException(e, "Error while updating project"); + } catch (RegistryServiceException e) { + logger.error("Error while updating project", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while updating project. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public boolean deleteProject(String projectId) { + public boolean deleteProject(String projectId) throws AiravataSystemException, ProjectNotFoundException { try { return registryService.deleteProject(projectId); - } catch (Throwable e) { - throw convertException(e, "Error while removing the project"); + } catch (ProjectNotFoundException e) { + throw e; + } catch (RegistryServiceException e) { + logger.error("Error while removing the project", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while removing the project. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -541,8 +623,9 @@ public List searchProjectsWithSharing( String userName, Map filters, int limit, - int offset) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { + int offset) + throws AiravataSystemException { + try { var accessibleProjIds = new ArrayList(); List result; if (ServerSettings.isEnableSharing()) { @@ -552,7 +635,8 @@ public List searchProjectsWithSharing( searchCriteria.setSearchCondition(SearchCondition.EQUAL); searchCriteria.setValue(gatewayId + ":PROJECT"); sharingFilters.add(searchCriteria); - sharingRegistryService.searchEntities( + sharingRegistryService + .searchEntities( authzToken.getClaimsMap().get(Constants.GATEWAY_ID), userName + "@" + gatewayId, sharingFilters, @@ -570,9 +654,21 @@ public List searchProjectsWithSharing( result = registryService.searchProjects(gatewayId, userName, accessibleProjIds, filters, limit, offset); } return result; - } catch (Throwable e) { - throw convertException(e, "Error while retrieving projects"); - } + } catch (RegistryServiceException | SharingRegistryException e) { + logger.error("Error while retrieving projects", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving projects. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; + } catch (Throwable e) { + logger.error("Error while retrieving projects", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving projects. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; + } } public List searchProjects( @@ -581,44 +677,72 @@ public List searchProjects( List accessibleProjectIds, Map filters, int limit, - int offset) throws RegistryServiceException { + int offset) + throws RegistryServiceException { return registryService.searchProjects(gatewayId, userName, accessibleProjectIds, filters, limit, offset); } - public List getUserExperiments(String gatewayId, String userName, int limit, int offset) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + public List getUserExperiments(String gatewayId, String userName, int limit, int offset) + throws AiravataSystemException { try { return registryService.getUserExperiments(gatewayId, userName, limit, offset); - } catch (Throwable e) { - throw convertException(e, "Error occurred while getting user experiments"); + } catch (RegistryServiceException e) { + logger.error("Error occurred while getting user experiments", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error occurred while getting user experiments. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public List getExperimentsInProject(String gatewayId, String projectId, int limit, int offset) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + public List getExperimentsInProject(String gatewayId, String projectId, int limit, int offset) + throws AiravataSystemException { try { return registryService.getExperimentsInProject(gatewayId, projectId, limit, offset); - } catch (Throwable e) { - throw convertException(e, "Error occurred while getting experiments in project"); + } catch (RegistryServiceException e) { + logger.error("Error occurred while getting experiments in project", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error occurred while getting experiments in project. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public List getExperimentsInProject( - AuthzToken authzToken, String projectId, int limit, int offset) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + public List getExperimentsInProject(AuthzToken authzToken, String projectId, int limit, int offset) + throws AuthorizationException, AiravataSystemException, ProjectNotFoundException { try { var project = getProject(projectId); var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); if (ServerSettings.isEnableSharing() - && (!authzToken.getClaimsMap().get(Constants.USER_NAME).equals(project.getOwner()) - || !authzToken.getClaimsMap().get(Constants.GATEWAY_ID).equals(project.getGatewayId()))) { - var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!userHasAccess( - gatewayId, userId + "@" + gatewayId, projectId, gatewayId + ":READ")) { - throw new AuthorizationException("User does not have permission to access this resource"); - } + && (!authzToken.getClaimsMap().get(Constants.USER_NAME).equals(project.getOwner()) + || !authzToken + .getClaimsMap() + .get(Constants.GATEWAY_ID) + .equals(project.getGatewayId()))) { + var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + if (!userHasAccess(gatewayId, userId + "@" + gatewayId, projectId, gatewayId + ":READ")) { + throw new AuthorizationException("User does not have permission to access this resource"); + } } return registryService.getExperimentsInProject(gatewayId, projectId, limit, offset); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving the experiments"); + } catch (AuthorizationException | ProjectNotFoundException | AiravataSystemException e) { + throw e; + } catch (ApplicationSettingsException 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()); + exception.initCause(e); + throw exception; + } catch (SharingRegistryException | RegistryServiceException 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()); + exception.initCause(e); + throw exception; } } @@ -632,40 +756,56 @@ public ExperimentStatistics getExperimentStatistics( List accessibleExpIds, int limit, int offset) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + throws AiravataSystemException { try { - return registryService.getExperimentStatistics( - gatewayId, - fromTime, - toTime, - userName, - applicationName, - resourceHostName, - accessibleExpIds, - limit, - offset); - } catch (Throwable e) { - throw convertException(e, "Error while getting experiment statistics"); + return registryService.getExperimentStatistics( + gatewayId, + fromTime, + toTime, + userName, + applicationName, + resourceHostName, + accessibleExpIds, + limit, + offset); + } catch (RegistryServiceException e) { + logger.error("Error while getting experiment statistics", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while getting experiment statistics. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public ExperimentModel getExperiment(String airavataExperimentId) { + public ExperimentModel getExperiment(String airavataExperimentId) throws AiravataSystemException { try { return registryService.getExperiment(airavataExperimentId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving experiment"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving experiment", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving experiment. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public String createExperiment(String gatewayId, ExperimentModel experiment) { + public String createExperiment(String gatewayId, ExperimentModel experiment) throws AiravataSystemException { try { return registryService.createExperiment(gatewayId, experiment); - } catch (Throwable e) { - throw convertException(e, "Error while creating experiment"); + } catch (RegistryServiceException e) { + logger.error("Error while creating experiment", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while creating experiment. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public ExperimentModel getExperiment(AuthzToken authzToken, String airavataExperimentId) throws AuthorizationException { + public ExperimentModel getExperiment(AuthzToken authzToken, String airavataExperimentId) + throws AuthorizationException, InvalidRequestException, AiravataSystemException { try { var existingExperiment = getExperiment(airavataExperimentId); if (authzToken.getClaimsMap().get(Constants.USER_NAME).equals(existingExperiment.getUserName()) @@ -674,22 +814,34 @@ public ExperimentModel getExperiment(AuthzToken authzToken, String airavataExper } else if (ServerSettings.isEnableSharing()) { var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!userHasAccess( - gatewayId, userId + "@" + gatewayId, airavataExperimentId, gatewayId + ":READ")) { + if (!userHasAccess(gatewayId, userId + "@" + gatewayId, airavataExperimentId, gatewayId + ":READ")) { throw new AuthorizationException("User does not have permission to access this resource"); } return existingExperiment; } else { throw new AuthorizationException("User does not have permission to access this resource"); } - } catch (AuthorizationException e) { + } catch (AuthorizationException | AiravataSystemException e) { throw e; - } catch (Throwable e) { - throw convertException(e, "Error while getting the experiment"); + } catch (ApplicationSettingsException e) { + logger.error("Error while getting the experiment", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while getting the experiment. More info: " + e.getMessage()); + exception.initCause(e); + throw exception; + } catch (SharingRegistryException e) { + logger.error("Error while getting the experiment", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while getting the experiment. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public ExperimentModel getExperimentByAdmin(AuthzToken authzToken, String airavataExperimentId) throws AuthorizationException { + public ExperimentModel getExperimentByAdmin(AuthzToken authzToken, String airavataExperimentId) + throws AuthorizationException, AiravataSystemException { try { var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); var existingExperiment = getExperiment(airavataExperimentId); @@ -698,58 +850,84 @@ public ExperimentModel getExperimentByAdmin(AuthzToken authzToken, String airava } else { throw new AuthorizationException("User does not have permission to access this resource"); } - } catch (AuthorizationException e) { + } catch (AuthorizationException | AiravataSystemException e) { throw e; - } catch (Throwable e) { - throw convertException(e, "Error while getting experiment by admin"); } } - public void updateExperiment(AuthzToken authzToken, String airavataExperimentId, ExperimentModel experiment) throws AuthorizationException { - try { + public void updateExperiment(AuthzToken authzToken, String airavataExperimentId, ExperimentModel experiment) + throws AuthorizationException, AiravataSystemException { + try { var existingExperiment = getExperiment(airavataExperimentId); var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); if (ServerSettings.isEnableSharing() - && (!authzToken.getClaimsMap().get(Constants.USER_NAME).equals(existingExperiment.getUserName()) - || !authzToken.getClaimsMap().get(Constants.GATEWAY_ID).equals(existingExperiment.getGatewayId()))) { - var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!userHasAccess( - gatewayId, userId + "@" + gatewayId, airavataExperimentId, gatewayId + ":WRITE")) { - throw new AuthorizationException("User does not have permission to access this resource"); - } + && (!authzToken.getClaimsMap().get(Constants.USER_NAME).equals(existingExperiment.getUserName()) + || !authzToken + .getClaimsMap() + .get(Constants.GATEWAY_ID) + .equals(existingExperiment.getGatewayId()))) { + var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); + if (!userHasAccess(gatewayId, userId + "@" + gatewayId, airavataExperimentId, gatewayId + ":WRITE")) { + throw new AuthorizationException("User does not have permission to access this resource"); + } } try { // Update name, description and parent on Entity // TODO: update the experiment via a DB event var entity = getEntity(gatewayId, airavataExperimentId); - entity.setName(experiment.getExperimentName()); - entity.setDescription(experiment.getDescription()); - entity.setParentEntityId(experiment.getProjectId()); + entity.delegate().setName(experiment.getExperimentName()); + entity.delegate().setDescription(experiment.getDescription()); + entity.delegate().setParentEntityId(experiment.getProjectId()); updateEntity(entity); } catch (Throwable e) { throw new Exception("Failed to update entity in sharing registry", e); } updateExperiment(airavataExperimentId, experiment); - } catch (Throwable e) { - throw convertException(e, "Error while updating experiment"); - } + } catch (AuthorizationException | AiravataSystemException e) { + throw e; + } catch (RegistryServiceException | SharingRegistryException e) { + logger.error("Error while updating experiment", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while updating experiment. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; + } catch (Exception e) { + logger.error("Error while updating experiment", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while updating experiment. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; + } } - public void updateExperiment(String airavataExperimentId, ExperimentModel experiment) { + public void updateExperiment(String airavataExperimentId, ExperimentModel experiment) + throws AiravataSystemException { try { registryService.updateExperiment(airavataExperimentId, experiment); - } catch (Throwable e) { - throw convertException(e, "Error while updating experiment"); + } catch (RegistryServiceException e) { + logger.error("Error while updating experiment", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while updating experiment. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public boolean deleteExperiment(String experimentId) { + public boolean deleteExperiment(String experimentId) throws AiravataSystemException { try { return registryService.deleteExperiment(experimentId); - } catch (Throwable e) { - throw convertException(e, "Error while deleting experiment"); + } catch (RegistryServiceException e) { + logger.error("Error while deleting experiment", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while deleting experiment. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -759,7 +937,8 @@ public String cloneExperimentInternal( String newExperimentName, String newExperimentProjectId, ExperimentModel existingExperiment) - throws ExperimentNotFoundException, ProjectNotFoundException, AuthorizationException { + throws ExperimentNotFoundException, ProjectNotFoundException, AuthorizationException, + AiravataSystemException, InvalidRequestException { try { if (existingExperiment == null) { logger.error( @@ -792,10 +971,12 @@ public String cloneExperimentInternal( "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"); + throw new AuthorizationException( + "User does not have permission to clone an experiment in this project"); } - existingExperiment.setCreationTime(AiravataUtils.getCurrentTimestamp().getTime()); + existingExperiment.setCreationTime( + AiravataUtils.getCurrentTimestamp().getTime()); if (existingExperiment.getExecutionId() != null) { try { var applicationOutputs = getApplicationOutputs(existingExperiment.getExecutionId()); @@ -833,7 +1014,7 @@ public String cloneExperimentInternal( } logger.debug("Airavata cloned experiment with experiment id : " + existingExperimentID); existingExperiment.setUserName(userId); - + var expId = createExperiment(gatewayId, existingExperiment); if (ServerSettings.isEnableSharing()) { try { @@ -845,7 +1026,7 @@ public String cloneExperimentInternal( entity.setOwnerId(existingExperiment.getUserName() + "@" + domainId); entity.setName(existingExperiment.getExperimentName()); entity.setDescription(existingExperiment.getDescription()); - createEntity(entity); + createEntity(new SharingEntity(entity)); shareEntityWithAdminGatewayGroups(entity); } catch (Throwable ex) { logger.error(ex.getMessage(), ex); @@ -855,20 +1036,34 @@ public String cloneExperimentInternal( } catch (Throwable e) { logger.error("Error deleting experiment during rollback: " + e.getMessage()); } - throw convertException(ex, "Error while creating entity for cloned experiment"); + logger.error("Error while creating entity for cloned experiment", ex); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while creating entity for cloned experiment. More info : " + ex.getMessage()); + exception.initCause(ex); + throw exception; } } return expId; - } catch (ExperimentNotFoundException | ProjectNotFoundException | AuthorizationException e) { + } catch (ExperimentNotFoundException + | ProjectNotFoundException + | AuthorizationException + | AiravataSystemException e) { throw e; - } catch (Throwable e) { - throw convertException(e, "Error while cloning experiment"); + } catch (SharingRegistryException | ApplicationSettingsException e) { + logger.error("Error while cloning experiment", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while cloning experiment. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public void terminateExperiment(Publisher experimentPublisher, String airavataExperimentId, String gatewayId) - throws ExperimentNotFoundException { + throws ExperimentNotFoundException, AiravataSystemException { try { var existingExperiment = getExperiment(airavataExperimentId); var experimentLastStatus = getExperimentStatus(airavataExperimentId); @@ -905,7 +1100,12 @@ public void terminateExperiment(Publisher experimentPublisher, String airavataEx throw e; } catch (Throwable e) { logger.error(airavataExperimentId, "Error while cancelling the experiment...", e); - throw convertException(e, "Error occurred"); + logger.error("Error occurred", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error occurred. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -915,7 +1115,8 @@ public List searchExperiments( List accessibleExpIds, Map filters, int limit, - int offset) throws RegistryServiceException { + int offset) + throws RegistryServiceException { return registryService.searchExperiments(gatewayId, userName, accessibleExpIds, filters, limit, offset); } @@ -923,345 +1124,504 @@ public List searchExperiments( * Search experiments with sharing registry integration - processes filters and builds search criteria */ public List searchExperimentsWithSharing( - AuthzToken authzToken, String gatewayId, String userName, Map filters, int limit, int offset) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - try { - var accessibleExpIds = new ArrayList(); - var filtersCopy = new HashMap(filters); - var sharingFilters = new ArrayList(); - var searchCriteria = new SearchCriteria(); - searchCriteria.setSearchField(EntitySearchField.ENTITY_TYPE_ID); - searchCriteria.setSearchCondition(SearchCondition.EQUAL); - searchCriteria.setValue(gatewayId + ":EXPERIMENT"); - sharingFilters.add(searchCriteria); - - // Apply as much of the filters in the sharing API as possible, - // removing each filter that can be filtered via the sharing API - if (filtersCopy.containsKey(ExperimentSearchFields.FROM_DATE)) { - var fromTime = filtersCopy.remove(ExperimentSearchFields.FROM_DATE); - var fromCreatedTimeCriteria = new SearchCriteria(); - fromCreatedTimeCriteria.setSearchField(EntitySearchField.CREATED_TIME); - fromCreatedTimeCriteria.setSearchCondition(SearchCondition.GTE); - fromCreatedTimeCriteria.setValue(fromTime); - sharingFilters.add(fromCreatedTimeCriteria); - } - if (filtersCopy.containsKey(ExperimentSearchFields.TO_DATE)) { - var toTime = filtersCopy.remove(ExperimentSearchFields.TO_DATE); - var toCreatedTimeCriteria = new SearchCriteria(); - toCreatedTimeCriteria.setSearchField(EntitySearchField.CREATED_TIME); - toCreatedTimeCriteria.setSearchCondition(SearchCondition.LTE); - toCreatedTimeCriteria.setValue(toTime); - sharingFilters.add(toCreatedTimeCriteria); - } - if (filtersCopy.containsKey(ExperimentSearchFields.PROJECT_ID)) { - var projectId = filtersCopy.remove(ExperimentSearchFields.PROJECT_ID); - var projectParentEntityCriteria = new SearchCriteria(); - projectParentEntityCriteria.setSearchField(EntitySearchField.PARRENT_ENTITY_ID); - projectParentEntityCriteria.setSearchCondition(SearchCondition.EQUAL); - projectParentEntityCriteria.setValue(projectId); - sharingFilters.add(projectParentEntityCriteria); - } - if (filtersCopy.containsKey(ExperimentSearchFields.USER_NAME)) { - var username = filtersCopy.remove(ExperimentSearchFields.USER_NAME); - var usernameOwnerCriteria = new SearchCriteria(); - usernameOwnerCriteria.setSearchField(EntitySearchField.OWNER_ID); - usernameOwnerCriteria.setSearchCondition(SearchCondition.EQUAL); - usernameOwnerCriteria.setValue(username + "@" + gatewayId); - sharingFilters.add(usernameOwnerCriteria); - } - if (filtersCopy.containsKey(ExperimentSearchFields.EXPERIMENT_NAME)) { - var experimentName = filtersCopy.remove(ExperimentSearchFields.EXPERIMENT_NAME); - var experimentNameCriteria = new SearchCriteria(); - experimentNameCriteria.setSearchField(EntitySearchField.NAME); - experimentNameCriteria.setSearchCondition(SearchCondition.LIKE); - experimentNameCriteria.setValue(experimentName); - sharingFilters.add(experimentNameCriteria); - } - if (filtersCopy.containsKey(ExperimentSearchFields.EXPERIMENT_DESC)) { - var experimentDescription = filtersCopy.remove(ExperimentSearchFields.EXPERIMENT_DESC); - var experimentDescriptionCriteria = new SearchCriteria(); - experimentDescriptionCriteria.setSearchField(EntitySearchField.DESCRIPTION); - experimentDescriptionCriteria.setSearchCondition(SearchCondition.LIKE); - experimentDescriptionCriteria.setValue(experimentDescription); - sharingFilters.add(experimentDescriptionCriteria); - } - // Grab all of the matching experiments in the sharing registry - // unless all of the filtering can be done through the sharing API - int searchOffset = 0; - int searchLimit = Integer.MAX_VALUE; - boolean filteredInSharing = filtersCopy.isEmpty(); - if (filteredInSharing) { - searchOffset = offset; - searchLimit = limit; - } - sharingRegistryService - .searchEntities( - authzToken.getClaimsMap().get(Constants.GATEWAY_ID), - userName + "@" + gatewayId, - sharingFilters, - searchOffset, - searchLimit) - .forEach(e -> accessibleExpIds.add(e.getEntityId())); - int finalOffset = offset; - // If no more filtering to be done (either empty or all done through sharing API), set the offset to 0 - if (filteredInSharing) { - finalOffset = 0; - } - return searchExperiments(gatewayId, userName, accessibleExpIds, filtersCopy, limit, finalOffset); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving experiments"); + throws AiravataSystemException { + try { + var accessibleExpIds = new ArrayList(); + var filtersCopy = new HashMap(filters); + var sharingFilters = new ArrayList(); + var searchCriteria = new SearchCriteria(); + searchCriteria.setSearchField(EntitySearchField.ENTITY_TYPE_ID); + searchCriteria.setSearchCondition(SearchCondition.EQUAL); + searchCriteria.setValue(gatewayId + ":EXPERIMENT"); + sharingFilters.add(searchCriteria); + + // Apply as much of the filters in the sharing API as possible, + // removing each filter that can be filtered via the sharing API + if (filtersCopy.containsKey(ExperimentSearchFields.FROM_DATE)) { + var fromTime = filtersCopy.remove(ExperimentSearchFields.FROM_DATE); + var fromCreatedTimeCriteria = new SearchCriteria(); + fromCreatedTimeCriteria.setSearchField(EntitySearchField.CREATED_TIME); + fromCreatedTimeCriteria.setSearchCondition(SearchCondition.GTE); + fromCreatedTimeCriteria.setValue(fromTime); + sharingFilters.add(fromCreatedTimeCriteria); + } + if (filtersCopy.containsKey(ExperimentSearchFields.TO_DATE)) { + var toTime = filtersCopy.remove(ExperimentSearchFields.TO_DATE); + var toCreatedTimeCriteria = new SearchCriteria(); + toCreatedTimeCriteria.setSearchField(EntitySearchField.CREATED_TIME); + toCreatedTimeCriteria.setSearchCondition(SearchCondition.LTE); + toCreatedTimeCriteria.setValue(toTime); + sharingFilters.add(toCreatedTimeCriteria); + } + if (filtersCopy.containsKey(ExperimentSearchFields.PROJECT_ID)) { + var projectId = filtersCopy.remove(ExperimentSearchFields.PROJECT_ID); + var projectParentEntityCriteria = new SearchCriteria(); + projectParentEntityCriteria.setSearchField(EntitySearchField.PARRENT_ENTITY_ID); + projectParentEntityCriteria.setSearchCondition(SearchCondition.EQUAL); + projectParentEntityCriteria.setValue(projectId); + sharingFilters.add(projectParentEntityCriteria); + } + if (filtersCopy.containsKey(ExperimentSearchFields.USER_NAME)) { + var username = filtersCopy.remove(ExperimentSearchFields.USER_NAME); + var usernameOwnerCriteria = new SearchCriteria(); + usernameOwnerCriteria.setSearchField(EntitySearchField.OWNER_ID); + usernameOwnerCriteria.setSearchCondition(SearchCondition.EQUAL); + usernameOwnerCriteria.setValue(username + "@" + gatewayId); + sharingFilters.add(usernameOwnerCriteria); + } + if (filtersCopy.containsKey(ExperimentSearchFields.EXPERIMENT_NAME)) { + var experimentName = filtersCopy.remove(ExperimentSearchFields.EXPERIMENT_NAME); + var experimentNameCriteria = new SearchCriteria(); + experimentNameCriteria.setSearchField(EntitySearchField.NAME); + experimentNameCriteria.setSearchCondition(SearchCondition.LIKE); + experimentNameCriteria.setValue(experimentName); + sharingFilters.add(experimentNameCriteria); + } + if (filtersCopy.containsKey(ExperimentSearchFields.EXPERIMENT_DESC)) { + var experimentDescription = filtersCopy.remove(ExperimentSearchFields.EXPERIMENT_DESC); + var experimentDescriptionCriteria = new SearchCriteria(); + experimentDescriptionCriteria.setSearchField(EntitySearchField.DESCRIPTION); + experimentDescriptionCriteria.setSearchCondition(SearchCondition.LIKE); + experimentDescriptionCriteria.setValue(experimentDescription); + sharingFilters.add(experimentDescriptionCriteria); + } + // Grab all of the matching experiments in the sharing registry + // unless all of the filtering can be done through the sharing API + int searchOffset = 0; + int searchLimit = Integer.MAX_VALUE; + boolean filteredInSharing = filtersCopy.isEmpty(); + if (filteredInSharing) { + searchOffset = offset; + searchLimit = limit; + } + sharingRegistryService + .searchEntities( + authzToken.getClaimsMap().get(Constants.GATEWAY_ID), + userName + "@" + gatewayId, + sharingFilters, + searchOffset, + searchLimit) + .forEach(e -> accessibleExpIds.add(e.getEntityId())); + int finalOffset = offset; + // If no more filtering to be done (either empty or all done through sharing API), set the offset to 0 + if (filteredInSharing) { + finalOffset = 0; + } + return searchExperiments(gatewayId, userName, accessibleExpIds, filtersCopy, limit, finalOffset); + } catch (RegistryServiceException | SharingRegistryException e) { + logger.error("Error while retrieving experiments", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving experiments. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public ExperimentStatus getExperimentStatus(String airavataExperimentId) { + public ExperimentStatus getExperimentStatus(String airavataExperimentId) throws AiravataSystemException { try { return registryService.getExperimentStatus(airavataExperimentId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving experiment status"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving experiment status", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving experiment status. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public List getExperimentOutputs(String airavataExperimentId) { + public List getExperimentOutputs(String airavataExperimentId) throws AiravataSystemException { try { return registryService.getExperimentOutputs(airavataExperimentId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving experiment outputs"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving experiment outputs", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving experiment outputs. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public ExperimentModel getDetailedExperimentTree(String airavataExperimentId) { + public ExperimentModel getDetailedExperimentTree(String airavataExperimentId) throws AiravataSystemException { try { return registryService.getDetailedExperimentTree(airavataExperimentId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving detailed experiment tree"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving detailed experiment tree", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving detailed experiment tree. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public List getApplicationOutputs(String appInterfaceId) { + public List getApplicationOutputs(String appInterfaceId) throws AiravataSystemException { try { return registryService.getApplicationOutputs(appInterfaceId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving application outputs"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving application outputs", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving application outputs. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public ComputeResourceDescription getComputeResource(String computeResourceId) { + public ComputeResourceDescription getComputeResource(String computeResourceId) throws AiravataSystemException { try { return registryService.getComputeResource(computeResourceId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving compute resource"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving compute resource", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving compute resource. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public String registerComputeResource(ComputeResourceDescription computeResourceDescription) { + public String registerComputeResource(ComputeResourceDescription computeResourceDescription) + throws AiravataSystemException { try { return registryService.registerComputeResource(computeResourceDescription); - } catch (Throwable e) { - throw convertException(e, "Error while saving compute resource"); + } catch (RegistryServiceException e) { + logger.error("Error while saving compute resource", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while saving compute resource. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean updateComputeResource( - String computeResourceId, ComputeResourceDescription computeResourceDescription) { + String computeResourceId, ComputeResourceDescription computeResourceDescription) + throws AiravataSystemException { try { return registryService.updateComputeResource(computeResourceId, computeResourceDescription); - } catch (Throwable e) { - throw convertException(e, "Error while updating compute resource"); + } catch (RegistryServiceException e) { + logger.error("Error while updating compute resource", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while updating compute resource. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public boolean deleteComputeResource(String computeResourceId) { + public boolean deleteComputeResource(String computeResourceId) throws AiravataSystemException { try { return registryService.deleteComputeResource(computeResourceId); - } catch (Throwable e) { - throw convertException(e, "Error while deleting compute resource"); + } catch (RegistryServiceException e) { + logger.error("Error while deleting compute resource", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while deleting compute resource. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public Map getAllComputeResourceNames() { + public Map getAllComputeResourceNames() throws AiravataSystemException { try { return registryService.getAllComputeResourceNames(); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving compute resource names"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving compute resource names", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving compute resource names. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public String registerStorageResource(StorageResourceDescription storageResourceDescription) { + public String registerStorageResource(StorageResourceDescription storageResourceDescription) + throws AiravataSystemException { try { return registryService.registerStorageResource(storageResourceDescription); - } catch (Throwable e) { - throw convertException(e, "Error while saving storage resource"); + } catch (RegistryServiceException e) { + logger.error("Error while saving storage resource", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while saving storage resource. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public StorageResourceDescription getStorageResource(String storageResourceId) { + public StorageResourceDescription getStorageResource(String storageResourceId) throws AiravataSystemException { try { return registryService.getStorageResource(storageResourceId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving storage resource"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving storage resource", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving storage resource. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean updateStorageResource( - String storageResourceId, StorageResourceDescription storageResourceDescription) { + String storageResourceId, StorageResourceDescription storageResourceDescription) + throws AiravataSystemException { try { return registryService.updateStorageResource(storageResourceId, storageResourceDescription); - } catch (Throwable e) { - throw convertException(e, "Error while updating storage resource"); + } catch (RegistryServiceException e) { + logger.error("Error while updating storage resource", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while updating storage resource. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public boolean deleteStorageResource(String storageResourceId) { + public boolean deleteStorageResource(String storageResourceId) throws AiravataSystemException { try { return registryService.deleteStorageResource(storageResourceId); - } catch (Throwable e) { - throw convertException(e, "Error while deleting storage resource"); + } catch (RegistryServiceException e) { + logger.error("Error while deleting storage resource", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while deleting storage resource. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public Map getAllStorageResourceNames() { + public Map getAllStorageResourceNames() throws AiravataSystemException { try { return registryService.getAllStorageResourceNames(); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving storage resource names"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving storage resource names", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving storage resource names. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public String registerGatewayResourceProfile(GatewayResourceProfile gatewayResourceProfile) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + throws AiravataSystemException { try { return registryService.registerGatewayResourceProfile(gatewayResourceProfile); - } catch (Throwable e) { - throw convertException(e, "Error while registering gateway resource profile"); + } catch (RegistryServiceException e) { + logger.error("Error while registering gateway resource profile", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while registering gateway resource profile. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public GatewayResourceProfile getGatewayResourceProfile(String gatewayID) { + public GatewayResourceProfile getGatewayResourceProfile(String gatewayID) throws AiravataSystemException { try { return registryService.getGatewayResourceProfile(gatewayID); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving gateway resource profile"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving gateway resource profile", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving gateway resource profile. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public boolean updateGatewayResourceProfile(String gatewayID, GatewayResourceProfile gatewayResourceProfile) { + public boolean updateGatewayResourceProfile(String gatewayID, GatewayResourceProfile gatewayResourceProfile) + throws AiravataSystemException { try { return registryService.updateGatewayResourceProfile(gatewayID, gatewayResourceProfile); - } catch (Throwable e) { - throw convertException(e, "Error while updating gateway resource profile"); + } catch (RegistryServiceException e) { + logger.error("Error while updating gateway resource profile", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while updating gateway resource profile. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public boolean deleteGatewayResourceProfile(String gatewayID) { + public boolean deleteGatewayResourceProfile(String gatewayID) throws AiravataSystemException { try { return registryService.deleteGatewayResourceProfile(gatewayID); - } catch (Throwable e) { - throw convertException(e, "Error while removing gateway resource profile"); - } + } catch (RegistryServiceException e) { + logger.error("Error while removing gateway resource profile", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while removing gateway resource profile. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; + } } - public UserResourceProfile getUserResourceProfile(String userId, String gatewayId) { + public UserResourceProfile getUserResourceProfile(String userId, String gatewayId) throws AiravataSystemException { try { return registryService.getUserResourceProfile(userId, gatewayId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving user resource profile"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving user resource profile", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving user resource profile. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public boolean updateUserResourceProfile(String userId, String gatewayID, UserResourceProfile userResourceProfile) { + public boolean updateUserResourceProfile(String userId, String gatewayID, UserResourceProfile userResourceProfile) + throws AiravataSystemException { try { return registryService.updateUserResourceProfile(userId, gatewayID, userResourceProfile); - } catch (Throwable e) { - throw convertException(e, "Error while updating user resource profile"); + } catch (RegistryServiceException e) { + logger.error("Error while updating user resource profile", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while updating user resource profile. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public boolean deleteUserResourceProfile(String userId, String gatewayID) { + public boolean deleteUserResourceProfile(String userId, String gatewayID) throws AiravataSystemException { try { return registryService.deleteUserResourceProfile(userId, gatewayID); - } catch (Throwable e) { - throw convertException(e, "Error while removing user resource profile"); + } catch (RegistryServiceException e) { + logger.error("Error while removing user resource profile", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while removing user resource profile. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public GroupResourceProfile getGroupResourceProfile(String groupResourceProfileId) { + public GroupResourceProfile getGroupResourceProfile(String groupResourceProfileId) throws AiravataSystemException { try { return registryService.getGroupResourceProfile(groupResourceProfileId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving group resource profile"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving group resource profile", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving group resource profile. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public void updateGroupResourceProfile(GroupResourceProfile groupResourceProfile) { + public void updateGroupResourceProfile(GroupResourceProfile groupResourceProfile) throws AiravataSystemException { try { registryService.updateGroupResourceProfile(groupResourceProfile); - } catch (Throwable e) { - throw convertException(e, "Error while updating group resource profile"); + } catch (RegistryServiceException e) { + logger.error("Error while updating group resource profile", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while updating group resource profile. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public List getGroupResourceList(String gatewayId, List accessibleGroupResProfileIds) { + public List getGroupResourceList(String gatewayId, List accessibleGroupResProfileIds) + throws AiravataSystemException { try { return registryService.getGroupResourceList(gatewayId, accessibleGroupResProfileIds); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving group resource list"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving group resource list", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving group resource list. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public GatewayGroups getGatewayGroups(String gatewayId) { + public GatewayGroups getGatewayGroups(String gatewayId) throws AiravataSystemException { try { return registryService.getGatewayGroups(gatewayId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving gateway groups"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving gateway groups", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving gateway groups. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public boolean isGatewayGroupsExists(String gatewayId) { + public boolean isGatewayGroupsExists(String gatewayId) throws AiravataSystemException { try { return registryService.isGatewayGroupsExists(gatewayId); - } catch (Throwable e) { - throw convertException(e, "Error while checking if gateway groups exist"); + } catch (RegistryServiceException e) { + logger.error("Error while checking if gateway groups exist", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while checking if gateway groups exist. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public void updateExperimentConfiguration(String airavataExperimentId, UserConfigurationDataModel userConfiguration) { + public void updateExperimentConfiguration(String airavataExperimentId, UserConfigurationDataModel userConfiguration) + throws AiravataSystemException { try { registryService.updateExperimentConfiguration(airavataExperimentId, userConfiguration); - } catch (Throwable e) { - throw convertException(e, "Error while updating experiment configuration"); + } catch (RegistryServiceException e) { + logger.error("Error while updating experiment configuration", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while updating experiment configuration. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public void updateResourceScheduleing( - String airavataExperimentId, ComputationalResourceSchedulingModel resourceScheduling) { + String airavataExperimentId, ComputationalResourceSchedulingModel resourceScheduling) + throws AiravataSystemException { try { registryService.updateResourceScheduleing(airavataExperimentId, resourceScheduling); - } catch (Throwable e) { - throw convertException(e, "Error while updating resource scheduling"); + } catch (RegistryServiceException e) { + logger.error("Error while updating resource scheduling", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while updating resource scheduling. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public String registerApplicationDeployment( - String gatewayId, ApplicationDeploymentDescription applicationDeployment) { + String gatewayId, ApplicationDeploymentDescription applicationDeployment) throws AiravataSystemException { try { return registryService.registerApplicationDeployment(gatewayId, applicationDeployment); - } catch (Throwable e) { - throw convertException(e, "Error while registering application deployment"); + } catch (RegistryServiceException e) { + logger.error("Error while registering application deployment", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while registering application deployment. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public String registerApplicationDeploymentWithSharing( - AuthzToken authzToken, String gatewayId, ApplicationDeploymentDescription applicationDeployment) { + AuthzToken authzToken, String gatewayId, ApplicationDeploymentDescription applicationDeployment) + throws AiravataSystemException, InvalidRequestException, AuthorizationException { try { String result = registerApplicationDeployment(gatewayId, applicationDeployment); if (ServerSettings.isEnableSharing()) { - var entity = new Entity(); + var entity = new Entity(); entity.setEntityId(result); final String domainId = gatewayId; entity.setDomainId(domainId); @@ -1270,121 +1630,182 @@ public String registerApplicationDeploymentWithSharing( entity.setOwnerId(userName + "@" + domainId); entity.setName(result); entity.setDescription(applicationDeployment.getAppDeploymentDescription()); - createEntity(entity); + createEntity(new SharingEntity(entity)); shareEntityWithAdminGatewayGroups(entity); } return result; + } catch (InvalidRequestException | AuthorizationException e) { + throw e; } catch (Throwable e) { - throw convertException(e, "Error while registering application deployment"); + logger.error("Error while registering application deployment", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while registering application deployment. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public ApplicationDeploymentDescription getApplicationDeployment(String appDeploymentId) { + public ApplicationDeploymentDescription getApplicationDeployment(String appDeploymentId) + throws AiravataSystemException { try { return registryService.getApplicationDeployment(appDeploymentId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving application deployment"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving application deployment", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving application deployment. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public ApplicationDeploymentDescription getApplicationDeploymentWithAuth(AuthzToken authzToken, String appDeploymentId) - throws AuthorizationException { + public ApplicationDeploymentDescription getApplicationDeploymentWithAuth( + AuthzToken authzToken, String appDeploymentId) + throws AuthorizationException, AiravataSystemException, InvalidRequestException { try { if (ServerSettings.isEnableSharing()) { - final boolean hasAccess = userHasAccessInternal(authzToken, appDeploymentId, ResourcePermissionType.READ); + final boolean hasAccess = + userHasAccessInternal(authzToken, appDeploymentId, ResourcePermissionType.READ); if (!hasAccess) { throw new AuthorizationException( "User does not have access to application deployment " + appDeploymentId); } } return getApplicationDeployment(appDeploymentId); - } catch (AuthorizationException e) { + } catch (AuthorizationException | AiravataSystemException e) { throw e; - } catch (Throwable e) { - throw convertException(e, "Error while retrieving application deployment"); + } catch (ApplicationSettingsException e) { + logger.error("Error occurred while getting application deployment", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error occurred while getting application deployment. More info: " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean updateApplicationDeployment( - String appDeploymentId, ApplicationDeploymentDescription applicationDeployment) { + String appDeploymentId, ApplicationDeploymentDescription applicationDeployment) + throws AiravataSystemException { try { return registryService.updateApplicationDeployment(appDeploymentId, applicationDeployment); - } catch (Throwable e) { - throw convertException(e, "Error while updating application deployment"); + } catch (RegistryServiceException e) { + logger.error("Error while updating application deployment", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while updating application deployment. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean updateApplicationDeploymentWithAuth( AuthzToken authzToken, String appDeploymentId, ApplicationDeploymentDescription applicationDeployment) - throws AuthorizationException { + throws AuthorizationException, AiravataSystemException { try { if (ServerSettings.isEnableSharing()) { - final boolean hasAccess = userHasAccessInternal(authzToken, appDeploymentId, ResourcePermissionType.WRITE); + final boolean hasAccess = + userHasAccessInternal(authzToken, appDeploymentId, ResourcePermissionType.WRITE); if (!hasAccess) { throw new AuthorizationException( "User does not have WRITE access to application deployment " + appDeploymentId); } } return updateApplicationDeployment(appDeploymentId, applicationDeployment); - } catch (AuthorizationException e) { + } catch (AuthorizationException | AiravataSystemException e) { throw e; - } catch (Throwable e) { - throw convertException(e, "Error while updating application deployment"); + } catch (ApplicationSettingsException e) { + logger.error("Error occurred while updating application deployment", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error occurred while updating application deployment. More info: " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public boolean deleteApplicationDeployment(String appDeploymentId) { + public boolean deleteApplicationDeployment(String appDeploymentId) throws AiravataSystemException { try { return registryService.deleteApplicationDeployment(appDeploymentId); - } catch (Throwable e) { - throw convertException(e, "Error while deleting application deployment"); + } catch (RegistryServiceException e) { + logger.error("Error while deleting application deployment", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while deleting application deployment. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean deleteApplicationDeploymentWithAuth(AuthzToken authzToken, String appDeploymentId) - throws AuthorizationException { + throws AuthorizationException, AiravataSystemException, InvalidRequestException { try { if (ServerSettings.isEnableSharing()) { - final boolean hasAccess = userHasAccessInternal(authzToken, appDeploymentId, ResourcePermissionType.WRITE); + final boolean hasAccess = + userHasAccessInternal(authzToken, appDeploymentId, ResourcePermissionType.WRITE); if (!hasAccess) { throw new AuthorizationException( "User does not have WRITE access to application deployment " + appDeploymentId); } } return deleteApplicationDeployment(appDeploymentId); - } catch (AuthorizationException e) { + } catch (AuthorizationException | AiravataSystemException e) { throw e; - } catch (Throwable e) { - throw convertException(e, "Error while deleting application deployment"); + } catch (ApplicationSettingsException e) { + logger.error("Error occurred while deleting application deployment", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error occurred while deleting application deployment. More info: " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public ApplicationInterfaceDescription getApplicationInterface(String appInterfaceId) { + public ApplicationInterfaceDescription getApplicationInterface(String appInterfaceId) + throws AiravataSystemException { try { return registryService.getApplicationInterface(appInterfaceId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving application interface"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving application interface", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving application interface. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public List getApplicationDeployments(String appModuleId) { + public List getApplicationDeployments(String appModuleId) + throws AiravataSystemException { try { return registryService.getApplicationDeployments(appModuleId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving application deployments"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving application deployments", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving application deployments. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public String registerApplicationInterface(String gatewayId, ApplicationInterfaceDescription applicationInterface) { + public String registerApplicationInterface(String gatewayId, ApplicationInterfaceDescription applicationInterface) + throws AiravataSystemException { try { return registryService.registerApplicationInterface(gatewayId, applicationInterface); - } catch (Throwable e) { - throw convertException(e, "Error while adding application interface"); + } catch (RegistryServiceException e) { + logger.error("Error while adding application interface", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while adding application interface. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public String cloneApplicationInterface(String existingAppInterfaceID, String newApplicationName, String gatewayId) - throws AiravataSystemException { + throws AiravataSystemException, InvalidRequestException, AuthorizationException { try { var existingInterface = getApplicationInterface(existingAppInterfaceID); if (existingInterface == null) { @@ -1401,107 +1822,155 @@ public String cloneApplicationInterface(String existingAppInterfaceID, String ne return interfaceId; } catch (AiravataSystemException e) { throw e; - } catch (Throwable e) { - throw convertException(e, "Provided application interface does not exist.Please provide a valid application interface id..."); } } public boolean updateApplicationInterface( - String appInterfaceId, ApplicationInterfaceDescription applicationInterface) { + String appInterfaceId, ApplicationInterfaceDescription applicationInterface) + throws AiravataSystemException { try { return registryService.updateApplicationInterface(appInterfaceId, applicationInterface); - } catch (Throwable e) { - throw convertException(e, "Error while updating application interface"); + } catch (RegistryServiceException e) { + logger.error("Error while updating application interface", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while updating application interface. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public boolean deleteApplicationInterface(String appInterfaceId) { + public boolean deleteApplicationInterface(String appInterfaceId) throws AiravataSystemException { try { return registryService.deleteApplicationInterface(appInterfaceId); - } catch (Throwable e) { - throw convertException(e, "Error while deleting application interface"); + } catch (RegistryServiceException e) { + logger.error("Error while deleting application interface", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while deleting application interface. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public Map getAllApplicationInterfaceNames(String gatewayId) { + public Map getAllApplicationInterfaceNames(String gatewayId) throws AiravataSystemException { try { return registryService.getAllApplicationInterfaceNames(gatewayId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving application interfaces"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving application interfaces", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving application interfaces. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public List getAllApplicationInterfaces(String gatewayId) { + public List getAllApplicationInterfaces(String gatewayId) + throws AiravataSystemException { try { return registryService.getAllApplicationInterfaces(gatewayId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving application interfaces"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving application interfaces", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving application interfaces. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public List getApplicationInputs(String appInterfaceId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + public List getApplicationInputs(String appInterfaceId) throws AiravataSystemException { try { return registryService.getApplicationInputs(appInterfaceId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving application inputs"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving application inputs", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving application inputs. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public String registerApplicationModule(String gatewayId, ApplicationModule applicationModule) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + throws AiravataSystemException { try { return registryService.registerApplicationModule(gatewayId, applicationModule); - } catch (Throwable e) { - throw convertException(e, "Error while adding application module"); + } catch (RegistryServiceException e) { + logger.error("Error while adding application module", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while adding application module. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public ApplicationModule getApplicationModule(String appModuleId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + public ApplicationModule getApplicationModule(String appModuleId) throws AiravataSystemException { try { return registryService.getApplicationModule(appModuleId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving application module"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving application module", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving application module. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean updateApplicationModule(String appModuleId, ApplicationModule applicationModule) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + throws AiravataSystemException { try { return registryService.updateApplicationModule(appModuleId, applicationModule); - } catch (Throwable e) { - throw convertException(e, "Error while updating application module"); + } catch (RegistryServiceException e) { + logger.error("Error while updating application module", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while updating application module. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public List getAllAppModules(String gatewayId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + public List getAllAppModules(String gatewayId) throws AiravataSystemException { try { return registryService.getAllAppModules(gatewayId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving all application modules"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving all application modules", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving all application modules. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public boolean deleteApplicationModule(String appModuleId) { + public boolean deleteApplicationModule(String appModuleId) throws AiravataSystemException { try { return registryService.deleteApplicationModule(appModuleId); - } catch (Throwable e) { - throw convertException(e, "Error while deleting application module"); + } catch (RegistryServiceException e) { + logger.error("Error while deleting application module", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while deleting application module. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public List getAccessibleAppModules( - String gatewayId, List accessibleAppIds, List accessibleComputeResourceIds) throws RegistryServiceException { + String gatewayId, List accessibleAppIds, List accessibleComputeResourceIds) + throws RegistryServiceException { return registryService.getAccessibleAppModules(gatewayId, accessibleAppIds, accessibleComputeResourceIds); } /** * Get accessible app modules with sharing registry integration */ - public List getAccessibleAppModulesWithSharing( - AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + public List getAccessibleAppModulesWithSharing(AuthzToken authzToken, String gatewayId) + throws InvalidRequestException, AiravataSystemException, AuthorizationException { try { var userName = authzToken.getClaimsMap().get(Constants.USER_NAME); var accessibleAppDeploymentIds = new ArrayList(); @@ -1528,271 +1997,436 @@ public List getAccessibleAppModulesWithSharing( } var accessibleComputeResourceIds = new ArrayList(); List groupResourceProfileList = - getGroupResourceListWithSharing( authzToken, gatewayId); + getGroupResourceListWithSharing(authzToken, gatewayId); for (GroupResourceProfile groupResourceProfile : groupResourceProfileList) { List groupComputeResourcePreferenceList = groupResourceProfile.getComputePreferences(); - for (GroupComputeResourcePreference groupComputeResourcePreference : groupComputeResourcePreferenceList) { + for (GroupComputeResourcePreference groupComputeResourcePreference : + groupComputeResourcePreferenceList) { accessibleComputeResourceIds.add(groupComputeResourcePreference.getComputeResourceId()); } } return getAccessibleAppModules(gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); - } catch (Throwable e) { - throw convertException(e, "Error occurred while getting accessible app modules"); + } catch (AiravataSystemException e) { + throw e; + } catch (ApplicationSettingsException e) { + logger.error("Error occurred while getting accessible app modules", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error occurred while getting accessible app modules. More info: " + e.getMessage()); + exception.initCause(e); + throw exception; + } catch (RegistryServiceException | SharingRegistryException e) { + logger.error("Error occurred while getting accessible app modules", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error occurred while getting accessible app modules. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public Map getJobStatuses(String airavataExperimentId) { + public Map getJobStatuses(String airavataExperimentId) throws AiravataSystemException { try { return registryService.getJobStatuses(airavataExperimentId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving job statuses"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving job statuses", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving job statuses. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public List getJobDetails(String airavataExperimentId) { + public List getJobDetails(String airavataExperimentId) throws AiravataSystemException { try { return registryService.getJobDetails(airavataExperimentId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving job details"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving job details", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving job details. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public String addLocalSubmissionDetails( - String computeResourceId, int priorityOrder, LOCALSubmission localSubmission) { + String computeResourceId, int priorityOrder, LOCALSubmission localSubmission) + throws AiravataSystemException { try { return registryService.addLocalSubmissionDetails(computeResourceId, priorityOrder, localSubmission); + } catch (RegistryServiceException e) { + logger.error("Error while adding local job submission interface", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while adding local job submission interface. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } catch (Throwable e) { - throw convertException(e, "Error while adding local job submission interface"); + logger.error("Error while adding local job submission interface", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while adding local job submission interface. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public String addSSHJobSubmissionDetails( - String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) { + String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) + throws AiravataSystemException { try { return registryService.addSSHJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); - } catch (Throwable e) { - throw convertException(e, "Error while adding SSH job submission interface"); + } catch (RegistryServiceException e) { + logger.error("Error while adding SSH job submission interface", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while adding SSH job submission interface. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public String addSSHForkJobSubmissionDetails( - String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) { + String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) + throws AiravataSystemException { try { return registryService.addSSHForkJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); - } catch (Throwable e) { - throw convertException(e, "Error while adding SSH fork job submission interface"); + } catch (RegistryServiceException e) { + logger.error("Error while adding SSH fork job submission interface", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while adding SSH fork job submission interface. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public String addCloudJobSubmissionDetails( - String computeResourceId, int priorityOrder, CloudJobSubmission cloudJobSubmission) { + String computeResourceId, int priorityOrder, CloudJobSubmission cloudJobSubmission) + throws AiravataSystemException { try { return registryService.addCloudJobSubmissionDetails(computeResourceId, priorityOrder, cloudJobSubmission); - } catch (Throwable e) { - throw convertException(e, "Error while adding cloud job submission interface"); + } catch (RegistryServiceException e) { + logger.error("Error while adding cloud job submission interface", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while adding cloud job submission interface. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public String addUNICOREJobSubmissionDetails( - String computeResourceId, int priorityOrder, UnicoreJobSubmission unicoreJobSubmission) { + String computeResourceId, int priorityOrder, UnicoreJobSubmission unicoreJobSubmission) + throws AiravataSystemException { try { - return registryService.addUNICOREJobSubmissionDetails(computeResourceId, priorityOrder, unicoreJobSubmission); - } catch (Throwable e) { - throw convertException(e, "Error while adding UNICORE job submission interface"); + return registryService.addUNICOREJobSubmissionDetails( + computeResourceId, priorityOrder, unicoreJobSubmission); + } catch (RegistryServiceException e) { + logger.error("Error while adding UNICORE job submission interface", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while adding UNICORE job submission interface. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public boolean updateLocalSubmissionDetails(String jobSubmissionInterfaceId, LOCALSubmission localSubmission) { + public boolean updateLocalSubmissionDetails(String jobSubmissionInterfaceId, LOCALSubmission localSubmission) + throws AiravataSystemException { try { return registryService.updateLocalSubmissionDetails(jobSubmissionInterfaceId, localSubmission); + } catch (RegistryServiceException e) { + logger.error("Error while updating local job submission interface", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while updating local job submission interface. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } catch (Throwable e) { - throw convertException(e, "Error while updating local job submission interface"); + logger.error("Error while updating local job submission interface", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while updating local job submission interface. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public LOCALSubmission getLocalJobSubmission(String jobSubmissionId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + public LOCALSubmission getLocalJobSubmission(String jobSubmissionId) throws AiravataSystemException { try { return registryService.getLocalJobSubmission(jobSubmissionId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving local job submission interface"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving local job submission interface", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while retrieving local job submission interface. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public SSHJobSubmission getSSHJobSubmission(String jobSubmissionId) { + public SSHJobSubmission getSSHJobSubmission(String jobSubmissionId) throws AiravataSystemException { try { return registryService.getSSHJobSubmission(jobSubmissionId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving SSH job submission"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving SSH job submission", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving SSH job submission. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public CloudJobSubmission getCloudJobSubmission(String jobSubmissionId) { + public CloudJobSubmission getCloudJobSubmission(String jobSubmissionId) throws AiravataSystemException { try { return registryService.getCloudJobSubmission(jobSubmissionId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving cloud job submission"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving cloud job submission", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving cloud job submission. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public UnicoreJobSubmission getUnicoreJobSubmission(String jobSubmissionId) { + public UnicoreJobSubmission getUnicoreJobSubmission(String jobSubmissionId) throws AiravataSystemException { try { return registryService.getUnicoreJobSubmission(jobSubmissionId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving UNICORE job submission"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving UNICORE job submission", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving UNICORE job submission. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean updateSSHJobSubmissionDetails(String jobSubmissionInterfaceId, SSHJobSubmission sshJobSubmission) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + throws AiravataSystemException { try { return registryService.updateSSHJobSubmissionDetails(jobSubmissionInterfaceId, sshJobSubmission); - } catch (Throwable e) { - throw convertException(e, "Error while updating job submission interface"); + } catch (RegistryServiceException e) { + logger.error("Error while updating job submission interface", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while updating job submission interface. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean updateCloudJobSubmissionDetails( - String jobSubmissionInterfaceId, CloudJobSubmission cloudJobSubmission) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + String jobSubmissionInterfaceId, CloudJobSubmission cloudJobSubmission) throws AiravataSystemException { try { return registryService.updateCloudJobSubmissionDetails(jobSubmissionInterfaceId, cloudJobSubmission); - } catch (Throwable e) { - throw convertException(e, "Error while updating job submission interface"); + } catch (RegistryServiceException e) { + logger.error("Error while updating job submission interface", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while updating job submission interface. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean updateUnicoreJobSubmissionDetails( - String jobSubmissionInterfaceId, UnicoreJobSubmission unicoreJobSubmission) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + String jobSubmissionInterfaceId, UnicoreJobSubmission unicoreJobSubmission) throws AiravataSystemException { try { return registryService.updateUnicoreJobSubmissionDetails(jobSubmissionInterfaceId, unicoreJobSubmission); - } catch (Throwable e) { - throw convertException(e, "Error while updating job submission interface"); + } catch (RegistryServiceException e) { + logger.error("Error while updating job submission interface", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while updating job submission interface. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean deleteJobSubmissionInterface(String computeResourceId, String jobSubmissionInterfaceId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + throws AiravataSystemException { try { return registryService.deleteJobSubmissionInterface(computeResourceId, jobSubmissionInterfaceId); - } catch (Throwable e) { - throw convertException(e, "Error while deleting job submission interface"); + } catch (RegistryServiceException e) { + logger.error("Error while deleting job submission interface", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while deleting job submission interface. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public String registerResourceJobManager(ResourceJobManager resourceJobManager) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + public String registerResourceJobManager(ResourceJobManager resourceJobManager) throws AiravataSystemException { try { return registryService.registerResourceJobManager(resourceJobManager); - } catch (Throwable e) { - throw convertException(e, "Error while adding resource job manager"); + } catch (RegistryServiceException e) { + logger.error("Error while adding resource job manager", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while adding resource job manager. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean updateResourceJobManager(String resourceJobManagerId, ResourceJobManager updatedResourceJobManager) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + throws AiravataSystemException { try { return registryService.updateResourceJobManager(resourceJobManagerId, updatedResourceJobManager); - } catch (Throwable e) { - throw convertException(e, "Error while updating resource job manager"); + } catch (RegistryServiceException e) { + logger.error("Error while updating resource job manager", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while updating resource job manager. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public ResourceJobManager getResourceJobManager(String resourceJobManagerId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + public ResourceJobManager getResourceJobManager(String resourceJobManagerId) throws AiravataSystemException { try { return registryService.getResourceJobManager(resourceJobManagerId); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving resource job manager", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving resource job manager. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } catch (Throwable e) { - throw convertException(e, "Error while retrieving resource job manager"); + logger.error("Error while retrieving resource job manager", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving resource job manager. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public boolean deleteResourceJobManager(String resourceJobManagerId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + public boolean deleteResourceJobManager(String resourceJobManagerId) throws AiravataSystemException { try { return registryService.deleteResourceJobManager(resourceJobManagerId); + } catch (RegistryServiceException e) { + logger.error("Error while deleting resource job manager", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while deleting resource job manager. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } catch (Throwable e) { - throw convertException(e, "Error while deleting resource job manager"); + logger.error("Error while deleting resource job manager", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while deleting resource job manager. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public String addPasswordCredential( PasswordCredential passwordCredential) - throws CredentialStoreException, TException { + public String addPasswordCredential(PasswordCredential passwordCredential) throws CredentialStoreException { return credentialStoreService.addPasswordCredential(passwordCredential); } - public void deletePWDCredential( String tokenId, String gatewayId) - throws CredentialStoreException, TException { + public void deletePWDCredential(String tokenId, String gatewayId) throws CredentialStoreException { credentialStoreService.deletePWDCredential(tokenId, gatewayId); } - public boolean deleteSSHCredential( String tokenId, String gatewayId) - throws CredentialStoreException, TException { + public boolean deleteSSHCredential(String tokenId, String gatewayId) throws CredentialStoreException { return credentialStoreService.deleteSSHCredential(tokenId, gatewayId); } - public CredentialSummary getCredentialSummary( - String tokenId, String gatewayId) - throws CredentialStoreException, TException { + public CredentialSummary getCredentialSummary(String tokenId, String gatewayId) throws CredentialStoreException { return credentialStoreService.getCredentialSummary(tokenId, gatewayId); } public List getAllCredentialSummaries( - SummaryType type, List accessibleTokenIds, String gatewayId) - throws CredentialStoreException, TException { + SummaryType type, List accessibleTokenIds, String gatewayId) throws CredentialStoreException { return credentialStoreService.getAllCredentialSummaries(type, accessibleTokenIds, gatewayId); } public String addLocalDataMovementDetails( String resourceId, DMType dmType, int priorityOrder, LOCALDataMovement localDataMovement) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + throws AiravataSystemException { try { return registryService.addLocalDataMovementDetails(resourceId, dmType, priorityOrder, localDataMovement); - } catch (Throwable e) { - throw convertException(e, "Error while adding data movement interface to resource"); + } catch (RegistryServiceException e) { + logger.error("Error while adding data movement interface to resource", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while adding data movement interface to resource. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean updateLocalDataMovementDetails(String dataMovementInterfaceId, LOCALDataMovement localDataMovement) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + throws AiravataSystemException { try { return registryService.updateLocalDataMovementDetails(dataMovementInterfaceId, localDataMovement); - } catch (Throwable e) { - throw convertException(e, "Error while updating local data movement interface"); + } catch (RegistryServiceException e) { + logger.error("Error while updating local data movement interface", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while updating local data movement interface. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public LOCALDataMovement getLocalDataMovement(String dataMovementId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + public LOCALDataMovement getLocalDataMovement(String dataMovementId) throws AiravataSystemException { try { return registryService.getLocalDataMovement(dataMovementId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving local data movement interface"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving local data movement interface", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving local data movement interface. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public String addSCPDataMovementDetails( String resourceId, DMType dmType, int priorityOrder, SCPDataMovement scpDataMovement) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + throws AiravataSystemException { try { return registryService.addSCPDataMovementDetails(resourceId, dmType, priorityOrder, scpDataMovement); - } catch (Throwable e) { - throw convertException(e, "Error while adding SCP data movement interface"); + } catch (RegistryServiceException e) { + logger.error("Error while adding SCP data movement interface", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while adding SCP data movement interface. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean updateSCPDataMovementDetails(String dataMovementInterfaceId, SCPDataMovement scpDataMovement) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + throws AiravataSystemException { try { return registryService.updateSCPDataMovementDetails(dataMovementInterfaceId, scpDataMovement); - } catch (Throwable e) { - throw convertException(e, "Error while updating SCP data movement interface"); + } catch (RegistryServiceException e) { + logger.error("Error while updating SCP data movement interface", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while updating SCP data movement interface. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public List getUserProjects(String gatewayId, String userName, int limit, int offset) throws RegistryServiceException { + public List getUserProjects(String gatewayId, String userName, int limit, int offset) + throws RegistryServiceException { return registryService.getUserProjects(gatewayId, userName, limit, offset); } @@ -1800,12 +2434,8 @@ public List getUserProjects(String gatewayId, String userName, int limi * Get user projects with sharing registry integration */ public List getUserProjectsWithSharing( - AuthzToken authzToken, - String gatewayId, - String userName, - int limit, - int offset) - throws TException { + AuthzToken authzToken, String gatewayId, String userName, int limit, int offset) + throws AiravataSystemException { try { if (ServerSettings.isEnableSharing()) { // user projects + user accessible projects @@ -1835,13 +2465,26 @@ public List getUserProjectsWithSharing( } else { return getUserProjects(gatewayId, userName, limit, offset); } - } catch (Throwable e) { - throw convertException(e, "Error while retrieving user projects"); + } catch (ApplicationSettingsException e) { + logger.error("Error while retrieving user projects", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving user projects. More info: " + e.getMessage()); + exception.initCause(e); + throw exception; + } catch (RegistryServiceException | SharingRegistryException e) { + logger.error("Error while retrieving user projects", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving user projects. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public List getAccessibleApplicationDeployments( - String gatewayId, List accessibleAppDeploymentIds, List accessibleComputeResourceIds) throws RegistryServiceException { + String gatewayId, List accessibleAppDeploymentIds, List accessibleComputeResourceIds) + throws RegistryServiceException { return registryService.getAccessibleApplicationDeployments( gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); } @@ -1850,57 +2493,74 @@ public List getAccessibleApplicationDeployment * Get accessible application deployments with sharing registry integration */ public List getAccessibleApplicationDeploymentsWithSharing( - - AuthzToken authzToken, - String gatewayId, - ResourcePermissionType permissionType) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + AuthzToken authzToken, String gatewayId, ResourcePermissionType permissionType) + throws InvalidRequestException, AiravataSystemException, AuthorizationException { try { - String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); - List accessibleAppDeploymentIds = new ArrayList<>(); - if (ServerSettings.isEnableSharing()) { - List sharingFilters = new ArrayList<>(); - var entityTypeFilter = new SearchCriteria(); - entityTypeFilter.setSearchField(EntitySearchField.ENTITY_TYPE_ID); - entityTypeFilter.setSearchCondition(SearchCondition.EQUAL); - entityTypeFilter.setValue(gatewayId + ":" + ResourceType.APPLICATION_DEPLOYMENT.name()); - sharingFilters.add(entityTypeFilter); - var permissionTypeFilter = new SearchCriteria(); - permissionTypeFilter.setSearchField(EntitySearchField.PERMISSION_TYPE_ID); - permissionTypeFilter.setSearchCondition(SearchCondition.EQUAL); - permissionTypeFilter.setValue(gatewayId + ":" + permissionType.name()); - sharingFilters.add(permissionTypeFilter); - sharingRegistryService - .searchEntities( - authzToken.getClaimsMap().get(Constants.GATEWAY_ID), - userName + "@" + gatewayId, - sharingFilters, - 0, - -1) - .forEach(a -> accessibleAppDeploymentIds.add(a.getEntityId())); - } - var accessibleComputeResourceIds = new ArrayList(); - List groupResourceProfileList = - getGroupResourceListWithSharing( authzToken, gatewayId); - for (GroupResourceProfile groupResourceProfile : groupResourceProfileList) { - List groupComputeResourcePreferenceList = - groupResourceProfile.getComputePreferences(); - for (GroupComputeResourcePreference groupComputeResourcePreference : groupComputeResourcePreferenceList) { - accessibleComputeResourceIds.add(groupComputeResourcePreference.getComputeResourceId()); + String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); + List accessibleAppDeploymentIds = new ArrayList<>(); + if (ServerSettings.isEnableSharing()) { + List sharingFilters = new ArrayList<>(); + var entityTypeFilter = new SearchCriteria(); + entityTypeFilter.setSearchField(EntitySearchField.ENTITY_TYPE_ID); + entityTypeFilter.setSearchCondition(SearchCondition.EQUAL); + entityTypeFilter.setValue(gatewayId + ":" + ResourceType.APPLICATION_DEPLOYMENT.name()); + sharingFilters.add(entityTypeFilter); + var permissionTypeFilter = new SearchCriteria(); + permissionTypeFilter.setSearchField(EntitySearchField.PERMISSION_TYPE_ID); + permissionTypeFilter.setSearchCondition(SearchCondition.EQUAL); + permissionTypeFilter.setValue(gatewayId + ":" + permissionType.name()); + sharingFilters.add(permissionTypeFilter); + sharingRegistryService + .searchEntities( + authzToken.getClaimsMap().get(Constants.GATEWAY_ID), + userName + "@" + gatewayId, + sharingFilters, + 0, + -1) + .forEach(a -> accessibleAppDeploymentIds.add(a.getEntityId())); } - } - return getAccessibleApplicationDeployments(gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); - } catch (Throwable e) { - throw convertException(e, "Error occurred while getting accessible application deployments"); + var accessibleComputeResourceIds = new ArrayList(); + List groupResourceProfileList = + getGroupResourceListWithSharing(authzToken, gatewayId); + for (GroupResourceProfile groupResourceProfile : groupResourceProfileList) { + List groupComputeResourcePreferenceList = + groupResourceProfile.getComputePreferences(); + for (GroupComputeResourcePreference groupComputeResourcePreference : + groupComputeResourcePreferenceList) { + accessibleComputeResourceIds.add(groupComputeResourcePreference.getComputeResourceId()); + } + } + return getAccessibleApplicationDeployments( + gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); + } catch (ApplicationSettingsException e) { + logger.error("Error occurred while getting accessible application deployments", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error occurred while getting accessible application deployments. More info: " + e.getMessage()); + exception.initCause(e); + throw exception; + } catch (RegistryServiceException | SharingRegistryException e) { + logger.error("Error occurred while getting accessible application deployments", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error occurred while getting accessible application deployments. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public List getAppModuleDeployedResources(String appModuleId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + public List getAppModuleDeployedResources(String appModuleId) throws AiravataSystemException { try { return registryService.getAppModuleDeployedResources(appModuleId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving application deployment"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving application deployment", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving application deployment. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1909,22 +2569,28 @@ public List getAccessibleApplicationDeployment String gatewayId, List accessibleAppDeploymentIds, List accessibleComputeResourceIds) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException { + throws AiravataSystemException { try { return registryService.getAccessibleApplicationDeploymentsForAppModule( gatewayId, appModuleId, accessibleAppDeploymentIds, accessibleComputeResourceIds); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving accessible application deployments"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving accessible application deployments", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while retrieving accessible application deployments. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public List getApplicationDeploymentsForAppModuleAndGroupResourceProfile( AuthzToken authzToken, String appModuleId, String groupResourceProfileId) - throws AuthorizationException { + throws AuthorizationException, InvalidRequestException, AiravataSystemException { try { var userName = authzToken.getClaimsMap().get(Constants.USER_NAME); var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - + // Get list of compute resources for this Group Resource Profile if (!userHasAccessInternal(authzToken, groupResourceProfileId, ResourcePermissionType.READ)) { throw new AuthorizationException( @@ -1949,226 +2615,390 @@ public List getApplicationDeploymentsForAppMod permissionTypeFilter.setValue(gatewayId + ":" + ResourcePermissionType.READ); sharingFilters.add(permissionTypeFilter); searchEntities(gatewayId, userName + "@" + gatewayId, sharingFilters, 0, -1) - .forEach(a -> accessibleAppDeploymentIds.add(a.getEntityId())); + .forEach(a -> accessibleAppDeploymentIds.add(a.delegate().getEntityId())); return getAccessibleApplicationDeploymentsForAppModule( appModuleId, gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); - } catch (AuthorizationException e) { + } catch (AiravataSystemException e) { throw e; - } catch (Throwable e) { - throw convertException(e, "Error while retrieving application deployments"); + } catch (SharingRegistryException e) { + logger.error("Error while retrieving application deployments", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving application deployments. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public Map getAvailableAppInterfaceComputeResources(String appInterfaceId) { + public Map getAvailableAppInterfaceComputeResources(String appInterfaceId) + throws AiravataSystemException { try { return registryService.getAvailableAppInterfaceComputeResources(appInterfaceId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving available compute resources"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving available compute resources", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving available compute resources. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public SCPDataMovement getSCPDataMovement(String dataMovementId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + public SCPDataMovement getSCPDataMovement(String dataMovementId) throws AiravataSystemException { try { return registryService.getSCPDataMovement(dataMovementId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving SCP data movement interface"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving SCP data movement interface", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving SCP data movement interface. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public String addUnicoreDataMovementDetails( String resourceId, DMType dmType, int priorityOrder, UnicoreDataMovement unicoreDataMovement) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + throws AiravataSystemException { try { - return registryService.addUnicoreDataMovementDetails(resourceId, dmType, priorityOrder, unicoreDataMovement); - } catch (Throwable e) { - throw convertException(e, "Error while adding UNICORE data movement interface"); + return registryService.addUnicoreDataMovementDetails( + resourceId, dmType, priorityOrder, unicoreDataMovement); + } catch (RegistryServiceException e) { + logger.error("Error while adding UNICORE data movement interface", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while adding UNICORE data movement interface. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean updateUnicoreDataMovementDetails( - String dataMovementInterfaceId, UnicoreDataMovement unicoreDataMovement) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + String dataMovementInterfaceId, UnicoreDataMovement unicoreDataMovement) throws AiravataSystemException { try { return registryService.updateUnicoreDataMovementDetails(dataMovementInterfaceId, unicoreDataMovement); - } catch (Throwable e) { - throw convertException(e, "Error while updating unicore data movement interface"); + } catch (RegistryServiceException e) { + logger.error("Error while updating unicore data movement interface", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while updating unicore data movement interface. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public UnicoreDataMovement getUnicoreDataMovement(String dataMovementId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + public UnicoreDataMovement getUnicoreDataMovement(String dataMovementId) throws AiravataSystemException { try { return registryService.getUnicoreDataMovement(dataMovementId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving UNICORE data movement interface"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving UNICORE data movement interface", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while retrieving UNICORE data movement interface. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public String addGridFTPDataMovementDetails( String resourceId, DMType dmType, int priorityOrder, GridFTPDataMovement gridFTPDataMovement) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + throws AiravataSystemException { try { - return registryService.addGridFTPDataMovementDetails(resourceId, dmType, priorityOrder, gridFTPDataMovement); - } catch (Throwable e) { - throw convertException(e, "Error while adding GridFTP data movement interface"); + return registryService.addGridFTPDataMovementDetails( + resourceId, dmType, priorityOrder, gridFTPDataMovement); + } catch (RegistryServiceException e) { + logger.error("Error while adding GridFTP data movement interface", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while adding GridFTP data movement interface. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean updateGridFTPDataMovementDetails( - String dataMovementInterfaceId, GridFTPDataMovement gridFTPDataMovement) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + String dataMovementInterfaceId, GridFTPDataMovement gridFTPDataMovement) throws AiravataSystemException { try { return registryService.updateGridFTPDataMovementDetails(dataMovementInterfaceId, gridFTPDataMovement); - } catch (Throwable e) { - throw convertException(e, "Error while updating GridFTP data movement interface"); + } catch (RegistryServiceException e) { + logger.error("Error while updating GridFTP data movement interface", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while updating GridFTP data movement interface. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public GridFTPDataMovement getGridFTPDataMovement(String dataMovementId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + public GridFTPDataMovement getGridFTPDataMovement(String dataMovementId) throws AiravataSystemException { try { return registryService.getGridFTPDataMovement(dataMovementId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving GridFTP data movement interface"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving GridFTP data movement interface", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while retrieving GridFTP data movement interface. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean deleteDataMovementInterface(String resourceId, String dataMovementInterfaceId, DMType dmType) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + throws AiravataSystemException { try { return registryService.deleteDataMovementInterface(resourceId, dataMovementInterfaceId, dmType); - } catch (Throwable e) { - throw convertException(e, "Error while deleting data movement interface"); + } catch (RegistryServiceException e) { + logger.error("Error while deleting data movement interface", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while deleting data movement interface. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public boolean deleteBatchQueue(String computeResourceId, String queueName) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + public boolean deleteBatchQueue(String computeResourceId, String queueName) throws AiravataSystemException { try { return registryService.deleteBatchQueue(computeResourceId, queueName); - } catch (Throwable e) { - throw convertException(e, "Error while deleting batch queue"); + } catch (RegistryServiceException e) { + logger.error("Error while deleting batch queue", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while deleting batch queue. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean addGatewayComputeResourcePreference( String gatewayID, String computeResourceId, ComputeResourcePreference computeResourcePreference) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + throws AiravataSystemException { try { return registryService.addGatewayComputeResourcePreference( gatewayID, computeResourceId, computeResourcePreference); - } catch (Throwable e) { - throw convertException(e, "Error while registering gateway resource profile preference"); + } catch (RegistryServiceException e) { + logger.error("Error while registering gateway resource profile preference", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while registering gateway resource profile preference. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean addGatewayStoragePreference( String gatewayID, String storageResourceId, StoragePreference dataStoragePreference) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + throws AiravataSystemException { try { return registryService.addGatewayStoragePreference(gatewayID, storageResourceId, dataStoragePreference); - } catch (Throwable e) { - throw convertException(e, "Error while registering gateway storage preference"); + } catch (RegistryServiceException e) { + logger.error("Error while registering gateway storage preference", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while registering gateway storage preference. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public ComputeResourcePreference getGatewayComputeResourcePreference(String gatewayID, String computeResourceId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + public ComputeResourcePreference getGatewayComputeResourcePreference(String gatewayID, String computeResourceId) + throws AiravataSystemException { try { return registryService.getGatewayComputeResourcePreference(gatewayID, computeResourceId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving gateway compute resource preference"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving gateway compute resource preference", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while retrieving gateway compute resource preference. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public StoragePreference getGatewayStoragePreference(String gatewayID, String storageId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + public StoragePreference getGatewayStoragePreference(String gatewayID, String storageId) + throws AiravataSystemException { try { return registryService.getGatewayStoragePreference(gatewayID, storageId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving gateway storage preference"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving gateway storage preference", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving gateway storage preference. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public List getAllGatewayComputeResourcePreferences(String gatewayID) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + public List getAllGatewayComputeResourcePreferences(String gatewayID) + throws AiravataSystemException { try { return registryService.getAllGatewayComputeResourcePreferences(gatewayID); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving all gateway compute resource preferences", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while retrieving all gateway compute resource preferences. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } catch (Throwable e) { - throw convertException(e, "Error while retrieving all gateway compute resource preferences"); + logger.error("Error while retrieving all gateway compute resource preferences", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while retrieving all gateway compute resource preferences. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public List getAllGatewayStoragePreferences(String gatewayID) { + public List getAllGatewayStoragePreferences(String gatewayID) throws AiravataSystemException { try { return registryService.getAllGatewayStoragePreferences(gatewayID); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving all gateway storage preferences", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while retrieving all gateway storage preferences. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } catch (Throwable e) { - throw convertException(e, "Error while retrieving all gateway storage preferences"); + logger.error("Error while retrieving all gateway storage preferences", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while retrieving all gateway storage preferences. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public List getAllGatewayResourceProfiles() { + public List getAllGatewayResourceProfiles() throws AiravataSystemException { try { return registryService.getAllGatewayResourceProfiles(); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving all gateway resource profiles", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving all gateway resource profiles. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } catch (Throwable e) { - throw convertException(e, "Error while retrieving all gateway resource profiles"); + logger.error("Error while retrieving all gateway resource profiles", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving all gateway resource profiles. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean updateGatewayComputeResourcePreference( String gatewayID, String computeResourceId, ComputeResourcePreference computeResourcePreference) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + throws AiravataSystemException { try { return registryService.updateGatewayComputeResourcePreference( gatewayID, computeResourceId, computeResourcePreference); + } catch (RegistryServiceException e) { + logger.error("Error while updating gateway compute resource preference", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while updating gateway compute resource preference. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } catch (Throwable e) { - throw convertException(e, "Error while updating gateway compute resource preference"); + logger.error("Error while updating gateway compute resource preference", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while updating gateway compute resource preference. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean updateGatewayStoragePreference( String gatewayID, String storageId, StoragePreference dataStoragePreference) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + throws AiravataSystemException { try { return registryService.updateGatewayStoragePreference(gatewayID, storageId, dataStoragePreference); + } catch (RegistryServiceException e) { + logger.error("Error while updating gateway data storage preference", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while updating gateway data storage preference. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } catch (Throwable e) { - throw convertException(e, "Error while updating gateway data storage preference"); + logger.error("Error while updating gateway data storage preference", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while updating gateway data storage preference. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean deleteGatewayComputeResourcePreference(String gatewayID, String computeResourceId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + throws AiravataSystemException { try { return registryService.deleteGatewayComputeResourcePreference(gatewayID, computeResourceId); } catch (Throwable e) { logger.error(gatewayID, "Error while deleting gateway compute resource preference...", e); - throw convertException(e, "Error while deleting gateway compute resource preference"); + logger.error("Error while deleting gateway compute resource preference", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while deleting gateway compute resource preference. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public boolean deleteGatewayStoragePreference(String gatewayID, String storageId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + public boolean deleteGatewayStoragePreference(String gatewayID, String storageId) throws AiravataSystemException { try { return registryService.deleteGatewayStoragePreference(gatewayID, storageId); - } catch (Throwable e) { - throw convertException(e, "Error while deleting gateway data storage preference"); + } catch (RegistryServiceException e) { + logger.error("Error while deleting gateway data storage preference", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while deleting gateway data storage preference. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public String registerUserResourceProfile(UserResourceProfile userResourceProfile) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + public String registerUserResourceProfile(UserResourceProfile userResourceProfile) throws AiravataSystemException { try { return registryService.registerUserResourceProfile(userResourceProfile); - } catch (Throwable e) { - throw convertException(e, "Error while registering user resource profile"); + } catch (RegistryServiceException e) { + logger.error("Error while registering user resource profile", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while registering user resource profile. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public boolean isUserResourceProfileExists(String userId, String gatewayId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + public boolean isUserResourceProfileExists(String userId, String gatewayId) throws AiravataSystemException { try { return registryService.isUserResourceProfileExists(userId, gatewayId); - } catch (Throwable e) { - throw convertException(e, "Error while checking existence of user resource profile"); + } catch (RegistryServiceException e) { + logger.error("Error while checking existence of user resource profile", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while checking existence of user resource profile. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2177,70 +3007,106 @@ public boolean addUserComputeResourcePreference( String gatewayID, String computeResourceId, UserComputeResourcePreference userComputeResourcePreference) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + throws AiravataSystemException { try { return registryService.addUserComputeResourcePreference( userId, gatewayID, computeResourceId, userComputeResourcePreference); } catch (Throwable e) { logger.error(userId, "Error while registering user resource profile preference...", e); - throw convertException(e, "Error while registering user resource profile preference"); + logger.error("Error while registering user resource profile preference", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while registering user resource profile preference. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean addUserStoragePreference( String userId, String gatewayID, String userStorageResourceId, UserStoragePreference dataStoragePreference) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + throws AiravataSystemException { try { return registryService.addUserStoragePreference( userId, gatewayID, userStorageResourceId, dataStoragePreference); - } catch (Throwable e) { - throw convertException(e, "Error while registering user storage preference"); + } catch (RegistryServiceException e) { + logger.error("Error while registering user storage preference", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while registering user storage preference. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public UserComputeResourcePreference getUserComputeResourcePreference( - String userId, String gatewayID, String userComputeResourceId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + String userId, String gatewayID, String userComputeResourceId) throws AiravataSystemException { try { return registryService.getUserComputeResourcePreference(userId, gatewayID, userComputeResourceId); - } catch (Throwable e) { - throw convertException(e, "Error while reading user compute resource preference"); + } catch (RegistryServiceException e) { + logger.error("Error while reading user compute resource preference", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while reading user compute resource preference. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public UserStoragePreference getUserStoragePreference(String userId, String gatewayID, String userStorageId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + throws AiravataSystemException { try { return registryService.getUserStoragePreference(userId, gatewayID, userStorageId); - } catch (Throwable e) { - throw convertException(e, "Error while reading user data storage preference"); + } catch (RegistryServiceException e) { + logger.error("Error while reading user data storage preference", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while reading user data storage preference. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public List getAllUserComputeResourcePreferences(String userId, String gatewayID) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + throws AiravataSystemException { try { return registryService.getAllUserComputeResourcePreferences(userId, gatewayID); - } catch (Throwable e) { - throw convertException(e, "Error while reading User compute resource preferences"); + } catch (RegistryServiceException e) { + logger.error("Error while reading User compute resource preferences", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while reading User compute resource preferences. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public List getAllUserStoragePreferences(String userId, String gatewayID) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + throws AiravataSystemException { try { return registryService.getAllUserStoragePreferences(userId, gatewayID); - } catch (Throwable e) { - throw convertException(e, "Error while reading User data storage preferences"); + } catch (RegistryServiceException e) { + logger.error("Error while reading User data storage preferences", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while reading User data storage preferences. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public List getAllUserResourceProfiles() - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + public List getAllUserResourceProfiles() throws AiravataSystemException { try { return registryService.getAllUserResourceProfiles(); - } catch (Throwable e) { - throw convertException(e, "Error while reading retrieving all user resource profiles"); + } catch (RegistryServiceException e) { + logger.error("Error while reading retrieving all user resource profiles", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while reading retrieving all user resource profiles. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2249,230 +3115,368 @@ public boolean updateUserComputeResourcePreference( String gatewayID, String computeResourceId, UserComputeResourcePreference userComputeResourcePreference) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + throws AiravataSystemException { try { return registryService.updateUserComputeResourcePreference( userId, gatewayID, computeResourceId, userComputeResourcePreference); - } catch (Throwable e) { - throw convertException(e, "Error while updating user compute resource preference"); + } catch (RegistryServiceException e) { + logger.error("Error while updating user compute resource preference", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while updating user compute resource preference. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean updateUserStoragePreference( String userId, String gatewayID, String userStorageId, UserStoragePreference userStoragePreference) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + throws AiravataSystemException { try { return registryService.updateUserStoragePreference(userId, gatewayID, userStorageId, userStoragePreference); - } catch (Throwable e) { - throw convertException(e, "Error while updating user data storage preference"); + } catch (RegistryServiceException e) { + logger.error("Error while updating user data storage preference", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while updating user data storage preference. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean deleteUserComputeResourcePreference(String userId, String gatewayID, String userComputeResourceId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + throws AiravataSystemException { try { return registryService.deleteUserComputeResourcePreference(userId, gatewayID, userComputeResourceId); } catch (Throwable e) { logger.error(userId, "Error while deleting user compute resource preference...", e); - throw convertException(e, "Error while deleting user compute resource preference"); + logger.error("Error while deleting user compute resource preference", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while deleting user compute resource preference. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean deleteUserStoragePreference(String userId, String gatewayID, String userStorageId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + throws AiravataSystemException { try { return registryService.deleteUserStoragePreference(userId, gatewayID, userStorageId); - } catch (Throwable e) { - throw convertException(e, "Error while deleting user data storage preference"); + } catch (RegistryServiceException e) { + logger.error("Error while deleting user data storage preference", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while deleting user data storage preference. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public List getLatestQueueStatuses() { + public List getLatestQueueStatuses() throws AiravataSystemException { try { return registryService.getLatestQueueStatuses(); } catch (Throwable e) { var msg = "Error in retrieving queue statuses"; logger.error(msg, e); - throw convertException(e, msg); + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + ". More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public String createGroupResourceProfile(GroupResourceProfile groupResourceProfile) { + public String createGroupResourceProfile(GroupResourceProfile groupResourceProfile) throws AiravataSystemException { try { return registryService.createGroupResourceProfile(groupResourceProfile); - } catch (Throwable e) { - throw convertException(e, "Error while creating group resource profile"); + } catch (RegistryServiceException e) { + logger.error("Error while creating group resource profile", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while creating group resource profile. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public boolean removeGroupResourceProfile(String groupResourceProfileId) { + public boolean removeGroupResourceProfile(String groupResourceProfileId) throws AiravataSystemException { try { return registryService.removeGroupResourceProfile(groupResourceProfileId); - } catch (Throwable e) { - throw convertException(e, "Error while removing group resource profile"); + } catch (RegistryServiceException e) { + logger.error("Error while removing group resource profile", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while removing group resource profile. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public boolean removeGroupComputePrefs(String computeResourceId, String groupResourceProfileId) { + public boolean removeGroupComputePrefs(String computeResourceId, String groupResourceProfileId) + throws AiravataSystemException { try { return registryService.removeGroupComputePrefs(computeResourceId, groupResourceProfileId); - } catch (Throwable e) { - throw convertException(e, "Error while removing group compute preferences"); + } catch (RegistryServiceException e) { + logger.error("Error while removing group compute preferences", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while removing group compute preferences. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public GroupComputeResourcePreference getGroupComputeResourcePreference( - String computeResourceId, String groupResourceProfileId) { + String computeResourceId, String groupResourceProfileId) throws AiravataSystemException { try { return registryService.getGroupComputeResourcePreference(computeResourceId, groupResourceProfileId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving group compute resource preference"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving group compute resource preference", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while retrieving group compute resource preference. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public ComputeResourcePolicy getGroupComputeResourcePolicy(String resourcePolicyId) { + public ComputeResourcePolicy getGroupComputeResourcePolicy(String resourcePolicyId) throws AiravataSystemException { try { return registryService.getGroupComputeResourcePolicy(resourcePolicyId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving group compute resource policy"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving group compute resource policy", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving group compute resource policy. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public boolean removeGroupComputeResourcePolicy(String resourcePolicyId) { + public boolean removeGroupComputeResourcePolicy(String resourcePolicyId) throws AiravataSystemException { try { return registryService.removeGroupComputeResourcePolicy(resourcePolicyId); - } catch (Throwable e) { - throw convertException(e, "Error while removing group compute resource policy"); + } catch (RegistryServiceException e) { + logger.error("Error while removing group compute resource policy", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while removing group compute resource policy. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public BatchQueueResourcePolicy getBatchQueueResourcePolicy(String resourcePolicyId) { + public BatchQueueResourcePolicy getBatchQueueResourcePolicy(String resourcePolicyId) + throws AiravataSystemException { try { return registryService.getBatchQueueResourcePolicy(resourcePolicyId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving batch queue resource policy"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving batch queue resource policy", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving batch queue resource policy. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public boolean removeGroupBatchQueueResourcePolicy(String resourcePolicyId) { + public boolean removeGroupBatchQueueResourcePolicy(String resourcePolicyId) throws AiravataSystemException { try { return registryService.removeGroupBatchQueueResourcePolicy(resourcePolicyId); - } catch (Throwable e) { - throw convertException(e, "Error while removing group batch queue resource policy"); + } catch (RegistryServiceException e) { + logger.error("Error while removing group batch queue resource policy", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while removing group batch queue resource policy. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public List getGroupComputeResourcePrefList(String groupResourceProfileId) { + public List getGroupComputeResourcePrefList(String groupResourceProfileId) + throws AiravataSystemException { try { return registryService.getGroupComputeResourcePrefList(groupResourceProfileId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving group compute resource preference list"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving group compute resource preference list", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while retrieving group compute resource preference list. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public List getGroupBatchQueueResourcePolicyList(String groupResourceProfileId) { + public List getGroupBatchQueueResourcePolicyList(String groupResourceProfileId) + throws AiravataSystemException { try { return registryService.getGroupBatchQueueResourcePolicyList(groupResourceProfileId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving group batch queue resource policy list"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving group batch queue resource policy list", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while retrieving group batch queue resource policy list. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public List getGroupComputeResourcePolicyList(String groupResourceProfileId) { + public List getGroupComputeResourcePolicyList(String groupResourceProfileId) + throws AiravataSystemException { try { return registryService.getGroupComputeResourcePolicyList(groupResourceProfileId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving group compute resource policy list"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving group compute resource policy list", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while retrieving group compute resource policy list. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public Parser getParser(String parserId, String gatewayId) { + public Parser getParser(String parserId, String gatewayId) throws AiravataSystemException { try { return registryService.getParser(parserId, gatewayId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving parser"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving parser", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving parser. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public String saveParser(Parser parser) { + public String saveParser(Parser parser) throws AiravataSystemException { try { return registryService.saveParser(parser); - } catch (Throwable e) { - throw convertException(e, "Error while saving parser"); + } catch (RegistryServiceException e) { + logger.error("Error while saving parser", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while saving parser. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public List listAllParsers(String gatewayId) { + public List listAllParsers(String gatewayId) throws AiravataSystemException { try { return registryService.listAllParsers(gatewayId); - } catch (Throwable e) { - throw convertException(e, "Error while listing all parsers"); + } catch (RegistryServiceException e) { + logger.error("Error while listing all parsers", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while listing all parsers. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public void removeParser(String parserId, String gatewayId) { + public void removeParser(String parserId, String gatewayId) throws AiravataSystemException { try { registryService.removeParser(parserId, gatewayId); - } catch (Throwable e) { - throw convertException(e, "Error while removing parser"); + } catch (RegistryServiceException e) { + logger.error("Error while removing parser", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while removing parser. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public ParsingTemplate getParsingTemplate(String templateId, String gatewayId) { + public ParsingTemplate getParsingTemplate(String templateId, String gatewayId) throws AiravataSystemException { try { return registryService.getParsingTemplate(templateId, gatewayId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving parsing template"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving parsing template", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving parsing template. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public List getParsingTemplatesForExperiment(String experimentId, String gatewayId) { + public List getParsingTemplatesForExperiment(String experimentId, String gatewayId) + throws AiravataSystemException { try { return registryService.getParsingTemplatesForExperiment(experimentId, gatewayId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving parsing templates for experiment"); + } catch (RegistryServiceException e) { + logger.error("Error while retrieving parsing templates for experiment", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error while retrieving parsing templates for experiment. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public String saveParsingTemplate(ParsingTemplate parsingTemplate) { + public String saveParsingTemplate(ParsingTemplate parsingTemplate) throws AiravataSystemException { try { return registryService.saveParsingTemplate(parsingTemplate); - } catch (Throwable e) { - throw convertException(e, "Error while saving parsing template"); + } catch (RegistryServiceException e) { + logger.error("Error while saving parsing template", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while saving parsing template. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public void removeParsingTemplate(String templateId, String gatewayId) { + public void removeParsingTemplate(String templateId, String gatewayId) throws AiravataSystemException { try { registryService.removeParsingTemplate(templateId, gatewayId); - } catch (Throwable e) { - throw convertException(e, "Error while removing parsing template"); + } catch (RegistryServiceException e) { + logger.error("Error while removing parsing template", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while removing parsing template. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public List listAllParsingTemplates(String gatewayId) { + public List listAllParsingTemplates(String gatewayId) throws AiravataSystemException { try { return registryService.listAllParsingTemplates(gatewayId); - } catch (Throwable e) { - throw convertException(e, "Error while listing all parsing templates"); + } catch (RegistryServiceException e) { + logger.error("Error while listing all parsing templates", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while listing all parsing templates. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } // Helper methods for sharing registry and authorization - public GatewayGroups retrieveGatewayGroups(String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + public GatewayGroups retrieveGatewayGroups(String gatewayId) throws AiravataSystemException { try { if (isGatewayGroupsExists(gatewayId)) { return getGatewayGroups(gatewayId); } else { return GatewayGroupsInitializer.initializeGatewayGroups(gatewayId); } - } catch (Throwable e) { - throw convertException(e, "Error retrieving gateway groups"); + } catch (AiravataSystemException e) { + throw e; } } - public void createManageSharingPermissionTypeIfMissing( String domainId) - throws TException { + public void createManageSharingPermissionTypeIfMissing(String domainId) throws AiravataSystemException { // AIRAVATA-3297 Some gateways were created without the MANAGE_SHARING permission, so add it if missing var permissionTypeId = domainId + ":MANAGE_SHARING"; try { @@ -2486,15 +3490,20 @@ public void createManageSharingPermissionTypeIfMissing( String domainId) logger.info("Created MANAGE_SHARING permission type for domain " + domainId); } } catch (Exception e) { - throw new TException("Error creating MANAGE_SHARING permission type", e); + var exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error creating MANAGE_SHARING permission type. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public void shareEntityWithAdminGatewayGroups( Entity entity) - throws TException { + public void shareEntityWithAdminGatewayGroups(Entity entity) + throws AiravataSystemException, InvalidRequestException, AuthorizationException, + ApplicationSettingsException, SharingRegistryException { final String domainId = entity.getDomainId(); GatewayGroups gatewayGroups = retrieveGatewayGroups(domainId); - createManageSharingPermissionTypeIfMissing( domainId); + createManageSharingPermissionTypeIfMissing(domainId); sharingRegistryService.shareEntityWithGroups( domainId, entity.getEntityId(), @@ -2516,10 +3525,7 @@ public void shareEntityWithAdminGatewayGroups( Entity entity) } public boolean userHasAccessInternal( - - AuthzToken authzToken, - String entityId, - ResourcePermissionType permissionType) { + AuthzToken authzToken, String entityId, ResourcePermissionType permissionType) { final String domainId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); final String userId = authzToken.getClaimsMap().get(Constants.USER_NAME) + "@" + domainId; try { @@ -2548,11 +3554,8 @@ public boolean userHasAccessInternal( } // Credential management methods - public String generateAndRegisterSSHKeys( - String gatewayId, - String userName, - String description) - throws InvalidRequestException, AiravataClientException, AiravataSystemException { + public String generateAndRegisterSSHKeys(String gatewayId, String userName, String description) + throws InvalidRequestException, AiravataSystemException { try { var sshCredential = new SSHCredential(); sshCredential.setUsername(userName); @@ -2561,7 +3564,7 @@ public String generateAndRegisterSSHKeys( var key = credentialStoreService.addSSHCredential(sshCredential); try { - var entity = new Entity(); + var entity = new Entity(); entity.setEntityId(key); entity.setDomainId(gatewayId); entity.setEntityTypeId(gatewayId + ":" + ResourceType.CREDENTIAL_TOKEN); @@ -2571,27 +3574,33 @@ public String generateAndRegisterSSHKeys( sharingRegistryService.createEntity(entity); } catch (Exception ex) { logger.error(ex.getMessage(), ex); - logger.error( - "Rolling back ssh key creation for user " + userName + " and description [" + description + "]"); + logger.error("Rolling back ssh key creation for user " + userName + " and description [" + description + + "]"); credentialStoreService.deleteSSHCredential(key, gatewayId); - throw convertException(ex, "Failed to create sharing registry record"); + logger.error("Failed to create sharing registry record", ex); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Failed to create sharing registry record. More info : " + ex.getMessage()); + exception.initCause(ex); + throw exception; } logger.debug("Airavata generated SSH keys for gateway : " + gatewayId + " and for user : " + userName); return key; - } catch (Throwable e) { - throw convertException(e, "Error occurred while registering SSH Credential"); + } catch (AiravataSystemException e) { + throw e; + } catch (CredentialStoreException e) { + logger.error("Error occurred while registering SSH Credential", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error occurred while registering SSH Credential. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public String registerPwdCredential( - - - String gatewayId, - String userName, - String loginUserName, - String password, - String description) - throws InvalidRequestException, AiravataClientException, AiravataSystemException { + String gatewayId, String userName, String loginUserName, String password, String description) + throws InvalidRequestException, AiravataSystemException { try { var pwdCredential = new PasswordCredential(); pwdCredential.setPortalUserName(userName); @@ -2599,9 +3608,9 @@ public String registerPwdCredential( pwdCredential.setPassword(password); pwdCredential.setDescription(description); pwdCredential.setGatewayId(gatewayId); - var key = addPasswordCredential( pwdCredential); + var key = addPasswordCredential(pwdCredential); try { - var entity = new Entity(); + var entity = new Entity(); entity.setEntityId(key); entity.setDomainId(gatewayId); entity.setEntityTypeId(gatewayId + ":" + ResourceType.CREDENTIAL_TOKEN); @@ -2611,50 +3620,59 @@ public String registerPwdCredential( sharingRegistryService.createEntity(entity); } catch (Exception ex) { logger.error(ex.getMessage(), ex); - logger.error("Rolling back password registration for user " + userName + " and description [" + description - + "]"); + logger.error("Rolling back password registration for user " + userName + " and description [" + + description + "]"); try { - deletePWDCredential( key, gatewayId); + deletePWDCredential(key, gatewayId); } catch (Exception rollbackEx) { logger.error("Failed to rollback password credential deletion", rollbackEx); } - throw convertException(ex, "Failed to create sharing registry record"); + logger.error("Failed to create sharing registry record", ex); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Failed to create sharing registry record. More info : " + ex.getMessage()); + exception.initCause(ex); + throw exception; } - logger.debug( - "Airavata generated PWD credential for gateway : " + gatewayId + " and for user : " + loginUserName); + logger.debug("Airavata generated PWD credential for gateway : " + gatewayId + " and for user : " + + loginUserName); return key; - } catch (Throwable e) { - throw convertException(e, "Error occurred while registering password credential"); + } catch (AiravataSystemException e) { + throw e; + } catch (CredentialStoreException e) { + logger.error("Error occurred while registering password credential", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error occurred while registering password credential. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public CredentialSummary getCredentialSummaryWithAuth( - - - AuthzToken authzToken, - String tokenId, - String gatewayId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + public CredentialSummary getCredentialSummaryWithAuth(AuthzToken authzToken, String tokenId, String gatewayId) + throws AiravataSystemException, AuthorizationException { try { - if (!userHasAccessInternal( authzToken, tokenId, ResourcePermissionType.READ)) { + if (!userHasAccessInternal(authzToken, tokenId, ResourcePermissionType.READ)) { throw new AuthorizationException("User does not have permission to access this resource"); } - var credentialSummary = getCredentialSummary( tokenId, gatewayId); + var credentialSummary = getCredentialSummary(tokenId, gatewayId); logger.debug("Airavata retrived the credential summary for token " + tokenId + "GatewayId: " + gatewayId); return credentialSummary; - } catch (Throwable e) { - throw convertException(e, "Error occurred while getting credential summary"); + } catch (AuthorizationException e) { + throw e; + } catch (CredentialStoreException e) { + logger.error("Error occurred while getting credential summary", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error occurred while getting credential summary. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public List getAllCredentialSummariesWithAuth( - - - AuthzToken authzToken, - SummaryType type, - String gatewayId, - String userName) - throws InvalidRequestException, AiravataClientException, AiravataSystemException { + AuthzToken authzToken, SummaryType type, String gatewayId, String userName) + throws AiravataSystemException, InvalidRequestException { try { List filters = new ArrayList<>(); SearchCriteria searchCriteria = new SearchCriteria(); @@ -2663,67 +3681,78 @@ public List getAllCredentialSummariesWithAuth( searchCriteria.setValue(gatewayId + ":" + ResourceType.CREDENTIAL_TOKEN.name()); filters.add(searchCriteria); List accessibleTokenIds = - sharingRegistryService.searchEntities(gatewayId, userName + "@" + gatewayId, filters, 0, -1).stream() + sharingRegistryService + .searchEntities(gatewayId, userName + "@" + gatewayId, filters, 0, -1) + .stream() .map(p -> p.getEntityId()) .collect(Collectors.toList()); List credentialSummaries = - getAllCredentialSummaries( type, accessibleTokenIds, gatewayId); + getAllCredentialSummaries(type, accessibleTokenIds, gatewayId); logger.debug( "Airavata successfully retrived credential summaries of type " + type + " GatewayId: " + gatewayId); return credentialSummaries; - } catch (Throwable e) { - throw convertException(e, "Error occurred while getting all credential summaries"); + } catch (CredentialStoreException | SharingRegistryException e) { + logger.error("Error occurred while getting all credential summaries", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error occurred while getting all credential summaries. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public boolean deleteSSHPubKey( - - - AuthzToken authzToken, - String airavataCredStoreToken, - String gatewayId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + public boolean deleteSSHPubKey(AuthzToken authzToken, String airavataCredStoreToken, String gatewayId) + throws AiravataSystemException, AuthorizationException { try { - if (!userHasAccessInternal( authzToken, airavataCredStoreToken, ResourcePermissionType.WRITE)) { + if (!userHasAccessInternal(authzToken, airavataCredStoreToken, ResourcePermissionType.WRITE)) { throw new AuthorizationException("User does not have permission to delete this resource."); } logger.debug("Airavata deleted SSH pub key for gateway Id : " + gatewayId + " and with token id : " + airavataCredStoreToken); - return deleteSSHCredential( airavataCredStoreToken, gatewayId); - } catch (Throwable e) { - throw convertException(e, "Error occurred while deleting SSH pub key"); + return deleteSSHCredential(airavataCredStoreToken, gatewayId); + } catch (AuthorizationException e) { + throw e; + } catch (CredentialStoreException e) { + logger.error("Error occurred while deleting SSH pub key", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error occurred while deleting SSH pub key. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public boolean deletePWDCredentialWithAuth( - - - AuthzToken authzToken, - String airavataCredStoreToken, - String gatewayId) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + public boolean deletePWDCredentialWithAuth(AuthzToken authzToken, String airavataCredStoreToken, String gatewayId) + throws AiravataSystemException, AuthorizationException { try { - if (!userHasAccessInternal( authzToken, airavataCredStoreToken, ResourcePermissionType.WRITE)) { + if (!userHasAccessInternal(authzToken, airavataCredStoreToken, ResourcePermissionType.WRITE)) { throw new AuthorizationException("User does not have permission to delete this resource."); } logger.debug("Airavata deleted PWD credential for gateway Id : " + gatewayId + " and with token id : " + airavataCredStoreToken); - deletePWDCredential( airavataCredStoreToken, gatewayId); + deletePWDCredential(airavataCredStoreToken, gatewayId); return true; - } catch (Throwable e) { - throw convertException(e, "Error occurred while deleting PWD credential"); + } catch (AuthorizationException e) { + throw e; + } catch (CredentialStoreException e) { + logger.error("Error occurred while deleting PWD credential", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error occurred while deleting PWD credential. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } // Project management methods with sharing registry integration - public String createProjectWithSharing( - String gatewayId, Project project) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + public String createProjectWithSharing(String gatewayId, Project project) throws AiravataSystemException { try { var projectId = createProject(gatewayId, project); // TODO: verify that gatewayId and project.gatewayId match authzToken if (ServerSettings.isEnableSharing()) { try { - var entity = new Entity(); + var entity = new Entity(); entity.setEntityId(projectId); final String domainId = project.getGatewayId(); entity.setDomainId(domainId); @@ -2735,31 +3764,48 @@ public String createProjectWithSharing( } catch (Exception ex) { logger.error(ex.getMessage(), ex); logger.error("Rolling back project creation Proj ID : " + projectId); - deleteProject(projectId); - throw convertException(ex, "Failed to create entry for project in Sharing Registry"); + try { + deleteProject(projectId); + } catch (ProjectNotFoundException e) { + // Ignore - project may not exist if creation failed + } + logger.error("Failed to create entry for project in Sharing Registry", ex); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Failed to create entry for project in Sharing Registry. More info : " + ex.getMessage()); + exception.initCause(ex); + throw exception; } } logger.debug("Airavata created project with project Id : " + projectId + " for gateway Id : " + gatewayId); return projectId; - } catch (Throwable e) { - throw convertException(e, "Error occurred while creating project"); + } catch (AiravataSystemException e) { + throw e; + } catch (ApplicationSettingsException e) { + logger.error("Error occurred while creating project", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error occurred while creating project. More info: " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public void updateProjectWithAuth( - - AuthzToken authzToken, - String projectId, - Project updatedProject) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, ProjectNotFoundException, AuthorizationException { + public void updateProjectWithAuth(AuthzToken authzToken, String projectId, Project updatedProject) + throws InvalidRequestException, AiravataSystemException, ProjectNotFoundException, AuthorizationException { try { var existingProject = getProject(projectId); if (ServerSettings.isEnableSharing() - && !authzToken.getClaimsMap().get(Constants.USER_NAME).equals(existingProject.getOwner()) + && !authzToken + .getClaimsMap() + .get(Constants.USER_NAME) + .equals(existingProject.getOwner()) || !authzToken.getClaimsMap().get(Constants.GATEWAY_ID).equals(existingProject.getGatewayId())) { var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!sharingRegistryService.userHasAccess(gatewayId, userId + "@" + gatewayId, projectId, gatewayId + ":WRITE")) { + if (!sharingRegistryService.userHasAccess( + gatewayId, userId + "@" + gatewayId, projectId, gatewayId + ":WRITE")) { throw new AuthorizationException("User does not have permission to access this resource"); } } @@ -2771,34 +3817,69 @@ public void updateProjectWithAuth( } updateProject(projectId, updatedProject); logger.debug("Airavata updated project with project Id : " + projectId); - } catch (Throwable e) { - throw convertException(e, "Error occurred while updating project"); + } catch (ProjectNotFoundException + | AuthorizationException + | InvalidRequestException + | AiravataSystemException e) { + throw e; + } catch (ApplicationSettingsException e) { + logger.error("Error occurred while updating project", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error occurred while updating project. More info: " + e.getMessage()); + exception.initCause(e); + throw exception; + } catch (SharingRegistryException e) { + logger.error("Error occurred while updating project", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error occurred while updating project. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public boolean deleteProjectWithAuth( - AuthzToken authzToken, String projectId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, ProjectNotFoundException, AuthorizationException { + public boolean deleteProjectWithAuth(AuthzToken authzToken, String projectId) + throws AiravataSystemException, ProjectNotFoundException, AuthorizationException { try { var existingProject = getProject(projectId); if (ServerSettings.isEnableSharing() - && !authzToken.getClaimsMap().get(Constants.USER_NAME).equals(existingProject.getOwner()) + && !authzToken + .getClaimsMap() + .get(Constants.USER_NAME) + .equals(existingProject.getOwner()) || !authzToken.getClaimsMap().get(Constants.GATEWAY_ID).equals(existingProject.getGatewayId())) { var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!sharingRegistryService.userHasAccess(gatewayId, userId + "@" + gatewayId, projectId, gatewayId + ":WRITE")) { + if (!sharingRegistryService.userHasAccess( + gatewayId, userId + "@" + gatewayId, projectId, gatewayId + ":WRITE")) { throw new AuthorizationException("User does not have permission to access this resource"); } } boolean ret = deleteProject(projectId); logger.debug("Airavata deleted project with project Id : " + projectId); return ret; - } catch (Throwable e) { - throw convertException(e, "Error occurred while deleting project"); + } catch (ProjectNotFoundException | AuthorizationException | AiravataSystemException e) { + throw e; + } catch (ApplicationSettingsException e) { + logger.error("Error occurred while deleting project", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error occurred while deleting project. More info: " + e.getMessage()); + exception.initCause(e); + throw exception; + } catch (SharingRegistryException e) { + logger.error("Error occurred while deleting project", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error occurred while deleting project. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public Project getProjectWithAuth( - AuthzToken authzToken, String projectId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, ProjectNotFoundException, AuthorizationException { + public Project getProjectWithAuth(AuthzToken authzToken, String projectId) + throws AiravataSystemException, ProjectNotFoundException, AuthorizationException { try { var project = getProject(projectId); if (authzToken.getClaimsMap().get(Constants.USER_NAME).equals(project.getOwner()) @@ -2807,67 +3888,92 @@ public Project getProjectWithAuth( } else if (ServerSettings.isEnableSharing()) { var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!sharingRegistryService.userHasAccess(gatewayId, userId + "@" + gatewayId, projectId, gatewayId + ":READ")) { + if (!sharingRegistryService.userHasAccess( + gatewayId, userId + "@" + gatewayId, projectId, gatewayId + ":READ")) { throw new AuthorizationException("User does not have permission to access this resource"); } return project; } else { return null; } - } catch (Throwable e) { - throw convertException(e, "Error occurred while getting project"); + } catch (ProjectNotFoundException | AuthorizationException | AiravataSystemException e) { + throw e; + } catch (ApplicationSettingsException e) { + logger.error("Error occurred while getting project", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error occurred while getting project. More info: " + e.getMessage()); + exception.initCause(e); + throw exception; + } catch (SharingRegistryException e) { + logger.error("Error occurred while getting project", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error occurred while getting project. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } // Experiment management methods with sharing registry integration - public String createExperimentWithSharing( - String gatewayId, ExperimentModel experiment) - throws Exception { - var experimentId = createExperiment(gatewayId, experiment); + public String createExperimentWithSharing(String gatewayId, ExperimentModel experiment) + throws AiravataSystemException { + try { + var experimentId = createExperiment(gatewayId, experiment); - if (ServerSettings.isEnableSharing()) { - try { + if (ServerSettings.isEnableSharing()) { + try { var entity = new Entity(); - entity.setEntityId(experimentId); - final String domainId = experiment.getGatewayId(); - entity.setDomainId(domainId); - entity.setEntityTypeId(domainId + ":" + "EXPERIMENT"); - entity.setOwnerId(experiment.getUserName() + "@" + domainId); - entity.setName(experiment.getExperimentName()); - entity.setDescription(experiment.getDescription()); - entity.setParentEntityId(experiment.getProjectId()); + entity.setEntityId(experimentId); + final String domainId = experiment.getGatewayId(); + entity.setDomainId(domainId); + entity.setEntityTypeId(domainId + ":" + "EXPERIMENT"); + entity.setOwnerId(experiment.getUserName() + "@" + domainId); + entity.setName(experiment.getExperimentName()); + entity.setDescription(experiment.getDescription()); + entity.setParentEntityId(experiment.getProjectId()); - sharingRegistryService.createEntity(entity); - shareEntityWithAdminGatewayGroups( entity); - } catch (Exception ex) { - logger.error(ex.getMessage(), ex); - logger.error("Rolling back experiment creation Exp ID : " + experimentId); - deleteExperiment(experimentId); - throw new Exception("Failed to create sharing registry record", ex); + sharingRegistryService.createEntity(entity); + shareEntityWithAdminGatewayGroups(entity); + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + logger.error("Rolling back experiment creation Exp ID : " + experimentId); + deleteExperiment(experimentId); + var exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Failed to create sharing registry record. " + ex.getMessage()); + exception.initCause(ex); + throw exception; + } } - } - logger.info( - experimentId, - "Created new experiment with experiment name {} and id ", - experiment.getExperimentName(), - experimentId); - return experimentId; + logger.info( + experimentId, + "Created new experiment with experiment name {} and id ", + experiment.getExperimentName(), + experimentId); + return experimentId; + } catch (AiravataSystemException e) { + throw e; + } catch (ApplicationSettingsException e) { + logger.error("Error occurred while creating experiment", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error occurred while creating experiment. More info: " + e.getMessage()); + exception.initCause(e); + throw exception; + } } public String createExperimentWithSharingAndPublish( - - Publisher statusPublisher, - String gatewayId, - ExperimentModel experiment) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + Publisher statusPublisher, String gatewayId, ExperimentModel experiment) + throws InvalidRequestException, AiravataSystemException, AuthorizationException { try { logger.info("Api server accepted experiment creation with name {}", experiment.getExperimentName()); - var experimentId = createExperimentWithSharing( gatewayId, experiment); + var experimentId = createExperimentWithSharing(gatewayId, experiment); if (statusPublisher != null) { - var event = - new ExperimentStatusChangeEvent(ExperimentState.CREATED, experimentId, gatewayId); + var event = new ExperimentStatusChangeEvent(ExperimentState.CREATED, experimentId, gatewayId); var messageId = AiravataUtils.getId("EXPERIMENT"); var messageContext = new MessageContext(event, MessageType.EXPERIMENT, messageId, gatewayId); messageContext.setUpdatedTime(AiravataUtils.getCurrentTimestamp()); @@ -2875,23 +3981,26 @@ public String createExperimentWithSharingAndPublish( } return experimentId; + } catch (AiravataSystemException e) { + throw e; } catch (Throwable e) { - throw convertException(e, "Error while creating the experiment"); + logger.error("Error while creating the experiment", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while creating the experiment. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public void validateLaunchExperimentAccess( - - AuthzToken authzToken, - String gatewayId, - ExperimentModel experiment) - throws Exception { + public void validateLaunchExperimentAccess(AuthzToken authzToken, String gatewayId, ExperimentModel experiment) + throws InvalidRequestException, AuthorizationException, AiravataSystemException, SharingRegistryException { String username = authzToken.getClaimsMap().get(Constants.USER_NAME); // For backwards compatibility, if there is no groupResourceProfileId, look up one that is shared with the user if (!experiment.getUserConfigurationData().isSetGroupResourceProfileId()) { // This will be handled by the handler calling getGroupResourceList - throw new Exception("Experiment doesn't have groupResourceProfileId"); + throw new InvalidRequestException("Experiment doesn't have groupResourceProfileId"); } // Verify user has READ access to groupResourceProfileId @@ -2900,7 +4009,7 @@ public void validateLaunchExperimentAccess( username + "@" + gatewayId, experiment.getUserConfigurationData().getGroupResourceProfileId(), gatewayId + ":READ")) { - throw new Exception("User " + username + " in gateway " + gatewayId + throw new AuthorizationException("User " + username + " in gateway " + gatewayId + " doesn't have access to group resource profile " + experiment.getUserConfigurationData().getGroupResourceProfileId()); } @@ -2930,12 +4039,12 @@ public void validateLaunchExperimentAccess( applicationDeploymentDescription.get().getAppDeploymentId(); if (!sharingRegistryService.userHasAccess( gatewayId, username + "@" + gatewayId, appDeploymentId, gatewayId + ":READ")) { - throw new Exception("User " + username + " in gateway " + gatewayId + throw new AuthorizationException("User " + username + " in gateway " + gatewayId + " doesn't have access to app deployment " + appDeploymentId); } } else { - throw new Exception("Application deployment doesn't exist for application interface " + appInterfaceId - + " and host " + resourceHostId + " in gateway " + gatewayId); + throw new InvalidRequestException("Application deployment doesn't exist for application interface " + + appInterfaceId + " and host " + resourceHostId + " in gateway " + gatewayId); } } else if (experiment.getUserConfigurationData().getAutoScheduledCompResourceSchedulingList() != null && !experiment @@ -2954,7 +4063,7 @@ public void validateLaunchExperimentAccess( applicationDeploymentDescription.get().getAppDeploymentId(); if (!sharingRegistryService.userHasAccess( gatewayId, username + "@" + gatewayId, appDeploymentId, gatewayId + ":READ")) { - throw new Exception("User " + username + " in gateway " + gatewayId + throw new AuthorizationException("User " + username + " in gateway " + gatewayId + " doesn't have access to app deployment " + appDeploymentId); } } @@ -2962,34 +4071,51 @@ public void validateLaunchExperimentAccess( } } - public boolean deleteExperimentWithAuth( - AuthzToken authzToken, String experimentId) throws AuthorizationException, InvalidRequestException { + public boolean deleteExperimentWithAuth(AuthzToken authzToken, String experimentId) + throws AuthorizationException, InvalidRequestException, AiravataSystemException, + ExperimentNotFoundException, ProjectNotFoundException { try { var experimentModel = getExperiment(experimentId); if (ServerSettings.isEnableSharing() - && !authzToken.getClaimsMap().get(Constants.USER_NAME).equals(experimentModel.getUserName()) + && !authzToken + .getClaimsMap() + .get(Constants.USER_NAME) + .equals(experimentModel.getUserName()) || !authzToken.getClaimsMap().get(Constants.GATEWAY_ID).equals(experimentModel.getGatewayId())) { var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - if (!sharingRegistryService.userHasAccess(gatewayId, userId + "@" + gatewayId, experimentId, gatewayId + ":WRITE")) { + if (!sharingRegistryService.userHasAccess( + gatewayId, userId + "@" + gatewayId, experimentId, gatewayId + ":WRITE")) { throw new AuthorizationException("User does not have permission to access this resource"); } } - if (!(experimentModel.getExperimentStatus().get(0).getState() - == org.apache.airavata.model.status.ExperimentState.CREATED)) { - throw new InvalidRequestException("Experiment is not in CREATED state. Hence cannot deleted. ID:" + experimentId); + if (!(experimentModel.getExperimentStatus().get(0).getState() == ExperimentState.CREATED)) { + throw new InvalidRequestException( + "Experiment is not in CREATED state. Hence cannot deleted. ID:" + experimentId); } return deleteExperiment(experimentId); - } catch (AuthorizationException | InvalidRequestException e) { + } catch (AuthorizationException | InvalidRequestException | AiravataSystemException e) { throw e; - } catch (Throwable e) { - throw convertException(e, "Error while deleting experiment"); + } catch (ApplicationSettingsException e) { + logger.error("Error occurred while deleting experiment", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error occurred while deleting experiment. More info: " + e.getMessage()); + exception.initCause(e); + throw exception; + } catch (SharingRegistryException e) { + logger.error("Error occurred while deleting experiment", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error occurred while deleting experiment. More info: " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public ResourceType getResourceType( String domainId, String entityId) { + public ResourceType getResourceType(String domainId, String entityId) throws AiravataSystemException { try { var entity = sharingRegistryService.getEntity(domainId, entityId); for (ResourceType resourceType : ResourceType.values()) { @@ -2998,13 +4124,18 @@ public ResourceType getResourceType( String domainId, String entityId) { } } throw new RuntimeException("Unrecognized entity type id: " + entity.getEntityTypeId()); - } catch (Throwable e) { - throw convertException(e, "Error while getting resource type"); + } catch (SharingRegistryException e) { + logger.error("Error while getting resource type", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while getting resource type. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } // Gateway management methods with sharing registry integration - public String addGatewayWithSharing(Gateway gateway) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + public String addGatewayWithSharing(Gateway gateway) throws AiravataSystemException { try { var gatewayId = registryService.addGateway(gateway); Domain domain = new Domain(); @@ -3073,8 +4204,20 @@ public String addGatewayWithSharing(Gateway gateway) throws InvalidRequestExcept logger.debug("Airavata successfully created the gateway with " + gatewayId); return gatewayId; - } catch (Throwable e) { - throw convertException(e, "Error while adding gateway"); + } catch (RegistryServiceException e) { + logger.error("Error while adding gateway", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while adding gateway. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; + } catch (SharingRegistryException | DuplicateEntryException e) { + logger.error("Error while adding gateway", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while adding gateway. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3103,8 +4246,7 @@ public void publishExperimentCancelEvent(Publisher experimentPublisher, String g public void publishExperimentIntermediateOutputsEvent( Publisher experimentPublisher, String gatewayId, String experimentId, List outputNames) throws Exception { - var event = - new ExperimentIntermediateOutputsEvent(experimentId, gatewayId, outputNames); + var event = new ExperimentIntermediateOutputsEvent(experimentId, gatewayId, outputNames); var messageContext = new MessageContext( event, MessageType.INTERMEDIATE_OUTPUTS, @@ -3118,16 +4260,12 @@ public void publishExperimentIntermediateOutputsEvent( * Validate and fetch intermediate outputs - checks access, job state, and existing processes */ public void validateAndFetchIntermediateOutputs( - - AuthzToken authzToken, - String airavataExperimentId, - List outputNames, - Publisher experimentPublisher) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + AuthzToken authzToken, String airavataExperimentId, List outputNames, Publisher experimentPublisher) + throws InvalidRequestException, AiravataSystemException, AuthorizationException { try { // Verify that user has WRITE access to experiment final boolean hasAccess = - userHasAccessInternal( authzToken, airavataExperimentId, ResourcePermissionType.WRITE); + userHasAccessInternal(authzToken, airavataExperimentId, ResourcePermissionType.WRITE); if (!hasAccess) { var msg = "User does not have WRITE access to this experiment"; logger.error(msg); @@ -3152,7 +4290,7 @@ public void validateAndFetchIntermediateOutputs( // Figure out if there are any currently running intermediate output fetching processes for outputNames // First, find any existing intermediate output fetch processes for outputNames - var intermediateOutputFetchProcesses = existingExperiment.getProcesses().stream() + List intermediateOutputFetchProcesses = existingExperiment.getProcesses().stream() .filter(p -> { // Filter out completed or failed processes if (p.getProcessStatusesSize() > 0) { @@ -3164,8 +4302,12 @@ public void validateAndFetchIntermediateOutputs( } return true; }) - .filter(p -> p.getTasks().stream().allMatch(t -> t.getTaskType() == TaskTypes.OUTPUT_FETCHING)) - .filter(p -> p.getProcessOutputs().stream().anyMatch(o -> outputNames.contains(o.getName()))) + .filter(p -> { + return p.getTasks().stream().allMatch(t -> t.getTaskType() == TaskTypes.OUTPUT_FETCHING); + }) + .filter(p -> { + return p.getProcessOutputs().stream().anyMatch(o -> outputNames.contains(o.getName())); + }) .collect(Collectors.toList()); if (!intermediateOutputFetchProcesses.isEmpty()) { var msg = "There are already intermediate output fetching tasks running for those outputs."; @@ -3174,7 +4316,8 @@ public void validateAndFetchIntermediateOutputs( } var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - publishExperimentIntermediateOutputsEvent(experimentPublisher, gatewayId, airavataExperimentId, outputNames); + publishExperimentIntermediateOutputsEvent( + experimentPublisher, gatewayId, airavataExperimentId, outputNames); } catch (AuthorizationException | InvalidRequestException e) { throw e; } catch (Throwable e) { @@ -3182,7 +4325,11 @@ public void validateAndFetchIntermediateOutputs( "Error while processing request to fetch intermediate outputs for experiment: " + airavataExperimentId, e); - throw convertException(e, "Error occurred"); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error occurred. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3190,15 +4337,12 @@ public void validateAndFetchIntermediateOutputs( * Get intermediate output process status - finds the most recent matching process and returns its status */ public ProcessStatus getIntermediateOutputProcessStatusInternal( - - AuthzToken authzToken, - String airavataExperimentId, - List outputNames) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + AuthzToken authzToken, String airavataExperimentId, List outputNames) + throws InvalidRequestException, AiravataSystemException, AuthorizationException { try { // Verify that user has READ access to experiment final boolean hasAccess = - userHasAccessInternal( authzToken, airavataExperimentId, ResourcePermissionType.READ); + userHasAccessInternal(authzToken, airavataExperimentId, ResourcePermissionType.READ); if (!hasAccess) { var msg = "User does not have READ access to this experiment"; logger.debug(msg); @@ -3213,11 +4357,13 @@ public ProcessStatus getIntermediateOutputProcessStatusInternal( Optional mostRecentOutputFetchProcess = existingExperiment.getProcesses().stream() .filter(p -> p.getTasks().stream().allMatch(t -> t.getTaskType() == TaskTypes.OUTPUT_FETCHING)) .filter(p -> { - List names = - p.getProcessOutputs().stream().map(o -> o.getName()).collect(Collectors.toList()); + List names = p.getProcessOutputs().stream() + .map(o -> o.getName()) + .collect(Collectors.toList()); return new HashSet<>(names).equals(new HashSet<>(outputNames)); }) - .sorted(Comparator.comparing(ProcessModel::getLastUpdateTime).reversed()) + .sorted(Comparator.comparing(ProcessModel::getLastUpdateTime) + .reversed()) .findFirst(); if (!mostRecentOutputFetchProcess.isPresent()) { @@ -3244,18 +4390,21 @@ public ProcessStatus getIntermediateOutputProcessStatusInternal( "Error while processing request to get intermediate output process status for experiment: " + airavataExperimentId, e); - throw convertException(e, "Error occurred"); + logger.error("Error occurred", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error occurred. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } // Access control methods public List getAllAccessibleUsers( - String gatewayId, String resourceId, ResourcePermissionType permissionType, - BiFunction> userListFunction) - throws Exception { + BiFunction> userListFunction) { HashSet accessibleUsers = new HashSet<>(); if (permissionType.equals(ResourcePermissionType.WRITE)) { userListFunction.apply(sharingRegistryService, ResourcePermissionType.WRITE).stream() @@ -3280,12 +4429,10 @@ public List getAllAccessibleUsers( } public List getAllAccessibleGroups( - String gatewayId, String resourceId, ResourcePermissionType permissionType, - BiFunction> groupListFunction) - throws Exception { + BiFunction> groupListFunction) { HashSet accessibleGroups = new HashSet<>(); if (permissionType.equals(ResourcePermissionType.WRITE)) { groupListFunction.apply(sharingRegistryService, ResourcePermissionType.WRITE).stream() @@ -3304,35 +4451,36 @@ public List getAllAccessibleGroups( * Get all accessible users for a resource (includes shared and directly shared) */ public List getAllAccessibleUsersWithSharing( - - AuthzToken authzToken, - String resourceId, - ResourcePermissionType permissionType, - boolean directlySharedOnly) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + AuthzToken authzToken, String resourceId, ResourcePermissionType permissionType, boolean directlySharedOnly) + throws AiravataSystemException { try { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - BiFunction> userListFunction; - if (directlySharedOnly) { - userListFunction = (c, t) -> { - try { - return c.getListOfDirectlySharedUsers(gatewayId, resourceId, gatewayId + ":" + t.name()); - } catch (Exception e) { - throw new RuntimeException(e); - } - }; - } else { - userListFunction = (c, t) -> { - try { - return c.getListOfSharedUsers(gatewayId, resourceId, gatewayId + ":" + t.name()); - } catch (Exception e) { - throw new RuntimeException(e); - } - }; - } - return getAllAccessibleUsers( gatewayId, resourceId, permissionType, userListFunction); - } catch (Throwable e) { - throw convertException(e, "Error occurred while getting all accessible users"); + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + BiFunction> userListFunction; + if (directlySharedOnly) { + userListFunction = (c, t) -> { + try { + return c.getListOfDirectlySharedUsers(gatewayId, resourceId, gatewayId + ":" + t.name()); + } catch (Exception e) { + throw new RuntimeException(e); + } + }; + } else { + userListFunction = (c, t) -> { + try { + return c.getListOfSharedUsers(gatewayId, resourceId, gatewayId + ":" + t.name()); + } catch (Exception e) { + throw new RuntimeException(e); + } + }; + } + return getAllAccessibleUsers(gatewayId, resourceId, permissionType, userListFunction); + } catch (Exception e) { + logger.error("Error occurred while getting all accessible users", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error occurred while getting all accessible users. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3340,50 +4488,50 @@ public List getAllAccessibleUsersWithSharing( * Get all accessible groups for a resource (includes shared and directly shared) */ public List getAllAccessibleGroupsWithSharing( - - AuthzToken authzToken, - String resourceId, - ResourcePermissionType permissionType, - boolean directlySharedOnly) - throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + AuthzToken authzToken, String resourceId, ResourcePermissionType permissionType, boolean directlySharedOnly) + throws AiravataSystemException { try { - String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - BiFunction> groupListFunction; - if (directlySharedOnly) { - groupListFunction = (c, t) -> { - try { - return c.getListOfDirectlySharedGroups(gatewayId, resourceId, gatewayId + ":" + t.name()); - } catch (Exception e) { - throw new RuntimeException(e); - } - }; - } else { - groupListFunction = (c, t) -> { - try { - return c.getListOfSharedGroups(gatewayId, resourceId, gatewayId + ":" + t.name()); - } catch (Exception e) { - throw new RuntimeException(e); - } - }; - } - return getAllAccessibleGroups( gatewayId, resourceId, permissionType, groupListFunction); - } catch (Throwable e) { - throw convertException(e, "Error occurred while getting all accessible groups"); + String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); + BiFunction> groupListFunction; + if (directlySharedOnly) { + groupListFunction = (c, t) -> { + try { + return c.getListOfDirectlySharedGroups(gatewayId, resourceId, gatewayId + ":" + t.name()); + } catch (Exception e) { + throw new RuntimeException(e); + } + }; + } else { + groupListFunction = (c, t) -> { + try { + return c.getListOfSharedGroups(gatewayId, resourceId, gatewayId + ":" + t.name()); + } catch (Exception e) { + throw new RuntimeException(e); + } + }; + } + return getAllAccessibleGroups(gatewayId, resourceId, permissionType, groupListFunction); + } catch (Exception e) { + logger.error("Error occurred while getting all accessible groups", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error occurred while getting all accessible groups. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } // Group resource profile management with sharing registry integration public String createGroupResourceProfileWithSharing( - - AuthzToken authzToken, - GroupResourceProfile groupResourceProfile) - throws Exception { + AuthzToken authzToken, GroupResourceProfile groupResourceProfile) + throws AuthorizationException, AiravataSystemException, SharingRegistryException, DuplicateEntryException, + InvalidRequestException, ApplicationSettingsException { String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); - validateGroupResourceProfile( authzToken, groupResourceProfile); + validateGroupResourceProfile(authzToken, groupResourceProfile); String groupResourceProfileId = createGroupResourceProfile(groupResourceProfile); if (ServerSettings.isEnableSharing()) { try { - var entity = new Entity(); + var entity = new Entity(); entity.setEntityId(groupResourceProfileId); entity.setDomainId(groupResourceProfile.getGatewayId()); entity.setEntityTypeId(groupResourceProfile.getGatewayId() + ":" + "GROUP_RESOURCE_PROFILE"); @@ -3391,8 +4539,13 @@ public String createGroupResourceProfileWithSharing( entity.setName(groupResourceProfile.getGroupResourceProfileName()); sharingRegistryService.createEntity(entity); - shareEntityWithAdminGatewayGroups( entity); - } catch (Exception ex) { + shareEntityWithAdminGatewayGroups(entity); + } catch (SharingRegistryException + | DuplicateEntryException + | AiravataSystemException + | InvalidRequestException + | AuthorizationException + | ApplicationSettingsException ex) { logger.error(ex.getMessage(), ex); logger.error("Rolling back group resource profile creation Group Resource Profile ID : " + groupResourceProfileId); @@ -3401,17 +4554,14 @@ public String createGroupResourceProfileWithSharing( } catch (Throwable rollbackEx) { logger.error("Failed to rollback group resource profile deletion", rollbackEx); } - throw new Exception("Failed to create sharing registry record", ex); + throw ex; } } return groupResourceProfileId; } - public void validateGroupResourceProfile( - - AuthzToken authzToken, - GroupResourceProfile groupResourceProfile) - throws Exception { + public void validateGroupResourceProfile(AuthzToken authzToken, GroupResourceProfile groupResourceProfile) + throws AuthorizationException { Set tokenIds = new HashSet<>(); if (groupResourceProfile.getComputePreferences() != null) { for (GroupComputeResourcePreference groupComputeResourcePreference : @@ -3425,32 +4575,33 @@ public void validateGroupResourceProfile( tokenIds.add(groupResourceProfile.getDefaultCredentialStoreToken()); } for (String tokenId : tokenIds) { - if (!userHasAccessInternal( authzToken, tokenId, ResourcePermissionType.READ)) { - throw new Exception("User does not have READ permission to credential token " + tokenId + "."); + if (!userHasAccessInternal(authzToken, tokenId, ResourcePermissionType.READ)) { + throw new AuthorizationException( + "User does not have READ permission to credential token " + tokenId + "."); } } } // Launch experiment business logic public void launchExperimentWithValidation( - AuthzToken authzToken, - String gatewayId, - String airavataExperimentId, - Publisher experimentPublisher) - throws TException { + AuthzToken authzToken, String gatewayId, String airavataExperimentId, Publisher experimentPublisher) + throws InvalidRequestException, AiravataSystemException, AuthorizationException, + ExperimentNotFoundException, ProjectNotFoundException { try { logger.info("Launching experiment {}", airavataExperimentId); ExperimentModel experiment = getExperiment(airavataExperimentId); if (experiment == null) { - throw new ExperimentNotFoundException("Requested experiment id " + airavataExperimentId + " does not exist in the system.."); + throw new ExperimentNotFoundException( + "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); } String username = authzToken.getClaimsMap().get(Constants.USER_NAME); - // For backwards compatibility, if there is no groupResourceProfileId, look up one that is shared with the user + // For backwards compatibility, if there is no groupResourceProfileId, look up one that is shared with the + // user if (!experiment.getUserConfigurationData().isSetGroupResourceProfileId()) { List groupResourceProfiles = - getGroupResourceListWithSharing( authzToken, gatewayId); + getGroupResourceListWithSharing(authzToken, gatewayId); if (groupResourceProfiles != null && !groupResourceProfiles.isEmpty()) { // Just pick the first one final String groupResourceProfileId = @@ -3468,18 +4619,36 @@ public void launchExperimentWithValidation( } // Validate access to group resource profile and application deployments - validateLaunchExperimentAccess( authzToken, gatewayId, experiment); + validateLaunchExperimentAccess(authzToken, gatewayId, experiment); publishExperimentSubmitEvent(experimentPublisher, gatewayId, airavataExperimentId); + } catch (InvalidRequestException + | AiravataSystemException + | AuthorizationException + | ExperimentNotFoundException + | ProjectNotFoundException e) { + throw e; + } catch (RegistryException | AppCatalogException | CredentialStoreException | SharingRegistryException e) { + logger.error("Error launching experiment", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error launching experiment. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } catch (Throwable e) { - throw convertException(e, "Error launching experiment"); + logger.error("Error launching experiment", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error launching experiment. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } /** * Get group resource list with sharing registry integration */ - public List getGroupResourceListWithSharing( - AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { + public List getGroupResourceListWithSharing(AuthzToken authzToken, String gatewayId) + throws AiravataSystemException { try { String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); var accessibleGroupResProfileIds = new ArrayList(); @@ -3501,85 +4670,110 @@ public List getGroupResourceListWithSharing( .forEach(p -> accessibleGroupResProfileIds.add(p.getEntityId())); } return getGroupResourceList(gatewayId, accessibleGroupResProfileIds); - } catch (Throwable e) { - throw convertException(e, "Error occurred while getting group resource list"); + } catch (ApplicationSettingsException | SharingRegistryException e) { + logger.error("Error occurred while getting group resource list", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error occurred while getting group resource list. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } // Sharing Registry Delegation Methods for ServerHandler - public boolean isDomainExists(String domainId) throws org.apache.airavata.sharing.registry.models.SharingRegistryException { + public boolean isDomainExists(String domainId) throws SharingRegistryException { return sharingRegistryService.isDomainExists(domainId); } - public String createDomain(Domain domain) throws org.apache.airavata.sharing.registry.models.SharingRegistryException, org.apache.airavata.sharing.registry.models.DuplicateEntryException { + public String createDomain(Domain domain) throws SharingRegistryException, DuplicateEntryException { return sharingRegistryService.createDomain(domain); } - public String createUser(User user) throws org.apache.airavata.sharing.registry.models.SharingRegistryException, org.apache.airavata.sharing.registry.models.DuplicateEntryException { + public String createUser(User user) throws SharingRegistryException, DuplicateEntryException { return sharingRegistryService.createUser(user); } - public String createGroup(UserGroup group) throws org.apache.airavata.sharing.registry.models.SharingRegistryException, org.apache.airavata.sharing.registry.models.DuplicateEntryException { + public String createGroup(UserGroup group) throws SharingRegistryException, DuplicateEntryException { return sharingRegistryService.createGroup(group); } - public boolean addUsersToGroup(String domainId, List userIds, String groupId) throws org.apache.airavata.sharing.registry.models.SharingRegistryException { + public boolean addUsersToGroup(String domainId, List userIds, String groupId) + throws SharingRegistryException { return sharingRegistryService.addUsersToGroup(domainId, userIds, groupId); } - public String createEntityType(org.apache.airavata.sharing.registry.models.EntityType entityType) throws org.apache.airavata.sharing.registry.models.SharingRegistryException, org.apache.airavata.sharing.registry.models.DuplicateEntryException { + public String createEntityType(EntityType entityType) throws SharingRegistryException, DuplicateEntryException { return sharingRegistryService.createEntityType(entityType); } - public String createPermissionType(org.apache.airavata.sharing.registry.models.PermissionType permissionType) throws org.apache.airavata.sharing.registry.models.SharingRegistryException, org.apache.airavata.sharing.registry.models.DuplicateEntryException { + public String createPermissionType(PermissionType permissionType) + throws SharingRegistryException, DuplicateEntryException { return sharingRegistryService.createPermissionType(permissionType); } - public boolean userHasAccess(String domainId, String userId, String entityId, String permissionTypeId) throws org.apache.airavata.sharing.registry.models.SharingRegistryException { + public boolean userHasAccess(String domainId, String userId, String entityId, String permissionTypeId) + throws SharingRegistryException { return sharingRegistryService.userHasAccess(domainId, userId, entityId, permissionTypeId); } - public org.apache.airavata.sharing.registry.models.Entity getEntity(String domainId, String entityId) throws org.apache.airavata.sharing.registry.models.SharingRegistryException { - return sharingRegistryService.getEntity(domainId, entityId); + public SharingEntity getEntity(String domainId, String entityId) throws SharingRegistryException { + return new SharingEntity(sharingRegistryService.getEntity(domainId, entityId)); } - public void updateEntity(org.apache.airavata.sharing.registry.models.Entity entity) throws org.apache.airavata.sharing.registry.models.SharingRegistryException { - sharingRegistryService.updateEntity(entity); + public void updateEntity(SharingEntity entity) throws SharingRegistryException { + sharingRegistryService.updateEntity(entity.delegate()); } - public boolean shareEntityWithUsers(String domainId, String entityId, List userList, String permissionTypeId, boolean cascade) throws org.apache.airavata.sharing.registry.models.SharingRegistryException { + public boolean shareEntityWithUsers( + String domainId, String entityId, List userList, String permissionTypeId, boolean cascade) + throws SharingRegistryException { return sharingRegistryService.shareEntityWithUsers(domainId, entityId, userList, permissionTypeId, cascade); } - public SSHCredential getSSHCredential(String token, String gatewayId) { + public SSHCredential getSSHCredential(String token, String gatewayId) throws AiravataSystemException { try { return credentialStoreService.getSSHCredential(token, gatewayId); - } catch (Throwable e) { - throw convertException(e, "Error while retrieving SSH credential"); + } catch (CredentialStoreException e) { + logger.error("Error while retrieving SSH credential", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error while retrieving SSH credential. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public void createEntity(org.apache.airavata.sharing.registry.models.Entity entity) throws org.apache.airavata.sharing.registry.models.SharingRegistryException, org.apache.airavata.sharing.registry.models.DuplicateEntryException { - sharingRegistryService.createEntity(entity); + public void createEntity(SharingEntity entity) throws SharingRegistryException, DuplicateEntryException { + sharingRegistryService.createEntity(entity.delegate()); } - public java.util.List searchEntities(String domainId, String userId, java.util.List filters, int offset, int limit) throws org.apache.airavata.sharing.registry.models.SharingRegistryException { - return sharingRegistryService.searchEntities(domainId, userId, filters, offset, limit); + public List searchEntities( + String domainId, String userId, List filters, int offset, int limit) + throws SharingRegistryException { + return sharingRegistryService.searchEntities(domainId, userId, filters, offset, limit).stream() + .map(SharingEntity::new) + .collect(Collectors.toList()); } - public boolean shareEntityWithGroups(String domainId, String entityId, List groupList, String permissionTypeId, boolean cascade) throws org.apache.airavata.sharing.registry.models.SharingRegistryException { + public boolean shareEntityWithGroups( + String domainId, String entityId, List groupList, String permissionTypeId, boolean cascade) + throws SharingRegistryException { return sharingRegistryService.shareEntityWithGroups(domainId, entityId, groupList, permissionTypeId, cascade); } - public boolean revokeEntitySharingFromUsers(String domainId, String entityId, List userList, String permissionTypeId) throws org.apache.airavata.sharing.registry.models.SharingRegistryException { + public boolean revokeEntitySharingFromUsers( + String domainId, String entityId, List userList, String permissionTypeId) + throws SharingRegistryException { return sharingRegistryService.revokeEntitySharingFromUsers(domainId, entityId, userList, permissionTypeId); } - public boolean revokeEntitySharingFromGroups(String domainId, String entityId, List groupList, String permissionTypeId) throws org.apache.airavata.sharing.registry.models.SharingRegistryException { + public boolean revokeEntitySharingFromGroups( + String domainId, String entityId, List groupList, String permissionTypeId) + throws SharingRegistryException { return sharingRegistryService.revokeEntitySharingFromGroups(domainId, entityId, groupList, permissionTypeId); } - public boolean deleteEntity(String domainId, String entityId) throws org.apache.airavata.sharing.registry.models.SharingRegistryException { + public boolean deleteEntity(String domainId, String entityId) throws SharingRegistryException { return sharingRegistryService.deleteEntity(domainId, entityId); } @@ -3589,7 +4783,7 @@ public boolean deleteEntity(String domainId, String entityId) throws org.apache. */ private StorageInfoContext resolveComputeStorageInfoContext( AuthzToken authzToken, String gatewayId, String userId, String resourceId) - throws Exception { + throws InvalidRequestException, AiravataSystemException, ApplicationSettingsException, AgentException { String loginUserName = null; boolean loginFromUserPref = false; GroupComputeResourcePreference groupComputePref = null; @@ -3660,7 +4854,7 @@ private StorageInfoContext resolveComputeStorageInfoContext( || userResourceProfile.getCredentialStoreToken() == null || userResourceProfile.getCredentialStoreToken().trim().isEmpty()) { logger.error("No credential store token found for user {} in gateway {}", userId, gatewayId); - throw clientException( + throw airavataSystemException( AiravataErrorType.AUTHENTICATION_FAILURE, "No credential store token found for user " + userId + " in gateway " + gatewayId); } @@ -3691,7 +4885,7 @@ private StorageInfoContext resolveComputeStorageInfoContext( || userResourceProfile.getCredentialStoreToken() == null || userResourceProfile.getCredentialStoreToken().trim().isEmpty()) { logger.error("No credential store token found for user {} in gateway {}", userId, gatewayId); - throw clientException( + throw airavataSystemException( AiravataErrorType.AUTHENTICATION_FAILURE, "No credential store token found for compute resource " + resourceId); } @@ -3712,7 +4906,8 @@ private StorageInfoContext resolveComputeStorageInfoContext( */ private StorageInfoContext resolveStorageStorageInfoContext( AuthzToken authzToken, String gatewayId, String userId, String resourceId) - throws Exception { + throws InvalidRequestException, AgentException, ApplicationSettingsException, AiravataSystemException, + AuthorizationException { UserStoragePreference userStoragePref = null; if (safeIsUserResourceProfileExists(authzToken, userId, gatewayId)) { userStoragePref = getUserStoragePreference(userId, gatewayId, resourceId); @@ -3773,7 +4968,7 @@ private StorageInfoContext resolveStorageStorageInfoContext( || userResourceProfile.getCredentialStoreToken() == null || userResourceProfile.getCredentialStoreToken().trim().isEmpty()) { logger.error("No credential store token found for user {} in gateway {}", userId, gatewayId); - throw clientException( + throw airavataSystemException( AiravataErrorType.AUTHENTICATION_FAILURE, "No credential store token found for user " + userId + " in gateway " + gatewayId); } @@ -3798,7 +4993,7 @@ private StorageInfoContext resolveStorageStorageInfoContext( .trim() .isEmpty()) { logger.error("No credential store token found for gateway {}", gatewayId); - throw clientException( + throw airavataSystemException( AiravataErrorType.AUTHENTICATION_FAILURE, "No credential store token found for gateway " + gatewayId); } @@ -3813,9 +5008,8 @@ private StorageInfoContext resolveStorageStorageInfoContext( return new StorageInfoContext(loginUserName, credentialToken, adaptor); } - public StorageVolumeInfo getResourceStorageInfo( - AuthzToken authzToken, String resourceId, String location) - throws InvalidRequestException { + public StorageVolumeInfo getResourceStorageInfo(AuthzToken authzToken, String resourceId, String location) + throws InvalidRequestException, AiravataSystemException, AuthorizationException { try { var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); @@ -3859,17 +5053,20 @@ public StorageVolumeInfo getResourceStorageInfo( } return context.adaptor().getStorageVolumeInfo(location); - } catch (InvalidRequestException e) { - logger.error("Error while retrieving storage resource.", e); + } catch (InvalidRequestException | AiravataSystemException | AuthorizationException e) { throw e; } catch (Throwable e) { - throw convertException(e, "Error while retrieving storage resource"); + logger.error("Error occurred while getting resource storage info", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error occurred while getting resource storage info. More info: " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public StorageDirectoryInfo getStorageDirectoryInfo( - AuthzToken authzToken, String resourceId, String location) - throws InvalidRequestException { + public StorageDirectoryInfo getStorageDirectoryInfo(AuthzToken authzToken, String resourceId, String location) + throws InvalidRequestException, AiravataSystemException, AuthorizationException { try { var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); @@ -3913,54 +5110,93 @@ public StorageDirectoryInfo getStorageDirectoryInfo( } return context.adaptor().getStorageDirectoryInfo(location); - } catch (InvalidRequestException e) { - logger.error("Error while retrieving storage resource.", e); + } catch (InvalidRequestException | AiravataSystemException | AuthorizationException e) { throw e; } catch (Throwable e) { - throw convertException(e, "Error while retrieving storage directory info"); + logger.error("Error occurred while getting storage directory info", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error occurred while getting storage directory info. More info: " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public boolean doesUserHaveSSHAccount(AuthzToken authzToken, String computeResourceId, String userId) { + public boolean doesUserHaveSSHAccount(AuthzToken authzToken, String computeResourceId, String userId) + throws InvalidRequestException, AiravataSystemException, AuthorizationException { try { var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - logger.debug("Checking if user {} has SSH account on compute resource {} in gateway {}", userId, computeResourceId, gatewayId); - return org.apache.airavata.accountprovisioning.SSHAccountManager.doesUserHaveSSHAccount(gatewayId, computeResourceId, userId); + logger.debug( + "Checking if user {} has SSH account on compute resource {} in gateway {}", + userId, + computeResourceId, + gatewayId); + return SSHAccountManager.doesUserHaveSSHAccount(gatewayId, computeResourceId, userId); } catch (Throwable e) { - throw convertException(e, "Error occurred while checking if user has an SSH Account"); + logger.error("Error occurred while checking if user has an SSH Account", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error occurred while checking if user has an SSH Account. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean isSSHAccountSetupComplete( - AuthzToken authzToken, String computeResourceId, String airavataCredStoreToken) { + AuthzToken authzToken, String computeResourceId, String airavataCredStoreToken) + throws AiravataSystemException, AuthorizationException { try { var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); - logger.debug("Checking if SSH account setup is complete for user {} on compute resource {} in gateway {}", userId, computeResourceId, gatewayId); - + logger.debug( + "Checking if SSH account setup is complete for user {} on compute resource {} in gateway {}", + userId, + computeResourceId, + gatewayId); + SSHCredential sshCredential = getSSHCredential(airavataCredStoreToken, gatewayId); - return org.apache.airavata.accountprovisioning.SSHAccountManager.isSSHAccountSetupComplete(gatewayId, computeResourceId, userId, sshCredential); + return SSHAccountManager.isSSHAccountSetupComplete(gatewayId, computeResourceId, userId, sshCredential); } catch (Throwable e) { - throw convertException(e, "Error occurred while checking if setup of SSH account is complete"); + logger.error("Error occurred while checking if setup of SSH account is complete", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage( + "Error occurred while checking if setup of SSH account is complete. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public UserComputeResourcePreference setupSSHAccount( - AuthzToken authzToken, String computeResourceId, String userId, String airavataCredStoreToken) { + AuthzToken authzToken, String computeResourceId, String userId, String airavataCredStoreToken) + throws InvalidRequestException, AiravataSystemException, AuthorizationException { try { var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - logger.debug("Setting up SSH account for user {} on compute resource {} in gateway {}", userId, computeResourceId, gatewayId); - + logger.debug( + "Setting up SSH account for user {} on compute resource {} in gateway {}", + userId, + computeResourceId, + gatewayId); + SSHCredential sshCredential = getSSHCredential(airavataCredStoreToken, gatewayId); - return org.apache.airavata.accountprovisioning.SSHAccountManager.setupSSHAccount(gatewayId, computeResourceId, userId, sshCredential); + return SSHAccountManager.setupSSHAccount(gatewayId, computeResourceId, userId, sshCredential); + } catch (AiravataSystemException e) { + throw e; } catch (Throwable e) { - throw convertException(e, "Error occurred while automatically setting up SSH account for user"); + logger.error("Error occurred while automatically setting up SSH account for user", e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage("Error occurred while automatically setting up SSH account for user. More info : " + + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean shareResourceWithUsers( AuthzToken authzToken, String resourceId, Map userPermissionList) - throws AuthorizationException, AiravataClientException { + throws AuthorizationException, AiravataSystemException { try { if (!userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.OWNER) && !userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { @@ -3997,23 +5233,29 @@ public boolean shareResourceWithUsers( "User is not allowed to grant sharing permission because the user is not the resource owner."); } } else { - logger.error("Invalid ResourcePermissionType : {}", userPermission.getValue().toString()); - throw new AiravataClientException(AiravataErrorType.UNSUPPORTED_OPERATION); + logger.error( + "Invalid ResourcePermissionType : {}", + userPermission.getValue().toString()); + throw new AiravataSystemException(AiravataErrorType.UNSUPPORTED_OPERATION); } } return true; - } catch (AuthorizationException | AiravataClientException e) { + } catch (AuthorizationException e) { throw e; } catch (Throwable e) { var msg = "Error in sharing resource with users. Resource ID : " + resourceId; logger.error(msg, e); - throw convertException(e, msg); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + ". More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean shareResourceWithGroups( AuthzToken authzToken, String resourceId, Map groupPermissionList) - throws AuthorizationException, AiravataClientException { + throws AuthorizationException, AiravataSystemException { try { if (!userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.OWNER) && !userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { @@ -4050,23 +5292,30 @@ public boolean shareResourceWithGroups( "User is not allowed to grant sharing permission because the user is not the resource owner."); } } else { - logger.error("Invalid ResourcePermissionType : {}", groupPermission.getValue().toString()); - throw new AiravataClientException(AiravataErrorType.UNSUPPORTED_OPERATION); + logger.error( + "Invalid ResourcePermissionType : {}", + groupPermission.getValue().toString()); + throw new AiravataSystemException(AiravataErrorType.UNSUPPORTED_OPERATION); } } return true; - } catch (AuthorizationException | AiravataClientException e) { + } catch (AuthorizationException e) { throw e; } catch (Throwable e) { var msg = "Error in sharing resource with groups. Resource ID : " + resourceId; logger.error(msg, e); - throw convertException(e, msg); + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + ". More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean revokeSharingOfResourceFromUsers( AuthzToken authzToken, String resourceId, Map userPermissionList) - throws AuthorizationException, AiravataClientException { + throws AuthorizationException, AiravataSystemException, InvalidRequestException { try { if (!userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.OWNER) && !userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { @@ -4077,16 +5326,10 @@ public boolean revokeSharingOfResourceFromUsers( for (Map.Entry userPermission : userPermissionList.entrySet()) { if (userPermission.getValue().equals(ResourcePermissionType.WRITE)) { revokeEntitySharingFromUsers( - gatewayId, - resourceId, - Arrays.asList(userPermission.getKey()), - gatewayId + ":" + "WRITE"); + gatewayId, resourceId, Arrays.asList(userPermission.getKey()), gatewayId + ":" + "WRITE"); } else if (userPermission.getValue().equals(ResourcePermissionType.READ)) { revokeEntitySharingFromUsers( - gatewayId, - resourceId, - Arrays.asList(userPermission.getKey()), - gatewayId + ":" + "READ"); + gatewayId, resourceId, Arrays.asList(userPermission.getKey()), gatewayId + ":" + "READ"); } else if (userPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING)) { if (userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.OWNER)) { createManageSharingPermissionTypeIfMissing(gatewayId); @@ -4100,23 +5343,29 @@ public boolean revokeSharingOfResourceFromUsers( "User is not allowed to change sharing permission because the user is not the resource owner."); } } else { - logger.error("Invalid ResourcePermissionType : {}", userPermission.getValue().toString()); - throw new AiravataClientException(AiravataErrorType.UNSUPPORTED_OPERATION); + logger.error( + "Invalid ResourcePermissionType : {}", + userPermission.getValue().toString()); + throw new AiravataSystemException(AiravataErrorType.UNSUPPORTED_OPERATION); } } return true; - } catch (AuthorizationException | AiravataClientException e) { + } catch (AuthorizationException e) { throw e; } catch (Throwable e) { var msg = "Error in revoking access to resource from users. Resource ID : " + resourceId; logger.error(msg, e); - throw convertException(e, msg); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + ". More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean revokeSharingOfResourceFromGroups( AuthzToken authzToken, String resourceId, Map groupPermissionList) - throws AuthorizationException, AiravataClientException, InvalidRequestException { + throws AuthorizationException, InvalidRequestException, AiravataSystemException { try { var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); if (!userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.OWNER) @@ -4176,29 +5425,35 @@ public boolean revokeSharingOfResourceFromGroups( "User is not allowed to change sharing because the user is not the resource owner"); } } else { - logger.error("Invalid ResourcePermissionType : {}", groupPermission.getValue().toString()); - throw new AiravataClientException(AiravataErrorType.UNSUPPORTED_OPERATION); + logger.error( + "Invalid ResourcePermissionType : {}", + groupPermission.getValue().toString()); + throw new AiravataSystemException(AiravataErrorType.UNSUPPORTED_OPERATION); } } return true; - } catch (AuthorizationException | AiravataClientException | InvalidRequestException e) { + } catch (AuthorizationException | InvalidRequestException e) { throw e; } catch (Throwable e) { var msg = "Error in revoking access to resource from groups. Resource ID : " + resourceId; logger.error(msg, e); - throw convertException(e, msg); + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + ". More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public GroupResourceProfile getGroupResourceProfileWithAuth(AuthzToken authzToken, String groupResourceProfileId) - throws AuthorizationException { + throws AuthorizationException, AiravataSystemException { try { if (ServerSettings.isEnableSharing()) { var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); if (!userHasAccess(gatewayId, userId + "@" + gatewayId, groupResourceProfileId, gatewayId + ":READ")) { - throw new AuthorizationException( - "User does not have permission to access group resource profile"); + throw new AuthorizationException("User does not have permission to access group resource profile"); } } return getGroupResourceProfile(groupResourceProfileId); @@ -4210,19 +5465,22 @@ public GroupResourceProfile getGroupResourceProfileWithAuth(AuthzToken authzToke } catch (Throwable e) { var msg = "Error retrieving group resource profile. groupResourceProfileId: " + groupResourceProfileId; logger.error(msg, e); - throw convertException(e, msg); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + ". More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean removeGroupResourceProfileWithAuth(AuthzToken authzToken, String groupResourceProfileId) - throws AuthorizationException { + throws AuthorizationException, AiravataSystemException { try { var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); if (ServerSettings.isEnableSharing()) { var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); if (!userHasAccess(gatewayId, userId + "@" + gatewayId, groupResourceProfileId, gatewayId + ":WRITE")) { - throw new AuthorizationException( - "User does not have permission to remove group resource profile"); + throw new AuthorizationException("User does not have permission to remove group resource profile"); } } boolean result = removeGroupResourceProfile(groupResourceProfileId); @@ -4235,13 +5493,18 @@ public boolean removeGroupResourceProfileWithAuth(AuthzToken authzToken, String } catch (Throwable e) { var msg = "Error removing group resource profile. groupResourceProfileId: " + groupResourceProfileId; logger.error(msg, e); - throw convertException(e, msg); + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + ". More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean removeGroupComputePrefsWithAuth( AuthzToken authzToken, String computeResourceId, String groupResourceProfileId) - throws AuthorizationException { + throws AuthorizationException, AiravataSystemException { try { if (ServerSettings.isEnableSharing()) { var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); @@ -4257,12 +5520,17 @@ public boolean removeGroupComputePrefsWithAuth( } catch (Throwable e) { var msg = "Error removing group compute preferences. GroupResourceProfileId: " + groupResourceProfileId; logger.error(msg, e); - throw convertException(e, msg); + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + ". More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean removeGroupComputeResourcePolicyWithAuth(AuthzToken authzToken, String resourcePolicyId) - throws AuthorizationException { + throws AuthorizationException, AiravataSystemException { try { if (ServerSettings.isEnableSharing()) { ComputeResourcePolicy computeResourcePolicy = getGroupComputeResourcePolicy(resourcePolicyId); @@ -4283,12 +5551,17 @@ public boolean removeGroupComputeResourcePolicyWithAuth(AuthzToken authzToken, S } catch (Throwable e) { var msg = "Error removing group compute resource policy. ResourcePolicyId: " + resourcePolicyId; logger.error(msg, e); - throw convertException(e, msg); + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + ". More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean removeGroupBatchQueueResourcePolicyWithAuth(AuthzToken authzToken, String resourcePolicyId) - throws AuthorizationException { + throws AuthorizationException, AiravataSystemException { try { if (ServerSettings.isEnableSharing()) { BatchQueueResourcePolicy batchQueueResourcePolicy = getBatchQueueResourcePolicy(resourcePolicyId); @@ -4309,34 +5582,43 @@ public boolean removeGroupBatchQueueResourcePolicyWithAuth(AuthzToken authzToken } catch (Throwable e) { var msg = "Error removing batch queue resource policy. ResourcePolicyId: " + resourcePolicyId; logger.error(msg, e); - throw convertException(e, msg); + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + ". More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public GroupComputeResourcePreference getGroupComputeResourcePreferenceWithAuth( AuthzToken authzToken, String computeResourceId, String groupResourceProfileId) - throws AuthorizationException { + throws AuthorizationException, AiravataSystemException, InvalidRequestException { try { if (ServerSettings.isEnableSharing()) { var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); if (!userHasAccess(gatewayId, userId + "@" + gatewayId, groupResourceProfileId, gatewayId + ":READ")) { - throw new AuthorizationException( - "User does not have permission to access group resource profile"); + throw new AuthorizationException("User does not have permission to access group resource profile"); } } return getGroupComputeResourcePreference(computeResourceId, groupResourceProfileId); - } catch (AuthorizationException e) { + } catch (AuthorizationException | AiravataSystemException e) { throw e; } catch (Throwable e) { var msg = "Error retrieving Group compute preference. GroupResourceProfileId: " + groupResourceProfileId; logger.error(msg, e); - throw convertException(e, msg); + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + ". More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public ComputeResourcePolicy getGroupComputeResourcePolicyWithAuth(AuthzToken authzToken, String resourcePolicyId) - throws AuthorizationException { + throws AuthorizationException, AiravataSystemException { try { if (ServerSettings.isEnableSharing()) { ComputeResourcePolicy computeResourcePolicy = getGroupComputeResourcePolicy(resourcePolicyId); @@ -4347,8 +5629,7 @@ public ComputeResourcePolicy getGroupComputeResourcePolicyWithAuth(AuthzToken au userId + "@" + gatewayId, computeResourcePolicy.getGroupResourceProfileId(), gatewayId + ":READ")) { - throw new AuthorizationException( - "User does not have permission to access group resource profile"); + throw new AuthorizationException("User does not have permission to access group resource profile"); } } return getGroupComputeResourcePolicy(resourcePolicyId); @@ -4357,12 +5638,17 @@ public ComputeResourcePolicy getGroupComputeResourcePolicyWithAuth(AuthzToken au } catch (Throwable e) { var msg = "Error retrieving Group compute resource policy. ResourcePolicyId: " + resourcePolicyId; logger.error(msg, e); - throw convertException(e, msg); + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + ". More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public BatchQueueResourcePolicy getBatchQueueResourcePolicyWithAuth(AuthzToken authzToken, String resourcePolicyId) - throws AuthorizationException { + throws AuthorizationException, AiravataSystemException { try { if (ServerSettings.isEnableSharing()) { BatchQueueResourcePolicy batchQueueResourcePolicy = getBatchQueueResourcePolicy(resourcePolicyId); @@ -4373,8 +5659,7 @@ public BatchQueueResourcePolicy getBatchQueueResourcePolicyWithAuth(AuthzToken a userId + "@" + gatewayId, batchQueueResourcePolicy.getGroupResourceProfileId(), gatewayId + ":READ")) { - throw new AuthorizationException( - "User does not have permission to access group resource profile"); + throw new AuthorizationException("User does not have permission to access group resource profile"); } } return getBatchQueueResourcePolicy(resourcePolicyId); @@ -4383,18 +5668,21 @@ public BatchQueueResourcePolicy getBatchQueueResourcePolicyWithAuth(AuthzToken a } catch (Throwable e) { var msg = "Error retrieving batch queue resource policy. ResourcePolicyId: " + resourcePolicyId; logger.error(msg, e); - throw convertException(e, msg); + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + ". More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public void updateGroupResourceProfileWithAuth(AuthzToken authzToken, GroupResourceProfile groupResourceProfile) - throws AuthorizationException { + throws AuthorizationException, AiravataSystemException { try { validateGroupResourceProfile(authzToken, groupResourceProfile); if (!userHasAccessInternal( - authzToken, - groupResourceProfile.getGroupResourceProfileId(), - ResourcePermissionType.WRITE)) { + authzToken, groupResourceProfile.getGroupResourceProfileId(), ResourcePermissionType.WRITE)) { throw new AuthorizationException("User does not have permission to update group resource profile"); } updateGroupResourceProfile(groupResourceProfile); @@ -4407,19 +5695,24 @@ public void updateGroupResourceProfileWithAuth(AuthzToken authzToken, GroupResou var msg = "Error updating group resource profile. groupResourceProfileId: " + groupResourceProfile.getGroupResourceProfileId(); logger.error(msg, e); - throw convertException(e, msg); + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + ". More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public List getGroupComputeResourcePrefListWithAuth( - AuthzToken authzToken, String groupResourceProfileId) throws AuthorizationException { + AuthzToken authzToken, String groupResourceProfileId) + throws AuthorizationException, AiravataSystemException { try { if (ServerSettings.isEnableSharing()) { var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); if (!userHasAccess(gatewayId, userId + "@" + gatewayId, groupResourceProfileId, gatewayId + ":READ")) { - throw new AuthorizationException( - "User does not have permission to access group resource profile"); + throw new AuthorizationException("User does not have permission to access group resource profile"); } } return getGroupComputeResourcePrefList(groupResourceProfileId); @@ -4429,19 +5722,24 @@ public List getGroupComputeResourcePrefListWithA var msg = "Error retrieving Group compute resource preference. GroupResourceProfileId: " + groupResourceProfileId; logger.error(msg, e); - throw convertException(e, msg); + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + ". More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public List getGroupBatchQueueResourcePolicyListWithAuth( - AuthzToken authzToken, String groupResourceProfileId) throws AuthorizationException { + AuthzToken authzToken, String groupResourceProfileId) + throws AuthorizationException, AiravataSystemException { try { if (ServerSettings.isEnableSharing()) { var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); if (!userHasAccess(gatewayId, userId + "@" + gatewayId, groupResourceProfileId, gatewayId + ":READ")) { - throw new AuthorizationException( - "User does not have permission to access group resource profile"); + throw new AuthorizationException("User does not have permission to access group resource profile"); } } return getGroupBatchQueueResourcePolicyList(groupResourceProfileId); @@ -4451,19 +5749,24 @@ public List getGroupBatchQueueResourcePolicyListWithAu var msg = "Error retrieving Group batch queue resource policy list. GroupResourceProfileId: " + groupResourceProfileId; logger.error(msg, e); - throw convertException(e, msg); + logger.error(msg, e); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + ". More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public List getGroupComputeResourcePolicyListWithAuth( - AuthzToken authzToken, String groupResourceProfileId) throws AuthorizationException { + AuthzToken authzToken, String groupResourceProfileId) + throws AuthorizationException, AiravataSystemException { try { if (ServerSettings.isEnableSharing()) { var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); var userId = authzToken.getClaimsMap().get(Constants.USER_NAME); if (!userHasAccess(gatewayId, userId + "@" + gatewayId, groupResourceProfileId, gatewayId + ":READ")) { - throw new AuthorizationException( - "User does not have permission to access group resource profile"); + throw new AuthorizationException("User does not have permission to access group resource profile"); } } return getGroupComputeResourcePolicyList(groupResourceProfileId); @@ -4473,25 +5776,29 @@ public List getGroupComputeResourcePolicyListWithAuth( var msg = "Error retrieving Group compute resource policy list. GroupResourceProfileId: " + groupResourceProfileId; logger.error(msg, e); - throw convertException(e, msg); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + ". More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public String createGroupResourceProfileWithAuth(AuthzToken authzToken, GroupResourceProfile groupResourceProfile) - throws AuthorizationException { + throws AuthorizationException, AiravataSystemException, InvalidRequestException { try { var result = createGroupResourceProfileWithSharing(authzToken, groupResourceProfile); return result; - } catch (AuthorizationException e) { - var userName = authzToken.getClaimsMap().get(Constants.USER_NAME); - logger.info("User " + userName - + " not allowed access to resources referenced in this GroupResourceProfile. Reason: " - + e.getMessage()); + } catch (AuthorizationException | AiravataSystemException | InvalidRequestException e) { throw e; } catch (Throwable e) { var msg = "Error creating group resource profile."; logger.error(msg, e); - throw convertException(e, msg); + AiravataSystemException exception = new AiravataSystemException(); + exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); + exception.setMessage(msg + ". More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/CredentialStoreService.java b/airavata-api/src/main/java/org/apache/airavata/service/CredentialStoreService.java index 6e0e5a5172..6985f54abd 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/CredentialStoreService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/CredentialStoreService.java @@ -20,10 +20,8 @@ package org.apache.airavata.service; import java.io.ByteArrayInputStream; -import java.io.IOException; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; -import java.sql.SQLException; import java.util.*; import java.util.stream.Collectors; import org.apache.airavata.common.exception.ApplicationSettingsException; @@ -53,8 +51,8 @@ public class CredentialStoreService { private CredentialReaderImpl credentialReader; public CredentialStoreService() - throws ApplicationSettingsException, IllegalAccessException, ClassNotFoundException, InstantiationException, - SQLException, IOException { + throws ApplicationSettingsException, IllegalAccessException, ClassNotFoundException, + InstantiationException { String jdbcUrl = ServerSettings.getCredentialStoreDBURL(); String userName = ServerSettings.getCredentialStoreDBUser(); String password = ServerSettings.getCredentialStoreDBPassword(); @@ -70,15 +68,8 @@ public CredentialStoreService() credentialReader = new CredentialReaderImpl(dbUtil); } - private org.apache.airavata.credential.store.exception.CredentialStoreException convertException(Throwable e, String msg) { - logger.error(msg, e); - org.apache.airavata.credential.store.exception.CredentialStoreException exception = - new org.apache.airavata.credential.store.exception.CredentialStoreException(msg); - exception.initCause(e); - return exception; - } - - public String addSSHCredential(SSHCredential sshCredential) throws org.apache.airavata.credential.store.exception.CredentialStoreException { + public String addSSHCredential(SSHCredential sshCredential) + throws org.apache.airavata.credential.store.exception.CredentialStoreException { try { org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential credential = new org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential(); @@ -104,7 +95,12 @@ public String addSSHCredential(SSHCredential sshCredential) throws org.apache.ai sshCredentialWriter.writeCredentials(credential); return token; } catch (Throwable e) { - throw convertException(e, "Error occurred while saving SSH Credentials."); + logger.error("Error occurred while saving SSH Credentials.", e); + org.apache.airavata.credential.store.exception.CredentialStoreException exception = + new org.apache.airavata.credential.store.exception.CredentialStoreException( + "Error occurred while saving SSH Credentials.. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -135,11 +131,17 @@ public String addCertificateCredential(CertificateCredential certificateCredenti certificateCredentialWriter.writeCredentials(credential); return token; } catch (Throwable e) { - throw convertException(e, "Error occurred while saving Certificate Credentials."); + logger.error("Error occurred while saving Certificate Credentials.", e); + org.apache.airavata.credential.store.exception.CredentialStoreException exception = + new org.apache.airavata.credential.store.exception.CredentialStoreException( + "Error occurred while saving Certificate Credentials.. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public String addPasswordCredential(PasswordCredential passwordCredential) throws org.apache.airavata.credential.store.exception.CredentialStoreException { + public String addPasswordCredential(PasswordCredential passwordCredential) + throws org.apache.airavata.credential.store.exception.CredentialStoreException { try { org.apache.airavata.credential.store.credential.impl.password.PasswordCredential credential = new org.apache.airavata.credential.store.credential.impl.password.PasswordCredential(); @@ -153,11 +155,17 @@ public String addPasswordCredential(PasswordCredential passwordCredential) throw sshCredentialWriter.writeCredentials(credential); return token; } catch (Throwable e) { - throw convertException(e, "Error occurred while saving PWD Credentials."); + logger.error("Error occurred while saving PWD Credentials.", e); + org.apache.airavata.credential.store.exception.CredentialStoreException exception = + new org.apache.airavata.credential.store.exception.CredentialStoreException( + "Error occurred while saving PWD Credentials.. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public SSHCredential getSSHCredential(String tokenId, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException { + public SSHCredential getSSHCredential(String tokenId, String gatewayId) + throws org.apache.airavata.credential.store.exception.CredentialStoreException { try { Credential credential = credentialReader.getCredential(gatewayId, tokenId); if (credential instanceof org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential @@ -183,12 +191,18 @@ public SSHCredential getSSHCredential(String tokenId, String gatewayId) throws o return null; } } catch (Throwable e) { - throw convertException(e, "Error occurred while retrieving SSH credential for token - " + tokenId - + " and gateway id - " + gatewayId); + String msg = "Error occurred while retrieving SSH credential for token - " + tokenId + " and gateway id - " + + gatewayId; + logger.error(msg, e); + org.apache.airavata.credential.store.exception.CredentialStoreException exception = + new org.apache.airavata.credential.store.exception.CredentialStoreException(msg); + exception.initCause(e); + throw exception; } } - public CredentialSummary getCredentialSummary(String tokenId, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException { + public CredentialSummary getCredentialSummary(String tokenId, String gatewayId) + throws org.apache.airavata.credential.store.exception.CredentialStoreException { try { Credential credential = credentialReader.getCredential(gatewayId, tokenId); if (isSSHCredential(credential)) { @@ -202,19 +216,29 @@ public CredentialSummary getCredentialSummary(String tokenId, String gatewayId) return convertToCredentialSummary( (org.apache.airavata.credential.store.credential.impl.password.PasswordCredential) credential); } - throw convertException(new RuntimeException("Unrecognized type of credential for token: " + tokenId), - "Unrecognized type of credential for token: " + tokenId); + String msg = "Unrecognized type of credential for token: " + tokenId; + logger.error(msg, new RuntimeException(msg)); + org.apache.airavata.credential.store.exception.CredentialStoreException exception = + new org.apache.airavata.credential.store.exception.CredentialStoreException(msg); + exception.initCause(new RuntimeException(msg)); + throw exception; } catch (org.apache.airavata.credential.store.exception.CredentialStoreException e) { throw e; } catch (Throwable e) { final String msg = "Error occurred while retrieving credential summary for token - " + tokenId + " and gateway id - " + gatewayId; - throw convertException(e, msg); + logger.error(msg, e); + org.apache.airavata.credential.store.exception.CredentialStoreException exception = + new org.apache.airavata.credential.store.exception.CredentialStoreException( + msg + ". More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public List getAllCredentialSummaries( - SummaryType type, List accessibleTokenIds, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException { + SummaryType type, List accessibleTokenIds, String gatewayId) + throws org.apache.airavata.credential.store.exception.CredentialStoreException { try { List credentials = credentialReader.getAllAccessibleCredentialsPerGateway(gatewayId, accessibleTokenIds); @@ -240,15 +264,24 @@ public List getAllCredentialSummaries( .map(cred -> convertToCredentialSummary(cred)) .collect(Collectors.toList()); } else { - throw convertException(new RuntimeException("Summary Type " + type + " is not supported."), - "Summary Type " + type + " is not supported."); + String msg = "Summary Type " + type + " is not supported."; + logger.error(msg, new RuntimeException(msg)); + org.apache.airavata.credential.store.exception.CredentialStoreException exception = + new org.apache.airavata.credential.store.exception.CredentialStoreException(msg); + exception.initCause(new RuntimeException(msg)); + throw exception; } } catch (org.apache.airavata.credential.store.exception.CredentialStoreException e) { throw e; } catch (Throwable e) { final String msg = "Error occurred while retrieving " + type + " credential Summary for tokens - " + accessibleTokenIds + " and gateway id - " + gatewayId; - throw convertException(e, msg); + logger.error(msg, e); + org.apache.airavata.credential.store.exception.CredentialStoreException exception = + new org.apache.airavata.credential.store.exception.CredentialStoreException( + msg + ". More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -339,12 +372,18 @@ public CertificateCredential getCertificateCredential(String tokenId, String gat return null; } } catch (Throwable e) { - throw convertException(e, "Error occurred while retrieving Certificate credential for token - " - + tokenId + " and gateway id - " + gatewayId); + String msg = "Error occurred while retrieving Certificate credential for token - " + tokenId + + " and gateway id - " + gatewayId; + logger.error(msg, e); + org.apache.airavata.credential.store.exception.CredentialStoreException exception = + new org.apache.airavata.credential.store.exception.CredentialStoreException(msg); + exception.initCause(e); + throw exception; } } - public PasswordCredential getPasswordCredential(String tokenId, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException { + public PasswordCredential getPasswordCredential(String tokenId, String gatewayId) + throws org.apache.airavata.credential.store.exception.CredentialStoreException { try { Credential credential = credentialReader.getCredential(gatewayId, tokenId); if (credential @@ -367,8 +406,13 @@ public PasswordCredential getPasswordCredential(String tokenId, String gatewayId return null; } } catch (Throwable e) { - throw convertException(e, "Error occurred while retrieving PWD credential for token - " + tokenId - + " and gateway id - " + gatewayId); + String msg = "Error occurred while retrieving PWD credential for token - " + tokenId + " and gateway id - " + + gatewayId; + logger.error(msg, e); + org.apache.airavata.credential.store.exception.CredentialStoreException exception = + new org.apache.airavata.credential.store.exception.CredentialStoreException(msg); + exception.initCause(e); + throw exception; } } @@ -402,7 +446,12 @@ public List getAllCredentialSummaryForGateway(SummaryType typ } } } catch (Throwable e) { - throw convertException(e, "Error occurred while retrieving credential Summary"); + logger.error("Error occurred while retrieving credential Summary", e); + org.apache.airavata.credential.store.exception.CredentialStoreException exception = + new org.apache.airavata.credential.store.exception.CredentialStoreException( + "Error occurred while retrieving credential Summary. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } return summaryList; } else { @@ -413,7 +462,8 @@ public List getAllCredentialSummaryForGateway(SummaryType typ @Deprecated public List getAllCredentialSummaryForUserInGateway( - SummaryType type, String gatewayId, String userId) throws org.apache.airavata.credential.store.exception.CredentialStoreException { + SummaryType type, String gatewayId, String userId) + throws org.apache.airavata.credential.store.exception.CredentialStoreException { if (type.equals(SummaryType.SSH)) { Map sshKeyMap = new HashMap<>(); List summaryList = new ArrayList<>(); @@ -453,7 +503,12 @@ public List getAllCredentialSummaryForUserInGateway( } } } catch (Throwable e) { - throw convertException(e, "Error occurred while retrieving credential Summary"); + logger.error("Error occurred while retrieving credential Summary", e); + org.apache.airavata.credential.store.exception.CredentialStoreException exception = + new org.apache.airavata.credential.store.exception.CredentialStoreException( + "Error occurred while retrieving credential Summary. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } return summaryList; } else { @@ -464,7 +519,8 @@ public List getAllCredentialSummaryForUserInGateway( } @Deprecated - public Map getAllPWDCredentialsForGateway(String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException { + public Map getAllPWDCredentialsForGateway(String gatewayId) + throws org.apache.airavata.credential.store.exception.CredentialStoreException { Map pwdCredMap = new HashMap<>(); try { List allCredentials = credentialReader.getAllCredentialsPerGateway(gatewayId); @@ -483,28 +539,45 @@ public Map getAllPWDCredentialsForGateway(String gatewayId) thro } } } catch (Throwable e) { - throw convertException(e, "Error occurred while retrieving credentials"); + logger.error("Error occurred while retrieving credentials", e); + org.apache.airavata.credential.store.exception.CredentialStoreException exception = + new org.apache.airavata.credential.store.exception.CredentialStoreException( + "Error occurred while retrieving credentials. More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } return pwdCredMap; } - public boolean deleteSSHCredential(String tokenId, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException { + public boolean deleteSSHCredential(String tokenId, String gatewayId) + throws org.apache.airavata.credential.store.exception.CredentialStoreException { try { credentialReader.removeCredentials(gatewayId, tokenId); return true; } catch (Throwable e) { - throw convertException(e, "Error occurred while deleting SSH credential for token - " + tokenId - + " and gateway id - " + gatewayId); + String msg = "Error occurred while deleting SSH credential for token - " + tokenId + " and gateway id - " + + gatewayId; + logger.error(msg, e); + org.apache.airavata.credential.store.exception.CredentialStoreException exception = + new org.apache.airavata.credential.store.exception.CredentialStoreException(msg); + exception.initCause(e); + throw exception; } } - public boolean deletePWDCredential(String tokenId, String gatewayId) throws org.apache.airavata.credential.store.exception.CredentialStoreException { + public boolean deletePWDCredential(String tokenId, String gatewayId) + throws org.apache.airavata.credential.store.exception.CredentialStoreException { try { credentialReader.removeCredentials(gatewayId, tokenId); return true; } catch (Throwable e) { - throw convertException(e, "Error occurred while deleting PWD credential for token - " + tokenId - + " and gateway id - " + gatewayId); + String msg = "Error occurred while deleting PWD credential for token - " + tokenId + " and gateway id - " + + gatewayId; + logger.error(msg, e); + org.apache.airavata.credential.store.exception.CredentialStoreException exception = + new org.apache.airavata.credential.store.exception.CredentialStoreException(msg); + exception.initCause(e); + throw exception; } } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/GroupManagerService.java b/airavata-api/src/main/java/org/apache/airavata/service/GroupManagerService.java index c76dbffe55..b736a3f604 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/GroupManagerService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/GroupManagerService.java @@ -46,14 +46,6 @@ public class GroupManagerService { private static final Logger logger = LoggerFactory.getLogger(GroupManagerService.class); private UserProfileRepository userProfileRepository = new UserProfileRepository(); - private GroupManagerServiceException convertException(Throwable e, String msg) { - logger.error(msg, e); - var exception = new GroupManagerServiceException(); - exception.setMessage(msg + ". More info : " + e.getMessage()); - exception.initCause(e); - return exception; - } - public String createGroup(AuthzToken authzToken, GroupModel groupModel) throws GroupManagerServiceException { try { // TODO Validations for authorization diff --git a/airavata-api/src/main/java/org/apache/airavata/service/IamAdminService.java b/airavata-api/src/main/java/org/apache/airavata/service/IamAdminService.java index 9c89f5bb2a..b3d79e3187 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/IamAdminService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/IamAdminService.java @@ -52,13 +52,6 @@ public class IamAdminService { private UserProfileRepository userProfileRepository = new UserProfileRepository(); private DBEventPublisherUtils dbEventPublisherUtils = new DBEventPublisherUtils(DBEventService.IAM_ADMIN); - private IamAdminServicesException convertException(Throwable e, String msg) { - logger.error(msg, e); - var exception = new IamAdminServicesException(msg + ". More info : " + e.getMessage()); - exception.initCause(e); - return exception; - } - public Gateway setUpGateway(AuthzToken authzToken, Gateway gateway) throws IamAdminServicesException { var keycloakclient = new TenantManagementKeycloakImpl(); var isSuperAdminCredentials = getSuperAdminPasswordCredential(); @@ -79,7 +72,8 @@ public Gateway setUpGateway(AuthzToken authzToken, Gateway gateway) throws IamAd return gatewayWithIdAndSecret; } catch (TException | ApplicationSettingsException ex) { logger.error("Gateway Setup Failed, reason: " + ex.getMessage(), ex); - var iamAdminServicesException = new IamAdminServicesException("Gateway Setup Failed, reason: " + ex.getMessage()); + var iamAdminServicesException = + new IamAdminServicesException("Gateway Setup Failed, reason: " + ex.getMessage()); iamAdminServicesException.initCause(ex); throw iamAdminServicesException; } @@ -93,7 +87,11 @@ public boolean isUsernameAvailable(AuthzToken authzToken, String username) throw } catch (IamAdminServicesException e) { throw e; } catch (Throwable ex) { - throw convertException(ex, "Error while checking username availability"); + logger.error("Error while checking username availability", ex); + var exception = new IamAdminServicesException( + "Error while checking username availability. More info : " + ex.getMessage()); + exception.initCause(ex); + throw exception; } } @@ -252,7 +250,11 @@ public void updateUserProfile(AuthzToken authzToken, UserProfile userDetails) th } catch (IamAdminServicesException e) { throw e; } catch (Throwable ex) { - throw convertException(ex, "Error while updating user profile"); + logger.error("Error while updating user profile", ex); + var exception = + new IamAdminServicesException("Error while updating user profile. More info : " + ex.getMessage()); + exception.initCause(ex); + throw exception; } } @@ -264,7 +266,10 @@ public boolean deleteUser(AuthzToken authzToken, String username) throws IamAdmi } catch (IamAdminServicesException e) { throw e; } catch (Throwable ex) { - throw convertException(ex, "Error while deleting user"); + logger.error("Error while deleting user", ex); + var exception = new IamAdminServicesException("Error while deleting user. More info : " + ex.getMessage()); + exception.initCause(ex); + throw exception; } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorRegistryService.java b/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorRegistryService.java index b6bd6bfd8d..84fc9c44fe 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorRegistryService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorRegistryService.java @@ -72,7 +72,8 @@ public ExperimentStatus getExperimentStatus(String airavataExperimentId) throws return registryService.getExperimentStatus(airavataExperimentId); } - public void updateExperimentStatus(ExperimentStatus experimentStatus, String experimentId) throws RegistryServiceException { + public void updateExperimentStatus(ExperimentStatus experimentStatus, String experimentId) + throws RegistryServiceException { registryService.updateExperimentStatus(experimentStatus, experimentId); } @@ -104,7 +105,8 @@ public List getApplicationOutputs(String appInterfaceId) t return registryService.getApplicationOutputs(appInterfaceId); } - public ApplicationInterfaceDescription getApplicationInterface(String appInterfaceId) throws RegistryServiceException { + public ApplicationInterfaceDescription getApplicationInterface(String appInterfaceId) + throws RegistryServiceException { return registryService.getApplicationInterface(appInterfaceId); } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorService.java b/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorService.java index 409890a74f..3360343027 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorService.java @@ -22,13 +22,20 @@ import java.lang.reflect.InvocationTargetException; import java.text.MessageFormat; import java.util.*; +import org.apache.airavata.common.exception.AiravataException; +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.logging.MDCConstants; import org.apache.airavata.common.logging.MDCUtil; import org.apache.airavata.common.utils.AiravataUtils; import org.apache.airavata.common.utils.ServerSettings; import org.apache.airavata.common.utils.ThriftUtils; import org.apache.airavata.common.utils.ZkConstants; import org.apache.airavata.messaging.core.MessageContext; +import org.apache.airavata.messaging.core.MessageHandler; +import org.apache.airavata.messaging.core.MessagingFactory; import org.apache.airavata.messaging.core.Publisher; +import org.apache.airavata.messaging.core.Subscriber; +import org.apache.airavata.messaging.core.Type; import org.apache.airavata.metascheduler.core.api.ProcessScheduler; import org.apache.airavata.metascheduler.process.scheduling.api.ProcessSchedulerImpl; import org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription; @@ -44,9 +51,11 @@ import org.apache.airavata.model.data.replica.ReplicaLocationCategory; import org.apache.airavata.model.error.ExperimentNotFoundException; import org.apache.airavata.model.error.LaunchValidationException; +import org.apache.airavata.model.error.ValidationResults; import org.apache.airavata.model.experiment.ExperimentModel; import org.apache.airavata.model.experiment.ExperimentType; import org.apache.airavata.model.experiment.UserConfigurationDataModel; +import org.apache.airavata.model.messaging.event.*; import org.apache.airavata.model.process.ProcessModel; import org.apache.airavata.model.scheduling.ComputationalResourceSchedulingModel; import org.apache.airavata.model.status.ExperimentState; @@ -62,24 +71,15 @@ import org.apache.airavata.orchestrator.cpi.impl.SimpleOrchestratorImpl; import org.apache.airavata.registry.api.exception.RegistryServiceException; import org.apache.commons.lang3.StringUtils; +import org.apache.curator.RetryPolicy; import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.framework.CuratorFrameworkFactory; +import org.apache.curator.retry.ExponentialBackoffRetry; import org.apache.curator.utils.ZKPaths; import org.apache.thrift.TException; import org.apache.zookeeper.data.Stat; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import org.apache.airavata.common.exception.ApplicationSettingsException; -import org.apache.airavata.common.exception.AiravataException; -import org.apache.airavata.common.logging.MDCConstants; -import org.apache.airavata.messaging.core.MessageHandler; -import org.apache.airavata.messaging.core.MessagingFactory; -import org.apache.airavata.messaging.core.Subscriber; -import org.apache.airavata.messaging.core.Type; -import org.apache.airavata.model.messaging.event.*; -import org.apache.curator.RetryPolicy; -import org.apache.curator.framework.CuratorFrameworkFactory; -import org.apache.curator.retry.ExponentialBackoffRetry; import org.slf4j.MDC; public class OrchestratorService { @@ -119,14 +119,22 @@ public OrchestratorService( this.publisher = publisher; } - public boolean launchExperiment(String experimentId, String gatewayId) throws Exception { + public boolean launchExperiment(String experimentId, String gatewayId) + throws ExperimentNotFoundException, OrchestratorException, RegistryServiceException, + LaunchValidationException { String experimentNodePath = getExperimentNodePath(experimentId); - ZKPaths.mkdirs(curatorClient.getZookeeperClient().getZooKeeper(), experimentNodePath); - String experimentCancelNode = ZKPaths.makePath(experimentNodePath, ZkConstants.ZOOKEEPER_CANCEL_LISTENER_NODE); - ZKPaths.mkdirs(curatorClient.getZookeeperClient().getZooKeeper(), experimentCancelNode); + try { + ZKPaths.mkdirs(curatorClient.getZookeeperClient().getZooKeeper(), experimentNodePath); + String experimentCancelNode = + ZKPaths.makePath(experimentNodePath, ZkConstants.ZOOKEEPER_CANCEL_LISTENER_NODE); + ZKPaths.mkdirs(curatorClient.getZookeeperClient().getZooKeeper(), experimentCancelNode); + } catch (Exception e) { + throw new OrchestratorException("Error creating ZooKeeper nodes for experiment: " + experimentId, e); + } ExperimentModel experiment = orchestratorRegistryService.getExperiment(experimentId); if (experiment == null) { - throw new ExperimentNotFoundException("Error retrieving the Experiment by the given experimentID: " + experimentId); + throw new ExperimentNotFoundException( + "Error retrieving the Experiment by the given experimentID: " + experimentId); } UserConfigurationDataModel userConfigurationData = experiment.getUserConfigurationData(); @@ -151,7 +159,8 @@ public boolean launchExperiment(String experimentId, String gatewayId) throws Ex } private boolean launchSingleAppExperiment( - ExperimentModel experiment, String experimentId, String gatewayId, String token) throws Exception { + ExperimentModel experiment, String experimentId, String gatewayId, String token) + throws OrchestratorException, RegistryServiceException, LaunchValidationException { List processes = orchestrator.createProcesses(experimentId, gatewayId); for (ProcessModel processModel : processes) { @@ -166,7 +175,13 @@ private boolean launchSingleAppExperiment( if (!experiment.getUserConfigurationData().isAiravataAutoSchedule() && !validateProcess(experimentId, processes)) { - throw new Exception("Validating process fails for given experiment Id : " + experimentId); + LaunchValidationException exception = new LaunchValidationException(); + ValidationResults validationResults = new ValidationResults(); + validationResults.setValidationState(false); + validationResults.setValidationResultList(new ArrayList<>()); + exception.setValidationResult(validationResults); + exception.setErrorMessage("Validating process fails for given experiment Id : " + experimentId); + throw exception; } ProcessScheduler scheduler = new ProcessSchedulerImpl(); @@ -184,53 +199,44 @@ private boolean launchSingleAppExperiment( } } - private void resolveInputReplicas(ProcessModel processModel) throws Exception { + private void resolveInputReplicas(ProcessModel processModel) throws RegistryServiceException { for (var pi : processModel.getProcessInputs()) { if (pi.getType().equals(DataType.URI) && pi.getValue() != null && pi.getValue().startsWith("airavata-dp://")) { - try { - DataProductModel dataProductModel = orchestratorRegistryService.getDataProduct(pi.getValue()); - Optional 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 { - logger.error("Could not find a replica for the URI " + pi.getValue()); - } - } catch (RegistryServiceException e) { - throw new Exception("Error while launching experiment", e); + DataProductModel dataProductModel = orchestratorRegistryService.getDataProduct(pi.getValue()); + Optional 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 { + logger.error("Could not find a replica for the URI " + pi.getValue()); } } else if (pi.getType().equals(DataType.URI_COLLECTION) && pi.getValue() != null && pi.getValue().contains("airavata-dp://")) { - try { - String[] uriList = pi.getValue().split(","); - final ArrayList filePathList = new ArrayList<>(); - for (String uri : uriList) { - if (uri.startsWith("airavata-dp://")) { - DataProductModel dataProductModel = orchestratorRegistryService.getDataProduct(uri); - Optional rpLocation = - dataProductModel.getReplicaLocations().stream() - .filter(rpModel -> rpModel.getReplicaLocationCategory() - .equals(ReplicaLocationCategory.GATEWAY_DATA_STORE)) - .findFirst(); - if (rpLocation.isPresent()) { - filePathList.add(rpLocation.get().getFilePath()); - } else { - logger.error("Could not find a replica for the URI " + pi.getValue()); - } + String[] uriList = pi.getValue().split(","); + final ArrayList filePathList = new ArrayList<>(); + for (String uri : uriList) { + if (uri.startsWith("airavata-dp://")) { + DataProductModel dataProductModel = orchestratorRegistryService.getDataProduct(uri); + Optional rpLocation = dataProductModel.getReplicaLocations().stream() + .filter(rpModel -> rpModel.getReplicaLocationCategory() + .equals(ReplicaLocationCategory.GATEWAY_DATA_STORE)) + .findFirst(); + if (rpLocation.isPresent()) { + filePathList.add(rpLocation.get().getFilePath()); } else { - filePathList.add(uri); + logger.error("Could not find a replica for the URI " + pi.getValue()); } + } else { + filePathList.add(uri); } - pi.setValue(StringUtils.join(filePathList, ',')); - } catch (RegistryServiceException e) { - throw new Exception("Error while launching experiment", e); } + pi.setValue(StringUtils.join(filePathList, ',')); } } } @@ -291,12 +297,14 @@ public boolean validateProcess(String experimentId, List processes return true; } - public boolean terminateExperiment(String experimentId, String gatewayId) throws RegistryServiceException, OrchestratorException { + public boolean terminateExperiment(String experimentId, String gatewayId) + throws RegistryServiceException, OrchestratorException { logger.info(experimentId, "Experiment: {} is cancelling !!!!!", experimentId); return validateStatesAndCancel(experimentId, gatewayId); } - private boolean validateStatesAndCancel(String experimentId, String gatewayId) throws RegistryServiceException, OrchestratorException { + private boolean validateStatesAndCancel(String experimentId, String gatewayId) + throws RegistryServiceException, OrchestratorException { ExperimentStatus experimentStatus = orchestratorRegistryService.getExperimentStatus(experimentId); switch (experimentStatus.getState()) { case COMPLETED: @@ -343,7 +351,8 @@ private boolean validateStatesAndCancel(String experimentId, String gatewayId) t stat = curatorClient.checkExists().forPath(expCancelNodePath); } catch (Exception e) { logger.error("Error checking existence of Zookeeper node: " + expCancelNodePath, e); - throw new OrchestratorException("Error checking existence of Zookeeper node: " + expCancelNodePath, e); + throw new OrchestratorException( + "Error checking existence of Zookeeper node: " + expCancelNodePath, e); } if (stat != null) { try { @@ -353,7 +362,8 @@ private boolean validateStatesAndCancel(String experimentId, String gatewayId) t .forPath(expCancelNodePath, ZkConstants.ZOOKEEPER_CANCEL_REQEUST.getBytes()); } catch (Exception e) { logger.error("Error setting data for Zookeeper node: " + expCancelNodePath, e); - throw new OrchestratorException("Error setting data for Zookeeper node: " + expCancelNodePath, e); + throw new OrchestratorException( + "Error setting data for Zookeeper node: " + expCancelNodePath, e); } ExperimentStatus status = new ExperimentStatus(ExperimentState.CANCELING); status.setReason("Experiment cancel request processed"); @@ -420,7 +430,8 @@ private void submitIntermediateOutputsProcess(String experimentId, String gatewa } } - public boolean launchProcess(String processId, String airavataCredStoreToken, String gatewayId) throws RegistryServiceException, OrchestratorException { + public boolean launchProcess(String processId, String airavataCredStoreToken, String gatewayId) + throws RegistryServiceException, OrchestratorException { ProcessStatus processStatus = orchestratorRegistryService.getProcessStatus(processId); switch (processStatus.getState()) { @@ -478,10 +489,15 @@ private ApplicationDeploymentDescription getAppDeploymentForModule( Arrays.asList(deploymentMap.keySet().toArray(new ComputeResourceDescription[] {})); HostScheduler hostScheduler; try { - var schedulerClass = Class.forName(ServerSettings.getHostScheduler()).asSubclass(HostScheduler.class); + var schedulerClass = + Class.forName(ServerSettings.getHostScheduler()).asSubclass(HostScheduler.class); hostScheduler = schedulerClass.getDeclaredConstructor().newInstance(); - } catch (ClassNotFoundException | ApplicationSettingsException | NoSuchMethodException - | InstantiationException | IllegalAccessException | InvocationTargetException e) { + } catch (ClassNotFoundException + | ApplicationSettingsException + | NoSuchMethodException + | InstantiationException + | IllegalAccessException + | InvocationTargetException e) { throw new OrchestratorException("Failed to instantiate HostScheduler", e); } ComputeResourceDescription ComputeResourceDescription = hostScheduler.schedule(computeHostList); @@ -504,7 +520,8 @@ private void launchWorkflowExperiment(String experimentId, String airavataCredSt throw new UnsupportedOperationException("Workflow support not implemented"); } - public void createAndValidateTasks(ExperimentModel experiment, boolean recreateTaskDag) throws Exception { + public void createAndValidateTasks(ExperimentModel experiment, boolean recreateTaskDag) + throws OrchestratorException, RegistryServiceException, LaunchValidationException { if (experiment.getUserConfigurationData().isAiravataAutoSchedule()) { List processModels = orchestratorRegistryService.getProcessList(experiment.getExperimentId()); for (ProcessModel processModel : processModels) { @@ -516,8 +533,14 @@ public void createAndValidateTasks(ExperimentModel experiment, boolean recreateT } } if (!validateProcess(experiment.getExperimentId(), processModels)) { - throw new Exception( + LaunchValidationException exception = new LaunchValidationException(); + ValidationResults validationResults = new ValidationResults(); + validationResults.setValidationState(false); + validationResults.setValidationResultList(new ArrayList<>()); + exception.setValidationResult(validationResults); + exception.setErrorMessage( "Validating process fails for given experiment Id : " + experiment.getExperimentId()); + throw exception; } } } @@ -531,7 +554,8 @@ public String getExperimentNodePath(String experimentId) { } public boolean launchSingleAppExperimentInternal( - String experimentId, String airavataCredStoreToken, String gatewayId) throws Exception { + String experimentId, String airavataCredStoreToken, String gatewayId) + throws RegistryServiceException, OrchestratorException { try { List processIds = orchestratorRegistryService.getProcessIds(experimentId); for (String processId : processIds) { @@ -543,8 +567,8 @@ public boolean launchSingleAppExperimentInternal( status.setReason("Error while retrieving process IDs"); updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); logger.error("expId: " + experimentId + ", Error while retrieving process IDs", e); - throw new Exception("Error while retrieving process IDs", e); - } catch (Exception e) { + throw e; + } catch (OrchestratorException e) { ExperimentStatus status = new ExperimentStatus(ExperimentState.FAILED); status.setReason("Error while launching processes"); updateAndPublishExperimentStatus(experimentId, status, publisher, gatewayId); @@ -553,10 +577,13 @@ public boolean launchSingleAppExperimentInternal( } } - public void launchQueuedExperiment(String experimentId) throws Exception { + public void launchQueuedExperiment(String experimentId) + throws ExperimentNotFoundException, OrchestratorException, RegistryServiceException, + LaunchValidationException { ExperimentModel experiment = orchestratorRegistryService.getExperiment(experimentId); if (experiment == null) { - throw new ExperimentNotFoundException("Error retrieving the Experiment by the given experimentID: " + experimentId); + throw new ExperimentNotFoundException( + "Error retrieving the Experiment by the given experimentID: " + experimentId); } UserConfigurationDataModel userConfigurationData = experiment.getUserConfigurationData(); @@ -575,7 +602,9 @@ public void launchQueuedExperiment(String experimentId) throws Exception { } public void handleProcessStatusChange( - ProcessStatusChangeEvent processStatusChangeEvent, ProcessIdentifier processIdentity) throws Exception { + ProcessStatusChangeEvent processStatusChangeEvent, ProcessIdentifier processIdentity) + throws ExperimentNotFoundException, OrchestratorException, RegistryServiceException, + LaunchValidationException { ExperimentStatus status = new ExperimentStatus(); // Check if this is an intermediate output fetching process @@ -684,7 +713,9 @@ private void registerQueueStatusForRequeue(String experimentId) { } } - public void handleLaunchExperiment(ExperimentSubmitEvent expEvent) throws Exception { + public void handleLaunchExperiment(ExperimentSubmitEvent expEvent) + throws ExperimentNotFoundException, OrchestratorException, RegistryServiceException, + LaunchValidationException { ExperimentModel experimentModel = orchestratorRegistryService.getExperiment(expEvent.getExperimentId()); if (experimentModel.getExperimentStatus().get(0).getState() == ExperimentState.CREATED) { launchExperiment(expEvent.getExperimentId(), expEvent.getGatewayId()); @@ -694,7 +725,9 @@ public void handleLaunchExperiment(ExperimentSubmitEvent expEvent) throws Except /** * Handle launch experiment from message context with deserialization and redelivery checks */ - public void handleLaunchExperimentFromMessage(MessageContext messageContext) throws Exception { + public void handleLaunchExperimentFromMessage(MessageContext messageContext) + throws ExperimentNotFoundException, OrchestratorException, RegistryServiceException, + LaunchValidationException, TException { ExperimentSubmitEvent expEvent = new ExperimentSubmitEvent(); byte[] bytes = ThriftUtils.serializeThriftObject(messageContext.getEvent()); ThriftUtils.createThriftFromBytes(bytes, expEvent); @@ -710,7 +743,8 @@ public void handleLaunchExperimentFromMessage(MessageContext messageContext) thr } } - public void handleCancelExperiment(ExperimentSubmitEvent expEvent) throws Exception { + public void handleCancelExperiment(ExperimentSubmitEvent expEvent) + throws RegistryServiceException, OrchestratorException { terminateExperiment(expEvent.getExperimentId(), expEvent.getGatewayId()); } @@ -846,13 +880,15 @@ private Subscriber getExperimentSubscriber() throws AiravataException { // throw new RuntimeException("Error while updating experiment status", e); // } catch (Throwable e) { // logger.error( - // "Message Id : " + message.getMessageId() + ", Message type : " + message.getType() + "Error" + // "Message Id : " + message.getMessageId() + ", Message type : " + message.getType() + + // "Error" // + " while prcessing process status change event", // e); // throw new RuntimeException("Error while updating experiment status", e); // } // } else { - // System.out.println("Message Recieved with message id " + message.getMessageId() + " and with message " + // System.out.println("Message Recieved with message id " + message.getMessageId() + " and with message + // " // + "type " + message.getType().name()); // } // } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/RegistryService.java b/airavata-api/src/main/java/org/apache/airavata/service/RegistryService.java index 419fc6f2b0..71f449bf3d 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/RegistryService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/RegistryService.java @@ -61,6 +61,7 @@ import org.apache.airavata.model.workspace.GatewayUsageReportingCommand; import org.apache.airavata.model.workspace.Notification; import org.apache.airavata.model.workspace.Project; +import org.apache.airavata.registry.api.exception.RegistryServiceException; import org.apache.airavata.registry.core.entities.expcatalog.JobPK; import org.apache.airavata.registry.core.repositories.appcatalog.*; import org.apache.airavata.registry.core.repositories.appcatalog.GroupResourceProfileRepository; @@ -73,7 +74,6 @@ import org.apache.airavata.registry.cpi.*; import org.apache.airavata.registry.cpi.ExpCatChildDataType; import org.apache.airavata.registry.cpi.WorkflowCatalogException; -import org.apache.airavata.registry.api.exception.RegistryServiceException; import org.apache.airavata.registry.cpi.utils.Constants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -81,14 +81,6 @@ public class RegistryService { private static final Logger logger = LoggerFactory.getLogger(RegistryService.class); - private RegistryServiceException convertException(Throwable e, String msg) { - logger.error(msg, e); - var exception = new RegistryServiceException(); - exception.setMessage(msg + " More info : " + e.getMessage()); - exception.initCause(e); - return exception; - } - private ApplicationDeploymentRepository applicationDeploymentRepository = new ApplicationDeploymentRepository(); private ApplicationInterfaceRepository applicationInterfaceRepository = new ApplicationInterfaceRepository(); private StorageResourceRepository storageResourceRepository = new StorageResourceRepository(); @@ -133,7 +125,11 @@ public boolean isUserExists(String gatewayId, String userName) throws RegistrySe try { return userRepository.isUserExists(gatewayId, userName); } catch (Throwable e) { - throw convertException(e, "Error while verifying user"); + logger.error("Error while verifying user", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while verifying user More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -141,7 +137,11 @@ public List getAllUsersInGateway(String gatewayId) throws RegistryServic try { return userRepository.getAllUsernamesInGateway(gatewayId); } catch (Throwable e) { - throw convertException(e, "Error while retrieving users"); + logger.error("Error while retrieving users", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving users More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -149,13 +149,18 @@ public Gateway getGateway(String gatewayId) throws RegistryServiceException { try { if (!gatewayRepository.isGatewayExist(gatewayId)) { logger.error("Gateway does not exist in the system. Please provide a valid gateway ID..."); - throw new RegistryException("Gateway does not exist in the system. Please provide a valid gateway ID..."); + throw new RegistryException( + "Gateway does not exist in the system. Please provide a valid gateway ID..."); } var gateway = gatewayRepository.getGateway(gatewayId); logger.debug("Airavata retrieved gateway with gateway id : " + gateway.getGatewayId()); return gateway; } catch (Throwable e) { - throw convertException(e, "Error while getting the gateway"); + logger.error("Error while getting the gateway", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while getting the gateway More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -163,13 +168,18 @@ public boolean deleteGateway(String gatewayId) throws RegistryServiceException { try { if (!gatewayRepository.isGatewayExist(gatewayId)) { logger.error("Gateway does not exist in the system. Please provide a valid gateway ID..."); - throw new RegistryException("Gateway does not exist in the system. Please provide a valid gateway ID..."); + throw new RegistryException( + "Gateway does not exist in the system. Please provide a valid gateway ID..."); } gatewayRepository.removeGateway(gatewayId); logger.debug("Airavata deleted gateway with gateway id : " + gatewayId); return true; } catch (Throwable e) { - throw convertException(e, "Error while deleting the gateway"); + logger.error("Error while deleting the gateway", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while deleting the gateway More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -179,7 +189,11 @@ public List getAllGateways() throws RegistryServiceException { logger.debug("Airavata retrieved all available gateways..."); return gateways; } catch (Throwable e) { - throw convertException(e, "Error while getting all the gateways"); + 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()); + exception.initCause(e); + throw exception; } } @@ -187,7 +201,11 @@ public boolean isGatewayExist(String gatewayId) throws RegistryServiceException try { return gatewayRepository.isGatewayExist(gatewayId); } catch (Throwable e) { - throw convertException(e, "Error while checking if gateway exists"); + logger.error("Error while checking if gateway exists", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while checking if gateway exists More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -196,7 +214,11 @@ public boolean deleteNotification(String gatewayId, String notificationId) throw notificationRepository.deleteNotification(notificationId); return true; } catch (Throwable e) { - throw convertException(e, "Error while deleting notification"); + logger.error("Error while deleting notification", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while deleting notification More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -204,7 +226,11 @@ public Notification getNotification(String gatewayId, String notificationId) thr try { return notificationRepository.getNotification(notificationId); } catch (Throwable e) { - throw convertException(e, "Error while retrieving notification"); + logger.error("Error while retrieving notification", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving notification More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -213,7 +239,11 @@ public List getAllNotifications(String gatewayId) throws RegistryS List notifications = notificationRepository.getAllGatewayNotifications(gatewayId); return notifications; } catch (Throwable e) { - throw convertException(e, "Error while getting all notifications"); + logger.error("Error while getting all notifications", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while getting all notifications More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -231,7 +261,11 @@ public Project getProject(String projectId) throws RegistryServiceException, Pro } catch (ProjectNotFoundException e) { throw e; } catch (Throwable e) { - throw convertException(e, "Error while retrieving the project"); + logger.error("Error while retrieving the project", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving the project More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -249,7 +283,11 @@ public boolean deleteProject(String projectId) throws RegistryServiceException, } catch (ProjectNotFoundException e) { throw e; } catch (Throwable e) { - throw convertException(e, "Error while removing the project"); + logger.error("Error while removing the project", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while removing the project More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -273,11 +311,19 @@ public List getUserProjects(String gatewayId, String userName, int limi filters.put(Constants.FieldConstants.ProjectConstants.OWNER, userName); filters.put(Constants.FieldConstants.ProjectConstants.GATEWAY_ID, gatewayId); projects = projectRepository.searchProjects( - filters, limit, offset, Constants.FieldConstants.ProjectConstants.CREATION_TIME, ResultOrderType.DESC); + filters, + limit, + offset, + Constants.FieldConstants.ProjectConstants.CREATION_TIME, + ResultOrderType.DESC); logger.debug("Airavata retrieved projects for user : " + userName + " and gateway id : " + gatewayId); return projects; } catch (Throwable e) { - throw convertException(e, "Error while retrieving projects"); + logger.error("Error while retrieving projects", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving projects More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -311,14 +357,18 @@ public ExperimentStatistics getExperimentStatistics( filters.put(Constants.FieldConstants.ExperimentConstants.RESOURCE_HOST_ID, resourceHostName); } limit = Math.min(limit, 1000); - ExperimentStatistics result = - experimentSummaryRepository.getAccessibleExperimentStatistics(accessibleExpIds, filters, limit, offset); + ExperimentStatistics result = experimentSummaryRepository.getAccessibleExperimentStatistics( + accessibleExpIds, filters, limit, offset); logger.debug("Airavata retrieved experiments for gateway id : " + gatewayId + " between : " + org.apache.airavata.common.utils.AiravataUtils.getTime(fromTime) + " and " + org.apache.airavata.common.utils.AiravataUtils.getTime(toTime)); return result; } catch (Throwable e) { - throw convertException(e, "Error while getting experiment statistics"); + logger.error("Error while getting experiment statistics", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while getting experiment statistics More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -335,7 +385,8 @@ public List getExperimentsInProject(String gatewayId, String pr } if (!projectRepository.isProjectExist(projectId)) { logger.error("Project does not exist in the system. Please provide a valid project ID..."); - throw new RegistryException("Project does not exist in the system. Please provide a valid project ID..."); + throw new RegistryException( + "Project does not exist in the system. Please provide a valid project ID..."); } List experiments = experimentRepository.getExperimentList( gatewayId, @@ -348,7 +399,11 @@ public List getExperimentsInProject(String gatewayId, String pr logger.debug("Airavata retrieved experiments for project : " + projectId); return experiments; } catch (Throwable e) { - throw convertException(e, "Error while retrieving the experiments"); + logger.error("Error while retrieving the experiments", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving the experiments More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -379,25 +434,35 @@ public List getUserExperiments(String gatewayId, String userNam logger.debug("Airavata retrieved experiments for user : " + userName); return experiments; } catch (Throwable e) { - throw convertException(e, "Error while retrieving the experiments"); + logger.error("Error while retrieving the experiments", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving the experiments More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean deleteExperiment(String experimentId) throws RegistryServiceException { try { if (!experimentRepository.isExperimentExist(experimentId)) { - throw new RegistryException("Requested experiment id " + experimentId + " does not exist in the system.."); + throw new RegistryException( + "Requested experiment id " + experimentId + " does not exist in the system.."); } ExperimentModel experimentModel = experimentRepository.getExperiment(experimentId); if (!(experimentModel.getExperimentStatus().get(0).getState() == ExperimentState.CREATED)) { logger.error("Error while deleting the experiment"); - throw new RegistryException("Experiment is not in CREATED state. Hence cannot deleted. ID:" + experimentId); + throw new RegistryException( + "Experiment is not in CREATED state. Hence cannot deleted. ID:" + experimentId); } experimentRepository.removeExperiment(experimentId); logger.debug("Airavata removed experiment with experiment id : " + experimentId); return true; } catch (Throwable e) { - throw convertException(e, "Error while deleting the experiment"); + logger.error("Error while deleting the experiment", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while deleting the experiment More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -409,7 +474,11 @@ private ExperimentModel getExperimentInternal(String airavataExperimentId) throw } return experimentRepository.getExperiment(airavataExperimentId); } catch (Throwable e) { - throw convertException(e, "Error while retrieving the experiment"); + logger.error("Error while retrieving the experiment", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving the experiment More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -447,7 +516,11 @@ public int compare(JobModel o1, JobModel o2) { logger.debug("Airavata retrieved detailed experiment with experiment id : " + airavataExperimentId); return experimentModel; } catch (Throwable e) { - throw convertException(e, "Error while retrieving the experiment"); + logger.error("Error while retrieving the experiment", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving the experiment More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -463,7 +536,11 @@ private ExperimentStatus getExperimentStatusInternal(String airavataExperimentId } return experimentStatusRepository.getExperimentStatus(airavataExperimentId); } catch (Throwable e) { - throw convertException(e, "Error while retrieving experiment status"); + logger.error("Error while retrieving experiment status", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving experiment status More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -473,11 +550,16 @@ public ExperimentStatus getExperimentStatus(String airavataExperimentId) throws logger.debug("Airavata retrieved experiment status for experiment id : " + airavataExperimentId); return experimentStatus; } catch (Throwable e) { - throw convertException(e, "Error while retrieving experiment status"); + logger.error("Error while retrieving experiment status", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving experiment status More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public List getExperimentOutputs(String airavataExperimentId) throws RegistryServiceException { + public List getExperimentOutputs(String airavataExperimentId) + throws RegistryServiceException { try { if (!experimentRepository.isExperimentExist(airavataExperimentId)) { logger.error( @@ -490,19 +572,26 @@ public List getExperimentOutputs(String airavataExperiment logger.debug("Airavata retrieved experiment outputs for experiment id : " + airavataExperimentId); return experimentOutputRepository.getExperimentOutputs(airavataExperimentId); } catch (Throwable e) { - throw convertException(e, "Error while retrieving the experiment outputs"); + logger.error("Error while retrieving the experiment outputs", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving the experiment outputs More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public void updateJobStatus(JobStatus jobStatus, String taskId, String jobId) throws RegistryServiceException { try { - var jobPK = - new org.apache.airavata.registry.core.entities.expcatalog.JobPK(); + var jobPK = new org.apache.airavata.registry.core.entities.expcatalog.JobPK(); jobPK.setTaskId(taskId); jobPK.setJobId(jobId); jobStatusRepository.updateJobStatus(jobStatus, jobPK); } catch (Throwable e) { - throw convertException(e, "Error while updating job status"); + logger.error("Error while updating job status", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while updating job status More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -510,7 +599,11 @@ public void addJob(JobModel jobModel, String processId) throws RegistryServiceEx try { jobRepository.addJob(jobModel, processId); } catch (Throwable e) { - throw convertException(e, "Error while adding job"); + logger.error("Error while adding job", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while adding job More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -521,7 +614,11 @@ public String addProcess(ProcessModel processModel, String experimentId) throws try { return processRepository.addProcess(processModel, experimentId); } catch (Throwable e) { - throw convertException(e, "Error while adding process"); + logger.error("Error while adding process", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while adding process More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -529,7 +626,11 @@ public void updateProcess(ProcessModel processModel, String processId) throws Re try { processRepository.updateProcess(processModel, processId); } catch (Throwable e) { - throw convertException(e, "Error while updating process"); + logger.error("Error while updating process", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while updating process More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -537,7 +638,11 @@ public String addTask(TaskModel taskModel, String processId) throws RegistryServ try { return taskRepository.addTask(taskModel, processId); } catch (Throwable e) { - throw convertException(e, "Error while adding task"); + logger.error("Error while adding task", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while adding task More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -545,7 +650,11 @@ public void deleteTasks(String processId) throws RegistryServiceException { try { taskRepository.deleteTasks(processId); } catch (Throwable e) { - throw convertException(e, "Error while deleting tasks"); + logger.error("Error while deleting tasks", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while deleting tasks More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -553,7 +662,11 @@ public UserConfigurationDataModel getUserConfigurationData(String experimentId) try { return experimentRepository.getUserConfigurationData(experimentId); } catch (Throwable e) { - throw convertException(e, "Error while getting user configuration"); + logger.error("Error while getting user configuration", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while getting user configuration More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -561,7 +674,11 @@ public ProcessModel getProcess(String processId) throws RegistryServiceException try { return processRepository.getProcess(processId); } catch (Throwable e) { - throw convertException(e, "Error while retrieving process"); + logger.error("Error while retrieving process", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving process More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -571,7 +688,11 @@ public List getProcessList(String experimentId) throws RegistrySer Constants.FieldConstants.ExperimentConstants.EXPERIMENT_ID, experimentId); return processModels; } catch (Throwable e) { - throw convertException(e, "Error while retrieving process list"); + logger.error("Error while retrieving process list", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving process list More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -579,7 +700,11 @@ public ProcessStatus getProcessStatus(String processId) throws RegistryServiceEx try { return processStatusRepository.getProcessStatus(processId); } catch (Throwable e) { - throw convertException(e, "Error while retrieving process status"); + logger.error("Error while retrieving process status", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving process status More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -590,8 +715,7 @@ public List getProcessListInState(ProcessState processState) throw int limit = 100; int count = 0; do { - var processStatusList = - processStatusRepository.getProcessStatusList(processState, offset, limit); + var processStatusList = processStatusRepository.getProcessStatusList(processState, offset, limit); offset += processStatusList.size(); count = processStatusList.size(); for (ProcessStatus processStatus : processStatusList) { @@ -603,7 +727,11 @@ public List getProcessListInState(ProcessState processState) throw } while (count == limit); return finalProcessList; } catch (Throwable e) { - throw convertException(e, "Error while retrieving process list with given status"); + logger.error("Error while retrieving process list with given status", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving process list with given status More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -611,7 +739,12 @@ public List getProcessStatusList(String processId) throws Registr try { return processStatusRepository.getProcessStatusList(processId); } catch (Throwable e) { - throw convertException(e, "Error while retrieving process status list for given process Id"); + logger.error("Error while retrieving process status list for given process Id", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage( + "Error while retrieving process status list for given process Id More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -638,7 +771,11 @@ private JobModel fetchJobModel(String queryType, String id) throws RegistryServi } return null; } catch (Throwable e) { - throw convertException(e, "Error while fetching job model"); + logger.error("Error while fetching job model", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while fetching job model More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -661,7 +798,11 @@ private List fetchJobModels(String queryType, String id) throws Regist } return jobs; } catch (Throwable e) { - throw convertException(e, "Error while fetching job models"); + logger.error("Error while fetching job models", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while fetching job models More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -676,7 +817,11 @@ public JobModel getJob(String queryType, String id) throws RegistryServiceExcept if (jobModel != null) return jobModel; throw new RegistryException("Job not found for queryType: " + queryType + ", id: " + id); } catch (Throwable e) { - throw convertException(e, "Error while getting job"); + logger.error("Error while getting job", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while getting job More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -684,7 +829,11 @@ public List getJobs(String queryType, String id) throws RegistryServic try { return fetchJobModels(queryType, id); } catch (Throwable e) { - throw convertException(e, "Error while getting jobs"); + logger.error("Error while getting jobs", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while getting jobs More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -696,7 +845,11 @@ public int getJobCount( gatewayId, jobStatus.getJobState().name(), searchBackTimeInMinutes); return jobStatusList.size(); } catch (Throwable e) { - throw convertException(e, "Error while getting job count"); + logger.error("Error while getting job count", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while getting job count More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -705,7 +858,11 @@ public Map getAVGTimeDistribution(String gatewayId, double searc try { return processRepository.getAVGTimeDistribution(gatewayId, searchBackTimeInMinutes); } catch (Throwable e) { - throw convertException(e, "Error while getting average time distribution"); + logger.error("Error while getting average time distribution", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while getting average time distribution More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -713,7 +870,11 @@ public List getProcessOutputs(String processId) throws Reg try { return processOutputRepository.getProcessOutputs(processId); } catch (Throwable e) { - throw convertException(e, "Error while getting process outputs"); + logger.error("Error while getting process outputs", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while getting process outputs More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -721,7 +882,11 @@ public List getProcessWorkflows(String processId) throws Regist try { return processWorkflowRepository.getProcessWorkflows(processId); } catch (Throwable e) { - throw convertException(e, "Error while getting process workflows"); + logger.error("Error while getting process workflows", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while getting process workflows More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -729,7 +894,11 @@ public void addProcessWorkflow(ProcessWorkflow processWorkflow) throws RegistryS try { processWorkflowRepository.addProcessWorkflow(processWorkflow, processWorkflow.getProcessId()); } catch (Throwable e) { - throw convertException(e, "Error while adding process workflow"); + logger.error("Error while adding process workflow", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while adding process workflow More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -737,7 +906,11 @@ public List getProcessIds(String experimentId) throws RegistryServiceExc try { return processRepository.getProcessIds(DBConstants.Process.EXPERIMENT_ID, experimentId); } catch (Throwable e) { - throw convertException(e, "Error while getting process ids"); + logger.error("Error while getting process ids", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while getting process ids More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -770,7 +943,11 @@ public List getJobDetails(String airavataExperimentId) throws Registry logger.debug("Airavata retrieved job models for experiment with experiment id : " + airavataExperimentId); return jobList; } catch (Throwable e) { - throw convertException(e, "Error while getting job details"); + logger.error("Error while getting job details", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while getting job details More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -786,7 +963,11 @@ public boolean isGatewayExistInternal(String gatewayId) throws RegistryServiceEx try { return gatewayRepository.isGatewayExist(gatewayId); } catch (Throwable e) { - throw convertException(e, "Error while checking if gateway exists"); + logger.error("Error while checking if gateway exists", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while checking if gateway exists More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -796,7 +977,11 @@ public ApplicationModule getApplicationModule(String appModuleId) throws Registr logger.debug("Airavata retrieved application module with module id : " + appModuleId); return module; } catch (Throwable e) { - throw convertException(e, "Error while getting application module"); + logger.error("Error while getting application module", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while getting application module More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -810,7 +995,11 @@ public List getAllAppModules(String gatewayId) throws Registr logger.debug("Airavata retrieved modules for gateway id : " + gatewayId); return moduleList; } catch (Throwable e) { - throw convertException(e, "Error while getting all app modules"); + logger.error("Error while getting all app modules", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while getting all app modules More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -827,7 +1016,11 @@ public List getAccessibleAppModules( logger.debug("Airavata retrieved modules for gateway id : " + gatewayId); return moduleList; } catch (Throwable e) { - throw convertException(e, "Error while getting accessible app modules"); + logger.error("Error while getting accessible app modules", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while getting accessible app modules More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -836,19 +1029,26 @@ public boolean deleteApplicationModule(String appModuleId) throws RegistryServic logger.debug("Airavata deleted application module with module id : " + appModuleId); return applicationInterfaceRepository.removeApplicationModule(appModuleId); } catch (Throwable e) { - throw convertException(e, "Error while deleting application module"); + logger.error("Error while deleting application module", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while deleting application module More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public ApplicationDeploymentDescription getApplicationDeployment(String appDeploymentId) throws RegistryServiceException { try { - var deployement = - applicationDeploymentRepository.getApplicationDeployement(appDeploymentId); + var deployement = applicationDeploymentRepository.getApplicationDeployement(appDeploymentId); logger.debug("Airavata registered application deployment for deployment id : " + appDeploymentId); return deployement; } catch (Throwable e) { - throw convertException(e, "Error while getting application deployment"); + logger.error("Error while getting application deployment", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while getting application deployment More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -858,7 +1058,11 @@ public boolean deleteApplicationDeployment(String appDeploymentId) throws Regist logger.debug("Airavata removed application deployment with deployment id : " + appDeploymentId); return true; } catch (Throwable e) { - throw convertException(e, "Error while deleting application deployment"); + logger.error("Error while deleting application deployment", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while deleting application deployment More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -869,12 +1073,15 @@ public List getAllApplicationDeployments(Strin logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - var deployements = - applicationDeploymentRepository.getAllApplicationDeployements(gatewayId); + var deployements = applicationDeploymentRepository.getAllApplicationDeployements(gatewayId); logger.debug("Airavata retrieved application deployments for gateway id : " + gatewayId); return deployements; } catch (Throwable e) { - throw convertException(e, "Error while getting all application deployments"); + logger.error("Error while getting all application deployments", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while getting all application deployments More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -886,13 +1093,17 @@ public List getAccessibleApplicationDeployment logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - var deployements = - applicationDeploymentRepository.getAccessibleApplicationDeployments( - gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); + var deployements = applicationDeploymentRepository.getAccessibleApplicationDeployments( + gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); logger.debug("Airavata retrieved application deployments for gateway id : " + gatewayId); return deployements; } catch (Throwable e) { - throw convertException(e, "Error while getting accessible application deployments"); + logger.error("Error while getting accessible application deployments", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage( + "Error while getting accessible application deployments More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -907,12 +1118,16 @@ public List getAccessibleApplicationDeployment logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - var deployments = - applicationDeploymentRepository.getAccessibleApplicationDeployments( - gatewayId, appModuleId, accessibleAppDeploymentIds, accessibleComputeResourceIds); + var deployments = applicationDeploymentRepository.getAccessibleApplicationDeployments( + gatewayId, appModuleId, accessibleAppDeploymentIds, accessibleComputeResourceIds); return deployments; } catch (Throwable e) { - throw convertException(e, "Error while getting accessible application deployments for app module"); + logger.error("Error while getting accessible application deployments for app module", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while getting accessible application deployments for app module More info : " + + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -921,15 +1136,18 @@ public List getAppModuleDeployedResources(String appModuleId) throws Reg var appDeployments = new ArrayList(); var filters = new HashMap(); filters.put(DBConstants.ApplicationDeployment.APPLICATION_MODULE_ID, appModuleId); - var applicationDeployments = - applicationDeploymentRepository.getApplicationDeployments(filters); + var applicationDeployments = applicationDeploymentRepository.getApplicationDeployments(filters); for (ApplicationDeploymentDescription description : applicationDeployments) { appDeployments.add(description.getAppDeploymentId()); } logger.debug("Airavata retrieved application deployments for module id : " + appModuleId); return appDeployments; } catch (Throwable e) { - throw convertException(e, "Error while getting app module deployed resources"); + logger.error("Error while getting app module deployed resources", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while getting app module deployed resources More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -938,32 +1156,44 @@ public List getApplicationDeployments(String a try { var filters = new HashMap(); filters.put(DBConstants.ApplicationDeployment.APPLICATION_MODULE_ID, appModuleId); - var applicationDeployments = - applicationDeploymentRepository.getApplicationDeployments(filters); + var applicationDeployments = applicationDeploymentRepository.getApplicationDeployments(filters); return applicationDeployments; } catch (Throwable e) { - throw convertException(e, "Error while getting application deployments"); + logger.error("Error while getting application deployments", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while getting application deployments More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public ApplicationInterfaceDescription getApplicationInterface(String appInterfaceId) throws RegistryServiceException { + public ApplicationInterfaceDescription getApplicationInterface(String appInterfaceId) + throws RegistryServiceException { try { - var interfaceDescription = - applicationInterfaceRepository.getApplicationInterface(appInterfaceId); + var interfaceDescription = applicationInterfaceRepository.getApplicationInterface(appInterfaceId); logger.debug("Airavata retrieved application interface with interface id : " + appInterfaceId); return interfaceDescription; } catch (Throwable e) { - throw convertException(e, "Error while getting application interface"); + logger.error("Error while getting application interface", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while getting application interface More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean deleteApplicationInterface(String appInterfaceId) throws RegistryServiceException { try { - boolean removeApplicationInterface = applicationInterfaceRepository.removeApplicationInterface(appInterfaceId); + boolean removeApplicationInterface = + applicationInterfaceRepository.removeApplicationInterface(appInterfaceId); logger.debug("Airavata removed application interface with interface id : " + appInterfaceId); return removeApplicationInterface; } catch (Throwable e) { - throw convertException(e, "Error while deleting application interface"); + logger.error("Error while deleting application interface", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while deleting application interface More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -979,13 +1209,19 @@ public Map getAllApplicationInterfaceNames(String gatewayId) thr if (allApplicationInterfaces != null && !allApplicationInterfaces.isEmpty()) { for (ApplicationInterfaceDescription interfaceDescription : allApplicationInterfaces) { allApplicationInterfacesMap.put( - interfaceDescription.getApplicationInterfaceId(), interfaceDescription.getApplicationName()); + interfaceDescription.getApplicationInterfaceId(), + interfaceDescription.getApplicationName()); } } logger.debug("Airavata retrieved application interfaces for gateway id : " + gatewayId); return allApplicationInterfacesMap; } catch (Throwable e) { - throw convertException(e, "Error while retrieving all application interface names"); + logger.error("Error while retrieving all application interface names", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage( + "Error while retrieving all application interface names More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1001,7 +1237,11 @@ public List getAllApplicationInterfaces(String logger.debug("Airavata retrieved application interfaces for gateway id : " + gatewayId); return interfaces; } catch (Throwable e) { - throw convertException(e, "Error while retrieving all application interfaces"); + logger.error("Error while retrieving all application interfaces", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving all application interfaces More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1012,18 +1252,27 @@ public List getApplicationInputs(String appInterfaceId) thr logger.debug("Airavata retrieved application inputs for application interface id : " + appInterfaceId); return applicationInputs; } catch (Throwable e) { - throw convertException(e, "Error while retrieving application inputs"); + logger.error("Error while retrieving application inputs", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving application inputs More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - private List getApplicationOutputsInternal(String appInterfaceId) throws RegistryServiceException { + private List getApplicationOutputsInternal(String appInterfaceId) + throws RegistryServiceException { try { List applicationOutputs = applicationInterfaceRepository.getApplicationOutputs(appInterfaceId); logger.debug("Airavata retrieved application outputs for application interface id : " + appInterfaceId); return applicationOutputs; } catch (Throwable e) { - throw convertException(e, "Error while retrieving application outputs"); + logger.error("Error while retrieving application outputs", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving application outputs More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1033,14 +1282,19 @@ public List getApplicationOutputs(String appInterfaceId) t logger.debug("Airavata retrieved application outputs for app interface id : " + appInterfaceId); return list; } catch (Throwable e) { - throw convertException(e, "Error while retrieving application outputs"); + logger.error("Error while retrieving application outputs", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving application outputs More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public Map getAvailableAppInterfaceComputeResources(String appInterfaceId) throws RegistryServiceException { try { - Map allComputeResources = new ComputeResourceRepository().getAvailableComputeResourceIdList(); + Map allComputeResources = + new ComputeResourceRepository().getAvailableComputeResourceIdList(); Map availableComputeResources = new HashMap(); ApplicationInterfaceDescription applicationInterface = applicationInterfaceRepository.getApplicationInterface(appInterfaceId); @@ -1060,10 +1314,16 @@ public Map getAvailableAppInterfaceComputeResources(String appIn } } } - logger.debug("Airavata retrieved available compute resources for application interface id : " + appInterfaceId); + logger.debug( + "Airavata retrieved available compute resources for application interface id : " + appInterfaceId); return availableComputeResources; } catch (Throwable e) { - throw convertException(e, "Error while retrieving available app interface compute resources"); + logger.error("Error while retrieving available app interface compute resources", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage( + "Error while retrieving available app interface compute resources More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1074,7 +1334,11 @@ public ComputeResourceDescription getComputeResource(String computeResourceId) t logger.debug("Airavata retrieved compute resource with compute resource Id : " + computeResourceId); return computeResource; } catch (Throwable e) { - throw convertException(e, "Error while retrieving compute resource"); + logger.error("Error while retrieving compute resource", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving compute resource More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1084,7 +1348,11 @@ public Map getAllComputeResourceNames() throws RegistryServiceEx logger.debug("Airavata retrieved all the available compute resources..."); return computeResourceIdList; } catch (Throwable e) { - throw convertException(e, "Error while retrieving all compute resource names"); + logger.error("Error while retrieving all compute resource names", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving all compute resource names More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1094,17 +1362,26 @@ public boolean deleteComputeResource(String computeResourceId) throws RegistrySe logger.debug("Airavata deleted compute resource with compute resource Id : " + computeResourceId); return true; } catch (Throwable e) { - throw convertException(e, "Error while deleting compute resource"); + logger.error("Error while deleting compute resource", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while deleting compute resource More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public StorageResourceDescription getStorageResource(String storageResourceId) throws RegistryServiceException { try { - StorageResourceDescription storageResource = storageResourceRepository.getStorageResource(storageResourceId); + StorageResourceDescription storageResource = + storageResourceRepository.getStorageResource(storageResourceId); logger.debug("Airavata retrieved storage resource with storage resource Id : " + storageResourceId); return storageResource; } catch (Throwable e) { - throw convertException(e, "Error while retrieving storage resource"); + logger.error("Error while retrieving storage resource", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving storage resource More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1114,7 +1391,11 @@ public Map getAllStorageResourceNames() throws RegistryServiceEx logger.debug("Airavata retrieved storage resources list..."); return resourceIdList; } catch (Throwable e) { - throw convertException(e, "Error while retrieving all storage resource names"); + logger.error("Error while retrieving all storage resource names", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving all storage resource names More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1124,7 +1405,11 @@ public boolean deleteStorageResource(String storageResourceId) throws RegistrySe logger.debug("Airavata deleted storage resource with storage resource Id : " + storageResourceId); return true; } catch (Throwable e) { - throw convertException(e, "Error while deleting storage resource"); + logger.error("Error while deleting storage resource", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while deleting storage resource More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1134,7 +1419,11 @@ public LOCALSubmission getLocalJobSubmission(String jobSubmissionId) throws Regi logger.debug("Airavata retrieved local job submission for job submission interface id: " + jobSubmissionId); return localJobSubmission; } catch (Throwable e) { - throw convertException(e, "Error while retrieving local job submission"); + logger.error("Error while retrieving local job submission", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving local job submission More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1144,7 +1433,11 @@ public SSHJobSubmission getSSHJobSubmission(String jobSubmissionId) throws Regis logger.debug("Airavata retrieved SSH job submission for job submission interface id: " + jobSubmissionId); return sshJobSubmission; } catch (Throwable e) { - throw convertException(e, "Error while retrieving SSH job submission"); + logger.error("Error while retrieving SSH job submission", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving SSH job submission More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1152,20 +1445,30 @@ public UnicoreJobSubmission getUnicoreJobSubmission(String jobSubmissionId) thro try { UnicoreJobSubmission unicoreJobSubmission = new ComputeResourceRepository().getUNICOREJobSubmission(jobSubmissionId); - logger.debug("Airavata retrieved UNICORE job submission for job submission interface id: " + jobSubmissionId); + logger.debug( + "Airavata retrieved UNICORE job submission for job submission interface id: " + jobSubmissionId); return unicoreJobSubmission; } catch (Throwable e) { - throw convertException(e, "Error while retrieving UNICORE job submission"); + logger.error("Error while retrieving UNICORE job submission", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving UNICORE job submission More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public CloudJobSubmission getCloudJobSubmission(String jobSubmissionId) throws RegistryServiceException { try { - CloudJobSubmission cloudJobSubmission = new ComputeResourceRepository().getCloudJobSubmission(jobSubmissionId); + CloudJobSubmission cloudJobSubmission = + new ComputeResourceRepository().getCloudJobSubmission(jobSubmissionId); logger.debug("Airavata retrieved cloud job submission for job submission interface id: " + jobSubmissionId); return cloudJobSubmission; } catch (Throwable e) { - throw convertException(e, "Error while retrieving cloud job submission"); + logger.error("Error while retrieving cloud job submission", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving cloud job submission More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1184,7 +1487,8 @@ public boolean changeJobSubmissionPriorities(Map jobSubmissionP return false; } - public boolean changeDataMovementPriorities(Map dataMovementPriorityMap) throws RegistryServiceException { + public boolean changeDataMovementPriorities(Map dataMovementPriorityMap) + throws RegistryServiceException { return false; } @@ -1195,7 +1499,11 @@ public boolean deleteJobSubmissionInterface(String computeResourceId, String job logger.debug("Airavata deleted job submission interface with interface id : " + jobSubmissionInterfaceId); return true; } catch (Throwable e) { - throw convertException(e, "Error while deleting job submission interface"); + logger.error("Error while deleting job submission interface", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while deleting job submission interface More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1203,7 +1511,11 @@ public ResourceJobManager getResourceJobManager(String resourceJobManagerId) thr try { return new ComputeResourceRepository().getResourceJobManager(resourceJobManagerId); } catch (Throwable e) { - throw convertException(e, "Error while retrieving resource job manager"); + logger.error("Error while retrieving resource job manager", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving resource job manager More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1212,7 +1524,11 @@ public boolean deleteResourceJobManager(String resourceJobManagerId) throws Regi new ComputeResourceRepository().deleteResourceJobManager(resourceJobManagerId); return true; } catch (Throwable e) { - throw convertException(e, "Error while deleting resource job manager"); + logger.error("Error while deleting resource job manager", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while deleting resource job manager More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1221,7 +1537,11 @@ public boolean deleteBatchQueue(String computeResourceId, String queueName) thro new ComputeResourceRepository().removeBatchQueue(computeResourceId, queueName); return true; } catch (Throwable e) { - throw convertException(e, "Error while deleting batch queue"); + logger.error("Error while deleting batch queue", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while deleting batch queue More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1236,7 +1556,11 @@ public GatewayResourceProfile getGatewayResourceProfile(String gatewayID) throws logger.debug("Airavata retrieved gateway profile with gateway id : " + gatewayID); return gatewayResourceProfile; } catch (Throwable e) { - throw convertException(e, "Error while retrieving gateway resource profile"); + logger.error("Error while retrieving gateway resource profile", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving gateway resource profile More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1251,7 +1575,11 @@ public boolean deleteGatewayResourceProfile(String gatewayID) throws RegistrySer logger.debug("Airavata deleted gateway profile with gateway id : " + gatewayID); return true; } catch (Throwable e) { - throw convertException(e, "Error while deleting gateway resource profile"); + logger.error("Error while deleting gateway resource profile", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while deleting gateway resource profile More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1284,7 +1612,12 @@ public ComputeResourcePreference getGatewayComputeResourcePreference(String gate + " and for compute resoruce id : " + computeResourceId); return computeResourcePreference; } catch (Throwable e) { - throw convertException(e, "Error while retrieving gateway compute resource preference"); + logger.error("Error while retrieving gateway compute resource preference", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage( + "Error while retrieving gateway compute resource preference More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1303,12 +1636,17 @@ public StoragePreference getGatewayStoragePreference(String gatewayID, String st throw new AppCatalogException( "Given gateway profile does not exist in the system. Please provide a valid gateway id..."); } - StoragePreference storagePreference = gwyResourceProfileRepository.getStoragePreference(gatewayID, storageId); + StoragePreference storagePreference = + gwyResourceProfileRepository.getStoragePreference(gatewayID, storageId); logger.debug("Airavata retrieved storage resource preference with gateway id : " + gatewayID + " and for storage resource id : " + storageId); return storagePreference; } catch (Throwable e) { - throw convertException(e, "Error while retrieving gateway storage preference"); + logger.error("Error while retrieving gateway storage preference", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving gateway storage preference More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1322,7 +1660,12 @@ public List getAllGatewayComputeResourcePreferences(S GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); return gwyResourceProfileRepository.getGatewayProfile(gatewayID).getComputeResourcePreferences(); } catch (Throwable e) { - throw convertException(e, "Error while retrieving all gateway compute resource preferences"); + logger.error("Error while retrieving all gateway compute resource preferences", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage( + "Error while retrieving all gateway compute resource preferences More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1335,7 +1678,12 @@ public List getAllGatewayStoragePreferences(String gatewayID) GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); return gwyResourceProfileRepository.getGatewayProfile(gatewayID).getStoragePreferences(); } catch (Throwable e) { - throw convertException(e, "Error while retrieving all gateway storage preferences"); + logger.error("Error while retrieving all gateway storage preferences", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage( + "Error while retrieving all gateway storage preferences More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1344,7 +1692,11 @@ public List getAllGatewayResourceProfiles() throws Regis GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); return gwyResourceProfileRepository.getAllGatewayProfiles(); } catch (Throwable e) { - throw convertException(e, "Error while retrieving all gateway resource profiles"); + logger.error("Error while retrieving all gateway resource profiles", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving all gateway resource profiles More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1356,9 +1708,15 @@ public boolean deleteGatewayComputeResourcePreference(String gatewayID, String c throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); - return gwyResourceProfileRepository.removeComputeResourcePreferenceFromGateway(gatewayID, computeResourceId); + return gwyResourceProfileRepository.removeComputeResourcePreferenceFromGateway( + gatewayID, computeResourceId); } catch (Throwable e) { - throw convertException(e, "Error while deleting gateway compute resource preference"); + logger.error("Error while deleting gateway compute resource preference", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage( + "Error while deleting gateway compute resource preference More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1371,7 +1729,11 @@ public boolean deleteGatewayStoragePreference(String gatewayID, String storageId GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); return gwyResourceProfileRepository.removeDataStoragePreferenceFromGateway(gatewayID, storageId); } catch (Throwable e) { - throw convertException(e, "Error while deleting gateway storage preference"); + logger.error("Error while deleting gateway storage preference", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while deleting gateway storage preference More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1380,7 +1742,11 @@ public DataProductModel getDataProduct(String productUri) throws RegistryService DataProductModel dataProductModel = dataProductRepository.getDataProduct(productUri); return dataProductModel; } catch (Throwable e) { - throw convertException(e, "Error while retrieving data product"); + logger.error("Error while retrieving data product", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving data product More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1389,7 +1755,11 @@ public DataProductModel getParentDataProduct(String productUri) throws RegistryS DataProductModel dataProductModel = dataProductRepository.getParentDataProduct(productUri); return dataProductModel; } catch (Throwable e) { - throw convertException(e, "Error while retrieving parent data product"); + logger.error("Error while retrieving parent data product", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving parent data product More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1398,33 +1768,48 @@ public List getChildDataProducts(String productUri) throws Reg List dataProductModels = dataProductRepository.getChildDataProducts(productUri); return dataProductModels; } catch (Throwable e) { - throw convertException(e, "Error while retrieving child data products"); + logger.error("Error while retrieving child data products", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving child data products More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public List searchDataProductsByName( - String gatewayId, String userId, String productName, int limit, int offset) throws RegistryServiceException { + String gatewayId, String userId, String productName, int limit, int offset) + throws RegistryServiceException { try { List dataProductModels = dataProductRepository.searchDataProductsByName(gatewayId, userId, productName, limit, offset); return dataProductModels; } catch (Throwable e) { - throw convertException(e, "Error while searching data products by name"); + logger.error("Error while searching data products by name", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while searching data products by name More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public String createGroupResourceProfile(GroupResourceProfile groupResourceProfile) throws RegistryServiceException { + public String createGroupResourceProfile(GroupResourceProfile groupResourceProfile) + throws RegistryServiceException { try { if (!isGatewayExistInternal(groupResourceProfile.getGatewayId())) { logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); - String groupResourceProfileId = groupResourceProfileRepository.addGroupResourceProfile(groupResourceProfile); + String groupResourceProfileId = + groupResourceProfileRepository.addGroupResourceProfile(groupResourceProfile); logger.debug("New Group Resource Profile Created: " + groupResourceProfileId); return groupResourceProfileId; } catch (Throwable e) { - throw convertException(e, "Error while creating group resource profile"); + logger.error("Error while creating group resource profile", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while creating group resource profile More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1438,10 +1823,15 @@ public void updateGroupResourceProfile(GroupResourceProfile groupResourceProfile throw new AppCatalogException( "Cannot update. No group resource profile found with matching gatewayId and groupResourceProfileId"); } - String groupResourceProfileId = groupResourceProfileRepository.updateGroupResourceProfile(groupResourceProfile); + String groupResourceProfileId = + groupResourceProfileRepository.updateGroupResourceProfile(groupResourceProfile); logger.debug(" Group Resource Profile updated: " + groupResourceProfileId); } catch (Throwable e) { - throw convertException(e, "Error while updating group resource profile"); + logger.error("Error while updating group resource profile", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while updating group resource profile More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1455,7 +1845,11 @@ public GroupResourceProfile getGroupResourceProfile(String groupResourceProfileI } return groupResourceProfileRepository.getGroupResourceProfile(groupResourceProfileId); } catch (Throwable e) { - throw convertException(e, "Error while retrieving group resource profile"); + logger.error("Error while retrieving group resource profile", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving group resource profile More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1464,7 +1858,11 @@ public boolean isGroupResourceProfileExists(String groupResourceProfileId) throw GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); return groupResourceProfileRepository.isGroupResourceProfileExists(groupResourceProfileId); } catch (Throwable e) { - throw convertException(e, "Error while checking if group resource profile exists"); + logger.error("Error while checking if group resource profile exists", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while checking if group resource profile exists More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1479,7 +1877,11 @@ public boolean removeGroupResourceProfile(String groupResourceProfileId) throws } return groupResourceProfileRepository.removeGroupResourceProfile(groupResourceProfileId); } catch (Throwable e) { - throw convertException(e, "Error while removing group resource profile"); + logger.error("Error while removing group resource profile", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while removing group resource profile More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1489,7 +1891,11 @@ public List getGroupResourceList(String gatewayId, List getGroupComputeResourcePrefList(Stri GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); return groupResourceProfileRepository.getAllGroupComputeResourcePreferences(groupResourceProfileId); } catch (Throwable e) { - throw convertException(e, "Error while retrieving group compute resource preference list"); + logger.error("Error while retrieving group compute resource preference list", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage( + "Error while retrieving group compute resource preference list More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1601,7 +2046,12 @@ public List getGroupBatchQueueResourcePolicyList(Strin GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); return groupResourceProfileRepository.getAllGroupBatchQueueResourcePolicies(groupResourceProfileId); } catch (Throwable e) { - throw convertException(e, "Error while retrieving group batch queue resource policy list"); + logger.error("Error while retrieving group batch queue resource policy list", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage( + "Error while retrieving group batch queue resource policy list More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1611,16 +2061,27 @@ public List getGroupComputeResourcePolicyList(String grou GroupResourceProfileRepository groupResourceProfileRepository = new GroupResourceProfileRepository(); return groupResourceProfileRepository.getAllGroupComputeResourcePolicies(groupResourceProfileId); } catch (Throwable e) { - throw convertException(e, "Error while retrieving group compute resource policy list"); + logger.error("Error while retrieving group compute resource policy list", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage( + "Error while retrieving group compute resource policy list More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public String registerReplicaLocation(DataReplicaLocationModel replicaLocationModel) throws RegistryServiceException { + public String registerReplicaLocation(DataReplicaLocationModel replicaLocationModel) + throws RegistryServiceException { try { String replicaId = dataReplicaLocationRepository.registerReplicaLocation(replicaLocationModel); return replicaId; } catch (Throwable e) { - throw convertException(e, "Error in retreiving the replica " + replicaLocationModel.getReplicaName()); + logger.error("Error in retreiving the replica " + replicaLocationModel.getReplicaName(), e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error in retreiving the replica " + replicaLocationModel.getReplicaName() + + " More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1629,7 +2090,12 @@ public String registerDataProduct(DataProductModel dataProductModel) throws Regi String productUrl = dataProductRepository.registerDataProduct(dataProductModel); return productUrl; } catch (Throwable e) { - throw convertException(e, "Error in registering the data resource" + dataProductModel.getProductName()); + logger.error("Error in registering the data resource" + dataProductModel.getProductName(), e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error in registering the data resource" + dataProductModel.getProductName() + + " More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1639,7 +2105,11 @@ public LOCALDataMovement getLocalDataMovement(String dataMovementId) throws Regi logger.debug("Airavata retrieved local data movement with data movement id: " + dataMovementId); return localDataMovement; } catch (Throwable e) { - throw convertException(e, "Error while retrieving local data movement"); + logger.error("Error while retrieving local data movement", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving local data movement More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1649,7 +2119,11 @@ public SCPDataMovement getSCPDataMovement(String dataMovementId) throws Registry logger.debug("Airavata retrieved SCP data movement with data movement id: " + dataMovementId); return scpDataMovement; } catch (Throwable e) { - throw convertException(e, "Error while retrieving SCP data movement"); + logger.error("Error while retrieving SCP data movement", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving SCP data movement More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1660,7 +2134,11 @@ public UnicoreDataMovement getUnicoreDataMovement(String dataMovementId) throws logger.debug("Airavata retrieved UNICORE data movement with data movement id: " + dataMovementId); return unicoreDataMovement; } catch (Throwable e) { - throw convertException(e, "Error while retrieving UNICORE data movement"); + logger.error("Error while retrieving UNICORE data movement", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving UNICORE data movement More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1671,7 +2149,11 @@ public GridFTPDataMovement getGridFTPDataMovement(String dataMovementId) throws logger.debug("Airavata retrieved GRIDFTP data movement with data movement id: " + dataMovementId); return gridFTPDataMovement; } catch (Throwable e) { - throw convertException(e, "Error while retrieving GRIDFTP data movement"); + logger.error("Error while retrieving GRIDFTP data movement", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving GRIDFTP data movement More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1690,10 +2172,11 @@ public String createExperiment(String gatewayId, ExperimentModel experiment) thr if (experiment.getUserConfigurationData() != null && experiment.getUserConfigurationData().getComputationalResourceScheduling() != null - && experiment.getUserConfigurationData() - .getComputationalResourceScheduling() - .getResourceHostId() - != null) { + && experiment + .getUserConfigurationData() + .getComputationalResourceScheduling() + .getResourceHostId() + != null) { String compResourceId = experiment .getUserConfigurationData() @@ -1720,11 +2203,12 @@ public String createExperiment(String gatewayId, ExperimentModel experiment) thr ComputeResourceDescription computeResourceDescription = new ComputeResourceRepository() .getComputeResource(computationalResourceScheduling.getResourceHostId()); if (!computeResourceDescription.isEnabled()) { - logger.error("Compute Resource with id" + computationalResourceScheduling.getResourceHostId() - + "" + " is not enabled by the Admin!"); + logger.error( + "Compute Resource with id" + computationalResourceScheduling.getResourceHostId() + + "" + " is not enabled by the Admin!"); throw new RegistryException( - "Compute Resource with id" + computationalResourceScheduling.getResourceHostId() + "" - + " is not enabled by the Admin!"); + "Compute Resource with id" + computationalResourceScheduling.getResourceHostId() + + "" + " is not enabled by the Admin!"); } } catch (AppCatalogException e) { throw new RegistryException("Error checking compute resource: " + e.getMessage(), e); @@ -1741,10 +2225,15 @@ public String createExperiment(String gatewayId, ExperimentModel experiment) thr throw new RegistryException("Error registering workflow: " + e.getMessage(), e); } } - logger.debug(experimentId, "Created new experiment with experiment name {}", experiment.getExperimentName()); + logger.debug( + experimentId, "Created new experiment with experiment name {}", experiment.getExperimentName()); return experimentId; } catch (Throwable e) { - throw convertException(e, "Error while creating experiment"); + logger.error("Error while creating experiment", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while creating experiment More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1813,15 +2302,22 @@ public List searchExperiments( logger.debug("Airavata retrieved experiments for user : " + userName + " and gateway id : " + gatewayId); return summaries; } catch (Throwable e) { - throw convertException(e, "Error while searching experiments"); + logger.error("Error while searching experiments", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while searching experiments More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public void updateExperiment(String airavataExperimentId, ExperimentModel experiment) throws RegistryServiceException { + public void updateExperiment(String airavataExperimentId, ExperimentModel experiment) + throws RegistryServiceException { try { if (!experimentRepository.isExperimentExist(airavataExperimentId)) { logger.error( - airavataExperimentId, "Update request failed, Experiment {} doesn't exist.", airavataExperimentId); + airavataExperimentId, + "Update request failed, Experiment {} doesn't exist.", + airavataExperimentId); throw new RegistryException( "Requested experiment id " + airavataExperimentId + " does not exist in the system.."); } @@ -1835,10 +2331,11 @@ public void updateExperiment(String airavataExperimentId, ExperimentModel experi case VALIDATED: if (experiment.getUserConfigurationData() != null && experiment.getUserConfigurationData().getComputationalResourceScheduling() != null - && experiment.getUserConfigurationData() - .getComputationalResourceScheduling() - .getResourceHostId() - != null) { + && experiment + .getUserConfigurationData() + .getComputationalResourceScheduling() + .getResourceHostId() + != null) { String compResourceId = experiment .getUserConfigurationData() .getComputationalResourceScheduling() @@ -1873,7 +2370,11 @@ public void updateExperiment(String airavataExperimentId, ExperimentModel experi } } } catch (Throwable e) { - throw convertException(e, "Error while updating experiment"); + logger.error("Error while updating experiment", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while updating experiment More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1916,11 +2417,16 @@ public void updateExperimentConfiguration(String airavataExperimentId, UserConfi } } } catch (Throwable e) { - throw convertException(e, "Error while updating experiment configuration"); + logger.error("Error while updating experiment configuration", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while updating experiment configuration More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public List getIntermediateOutputs(String airavataExperimentId) throws RegistryServiceException { + public List getIntermediateOutputs(String airavataExperimentId) + throws RegistryServiceException { try { if (!experimentRepository.isExperimentExist(airavataExperimentId)) { logger.error( @@ -1942,11 +2448,15 @@ public List getIntermediateOutputs(String airavataExperime } } } - logger.debug( - "Airavata retrieved intermediate outputs for experiment with experiment id : " + airavataExperimentId); + logger.debug("Airavata retrieved intermediate outputs for experiment with experiment id : " + + airavataExperimentId); return intermediateOutputs; } catch (Throwable e) { - throw convertException(e, "Error while retrieving intermediate outputs"); + logger.error("Error while retrieving intermediate outputs", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving intermediate outputs More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -1989,7 +2499,11 @@ public Map getJobStatuses(String airavataExperimentId) throws logger.debug("Airavata retrieved job statuses for experiment with experiment id : " + airavataExperimentId); return jobStatus; } catch (Throwable e) { - throw convertException(e, "Error while retrieving the job statuses"); + logger.error("Error while retrieving the job statuses", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving the job statuses More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2002,7 +2516,11 @@ public void addExperimentProcessOutputs(String outputType, List searchProjects( logger.debug("Airavata retrieved projects for user : " + userName + " and gateway id : " + gatewayId); return projects; } catch (Throwable e) { - throw convertException(e, "Error while searching projects"); + logger.error("Error while searching projects", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while searching projects More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2184,10 +2743,15 @@ public String registerGatewayResourceProfile(GatewayResourceProfile gatewayResou } GwyResourceProfileRepository gwyResourceProfileRepository = new GwyResourceProfileRepository(); String resourceProfile = gwyResourceProfileRepository.addGatewayResourceProfile(gatewayResourceProfile); - logger.debug("Airavata registered gateway profile with gateway id : " + gatewayResourceProfile.getGatewayID()); + logger.debug( + "Airavata registered gateway profile with gateway id : " + gatewayResourceProfile.getGatewayID()); return resourceProfile; } catch (Throwable e) { - throw convertException(e, "Error while registering gateway resource profile"); + logger.error("Error while registering gateway resource profile", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while registering gateway resource profile More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2203,7 +2767,11 @@ public boolean updateGatewayResourceProfile(String gatewayID, GatewayResourcePro logger.debug("Airavata updated gateway profile with gateway id : " + gatewayID); return true; } catch (Throwable e) { - throw convertException(e, "Error while updating gateway resource profile"); + logger.error("Error while updating gateway resource profile", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while updating gateway resource profile More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2226,7 +2794,12 @@ public boolean addGatewayComputeResourcePreference( + " and for compute resource id : " + computeResourceId); return true; } catch (Throwable e) { - throw convertException(e, "Error while adding gateway compute resource preference"); + logger.error("Error while adding gateway compute resource preference", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage( + "Error while adding gateway compute resource preference More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2257,7 +2830,12 @@ public boolean updateGatewayComputeResourcePreference( + " and for compute resource id : " + computeResourceId); return true; } catch (Throwable e) { - throw convertException(e, "Error while updating gateway compute resource preference"); + logger.error("Error while updating gateway compute resource preference", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage( + "Error while updating gateway compute resource preference More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2281,7 +2859,11 @@ public boolean addGatewayStoragePreference( + " and for storage resource id : " + storageResourceId); return true; } catch (Throwable e) { - throw convertException(e, "Error while adding gateway storage preference"); + logger.error("Error while adding gateway storage preference", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while adding gateway storage preference More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2311,7 +2893,11 @@ public boolean updateGatewayStoragePreference( + " and for storage resource id : " + storageId); return true; } catch (Throwable e) { - throw convertException(e, "Error while updating gateway storage preference"); + logger.error("Error while updating gateway storage preference", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while updating gateway storage preference More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2323,7 +2909,11 @@ public String registerComputeResource(ComputeResourceDescription computeResource logger.debug("Airavata registered compute resource with compute resource Id : " + computeResource); return computeResource; } catch (Throwable e) { - throw convertException(e, "Error while registering compute resource"); + logger.error("Error while registering compute resource", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while registering compute resource More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2335,7 +2925,11 @@ public boolean updateComputeResource( logger.debug("Airavata updated compute resource with compute resource Id : " + computeResourceId); return true; } catch (Throwable e) { - throw convertException(e, "Error while updating compute resource"); + logger.error("Error while updating compute resource", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while updating compute resource More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2343,7 +2937,11 @@ public String registerResourceJobManager(ResourceJobManager resourceJobManager) try { return new ComputeResourceRepository().addResourceJobManager(resourceJobManager); } catch (Throwable e) { - throw convertException(e, "Error while registering resource job manager"); + logger.error("Error while registering resource job manager", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while registering resource job manager More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2353,7 +2951,11 @@ public boolean updateResourceJobManager(String resourceJobManagerId, ResourceJob new ComputeResourceRepository().updateResourceJobManager(resourceJobManagerId, updatedResourceJobManager); return true; } catch (Throwable e) { - throw convertException(e, "Error while updating resource job manager"); + logger.error("Error while updating resource job manager", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while updating resource job manager More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2363,11 +2965,13 @@ public boolean deleteDataMovementInterface(String resourceId, String dataMovemen switch (dmType) { case COMPUTE_RESOURCE: new ComputeResourceRepository().removeDataMovementInterface(resourceId, dataMovementInterfaceId); - logger.debug("Airavata deleted data movement interface with interface id : " + dataMovementInterfaceId); + logger.debug( + "Airavata deleted data movement interface with interface id : " + dataMovementInterfaceId); return true; case STORAGE_RESOURCE: storageResourceRepository.removeDataMovementInterface(resourceId, dataMovementInterfaceId); - logger.debug("Airavata deleted data movement interface with interface id : " + dataMovementInterfaceId); + logger.debug( + "Airavata deleted data movement interface with interface id : " + dataMovementInterfaceId); return true; default: logger.error( @@ -2375,7 +2979,11 @@ public boolean deleteDataMovementInterface(String resourceId, String dataMovemen return false; } } catch (Throwable e) { - throw convertException(e, "Error while deleting data movement interface"); + logger.error("Error while deleting data movement interface", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while deleting data movement interface More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2384,7 +2992,11 @@ public boolean updateGridFTPDataMovementDetails( try { throw new AppCatalogException("updateGridFTPDataMovementDetails is not yet implemented"); } catch (Throwable e) { - throw convertException(e, "Error while updating GridFTP data movement details"); + logger.error("Error while updating GridFTP data movement details", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while updating GridFTP data movement details More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2403,7 +3015,11 @@ public String addGridFTPDataMovementDetails( logger.debug("Airavata registered GridFTP data movement for resource Id: " + computeResourceId); return addDataMovementInterface; } catch (Throwable e) { - throw convertException(e, "Error while adding GridFTP data movement details"); + logger.error("Error while adding GridFTP data movement details", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while adding GridFTP data movement details More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2412,7 +3028,11 @@ public boolean updateUnicoreDataMovementDetails( try { throw new AppCatalogException("updateUnicoreDataMovementDetails is not yet implemented"); } catch (Throwable e) { - throw convertException(e, "Error while updating Unicore data movement details"); + logger.error("Error while updating Unicore data movement details", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while updating Unicore data movement details More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2431,7 +3051,11 @@ public String addUnicoreDataMovementDetails( logger.debug("Airavata registered UNICORE data movement for resource Id: " + resourceId); return movementInterface; } catch (Throwable e) { - throw convertException(e, "Error while adding Unicore data movement details"); + logger.error("Error while adding Unicore data movement details", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while adding Unicore data movement details More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2442,7 +3066,11 @@ public boolean updateSCPDataMovementDetails(String dataMovementInterfaceId, SCPD logger.debug("Airavata updated SCP data movement with data movement id: " + dataMovementInterfaceId); return true; } catch (Throwable e) { - throw convertException(e, "Error while updating SCP data movement details"); + logger.error("Error while updating SCP data movement details", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while updating SCP data movement details More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2461,7 +3089,11 @@ public String addSCPDataMovementDetails( logger.debug("Airavata registered SCP data movement for resource Id: " + resourceId); return movementInterface; } catch (Throwable e) { - throw convertException(e, "Error while adding SCP data movement details"); + logger.error("Error while adding SCP data movement details", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while adding SCP data movement details More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2472,7 +3104,11 @@ public boolean updateLocalDataMovementDetails(String dataMovementInterfaceId, LO logger.debug("Airavata updated local data movement with data movement id: " + dataMovementInterfaceId); return true; } catch (Throwable e) { - throw convertException(e, "Error while updating local data movement details"); + logger.error("Error while updating local data movement details", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while updating local data movement details More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2491,7 +3127,11 @@ public String addLocalDataMovementDetails( logger.debug("Airavata registered local data movement for resource Id: " + resourceId); return movementInterface; } catch (Throwable e) { - throw convertException(e, "Error while adding local data movement details"); + logger.error("Error while adding local data movement details", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while adding local data movement details More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2503,7 +3143,11 @@ public String registerStorageResource(StorageResourceDescription storageResource logger.debug("Airavata registered storage resource with storage resource Id : " + storageResource); return storageResource; } catch (Throwable e) { - throw convertException(e, "Error while registering storage resource"); + logger.error("Error while registering storage resource", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while registering storage resource More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2515,7 +3159,11 @@ public boolean updateStorageResource( logger.debug("Airavata updated storage resource with storage resource Id : " + storageResourceId); return true; } catch (Throwable e) { - throw convertException(e, "Error while updating storage resource"); + logger.error("Error while updating storage resource", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while updating storage resource More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2534,7 +3182,11 @@ private String addJobSubmissionInterface( jobSubmissionInterface.setJobSubmissionProtocol(protocolType); return computeResourceRepository.addJobSubmissionProtocol(computeResourceId, jobSubmissionInterface); } catch (Throwable e) { - throw convertException(e, "Error while adding job submission interface"); + logger.error("Error while adding job submission interface", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while adding job submission interface More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2552,20 +3204,26 @@ private String addDataMovementInterface( dataMovementInterface.setPriorityOrder(priorityOrder); dataMovementInterface.setDataMovementProtocol(protocolType); if (dmType.equals(DMType.COMPUTE_RESOURCE)) { - return computeResourceRepository.addDataMovementProtocol(computeResourceId, dmType, dataMovementInterface); + return computeResourceRepository.addDataMovementProtocol( + computeResourceId, dmType, dataMovementInterface); } else if (dmType.equals(DMType.STORAGE_RESOURCE)) { dataMovementInterface.setStorageResourceId(computeResourceId); return storageResourceRepository.addDataMovementInterface(dataMovementInterface); } return null; } catch (Throwable e) { - throw convertException(e, "Error while adding data movement interface"); + logger.error("Error while adding data movement interface", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while adding data movement interface More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } // Job Submission Interface operations public String addSSHJobSubmissionDetails( - String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) throws RegistryServiceException { + String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) + throws RegistryServiceException { try { ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); String submissionInterface = addJobSubmissionInterface( @@ -2577,12 +3235,17 @@ public String addSSHJobSubmissionDetails( logger.debug("Airavata registered SSH job submission for compute resource id: " + computeResourceId); return submissionInterface; } catch (Throwable e) { - throw convertException(e, "Error while adding SSH job submission details"); + logger.error("Error while adding SSH job submission details", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while adding SSH job submission details More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public String addSSHForkJobSubmissionDetails( - String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) throws RegistryServiceException { + String computeResourceId, int priorityOrder, SSHJobSubmission sshJobSubmission) + throws RegistryServiceException { try { ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); String submissionDetails = addJobSubmissionInterface( @@ -2594,12 +3257,17 @@ public String addSSHForkJobSubmissionDetails( logger.debug("Airavata registered Fork job submission for compute resource id: " + computeResourceId); return submissionDetails; } catch (Throwable e) { - throw convertException(e, "Error while adding SSH Fork job submission details"); + logger.error("Error while adding SSH Fork job submission details", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while adding SSH Fork job submission details More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public String addLocalSubmissionDetails( - String computeResourceId, int priorityOrder, LOCALSubmission localSubmission) throws RegistryServiceException { + String computeResourceId, int priorityOrder, LOCALSubmission localSubmission) + throws RegistryServiceException { try { ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); String submissionInterface = addJobSubmissionInterface( @@ -2611,7 +3279,11 @@ public String addLocalSubmissionDetails( logger.debug("Airavata added local job submission for compute resource id: " + computeResourceId); return submissionInterface; } catch (Throwable e) { - throw convertException(e, "Error while adding local submission details"); + logger.error("Error while adding local submission details", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while adding local submission details More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2619,11 +3291,15 @@ public boolean updateLocalSubmissionDetails(String jobSubmissionInterfaceId, LOC throws RegistryServiceException { try { new ComputeResourceRepository().updateLocalJobSubmission(localSubmission); - logger.debug( - "Airavata updated local job submission for job submission interface id: " + jobSubmissionInterfaceId); + logger.debug("Airavata updated local job submission for job submission interface id: " + + jobSubmissionInterfaceId); return true; } catch (Throwable e) { - throw convertException(e, "Error while updating local submission details"); + logger.error("Error while updating local submission details", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while updating local submission details More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2641,7 +3317,11 @@ public String addCloudJobSubmissionDetails( logger.debug("Airavata registered Cloud job submission for compute resource id: " + computeResourceId); return submissionInterface; } catch (Throwable e) { - throw convertException(e, "Error while adding cloud job submission details"); + logger.error("Error while adding cloud job submission details", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while adding cloud job submission details More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2659,7 +3339,11 @@ public String addUNICOREJobSubmissionDetails( logger.debug("Airavata registered UNICORE job submission for compute resource id: " + computeResourceId); return submissionInterface; } catch (Throwable e) { - throw convertException(e, "Error while adding UNICORE job submission details"); + logger.error("Error while adding UNICORE job submission details", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while adding UNICORE job submission details More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2671,22 +3355,32 @@ public String registerApplicationInterface(String gatewayId, ApplicationInterfac logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - String interfaceId = applicationInterfaceRepository.addApplicationInterface(applicationInterface, gatewayId); + String interfaceId = + applicationInterfaceRepository.addApplicationInterface(applicationInterface, gatewayId); logger.debug("Airavata registered application interface for gateway id : " + gatewayId); return interfaceId; } catch (Throwable e) { - throw convertException(e, "Error while registering application interface"); + logger.error("Error while registering application interface", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while registering application interface More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean updateApplicationInterface( - String appInterfaceId, ApplicationInterfaceDescription applicationInterface) throws RegistryServiceException { + String appInterfaceId, ApplicationInterfaceDescription applicationInterface) + throws RegistryServiceException { try { applicationInterfaceRepository.updateApplicationInterface(appInterfaceId, applicationInterface); logger.debug("Airavata updated application interface with interface id : " + appInterfaceId); return true; } catch (Throwable e) { - throw convertException(e, "Error while updating application interface"); + logger.error("Error while updating application interface", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while updating application interface More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2701,7 +3395,11 @@ public String registerApplicationModule(String gatewayId, ApplicationModule appl logger.debug("Airavata registered application module for gateway id : " + gatewayId); return module; } catch (Throwable e) { - throw convertException(e, "Error while registering application module"); + logger.error("Error while registering application module", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while registering application module More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2712,7 +3410,11 @@ public boolean updateApplicationModule(String appModuleId, ApplicationModule app logger.debug("Airavata updated application module with module id: " + appModuleId); return true; } catch (Throwable e) { - throw convertException(e, "Error while updating application module"); + logger.error("Error while updating application module", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while updating application module More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2723,22 +3425,32 @@ public String registerApplicationDeployment( logger.error("Gateway does not exist.Please provide a valid gateway id..."); throw new AppCatalogException("Gateway does not exist.Please provide a valid gateway id..."); } - String deployment = applicationDeploymentRepository.addApplicationDeployment(applicationDeployment, gatewayId); + String deployment = + applicationDeploymentRepository.addApplicationDeployment(applicationDeployment, gatewayId); logger.debug("Airavata registered application deployment for gateway id : " + gatewayId); return deployment; } catch (Throwable e) { - throw convertException(e, "Error while registering application deployment"); + logger.error("Error while registering application deployment", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while registering application deployment More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean updateApplicationDeployment( - String appDeploymentId, ApplicationDeploymentDescription applicationDeployment) throws RegistryServiceException { + String appDeploymentId, ApplicationDeploymentDescription applicationDeployment) + throws RegistryServiceException { try { applicationDeploymentRepository.updateApplicationDeployment(appDeploymentId, applicationDeployment); logger.debug("Airavata updated application deployment for deployment id : " + appDeploymentId); return true; } catch (Throwable e) { - throw convertException(e, "Error while updating application deployment"); + logger.error("Error while updating application deployment", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while updating application deployment More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2758,11 +3470,15 @@ public String registerUserResourceProfile(UserResourceProfile userResourceProfil throw new AppCatalogException("User does not exist.Please provide a valid user ID..."); } String resourceProfile = userResourceProfileRepository.addUserResourceProfile(userResourceProfile); - logger.debug("Airavata registered user resource profile with gateway id : " + userResourceProfile.getGatewayID() - + "and user id : " + userResourceProfile.getUserId()); + logger.debug("Airavata registered user resource profile with gateway id : " + + userResourceProfile.getGatewayID() + "and user id : " + userResourceProfile.getUserId()); return resourceProfile; } catch (Throwable e) { - throw convertException(e, "Error while registering user resource profile"); + logger.error("Error while registering user resource profile", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while registering user resource profile More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2774,7 +3490,11 @@ public boolean isUserResourceProfileExists(String userId, String gatewayId) thro } return userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayId); } catch (Throwable e) { - throw convertException(e, "Error while checking if user resource profile exists"); + logger.error("Error while checking if user resource profile exists", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while checking if user resource profile exists More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2789,7 +3509,11 @@ public UserResourceProfile getUserResourceProfile(String userId, String gatewayI logger.debug("Airavata retrieved User resource profile with user id : " + userId); return userResourceProfile; } catch (Throwable e) { - throw convertException(e, "Error while getting user resource profile"); + logger.error("Error while getting user resource profile", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while getting user resource profile More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2804,7 +3528,11 @@ public boolean updateUserResourceProfile(String userId, String gatewayID, UserRe logger.debug("Airavata updated gateway profile with gateway id : " + userId); return true; } catch (Throwable e) { - throw convertException(e, "Error while updating user resource profile"); + logger.error("Error while updating user resource profile", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while updating user resource profile More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2818,7 +3546,11 @@ public boolean deleteUserResourceProfile(String userId, String gatewayID) throws logger.debug("Airavata deleted User profile with gateway id : " + gatewayID + " and user id : " + userId); return true; } catch (Throwable e) { - throw convertException(e, "Error while deleting user resource profile"); + logger.error("Error while deleting user resource profile", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while deleting user resource profile More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2862,7 +3594,11 @@ public void updateResourceScheduleing( } } } catch (Throwable e) { - throw convertException(e, "Error while updating resource scheduling"); + logger.error("Error while updating resource scheduling", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while updating resource scheduling More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2877,7 +3613,11 @@ public String addUser(UserProfile userProfile) throws RegistryServiceException { UserProfile savedUser = userRepository.addUser(userProfile); return savedUser.getUserId(); } catch (Throwable e) { - throw convertException(e, "Error while adding user"); + logger.error("Error while adding user", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while adding user More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2894,8 +3634,8 @@ public boolean addUserComputeResourcePreference( throw new AppCatalogException("user does not exist.Please provide a valid user id..."); } if (!userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayID)) { - throw new AppCatalogException("User resource profile with user id'" + userId + " & gateway Id" + gatewayID - + "' does not exist!!!"); + throw new AppCatalogException("User resource profile with user id'" + userId + " & gateway Id" + + gatewayID + "' does not exist!!!"); } UserResourceProfile profile = userResourceProfileRepository.getUserResourceProfile(userId, gatewayID); profile.addToUserComputeResourcePreferences(userComputeResourcePreference); @@ -2904,7 +3644,11 @@ public boolean addUserComputeResourcePreference( + " and for compute resource id : " + computeResourceId); return true; } catch (Throwable e) { - throw convertException(e, "Error while adding user compute resource preference"); + logger.error("Error while adding user compute resource preference", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while adding user compute resource preference More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2918,7 +3662,12 @@ public boolean isUserComputeResourcePreferenceExists(String userId, String gatew } return false; } catch (Throwable e) { - throw convertException(e, "Error while checking if user compute resource preference exists"); + logger.error("Error while checking if user compute resource preference exists", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage( + "Error while checking if user compute resource preference exists More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2930,8 +3679,8 @@ public UserComputeResourcePreference getUserComputeResourcePreference( throw new AppCatalogException("user does not exist.Please provide a valid user id..."); } if (!userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayID)) { - throw new AppCatalogException("User resource profile with user id'" + userId + " & gateway Id" + gatewayID - + "' does not exist!!!"); + throw new AppCatalogException("User resource profile with user id'" + userId + " & gateway Id" + + gatewayID + "' does not exist!!!"); } ComputeResourceRepository computeResourceRepository = new ComputeResourceRepository(); if (!computeResourceRepository.isComputeResourceExists(userComputeResourceId)) { @@ -2948,7 +3697,11 @@ public UserComputeResourcePreference getUserComputeResourcePreference( + " and for compute resoruce id : " + userComputeResourceId); return userComputeResourcePreference; } catch (Throwable e) { - throw convertException(e, "Error while getting user compute resource preference"); + logger.error("Error while getting user compute resource preference", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while getting user compute resource preference More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2982,7 +3735,11 @@ public boolean updateUserComputeResourcePreference( + " and for compute resource id : " + computeResourceId); return true; } catch (Throwable e) { - throw convertException(e, "Error while updating user compute resource preference"); + logger.error("Error while updating user compute resource preference", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while updating user compute resource preference More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -2995,8 +3752,8 @@ public boolean addUserStoragePreference( throw new AppCatalogException("user does not exist.Please provide a valid user id..."); } if (!userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayID)) { - throw new AppCatalogException("User resource profile with user id'" + userId + " & gateway Id" + gatewayID - + "' does not exist!!!"); + throw new AppCatalogException("User resource profile with user id'" + userId + " & gateway Id" + + gatewayID + "' does not exist!!!"); } UserResourceProfile profile = userResourceProfileRepository.getUserResourceProfile(userId, gatewayID); dataStoragePreference.setStorageResourceId(storageResourceId); @@ -3006,7 +3763,11 @@ public boolean addUserStoragePreference( + " and for storage resource id : " + storageResourceId); return true; } catch (Throwable e) { - throw convertException(e, "Error while adding user storage preference"); + logger.error("Error while adding user storage preference", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while adding user storage preference More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3018,8 +3779,8 @@ public UserStoragePreference getUserStoragePreference(String userId, String gate throw new AppCatalogException("user does not exist.Please provide a valid user id..."); } if (!userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayID)) { - throw new AppCatalogException("User resource profile with user id'" + userId + " & gateway Id" + gatewayID - + "' does not exist!!!"); + throw new AppCatalogException("User resource profile with user id'" + userId + " & gateway Id" + + gatewayID + "' does not exist!!!"); } UserStoragePreference storagePreference = @@ -3028,7 +3789,11 @@ public UserStoragePreference getUserStoragePreference(String userId, String gate + " and for storage resource id : " + storageId); return storagePreference; } catch (Throwable e) { - throw convertException(e, "Error while getting user storage preference"); + logger.error("Error while getting user storage preference", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while getting user storage preference More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3036,7 +3801,11 @@ public List getAllUserResourceProfiles() throws RegistrySer try { return userResourceProfileRepository.getAllUserResourceProfiles(); } catch (Throwable e) { - throw convertException(e, "Error while getting all user resource profiles"); + logger.error("Error while getting all user resource profiles", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while getting all user resource profiles More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3050,7 +3819,11 @@ public GatewayGroups getGatewayGroups(String gatewayId) throws RegistryServiceEx } return gatewayGroupsRepository.get(gatewayId); } catch (Throwable e) { - throw convertException(e, "Error while getting gateway groups"); + logger.error("Error while getting gateway groups", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while getting gateway groups More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3064,7 +3837,11 @@ public Parser getParser(String parserId, String gatewayId) throws RegistryServic } return parserRepository.get(parserId); } catch (Throwable e) { - throw convertException(e, "Error while getting parser"); + logger.error("Error while getting parser", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while getting parser More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3073,7 +3850,11 @@ public String saveParser(Parser parser) throws RegistryServiceException { Parser saved = parserRepository.saveParser(parser); return saved.getId(); } catch (Throwable e) { - throw convertException(e, "Error while saving parser"); + logger.error("Error while saving parser", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while saving parser More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3085,7 +3866,11 @@ public void removeParser(String parserId, String gatewayId) throws RegistryServi } parserRepository.delete(parserId); } catch (Throwable e) { - throw convertException(e, "Error while removing parser"); + logger.error("Error while removing parser", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while removing parser More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3095,9 +3880,13 @@ public ParserInput getParserInput(String parserInputId, String gatewayId) throws final String message = "No ParserInput entry exists for " + parserInputId; logger.error(message); throw new RegistryException(message); - } catch (Throwable e) { - throw convertException(e, "Error in getParserInput"); - } + } catch (Throwable e) { + logger.error("Error in getParserInput", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error in getParserInput More info : " + e.getMessage()); + exception.initCause(e); + throw exception; + } } return parserInputRepository.get(parserInputId); } @@ -3121,7 +3910,11 @@ public void removeParserInput(String parserInputId, String gatewayId) throws Reg } parserInputRepository.delete(parserInputId); } catch (Throwable e) { - throw convertException(e, "Error in removeParserInput"); + logger.error("Error in removeParserInput", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error in removeParserInput More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3134,7 +3927,11 @@ public ParserOutput getParserOutput(String parserOutputId, String gatewayId) thr } return parserOutputRepository.get(parserOutputId); } catch (Throwable e) { - throw convertException(e, "Error in getParserOutput"); + logger.error("Error in getParserOutput", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error in getParserOutput More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3143,7 +3940,11 @@ public String saveParserOutput(ParserOutput parserOutput) throws RegistryService ParserOutput saved = parserOutputRepository.create(parserOutput); return saved.getId(); } catch (Throwable e) { - throw convertException(e, "Error while saving parser output"); + logger.error("Error while saving parser output", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while saving parser output More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3161,7 +3962,11 @@ public void removeParserOutput(String parserOutputId, String gatewayId) throws R } parserOutputRepository.delete(parserOutputId); } catch (Throwable e) { - throw convertException(e, "Error in removeParserOutput"); + logger.error("Error in removeParserOutput", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error in removeParserOutput More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3174,7 +3979,11 @@ public ParsingTemplate getParsingTemplate(String templateId, String gatewayId) t } return parsingTemplateRepository.get(templateId); } catch (Throwable e) { - throw convertException(e, "Error in getParsingTemplate"); + logger.error("Error in getParsingTemplate", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error in getParsingTemplate More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3183,19 +3992,29 @@ public String saveParsingTemplate(ParsingTemplate parsingTemplate) throws Regist ParsingTemplate saved = parsingTemplateRepository.create(parsingTemplate); return saved.getId(); } catch (Throwable e) { - throw convertException(e, "Error while saving parsing template"); + logger.error("Error while saving parsing template", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while saving parsing template More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public void removeParsingTemplate(String templateId, String gatewayId) throws RegistryServiceException { try { boolean exists = parsingTemplateRepository.isExists(templateId); - if (!exists || gatewayId.equals(parsingTemplateRepository.get(templateId).getGatewayId())) { + if (!exists + || gatewayId.equals( + parsingTemplateRepository.get(templateId).getGatewayId())) { throw new RegistryException("Parsing template " + templateId + " does not exist"); } parsingTemplateRepository.delete(templateId); } catch (Throwable e) { - throw convertException(e, "Error in removeParsingTemplate"); + logger.error("Error in removeParsingTemplate", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error in removeParsingTemplate More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3205,7 +4024,12 @@ public boolean isGatewayUsageReportingAvailable(String gatewayId, String compute try { return usageReportingCommandRepository.isGatewayUsageReportingCommandExists(gatewayId, computeResourceId); } catch (Throwable e) { - throw convertException(e, "Error while checking if gateway usage reporting is available"); + logger.error("Error while checking if gateway usage reporting is available", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage( + "Error while checking if gateway usage reporting is available More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3213,14 +4037,18 @@ public GatewayUsageReportingCommand getGatewayReportingCommand(String gatewayId, throws RegistryServiceException { try { if (!usageReportingCommandRepository.isGatewayUsageReportingCommandExists(gatewayId, computeResourceId)) { - String message = "No usage reporting information for the gateway " + gatewayId + " and compute resource " - + computeResourceId; + String message = "No usage reporting information for the gateway " + gatewayId + + " and compute resource " + computeResourceId; logger.error(message); throw new RegistryException(message); } return usageReportingCommandRepository.getGatewayUsageReportingCommand(gatewayId, computeResourceId); } catch (Throwable e) { - throw convertException(e, "Error while getting gateway reporting command"); + logger.error("Error while getting gateway reporting command", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while getting gateway reporting command More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3228,7 +4056,11 @@ public void addGatewayUsageReportingCommand(GatewayUsageReportingCommand command try { usageReportingCommandRepository.addGatewayUsageReportingCommand(command); } catch (Throwable e) { - throw convertException(e, "Error while adding gateway usage reporting command"); + logger.error("Error while adding gateway usage reporting command", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while adding gateway usage reporting command More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3237,7 +4069,11 @@ public void removeGatewayUsageReportingCommand(String gatewayId, String computeR try { usageReportingCommandRepository.removeGatewayUsageReportingCommand(gatewayId, computeResourceId); } catch (Throwable e) { - throw convertException(e, "Error while removing gateway usage reporting command"); + logger.error("Error while removing gateway usage reporting command", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while removing gateway usage reporting command More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3246,11 +4082,15 @@ public boolean updateCloudJobSubmissionDetails( try { cloudJobSubmission.setJobSubmissionInterfaceId(jobSubmissionInterfaceId); computeResourceRepository.updateCloudJobSubmission(cloudJobSubmission); - logger.debug( - "Airavata updated Cloud job submission for job submission interface id: " + jobSubmissionInterfaceId); + logger.debug("Airavata updated Cloud job submission for job submission interface id: " + + jobSubmissionInterfaceId); return true; } catch (Throwable e) { - throw convertException(e, "Error while updating cloud job submission details"); + logger.error("Error while updating cloud job submission details", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while updating cloud job submission details More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3263,20 +4103,29 @@ public boolean updateSSHJobSubmissionDetails(String jobSubmissionInterfaceId, SS "Airavata updated SSH job submission for job submission interface id: " + jobSubmissionInterfaceId); return true; } catch (Throwable e) { - throw convertException(e, "Error while updating SSH job submission details"); + logger.error("Error while updating SSH job submission details", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while updating SSH job submission details More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public boolean updateUnicoreJobSubmissionDetails( - String jobSubmissionInterfaceId, UnicoreJobSubmission unicoreJobSubmission) throws RegistryServiceException { + String jobSubmissionInterfaceId, UnicoreJobSubmission unicoreJobSubmission) + throws RegistryServiceException { try { unicoreJobSubmission.setJobSubmissionInterfaceId(jobSubmissionInterfaceId); computeResourceRepository.updateUNICOREJobSubmission(unicoreJobSubmission); - logger.debug( - "Airavata updated UNICORE job submission for job submission interface id: " + jobSubmissionInterfaceId); + logger.debug("Airavata updated UNICORE job submission for job submission interface id: " + + jobSubmissionInterfaceId); return true; } catch (Throwable e) { - throw convertException(e, "Error while updating Unicore job submission details"); + logger.error("Error while updating Unicore job submission details", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while updating Unicore job submission details More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3286,7 +4135,11 @@ public boolean updateNotification(Notification notification) throws RegistryServ logger.debug("Airavata updated notification with notification id: " + notification.getNotificationId()); return true; } catch (Throwable e) { - throw convertException(e, "Error while updating notification"); + logger.error("Error while updating notification", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while updating notification More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3296,23 +4149,31 @@ public String createNotification(Notification notification) throws RegistryServi logger.debug("Airavata created notification with notification id: " + notificationId); return notificationId; } catch (Throwable e) { - throw convertException(e, "Error while creating notification"); + logger.error("Error while creating notification", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while creating notification More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } - public boolean updateGateway(String gatewayId, Gateway updatedGateway) - throws RegistryServiceException { + public boolean updateGateway(String gatewayId, Gateway updatedGateway) throws RegistryServiceException { try { if (!gatewayRepository.isGatewayExist(gatewayId)) { logger.error("Gateway does not exist in the system. Please provide a valid gateway ID..."); - throw new RegistryException("Gateway does not exist in the system. Please provide a valid gateway ID..."); + throw new RegistryException( + "Gateway does not exist in the system. Please provide a valid gateway ID..."); } updatedGateway.setGatewayId(gatewayId); gatewayRepository.updateGateway(gatewayId, updatedGateway); logger.debug("Airavata updated gateway with gateway id: " + gatewayId); return true; } catch (Throwable e) { - throw convertException(e, "Error while updating gateway"); + logger.error("Error while updating gateway", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while updating gateway More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3327,7 +4188,11 @@ public String addGateway(Gateway gateway) throws RegistryServiceException { logger.debug("Airavata registered gateway with gateway id: " + gatewayId); return gatewayId; } catch (Throwable e) { - throw convertException(e, "Error while adding gateway"); + logger.error("Error while adding gateway", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while adding gateway More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3340,8 +4205,8 @@ public boolean updateUserStoragePreference( throw new AppCatalogException("user does not exist.Please provide a valid user id..."); } if (!userResourceProfileRepository.isUserResourceProfileExists(userId, gatewayID)) { - throw new AppCatalogException("User resource profile with user id'" + userId + " & gateway Id" + gatewayID - + "' does not exist!!!"); + throw new AppCatalogException("User resource profile with user id'" + userId + " & gateway Id" + + gatewayID + "' does not exist!!!"); } UserResourceProfile profile = userResourceProfileRepository.getUserResourceProfile(userId, gatewayID); List userStoragePreferences = profile.getUserStoragePreferences(); @@ -3362,7 +4227,11 @@ public boolean updateUserStoragePreference( + " and for storage resource id : " + storageId); return true; } catch (Throwable e) { - throw convertException(e, "Error while updating user storage preference"); + logger.error("Error while updating user storage preference", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while updating user storage preference More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3376,7 +4245,11 @@ public boolean deleteUserComputeResourcePreference(String userId, String gateway return userResourceProfileRepository.removeUserComputeResourcePreferenceFromGateway( userId, gatewayID, computeResourceId); } catch (Throwable e) { - throw convertException(e, "Error while deleting user compute resource preference"); + logger.error("Error while deleting user compute resource preference", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while deleting user compute resource preference More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3387,9 +4260,14 @@ public boolean deleteUserStoragePreference(String userId, String gatewayID, Stri logger.error("user does not exist.Please provide a valid user id..."); throw new AppCatalogException("user does not exist.Please provide a valid user id..."); } - return userResourceProfileRepository.removeUserDataStoragePreferenceFromGateway(userId, gatewayID, storageId); + return userResourceProfileRepository.removeUserDataStoragePreferenceFromGateway( + userId, gatewayID, storageId); } catch (Throwable e) { - throw convertException(e, "Error while deleting user storage preference"); + logger.error("Error while deleting user storage preference", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while deleting user storage preference More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3397,7 +4275,11 @@ public List getLatestQueueStatuses() throws RegistryServiceExc try { return queueStatusRepository.getLatestQueueStatuses(); } catch (Throwable e) { - throw convertException(e, "Error while retrieving latest queue statuses"); + logger.error("Error while retrieving latest queue statuses", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving latest queue statuses More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3405,13 +4287,18 @@ public void registerQueueStatuses(List queueStatuses) throws R try { queueStatusRepository.createQueueStatuses(queueStatuses); } catch (Throwable e) { - throw convertException(e, "Error while registering queue statuses"); + logger.error("Error while registering queue statuses", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while registering queue statuses More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } public QueueStatusModel getQueueStatus(String hostName, String queueName) throws RegistryServiceException { try { - Optional optionalQueueStatusModel = queueStatusRepository.getQueueStatus(hostName, queueName); + Optional optionalQueueStatusModel = + queueStatusRepository.getQueueStatus(hostName, queueName); if (optionalQueueStatusModel.isPresent()) { return optionalQueueStatusModel.get(); } else { @@ -3425,7 +4312,11 @@ public QueueStatusModel getQueueStatus(String hostName, String queueName) throws return queueStatusModel; } } catch (Throwable e) { - throw convertException(e, "Error while retrieving queue status"); + logger.error("Error while retrieving queue status", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving queue status More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3438,7 +4329,11 @@ public void createGatewayGroups(GatewayGroups gatewayGroups) throws RegistryServ } gatewayGroupsRepository.create(gatewayGroups); } catch (Throwable e) { - throw convertException(e, "Error while creating gateway groups"); + logger.error("Error while creating gateway groups", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while creating gateway groups More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3451,7 +4346,11 @@ public void updateGatewayGroups(GatewayGroups gatewayGroups) throws RegistryServ } gatewayGroupsRepository.update(gatewayGroups); } catch (Throwable e) { - throw convertException(e, "Error while updating gateway groups"); + logger.error("Error while updating gateway groups", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while updating gateway groups More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3459,7 +4358,11 @@ public boolean isGatewayGroupsExists(String gatewayId) throws RegistryServiceExc try { return gatewayGroupsRepository.isExists(gatewayId); } catch (Throwable e) { - throw convertException(e, "Error while checking if gateway groups exist"); + logger.error("Error while checking if gateway groups exist", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while checking if gateway groups exist More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3467,7 +4370,11 @@ public List listAllParsers(String gatewayId) throws RegistryServiceExcep try { return parserRepository.getAllParsers(gatewayId); } catch (Throwable e) { - throw convertException(e, "Error while listing all parsers"); + logger.error("Error while listing all parsers", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while listing all parsers More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3476,7 +4383,12 @@ public List getParsingTemplatesForApplication(String applicatio try { return parsingTemplateRepository.getParsingTemplatesForApplication(applicationInterfaceId); } catch (Throwable e) { - throw convertException(e, "Error while retrieving parsing templates for application"); + logger.error("Error while retrieving parsing templates for application", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage( + "Error while retrieving parsing templates for application More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3491,7 +4403,12 @@ public List getParsingTemplatesForExperiment(String experimentI } return Collections.emptyList(); } catch (Throwable e) { - throw convertException(e, "Error while retrieving parsing templates for experiment"); + logger.error("Error while retrieving parsing templates for experiment", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage( + "Error while retrieving parsing templates for experiment More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3499,7 +4416,11 @@ public List listAllParsingTemplates(String gatewayId) throws Re try { return parsingTemplateRepository.getAllParsingTemplates(gatewayId); } catch (Throwable e) { - throw convertException(e, "Error while listing all parsing templates"); + logger.error("Error while listing all parsing templates", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while listing all parsing templates More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3515,7 +4436,12 @@ public List getAllUserComputeResourcePreferences( .getUserResourceProfile(userId, gatewayID) .getUserComputeResourcePreferences(); } catch (Throwable e) { - throw convertException(e, "Error while retrieving all user compute resource preferences"); + logger.error("Error while retrieving all user compute resource preferences", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage( + "Error while retrieving all user compute resource preferences More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } @@ -3530,7 +4456,11 @@ public List getAllUserStoragePreferences(String userId, S .getUserResourceProfile(userId, gatewayID) .getUserStoragePreferences(); } catch (Throwable e) { - throw convertException(e, "Error while retrieving all user storage preferences"); + logger.error("Error while retrieving all user storage preferences", e); + RegistryServiceException exception = new RegistryServiceException(); + exception.setMessage("Error while retrieving all user storage preferences More info : " + e.getMessage()); + exception.initCause(e); + throw exception; } } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/SharingRegistryService.java b/airavata-api/src/main/java/org/apache/airavata/service/SharingRegistryService.java index 11d6b65ba5..5f2c8b3594 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/SharingRegistryService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/SharingRegistryService.java @@ -35,13 +35,6 @@ public class SharingRegistryService { public static String OWNER_PERMISSION_NAME = "OWNER"; - private SharingRegistryException convertException(Throwable ex, String context) { - logger.error(context + ": " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException(context + ": " + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); - exception.initCause(ex); - return exception; - } - /** * * Domain Operations * * @@ -70,7 +63,8 @@ public String createDomain(Domain domain) throws SharingRegistryException, Dupli throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + SharingRegistryException exception = + new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); exception.initCause(ex); throw exception; } @@ -88,7 +82,8 @@ public boolean updateDomain(Domain domain) throws SharingRegistryException { throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + SharingRegistryException exception = + new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); exception.initCause(ex); throw exception; } @@ -101,7 +96,8 @@ public boolean isDomainExists(String domainId) throws SharingRegistryException { throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + SharingRegistryException exception = + new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); exception.initCause(ex); throw exception; } @@ -115,7 +111,8 @@ public boolean deleteDomain(String domainId) throws SharingRegistryException { throw e; } catch (Throwable ex) { logger.error(ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + SharingRegistryException exception = + new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); exception.initCause(ex); throw exception; } @@ -127,7 +124,11 @@ public Domain getDomain(String domainId) throws SharingRegistryException { } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - throw convertException(ex, "Error while getting domain"); + logger.error("Error while getting domain: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while getting domain: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -137,7 +138,11 @@ public List getDomains(int offset, int limit) throws SharingRegistryExce } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - throw convertException(ex, "Error while getting domains"); + logger.error("Error while getting domains: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while getting domains: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -170,14 +175,20 @@ public String createUser(User user) throws SharingRegistryException, DuplicateEn Domain domain = new DomainRepository().get(user.getDomainId()); if (domain.getInitialUserGroupId() != null) { addUsersToGroup( - user.getDomainId(), Collections.singletonList(user.getUserId()), domain.getInitialUserGroupId()); + user.getDomainId(), + Collections.singletonList(user.getUserId()), + domain.getInitialUserGroupId()); } return user.getUserId(); } catch (SharingRegistryException | DuplicateEntryException e) { throw e; } catch (Throwable ex) { - throw convertException(ex, "Error while creating user"); + logger.error("Error while creating user: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while creating user: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -203,7 +214,11 @@ public boolean updatedUser(User user) throws SharingRegistryException { } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - throw convertException(ex, "Error while updating user"); + logger.error("Error while updating user: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while updating user: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -216,7 +231,11 @@ public boolean isUserExists(String domainId, String userId) throws SharingRegist } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - throw convertException(ex, "Error while checking if user exists"); + logger.error("Error while checking if user exists: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while checking if user exists: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -235,7 +254,11 @@ public boolean deleteUser(String domainId, String userId) throws SharingRegistry } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - throw convertException(ex, "Error while deleting user"); + logger.error("Error while deleting user: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while deleting user: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -248,7 +271,11 @@ public User getUser(String domainId, String userId) throws SharingRegistryExcept } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - throw convertException(ex, "Error while getting user"); + logger.error("Error while getting user: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while getting user: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -258,7 +285,11 @@ public List getUsers(String domain, int offset, int limit) throws SharingR filters.put(DBConstants.UserTable.DOMAIN_ID, domain); return (new UserRepository()).select(filters, offset, limit); } catch (Throwable ex) { - throw convertException(ex, "Error while getting users"); + logger.error("Error while getting users: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while getting users: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -286,7 +317,11 @@ public String createGroup(UserGroup group) throws SharingRegistryException { } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - throw convertException(ex, "Error while creating group"); + logger.error("Error while creating group: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while creating group: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -309,7 +344,11 @@ public boolean updateGroup(UserGroup group) throws SharingRegistryException { } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - throw convertException(ex, "Error while updating group"); + logger.error("Error while updating group: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while updating group: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -320,7 +359,11 @@ public boolean isGroupExists(String domainId, String groupId) throws SharingRegi userGroupPK.setGroupId(groupId); return (new UserGroupRepository()).isExists(userGroupPK); } catch (Throwable ex) { - throw convertException(ex, "Error while checking if group exists"); + logger.error("Error while checking if group exists: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while checking if group exists: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -332,7 +375,11 @@ public boolean deleteGroup(String domainId, String groupId) throws SharingRegist (new UserGroupRepository()).delete(userGroupPK); return true; } catch (Throwable ex) { - throw convertException(ex, "Error while deleting group"); + logger.error("Error while deleting group: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while deleting group: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -343,7 +390,11 @@ public UserGroup getGroup(String domainId, String groupId) throws SharingRegistr userGroupPK.setDomainId(domainId); return (new UserGroupRepository()).get(userGroupPK); } catch (Throwable ex) { - throw convertException(ex, "Error while getting group"); + logger.error("Error while getting group: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while getting group: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -356,7 +407,11 @@ public List getGroups(String domain, int offset, int limit) throws Sh filters.put(DBConstants.UserGroupTable.GROUP_CARDINALITY, GroupCardinality.MULTI_USER.name()); return (new UserGroupRepository()).select(filters, offset, limit); } catch (Throwable ex) { - throw convertException(ex, "Error while getting groups"); + logger.error("Error while getting groups: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while getting groups: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -375,7 +430,11 @@ public boolean addUsersToGroup(String domainId, List userIds, String gro } return true; } catch (Throwable ex) { - throw convertException(ex, "Error while adding users to group"); + logger.error("Error while adding users to group: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while adding users to group: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -400,12 +459,16 @@ public boolean removeUsersFromGroup(String domainId, List userIds, Strin } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - throw convertException(ex, "Error while removing users from group"); + logger.error("Error while removing users from group: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while removing users from group: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } public boolean transferGroupOwnership(String domainId, String groupId, String newOwnerId) - throws SharingRegistryException, DuplicateEntryException { + throws SharingRegistryException { try { List groupUser = getGroupMembersOfTypeUser(domainId, groupId, 0, -1); if (!isUserBelongsToGroup(groupUser, newOwnerId)) { @@ -434,10 +497,15 @@ public boolean transferGroupOwnership(String domainId, String groupId, String ne (new UserGroupRepository()).update(newUserGroup); return true; - } catch (SharingRegistryException | DuplicateEntryException e) { + } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - throw convertException(ex, "Error while transferring group ownership"); + logger.error("Error while transferring group ownership: " + ex.getMessage(), ex); + SharingRegistryException exception = + new SharingRegistryException("Error while transferring group ownership: " + ex.getMessage() + + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -451,7 +519,7 @@ private boolean isUserBelongsToGroup(List groupUser, String newOwnerId) { } public boolean addGroupAdmins(String domainId, String groupId, List adminIds) - throws SharingRegistryException, DuplicateEntryException { + throws SharingRegistryException { try { List groupUser = getGroupMembersOfTypeUser(domainId, groupId, 0, -1); @@ -475,10 +543,14 @@ public boolean addGroupAdmins(String domainId, String groupId, List admi (new GroupAdminRepository()).create(admin); } return true; - } catch (SharingRegistryException | DuplicateEntryException e) { + } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - throw convertException(ex, "Error while adding group admins"); + logger.error("Error while adding group admins: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while adding group admins: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -494,7 +566,11 @@ public boolean removeGroupAdmins(String domainId, String groupId, List a } return true; } catch (Throwable ex) { - throw convertException(ex, "Error while removing group admins"); + logger.error("Error while removing group admins: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while removing group admins: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -508,7 +584,11 @@ public boolean hasAdminAccess(String domainId, String groupId, String adminId) t if ((new GroupAdminRepository()).get(groupAdminPK) != null) return true; return false; } catch (Throwable ex) { - throw convertException(ex, "Error while checking admin access"); + logger.error("Error while checking admin access: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while checking admin access: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -522,7 +602,11 @@ public boolean hasOwnerAccess(String domainId, String groupId, String ownerId) t if (getGroup.getOwnerId().equals(ownerId)) return true; return false; } catch (Throwable ex) { - throw convertException(ex, "Error while checking owner access"); + logger.error("Error while checking owner access: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while checking owner access: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -533,7 +617,12 @@ public List getGroupMembersOfTypeUser(String domainId, String groupId, int List groupMemberUsers = (new GroupMembershipRepository()).getAllChildUsers(domainId, groupId); return groupMemberUsers; } catch (Throwable ex) { - throw convertException(ex, "Error while getting group members of type user"); + logger.error("Error while getting group members of type user: " + ex.getMessage(), ex); + SharingRegistryException exception = + new SharingRegistryException("Error while getting group members of type user: " + ex.getMessage() + + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -544,7 +633,12 @@ public List getGroupMembersOfTypeGroup(String domainId, String groupI List groupMemberGroups = (new GroupMembershipRepository()).getAllChildGroups(domainId, groupId); return groupMemberGroups; } catch (Throwable ex) { - throw convertException(ex, "Error while getting group members of type group"); + logger.error("Error while getting group members of type group: " + ex.getMessage(), ex); + SharingRegistryException exception = + new SharingRegistryException("Error while getting group members of type group: " + ex.getMessage() + + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -564,7 +658,12 @@ public boolean addChildGroupsToParentGroup(String domainId, List childId } return true; } catch (Throwable ex) { - throw convertException(ex, "Error while adding child groups to parent group"); + logger.error("Error while adding child groups to parent group: " + ex.getMessage(), ex); + SharingRegistryException exception = + new SharingRegistryException("Error while adding child groups to parent group: " + ex.getMessage() + + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -578,7 +677,12 @@ public boolean removeChildGroupFromParentGroup(String domainId, String childId, (new GroupMembershipRepository()).delete(groupMembershipPK); return true; } catch (Throwable ex) { - throw convertException(ex, "Error while removing child group from parent group"); + logger.error("Error while removing child group from parent group: " + ex.getMessage(), ex); + SharingRegistryException exception = + new SharingRegistryException("Error while removing child group from parent group: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -587,7 +691,12 @@ public List getAllMemberGroupsForUser(String domainId, String userId) GroupMembershipRepository groupMembershipRepository = new GroupMembershipRepository(); return groupMembershipRepository.getAllMemberGroupsForUser(domainId, userId); } catch (Throwable ex) { - throw convertException(ex, "Error while getting all member groups for user"); + logger.error("Error while getting all member groups for user: " + ex.getMessage(), ex); + SharingRegistryException exception = + new SharingRegistryException("Error while getting all member groups for user: " + ex.getMessage() + + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -610,7 +719,11 @@ public String createEntityType(EntityType entityType) throws SharingRegistryExce } catch (SharingRegistryException | DuplicateEntryException e) { throw e; } catch (Throwable ex) { - throw convertException(ex, "Error while creating entity type"); + logger.error("Error while creating entity type: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while creating entity type: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -628,7 +741,11 @@ public boolean updateEntityType(EntityType entityType) throws SharingRegistryExc } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - throw convertException(ex, "Error while updating entity type"); + logger.error("Error while updating entity type: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while updating entity type: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -639,7 +756,12 @@ public boolean isEntityTypeExists(String domainId, String entityTypeId) throws S entityTypePK.setEntityTypeId(entityTypeId); return (new EntityTypeRepository()).isExists(entityTypePK); } catch (Throwable ex) { - throw convertException(ex, "Error while checking if entity type exists"); + logger.error("Error while checking if entity type exists: " + ex.getMessage(), ex); + SharingRegistryException exception = + new SharingRegistryException("Error while checking if entity type exists: " + ex.getMessage() + + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -651,7 +773,11 @@ public boolean deleteEntityType(String domainId, String entityTypeId) throws Sha (new EntityTypeRepository()).delete(entityTypePK); return true; } catch (Throwable ex) { - throw convertException(ex, "Error while deleting entity type"); + logger.error("Error while deleting entity type: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while deleting entity type: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -662,7 +788,11 @@ public EntityType getEntityType(String domainId, String entityTypeId) throws Sha entityTypePK.setEntityTypeId(entityTypeId); return (new EntityTypeRepository()).get(entityTypePK); } catch (Throwable ex) { - throw convertException(ex, "Error while getting entity type"); + logger.error("Error while getting entity type: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while getting entity type: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -672,7 +802,11 @@ public List getEntityTypes(String domain, int offset, int limit) thr filters.put(DBConstants.EntityTypeTable.DOMAIN_ID, domain); return (new EntityTypeRepository()).select(filters, offset, limit); } catch (Throwable ex) { - throw convertException(ex, "Error while getting entity types"); + logger.error("Error while getting entity types: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while getting entity types: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -695,7 +829,11 @@ public String createPermissionType(PermissionType permissionType) } catch (SharingRegistryException | DuplicateEntryException e) { throw e; } catch (Throwable ex) { - throw convertException(ex, "Error while creating permission type"); + logger.error("Error while creating permission type: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while creating permission type: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -712,7 +850,11 @@ public boolean updatePermissionType(PermissionType permissionType) throws Sharin } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - throw convertException(ex, "Error while updating permission type"); + logger.error("Error while updating permission type: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while updating permission type: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -723,7 +865,12 @@ public boolean isPermissionExists(String domainId, String permissionId) throws S permissionTypePK.setPermissionTypeId(permissionId); return (new PermissionTypeRepository()).isExists(permissionTypePK); } catch (Throwable ex) { - throw convertException(ex, "Error while checking if permission exists"); + logger.error("Error while checking if permission exists: " + ex.getMessage(), ex); + SharingRegistryException exception = + new SharingRegistryException("Error while checking if permission exists: " + ex.getMessage() + + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -735,7 +882,11 @@ public boolean deletePermissionType(String domainId, String permissionTypeId) th (new PermissionTypeRepository()).delete(permissionTypePK); return true; } catch (Throwable ex) { - throw convertException(ex, "Error while deleting permission type"); + logger.error("Error while deleting permission type: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while deleting permission type: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -746,7 +897,11 @@ public PermissionType getPermissionType(String domainId, String permissionTypeId permissionTypePK.setPermissionTypeId(permissionTypeId); return (new PermissionTypeRepository()).get(permissionTypePK); } catch (Throwable ex) { - throw convertException(ex, "Error while getting permission type"); + logger.error("Error while getting permission type: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while getting permission type: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -757,7 +912,11 @@ public List getPermissionTypes(String domain, int offset, int li filters.put(DBConstants.PermissionTypeTable.DOMAIN_ID, domain); return (new PermissionTypeRepository()).select(filters, offset, limit); } catch (Throwable ex) { - throw convertException(ex, "Error while getting permission types"); + logger.error("Error while getting permission types: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while getting permission types: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -816,7 +975,11 @@ public String createEntity(Entity entity) throws SharingRegistryException, Dupli } catch (SharingRegistryException | DuplicateEntryException e) { throw e; } catch (Throwable ex) { - throw convertException(ex, "Error while creating entity"); + logger.error("Error while creating entity: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while creating entity: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -841,7 +1004,12 @@ private void addCascadingPermissionsForEntity(Entity entity) throws SharingRegis } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - throw convertException(ex, "Error while adding cascading permissions for entity"); + logger.error("Error while adding cascading permissions for entity: " + ex.getMessage(), ex); + SharingRegistryException exception = + new SharingRegistryException("Error while adding cascading permissions for entity: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -881,7 +1049,11 @@ public boolean updateEntity(Entity entity) throws SharingRegistryException { } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - throw convertException(ex, "Error while updating entity"); + logger.error("Error while updating entity: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while updating entity: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -892,7 +1064,11 @@ public boolean isEntityExists(String domainId, String entityId) throws SharingRe entityPK.setEntityId(entityId); return (new EntityRepository()).isExists(entityPK); } catch (Throwable ex) { - throw convertException(ex, "Error while checking if entity exists"); + logger.error("Error while checking if entity exists: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while checking if entity exists: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -905,7 +1081,11 @@ public boolean deleteEntity(String domainId, String entityId) throws SharingRegi (new EntityRepository()).delete(entityPK); return true; } catch (Throwable ex) { - throw convertException(ex, "Error while deleting entity"); + logger.error("Error while deleting entity: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while deleting entity: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -916,7 +1096,11 @@ public Entity getEntity(String domainId, String entityId) throws SharingRegistry entityPK.setEntityId(entityId); return (new EntityRepository()).get(entityPK); } catch (Throwable ex) { - throw convertException(ex, "Error while getting entity"); + logger.error("Error while getting entity: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while getting entity: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -931,7 +1115,11 @@ public List searchEntities( .forEach(gm -> groupIds.add(gm.getParentId())); return (new EntityRepository()).searchEntities(domainId, groupIds, filters, offset, limit); } catch (Throwable ex) { - throw convertException(ex, "Error while searching entities"); + logger.error("Error while searching entities: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while searching entities: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -940,7 +1128,12 @@ public List getListOfSharedUsers(String domainId, String entityId, String try { return (new UserRepository()).getAccessibleUsers(domainId, entityId, permissionTypeId); } catch (Throwable ex) { - throw convertException(ex, "Error while getting list of shared users"); + logger.error("Error while getting list of shared users: " + ex.getMessage(), ex); + SharingRegistryException exception = + new SharingRegistryException("Error while getting list of shared users: " + ex.getMessage() + + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -949,7 +1142,12 @@ public List getListOfDirectlySharedUsers(String domainId, String entityId, try { return (new UserRepository()).getDirectlyAccessibleUsers(domainId, entityId, permissionTypeId); } catch (Throwable ex) { - throw convertException(ex, "Error while getting list of directly shared users"); + logger.error("Error while getting list of directly shared users: " + ex.getMessage(), ex); + SharingRegistryException exception = + new SharingRegistryException("Error while getting list of directly shared users: " + ex.getMessage() + + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -958,7 +1156,12 @@ public List getListOfSharedGroups(String domainId, String entityId, S try { return (new UserGroupRepository()).getAccessibleGroups(domainId, entityId, permissionTypeId); } catch (Throwable ex) { - throw convertException(ex, "Error while getting list of shared groups"); + logger.error("Error while getting list of shared groups: " + ex.getMessage(), ex); + SharingRegistryException exception = + new SharingRegistryException("Error while getting list of shared groups: " + ex.getMessage() + + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -967,7 +1170,12 @@ public List getListOfDirectlySharedGroups(String domainId, String ent try { return (new UserGroupRepository()).getDirectlyAccessibleGroups(domainId, entityId, permissionTypeId); } catch (Throwable ex) { - throw convertException(ex, "Error while getting list of directly shared groups"); + logger.error("Error while getting list of directly shared groups: " + ex.getMessage(), ex); + SharingRegistryException exception = + new SharingRegistryException("Error while getting list of directly shared groups: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -979,7 +1187,11 @@ public boolean shareEntityWithUsers( } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - throw convertException(ex, "Error while sharing entity with users"); + logger.error("Error while sharing entity with users: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while sharing entity with users: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -995,7 +1207,11 @@ public boolean shareEntityWithGroups( } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - throw convertException(ex, "Error while sharing entity with groups"); + logger.error("Error while sharing entity with groups: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while sharing entity with groups: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -1053,7 +1269,8 @@ private boolean shareEntity( sharing.setUpdatedTime(System.currentTimeMillis()); sharings.add(sharing); (new EntityRepository()) - .getChildEntities(domainId, childEntityId).stream().forEach(e -> temp.addLast(e)); + .getChildEntities(domainId, childEntityId).stream() + .forEach(e -> temp.addLast(e)); } } } @@ -1069,7 +1286,11 @@ private boolean shareEntity( } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - throw convertException(ex, "Error while sharing entity"); + logger.error("Error while sharing entity: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while sharing entity: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -1084,7 +1305,12 @@ public boolean revokeEntitySharingFromUsers( } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - throw convertException(ex, "Error while revoking entity sharing from users"); + logger.error("Error while revoking entity sharing from users: " + ex.getMessage(), ex); + SharingRegistryException exception = + new SharingRegistryException("Error while revoking entity sharing from users: " + ex.getMessage() + + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -1099,7 +1325,12 @@ public boolean revokeEntitySharingFromGroups( } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - throw convertException(ex, "Error while revoking entity sharing from groups"); + logger.error("Error while revoking entity sharing from groups: " + ex.getMessage(), ex); + SharingRegistryException exception = + new SharingRegistryException("Error while revoking entity sharing from groups: " + ex.getMessage() + + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -1114,14 +1345,18 @@ public boolean userHasAccess(String domainId, String userId, String entityId, St groupIds.add(userId); return (new SharingRepository()) .hasAccess( - domainId, - entityId, - groupIds, - Arrays.asList( - permissionTypeId, - (new PermissionTypeRepository()).getOwnerPermissionTypeIdForDomain(domainId))); + domainId, + entityId, + groupIds, + Arrays.asList( + permissionTypeId, + (new PermissionTypeRepository()).getOwnerPermissionTypeIdForDomain(domainId))); } catch (Throwable ex) { - throw convertException(ex, "Error while checking user access"); + logger.error("Error while checking user access: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while checking user access: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } @@ -1174,7 +1409,11 @@ public boolean revokeEntitySharing( } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - throw convertException(ex, "Error while revoking entity sharing"); + logger.error("Error while revoking entity sharing: " + ex.getMessage(), ex); + SharingRegistryException exception = new SharingRegistryException("Error while revoking entity sharing: " + + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + exception.initCause(ex); + throw exception; } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/TenantProfileService.java b/airavata-api/src/main/java/org/apache/airavata/service/TenantProfileService.java index 2ceb1cac62..bffdd00c19 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/TenantProfileService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/TenantProfileService.java @@ -48,14 +48,6 @@ public class TenantProfileService { private TenantProfileRepository tenantProfileRepository; private DBEventPublisherUtils dbEventPublisherUtils = new DBEventPublisherUtils(DBEventService.TENANT); - private TenantProfileServiceException convertException(Throwable e, String msg) { - logger.error(msg, e); - TenantProfileServiceException exception = new TenantProfileServiceException(); - exception.setMessage(msg + ". More info : " + e.getMessage()); - exception.initCause(e); - return exception; - } - public TenantProfileService() { logger.debug("Initializing TenantProfileService"); this.tenantProfileRepository = new TenantProfileRepository(Gateway.class, GatewayEntity.class); diff --git a/airavata-api/src/main/java/org/apache/airavata/service/UserProfileService.java b/airavata-api/src/main/java/org/apache/airavata/service/UserProfileService.java index 74aeb6c5d3..578574d15c 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/UserProfileService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/UserProfileService.java @@ -49,14 +49,6 @@ public class UserProfileService { private UserProfileRepository userProfileRepository; private DBEventPublisherUtils dbEventPublisherUtils = new DBEventPublisherUtils(DBEventService.USER_PROFILE); - private UserProfileServiceException convertException(Throwable e, String msg) { - logger.error(msg, e); - UserProfileServiceException exception = new UserProfileServiceException(); - exception.setMessage(msg + ". More info : " + e.getMessage()); - exception.initCause(e); - return exception; - } - public UserProfileService() { userProfileRepository = new UserProfileRepository(); } @@ -150,8 +142,7 @@ public boolean updateUserProfile(AuthzToken authzToken, UserProfile userProfile) } } - private Runnable getIAMUserProfileUpdater(AuthzToken authzToken, UserProfile userProfile) - throws UserProfileServiceException { + private Runnable getIAMUserProfileUpdater(AuthzToken authzToken, UserProfile userProfile) { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); return () -> { try { diff --git a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/GroupManagerServiceHandler.java b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/GroupManagerServiceHandler.java index 374d338fe9..da507b9815 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/GroupManagerServiceHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/GroupManagerServiceHandler.java @@ -28,7 +28,6 @@ import org.apache.airavata.service.profile.groupmanager.cpi.exception.GroupManagerServiceException; import org.apache.airavata.service.profile.groupmanager.cpi.group_manager_cpiConstants; import org.apache.airavata.service.security.interceptor.SecurityCheck; -import org.apache.thrift.TException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,89 +48,89 @@ public String getAPIVersion() throws AiravataSystemException { @Override @SecurityCheck public String createGroup(AuthzToken authzToken, GroupModel groupModel) - throws GroupManagerServiceException, AuthorizationException, TException { + throws GroupManagerServiceException, AuthorizationException { return groupManagerService.createGroup(authzToken, groupModel); } @Override @SecurityCheck public boolean updateGroup(AuthzToken authzToken, GroupModel groupModel) - throws GroupManagerServiceException, AuthorizationException, TException { + throws GroupManagerServiceException, AuthorizationException { return groupManagerService.updateGroup(authzToken, groupModel); } @Override @SecurityCheck public boolean deleteGroup(AuthzToken authzToken, String groupId, String ownerId) - throws GroupManagerServiceException, AuthorizationException, TException { + throws GroupManagerServiceException, AuthorizationException { return groupManagerService.deleteGroup(authzToken, groupId, ownerId); } @Override @SecurityCheck public GroupModel getGroup(AuthzToken authzToken, String groupId) - throws GroupManagerServiceException, AuthorizationException, TException { + throws GroupManagerServiceException, AuthorizationException { return groupManagerService.getGroup(authzToken, groupId); } @Override @SecurityCheck public List getGroups(AuthzToken authzToken) - throws GroupManagerServiceException, AuthorizationException, TException { + throws GroupManagerServiceException, AuthorizationException { return groupManagerService.getGroups(authzToken); } @Override @SecurityCheck public List getAllGroupsUserBelongs(AuthzToken authzToken, String userName) - throws GroupManagerServiceException, AuthorizationException, TException { + throws GroupManagerServiceException, AuthorizationException { return groupManagerService.getAllGroupsUserBelongs(authzToken, userName); } @Override public boolean addUsersToGroup(AuthzToken authzToken, List userIds, String groupId) - throws GroupManagerServiceException, AuthorizationException, TException { + throws GroupManagerServiceException, AuthorizationException { return groupManagerService.addUsersToGroup(authzToken, userIds, groupId); } @Override public boolean removeUsersFromGroup(AuthzToken authzToken, List userIds, String groupId) - throws GroupManagerServiceException, AuthorizationException, TException { + throws GroupManagerServiceException, AuthorizationException { return groupManagerService.removeUsersFromGroup(authzToken, userIds, groupId); } @Override @SecurityCheck public boolean transferGroupOwnership(AuthzToken authzToken, String groupId, String newOwnerId) - throws GroupManagerServiceException, AuthorizationException, TException { + throws GroupManagerServiceException, AuthorizationException { return groupManagerService.transferGroupOwnership(authzToken, groupId, newOwnerId); } @Override @SecurityCheck public boolean addGroupAdmins(AuthzToken authzToken, String groupId, List adminIds) - throws GroupManagerServiceException, AuthorizationException, TException { + throws GroupManagerServiceException, AuthorizationException { return groupManagerService.addGroupAdmins(authzToken, groupId, adminIds); } @Override @SecurityCheck public boolean removeGroupAdmins(AuthzToken authzToken, String groupId, List adminIds) - throws GroupManagerServiceException, AuthorizationException, TException { + throws GroupManagerServiceException, AuthorizationException { return groupManagerService.removeGroupAdmins(authzToken, groupId, adminIds); } @Override @SecurityCheck public boolean hasAdminAccess(AuthzToken authzToken, String groupId, String adminId) - throws GroupManagerServiceException, AuthorizationException, TException { + throws GroupManagerServiceException, AuthorizationException { return groupManagerService.hasAdminAccess(authzToken, groupId, adminId); } @Override @SecurityCheck public boolean hasOwnerAccess(AuthzToken authzToken, String groupId, String ownerId) - throws GroupManagerServiceException, AuthorizationException, TException { + throws GroupManagerServiceException, AuthorizationException { return groupManagerService.hasOwnerAccess(authzToken, groupId, ownerId); } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/IamAdminServicesHandler.java b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/IamAdminServicesHandler.java index 7833060862..5fb4ebc0a8 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/IamAdminServicesHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/IamAdminServicesHandler.java @@ -29,7 +29,6 @@ import org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException; import org.apache.airavata.service.profile.iam.admin.services.cpi.iam_admin_services_cpiConstants; import org.apache.airavata.service.security.interceptor.SecurityCheck; -import org.apache.thrift.TException; public class IamAdminServicesHandler implements IamAdminServices.Iface { @@ -54,7 +53,7 @@ public Gateway setUpGateway(AuthzToken authzToken, Gateway gateway) @Override @SecurityCheck public boolean isUsernameAvailable(AuthzToken authzToken, String username) - throws IamAdminServicesException, AuthorizationException, TException { + throws IamAdminServicesException, AuthorizationException { return iamAdminService.isUsernameAvailable(authzToken, username); } @@ -81,56 +80,56 @@ public boolean enableUser(AuthzToken authzToken, String username) @Override @SecurityCheck public boolean isUserEnabled(AuthzToken authzToken, String username) - throws IamAdminServicesException, AuthorizationException, TException { + throws IamAdminServicesException, AuthorizationException { return iamAdminService.isUserEnabled(authzToken, username); } @Override @SecurityCheck public boolean isUserExist(AuthzToken authzToken, String username) - throws IamAdminServicesException, AuthorizationException, TException { + throws IamAdminServicesException, AuthorizationException { return iamAdminService.isUserExist(authzToken, username); } @Override @SecurityCheck public UserProfile getUser(AuthzToken authzToken, String username) - throws IamAdminServicesException, AuthorizationException, TException { + throws IamAdminServicesException, AuthorizationException { return iamAdminService.getUser(authzToken, username); } @Override @SecurityCheck public List getUsers(AuthzToken authzToken, int offset, int limit, String search) - throws IamAdminServicesException, AuthorizationException, TException { + throws IamAdminServicesException, AuthorizationException { return iamAdminService.getUsers(authzToken, offset, limit, search); } @Override @SecurityCheck public boolean resetUserPassword(AuthzToken authzToken, String username, String newPassword) - throws IamAdminServicesException, AuthorizationException, TException { + throws IamAdminServicesException, AuthorizationException { return iamAdminService.resetUserPassword(authzToken, username, newPassword); } @Override @SecurityCheck public List findUsers(AuthzToken authzToken, String email, String userId) - throws IamAdminServicesException, AuthorizationException, TException { + throws IamAdminServicesException, AuthorizationException { return iamAdminService.findUsers(authzToken, email, userId); } @Override @SecurityCheck public void updateUserProfile(AuthzToken authzToken, UserProfile userDetails) - throws IamAdminServicesException, AuthorizationException, TException { + throws IamAdminServicesException, AuthorizationException { iamAdminService.updateUserProfile(authzToken, userDetails); } @Override @SecurityCheck public boolean deleteUser(AuthzToken authzToken, String username) - throws IamAdminServicesException, AuthorizationException, TException { + throws IamAdminServicesException, AuthorizationException { return iamAdminService.deleteUser(authzToken, username); } @@ -138,7 +137,7 @@ public boolean deleteUser(AuthzToken authzToken, String username) @SecurityCheck @Deprecated public boolean addRoleToUser(AuthzToken authzToken, String username, String roleName) - throws IamAdminServicesException, AuthorizationException, TException { + throws IamAdminServicesException, AuthorizationException { return iamAdminService.addRoleToUser(authzToken, username, roleName); } @@ -146,7 +145,7 @@ public boolean addRoleToUser(AuthzToken authzToken, String username, String role @SecurityCheck @Deprecated public boolean removeRoleFromUser(AuthzToken authzToken, String username, String roleName) - throws IamAdminServicesException, AuthorizationException, TException { + throws IamAdminServicesException, AuthorizationException { return iamAdminService.removeRoleFromUser(authzToken, username, roleName); } @@ -154,7 +153,7 @@ public boolean removeRoleFromUser(AuthzToken authzToken, String username, String @SecurityCheck @Deprecated public List getUsersWithRole(AuthzToken authzToken, String roleName) - throws IamAdminServicesException, AuthorizationException, TException { + throws IamAdminServicesException, AuthorizationException { return iamAdminService.getUsersWithRole(authzToken, roleName); } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/TenantProfileServiceHandler.java b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/TenantProfileServiceHandler.java index 13e97c812c..26b9bddc6e 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/TenantProfileServiceHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/TenantProfileServiceHandler.java @@ -28,7 +28,6 @@ import org.apache.airavata.service.profile.tenant.cpi.exception.TenantProfileServiceException; import org.apache.airavata.service.profile.tenant.cpi.profile_tenant_cpiConstants; import org.apache.airavata.service.security.interceptor.SecurityCheck; -import org.apache.thrift.TException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -53,49 +52,49 @@ public String getAPIVersion() throws AiravataSystemException { @Override @SecurityCheck public String addGateway(AuthzToken authzToken, Gateway gateway) - throws TenantProfileServiceException, AuthorizationException, TException { + throws TenantProfileServiceException, AuthorizationException { return tenantProfileService.addGateway(authzToken, gateway); } @Override @SecurityCheck public boolean updateGateway(AuthzToken authzToken, Gateway updatedGateway) - throws TenantProfileServiceException, AuthorizationException, TException { + throws TenantProfileServiceException, AuthorizationException { return tenantProfileService.updateGateway(authzToken, updatedGateway); } @Override @SecurityCheck public Gateway getGateway(AuthzToken authzToken, String airavataInternalGatewayId) - throws TenantProfileServiceException, AuthorizationException, TException { + throws TenantProfileServiceException, AuthorizationException { return tenantProfileService.getGateway(authzToken, airavataInternalGatewayId); } @Override @SecurityCheck public boolean deleteGateway(AuthzToken authzToken, String airavataInternalGatewayId, String gatewayId) - throws TenantProfileServiceException, AuthorizationException, TException { + throws TenantProfileServiceException, AuthorizationException { return tenantProfileService.deleteGateway(authzToken, airavataInternalGatewayId, gatewayId); } @Override @SecurityCheck public List getAllGateways(AuthzToken authzToken) - throws TenantProfileServiceException, AuthorizationException, TException { + throws TenantProfileServiceException, AuthorizationException { return tenantProfileService.getAllGateways(authzToken); } @Override @SecurityCheck public boolean isGatewayExist(AuthzToken authzToken, String gatewayId) - throws TenantProfileServiceException, AuthorizationException, TException { + throws TenantProfileServiceException, AuthorizationException { return tenantProfileService.isGatewayExist(authzToken, gatewayId); } @Override @SecurityCheck public List getAllGatewaysForUser(AuthzToken authzToken, String requesterUsername) - throws TenantProfileServiceException, AuthorizationException, TException { + throws TenantProfileServiceException, AuthorizationException { return tenantProfileService.getAllGatewaysForUser(authzToken, requesterUsername); } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/UserProfileServiceHandler.java b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/UserProfileServiceHandler.java index c2189db320..2435a16e51 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/UserProfileServiceHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/UserProfileServiceHandler.java @@ -24,13 +24,12 @@ import org.apache.airavata.model.error.AuthorizationException; import org.apache.airavata.model.security.AuthzToken; import org.apache.airavata.model.user.UserProfile; -import org.apache.airavata.service.profile.user.cpi.UserProfileService; import org.apache.airavata.service.profile.user.cpi.exception.UserProfileServiceException; import org.apache.airavata.service.profile.user.cpi.profile_user_cpiConstants; import org.apache.airavata.service.security.interceptor.SecurityCheck; -import org.apache.thrift.TException; -public class UserProfileServiceHandler implements UserProfileService.Iface { +public class UserProfileServiceHandler + implements org.apache.airavata.service.profile.user.cpi.UserProfileService.Iface { private org.apache.airavata.service.UserProfileService userProfileService; @@ -46,48 +45,48 @@ public String getAPIVersion() throws AiravataSystemException { @Override @SecurityCheck public String initializeUserProfile(AuthzToken authzToken) - throws UserProfileServiceException, AuthorizationException, TException { + throws UserProfileServiceException, AuthorizationException { return userProfileService.initializeUserProfile(authzToken); } @Override @SecurityCheck public String addUserProfile(AuthzToken authzToken, UserProfile userProfile) - throws UserProfileServiceException, AuthorizationException, TException { + throws UserProfileServiceException, AuthorizationException { return userProfileService.addUserProfile(authzToken, userProfile); } @Override @SecurityCheck public boolean updateUserProfile(AuthzToken authzToken, UserProfile userProfile) - throws UserProfileServiceException, AuthorizationException, TException { + throws UserProfileServiceException, AuthorizationException { return userProfileService.updateUserProfile(authzToken, userProfile); } @Override @SecurityCheck public UserProfile getUserProfileById(AuthzToken authzToken, String userId, String gatewayId) - throws UserProfileServiceException, AuthorizationException, TException { + throws UserProfileServiceException, AuthorizationException { return userProfileService.getUserProfileById(authzToken, userId, gatewayId); } @Override @SecurityCheck public boolean deleteUserProfile(AuthzToken authzToken, String userId, String gatewayId) - throws UserProfileServiceException, AuthorizationException, TException { + throws UserProfileServiceException, AuthorizationException { return userProfileService.deleteUserProfile(authzToken, userId, gatewayId); } @Override @SecurityCheck public List getAllUserProfilesInGateway(AuthzToken authzToken, String gatewayId, int offset, int limit) - throws UserProfileServiceException, AuthorizationException, TException { + throws UserProfileServiceException, AuthorizationException { return userProfileService.getAllUserProfilesInGateway(authzToken, gatewayId, offset, limit); } @Override public boolean doesUserExist(AuthzToken authzToken, String userId, String gatewayId) - throws UserProfileServiceException, AuthorizationException, TException { + throws UserProfileServiceException, AuthorizationException { return userProfileService.doesUserExist(authzToken, userId, gatewayId); } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/security/interceptor/SecurityInterceptor.java b/airavata-api/src/main/java/org/apache/airavata/service/security/interceptor/SecurityInterceptor.java index 74d735c5d3..0b07f8e69f 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/security/interceptor/SecurityInterceptor.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/security/interceptor/SecurityInterceptor.java @@ -74,12 +74,14 @@ private void authorize(AuthzToken authzToken, Map metaData) thro } } catch (AiravataSecurityException e) { logger.error(e.getMessage(), e); - AuthorizationException exception = new AuthorizationException("Error in authenticating or authorizing user."); + AuthorizationException exception = + new AuthorizationException("Error in authenticating or authorizing user."); exception.initCause(e); throw exception; } catch (ApplicationSettingsException e) { logger.error(e.getMessage(), e); - AuthorizationException exception = new AuthorizationException("Internal error in authenticating or authorizing user."); + AuthorizationException exception = + new AuthorizationException("Internal error in authenticating or authorizing user."); exception.initCause(e); throw exception; } diff --git a/airavata-api/src/main/java/org/apache/airavata/sharing/registry/messaging/SharingServiceDBEventHandler.java b/airavata-api/src/main/java/org/apache/airavata/sharing/registry/messaging/SharingServiceDBEventHandler.java index 173e809fe3..65261cc0a9 100644 --- a/airavata-api/src/main/java/org/apache/airavata/sharing/registry/messaging/SharingServiceDBEventHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/sharing/registry/messaging/SharingServiceDBEventHandler.java @@ -35,6 +35,7 @@ import org.apache.airavata.sharing.registry.client.SharingRegistryServiceClientFactory; import org.apache.airavata.sharing.registry.models.Domain; import org.apache.airavata.sharing.registry.models.Entity; +import org.apache.airavata.sharing.registry.models.EntityType; import org.apache.airavata.sharing.registry.models.PermissionType; import org.apache.airavata.sharing.registry.models.SharingRegistryException; import org.apache.airavata.sharing.registry.models.User; @@ -174,8 +175,7 @@ public void onMessage(MessageContext messageContext) { // Creating Entity Types for each domain log.info("Creating entity type. Id : " + domain.getDomainId() + ":PROJECT"); - org.apache.airavata.sharing.registry.models.EntityType entityType = - new org.apache.airavata.sharing.registry.models.EntityType(); + EntityType entityType = new EntityType(); entityType.setEntityTypeId(domain.getDomainId() + ":PROJECT"); entityType.setDomainId(domain.getDomainId()); entityType.setName("PROJECT"); diff --git a/airavata-api/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java index d897ead261..1dbef651b8 100644 --- a/airavata-api/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java @@ -27,7 +27,6 @@ import org.apache.airavata.sharing.registry.models.*; import org.apache.airavata.sharing.registry.service.cpi.SharingRegistryService; import org.apache.airavata.sharing.registry.service.cpi.sharing_cpiConstants; -import org.apache.thrift.TException; public class SharingRegistryServerHandler implements SharingRegistryService.Iface { private org.apache.airavata.service.SharingRegistryService sharingRegistryService; @@ -35,12 +34,12 @@ public class SharingRegistryServerHandler implements SharingRegistryService.Ifac public static String OWNER_PERMISSION_NAME = org.apache.airavata.service.SharingRegistryService.OWNER_PERMISSION_NAME; - public SharingRegistryServerHandler() throws ApplicationSettingsException, TException { + public SharingRegistryServerHandler() throws ApplicationSettingsException { this(new SharingRegistryDBInitConfig()); } public SharingRegistryServerHandler(SharingRegistryDBInitConfig sharingRegistryDBInitConfig) - throws ApplicationSettingsException, TException { + throws ApplicationSettingsException { DBInitializer.initializeDB(sharingRegistryDBInitConfig); sharingRegistryService = new org.apache.airavata.service.SharingRegistryService(); } @@ -55,12 +54,12 @@ public String getAPIVersion() throws AiravataSystemException { * * */ @Override - public String createDomain(Domain domain) throws SharingRegistryException, DuplicateEntryException, TException { + public String createDomain(Domain domain) throws SharingRegistryException, DuplicateEntryException { return sharingRegistryService.createDomain(domain); } @Override - public boolean updateDomain(Domain domain) throws SharingRegistryException, TException { + public boolean updateDomain(Domain domain) throws SharingRegistryException { return sharingRegistryService.updateDomain(domain); } @@ -70,22 +69,22 @@ public boolean updateDomain(Domain domain) throws SharingRegistryException, TExc * @param domainId */ @Override - public boolean isDomainExists(String domainId) throws SharingRegistryException, TException { + public boolean isDomainExists(String domainId) throws SharingRegistryException { return sharingRegistryService.isDomainExists(domainId); } @Override - public boolean deleteDomain(String domainId) throws SharingRegistryException, TException { + public boolean deleteDomain(String domainId) throws SharingRegistryException { return sharingRegistryService.deleteDomain(domainId); } @Override - public Domain getDomain(String domainId) throws SharingRegistryException, TException { + public Domain getDomain(String domainId) throws SharingRegistryException { return sharingRegistryService.getDomain(domainId); } @Override - public List getDomains(int offset, int limit) throws TException { + public List getDomains(int offset, int limit) throws SharingRegistryException { return sharingRegistryService.getDomains(offset, limit); } @@ -94,12 +93,12 @@ public List getDomains(int offset, int limit) throws TException { * * */ @Override - public String createUser(User user) throws SharingRegistryException, DuplicateEntryException, TException { + public String createUser(User user) throws SharingRegistryException, DuplicateEntryException { return sharingRegistryService.createUser(user); } @Override - public boolean updatedUser(User user) throws SharingRegistryException, TException { + public boolean updatedUser(User user) throws SharingRegistryException { return sharingRegistryService.updatedUser(user); } @@ -109,22 +108,22 @@ public boolean updatedUser(User user) throws SharingRegistryException, TExceptio * @param userId */ @Override - public boolean isUserExists(String domainId, String userId) throws SharingRegistryException, TException { + public boolean isUserExists(String domainId, String userId) throws SharingRegistryException { return sharingRegistryService.isUserExists(domainId, userId); } @Override - public boolean deleteUser(String domainId, String userId) throws SharingRegistryException, TException { + public boolean deleteUser(String domainId, String userId) throws SharingRegistryException { return sharingRegistryService.deleteUser(domainId, userId); } @Override - public User getUser(String domainId, String userId) throws SharingRegistryException, TException { + public User getUser(String domainId, String userId) throws SharingRegistryException { return sharingRegistryService.getUser(domainId, userId); } @Override - public List getUsers(String domain, int offset, int limit) throws SharingRegistryException, TException { + public List getUsers(String domain, int offset, int limit) throws SharingRegistryException { return sharingRegistryService.getUsers(domain, offset, limit); } @@ -133,12 +132,12 @@ public List getUsers(String domain, int offset, int limit) throws SharingR * * */ @Override - public String createGroup(UserGroup group) throws SharingRegistryException, TException { + public String createGroup(UserGroup group) throws SharingRegistryException { return sharingRegistryService.createGroup(group); } @Override - public boolean updateGroup(UserGroup group) throws SharingRegistryException, TException { + public boolean updateGroup(UserGroup group) throws SharingRegistryException { return sharingRegistryService.updateGroup(group); } @@ -148,20 +147,19 @@ public boolean updateGroup(UserGroup group) throws SharingRegistryException, TEx * @param groupId * @return * @throws SharingRegistryException - * @throws TException - */ + * @ */ @Override - public boolean isGroupExists(String domainId, String groupId) throws SharingRegistryException, TException { + public boolean isGroupExists(String domainId, String groupId) throws SharingRegistryException { return sharingRegistryService.isGroupExists(domainId, groupId); } @Override - public boolean deleteGroup(String domainId, String groupId) throws SharingRegistryException, TException { + public boolean deleteGroup(String domainId, String groupId) throws SharingRegistryException { return sharingRegistryService.deleteGroup(domainId, groupId); } @Override - public UserGroup getGroup(String domainId, String groupId) throws SharingRegistryException, TException { + public UserGroup getGroup(String domainId, String groupId) throws SharingRegistryException { return sharingRegistryService.getGroup(domainId, groupId); } @@ -172,73 +170,70 @@ public List getGroups(String domain, int offset, int limit) throws Sh @Override public boolean addUsersToGroup(String domainId, List userIds, String groupId) - throws SharingRegistryException, TException { + throws SharingRegistryException { return sharingRegistryService.addUsersToGroup(domainId, userIds, groupId); } @Override public boolean removeUsersFromGroup(String domainId, List userIds, String groupId) - throws SharingRegistryException, TException { + throws SharingRegistryException { return sharingRegistryService.removeUsersFromGroup(domainId, userIds, groupId); } @Override public boolean transferGroupOwnership(String domainId, String groupId, String newOwnerId) - throws SharingRegistryException, TException { + throws SharingRegistryException { return sharingRegistryService.transferGroupOwnership(domainId, groupId, newOwnerId); } @Override public boolean addGroupAdmins(String domainId, String groupId, List adminIds) - throws SharingRegistryException, TException { + throws SharingRegistryException { return sharingRegistryService.addGroupAdmins(domainId, groupId, adminIds); } @Override public boolean removeGroupAdmins(String domainId, String groupId, List adminIds) - throws SharingRegistryException, TException { + throws SharingRegistryException { return sharingRegistryService.removeGroupAdmins(domainId, groupId, adminIds); } @Override - public boolean hasAdminAccess(String domainId, String groupId, String adminId) - throws SharingRegistryException, TException { + public boolean hasAdminAccess(String domainId, String groupId, String adminId) throws SharingRegistryException { return sharingRegistryService.hasAdminAccess(domainId, groupId, adminId); } @Override - public boolean hasOwnerAccess(String domainId, String groupId, String ownerId) - throws SharingRegistryException, TException { + public boolean hasOwnerAccess(String domainId, String groupId, String ownerId) throws SharingRegistryException { return sharingRegistryService.hasOwnerAccess(domainId, groupId, ownerId); } @Override public List getGroupMembersOfTypeUser(String domainId, String groupId, int offset, int limit) - throws SharingRegistryException, TException { + throws SharingRegistryException { return sharingRegistryService.getGroupMembersOfTypeUser(domainId, groupId, offset, limit); } @Override public List getGroupMembersOfTypeGroup(String domainId, String groupId, int offset, int limit) - throws SharingRegistryException, TException { + throws SharingRegistryException { return sharingRegistryService.getGroupMembersOfTypeGroup(domainId, groupId, offset, limit); } @Override public boolean addChildGroupsToParentGroup(String domainId, List childIds, String groupId) - throws SharingRegistryException, TException { + throws SharingRegistryException { return sharingRegistryService.addChildGroupsToParentGroup(domainId, childIds, groupId); } @Override public boolean removeChildGroupFromParentGroup(String domainId, String childId, String groupId) - throws SharingRegistryException, TException { + throws SharingRegistryException { return sharingRegistryService.removeChildGroupFromParentGroup(domainId, childId, groupId); } @Override - public List getAllMemberGroupsForUser(String domainId, String userId) - throws SharingRegistryException, TException { + public List getAllMemberGroupsForUser(String domainId, String userId) throws SharingRegistryException { return sharingRegistryService.getAllMemberGroupsForUser(domainId, userId); } @@ -247,13 +242,12 @@ public List getAllMemberGroupsForUser(String domainId, String userId) * * */ @Override - public String createEntityType(EntityType entityType) - throws SharingRegistryException, DuplicateEntryException, TException { + public String createEntityType(EntityType entityType) throws SharingRegistryException, DuplicateEntryException { return sharingRegistryService.createEntityType(entityType); } @Override - public boolean updateEntityType(EntityType entityType) throws SharingRegistryException, TException { + public boolean updateEntityType(EntityType entityType) throws SharingRegistryException { return sharingRegistryService.updateEntityType(entityType); } @@ -263,23 +257,22 @@ public boolean updateEntityType(EntityType entityType) throws SharingRegistryExc * @param entityTypeId */ @Override - public boolean isEntityTypeExists(String domainId, String entityTypeId) - throws SharingRegistryException, TException { + public boolean isEntityTypeExists(String domainId, String entityTypeId) throws SharingRegistryException { return sharingRegistryService.isEntityTypeExists(domainId, entityTypeId); } @Override - public boolean deleteEntityType(String domainId, String entityTypeId) throws SharingRegistryException, TException { + public boolean deleteEntityType(String domainId, String entityTypeId) throws SharingRegistryException { return sharingRegistryService.deleteEntityType(domainId, entityTypeId); } @Override - public EntityType getEntityType(String domainId, String entityTypeId) throws SharingRegistryException, TException { + public EntityType getEntityType(String domainId, String entityTypeId) throws SharingRegistryException { return sharingRegistryService.getEntityType(domainId, entityTypeId); } @Override - public List getEntityTypes(String domain, int offset, int limit) throws TException { + public List getEntityTypes(String domain, int offset, int limit) throws SharingRegistryException { return sharingRegistryService.getEntityTypes(domain, offset, limit); } @@ -289,12 +282,12 @@ public List getEntityTypes(String domain, int offset, int limit) thr */ @Override public String createPermissionType(PermissionType permissionType) - throws SharingRegistryException, DuplicateEntryException, TException { + throws SharingRegistryException, DuplicateEntryException { return sharingRegistryService.createPermissionType(permissionType); } @Override - public boolean updatePermissionType(PermissionType permissionType) throws SharingRegistryException, TException { + public boolean updatePermissionType(PermissionType permissionType) throws SharingRegistryException { return sharingRegistryService.updatePermissionType(permissionType); } @@ -304,26 +297,23 @@ public boolean updatePermissionType(PermissionType permissionType) throws Sharin * @param permissionId */ @Override - public boolean isPermissionExists(String domainId, String permissionId) - throws SharingRegistryException, TException { + public boolean isPermissionExists(String domainId, String permissionId) throws SharingRegistryException { return sharingRegistryService.isPermissionExists(domainId, permissionId); } @Override - public boolean deletePermissionType(String domainId, String permissionTypeId) - throws SharingRegistryException, TException { + public boolean deletePermissionType(String domainId, String permissionTypeId) throws SharingRegistryException { return sharingRegistryService.deletePermissionType(domainId, permissionTypeId); } @Override - public PermissionType getPermissionType(String domainId, String permissionTypeId) - throws SharingRegistryException, TException { + public PermissionType getPermissionType(String domainId, String permissionTypeId) throws SharingRegistryException { return sharingRegistryService.getPermissionType(domainId, permissionTypeId); } @Override public List getPermissionTypes(String domain, int offset, int limit) - throws SharingRegistryException, TException { + throws SharingRegistryException { return sharingRegistryService.getPermissionTypes(domain, offset, limit); } @@ -332,12 +322,12 @@ public List getPermissionTypes(String domain, int offset, int li * * */ @Override - public String createEntity(Entity entity) throws SharingRegistryException, DuplicateEntryException, TException { + public String createEntity(Entity entity) throws SharingRegistryException, DuplicateEntryException { return sharingRegistryService.createEntity(entity); } @Override - public boolean updateEntity(Entity entity) throws SharingRegistryException, TException { + public boolean updateEntity(Entity entity) throws SharingRegistryException { return sharingRegistryService.updateEntity(entity); } @@ -347,48 +337,48 @@ public boolean updateEntity(Entity entity) throws SharingRegistryException, TExc * @param entityId */ @Override - public boolean isEntityExists(String domainId, String entityId) throws SharingRegistryException, TException { + public boolean isEntityExists(String domainId, String entityId) throws SharingRegistryException { return sharingRegistryService.isEntityExists(domainId, entityId); } @Override - public boolean deleteEntity(String domainId, String entityId) throws SharingRegistryException, TException { + public boolean deleteEntity(String domainId, String entityId) throws SharingRegistryException { return sharingRegistryService.deleteEntity(domainId, entityId); } @Override - public Entity getEntity(String domainId, String entityId) throws SharingRegistryException, TException { + public Entity getEntity(String domainId, String entityId) throws SharingRegistryException { return sharingRegistryService.getEntity(domainId, entityId); } @Override public List searchEntities( String domainId, String userId, List filters, int offset, int limit) - throws SharingRegistryException, TException { + throws SharingRegistryException { return sharingRegistryService.searchEntities(domainId, userId, filters, offset, limit); } @Override public List getListOfSharedUsers(String domainId, String entityId, String permissionTypeId) - throws SharingRegistryException, TException { + throws SharingRegistryException { return sharingRegistryService.getListOfSharedUsers(domainId, entityId, permissionTypeId); } @Override public List getListOfDirectlySharedUsers(String domainId, String entityId, String permissionTypeId) - throws SharingRegistryException, TException { + throws SharingRegistryException { return sharingRegistryService.getListOfDirectlySharedUsers(domainId, entityId, permissionTypeId); } @Override public List getListOfSharedGroups(String domainId, String entityId, String permissionTypeId) - throws SharingRegistryException, TException { + throws SharingRegistryException { return sharingRegistryService.getListOfSharedGroups(domainId, entityId, permissionTypeId); } @Override public List getListOfDirectlySharedGroups(String domainId, String entityId, String permissionTypeId) - throws SharingRegistryException, TException { + throws SharingRegistryException { return sharingRegistryService.getListOfDirectlySharedGroups(domainId, entityId, permissionTypeId); } @@ -401,14 +391,13 @@ public List getListOfDirectlySharedGroups(String domainId, String ent * @param cascadePermission * @return * @throws SharingRegistryException - * @throws TException - */ + * @ */ @Override public boolean shareEntityWithUsers( String domainId, String entityId, List userList, String permissionTypeId, boolean cascadePermission) - throws SharingRegistryException, TException { + throws SharingRegistryException { return sharingRegistryService.shareEntityWithUsers( - domainId, entityId, userList, permissionTypeId, cascadePermission); + domainId, entityId, userList, permissionTypeId, cascadePermission); } @Override @@ -418,29 +407,28 @@ public boolean shareEntityWithGroups( List groupList, String permissionTypeId, boolean cascadePermission) - throws SharingRegistryException, TException { + throws SharingRegistryException { return sharingRegistryService.shareEntityWithGroups( - domainId, entityId, groupList, permissionTypeId, cascadePermission); + domainId, entityId, groupList, permissionTypeId, cascadePermission); } @Override public boolean revokeEntitySharingFromUsers( String domainId, String entityId, List userList, String permissionTypeId) - throws SharingRegistryException, TException { + throws SharingRegistryException { return sharingRegistryService.revokeEntitySharingFromUsers(domainId, entityId, userList, permissionTypeId); } @Override public boolean revokeEntitySharingFromGroups( String domainId, String entityId, List groupList, String permissionTypeId) - throws SharingRegistryException, TException { - return sharingRegistryService.revokeEntitySharingFromGroups( - domainId, entityId, groupList, permissionTypeId); + throws SharingRegistryException { + return sharingRegistryService.revokeEntitySharingFromGroups(domainId, entityId, groupList, permissionTypeId); } @Override public boolean userHasAccess(String domainId, String userId, String entityId, String permissionTypeId) - throws SharingRegistryException, TException { + throws SharingRegistryException { return sharingRegistryService.userHasAccess(domainId, userId, entityId, permissionTypeId); } } From 0c7af7d21c61118711e668ef76961d3278e7da61 Mon Sep 17 00:00:00 2001 From: yasithdev Date: Wed, 26 Nov 2025 18:54:10 -0600 Subject: [PATCH 24/26] remove unused throws clauses and imports --- .../airavata/api/server/handler/AiravataServerHandler.java | 1 - .../sharing/registry/server/SharingRegistryServerHandler.java | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java index e0d3c96e13..4b4e09c1e5 100644 --- a/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java @@ -21,7 +21,6 @@ import java.util.*; import org.apache.airavata.accountprovisioning.ConfigParam; -import org.apache.airavata.accountprovisioning.InvalidSetupException; import org.apache.airavata.accountprovisioning.SSHAccountProvisionerFactory; import org.apache.airavata.accountprovisioning.SSHAccountProvisionerProvider; import org.apache.airavata.api.Airavata; diff --git a/airavata-api/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java index 1dbef651b8..d8cba77d6c 100644 --- a/airavata-api/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java @@ -45,7 +45,7 @@ public SharingRegistryServerHandler(SharingRegistryDBInitConfig sharingRegistryD } @Override - public String getAPIVersion() throws AiravataSystemException { + public String getAPIVersion() { return sharing_cpiConstants.SHARING_CPI_VERSION; } From a071897c6d86fcef5039fba4b568da0648bed0b3 Mon Sep 17 00:00:00 2001 From: yasithdev Date: Thu, 27 Nov 2025 12:57:44 -0600 Subject: [PATCH 25/26] run spotless:apply --- .../main/java/org/apache/airavata/service/AiravataService.java | 1 - .../sharing/registry/server/SharingRegistryServerHandler.java | 1 - 2 files changed, 2 deletions(-) diff --git a/airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java b/airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java index 2eae99b773..100d2c9235 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java @@ -33,7 +33,6 @@ import java.util.UUID; import java.util.function.BiFunction; import java.util.stream.Collectors; -import org.apache.airavata.accountprovisioning.InvalidSetupException; import org.apache.airavata.accountprovisioning.SSHAccountManager; import org.apache.airavata.agents.api.AgentAdaptor; import org.apache.airavata.agents.api.AgentException; diff --git a/airavata-api/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java index d8cba77d6c..7d846d7ac7 100644 --- a/airavata-api/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java @@ -22,7 +22,6 @@ import java.util.List; import org.apache.airavata.common.exception.ApplicationSettingsException; import org.apache.airavata.common.utils.DBInitializer; -import org.apache.airavata.model.error.AiravataSystemException; import org.apache.airavata.sharing.registry.db.utils.SharingRegistryDBInitConfig; import org.apache.airavata.sharing.registry.models.*; import org.apache.airavata.sharing.registry.service.cpi.SharingRegistryService; From b39d76411f5920fdacb0a1a60234ce65dd2e5b2e Mon Sep 17 00:00:00 2001 From: yasithdev Date: Tue, 2 Dec 2025 18:30:44 -0600 Subject: [PATCH 26/26] improve service exception handling --- .../server/handler/AiravataServerHandler.java | 194 +- .../server/CredentialStoreServerHandler.java | 12 +- .../server/OrchestratorServerHandler.java | 20 +- .../airavata/service/AiravataService.java | 2679 ++++++----------- .../service/CredentialStoreService.java | 100 +- .../airavata/service/GroupManagerService.java | 129 +- .../airavata/service/IamAdminService.java | 119 +- .../service/OrchestratorRegistryService.java | 6 +- .../airavata/service/OrchestratorService.java | 56 +- .../airavata/service/RegistryService.java | 6 +- .../service/SharingRegistryService.java | 442 +-- .../service/TenantProfileService.java | 51 +- .../handlers/IamAdminServicesHandler.java | 20 +- .../handlers/TenantProfileServiceHandler.java | 12 +- 14 files changed, 1423 insertions(+), 2423 deletions(-) diff --git a/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java index 4b4e09c1e5..ee1eea4888 100644 --- a/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java @@ -27,9 +27,6 @@ import org.apache.airavata.api.airavata_apiConstants; import org.apache.airavata.common.exception.ApplicationSettingsException; import org.apache.airavata.common.utils.Constants; -import org.apache.airavata.messaging.core.MessagingFactory; -import org.apache.airavata.messaging.core.Publisher; -import org.apache.airavata.messaging.core.Type; import org.apache.airavata.model.appcatalog.accountprovisioning.SSHAccountProvisioner; import org.apache.airavata.model.appcatalog.accountprovisioning.SSHAccountProvisionerConfigParam; import org.apache.airavata.model.appcatalog.accountprovisioning.SSHAccountProvisionerConfigParamType; @@ -63,7 +60,6 @@ import org.apache.airavata.model.error.*; import org.apache.airavata.model.experiment.*; import org.apache.airavata.model.group.ResourcePermissionType; -import org.apache.airavata.model.group.ResourceType; import org.apache.airavata.model.job.JobModel; import org.apache.airavata.model.scheduling.ComputationalResourceSchedulingModel; import org.apache.airavata.model.security.AuthzToken; @@ -74,28 +70,16 @@ import org.apache.airavata.model.workspace.Gateway; import org.apache.airavata.model.workspace.Notification; import org.apache.airavata.model.workspace.Project; +import org.apache.airavata.service.AiravataService; import org.apache.airavata.service.security.interceptor.SecurityCheck; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class AiravataServerHandler implements Airavata.Iface { - private static final Logger logger = LoggerFactory.getLogger(AiravataServerHandler.class); - private Publisher statusPublisher; - private Publisher experimentPublisher; - private org.apache.airavata.service.AiravataService airavataService = - new org.apache.airavata.service.AiravataService(); + private AiravataService airavataService; public AiravataServerHandler() { - try { - statusPublisher = MessagingFactory.getPublisher(Type.STATUS); - experimentPublisher = MessagingFactory.getPublisher(Type.EXPERIMENT_LAUNCH); - airavataService.init(); - } catch (ApplicationSettingsException e) { - logger.error("Error occured while reading airavata-server properties..", e); - } catch (Throwable e) { - logger.error("Error occured while reading airavata-server properties..", e); - } + airavataService = new AiravataService(); + airavataService.init(); } /** @@ -125,7 +109,7 @@ public boolean isUserExists(AuthzToken authzToken, String gatewayId, String user @SecurityCheck public String addGateway(AuthzToken authzToken, Gateway gateway) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.addGatewayWithSharing(gateway); + return airavataService.addGateway(gateway); } /** @@ -253,7 +237,7 @@ public String registerPwdCredential( public CredentialSummary getCredentialSummary(AuthzToken authzToken, String tokenId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - return airavataService.getCredentialSummaryWithAuth(authzToken, tokenId, gatewayId); + return airavataService.getCredentialSummary(authzToken, tokenId, gatewayId); } @Override @@ -262,7 +246,7 @@ public List getAllCredentialSummaries(AuthzToken authzToken, throws InvalidRequestException, AiravataClientException, AiravataSystemException { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); - return airavataService.getAllCredentialSummariesWithAuth(authzToken, type, gatewayId, userName); + return airavataService.getAllCredentialSummaries(authzToken, type, gatewayId, userName); } @Override @@ -278,7 +262,7 @@ public boolean deleteSSHPubKey(AuthzToken authzToken, String airavataCredStoreTo public boolean deletePWDCredential(AuthzToken authzToken, String airavataCredStoreToken) throws AiravataClientException, AiravataSystemException, AuthorizationException, InvalidRequestException { String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - return airavataService.deletePWDCredentialWithAuth(authzToken, airavataCredStoreToken, gatewayId); + return airavataService.deletePWDCredential(authzToken, airavataCredStoreToken, gatewayId); } /** @@ -290,7 +274,7 @@ public boolean deletePWDCredential(AuthzToken authzToken, String airavataCredSto @SecurityCheck public String createProject(AuthzToken authzToken, String gatewayId, Project project) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.createProjectWithSharing(gatewayId, project); + return airavataService.createProject(gatewayId, project); } @Override @@ -298,7 +282,7 @@ public String createProject(AuthzToken authzToken, String gatewayId, Project pro public void updateProject(AuthzToken authzToken, String projectId, Project updatedProject) throws InvalidRequestException, AiravataClientException, AiravataSystemException, ProjectNotFoundException, AuthorizationException { - airavataService.updateProjectWithAuth(authzToken, projectId, updatedProject); + airavataService.updateProject(authzToken, projectId, updatedProject); } @Override @@ -306,7 +290,7 @@ public void updateProject(AuthzToken authzToken, String projectId, Project updat public boolean deleteProject(AuthzToken authzToken, String projectId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, ProjectNotFoundException, AuthorizationException { - return airavataService.deleteProjectWithAuth(authzToken, projectId); + return airavataService.deleteProject(authzToken, projectId); } /** @@ -319,7 +303,7 @@ public boolean deleteProject(AuthzToken authzToken, String projectId) public Project getProject(AuthzToken authzToken, String projectId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, ProjectNotFoundException, AuthorizationException { - return airavataService.getProjectWithAuth(authzToken, projectId); + return airavataService.getProject(authzToken, projectId); } /** @@ -340,7 +324,7 @@ public Project getProject(AuthzToken authzToken, String projectId) public List getUserProjects( AuthzToken authzToken, String gatewayId, String userName, int limit, int offset) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getUserProjectsWithSharing(authzToken, gatewayId, userName, limit, offset); + return airavataService.getUserProjects(authzToken, gatewayId, userName, limit, offset); } /** @@ -375,7 +359,7 @@ public List searchProjects( int limit, int offset) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.searchProjectsWithSharing(authzToken, gatewayId, userName, filters, limit, offset); + return airavataService.searchProjects(authzToken, gatewayId, userName, filters, limit, offset); } /** @@ -403,7 +387,7 @@ public List searchExperiments( int limit, int offset) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.searchExperimentsWithSharing(authzToken, gatewayId, userName, filters, limit, offset); + return airavataService.searchExperiments(authzToken, gatewayId, userName, filters, limit, offset); } /** @@ -510,7 +494,7 @@ public List getUserExperiments( @SecurityCheck public String createExperiment(AuthzToken authzToken, String gatewayId, ExperimentModel experiment) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.createExperimentWithSharingAndPublish(statusPublisher, gatewayId, experiment); + return airavataService.createExperiment(gatewayId, experiment); } /** @@ -739,8 +723,7 @@ public List getIntermediateOutputs(AuthzToken authzToken, public void fetchIntermediateOutputs(AuthzToken authzToken, String airavataExperimentId, List outputNames) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException { - airavataService.validateAndFetchIntermediateOutputs( - authzToken, airavataExperimentId, outputNames, experimentPublisher); + airavataService.fetchIntermediateOutputs(authzToken, airavataExperimentId, outputNames); } @Override @@ -749,8 +732,7 @@ public ProcessStatus getIntermediateOutputProcessStatus( AuthzToken authzToken, String airavataExperimentId, List outputNames) throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getIntermediateOutputProcessStatusInternal( - authzToken, airavataExperimentId, outputNames); + return airavataService.getIntermediateOutputProcessStatus(authzToken, airavataExperimentId, outputNames); } @SecurityCheck @@ -799,8 +781,7 @@ public List getJobDetails(AuthzToken authzToken, String airavataExperi public void launchExperiment(AuthzToken authzToken, final String airavataExperimentId, String gatewayId) throws AiravataClientException, AiravataSystemException, AuthorizationException, ExperimentNotFoundException, InvalidRequestException, ProjectNotFoundException { - airavataService.launchExperimentWithValidation( - authzToken, gatewayId, airavataExperimentId, experimentPublisher); + airavataService.launchExperiment(authzToken, gatewayId, airavataExperimentId); } /** @@ -852,7 +833,7 @@ public String cloneExperiment( AiravataSystemException, AuthorizationException, ProjectNotFoundException { // getExperiment will apply sharing permissions ExperimentModel existingExperiment = airavataService.getExperiment(authzToken, existingExperimentID); - return airavataService.cloneExperimentInternal( + return airavataService.cloneExperiment( authzToken, existingExperimentID, newExperimentName, newExperimentProjectId, existingExperiment); } @@ -864,7 +845,7 @@ public String cloneExperimentByAdmin( AiravataSystemException, AuthorizationException, ProjectNotFoundException { // get existing experiment by bypassing normal sharing permissions for the admin user ExperimentModel existingExperiment = airavataService.getExperimentByAdmin(authzToken, existingExperimentID); - return airavataService.cloneExperimentInternal( + return airavataService.cloneExperiment( authzToken, existingExperimentID, newExperimentName, newExperimentProjectId, existingExperiment); } @@ -894,7 +875,7 @@ public String cloneExperimentByAdmin( public void terminateExperiment(AuthzToken authzToken, String airavataExperimentId, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, ExperimentNotFoundException { - airavataService.terminateExperiment(experimentPublisher, airavataExperimentId, gatewayId); + airavataService.terminateExperiment(airavataExperimentId, gatewayId); } /** @@ -965,7 +946,7 @@ public List getAllAppModules(AuthzToken authzToken, String ga @SecurityCheck public List getAccessibleAppModules(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getAccessibleAppModulesWithSharing(authzToken, gatewayId); + return airavataService.getAccessibleAppModules(authzToken, gatewayId); } /** @@ -993,7 +974,7 @@ public boolean deleteApplicationModule(AuthzToken authzToken, String appModuleId public String registerApplicationDeployment( AuthzToken authzToken, String gatewayId, ApplicationDeploymentDescription applicationDeployment) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.registerApplicationDeploymentWithSharing(authzToken, gatewayId, applicationDeployment); + return airavataService.registerApplicationDeployment(authzToken, gatewayId, applicationDeployment); } /** @@ -1007,7 +988,7 @@ public String registerApplicationDeployment( @SecurityCheck public ApplicationDeploymentDescription getApplicationDeployment(AuthzToken authzToken, String appDeploymentId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getApplicationDeploymentWithAuth(authzToken, appDeploymentId); + return airavataService.getApplicationDeployment(authzToken, appDeploymentId); } /** @@ -1023,7 +1004,7 @@ public ApplicationDeploymentDescription getApplicationDeployment(AuthzToken auth public boolean updateApplicationDeployment( AuthzToken authzToken, String appDeploymentId, ApplicationDeploymentDescription applicationDeployment) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.updateApplicationDeploymentWithAuth(authzToken, appDeploymentId, applicationDeployment); + return airavataService.updateApplicationDeployment(authzToken, appDeploymentId, applicationDeployment); } /** @@ -1037,7 +1018,7 @@ public boolean updateApplicationDeployment( @SecurityCheck public boolean deleteApplicationDeployment(AuthzToken authzToken, String appDeploymentId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.deleteApplicationDeploymentWithAuth(authzToken, appDeploymentId); + return airavataService.deleteApplicationDeployment(authzToken, appDeploymentId); } /** @@ -1064,7 +1045,7 @@ public List getAllApplicationDeployments(Authz public List getAccessibleApplicationDeployments( AuthzToken authzToken, String gatewayId, ResourcePermissionType permissionType) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getAccessibleApplicationDeploymentsWithSharing(authzToken, gatewayId, permissionType); + return airavataService.getAccessibleApplicationDeployments(authzToken, gatewayId, permissionType); } /** @@ -2418,85 +2399,7 @@ public boolean revokeSharingOfResourceFromUsers( public boolean revokeSharingOfResourceFromGroups( AuthzToken authzToken, String resourceId, Map groupPermissionList) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - final String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - try { - if (!airavataService.userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.OWNER) - && !airavataService.userHasAccessInternal( - authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { - throw new AuthorizationException( - "User is not allowed to change sharing because the user is either not the resource owner or does not have access to share the resource"); - } - // For certain resource types, restrict them from being unshared with admin groups - ResourceType resourceType = airavataService.getResourceType(gatewayId, resourceId); - Set adminRestrictedResourceTypes = new HashSet<>(Arrays.asList( - ResourceType.EXPERIMENT, ResourceType.APPLICATION_DEPLOYMENT, ResourceType.GROUP_RESOURCE_PROFILE)); - if (adminRestrictedResourceTypes.contains(resourceType)) { - // Prevent removing Admins WRITE/MANAGE_SHARING access and Read Only Admins READ access - GatewayGroups gatewayGroups = airavataService.retrieveGatewayGroups(gatewayId); - if (groupPermissionList.containsKey(gatewayGroups.getAdminsGroupId()) - && groupPermissionList - .get(gatewayGroups.getAdminsGroupId()) - .equals(ResourcePermissionType.WRITE)) { - throw new Exception("Not allowed to remove Admins group's WRITE access."); - } - if (groupPermissionList.containsKey(gatewayGroups.getReadOnlyAdminsGroupId()) - && groupPermissionList - .get(gatewayGroups.getReadOnlyAdminsGroupId()) - .equals(ResourcePermissionType.READ)) { - throw new Exception("Not allowed to remove Read Only Admins group's READ access."); - } - if (groupPermissionList.containsKey(gatewayGroups.getAdminsGroupId()) - && groupPermissionList - .get(gatewayGroups.getAdminsGroupId()) - .equals(ResourcePermissionType.READ)) { - throw new Exception("Not allowed to remove Admins group's READ access."); - } - if (groupPermissionList.containsKey(gatewayGroups.getAdminsGroupId()) - && groupPermissionList - .get(gatewayGroups.getAdminsGroupId()) - .equals(ResourcePermissionType.MANAGE_SHARING)) { - throw new Exception("Not allowed to remove Admins group's MANAGE_SHARING access."); - } - } - for (Map.Entry groupPermission : groupPermissionList.entrySet()) { - if (groupPermission.getValue().equals(ResourcePermissionType.WRITE)) - airavataService.revokeEntitySharingFromUsers( - gatewayId, resourceId, Arrays.asList(groupPermission.getKey()), gatewayId + ":" + "WRITE"); - else if (groupPermission.getValue().equals(ResourcePermissionType.READ)) - airavataService.revokeEntitySharingFromUsers( - gatewayId, resourceId, Arrays.asList(groupPermission.getKey()), gatewayId + ":" + "READ"); - else if (groupPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING)) { - if (airavataService.userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.OWNER)) { - airavataService.createManageSharingPermissionTypeIfMissing(gatewayId); - airavataService.revokeEntitySharingFromUsers( - gatewayId, - resourceId, - Arrays.asList(groupPermission.getKey()), - gatewayId + ":" + "MANAGE_SHARING"); - } else - throw new AuthorizationException( - "User is not allowed to change sharing because the user is not the resource owner"); - } else { - logger.error("Invalid ResourcePermissionType : " - + groupPermission.getValue().toString()); - throw new AiravataClientException(AiravataErrorType.UNSUPPORTED_OPERATION); - } - } - return true; - } catch (InvalidRequestException - | AiravataClientException - | AiravataSystemException - | AuthorizationException e) { - throw e; - } catch (Exception e) { - String msg = "Error in revoking access to resource from groups. Resource ID : " + resourceId; - logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + ". More info: " + e.getMessage()); - exception.initCause(e); - throw exception; - } + return airavataService.revokeSharingOfResourceFromGroups(authzToken, resourceId, groupPermissionList); } @Override @@ -2504,7 +2407,7 @@ else if (groupPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING public List getAllAccessibleUsers( AuthzToken authzToken, String resourceId, ResourcePermissionType permissionType) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getAllAccessibleUsersWithSharing(authzToken, resourceId, permissionType, false); + return airavataService.getAllAccessibleUsers(authzToken, resourceId, permissionType, false); } @Override @@ -2512,7 +2415,7 @@ public List getAllAccessibleUsers( public List getAllDirectlyAccessibleUsers( AuthzToken authzToken, String resourceId, ResourcePermissionType permissionType) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getAllAccessibleUsersWithSharing(authzToken, resourceId, permissionType, true); + return airavataService.getAllAccessibleUsers(authzToken, resourceId, permissionType, true); } @Override @@ -2520,7 +2423,7 @@ public List getAllDirectlyAccessibleUsers( public List getAllAccessibleGroups( AuthzToken authzToken, String resourceId, ResourcePermissionType permissionType) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getAllAccessibleGroupsWithSharing(authzToken, resourceId, permissionType, false); + return airavataService.getAllAccessibleGroups(authzToken, resourceId, permissionType, false); } @Override @@ -2528,49 +2431,49 @@ public List getAllAccessibleGroups( public List getAllDirectlyAccessibleGroups( AuthzToken authzToken, String resourceId, ResourcePermissionType permissionType) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getAllAccessibleGroupsWithSharing(authzToken, resourceId, permissionType, true); + return airavataService.getAllAccessibleGroups(authzToken, resourceId, permissionType, true); } @Override @SecurityCheck public boolean userHasAccess(AuthzToken authzToken, String resourceId, ResourcePermissionType permissionType) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.userHasAccessInternal(authzToken, resourceId, permissionType); + return airavataService.userHasAccess(authzToken, resourceId, permissionType); } @Override @SecurityCheck public String createGroupResourceProfile(AuthzToken authzToken, GroupResourceProfile groupResourceProfile) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.createGroupResourceProfileWithAuth(authzToken, groupResourceProfile); + return airavataService.createGroupResourceProfile(authzToken, groupResourceProfile); } @Override @SecurityCheck public void updateGroupResourceProfile(AuthzToken authzToken, GroupResourceProfile groupResourceProfile) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - airavataService.updateGroupResourceProfileWithAuth(authzToken, groupResourceProfile); + airavataService.updateGroupResourceProfile(authzToken, groupResourceProfile); } @Override @SecurityCheck public GroupResourceProfile getGroupResourceProfile(AuthzToken authzToken, String groupResourceProfileId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getGroupResourceProfileWithAuth(authzToken, groupResourceProfileId); + return airavataService.getGroupResourceProfile(authzToken, groupResourceProfileId); } @Override @SecurityCheck public boolean removeGroupResourceProfile(AuthzToken authzToken, String groupResourceProfileId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.removeGroupResourceProfileWithAuth(authzToken, groupResourceProfileId); + return airavataService.removeGroupResourceProfile(authzToken, groupResourceProfileId); } @Override @SecurityCheck public List getGroupResourceList(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getGroupResourceListWithSharing(authzToken, gatewayId); + return airavataService.getGroupResourceList(authzToken, gatewayId); } @Override @@ -2578,21 +2481,21 @@ public List getGroupResourceList(AuthzToken authzToken, St public boolean removeGroupComputePrefs( AuthzToken authzToken, String computeResourceId, String groupResourceProfileId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.removeGroupComputePrefsWithAuth(authzToken, computeResourceId, groupResourceProfileId); + return airavataService.removeGroupComputePrefs(authzToken, computeResourceId, groupResourceProfileId); } @Override @SecurityCheck public boolean removeGroupComputeResourcePolicy(AuthzToken authzToken, String resourcePolicyId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.removeGroupComputeResourcePolicyWithAuth(authzToken, resourcePolicyId); + return airavataService.removeGroupComputeResourcePolicy(authzToken, resourcePolicyId); } @Override @SecurityCheck public boolean removeGroupBatchQueueResourcePolicy(AuthzToken authzToken, String resourcePolicyId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.removeGroupBatchQueueResourcePolicyWithAuth(authzToken, resourcePolicyId); + return airavataService.removeGroupBatchQueueResourcePolicy(authzToken, resourcePolicyId); } @Override @@ -2600,22 +2503,21 @@ public boolean removeGroupBatchQueueResourcePolicy(AuthzToken authzToken, String public GroupComputeResourcePreference getGroupComputeResourcePreference( AuthzToken authzToken, String computeResourceId, String groupResourceProfileId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getGroupComputeResourcePreferenceWithAuth( - authzToken, computeResourceId, groupResourceProfileId); + return airavataService.getGroupComputeResourcePreference(authzToken, computeResourceId, groupResourceProfileId); } @Override @SecurityCheck public ComputeResourcePolicy getGroupComputeResourcePolicy(AuthzToken authzToken, String resourcePolicyId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getGroupComputeResourcePolicyWithAuth(authzToken, resourcePolicyId); + return airavataService.getGroupComputeResourcePolicy(authzToken, resourcePolicyId); } @Override @SecurityCheck public BatchQueueResourcePolicy getBatchQueueResourcePolicy(AuthzToken authzToken, String resourcePolicyId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getBatchQueueResourcePolicyWithAuth(authzToken, resourcePolicyId); + return airavataService.getBatchQueueResourcePolicy(authzToken, resourcePolicyId); } @Override @@ -2623,7 +2525,7 @@ public BatchQueueResourcePolicy getBatchQueueResourcePolicy(AuthzToken authzToke public List getGroupComputeResourcePrefList( AuthzToken authzToken, String groupResourceProfileId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getGroupComputeResourcePrefListWithAuth(authzToken, groupResourceProfileId); + return airavataService.getGroupComputeResourcePrefList(authzToken, groupResourceProfileId); } @Override @@ -2631,7 +2533,7 @@ public List getGroupComputeResourcePrefList( public List getGroupBatchQueueResourcePolicyList( AuthzToken authzToken, String groupResourceProfileId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getGroupBatchQueueResourcePolicyListWithAuth(authzToken, groupResourceProfileId); + return airavataService.getGroupBatchQueueResourcePolicyList(authzToken, groupResourceProfileId); } @Override @@ -2639,7 +2541,7 @@ public List getGroupBatchQueueResourcePolicyList( public List getGroupComputeResourcePolicyList( AuthzToken authzToken, String groupResourceProfileId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException { - return airavataService.getGroupComputeResourcePolicyListWithAuth(authzToken, groupResourceProfileId); + return airavataService.getGroupComputeResourcePolicyList(authzToken, groupResourceProfileId); } @Override diff --git a/airavata-api/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java index c6f0805930..a016cb9abb 100644 --- a/airavata-api/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/credential/store/server/CredentialStoreServerHandler.java @@ -19,8 +19,6 @@ */ package org.apache.airavata.credential.store.server; -import java.io.IOException; -import java.sql.SQLException; import java.util.List; import java.util.Map; import org.apache.airavata.common.exception.ApplicationSettingsException; @@ -28,19 +26,19 @@ import org.apache.airavata.credential.store.exception.CredentialStoreException; import org.apache.airavata.model.credential.store.*; import org.apache.airavata.model.error.AiravataSystemException; +import org.apache.airavata.service.CredentialStoreService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -// import sun.security.provider.X509Factory; public class CredentialStoreServerHandler implements org.apache.airavata.credential.store.cpi.CredentialStoreService.Iface { protected static Logger log = LoggerFactory.getLogger(CredentialStoreServerHandler.class); - private org.apache.airavata.service.CredentialStoreService credentialStoreService; + private CredentialStoreService credentialStoreService; public CredentialStoreServerHandler() - throws ApplicationSettingsException, IllegalAccessException, ClassNotFoundException, InstantiationException, - SQLException, IOException { - credentialStoreService = new org.apache.airavata.service.CredentialStoreService(); + throws ApplicationSettingsException, IllegalAccessException, ClassNotFoundException, + InstantiationException { + credentialStoreService = new CredentialStoreService(); } @Override diff --git a/airavata-api/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java b/airavata-api/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java index 0eed4c532d..daefcaa194 100644 --- a/airavata-api/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/orchestrator/server/OrchestratorServerHandler.java @@ -19,31 +19,31 @@ */ package org.apache.airavata.orchestrator.server; -import java.util.*; +import java.util.List; import org.apache.airavata.model.error.AiravataErrorType; import org.apache.airavata.model.error.AiravataSystemException; import org.apache.airavata.model.error.LaunchValidationException; import org.apache.airavata.model.process.ProcessModel; -import org.apache.airavata.orchestrator.cpi.OrchestratorService; -import org.apache.airavata.orchestrator.cpi.orchestrator_cpiConstants; +import org.apache.airavata.orchestrator.util.OrchestratorServerThreadPoolExecutor; +import org.apache.airavata.service.OrchestratorService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class OrchestratorServerHandler implements OrchestratorService.Iface { +public class OrchestratorServerHandler implements org.apache.airavata.orchestrator.cpi.OrchestratorService.Iface { private static Logger log = LoggerFactory.getLogger(OrchestratorServerHandler.class); - private org.apache.airavata.service.OrchestratorService orchestratorService; + private OrchestratorService orchestratorService; /** * Query orchestrator server to fetch the CPI version */ @Override public String getAPIVersion() throws AiravataSystemException { - return orchestrator_cpiConstants.ORCHESTRATOR_CPI_VERSION; + return org.apache.airavata.orchestrator.cpi.orchestrator_cpiConstants.ORCHESTRATOR_CPI_VERSION; } public OrchestratorServerHandler() { try { - orchestratorService = new org.apache.airavata.service.OrchestratorService(); + orchestratorService = new OrchestratorService(); } catch (Exception e) { log.error("Error while initializing orchestrator service", e); throw new RuntimeException("Error while initializing orchestrator service", e); @@ -60,11 +60,9 @@ public OrchestratorServerHandler() { */ @Override public boolean launchExperiment(String experimentId, String gatewayId) throws AiravataSystemException { + var pool = OrchestratorServerThreadPoolExecutor.getCachedThreadPool(); try { - return orchestratorService.launchExperimentWithErrorHandling( - experimentId, - gatewayId, - org.apache.airavata.orchestrator.util.OrchestratorServerThreadPoolExecutor.getCachedThreadPool()); + return orchestratorService.launchExperiment(experimentId, gatewayId, pool); } catch (Throwable e) { log.error("Error launching experiment: " + experimentId, e); AiravataSystemException exception = new AiravataSystemException(); diff --git a/airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java b/airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java index 100d2c9235..09a065a4ab 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/AiravataService.java @@ -36,6 +36,7 @@ import org.apache.airavata.accountprovisioning.SSHAccountManager; import org.apache.airavata.agents.api.AgentAdaptor; import org.apache.airavata.agents.api.AgentException; +import org.apache.airavata.common.exception.AiravataException; import org.apache.airavata.common.exception.ApplicationSettingsException; import org.apache.airavata.common.utils.AiravataUtils; import org.apache.airavata.common.utils.Constants; @@ -43,7 +44,9 @@ import org.apache.airavata.credential.store.exception.CredentialStoreException; import org.apache.airavata.helix.core.support.adaptor.AdaptorSupportImpl; import org.apache.airavata.messaging.core.MessageContext; +import org.apache.airavata.messaging.core.MessagingFactory; import org.apache.airavata.messaging.core.Publisher; +import org.apache.airavata.messaging.core.Type; import org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription; import org.apache.airavata.model.appcatalog.appdeployment.ApplicationModule; import org.apache.airavata.model.appcatalog.appinterface.ApplicationInterfaceDescription; @@ -117,8 +120,6 @@ import org.apache.airavata.model.workspace.Notification; import org.apache.airavata.model.workspace.Project; import org.apache.airavata.registry.api.exception.RegistryServiceException; -import org.apache.airavata.registry.cpi.AppCatalogException; -import org.apache.airavata.registry.cpi.RegistryException; import org.apache.airavata.service.security.GatewayGroupsInitializer; import org.apache.airavata.sharing.registry.models.Domain; import org.apache.airavata.sharing.registry.models.DuplicateEntryException; @@ -150,10 +151,13 @@ private boolean validateString(String name) { return valid; } - private AiravataSystemException airavataSystemException(AiravataErrorType errorType, String message) { - var exception = new AiravataSystemException(); - exception.setAiravataErrorType(errorType); + private AiravataSystemException airavataSystemException( + AiravataErrorType errorType, String message, Throwable cause) { + var exception = new AiravataSystemException(errorType); exception.setMessage(message); + if (cause != null) { + exception.initCause(cause); + } return exception; } @@ -176,18 +180,27 @@ private boolean isGatewayResourceProfileExists(String gatewayId) { } } - private RegistryService registryService = new RegistryService(); - - private SharingRegistryService sharingRegistryService = new SharingRegistryService(); - + private RegistryService registryService; + private SharingRegistryService sharingRegistryService; private CredentialStoreService credentialStoreService; + private Publisher statusPublisher; + private Publisher experimentPublisher; public AiravataService() { try { + registryService = new RegistryService(); + logger.info("Initialized RegistryService"); + sharingRegistryService = new SharingRegistryService(); + logger.info("Initialized SharingRegistryService"); credentialStoreService = new CredentialStoreService(); + logger.info("Initialized CredentialStoreService"); + statusPublisher = MessagingFactory.getPublisher(Type.STATUS); + logger.info("Initialized StatusPublisher"); + experimentPublisher = MessagingFactory.getPublisher(Type.EXPERIMENT_LAUNCH); + logger.info("Initialized ExperimentPublisher"); } catch (Exception e) { - logger.error("Failed to initialize CredentialStoreService", e); - throw new RuntimeException("Failed to initialize CredentialStoreService", e); + logger.error("Error initializing AiravataService", e); + throw new RuntimeException("Error initializing AiravataService", e); } } @@ -329,12 +342,9 @@ public List getAllUsersInGateway(String gatewayId) throws AiravataSystem try { return registryService.getAllUsersInGateway(gatewayId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving users", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving users. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving users: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -342,12 +352,9 @@ public boolean updateGateway(String gatewayId, Gateway updatedGateway) throws Ai try { return registryService.updateGateway(gatewayId, updatedGateway); } catch (RegistryServiceException e) { - logger.error("Error while updating gateway", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating gateway. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while updating gateway: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -357,12 +364,9 @@ public Gateway getGateway(String gatewayId) throws AiravataSystemException { logger.debug("Airavata found the gateway with " + gatewayId); return result; } catch (RegistryServiceException e) { - logger.error("Error while getting the gateway", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while getting the gateway. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while getting the gateway: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -370,12 +374,9 @@ public boolean deleteGateway(String gatewayId) throws AiravataSystemException { try { return registryService.deleteGateway(gatewayId); } catch (RegistryServiceException e) { - logger.error("Error while deleting the gateway", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while deleting the gateway. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while deleting the gateway: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -384,12 +385,9 @@ public List getAllGateways() throws AiravataSystemException { logger.debug("Airavata searching for all gateways"); return registryService.getAllGateways(); } catch (RegistryServiceException e) { - logger.error("Error while getting all the gateways", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while getting all the gateways. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while getting all the gateways: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -398,12 +396,9 @@ public boolean isGatewayExist(String gatewayId) throws AiravataSystemException { logger.debug("Airavata verifying if the gateway with " + gatewayId + "exits"); return registryService.isGatewayExist(gatewayId); } catch (RegistryServiceException e) { - logger.error("Error while getting gateway", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while getting gateway. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while getting gateway: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -411,12 +406,9 @@ public String createNotification(Notification notification) throws AiravataSyste try { return registryService.createNotification(notification); } catch (RegistryServiceException e) { - logger.error("Error while creating notification", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while creating notification. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while creating notification: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -424,12 +416,9 @@ public boolean updateNotification(Notification notification) throws AiravataSyst try { return registryService.updateNotification(notification); } catch (RegistryServiceException e) { - logger.error("Error while updating notification", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating notification. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while updating notification: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -437,12 +426,9 @@ public boolean deleteNotification(String gatewayId, String notificationId) throw try { return registryService.deleteNotification(gatewayId, notificationId); } catch (RegistryServiceException e) { - logger.error("Error while deleting notification", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while deleting notification. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while deleting notification: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -450,12 +436,9 @@ public Notification getNotification(String gatewayId, String notificationId) thr try { return registryService.getNotification(gatewayId, notificationId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving notification", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving notification. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving notification: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -463,12 +446,9 @@ public List getAllNotifications(String gatewayId) throws AiravataS try { return registryService.getAllNotifications(gatewayId); } catch (RegistryServiceException e) { - logger.error("Error while getting all notifications", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while getting all notifications. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while getting all notifications: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -478,12 +458,7 @@ public String registerDataProduct(DataProductModel dataProductModel) throws Aira } catch (Throwable e) { var msg = "Error in registering the data resource" + dataProductModel.getProductName() + "."; logger.error(msg, e); - logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + ". More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -491,12 +466,9 @@ public DataProductModel getDataProduct(String productUri) throws AiravataSystemE try { return registryService.getDataProduct(productUri); } catch (RegistryServiceException e) { - logger.error("Error while retrieving data product", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving data product. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving data product: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -505,14 +477,9 @@ public String registerReplicaLocation(DataReplicaLocationModel replicaLocationMo try { return registryService.registerReplicaLocation(replicaLocationModel); } catch (Throwable e) { - var msg = "Error in retreiving the replica " + replicaLocationModel.getReplicaName() + "."; + var msg = "Error in retreiving the replica " + replicaLocationModel.getReplicaName() + "." + e.getMessage(); logger.error(msg, e); - logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + ". More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -520,14 +487,9 @@ public DataProductModel getParentDataProduct(String productUri) throws AiravataS try { return registryService.getParentDataProduct(productUri); } catch (Throwable e) { - var msg = "Error in retreiving the parent data product for " + productUri + "."; - logger.error(msg, e); + var msg = "Error in retreiving the parent data product for " + productUri + "." + e.getMessage(); logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + ". More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -535,14 +497,9 @@ public List getChildDataProducts(String productUri) throws Air try { return registryService.getChildDataProducts(productUri); } catch (Throwable e) { - var msg = "Error in retreiving the child products for " + productUri + "."; - logger.error(msg, e); + var msg = "Error in retreiving the child products for " + productUri + "." + e.getMessage(); logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + ". More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -551,12 +508,9 @@ public boolean isUserExists(String gatewayId, String userName) throws AiravataSy logger.debug("Checking if the user" + userName + "exists in the gateway" + gatewayId); return registryService.isUserExists(gatewayId, userName); } catch (RegistryServiceException e) { - logger.error("Error while verifying user", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while verifying user. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while verifying user: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -566,25 +520,9 @@ public Project getProject(String projectId) throws AiravataSystemException, Proj } catch (ProjectNotFoundException e) { throw e; } catch (RegistryServiceException e) { - logger.error("Error while retrieving the project", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving the project. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; - } - } - - public String createProject(String gatewayId, Project project) throws AiravataSystemException { - try { - return registryService.createProject(gatewayId, project); - } catch (RegistryServiceException e) { - logger.error("Error while creating project", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while creating project. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving the project: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -592,12 +530,9 @@ public void updateProject(String projectId, Project updatedProject) throws Airav try { registryService.updateProject(projectId, updatedProject); } catch (RegistryServiceException e) { - logger.error("Error while updating project", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating project. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while updating project: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -607,16 +542,13 @@ public boolean deleteProject(String projectId) throws AiravataSystemException, P } catch (ProjectNotFoundException e) { throw e; } catch (RegistryServiceException e) { - logger.error("Error while removing the project", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while removing the project. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while removing the project: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } - public List searchProjectsWithSharing( + public List searchProjects( AuthzToken authzToken, String gatewayId, String userName, @@ -653,20 +585,10 @@ public List searchProjectsWithSharing( result = registryService.searchProjects(gatewayId, userName, accessibleProjIds, filters, limit, offset); } return result; - } catch (RegistryServiceException | SharingRegistryException e) { - logger.error("Error while retrieving projects", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving projects. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; } catch (Throwable e) { - logger.error("Error while retrieving projects", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving projects. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving projects: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -686,12 +608,9 @@ public List getUserExperiments(String gatewayId, String userNam try { return registryService.getUserExperiments(gatewayId, userName, limit, offset); } catch (RegistryServiceException e) { - logger.error("Error occurred while getting user experiments", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while getting user experiments. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error occurred while getting user experiments: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -700,12 +619,9 @@ public List getExperimentsInProject(String gatewayId, String pr try { return registryService.getExperimentsInProject(gatewayId, projectId, limit, offset); } catch (RegistryServiceException e) { - logger.error("Error occurred while getting experiments in project", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while getting experiments in project. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error occurred while getting experiments in project: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -728,20 +644,10 @@ public List getExperimentsInProject(AuthzToken authzToken, Stri return registryService.getExperimentsInProject(gatewayId, projectId, limit, offset); } catch (AuthorizationException | ProjectNotFoundException | AiravataSystemException e) { throw e; - } catch (ApplicationSettingsException 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()); - exception.initCause(e); - throw exception; - } catch (SharingRegistryException | RegistryServiceException 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()); - exception.initCause(e); - throw exception; + } catch (ApplicationSettingsException | SharingRegistryException | RegistryServiceException e) { + String msg = "Error while retrieving the experiments: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -768,12 +674,9 @@ public ExperimentStatistics getExperimentStatistics( limit, offset); } catch (RegistryServiceException e) { - logger.error("Error while getting experiment statistics", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while getting experiment statistics. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while getting experiment statistics: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -781,25 +684,28 @@ public ExperimentModel getExperiment(String airavataExperimentId) throws Airavat try { return registryService.getExperiment(airavataExperimentId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving experiment", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving experiment. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving experiment: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } - public String createExperiment(String gatewayId, ExperimentModel experiment) throws AiravataSystemException { + private String createExperimentInternal(String gatewayId, ExperimentModel experiment) + throws AiravataSystemException { try { - return registryService.createExperiment(gatewayId, experiment); - } catch (RegistryServiceException e) { - logger.error("Error while creating experiment", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while creating experiment. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + var experimentId = registryService.createExperiment(gatewayId, experiment); + if (statusPublisher != null) { + var event = new ExperimentStatusChangeEvent(ExperimentState.CREATED, experimentId, gatewayId); + var messageId = AiravataUtils.getId("EXPERIMENT"); + var messageContext = new MessageContext(event, MessageType.EXPERIMENT, messageId, gatewayId); + messageContext.setUpdatedTime(AiravataUtils.getCurrentTimestamp()); + statusPublisher.publish(messageContext); + } + return experimentId; + } catch (RegistryServiceException | AiravataException e) { + String msg = "Error while creating experiment: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -822,20 +728,10 @@ public ExperimentModel getExperiment(AuthzToken authzToken, String airavataExper } } catch (AuthorizationException | AiravataSystemException e) { throw e; - } catch (ApplicationSettingsException e) { - logger.error("Error while getting the experiment", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while getting the experiment. More info: " + e.getMessage()); - exception.initCause(e); - throw exception; - } catch (SharingRegistryException e) { - logger.error("Error while getting the experiment", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while getting the experiment. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + } catch (ApplicationSettingsException | SharingRegistryException e) { + String msg = "Error while getting the experiment: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -871,35 +767,21 @@ public void updateExperiment(AuthzToken authzToken, String airavataExperimentId, } } - try { - // Update name, description and parent on Entity - // TODO: update the experiment via a DB event - var entity = getEntity(gatewayId, airavataExperimentId); - entity.delegate().setName(experiment.getExperimentName()); - entity.delegate().setDescription(experiment.getDescription()); - entity.delegate().setParentEntityId(experiment.getProjectId()); - updateEntity(entity); - } catch (Throwable e) { - throw new Exception("Failed to update entity in sharing registry", e); - } + // Update name, description and parent on Entity + // TODO: update the experiment via a DB event + var entity = getEntity(gatewayId, airavataExperimentId); + entity.delegate().setName(experiment.getExperimentName()); + entity.delegate().setDescription(experiment.getDescription()); + entity.delegate().setParentEntityId(experiment.getProjectId()); + updateEntity(entity); updateExperiment(airavataExperimentId, experiment); } catch (AuthorizationException | AiravataSystemException e) { throw e; - } catch (RegistryServiceException | SharingRegistryException e) { - logger.error("Error while updating experiment", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating experiment. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; - } catch (Exception e) { - logger.error("Error while updating experiment", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating experiment. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + } catch (Throwable e) { + String msg = "Error while updating experiment: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -908,12 +790,9 @@ public void updateExperiment(String airavataExperimentId, ExperimentModel experi try { registryService.updateExperiment(airavataExperimentId, experiment); } catch (RegistryServiceException e) { - logger.error("Error while updating experiment", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating experiment. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while updating experiment: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -921,16 +800,13 @@ public boolean deleteExperiment(String experimentId) throws AiravataSystemExcept try { return registryService.deleteExperiment(experimentId); } catch (RegistryServiceException e) { - logger.error("Error while deleting experiment", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while deleting experiment. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while deleting experiment: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } - public String cloneExperimentInternal( + public String cloneExperiment( AuthzToken authzToken, String existingExperimentID, String newExperimentName, @@ -949,7 +825,7 @@ public String cloneExperimentInternal( } if (newExperimentProjectId != null) { // getProject will apply sharing permissions - var project = getProjectWithAuth(authzToken, newExperimentProjectId); + var project = getProject(authzToken, newExperimentProjectId); if (project == null) { logger.error( "Error while cloning experiment {}, project {} doesn't exist.", @@ -1014,7 +890,7 @@ public String cloneExperimentInternal( logger.debug("Airavata cloned experiment with experiment id : " + existingExperimentID); existingExperiment.setUserName(userId); - var expId = createExperiment(gatewayId, existingExperiment); + var expId = createExperimentInternal(gatewayId, existingExperiment); if (ServerSettings.isEnableSharing()) { try { var entity = new Entity(); @@ -1036,12 +912,10 @@ public String cloneExperimentInternal( logger.error("Error deleting experiment during rollback: " + e.getMessage()); } logger.error("Error while creating entity for cloned experiment", ex); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while creating entity for cloned experiment. More info : " + ex.getMessage()); - exception.initCause(ex); - throw exception; + throw airavataSystemException( + AiravataErrorType.INTERNAL_ERROR, + "Error while creating entity for cloned experiment. More info : " + ex.getMessage(), + ex); } } @@ -1052,16 +926,13 @@ public String cloneExperimentInternal( | AiravataSystemException e) { throw e; } catch (SharingRegistryException | ApplicationSettingsException e) { - logger.error("Error while cloning experiment", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while cloning experiment. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while cloning experiment: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } - public void terminateExperiment(Publisher experimentPublisher, String airavataExperimentId, String gatewayId) + public void terminateExperiment(String airavataExperimentId, String gatewayId) throws ExperimentNotFoundException, AiravataSystemException { try { var existingExperiment = getExperiment(airavataExperimentId); @@ -1098,13 +969,9 @@ public void terminateExperiment(Publisher experimentPublisher, String airavataEx } catch (ExperimentNotFoundException e) { throw e; } catch (Throwable e) { - logger.error(airavataExperimentId, "Error while cancelling the experiment...", e); - logger.error("Error occurred", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error occurred while cancelling the experiment: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1120,9 +987,10 @@ public List searchExperiments( } /** - * Search experiments with sharing registry integration - processes filters and builds search criteria + * Search experiments with sharing registry integration - processes filters and + * builds search criteria */ - public List searchExperimentsWithSharing( + public List searchExperiments( AuthzToken authzToken, String gatewayId, String userName, @@ -1208,18 +1076,16 @@ public List searchExperimentsWithSharing( searchLimit) .forEach(e -> accessibleExpIds.add(e.getEntityId())); int finalOffset = offset; - // If no more filtering to be done (either empty or all done through sharing API), set the offset to 0 + // If no more filtering to be done (either empty or all done through sharing + // API), set the offset to 0 if (filteredInSharing) { finalOffset = 0; } return searchExperiments(gatewayId, userName, accessibleExpIds, filtersCopy, limit, finalOffset); } catch (RegistryServiceException | SharingRegistryException e) { - logger.error("Error while retrieving experiments", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving experiments. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving experiments: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1227,12 +1093,9 @@ public ExperimentStatus getExperimentStatus(String airavataExperimentId) throws try { return registryService.getExperimentStatus(airavataExperimentId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving experiment status", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving experiment status. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving experiment status: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1240,12 +1103,9 @@ public List getExperimentOutputs(String airavataExperiment try { return registryService.getExperimentOutputs(airavataExperimentId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving experiment outputs", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving experiment outputs. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving experiment outputs: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1253,12 +1113,9 @@ public ExperimentModel getDetailedExperimentTree(String airavataExperimentId) th try { return registryService.getDetailedExperimentTree(airavataExperimentId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving detailed experiment tree", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving detailed experiment tree. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving detailed experiment tree: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1266,12 +1123,9 @@ public List getApplicationOutputs(String appInterfaceId) t try { return registryService.getApplicationOutputs(appInterfaceId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving application outputs", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving application outputs. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving application outputs: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1279,12 +1133,9 @@ public ComputeResourceDescription getComputeResource(String computeResourceId) t try { return registryService.getComputeResource(computeResourceId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving compute resource", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving compute resource. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving compute resource: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1293,12 +1144,9 @@ public String registerComputeResource(ComputeResourceDescription computeResource try { return registryService.registerComputeResource(computeResourceDescription); } catch (RegistryServiceException e) { - logger.error("Error while saving compute resource", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while saving compute resource. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while saving compute resource: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1308,12 +1156,9 @@ public boolean updateComputeResource( try { return registryService.updateComputeResource(computeResourceId, computeResourceDescription); } catch (RegistryServiceException e) { - logger.error("Error while updating compute resource", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating compute resource. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while updating compute resource: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1321,12 +1166,9 @@ public boolean deleteComputeResource(String computeResourceId) throws AiravataSy try { return registryService.deleteComputeResource(computeResourceId); } catch (RegistryServiceException e) { - logger.error("Error while deleting compute resource", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while deleting compute resource. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while deleting compute resource: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1334,12 +1176,9 @@ public Map getAllComputeResourceNames() throws AiravataSystemExc try { return registryService.getAllComputeResourceNames(); } catch (RegistryServiceException e) { - logger.error("Error while retrieving compute resource names", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving compute resource names. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving compute resource names: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1348,12 +1187,9 @@ public String registerStorageResource(StorageResourceDescription storageResource try { return registryService.registerStorageResource(storageResourceDescription); } catch (RegistryServiceException e) { - logger.error("Error while saving storage resource", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while saving storage resource. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while saving storage resource: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1361,12 +1197,9 @@ public StorageResourceDescription getStorageResource(String storageResourceId) t try { return registryService.getStorageResource(storageResourceId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving storage resource", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving storage resource. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving storage resource: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1376,12 +1209,9 @@ public boolean updateStorageResource( try { return registryService.updateStorageResource(storageResourceId, storageResourceDescription); } catch (RegistryServiceException e) { - logger.error("Error while updating storage resource", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating storage resource. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while updating storage resource: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1389,12 +1219,9 @@ public boolean deleteStorageResource(String storageResourceId) throws AiravataSy try { return registryService.deleteStorageResource(storageResourceId); } catch (RegistryServiceException e) { - logger.error("Error while deleting storage resource", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while deleting storage resource. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while deleting storage resource: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1402,12 +1229,9 @@ public Map getAllStorageResourceNames() throws AiravataSystemExc try { return registryService.getAllStorageResourceNames(); } catch (RegistryServiceException e) { - logger.error("Error while retrieving storage resource names", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving storage resource names. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving storage resource names: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1416,12 +1240,9 @@ public String registerGatewayResourceProfile(GatewayResourceProfile gatewayResou try { return registryService.registerGatewayResourceProfile(gatewayResourceProfile); } catch (RegistryServiceException e) { - logger.error("Error while registering gateway resource profile", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while registering gateway resource profile. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while registering gateway resource profile: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1429,12 +1250,9 @@ public GatewayResourceProfile getGatewayResourceProfile(String gatewayID) throws try { return registryService.getGatewayResourceProfile(gatewayID); } catch (RegistryServiceException e) { - logger.error("Error while retrieving gateway resource profile", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving gateway resource profile. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving gateway resource profile: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1443,12 +1261,9 @@ public boolean updateGatewayResourceProfile(String gatewayID, GatewayResourcePro try { return registryService.updateGatewayResourceProfile(gatewayID, gatewayResourceProfile); } catch (RegistryServiceException e) { - logger.error("Error while updating gateway resource profile", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating gateway resource profile. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while updating gateway resource profile: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1456,12 +1271,9 @@ public boolean deleteGatewayResourceProfile(String gatewayID) throws AiravataSys try { return registryService.deleteGatewayResourceProfile(gatewayID); } catch (RegistryServiceException e) { - logger.error("Error while removing gateway resource profile", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while removing gateway resource profile. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while removing gateway resource profile: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1469,12 +1281,9 @@ public UserResourceProfile getUserResourceProfile(String userId, String gatewayI try { return registryService.getUserResourceProfile(userId, gatewayId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving user resource profile", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving user resource profile. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving user resource profile: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1483,12 +1292,9 @@ public boolean updateUserResourceProfile(String userId, String gatewayID, UserRe try { return registryService.updateUserResourceProfile(userId, gatewayID, userResourceProfile); } catch (RegistryServiceException e) { - logger.error("Error while updating user resource profile", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating user resource profile. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while updating user resource profile: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1496,12 +1302,9 @@ public boolean deleteUserResourceProfile(String userId, String gatewayID) throws try { return registryService.deleteUserResourceProfile(userId, gatewayID); } catch (RegistryServiceException e) { - logger.error("Error while removing user resource profile", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while removing user resource profile. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while removing user resource profile: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1509,12 +1312,9 @@ public GroupResourceProfile getGroupResourceProfile(String groupResourceProfileI try { return registryService.getGroupResourceProfile(groupResourceProfileId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving group resource profile", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving group resource profile. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving group resource profile: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1522,12 +1322,9 @@ public void updateGroupResourceProfile(GroupResourceProfile groupResourceProfile try { registryService.updateGroupResourceProfile(groupResourceProfile); } catch (RegistryServiceException e) { - logger.error("Error while updating group resource profile", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating group resource profile. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while updating group resource profile: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1536,12 +1333,9 @@ public List getGroupResourceList(String gatewayId, List getApplicationDeployments(String a try { return registryService.getApplicationDeployments(appModuleId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving application deployments", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving application deployments. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving application deployments: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1794,12 +1542,9 @@ public String registerApplicationInterface(String gatewayId, ApplicationInterfac try { return registryService.registerApplicationInterface(gatewayId, applicationInterface); } catch (RegistryServiceException e) { - logger.error("Error while adding application interface", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding application interface. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while adding application interface: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1808,9 +1553,10 @@ public String cloneApplicationInterface(String existingAppInterfaceID, String ne try { var existingInterface = getApplicationInterface(existingAppInterfaceID); if (existingInterface == null) { - logger.error( - "Provided application interface does not exist.Please provide a valid application interface id..."); - throw new AiravataSystemException(AiravataErrorType.INTERNAL_ERROR); + String msg = + "Provided application interface does not exist.Please provide a valid application interface id..."; + logger.error(msg); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, null); } existingInterface.setApplicationName(newApplicationName); @@ -1830,12 +1576,9 @@ public boolean updateApplicationInterface( try { return registryService.updateApplicationInterface(appInterfaceId, applicationInterface); } catch (RegistryServiceException e) { - logger.error("Error while updating application interface", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating application interface. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while updating application interface: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1843,12 +1586,9 @@ public boolean deleteApplicationInterface(String appInterfaceId) throws Airavata try { return registryService.deleteApplicationInterface(appInterfaceId); } catch (RegistryServiceException e) { - logger.error("Error while deleting application interface", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while deleting application interface. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while deleting application interface: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1856,12 +1596,9 @@ public Map getAllApplicationInterfaceNames(String gatewayId) thr try { return registryService.getAllApplicationInterfaceNames(gatewayId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving application interfaces", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving application interfaces. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving application interfaces: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1870,12 +1607,9 @@ public List getAllApplicationInterfaces(String try { return registryService.getAllApplicationInterfaces(gatewayId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving application interfaces", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving application interfaces. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving application interfaces: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1883,12 +1617,9 @@ public List getApplicationInputs(String appInterfaceId) thr try { return registryService.getApplicationInputs(appInterfaceId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving application inputs", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving application inputs. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving application inputs: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1897,12 +1628,9 @@ public String registerApplicationModule(String gatewayId, ApplicationModule appl try { return registryService.registerApplicationModule(gatewayId, applicationModule); } catch (RegistryServiceException e) { - logger.error("Error while adding application module", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding application module. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while adding application module: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1910,12 +1638,9 @@ public ApplicationModule getApplicationModule(String appModuleId) throws Airavat try { return registryService.getApplicationModule(appModuleId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving application module", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving application module. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving application module: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1924,12 +1649,9 @@ public boolean updateApplicationModule(String appModuleId, ApplicationModule app try { return registryService.updateApplicationModule(appModuleId, applicationModule); } catch (RegistryServiceException e) { - logger.error("Error while updating application module", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating application module. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while updating application module: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1937,12 +1659,9 @@ public List getAllAppModules(String gatewayId) throws Airavat try { return registryService.getAllAppModules(gatewayId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving all application modules", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving all application modules. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving all application modules: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1950,12 +1669,9 @@ public boolean deleteApplicationModule(String appModuleId) throws AiravataSystem try { return registryService.deleteApplicationModule(appModuleId); } catch (RegistryServiceException e) { - logger.error("Error while deleting application module", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while deleting application module. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while deleting application module: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -1968,7 +1684,7 @@ public List getAccessibleAppModules( /** * Get accessible app modules with sharing registry integration */ - public List getAccessibleAppModulesWithSharing(AuthzToken authzToken, String gatewayId) + public List getAccessibleAppModules(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataSystemException, AuthorizationException { try { var userName = authzToken.getClaimsMap().get(Constants.USER_NAME); @@ -1995,8 +1711,7 @@ public List getAccessibleAppModulesWithSharing(AuthzToken aut .forEach(a -> accessibleAppDeploymentIds.add(a.getEntityId())); } var accessibleComputeResourceIds = new ArrayList(); - List groupResourceProfileList = - getGroupResourceListWithSharing(authzToken, gatewayId); + List groupResourceProfileList = getGroupResourceList(authzToken, gatewayId); for (GroupResourceProfile groupResourceProfile : groupResourceProfileList) { List groupComputeResourcePreferenceList = groupResourceProfile.getComputePreferences(); @@ -2008,20 +1723,10 @@ public List getAccessibleAppModulesWithSharing(AuthzToken aut return getAccessibleAppModules(gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); } catch (AiravataSystemException e) { throw e; - } catch (ApplicationSettingsException e) { - logger.error("Error occurred while getting accessible app modules", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while getting accessible app modules. More info: " + e.getMessage()); - exception.initCause(e); - throw exception; - } catch (RegistryServiceException | SharingRegistryException e) { - logger.error("Error occurred while getting accessible app modules", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while getting accessible app modules. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + } catch (ApplicationSettingsException | RegistryServiceException | SharingRegistryException e) { + String msg = "Error occurred while getting accessible app modules: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2029,12 +1734,9 @@ public Map getJobStatuses(String airavataExperimentId) throws try { return registryService.getJobStatuses(airavataExperimentId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving job statuses", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving job statuses. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving job statuses: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2042,12 +1744,9 @@ public List getJobDetails(String airavataExperimentId) throws Airavata try { return registryService.getJobDetails(airavataExperimentId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving job details", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving job details. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving job details: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2057,19 +1756,9 @@ public String addLocalSubmissionDetails( try { return registryService.addLocalSubmissionDetails(computeResourceId, priorityOrder, localSubmission); } catch (RegistryServiceException e) { - logger.error("Error while adding local job submission interface", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding local job submission interface. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; - } catch (Throwable e) { - logger.error("Error while adding local job submission interface", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding local job submission interface. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while adding local job submission interface: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2079,12 +1768,9 @@ public String addSSHJobSubmissionDetails( try { return registryService.addSSHJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); } catch (RegistryServiceException e) { - logger.error("Error while adding SSH job submission interface", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding SSH job submission interface. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while adding SSH job submission interface: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2094,12 +1780,9 @@ public String addSSHForkJobSubmissionDetails( try { return registryService.addSSHForkJobSubmissionDetails(computeResourceId, priorityOrder, sshJobSubmission); } catch (RegistryServiceException e) { - logger.error("Error while adding SSH fork job submission interface", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding SSH fork job submission interface. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while adding SSH fork job submission interface: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2109,12 +1792,9 @@ public String addCloudJobSubmissionDetails( try { return registryService.addCloudJobSubmissionDetails(computeResourceId, priorityOrder, cloudJobSubmission); } catch (RegistryServiceException e) { - logger.error("Error while adding cloud job submission interface", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding cloud job submission interface. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while adding cloud job submission interface: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2125,12 +1805,9 @@ public String addUNICOREJobSubmissionDetails( return registryService.addUNICOREJobSubmissionDetails( computeResourceId, priorityOrder, unicoreJobSubmission); } catch (RegistryServiceException e) { - logger.error("Error while adding UNICORE job submission interface", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding UNICORE job submission interface. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while adding UNICORE job submission interface: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2138,20 +1815,10 @@ public boolean updateLocalSubmissionDetails(String jobSubmissionInterfaceId, LOC throws AiravataSystemException { try { return registryService.updateLocalSubmissionDetails(jobSubmissionInterfaceId, localSubmission); - } catch (RegistryServiceException e) { - logger.error("Error while updating local job submission interface", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating local job submission interface. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; } catch (Throwable e) { - logger.error("Error while updating local job submission interface", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating local job submission interface. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while updating local job submission interface: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2159,13 +1826,9 @@ public LOCALSubmission getLocalJobSubmission(String jobSubmissionId) throws Aira try { return registryService.getLocalJobSubmission(jobSubmissionId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving local job submission interface", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while retrieving local job submission interface. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving local job submission interface: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2173,12 +1836,9 @@ public SSHJobSubmission getSSHJobSubmission(String jobSubmissionId) throws Airav try { return registryService.getSSHJobSubmission(jobSubmissionId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving SSH job submission", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving SSH job submission. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving SSH job submission: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2186,12 +1846,9 @@ public CloudJobSubmission getCloudJobSubmission(String jobSubmissionId) throws A try { return registryService.getCloudJobSubmission(jobSubmissionId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving cloud job submission", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving cloud job submission. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving cloud job submission: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2199,12 +1856,9 @@ public UnicoreJobSubmission getUnicoreJobSubmission(String jobSubmissionId) thro try { return registryService.getUnicoreJobSubmission(jobSubmissionId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving UNICORE job submission", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving UNICORE job submission. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving UNICORE job submission: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2213,12 +1867,9 @@ public boolean updateSSHJobSubmissionDetails(String jobSubmissionInterfaceId, SS try { return registryService.updateSSHJobSubmissionDetails(jobSubmissionInterfaceId, sshJobSubmission); } catch (RegistryServiceException e) { - logger.error("Error while updating job submission interface", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating job submission interface. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while updating job submission interface: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2227,12 +1878,9 @@ public boolean updateCloudJobSubmissionDetails( try { return registryService.updateCloudJobSubmissionDetails(jobSubmissionInterfaceId, cloudJobSubmission); } catch (RegistryServiceException e) { - logger.error("Error while updating job submission interface", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating job submission interface. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while updating job submission interface: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2241,12 +1889,9 @@ public boolean updateUnicoreJobSubmissionDetails( try { return registryService.updateUnicoreJobSubmissionDetails(jobSubmissionInterfaceId, unicoreJobSubmission); } catch (RegistryServiceException e) { - logger.error("Error while updating job submission interface", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating job submission interface. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while updating job submission interface: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2255,12 +1900,9 @@ public boolean deleteJobSubmissionInterface(String computeResourceId, String job try { return registryService.deleteJobSubmissionInterface(computeResourceId, jobSubmissionInterfaceId); } catch (RegistryServiceException e) { - logger.error("Error while deleting job submission interface", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while deleting job submission interface. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while deleting job submission interface: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2268,12 +1910,9 @@ public String registerResourceJobManager(ResourceJobManager resourceJobManager) try { return registryService.registerResourceJobManager(resourceJobManager); } catch (RegistryServiceException e) { - logger.error("Error while adding resource job manager", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding resource job manager. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while adding resource job manager: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2282,52 +1921,29 @@ public boolean updateResourceJobManager(String resourceJobManagerId, ResourceJob try { return registryService.updateResourceJobManager(resourceJobManagerId, updatedResourceJobManager); } catch (RegistryServiceException e) { - logger.error("Error while updating resource job manager", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating resource job manager. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while updating resource job manager: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } public ResourceJobManager getResourceJobManager(String resourceJobManagerId) throws AiravataSystemException { try { return registryService.getResourceJobManager(resourceJobManagerId); - } catch (RegistryServiceException e) { - logger.error("Error while retrieving resource job manager", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving resource job manager. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; } catch (Throwable e) { - logger.error("Error while retrieving resource job manager", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving resource job manager. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving resource job manager: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } public boolean deleteResourceJobManager(String resourceJobManagerId) throws AiravataSystemException { try { return registryService.deleteResourceJobManager(resourceJobManagerId); - } catch (RegistryServiceException e) { - logger.error("Error while deleting resource job manager", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while deleting resource job manager. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; } catch (Throwable e) { - logger.error("Error while deleting resource job manager", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while deleting resource job manager. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while deleting resource job manager: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2358,13 +1974,9 @@ public String addLocalDataMovementDetails( try { return registryService.addLocalDataMovementDetails(resourceId, dmType, priorityOrder, localDataMovement); } catch (RegistryServiceException e) { - logger.error("Error while adding data movement interface to resource", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while adding data movement interface to resource. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while adding data movement interface to resource: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2373,12 +1985,9 @@ public boolean updateLocalDataMovementDetails(String dataMovementInterfaceId, LO try { return registryService.updateLocalDataMovementDetails(dataMovementInterfaceId, localDataMovement); } catch (RegistryServiceException e) { - logger.error("Error while updating local data movement interface", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating local data movement interface. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while updating local data movement interface: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2386,12 +1995,9 @@ public LOCALDataMovement getLocalDataMovement(String dataMovementId) throws Aira try { return registryService.getLocalDataMovement(dataMovementId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving local data movement interface", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving local data movement interface. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving local data movement interface: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2401,12 +2007,9 @@ public String addSCPDataMovementDetails( try { return registryService.addSCPDataMovementDetails(resourceId, dmType, priorityOrder, scpDataMovement); } catch (RegistryServiceException e) { - logger.error("Error while adding SCP data movement interface", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding SCP data movement interface. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while adding SCP data movement interface: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2415,12 +2018,9 @@ public boolean updateSCPDataMovementDetails(String dataMovementInterfaceId, SCPD try { return registryService.updateSCPDataMovementDetails(dataMovementInterfaceId, scpDataMovement); } catch (RegistryServiceException e) { - logger.error("Error while updating SCP data movement interface", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating SCP data movement interface. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while updating SCP data movement interface: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2432,7 +2032,7 @@ public List getUserProjects(String gatewayId, String userName, int limi /** * Get user projects with sharing registry integration */ - public List getUserProjectsWithSharing( + public List getUserProjects( AuthzToken authzToken, String gatewayId, String userName, int limit, int offset) throws AiravataSystemException { try { @@ -2464,20 +2064,10 @@ public List getUserProjectsWithSharing( } else { return getUserProjects(gatewayId, userName, limit, offset); } - } catch (ApplicationSettingsException e) { - logger.error("Error while retrieving user projects", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving user projects. More info: " + e.getMessage()); - exception.initCause(e); - throw exception; - } catch (RegistryServiceException | SharingRegistryException e) { - logger.error("Error while retrieving user projects", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving user projects. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + } catch (ApplicationSettingsException | RegistryServiceException | SharingRegistryException e) { + String msg = "Error while retrieving user projects: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2491,7 +2081,7 @@ public List getAccessibleApplicationDeployment /** * Get accessible application deployments with sharing registry integration */ - public List getAccessibleApplicationDeploymentsWithSharing( + public List getAccessibleApplicationDeployments( AuthzToken authzToken, String gatewayId, ResourcePermissionType permissionType) throws InvalidRequestException, AiravataSystemException, AuthorizationException { try { @@ -2519,8 +2109,7 @@ public List getAccessibleApplicationDeployment .forEach(a -> accessibleAppDeploymentIds.add(a.getEntityId())); } var accessibleComputeResourceIds = new ArrayList(); - List groupResourceProfileList = - getGroupResourceListWithSharing(authzToken, gatewayId); + List groupResourceProfileList = getGroupResourceList(authzToken, gatewayId); for (GroupResourceProfile groupResourceProfile : groupResourceProfileList) { List groupComputeResourcePreferenceList = groupResourceProfile.getComputePreferences(); @@ -2531,22 +2120,10 @@ public List getAccessibleApplicationDeployment } return getAccessibleApplicationDeployments( gatewayId, accessibleAppDeploymentIds, accessibleComputeResourceIds); - } catch (ApplicationSettingsException e) { - logger.error("Error occurred while getting accessible application deployments", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error occurred while getting accessible application deployments. More info: " + e.getMessage()); - exception.initCause(e); - throw exception; - } catch (RegistryServiceException | SharingRegistryException e) { - logger.error("Error occurred while getting accessible application deployments", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error occurred while getting accessible application deployments. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + } catch (ApplicationSettingsException | RegistryServiceException | SharingRegistryException e) { + String msg = "Error occurred while getting accessible application deployments: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2554,12 +2131,9 @@ public List getAppModuleDeployedResources(String appModuleId) throws Air try { return registryService.getAppModuleDeployedResources(appModuleId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving application deployment", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving application deployment. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving application deployment: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2573,13 +2147,9 @@ public List getAccessibleApplicationDeployment return registryService.getAccessibleApplicationDeploymentsForAppModule( gatewayId, appModuleId, accessibleAppDeploymentIds, accessibleComputeResourceIds); } catch (RegistryServiceException e) { - logger.error("Error while retrieving accessible application deployments", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while retrieving accessible application deployments. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving accessible application deployments: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2591,7 +2161,7 @@ public List getApplicationDeploymentsForAppMod var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); // Get list of compute resources for this Group Resource Profile - if (!userHasAccessInternal(authzToken, groupResourceProfileId, ResourcePermissionType.READ)) { + if (!userHasAccess(authzToken, groupResourceProfileId, ResourcePermissionType.READ)) { throw new AuthorizationException( "User is not authorized to access Group Resource Profile " + groupResourceProfileId); } @@ -2621,12 +2191,9 @@ public List getApplicationDeploymentsForAppMod } catch (AiravataSystemException e) { throw e; } catch (SharingRegistryException e) { - logger.error("Error while retrieving application deployments", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving application deployments. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving application deployments: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2635,12 +2202,9 @@ public Map getAvailableAppInterfaceComputeResources(String appIn try { return registryService.getAvailableAppInterfaceComputeResources(appInterfaceId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving available compute resources", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving available compute resources. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving available compute resources: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2648,12 +2212,9 @@ public SCPDataMovement getSCPDataMovement(String dataMovementId) throws Airavata try { return registryService.getSCPDataMovement(dataMovementId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving SCP data movement interface", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving SCP data movement interface. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving SCP data movement interface: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2664,12 +2225,9 @@ public String addUnicoreDataMovementDetails( return registryService.addUnicoreDataMovementDetails( resourceId, dmType, priorityOrder, unicoreDataMovement); } catch (RegistryServiceException e) { - logger.error("Error while adding UNICORE data movement interface", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding UNICORE data movement interface. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while adding UNICORE data movement interface: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2678,12 +2236,9 @@ public boolean updateUnicoreDataMovementDetails( try { return registryService.updateUnicoreDataMovementDetails(dataMovementInterfaceId, unicoreDataMovement); } catch (RegistryServiceException e) { - logger.error("Error while updating unicore data movement interface", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating unicore data movement interface. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while updating unicore data movement interface: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2691,13 +2246,9 @@ public UnicoreDataMovement getUnicoreDataMovement(String dataMovementId) throws try { return registryService.getUnicoreDataMovement(dataMovementId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving UNICORE data movement interface", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while retrieving UNICORE data movement interface. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving UNICORE data movement interface: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2708,12 +2259,9 @@ public String addGridFTPDataMovementDetails( return registryService.addGridFTPDataMovementDetails( resourceId, dmType, priorityOrder, gridFTPDataMovement); } catch (RegistryServiceException e) { - logger.error("Error while adding GridFTP data movement interface", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding GridFTP data movement interface. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while adding GridFTP data movement interface: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2722,12 +2270,9 @@ public boolean updateGridFTPDataMovementDetails( try { return registryService.updateGridFTPDataMovementDetails(dataMovementInterfaceId, gridFTPDataMovement); } catch (RegistryServiceException e) { - logger.error("Error while updating GridFTP data movement interface", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating GridFTP data movement interface. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while updating GridFTP data movement interface: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2735,13 +2280,9 @@ public GridFTPDataMovement getGridFTPDataMovement(String dataMovementId) throws try { return registryService.getGridFTPDataMovement(dataMovementId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving GridFTP data movement interface", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while retrieving GridFTP data movement interface. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving GridFTP data movement interface: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2750,12 +2291,9 @@ public boolean deleteDataMovementInterface(String resourceId, String dataMovemen try { return registryService.deleteDataMovementInterface(resourceId, dataMovementInterfaceId, dmType); } catch (RegistryServiceException e) { - logger.error("Error while deleting data movement interface", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while deleting data movement interface. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while deleting data movement interface: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2763,12 +2301,9 @@ public boolean deleteBatchQueue(String computeResourceId, String queueName) thro try { return registryService.deleteBatchQueue(computeResourceId, queueName); } catch (RegistryServiceException e) { - logger.error("Error while deleting batch queue", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while deleting batch queue. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while deleting batch queue: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2779,13 +2314,9 @@ public boolean addGatewayComputeResourcePreference( return registryService.addGatewayComputeResourcePreference( gatewayID, computeResourceId, computeResourcePreference); } catch (RegistryServiceException e) { - logger.error("Error while registering gateway resource profile preference", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while registering gateway resource profile preference. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while registering gateway resource profile preference: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2795,12 +2326,9 @@ public boolean addGatewayStoragePreference( try { return registryService.addGatewayStoragePreference(gatewayID, storageResourceId, dataStoragePreference); } catch (RegistryServiceException e) { - logger.error("Error while registering gateway storage preference", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while registering gateway storage preference. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while registering gateway storage preference: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2809,13 +2337,9 @@ public ComputeResourcePreference getGatewayComputeResourcePreference(String gate try { return registryService.getGatewayComputeResourcePreference(gatewayID, computeResourceId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving gateway compute resource preference", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while retrieving gateway compute resource preference. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving gateway compute resource preference: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2824,12 +2348,9 @@ public StoragePreference getGatewayStoragePreference(String gatewayID, String st try { return registryService.getGatewayStoragePreference(gatewayID, storageId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving gateway storage preference", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving gateway storage preference. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving gateway storage preference: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2838,43 +2359,19 @@ public List getAllGatewayComputeResourcePreferences(S try { return registryService.getAllGatewayComputeResourcePreferences(gatewayID); } catch (RegistryServiceException e) { - logger.error("Error while retrieving all gateway compute resource preferences", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while retrieving all gateway compute resource preferences. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; - } catch (Throwable e) { - logger.error("Error while retrieving all gateway compute resource preferences", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while retrieving all gateway compute resource preferences. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving all gateway compute resource preferences: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } public List getAllGatewayStoragePreferences(String gatewayID) throws AiravataSystemException { try { return registryService.getAllGatewayStoragePreferences(gatewayID); - } catch (RegistryServiceException e) { - logger.error("Error while retrieving all gateway storage preferences", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while retrieving all gateway storage preferences. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; } catch (Throwable e) { - logger.error("Error while retrieving all gateway storage preferences", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while retrieving all gateway storage preferences. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving all gateway storage preferences: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2882,19 +2379,9 @@ public List getAllGatewayResourceProfiles() throws Airav try { return registryService.getAllGatewayResourceProfiles(); } catch (RegistryServiceException e) { - logger.error("Error while retrieving all gateway resource profiles", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving all gateway resource profiles. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; - } catch (Throwable e) { - logger.error("Error while retrieving all gateway resource profiles", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving all gateway resource profiles. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving all gateway resource profiles: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2905,21 +2392,9 @@ public boolean updateGatewayComputeResourcePreference( return registryService.updateGatewayComputeResourcePreference( gatewayID, computeResourceId, computeResourcePreference); } catch (RegistryServiceException e) { - logger.error("Error while updating gateway compute resource preference", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while updating gateway compute resource preference. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; - } catch (Throwable e) { - logger.error("Error while updating gateway compute resource preference", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while updating gateway compute resource preference. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while updating gateway compute resource preference: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2929,19 +2404,9 @@ public boolean updateGatewayStoragePreference( try { return registryService.updateGatewayStoragePreference(gatewayID, storageId, dataStoragePreference); } catch (RegistryServiceException e) { - logger.error("Error while updating gateway data storage preference", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating gateway data storage preference. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; - } catch (Throwable e) { - logger.error("Error while updating gateway data storage preference", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating gateway data storage preference. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while updating gateway data storage preference: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2950,14 +2415,10 @@ public boolean deleteGatewayComputeResourcePreference(String gatewayID, String c try { return registryService.deleteGatewayComputeResourcePreference(gatewayID, computeResourceId); } catch (Throwable e) { - logger.error(gatewayID, "Error while deleting gateway compute resource preference...", e); - logger.error("Error while deleting gateway compute resource preference", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while deleting gateway compute resource preference. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while deleting gateway compute resource preference: " + gatewayID + " " + + computeResourceId + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2965,12 +2426,10 @@ public boolean deleteGatewayStoragePreference(String gatewayID, String storageId try { return registryService.deleteGatewayStoragePreference(gatewayID, storageId); } catch (RegistryServiceException e) { - logger.error("Error while deleting gateway data storage preference", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while deleting gateway data storage preference. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while deleting gateway data storage preference: " + gatewayID + " " + storageId + " " + + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2978,12 +2437,10 @@ public String registerUserResourceProfile(UserResourceProfile userResourceProfil try { return registryService.registerUserResourceProfile(userResourceProfile); } catch (RegistryServiceException e) { - logger.error("Error while registering user resource profile", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while registering user resource profile. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while registering user resource profile: " + userResourceProfile.getUserId() + " " + + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -2991,13 +2448,10 @@ public boolean isUserResourceProfileExists(String userId, String gatewayId) thro try { return registryService.isUserResourceProfileExists(userId, gatewayId); } catch (RegistryServiceException e) { - logger.error("Error while checking existence of user resource profile", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while checking existence of user resource profile. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while checking existence of user resource profile: " + userId + " " + gatewayId + " " + + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3011,14 +2465,10 @@ public boolean addUserComputeResourcePreference( return registryService.addUserComputeResourcePreference( userId, gatewayID, computeResourceId, userComputeResourcePreference); } catch (Throwable e) { - logger.error(userId, "Error while registering user resource profile preference...", e); - logger.error("Error while registering user resource profile preference", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while registering user resource profile preference. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while registering user resource profile preference: " + userId + " " + gatewayID + " " + + computeResourceId + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3029,12 +2479,10 @@ public boolean addUserStoragePreference( return registryService.addUserStoragePreference( userId, gatewayID, userStorageResourceId, dataStoragePreference); } catch (RegistryServiceException e) { - logger.error("Error while registering user storage preference", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while registering user storage preference. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while registering user storage preference: " + userId + " " + gatewayID + " " + + userStorageResourceId + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3043,12 +2491,10 @@ public UserComputeResourcePreference getUserComputeResourcePreference( try { return registryService.getUserComputeResourcePreference(userId, gatewayID, userComputeResourceId); } catch (RegistryServiceException e) { - logger.error("Error while reading user compute resource preference", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while reading user compute resource preference. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while reading user compute resource preference: " + userId + " " + gatewayID + " " + + userComputeResourceId + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3057,12 +2503,10 @@ public UserStoragePreference getUserStoragePreference(String userId, String gate try { return registryService.getUserStoragePreference(userId, gatewayID, userStorageId); } catch (RegistryServiceException e) { - logger.error("Error while reading user data storage preference", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while reading user data storage preference. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while reading user data storage preference: " + userId + " " + gatewayID + " " + + userStorageId + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3071,13 +2515,10 @@ public List getAllUserComputeResourcePreferences( try { return registryService.getAllUserComputeResourcePreferences(userId, gatewayID); } catch (RegistryServiceException e) { - logger.error("Error while reading User compute resource preferences", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while reading User compute resource preferences. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while reading User compute resource preferences: " + userId + " " + gatewayID + " " + + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3086,12 +2527,10 @@ public List getAllUserStoragePreferences(String userId, S try { return registryService.getAllUserStoragePreferences(userId, gatewayID); } catch (RegistryServiceException e) { - logger.error("Error while reading User data storage preferences", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while reading User data storage preferences. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while reading User data storage preferences: " + userId + " " + gatewayID + " " + + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3099,13 +2538,9 @@ public List getAllUserResourceProfiles() throws AiravataSys try { return registryService.getAllUserResourceProfiles(); } catch (RegistryServiceException e) { - logger.error("Error while reading retrieving all user resource profiles", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while reading retrieving all user resource profiles. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while reading retrieving all user resource profiles: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3119,13 +2554,10 @@ public boolean updateUserComputeResourcePreference( return registryService.updateUserComputeResourcePreference( userId, gatewayID, computeResourceId, userComputeResourcePreference); } catch (RegistryServiceException e) { - logger.error("Error while updating user compute resource preference", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while updating user compute resource preference. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while updating user compute resource preference: " + userId + " " + gatewayID + " " + + computeResourceId + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3135,12 +2567,10 @@ public boolean updateUserStoragePreference( try { return registryService.updateUserStoragePreference(userId, gatewayID, userStorageId, userStoragePreference); } catch (RegistryServiceException e) { - logger.error("Error while updating user data storage preference", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while updating user data storage preference. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while updating user data storage preference: " + userId + " " + gatewayID + " " + + userStorageId + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3149,14 +2579,10 @@ public boolean deleteUserComputeResourcePreference(String userId, String gateway try { return registryService.deleteUserComputeResourcePreference(userId, gatewayID, userComputeResourceId); } catch (Throwable e) { - logger.error(userId, "Error while deleting user compute resource preference...", e); - logger.error("Error while deleting user compute resource preference", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while deleting user compute resource preference. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while deleting user compute resource preference: " + userId + " " + gatewayID + " " + + userComputeResourceId + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3165,12 +2591,10 @@ public boolean deleteUserStoragePreference(String userId, String gatewayID, Stri try { return registryService.deleteUserStoragePreference(userId, gatewayID, userStorageId); } catch (RegistryServiceException e) { - logger.error("Error while deleting user data storage preference", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while deleting user data storage preference. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while deleting user data storage preference: " + userId + " " + gatewayID + " " + + userStorageId + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3178,14 +2602,9 @@ public List getLatestQueueStatuses() throws AiravataSystemExce try { return registryService.getLatestQueueStatuses(); } catch (Throwable e) { - var msg = "Error in retrieving queue statuses"; - logger.error(msg, e); + String msg = "Error in retrieving queue statuses: " + e.getMessage(); logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + ". More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3193,12 +2612,10 @@ public String createGroupResourceProfile(GroupResourceProfile groupResourceProfi try { return registryService.createGroupResourceProfile(groupResourceProfile); } catch (RegistryServiceException e) { - logger.error("Error while creating group resource profile", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while creating group resource profile. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while creating group resource profile: " + + groupResourceProfile.getGroupResourceProfileId() + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3206,12 +2623,10 @@ public boolean removeGroupResourceProfile(String groupResourceProfileId) throws try { return registryService.removeGroupResourceProfile(groupResourceProfileId); } catch (RegistryServiceException e) { - logger.error("Error while removing group resource profile", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while removing group resource profile. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = + "Error while removing group resource profile: " + groupResourceProfileId + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3220,12 +2635,10 @@ public boolean removeGroupComputePrefs(String computeResourceId, String groupRes try { return registryService.removeGroupComputePrefs(computeResourceId, groupResourceProfileId); } catch (RegistryServiceException e) { - logger.error("Error while removing group compute preferences", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while removing group compute preferences. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while removing group compute preferences: " + computeResourceId + " " + + groupResourceProfileId + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3234,13 +2647,10 @@ public GroupComputeResourcePreference getGroupComputeResourcePreference( try { return registryService.getGroupComputeResourcePreference(computeResourceId, groupResourceProfileId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving group compute resource preference", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while retrieving group compute resource preference. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving group compute resource preference: " + computeResourceId + " " + + groupResourceProfileId + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3248,12 +2658,10 @@ public ComputeResourcePolicy getGroupComputeResourcePolicy(String resourcePolicy try { return registryService.getGroupComputeResourcePolicy(resourcePolicyId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving group compute resource policy", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving group compute resource policy. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = + "Error while retrieving group compute resource policy: " + resourcePolicyId + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3261,12 +2669,10 @@ public boolean removeGroupComputeResourcePolicy(String resourcePolicyId) throws try { return registryService.removeGroupComputeResourcePolicy(resourcePolicyId); } catch (RegistryServiceException e) { - logger.error("Error while removing group compute resource policy", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while removing group compute resource policy. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = + "Error while removing group compute resource policy: " + resourcePolicyId + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3275,12 +2681,10 @@ public BatchQueueResourcePolicy getBatchQueueResourcePolicy(String resourcePolic try { return registryService.getBatchQueueResourcePolicy(resourcePolicyId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving batch queue resource policy", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving batch queue resource policy. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = + "Error while retrieving batch queue resource policy: " + resourcePolicyId + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3288,13 +2692,10 @@ public boolean removeGroupBatchQueueResourcePolicy(String resourcePolicyId) thro try { return registryService.removeGroupBatchQueueResourcePolicy(resourcePolicyId); } catch (RegistryServiceException e) { - logger.error("Error while removing group batch queue resource policy", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while removing group batch queue resource policy. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while removing group batch queue resource policy: " + resourcePolicyId + " " + + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3303,13 +2704,10 @@ public List getGroupComputeResourcePrefList(Stri try { return registryService.getGroupComputeResourcePrefList(groupResourceProfileId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving group compute resource preference list", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while retrieving group compute resource preference list. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving group compute resource preference list: " + groupResourceProfileId + + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3318,13 +2716,10 @@ public List getGroupBatchQueueResourcePolicyList(Strin try { return registryService.getGroupBatchQueueResourcePolicyList(groupResourceProfileId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving group batch queue resource policy list", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while retrieving group batch queue resource policy list. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving group batch queue resource policy list: " + groupResourceProfileId + + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3333,13 +2728,10 @@ public List getGroupComputeResourcePolicyList(String grou try { return registryService.getGroupComputeResourcePolicyList(groupResourceProfileId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving group compute resource policy list", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while retrieving group compute resource policy list. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving group compute resource policy list: " + groupResourceProfileId + " " + + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3347,12 +2739,9 @@ public Parser getParser(String parserId, String gatewayId) throws AiravataSystem try { return registryService.getParser(parserId, gatewayId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving parser", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving parser. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving parser: " + parserId + " " + gatewayId + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3360,12 +2749,10 @@ public String saveParser(Parser parser) throws AiravataSystemException { try { return registryService.saveParser(parser); } catch (RegistryServiceException e) { - logger.error("Error while saving parser", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while saving parser. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = + "Error while saving parser: " + parser.getId() + " " + parser.getGatewayId() + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3373,12 +2760,9 @@ public List listAllParsers(String gatewayId) throws AiravataSystemExcept try { return registryService.listAllParsers(gatewayId); } catch (RegistryServiceException e) { - logger.error("Error while listing all parsers", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while listing all parsers. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while listing all parsers: " + gatewayId + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3386,12 +2770,9 @@ public void removeParser(String parserId, String gatewayId) throws AiravataSyste try { registryService.removeParser(parserId, gatewayId); } catch (RegistryServiceException e) { - logger.error("Error while removing parser", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while removing parser. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while removing parser: " + parserId + " " + gatewayId + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3399,12 +2780,10 @@ public ParsingTemplate getParsingTemplate(String templateId, String gatewayId) t try { return registryService.getParsingTemplate(templateId, gatewayId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving parsing template", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving parsing template. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = + "Error while retrieving parsing template: " + templateId + " " + gatewayId + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3413,13 +2792,10 @@ public List getParsingTemplatesForExperiment(String experimentI try { return registryService.getParsingTemplatesForExperiment(experimentId, gatewayId); } catch (RegistryServiceException e) { - logger.error("Error while retrieving parsing templates for experiment", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error while retrieving parsing templates for experiment. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving parsing templates for experiment: " + experimentId + " " + gatewayId + + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3427,12 +2803,10 @@ public String saveParsingTemplate(ParsingTemplate parsingTemplate) throws Airava try { return registryService.saveParsingTemplate(parsingTemplate); } catch (RegistryServiceException e) { - logger.error("Error while saving parsing template", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while saving parsing template. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while saving parsing template: " + parsingTemplate.getId() + " " + + parsingTemplate.getGatewayId() + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3440,12 +2814,10 @@ public void removeParsingTemplate(String templateId, String gatewayId) throws Ai try { registryService.removeParsingTemplate(templateId, gatewayId); } catch (RegistryServiceException e) { - logger.error("Error while removing parsing template", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while removing parsing template. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = + "Error while removing parsing template: " + templateId + " " + gatewayId + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3453,12 +2825,9 @@ public List listAllParsingTemplates(String gatewayId) throws Ai try { return registryService.listAllParsingTemplates(gatewayId); } catch (RegistryServiceException e) { - logger.error("Error while listing all parsing templates", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while listing all parsing templates. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while listing all parsing templates: " + gatewayId + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3476,7 +2845,8 @@ public GatewayGroups retrieveGatewayGroups(String gatewayId) throws AiravataSyst } public void createManageSharingPermissionTypeIfMissing(String domainId) throws AiravataSystemException { - // AIRAVATA-3297 Some gateways were created without the MANAGE_SHARING permission, so add it if missing + // AIRAVATA-3297 Some gateways were created without the MANAGE_SHARING + // permission, so add it if missing var permissionTypeId = domainId + ":MANAGE_SHARING"; try { if (!sharingRegistryService.isPermissionExists(domainId, permissionTypeId)) { @@ -3489,11 +2859,9 @@ public void createManageSharingPermissionTypeIfMissing(String domainId) throws A logger.info("Created MANAGE_SHARING permission type for domain " + domainId); } } catch (Exception e) { - var exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error creating MANAGE_SHARING permission type. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error creating MANAGE_SHARING permission type: " + domainId + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3523,8 +2891,8 @@ public void shareEntityWithAdminGatewayGroups(Entity entity) true); } - public boolean userHasAccessInternal( - AuthzToken authzToken, String entityId, ResourcePermissionType permissionType) { + public boolean userHasAccess(AuthzToken authzToken, String entityId, ResourcePermissionType permissionType) + throws AiravataSystemException { final String domainId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); final String userId = authzToken.getClaimsMap().get(Constants.USER_NAME) + "@" + domainId; try { @@ -3548,7 +2916,10 @@ public boolean userHasAccessInternal( } return hasAccess; } catch (Exception e) { - throw new RuntimeException("Unable to check if user has access", e); + String msg = "Error while checking if user has access: " + entityId + " " + permissionType + " " + + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3572,28 +2943,20 @@ public String generateAndRegisterSSHKeys(String gatewayId, String userName, Stri entity.setDescription(description); sharingRegistryService.createEntity(entity); } catch (Exception ex) { - logger.error(ex.getMessage(), ex); - logger.error("Rolling back ssh key creation for user " + userName + " and description [" + description - + "]"); + String msg = "Error while creating SSH credential: " + userName + " " + description + " " + + ex.getMessage() + ". rolling back ssh key creation"; + logger.error(msg, ex); credentialStoreService.deleteSSHCredential(key, gatewayId); - logger.error("Failed to create sharing registry record", ex); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Failed to create sharing registry record. More info : " + ex.getMessage()); - exception.initCause(ex); - throw exception; + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, ex); } logger.debug("Airavata generated SSH keys for gateway : " + gatewayId + " and for user : " + userName); return key; } catch (AiravataSystemException e) { throw e; } catch (CredentialStoreException e) { - logger.error("Error occurred while registering SSH Credential", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while registering SSH Credential. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error occurred while registering SSH Credential: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3618,58 +2981,47 @@ public String registerPwdCredential( entity.setDescription(description); sharingRegistryService.createEntity(entity); } catch (Exception ex) { - logger.error(ex.getMessage(), ex); - logger.error("Rolling back password registration for user " + userName + " and description [" - + description + "]"); + String msg = "Error while registering password credential: " + userName + " " + description + " " + + ex.getMessage() + ". rolling back password registration"; + logger.error(msg, ex); try { deletePWDCredential(key, gatewayId); } catch (Exception rollbackEx) { logger.error("Failed to rollback password credential deletion", rollbackEx); } - logger.error("Failed to create sharing registry record", ex); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Failed to create sharing registry record. More info : " + ex.getMessage()); - exception.initCause(ex); - throw exception; + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, ex); } - logger.debug("Airavata generated PWD credential for gateway : " + gatewayId + " and for user : " - + loginUserName); + logger.debug("Generated PWD credential for gateway: " + gatewayId + ", user: " + loginUserName); return key; } catch (AiravataSystemException e) { throw e; } catch (CredentialStoreException e) { - logger.error("Error occurred while registering password credential", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while registering password credential. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error occurred while registering password credential: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } - public CredentialSummary getCredentialSummaryWithAuth(AuthzToken authzToken, String tokenId, String gatewayId) + public CredentialSummary getCredentialSummary(AuthzToken authzToken, String tokenId, String gatewayId) throws AiravataSystemException, AuthorizationException { try { - if (!userHasAccessInternal(authzToken, tokenId, ResourcePermissionType.READ)) { + if (!userHasAccess(authzToken, tokenId, ResourcePermissionType.READ)) { throw new AuthorizationException("User does not have permission to access this resource"); } var credentialSummary = getCredentialSummary(tokenId, gatewayId); - logger.debug("Airavata retrived the credential summary for token " + tokenId + "GatewayId: " + gatewayId); + logger.debug("Retrieved the credential summary for token: " + tokenId + ", GatewayId: " + gatewayId); return credentialSummary; } catch (AuthorizationException e) { throw e; } catch (CredentialStoreException e) { - logger.error("Error occurred while getting credential summary", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while getting credential summary. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error occurred while getting credential summary: " + tokenId + " " + gatewayId + " " + + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } - public List getAllCredentialSummariesWithAuth( + public List getAllCredentialSummaries( AuthzToken authzToken, SummaryType type, String gatewayId, String userName) throws AiravataSystemException, InvalidRequestException { try { @@ -3687,67 +3039,59 @@ public List getAllCredentialSummariesWithAuth( .collect(Collectors.toList()); List credentialSummaries = getAllCredentialSummaries(type, accessibleTokenIds, gatewayId); - logger.debug( - "Airavata successfully retrived credential summaries of type " + type + " GatewayId: " + gatewayId); + logger.debug("Successfully retrieved credential summaries of type: " + type + ", GatewayId: " + gatewayId); return credentialSummaries; } catch (CredentialStoreException | SharingRegistryException e) { - logger.error("Error occurred while getting all credential summaries", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error occurred while getting all credential summaries. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error occurred while getting all credential summaries: " + type + " " + gatewayId + " " + + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } public boolean deleteSSHPubKey(AuthzToken authzToken, String airavataCredStoreToken, String gatewayId) throws AiravataSystemException, AuthorizationException { try { - if (!userHasAccessInternal(authzToken, airavataCredStoreToken, ResourcePermissionType.WRITE)) { + if (!userHasAccess(authzToken, airavataCredStoreToken, ResourcePermissionType.WRITE)) { throw new AuthorizationException("User does not have permission to delete this resource."); } - logger.debug("Airavata deleted SSH pub key for gateway Id : " + gatewayId + " and with token id : " + logger.debug("Deleted SSH pub key for gateway Id : " + gatewayId + " and with token id : " + airavataCredStoreToken); return deleteSSHCredential(airavataCredStoreToken, gatewayId); } catch (AuthorizationException e) { throw e; } catch (CredentialStoreException e) { - logger.error("Error occurred while deleting SSH pub key", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while deleting SSH pub key. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error occurred while deleting SSH pub key: " + airavataCredStoreToken + " " + gatewayId + " " + + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } - public boolean deletePWDCredentialWithAuth(AuthzToken authzToken, String airavataCredStoreToken, String gatewayId) + public boolean deletePWDCredential(AuthzToken authzToken, String airavataCredStoreToken, String gatewayId) throws AiravataSystemException, AuthorizationException { try { - if (!userHasAccessInternal(authzToken, airavataCredStoreToken, ResourcePermissionType.WRITE)) { + if (!userHasAccess(authzToken, airavataCredStoreToken, ResourcePermissionType.WRITE)) { throw new AuthorizationException("User does not have permission to delete this resource."); } - logger.debug("Airavata deleted PWD credential for gateway Id : " + gatewayId + " and with token id : " + logger.debug("Deleted PWD credential for gateway Id : " + gatewayId + " and with token id : " + airavataCredStoreToken); deletePWDCredential(airavataCredStoreToken, gatewayId); return true; } catch (AuthorizationException e) { throw e; } catch (CredentialStoreException e) { - logger.error("Error occurred while deleting PWD credential", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while deleting PWD credential. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error occurred while deleting PWD credential: " + airavataCredStoreToken + " " + gatewayId + + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } // Project management methods with sharing registry integration - public String createProjectWithSharing(String gatewayId, Project project) throws AiravataSystemException { + public String createProject(String gatewayId, Project project) throws AiravataSystemException { try { - var projectId = createProject(gatewayId, project); + var projectId = registryService.createProject(gatewayId, project); // TODO: verify that gatewayId and project.gatewayId match authzToken if (ServerSettings.isEnableSharing()) { try { @@ -3768,30 +3112,25 @@ public String createProjectWithSharing(String gatewayId, Project project) throws } catch (ProjectNotFoundException e) { // Ignore - project may not exist if creation failed } - logger.error("Failed to create entry for project in Sharing Registry", ex); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Failed to create entry for project in Sharing Registry. More info : " + ex.getMessage()); - exception.initCause(ex); - throw exception; + String msg = + "Failed to create entry for project in Sharing Registry. More info : " + ex.getMessage(); + logger.error(msg, ex); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, ex); } } logger.debug("Airavata created project with project Id : " + projectId + " for gateway Id : " + gatewayId); return projectId; } catch (AiravataSystemException e) { throw e; - } catch (ApplicationSettingsException e) { - logger.error("Error occurred while creating project", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while creating project. More info: " + e.getMessage()); - exception.initCause(e); - throw exception; + } catch (ApplicationSettingsException | RegistryServiceException e) { + String msg = "Error occurred while creating project: " + project.getName() + " " + project.getDescription() + + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } - public void updateProjectWithAuth(AuthzToken authzToken, String projectId, Project updatedProject) + public void updateProject(AuthzToken authzToken, String projectId, Project updatedProject) throws InvalidRequestException, AiravataSystemException, ProjectNotFoundException, AuthorizationException { try { var existingProject = getProject(projectId); @@ -3815,30 +3154,21 @@ public void updateProjectWithAuth(AuthzToken authzToken, String projectId, Proje throw new InvalidRequestException("Gateway ID of a project cannot be changed"); } updateProject(projectId, updatedProject); - logger.debug("Airavata updated project with project Id : " + projectId); + logger.debug("Updated project with project Id : " + projectId); } catch (ProjectNotFoundException | AuthorizationException | InvalidRequestException | AiravataSystemException e) { throw e; - } catch (ApplicationSettingsException e) { - logger.error("Error occurred while updating project", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while updating project. More info: " + e.getMessage()); - exception.initCause(e); - throw exception; - } catch (SharingRegistryException e) { - logger.error("Error occurred while updating project", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while updating project. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + } catch (ApplicationSettingsException | SharingRegistryException e) { + String msg = "Error occurred while updating project: " + projectId + " " + updatedProject.getName() + " " + + updatedProject.getDescription() + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } - public boolean deleteProjectWithAuth(AuthzToken authzToken, String projectId) + public boolean deleteProject(AuthzToken authzToken, String projectId) throws AiravataSystemException, ProjectNotFoundException, AuthorizationException { try { var existingProject = getProject(projectId); @@ -3860,24 +3190,14 @@ public boolean deleteProjectWithAuth(AuthzToken authzToken, String projectId) return ret; } catch (ProjectNotFoundException | AuthorizationException | AiravataSystemException e) { throw e; - } catch (ApplicationSettingsException e) { - logger.error("Error occurred while deleting project", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while deleting project. More info: " + e.getMessage()); - exception.initCause(e); - throw exception; - } catch (SharingRegistryException e) { - logger.error("Error occurred while deleting project", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while deleting project. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + } catch (ApplicationSettingsException | SharingRegistryException e) { + String msg = "Error occurred while deleting project: " + projectId + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } - public Project getProjectWithAuth(AuthzToken authzToken, String projectId) + public Project getProject(AuthzToken authzToken, String projectId) throws AiravataSystemException, ProjectNotFoundException, AuthorizationException { try { var project = getProject(projectId); @@ -3897,29 +3217,17 @@ public Project getProjectWithAuth(AuthzToken authzToken, String projectId) } } catch (ProjectNotFoundException | AuthorizationException | AiravataSystemException e) { throw e; - } catch (ApplicationSettingsException e) { - logger.error("Error occurred while getting project", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while getting project. More info: " + e.getMessage()); - exception.initCause(e); - throw exception; - } catch (SharingRegistryException e) { - logger.error("Error occurred while getting project", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while getting project. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + } catch (ApplicationSettingsException | SharingRegistryException e) { + String msg = "Error occurred while getting project: " + projectId + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } // Experiment management methods with sharing registry integration - public String createExperimentWithSharing(String gatewayId, ExperimentModel experiment) - throws AiravataSystemException { + public String createExperiment(String gatewayId, ExperimentModel experiment) throws AiravataSystemException { try { - var experimentId = createExperiment(gatewayId, experiment); - + var experimentId = createExperimentInternal(gatewayId, experiment); if (ServerSettings.isEnableSharing()) { try { var entity = new Entity(); @@ -3938,11 +3246,10 @@ public String createExperimentWithSharing(String gatewayId, ExperimentModel expe logger.error(ex.getMessage(), ex); logger.error("Rolling back experiment creation Exp ID : " + experimentId); deleteExperiment(experimentId); - var exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Failed to create sharing registry record. " + ex.getMessage()); - exception.initCause(ex); - throw exception; + throw airavataSystemException( + AiravataErrorType.INTERNAL_ERROR, + "Failed to create sharing registry record. " + ex.getMessage(), + ex); } } @@ -3954,41 +3261,11 @@ public String createExperimentWithSharing(String gatewayId, ExperimentModel expe return experimentId; } catch (AiravataSystemException e) { throw e; - } catch (ApplicationSettingsException e) { - logger.error("Error occurred while creating experiment", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while creating experiment. More info: " + e.getMessage()); - exception.initCause(e); - throw exception; - } - } - - public String createExperimentWithSharingAndPublish( - Publisher statusPublisher, String gatewayId, ExperimentModel experiment) - throws InvalidRequestException, AiravataSystemException, AuthorizationException { - try { - logger.info("Api server accepted experiment creation with name {}", experiment.getExperimentName()); - var experimentId = createExperimentWithSharing(gatewayId, experiment); - - if (statusPublisher != null) { - var event = new ExperimentStatusChangeEvent(ExperimentState.CREATED, experimentId, gatewayId); - var messageId = AiravataUtils.getId("EXPERIMENT"); - var messageContext = new MessageContext(event, MessageType.EXPERIMENT, messageId, gatewayId); - messageContext.setUpdatedTime(AiravataUtils.getCurrentTimestamp()); - statusPublisher.publish(messageContext); - } - - return experimentId; - } catch (AiravataSystemException e) { - throw e; } catch (Throwable e) { - logger.error("Error while creating the experiment", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while creating the experiment. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error occurred while creating experiment: " + experiment.getExperimentName() + " " + + experiment.getExperimentId() + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -3996,7 +3273,8 @@ public void validateLaunchExperimentAccess(AuthzToken authzToken, String gateway throws InvalidRequestException, AuthorizationException, AiravataSystemException, SharingRegistryException { String username = authzToken.getClaimsMap().get(Constants.USER_NAME); - // For backwards compatibility, if there is no groupResourceProfileId, look up one that is shared with the user + // For backwards compatibility, if there is no groupResourceProfileId, look up + // one that is shared with the user if (!experiment.getUserConfigurationData().isSetGroupResourceProfileId()) { // This will be handled by the handler calling getGroupResourceList throw new InvalidRequestException("Experiment doesn't have groupResourceProfileId"); @@ -4097,20 +3375,10 @@ public boolean deleteExperimentWithAuth(AuthzToken authzToken, String experiment return deleteExperiment(experimentId); } catch (AuthorizationException | InvalidRequestException | AiravataSystemException e) { throw e; - } catch (ApplicationSettingsException e) { - logger.error("Error occurred while deleting experiment", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while deleting experiment. More info: " + e.getMessage()); - exception.initCause(e); - throw exception; - } catch (SharingRegistryException e) { - logger.error("Error occurred while deleting experiment", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while deleting experiment. More info: " + e.getMessage()); - exception.initCause(e); - throw exception; + } catch (ApplicationSettingsException | SharingRegistryException e) { + String msg = "Error occurred while deleting experiment: " + experimentId + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -4124,17 +3392,14 @@ public ResourceType getResourceType(String domainId, String entityId) throws Air } throw new RuntimeException("Unrecognized entity type id: " + entity.getEntityTypeId()); } catch (SharingRegistryException e) { - logger.error("Error while getting resource type", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while getting resource type. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while getting resource type: " + domainId + " " + entityId + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } // Gateway management methods with sharing registry integration - public String addGatewayWithSharing(Gateway gateway) throws AiravataSystemException { + public String addGateway(Gateway gateway) throws AiravataSystemException { try { var gatewayId = registryService.addGateway(gateway); Domain domain = new Domain(); @@ -4201,37 +3466,33 @@ public String addGatewayWithSharing(Gateway gateway) throws AiravataSystemExcept permissionType.setDescription("Sharing permission type"); sharingRegistryService.createPermissionType(permissionType); - logger.debug("Airavata successfully created the gateway with " + gatewayId); + logger.debug("Successfully created the gateway with " + gatewayId); return gatewayId; - } catch (RegistryServiceException e) { - logger.error("Error while adding gateway", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding gateway. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; - } catch (SharingRegistryException | DuplicateEntryException e) { - logger.error("Error while adding gateway", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while adding gateway. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + } catch (RegistryServiceException | SharingRegistryException | DuplicateEntryException e) { + String msg = "Error while adding gateway: " + gateway.getGatewayId() + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } // Event publishing methods public void publishExperimentSubmitEvent(Publisher experimentPublisher, String gatewayId, String experimentId) - throws Exception { + throws AiravataSystemException { var event = new ExperimentSubmitEvent(experimentId, gatewayId); var messageContext = new MessageContext( event, MessageType.EXPERIMENT, "LAUNCH.EXP-" + UUID.randomUUID().toString(), gatewayId); messageContext.setUpdatedTime(AiravataUtils.getCurrentTimestamp()); - experimentPublisher.publish(messageContext); + try { + experimentPublisher.publish(messageContext); + } catch (AiravataException e) { + String msg = "Error while publishing experiment submit event: " + experimentId + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); + } } public void publishExperimentCancelEvent(Publisher experimentPublisher, String gatewayId, String experimentId) - throws Exception { + throws AiravataSystemException { var event = new ExperimentSubmitEvent(experimentId, gatewayId); var messageContext = new MessageContext( event, @@ -4239,12 +3500,18 @@ public void publishExperimentCancelEvent(Publisher experimentPublisher, String g "CANCEL.EXP-" + UUID.randomUUID().toString(), gatewayId); messageContext.setUpdatedTime(AiravataUtils.getCurrentTimestamp()); - experimentPublisher.publish(messageContext); + try { + experimentPublisher.publish(messageContext); + } catch (AiravataException e) { + String msg = "Error while publishing experiment cancel event: " + experimentId + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); + } } public void publishExperimentIntermediateOutputsEvent( Publisher experimentPublisher, String gatewayId, String experimentId, List outputNames) - throws Exception { + throws AiravataSystemException { var event = new ExperimentIntermediateOutputsEvent(experimentId, gatewayId, outputNames); var messageContext = new MessageContext( event, @@ -4252,19 +3519,25 @@ public void publishExperimentIntermediateOutputsEvent( "INTERMEDIATE_OUTPUTS.EXP-" + UUID.randomUUID().toString(), gatewayId); messageContext.setUpdatedTime(AiravataUtils.getCurrentTimestamp()); - experimentPublisher.publish(messageContext); + try { + experimentPublisher.publish(messageContext); + } catch (AiravataException e) { + String msg = "Error while publishing experiment intermediate outputs event: " + experimentId + " " + + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); + } } /** - * Validate and fetch intermediate outputs - checks access, job state, and existing processes + * Validate and fetch intermediate outputs - checks access, job state, and + * existing processes */ - public void validateAndFetchIntermediateOutputs( - AuthzToken authzToken, String airavataExperimentId, List outputNames, Publisher experimentPublisher) + public void fetchIntermediateOutputs(AuthzToken authzToken, String airavataExperimentId, List outputNames) throws InvalidRequestException, AiravataSystemException, AuthorizationException { try { // Verify that user has WRITE access to experiment - final boolean hasAccess = - userHasAccessInternal(authzToken, airavataExperimentId, ResourcePermissionType.WRITE); + final boolean hasAccess = userHasAccess(authzToken, airavataExperimentId, ResourcePermissionType.WRITE); if (!hasAccess) { var msg = "User does not have WRITE access to this experiment"; logger.error(msg); @@ -4287,7 +3560,8 @@ public void validateAndFetchIntermediateOutputs( throw new InvalidRequestException(msg); } - // Figure out if there are any currently running intermediate output fetching processes for outputNames + // Figure out if there are any currently running intermediate output fetching + // processes for outputNames // First, find any existing intermediate output fetch processes for outputNames List intermediateOutputFetchProcesses = existingExperiment.getProcesses().stream() .filter(p -> { @@ -4320,28 +3594,23 @@ public void validateAndFetchIntermediateOutputs( } catch (AuthorizationException | InvalidRequestException e) { throw e; } catch (Throwable e) { - logger.error( - "Error while processing request to fetch intermediate outputs for experiment: " - + airavataExperimentId, - e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while processing request to fetch intermediate outputs for experiment: " + + airavataExperimentId + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } /** - * Get intermediate output process status - finds the most recent matching process and returns its status + * Get intermediate output process status - finds the most recent matching + * process and returns its status */ - public ProcessStatus getIntermediateOutputProcessStatusInternal( + public ProcessStatus getIntermediateOutputProcessStatus( AuthzToken authzToken, String airavataExperimentId, List outputNames) throws InvalidRequestException, AiravataSystemException, AuthorizationException { try { // Verify that user has READ access to experiment - final boolean hasAccess = - userHasAccessInternal(authzToken, airavataExperimentId, ResourcePermissionType.READ); + final boolean hasAccess = userHasAccess(authzToken, airavataExperimentId, ResourcePermissionType.READ); if (!hasAccess) { var msg = "User does not have READ access to this experiment"; logger.debug(msg); @@ -4385,16 +3654,10 @@ public ProcessStatus getIntermediateOutputProcessStatusInternal( } catch (AuthorizationException | InvalidRequestException e) { throw e; } catch (Throwable e) { - logger.error( - "Error while processing request to get intermediate output process status for experiment: " - + airavataExperimentId, - e); - logger.error("Error occurred", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while processing request to get intermediate output process status for experiment: " + + airavataExperimentId + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -4449,7 +3712,7 @@ public List getAllAccessibleGroups( /** * Get all accessible users for a resource (includes shared and directly shared) */ - public List getAllAccessibleUsersWithSharing( + public List getAllAccessibleUsers( AuthzToken authzToken, String resourceId, ResourcePermissionType permissionType, boolean directlySharedOnly) throws AiravataSystemException { try { @@ -4474,19 +3737,17 @@ public List getAllAccessibleUsersWithSharing( } return getAllAccessibleUsers(gatewayId, resourceId, permissionType, userListFunction); } catch (Exception e) { - logger.error("Error occurred while getting all accessible users", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while getting all accessible users. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error occurred while getting all accessible users: " + resourceId + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } /** - * Get all accessible groups for a resource (includes shared and directly shared) + * Get all accessible groups for a resource (includes shared and directly + * shared) */ - public List getAllAccessibleGroupsWithSharing( + public List getAllAccessibleGroups( AuthzToken authzToken, String resourceId, ResourcePermissionType permissionType, boolean directlySharedOnly) throws AiravataSystemException { try { @@ -4511,12 +3772,9 @@ public List getAllAccessibleGroupsWithSharing( } return getAllAccessibleGroups(gatewayId, resourceId, permissionType, groupListFunction); } catch (Exception e) { - logger.error("Error occurred while getting all accessible groups", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while getting all accessible groups. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error occurred while getting all accessible groups: " + resourceId + " " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -4545,22 +3803,24 @@ public String createGroupResourceProfileWithSharing( | InvalidRequestException | AuthorizationException | ApplicationSettingsException ex) { - logger.error(ex.getMessage(), ex); - logger.error("Rolling back group resource profile creation Group Resource Profile ID : " - + groupResourceProfileId); + String msg = "Error while creating group resource profile: " + groupResourceProfileId + " " + + ex.getMessage() + ". Rolling back group resource profile creation."; + logger.error(msg, ex); try { removeGroupResourceProfile(groupResourceProfileId); } catch (Throwable rollbackEx) { - logger.error("Failed to rollback group resource profile deletion", rollbackEx); + String rollbackMsg = "Failed to rollback group resource profile creation: " + groupResourceProfileId + + " " + rollbackEx.getMessage(); + logger.error(rollbackMsg, rollbackEx); } - throw ex; + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, ex); } } return groupResourceProfileId; } public void validateGroupResourceProfile(AuthzToken authzToken, GroupResourceProfile groupResourceProfile) - throws AuthorizationException { + throws AuthorizationException, AiravataSystemException { Set tokenIds = new HashSet<>(); if (groupResourceProfile.getComputePreferences() != null) { for (GroupComputeResourcePreference groupComputeResourcePreference : @@ -4574,16 +3834,15 @@ public void validateGroupResourceProfile(AuthzToken authzToken, GroupResourcePro tokenIds.add(groupResourceProfile.getDefaultCredentialStoreToken()); } for (String tokenId : tokenIds) { - if (!userHasAccessInternal(authzToken, tokenId, ResourcePermissionType.READ)) { - throw new AuthorizationException( - "User does not have READ permission to credential token " + tokenId + "."); + if (!userHasAccess(authzToken, tokenId, ResourcePermissionType.READ)) { + String msg = "User does not have READ permission to credential token " + tokenId + "."; + throw new AuthorizationException(msg); } } } // Launch experiment business logic - public void launchExperimentWithValidation( - AuthzToken authzToken, String gatewayId, String airavataExperimentId, Publisher experimentPublisher) + public void launchExperiment(AuthzToken authzToken, String gatewayId, String airavataExperimentId) throws InvalidRequestException, AiravataSystemException, AuthorizationException, ExperimentNotFoundException, ProjectNotFoundException { try { @@ -4596,11 +3855,11 @@ public void launchExperimentWithValidation( } String username = authzToken.getClaimsMap().get(Constants.USER_NAME); - // For backwards compatibility, if there is no groupResourceProfileId, look up one that is shared with the + // For backwards compatibility, if there is no groupResourceProfileId, look up + // one that is shared with the // user if (!experiment.getUserConfigurationData().isSetGroupResourceProfileId()) { - List groupResourceProfiles = - getGroupResourceListWithSharing(authzToken, gatewayId); + List groupResourceProfiles = getGroupResourceList(authzToken, gatewayId); if (groupResourceProfiles != null && !groupResourceProfiles.isEmpty()) { // Just pick the first one final String groupResourceProfileId = @@ -4612,8 +3871,10 @@ public void launchExperimentWithValidation( experiment.getUserConfigurationData().setGroupResourceProfileId(groupResourceProfileId); updateExperimentConfiguration(airavataExperimentId, experiment.getUserConfigurationData()); } else { - throw new Exception("User " + username + " in gateway " + gatewayId - + " doesn't have access to any group resource profiles."); + String msg = "User " + username + " in gateway " + gatewayId + + " doesn't have access to any group resource profiles."; + logger.error(msg); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, null); } } @@ -4623,30 +3884,19 @@ public void launchExperimentWithValidation( } catch (InvalidRequestException | AiravataSystemException | AuthorizationException - | ExperimentNotFoundException - | ProjectNotFoundException e) { + | ExperimentNotFoundException e) { throw e; - } catch (RegistryException | AppCatalogException | CredentialStoreException | SharingRegistryException e) { - logger.error("Error launching experiment", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error launching experiment. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; } catch (Throwable e) { - logger.error("Error launching experiment", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error launching experiment. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error launching experiment: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } /** * Get group resource list with sharing registry integration */ - public List getGroupResourceListWithSharing(AuthzToken authzToken, String gatewayId) + public List getGroupResourceList(AuthzToken authzToken, String gatewayId) throws AiravataSystemException { try { String userName = authzToken.getClaimsMap().get(Constants.USER_NAME); @@ -4670,12 +3920,9 @@ public List getGroupResourceListWithSharing(AuthzToken aut } return getGroupResourceList(gatewayId, accessibleGroupResProfileIds); } catch (ApplicationSettingsException | SharingRegistryException e) { - logger.error("Error occurred while getting group resource list", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while getting group resource list. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error occurred while getting group resource list: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -4733,12 +3980,9 @@ public SSHCredential getSSHCredential(String token, String gatewayId) throws Air try { return credentialStoreService.getSSHCredential(token, gatewayId); } catch (CredentialStoreException e) { - logger.error("Error while retrieving SSH credential", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error while retrieving SSH credential. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error while retrieving SSH credential: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -4777,8 +4021,10 @@ public boolean deleteEntity(String domainId, String entityId) throws SharingRegi } /** - * Resolves compute resource storage info context (login username, credential token, and adaptor). - * Handles user preference → group preference fallback for both login and credentials. + * Resolves compute resource storage info context (login username, credential + * token, and adaptor). + * Handles user preference → group preference fallback for both login and + * credentials. */ private StorageInfoContext resolveComputeStorageInfoContext( AuthzToken authzToken, String gatewayId, String userId, String resourceId) @@ -4807,7 +4053,7 @@ private StorageInfoContext resolveComputeStorageInfoContext( } else { // Fallback to GroupComputeResourcePreference - var groupResourceProfiles = getGroupResourceListWithSharing(authzToken, gatewayId); + var groupResourceProfiles = getGroupResourceList(authzToken, gatewayId); for (GroupResourceProfile groupProfile : groupResourceProfiles) { List groupComputePrefs = groupProfile.getComputePreferences(); @@ -4839,7 +4085,8 @@ private StorageInfoContext resolveComputeStorageInfoContext( // Resolve credential token based on where login came from String credentialToken; if (loginFromUserPref) { - // Login username came from user preference. Use user preference token → user profile token + // Login username came from user preference. Use user preference token → user + // profile token if (userComputePref != null && userComputePref.getResourceSpecificCredentialStoreToken() != null && !userComputePref @@ -4852,15 +4099,15 @@ private StorageInfoContext resolveComputeStorageInfoContext( if (userResourceProfile == null || userResourceProfile.getCredentialStoreToken() == null || userResourceProfile.getCredentialStoreToken().trim().isEmpty()) { - logger.error("No credential store token found for user {} in gateway {}", userId, gatewayId); - throw airavataSystemException( - AiravataErrorType.AUTHENTICATION_FAILURE, - "No credential store token found for user " + userId + " in gateway " + gatewayId); + String msg = "No credential store token found for user " + userId + " in gateway " + gatewayId; + logger.error(msg); + throw airavataSystemException(AiravataErrorType.AUTHENTICATION_FAILURE, msg, null); } credentialToken = userResourceProfile.getCredentialStoreToken(); } } else { - // Login username came from group preference. Use group preference token → group profile default token → + // Login username came from group preference. Use group preference token → group + // profile default token → // user profile token (fallback) if (groupComputePref != null && groupComputePref.getResourceSpecificCredentialStoreToken() != null @@ -4883,10 +4130,9 @@ private StorageInfoContext resolveComputeStorageInfoContext( if (userResourceProfile == null || userResourceProfile.getCredentialStoreToken() == null || userResourceProfile.getCredentialStoreToken().trim().isEmpty()) { - logger.error("No credential store token found for user {} in gateway {}", userId, gatewayId); - throw airavataSystemException( - AiravataErrorType.AUTHENTICATION_FAILURE, - "No credential store token found for compute resource " + resourceId); + String msg = "No credential store token found for user " + userId + " in gateway " + gatewayId; + logger.error(msg); + throw airavataSystemException(AiravataErrorType.AUTHENTICATION_FAILURE, msg, null); } credentialToken = userResourceProfile.getCredentialStoreToken(); } @@ -4900,8 +4146,10 @@ private StorageInfoContext resolveComputeStorageInfoContext( } /** - * Resolves storage resource storage info context (login username, credential token, and adaptor). - * Handles user preference → gateway preference fallback for both login and credentials. + * Resolves storage resource storage info context (login username, credential + * token, and adaptor). + * Handles user preference → gateway preference fallback for both login and + * credentials. */ private StorageInfoContext resolveStorageStorageInfoContext( AuthzToken authzToken, String gatewayId, String userId, String resourceId) @@ -4951,7 +4199,8 @@ private StorageInfoContext resolveStorageStorageInfoContext( // Resolve credential token based on where login came from String credentialToken; if (loginFromUserPref) { - // Login came from user preference. Use user preference token or user profile token + // Login came from user preference. Use user preference token or user profile + // token if (userStoragePref != null && userStoragePref.getResourceSpecificCredentialStoreToken() != null && !userStoragePref @@ -4966,15 +4215,15 @@ private StorageInfoContext resolveStorageStorageInfoContext( if (userResourceProfile == null || userResourceProfile.getCredentialStoreToken() == null || userResourceProfile.getCredentialStoreToken().trim().isEmpty()) { - logger.error("No credential store token found for user {} in gateway {}", userId, gatewayId); - throw airavataSystemException( - AiravataErrorType.AUTHENTICATION_FAILURE, - "No credential store token found for user " + userId + " in gateway " + gatewayId); + String msg = "No credential store token found for user " + userId + " in gateway " + gatewayId; + logger.error(msg); + throw airavataSystemException(AiravataErrorType.AUTHENTICATION_FAILURE, msg, null); } credentialToken = userResourceProfile.getCredentialStoreToken(); } } else { - // Login came from gateway preference. Use gateway preference token or gateway profile token + // Login came from gateway preference. Use gateway preference token or gateway + // profile token if (storagePref != null && storagePref.getResourceSpecificCredentialStoreToken() != null && !storagePref @@ -4991,10 +4240,9 @@ private StorageInfoContext resolveStorageStorageInfoContext( .getCredentialStoreToken() .trim() .isEmpty()) { - logger.error("No credential store token found for gateway {}", gatewayId); - throw airavataSystemException( - AiravataErrorType.AUTHENTICATION_FAILURE, - "No credential store token found for gateway " + gatewayId); + String msg = "No credential store token found for gateway " + gatewayId; + logger.error(msg); + throw airavataSystemException(AiravataErrorType.AUTHENTICATION_FAILURE, msg, null); } credentialToken = gatewayResourceProfile.getCredentialStoreToken(); } @@ -5055,12 +4303,9 @@ public StorageVolumeInfo getResourceStorageInfo(AuthzToken authzToken, String re } catch (InvalidRequestException | AiravataSystemException | AuthorizationException e) { throw e; } catch (Throwable e) { - logger.error("Error occurred while getting resource storage info", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while getting resource storage info. More info: " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error occurred while getting resource storage info: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -5112,12 +4357,9 @@ public StorageDirectoryInfo getStorageDirectoryInfo(AuthzToken authzToken, Strin } catch (InvalidRequestException | AiravataSystemException | AuthorizationException e) { throw e; } catch (Throwable e) { - logger.error("Error occurred while getting storage directory info", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while getting storage directory info. More info: " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error occurred while getting storage directory info: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -5132,13 +4374,9 @@ public boolean doesUserHaveSSHAccount(AuthzToken authzToken, String computeResou gatewayId); return SSHAccountManager.doesUserHaveSSHAccount(gatewayId, computeResourceId, userId); } catch (Throwable e) { - logger.error("Error occurred while checking if user has an SSH Account", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error occurred while checking if user has an SSH Account. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error occurred while checking if user has an SSH Account: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -5157,13 +4395,9 @@ public boolean isSSHAccountSetupComplete( SSHCredential sshCredential = getSSHCredential(airavataCredStoreToken, gatewayId); return SSHAccountManager.isSSHAccountSetupComplete(gatewayId, computeResourceId, userId, sshCredential); } catch (Throwable e) { - logger.error("Error occurred while checking if setup of SSH account is complete", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage( - "Error occurred while checking if setup of SSH account is complete. More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error occurred while checking if setup of SSH account is complete: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -5183,13 +4417,9 @@ public UserComputeResourcePreference setupSSHAccount( } catch (AiravataSystemException e) { throw e; } catch (Throwable e) { - logger.error("Error occurred while automatically setting up SSH account for user", e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage("Error occurred while automatically setting up SSH account for user. More info : " - + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error occurred while automatically setting up SSH account for user: " + e.getMessage(); + logger.error(msg, e); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -5197,8 +4427,8 @@ public boolean shareResourceWithUsers( AuthzToken authzToken, String resourceId, Map userPermissionList) throws AuthorizationException, AiravataSystemException { try { - if (!userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.OWNER) - && !userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { + if (!userHasAccess(authzToken, resourceId, ResourcePermissionType.OWNER) + && !userHasAccess(authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { throw new AuthorizationException( "User is not allowed to change sharing because the user is either not the resource owner or does not have access to share the resource"); } @@ -5219,7 +4449,7 @@ public boolean shareResourceWithUsers( gatewayId + ":" + "READ", true); } else if (userPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING)) { - if (userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.OWNER)) { + if (userHasAccess(authzToken, resourceId, ResourcePermissionType.OWNER)) { createManageSharingPermissionTypeIfMissing(gatewayId); shareEntityWithUsers( gatewayId, @@ -5242,13 +4472,9 @@ public boolean shareResourceWithUsers( } catch (AuthorizationException e) { throw e; } catch (Throwable e) { - var msg = "Error in sharing resource with users. Resource ID : " + resourceId; + String msg = "Error in sharing resource with users. Resource ID : " + resourceId + ": " + e.getMessage(); logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + ". More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -5256,8 +4482,8 @@ public boolean shareResourceWithGroups( AuthzToken authzToken, String resourceId, Map groupPermissionList) throws AuthorizationException, AiravataSystemException { try { - if (!userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.OWNER) - && !userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { + if (!userHasAccess(authzToken, resourceId, ResourcePermissionType.OWNER) + && !userHasAccess(authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { throw new AuthorizationException( "User is not allowed to change sharing because the user is either not the resource owner or does not have access to share the resource"); } @@ -5278,7 +4504,7 @@ public boolean shareResourceWithGroups( gatewayId + ":" + "READ", true); } else if (groupPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING)) { - if (userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.OWNER)) { + if (userHasAccess(authzToken, resourceId, ResourcePermissionType.OWNER)) { createManageSharingPermissionTypeIfMissing(gatewayId); shareEntityWithGroups( gatewayId, @@ -5301,14 +4527,10 @@ public boolean shareResourceWithGroups( } catch (AuthorizationException e) { throw e; } catch (Throwable e) { - var msg = "Error in sharing resource with groups. Resource ID : " + resourceId; + var msg = "Error in sharing resource with groups. Resource ID : " + resourceId + ". More info : " + + e.getMessage(); logger.error(msg, e); - logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + ". More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -5316,8 +4538,8 @@ public boolean revokeSharingOfResourceFromUsers( AuthzToken authzToken, String resourceId, Map userPermissionList) throws AuthorizationException, AiravataSystemException, InvalidRequestException { try { - if (!userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.OWNER) - && !userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { + if (!userHasAccess(authzToken, resourceId, ResourcePermissionType.OWNER) + && !userHasAccess(authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { throw new AuthorizationException( "User is not allowed to change sharing because the user is either not the resource owner or does not have access to share the resource"); } @@ -5330,7 +4552,7 @@ public boolean revokeSharingOfResourceFromUsers( revokeEntitySharingFromUsers( gatewayId, resourceId, Arrays.asList(userPermission.getKey()), gatewayId + ":" + "READ"); } else if (userPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING)) { - if (userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.OWNER)) { + if (userHasAccess(authzToken, resourceId, ResourcePermissionType.OWNER)) { createManageSharingPermissionTypeIfMissing(gatewayId); revokeEntitySharingFromUsers( gatewayId, @@ -5354,11 +4576,7 @@ public boolean revokeSharingOfResourceFromUsers( } catch (Throwable e) { var msg = "Error in revoking access to resource from users. Resource ID : " + resourceId; logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + ". More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } @@ -5367,17 +4585,19 @@ public boolean revokeSharingOfResourceFromGroups( throws AuthorizationException, InvalidRequestException, AiravataSystemException { try { var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - if (!userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.OWNER) - && !userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { + if (!userHasAccess(authzToken, resourceId, ResourcePermissionType.OWNER) + && !userHasAccess(authzToken, resourceId, ResourcePermissionType.MANAGE_SHARING)) { throw new AuthorizationException( "User is not allowed to change sharing because the user is either not the resource owner or does not have access to share the resource"); } - // For certain resource types, restrict them from being unshared with admin groups + // For certain resource types, restrict them from being unshared with admin + // groups ResourceType resourceType = getResourceType(gatewayId, resourceId); Set adminRestrictedResourceTypes = new HashSet<>(Arrays.asList( ResourceType.EXPERIMENT, ResourceType.APPLICATION_DEPLOYMENT, ResourceType.GROUP_RESOURCE_PROFILE)); if (adminRestrictedResourceTypes.contains(resourceType)) { - // Prevent removing Admins WRITE/MANAGE_SHARING access and Read Only Admins READ access + // Prevent removing Admins WRITE/MANAGE_SHARING access and Read Only Admins READ + // access GatewayGroups gatewayGroups = retrieveGatewayGroups(gatewayId); if (groupPermissionList.containsKey(gatewayGroups.getAdminsGroupId()) && groupPermissionList @@ -5412,7 +4632,7 @@ public boolean revokeSharingOfResourceFromGroups( revokeEntitySharingFromGroups( gatewayId, resourceId, Arrays.asList(groupPermission.getKey()), gatewayId + ":" + "READ"); } else if (groupPermission.getValue().equals(ResourcePermissionType.MANAGE_SHARING)) { - if (userHasAccessInternal(authzToken, resourceId, ResourcePermissionType.OWNER)) { + if (userHasAccess(authzToken, resourceId, ResourcePermissionType.OWNER)) { createManageSharingPermissionTypeIfMissing(gatewayId); revokeEntitySharingFromGroups( gatewayId, @@ -5434,18 +4654,14 @@ public boolean revokeSharingOfResourceFromGroups( } catch (AuthorizationException | InvalidRequestException e) { throw e; } catch (Throwable e) { - var msg = "Error in revoking access to resource from groups. Resource ID : " + resourceId; - logger.error(msg, e); + String msg = "Error in revoking access to resource from groups. Resource ID : " + resourceId + + ". More info : " + e.getMessage(); logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + ". More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } - public GroupResourceProfile getGroupResourceProfileWithAuth(AuthzToken authzToken, String groupResourceProfileId) + public GroupResourceProfile getGroupResourceProfile(AuthzToken authzToken, String groupResourceProfileId) throws AuthorizationException, AiravataSystemException { try { if (ServerSettings.isEnableSharing()) { @@ -5457,22 +4673,16 @@ public GroupResourceProfile getGroupResourceProfileWithAuth(AuthzToken authzToke } return getGroupResourceProfile(groupResourceProfileId); } catch (AuthorizationException e) { - logger.error( - "Error while retrieving group resource profile. groupResourceProfileId: " + groupResourceProfileId, - e); throw e; } catch (Throwable e) { - var msg = "Error retrieving group resource profile. groupResourceProfileId: " + groupResourceProfileId; + String msg = "Error retrieving group resource profile. groupResourceProfileId: " + groupResourceProfileId + + ". More info : " + e.getMessage(); logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + ". More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } - public boolean removeGroupResourceProfileWithAuth(AuthzToken authzToken, String groupResourceProfileId) + public boolean removeGroupResourceProfile(AuthzToken authzToken, String groupResourceProfileId) throws AuthorizationException, AiravataSystemException { try { var gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); @@ -5492,16 +4702,11 @@ public boolean removeGroupResourceProfileWithAuth(AuthzToken authzToken, String } catch (Throwable e) { var msg = "Error removing group resource profile. groupResourceProfileId: " + groupResourceProfileId; logger.error(msg, e); - logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + ". More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } - public boolean removeGroupComputePrefsWithAuth( + public boolean removeGroupComputePrefs( AuthzToken authzToken, String computeResourceId, String groupResourceProfileId) throws AuthorizationException, AiravataSystemException { try { @@ -5517,18 +4722,14 @@ public boolean removeGroupComputePrefsWithAuth( } catch (AuthorizationException e) { throw e; } catch (Throwable e) { - var msg = "Error removing group compute preferences. GroupResourceProfileId: " + groupResourceProfileId; + var msg = "Error removing group compute preferences. GroupResourceProfileId: " + groupResourceProfileId + + ". More info : " + e.getMessage(); logger.error(msg, e); - logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + ". More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } - public boolean removeGroupComputeResourcePolicyWithAuth(AuthzToken authzToken, String resourcePolicyId) + public boolean removeGroupComputeResourcePolicy(AuthzToken authzToken, String resourcePolicyId) throws AuthorizationException, AiravataSystemException { try { if (ServerSettings.isEnableSharing()) { @@ -5548,18 +4749,14 @@ public boolean removeGroupComputeResourcePolicyWithAuth(AuthzToken authzToken, S } catch (AuthorizationException e) { throw e; } catch (Throwable e) { - var msg = "Error removing group compute resource policy. ResourcePolicyId: " + resourcePolicyId; - logger.error(msg, e); + String msg = "Error removing group compute resource policy. ResourcePolicyId: " + resourcePolicyId + + ". More info : " + e.getMessage(); logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + ". More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } - public boolean removeGroupBatchQueueResourcePolicyWithAuth(AuthzToken authzToken, String resourcePolicyId) + public boolean removeGroupBatchQueueResourcePolicy(AuthzToken authzToken, String resourcePolicyId) throws AuthorizationException, AiravataSystemException { try { if (ServerSettings.isEnableSharing()) { @@ -5579,18 +4776,14 @@ public boolean removeGroupBatchQueueResourcePolicyWithAuth(AuthzToken authzToken } catch (AuthorizationException e) { throw e; } catch (Throwable e) { - var msg = "Error removing batch queue resource policy. ResourcePolicyId: " + resourcePolicyId; + String msg = "Error removing batch queue resource policy. ResourcePolicyId: " + resourcePolicyId + + ". More info : " + e.getMessage(); logger.error(msg, e); - logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + ". More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } - public GroupComputeResourcePreference getGroupComputeResourcePreferenceWithAuth( + public GroupComputeResourcePreference getGroupComputeResourcePreference( AuthzToken authzToken, String computeResourceId, String groupResourceProfileId) throws AuthorizationException, AiravataSystemException, InvalidRequestException { try { @@ -5605,18 +4798,14 @@ public GroupComputeResourcePreference getGroupComputeResourcePreferenceWithAuth( } catch (AuthorizationException | AiravataSystemException e) { throw e; } catch (Throwable e) { - var msg = "Error retrieving Group compute preference. GroupResourceProfileId: " + groupResourceProfileId; - logger.error(msg, e); + String msg = "Error retrieving Group compute preference. GroupResourceProfileId: " + groupResourceProfileId + + ". More info : " + e.getMessage(); logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + ". More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } - public ComputeResourcePolicy getGroupComputeResourcePolicyWithAuth(AuthzToken authzToken, String resourcePolicyId) + public ComputeResourcePolicy getGroupComputeResourcePolicy(AuthzToken authzToken, String resourcePolicyId) throws AuthorizationException, AiravataSystemException { try { if (ServerSettings.isEnableSharing()) { @@ -5635,18 +4824,14 @@ public ComputeResourcePolicy getGroupComputeResourcePolicyWithAuth(AuthzToken au } catch (AuthorizationException e) { throw e; } catch (Throwable e) { - var msg = "Error retrieving Group compute resource policy. ResourcePolicyId: " + resourcePolicyId; + String msg = "Error retrieving Group compute resource policy. ResourcePolicyId: " + resourcePolicyId + + ". More info : " + e.getMessage(); logger.error(msg, e); - logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + ". More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } - public BatchQueueResourcePolicy getBatchQueueResourcePolicyWithAuth(AuthzToken authzToken, String resourcePolicyId) + public BatchQueueResourcePolicy getBatchQueueResourcePolicy(AuthzToken authzToken, String resourcePolicyId) throws AuthorizationException, AiravataSystemException { try { if (ServerSettings.isEnableSharing()) { @@ -5665,22 +4850,18 @@ public BatchQueueResourcePolicy getBatchQueueResourcePolicyWithAuth(AuthzToken a } catch (AuthorizationException e) { throw e; } catch (Throwable e) { - var msg = "Error retrieving batch queue resource policy. ResourcePolicyId: " + resourcePolicyId; - logger.error(msg, e); + String msg = "Error retrieving batch queue resource policy. ResourcePolicyId: " + resourcePolicyId + + ". More info : " + e.getMessage(); logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + ". More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } - public void updateGroupResourceProfileWithAuth(AuthzToken authzToken, GroupResourceProfile groupResourceProfile) + public void updateGroupResourceProfile(AuthzToken authzToken, GroupResourceProfile groupResourceProfile) throws AuthorizationException, AiravataSystemException { try { validateGroupResourceProfile(authzToken, groupResourceProfile); - if (!userHasAccessInternal( + if (!userHasAccess( authzToken, groupResourceProfile.getGroupResourceProfileId(), ResourcePermissionType.WRITE)) { throw new AuthorizationException("User does not have permission to update group resource profile"); } @@ -5691,19 +4872,14 @@ public void updateGroupResourceProfileWithAuth(AuthzToken authzToken, GroupResou + groupResourceProfile.getGroupResourceProfileId() + ", reason: " + e.getMessage()); throw e; } catch (Throwable e) { - var msg = "Error updating group resource profile. groupResourceProfileId: " - + groupResourceProfile.getGroupResourceProfileId(); - logger.error(msg, e); + String msg = "Error updating group resource profile. groupResourceProfileId: " + + groupResourceProfile.getGroupResourceProfileId() + ". More info : " + e.getMessage(); logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + ". More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } - public List getGroupComputeResourcePrefListWithAuth( + public List getGroupComputeResourcePrefList( AuthzToken authzToken, String groupResourceProfileId) throws AuthorizationException, AiravataSystemException { try { @@ -5718,19 +4894,14 @@ public List getGroupComputeResourcePrefListWithA } catch (AuthorizationException e) { throw e; } catch (Throwable e) { - var msg = "Error retrieving Group compute resource preference. GroupResourceProfileId: " - + groupResourceProfileId; - logger.error(msg, e); + String msg = "Error retrieving Group compute resource preference. GroupResourceProfileId: " + + groupResourceProfileId + ". More info : " + e.getMessage(); logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + ". More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } - public List getGroupBatchQueueResourcePolicyListWithAuth( + public List getGroupBatchQueueResourcePolicyList( AuthzToken authzToken, String groupResourceProfileId) throws AuthorizationException, AiravataSystemException { try { @@ -5745,19 +4916,14 @@ public List getGroupBatchQueueResourcePolicyListWithAu } catch (AuthorizationException e) { throw e; } catch (Throwable e) { - var msg = "Error retrieving Group batch queue resource policy list. GroupResourceProfileId: " - + groupResourceProfileId; + String msg = "Error retrieving Group batch queue resource policy list. GroupResourceProfileId: " + + groupResourceProfileId + ". More info : " + e.getMessage(); logger.error(msg, e); - logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + ". More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } - public List getGroupComputeResourcePolicyListWithAuth( + public List getGroupComputeResourcePolicyList( AuthzToken authzToken, String groupResourceProfileId) throws AuthorizationException, AiravataSystemException { try { @@ -5772,18 +4938,13 @@ public List getGroupComputeResourcePolicyListWithAuth( } catch (AuthorizationException e) { throw e; } catch (Throwable e) { - var msg = "Error retrieving Group compute resource policy list. GroupResourceProfileId: " - + groupResourceProfileId; - logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + ". More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + String msg = "Error retrieving Group compute resource policy list. GroupResourceProfileId: " + + groupResourceProfileId + ". More info : " + e.getMessage(); + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } - public String createGroupResourceProfileWithAuth(AuthzToken authzToken, GroupResourceProfile groupResourceProfile) + public String createGroupResourceProfile(AuthzToken authzToken, GroupResourceProfile groupResourceProfile) throws AuthorizationException, AiravataSystemException, InvalidRequestException { try { var result = createGroupResourceProfileWithSharing(authzToken, groupResourceProfile); @@ -5791,13 +4952,9 @@ public String createGroupResourceProfileWithAuth(AuthzToken authzToken, GroupRes } catch (AuthorizationException | AiravataSystemException | InvalidRequestException e) { throw e; } catch (Throwable e) { - var msg = "Error creating group resource profile."; + String msg = "Error creating group resource profile. More info : " + e.getMessage(); logger.error(msg, e); - AiravataSystemException exception = new AiravataSystemException(); - exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR); - exception.setMessage(msg + ". More info : " + e.getMessage()); - exception.initCause(e); - throw exception; + throw airavataSystemException(AiravataErrorType.INTERNAL_ERROR, msg, e); } } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/CredentialStoreService.java b/airavata-api/src/main/java/org/apache/airavata/service/CredentialStoreService.java index 6985f54abd..f15f649238 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/CredentialStoreService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/CredentialStoreService.java @@ -31,6 +31,7 @@ import org.apache.airavata.credential.store.credential.CommunityUser; import org.apache.airavata.credential.store.credential.Credential; import org.apache.airavata.credential.store.credential.CredentialOwnerType; +import org.apache.airavata.credential.store.exception.CredentialStoreException; import org.apache.airavata.credential.store.store.impl.CertificateCredentialWriter; import org.apache.airavata.credential.store.store.impl.CredentialReaderImpl; import org.apache.airavata.credential.store.store.impl.SSHCredentialWriter; @@ -68,8 +69,7 @@ public CredentialStoreService() credentialReader = new CredentialReaderImpl(dbUtil); } - public String addSSHCredential(SSHCredential sshCredential) - throws org.apache.airavata.credential.store.exception.CredentialStoreException { + public String addSSHCredential(SSHCredential sshCredential) throws CredentialStoreException { try { org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential credential = new org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential(); @@ -96,16 +96,15 @@ public String addSSHCredential(SSHCredential sshCredential) return token; } catch (Throwable e) { logger.error("Error occurred while saving SSH Credentials.", e); - org.apache.airavata.credential.store.exception.CredentialStoreException exception = - new org.apache.airavata.credential.store.exception.CredentialStoreException( - "Error occurred while saving SSH Credentials.. More info : " + e.getMessage()); + CredentialStoreException exception = new CredentialStoreException( + "Error occurred while saving SSH Credentials.. More info : " + e.getMessage()); exception.initCause(e); throw exception; } } public String addCertificateCredential(CertificateCredential certificateCredential) - throws org.apache.airavata.credential.store.exception.CredentialStoreException { + throws CredentialStoreException { try { org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential credential = new org.apache.airavata.credential.store.credential.impl.certificate.CertificateCredential(); @@ -132,16 +131,14 @@ public String addCertificateCredential(CertificateCredential certificateCredenti return token; } catch (Throwable e) { logger.error("Error occurred while saving Certificate Credentials.", e); - org.apache.airavata.credential.store.exception.CredentialStoreException exception = - new org.apache.airavata.credential.store.exception.CredentialStoreException( - "Error occurred while saving Certificate Credentials.. More info : " + e.getMessage()); + CredentialStoreException exception = new CredentialStoreException( + "Error occurred while saving Certificate Credentials.. More info : " + e.getMessage()); exception.initCause(e); throw exception; } } - public String addPasswordCredential(PasswordCredential passwordCredential) - throws org.apache.airavata.credential.store.exception.CredentialStoreException { + public String addPasswordCredential(PasswordCredential passwordCredential) throws CredentialStoreException { try { org.apache.airavata.credential.store.credential.impl.password.PasswordCredential credential = new org.apache.airavata.credential.store.credential.impl.password.PasswordCredential(); @@ -156,16 +153,14 @@ public String addPasswordCredential(PasswordCredential passwordCredential) return token; } catch (Throwable e) { logger.error("Error occurred while saving PWD Credentials.", e); - org.apache.airavata.credential.store.exception.CredentialStoreException exception = - new org.apache.airavata.credential.store.exception.CredentialStoreException( - "Error occurred while saving PWD Credentials.. More info : " + e.getMessage()); + CredentialStoreException exception = new CredentialStoreException( + "Error occurred while saving PWD Credentials.. More info : " + e.getMessage()); exception.initCause(e); throw exception; } } - public SSHCredential getSSHCredential(String tokenId, String gatewayId) - throws org.apache.airavata.credential.store.exception.CredentialStoreException { + public SSHCredential getSSHCredential(String tokenId, String gatewayId) throws CredentialStoreException { try { Credential credential = credentialReader.getCredential(gatewayId, tokenId); if (credential instanceof org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential @@ -194,15 +189,13 @@ public SSHCredential getSSHCredential(String tokenId, String gatewayId) String msg = "Error occurred while retrieving SSH credential for token - " + tokenId + " and gateway id - " + gatewayId; logger.error(msg, e); - org.apache.airavata.credential.store.exception.CredentialStoreException exception = - new org.apache.airavata.credential.store.exception.CredentialStoreException(msg); + CredentialStoreException exception = new CredentialStoreException(msg); exception.initCause(e); throw exception; } } - public CredentialSummary getCredentialSummary(String tokenId, String gatewayId) - throws org.apache.airavata.credential.store.exception.CredentialStoreException { + public CredentialSummary getCredentialSummary(String tokenId, String gatewayId) throws CredentialStoreException { try { Credential credential = credentialReader.getCredential(gatewayId, tokenId); if (isSSHCredential(credential)) { @@ -218,27 +211,23 @@ public CredentialSummary getCredentialSummary(String tokenId, String gatewayId) } String msg = "Unrecognized type of credential for token: " + tokenId; logger.error(msg, new RuntimeException(msg)); - org.apache.airavata.credential.store.exception.CredentialStoreException exception = - new org.apache.airavata.credential.store.exception.CredentialStoreException(msg); + CredentialStoreException exception = new CredentialStoreException(msg); exception.initCause(new RuntimeException(msg)); throw exception; - } catch (org.apache.airavata.credential.store.exception.CredentialStoreException e) { + } catch (CredentialStoreException e) { throw e; } catch (Throwable e) { final String msg = "Error occurred while retrieving credential summary for token - " + tokenId + " and gateway id - " + gatewayId; logger.error(msg, e); - org.apache.airavata.credential.store.exception.CredentialStoreException exception = - new org.apache.airavata.credential.store.exception.CredentialStoreException( - msg + ". More info : " + e.getMessage()); + CredentialStoreException exception = new CredentialStoreException(msg + ". More info : " + e.getMessage()); exception.initCause(e); throw exception; } } public List getAllCredentialSummaries( - SummaryType type, List accessibleTokenIds, String gatewayId) - throws org.apache.airavata.credential.store.exception.CredentialStoreException { + SummaryType type, List accessibleTokenIds, String gatewayId) throws CredentialStoreException { try { List credentials = credentialReader.getAllAccessibleCredentialsPerGateway(gatewayId, accessibleTokenIds); @@ -266,20 +255,17 @@ public List getAllCredentialSummaries( } else { String msg = "Summary Type " + type + " is not supported."; logger.error(msg, new RuntimeException(msg)); - org.apache.airavata.credential.store.exception.CredentialStoreException exception = - new org.apache.airavata.credential.store.exception.CredentialStoreException(msg); + CredentialStoreException exception = new CredentialStoreException(msg); exception.initCause(new RuntimeException(msg)); throw exception; } - } catch (org.apache.airavata.credential.store.exception.CredentialStoreException e) { + } catch (CredentialStoreException e) { throw e; } catch (Throwable e) { final String msg = "Error occurred while retrieving " + type + " credential Summary for tokens - " + accessibleTokenIds + " and gateway id - " + gatewayId; logger.error(msg, e); - org.apache.airavata.credential.store.exception.CredentialStoreException exception = - new org.apache.airavata.credential.store.exception.CredentialStoreException( - msg + ". More info : " + e.getMessage()); + CredentialStoreException exception = new CredentialStoreException(msg + ". More info : " + e.getMessage()); exception.initCause(e); throw exception; } @@ -339,7 +325,7 @@ private CredentialSummary convertToCredentialSummary( } public CertificateCredential getCertificateCredential(String tokenId, String gatewayId) - throws org.apache.airavata.credential.store.exception.CredentialStoreException { + throws CredentialStoreException { try { Credential credential = credentialReader.getCredential(gatewayId, tokenId); if (credential @@ -375,15 +361,13 @@ public CertificateCredential getCertificateCredential(String tokenId, String gat String msg = "Error occurred while retrieving Certificate credential for token - " + tokenId + " and gateway id - " + gatewayId; logger.error(msg, e); - org.apache.airavata.credential.store.exception.CredentialStoreException exception = - new org.apache.airavata.credential.store.exception.CredentialStoreException(msg); + CredentialStoreException exception = new CredentialStoreException(msg); exception.initCause(e); throw exception; } } - public PasswordCredential getPasswordCredential(String tokenId, String gatewayId) - throws org.apache.airavata.credential.store.exception.CredentialStoreException { + public PasswordCredential getPasswordCredential(String tokenId, String gatewayId) throws CredentialStoreException { try { Credential credential = credentialReader.getCredential(gatewayId, tokenId); if (credential @@ -409,8 +393,7 @@ public PasswordCredential getPasswordCredential(String tokenId, String gatewayId String msg = "Error occurred while retrieving PWD credential for token - " + tokenId + " and gateway id - " + gatewayId; logger.error(msg, e); - org.apache.airavata.credential.store.exception.CredentialStoreException exception = - new org.apache.airavata.credential.store.exception.CredentialStoreException(msg); + CredentialStoreException exception = new CredentialStoreException(msg); exception.initCause(e); throw exception; } @@ -418,7 +401,7 @@ public PasswordCredential getPasswordCredential(String tokenId, String gatewayId @Deprecated public List getAllCredentialSummaryForGateway(SummaryType type, String gatewayId) - throws org.apache.airavata.credential.store.exception.CredentialStoreException { + throws CredentialStoreException { if (type.equals(SummaryType.SSH)) { Map sshKeyMap = new HashMap<>(); List summaryList = new ArrayList<>(); @@ -447,9 +430,8 @@ public List getAllCredentialSummaryForGateway(SummaryType typ } } catch (Throwable e) { logger.error("Error occurred while retrieving credential Summary", e); - org.apache.airavata.credential.store.exception.CredentialStoreException exception = - new org.apache.airavata.credential.store.exception.CredentialStoreException( - "Error occurred while retrieving credential Summary. More info : " + e.getMessage()); + CredentialStoreException exception = new CredentialStoreException( + "Error occurred while retrieving credential Summary. More info : " + e.getMessage()); exception.initCause(e); throw exception; } @@ -462,8 +444,7 @@ public List getAllCredentialSummaryForGateway(SummaryType typ @Deprecated public List getAllCredentialSummaryForUserInGateway( - SummaryType type, String gatewayId, String userId) - throws org.apache.airavata.credential.store.exception.CredentialStoreException { + SummaryType type, String gatewayId, String userId) throws CredentialStoreException { if (type.equals(SummaryType.SSH)) { Map sshKeyMap = new HashMap<>(); List summaryList = new ArrayList<>(); @@ -504,9 +485,8 @@ public List getAllCredentialSummaryForUserInGateway( } } catch (Throwable e) { logger.error("Error occurred while retrieving credential Summary", e); - org.apache.airavata.credential.store.exception.CredentialStoreException exception = - new org.apache.airavata.credential.store.exception.CredentialStoreException( - "Error occurred while retrieving credential Summary. More info : " + e.getMessage()); + CredentialStoreException exception = new CredentialStoreException( + "Error occurred while retrieving credential Summary. More info : " + e.getMessage()); exception.initCause(e); throw exception; } @@ -519,8 +499,7 @@ public List getAllCredentialSummaryForUserInGateway( } @Deprecated - public Map getAllPWDCredentialsForGateway(String gatewayId) - throws org.apache.airavata.credential.store.exception.CredentialStoreException { + public Map getAllPWDCredentialsForGateway(String gatewayId) throws CredentialStoreException { Map pwdCredMap = new HashMap<>(); try { List allCredentials = credentialReader.getAllCredentialsPerGateway(gatewayId); @@ -540,17 +519,15 @@ public Map getAllPWDCredentialsForGateway(String gatewayId) } } catch (Throwable e) { logger.error("Error occurred while retrieving credentials", e); - org.apache.airavata.credential.store.exception.CredentialStoreException exception = - new org.apache.airavata.credential.store.exception.CredentialStoreException( - "Error occurred while retrieving credentials. More info : " + e.getMessage()); + CredentialStoreException exception = new CredentialStoreException( + "Error occurred while retrieving credentials. More info : " + e.getMessage()); exception.initCause(e); throw exception; } return pwdCredMap; } - public boolean deleteSSHCredential(String tokenId, String gatewayId) - throws org.apache.airavata.credential.store.exception.CredentialStoreException { + public boolean deleteSSHCredential(String tokenId, String gatewayId) throws CredentialStoreException { try { credentialReader.removeCredentials(gatewayId, tokenId); return true; @@ -558,15 +535,13 @@ public boolean deleteSSHCredential(String tokenId, String gatewayId) String msg = "Error occurred while deleting SSH credential for token - " + tokenId + " and gateway id - " + gatewayId; logger.error(msg, e); - org.apache.airavata.credential.store.exception.CredentialStoreException exception = - new org.apache.airavata.credential.store.exception.CredentialStoreException(msg); + CredentialStoreException exception = new CredentialStoreException(msg); exception.initCause(e); throw exception; } } - public boolean deletePWDCredential(String tokenId, String gatewayId) - throws org.apache.airavata.credential.store.exception.CredentialStoreException { + public boolean deletePWDCredential(String tokenId, String gatewayId) throws CredentialStoreException { try { credentialReader.removeCredentials(gatewayId, tokenId); return true; @@ -574,8 +549,7 @@ public boolean deletePWDCredential(String tokenId, String gatewayId) String msg = "Error occurred while deleting PWD credential for token - " + tokenId + " and gateway id - " + gatewayId; logger.error(msg, e); - org.apache.airavata.credential.store.exception.CredentialStoreException exception = - new org.apache.airavata.credential.store.exception.CredentialStoreException(msg); + CredentialStoreException exception = new CredentialStoreException(msg); exception.initCause(e); throw exception; } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/GroupManagerService.java b/airavata-api/src/main/java/org/apache/airavata/service/GroupManagerService.java index b736a3f604..52a464286c 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/GroupManagerService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/GroupManagerService.java @@ -23,34 +23,28 @@ import java.util.List; import java.util.UUID; import java.util.stream.Collectors; -import org.apache.airavata.common.exception.ApplicationSettingsException; import org.apache.airavata.common.utils.Constants; -import org.apache.airavata.common.utils.ServerSettings; import org.apache.airavata.model.group.GroupModel; import org.apache.airavata.model.security.AuthzToken; import org.apache.airavata.model.user.UserProfile; import org.apache.airavata.service.profile.groupmanager.cpi.exception.GroupManagerServiceException; import org.apache.airavata.service.profile.user.core.repositories.UserProfileRepository; -import org.apache.airavata.sharing.registry.client.SharingRegistryServiceClientFactory; import org.apache.airavata.sharing.registry.models.GroupCardinality; import org.apache.airavata.sharing.registry.models.GroupType; import org.apache.airavata.sharing.registry.models.SharingRegistryException; import org.apache.airavata.sharing.registry.models.User; import org.apache.airavata.sharing.registry.models.UserGroup; -import org.apache.airavata.sharing.registry.service.cpi.SharingRegistryService; -import org.apache.thrift.TException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class GroupManagerService { private static final Logger logger = LoggerFactory.getLogger(GroupManagerService.class); private UserProfileRepository userProfileRepository = new UserProfileRepository(); + private SharingRegistryService sharingService = new SharingRegistryService(); public String createGroup(AuthzToken authzToken, GroupModel groupModel) throws GroupManagerServiceException { try { // TODO Validations for authorization - var sharingClient = getSharingRegistryServiceClient(); - var sharingUserGroup = new UserGroup(); sharingUserGroup.setGroupId(UUID.randomUUID().toString()); sharingUserGroup.setName(groupModel.getName()); @@ -61,10 +55,10 @@ public String createGroup(AuthzToken authzToken, GroupModel groupModel) throws G sharingUserGroup.setDomainId(gatewayId); sharingUserGroup.setOwnerId(getUserId(authzToken)); - var groupId = sharingClient.createGroup(sharingUserGroup); - internalAddUsersToGroup(sharingClient, gatewayId, groupModel.getMembers(), groupId); + var groupId = sharingService.createGroup(sharingUserGroup); + internalAddUsersToGroup(sharingService, gatewayId, groupModel.getMembers(), groupId); if (groupModel.getAdmins() != null && !groupModel.getAdmins().isEmpty()) { - sharingClient.addGroupAdmins(gatewayId, groupId, groupModel.getAdmins()); + sharingService.addGroupAdmins(gatewayId, groupId, groupModel.getAdmins()); } return groupId; } catch (Exception e) { @@ -79,11 +73,10 @@ public String createGroup(AuthzToken authzToken, GroupModel groupModel) throws G public boolean updateGroup(AuthzToken authzToken, GroupModel groupModel) throws GroupManagerServiceException { try { - var sharingClient = getSharingRegistryServiceClient(); var userId = getUserId(authzToken); var domainId = getDomainId(authzToken); - if (!(sharingClient.hasOwnerAccess(domainId, groupModel.getId(), userId) - || sharingClient.hasAdminAccess(domainId, groupModel.getId(), userId))) { + if (!(sharingService.hasOwnerAccess(domainId, groupModel.getId(), userId) + || sharingService.hasAdminAccess(domainId, groupModel.getId(), userId))) { throw new GroupManagerServiceException("User does not have permission to update group"); } @@ -95,7 +88,7 @@ public boolean updateGroup(AuthzToken authzToken, GroupModel groupModel) throws sharingUserGroup.setDomainId(getDomainId(authzToken)); // adding and removal of users should be handle separately - sharingClient.updateGroup(sharingUserGroup); + sharingService.updateGroup(sharingUserGroup); return true; } catch (Exception e) { String msg = "Error Updating Group"; @@ -110,14 +103,13 @@ public boolean updateGroup(AuthzToken authzToken, GroupModel groupModel) throws public boolean deleteGroup(AuthzToken authzToken, String groupId, String ownerId) throws GroupManagerServiceException { try { - SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); String userId = getUserId(authzToken); String domainId = getDomainId(authzToken); - if (!(sharingClient.hasOwnerAccess(domainId, groupId, userId))) { + if (!(sharingService.hasOwnerAccess(domainId, groupId, userId))) { throw new GroupManagerServiceException("User does not have permission to delete group"); } - sharingClient.deleteGroup(getDomainId(authzToken), groupId); + sharingService.deleteGroup(getDomainId(authzToken), groupId); return true; } catch (Exception e) { String msg = "Error Deleting Group. Group ID: " + groupId; @@ -131,12 +123,9 @@ public boolean deleteGroup(AuthzToken authzToken, String groupId, String ownerId public GroupModel getGroup(AuthzToken authzToken, String groupId) throws GroupManagerServiceException { try { - SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); final String domainId = getDomainId(authzToken); - UserGroup userGroup = sharingClient.getGroup(domainId, groupId); - - GroupModel groupModel = convertToGroupModel(userGroup, sharingClient); - + UserGroup userGroup = sharingService.getGroup(domainId, groupId); + GroupModel groupModel = convertToGroupModel(userGroup, sharingService); return groupModel; } catch (Exception e) { String msg = "Error Retreiving Group. Group ID: " + groupId; @@ -150,12 +139,9 @@ public GroupModel getGroup(AuthzToken authzToken, String groupId) throws GroupMa public List getGroups(AuthzToken authzToken) throws GroupManagerServiceException { final String domainId = getDomainId(authzToken); - SharingRegistryService.Client sharingClient = null; try { - sharingClient = getSharingRegistryServiceClient(); - List userGroups = sharingClient.getGroups(domainId, 0, -1); - - return convertToGroupModels(userGroups, sharingClient); + List userGroups = sharingService.getGroups(domainId, 0, -1); + return convertToGroupModels(userGroups, sharingService); } catch (Exception e) { String msg = "Error Retrieving Groups. Domain ID: " + domainId; logger.error(msg, e); @@ -163,20 +149,15 @@ public List getGroups(AuthzToken authzToken) throws GroupManagerServ exception.setMessage(msg + " More info : " + e.getMessage()); exception.initCause(e); throw exception; - } finally { - closeSharingClient(sharingClient); } } public List getAllGroupsUserBelongs(AuthzToken authzToken, String userName) throws GroupManagerServiceException { try { - SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); - List groupModels = new ArrayList(); final String domainId = getDomainId(authzToken); - List userGroups = sharingClient.getAllMemberGroupsForUser(domainId, userName); - - return convertToGroupModels(userGroups, sharingClient); + List userGroups = sharingService.getAllMemberGroupsForUser(domainId, userName); + return convertToGroupModels(userGroups, sharingService); } catch (Exception e) { String msg = "Error Retreiving All Groups for User. User ID: " + userName; logger.error(msg, e); @@ -190,14 +171,13 @@ public List getAllGroupsUserBelongs(AuthzToken authzToken, String us public boolean addUsersToGroup(AuthzToken authzToken, List userIds, String groupId) throws GroupManagerServiceException { try { - SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); String userId = getUserId(authzToken); String domainId = getDomainId(authzToken); - if (!(sharingClient.hasOwnerAccess(domainId, groupId, userId) - || sharingClient.hasAdminAccess(domainId, groupId, userId))) { + if (!(sharingService.hasOwnerAccess(domainId, groupId, userId) + || sharingService.hasAdminAccess(domainId, groupId, userId))) { throw new GroupManagerServiceException("User does not have access to add users to the group"); } - return internalAddUsersToGroup(sharingClient, domainId, userIds, groupId); + return internalAddUsersToGroup(sharingService, domainId, userIds, groupId); } catch (Exception e) { String msg = "Error adding users to group. Group ID: " + groupId; @@ -212,14 +192,13 @@ public boolean addUsersToGroup(AuthzToken authzToken, List userIds, Stri public boolean removeUsersFromGroup(AuthzToken authzToken, List userIds, String groupId) throws GroupManagerServiceException { try { - SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); String userId = getUserId(authzToken); String domainId = getDomainId(authzToken); - if (!(sharingClient.hasOwnerAccess(domainId, groupId, userId) - || sharingClient.hasAdminAccess(domainId, groupId, userId))) { + if (!(sharingService.hasOwnerAccess(domainId, groupId, userId) + || sharingService.hasAdminAccess(domainId, groupId, userId))) { throw new GroupManagerServiceException("User does not have access to remove users to the group"); } - return sharingClient.removeUsersFromGroup(domainId, userIds, groupId); + return sharingService.removeUsersFromGroup(domainId, userIds, groupId); } catch (Exception e) { String msg = "Error remove users to group. Group ID: " + groupId; logger.error(msg, e); @@ -233,14 +212,13 @@ public boolean removeUsersFromGroup(AuthzToken authzToken, List userIds, public boolean transferGroupOwnership(AuthzToken authzToken, String groupId, String newOwnerId) throws GroupManagerServiceException { try { - SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); String userId = getUserId(authzToken); String domainId = getDomainId(authzToken); - if (!(sharingClient.hasOwnerAccess(domainId, groupId, userId))) { + if (!(sharingService.hasOwnerAccess(domainId, groupId, userId))) { throw new GroupManagerServiceException( "User does not have Owner permission to transfer group ownership"); } - return sharingClient.transferGroupOwnership(getDomainId(authzToken), groupId, newOwnerId); + return sharingService.transferGroupOwnership(getDomainId(authzToken), groupId, newOwnerId); } catch (Exception e) { String msg = "Error Transferring Group Ownership"; logger.error(msg, e); @@ -254,13 +232,12 @@ public boolean transferGroupOwnership(AuthzToken authzToken, String groupId, Str public boolean addGroupAdmins(AuthzToken authzToken, String groupId, List adminIds) throws GroupManagerServiceException { try { - SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); String userId = getUserId(authzToken); String domainId = getDomainId(authzToken); - if (!(sharingClient.hasOwnerAccess(domainId, groupId, userId))) { + if (!(sharingService.hasOwnerAccess(domainId, groupId, userId))) { throw new GroupManagerServiceException("User does not have Owner permission to add group admins"); } - return sharingClient.addGroupAdmins(getDomainId(authzToken), groupId, adminIds); + return sharingService.addGroupAdmins(getDomainId(authzToken), groupId, adminIds); } catch (Exception e) { String msg = "Error Adding Admins to Group. Group ID: " + groupId; logger.error(msg, e); @@ -274,13 +251,12 @@ public boolean addGroupAdmins(AuthzToken authzToken, String groupId, List adminIds) throws GroupManagerServiceException { try { - SharingRegistryService.Client sharingClient = getSharingRegistryServiceClient(); String userId = getUserId(authzToken); String domainId = getDomainId(authzToken); - if (!(sharingClient.hasOwnerAccess(domainId, groupId, userId))) { + if (!(sharingService.hasOwnerAccess(domainId, groupId, userId))) { throw new GroupManagerServiceException("User does not have Owner permission to remove group admins"); } - return sharingClient.removeGroupAdmins(getDomainId(authzToken), groupId, adminIds); + return sharingService.removeGroupAdmins(getDomainId(authzToken), groupId, adminIds); } catch (Exception e) { String msg = "Error Removing Admins from the Group. Group ID: " + groupId; logger.error(msg, e); @@ -294,8 +270,7 @@ public boolean removeGroupAdmins(AuthzToken authzToken, String groupId, List convertToGroupModels( - List userGroups, SharingRegistryService.Client sharingClient) throws TException { + private List convertToGroupModels(List userGroups, SharingRegistryService sharingService) + throws SharingRegistryException { List groupModels = new ArrayList<>(); for (UserGroup userGroup : userGroups) { - GroupModel groupModel = convertToGroupModel(userGroup, sharingClient); + GroupModel groupModel = convertToGroupModel(userGroup, sharingService); groupModels.add(groupModel); } return groupModels; } - private GroupModel convertToGroupModel(UserGroup userGroup, SharingRegistryService.Client sharingClient) - throws TException { + private GroupModel convertToGroupModel(UserGroup userGroup, SharingRegistryService sharingService) + throws SharingRegistryException { GroupModel groupModel = new GroupModel(); groupModel.setId(userGroup.getGroupId()); groupModel.setName(userGroup.getName()); @@ -366,30 +328,19 @@ private GroupModel convertToGroupModel(UserGroup userGroup, SharingRegistryServi .collect(Collectors.toList()); groupModel.setAdmins(admins); - sharingClient.getGroupMembersOfTypeUser(userGroup.getDomainId(), userGroup.getGroupId(), 0, -1).stream() + sharingService.getGroupMembersOfTypeUser(userGroup.getDomainId(), userGroup.getGroupId(), 0, -1).stream() .forEach(user -> groupModel.addToMembers(user.getUserId())); return groupModel; } - private void closeSharingClient(SharingRegistryService.Client sharingClient) { - if (sharingClient != null) { - if (sharingClient.getInputProtocol().getTransport().isOpen()) { - sharingClient.getInputProtocol().getTransport().close(); - } - if (sharingClient.getOutputProtocol().getTransport().isOpen()) { - sharingClient.getOutputProtocol().getTransport().close(); - } - } - } - private boolean internalAddUsersToGroup( - SharingRegistryService.Client sharingClient, String domainId, List userIds, String groupId) - throws SharingRegistryException, TException { + SharingRegistryService sharingService, String domainId, List userIds, String groupId) + throws SharingRegistryException { // FIXME: workaround for UserProfiles that failed to sync to the sharing // registry: create any missing users in the sharing registry for (String userId : userIds) { - if (!sharingClient.isUserExists(domainId, userId)) { + if (!sharingService.isUserExists(domainId, userId)) { User user = new User(); user.setDomainId(domainId); user.setUserId(userId); @@ -402,9 +353,9 @@ private boolean internalAddUsersToGroup( : null); user.setFirstName(userProfile.getFirstName()); user.setLastName(userProfile.getLastName()); - sharingClient.createUser(user); + sharingService.createUser(user); } } - return sharingClient.addUsersToGroup(domainId, userIds, groupId); + return sharingService.addUsersToGroup(domainId, userIds, groupId); } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/IamAdminService.java b/airavata-api/src/main/java/org/apache/airavata/service/IamAdminService.java index b3d79e3187..582aa0b3bd 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/IamAdminService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/IamAdminService.java @@ -20,14 +20,11 @@ package org.apache.airavata.service; import java.util.List; -import org.apache.airavata.common.exception.AiravataException; import org.apache.airavata.common.exception.ApplicationSettingsException; import org.apache.airavata.common.utils.AiravataUtils; import org.apache.airavata.common.utils.Constants; import org.apache.airavata.common.utils.DBEventService; import org.apache.airavata.common.utils.ServerSettings; -import org.apache.airavata.credential.store.client.CredentialStoreClientFactory; -import org.apache.airavata.credential.store.cpi.CredentialStoreService; import org.apache.airavata.credential.store.exception.CredentialStoreException; import org.apache.airavata.messaging.core.util.DBEventPublisherUtils; import org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile; @@ -37,13 +34,10 @@ import org.apache.airavata.model.security.AuthzToken; import org.apache.airavata.model.user.UserProfile; import org.apache.airavata.model.workspace.Gateway; -import org.apache.airavata.registry.api.RegistryService; -import org.apache.airavata.registry.api.client.RegistryServiceClientFactory; import org.apache.airavata.registry.api.exception.RegistryServiceException; import org.apache.airavata.service.profile.iam.admin.services.core.impl.TenantManagementKeycloakImpl; import org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException; import org.apache.airavata.service.profile.user.core.repositories.UserProfileRepository; -import org.apache.thrift.TException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,6 +45,17 @@ public class IamAdminService { private static final Logger logger = LoggerFactory.getLogger(IamAdminService.class); private UserProfileRepository userProfileRepository = new UserProfileRepository(); private DBEventPublisherUtils dbEventPublisherUtils = new DBEventPublisherUtils(DBEventService.IAM_ADMIN); + private final CredentialStoreService credentialStoreService; + private final RegistryService registryService; + + public IamAdminService() throws ApplicationSettingsException { + try { + credentialStoreService = new CredentialStoreService(); + registryService = new RegistryService(); + } catch (Throwable e) { + throw new RuntimeException("Unable to create credential store and registry services", e); + } + } public Gateway setUpGateway(AuthzToken authzToken, Gateway gateway) throws IamAdminServicesException { var keycloakclient = new TenantManagementKeycloakImpl(); @@ -59,9 +64,8 @@ public Gateway setUpGateway(AuthzToken authzToken, Gateway gateway) throws IamAd keycloakclient.addTenant(isSuperAdminCredentials, gateway); // Load the tenant admin password stored in gateway request - var credentialStoreClient = getCredentialStoreServiceClient(); // Admin password token should already be stored under requested gateway's gatewayId - var tenantAdminPasswordCredential = credentialStoreClient.getPasswordCredential( + var tenantAdminPasswordCredential = credentialStoreService.getPasswordCredential( gateway.getIdentityServerPasswordToken(), gateway.getGatewayId()); if (!keycloakclient.createTenantAdminAccount( @@ -70,12 +74,12 @@ public Gateway setUpGateway(AuthzToken authzToken, Gateway gateway) throws IamAd } var gatewayWithIdAndSecret = keycloakclient.configureClient(isSuperAdminCredentials, gateway); return gatewayWithIdAndSecret; - } catch (TException | ApplicationSettingsException ex) { - logger.error("Gateway Setup Failed, reason: " + ex.getMessage(), ex); - var iamAdminServicesException = - new IamAdminServicesException("Gateway Setup Failed, reason: " + ex.getMessage()); - iamAdminServicesException.initCause(ex); - throw iamAdminServicesException; + } catch (Throwable ex) { + String msg = "Gateway Setup Failed, reason: " + ex.getMessage(); + logger.error(msg, ex); + IamAdminServicesException exception = new IamAdminServicesException(msg); + exception.initCause(ex); + throw exception; } } @@ -87,9 +91,9 @@ public boolean isUsernameAvailable(AuthzToken authzToken, String username) throw } catch (IamAdminServicesException e) { throw e; } catch (Throwable ex) { - logger.error("Error while checking username availability", ex); - var exception = new IamAdminServicesException( - "Error while checking username availability. More info : " + ex.getMessage()); + String msg = "Error while checking username availability, reason: " + ex.getMessage(); + logger.error(msg, ex); + var exception = new IamAdminServicesException(msg); exception.initCause(ex); throw exception; } @@ -110,10 +114,10 @@ public boolean registerUser( authzToken.getAccessToken(), gatewayId, username, emailAddress, firstName, lastName, newPassword)) return true; else return false; - } catch (TException ex) { + } catch (Throwable ex) { String msg = "Error while registering user into Identity Server, reason: " + ex.getMessage(); logger.error(msg, ex); - IamAdminServicesException exception = new IamAdminServicesException(msg); + var exception = new IamAdminServicesException(msg); exception.initCause(ex); throw exception; } @@ -143,10 +147,10 @@ public boolean enableUser(AuthzToken authzToken, String username) throws IamAdmi } else { return false; } - } catch (TException | AiravataException ex) { + } catch (Throwable ex) { String msg = "Error while enabling user account, reason: " + ex.getMessage(); logger.error(msg, ex); - IamAdminServicesException exception = new IamAdminServicesException(msg); + var exception = new IamAdminServicesException(msg); exception.initCause(ex); throw exception; } @@ -160,7 +164,7 @@ public boolean isUserEnabled(AuthzToken authzToken, String username) throws IamA } catch (Exception ex) { String msg = "Error while checking if user account is enabled, reason: " + ex.getMessage(); logger.error(msg, ex); - IamAdminServicesException exception = new IamAdminServicesException(msg); + var exception = new IamAdminServicesException(msg); exception.initCause(ex); throw exception; } @@ -174,7 +178,7 @@ public boolean isUserExist(AuthzToken authzToken, String username) throws IamAdm } catch (Exception ex) { String msg = "Error while checking if user account exists, reason: " + ex.getMessage(); logger.error(msg, ex); - IamAdminServicesException exception = new IamAdminServicesException(msg); + var exception = new IamAdminServicesException(msg); exception.initCause(ex); throw exception; } @@ -188,7 +192,7 @@ public UserProfile getUser(AuthzToken authzToken, String username) throws IamAdm } catch (Exception ex) { String msg = "Error while retrieving user profile from IAM backend, reason: " + ex.getMessage(); logger.error(msg, ex); - IamAdminServicesException exception = new IamAdminServicesException(msg); + var exception = new IamAdminServicesException(msg); exception.initCause(ex); throw exception; } @@ -203,7 +207,7 @@ public List getUsers(AuthzToken authzToken, int offset, int limit, } catch (Exception ex) { String msg = "Error while retrieving user profile from IAM backend, reason: " + ex.getMessage(); logger.error(msg, ex); - IamAdminServicesException exception = new IamAdminServicesException(msg); + var exception = new IamAdminServicesException(msg); exception.initCause(ex); throw exception; } @@ -217,10 +221,10 @@ public boolean resetUserPassword(AuthzToken authzToken, String username, String if (keycloakclient.resetUserPassword(authzToken.getAccessToken(), gatewayId, username, newPassword)) return true; else return false; - } catch (TException ex) { + } catch (Throwable ex) { String msg = "Error while resetting user password in Identity Server, reason: " + ex.getMessage(); logger.error(msg, ex); - IamAdminServicesException exception = new IamAdminServicesException(msg); + var exception = new IamAdminServicesException(msg); exception.initCause(ex); throw exception; } @@ -232,10 +236,10 @@ public List findUsers(AuthzToken authzToken, String email, String u String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); try { return keycloakclient.findUser(authzToken.getAccessToken(), gatewayId, email, userId); - } catch (TException ex) { + } catch (Throwable ex) { String msg = "Error while retrieving users from Identity Server, reason: " + ex.getMessage(); logger.error(msg, ex); - IamAdminServicesException exception = new IamAdminServicesException(msg); + var exception = new IamAdminServicesException(msg); exception.initCause(ex); throw exception; } @@ -250,9 +254,9 @@ public void updateUserProfile(AuthzToken authzToken, UserProfile userDetails) th } catch (IamAdminServicesException e) { throw e; } catch (Throwable ex) { - logger.error("Error while updating user profile", ex); - var exception = - new IamAdminServicesException("Error while updating user profile. More info : " + ex.getMessage()); + String msg = "Error while updating user profile, reason: " + ex.getMessage(); + logger.error(msg, ex); + var exception = new IamAdminServicesException(msg); exception.initCause(ex); throw exception; } @@ -266,8 +270,9 @@ public boolean deleteUser(AuthzToken authzToken, String username) throws IamAdmi } catch (IamAdminServicesException e) { throw e; } catch (Throwable ex) { - logger.error("Error while deleting user", ex); - var exception = new IamAdminServicesException("Error while deleting user. More info : " + ex.getMessage()); + String msg = "Error while deleting user, reason: " + ex.getMessage(); + logger.error(msg, ex); + var exception = new IamAdminServicesException(msg); exception.initCause(ex); throw exception; } @@ -280,10 +285,10 @@ public boolean addRoleToUser(AuthzToken authzToken, String username, String role try { PasswordCredential isRealmAdminCredentials = getTenantAdminPasswordCredential(gatewayId); return keycloakclient.addRoleToUser(isRealmAdminCredentials, gatewayId, username, roleName); - } catch (TException | ApplicationSettingsException ex) { + } catch (Throwable ex) { String msg = "Error while adding role to user, reason: " + ex.getMessage(); logger.error(msg, ex); - IamAdminServicesException exception = new IamAdminServicesException(msg); + var exception = new IamAdminServicesException(msg); exception.initCause(ex); throw exception; } @@ -296,10 +301,10 @@ public boolean removeRoleFromUser(AuthzToken authzToken, String username, String try { PasswordCredential isRealmAdminCredentials = getTenantAdminPasswordCredential(gatewayId); return keycloakclient.removeRoleFromUser(isRealmAdminCredentials, gatewayId, username, roleName); - } catch (TException | ApplicationSettingsException ex) { + } catch (Throwable ex) { String msg = "Error while removing role from user, reason: " + ex.getMessage(); logger.error(msg, ex); - IamAdminServicesException exception = new IamAdminServicesException(msg); + var exception = new IamAdminServicesException(msg); exception.initCause(ex); throw exception; } @@ -314,7 +319,7 @@ public List getUsersWithRole(AuthzToken authzToken, String roleName } catch (Exception ex) { String msg = "Error while retrieving users with role, reason: " + ex.getMessage(); logger.error(msg, ex); - IamAdminServicesException exception = new IamAdminServicesException(msg); + var exception = new IamAdminServicesException(msg); exception.initCause(ex); throw exception; } @@ -331,33 +336,27 @@ private PasswordCredential getSuperAdminPasswordCredential() { return isSuperAdminCredentials; } - private PasswordCredential getTenantAdminPasswordCredential(String tenantId) - throws TException, ApplicationSettingsException { - - GatewayResourceProfile gwrp = getRegistryServiceClient().getGatewayResourceProfile(tenantId); - - CredentialStoreService.Client csClient = getCredentialStoreServiceClient(); - return csClient.getPasswordCredential(gwrp.getIdentityServerPwdCredToken(), gwrp.getGatewayID()); - } + private PasswordCredential getTenantAdminPasswordCredential(String tenantId) throws IamAdminServicesException { - private RegistryService.Client getRegistryServiceClient() throws TException, ApplicationSettingsException { - final int serverPort = Integer.parseInt(ServerSettings.getRegistryServerPort()); - final String serverHost = ServerSettings.getRegistryServerHost(); + GatewayResourceProfile gwrp = null; try { - return RegistryServiceClientFactory.createRegistryClient(serverHost, serverPort); + gwrp = registryService.getGatewayResourceProfile(tenantId); } catch (RegistryServiceException e) { - throw new TException("Unable to create registry client...", e); + String msg = "Error while getting gateway resource profile, reason: " + e.getMessage(); + logger.error(msg, e); + var exception = new IamAdminServicesException(msg); + exception.initCause(e); + throw exception; } - } - - private CredentialStoreService.Client getCredentialStoreServiceClient() - throws TException, ApplicationSettingsException { - final int serverPort = Integer.parseInt(ServerSettings.getCredentialStoreServerPort()); - final String serverHost = ServerSettings.getCredentialStoreServerHost(); try { - return CredentialStoreClientFactory.createAiravataCSClient(serverHost, serverPort); + return credentialStoreService.getPasswordCredential( + gwrp.getIdentityServerPwdCredToken(), gwrp.getGatewayID()); } catch (CredentialStoreException e) { - throw new TException("Unable to create credential store client...", e); + String msg = "Error while getting password credential, reason: " + e.getMessage(); + logger.error(msg, e); + var exception = new IamAdminServicesException(msg); + exception.initCause(e); + throw exception; } } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorRegistryService.java b/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorRegistryService.java index 84fc9c44fe..2a014b362d 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorRegistryService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorRegistryService.java @@ -34,14 +34,10 @@ import org.apache.airavata.model.status.ProcessStatus; import org.apache.airavata.model.status.QueueStatusModel; import org.apache.airavata.registry.api.exception.RegistryServiceException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class OrchestratorRegistryService { - private static final Logger logger = LoggerFactory.getLogger(OrchestratorRegistryService.class); - private org.apache.airavata.service.RegistryService registryService = - new org.apache.airavata.service.RegistryService(); + private RegistryService registryService = new RegistryService(); public ExperimentModel getExperiment(String airavataExperimentId) throws RegistryServiceException { return registryService.getExperiment(airavataExperimentId); diff --git a/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorService.java b/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorService.java index 3360343027..58a73bb785 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/OrchestratorService.java @@ -22,6 +22,7 @@ import java.lang.reflect.InvocationTargetException; import java.text.MessageFormat; import java.util.*; +import java.util.concurrent.ExecutorService; import org.apache.airavata.common.exception.AiravataException; import org.apache.airavata.common.exception.ApplicationSettingsException; import org.apache.airavata.common.logging.MDCConstants; @@ -119,7 +120,7 @@ public OrchestratorService( this.publisher = publisher; } - public boolean launchExperiment(String experimentId, String gatewayId) + private boolean launchExperimentInternal(String experimentId, String gatewayId) throws ExperimentNotFoundException, OrchestratorException, RegistryServiceException, LaunchValidationException { String experimentNodePath = getExperimentNodePath(experimentId); @@ -718,7 +719,7 @@ public void handleLaunchExperiment(ExperimentSubmitEvent expEvent) LaunchValidationException { ExperimentModel experimentModel = orchestratorRegistryService.getExperiment(expEvent.getExperimentId()); if (experimentModel.getExperimentStatus().get(0).getState() == ExperimentState.CREATED) { - launchExperiment(expEvent.getExperimentId(), expEvent.getGatewayId()); + launchExperimentInternal(expEvent.getExperimentId(), expEvent.getGatewayId()); } } @@ -784,11 +785,10 @@ public ProcessModel getProcess(String processId) throws RegistryServiceException return orchestratorRegistryService.getProcess(processId); } - public boolean launchExperimentWithErrorHandling( - String experimentId, String gatewayId, java.util.concurrent.ExecutorService executorService) + public boolean launchExperiment(String experimentId, String gatewayId, ExecutorService executorService) throws OrchestratorException { try { - boolean result = launchExperiment(experimentId, gatewayId); + boolean result = launchExperimentInternal(experimentId, gatewayId); if (result) { ExperimentModel experiment = orchestratorRegistryService.getExperiment(experimentId); String token = getCredentialToken(experiment, experiment.getUserConfigurationData()); @@ -842,58 +842,12 @@ private void startCurator() throws ApplicationSettingsException { curatorClient.start(); } - // private Subscriber getStatusSubscriber() throws AiravataException { - // List routingKeys = new ArrayList<>(); - // routingKeys.add("*.*.*"); - // return MessagingFactory.getSubscriber(new ProcessStatusHandler(), routingKeys, Type.STATUS); - // } - private Subscriber getExperimentSubscriber() throws AiravataException { List routingKeys = new ArrayList<>(); routingKeys.add(ServerSettings.getRabbitmqExperimentLaunchQueueName()); return MessagingFactory.getSubscriber(new ExperimentHandler(), routingKeys, Type.EXPERIMENT_LAUNCH); } - // private void setAiravataUserName(String airavataUserName) { - // this.airavataUserName = airavataUserName; - // } - - // private class ProcessStatusHandler implements MessageHandler { - // @Override - // public void onMessage(MessageContext message) { - // if (message.getType().equals(MessageType.PROCESS)) { - // try { - // ProcessStatusChangeEvent processStatusChangeEvent = new ProcessStatusChangeEvent(); - // TBase event = message.getEvent(); - // byte[] bytes = ThriftUtils.serializeThriftObject(event); - // ThriftUtils.createThriftFromBytes(bytes, processStatusChangeEvent); - // ProcessIdentifier processIdentity = processStatusChangeEvent.getProcessIdentity(); - // logger.info( - // "expId: {}, processId: {} :- Process status changed event received for status {}", - // processIdentity.getExperimentId(), - // processIdentity.getProcessId(), - // processStatusChangeEvent.getState().name()); - // handleProcessStatusChange(processStatusChangeEvent, processIdentity); - // } catch (OrchestratorException e) { - // logger.error("Message Id : " + message.getMessageId() + ", Message type : " + message.getType() - // + "Error" + " while prcessing process status change event"); - // throw new RuntimeException("Error while updating experiment status", e); - // } catch (Throwable e) { - // logger.error( - // "Message Id : " + message.getMessageId() + ", Message type : " + message.getType() + - // "Error" - // + " while prcessing process status change event", - // e); - // throw new RuntimeException("Error while updating experiment status", e); - // } - // } else { - // System.out.println("Message Recieved with message id " + message.getMessageId() + " and with message - // " - // + "type " + message.getType().name()); - // } - // } - // } - private class ExperimentHandler implements MessageHandler { @Override diff --git a/airavata-api/src/main/java/org/apache/airavata/service/RegistryService.java b/airavata-api/src/main/java/org/apache/airavata/service/RegistryService.java index 71f449bf3d..41ca818211 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/RegistryService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/RegistryService.java @@ -156,9 +156,9 @@ public Gateway getGateway(String gatewayId) throws RegistryServiceException { logger.debug("Airavata retrieved gateway with gateway id : " + gateway.getGatewayId()); return gateway; } catch (Throwable e) { - logger.error("Error while getting the gateway", e); - RegistryServiceException exception = new RegistryServiceException(); - exception.setMessage("Error while getting the gateway More info : " + e.getMessage()); + String msg = "Error while getting the gateway: " + e.getMessage(); + logger.error(msg, e); + var exception = new RegistryServiceException(msg); exception.initCause(e); throw exception; } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/SharingRegistryService.java b/airavata-api/src/main/java/org/apache/airavata/service/SharingRegistryService.java index 5f2c8b3594..1595cff025 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/SharingRegistryService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/SharingRegistryService.java @@ -62,9 +62,10 @@ public String createDomain(Domain domain) throws SharingRegistryException, Dupli } catch (SharingRegistryException | DuplicateEntryException e) { throw e; } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); + String msg = "Error while creating domain: domainId=" + domain.getDomainId() + ", " + ex.getMessage(); + logger.error(msg, ex); SharingRegistryException exception = - new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + new SharingRegistryException(msg + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); exception.initCause(ex); throw exception; } @@ -81,9 +82,10 @@ public boolean updateDomain(Domain domain) throws SharingRegistryException { } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); + String msg = "Error while updating domain: domainId=" + domain.getDomainId() + ", " + ex.getMessage(); + logger.error(msg, ex); SharingRegistryException exception = - new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + new SharingRegistryException(msg + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); exception.initCause(ex); throw exception; } @@ -95,9 +97,10 @@ public boolean isDomainExists(String domainId) throws SharingRegistryException { } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); + String msg = "Error while checking if domain exists: domainId=" + domainId + ", " + ex.getMessage(); + logger.error(msg, ex); SharingRegistryException exception = - new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + new SharingRegistryException(msg + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); exception.initCause(ex); throw exception; } @@ -110,9 +113,10 @@ public boolean deleteDomain(String domainId) throws SharingRegistryException { } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - logger.error(ex.getMessage(), ex); + String msg = "Error while deleting domain: domainId=" + domainId + ", " + ex.getMessage(); + logger.error(msg, ex); SharingRegistryException exception = - new SharingRegistryException(ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + new SharingRegistryException(msg + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); exception.initCause(ex); throw exception; } @@ -124,9 +128,10 @@ public Domain getDomain(String domainId) throws SharingRegistryException { } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - logger.error("Error while getting domain: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while getting domain: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while getting domain: domainId=" + domainId + ", " + ex.getMessage(); + logger.error(msg, ex); + SharingRegistryException exception = + new SharingRegistryException(msg + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); exception.initCause(ex); throw exception; } @@ -138,9 +143,10 @@ public List getDomains(int offset, int limit) throws SharingRegistryExce } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - logger.error("Error while getting domains: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while getting domains: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while getting domains: offset=" + offset + ", limit=" + limit + ", " + ex.getMessage(); + logger.error(msg, ex); + SharingRegistryException exception = + new SharingRegistryException(msg + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); exception.initCause(ex); throw exception; } @@ -150,13 +156,13 @@ public List getDomains(int offset, int limit) throws SharingRegistryExce * * User Operations * * */ - public String createUser(User user) throws SharingRegistryException, DuplicateEntryException { + public String createUser(User user) throws SharingRegistryException { try { UserPK userPK = new UserPK(); userPK.setUserId(user.getUserId()); userPK.setDomainId(user.getDomainId()); if ((new UserRepository()).get(userPK) != null) - throw new DuplicateEntryException("There exist user with given user id"); + throw new SharingRegistryException("There exist user with given user id"); user.setCreatedTime(System.currentTimeMillis()); user.setUpdatedTime(System.currentTimeMillis()); @@ -181,12 +187,13 @@ public String createUser(User user) throws SharingRegistryException, DuplicateEn } return user.getUserId(); - } catch (SharingRegistryException | DuplicateEntryException e) { + } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - logger.error("Error while creating user: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while creating user: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while creating user: userId=" + user.getUserId() + ", domainId=" + user.getDomainId() + + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -214,9 +221,10 @@ public boolean updatedUser(User user) throws SharingRegistryException { } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - logger.error("Error while updating user: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while updating user: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while updating user: userId=" + user.getUserId() + ", domainId=" + user.getDomainId() + + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -231,9 +239,10 @@ public boolean isUserExists(String domainId, String userId) throws SharingRegist } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - logger.error("Error while checking if user exists: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while checking if user exists: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while checking if user exists: domainId=" + domainId + ", userId=" + userId + ", " + + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -254,9 +263,10 @@ public boolean deleteUser(String domainId, String userId) throws SharingRegistry } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - logger.error("Error while deleting user: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while deleting user: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = + "Error while deleting user: domainId=" + domainId + ", userId=" + userId + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -271,9 +281,10 @@ public User getUser(String domainId, String userId) throws SharingRegistryExcept } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - logger.error("Error while getting user: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while getting user: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = + "Error while getting user: domainId=" + domainId + ", userId=" + userId + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -285,9 +296,10 @@ public List getUsers(String domain, int offset, int limit) throws SharingR filters.put(DBConstants.UserTable.DOMAIN_ID, domain); return (new UserRepository()).select(filters, offset, limit); } catch (Throwable ex) { - logger.error("Error while getting users: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while getting users: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while getting users: domain=" + domain + ", offset=" + offset + ", limit=" + limit + + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -317,9 +329,10 @@ public String createGroup(UserGroup group) throws SharingRegistryException { } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - logger.error("Error while creating group: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while creating group: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while creating group: groupId=" + group.getGroupId() + ", domainId=" + + group.getDomainId() + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -344,9 +357,10 @@ public boolean updateGroup(UserGroup group) throws SharingRegistryException { } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - logger.error("Error while updating group: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while updating group: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while updating group: groupId=" + group.getGroupId() + ", domainId=" + + group.getDomainId() + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -359,9 +373,10 @@ public boolean isGroupExists(String domainId, String groupId) throws SharingRegi userGroupPK.setGroupId(groupId); return (new UserGroupRepository()).isExists(userGroupPK); } catch (Throwable ex) { - logger.error("Error while checking if group exists: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while checking if group exists: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while checking if group exists: domainId=" + domainId + ", groupId=" + groupId + ", " + + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -375,9 +390,10 @@ public boolean deleteGroup(String domainId, String groupId) throws SharingRegist (new UserGroupRepository()).delete(userGroupPK); return true; } catch (Throwable ex) { - logger.error("Error while deleting group: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while deleting group: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while deleting group: domainId=" + domainId + ", groupId=" + groupId + ", " + + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -390,9 +406,10 @@ public UserGroup getGroup(String domainId, String groupId) throws SharingRegistr userGroupPK.setDomainId(domainId); return (new UserGroupRepository()).get(userGroupPK); } catch (Throwable ex) { - logger.error("Error while getting group: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while getting group: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = + "Error while getting group: domainId=" + domainId + ", groupId=" + groupId + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -407,9 +424,10 @@ public List getGroups(String domain, int offset, int limit) throws Sh filters.put(DBConstants.UserGroupTable.GROUP_CARDINALITY, GroupCardinality.MULTI_USER.name()); return (new UserGroupRepository()).select(filters, offset, limit); } catch (Throwable ex) { - logger.error("Error while getting groups: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while getting groups: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while getting groups: domain=" + domain + ", offset=" + offset + ", limit=" + limit + + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -430,9 +448,10 @@ public boolean addUsersToGroup(String domainId, List userIds, String gro } return true; } catch (Throwable ex) { - logger.error("Error while adding users to group: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while adding users to group: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while adding users to group: domainId=" + domainId + ", userIds=" + userIds + + ", groupId=" + groupId + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -459,9 +478,10 @@ public boolean removeUsersFromGroup(String domainId, List userIds, Strin } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - logger.error("Error while removing users from group: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while removing users from group: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while removing users from group: domainId=" + domainId + ", userIds=" + userIds + + ", groupId=" + groupId + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -500,10 +520,10 @@ public boolean transferGroupOwnership(String domainId, String groupId, String ne } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - logger.error("Error while transferring group ownership: " + ex.getMessage(), ex); - SharingRegistryException exception = - new SharingRegistryException("Error while transferring group ownership: " + ex.getMessage() - + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while transferring group ownership: domainId=" + domainId + ", groupId=" + groupId + + ", newOwnerId=" + newOwnerId + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -546,9 +566,10 @@ public boolean addGroupAdmins(String domainId, String groupId, List admi } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - logger.error("Error while adding group admins: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while adding group admins: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while adding group admins: domainId=" + domainId + ", groupId=" + groupId + + ", adminIds=" + adminIds + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -566,9 +587,10 @@ public boolean removeGroupAdmins(String domainId, String groupId, List a } return true; } catch (Throwable ex) { - logger.error("Error while removing group admins: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while removing group admins: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while removing group admins: domainId=" + domainId + ", groupId=" + groupId + + ", adminIds=" + adminIds + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -584,9 +606,10 @@ public boolean hasAdminAccess(String domainId, String groupId, String adminId) t if ((new GroupAdminRepository()).get(groupAdminPK) != null) return true; return false; } catch (Throwable ex) { - logger.error("Error while checking admin access: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while checking admin access: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while checking admin access: domainId=" + domainId + ", groupId=" + groupId + + ", adminId=" + adminId + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -602,9 +625,10 @@ public boolean hasOwnerAccess(String domainId, String groupId, String ownerId) t if (getGroup.getOwnerId().equals(ownerId)) return true; return false; } catch (Throwable ex) { - logger.error("Error while checking owner access: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while checking owner access: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while checking owner access: domainId=" + domainId + ", groupId=" + groupId + + ", ownerId=" + ownerId + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -617,10 +641,10 @@ public List getGroupMembersOfTypeUser(String domainId, String groupId, int List groupMemberUsers = (new GroupMembershipRepository()).getAllChildUsers(domainId, groupId); return groupMemberUsers; } catch (Throwable ex) { - logger.error("Error while getting group members of type user: " + ex.getMessage(), ex); - SharingRegistryException exception = - new SharingRegistryException("Error while getting group members of type user: " + ex.getMessage() - + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while getting group members of type user: domainId=" + domainId + ", groupId=" + groupId + + ", offset=" + offset + ", limit=" + limit + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -633,10 +657,10 @@ public List getGroupMembersOfTypeGroup(String domainId, String groupI List groupMemberGroups = (new GroupMembershipRepository()).getAllChildGroups(domainId, groupId); return groupMemberGroups; } catch (Throwable ex) { - logger.error("Error while getting group members of type group: " + ex.getMessage(), ex); - SharingRegistryException exception = - new SharingRegistryException("Error while getting group members of type group: " + ex.getMessage() - + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while getting group members of type group: domainId=" + domainId + ", groupId=" + + groupId + ", offset=" + offset + ", limit=" + limit + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -658,10 +682,10 @@ public boolean addChildGroupsToParentGroup(String domainId, List childId } return true; } catch (Throwable ex) { - logger.error("Error while adding child groups to parent group: " + ex.getMessage(), ex); - SharingRegistryException exception = - new SharingRegistryException("Error while adding child groups to parent group: " + ex.getMessage() - + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while adding child groups to parent group: domainId=" + domainId + ", childIds=" + + childIds + ", groupId=" + groupId + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -677,10 +701,10 @@ public boolean removeChildGroupFromParentGroup(String domainId, String childId, (new GroupMembershipRepository()).delete(groupMembershipPK); return true; } catch (Throwable ex) { - logger.error("Error while removing child group from parent group: " + ex.getMessage(), ex); - SharingRegistryException exception = - new SharingRegistryException("Error while removing child group from parent group: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while removing child group from parent group: domainId=" + domainId + ", childId=" + + childId + ", groupId=" + groupId + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -691,10 +715,10 @@ public List getAllMemberGroupsForUser(String domainId, String userId) GroupMembershipRepository groupMembershipRepository = new GroupMembershipRepository(); return groupMembershipRepository.getAllMemberGroupsForUser(domainId, userId); } catch (Throwable ex) { - logger.error("Error while getting all member groups for user: " + ex.getMessage(), ex); - SharingRegistryException exception = - new SharingRegistryException("Error while getting all member groups for user: " + ex.getMessage() - + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while getting all member groups for user: domainId=" + domainId + ", userId=" + userId + + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -719,9 +743,10 @@ public String createEntityType(EntityType entityType) throws SharingRegistryExce } catch (SharingRegistryException | DuplicateEntryException e) { throw e; } catch (Throwable ex) { - logger.error("Error while creating entity type: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while creating entity type: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while creating entity type: entityTypeId=" + entityType.getEntityTypeId() + + ", domainId=" + entityType.getDomainId() + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -741,9 +766,10 @@ public boolean updateEntityType(EntityType entityType) throws SharingRegistryExc } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - logger.error("Error while updating entity type: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while updating entity type: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while updating entity type: entityTypeId=" + entityType.getEntityTypeId() + + ", domainId=" + entityType.getDomainId() + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -756,10 +782,10 @@ public boolean isEntityTypeExists(String domainId, String entityTypeId) throws S entityTypePK.setEntityTypeId(entityTypeId); return (new EntityTypeRepository()).isExists(entityTypePK); } catch (Throwable ex) { - logger.error("Error while checking if entity type exists: " + ex.getMessage(), ex); - SharingRegistryException exception = - new SharingRegistryException("Error while checking if entity type exists: " + ex.getMessage() - + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while checking if entity type exists: domainId=" + domainId + ", entityTypeId=" + + entityTypeId + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -773,9 +799,10 @@ public boolean deleteEntityType(String domainId, String entityTypeId) throws Sha (new EntityTypeRepository()).delete(entityTypePK); return true; } catch (Throwable ex) { - logger.error("Error while deleting entity type: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while deleting entity type: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while deleting entity type: domainId=" + domainId + ", entityTypeId=" + entityTypeId + + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -788,9 +815,10 @@ public EntityType getEntityType(String domainId, String entityTypeId) throws Sha entityTypePK.setEntityTypeId(entityTypeId); return (new EntityTypeRepository()).get(entityTypePK); } catch (Throwable ex) { - logger.error("Error while getting entity type: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while getting entity type: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while getting entity type: domainId=" + domainId + ", entityTypeId=" + entityTypeId + + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -802,9 +830,10 @@ public List getEntityTypes(String domain, int offset, int limit) thr filters.put(DBConstants.EntityTypeTable.DOMAIN_ID, domain); return (new EntityTypeRepository()).select(filters, offset, limit); } catch (Throwable ex) { - logger.error("Error while getting entity types: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while getting entity types: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while getting entity types: domain=" + domain + ", offset=" + offset + ", limit=" + + limit + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -829,9 +858,11 @@ public String createPermissionType(PermissionType permissionType) } catch (SharingRegistryException | DuplicateEntryException e) { throw e; } catch (Throwable ex) { - logger.error("Error while creating permission type: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while creating permission type: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = + "Error while creating permission type: permissionTypeId=" + permissionType.getPermissionTypeId() + + ", domainId=" + permissionType.getDomainId() + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -850,9 +881,11 @@ public boolean updatePermissionType(PermissionType permissionType) throws Sharin } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - logger.error("Error while updating permission type: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while updating permission type: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = + "Error while updating permission type: permissionTypeId=" + permissionType.getPermissionTypeId() + + ", domainId=" + permissionType.getDomainId() + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -865,10 +898,10 @@ public boolean isPermissionExists(String domainId, String permissionId) throws S permissionTypePK.setPermissionTypeId(permissionId); return (new PermissionTypeRepository()).isExists(permissionTypePK); } catch (Throwable ex) { - logger.error("Error while checking if permission exists: " + ex.getMessage(), ex); - SharingRegistryException exception = - new SharingRegistryException("Error while checking if permission exists: " + ex.getMessage() - + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while checking if permission exists: domainId=" + domainId + ", permissionId=" + + permissionId + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -882,9 +915,10 @@ public boolean deletePermissionType(String domainId, String permissionTypeId) th (new PermissionTypeRepository()).delete(permissionTypePK); return true; } catch (Throwable ex) { - logger.error("Error while deleting permission type: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while deleting permission type: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while deleting permission type: domainId=" + domainId + ", permissionTypeId=" + + permissionTypeId + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -897,9 +931,10 @@ public PermissionType getPermissionType(String domainId, String permissionTypeId permissionTypePK.setPermissionTypeId(permissionTypeId); return (new PermissionTypeRepository()).get(permissionTypePK); } catch (Throwable ex) { - logger.error("Error while getting permission type: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while getting permission type: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while getting permission type: domainId=" + domainId + ", permissionTypeId=" + + permissionTypeId + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -912,9 +947,10 @@ public List getPermissionTypes(String domain, int offset, int li filters.put(DBConstants.PermissionTypeTable.DOMAIN_ID, domain); return (new PermissionTypeRepository()).select(filters, offset, limit); } catch (Throwable ex) { - logger.error("Error while getting permission types: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while getting permission types: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while getting permission types: domain=" + domain + ", offset=" + offset + ", limit=" + + limit + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -975,9 +1011,10 @@ public String createEntity(Entity entity) throws SharingRegistryException, Dupli } catch (SharingRegistryException | DuplicateEntryException e) { throw e; } catch (Throwable ex) { - logger.error("Error while creating entity: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while creating entity: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while creating entity: entityId=" + entity.getEntityId() + ", domainId=" + + entity.getDomainId() + ", ownerId=" + entity.getOwnerId() + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -1004,10 +1041,11 @@ private void addCascadingPermissionsForEntity(Entity entity) throws SharingRegis } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - logger.error("Error while adding cascading permissions for entity: " + ex.getMessage(), ex); - SharingRegistryException exception = - new SharingRegistryException("Error while adding cascading permissions for entity: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while adding cascading permissions for entity: entityId=" + entity.getEntityId() + + ", domainId=" + entity.getDomainId() + ", parentEntityId=" + entity.getParentEntityId() + ", " + + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -1049,9 +1087,10 @@ public boolean updateEntity(Entity entity) throws SharingRegistryException { } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - logger.error("Error while updating entity: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while updating entity: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while updating entity: entityId=" + entity.getEntityId() + ", domainId=" + + entity.getDomainId() + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -1064,9 +1103,10 @@ public boolean isEntityExists(String domainId, String entityId) throws SharingRe entityPK.setEntityId(entityId); return (new EntityRepository()).isExists(entityPK); } catch (Throwable ex) { - logger.error("Error while checking if entity exists: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while checking if entity exists: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while checking if entity exists: domainId=" + domainId + ", entityId=" + entityId + ", " + + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -1081,9 +1121,10 @@ public boolean deleteEntity(String domainId, String entityId) throws SharingRegi (new EntityRepository()).delete(entityPK); return true; } catch (Throwable ex) { - logger.error("Error while deleting entity: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while deleting entity: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while deleting entity: domainId=" + domainId + ", entityId=" + entityId + ", " + + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -1096,9 +1137,10 @@ public Entity getEntity(String domainId, String entityId) throws SharingRegistry entityPK.setEntityId(entityId); return (new EntityRepository()).get(entityPK); } catch (Throwable ex) { - logger.error("Error while getting entity: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while getting entity: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while getting entity: domainId=" + domainId + ", entityId=" + entityId + ", " + + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -1115,9 +1157,10 @@ public List searchEntities( .forEach(gm -> groupIds.add(gm.getParentId())); return (new EntityRepository()).searchEntities(domainId, groupIds, filters, offset, limit); } catch (Throwable ex) { - logger.error("Error while searching entities: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while searching entities: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while searching entities: domainId=" + domainId + ", userId=" + userId + ", filters=" + + filters + ", offset=" + offset + ", limit=" + limit + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -1128,10 +1171,10 @@ public List getListOfSharedUsers(String domainId, String entityId, String try { return (new UserRepository()).getAccessibleUsers(domainId, entityId, permissionTypeId); } catch (Throwable ex) { - logger.error("Error while getting list of shared users: " + ex.getMessage(), ex); - SharingRegistryException exception = - new SharingRegistryException("Error while getting list of shared users: " + ex.getMessage() - + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while getting list of shared users: domainId=" + domainId + ", entityId=" + entityId + + ", permissionTypeId=" + permissionTypeId + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -1142,10 +1185,10 @@ public List getListOfDirectlySharedUsers(String domainId, String entityId, try { return (new UserRepository()).getDirectlyAccessibleUsers(domainId, entityId, permissionTypeId); } catch (Throwable ex) { - logger.error("Error while getting list of directly shared users: " + ex.getMessage(), ex); - SharingRegistryException exception = - new SharingRegistryException("Error while getting list of directly shared users: " + ex.getMessage() - + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while getting list of directly shared users: domainId=" + domainId + ", entityId=" + + entityId + ", permissionTypeId=" + permissionTypeId + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -1156,10 +1199,10 @@ public List getListOfSharedGroups(String domainId, String entityId, S try { return (new UserGroupRepository()).getAccessibleGroups(domainId, entityId, permissionTypeId); } catch (Throwable ex) { - logger.error("Error while getting list of shared groups: " + ex.getMessage(), ex); - SharingRegistryException exception = - new SharingRegistryException("Error while getting list of shared groups: " + ex.getMessage() - + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while getting list of shared groups: domainId=" + domainId + ", entityId=" + entityId + + ", permissionTypeId=" + permissionTypeId + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -1170,10 +1213,10 @@ public List getListOfDirectlySharedGroups(String domainId, String ent try { return (new UserGroupRepository()).getDirectlyAccessibleGroups(domainId, entityId, permissionTypeId); } catch (Throwable ex) { - logger.error("Error while getting list of directly shared groups: " + ex.getMessage(), ex); - SharingRegistryException exception = - new SharingRegistryException("Error while getting list of directly shared groups: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while getting list of directly shared groups: domainId=" + domainId + ", entityId=" + + entityId + ", permissionTypeId=" + permissionTypeId + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -1187,9 +1230,11 @@ public boolean shareEntityWithUsers( } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - logger.error("Error while sharing entity with users: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while sharing entity with users: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while sharing entity with users: domainId=" + domainId + ", entityId=" + entityId + + ", userList=" + userList + ", permissionTypeId=" + permissionTypeId + ", cascadePermission=" + + cascadePermission + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -1207,9 +1252,11 @@ public boolean shareEntityWithGroups( } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - logger.error("Error while sharing entity with groups: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while sharing entity with groups: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while sharing entity with groups: domainId=" + domainId + ", entityId=" + entityId + + ", groupList=" + groupList + ", permissionTypeId=" + permissionTypeId + ", cascadePermission=" + + cascadePermission + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -1286,9 +1333,11 @@ private boolean shareEntity( } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - logger.error("Error while sharing entity: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while sharing entity: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while sharing entity: domainId=" + domainId + ", entityId=" + entityId + + ", groupOrUserList=" + groupOrUserList + ", permissionTypeId=" + permissionTypeId + + ", cascadePermission=" + cascadePermission + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -1305,10 +1354,11 @@ public boolean revokeEntitySharingFromUsers( } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - logger.error("Error while revoking entity sharing from users: " + ex.getMessage(), ex); - SharingRegistryException exception = - new SharingRegistryException("Error while revoking entity sharing from users: " + ex.getMessage() - + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while revoking entity sharing from users: domainId=" + domainId + ", entityId=" + + entityId + ", userList=" + userList + ", permissionTypeId=" + permissionTypeId + ", " + + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -1325,10 +1375,11 @@ public boolean revokeEntitySharingFromGroups( } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - logger.error("Error while revoking entity sharing from groups: " + ex.getMessage(), ex); - SharingRegistryException exception = - new SharingRegistryException("Error while revoking entity sharing from groups: " + ex.getMessage() - + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while revoking entity sharing from groups: domainId=" + domainId + ", entityId=" + + entityId + ", groupList=" + groupList + ", permissionTypeId=" + permissionTypeId + ", " + + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -1352,9 +1403,10 @@ public boolean userHasAccess(String domainId, String userId, String entityId, St permissionTypeId, (new PermissionTypeRepository()).getOwnerPermissionTypeIdForDomain(domainId))); } catch (Throwable ex) { - logger.error("Error while checking user access: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while checking user access: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while checking user access: domainId=" + domainId + ", userId=" + userId + ", entityId=" + + entityId + ", permissionTypeId=" + permissionTypeId + ", " + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } @@ -1409,9 +1461,11 @@ public boolean revokeEntitySharing( } catch (SharingRegistryException e) { throw e; } catch (Throwable ex) { - logger.error("Error while revoking entity sharing: " + ex.getMessage(), ex); - SharingRegistryException exception = new SharingRegistryException("Error while revoking entity sharing: " - + ex.getMessage() + " Stack trace:" + ExceptionUtils.getStackTrace(ex)); + String msg = "Error while revoking entity sharing: domainId=" + domainId + ", entityId=" + entityId + + ", groupOrUserList=" + groupOrUserList + ", permissionTypeId=" + permissionTypeId + ", " + + ex.getMessage(); + logger.error(msg, ex); + var exception = new SharingRegistryException(msg); exception.initCause(ex); throw exception; } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/TenantProfileService.java b/airavata-api/src/main/java/org/apache/airavata/service/TenantProfileService.java index bffdd00c19..f9d9e72272 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/TenantProfileService.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/TenantProfileService.java @@ -24,10 +24,6 @@ import org.apache.airavata.common.exception.ApplicationSettingsException; import org.apache.airavata.common.utils.Constants; import org.apache.airavata.common.utils.DBEventService; -import org.apache.airavata.common.utils.ServerSettings; -import org.apache.airavata.credential.store.client.CredentialStoreClientFactory; -import org.apache.airavata.credential.store.cpi.CredentialStoreService; -import org.apache.airavata.credential.store.exception.CredentialStoreException; import org.apache.airavata.messaging.core.util.DBEventPublisherUtils; import org.apache.airavata.model.credential.store.PasswordCredential; import org.apache.airavata.model.dbevent.CrudType; @@ -47,10 +43,23 @@ public class TenantProfileService { private TenantProfileRepository tenantProfileRepository; private DBEventPublisherUtils dbEventPublisherUtils = new DBEventPublisherUtils(DBEventService.TENANT); + private CredentialStoreService credentialStoreService; - public TenantProfileService() { + public TenantProfileService() throws TenantProfileServiceException { logger.debug("Initializing TenantProfileService"); this.tenantProfileRepository = new TenantProfileRepository(Gateway.class, GatewayEntity.class); + try { + this.credentialStoreService = new CredentialStoreService(); + } catch (ApplicationSettingsException + | IllegalAccessException + | ClassNotFoundException + | InstantiationException e) { + String msg = "Error initializing TenantProfileService, reason: " + e.getMessage(); + logger.error(msg, e); + var exception = new TenantProfileServiceException(msg); + exception.initCause(e); + throw exception; + } } public String addGateway(AuthzToken authzToken, Gateway gateway) throws TenantProfileServiceException { @@ -219,32 +228,20 @@ private boolean checkDuplicateGateway(Gateway gateway) throws TenantProfileServi // copied to a credential that is stored in the requested/newly created gateway private void copyAdminPasswordToGateway(AuthzToken authzToken, Gateway gateway) throws TException, ApplicationSettingsException { - CredentialStoreService.Client csClient = getCredentialStoreServiceClient(); try { String requestGatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID); - PasswordCredential adminPasswordCredential = - csClient.getPasswordCredential(gateway.getIdentityServerPasswordToken(), requestGatewayId); + PasswordCredential adminPasswordCredential = credentialStoreService.getPasswordCredential( + gateway.getIdentityServerPasswordToken(), requestGatewayId); adminPasswordCredential.setGatewayId(gateway.getGatewayId()); - String newAdminPasswordCredentialToken = csClient.addPasswordCredential(adminPasswordCredential); + String newAdminPasswordCredentialToken = + credentialStoreService.addPasswordCredential(adminPasswordCredential); gateway.setIdentityServerPasswordToken(newAdminPasswordCredentialToken); - } finally { - if (csClient.getInputProtocol().getTransport().isOpen()) { - csClient.getInputProtocol().getTransport().close(); - } - if (csClient.getOutputProtocol().getTransport().isOpen()) { - csClient.getOutputProtocol().getTransport().close(); - } - } - } - - private CredentialStoreService.Client getCredentialStoreServiceClient() - throws TException, ApplicationSettingsException { - final int serverPort = Integer.parseInt(ServerSettings.getCredentialStoreServerPort()); - final String serverHost = ServerSettings.getCredentialStoreServerHost(); - try { - return CredentialStoreClientFactory.createAiravataCSClient(serverHost, serverPort); - } catch (CredentialStoreException e) { - throw new TException("Unable to create credential store client...", e); + } catch (Exception ex) { + String msg = "Error copying admin password to gateway, reason: " + ex.getMessage(); + logger.error(msg, ex); + var exception = new TenantProfileServiceException(msg); + exception.initCause(ex); + throw exception; } } } diff --git a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/IamAdminServicesHandler.java b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/IamAdminServicesHandler.java index 5fb4ebc0a8..de517b7358 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/IamAdminServicesHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/IamAdminServicesHandler.java @@ -25,17 +25,29 @@ import org.apache.airavata.model.security.AuthzToken; import org.apache.airavata.model.user.UserProfile; import org.apache.airavata.model.workspace.Gateway; +import org.apache.airavata.service.IamAdminService; import org.apache.airavata.service.profile.iam.admin.services.cpi.IamAdminServices; import org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException; import org.apache.airavata.service.profile.iam.admin.services.cpi.iam_admin_services_cpiConstants; import org.apache.airavata.service.security.interceptor.SecurityCheck; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class IamAdminServicesHandler implements IamAdminServices.Iface { - private org.apache.airavata.service.IamAdminService iamAdminService; - - public IamAdminServicesHandler() { - iamAdminService = new org.apache.airavata.service.IamAdminService(); + private static final Logger logger = LoggerFactory.getLogger(IamAdminServicesHandler.class); + private IamAdminService iamAdminService; + + public IamAdminServicesHandler() throws IamAdminServicesException { + try { + iamAdminService = new org.apache.airavata.service.IamAdminService(); + } catch (Throwable e) { + String msg = "Error initializing IamAdminServicesHandler, reason: " + e.getMessage(); + logger.error(msg, e); + var exception = new IamAdminServicesException(msg); + exception.initCause(e); + throw exception; + } } @Override diff --git a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/TenantProfileServiceHandler.java b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/TenantProfileServiceHandler.java index 26b9bddc6e..d9d6d0643d 100644 --- a/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/TenantProfileServiceHandler.java +++ b/airavata-api/src/main/java/org/apache/airavata/service/profile/handlers/TenantProfileServiceHandler.java @@ -39,9 +39,17 @@ public class TenantProfileServiceHandler implements TenantProfileService.Iface { private static final Logger logger = LoggerFactory.getLogger(TenantProfileServiceHandler.class); private org.apache.airavata.service.TenantProfileService tenantProfileService; - public TenantProfileServiceHandler() { + public TenantProfileServiceHandler() throws TenantProfileServiceException { logger.debug("Initializing TenantProfileServiceHandler"); - tenantProfileService = new org.apache.airavata.service.TenantProfileService(); + try { + tenantProfileService = new org.apache.airavata.service.TenantProfileService(); + } catch (Throwable e) { + String msg = "Error initializing TenantProfileServiceHandler, reason: " + e.getMessage(); + logger.error(msg, e); + var exception = new TenantProfileServiceException(msg); + exception.initCause(e); + throw exception; + } } @Override