From f6cf196ae57a49237b024d159eb0ec6057a30cda Mon Sep 17 00:00:00 2001 From: "Francois @fanf42 Armand" Date: Mon, 25 May 2020 10:28:40 +0200 Subject: [PATCH] Work in progress --- .../inventory/InventoryFileWatcher.scala | 26 ++++++----------- .../rudder/rest/lift/InventoryApi.scala | 28 +++++-------------- .../rudder/web/components/NodeGroupForm.scala | 1 - .../rudder/web/services/DisplayNode.scala | 3 -- 4 files changed, 16 insertions(+), 42 deletions(-) diff --git a/webapp/sources/rudder/rudder-core/src/main/scala/com/normation/rudder/inventory/InventoryFileWatcher.scala b/webapp/sources/rudder/rudder-core/src/main/scala/com/normation/rudder/inventory/InventoryFileWatcher.scala index b68d643e373..33fb0f3cff3 100644 --- a/webapp/sources/rudder/rudder-core/src/main/scala/com/normation/rudder/inventory/InventoryFileWatcher.scala +++ b/webapp/sources/rudder/rudder-core/src/main/scala/com/normation/rudder/inventory/InventoryFileWatcher.scala @@ -48,6 +48,7 @@ import java.util.concurrent.TimeUnit import better.files._ import com.normation.errors.IOResult import com.normation.errors.RudderError +import com.normation.errors.SystemError import com.normation.inventory.domain.InventoryProcessingLogger import com.normation.zio.ZioRuntime @@ -62,19 +63,17 @@ import zio.blocking.Blocking import zio.clock.Clock final class Watchers(incoming: FileMonitor, updates: FileMonitor) { - def start(): IOResult[Unit] = { + def start(): UIO[Fiber[SystemError, Unit]] = { IOResult.effect { incoming.start()(ZioRuntime.platform.executor.asECES) updates.start()(ZioRuntime.platform.executor.asECES) - Right(()) - } + }.forkDaemon } - def stop(): IOResult[Unit] = { + def stop(): UIO[Fiber[SystemError, Unit]] = { IOResult.effect { incoming.close() updates.close() - Right(()) - } + }.forkDaemon } } object Watchers { @@ -255,13 +254,10 @@ class InventoryFileWatcher( // start scheduler for old file, it will take care of inventories s <- cronForMissed.schedule _ <- InventoryProcessingLogger.info(s"Incoming inventory watcher started - process existing inventories") - } yield Some((w,s)) ).catchAll(err => - InventoryProcessingLogger.error(s"Error when trying to start incoming inventories file watcher. Reported exception was: ${err.fullMsg}") *> - err.fail - ) + } yield Some((w,s)) ) } ) - ).either.runNow + ).runNow def stopWatcher() = semaphore.withPermit( ref.update(opt => @@ -274,14 +270,10 @@ class InventoryFileWatcher( (for { _ <- ZIO.collectAll(w.stop() :: f.interrupt :: Nil) _ <- InventoryProcessingLogger.info(s"Incoming inventory watcher stoped") - } yield None).catchAll(err => - InventoryProcessingLogger.error(s"Error when trying to stop incoming inventories file watcher. Reported exception was: ${err.fullMsg}.") *> - // in all case, remove the previous watcher, it's most likely in a dead state - err.fail - ) + } yield None) } ) - ).either.runNow + ).runNow } diff --git a/webapp/sources/rudder/rudder-rest/src/main/scala/com/normation/rudder/rest/lift/InventoryApi.scala b/webapp/sources/rudder/rudder-rest/src/main/scala/com/normation/rudder/rest/lift/InventoryApi.scala index 3e52de0f0dc..4ca7419e21b 100644 --- a/webapp/sources/rudder/rudder-rest/src/main/scala/com/normation/rudder/rest/lift/InventoryApi.scala +++ b/webapp/sources/rudder/rudder-rest/src/main/scala/com/normation/rudder/rest/lift/InventoryApi.scala @@ -191,12 +191,8 @@ class InventoryApi ( implicit val actionName = "fileWatcherStart" def process0(version: ApiVersion, path: ApiPath, req: Req, params: DefaultParams, authzToken: AuthzToken): LiftResponse = { implicit val pretty = params.prettify - inventoryFileWatcher.startWatcher() match { - case Right(()) => - toJsonResponse(None, "Incoming inventory watcher started") - case Left(ex) => - toJsonError(None, s"Error when trying to start incoming inventories file watcher. Reported exception was: ${ex.fullMsg}.") - } + inventoryFileWatcher.startWatcher() + toJsonResponse(None, "Incoming inventory watcher started") } } @@ -206,12 +202,8 @@ class InventoryApi ( implicit val actionName = "fileWatcherStop" def process0(version: ApiVersion, path: ApiPath, req: Req, params: DefaultParams, authzToken: AuthzToken): LiftResponse = { implicit val pretty = params.prettify - inventoryFileWatcher.stopWatcher() match { - case Right(()) => - toJsonResponse(None, "Incoming inventory watcher stopped") - case Left(ex) => - toJsonError(None, s"Error when trying to stop incoming inventories file watcher. Reported exception was: ${ex.fullMsg}.") - } + inventoryFileWatcher.stopWatcher() + toJsonResponse(None, "Incoming inventory watcher stopped") } } @@ -221,15 +213,9 @@ class InventoryApi ( implicit val actionName = "frileWatcherRestart" def process0(version: ApiVersion, path: ApiPath, req: Req, params: DefaultParams, authzToken: AuthzToken): LiftResponse = { implicit val pretty = params.prettify - (for { - _ <- inventoryFileWatcher.stopWatcher() - _ <- inventoryFileWatcher.startWatcher() - } yield ()) match { - case Right(()) => - toJsonResponse(None, "Incoming inventory watcher restarted") - case Left(ex) => - toJsonError(None, s"Error when trying to restart incoming inventories file watcher. Reported exception was: ${ex.fullMsg}.") - } + inventoryFileWatcher.stopWatcher() + inventoryFileWatcher.startWatcher() + toJsonResponse(None, "Incoming inventory watcher restarted") } } diff --git a/webapp/sources/rudder/rudder-web/src/main/scala/com/normation/rudder/web/components/NodeGroupForm.scala b/webapp/sources/rudder/rudder-web/src/main/scala/com/normation/rudder/web/components/NodeGroupForm.scala index b5a6a385f82..350d4a8482d 100644 --- a/webapp/sources/rudder/rudder-web/src/main/scala/com/normation/rudder/web/components/NodeGroupForm.scala +++ b/webapp/sources/rudder/rudder-web/src/main/scala/com/normation/rudder/web/components/NodeGroupForm.scala @@ -264,7 +264,6 @@ class NodeGroupForm( def showGroupProperties(group: NodeGroup): NodeSeq = { import com.normation.rudder.AuthorizationType - import net.liftweb.json._ val groupId = group.id.value val userHasRights = CurrentUser.checkRights(AuthorizationType.Group.Edit) diff --git a/webapp/sources/rudder/rudder-web/src/main/scala/com/normation/rudder/web/services/DisplayNode.scala b/webapp/sources/rudder/rudder-web/src/main/scala/com/normation/rudder/web/services/DisplayNode.scala index 61bb2b8b99c..7c54a4b184b 100644 --- a/webapp/sources/rudder/rudder-web/src/main/scala/com/normation/rudder/web/services/DisplayNode.scala +++ b/webapp/sources/rudder/rudder-web/src/main/scala/com/normation/rudder/web/services/DisplayNode.scala @@ -687,12 +687,9 @@ object DisplayNode extends Loggable { } def displayTabProperties(jsId:JsNodeId, node: NodeInfo) : NodeSeq = { - import com.normation.rudder.domain.nodes.JsonSerialisation._ import com.normation.rudder.AuthorizationType - import net.liftweb.json._ val nodeId = node.id.value - val allProps = ZioRuntime.runNow(RudderConfig.nodePropertiesInheritance.getNodePropertiesTree(node)) val userHasRights = CurrentUser.checkRights(AuthorizationType.Node.Edit) def tabProperties = ChooseTemplate(List("templates-hidden", "components", "ComponentNodeProperties") , "nodeproperties-tab") val tabId = htmlId(jsId,"sd_props_")