Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
ElaadF committed Nov 22, 2021
1 parent e297d31 commit 26aa010
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ class AcceptedNodesLDAPQueryProcessor(
timeres = (System.currentTimeMillis - timePreCompute)
_ = logger.debug(s"LDAP result: ${res.entries.size} entries obtained in ${timeres}ms for query ${query.toString}")
ldapEntries <- nodeInfoService.getLDAPNodeInfo(res.entries.flatMap(x => x(A_NODE_UUID).map(NodeId(_))).toSet, res.nodeFilters, query.composition)
// o <- nodeInfoService.getPendingNodeInfo(res.entries.flatMap(x => x(A_NODE_UUID).map(NodeId(_))).toSet, res.nodeFilters, query.composition)
ldapEntryTime = (System.currentTimeMillis - timePreCompute - timeres)
_ = logger.debug(s"[post-filter:rudderNode] Found ${ldapEntries.size} nodes when filtering for info service existence and properties (${ldapEntryTime} ms)")

Expand Down Expand Up @@ -302,10 +303,13 @@ class PendingNodesLDAPQueryChecker(
LoggerFactory.getILoggerFactory.getLogger(Logger.loggerNameFor(classOf[InternalLDAPQueryProcessor])).debug(
s"Checking a query with 0 criterium will always lead to 0 nodes: ${query}"
)
println("vide")
Full(Seq.empty[NodeId])
} else {
println("pas vide")
for {
res <- checker.internalQueryProcessor(query, Seq("1.1"), Some(limitToNodeIds)).toBox
_ <- IOResult.effect(println(res)).toBox
ids <- sequence(res.entries) { entry =>
checker.ldapMapper.nodeDn2OptNodeId(entry.dn).toBox ?~! "Can not get node ID from dn %s".format(entry.dn)
}
Expand Down Expand Up @@ -476,7 +480,9 @@ class InternalLDAPQueryProcessor(
// If dnMapSets returns a None, then it means that we are ANDing composition with an empty value
// so we skip the last query
results <- optdms match {
case None => Seq[LDAPEntry]().succeed
case None =>
println("optmdn none")
Seq[LDAPEntry]().succeed
case Some(dms) =>
(for {
// Ok, do the computation here
Expand All @@ -500,8 +506,12 @@ class InternalLDAPQueryProcessor(
tap(seq => logPure.debug(s"[${debugId}] `-> ${seq.size} results"))
}
inverted <- query.transform match {
case ResultTransformation.Identity => results.succeed
case ResultTransformation.Identity =>
println(results)
println("world")
results.succeed
case ResultTransformation.Invert =>
println("hello")
for {
_ <- logPure.debug(s"[${debugId}] |- (need to get all nodeIds for inversion) ")
allIds <- executeQuery(nodeObjectTypes.baseDn, nodeObjectTypes.scope, nodeObjectTypes.objectFilter, Some(ALL), Set(), Set(), nq.composition, debugId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,16 @@ class NodeApi (
def process0(version: ApiVersion, path: ApiPath, req: Req, params: DefaultParams, authzToken: AuthzToken): LiftResponse = {
implicit val prettify = params.prettify
restExtractor.extractNodeDetailLevel(req.params) match {
case Full(level) => serviceV6.listNodes(PendingInventory, level, None, version)
case Full(level) =>
restExtractor.extractQuery(req.params) match {
case Full(None) =>
serviceV6.listNodes(PendingInventory, level, None, version)
case Full(Some(query)) =>
serviceV6.queryNodes(query,PendingInventory, level, version)
case eb:EmptyBox =>
val failMsg = eb ?~ "Node query not correctly sent"
toJsonError(None, failMsg.msg)("listPendingNodes",prettify)
}
case eb:EmptyBox =>
val failMsg = eb ?~ "node detail level not correctly sent"
toJsonError(None, failMsg.msg)(schema.name,prettify)
Expand Down Expand Up @@ -993,6 +1002,7 @@ class NodeApiService6 (
, restExtractor : RestExtractorService
, restSerializer : RestDataSerializer
, acceptedNodeQueryProcessor: QueryProcessor
, pendingNodeQueryProcessor : PendingNodesLDAPQueryChecker
, roAgentRunsRepository : RoReportsExecutionRepository
) extends Loggable {

Expand Down Expand Up @@ -1041,7 +1051,16 @@ class NodeApiService6 (
def queryNodes ( query: QueryTrait, state: InventoryStatus, detailLevel : NodeDetailLevel, version : ApiVersion)( implicit prettify : Boolean) = {
implicit val action = s"list${state.name.capitalize}Nodes"
( for {
nodeIds <- acceptedNodeQueryProcessor.processOnlyId(query)
nodeIds <- state match {
case PendingInventory =>
println("==============toto")
val res = pendingNodeQueryProcessor.check(query, Seq(NodeId("root")))
println(query.toJSONString)
println(res)
res
case AcceptedInventory => acceptedNodeQueryProcessor.processOnlyId(query)
case _ => Failure("test")
}
} yield {
listNodes(state,detailLevel,Some(nodeIds),version)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,17 @@ import scala.concurrent.duration.Duration
import scala.concurrent.duration.FiniteDuration
import scala.xml.Elem
import com.normation.box._
import com.normation.errors.Inconsistency
import com.normation.inventory.ldap.core.InventoryMapper
import com.normation.ldap.ldif.DefaultLDIFFileLogger
import com.normation.ldap.listener.InMemoryDsConnectionProvider
import com.normation.ldap.sdk.RoLDAPConnection
import com.normation.rudder.db.GenerateCompliance.roLdap
import com.normation.rudder.domain.nodes.NodeGroupId
import com.normation.rudder.repository.ldap.LDAPEntityMapper
import com.normation.rudder.rest.v1.RestTechniqueReload
import com.normation.rudder.services.queries.InternalLDAPQueryProcessor
import com.normation.rudder.services.queries.PendingNodesLDAPQueryChecker


/*
Expand Down Expand Up @@ -505,9 +514,61 @@ object RestTestSetUp {
override def getNodesLastRun(nodeIds: Set[NodeId]): Box[Map[NodeId, Option[AgentRunWithNodeConfig]]] = Full(Map())
}

val schemaLDIFs = (
"00-core" ::
"01-pwpolicy" ::
"04-rfc2307bis" ::
"05-rfc4876" ::
"099-0-inventory" ::
"099-1-rudder" ::
Nil
) map { name =>
// toURI is needed for https://issues.rudder.io/issues/19186
this.getClass.getClassLoader.getResource("ldap-data/schema/" + name + ".ldif").toURI.getPath
}
val bootstrapLDIFs = ("ldap/bootstrap.ldif" :: "ldap-data/inventory-sample-data.ldif" :: Nil) map { name =>
// toURI is needed for https://issues.rudder.io/issues/19186
this.getClass.getClassLoader.getResource(name).toURI.getPath
}
val ldifLogger = new DefaultLDIFFileLogger("TestQueryProcessor","/tmp/normation/rudder/ldif")

val ldap = InMemoryDsConnectionProvider[RoLDAPConnection](
baseDNs = "cn=rudder-configuration" :: Nil
, schemaLDIFPaths = schemaLDIFs
, bootstrapLDIFPaths = bootstrapLDIFs
, ldifLogger
)

val DIT = new InventoryDit(new DN("ou=Accepted Inventories,ou=Inventories,cn=rudder-configuration"),new DN("ou=Inventories,cn=rudder-configuration"),"test")
val ditQueryData = new DitQueryData(DIT, nodeDit, rudderDit, () => Inconsistency("For test, no subgroup").fail)
val ldapMapper = new LDAPEntityMapper(rudderDit, nodeDit, DIT, null, inventoryMapper)
val pendingDIT = new InventoryDit(new DN("ou=Pending Inventories,ou=Inventories,cn=rudder-configuration"),new DN("ou=Inventories,cn=rudder-configuration"),"test")
val removedDIT = new InventoryDit(new DN("ou=Removed Inventories,ou=Inventories,cn=rudder-configuration"),new DN("ou=Inventories,cn=rudder-configuration"),"test")

val ditService = new InventoryDitServiceImpl(pendingDIT, DIT, removedDIT)

val inventoryMapper = new InventoryMapper(ditService, pendingDIT, DIT, removedDIT)



val internalLDAPQueryProcessor = new InternalLDAPQueryProcessor(ldap,DIT,nodeDit,ditQueryData,ldapMapper)
val inventoryQueryChecker = new PendingNodesLDAPQueryChecker(internalLDAPQueryProcessor)

//we need a roLdap query checker for nodes in pending
// val inventoryQueryChecker = new PendingNodesLDAPQueryChecker(
// new InternalLDAPQueryProcessor(
// roLdap
// , pendingNodesDitImpl
// , nodeDit
// // here, we don't want to look for subgroups to show them in the form => always return an empty list
// , new DitQueryData(pendingNodesDitImpl, nodeDit, rudderDit, () => Nil.succeed)
// , ldapEntityMapper
// )
// )

val nodeApiService2 = new NodeApiService2(null, nodeInfo, null, uuidGen, restExtractorService, restDataSerializer)
val nodeApiService4 = new NodeApiService4(nodeInfo, nodeInfo, softDao, uuidGen, restExtractorService, restDataSerializer, roReportsExecutionRepository)
val nodeApiService6 = new NodeApiService6(nodeInfo, nodeInfo, softDao, restExtractorService, restDataSerializer, mockNodes.queryProcessor, roReportsExecutionRepository)
val nodeApiService6 = new NodeApiService6(nodeInfo, nodeInfo, softDao, restExtractorService, restDataSerializer, mockNodes.queryProcessor, inventoryQueryChecker, roReportsExecutionRepository)
val nodeApiService8 = new NodeApiService8(null, nodeInfo, uuidGen, asyncDeploymentAgent, "relay", null)
val nodeApiService12 = new NodeApiService12(null, uuidGen, restDataSerializer)
val nodeApiService13 = new NodeApiService13(nodeInfo, roReportsExecutionRepository, softDao,restExtractorService, () => Full(GlobalPolicyMode(Audit, PolicyModeOverrides.Always)),null, null, null )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,7 @@ object RudderConfig extends Loggable {
, restExtractorService
, restDataSerializer
, queryProcessor
, inventoryQueryChecker
, roAgentRunsRepository
)

Expand Down Expand Up @@ -1497,6 +1498,14 @@ object RudderConfig extends Loggable {
nodeInfoServiceImpl
)

// //query processor for pending nodes
// private[this] lazy val queryProcessorPendingNodes = new PendingNodesLDAPQueryProcessor(
// nodeDitImpl,
// pendingNodesDitImpl,
// new InternalLDAPQueryProcessor(roLdap, pendingNodesDitImpl, nodeDit, ditQueryDataImpl, ldapEntityMapper),
// nodeInfoServiceImpl
// )

//we need a roLdap query checker for nodes in pending
private[this] lazy val inventoryQueryChecker = new PendingNodesLDAPQueryChecker(
new InternalLDAPQueryProcessor(
Expand Down

0 comments on commit 26aa010

Please sign in to comment.