-
Notifications
You must be signed in to change notification settings - Fork 262
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
feat(xo-web/host): warning when host and XOA's time differ too much #4173
feat(xo-web/host): warning when host and XOA's time differ too much #4173
Conversation
1efdd6c
to
ba3356d
Compare
@@ -128,6 +129,12 @@ export default class HostItem extends Component { | |||
</Tooltip> | |||
)} | |||
| |||
{!assertConsistentHostServerTime(host) && ( |
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.
The promise is not yet resolved.
@@ -254,6 +259,12 @@ export default class Host extends Component { | |||
</Link> | |||
</Tooltip> | |||
)} | |||
| |||
{!assertConsistentHostServerTime(host) && ( |
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.
The promise is not yet resolved.
91ac451
to
6e71e3f
Compare
6e71e3f
to
4d61825
Compare
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.
Please fix the PR title by adding (feat/fix(...)).
packages/xo-server/src/api/host.js
Outdated
@@ -215,6 +215,20 @@ emergencyShutdownHost.resolve = { | |||
|
|||
// ------------------------------------------------------------------- | |||
|
|||
export async function assertConsistentHostServerTime({ host }) { | |||
await this.getXapi(host)._assertConsistentHostServerTime(host._xapiRef) |
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.
Simply return the _assertConsistentHostServerTime
promise because we don't need to change it's returned value.
@@ -777,6 +777,12 @@ export const emergencyShutdownHosts = hosts => { | |||
}).then(() => map(hosts, host => emergencyShutdownHost(host)), noop) | |||
} | |||
|
|||
export const assertConsistentHostServerTime = host => | |||
_call('host.assertConsistentHostServerTime', { host: resolveId(host) }).then( |
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.
It's a public function which can be used on other cases. Simply return the promise to not change the behavior.
@@ -52,6 +53,12 @@ export default class HostItem extends Component { | |||
return host && host.power_state === 'Running' | |||
} | |||
|
|||
componentDidMount() { | |||
assertConsistentHostServerTime(this.props.item).then(res => { | |||
this.setState({ assertConsistentHostServerTime: res }) |
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.
Better create a new var which its initial value is false
.
4d61825
to
ca59421
Compare
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.
Please take care of the comment
packages/xo-server/src/api/host.js
Outdated
@@ -215,6 +215,20 @@ emergencyShutdownHost.resolve = { | |||
|
|||
// ------------------------------------------------------------------- | |||
|
|||
export async function assertConsistentHostServerTime({ host }) { |
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.
The async
is not needed.
packages/xo-server/src/api/host.js
Outdated
@@ -215,6 +215,20 @@ emergencyShutdownHost.resolve = { | |||
|
|||
// ------------------------------------------------------------------- | |||
|
|||
export async function assertConsistentHostServerTime({ host }) { | |||
return this.getXapi(host)._assertConsistentHostServerTime(host._xapiRef) |
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.
_assertConsistentHostServerTime
is a private method which cannot be call out side its class. Please make it public.
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 don't see why I change it to public method? it reserved for host.
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.
A private method (_methodName
) should not be called by the instance.
@@ -922,6 +922,10 @@ const messages = { | |||
changelogAuthor: 'Author', | |||
changelogDate: 'Date', | |||
changelogDescription: 'Description', | |||
// ----- Host home ----- | |||
assertConsistentHostServerTimeTooltip: | |||
'host server time and XOA date are not consistent with each other', |
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.
To be consistent, host server time and XOA date -> time
.
@@ -47,11 +48,21 @@ import styles from './index.css' | |||
), | |||
})) | |||
export default class HostItem extends Component { | |||
state = { | |||
assertConsistentHostServerTime: false, |
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.
isHostServerTimeConsistent
f03f7ee
to
9df523e
Compare
get _isRunning() { | ||
const host = this.props.item | ||
return host && host.power_state === 'Running' | ||
} | ||
|
||
componentDidMount() { | ||
assertConsistentHostServerTime(this.props.item).catch(() => { |
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.
What about creating a component using reaclette
to avoid code duplication ?
packages/xo-web/src/common/utils.js
Outdated
|
||
// =================================================================== | ||
|
||
export const AssertConsistentHostServerTime = decorate([ |
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.
Let's move it to its own module to avoid have a big file with a lot of functions.
packages/xo-web/src/common/utils.js
Outdated
<Icon color='text-danger' icon='alarm' /> | ||
</Tooltip> | ||
), | ||
]) |
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.
Please define propTypes
.
packages/xo-web/src/common/utils.js
Outdated
}, | ||
}), | ||
injectState, | ||
({ state: { isHostServerTimeConsistent } }) => |
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.
{ state: { isHostServerTimeConsistent = true } }
connectStore, | ||
formatSizeShort, | ||
hasLicenseRestrictions, | ||
osFamily, | ||
} from 'utils' | ||
import { Col, Row } from 'grid' |
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.
Not related change.
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 made some changes that require Sort
.
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.
It's not sorted.
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.
Inline imports before multiple lines imports.
import { | ||
createDoesHostNeedRestart, | ||
createGetObject, | ||
createGetObjectsOfType, | ||
createSelector, | ||
} from 'selectors' | ||
import { Text } from 'editable' |
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.
Not related change.
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 made some changes that require Sort.
<Icon icon='alarm' /> | ||
</Link> | ||
</Tooltip> | ||
)} | ||
| ||
<AssertConsistentHostServerTime host={id} /> |
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.
Simply host.id
to avoid unrelated changes.
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 do it to not access to id
many times.
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.
It not cost a lot of performance and it produce a lot of unrelated change. Better use host.id
to avoid it.
<Icon icon='alarm' /> | ||
</Link> | ||
</Tooltip> | ||
)} | ||
| ||
<AssertConsistentHostServerTime host={id} /> |
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.
host
-> hostId
.
2900ab9
to
bf1f55b
Compare
packages/xo-server/src/api/host.js
Outdated
@@ -215,6 +215,20 @@ emergencyShutdownHost.resolve = { | |||
|
|||
// ------------------------------------------------------------------- | |||
|
|||
export function assertConsistentHostServerTime({ host }) { |
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.
Should this be a checkConsistentHostServerTime
?
Ping @julien-f
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.
For me assert
(check
to a lesser extent) means that it will throws if the condition is not fulfilled.
IMHO, if it returns a boolean, it should be called isConsistentHostServerTime
.
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.
Ok so my (unclear) question should have been: should this return a boolean (and be named accordingly)?
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.
Yes, for an API, I agree it makes more sense.
@@ -887,6 +889,10 @@ const messages = { | |||
changelogAuthor: 'Author', | |||
changelogDate: 'Date', | |||
changelogDescription: 'Description', | |||
// ----- Host home ----- | |||
assertConsistentHostServerTimeTooltip: | |||
'Host server time and XOA time are not consistent with each other', |
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.
"Host time"?
power_state: powerState, | ||
tags, | ||
version, | ||
} = host |
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.
Avoid adding too many unrelated changes.
@@ -887,6 +889,10 @@ const messages = { | |||
changelogAuthor: 'Author', | |||
changelogDate: 'Date', | |||
changelogDescription: 'Description', | |||
// ----- Host home ----- | |||
assertConsistentHostServerTimeTooltip: |
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.
This is not an assert.
}), | ||
injectState, | ||
({ state: { isHostServerTimeConsistent = true } }) => | ||
isHostServerTimeConsistent ? null : ( |
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.
IMO, it's a bit weird to say that something is "consistent" by itself.
a531f4f
to
cb6d68f
Compare
packages/xo-server/src/api/host.js
Outdated
@@ -215,6 +215,21 @@ emergencyShutdownHost.resolve = { | |||
|
|||
// ------------------------------------------------------------------- | |||
|
|||
export async function isConsistentHostServerTime({ host }) { | |||
await this.getXapi(host).assertConsistentHostServerTime(host._xapiRef) |
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.
We don't want something that rejects as a normal behaviour. You'd need something like:
try {
await this.getXapi(host).assertConsistentHostServerTime(host._xapiRef)
return true
} catch () {
return false
}
But then it would also take any other error as a "no", or maybe create a whole new helper method.
provideState({ | ||
computed: { | ||
isHostTimeConsistentToXoaTime: (_, { hostId }) => | ||
isHostTimeConsistentToXoaTime(hostId).then(() => true, () => false), |
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.
It should already resolve with a boolean.
import { injectState, provideState } from 'reaclette' | ||
import { isHostTimeConsistentToXoaTime } from 'xo' | ||
|
||
const AssertConsistentHostTime = decorate([ |
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.
Assert is a verb. This is a component and it doesn't assert anything.
cb6d68f
to
2283d4b
Compare
packages/xo-server/src/api/host.js
Outdated
@@ -211,6 +211,25 @@ emergencyShutdownHost.resolve = { | |||
|
|||
// ------------------------------------------------------------------- | |||
|
|||
export async function isConsistentHostServerTime({ host }) { |
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.
isHostServerTimeConsistent
import { injectState, provideState } from 'reaclette' | ||
import { isHostTimeConsistentToXoaTime } from 'xo' | ||
|
||
const ConsistentHostTimeWarning = decorate([ |
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.
So it would be Inconsistent...
if it's a warning.
}), | ||
injectState, | ||
({ state: { isHostTimeConsistentToXoaTime = true } }) => | ||
isHostTimeConsistentToXoaTime ? null : ( |
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.
With
?
@@ -890,6 +890,10 @@ const messages = { | |||
changelogAuthor: 'Author', | |||
changelogDate: 'Date', | |||
changelogDescription: 'Description', | |||
// ----- Host home ----- |
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.
Not necessarily apparently.
2283d4b
to
088abfe
Compare
088abfe
to
dfd301b
Compare
fixes #4113
Screenshots
Check list
Fixes #007
)CHANGELOG.unreleased.md
:${name} v${new version}
)Process
WiP:
(Work in Progress) if not ready to be merged