Skip to content
This repository has been archived by the owner on Feb 8, 2019. It is now read-only.

Commit

Permalink
Merge pull request #79 from fanf/bug_7562/reload_technique_api_call_m…
Browse files Browse the repository at this point in the history
…ust_be_synchrone_cfclerk_part

Fixes #7562: Reload technique API call must be synchrone (cfclerk part)
  • Loading branch information
VinceMacBuche committed Dec 8, 2015
2 parents 67c255c + b25f007 commit 754dcff
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ package com.normation.cfclerk.services
import com.normation.cfclerk.domain.TechniqueId
import com.normation.eventlog.EventActor
import com.normation.eventlog.ModificationId
import net.liftweb.common.Box

/**
* A trait that allows its implementation to get notification
Expand All @@ -60,6 +61,6 @@ trait TechniquesLibraryUpdateNotification {
* Description is a log description to explain why techniques should be updated
* (user action, commit, etc).
*/
def updatedTechniques(TechniqueIds:Seq[TechniqueId], modId: ModificationId, actor: EventActor, reason: Option[String]) : Unit
def updatedTechniques(TechniqueIds:Seq[TechniqueId], modId: ModificationId, actor: EventActor, reason: Option[String]) : Box[Unit]

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ trait UpdateTechniqueLibrary {
*/
def registerCallback(callback:TechniquesLibraryUpdateNotification) : Unit

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import scala.collection.mutable
import com.normation.eventlog.EventActor
import com.normation.eventlog.ModificationId
import com.normation.utils.StringUuidGenerator
import com.normation.utils.Control

class TechniqueRepositoryImpl(
techniqueReader: TechniqueReader
Expand Down Expand Up @@ -102,18 +103,20 @@ class TechniqueRepositoryImpl(
})
techniqueInfosCache = techniqueReader.readTechniques

callbacks.foreach { callback =>
val res = Control.bestEffort(callbacks) { callback =>
try {
callback.updatedTechniques(modifiedPackages, modId, actor, reason)
} catch {
case e: Exception => logger.error("Error when executing callback '%s' with updated technique: '%s'".format(callback.name, modifiedPackages.mkString(", ")), e)
case e: Exception =>
Failure(s"Error when executing callback '${callback.name}' for updated techniques: '${modifiedPackages.mkString(", ")}'", Full(e), Empty)
}
}

res.map { _ => modifiedPackages }
} else {
logger.debug("Not reloading technique library as nothing changed since last reload")
Full(modifiedPackages)
}
Full(modifiedPackages)
} catch {
case e:Exception => Failure("Error when trying to read technique library", Full(e), Empty)
}
Expand Down

0 comments on commit 754dcff

Please sign in to comment.