[ 
https://issues.apache.org/jira/browse/AIRAVATA-2657?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16411504#comment-16411504
 ] 

ASF GitHub Bot commented on AIRAVATA-2657:
------------------------------------------

DImuthuUpe commented on a change in pull request #167: [AIRAVATA-2657] 
Refactoring App Catalog Implementation - ApplicationDeployment and 
ApplicationInterface Modules
URL: https://github.com/apache/airavata/pull/167#discussion_r176758465
 
 

 ##########
 File path: 
modules/registry-refactoring/src/main/java/org/apache/airavata/registry/core/repositories/appcatalog/ApplicationDeploymentRepository.java
 ##########
 @@ -0,0 +1,159 @@
+/**
+ *
+ * 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.registry.core.repositories.appcatalog;
+
+import org.apache.airavata.model.appcatalog.appdeployment.*;
+import org.apache.airavata.registry.core.entities.appcatalog.*;
+import org.apache.airavata.registry.core.utils.DBConstants;
+import org.apache.airavata.registry.core.utils.ObjectMapperSingleton;
+import org.apache.airavata.registry.core.utils.QueryConstants;
+import org.apache.airavata.registry.cpi.AppCatalogException;
+import org.apache.airavata.registry.cpi.ApplicationDeployment;
+import org.dozer.Mapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class ApplicationDeploymentRepository extends 
AppCatAbstractRepository<ApplicationDeploymentDescription, 
ApplicationDeploymentEntity, String> implements ApplicationDeployment {
+    private final static Logger logger = 
LoggerFactory.getLogger(ApplicationDeploymentRepository.class);
+
+    public ApplicationDeploymentRepository() {
+        super(ApplicationDeploymentDescription.class, 
ApplicationDeploymentEntity.class);
+    }
+
+    protected String saveApplicationDeploymentDescriptorData(
+            ApplicationDeploymentDescription applicationDeploymentDescription, 
String gatewayId) throws AppCatalogException {
+        ApplicationDeploymentEntity applicationDeploymentEntity = 
saveApplicationDeployment(applicationDeploymentDescription, gatewayId);
+        return applicationDeploymentEntity.getAppDeploymentId();
+    }
+
+    protected ApplicationDeploymentEntity saveApplicationDeployment(
+            ApplicationDeploymentDescription applicationDeploymentDescription, 
String gatewayId) throws AppCatalogException {
+        String applicationDeploymentId = 
applicationDeploymentDescription.getAppDeploymentId();
+        Mapper mapper = ObjectMapperSingleton.getInstance();
+        ApplicationDeploymentEntity applicationDeploymentEntity = 
mapper.map(applicationDeploymentDescription, ApplicationDeploymentEntity.class);
+        if (gatewayId != null)
+            applicationDeploymentEntity.setGatewayId(gatewayId);
+        if (applicationDeploymentEntity.getModuleLoadCmds() != null) {
+            
applicationDeploymentEntity.getModuleLoadCmds().forEach(moduleLoadCmdEntity -> 
moduleLoadCmdEntity.setAppdeploymentId(applicationDeploymentId));
+        }
+        if (applicationDeploymentEntity.getPreJobCommands() != null) {
+            
applicationDeploymentEntity.getPreJobCommands().forEach(prejobCommandEntity -> 
prejobCommandEntity.setAppdeploymentId(applicationDeploymentId));
+        }
+        if (applicationDeploymentEntity.getPostJobCommands() != null) {
+            
applicationDeploymentEntity.getPostJobCommands().forEach(postjobCommandEntity 
-> postjobCommandEntity.setAppdeploymentId(applicationDeploymentId));
+        }
+        if (applicationDeploymentEntity.getLibPrependPaths() != null) {
+            
applicationDeploymentEntity.getLibPrependPaths().forEach(libraryPrependPathEntity
 -> libraryPrependPathEntity.setDeploymentId(applicationDeploymentId));
+        }
+        if (applicationDeploymentEntity.getLibAppendPaths() != null) {
+            
applicationDeploymentEntity.getLibAppendPaths().forEach(libraryApendPathEntity 
-> libraryApendPathEntity.setDeploymentId(applicationDeploymentId));
+        }
+        if (applicationDeploymentEntity.getSetEnvironment() != null) {
+            
applicationDeploymentEntity.getSetEnvironment().forEach(appEnvironmentEntity -> 
appEnvironmentEntity.setDeploymentId(applicationDeploymentId));
+        }
+        if (!isAppDeploymentExists(applicationDeploymentId))
+            applicationDeploymentEntity.setCreationTime(new 
Timestamp(System.currentTimeMillis()));
+        applicationDeploymentEntity.setUpdateTime(new 
Timestamp(System.currentTimeMillis()));
+        return execute(entityManager -> 
entityManager.merge(applicationDeploymentEntity));
+    }
+
+    @Override
+    public String addApplicationDeployment(ApplicationDeploymentDescription 
applicationDeploymentDescription, String gatewayId) throws AppCatalogException {
+        return 
saveApplicationDeploymentDescriptorData(applicationDeploymentDescription, 
gatewayId);
+    }
+
+    @Override
+    public void updateApplicationDeployment(String deploymentId, 
ApplicationDeploymentDescription updatedApplicationDeploymentDescription) 
throws AppCatalogException {
+        
saveApplicationDeploymentDescriptorData(updatedApplicationDeploymentDescription,
 null);
+    }
+
+    @Override
+    public ApplicationDeploymentDescription getApplicationDeployement(String 
deploymentId) throws AppCatalogException {
+        Map<String, Object> queryParameters = new HashMap<>();
+        
queryParameters.put(DBConstants.ApplicationDeployment.APPLICATION_DEPLOYMENT_ID,
 deploymentId);
+        ApplicationDeploymentDescription applicationDeploymentDescription = 
select(QueryConstants.FIND_APPLICATION_DEPLOYMENT, -1, 0, 
queryParameters).get(0);
+        return applicationDeploymentDescription;
+    }
+
+    @Override
+    public List<ApplicationDeploymentDescription> 
getApplicationDeployements(Map<String, String> filters) throws 
AppCatalogException {
+        
if(filters.containsKey(DBConstants.ApplicationDeployment.APPLICATION_MODULE_ID))
 {
 
 Review comment:
   Add debug logs in each block and add a newline at the end of each block to 
improve the readability 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Refactoring App Catalog implementation - ApplicationDeployment and 
> ApplicationInterface
> ---------------------------------------------------------------------------------------
>
>                 Key: AIRAVATA-2657
>                 URL: https://issues.apache.org/jira/browse/AIRAVATA-2657
>             Project: Airavata
>          Issue Type: Task
>          Components: Application Catalog
>            Reporter: Sneha Tilak
>            Assignee: Sneha Tilak
>            Priority: Major
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to