Skip to content

Commit

Permalink
Feat/1187 cloud bus refresh (#3947)
Browse files Browse the repository at this point in the history
  • Loading branch information
ulischulte authored Jan 3, 2025
1 parent 1f4bf83 commit d728319
Show file tree
Hide file tree
Showing 9 changed files with 339 additions and 616 deletions.
812 changes: 197 additions & 615 deletions spring-boot-admin-server-ui/package-lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
class="btn relative"
:class="cssClasses"
:disabled="disabled === true"
:title="title"
@click="$emit('click', $event)"
>
<slot />
Expand All @@ -13,6 +14,10 @@
export default {
name: 'SbaButton',
props: {
title: {
type: String,
default: '',
},
size: {
type: String,
default: 'sm',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<sba-button
v-on-clickaway="abort"
:class="{ 'is-success': confirm }"
:title="title"
@click="click"
>
<slot v-if="confirm" name="confirm">
Expand All @@ -32,6 +33,12 @@ import { directive as onClickaway } from 'vue3-click-away';

export default {
directives: { onClickaway },
props: {
title: {
type: String,
default: '',
},
},
emits: ['click'],
data() {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ class Instance {
return this.axios.post(uri`actuator/refresh`);
}

async busRefreshContext() {
return this.axios.post(uri`actuator/busrefresh`);
}

async fetchLiquibase() {
return this.axios.get(uri`actuator/liquibase`);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import userEvent from '@testing-library/user-event';
import { screen } from '@testing-library/vue';
import { HttpResponse, http } from 'msw';
import { beforeEach, describe, expect, it, vi } from 'vitest';

import { server } from '@/mocks/server';
import Instance from '@/services/instance';
import { render } from '@/test-utils';
import Busrefresh from '@/views/instances/env/busrefresh.vue';

describe('Busrefresh', () => {
const busRefreshInstanceContextMock = vi.fn();
let emitted;

function createInstance() {
const instance = new Instance({ id: 1233 });
instance.busRefreshContext = busRefreshInstanceContextMock;
return instance;
}

beforeEach(async () => {
server.use(
http.post('/instances/:instanceId/actuator/busrefresh', () => {
return HttpResponse.json({});
}),
);
const vm = render(Busrefresh, {
props: {
instance: createInstance(),
},
});
emitted = vm.emitted;
});

it('should trigger busrefresh on confirm', async () => {
busRefreshInstanceContextMock.mockResolvedValue({});
const busRefreshButton = await screen.findByText(
'instances.env.bus_refresh',
);
await userEvent.click(busRefreshButton);

const confirmButton = await screen.findByText('Confirm');
await userEvent.click(confirmButton);

expect(emitted().refresh[0][0]).toBe(true);
});

it('should handle busrefresh failure gracefully', async () => {
busRefreshInstanceContextMock.mockRejectedValueOnce(new Error());

const busRefreshButton = await screen.findByText(
'instances.env.bus_refresh',
);
await userEvent.click(busRefreshButton);

const confirmButton = await screen.findByText('Confirm');
await userEvent.click(confirmButton);

expect(emitted().refresh).toBeUndefined();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<template>
<sba-confirm-button
:title="$t('instances.env.bus_refresh_title')"
class="inline-flex focus:z-10"
@click="refreshInstance"
>
<span v-text="t('instances.env.bus_refresh')" />
</sba-confirm-button>
</template>

<script lang="ts">
import { useNotificationCenter } from '@stekoe/vue-toast-notificationcenter';
import { useI18n } from 'vue-i18n';
import SbaConfirmButton from '@/components/sba-confirm-button.vue';
import Instance from '@/services/instance';
const notificationCenter = useNotificationCenter({});
export default {
components: { SbaConfirmButton },
props: {
instance: {
type: Instance,
required: true,
},
},
emits: ['refresh'],
setup() {
const i18n = useI18n();
return {
t: i18n.t,
};
},
methods: {
async refreshInstance() {
this.instance
.busRefreshContext()
.then(() => {
notificationCenter.success(
this.t('instances.env.bus_refresh_success'),
);
this.$emit('refresh', true);
})
.catch(() => {
notificationCenter.error(this.t('instances.env.bus_refresh_failure'));
});
},
},
};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
"manager": "Umgebungskonfiguration anpassen",
"active_profile": "Profil",
"context_refresh": "Kontext neu laden",
"bus_refresh": "Spring Cloud Bus-refresh",
"bus_refresh_success": "Spring Cloud Bus Refresh erfolgreich!",
"bus_refresh_failure": "Fehlgeschlagen: Konnte Spring Cloud Bus Refresh nicht ausführen!",
"bus_refresh_title": "Sendet eine Refresh Message an den konfigurierten Spring Cloud Bus, der eine Refresh Message an alle verbundenen Nodes sendet",
"context_refresh_failed": "Fehlgeschlagen",
"context_refreshed": "Erfolreich!",
"context_reset": "Zurücksetzen",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
"manager": "Environment Manager",
"active_profile": "Profile",
"context_refresh": "Refresh context",
"bus_refresh": "Spring Cloud Bus-refresh",
"bus_refresh_success": "Spring Cloud Bus successfully refreshed.",
"bus_refresh_failure": "Failure: Unable to trigger Spring Cloud Bus refresh!",
"bus_refresh_title": "Sends a refresh message to the configured Spring Cloud Bus which broadcasts a refresh to all nodes listening",
"context_refresh_failed": "Failed",
"context_refreshed": "Context refreshed",
"context_reset": "Reset",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
@refresh="fetchEnv"
/>
</div>
<div v-if="instance.hasEndpoint('busrefresh')" class="mr-1">
<busrefresh :instance="instance" @refresh="fetchEnv" />
</div>
<div class="flex-1">
<sba-input
v-model="filter"
Expand Down Expand Up @@ -111,6 +114,7 @@ import { pickBy } from 'lodash-es';
import Application from '@/services/application';
import Instance from '@/services/instance';
import { VIEW_GROUP } from '@/views/ViewGroup';
import Busrefresh from '@/views/instances/env/busrefresh.vue';
import sbaEnvManager from '@/views/instances/env/env-manager';
import refresh from '@/views/instances/env/refresh';
import SbaInstanceSection from '@/views/instances/shell/sba-instance-section';
Expand All @@ -134,7 +138,7 @@ const filterPropertySource = (needle) => (propertySource) => {
};

export default {
components: { SbaInstanceSection, sbaEnvManager, refresh },
components: { Busrefresh, SbaInstanceSection, sbaEnvManager, refresh },
props: {
instance: {
type: Instance,
Expand Down

0 comments on commit d728319

Please sign in to comment.