Skip to content

Commit

Permalink
Fixes #23955: Upmerge collision in rudder 8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
fanf committed Dec 22, 2023
1 parent 22155e2 commit 6281da8
Showing 1 changed file with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -427,13 +427,7 @@ class AcceptHostnameAndIp(
* search in database nodes having the same hostname as one provided.
* Only return existing hostname (and so again, we want that to be empty)
*/
private[this] def queryForDuplicateHostname(hostnames: Seq[String])(implicit qc: QueryContext): IOResult[Unit] = {
def failure(duplicates: Seq[String], name: String) = {
Inconsistency(
s"There is already a node with ${name} ${duplicates.mkString("'", "' or '", "'")} in database. You can not add it again."
).fail
}

private[this] def queryForDuplicateHostname(hostnames: Seq[String]): IOResult[Unit] = {
val hostnameCriterion = hostnames.toList.map { h =>
CriterionLine(
objectType = objectType,
Expand All @@ -444,18 +438,18 @@ class AcceptHostnameAndIp(
}

for {
duplicatesH <- BoxToIO(
queryProcessor.process(Query(NodeReturnType, Or, ResultTransformation.Identity, hostnameCriterion))
).toIO
duplicatesH <- queryProcessor.process(Query(NodeReturnType, Or, ResultTransformation.Identity, hostnameCriterion)).toIO
// here, all nodes found are duplicate-in-being. They should be unique, but
// if not, we don't group them that the duplicate appears in the list
noDuplicatesH <- if (duplicatesH.isEmpty) ZIO.unit
else {
// get the hostname from nodeFactRepo
nodeFactRepo
.getAll()
.map(_.collect { case (_, n) if (duplicatesH.contains(n.id)) => n.fqdn }.toSeq)
.flatMap(failure(_, "Hostname"))
val startMessage = {
if (duplicatesH.size >= 2) s"There are already ${duplicatesH.size} nodes"
else "There is already a node"
}
Inconsistency(
s"${startMessage} with hostname '${name}' in Rudder. You can not add it again."
).fail
}
} yield ()
}
Expand All @@ -470,7 +464,7 @@ class AcceptHostnameAndIp(
_ <- ZIO.when(!acceptDuplicated) {
for {
noDuplicateHostnames <- checkDuplicateString(List(cnf.fqdn), "hostname")
noDuplicateInDB <- queryForDuplicateHostname(List(cnf.fqdn))(cc.toQuery)
noDuplicateInDB <- queryForDuplicateHostname(List(cnf.fqdn))
} yield ()
}
} yield ()
Expand Down

0 comments on commit 6281da8

Please sign in to comment.