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 2021/07/30 18:35:40 UTC
[airavata-django-portal] 04/06: AIRAVATA-3491 Accept application
module id as input too
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal.git
commit 9eed16fd9dfa72530d2d4e0a52b0ff4b5087e493
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Fri Jul 30 13:19:31 2021 -0400
AIRAVATA-3491 Accept application module id as input too
---
.../js/utils/ExperimentUtils.js | 21 +++++++++++++----
.../tests/utils/ExperimentUtils.test.js | 27 +++++++++++++++++++++-
2 files changed, 42 insertions(+), 6 deletions(-)
diff --git a/django_airavata/apps/api/static/django_airavata_api/js/utils/ExperimentUtils.js b/django_airavata/apps/api/static/django_airavata_api/js/utils/ExperimentUtils.js
index 2e6cea0..0088e27 100644
--- a/django_airavata/apps/api/static/django_airavata_api/js/utils/ExperimentUtils.js
+++ b/django_airavata/apps/api/static/django_airavata_api/js/utils/ExperimentUtils.js
@@ -2,17 +2,22 @@ import { services } from "../index";
const createExperiment = async function ({
applicationName, // name of the application interface (usually the same as the application module)
+ applicationId, // the id of the application module
computeResourceName,
experimentName,
experimentInputs,
} = {}) {
let applicationInterface = null;
- if (applicationName) {
+ if (applicationId) {
+ applicationInterface = await loadApplicationInterfaceByApplicationModuleId(
+ applicationId
+ );
+ } else if (applicationName) {
applicationInterface = await loadApplicationInterfaceByName(
applicationName
);
} else {
- throw new Error("applicationName is required");
+ throw new Error("Either applicationName or applicationId is required");
}
const applicationModuleId = applicationInterface.applicationModuleId;
let computeResourceId = null;
@@ -85,6 +90,14 @@ const loadApplicationInterfaceByName = async function (applicationName) {
return applicationInterface;
};
+const loadApplicationInterfaceByApplicationModuleId = async function (
+ applicationId
+) {
+ return await services.ApplicationModuleService.getApplicationInterface({
+ lookup: applicationId,
+ });
+};
+
const loadComputeResourceIdByName = async function (computeResourceName) {
const computeResourceNames = await services.ComputeResourceService.names();
for (const computeResourceId in computeResourceNames) {
@@ -146,9 +159,7 @@ const loadWorkspacePreferences = async function () {
return await services.WorkspacePreferencesService.get();
};
-export {
- createExperiment,
-};
+export { createExperiment };
export default {
createExperiment,
diff --git a/django_airavata/apps/api/static/django_airavata_api/tests/utils/ExperimentUtils.test.js b/django_airavata/apps/api/static/django_airavata_api/tests/utils/ExperimentUtils.test.js
index 02ecde7..8e64229 100644
--- a/django_airavata/apps/api/static/django_airavata_api/tests/utils/ExperimentUtils.test.js
+++ b/django_airavata/apps/api/static/django_airavata_api/tests/utils/ExperimentUtils.test.js
@@ -14,7 +14,9 @@ test("error thrown when no applicationName given", async () => {
await createExperiment();
} catch (e) {
expect(e).toBeInstanceOf(Error);
- expect(e.message).toEqual("applicationName is required");
+ expect(e.message).toEqual(
+ "Either applicationName or applicationId is required"
+ );
}
});
@@ -40,6 +42,29 @@ test("error thrown with applicationName doesn't match any interfaces", async ()
}
});
+test("verify if applicationId and applicationName are given, applicationInterface is loaded with applicationId", async () => {
+ services.ApplicationModuleService.getApplicationInterface.mockResolvedValue(
+ new ApplicationInterfaceDefinition({
+ applicationName: "Foo",
+ applicationModules: ["Foo_module1"],
+ })
+ );
+ try {
+ expect.assertions(2);
+ await createExperiment({
+ applicationId: "Foo_module1",
+ applicationName: "Foo",
+ });
+ } catch (e) {
+ expect(services.ApplicationModuleService.list).not.toHaveBeenCalled();
+ expect(
+ services.ApplicationModuleService.getApplicationInterface
+ ).toHaveBeenCalledWith({
+ lookup: "Foo_module1",
+ });
+ }
+});
+
test("error thrown when no computeResourceName given", async () => {
services.ApplicationInterfaceService.list.mockResolvedValue([
new ApplicationInterfaceDefinition({