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

Fixes #4299 : XmlMigration from format 4 to 5 #404

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
*************************************************************************************
* Copyright 2013 Normation SAS
*************************************************************************************
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero GPL v3, 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 Affero GPL v3
* licence, 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.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/agpl.html>.
*
*************************************************************************************
*/


-- if an old EventLog entry has been detected, add a flag with the format 4 and the current date to tell Rudder about it

INSERT INTO migrationeventlog(detectiontime, detectedfileformat) VALUES (NOW(), 4);
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,12 @@ object Constants {
val XML_FILE_FORMAT_2 = 2
val XML_FILE_FORMAT_3 = 3
val XML_FILE_FORMAT_4 = 4
val XML_FILE_FORMAT_5 = 5

val XML_CURRENT_FILE_FORMAT = XML_FILE_FORMAT_4
val XML_CURRENT_FILE_FORMAT = XML_FILE_FORMAT_5

val CONFIGURATION_RULES_ARCHIVE_TAG = "#rules-archive"
val RULE_CATEGORY_ARCHIVE_TAG = "#rule-categories-archive"
val GROUPS_ARCHIVE_TAG = "#groups-archive"
val POLICY_LIBRARY_ARCHIVE_TAG = "#directives-archive"
val FULL_ARCHIVE_TAG = "#full-archive"
Expand All @@ -107,6 +109,7 @@ object Constants {
///// XML tag names for directive, categories, etc

val XML_TAG_RULE = "rule"
val XML_TAG_RULE_CATEGORY = "ruleCategory"
val XML_TAG_ACTIVE_TECHNIQUE_CATEGORY = "activeTechniqueCategory"
val XML_TAG_ACTIVE_TECHNIQUE = "activeTechnique"
val XML_TAG_DIRECTIVE = "directive"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class RudderDit(val BASE_DN:DN) extends AbstractDit {
)
}

/* def ruleCategory(
def ruleCategory (
uuid : String
, parentDN : DN
, name : String = ""
Expand All @@ -152,7 +152,7 @@ class RudderDit(val BASE_DN:DN) extends AbstractDit {
, OC_RULE_CATEGORY
, A_RULE_CATEGORY_UUID
)
}*/
}


/*
Expand Down Expand Up @@ -516,6 +516,13 @@ class RudderDit(val BASE_DN:DN) extends AbstractDit {
).model.dn
}

def RuleCategoryLibDN(id:RuleCategoryArchiveId) : DN = {
ruleCategory(
uuid = "RuleCategoryLibrarby-" + id.value
, parentDN = archives.dn
).model.dn
}

def parameterModel(
parameterArchiveId : ParameterArchiveId
) : LDAPEntry = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ import com.normation.utils.HashcodeCaching

final case class RuleArchiveId(value:String) extends HashcodeCaching

final case class ParameterArchiveId(value:String) extends HashcodeCaching
final case class ParameterArchiveId(value:String) extends HashcodeCaching

final case class RuleCategoryArchiveId(value:String) extends HashcodeCaching
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ trait XmlEntityMigration {
class DefaultXmlEventLogMigration(
xmlMigration_2_3: XmlMigration_2_3
, xmlMigration_3_4: XmlMigration_3_4
, xmlMigration_4_5: XmlMigration_4_5
) extends XmlEntityMigration {

def getUpToDateXml(entity:Elem) : Box[Elem] = {
Expand All @@ -400,10 +401,11 @@ class DefaultXmlEventLogMigration(
versionT <- Box(entity.attribute("fileFormat").map( _.text )) ?~! s"Can not migrate element with unknow fileFormat: ${entity}"
version <- try { Full(versionT.toFloat.toInt) } catch { case e:Exception => Failure(s"Bad version (expecting an integer or a float: '${versionT}'")}
migrate <- version match {
case 2 => migrate2_4(entity)
case 3 => migrate3_4(entity)
case 4 => Full(entity)
case x => Failure(s"Can not migrate XML file with fileFormat='${version}' (expecting 2,3 or 4)")
case 2 => migrate2_5(entity)
case 3 => migrate3_5(entity)
case 4 => migrate4_5(entity)
case 5 => Full(entity)
case x => Failure(s"Can not migrate XML file with fileFormat='${version}' (expecting 2,3,4 or 5)")
}
} yield {
migrate
Expand All @@ -424,11 +426,28 @@ class DefaultXmlEventLogMigration(
}
}

private[this] def migrate4_5(xml:Elem) : Box[Elem] = {
xml.label match {
case "rule" => xmlMigration_4_5.rule(xml)
case "changeRequest" => xmlMigration_4_5.changeRequest(xml)
case _ => xmlMigration_3_4.other(xml)
}
}


private[this] def migrate3_5(xml:Elem) : Box[Elem] = {
for {
a <- migrate3_4(xml)
b <- migrate4_5(a)
} yield {
b
}
}

private[this] def migrate2_4(xml:Elem) : Box[Elem] = {
private[this] def migrate2_5(xml:Elem) : Box[Elem] = {
for {
a <- migrate2_3(xml)
b <- migrate3_4(a)
b <- migrate3_5(a)
} yield {
b
}
Expand Down
Loading