Repository: airavata Updated Branches: refs/heads/master b70474ca5 -> 3630458b2
adding test class for gateway profile Project: http://git-wip-us.apache.org/repos/asf/airavata/repo Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/3630458b Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/3630458b Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/3630458b Branch: refs/heads/master Commit: 3630458b21a3b3e9918f6b96c0f7e1e25f264c1a Parents: b70474c Author: Chathuri Wimalasena <[email protected]> Authored: Mon Jul 7 21:49:04 2014 -0400 Committer: Chathuri Wimalasena <[email protected]> Committed: Mon Jul 7 21:49:04 2014 -0400 ---------------------------------------------------------------------- .../appcatalog/cpi/GwyResourceProfile.java | 2 +- .../data/impl/GwyResourceProfileImpl.java | 3 +- .../ComputeHostPreferenceResource.java | 2 + .../app/catalog/test/GatewayProfileTest.java | 127 +++++++++++++++++++ 4 files changed, 132 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/airavata/blob/3630458b/modules/app-catalog/app-catalog-cpi/src/main/java/org/airavata/appcatalog/cpi/GwyResourceProfile.java ---------------------------------------------------------------------- diff --git a/modules/app-catalog/app-catalog-cpi/src/main/java/org/airavata/appcatalog/cpi/GwyResourceProfile.java b/modules/app-catalog/app-catalog-cpi/src/main/java/org/airavata/appcatalog/cpi/GwyResourceProfile.java index dd80762..ceb4921 100644 --- a/modules/app-catalog/app-catalog-cpi/src/main/java/org/airavata/appcatalog/cpi/GwyResourceProfile.java +++ b/modules/app-catalog/app-catalog-cpi/src/main/java/org/airavata/appcatalog/cpi/GwyResourceProfile.java @@ -25,7 +25,7 @@ public interface GwyResourceProfile { * @param gatewayId * @return */ - org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile getGatewayProfile (String gatewayId) throws AppCatalogException; + GatewayResourceProfile getGatewayProfile (String gatewayId) throws AppCatalogException; /** * This method will remove a gateway profile http://git-wip-us.apache.org/repos/asf/airavata/blob/3630458b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/impl/GwyResourceProfileImpl.java ---------------------------------------------------------------------- diff --git a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/impl/GwyResourceProfileImpl.java b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/impl/GwyResourceProfileImpl.java index 3d3bdbc..c4eb791 100644 --- a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/impl/GwyResourceProfileImpl.java +++ b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/impl/GwyResourceProfileImpl.java @@ -32,6 +32,7 @@ import org.apache.aiaravata.application.catalog.data.resources.GatewayProfileRes import org.apache.aiaravata.application.catalog.data.resources.Resource; import org.apache.aiaravata.application.catalog.data.util.AppCatalogThriftConversion; import org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference; +import org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -106,7 +107,7 @@ public class GwyResourceProfileImpl implements GwyResourceProfile { } @Override - public org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile getGatewayProfile(String gatewayId) throws AppCatalogException { + public GatewayResourceProfile getGatewayProfile(String gatewayId) throws AppCatalogException { try { GatewayProfileResource resource = new GatewayProfileResource(); GatewayProfileResource gwresource = (GatewayProfileResource)resource.get(gatewayId); http://git-wip-us.apache.org/repos/asf/airavata/blob/3630458b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/ComputeHostPreferenceResource.java ---------------------------------------------------------------------- diff --git a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/ComputeHostPreferenceResource.java b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/ComputeHostPreferenceResource.java index 14d6070..2049bb3 100644 --- a/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/ComputeHostPreferenceResource.java +++ b/modules/app-catalog/app-catalog-data/src/main/java/org/apache/aiaravata/application/catalog/data/resources/ComputeHostPreferenceResource.java @@ -338,6 +338,7 @@ public class ComputeHostPreferenceResource extends AbstractResource { existingPreference.setPreferedDataMoveProtocol(preferedDMProtocol); existingPreference.setScratchLocation(scratchLocation); existingPreference.setProjectNumber(projectNumber); + existingPreference.setBatchQueue(batchQueue); em.merge(existingPreference); } else { ComputeResourcePreference resourcePreference = new ComputeResourcePreference(); @@ -350,6 +351,7 @@ public class ComputeHostPreferenceResource extends AbstractResource { resourcePreference.setPreferedDataMoveProtocol(preferedDMProtocol); resourcePreference.setScratchLocation(scratchLocation); resourcePreference.setProjectNumber(projectNumber); + resourcePreference.setBatchQueue(batchQueue); em.persist(resourcePreference); } em.getTransaction().commit(); http://git-wip-us.apache.org/repos/asf/airavata/blob/3630458b/modules/app-catalog/app-catalog-data/src/test/java/org/apache/airavata/app/catalog/test/GatewayProfileTest.java ---------------------------------------------------------------------- diff --git a/modules/app-catalog/app-catalog-data/src/test/java/org/apache/airavata/app/catalog/test/GatewayProfileTest.java b/modules/app-catalog/app-catalog-data/src/test/java/org/apache/airavata/app/catalog/test/GatewayProfileTest.java new file mode 100644 index 0000000..66eb6bb --- /dev/null +++ b/modules/app-catalog/app-catalog-data/src/test/java/org/apache/airavata/app/catalog/test/GatewayProfileTest.java @@ -0,0 +1,127 @@ +/* + * + * 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.test; + +import org.airavata.appcatalog.cpi.AppCatalog; +import org.airavata.appcatalog.cpi.AppCatalogException; +import org.airavata.appcatalog.cpi.ComputeResource; +import org.airavata.appcatalog.cpi.GwyResourceProfile; +import org.apache.aiaravata.application.catalog.data.impl.AppCatalogFactory; +import org.apache.airavata.app.catalog.test.util.Initialize; +import org.apache.airavata.common.utils.AiravataUtils; +import org.apache.airavata.model.appcatalog.computeresource.ComputeResourceDescription; +import org.apache.airavata.model.appcatalog.computeresource.DataMovementProtocol; +import org.apache.airavata.model.appcatalog.computeresource.JobSubmissionProtocol; +import org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference; +import org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertTrue; + +public class GatewayProfileTest { + private static Initialize initialize; + private static AppCatalog appcatalog; + + @Before + public void setUp() { + try { + AiravataUtils.setExecutionAsServer(); + initialize = new Initialize("appcatalog-derby.sql"); + initialize.initializeDB(); + appcatalog = AppCatalogFactory.getAppCatalog(); + } catch (AppCatalogException e) { + e.printStackTrace(); + } + } + + @After + public void tearDown() throws Exception { + System.out.println("********** TEAR DOWN ************"); + initialize.stopDerbyServer(); + } + + @Test + public void gatewayProfileTest() throws Exception { + GwyResourceProfile gatewayProfile = appcatalog.getGatewayProfile(); + GatewayResourceProfile gf = new GatewayResourceProfile(); + gf.setGatewayName("test"); + gf.setGatewayDescription("test gateway"); + ComputeResource computeRs = appcatalog.getComputeResource(); + ComputeResourceDescription cm1 = new ComputeResourceDescription(); + cm1.setHostName("localhost"); + cm1.setResourceDescription("test compute host"); + String hostId1 = computeRs.addComputeResource(cm1); + + ComputeResourceDescription cm2 = new ComputeResourceDescription(); + cm2.setHostName("localhost"); + cm2.setResourceDescription("test compute host"); + String hostId2 = computeRs.addComputeResource(cm2); + + ComputeResourcePreference preference1 = new ComputeResourcePreference(); + preference1.setComputeResourceId(hostId1); + preference1.setOverridebyAiravata(true); + preference1.setPreferredJobSubmissionProtocol(JobSubmissionProtocol.SSH.toString()); + preference1.setPreferredDataMovementProtocol(DataMovementProtocol.SCP.toString()); + preference1.setPreferredBatchQueue("queue1"); + preference1.setScratchLocation("/tmp"); + preference1.setAllocationProjectNumber("project1"); + + ComputeResourcePreference preference2 = new ComputeResourcePreference(); + preference2.setComputeResourceId(hostId2); + preference2.setOverridebyAiravata(true); + preference2.setPreferredJobSubmissionProtocol(JobSubmissionProtocol.LOCAL.toString()); + preference2.setPreferredDataMovementProtocol(DataMovementProtocol.GridFTP.toString()); + preference2.setPreferredBatchQueue("queue2"); + preference2.setScratchLocation("/tmp"); + preference2.setAllocationProjectNumber("project2"); + + List<ComputeResourcePreference> list = new ArrayList<ComputeResourcePreference>(); + list.add(preference1); + list.add(preference2); + gf.setComputeResourcePreferences(list); + + String gwId = gatewayProfile.addGatewayResourceProfile(gf); + GatewayResourceProfile retrievedProfile = null; + if (gatewayProfile.isGatewayResourceProfileExists(gwId)){ + retrievedProfile = gatewayProfile.getGatewayProfile(gwId); + System.out.println("************ gateway name ************** :" + retrievedProfile.getGatewayName()); + } + List<ComputeResourcePreference> preferences = gatewayProfile.getAllComputeResourcePreferences(gwId); + System.out.println("compute preferences size : " + preferences.size()); + if (preferences != null && !preferences.isEmpty()){ + for (ComputeResourcePreference cm : preferences){ + System.out.println("******** host id ********* : " + cm.getComputeResourceId()); + System.out.println(cm.getPreferredBatchQueue()); + System.out.println(cm.getPreferredDataMovementProtocol()); + System.out.println(cm.getPreferredJobSubmissionProtocol()); + } + } + + assertTrue("App interface saved successfully", retrievedProfile != null); + } + +}
