Commit 5eeb60d2 authored by Romain Reuillon's avatar Romain Reuillon
Browse files

[Core] enh: add logger service as default service

parent 33c73ef2
Pipeline #178 failed with stage
in 6 minutes and 16 seconds
......@@ -24,7 +24,7 @@ import org.openmole.core.exception.InternalProcessingError
import org.openmole.core.outputmanager.OutputManager
import org.openmole.core.pluginmanager.PluginManager
import org.openmole.core.workflow.task.TaskExecutionContext
import org.openmole.tool.logger.JavaLogger
import org.openmole.tool.logger.{ JavaLogger, LoggerService }
import org.openmole.core.tools.service.Retry
import org.openmole.core.workspace.{ NewFile, Workspace }
import org.openmole.core.tools.service._
......@@ -64,7 +64,7 @@ class Runtime {
outputMessagePath: String,
threads: Int,
debug: Boolean
)(implicit serializerService: SerializerService, newFile: NewFile, fileService: FileService, preference: Preference, threadProvider: ThreadProvider, eventDispatcher: EventDispatcher, workspace: Workspace) = {
)(implicit serializerService: SerializerService, newFile: NewFile, fileService: FileService, preference: Preference, threadProvider: ThreadProvider, eventDispatcher: EventDispatcher, workspace: Workspace, loggerService: LoggerService) = {
/*--- get execution message and job for runtime---*/
val usedFiles = new HashMap[String, File]
......@@ -145,7 +145,18 @@ class Runtime {
try {
val outputRedirection = OutputRedirection(outSt)
val taskExecutionContext = TaskExecutionContext(newFile.makeNewDir("runtime"), environment, preference, threadProvider, fileService, workspace, outputRedirection, KeyValueCache(), LockRepository[LockKey]())
val taskExecutionContext = TaskExecutionContext(
tmpDirectory = newFile.makeNewDir("runtime"),
localEnvironment = environment,
preference = preference,
threadProvider = threadProvider,
fileService = fileService,
workspace = workspace,
outputRedirection = outputRedirection,
loggerService = loggerService,
cache = KeyValueCache(),
lockRepository = LockRepository[LockKey]())
for (toProcess allMoleJobs) environment.submit(toProcess, taskExecutionContext)
saver.waitAllFinished
}
......
......@@ -17,10 +17,10 @@
package org.openmole.runtime
import org.openmole.core.logconfig.LoggerConfig
import org.openmole.core.logconfig._
import org.openmole.core.pluginmanager.PluginManager
import org.openmole.tool.file._
import org.openmole.tool.logger.JavaLogger
import org.openmole.tool.logger.{ JavaLogger, LoggerService }
import scopt._
import java.io.File
......@@ -92,6 +92,7 @@ object SimExplorer extends JavaLogger {
implicit val threadProvider = ThreadProvider(config.nbThread.get + 5)
implicit val fileService = FileService()
implicit val eventDispatcher = EventDispatcher()
implicit val loggerService = if (config.debug) LoggerService(level = finest) else LoggerService()
try {
......
......@@ -198,7 +198,7 @@ lazy val exception = OsgiProject(coreDir, "org.openmole.core.exception", imports
lazy val tools = OsgiProject(coreDir, "org.openmole.core.tools", global = true, imports = Seq("*")) settings
(libraryDependencies ++= Seq(Libraries.xstream, Libraries.exec, Libraries.math, Libraries.scalatest, Libraries.equinoxOSGi), Libraries.addScalaLang(scalaVersionValue)) dependsOn
(exception, openmoleTar, openmoleFile, openmoleLock, openmoleThread, openmoleHash, openmoleLogger, openmoleStream, openmoleCollection, openmoleStatistics, openmoleTypes, openmoleCache, openmoleRandom, openmoleNetwork, openmoleException) settings (coreSettings: _*)
(exception, openmoleTar, openmoleFile, openmoleLock, openmoleThread, openmoleHash, openmoleLogger, openmoleStream, openmoleCollection, openmoleStatistics, openmoleTypes, openmoleCache, openmoleRandom, openmoleNetwork, openmoleException, openmoleOutputRedirection, openmoleLogger) settings (coreSettings: _*)
lazy val event = OsgiProject(coreDir, "org.openmole.core.event", imports = Seq("*")) dependsOn (tools) settings (coreSettings: _*)
......
......@@ -178,6 +178,7 @@ object MoleExecution extends JavaLogger {
fileService,
workspace,
outputRedirection,
loggerService,
subMoleExecutionState.moleExecution.taskCache,
subMoleExecutionState.moleExecution.lockRepository,
moleExecution = Some(subMoleExecutionState.moleExecution)
......@@ -396,6 +397,7 @@ object MoleExecution extends JavaLogger {
fileService,
workspace,
outputRedirection,
loggerService,
moleExecution.taskCache,
moleExecution.lockRepository,
moleExecution = Some(moleExecution)
......
......@@ -28,6 +28,7 @@ import org.openmole.core.threadprovider._
import org.openmole.core.workspace._
import org.openmole.core.workflow.dsl._
import org.openmole.tool.cache._
import org.openmole.tool.logger.LoggerService
import org.openmole.tool.outputredirection.OutputRedirection
import org.openmole.tool.random.Seeder
......@@ -55,7 +56,7 @@ object MoleServices {
* @param outputRedirection
* @return
*/
implicit def create(implicit preference: Preference, seeder: Seeder, threadProvider: ThreadProvider, eventDispatcher: EventDispatcher, newFile: NewFile, fileService: FileService, workspace: Workspace, outputRedirection: OutputRedirection) = {
implicit def create(implicit preference: Preference, seeder: Seeder, threadProvider: ThreadProvider, eventDispatcher: EventDispatcher, newFile: NewFile, fileService: FileService, workspace: Workspace, outputRedirection: OutputRedirection, loggerService: LoggerService) = {
new MoleServices()(
preference = preference,
seeder = Seeder(seeder.newSeed),
......@@ -65,7 +66,8 @@ object MoleServices {
workspace = workspace,
fileService = fileService,
fileServiceCache = FileServiceCache(),
outputRedirection = outputRedirection
outputRedirection = outputRedirection,
loggerService = loggerService
)
}
......@@ -78,7 +80,8 @@ object MoleServices {
fileService: FileService = moleServices.fileService,
fileServiceCache: FileServiceCache = moleServices.fileServiceCache,
workspace: Workspace = moleServices.workspace,
outputRedirection: OutputRedirection = moleServices.outputRedirection) =
outputRedirection: OutputRedirection = moleServices.outputRedirection,
loggerService: LoggerService = moleServices.loggerService) =
new MoleServices()(
preference = preference,
seeder = seeder,
......@@ -88,7 +91,8 @@ object MoleServices {
workspace = workspace,
fileService = fileService,
fileServiceCache = fileServiceCache,
outputRedirection = outputRedirection
outputRedirection = outputRedirection,
loggerService = loggerService
)
}
......@@ -115,7 +119,8 @@ class MoleServices(
val workspace: Workspace,
val fileService: FileService,
val fileServiceCache: FileServiceCache,
val outputRedirection: OutputRedirection
val outputRedirection: OutputRedirection,
val loggerService: LoggerService
) {
def newRandom = Lazy(seeder.newRNG)
implicit lazy val defaultRandom = newRandom
......
......@@ -116,6 +116,7 @@ object MoleTask {
import executionContext.threadProvider
import executionContext.workspace
import executionContext.outputRedirection
import executionContext.loggerService
val localEnvironment =
LocalEnvironment(1, executionContext.localEnvironment.deinterleave)
......
......@@ -35,6 +35,7 @@ import org.openmole.core.workflow.tools._
import org.openmole.core.workspace.{ NewFile, Workspace }
import org.openmole.tool.cache._
import org.openmole.tool.lock._
import org.openmole.tool.logger.LoggerService
import org.openmole.tool.outputredirection.OutputRedirection
import org.openmole.tool.random
import org.openmole.tool.random._
......@@ -62,10 +63,10 @@ case class TaskExecutionContext(
fileService: FileService,
implicit val workspace: Workspace,
implicit val outputRedirection: OutputRedirection,
implicit val loggerService: LoggerService,
cache: KeyValueCache,
lockRepository: LockRepository[LockKey],
moleExecution: Option[MoleExecution] = None
)
moleExecution: Option[MoleExecution] = None)
object Task {
......
......@@ -42,16 +42,17 @@ import org.openmole.plugin.environment.batch.refresh._
import org.openmole.tool.cache._
import org.openmole.tool.collection.RingBuffer
import org.openmole.tool.file._
import org.openmole.tool.logger.JavaLogger
import org.openmole.tool.logger.{JavaLogger, LoggerService}
import org.openmole.tool.random.{RandomProvider, Seeder, shuffled}
import squants.information.Information
import squants.information.InformationConversions._
import squants.time.TimeConversions._
import org.openmole.tool.lock._
import org.openmole.tool.outputredirection.OutputRedirection
import scala.collection.immutable.TreeSet
object BatchEnvironment extends JavaLogger {
object BatchEnvironment {
trait Transfer {
def id: Long
......@@ -146,7 +147,9 @@ object BatchEnvironment extends JavaLogger {
randomProvider: RandomProvider = services.randomProvider,
replicaCatalog: ReplicaCatalog = services.replicaCatalog,
eventDispatcher: EventDispatcher = services.eventDispatcher,
fileServiceCache: FileServiceCache = services.fileServiceCache) =
fileServiceCache: FileServiceCache = services.fileServiceCache,
outputRedirection: OutputRedirection = services.outputRedirection,
loggerService: LoggerService) =
new Services()(
threadProvider = threadProvider,
preference = preference,
......@@ -157,7 +160,9 @@ object BatchEnvironment extends JavaLogger {
randomProvider = randomProvider,
replicaCatalog = replicaCatalog,
eventDispatcher = eventDispatcher,
fileServiceCache = fileServiceCache)
fileServiceCache = fileServiceCache,
outputRedirection = outputRedirection,
loggerService = loggerService)
def set(services: Services)(ms: MoleServices) =
new Services() (
......@@ -170,7 +175,9 @@ object BatchEnvironment extends JavaLogger {
randomProvider = services.randomProvider,
replicaCatalog = services.replicaCatalog,
eventDispatcher = ms.eventDispatcher,
fileServiceCache = ms.fileServiceCache
fileServiceCache = ms.fileServiceCache,
outputRedirection = ms.outputRedirection,
loggerService = ms.loggerService
)
}
......@@ -186,7 +193,9 @@ object BatchEnvironment extends JavaLogger {
implicit val randomProvider: RandomProvider,
implicit val replicaCatalog: ReplicaCatalog,
implicit val eventDispatcher: EventDispatcher,
implicit val fileServiceCache: FileServiceCache
implicit val fileServiceCache: FileServiceCache,
implicit val outputRedirection: OutputRedirection,
implicit val loggerService: LoggerService
) { services =>
def set(ms: MoleServices) = Services.set(services)(ms)
......@@ -201,7 +210,9 @@ object BatchEnvironment extends JavaLogger {
randomProvider: RandomProvider = services.randomProvider,
replicaCatalog: ReplicaCatalog = services.replicaCatalog,
eventDispatcher: EventDispatcher = services.eventDispatcher,
fileServiceCache: FileServiceCache = services.fileServiceCache) =
fileServiceCache: FileServiceCache = services.fileServiceCache,
outputRedirection: OutputRedirection = services.outputRedirection,
loggerService: LoggerService = services.loggerService) =
Services.copy(services)(
threadProvider = threadProvider,
preference = preference,
......@@ -212,7 +223,9 @@ object BatchEnvironment extends JavaLogger {
randomProvider = randomProvider,
replicaCatalog = replicaCatalog,
eventDispatcher = eventDispatcher,
fileServiceCache = fileServiceCache)
fileServiceCache = fileServiceCache,
outputRedirection = outputRedirection,
loggerService = loggerService)
}
def jobFiles(job: BatchExecutionJob) =
......
......@@ -6,16 +6,16 @@ import gridscale.authentication.AuthenticationException
import org.openmole.core.exception.{ InternalProcessingError, UserBadDataError }
import org.openmole.core.workflow.execution.Environment
import org.openmole.plugin.environment.batch.environment.{ BatchEnvironment, BatchExecutionJob, FailedJobExecution, AccessControl }
import org.openmole.tool.logger.JavaLogger
import org.openmole.tool.logger._
object ErrorActor extends JavaLogger {
object ErrorActor {
def receive(msg: Error)(implicit services: BatchEnvironment.Services) = {
val Error(job, exception, output) = msg
processError(job, exception, output)
}
def processError(job: BatchExecutionJob, exception: Throwable, output: Option[(String, String)])(implicit services: BatchEnvironment.Services) = {
import Log._
import services._
def defaultMessage = """OpenMOLE job execution failed on remote environment"""
......@@ -47,6 +47,6 @@ object ErrorActor extends JavaLogger {
job.environment.error(er)
services.eventDispatcher.trigger(job.environment: Environment, er)
logger.log(FINE, "Error in job refresh", detailedException)
LoggerService.log(FINE, "Error in job refresh", Some(detailedException))
}
}
......@@ -33,7 +33,7 @@ import org.openmole.core.workflow.job._
import scala.util.{ Failure, Success }
object GetResultActor extends JavaLogger {
object GetResultActor {
case class JobRemoteExecutionException(message: String, cause: Throwable) extends InternalProcessingError(message, cause)
......
......@@ -19,18 +19,27 @@ package org.openmole.tool.logger
import java.util.logging.{ Logger JLogger, Level }
trait Levels {
def SEVERE = Level.SEVERE
def WARNING = Level.WARNING
def INFO = Level.INFO
def FINE = Level.FINE
def FINER = Level.FINER
def FINEST = Level.FINEST
def severe = SEVERE
def warning = Level.WARNING
def info = Level.INFO
def fine = Level.FINE
def finer = Level.FINER
def finest = Level.FINEST
}
trait JavaLogger { l
object Log {
object Log extends Levels {
@transient lazy val logger = JLogger.getLogger(l.getClass.getName)
def SEVERE = Level.SEVERE
def WARNING = Level.WARNING
def INFO = Level.INFO
def FINE = Level.FINE
def FINER = Level.FINER
def FINEST = Level.FINEST
def log(level: Level, message: String) =
if (logger.isLoggable(level)) logger.log(level, message)
}
......
......@@ -23,13 +23,16 @@ import org.openmole.tool.outputredirection._
import sourcecode._
object LoggerService {
def log(msg: String, level: Level = Level.INFO)(implicit loggerService: LoggerService, name: FullName, line: Line, outputRedirection: OutputRedirection) =
if (level.intValue() > loggerService.level.intValue()) {
def log(l: Level, msg: String, exception: Option[Throwable] = None)(implicit name: FullName, line: Line, loggerService: LoggerService, outputRedirection: OutputRedirection) =
if (l.intValue() > loggerService.level.intValue()) {
OutputRedirection.println(s"""${name.value}:${line.value} - $msg""")
exception match {
case Some(e)
outputRedirection.output.print(s"Caused by: ${e}")
e.printStackTrace(outputRedirection.output)
case None
}
}
}
case class LoggerService(level: Level = Level.WARNING)
package org.openmole.tool
/*
* Copyright (C) 2019 Romain Reuillon
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package object logger extends Levels
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment