Skip to content

Commit

Permalink
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
Browse files Browse the repository at this point in the history
…-ref HEAD~1..HEAD --fix'
  • Loading branch information
kibanamachine committed May 18, 2022
1 parent d03bd38 commit 8d35d71
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 54 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/common/types/rest_spec/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export interface PostBulkAgentUpgradeRequest {
agents: string[] | string;
source_uri?: string;
version: string;
rollout_duration_seconds?: number
rollout_duration_seconds?: number;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,23 @@
// in the event that the updated versions cannot be retrieved from the endpoint

export const FALLBACK_VERSIONS = [
'8.2.0',
'8.1.3',
'8.1.2',
'8.1.1',
'8.1.0',
'8.0.1',
'8.0.0',
'7.9.3',
'7.9.2',
'7.9.1',
'7.9.0',
'7.8.1',
'7.8.0',
'7.17.3',
'7.17.2',
'7.17.1',
'7.17.0'
'8.2.0',
'8.1.3',
'8.1.2',
'8.1.1',
'8.1.0',
'8.0.1',
'8.0.0',
'7.9.3',
'7.9.2',
'7.9.1',
'7.9.0',
'7.8.1',
'7.8.0',
'7.17.3',
'7.17.2',
'7.17.1',
'7.17.0',
];

export const MAINTAINANCE_VALUES = [
1,
2,
4,
8,
12,
24,
48
];
export const MAINTAINANCE_VALUES = [1, 2, 4, 8, 12, 24, 48];
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
sendPostBulkAgentUpgrade,
useStartServices,
} from '../../../../hooks';

import { FALLBACK_VERSIONS, MAINTAINANCE_VALUES } from './constants';

interface Props {
Expand All @@ -43,50 +44,58 @@ export const AgentUpgradeAgentModal: React.FunctionComponent<Props> = ({
const { notifications } = useStartServices();
const [isSubmitting, setIsSubmitting] = useState(false);
const isSingleAgent = Array.isArray(agents) && agents.length === 1;
const isSmallBatch = Array.isArray(agents) && agents.length > 1 && agents.length <= 10;
const isSmallBatch = Array.isArray(agents) && agents.length > 1 && agents.length <= 10;
const isAllAgents = agents === '';

const fallbackVersions: Array<EuiComboBoxOptionOption<string>> = FALLBACK_VERSIONS.map((option) => ({
label: option,
value: option,
}));
const fallbackVersions: Array<EuiComboBoxOptionOption<string>> = FALLBACK_VERSIONS.map(
(option) => ({
label: option,
value: option,
})
);
const maintainanceWindows = isSmallBatch ? [0].concat(MAINTAINANCE_VALUES) : MAINTAINANCE_VALUES;
const maintainanceOptions: Array<EuiComboBoxOptionOption<number>> = maintainanceWindows.map((option) => ({
label: option === 0 ? i18n.translate(
'xpack.fleet.upgradeAgents.noMaintainanceWindowOption',
{
defaultMessage: 'Immediately',
}
) : i18n.translate('xpack.fleet.upgradeAgents.hourLabel', {
defaultMessage:
'{option} {count, plural, one {hour} other {hours}}',
values: { option, count: option === 1 },
}),
value: option === 0 ? 0 : option * 3600
}));
const maintainanceOptions: Array<EuiComboBoxOptionOption<number>> = maintainanceWindows.map(
(option) => ({
label:
option === 0
? i18n.translate('xpack.fleet.upgradeAgents.noMaintainanceWindowOption', {
defaultMessage: 'Immediately',
})
: i18n.translate('xpack.fleet.upgradeAgents.hourLabel', {
defaultMessage: '{option} {count, plural, one {hour} other {hours}}',
values: { option, count: option === 1 },
}),
value: option === 0 ? 0 : option * 3600,
})
);
const [selectedVersion, setSelectedVersion] = useState([fallbackVersions[0]]);
const [selectedMantainanceWindow, setSelectedMantainanceWindow] = useState([maintainanceOptions[0]]);
const [selectedMantainanceWindow, setSelectedMantainanceWindow] = useState([
maintainanceOptions[0],
]);


const getVersion = (version: EuiComboBoxOptionOption<string>[]) => version[0].value as string;
const getVersion = (version: Array<EuiComboBoxOptionOption<string>>) =>
version[0].value as string;

async function onSubmit() {
const version = getVersion(selectedVersion);
const rolloutOptions = selectedMantainanceWindow.length > 0 && selectedMantainanceWindow[0]?.value as number > 0 ? {
rollout_duration_seconds: selectedMantainanceWindow[0].value
} : {};
const rolloutOptions =
selectedMantainanceWindow.length > 0 && (selectedMantainanceWindow[0]?.value as number) > 0
? {
rollout_duration_seconds: selectedMantainanceWindow[0].value,
}
: {};

try {
setIsSubmitting(true);
const { data, error } = isSingleAgent
? await sendPostAgentUpgrade((agents[0] as Agent).id, {
version,
})
: await sendPostBulkAgentUpgrade({
: await sendPostBulkAgentUpgrade({
version,
agents: Array.isArray(agents) ? agents.map((agent) => agent.id) : agents,
...rolloutOptions
})
...rolloutOptions,
});
if (error) {
throw error;
}
Expand Down

0 comments on commit 8d35d71

Please sign in to comment.