http://git-wip-us.apache.org/repos/asf/airavata/blob/801489bf/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/mongo/dao/ProjectDao.java ---------------------------------------------------------------------- diff --git a/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/mongo/dao/ProjectDao.java b/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/mongo/dao/ProjectDao.java new file mode 100644 index 0000000..ecffac4 --- /dev/null +++ b/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/mongo/dao/ProjectDao.java @@ -0,0 +1,189 @@ +/* + * + * 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.persistance.registry.mongo.dao; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.mongodb.*; +import com.mongodb.util.JSON; +import org.apache.airavata.model.workspace.Project; +import org.apache.airavata.persistance.registry.mongo.conversion.ModelConversionHelper; +import org.apache.airavata.persistance.registry.mongo.utils.MongoUtil; +import org.apache.airavata.registry.cpi.RegistryException; +import org.apache.airavata.registry.cpi.ResultOrderType; +import org.apache.airavata.registry.cpi.utils.Constants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class ProjectDao { + private final static Logger logger = LoggerFactory.getLogger(ProjectDao.class); + + private static final String PROJECTS_COLLECTION_NAME = "projects"; + private DBCollection collection; + private ModelConversionHelper modelConversionHelper; + + private static final String PROJECT_ID = "project_id"; + private static final String PROJECT_NAME = "name"; + private static final String PROJECT_DESCRIPTION = "description"; + private static final String PROJECT_OWNER = "owner"; + private static final String PROJECT_CREATION_TIME = "creation_time"; + + public ProjectDao(){ + collection = MongoUtil.getAiravataRegistry().getCollection(PROJECTS_COLLECTION_NAME); + modelConversionHelper = new ModelConversionHelper(); + collection.dropIndexes(); + initIndexes(); + } + + /** + * If indexes are already defined this will simply ignore them + */ + private void initIndexes(){ + collection.createIndex(new BasicDBObject(PROJECT_ID, 1), new BasicDBObject("unique", true)); + collection.createIndex(new BasicDBObject(PROJECT_NAME, 1)); + collection.createIndex(new BasicDBObject(PROJECT_OWNER, 1)); + collection.createIndex(new BasicDBObject(PROJECT_DESCRIPTION, 1)); + collection.createIndex(new BasicDBObject(PROJECT_CREATION_TIME, 1)); + } + + public List<Project> getAllProjects() throws RegistryException{ + List<Project> projectList = new ArrayList(); + DBCursor cursor = collection.find(); + for(DBObject document: cursor){ + try { + projectList.add((Project) modelConversionHelper.deserializeObject( + Project.class, document.toString())); + } catch (IOException e) { + throw new RegistryException(e); + } + } + return projectList; + } + + public void createProject(Project project) throws RegistryException{ + try { + WriteResult result = collection.insert((DBObject) JSON.parse( + modelConversionHelper.serializeObject(project))); + logger.debug("No of inserted results "+ result.getN()); + } catch (JsonProcessingException e) { + throw new RegistryException(e); + } + } + + /** + * The following operation replaces the document with item equal to + * the given project id. The newly replaced document will only + * contain the the _id field and the fields in the replacement document. + * @param project + * @throws org.apache.airavata.registry.cpi.RegistryException + */ + public void updateProject(Project project) throws RegistryException{ + try { + DBObject query = BasicDBObjectBuilder.start().add( + PROJECT_ID, project.getProjectId()).get(); + WriteResult result = collection.update(query, (DBObject) JSON.parse( + modelConversionHelper.serializeObject(project))); + logger.debug("No of updated results "+ result.getN()); + } catch (JsonProcessingException e) { + throw new RegistryException(e); + } + } + + public void deleteProject(Project project) throws RegistryException{ + DBObject query = BasicDBObjectBuilder.start().add( + PROJECT_ID, project.getProjectId()).get(); + WriteResult result = collection.remove(query); + logger.debug("No of removed experiments " + result.getN()); + } + + public Project getProject(String projectId) throws RegistryException{ + try { + DBObject criteria = new BasicDBObject(PROJECT_ID, projectId); + DBObject doc = collection.findOne(criteria); + if(doc != null){ + String json = doc.toString(); + return (Project)modelConversionHelper.deserializeObject( + Project.class, json); + } + } catch (IOException e) { + throw new RegistryException(e); + } + return null; + } + + public List<Project> searchProjects(Map<String, String> filters, int limit, + int offset, Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException{ + List<Project> projectList = new ArrayList(); + BasicDBObjectBuilder queryBuilder = BasicDBObjectBuilder.start(); + for (String field : filters.keySet()) { +// if (field.equals(Constants.FieldConstants.ProjectConstants.PROJECT_NAME)){ +// fil.put(AbstractResource.ProjectConstants.PROJECT_NAME, filters.get(field)); +// }else if (field.equals(Constants.FieldConstants.ProjectConstants.OWNER)){ +// fil.put(AbstractResource.ProjectConstants.USERNAME, filters.get(field)); +// }else if (field.equals(Constants.FieldConstants.ProjectConstants.DESCRIPTION)){ +// fil.put(AbstractResource.ProjectConstants.DESCRIPTION, filters.get(field)); +// }else if (field.equals(Constants.FieldConstants.ProjectConstants.GATEWAY_ID)){ +// fil.put(AbstractResource.ProjectConstants.GATEWAY_ID, filters.get(field)); +// } + } + + //handling pagination and ordering. ordering is allowed only on PROJECT_CREATION_TIME + DBCursor cursor; + if(limit > 0 && offset >= 0) { + if(orderByIdentifier != null && orderByIdentifier.equals( + Constants.FieldConstants.ProjectConstants.CREATION_TIME)){ + if(resultOrderType.equals(ResultOrderType.ASC)) { + cursor = collection.find(queryBuilder.get()).sort(new BasicDBObject(PROJECT_CREATION_TIME, 1)) + .skip(offset).limit(limit); + }else{ + cursor = collection.find(queryBuilder.get()).sort(new BasicDBObject(PROJECT_CREATION_TIME, -1)) + .skip(offset).limit(limit); + } + }else { + cursor = collection.find(queryBuilder.get()).skip(offset).limit(limit); + } + }else{ + if(resultOrderType != null && resultOrderType.equals( + Constants.FieldConstants.ProjectConstants.CREATION_TIME)){ + if(resultOrderType.equals(ResultOrderType.ASC)) { + cursor = collection.find(queryBuilder.get()).sort(new BasicDBObject(PROJECT_CREATION_TIME, 1)); + }else{ + cursor = collection.find(queryBuilder.get()).sort(new BasicDBObject(PROJECT_CREATION_TIME, -1)); + } + }else { + cursor = collection.find(queryBuilder.get()); + } + } + for(DBObject document: cursor){ + try { + projectList.add((Project) modelConversionHelper.deserializeObject( + Project.class, document.toString())); + } catch (IOException e) { + throw new RegistryException(e); + } + } + return projectList; + } +} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/801489bf/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/mongo/dao/UserDao.java ---------------------------------------------------------------------- diff --git a/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/mongo/dao/UserDao.java b/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/mongo/dao/UserDao.java new file mode 100644 index 0000000..059c3f5 --- /dev/null +++ b/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/mongo/dao/UserDao.java @@ -0,0 +1,124 @@ +/* + * + * 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.persistance.registry.mongo.dao; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.mongodb.*; +import com.mongodb.util.JSON; +import org.apache.airavata.model.workspace.User; +import org.apache.airavata.persistance.registry.mongo.conversion.ModelConversionHelper; +import org.apache.airavata.persistance.registry.mongo.utils.MongoUtil; +import org.apache.airavata.registry.cpi.RegistryException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class UserDao { + private final static Logger logger = LoggerFactory.getLogger(UserDao.class); + + private static final String USERS_COLLECTION_NAME = "users"; + private DBCollection collection; + private ModelConversionHelper modelConversionHelper; + + private static final String USER_NAME = "user_name"; + + public UserDao(){ + collection = MongoUtil.getAiravataRegistry().getCollection(USERS_COLLECTION_NAME); + modelConversionHelper = new ModelConversionHelper(); + collection.dropIndexes(); + initIndexes(); + } + + /** + * If indexes are already defined this will simply ignore them + */ + private void initIndexes(){ + collection.createIndex(new BasicDBObject(USER_NAME, 1), new BasicDBObject("unique", true)); + } + + public List<User> getAllUsers() throws RegistryException{ + List<User> userList = new ArrayList(); + DBCursor cursor = collection.find(); + for(DBObject document: cursor){ + try { + userList.add((User) modelConversionHelper.deserializeObject( + User.class, document.toString())); + } catch (IOException e) { + throw new RegistryException(e); + } + } + return userList; + } + + public void createUser(User user) throws RegistryException{ + try { + WriteResult result = collection.insert((DBObject) JSON.parse( + modelConversionHelper.serializeObject(user))); + logger.debug("No of inserted results "+ result.getN()); + } catch (JsonProcessingException e) { + throw new RegistryException(e); + } + } + + /** + * The following operation replaces the document with item equal to + * the given project id. The newly replaced document will only + * contain the the _id field and the fields in the replacement document. + * @param user + * @throws org.apache.airavata.registry.cpi.RegistryException + */ + public void updateUser(User user) throws RegistryException{ + try { + DBObject query = BasicDBObjectBuilder.start().add( + USER_NAME, user.getUserName()).get(); + WriteResult result = collection.update(query, (DBObject) JSON.parse( + modelConversionHelper.serializeObject(user))); + logger.debug("No of updated results "+ result.getN()); + } catch (JsonProcessingException e) { + throw new RegistryException(e); + } + } + + public void deleteUser(User user) throws RegistryException{ + DBObject query = BasicDBObjectBuilder.start().add( + USER_NAME, user.getUserName()).get(); + WriteResult result = collection.remove(query); + logger.debug("No of removed users " + result.getN()); + } + + public User getUser(String username) throws RegistryException{ + try { + DBObject criteria = new BasicDBObject(USER_NAME, username); + DBObject doc = collection.findOne(criteria); + if(doc != null){ + String json = doc.toString(); + return (User)modelConversionHelper.deserializeObject( + User.class, json); + } + } catch (IOException e) { + throw new RegistryException(e); + } + return null; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/801489bf/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/mongo/impl/RegistryFactory.java ---------------------------------------------------------------------- diff --git a/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/mongo/impl/RegistryFactory.java b/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/mongo/impl/RegistryFactory.java new file mode 100644 index 0000000..c71f1e6 --- /dev/null +++ b/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/mongo/impl/RegistryFactory.java @@ -0,0 +1,44 @@ +/* + * + * 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.persistance.registry.mongo.impl; + +import org.apache.airavata.registry.cpi.Registry; +import org.apache.airavata.registry.cpi.RegistryException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class RegistryFactory { + private static Registry registry; + private static Logger logger = LoggerFactory.getLogger(RegistryFactory.class); + + public static Registry getDefaultRegistry () throws RegistryException { + try { + if (registry == null) { + registry = new RegistryImpl(); + } + } catch (RegistryException e) { + logger.error("Unable to create registry instance", e); + throw new RegistryException(e); + } + return registry; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/801489bf/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/mongo/impl/RegistryImpl.java ---------------------------------------------------------------------- diff --git a/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/mongo/impl/RegistryImpl.java b/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/mongo/impl/RegistryImpl.java new file mode 100644 index 0000000..a4d3256 --- /dev/null +++ b/modules/registry/airavata-mongo-registry/src/main/java/org/apache/airavata/persistance/registry/mongo/impl/RegistryImpl.java @@ -0,0 +1,732 @@ +/* + * + * 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.persistance.registry.mongo.impl; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.ServerSettings; +import org.apache.airavata.model.appcatalog.appinterface.OutputDataObjectType; +import org.apache.airavata.model.workspace.Gateway; +import org.apache.airavata.model.workspace.Project; +import org.apache.airavata.model.workspace.User; +import org.apache.airavata.model.workspace.experiment.*; +import org.apache.airavata.persistance.registry.mongo.repository.ExperimentRepository; +import org.apache.airavata.persistance.registry.mongo.repository.GatewayRepository; +import org.apache.airavata.persistance.registry.mongo.repository.ProjectRepository; +import org.apache.airavata.persistance.registry.mongo.repository.UserRepository; +import org.apache.airavata.registry.cpi.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +public class RegistryImpl implements Registry { + private Gateway gateway; + private User user; + private final static Logger logger = LoggerFactory.getLogger(RegistryImpl.class); + private ExperimentRepository experimentRegistry; + private ProjectRepository projectRepository; + private GatewayRepository gatewayRepository; + private UserRepository userRepository; + + public RegistryImpl() throws RegistryException{ + try { + initRegistry(ServerSettings.getDefaultUserGateway(), ServerSettings.getDefaultUser()); + } catch (ApplicationSettingsException e) { + logger.error("Unable to read airavata server properties..", e); + throw new RegistryException("Unable to read airavata server properties..", e); + } + } + + public RegistryImpl(String gatewayName, String userName) throws RegistryException{ + initRegistry(gatewayName, userName); + } + + private void initRegistry(String gatewayName, String userName) throws RegistryException { + gatewayRepository = new GatewayRepository(); + userRepository = new UserRepository(); + + if (!gatewayRepository.isGatewayExist(userName)){ + this.gateway = new Gateway(); + gateway.setGatewayId(UUID.randomUUID().toString()); + gateway.setGatewayName(gatewayName); + gatewayRepository.addGateway(gateway); + }else { + this.gateway = gatewayRepository.getGateway(gatewayName); + } + + if (!userRepository.isUserExists(userName)){ + user = new User(userName); + userRepository.addUser(user); + }else { + user = userRepository.getUser(userName); + } + experimentRegistry = new ExperimentRepository(gateway, user); + projectRepository = new ProjectRepository(gateway, user); + } + + /** + * This method is to add an object in to the registry + * + * @param dataType Data type is a predefined type which the programmer should choose according to the object he + * is going to save in to registry + * @param newObjectToAdd Object which contains the fields that need to be saved in to registry. This object is a + * thrift model object. In experiment case this object can be BasicMetadata, ConfigurationData + * etc + * @return return the identifier to identify the object + */ + @Override + public Object add(ParentDataType dataType, Object newObjectToAdd, String gatewayId) throws RegistryException { + try { + switch (dataType) { + case PROJECT: + return projectRepository.addProject((Project)newObjectToAdd, gatewayId); + case EXPERIMENT: + return experimentRegistry.addExperiment((Experiment) newObjectToAdd, gatewayId); + case GATEWAY: + return gatewayRepository.addGateway((Gateway)newObjectToAdd); + default: + logger.error("Unsupported top level type..", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + } catch (Exception e) { + logger.error("Error while adding the resource " + dataType.toString(), new RegistryException(e)); + throw new RegistryException("Error while adding the resource " + dataType.toString(), e); + } + } + + /** + * This method is to add an object in to the registry + * + * @param dataType Data type is a predefined type which the programmer should choose according to the object he + * is going to save in to registry + * @param newObjectToAdd Object which contains the fields that need to be saved in to registry. This object is a + * thrift model object. In experiment case this object can be BasicMetadata, ConfigurationData + * etc + * @param dependentIdentifier Object which contains the identifier if the object that is going to add is not a top + * level object in the data model. If it is a top level object, programmer can pass it as + * null + */ + @Override + public Object add(ChildDataType dataType, Object newObjectToAdd, Object dependentIdentifier) throws RegistryException { + try { + switch (dataType) { + case EXPERIMENT_CONFIGURATION_DATA: + return experimentRegistry.addUserConfigData((UserConfigurationData) newObjectToAdd, (String) dependentIdentifier); + case EXPERIMENT_OUTPUT: + return experimentRegistry.addExpOutputs((List<OutputDataObjectType>) newObjectToAdd, (String) dependentIdentifier); + case EXPERIMENT_STATUS: + return experimentRegistry.updateExperimentStatus((ExperimentStatus) newObjectToAdd, (String) dependentIdentifier); + case WORKFLOW_NODE_DETAIL: + return experimentRegistry.addWorkflowNodeDetails((WorkflowNodeDetails) newObjectToAdd, (String) dependentIdentifier); + case WORKFLOW_NODE_STATUS: + return experimentRegistry.addWorkflowNodeStatus((WorkflowNodeStatus) newObjectToAdd, (CompositeIdentifier) dependentIdentifier); + case NODE_OUTPUT: + return experimentRegistry.addNodeOutputs((List<OutputDataObjectType>) newObjectToAdd, (CompositeIdentifier) dependentIdentifier); + case TASK_DETAIL: + return experimentRegistry.addTaskDetails((TaskDetails) newObjectToAdd, (String) dependentIdentifier); + case APPLICATION_OUTPUT: + return experimentRegistry.addApplicationOutputs((List<OutputDataObjectType>) newObjectToAdd, (CompositeIdentifier) dependentIdentifier); + case TASK_STATUS: + return experimentRegistry.addTaskStatus((TaskStatus) newObjectToAdd, (CompositeIdentifier) dependentIdentifier); + case JOB_DETAIL: + return experimentRegistry.addJobDetails((JobDetails) newObjectToAdd, (CompositeIdentifier) dependentIdentifier); + case JOB_STATUS: + return experimentRegistry.addJobStatus((JobStatus) newObjectToAdd, (CompositeIdentifier) dependentIdentifier); + case APPLICATION_STATUS: + return experimentRegistry.addApplicationStatus((ApplicationStatus) newObjectToAdd, (CompositeIdentifier) dependentIdentifier); + case DATA_TRANSFER_DETAIL: + return experimentRegistry.addDataTransferDetails((DataTransferDetails) newObjectToAdd, (String) dependentIdentifier); + case TRANSFER_STATUS: + return experimentRegistry.addTransferStatus((TransferStatus) newObjectToAdd, (CompositeIdentifier) dependentIdentifier); + case COMPUTATIONAL_RESOURCE_SCHEDULING: + return experimentRegistry.addComputationalResourceScheduling((ComputationalResourceScheduling) newObjectToAdd, (CompositeIdentifier) dependentIdentifier); + case ADVANCE_OUTPUT_DATA_HANDLING: + return experimentRegistry.addOutputDataHandling((AdvancedOutputDataHandling) newObjectToAdd, (CompositeIdentifier) dependentIdentifier); + case ADVANCE_INPUT_DATA_HANDLING: + return experimentRegistry.addInputDataHandling((AdvancedInputDataHandling) newObjectToAdd, (CompositeIdentifier) dependentIdentifier); + case QOS_PARAM: + return experimentRegistry.addQosParams((QualityOfServiceParams) newObjectToAdd, (String) dependentIdentifier); + case ERROR_DETAIL: + return experimentRegistry.addErrorDetails((ErrorDetails) newObjectToAdd, dependentIdentifier); + default: + logger.error("Unsupported dependent data type...", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + } catch (Exception e) { + logger.error("Error while adding " + dataType.toString() , new RegistryException(e)); + throw new RegistryException("Error while adding " + dataType.toString(), e); + } + + } + + /** + * This method is to update the whole object in registry + * + * @param dataType Data type is a predefined type which the programmer should choose according to the object he + * is going to save in to registry + * @param newObjectToUpdate Object which contains the fields that need to be updated in to registry. This object is a + * thrift model object. In experiment case this object can be BasicMetadata, ConfigurationData + * etc. CPI programmer can only fill necessary fields that need to be updated. He does not + * have to fill the whole object. He needs to only fill the mandatory fields and whatever the + * other fields that need to be updated. + */ + @Override + public void update(RegistryModelType dataType, Object newObjectToUpdate, Object identifier) throws RegistryException { + try { + switch (dataType) { + case PROJECT: + projectRepository.updateProject((Project) newObjectToUpdate, (String) identifier); + break; + case GATEWAY: + gatewayRepository.updateGateway((String) identifier, (Gateway) newObjectToUpdate); + break; + case EXPERIMENT: + experimentRegistry.updateExperiment((Experiment) newObjectToUpdate, (String) identifier); + break; + case EXPERIMENT_CONFIGURATION_DATA: + experimentRegistry.updateUserConfigData((UserConfigurationData) newObjectToUpdate, (String) identifier); + break; + case EXPERIMENT_OUTPUT: + experimentRegistry.updateExpOutputs((List<OutputDataObjectType>) newObjectToUpdate, (String) identifier); + break; + case EXPERIMENT_STATUS: + experimentRegistry.updateExperimentStatus((ExperimentStatus) newObjectToUpdate, (String) identifier); + break; + case WORKFLOW_NODE_DETAIL: + experimentRegistry.updateWorkflowNodeDetails((WorkflowNodeDetails) newObjectToUpdate, (String) identifier); + break; + case WORKFLOW_NODE_STATUS: + experimentRegistry.updateWorkflowNodeStatus((WorkflowNodeStatus) newObjectToUpdate, (String) identifier); + break; + case NODE_OUTPUT: + experimentRegistry.updateNodeOutputs((List<OutputDataObjectType>) newObjectToUpdate, (String) identifier); + break; + case TASK_DETAIL: + experimentRegistry.updateTaskDetails((TaskDetails) newObjectToUpdate, (String) identifier); + break; + case APPLICATION_OUTPUT: + experimentRegistry.updateAppOutputs((List<OutputDataObjectType>) newObjectToUpdate, (String) identifier); + break; + case TASK_STATUS: + experimentRegistry.updateTaskStatus((TaskStatus) newObjectToUpdate, (String) identifier); + break; + case JOB_DETAIL: + experimentRegistry.updateJobDetails((JobDetails) newObjectToUpdate, (CompositeIdentifier) identifier); + break; + case JOB_STATUS: + experimentRegistry.updateJobStatus((JobStatus) newObjectToUpdate, (CompositeIdentifier) identifier); + break; + case APPLICATION_STATUS: + experimentRegistry.updateApplicationStatus((ApplicationStatus) newObjectToUpdate, (CompositeIdentifier) identifier); + break; + case DATA_TRANSFER_DETAIL: + experimentRegistry.updateDataTransferDetails((DataTransferDetails) newObjectToUpdate, (CompositeIdentifier) identifier); + break; + case TRANSFER_STATUS: + experimentRegistry.updateTransferStatus((TransferStatus) newObjectToUpdate, (CompositeIdentifier) identifier); + break; + case COMPUTATIONAL_RESOURCE_SCHEDULING: + experimentRegistry.updateScheduling((ComputationalResourceScheduling) newObjectToUpdate, (String) identifier, dataType.toString()); + break; + case ADVANCE_INPUT_DATA_HANDLING: + experimentRegistry.updateInputDataHandling((AdvancedInputDataHandling) newObjectToUpdate, (String) identifier, dataType.toString()); + break; + case ADVANCE_OUTPUT_DATA_HANDLING: + experimentRegistry.updateOutputDataHandling((AdvancedOutputDataHandling) newObjectToUpdate, (String) identifier, dataType.toString()); + break; + case QOS_PARAM: + experimentRegistry.updateQOSParams((QualityOfServiceParams) newObjectToUpdate, (String) identifier, dataType.toString()); + break; + default: + logger.error("Unsupported data type...", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + } catch (Exception e) { + logger.error("Error while updating the resource " + dataType.toString(), new RegistryException(e)); + throw new RegistryException("Error while updating the resource.." + dataType.toString(), e); + } + + } + + /** + * This method is to update a specific field of the data model + * + * @param dataType Data type is a predefined type which the programmer should choose according to the object he + * is going to save in to registry + * @param identifier Identifier which will uniquely identify the data model. For example, in Experiment_Basic_Type, + * identifier will be generated experimentID + * @param fieldName Field which need to be updated in the registry. In Experiment_Basic_Type, if you want to update the + * description, field will be "description". Field names are defined in + * org.apache.airavata.registry.cpi.utils.Constants + * @param value Value by which the given field need to be updated. If the field is "description", that field will be + * updated by given value + */ + @Override + public void update(RegistryModelType dataType, Object identifier, String fieldName, Object value) throws RegistryException { + try { + switch (dataType) { + case EXPERIMENT: + experimentRegistry.updateExperimentField((String) identifier, fieldName, value); + break; + case EXPERIMENT_CONFIGURATION_DATA: + experimentRegistry.updateExpConfigDataField((String) identifier, fieldName, value); + break; + default: + logger.error("Unsupported data type...", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + } catch (Exception e) { + logger.error("Error while updating the resource " + dataType.toString(), new RegistryException(e)); + throw new RegistryException("Error while updating the resource " + dataType.toString(), e); + } + + } + + /** + * This method is to retrieve object according to the identifier. In the experiment basic data type, if you give the + * experiment id, this method will return the BasicMetadata object + * + * @param dataType Data type is a predefined type which the programmer should choose according to the object he + * is going to save in to registry + * @param identifier Identifier which will uniquely identify the data model. For example, in Experiment_Basic_Type, + * identifier will be generated experimentID + * @return object according to the given identifier. + */ + @Override + public Object get(RegistryModelType dataType, Object identifier) throws RegistryException { + try { + switch (dataType) { + case PROJECT: + return projectRepository.getProject((String)identifier); + case GATEWAY: + return gatewayRepository.getGateway((String)identifier); + case EXPERIMENT: + return experimentRegistry.getExperiment((String) identifier, null); + case EXPERIMENT_CONFIGURATION_DATA: + return experimentRegistry.getConfigData((String) identifier, null); + case EXPERIMENT_OUTPUT: + return experimentRegistry.getExperimentOutputs((String) identifier); + case EXPERIMENT_STATUS: + return experimentRegistry.getExperimentStatus((String) identifier); + case WORKFLOW_NODE_DETAIL: + return experimentRegistry.getWorkflowNodeDetails((String) identifier); + case WORKFLOW_NODE_STATUS: + return experimentRegistry.getWorkflowNodeStatus((String) identifier); + case NODE_OUTPUT: + return experimentRegistry.getNodeOutputs((String) identifier); + case TASK_DETAIL: + return experimentRegistry.getTaskDetails((String) identifier); + case APPLICATION_OUTPUT: + return experimentRegistry.getApplicationOutputs((String) identifier); + case TASK_STATUS: + return experimentRegistry.getTaskStatus((String) identifier); + case JOB_DETAIL: + return experimentRegistry.getJobDetails((CompositeIdentifier) identifier); + case JOB_STATUS: + return experimentRegistry.getJobStatus((CompositeIdentifier) identifier); + case APPLICATION_STATUS: + return experimentRegistry.getApplicationStatus((CompositeIdentifier) identifier); + case DATA_TRANSFER_DETAIL: + return experimentRegistry.getDataTransferDetails((CompositeIdentifier) identifier); + case TRANSFER_STATUS: + return experimentRegistry.getDataTransferStatus((CompositeIdentifier) identifier); + case COMPUTATIONAL_RESOURCE_SCHEDULING: + return experimentRegistry.getComputationalScheduling(dataType, (String) identifier); + case ADVANCE_INPUT_DATA_HANDLING: + return experimentRegistry.getInputDataHandling(dataType, (String) identifier); + case ADVANCE_OUTPUT_DATA_HANDLING: + return experimentRegistry.getOutputDataHandling(dataType, (String) identifier); + case QOS_PARAM: + return experimentRegistry.getQosParams(dataType, (String) identifier); + default: + logger.error("Unsupported data type...", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + } catch (Exception e) { + logger.error("Error while retrieving the resource " + dataType.toString(), new RegistryException(e)); + throw new RegistryException("Error while retrieving the resource " + dataType.toString() , e); + } + } + + /** + * This method is to retrieve list of objects according to a given criteria + * + * @param dataType Data type is a predefined type which the programmer should choose according to the object he + * is going to save in to registry + * @param fieldName FieldName is the field that filtering should be done. For example, if we want to retrieve all + * the experiments for a given user, filterBy will be "userName" + * @param value value for the filtering field. In the experiment case, value for "userName" can be "admin" + * @return List of objects according to the given criteria + */ + @Override + public List<Object> get(RegistryModelType dataType, String fieldName, Object value) throws RegistryException { + try { + List<Object> result = new ArrayList<Object>(); + switch (dataType) { + case PROJECT: + List<Project> projectList = projectRepository.getProjectList(fieldName, value); + for (Project project : projectList ){ + result.add(project); + } + return result; + case GATEWAY: + List<Gateway> allGateways = gatewayRepository.getAllGateways(); + for (Gateway gateway : allGateways){ + result.add(gateway); + } + return result; + case EXPERIMENT: + List<Experiment> experimentList = experimentRegistry.getExperimentList(fieldName, value); + for (Experiment experiment : experimentList) { + result.add(experiment); + } + return result; + case WORKFLOW_NODE_DETAIL: + List<WorkflowNodeDetails> wfNodeDetails = experimentRegistry.getWFNodeDetails(fieldName, value); + for (WorkflowNodeDetails wf : wfNodeDetails) { + result.add(wf); + } + return result; + case WORKFLOW_NODE_STATUS: + List<WorkflowNodeStatus> wfNodeStatusList = experimentRegistry.getWFNodeStatusList(fieldName, value); + for (WorkflowNodeStatus wfs : wfNodeStatusList) { + result.add(wfs); + } + return result; + case TASK_DETAIL: + List<TaskDetails> taskDetails = experimentRegistry.getTaskDetails(fieldName, value); + for (TaskDetails task : taskDetails) { + result.add(task); + } + return result; + case JOB_DETAIL: + List<JobDetails> jobDetails = experimentRegistry.getJobDetails(fieldName, value); + for (JobDetails job : jobDetails) { + result.add(job); + } + return result; + case DATA_TRANSFER_DETAIL: + List<DataTransferDetails> dataTransferDetails = experimentRegistry.getDataTransferDetails(fieldName, value); + for (DataTransferDetails transferDetails : dataTransferDetails) { + result.add(transferDetails); + } + return result; + case ERROR_DETAIL: + List<ErrorDetails> errorDetails = experimentRegistry.getErrorDetails(fieldName, value); + for (ErrorDetails error : errorDetails) { + result.add(error); + } + return result; + default: + logger.error("Unsupported data type...", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + } catch (Exception e) { + logger.error("Error while retrieving the resource " + dataType.toString(), new RegistryException(e)); + throw new RegistryException("Error while retrieving the resource " + dataType.toString(), e); + } + + } + + /** + * This method is to retrieve list of objects according to a given criteria with pagination and ordering + * + * @param dataType Data type is a predefined type which the programmer should choose according to the object he + * is going to save in to registry + * @param fieldName FieldName is the field that filtering should be done. For example, if we want to retrieve all + * the experiments for a given user, filterBy will be "userName" + * @param value value for the filtering field. In the experiment case, value for "userName" can be "admin" + * @param limit Size of the results to be returned + * @param offset Start position of the results to be retrieved + * @param orderByIdentifier Named of the column in which the ordering is based + * @param resultOrderType Type of ordering i.e ASC or DESC + * @return + * @throws RegistryException + */ + @Override + public List<Object> get(RegistryModelType dataType, String fieldName, Object value, int limit, + int offset, Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException { + try { + List<Object> result = new ArrayList<Object>(); + switch (dataType) { + case PROJECT: + List<Project> projectList = projectRepository + .getProjectList(fieldName, value, limit, offset, orderByIdentifier, resultOrderType); + for (Project project : projectList ){ + result.add(project); + } + return result; + case EXPERIMENT: + List<Experiment> experimentList = experimentRegistry.getExperimentList(fieldName, value, + limit, offset, orderByIdentifier, resultOrderType); + for (Experiment experiment : experimentList) { + result.add(experiment); + } + return result; + default: + logger.error("Unsupported data type...", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + } catch (Exception e) { + logger.error("Error while retrieving the resource " + dataType.toString(), new RegistryException(e)); + throw new RegistryException("Error while retrieving the resource " + dataType.toString(), e); + } + } + + /** + * This method is to retrieve list of objects according to a given criteria + * @param dataType Data type is a predefined type which the programmer should choose according to the object he + * is going to save in to registry + * @param filters filters is a map of field name and value that you need to use for search filtration + * @return List of objects according to the given criteria + */ + @Override + public List<Object> search(RegistryModelType dataType, Map<String, String> filters) throws RegistryException { + return search(dataType, filters, -1, -1, null, null); + } + + /** + * This method is to retrieve list of objects with pagination according to a given criteria sorted + * according by the specified identified and specified ordering (i.e either ASC or DESC) + * @param dataType Data type is a predefined type which the programmer should choose according to the object he + * is going to save in to registry + * @param filters filters is a map of field name and value that you need to use for search filtration + * @param limit amount of the results to be returned + * @param offset offset of the results from the sorted list to be fetched from + * @param orderByIdentifier identifier (i.e the column) which will be used as the basis to sort the results + * @param resultOrderType The type of ordering (i.e ASC or DESC) that has to be used when retrieving the results + * @return List of objects according to the given criteria + */ + @Override + public List<Object> search(RegistryModelType dataType, Map<String, String> filters, int limit, + int offset, Object orderByIdentifier, ResultOrderType resultOrderType) throws RegistryException { + try { + List<Object> result = new ArrayList<Object>(); + switch (dataType) { + case PROJECT: + List<Project> projectList + = projectRepository.searchProjects(filters, limit, offset, + orderByIdentifier, resultOrderType); + for (Project project : projectList ){ + result.add(project); + } + return result; + case EXPERIMENT: + List<ExperimentSummary> experimentSummaries = experimentRegistry + .searchExperiments(filters, limit, offset, orderByIdentifier, + resultOrderType); + for (ExperimentSummary ex : experimentSummaries){ + result.add(ex); + } + return result; + default: + logger.error("Unsupported data type...", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + } catch (Exception e) { + logger.error("Error while retrieving the resource " + dataType.toString(), new RegistryException(e)); + throw new RegistryException("Error while retrieving the resource " + dataType.toString(), e); + } + } + + /** + * This method is to retrieve a specific value for a given field. + * + * @param dataType Data type is a predefined type which the programmer should choose according to the object he + * is going to save in to registry + * @param identifier Identifier which will uniquely identify the data model. For example, in Experiment_Basic_Type, + * identifier will be generated experimentID + * @param field field that filtering should be done. For example, if we want to execution user for a given + * experiment, field will be "userName" + * @return return the value for the specific field where data model is identified by the unique identifier that has + * given + */ + @Override + public Object getValue(RegistryModelType dataType, Object identifier, String field) throws RegistryException { + try { + switch (dataType) { + case EXPERIMENT: + return experimentRegistry.getExperiment((String) identifier, field); + case EXPERIMENT_CONFIGURATION_DATA: + return experimentRegistry.getConfigData((String) identifier, field); + default: + logger.error("Unsupported data type...", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + } catch (Exception e) { + logger.error("Error while retrieving the resource " + dataType.toString(), new RegistryException(e)); + throw new RegistryException("Error while retrieving the resource " + dataType.toString(), e); + } + + } + + /** + * This method is to retrieve all the identifiers according to given filtering criteria. For an example, if you want + * to get all the experiment ids for a given gateway, your field name will be "gateway" and the value will be the + * name of the gateway ("default"). Similar manner you can retrieve all the experiment ids for a given user. + * + * @param dataType Data type is a predefined type which the programmer should choose according to the object he + * is going to save in to registry + * @param fieldName FieldName is the field that filtering should be done. For example, if we want to retrieve all + * the experiments for a given user, filterBy will be "userName" + * @param value value for the filtering field. In the experiment case, value for "userName" can be "admin" + * @return id list according to the filtering criteria + */ + @Override + public List<String> getIds(RegistryModelType dataType, String fieldName, Object value) throws RegistryException { + try { + switch (dataType) { + case PROJECT: + return projectRepository.getProjectIds(fieldName, value); + case EXPERIMENT: + return experimentRegistry.getExperimentIds(fieldName, value); + case EXPERIMENT_CONFIGURATION_DATA: + return experimentRegistry.getExperimentIds(fieldName, value); + case WORKFLOW_NODE_DETAIL: + return experimentRegistry.getWorkflowNodeIds(fieldName, value); + case TASK_DETAIL: + return experimentRegistry.getTaskDetailIds(fieldName, value); + case JOB_DETAIL: + return experimentRegistry.getJobDetailIds(fieldName, value); + case DATA_TRANSFER_DETAIL: + return experimentRegistry.getTransferDetailIds(fieldName, value); + default: + logger.error("Unsupported data type...", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + } catch (Exception e) { + logger.error("Error while retrieving the ids for" + dataType.toString(), new RegistryException(e)); + throw new RegistryException("Error while retrieving the ids for " + dataType.toString(), e); + } + + } + + /** + * This method is to remove a item from the registry + * + * @param dataType Data type is a predefined type which the programmer should choose according to the object he + * is going to save in to registry + * @param identifier Identifier which will uniquely identify the data model. For example, in Experiment_Basic_Type, + * identifier will be generated experimentID + */ + @Override + public void remove(RegistryModelType dataType, Object identifier) throws RegistryException { + try { + switch (dataType) { + case PROJECT: + projectRepository.removeProject((String) identifier); + break; + case GATEWAY: + gatewayRepository.removeGateway((String) identifier); + break; + case EXPERIMENT: + experimentRegistry.removeExperiment((String) identifier); + break; + case EXPERIMENT_CONFIGURATION_DATA: + experimentRegistry.removeExperimentConfigData((String) identifier); + break; + case WORKFLOW_NODE_DETAIL: + experimentRegistry.removeWorkflowNode((String) identifier); + break; + case TASK_DETAIL: + experimentRegistry.removeTaskDetails((String) identifier); + break; + case JOB_DETAIL: + experimentRegistry.removeJobDetails((CompositeIdentifier) identifier); + break; + case DATA_TRANSFER_DETAIL: + experimentRegistry.removeDataTransferDetails((CompositeIdentifier) identifier); + break; + case COMPUTATIONAL_RESOURCE_SCHEDULING: + experimentRegistry.removeComputationalScheduling(dataType, (String) identifier); + break; + case ADVANCE_OUTPUT_DATA_HANDLING: + experimentRegistry.removeOutputDataHandling(dataType, (String) identifier); + break; + case ADVANCE_INPUT_DATA_HANDLING: + experimentRegistry.removeInputDataHandling(dataType, (String) identifier); + break; + case QOS_PARAM: + experimentRegistry.removeQOSParams(dataType, (String) identifier); + break; + default: + logger.error("Unsupported data type...", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + } catch (Exception e) { + logger.error("Error while removing the resource " + dataType.toString(), new RegistryException(e)); + throw new RegistryException("Error while removing the resource " + dataType.toString(), e); + } + + } + + /** + * This method will check whether a given data type which can be identified with the identifier exists or not + * + * @param dataType Data type is a predefined type which the programmer should choose according to the object he + * is going to save in to registry + * @param identifier Identifier which will uniquely identify the data model. For example, in Experiment_Basic_Type, + * identifier will be generated experimentID + * @return whether the given data type exists or not + */ + @Override + public boolean isExist(RegistryModelType dataType, Object identifier) throws RegistryException { + try { + switch (dataType) { + case PROJECT: + return projectRepository.isProjectExist((String)identifier); + case GATEWAY: + return gatewayRepository.isGatewayExist((String)identifier); + case EXPERIMENT: + return experimentRegistry.isExperimentExist((String) identifier); + case EXPERIMENT_CONFIGURATION_DATA: + return experimentRegistry.isExperimentConfigDataExist((String) identifier); + case WORKFLOW_NODE_DETAIL: + return experimentRegistry.isWFNodeExist((String) identifier); + case TASK_DETAIL: + return experimentRegistry.isTaskDetailExist((String) identifier); + case JOB_DETAIL: + return experimentRegistry.isJobDetailExist((CompositeIdentifier) identifier); + case DATA_TRANSFER_DETAIL: + return experimentRegistry.isTransferDetailExist((CompositeIdentifier) identifier); + case COMPUTATIONAL_RESOURCE_SCHEDULING: + return experimentRegistry.isComputationalSchedulingExist(dataType, (String) identifier); + case ADVANCE_INPUT_DATA_HANDLING: + return experimentRegistry.isInputDataHandlingExist(dataType, (String) identifier); + case ADVANCE_OUTPUT_DATA_HANDLING: + return experimentRegistry.isOutputDataHandlingExist(dataType, (String) identifier); + case QOS_PARAM: + return experimentRegistry.isQOSParamsExist(dataType, (String) identifier); + default: + logger.error("Unsupported data type...", new UnsupportedOperationException()); + throw new UnsupportedOperationException(); + } + } catch (Exception e) { + logger.error("Error while checking existence of the resource " + dataType.toString(), new RegistryException(e)); + throw new RegistryException("Error while checking existence of the resource " + dataType.toString(), e); + } + } + +}
