@eclipse-slm/ui 1.5.0-snapshot.1 → 1.5.0-snapshot.1024

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/README.md +8 -0
  2. package/package.json +9 -7
  3. package/src/api/ansible-service/ansible-service-client.ts +15 -0
  4. package/src/api/ansible-service/ansible-service-sse.ts +124 -0
  5. package/src/api/notification-service/notificationServiceWebsocketClient.js +5 -5
  6. package/src/api/platform-management/platform-management-client.ts +2 -2
  7. package/src/api/resource-management/resource-management-client.ts +0 -2
  8. package/src/app/appInstance.ts +8 -0
  9. package/src/app/navigation.ts +21 -0
  10. package/src/app/routes.ts +23 -0
  11. package/src/components/admin/ansible/AnsibleAdminImages.vue +113 -0
  12. package/src/components/admin/ansible/AnsibleAdminJobs.vue +179 -0
  13. package/src/components/admin/ansible/AnsibleAdminOperations.vue +124 -0
  14. package/src/components/base/ConfirmDialog.vue +39 -25
  15. package/src/components/base/CustomDialog.vue +31 -3
  16. package/src/components/base/IconPickerDialog.vue +155 -0
  17. package/src/components/capabilities/CapabilitiesTable.vue +209 -0
  18. package/src/components/capabilities/CapabilityActionCard.vue +77 -0
  19. package/src/components/capabilities/CapabilityCreateDialog.vue +86 -0
  20. package/src/components/capabilities/CapabilityCreateForm.vue +306 -0
  21. package/src/components/capabilities/CapabilityImportDialog.vue +108 -0
  22. package/src/components/capabilities/capabilityForm.ts +244 -0
  23. package/src/components/core/AppBar.vue +1 -1
  24. package/src/components/core/Drawer.vue +12 -2
  25. package/src/components/jobs/JobDetail.vue +413 -0
  26. package/src/components/jobs/JobStatusChip.vue +16 -0
  27. package/src/components/jobs/JobsOverview.vue +59 -72
  28. package/src/components/profilers/ProfilerDialog.vue +95 -0
  29. package/src/components/profilers/ProfilerForm.vue +102 -0
  30. package/src/components/profilers/ProfilersTable.vue +98 -0
  31. package/src/components/profilers/profilerForm.ts +61 -0
  32. package/src/components/resources/deviceinfo/DeviceInfoView.vue +9 -1
  33. package/src/components/resources/dialogs/AddItemChooserDialog.vue +68 -0
  34. package/src/components/service_offerings/ServiceOfferingCardGrid.vue +1 -1
  35. package/src/components/service_offerings/wizard_service_offering_version/ServiceOfferingVersionWizardStep2DeploymentDefinitionDockerCompose.vue +1 -2
  36. package/src/components/service_offerings/wizard_service_offering_version/ServiceOfferingVersionWizardStep2DeploymentDefinitionKubernetes.vue +1 -2
  37. package/src/components/service_vendors/ServiceVendorDevelopersTable.vue +1 -1
  38. package/src/docker/entrypoint.sh +2 -2
  39. package/src/localisation/en.json +93 -0
  40. package/src/main.ts +3 -6
  41. package/src/pages/AdminAnsibleServicePage.vue +111 -0
  42. package/src/pages/AdminCapabilitiesPage.vue +60 -0
  43. package/src/pages/AdminProfilersPage.vue +73 -0
  44. package/src/pages/DashboardPage.vue +28 -56
  45. package/src/pages/JobDetailPage.vue +7 -0
  46. package/src/pages/ResourceInstancesPage.vue +71 -0
  47. package/src/pages/ServiceOfferingCreateOrEditPage.vue +2 -2
  48. package/src/stores/ansibleAdminStore.ts +206 -0
  49. package/src/stores/capabilitiesStore.ts +45 -2
  50. package/src/stores/environmentStore.ts +3 -3
  51. package/src/stores/jobsStore.ts +39 -39
  52. package/src/stores/notificationStore.ts +15 -1
  53. package/src/stores/profilersStore.ts +80 -0
  54. package/src/stores/resourceDevicesStore.ts +2 -2
  55. package/src/stores/serviceInstancesStore.ts +0 -1
  56. package/src/stores/serviceOfferingsStore.ts +1 -1
  57. package/src/stores/userStore.ts +1 -1
  58. package/src/utils/i18n.ts +4 -2
  59. package/src/utils/imageUtil.js +1 -1
  60. package/src/utils/jobStatus.ts +76 -0
  61. package/src/utils/mdiIcons.ts +49 -0
  62. package/src/utils/notificationTextGenerator.ts +27 -1
  63. package/src/utils/tokenInterceptor.js +1 -1
  64. package/src/utils/updateToken.js +1 -1
  65. package/vite/dist/apiClients.d.ts +1 -1
  66. package/vite/dist/apiClients.js +1 -0
  67. package/vite/dist/index.js +25 -4
@@ -52,7 +52,70 @@
52
52
  @canceled="showCreateDialog = false"
53
53
  @confirmed="showCreateDialog = false"
54
54
  />
55
+ <CapabilityCreateDialog
56
+ :show="showCapabilityDialog"
57
+ @canceled="showCapabilityDialog = false"
58
+ @confirmed="showCapabilityDialog = false"
59
+ />
60
+ <AddItemChooserDialog
61
+ :show="showChooserDialog"
62
+ @canceled="showChooserDialog = false"
63
+ @device="showChooserDialog = false; showCreateDialog = true"
64
+ @capability="showChooserDialog = false; showCapabilityDialog = true"
65
+ />
66
+ <!-- Speed dial sits inside the fab with activator="parent": with :app the fab's root element is the
67
+ full-height layout wrapper, so using it as activator would anchor the sub-buttons at the top of the page -->
68
+ <v-fab
69
+ v-if="isAdmin"
70
+ :active="!showCreateButton"
71
+ icon
72
+ class="mx-4"
73
+ elevation="15"
74
+ color="primary"
75
+ location="right bottom"
76
+ :app="true"
77
+ @click="showChooserDialog = true"
78
+ >
79
+ <v-icon>mdi-plus</v-icon>
80
+ <v-speed-dial
81
+ activator="parent"
82
+ open-on-hover
83
+ location="left center"
84
+ >
85
+ <v-fab
86
+ key="device"
87
+ icon
88
+ size="small"
89
+ color="primary"
90
+ @click="showCreateDialog = true"
91
+ >
92
+ <v-icon>mdi-devices</v-icon>
93
+ <v-tooltip
94
+ activator="parent"
95
+ location="top"
96
+ >
97
+ Add device
98
+ </v-tooltip>
99
+ </v-fab>
100
+ <v-fab
101
+ key="capability"
102
+ icon
103
+ size="small"
104
+ color="primary"
105
+ @click="showCapabilityDialog = true"
106
+ >
107
+ <v-icon>mdi-puzzle</v-icon>
108
+ <v-tooltip
109
+ activator="parent"
110
+ location="top"
111
+ >
112
+ Add capability
113
+ </v-tooltip>
114
+ </v-fab>
115
+ </v-speed-dial>
116
+ </v-fab>
55
117
  <v-fab
118
+ v-else
56
119
  :active="!showCreateButton"
57
120
  icon="mdi-plus"
58
121
  class="mx-4"
@@ -77,14 +140,22 @@ import DeviceInfoView from "@/components/resources/deviceinfo/DeviceInfoView.vue
77
140
  import OverviewHeading from "@/components/base/OverviewHeading.vue";
78
141
  import ResourcesTableDevices from "@/components/resources/ResourcesTableDevices.vue";
79
142
  import {useCapabilitiesStore} from "@/stores/capabilitiesStore";
143
+ import {useUserStore} from "@/stores/userStore";
144
+ import AddItemChooserDialog from "@/components/resources/dialogs/AddItemChooserDialog.vue";
145
+ import CapabilityCreateDialog from "@/components/capabilities/CapabilityCreateDialog.vue";
80
146
 
81
147
  const resourceDevicesStore = useResourceDevicesStore();
82
148
  const capabilitiesStore = useCapabilitiesStore();
149
+ const userStore = useUserStore();
150
+
151
+ const isAdmin = computed(() => userStore.userRoles.includes('slm-admin'));
83
152
 
84
153
  const selectedResource = ref(null);
85
154
  const selectedSection = ref("common");
86
155
  const showCreateDialog = ref(false);
87
156
  const showCreateButton = ref(false);
157
+ const showChooserDialog = ref(false);
158
+ const showCapabilityDialog = ref(false);
88
159
 
89
160
  const resources = computed(() => resourceDevicesStore.resources);
90
161
 
@@ -114,7 +114,7 @@ export default {
114
114
  serviceVendorId: this.serviceVendorId,
115
115
  description: 'My new service description',
116
116
  shortDescription: 'My new service short description',
117
- coverImage: 'none',
117
+ coverImage: null,
118
118
  serviceCategoryId: null,
119
119
  },
120
120
  }
@@ -149,7 +149,7 @@ export default {
149
149
  onStepCompleted (stepNumber) {
150
150
  switch (stepNumber) {
151
151
  case 1:
152
- if (this.newServiceOffering.coverImage.includes('image/')) {
152
+ if (this.newServiceOffering.coverImage?.includes('image/')) {
153
153
  this.newServiceOffering.coverImage =
154
154
  this.newServiceOffering.coverImage.slice(this.newServiceOffering.coverImage.indexOf(',') + 1, this.newServiceOffering.coverImage.length)
155
155
  }
@@ -0,0 +1,206 @@
1
+ import {defineStore} from "pinia";
2
+ import AnsibleServiceClient from "@/api/ansible-service/ansible-service-client";
3
+ import type {
4
+ AnsibleImageDTO,
5
+ AnsibleJobDTO,
6
+ AnsibleJobStatus,
7
+ AnsibleServiceStatusDTO,
8
+ } from "@/api/ansible-service/client";
9
+ import logRequestError from "@/api/restApiHelper";
10
+ import ApiState from "@/api/apiState";
11
+
12
+ const POLL_INTERVAL_MS = 5000;
13
+ const PULL_POLL_INTERVAL_MS = 3000;
14
+
15
+ export type SinceRange = '1h' | '24h' | '7d' | '30d' | 'all';
16
+
17
+ const SINCE_MS: Record<Exclude<SinceRange, 'all'>, number> = {
18
+ '1h': 3600_000,
19
+ '24h': 24 * 3600_000,
20
+ '7d': 7 * 24 * 3600_000,
21
+ '30d': 30 * 24 * 3600_000,
22
+ };
23
+
24
+ const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
25
+
26
+ export function isUuid(value: string): boolean {
27
+ return UUID_PATTERN.test(value.trim());
28
+ }
29
+
30
+ export interface AdminJobFilter {
31
+ status: AnsibleJobStatus | null,
32
+ resourceId: string,
33
+ user: string,
34
+ since: SinceRange,
35
+ }
36
+
37
+ export type AdminNoticeKind =
38
+ 'pull-started' | 'pull-success' | 'pull-failed' | 'pull-conflict' | 'pull-not-allowed' | 'pull-unavailable' | 'pull-error';
39
+
40
+ export interface AdminNotice {
41
+ id: number,
42
+ kind: AdminNoticeKind,
43
+ image: string,
44
+ detail?: string,
45
+ }
46
+
47
+ export interface AnsibleAdminStoreState {
48
+ apiState: number,
49
+ jobs: AnsibleJobDTO[],
50
+ status: AnsibleServiceStatusDTO | null,
51
+ images: AnsibleImageDTO[],
52
+ filter: AdminJobFilter,
53
+ watchedImages: string[],
54
+ notice: AdminNotice | null,
55
+ }
56
+
57
+ let pollTimer: ReturnType<typeof setInterval> | null = null;
58
+ let pullTimer: ReturnType<typeof setInterval> | null = null;
59
+ let noticeCounter = 0;
60
+
61
+ export const useAnsibleAdminStore = defineStore('ansibleAdminStore', {
62
+ state: (): AnsibleAdminStoreState => ({
63
+ apiState: ApiState.INIT,
64
+ jobs: [],
65
+ status: null,
66
+ images: [],
67
+ filter: {status: null, resourceId: '', user: '', since: '24h'},
68
+ watchedImages: [],
69
+ notice: null,
70
+ }),
71
+
72
+ actions: {
73
+ async loadStatus() {
74
+ try {
75
+ this.status = (await AnsibleServiceClient.adminApi.getStatus()).data ?? null;
76
+ } catch (e) {
77
+ logRequestError(e);
78
+ throw e;
79
+ }
80
+ },
81
+
82
+ async loadImages() {
83
+ try {
84
+ this.images = (await AnsibleServiceClient.adminApi.getImages()).data ?? [];
85
+ } catch (e) {
86
+ logRequestError(e);
87
+ throw e;
88
+ }
89
+ },
90
+
91
+ async loadAdminJobs(filter: AdminJobFilter = this.filter) {
92
+ this.filter = {...filter};
93
+ const resourceId = filter.resourceId.trim();
94
+ const user = filter.user.trim();
95
+ const since = filter.since === 'all'
96
+ ? undefined
97
+ : new Date(Date.now() - SINCE_MS[filter.since]).toISOString();
98
+ try {
99
+ const result = await AnsibleServiceClient.jobsApi.getJobs(
100
+ resourceId && isUuid(resourceId) ? resourceId : undefined,
101
+ filter.status ?? undefined,
102
+ user || undefined,
103
+ since);
104
+ this.jobs = [...(result.data ?? [])].sort(
105
+ (a, b) => new Date(b.createdAt ?? 0).getTime() - new Date(a.createdAt ?? 0).getTime());
106
+ } catch (e) {
107
+ logRequestError(e);
108
+ throw e;
109
+ }
110
+ },
111
+
112
+ async cancelJob(jobId: string) {
113
+ await AnsibleServiceClient.jobsApi.cancelJob(jobId);
114
+ await this.loadAdminJobs();
115
+ },
116
+
117
+ async refreshAll() {
118
+ this.apiState = this.apiState === ApiState.INIT ? ApiState.LOADING : ApiState.UPDATING;
119
+ const results = await Promise.allSettled([this.loadAdminJobs(), this.loadStatus(), this.loadImages()]);
120
+ const failed = results.every(r => r.status === 'rejected');
121
+ this.apiState = failed ? ApiState.ERROR : ApiState.LOADED;
122
+ },
123
+
124
+ /** Starts the periodic refresh; to be called when the admin page is shown. */
125
+ startPolling() {
126
+ this.refreshAll().catch(() => undefined);
127
+ if (pollTimer === null) {
128
+ pollTimer = setInterval(() => {
129
+ this.refreshAll().catch(() => undefined);
130
+ }, POLL_INTERVAL_MS);
131
+ }
132
+ },
133
+
134
+ /** Stops all timers; to be called when the admin page is left. */
135
+ stopPolling() {
136
+ if (pollTimer !== null) {
137
+ clearInterval(pollTimer);
138
+ pollTimer = null;
139
+ }
140
+ if (pullTimer !== null) {
141
+ clearInterval(pullTimer);
142
+ pullTimer = null;
143
+ }
144
+ this.watchedImages = [];
145
+ },
146
+
147
+ pushNotice(kind: AdminNoticeKind, image: string, detail?: string) {
148
+ this.notice = {id: ++noticeCounter, kind, image, detail};
149
+ },
150
+
151
+ async pullImage(image: string) {
152
+ try {
153
+ await AnsibleServiceClient.adminApi.pullImage({image});
154
+ } catch (e: any) {
155
+ logRequestError(e);
156
+ const code = e?.response?.status;
157
+ const kind: AdminNoticeKind =
158
+ code === 409 ? 'pull-conflict'
159
+ : code === 400 ? 'pull-not-allowed'
160
+ : code === 503 ? 'pull-unavailable'
161
+ : 'pull-error';
162
+ this.pushNotice(kind, image, e?.response?.data?.message);
163
+ if (code === 409) {
164
+ this.watchPull(image);
165
+ }
166
+ return;
167
+ }
168
+ this.pushNotice('pull-started', image);
169
+ this.watchPull(image);
170
+ },
171
+
172
+ /** Polls the images every 3 s until none of the watched images is pulling any more. */
173
+ watchPull(image: string) {
174
+ if (!this.watchedImages.includes(image)) {
175
+ this.watchedImages.push(image);
176
+ }
177
+ // reflect the running pull immediately
178
+ this.images = this.images.map(i => i.image === image ? {...i, pulling: true} : i);
179
+ if (pullTimer === null) {
180
+ pullTimer = setInterval(() => {
181
+ this.checkWatchedPulls().catch(() => undefined);
182
+ }, PULL_POLL_INTERVAL_MS);
183
+ }
184
+ },
185
+
186
+ async checkWatchedPulls() {
187
+ await this.loadImages();
188
+ for (const name of [...this.watchedImages]) {
189
+ const image = this.images.find(i => i.image === name);
190
+ if (image && image.pulling) {
191
+ continue;
192
+ }
193
+ this.watchedImages = this.watchedImages.filter(n => n !== name);
194
+ if (image?.lastPullError) {
195
+ this.pushNotice('pull-failed', name, image.lastPullError);
196
+ } else {
197
+ this.pushNotice('pull-success', name);
198
+ }
199
+ }
200
+ if (this.watchedImages.length === 0 && pullTimer !== null) {
201
+ clearInterval(pullTimer);
202
+ pullTimer = null;
203
+ }
204
+ },
205
+ }
206
+ });
@@ -1,7 +1,14 @@
1
1
  import ApiState from '@/api/apiState'
2
2
  import {defineStore} from "pinia";
3
3
  import ResourceManagementClient from "@/api/resource-management/resource-management-client";
4
- import {CapabilityServiceDTO, ResourceDTO} from "@/api/resource-management/client";
4
+ import {CapabilityServiceDTO, GetCapabilities200ResponseInner, ResourceDTO} from "@/api/resource-management/client";
5
+
6
+ export class CapabilityInUseError extends Error {
7
+ constructor(public installCount: number) {
8
+ super(`Capability is installed ${installCount} time(s)`)
9
+ this.name = 'CapabilityInUseError'
10
+ }
11
+ }
5
12
 
6
13
  interface CapabilitiesStoreState{
7
14
  apiState: number,
@@ -47,6 +54,10 @@ export const useCapabilitiesStore = defineStore('capabilitiesStore', {
47
54
  return capability;
48
55
  },
49
56
 
57
+ installCountOfCapability: (state) => (capabilityId: string) => {
58
+ return state.capabilityServices.filter(capabilityService => capabilityService.capabilityId === capabilityId).length
59
+ },
60
+
50
61
  isCapabilityInstalledOnResource: (state) => (resource: ResourceDTO, capabilityId) => {
51
62
  for (const capabilityServiceId of resource.capabilityServiceIds) {
52
63
  const capabilityService = state.capabilityServices.find(capabilityService => capabilityService.id === capabilityServiceId)
@@ -93,6 +104,39 @@ export const useCapabilitiesStore = defineStore('capabilitiesStore', {
93
104
  })
94
105
  },
95
106
 
107
+ async createCapability(body: GetCapabilities200ResponseInner) {
108
+ await ResourceManagementClient.capabilityApi.createCapability(body)
109
+ await this.reloadAfterChange()
110
+ },
111
+
112
+ async deleteCapability(capabilityId: string) {
113
+ // Fetch directly (not via getCapabilityServices, which swallows errors) so a failed fetch aborts the delete
114
+ const response = await ResourceManagementClient.capabilityApi.getAllCapabilityServices()
115
+ if (!Array.isArray(response.data)) {
116
+ throw new Error("Could not verify where the capability is installed")
117
+ }
118
+ this.capabilityServices = response.data
119
+
120
+ const installCount = this.installCountOfCapability(capabilityId)
121
+ if (installCount > 0) {
122
+ throw new CapabilityInUseError(installCount)
123
+ }
124
+
125
+ await ResourceManagementClient.capabilityApi.deleteCapability(capabilityId)
126
+ await this.reloadAfterChange()
127
+ // A successful delete is authoritative even if the list reload failed or returned stale data.
128
+ this.capabilities = this.capabilities.filter(capability => capability.id !== capabilityId)
129
+ },
130
+
131
+ // The change already succeeded; a failed reload must not make it look failed (a retry would duplicate it)
132
+ async reloadAfterChange() {
133
+ try {
134
+ await this.getCapabilities()
135
+ } catch (e) {
136
+ console.error('Failed to reload capabilities after a successful change', e)
137
+ }
138
+ },
139
+
96
140
  async updateStore () {
97
141
  if (this.apiState === ApiState.INIT) {
98
142
  this.apiState = ApiState.LOADING;
@@ -113,4 +157,3 @@ export const useCapabilitiesStore = defineStore('capabilitiesStore', {
113
157
  },
114
158
  },
115
159
  });
116
-
@@ -14,13 +14,13 @@ export const useEnvStore = defineStore('envStore', () => {
14
14
  const _platformManagementUrl = ref(import.meta.env.VITE_APP_PLATFORM_MANAGEMENT_URL || (isProduction ? '/__ENV_PLATFORM_MANAGEMENT_URL__PLACEHOLDER__/' : ''));
15
15
  const _resourceManagementUrl = ref(import.meta.env.VITE_APP_RESOURCE_MANAGEMENT_URL || (isProduction ? '/__ENV_RESOURCE_MANAGEMENT_URL__PLACEHOLDER__/' : ''));
16
16
  const _serviceManagementUrl = ref(import.meta.env.VITE_APP_SERVICE_MANAGEMENT_URL || (isProduction ? '/__ENV_SERVICE_MANAGEMENT_URL__PLACEHOLDER__/' : ''));
17
+ const _ansibleServiceUrl = ref(import.meta.env.VITE_APP_ANSIBLE_SERVICE_URL || (isProduction ? '/__ENV_ANSIBLE_SERVICE_URL__PLACEHOLDER__/' : ''));
17
18
  const _catalogServiceUrl = ref(import.meta.env.VITE_APP_CATALOG_SERVICE_URL || (isProduction ? '/__ENV_CATALOG_SERVICE_URL__PLACEHOLDER__/' : ''));
18
19
 
19
20
  const _keycloakUrl = ref(import.meta.env.VITE_APP_KEYCLOAK_URL || (isProduction ? '/__ENV_KEYCLOAK_URL__PLACEHOLDER__/' : ''));
20
21
  const _keycloakRealm = ref(import.meta.env.VITE_APP_KEYCLOAK_REALM || (isProduction ? '/__ENV_KEYCLOAK_REALM__PLACEHOLDER__/' : ''));
21
22
  const _keycloakClientId = ref(import.meta.env.VITE_APP_KEYCLOAK_CLIENT_ID || (isProduction ? '/__ENV_KEYCLOAK_CLIENT_ID__PLACEHOLDER__/' : ''));
22
23
 
23
- const _awxUrl = ref(import.meta.env.VITE_APP_AWX_URL || (isProduction ? '/__ENV_AWX_URL__PLACEHOLDER__/' : ''));
24
24
 
25
25
  const _basyxAasGuiUrl = ref(import.meta.env.VITE_APP_BASYX_AAS_GUI_URL || (isProduction ? '/__ENV_BASYX_AAS_GUI_URL__PLACEHOLDER__/' : ''));
26
26
 
@@ -34,13 +34,13 @@ export const useEnvStore = defineStore('envStore', () => {
34
34
  const platformManagementUrl = computed(() => _platformManagementUrl.value);
35
35
  const resourceManagementUrl = computed(() => _resourceManagementUrl.value);
36
36
  const serviceManagementUrl = computed(() => _serviceManagementUrl.value);
37
+ const ansibleServiceUrl = computed(() => _ansibleServiceUrl.value);
37
38
  const catalogServiceUrl = computed(() => _catalogServiceUrl.value);
38
39
 
39
40
  const keycloakUrl = computed(() => _keycloakUrl.value);
40
41
  const keycloakRealm = computed(() => _keycloakRealm.value);
41
42
  const keycloakClientId = computed(() => _keycloakClientId.value);
42
43
 
43
- const awxUrl = computed(() => _awxUrl.value);
44
44
 
45
45
  const basyxAasGuiUrl = computed(() => _basyxAasGuiUrl.value);
46
46
 
@@ -51,11 +51,11 @@ export const useEnvStore = defineStore('envStore', () => {
51
51
  notificationServiceUrl,
52
52
  resourceManagementUrl,
53
53
  serviceManagementUrl,
54
+ ansibleServiceUrl,
54
55
  catalogServiceUrl,
55
56
  keycloakUrl,
56
57
  keycloakRealm,
57
58
  keycloakClientId,
58
- awxUrl,
59
59
  basyxAasGuiUrl,
60
60
  };
61
61
  });
@@ -1,54 +1,58 @@
1
1
  import {defineStore} from "pinia";
2
- import ResourceManagementClient from "@/api/resource-management/resource-management-client";
2
+ import AnsibleServiceClient from "@/api/ansible-service/ansible-service-client";
3
+ import type {AnsibleJobDTO} from "@/api/ansible-service/client";
3
4
  import logRequestError from "@/api/restApiHelper";
4
5
  import ApiState from "@/api/apiState";
6
+ import {isFinalJobStatus} from "@/utils/jobStatus";
5
7
 
6
- export interface JobsStoreState{
7
- apiState: number,
8
- jobs: any[],
9
- jobs_running: any[],
10
- timeoutObject: NodeJS.Timeout | null,
8
+ const POLL_INTERVAL_MS = 5000;
9
+
10
+ export interface JobsStoreState {
11
+ apiState: number,
12
+ jobs: AnsibleJobDTO[],
11
13
  }
12
14
 
13
- export const useJobsStore = defineStore('jobsStore', {
14
- persist: true,
15
+ let pollTimer: ReturnType<typeof setInterval> | null = null;
15
16
 
17
+ export const useJobsStore = defineStore('jobsStore', {
16
18
  state: (): JobsStoreState => ({
17
19
  apiState: ApiState.INIT,
18
20
  jobs: [],
19
- jobs_running: [],
20
- timeoutObject: null,
21
21
  }),
22
22
 
23
- getters: {},
23
+ getters: {
24
+ activeJobs: (state) => state.jobs.filter(job => !isFinalJobStatus(job.status)),
25
+ },
24
26
 
25
27
  actions: {
26
28
  async getJobs() {
27
- ResourceManagementClient.jobApi.getJobs().then(result => {
28
- if (result.data) {
29
- const jobs = <any[]>result.data;
30
- this.jobs = jobs;
29
+ try {
30
+ const result = await AnsibleServiceClient.jobsApi.getJobs();
31
+ this.jobs = [...(result.data ?? [])].sort(
32
+ (a, b) => new Date(b.createdAt ?? 0).getTime() - new Date(a.createdAt ?? 0).getTime());
33
+ } catch (e) {
34
+ logRequestError(e);
35
+ throw e;
36
+ }
37
+ this.updatePolling();
38
+ },
31
39
 
32
- if (this.jobs && this.jobs.length > 0) {
33
- if (jobs.filter(job => job.status === 'running').length > 0) {
34
- this.timeoutObject = setInterval(() => {
35
- this.calculateElapsed();
36
- }, 1000)
37
- } else {
38
- if (this.timeoutObject) {
39
- clearInterval(this.timeoutObject)
40
- }
41
- }
42
- }
43
- }
44
- }).catch(logRequestError)
40
+ /** Polls while at least one job is not finished; stops otherwise. */
41
+ updatePolling() {
42
+ const needed = this.jobs.some(job => !isFinalJobStatus(job.status));
43
+ if (needed && pollTimer === null) {
44
+ pollTimer = setInterval(() => {
45
+ this.getJobs().catch(() => undefined);
46
+ }, POLL_INTERVAL_MS);
47
+ } else if (!needed && pollTimer !== null) {
48
+ clearInterval(pollTimer);
49
+ pollTimer = null;
50
+ }
45
51
  },
46
52
 
47
- calculateElapsed() {
48
- this.jobs_running.forEach(job => {
49
- const elapsed = new Date().getTime() - new Date(job.started).getTime()
50
- this.jobs_running.find(j => j.id === job.id).elapsed = elapsed;
51
- })
53
+ async cancelJob(jobId: string) {
54
+ await AnsibleServiceClient.jobsApi.cancelJob(jobId);
55
+ await this.getJobs();
52
56
  },
53
57
 
54
58
  async updateStore() {
@@ -58,16 +62,12 @@ export const useJobsStore = defineStore('jobsStore', {
58
62
  this.apiState = ApiState.UPDATING;
59
63
  }
60
64
 
61
- return Promise.all([
62
- this.getJobs(),
63
- ]).then(() => {
65
+ return this.getJobs().then(() => {
64
66
  this.apiState = ApiState.LOADED;
65
- console.log("jobsStore updated")
66
67
  }).catch((e) => {
67
68
  this.apiState = ApiState.ERROR;
68
- console.log("Failed to update jobsStore: ", e)
69
+ console.log("Failed to update jobsStore: ", e);
69
70
  });
70
71
  },
71
72
  }
72
73
  });
73
-
@@ -14,7 +14,8 @@ import {
14
14
  EventType, FirmwareUpdateJobEventNotification,
15
15
  Notification,
16
16
  NotificationCategory,
17
- NotificationSubCategory, EVENTCLASS, ResourceEventNotification, ResourceEventType
17
+ NotificationSubCategory, EVENTCLASS, ResourceEventNotification, ResourceEventType,
18
+ AasEventNotification, AasEventType, AasElementKind
18
19
  } from "@/api/notification-service/client";
19
20
  import NotificationTextGenerator from "@/utils/notificationTextGenerator";
20
21
  import i18n from '@/utils/i18n';
@@ -119,6 +120,19 @@ export const useNotificationStore = defineStore('notificationStore', {
119
120
  break;
120
121
  }
121
122
 
123
+ case EVENTCLASS.AasEvent: {
124
+ const aasEventNotification = eventNotification as unknown as AasEventNotification;
125
+ // A deleted resource shell usually means the resource is gone, refreshing it would fail
126
+ const shellDeleted = aasEventNotification.elementKind === AasElementKind.Shell
127
+ && aasEventNotification.eventType === AasEventType.Deleted;
128
+ if (!shellDeleted) {
129
+ const resourceDevicesStore = useResourceDevicesStore();
130
+ resourceDevicesStore.getResourceById(aasEventNotification.resourceId);
131
+ }
132
+ // $toast.info(NotificationTextGenerator.generateLocalizedText(eventNotification, i18n.global))
133
+ break;
134
+ }
135
+
122
136
  default: {
123
137
  console.debug("Unknown event notification type: ", eventNotification.type);
124
138
  break;
@@ -0,0 +1,80 @@
1
+ import ApiState from '@/api/apiState'
2
+ import {defineStore} from "pinia";
3
+ import ResourceManagementClient from "@/api/resource-management/resource-management-client";
4
+ import {Profiler, ProfilerDTOApi} from "@/api/resource-management/client";
5
+
6
+ interface ProfilersStoreState {
7
+ apiState: number,
8
+
9
+ profilers: Profiler[],
10
+ }
11
+
12
+ export const useProfilersStore = defineStore('profilersStore', {
13
+ persist: true,
14
+ state: (): ProfilersStoreState => ({
15
+ apiState: ApiState.INIT,
16
+
17
+ profilers: [],
18
+ }),
19
+
20
+ actions: {
21
+ async getProfilers() {
22
+ return await ResourceManagementClient.profilerApi.getProfiler()
23
+ .then(response => {
24
+ if (response) {
25
+ const receivedProfilers = response.data;
26
+ if (receivedProfilers === undefined) {
27
+ this.profilers = []
28
+ } else {
29
+ // Sort alphabetically
30
+ this.profilers = receivedProfilers.sort((a, b) => {
31
+ return a.name.localeCompare(b.name)
32
+ })
33
+ }
34
+ }
35
+ })
36
+ },
37
+
38
+ async createProfiler(body: ProfilerDTOApi) {
39
+ await ResourceManagementClient.profilerApi.createProfiler(body)
40
+ await this.reloadAfterChange()
41
+ },
42
+
43
+ async updateProfiler(profilerId: string, body: ProfilerDTOApi) {
44
+ await ResourceManagementClient.profilerApi.updateProfiler(profilerId, body)
45
+ await this.reloadAfterChange()
46
+ },
47
+
48
+ async deleteProfiler(profilerId: string) {
49
+ await ResourceManagementClient.profilerApi.deleteProfiler(profilerId)
50
+ await this.reloadAfterChange()
51
+ // A successful delete is authoritative even if the list reload failed or returned stale data.
52
+ this.profilers = this.profilers.filter(profiler => profiler.id !== profilerId)
53
+ },
54
+
55
+ // The change already succeeded; a failed reload must not make it look failed (a retry would duplicate it)
56
+ async reloadAfterChange() {
57
+ try {
58
+ await this.getProfilers()
59
+ } catch (e) {
60
+ console.error('Failed to reload profilers after a successful change', e)
61
+ }
62
+ },
63
+
64
+ async updateStore() {
65
+ if (this.apiState === ApiState.INIT) {
66
+ this.apiState = ApiState.LOADING;
67
+ } else {
68
+ this.apiState = ApiState.UPDATING;
69
+ }
70
+
71
+ return this.getProfilers().then(() => {
72
+ this.apiState = ApiState.LOADED;
73
+ console.log("profilersStore updated")
74
+ }).catch((e) => {
75
+ this.apiState = ApiState.ERROR;
76
+ console.log("Failed to update profilersStore: ", e)
77
+ });
78
+ },
79
+ },
80
+ });
@@ -2,7 +2,7 @@ import ApiState from '@/api/apiState'
2
2
  import {defineStore} from "pinia";
3
3
  import ResourceManagementClient from "@/api/resource-management/resource-management-client";
4
4
  import logRequestError from "@/api/restApiHelper";
5
- import jp from "jsonpath";
5
+ import {JSONPath} from "jsonpath-plus";
6
6
  import { Base64 } from "js-base64";
7
7
 
8
8
  interface ResourceDevicesStoreState{
@@ -163,7 +163,7 @@ export const useResourceDevicesStore = defineStore('resourceDevicesStore', {
163
163
 
164
164
  getSubmodelElementValueOfResourceSubmodel (resourceId, submodelIdShort, submodelElementJsonPath) {
165
165
  try {
166
- var value = jp.value(this.resourceAASValues[resourceId][submodelIdShort]["valuesOnlyMap"], submodelElementJsonPath);
166
+ var value = JSONPath({path: submodelElementJsonPath, json: this.resourceAASValues[resourceId][submodelIdShort]["valuesOnlyMap"], wrap: true})[0];
167
167
  if (value == undefined) {
168
168
  value = "N/A";
169
169
  }