Skip to content

Commit

Permalink
refresh synchronized group
Browse files Browse the repository at this point in the history
  • Loading branch information
moscicky committed Aug 8, 2024
1 parent c682bd3 commit 04492af
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 13 deletions.
26 changes: 26 additions & 0 deletions hermes-console/json-server/db.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,32 @@
]
}
],
"inconsistentGroups3":[
{
"name": "pl.allegro.public.group",
"inconsistentMetadata": [],
"inconsistentTopics": [
{
"name": "pl.allegro.public.group.DummyEvent",
"inconsistentMetadata": [],
"inconsistentSubscriptions": [
{
"name": "pl.allegro.public.group.DummyEvent$foobar-service",
"inconsistentMetadata": [
{
"datacenter": "DC1"
},
{
"datacenter": "DC2",
"content": "{\n \"id\": \"foobar-service\",\n \"topicName\": \"pl.allegro.public.group.DummyEvent\",\n \"name\": \"foobar-service\",\n \"endpoint\": \"service://foobar-service/events/dummy-event\",\n \"state\": \"ACTIVE\",\n \"description\": \"Test Hermes endpoint\",\n \"subscriptionPolicy\": {\n \"rate\": 10,\n \"messageTtl\": 60,\n \"messageBackoff\": 100,\n \"requestTimeout\": 1000,\n \"socketTimeout\": 0,\n \"sendingDelay\": 0,\n \"backoffMultiplier\": 1.0,\n \"backoffMaxIntervalInSec\": 600,\n \"retryClientErrors\": true,\n \"backoffMaxIntervalMillis\": 600000\n },\n \"trackingEnabled\": false,\n \"trackingMode\": \"trackingOff\",\n \"owner\": {\n \"source\": \"Service Catalog\",\n \"id\": \"42\"\n },\n \"monitoringDetails\": {\n \"severity\": \"NON_IMPORTANT\",\n \"reaction\": \"\"\n },\n \"contentType\": \"JSON\",\n \"deliveryType\": \"SERIAL\",\n \"filters\": [\n {\n \"type\": \"avropath\",\n \"path\": \"foobar\",\n \"matcher\": \"^FOO_BAR$|^BAZ_BAR$\",\n \"matchingStrategy\": \"any\"\n },\n {\n \"type\": \"avropath\",\n \"path\": \".foo.bar.baz\",\n \"matcher\": \"true\",\n \"matchingStrategy\": \"all\"\n }\n ],\n \"mode\": \"ANYCAST\",\n \"headers\": [\n {\n \"name\": \"X-My-Header\",\n \"value\": \"boobar\"\n },\n {\n \"name\": \"X-Another-Header\",\n \"value\": \"foobar\"\n }\n ],\n \"endpointAddressResolverMetadata\": {\n \"additionalMetadata\": false,\n \"nonSupportedProperty\": 2\n },\n \"http2Enabled\": false,\n \"subscriptionIdentityHeadersEnabled\": false,\n \"autoDeleteWithTopicEnabled\": false,\n \"createdAt\": 1579507131.238,\n \"modifiedAt\": 1672140855.813\n}"
}
]
}
]
}
]
}
],
"topicNames": [
"pl.allegro.public.offer.product.ProductEventV1",
"pl.allegro.public.offer.product.ProductEventV2",
Expand Down
1 change: 1 addition & 0 deletions hermes-console/json-server/routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"/consistency/groups": "/consistencyGroups",
"/consistency/inconsistencies/groups?groupNames=pl.allegro.public.offer*": "/inconsistentGroups",
"/consistency/inconsistencies/groups?groupNames=pl.allegro.public.group2*": "/inconsistentGroups2",
"/consistency/inconsistencies/groups?groupNames=pl.allegro.public.group": "/inconsistentGroups3",
"/groups": "/groups",
"/owners/sources/Service%20Catalog/:id": "/topicsOwners/:id",
"/readiness/datacenters": "/readinessDatacenters",
Expand Down
6 changes: 6 additions & 0 deletions hermes-console/json-server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ server.put(
},
);

server.post(
'/consistency/sync/topics/pl.allegro.public.group.DummyEvent/subscriptions/barbaz-service*', (req, res) => {

Check failure on line 91 in hermes-console/json-server/server.ts

View workflow job for this annotation

GitHub Actions / build

Replace `··'/consistency/sync/topics/pl.allegro.public.group.DummyEvent/subscriptions/barbaz-service*',` with `'/consistency/sync/topics/pl.allegro.public.group.DummyEvent/subscriptions/barbaz-service*',⏎·`

Check failure on line 91 in hermes-console/json-server/server.ts

View workflow job for this annotation

GitHub Actions / build

Replace `··'/consistency/sync/topics/pl.allegro.public.group.DummyEvent/subscriptions/barbaz-service*',` with `'/consistency/sync/topics/pl.allegro.public.group.DummyEvent/subscriptions/barbaz-service*',⏎·`
res.sendStatus(200)

Check failure on line 92 in hermes-console/json-server/server.ts

View workflow job for this annotation

GitHub Actions / build

Replace `······res.sendStatus(200)` with `····res.sendStatus(200);`

Check failure on line 92 in hermes-console/json-server/server.ts

View workflow job for this annotation

GitHub Actions / build

Replace `······res.sendStatus(200)` with `····res.sendStatus(200);`
}

Check failure on line 93 in hermes-console/json-server/server.ts

View workflow job for this annotation

GitHub Actions / build

Replace `··}` with `},`

Check failure on line 93 in hermes-console/json-server/server.ts

View workflow job for this annotation

GitHub Actions / build

Replace `··}` with `},`
)

Check failure on line 94 in hermes-console/json-server/server.ts

View workflow job for this annotation

GitHub Actions / build

Insert `;`

Check failure on line 94 in hermes-console/json-server/server.ts

View workflow job for this annotation

GitHub Actions / build

Insert `;`

server.post('/filters/:topic', (req, res) => {
res.jsonp(filterDebug);
});
Expand Down
65 changes: 59 additions & 6 deletions hermes-console/src/composables/sync/use-sync/useSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,78 @@ import {
syncSubscription as doSyncSubscription,
syncTopic as doSyncTopic,
} from '@/api/hermes-client';
import { groupName } from '@/utils/topic-utils/topic-utils';
import { ref, type Ref } from 'vue';
import { useConsistencyStore } from '@/store/consistency/useConsistencyStore';
import { useGlobalI18n } from '@/i18n';
import { useNotificationsStore } from '@/store/app-notifications/useAppNotifications';

export interface UseSync {
errorMessage: Ref<Error | null | undefined>;
syncGroup: (groupName: string, primaryDatacenter: string) => Promise<void>;
syncGroup: (groupName: string, primaryDatacenter: string) => Promise<boolean>;
syncTopic: (
topicQualifiedName: string,
primaryDatacenter: string,
) => Promise<void>;
) => Promise<boolean>;
syncSubscription: (
topicQualifiedName: string,
subscriptionName: string,
primaryDatacenter: string,
) => Promise<void>;
) => Promise<boolean>;
}

export function useSync(): UseSync {
const errorMessage: Ref<Error | null | undefined> = ref();

const notificationStore = useNotificationsStore();
const consistencyStore = useConsistencyStore();

const syncGroup = async (groupName: string, primaryDatacenter: string) => {
try {
await doSyncGroup(groupName, primaryDatacenter);
} catch (e) {
errorMessage.value = e as Error;
await notificationStore.dispatchNotification({
text: useGlobalI18n().t('notifications.sync.success', {
group: groupName,
}),
type: 'success',
});
await consistencyStore.refresh(groupName);
return true;
} catch (e: any) {
await notificationStore.dispatchNotification({
text: useGlobalI18n().t('notifications.sync.failure', {
group: groupName,
}),
type: 'error',
});
return false;
}
};

const syncTopic = async (
topicQualifiedName: string,
primaryDatacenter: string,
) => {
const group = groupName(topicQualifiedName);
try {
await doSyncTopic(topicQualifiedName, primaryDatacenter);
} catch (e) {
await notificationStore.dispatchNotification({
text: useGlobalI18n().t('notifications.sync.success', {
group,
}),
type: 'success',
});
await consistencyStore.refresh(group);
return true;
} catch (e: any) {
errorMessage.value = e as Error;
await notificationStore.dispatchNotification({
text: useGlobalI18n().t('notifications.sync.failure', {
group,
}),
type: 'error',
});
return false;
}
};

Expand All @@ -46,14 +83,30 @@ export function useSync(): UseSync {
subscriptionName: string,
primaryDatacenter: string,
) => {
const group = groupName(topicQualifiedName);
try {
await doSyncSubscription(
topicQualifiedName,
subscriptionName,
primaryDatacenter,
);
await notificationStore.dispatchNotification({
text: useGlobalI18n().t('notifications.sync.success', {
group,
}),
type: 'success',
});
await consistencyStore.refresh(group);
return true;
} catch (e) {
errorMessage.value = e as Error;
await notificationStore.dispatchNotification({
text: useGlobalI18n().t('notifications.sync.failure', {
group,
}),
type: 'error',
});
return false;
}
};

Expand Down
4 changes: 4 additions & 0 deletions hermes-console/src/i18n/en-US/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,10 @@ const en_US = {
failure: "Couldn't delete topic {topic}",
},
},
sync: {
success: 'Synchronization of {group} succeeded',
failure: 'Synchronization of {group} failed',
},
subscription: {
create: {
success: 'Subscription {subscriptionName} successfully created',
Expand Down
23 changes: 23 additions & 0 deletions hermes-console/src/store/consistency/useConsistencyStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,29 @@ export const useConsistencyStore = defineStore('consistency', {
this.fetchInProgress = false;
}
},
async refresh(group: string) {
this.fetchInProgress = true;
try {
const refreshedGroup = (await fetchInconsistentGroups([group])).data;
let groupIndex = -1;
for (let i = 0; i < this.groups.length; i++) {
if (this.groups[i].name == group) {
groupIndex = i;
break;
}
}
if (groupIndex == -1) return;
if (refreshedGroup.length == 0) {
this.groups = this.groups.splice(groupIndex, 1);
} else {
this.groups[groupIndex] = refreshedGroup[0];
}
} catch (e) {
this.error.fetchError = e as Error;
} finally {
this.fetchInProgress = false;
}
},
},
getters: {
group(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@
},
];
function sync(datacenter: string) {
syncGroup(groupId, datacenter);
async function sync(datacenter: string) {
const succeeded = await syncGroup(groupId, datacenter);
if (succeeded) {
router.push('/ui/consistency');
}
}
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
import { parseSubscriptionFqn } from '@/utils/subscription-utils/subscription-utils';
import { useConsistencyStore } from '@/store/consistency/useConsistencyStore';
import { useI18n } from 'vue-i18n';
import { useRoute } from 'vue-router';
import { useRoute, useRouter } from 'vue-router';
import { useSync } from '@/composables/sync/use-sync/useSync';
import InconsistentMetadata from '@/views/admin/consistency/inconsistent-metadata/InconsistentMetadata.vue';
const router = useRouter();
const route = useRoute();
const { t } = useI18n();
Expand Down Expand Up @@ -35,20 +36,26 @@
},
];
function doSyncTopic(datacenter: string) {
syncTopic(topicId, datacenter);
async function doSyncTopic(datacenter: string) {
const succeeded = await syncTopic(topicId, datacenter);
if (succeeded) {
router.push('/ui/consistency');
}
}
function doSyncSubscription(
async function doSyncSubscription(
subscriptionQualifiedName: string,
datacenter: string,
) {
const subscriptionName = parseSubscriptionFqn(subscriptionQualifiedName);
syncSubscription(
const succeeded = await syncSubscription(
subscriptionName.topicName,
subscriptionName.subscriptionName,
datacenter,
);
if (succeeded) {
router.push('/ui/consistency');
}
}
</script>

Expand Down

0 comments on commit 04492af

Please sign in to comment.