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 #16010: Dynamic group based on another dynamic group don't work correctly in 6.0 #2546

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
Expand Up @@ -345,22 +345,24 @@ class InternalLDAPQueryProcessor(
}.map(_.toMap)
}

//now, groups resulting set of same DnType according to composition
def dnMapSets(normalizedQuery: LDAPNodeQuery, dnMapMapSets: Map[DnType, Map[String,Set[DN]]]) : Map[DnType, Set[DN]] = {
dnMapMapSets map { case (dnType, dnMapSet) =>
// Now, groups resulting set of same DnType according to composition
// Returns None if the resulting composition (using AND) leads to an empty set of Nodes, Some filtering otherwise
def dnMapSets(normalizedQuery: LDAPNodeQuery, dnMapMapSets: Map[DnType, Map[String,Set[DN]]]) : Option[Map[DnType, Set[DN]]] = {
val mapSet = dnMapMapSets map { case (dnType, dnMapSet) =>
val dnSet:Set[DN] = normalizedQuery.composition match {
case Or => dnMapSet.foldLeft(Set[DN]())( _ union _._2 )
case And =>
val s = if(dnMapSet.isEmpty) Set[DN]() else dnMapSet.foldLeft(dnMapSet.head._2)( _ intersect _._2 )
// if(s.isEmpty) {
// logger.debug(s"[${debugId}] `-> early stop query (empty sub-query)"))
// return Full(LdapQueryProcessorResult(Nil, Nil)) //there is no need to go farther, since it will lead to ending with empty set
// }
// else s
// Here if s is empty, it means we are ANDing with an empty Set, so we could simply drop all computation from there
if(s.isEmpty) {
logPure.debug(s"[${debugId}] `-> early stop query (empty sub-query)")
return None
}
s
}
(dnType, dnSet)
}
Some(mapSet)
}


Expand Down Expand Up @@ -404,40 +406,51 @@ class InternalLDAPQueryProcessor(

for {
//log start query
_ <- logPure.debug(s"[${debugId}] Start search for ${query.toString}")
nq <- normalizedQuery
lots <- ldapObjectTypeSets(nq)
dmms <- dnMapMapSets(nq, lots)
dms = dnMapSets(nq, dmms)
_ <- logPure.ifTraceEnabled {
ZIO.foreach(dms) { case (dnType, dns) =>
logPure.trace(s"/// ${dnType} ==> ${dns.map( _.getRDN).mkString(", ")}")
_ <- logPure.debug(s"[${debugId}] Start search for ${query.toString}")
// Construct & normalize the data
nq <- normalizedQuery
lots <- ldapObjectTypeSets(nq)
dmms <- dnMapMapSets(nq, lots)
optdms = dnMapSets(nq, dmms)
// If dnMapSets returns a None, then it means that we are ANDing composition with an empty value
// so we skip rest of computation
result <- optdms match {
case None => LdapQueryProcessorResult(Nil, Nil).succeed
case Some(dms) => for {
// Ok, do the computation here
_ <- logPure.ifTraceEnabled {
ZIO.foreach(dms) { case (dnType, dns) =>
logPure.trace(s"/// ${dnType} ==> ${dns.map(_.getRDN).mkString(", ")}")
}
}
}
fss = filterSeqSet(dms)
blf <- buildLastFilter(nq, fss)

// for convenience
(finalLdapFilter, finalSpecialFilters) = blf

//final query, add "match only server id" filter if needed
rt = nodeObjectTypes.copy(filter = finalLdapFilter)
_ <- logPure.debug(s"[${debugId}] |- (final query) ${rt}")
entries <- (for {
con <- ldap
results <- executeQuery(rt.baseDn, rt.scope, nodeObjectTypes.objectFilter, rt.filter, finalSpecialFilters, select.toSet, nq.composition, debugId)
} yield {
postFilterNode(results.groupBy( _.dn ).map( _._2.head ).toSeq, query.returnType, limitToNodeIds)
}).foldM(
err =>
logPure.debug(s"[${debugId}] `-> error: ${err.fullMsg}") *>
err.fail
, seq =>
logPure.debug(s"[${debugId}] `-> ${seq.size} results") *>
seq.succeed
)
fss = filterSeqSet(dms)
blf <- buildLastFilter(nq, fss)

// for convenience
(finalLdapFilter, finalSpecialFilters) = blf

//final query, add "match only server id" filter if needed
rt = nodeObjectTypes.copy(filter = finalLdapFilter)
_ <- logPure.debug(s"[${debugId}] |- (final query) ${rt}")
entries <- (for {
con <- ldap
results <- executeQuery(rt.baseDn, rt.scope, nodeObjectTypes.objectFilter, rt.filter, finalSpecialFilters, select.toSet, nq.composition, debugId)
} yield {
postFilterNode(results.groupBy(_.dn).map(_._2.head).toSeq, query.returnType, limitToNodeIds)
}).foldM(
err =>
logPure.debug(s"[${debugId}] `-> error: ${err.fullMsg}") *>
err.fail
, seq =>
logPure.debug(s"[${debugId}] `-> ${seq.size} results") *>
seq.succeed
)
} yield {
LdapQueryProcessorResult(entries, nq.nodeInfoFilters)
}
}
} yield {
LdapQueryProcessorResult(entries, nq.nodeInfoFilters)
result
}
}

Expand Down Expand Up @@ -465,9 +478,6 @@ class InternalLDAPQueryProcessor(
step2
}

/*
* From the list of DN to query with their filters, build a list of LDAPObjectType
*/
/*
* From the list of DN to query with their filters, build a list of LDAPObjectType
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,17 @@ class TestQueryProcessor extends Loggable {
""").openOrThrowException("For tests"),
Nil)

testQueries(q1 :: q2 :: q3 :: q4 :: q5 :: q6 :: Nil)
val q7 = TestQuery(
"q7",
parser("""
{ "select":"node", "composition":"Or", "where":[
{ "objectType":"group", "attribute":"nodeGroupId", "comparator":"eq", "value":"AIXSystems" }
, { "objectType":"node", "attribute":"OS", "comparator":"eq", "value":"Linux"}
] }
""").openOrThrowException("For tests"),
s(0) :: s(1) :: s(2) :: s(3) :: s(4) :: s(5) :: s(6) :: s(7) :: Nil)

testQueries(q1 :: q2 :: q3 :: q4 :: q5 :: q6 :: q7 :: Nil)
}

@Test def machineComponentQueries(): Unit = {
Expand Down