-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- move serializer function around a little bit - move serialize migrate and allocate function out of serializer file
- Loading branch information
1 parent
adf967d
commit 79c1536
Showing
3 changed files
with
85 additions
and
64 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
...dex_lifecycle_management/public/application/sections/edit_policy/form/serializer/index.ts
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,7 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export { createSerializer } from './serializer'; |
70 changes: 70 additions & 0 deletions
70
...pplication/sections/edit_policy/form/serializer/serialize_migrate_and_allocate_actions.ts
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,70 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { isEmpty } from 'lodash'; | ||
|
||
import { SerializedActionWithAllocation } from '../../../../../../common/types'; | ||
|
||
import { DataAllocationMetaFields } from '../../types'; | ||
|
||
export const serializeMigrateAndAllocateActions = ( | ||
{ dataTierAllocationType, allocationNodeAttribute }: DataAllocationMetaFields, | ||
newActions: SerializedActionWithAllocation = {}, | ||
originalActions: SerializedActionWithAllocation = {} | ||
): SerializedActionWithAllocation => { | ||
const { allocate, migrate, ...otherActions } = newActions; | ||
|
||
// First copy over all non-allocate and migrate actions. | ||
const actions: SerializedActionWithAllocation = { ...otherActions }; | ||
|
||
// The UI only knows about include, exclude and require, so copy over all other values. | ||
if (allocate) { | ||
const { include, exclude, require, ...otherSettings } = allocate; | ||
if (!isEmpty(otherSettings)) { | ||
actions.allocate = { ...otherSettings }; | ||
} | ||
} | ||
|
||
switch (dataTierAllocationType) { | ||
case 'node_attrs': | ||
if (allocationNodeAttribute) { | ||
const [name, value] = allocationNodeAttribute.split(':'); | ||
actions.allocate = { | ||
// copy over any other allocate details like "number_of_replicas" | ||
...actions.allocate, | ||
require: { | ||
[name]: value, | ||
}, | ||
}; | ||
} else { | ||
// The form has been configured to use node attribute based allocation but no node attribute | ||
// was selected. We fall back to what was originally selected in this case. This might be | ||
// migrate.enabled: "false" | ||
actions.migrate = originalActions.migrate; | ||
} | ||
|
||
// copy over the original include and exclude values until we can set them in the form. | ||
if (!isEmpty(originalActions?.allocate?.include)) { | ||
actions.allocate = { | ||
...actions.allocate, | ||
include: { ...originalActions?.allocate?.include }, | ||
}; | ||
} | ||
|
||
if (!isEmpty(originalActions?.allocate?.exclude)) { | ||
actions.allocate = { | ||
...actions.allocate, | ||
exclude: { ...originalActions?.allocate?.exclude }, | ||
}; | ||
} | ||
break; | ||
case 'none': | ||
actions.migrate = { enabled: false }; | ||
break; | ||
default: | ||
} | ||
return actions; | ||
}; |
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