You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2018/02/20 18:21:50 UTC
[airavata] branch group-based-auth updated: getAll application
modules for list of accessible deployment ids
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch group-based-auth
in repository https://gitbox.apache.org/repos/asf/airavata.git
The following commit(s) were added to refs/heads/group-based-auth by this push:
new a6beeb5 getAll application modules for list of accessible deployment ids
a6beeb5 is described below
commit a6beeb552933e8ebf0d657d85bfd6792577d1888
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Tue Feb 20 13:20:53 2018 -0500
getAll application modules for list of accessible deployment ids
---
.../app/catalog/impl/ApplicationInterfaceImpl.java | 2 +-
.../catalog/resources/AppCatAbstractResource.java | 2 -
.../app/catalog/resources/AppModuleResource.java | 25 +++--
.../app/catalog/AppModuleResourceTest.java | 118 +++++++++++++++++++++
4 files changed, 137 insertions(+), 10 deletions(-)
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/impl/ApplicationInterfaceImpl.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/impl/ApplicationInterfaceImpl.java
index 55591e5..629bb56 100644
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/impl/ApplicationInterfaceImpl.java
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/impl/ApplicationInterfaceImpl.java
@@ -345,7 +345,7 @@ public class ApplicationInterfaceImpl implements ApplicationInterface {
try {
AppModuleResource resource = new AppModuleResource();
resource.setGatewayId(gatewayId);
- resource.setAccessibleAppIds(accessibleAppIds);
+ resource.setAccessibleAppDeploymentIds(accessibleAppIds);
List<AppCatalogResource> resources = resource.getAll();
if (resources != null && !resources.isEmpty()){
applicationModules = AppCatalogThriftConversion.getAppModules(resources);
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/AppCatAbstractResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/AppCatAbstractResource.java
index 966a023..f6027ba 100644
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/AppCatAbstractResource.java
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/AppCatAbstractResource.java
@@ -204,7 +204,6 @@ public abstract class AppCatAbstractResource implements AppCatalogResource {
public static final String MODULE_NAME = "moduleName";
public static final String MODULE_VERSION = "moduleVersion";
public static final String MODULE_DESC = "moduleDesc";
- public static final String ACCESSIBLE_APP_IDS = "accessibleAppIds";
}
public final class ApplicationDeploymentConstants {
@@ -216,7 +215,6 @@ public abstract class AppCatAbstractResource implements AppCatalogResource {
public static final String APPLICATION_DESC = "applicationDesc";
public static final String ENV_MODULE_LOAD_CMD = "envModuleLoaString";
public static final String PARALLELISM = "parallelism";
- public static final String ACCESSIBLE_APP_IDS = "accessibleAppIds";
}
public final class LibraryPrepandPathConstants {
diff --git a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/AppModuleResource.java b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/AppModuleResource.java
index 49fb24e..4d05efd 100644
--- a/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/AppModuleResource.java
+++ b/modules/registry/registry-core/src/main/java/org/apache/airavata/registry/core/app/catalog/resources/AppModuleResource.java
@@ -44,11 +44,11 @@ public class AppModuleResource extends AppCatAbstractResource {
private Timestamp createdTime;
private Timestamp updatedTime;
private String gatewayId;
- private List<String> accessibleAppIds;
+ private List<String> accessibleAppDeploymentIds;
- public List<String> getAccessibleAppIds() { return accessibleAppIds; }
+ public List<String> getAccessibleAppDeploymentIds() { return accessibleAppDeploymentIds; }
- public void setAccessibleAppIds(List<String> accessibleAppIds) { this.accessibleAppIds = accessibleAppIds; }
+ public void setAccessibleAppDeploymentIds(List<String> accessibleAppDeploymentIds) { this.accessibleAppDeploymentIds = accessibleAppDeploymentIds; }
public String getGatewayId() {
return gatewayId;
@@ -230,10 +230,21 @@ public class AppModuleResource extends AppCatAbstractResource {
try {
em = AppCatalogJPAUtils.getEntityManager();
em.getTransaction().begin();
- AppCatalogQueryGenerator generator = new AppCatalogQueryGenerator(APPLICATION_MODULE);
- generator.setParameter(ApplicationModuleConstants.GATEWAY_ID, gatewayId);
- generator.setParameter(ApplicationModuleConstants.ACCESSIBLE_APP_IDS, accessibleAppIds);
- Query q = generator.selectQuery(em);
+
+ String queryString = "SELECT appModule " +
+ "FROM " + APPLICATION_MODULE + " appModule " +
+ "WHERE appModule." + ApplicationModuleConstants.GATEWAY_ID + " = :" + ApplicationModuleConstants.GATEWAY_ID + " ";
+ if (accessibleAppDeploymentIds != null && !accessibleAppDeploymentIds.isEmpty()) {
+ queryString += " AND appModule." + ApplicationModuleConstants.MODULE_ID + " IN (" +
+ " SELECT appDeploy." + ApplicationDeploymentConstants.APP_MODULE_ID + " " +
+ " FROM " + APPLICATION_DEPLOYMENT + " appDeploy " +
+ " WHERE appDeploy." + ApplicationDeploymentConstants.DEPLOYMENT_ID + " IN :" + ApplicationDeploymentConstants.DEPLOYMENT_ID + ")";
+ }
+ Query q = em.createQuery(queryString);
+ q.setParameter(ApplicationModuleConstants.GATEWAY_ID, gatewayId);
+ if (accessibleAppDeploymentIds != null && !accessibleAppDeploymentIds.isEmpty()) {
+ q.setParameter(ApplicationDeploymentConstants.DEPLOYMENT_ID, accessibleAppDeploymentIds);
+ }
List<?> results = q.getResultList();
for (Object result : results) {
ApplicationModule module = (ApplicationModule) result;
diff --git a/modules/registry/registry-core/src/test/java/org/apache/airavata/app/catalog/AppModuleResourceTest.java b/modules/registry/registry-core/src/test/java/org/apache/airavata/app/catalog/AppModuleResourceTest.java
new file mode 100644
index 0000000..d0410a9
--- /dev/null
+++ b/modules/registry/registry-core/src/test/java/org/apache/airavata/app/catalog/AppModuleResourceTest.java
@@ -0,0 +1,118 @@
+/*
+ * 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.app.catalog;
+
+import org.apache.airavata.app.catalog.util.Initialize;
+import org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription;
+import org.apache.airavata.model.appcatalog.computeresource.ComputeResourceDescription;
+import org.apache.airavata.registry.core.app.catalog.resources.AppCatalogResource;
+import org.apache.airavata.registry.core.app.catalog.resources.AppModuleResource;
+import org.apache.airavata.registry.core.experiment.catalog.impl.RegistryFactory;
+import org.apache.airavata.registry.cpi.AppCatalog;
+import org.apache.airavata.registry.cpi.AppCatalogException;
+import org.apache.airavata.registry.cpi.ApplicationDeployment;
+import org.apache.airavata.registry.cpi.ComputeResource;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class AppModuleResourceTest {
+
+ private static Initialize initialize;
+ private static AppCatalog appcatalog;
+ private static final Logger logger = LoggerFactory.getLogger(AppDeploymentTest.class);
+
+ @Before
+ public void setUp() {
+ try {
+ initialize = new Initialize("appcatalog-derby.sql");
+ initialize.initializeDB();
+ appcatalog = RegistryFactory.getAppCatalog();
+ } catch (AppCatalogException e) {
+ logger.error(e.getMessage(), e);
+ }
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ System.out.println("********** TEAR DOWN ************");
+ initialize.stopDerbyServer();
+ }
+
+ @Test
+ public void testGetAllWithAccessibleDeploymentIds() throws Exception {
+
+ ApplicationDeployment appDep = appcatalog.getApplicationDeployment();
+
+ String gatewayId = "test-gateway";
+ AppModuleResource appModuleResource = new AppModuleResource();
+ appModuleResource.setGatewayId(gatewayId);
+ appModuleResource.setModuleId("module1-id");
+ appModuleResource.setModuleName("module1-name");
+ appModuleResource.setModuleDesc("module1-desc");
+
+ appModuleResource.save();
+
+ appModuleResource = new AppModuleResource();
+ appModuleResource.setGatewayId(gatewayId);
+ appModuleResource.setModuleId("module2-id");
+ appModuleResource.setModuleName("module2-name");
+ appModuleResource.setModuleDesc("module2-desc");
+
+ appModuleResource.save();
+
+ // Verify we can get the first module
+ appModuleResource = new AppModuleResource();
+ appModuleResource = (AppModuleResource) appModuleResource.get("module1-id");
+ Assert.assertEquals(appModuleResource.getGatewayId(), gatewayId);
+
+ // Verify when when get all modules it returns two of them
+ appModuleResource = new AppModuleResource();
+ appModuleResource.setGatewayId(gatewayId);
+ List<AppCatalogResource> appModuleResources = appModuleResource.getAll();
+ Assert.assertEquals(2, appModuleResources.size());
+
+ ComputeResource computeResource = appcatalog.getComputeResource();
+ ComputeResourceDescription computeResourceDescription = new ComputeResourceDescription();
+ computeResourceDescription.setHostName("localhost");
+ String computeResourceId = computeResource.addComputeResource(computeResourceDescription);
+
+ ApplicationDeploymentDescription appDep1 = new ApplicationDeploymentDescription();
+ appDep1.setAppModuleId("module2-id");
+ appDep1.setComputeHostId(computeResourceId);
+ String appDepId1 = appDep.addApplicationDeployment(appDep1, gatewayId);
+
+ appModuleResource = new AppModuleResource();
+ appModuleResource.setGatewayId(gatewayId);
+ appModuleResource.setAccessibleAppDeploymentIds(Arrays.asList(appDepId1));
+ appModuleResources = appModuleResource.getAll();
+ Assert.assertEquals(1, appModuleResources.size());
+ AppModuleResource firstAppModuleResource = (AppModuleResource) appModuleResources.get(0);
+ Assert.assertEquals("module2-id", firstAppModuleResource.getModuleId());
+
+ }
+}
--
To stop receiving notification emails like this one, please contact
machristie@apache.org.