Skip to content
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

Merged
merged 6 commits into from
Jun 21, 2019

Conversation

Rajaa-BARHTAOUI
Copy link
Contributor

@Rajaa-BARHTAOUI Rajaa-BARHTAOUI commented Apr 30, 2019

fixes #4113

Screenshots

Capture du 2019-05-21 15-52-56

Capture du 2019-05-21 15-53-51

Check list

Check items when done or if not relevant

  • PR reference the relevant issue (e.g. Fixes #007)
  • if UI changes, a screenshot has been added to the PR
  • CHANGELOG.unreleased.md:
    • enhancement/bug fix entry added
    • list of packages to release updated (${name} v${new version})
  • documentation updated
  • I have tested added/updated features (and impacted code)

Process

  1. create a PR as soon as possible
  2. mark it as WiP: (Work in Progress) if not ready to be merged
  3. when you want a review, add a reviewer
  4. if necessary, update your PR, and re- add a reviewer

@@ -128,6 +129,12 @@ export default class HostItem extends Component {
</Tooltip>
)}
&nbsp;
{!assertConsistentHostServerTime(host) && (
Copy link
Contributor

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>
)}
&nbsp;
{!assertConsistentHostServerTime(host) && (
Copy link
Contributor

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.

Copy link
Contributor

@badrAZ badrAZ left a 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(...)).

@@ -215,6 +215,20 @@ emergencyShutdownHost.resolve = {

// -------------------------------------------------------------------

export async function assertConsistentHostServerTime({ host }) {
await this.getXapi(host)._assertConsistentHostServerTime(host._xapiRef)
Copy link
Contributor

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(
Copy link
Contributor

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 })
Copy link
Contributor

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.

Copy link
Contributor

@badrAZ badrAZ left a 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

@@ -215,6 +215,20 @@ emergencyShutdownHost.resolve = {

// -------------------------------------------------------------------

export async function assertConsistentHostServerTime({ host }) {
Copy link
Contributor

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.

@@ -215,6 +215,20 @@ emergencyShutdownHost.resolve = {

// -------------------------------------------------------------------

export async function assertConsistentHostServerTime({ host }) {
return this.getXapi(host)._assertConsistentHostServerTime(host._xapiRef)
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@badrAZ badrAZ May 16, 2019

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',
Copy link
Contributor

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.

packages/xo-web/src/xo-app/home/host-item.js Outdated Show resolved Hide resolved
@Rajaa-BARHTAOUI Rajaa-BARHTAOUI changed the title Warning when host's time differs too much from XOA's time feat(xo-web/host): display warning when host's time differs too much from XOA's time May 16, 2019
@@ -47,11 +48,21 @@ import styles from './index.css'
),
}))
export default class HostItem extends Component {
state = {
assertConsistentHostServerTime: false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isHostServerTimeConsistent

@Rajaa-BARHTAOUI Rajaa-BARHTAOUI force-pushed the rajaa-warning-time-xoa branch 3 times, most recently from f03f7ee to 9df523e Compare May 16, 2019 15:26
get _isRunning() {
const host = this.props.item
return host && host.power_state === 'Running'
}

componentDidMount() {
assertConsistentHostServerTime(this.props.item).catch(() => {
Copy link
Contributor

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 ?


// ===================================================================

export const AssertConsistentHostServerTime = decorate([
Copy link
Contributor

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.

<Icon color='text-danger' icon='alarm' />
</Tooltip>
),
])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please define propTypes.

},
}),
injectState,
({ state: { isHostServerTimeConsistent } }) =>
Copy link
Contributor

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'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related change.

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not sorted.

Copy link
Contributor

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'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related change.

Copy link
Contributor Author

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>
)}
&nbsp;
<AssertConsistentHostServerTime host={id} />
Copy link
Contributor

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.

Copy link
Contributor Author

@Rajaa-BARHTAOUI Rajaa-BARHTAOUI May 20, 2019

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.

Copy link
Contributor

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>
)}
&nbsp;
<AssertConsistentHostServerTime host={id} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

host -> hostId.

@Rajaa-BARHTAOUI Rajaa-BARHTAOUI force-pushed the rajaa-warning-time-xoa branch 2 times, most recently from 2900ab9 to bf1f55b Compare May 20, 2019 13:58
@badrAZ badrAZ requested a review from pdonias May 21, 2019 10:36
@@ -215,6 +215,20 @@ emergencyShutdownHost.resolve = {

// -------------------------------------------------------------------

export function assertConsistentHostServerTime({ host }) {
Copy link
Member

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

Copy link
Member

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.

Copy link
Member

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)?

Copy link
Member

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',
Copy link
Member

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
Copy link
Member

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:
Copy link
Member

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 : (
Copy link
Member

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.

@Rajaa-BARHTAOUI Rajaa-BARHTAOUI force-pushed the rajaa-warning-time-xoa branch 2 times, most recently from a531f4f to cb6d68f Compare May 22, 2019 14:01
@@ -215,6 +215,21 @@ emergencyShutdownHost.resolve = {

// -------------------------------------------------------------------

export async function isConsistentHostServerTime({ host }) {
await this.getXapi(host).assertConsistentHostServerTime(host._xapiRef)
Copy link
Member

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),
Copy link
Member

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([
Copy link
Member

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.

@@ -211,6 +211,25 @@ emergencyShutdownHost.resolve = {

// -------------------------------------------------------------------

export async function isConsistentHostServerTime({ host }) {
Copy link
Member

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([
Copy link
Member

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 : (
Copy link
Member

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 -----
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessarily apparently.

@pdonias pdonias changed the title feat(xo-web/host): display warning when host's time differs too much from XOA's time feat(xo-web/host): warning when host and XOA's time differ too much Jun 21, 2019
@pdonias pdonias merged commit 8782151 into vatesfr:master Jun 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Warning when host's time differs too much from XOA's time
4 participants