Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #12255: Datasource compilation error with API provider trait #25

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import com.normation.rudder.api.HttpAction._
import com.normation.rudder.rest.EndpointSchema.syntax._

sealed trait DataSourceApi extends EndpointSchema with GeneralApi with SortIndex
object DataSourceApi {
object DataSourceApi extends ApiModuleProvider[DataSourceApi] {

/* Avoiding POST unreachable endpoint:
* (note: datasource must not have id "reload")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import com.normation.utils.Control
import com.normation.rudder.domain.nodes.Node
import com.normation.rudder.domain.nodes.CompareProperties
import net.liftweb.common.Failure
import com.normation.plugins.datasources.api.{ DataSourceApi => API }

class DataSourceApiImpl (
extractor : RestExtractorService
Expand All @@ -84,11 +85,13 @@ class DataSourceApiImpl (
, nodeInfoService : NodeInfoService
, nodeRepos : WoNodeRepository
, uuidGen : StringUuidGenerator
) extends LiftApiModuleProvider {
) extends LiftApiModuleProvider[API] {
api =>

val kind = "datasources"

def schemas = API

def response ( function : Box[JValue], req : Req, errorMessage : String, id : Option[String])(implicit action : String) : LiftResponse = {
RestUtils.response(extractor, kind, id)(function, req, errorMessage)
}
Expand All @@ -98,7 +101,6 @@ class DataSourceApiImpl (
RestUtils.actionResponse2(extractor, kind, uuidGen, id)(function, req, errorMessage)(action, actor)
}

import com.normation.plugins.datasources.api.{ DataSourceApi => API }
import extractor._
import com.normation.plugins.datasources.DataSourceExtractor.OptionnalJson._
import net.liftweb.json.JsonDSL._
Expand Down Expand Up @@ -155,10 +157,10 @@ class DataSourceApiImpl (
val schema = API.ClearValueOneDatasourceAllNodes
val restExtractor = extractor
def process(version: ApiVersion, path: ApiPath, datasourceId: String, req: Req, params: DefaultParams, authzToken: AuthzToken): LiftResponse = {

val modId = ModificationId(uuidGen.newUuid)
def cause(nodeId: NodeId) = UpdateCause(modId, authzToken.actor, Some(s"API request to clear '${datasourceId}' on node '${nodeId.value}'"), false)

val res: Box[Seq[NodeUpdateResult]] = for {
nodes <- nodeInfoService.getAllNodes()
updated <- Control.bestEffort(nodes.values.toSeq) { node =>
Expand Down Expand Up @@ -198,7 +200,7 @@ class DataSourceApiImpl (
val schema = API.ReloadAllDatasourcesAllNodes
val restExtractor = extractor
def process0(version: ApiVersion, path: ApiPath, req: Req, params: DefaultParams, authzToken: AuthzToken): LiftResponse = {
// reloadData All Nodes All Datasources
// reloadData All Nodes All Datasources
dataSourceRepo.onUserAskUpdateAllNodes(authzToken.actor)
toJsonResponse(None, JString("Data for all nodes, for all configured data sources are going to be updated"))(schema.name, params.prettify)
}
Expand Down Expand Up @@ -281,7 +283,7 @@ class DataSourceApiImpl (
}

/// utilities ///

def extractReqDataSource(req : Req, base : DataSource) : Box[DataSource] = {
req.json match {
case Full(json) =>
Expand Down