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/10/05 19:47:30 UTC

[airavata-django-portal] 19/24: AIRAVATA-3477 test logic around initializing experiment's GRP

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 ea6d5b9abd028346b9e2527299b59f03c93847a5
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Tue Sep 28 13:57:34 2021 -0400

    AIRAVATA-3477 test logic around initializing experiment's GRP
---
 .../api/static/django_airavata_api/js/index.js     |   2 +
 .../js/web-components/store.js                     |  56 +++++---
 .../tests/unit/web-components/store.spec.js        | 156 ++++++++++++++++++++-
 3 files changed, 191 insertions(+), 23 deletions(-)

diff --git a/django_airavata/apps/api/static/django_airavata_api/js/index.js b/django_airavata/apps/api/static/django_airavata_api/js/index.js
index 7728bea..ca08f1d 100644
--- a/django_airavata/apps/api/static/django_airavata_api/js/index.js
+++ b/django_airavata/apps/api/static/django_airavata_api/js/index.js
@@ -38,6 +38,7 @@ import StoragePreference from "./models/StoragePreference";
 import SummaryType from "./models/SummaryType";
 import UserConfigurationData from "./models/UserConfigurationData";
 import UserPermission from "./models/UserPermission";
+import WorkspacePreferences from "./models/WorkspacePreferences";
 
 import CloudJobSubmissionService from "./services/CloudJobSubmissionService";
 import GlobusJobSubmissionService from "./services/GlobusJobSubmissionService";
@@ -99,6 +100,7 @@ const models = {
   SummaryType,
   UserConfigurationData,
   UserPermission,
+  WorkspacePreferences,
 };
 
 const services = {
diff --git a/django_airavata/apps/workspace/static/django_airavata_workspace/js/web-components/store.js b/django_airavata/apps/workspace/static/django_airavata_workspace/js/web-components/store.js
index cfc98ab..a0e7e4d 100644
--- a/django_airavata/apps/workspace/static/django_airavata_workspace/js/web-components/store.js
+++ b/django_airavata/apps/workspace/static/django_airavata_workspace/js/web-components/store.js
@@ -101,7 +101,7 @@ export const actions = {
     commit("setExperiment", { experiment });
     await dispatch("loadExperimentData");
   },
-  async loadExperimentData({ commit, dispatch, getters, state }) {
+  async loadExperimentData({ commit, dispatch, state }) {
     await Promise.all([
       dispatch("loadProjects"),
       dispatch("loadWorkspacePreferences"),
@@ -113,28 +113,47 @@ export const actions = {
         projectId: state.workspacePreferences.most_recent_project_id,
       });
     }
+
+    dispatch("initializeGroupResourceProfileId");
+    const groupResourceProfileId =
+      state.experiment.userConfigurationData.groupResourceProfileId;
+    // If experiment has a group resource profile, load additional necessary
+    // data and re-apply group resource profile
+    if (groupResourceProfileId) {
+      await dispatch("loadApplicationDeployments");
+      await dispatch("loadAppDeploymentQueues");
+      await dispatch("applyGroupResourceProfile");
+    }
+  },
+  initializeGroupResourceProfileId({ commit, getters, state }) {
     // If there is no groupResourceProfileId set on the experiment, or there
     // is one set but it is no longer in the list of accessible
-    // groupResourceProfiles, set to the default one
+    // groupResourceProfiles, set to the default one, or the first one
     let groupResourceProfileId =
       state.experiment.userConfigurationData.groupResourceProfileId;
     if (
       !groupResourceProfileId ||
       !getters.findGroupResourceProfile(groupResourceProfileId)
     ) {
-      commit("updateGroupResourceProfileId", {
-        groupResourceProfileId:
-          state.workspacePreferences.most_recent_group_resource_profile_id,
-      });
-    }
-    groupResourceProfileId =
-      state.experiment.userConfigurationData.groupResourceProfileId;
-    // If experiment has a group resource profile and user has access to it,
-    // load additional necessary data and re-apply group resource profile
-    if (getters.findGroupResourceProfile(groupResourceProfileId)) {
-      await dispatch("loadApplicationDeployments");
-      await dispatch("loadAppDeploymentQueues");
-      await dispatch("applyGroupResourceProfile");
+      if (
+        getters.findGroupResourceProfile(
+          state.workspacePreferences.most_recent_group_resource_profile_id
+        )
+      ) {
+        commit("updateGroupResourceProfileId", {
+          groupResourceProfileId:
+            state.workspacePreferences.most_recent_group_resource_profile_id,
+        });
+      } else if (state.groupResourceProfiles.length > 0) {
+        commit("updateGroupResourceProfileId", {
+          groupResourceProfileId:
+            state.groupResourceProfiles[0].groupResourceProfileId,
+        });
+      } else {
+        commit("updateGroupResourceProfileId", {
+          groupResourceProfileId: null,
+        });
+      }
     }
   },
   updateExperimentName({ commit }, { name }) {
@@ -263,15 +282,14 @@ export const actions = {
       commit("setAppDeploymentQueues", { appDeploymentQueues: [] });
     }
   },
-  async setDefaultQueue({ commit, dispatch, getters }) {
+  async setDefaultQueue({ dispatch, getters }) {
     // set to the default queue or the first one
     const defaultQueue = getters.defaultQueue;
     if (defaultQueue) {
-      commit("updateQueueName", { queueName: defaultQueue.queueName });
+      dispatch("updateQueueName", { queueName: defaultQueue.queueName });
     } else {
-      commit("updateQueueName", { queueName: null });
+      dispatch("updateQueueName", { queueName: null });
     }
-    dispatch("initializeQueue");
   },
   initializeQueue({ commit, getters }) {
     const queue = getters.queue;
diff --git a/django_airavata/apps/workspace/static/django_airavata_workspace/tests/unit/web-components/store.spec.js b/django_airavata/apps/workspace/static/django_airavata_workspace/tests/unit/web-components/store.spec.js
index 8bc1606..615a806 100644
--- a/django_airavata/apps/workspace/static/django_airavata_workspace/tests/unit/web-components/store.spec.js
+++ b/django_airavata/apps/workspace/static/django_airavata_workspace/tests/unit/web-components/store.spec.js
@@ -1,4 +1,4 @@
-import { actions, mutations } from "@/web-components/store.js";
+import { actions, getters, mutations } from "@/web-components/store.js";
 import { models } from "django-airavata-api";
 
 /*
@@ -160,7 +160,7 @@ test("applyBatchQueueResourcePolicy: maxAllowedWalltime caps wallTimeLimit", (do
       maxAllowedWalltime: 6,
     },
     expectedMutations: [
-      { type: "updateWallTimeLimit", payload: { wallTimeLimit: 6} },
+      { type: "updateWallTimeLimit", payload: { wallTimeLimit: 6 } },
     ],
     done,
   });
@@ -178,8 +178,156 @@ test("applyBatchQueueResourcePolicy: maxAllowedWalltime doesn't affect wallTimeL
       maxAllowedNodes: 2,
       maxAllowedWalltime: 120,
     },
-    expectedMutations: [
-    ],
+    expectedMutations: [],
     done,
   });
 });
+
+test("initializeGroupResourceProfileId: set to most recent group resource profile when null", (done) => {
+  const state = {};
+  state.experiment = new models.Experiment();
+  state.workspacePreferences = new models.WorkspacePreferences();
+  state.workspacePreferences.most_recent_group_resource_profile_id =
+    "ec50a69d-54ea-4b7c-a578-9a2a8da09ba0";
+  state.groupResourceProfiles = [
+    new models.GroupResourceProfile({
+      groupResourceProfileId:
+        state.workspacePreferences.most_recent_group_resource_profile_id,
+    }),
+  ];
+
+  const g = {
+    experiment: state.experiment,
+    findGroupResourceProfile: (groupResourceProfileId) =>
+      getters.findGroupResourceProfile(state)(groupResourceProfileId),
+  };
+  const expectedMutations = [
+    {
+      type: "updateGroupResourceProfileId",
+      payload: {
+        groupResourceProfileId:
+          state.workspacePreferences.most_recent_group_resource_profile_id,
+      },
+    },
+  ];
+  testAction(
+    actions.initializeGroupResourceProfileId,
+    null,
+    state,
+    g,
+    expectedMutations,
+    done
+  );
+});
+
+test("initializeGroupResourceProfileId: set to most recent group resource profile when no longer has access to grp", (done) => {
+  const state = {};
+  state.experiment = new models.Experiment();
+  state.experiment.userConfigurationData.groupResourceProfileId =
+    "2580d4e6-7a8d-444e-b259-a8e6ae886d66";
+  state.workspacePreferences = new models.WorkspacePreferences();
+  state.workspacePreferences.most_recent_group_resource_profile_id =
+    "ec50a69d-54ea-4b7c-a578-9a2a8da09ba0";
+  state.groupResourceProfiles = [
+    new models.GroupResourceProfile({
+      groupResourceProfileId:
+        state.workspacePreferences.most_recent_group_resource_profile_id,
+    }),
+  ];
+  // experiment's grp isn't in the list of available grps
+  expect(
+    state.groupResourceProfiles.find(
+      (grp) =>
+        grp.groupResourceProfileId ===
+        state.experiment.userConfigurationData.groupResourceProfileId
+    )
+  ).toBeUndefined();
+  const g = {
+    experiment: state.experiment,
+    findGroupResourceProfile: (groupResourceProfileId) =>
+      getters.findGroupResourceProfile(state)(groupResourceProfileId),
+  };
+  const expectedMutations = [
+    {
+      type: "updateGroupResourceProfileId",
+      payload: {
+        groupResourceProfileId:
+          state.workspacePreferences.most_recent_group_resource_profile_id,
+      },
+    },
+  ];
+  testAction(
+    actions.initializeGroupResourceProfileId,
+    null,
+    state,
+    g,
+    expectedMutations,
+    done
+  );
+});
+
+test("initializeGroupResourceProfileId: set to first group resource profile when no most recent grp", (done) => {
+  const state = {};
+  state.experiment = new models.Experiment();
+  state.experiment.userConfigurationData.groupResourceProfileId =
+    "2580d4e6-7a8d-444e-b259-a8e6ae886d66";
+  state.workspacePreferences = new models.WorkspacePreferences();
+  state.workspacePreferences.most_recent_group_resource_profile_id = null;
+  state.groupResourceProfiles = [
+    new models.GroupResourceProfile({
+      groupResourceProfileId: "c84da77b-8ce6-457f-b5c7-c72a663d7f77",
+    }),
+  ];
+  const g = {
+    experiment: state.experiment,
+    findGroupResourceProfile: (groupResourceProfileId) =>
+      getters.findGroupResourceProfile(state)(groupResourceProfileId),
+  };
+  const expectedMutations = [
+    {
+      type: "updateGroupResourceProfileId",
+      payload: {
+        groupResourceProfileId: "c84da77b-8ce6-457f-b5c7-c72a663d7f77",
+      },
+    },
+  ];
+  testAction(
+    actions.initializeGroupResourceProfileId,
+    null,
+    state,
+    g,
+    expectedMutations,
+    done
+  );
+});
+
+test("initializeGroupResourceProfileId: set to null when no longer has access", (done) => {
+  const state = {};
+  state.experiment = new models.Experiment();
+  state.experiment.userConfigurationData.groupResourceProfileId =
+    "2580d4e6-7a8d-444e-b259-a8e6ae886d66";
+  state.workspacePreferences = new models.WorkspacePreferences();
+  state.workspacePreferences.most_recent_group_resource_profile_id = null;
+  state.groupResourceProfiles = [];
+  const g = {
+    experiment: state.experiment,
+    findGroupResourceProfile: (groupResourceProfileId) =>
+      getters.findGroupResourceProfile(state)(groupResourceProfileId),
+  };
+  const expectedMutations = [
+    {
+      type: "updateGroupResourceProfileId",
+      payload: {
+        groupResourceProfileId: null,
+      },
+    },
+  ];
+  testAction(
+    actions.initializeGroupResourceProfileId,
+    null,
+    state,
+    g,
+    expectedMutations,
+    done
+  );
+});