-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make frontend listen for events when instances' presence changes #1779
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import { | |
DATABASE_RESTORED, | ||
DATABASE_HEALTH_CHANGED, | ||
DATABASE_INSTANCE_REGISTERED, | ||
DATABASE_INSTANCE_ABSENT_AT_CHANGED, | ||
DATABASE_INSTANCE_DEREGISTERED, | ||
DATABASE_INSTANCE_HEALTH_CHANGED, | ||
DATABASE_INSTANCE_SYSTEM_REPLICATION_CHANGED, | ||
|
@@ -16,6 +17,7 @@ import { | |
updateDatabaseHealth, | ||
updateDatabaseInstanceHealth, | ||
updateDatabaseInstanceSystemReplication, | ||
updateDatabaseInstanceAbsentAt, | ||
removeDatabase, | ||
removeDatabaseInstance, | ||
setDatabaseInstanceDeregistering, | ||
|
@@ -111,6 +113,19 @@ function* databaseInstanceSystemReplicationChanged({ payload }) { | |
yield put(updateSAPSystemDatabaseInstanceSystemReplication(payload)); | ||
} | ||
|
||
export function* databaseInstanceAbsentAtChanged({ payload }) { | ||
yield put(updateDatabaseInstanceAbsentAt(payload)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
CDimonaco marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const { sid, absent_at } = payload; | ||
yield put( | ||
notify({ | ||
text: `The database instance ${sid} is now ${ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would put: |
||
absent_at ? 'absent' : 'present' | ||
}.`, | ||
icon: 'ℹ️', | ||
}) | ||
); | ||
} | ||
|
||
export function* deregisterDatabaseInstance({ | ||
payload, | ||
payload: { sid, sap_system_id, host_id, instance_number }, | ||
|
@@ -141,6 +156,10 @@ export function* watchDatabase() { | |
yield takeEvery(DATABASE_RESTORED, databaseRestored); | ||
yield takeEvery(DATABASE_HEALTH_CHANGED, databaseHealthChanged); | ||
yield takeEvery(DATABASE_INSTANCE_REGISTERED, databaseInstanceRegistered); | ||
yield takeEvery( | ||
DATABASE_INSTANCE_ABSENT_AT_CHANGED, | ||
databaseInstanceAbsentAtChanged | ||
); | ||
yield takeEvery(DATABASE_INSTANCE_DEREGISTERED, databaseInstanceDeregistered); | ||
yield takeEvery( | ||
DATABASE_INSTANCE_HEALTH_CHANGED, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import MockAdapter from 'axios-mock-adapter'; | |
|
||
import { recordSaga } from '@lib/test-utils'; | ||
import { | ||
databaseInstanceAbsentAtChanged, | ||
databaseDeregistered, | ||
databaseInstanceDeregistered, | ||
databaseRestored, | ||
|
@@ -12,6 +13,7 @@ import { | |
removeDatabase, | ||
removeDatabaseInstance, | ||
appendDatabase, | ||
updateDatabaseInstanceAbsentAt, | ||
setDatabaseInstanceDeregistering, | ||
unsetDatabaseInstanceDeregistering, | ||
} from '@state/databases'; | ||
|
@@ -41,6 +43,53 @@ describe('SAP Systems sagas', () => { | |
console.error.mockRestore(); | ||
}); | ||
|
||
it('should update the absent_at field when the database instance is marked absent', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this now in the top of the file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
const { sap_system_id, instance_number, host_id, sid } = | ||
databaseInstanceFactory.build(); | ||
const absent_at = Date.now(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I bit strange this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
const dispatched = await recordSaga(databaseInstanceAbsentAtChanged, { | ||
payload: { sap_system_id, instance_number, host_id, sid, absent_at }, | ||
}); | ||
|
||
expect(dispatched).toEqual([ | ||
updateDatabaseInstanceAbsentAt({ | ||
sap_system_id, | ||
instance_number, | ||
host_id, | ||
sid, | ||
absent_at, | ||
}), | ||
notify({ | ||
text: `The database instance ${sid} is now absent.`, | ||
icon: 'ℹ️', | ||
}), | ||
]); | ||
}); | ||
|
||
it('should update the absent_at field when the database instance is marked present', async () => { | ||
const { sap_system_id, instance_number, host_id, sid, absent_at } = | ||
databaseInstanceFactory.build(); | ||
|
||
const dispatched = await recordSaga(databaseInstanceAbsentAtChanged, { | ||
payload: { sap_system_id, instance_number, host_id, sid, absent_at }, | ||
}); | ||
|
||
expect(dispatched).toEqual([ | ||
updateDatabaseInstanceAbsentAt({ | ||
sap_system_id, | ||
instance_number, | ||
host_id, | ||
sid, | ||
absent_at, | ||
}), | ||
notify({ | ||
text: `The database instance ${sid} is now present.`, | ||
icon: 'ℹ️', | ||
}), | ||
]); | ||
}); | ||
|
||
it('should remove the database instance', async () => { | ||
const { sap_system_id, host_id, instance_number, sid } = | ||
databaseInstanceFactory.build(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import { | |
APPLICATION_INSTANCE_REGISTERED, | ||
APPLICATION_INSTANCE_MOVED, | ||
APPLICATION_INSTANCE_HEALTH_CHANGED, | ||
APPLICATION_INSTANCE_ABSENT_AT_CHANGED, | ||
APPLICATION_INSTANCE_DEREGISTERED, | ||
SAP_SYSTEM_DEREGISTERED, | ||
SAP_SYSTEM_RESTORED, | ||
|
@@ -19,6 +20,7 @@ import { | |
removeApplicationInstance, | ||
updateApplicationInstanceHost, | ||
updateApplicationInstanceHealth, | ||
updateApplicationInstanceAbsentAt, | ||
removeSAPSystem, | ||
updateSAPSystem, | ||
setApplicationInstanceDeregistering, | ||
|
@@ -79,6 +81,19 @@ function* applicationInstanceHealthChanged({ payload }) { | |
yield put(updateApplicationInstanceHealth(payload)); | ||
} | ||
|
||
export function* applicationInstanceAbsentAtChanged({ payload }) { | ||
yield put(updateApplicationInstanceAbsentAt(payload)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may be a bit technical, but There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't really matter, it is fine this way |
||
const { sid, absent_at } = payload; | ||
yield put( | ||
notify({ | ||
text: `The application instance ${sid} is now ${ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thoughts on this message? |
||
absent_at ? 'absent' : 'present' | ||
}.`, | ||
icon: 'ℹ️', | ||
}) | ||
); | ||
} | ||
|
||
export function* sapSystemDeregistered({ payload: { id, sid } }) { | ||
yield put(removeSAPSystem({ id })); | ||
yield put( | ||
|
@@ -142,6 +157,10 @@ export function* watchSapSystem() { | |
applicationInstanceRegistered | ||
); | ||
yield takeEvery(APPLICATION_INSTANCE_MOVED, applicationInstanceMoved); | ||
yield takeEvery( | ||
APPLICATION_INSTANCE_ABSENT_AT_CHANGED, | ||
applicationInstanceAbsentAtChanged | ||
); | ||
yield takeEvery( | ||
APPLICATION_INSTANCE_DEREGISTERED, | ||
applicationInstanceDeregistered | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,6 +149,15 @@ export const sapSystemsListSlice = createSlice({ | |
} | ||
); | ||
}, | ||
updateApplicationInstanceAbsentAt: (state, { payload: instance }) => { | ||
const { absent_at } = instance; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we have this like the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
state.applicationInstances = updateInstance( | ||
state.applicationInstances, | ||
instance, | ||
{ absent_at } | ||
); | ||
}, | ||
setApplicationInstanceDeregistering: (state, { payload: instance }) => { | ||
state.applicationInstances = updateInstance( | ||
state.applicationInstances, | ||
|
@@ -191,6 +200,8 @@ export const SAP_SYSTEM_HEALTH_CHANGED = 'SAP_SYSTEM_HEALTH_CHANGED'; | |
export const APPLICATION_INSTANCE_REGISTERED = | ||
'APPLICATION_INSTANCE_REGISTERED'; | ||
export const APPLICATION_INSTANCE_MOVED = 'APPLICATION_INSTANCE_MOVED'; | ||
export const APPLICATION_INSTANCE_ABSENT_AT_CHANGED = | ||
'APPLICATION_INSTANCE_ABSENT_AT_CHANGED'; | ||
export const APPLICATION_INSTANCE_DEREGISTERED = | ||
'APPLICATION_INSTANCE_DEREGISTERED'; | ||
export const APPLICATION_INSTANCE_HEALTH_CHANGED = | ||
|
@@ -223,6 +234,7 @@ export const { | |
removeTagFromSAPSystem, | ||
removeSAPSystem, | ||
updateSAPSystem, | ||
updateApplicationInstanceAbsentAt, | ||
setApplicationInstanceDeregistering, | ||
unsetApplicationInstanceDeregistering, | ||
setDatabaseInstanceDeregisteringToSAPSystem, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would put
{absent_at: instance.absent_at}
to have the same style like the other reducer functionsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done