forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fleet] Add package policy upgrade API (elastic#103017)
* Add Integrations page callout for package upgades * Fix props * Add missing file * Add integrations upgrade callout message * Add link to updates available tab * Fix merge * Upgrade ppolicies UI WIP * Initial upgrade dry run API * Add upgrade method * Move overridePackageInputs and use for upgrade method * Add new variables to dry run diff * Revert UI changes to uto upgrade wizard * Add vars and streams to error keys * Type fix * Fix jest * Fix types * Fix typecheck * Fix types * Add integration test for dry run API * Flesh out test cases * Clean up error responses for dry runs * Fix failing tests * WIP: Add (failing for now) test case for package upgrade w/ error * Add compiled_stream to test API payload * Fix failing test case for automatic upgrade * Fix compiled stream in package policy upgrade * Remove fleet and agent setup from integration test * Unload esarchiver fixtures in api integration test Co-authored-by: Kyle Pollich <[email protected]> Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
1bc4d31
commit b065196
Showing
30 changed files
with
932 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
x-pack/plugins/fleet/public/hooks/use_package_installations.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { useMemo } from 'react'; | ||
import semverLt from 'semver/functions/lt'; | ||
|
||
import { installationStatuses } from '../../common/constants'; | ||
import type { PackagePolicy } from '../types'; | ||
|
||
import { useGetPackages } from './use_request/epm'; | ||
import { useGetAgentPolicies } from './use_request/agent_policy'; | ||
|
||
export const usePackageInstallations = () => { | ||
const { data: allPackages, isLoading: isLoadingPackages } = useGetPackages({ | ||
experimental: true, | ||
}); | ||
|
||
const { data: agentPolicyData, isLoading: isLoadingPolicies } = useGetAgentPolicies({ | ||
full: true, | ||
}); | ||
|
||
const allInstalledPackages = useMemo( | ||
() => | ||
(allPackages?.response || []).filter((pkg) => pkg.status === installationStatuses.Installed), | ||
[allPackages?.response] | ||
); | ||
|
||
const updatablePackages = useMemo( | ||
() => | ||
allInstalledPackages.filter( | ||
(item) => | ||
'savedObject' in item && semverLt(item.savedObject.attributes.version, item.version) | ||
), | ||
[allInstalledPackages] | ||
); | ||
|
||
const updatableIntegrations = useMemo( | ||
() => | ||
(agentPolicyData?.items || []).reduce((result, policy) => { | ||
policy.package_policies.forEach((pkgPolicy: PackagePolicy | string) => { | ||
if (typeof pkgPolicy === 'string' || !pkgPolicy.package) return false; | ||
const { name, version } = pkgPolicy.package; | ||
const installedPackage = allInstalledPackages.find( | ||
(installedPkg) => | ||
'savedObject' in installedPkg && installedPkg.savedObject.attributes.name === name | ||
); | ||
if ( | ||
installedPackage && | ||
'savedObject' in installedPackage && | ||
semverLt(version, installedPackage.savedObject.attributes.version) | ||
) { | ||
const packageData = result.get(name) ?? { | ||
currentVersion: installedPackage.savedObject.attributes.version, | ||
policiesToUpgrade: [], | ||
}; | ||
packageData.policiesToUpgrade.push({ | ||
id: policy.id, | ||
name: policy.name, | ||
agentsCount: policy.agents, | ||
pkgPolicyId: pkgPolicy.id, | ||
pkgPolicyName: pkgPolicy.name, | ||
pkgPolicyIntegrationVersion: version, | ||
}); | ||
result.set(name, packageData); | ||
} | ||
}); | ||
return result; | ||
}, new Map()), | ||
[allInstalledPackages, agentPolicyData] | ||
); | ||
|
||
return { | ||
allPackages, | ||
allInstalledPackages, | ||
updatablePackages, | ||
updatableIntegrations, | ||
isLoadingPackages, | ||
isLoadingPolicies, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.