Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
fanf committed May 25, 2020
1 parent 08f560a commit f6cf196
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 {
Expand Down Expand Up @@ -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 =>
Expand All @@ -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
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

Expand All @@ -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")
}
}

Expand All @@ -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")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_")
Expand Down

0 comments on commit f6cf196

Please sign in to comment.