adding backend functionality for notifications
Project: http://git-wip-us.apache.org/repos/asf/airavata/repo Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/47290ad1 Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/47290ad1 Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/47290ad1 Branch: refs/heads/master Commit: 47290ad1545187e0ab6b970575896d2ff76fb2cd Parents: 4a1e79f Author: scnakandala <[email protected]> Authored: Fri Apr 22 15:14:11 2016 -0400 Committer: scnakandala <[email protected]> Committed: Fri Apr 22 15:14:12 2016 -0400 ---------------------------------------------------------------------- .../server/handler/AiravataServerHandler.java | 87 + .../handler/AiravataServerHandlerTest.java | 22 + .../java/org/apache/airavata/api/Airavata.java | 15220 ++++++++++++----- .../main/resources/lib/airavata/Airavata.cpp | 5355 ++++-- .../src/main/resources/lib/airavata/Airavata.h | 1172 +- .../lib/airavata/Airavata_server.skeleton.cpp | 32 + .../lib/airavata/workspace_model_types.cpp | 201 + .../lib/airavata/workspace_model_types.h | 81 + .../resources/lib/Airavata/API/Airavata.php | 3062 +++- .../lib/Airavata/Model/Workspace/Types.php | 190 + .../lib/apache/airavata/api/Airavata-remote | 35 + .../lib/apache/airavata/api/Airavata.py | 2754 ++- .../apache/airavata/model/workspace/ttypes.py | 136 + .../apache/airavata/model/ComponentStatus.java | 2 +- .../org/apache/airavata/model/EdgeModel.java | 2 +- .../org/apache/airavata/model/NodeModel.java | 2 +- .../org/apache/airavata/model/PortModel.java | 2 +- .../apache/airavata/model/WorkflowModel.java | 2 +- .../apache/airavata/model/WorkflowStatus.java | 2 +- .../ApplicationDeploymentDescription.java | 2 +- .../appdeployment/ApplicationModule.java | 2 +- .../appcatalog/appdeployment/CommandObject.java | 2 +- .../appcatalog/appdeployment/SetEnvPaths.java | 2 +- .../ApplicationInterfaceDescription.java | 2 +- .../appcatalog/computeresource/BatchQueue.java | 2 +- .../computeresource/CloudJobSubmission.java | 2 +- .../ComputeResourceDescription.java | 2 +- .../computeresource/GlobusJobSubmission.java | 2 +- .../computeresource/JobSubmissionInterface.java | 2 +- .../computeresource/LOCALSubmission.java | 2 +- .../computeresource/ResourceJobManager.java | 2 +- .../computeresource/SSHJobSubmission.java | 2 +- .../computeresource/UnicoreJobSubmission.java | 2 +- .../ComputeResourcePreference.java | 2 +- .../gatewayprofile/GatewayResourceProfile.java | 2 +- .../gatewayprofile/StoragePreference.java | 2 +- .../StorageResourceDescription.java | 2 +- .../application/io/InputDataObjectType.java | 2 +- .../application/io/OutputDataObjectType.java | 2 +- .../airavata/model/commons/ErrorModel.java | 2 +- .../model/commons/ValidationResults.java | 2 +- .../airavata/model/commons/ValidatorResult.java | 2 +- .../data/movement/DataMovementInterface.java | 2 +- .../data/movement/GridFTPDataMovement.java | 2 +- .../model/data/movement/LOCALDataMovement.java | 2 +- .../model/data/movement/SCPDataMovement.java | 2 +- .../data/movement/UnicoreDataMovement.java | 2 +- .../model/data/replica/DataProductModel.java | 2 +- .../data/replica/DataReplicaLocationModel.java | 2 +- .../model/error/AiravataClientException.java | 2 +- .../model/error/AiravataSystemException.java | 2 +- .../model/error/AuthenticationException.java | 2 +- .../model/error/AuthorizationException.java | 2 +- .../error/ExperimentNotFoundException.java | 2 +- .../model/error/InvalidRequestException.java | 2 +- .../model/error/LaunchValidationException.java | 2 +- .../model/error/ProjectNotFoundException.java | 2 +- .../airavata/model/error/TimedOutException.java | 2 +- .../airavata/model/error/ValidationResults.java | 2 +- .../airavata/model/error/ValidatorResult.java | 2 +- .../model/experiment/ExperimentModel.java | 2 +- .../model/experiment/ExperimentStatistics.java | 2 +- .../experiment/ExperimentSummaryModel.java | 2 +- .../experiment/UserConfigurationDataModel.java | 2 +- .../org/apache/airavata/model/job/JobModel.java | 2 +- .../event/ExperimentStatusChangeEvent.java | 2 +- .../model/messaging/event/JobIdentifier.java | 2 +- .../messaging/event/JobStatusChangeEvent.java | 2 +- .../event/JobStatusChangeRequestEvent.java | 2 +- .../airavata/model/messaging/event/Message.java | 2 +- .../messaging/event/ProcessIdentifier.java | 2 +- .../event/ProcessStatusChangeEvent.java | 2 +- .../event/ProcessStatusChangeRequestEvent.java | 2 +- .../messaging/event/ProcessSubmitEvent.java | 2 +- .../messaging/event/ProcessTerminateEvent.java | 2 +- .../model/messaging/event/TaskIdentifier.java | 2 +- .../messaging/event/TaskOutputChangeEvent.java | 2 +- .../messaging/event/TaskStatusChangeEvent.java | 2 +- .../event/TaskStatusChangeRequestEvent.java | 2 +- .../airavata/model/process/ProcessModel.java | 2 +- .../ComputationalResourceSchedulingModel.java | 2 +- .../airavata/model/security/AuthzToken.java | 2 +- .../airavata/model/status/ExperimentStatus.java | 2 +- .../apache/airavata/model/status/JobStatus.java | 2 +- .../airavata/model/status/ProcessStatus.java | 2 +- .../airavata/model/status/TaskStatus.java | 2 +- .../model/task/DataStagingTaskModel.java | 2 +- .../model/task/EnvironmentSetupTaskModel.java | 2 +- .../model/task/JobSubmissionTaskModel.java | 2 +- .../airavata/model/task/MonitorTaskModel.java | 2 +- .../apache/airavata/model/task/TaskModel.java | 2 +- .../airavata/model/workspace/Gateway.java | 2 +- .../apache/airavata/model/workspace/Group.java | 2 +- .../airavata/model/workspace/Project.java | 2 +- .../apache/airavata/model/workspace/User.java | 2 +- .../core/experiment/catalog/ResourceType.java | 1 + .../catalog/impl/ExperimentCatalogImpl.java | 17 + .../catalog/impl/NotificationRegistry.java | 87 + .../core/experiment/catalog/impl/UserReg.java | 41 - .../experiment/catalog/impl/UserRegistry.java | 41 + .../experiment/catalog/model/Notification.java | 98 + .../resources/AbstractExpCatResource.java | 7 + .../catalog/resources/NotificationResource.java | 267 + .../experiment/catalog/resources/Utils.java | 21 + .../utils/ThriftDataModelConversion.java | 17 + .../src/main/resources/META-INF/persistence.xml | 1 + .../src/main/resources/expcatalog-derby.sql | 11 + .../src/main/resources/expcatalog-mysql.sql | 11 + .../registry/cpi/ExpCatParentDataType.java | 3 +- .../cpi/ExperimentCatalogModelType.java | 1 + .../airavata-apis/airavata_api.thrift | 33 + .../workspace_model.thrift | 9 + 112 files changed, 22218 insertions(+), 6959 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/airavata/blob/47290ad1/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java b/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java index a176573..cfcd5d1 100644 --- a/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java +++ b/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java @@ -64,6 +64,7 @@ import org.apache.airavata.model.status.ExperimentStatus; import org.apache.airavata.model.status.JobStatus; import org.apache.airavata.model.task.TaskModel; 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.orchestrator.client.OrchestratorClientFactory; import org.apache.airavata.orchestrator.cpi.OrchestratorService; @@ -279,6 +280,92 @@ public class AiravataServerHandler implements Airavata.Iface { } } + /** + * * API methods to retrieve notifications + * * + * + * @param authzToken + * @param notification + */ + @Override + public String createNotification(AuthzToken authzToken, Notification notification) throws InvalidRequestException, + AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + experimentCatalog = RegistryFactory.getExperimentCatalog(notification.getGatewayId()); + return (String) experimentCatalog.add(ExpCatParentDataType.NOTIFICATION, notification, notification.getGatewayId()); + } catch (RegistryException 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; + } + } + + @Override + public void updateNotification(AuthzToken authzToken, Notification notification) throws InvalidRequestException, + AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + experimentCatalog = RegistryFactory.getExperimentCatalog(notification.getGatewayId()); + experimentCatalog.update(ExperimentCatalogModelType.NOTIFICATION, notification, notification.getGatewayId()); + } catch (RegistryException 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()); + throw exception; + } + } + + @Override + public void deleteNotification(AuthzToken authzToken, String gatewayId, String notificationId) throws InvalidRequestException, + AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + experimentCatalog = RegistryFactory.getExperimentCatalog(gatewayId); + experimentCatalog.remove(ExperimentCatalogModelType.NOTIFICATION, notificationId); + } catch (RegistryException 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; + } + } + + @Override + public Notification getNotification(AuthzToken authzToken, String gatewayId, String notificationId) throws InvalidRequestException, + AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + experimentCatalog = RegistryFactory.getExperimentCatalog(gatewayId); + return (Notification)experimentCatalog.get(ExperimentCatalogModelType.NOTIFICATION, notificationId); + } catch (RegistryException 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; + } + } + + @Override + public List<Notification> getAllNotifications(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, + AiravataClientException, AiravataSystemException, AuthorizationException, TException { + try { + experimentCatalog = RegistryFactory.getExperimentCatalog(gatewayId); + List<Object> objectList = experimentCatalog.get(ExperimentCatalogModelType.NOTIFICATION, null, gatewayId); + List<Notification> notifications = new ArrayList<>(); + for(Object o : objectList) + notifications.add((Notification) o); + return notifications; + } catch (RegistryException 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; + } + } + /*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{ http://git-wip-us.apache.org/repos/asf/airavata/blob/47290ad1/airavata-api/airavata-api-server/src/test/java/org/apache/airavata/api/server/handler/AiravataServerHandlerTest.java ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-api-server/src/test/java/org/apache/airavata/api/server/handler/AiravataServerHandlerTest.java b/airavata-api/airavata-api-server/src/test/java/org/apache/airavata/api/server/handler/AiravataServerHandlerTest.java index 453d17d..081d15c 100644 --- a/airavata-api/airavata-api-server/src/test/java/org/apache/airavata/api/server/handler/AiravataServerHandlerTest.java +++ b/airavata-api/airavata-api-server/src/test/java/org/apache/airavata/api/server/handler/AiravataServerHandlerTest.java @@ -35,7 +35,9 @@ 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.workspace.Gateway; +import org.apache.airavata.model.workspace.Notification; import org.apache.airavata.model.workspace.Project; +import org.apache.thrift.TException; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -308,4 +310,24 @@ public class AiravataServerHandlerTest { Assert.fail(); } } + + @Test + public void testNotifications(){ + try { + AuthzToken authzToken = new AuthzToken(); + authzToken.setAccessToken(""); + Notification notification = new Notification(); + notification.setTitle("3424234"); + notification.setGatewayId("test"); + notification.setNotifcationMessage("sdkjfbjks kjbsdf kjsdbfkjsdbf"); + String notificationId = airavataServerHandler.createNotification(authzToken, notification); + Assert.assertNotNull(notificationId); + List<Notification> notifications = airavataServerHandler.getAllNotifications(authzToken, "test"); + Assert.assertTrue(notifications.size() > 0); + Assert.assertNotNull(airavataServerHandler.getNotification(authzToken,"test",notificationId)); + } catch (TException e) { + e.printStackTrace(); + Assert.fail(); + } + } } \ No newline at end of file
