Skip to content

Commit

Permalink
Fixes #19229: Deadlock at start when loading new licence
Browse files Browse the repository at this point in the history
  • Loading branch information
fanf committed Jun 7, 2021
1 parent bf752a9 commit f62ec61
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 530 deletions.
343 changes: 0 additions & 343 deletions branding/src/main/resources/branding/toserve/media.css

This file was deleted.

139 changes: 0 additions & 139 deletions branding/src/main/resources/branding/toserve/toasty.css

This file was deleted.

24 changes: 12 additions & 12 deletions branding/src/main/scala/bootstrap/rudder/plugin/BrandingConf.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ package bootstrap.rudder.plugin

import bootstrap.liftweb.RudderConfig
import com.normation.plugins.RudderPluginModule
import com.normation.plugins.branding.{BrandingConfService, BrandingPluginDef}
import com.normation.plugins.branding.CheckRudderPluginEnableImpl
import com.normation.plugins.branding.snippet.{CommonBranding, LoginBranding}
import com.normation.rudder.rest.{BrandingApi, BrandingApiService}
import com.normation.plugins.branding.snippet.CommonBranding
import com.normation.plugins.branding.snippet.LoginBranding
import com.normation.plugins.branding.BrandingConfService
import com.normation.plugins.branding.BrandingPluginDef
import com.normation.plugins.branding.api.BrandingApi
import com.normation.plugins.branding.api.BrandingApiService


/*
* Actual configuration of the data sources logic
Expand All @@ -51,17 +55,13 @@ object BrandingPluginConf extends RudderPluginModule {

// by build convention, we have only one of that on the classpath
lazy val pluginStatusService = new CheckRudderPluginEnableImpl(RudderConfig.nodeInfoService)

import bootstrap.liftweb.{ RudderConfig => Cfg }

val brandingConfService : BrandingConfService = new BrandingConfService

val brandingApiService : BrandingApiService = new BrandingApiService(brandingConfService)
val brandingApi : BrandingApi = new BrandingApi(brandingApiService, Cfg.restExtractorService, Cfg.stringUuidGenerator)

Cfg.rudderApi.addModules(brandingApi.getLiftEndpoints())
lazy val pluginDef = new BrandingPluginDef(BrandingPluginConf.pluginStatusService)

val brandingConfService : BrandingConfService = new BrandingConfService(BrandingConfService.defaultConfigFilePath)
val brandingApiService : BrandingApiService = new BrandingApiService(brandingConfService)
val brandingApi : BrandingApi = new BrandingApi(brandingApiService, RudderConfig.restExtractorService, RudderConfig.stringUuidGenerator)

RudderConfig.rudderApi.addModules(brandingApi.getLiftEndpoints())
RudderConfig.snippetExtensionRegister.register(new CommonBranding(pluginStatusService))
RudderConfig.snippetExtensionRegister.register(new LoginBranding(pluginStatusService, pluginDef.version))
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ import better.files._
import net.liftweb.json.parseOpt
import com.normation.box._

class BrandingConfService extends Loggable {
object BrandingConfService {

private[this] val initialValue =
def initialValue =
BrandingConf(
true
, JsonColor(204,0,0,1)
Expand All @@ -73,11 +73,13 @@ class BrandingConfService extends Loggable {
, "Welcome, please sign in:"
)

val defaultConfigFilePath = "/var/rudder/plugins/branding/configuration.json"

val configFilePath = "/var/rudder/plugins/branding/configuration.json"
}

class BrandingConfService(configFilePath: String) {

private[this] lazy val cache : Ref[Either[RudderError, BrandingConf]] = (for {
private[this] val cache : Ref[Either[RudderError, BrandingConf]] = (for {
v <- Ref.make[Either[RudderError, BrandingConf]](Left(Unexpected("Cache is not yet initialized")))
c <- reloadCacheInternal(true, v).either
} yield v).runNow
Expand All @@ -99,7 +101,7 @@ class BrandingConfService extends Loggable {
}
} else {
if (init) {
updateConf(initialValue)
updateConf(BrandingConfService.initialValue)
} else {
// Should we update cache to that value ??
Inconsistency("Could not read plugin configuration from cache").fail
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,56 @@
package com.normation.rudder.rest
/*
*************************************************************************************
* Copyright 2018 Normation SAS
*************************************************************************************
*
* This file is part of Rudder.
*
* Rudder is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In accordance with the terms of section 7 (7. Additional Terms.) of
* the GNU General Public License version 3, the copyright holders add
* the following Additional permissions:
* Notwithstanding to the terms of section 5 (5. Conveying Modified Source
* Versions) and 6 (6. Conveying Non-Source Forms.) of the GNU General
* Public License version 3, when you create a Related Module, this
* Related Module is not considered as a part of the work and may be
* distributed under the license agreement of your choice.
* A "Related Module" means a set of sources files including their
* documentation that, without modification of the Source Code, enables
* supplementary functions or services in addition to those offered by
* the Software.
*
* Rudder 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Rudder. If not, see <http://www.gnu.org/licenses/>.
*
*************************************************************************************
*/

package com.normation.plugins.branding.api

import com.normation.box._
import com.normation.eventlog.EventActor
import com.normation.plugins.branding.{BrandingConf, BrandingConfService}
import com.normation.rudder.api.HttpAction._
import com.normation.rudder.rest.lift.{DefaultParams, LiftApiModule, LiftApiModule0, LiftApiModuleProvider}
import com.normation.plugins.branding.BrandingConf
import com.normation.plugins.branding.BrandingConfService
import com.normation.rudder.rest._
import com.normation.rudder.rest.lift.DefaultParams
import com.normation.rudder.rest.lift.LiftApiModule
import com.normation.rudder.rest.lift.LiftApiModule0
import com.normation.rudder.rest.lift.LiftApiModuleProvider
import com.normation.utils.StringUuidGenerator
import net.liftweb.common.Box
import net.liftweb.http.LiftResponse
import net.liftweb.http.Req
import net.liftweb.json.JsonAST.JValue
import net.liftweb.http.{LiftResponse, Req}
import sourcecode.Line
import com.normation.box._

sealed trait BrandingApiSchema extends EndpointSchema with GeneralApi with SortIndex
object BrandingApiEndpoints extends ApiModuleProvider[BrandingApiSchema] {
import EndpointSchema.syntax._
final case object GetBrandingConf extends BrandingApiSchema with ZeroParam with StartsAtVersion10 with SortIndex {
val z = implicitly[Line].value
val description = "Get branding plugin configuration"
val (action, path) = GET / "branding"
}

final case object UpdateBrandingConf extends BrandingApiSchema with ZeroParam with StartsAtVersion10 with SortIndex {
val z = implicitly[Line].value
val description = "Update branding plugin configuration"
val (action, path) = POST / "branding"
}

final case object ReloadBrandingConf extends BrandingApiSchema with ZeroParam with StartsAtVersion10 with SortIndex {
val z = implicitly[Line].value
val description = "Reload branding plugin configuration from config file"
val (action, path) = POST / "branding" / "reload"
}

def endpoints = ca.mrvisser.sealerate.values[BrandingApiSchema].toList.sortBy( _.z )
}


class BrandingApi (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
*************************************************************************************
* Copyright 2018 Normation SAS
*************************************************************************************
*
* This file is part of Rudder.
*
* Rudder is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In accordance with the terms of section 7 (7. Additional Terms.) of
* the GNU General Public License version 3, the copyright holders add
* the following Additional permissions:
* Notwithstanding to the terms of section 5 (5. Conveying Modified Source
* Versions) and 6 (6. Conveying Non-Source Forms.) of the GNU General
* Public License version 3, when you create a Related Module, this
* Related Module is not considered as a part of the work and may be
* distributed under the license agreement of your choice.
* A "Related Module" means a set of sources files including their
* documentation that, without modification of the Source Code, enables
* supplementary functions or services in addition to those offered by
* the Software.
*
* Rudder 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Rudder. If not, see <http://www.gnu.org/licenses/>.
*
*************************************************************************************
*/

package com.normation.rudder.rest

import com.normation.rudder.api.HttpAction._
import sourcecode.Line

/*
* these files need to be in that package because they need access to the
* package-protected `z` methods.
*/

sealed trait BrandingApiSchema extends EndpointSchema with GeneralApi with SortIndex

object BrandingApiEndpoints extends ApiModuleProvider[BrandingApiSchema] {
import EndpointSchema.syntax._
final case object GetBrandingConf extends BrandingApiSchema with ZeroParam with StartsAtVersion10 with SortIndex {
val z = implicitly[Line].value
val description = "Get branding plugin configuration"
val (action, path) = GET / "branding"
}

final case object UpdateBrandingConf extends BrandingApiSchema with ZeroParam with StartsAtVersion10 with SortIndex {
val z = implicitly[Line].value
val description = "Update branding plugin configuration"
val (action, path) = POST / "branding"
}

final case object ReloadBrandingConf extends BrandingApiSchema with ZeroParam with StartsAtVersion10 with SortIndex {
val z = implicitly[Line].value
val description = "Reload branding plugin configuration from config file"
val (action, path) = POST / "branding" / "reload"
}

def endpoints = ca.mrvisser.sealerate.values[BrandingApiSchema].toList.sortBy( _.z )
}

0 comments on commit f62ec61

Please sign in to comment.