-
Notifications
You must be signed in to change notification settings - Fork 77
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
Fixes #25979: Migrate custom properties along with node properties for consistency #6060
Draft
fanf
wants to merge
4
commits into
Normation:master
Choose a base branch
from
fanf:enh_25979/migrate_custom_properties_along_with_node_properties_for_consistency
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
924efda
Fixes #25977: Node update event does not correctly record old node
fanf 6b5da30
Fixes #25979: Migrate custom properties along with node properties fo…
fanf c82d952
fixup! Fixes #25979: Migrate custom properties along with node proper…
fanf 6e7c18c
fixup! fixup! Fixes #25979: Migrate custom properties along with node…
fanf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
123 changes: 123 additions & 0 deletions
123
...-web/src/main/scala/bootstrap/liftweb/checks/migration/CheckMigrateCustomProperties.scala
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,123 @@ | ||
/* | ||
************************************************************************************* | ||
* Copyright 2024 Normation SAS | ||
************************************************************************************* | ||
* | ||
* This file is part of Rudder. | ||
* | ||
* Rudder is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* In accordance with the terms of section 7 (7. Additional Terms.) of | ||
* the GNU General Public License version 3, the copyright holders add | ||
* the following Additional permissions: | ||
* Notwithstanding to the terms of section 5 (5. Conveying Modified Source | ||
* Versions) and 6 (6. Conveying Non-Source Forms.) of the GNU General | ||
* Public License version 3, when you create a Related Module, this | ||
* Related Module is not considered as a part of the work and may be | ||
* distributed under the license agreement of your choice. | ||
* A "Related Module" means a set of sources files including their | ||
* documentation that, without modification of the Source Code, enables | ||
* supplementary functions or services in addition to those offered by | ||
* the Software. | ||
* | ||
* Rudder is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Rudder. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
* | ||
************************************************************************************* | ||
*/ | ||
|
||
package bootstrap.liftweb.checks.migration | ||
|
||
import bootstrap.liftweb.BootstrapChecks | ||
import com.normation.errors.* | ||
import com.normation.inventory.domain.NodeId | ||
import com.normation.inventory.ldap.core.InventoryDit | ||
import com.normation.inventory.ldap.core.LDAPConstants.* | ||
import com.normation.ldap.sdk.BuildFilter | ||
import com.normation.ldap.sdk.LDAPConnectionProvider | ||
import com.normation.ldap.sdk.RwLDAPConnection | ||
import com.normation.rudder.domain.logger.MigrationLoggerPure | ||
import com.normation.rudder.facts.nodes.ChangeContext | ||
import com.normation.rudder.facts.nodes.NodeFactRepository | ||
import com.normation.zio.* | ||
import zio.* | ||
|
||
/* | ||
* This migration check looks if there is still nodes with custom properties | ||
* in the ou=Accepted Inventories branch, and if so, it save back them so that | ||
* they are moved along with other properties. | ||
* Added in rudder 8.1.8 (https://issues.rudder.io/issues/25978) | ||
* Can be removed in Rudder 8.3 | ||
*/ | ||
|
||
class CheckMigrateCustomProperties( | ||
ldap: LDAPConnectionProvider[RwLDAPConnection], | ||
factRepo: NodeFactRepository, | ||
inventoryDit: InventoryDit | ||
) extends BootstrapChecks { | ||
|
||
override def description: String = | ||
"Check if some nodes still have custom properties store in LDAP inventory and migrate them to LDAP node is so" | ||
|
||
override def checks(): Unit = { | ||
migrateAll() | ||
.catchAll(err => { | ||
MigrationLoggerPure.error(s"Error when trying to migrate nodes' custom properties in LDAP: ${err.fullMsg}") | ||
}) | ||
.forkDaemon // make it async to avoid blocking startup, there can be a lot of nodes to migrate | ||
.runNow | ||
} | ||
|
||
/* | ||
* The whole process | ||
*/ | ||
def migrateAll(): IOResult[Unit] = { | ||
for { | ||
ids <- findNodeNeedingMigration() | ||
_ <- migrateProperties(ids) | ||
} yield () | ||
} | ||
|
||
/* | ||
* Look for nodes with customProperty attribute | ||
*/ | ||
def findNodeNeedingMigration(): IOResult[Seq[NodeId]] = { | ||
for { | ||
con <- ldap | ||
needMigration <- con | ||
.searchOne(inventoryDit.NODES.dn, BuildFilter.HAS(A_CUSTOM_PROPERTY), A_NODE_UUID) | ||
.chainError(s"Error when trying to get node entries with existing ${A_CUSTOM_PROPERTY} attributes.") | ||
ids <- ZIO.foreach(needMigration)(e => inventoryDit.NODES.NODE.idFromDN(e.dn).toIO) | ||
} yield ids | ||
} | ||
|
||
/* | ||
* Migrate node after node. We don't want that one failure stop the process | ||
*/ | ||
def migrateProperties(nodeIds: Seq[NodeId]): UIO[Unit] = { | ||
implicit val cc = ChangeContext.newForRudder(Some("Migrating custom properties LDAP storage")) | ||
ZIO | ||
.foreach(nodeIds) { id => | ||
(for { | ||
opt <- factRepo.get(id)(cc.toQuery) | ||
_ <- opt match { | ||
case Some(node) => factRepo.save(node) | ||
case None => ZIO.unit | ||
} | ||
} yield ()).catchAll { | ||
case e => MigrationLoggerPure.error(s"Error when migrating custom properties for node '${id.value}': ${e.fullMsg}") | ||
} | ||
} | ||
.unit | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 PR is in 8.3, the comment could be misleading, why not removing this file 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.
yes, I was not sure if we should put it in 8.1 or not. But there is 0 reasons to do so:
That goes to 8.3. I updated the text accordingly.