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 #9701: Store data sources in backend #1401

Conversation

VinceMacBuche
Copy link
Member

@VinceMacBuche VinceMacBuche commented Dec 5, 2016

https://www.rudder-project.org/redmine/issues/9701

This PR consists in two things:

Adding a backend for datasources, easy part

Having one json serialization that will work both for backend and rest api. Most complicated part was that it has not the same needs (backend data must be complete, rest API may be partial)
I used some Monad magic from Scalaz (but I think i need an implicit somewere to make it much more readable)

Two implementation on json serialization, one with monad Id (backend, fails if a data is missing), one with Option (allow to have partial data)

enjoy!

@VinceMacBuche
Copy link
Member Author

PR rebased

@VinceMacBuche VinceMacBuche force-pushed the ust_9701/store_data_sources_in_backend branch from 5a946bb to 600fbe1 Compare January 2, 2017 14:36
@VinceMacBuche
Copy link
Member Author

PR rebased

@VinceMacBuche VinceMacBuche force-pushed the ust_9701/store_data_sources_in_backend branch 2 times, most recently from be179a9 to 2bc99af Compare January 2, 2017 16:13
-- data source properties and status are valid json, until we can use postgres 9.2 keep text type (more details in configuration details)

, properties text
, status text
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe they must not be empty, else it can't be changed to json latter on. So, nullable, but with a constrain for empty string

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I didn't know about that constraint, You added the constraint on configuration i'll keep the same

@fanf
Copy link
Member

fanf commented Jan 3, 2017

Nice!

@fanf
Copy link
Member

fanf commented Jan 3, 2017

It will need the added getAllDataSources (without statuse). And I'm not a fan a using lift auto sterilization, but it's good enough for now. A little test to check update of status of only one node and it can be merge.

@VinceMacBuche
Copy link
Member Author

This PR is not finished, lift serialization/unserialization does not work ( does not serialize datetime, can't unserialize datasource type without typehints ...)

I suggest we use the same serialization than Rest API for now, Even if we know that they can change and drift in the future

@VinceMacBuche
Copy link
Member Author

(I forgot to rudder-dev wip ... :( )

@VinceMacBuche VinceMacBuche force-pushed the ust_9701/store_data_sources_in_backend branch 2 times, most recently from 8bd3b96 to 4e44466 Compare January 5, 2017 14:39
@VinceMacBuche
Copy link
Member Author

PR rebased

@VinceMacBuche VinceMacBuche force-pushed the ust_9701/store_data_sources_in_backend branch from 4e44466 to 617aec5 Compare January 5, 2017 16:41
@VinceMacBuche
Copy link
Member Author

Commit modified

@VinceMacBuche
Copy link
Member Author

@fanf @ncharles Enjoy that pull request !!

@VinceMacBuche
Copy link
Member Author

ps: it works, need more testing though

@VinceMacBuche
Copy link
Member Author

And maybe some names are poor choices

Copy link
Member

@fanf fanf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appart from the little remarks, I believe it is all good. The code removal is much appreciated.

@@ -275,5 +281,67 @@ class DataSourceRepoImpl(

}

class PGDataSourceRepository(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use DataSourceJdbcRepository to match other repo naming scheme?

sql.attempt.transact(xa).run match {
case \/-(x) => Full(source)
case -\/(ex) => Failure(s"could not update lastId from database, cause is: ${ex.getMessage}", Full(ex), Empty)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an auto transform to avoid that boilerplate, you could use:

sql.map(_ => source).attempt.transact(xa).run

The implicit def is in Doobie object (xorToBox)

_ <- Update[DataSource](insert).run(source).attempt.transact(xa).run
} yield {
source
})*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be removed

val query = sql"""delete from datasources where id = ${sourceId}"""
for {
source <- get(sourceId).flatMap { _ match {
case None => Failure("no source")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, here, trying to delete a source which doesn't exists will lead to an error. I think it should not be the case so that we have an idempotent operation for deletion (ie: deleting a non existing datasource is a success with invariant: "after deletion, the datasource does not exist"

Composite[(DataSourceId,String)].xmap(
tuple => extractDataSource(tuple._1,parse(tuple._2)) match {
case Full(s) => s
case eb => throw new RuntimeException("oops")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change the message to log what is the cause of the error ("error when deserialising blabla") and perhaps even the faulty json (not sure if it is already logged in extractDataSource)

@VinceMacBuche VinceMacBuche force-pushed the ust_9701/store_data_sources_in_backend branch from db2b577 to bc94802 Compare January 9, 2017 22:28
@VinceMacBuche
Copy link
Member Author

Commit modified

@VinceMacBuche
Copy link
Member Author

PR rebased

@VinceMacBuche VinceMacBuche force-pushed the ust_9701/store_data_sources_in_backend branch from bc94802 to 4385858 Compare January 9, 2017 22:35
@Normation-Quality-Assistant
Copy link
Contributor

OK, merging this PR

@Normation-Quality-Assistant Normation-Quality-Assistant merged commit 4385858 into Normation:master Jan 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants