Skip to content

Commit

Permalink
Merge branch 'bug_13517/policy_generation_fails_definitively_when_pos…
Browse files Browse the repository at this point in the history
…tgresql_is_shut_down_during_policy_generation_pr' into branches/rudder/4.1
  • Loading branch information
fanf committed Sep 28, 2018
2 parents 2a48085 + 76eb3db commit 47b15b1
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ trait BatchElementMigration[T <: MigrableEntity] extends XmlFileFormatMigration
saved <- save(migrated)
} yield {
saved
}).attempt.transact(doobie.xa).unsafePerformSync
}).transact(doobie.xa).attempt.unsafePerformSync

res match {
case \/-(k) if(k.size < 1) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class MigrationEventLogRepository(val db: Doobie) {
def getLastDetectionLine: \/[Throwable, Option[DB.MigrationEventLog[Long]]] = {
val sql = sql"""select id, detectiontime, detectedfileformat, migrationstarttime, migrationendtime, migrationfileformat, description
from migrationeventlog order by id desc limit 1""".query[DB.MigrationEventLog[Long]].option
sql.attempt.transact(xa).unsafePerformSync
sql.transact(xa).attempt.unsafePerformSync
}

/**
Expand All @@ -70,7 +70,7 @@ class MigrationEventLogRepository(val db: Doobie) {
*/
def setMigrationStartTime(id: Long, startTime: DateTime) : \/[Throwable,Int] = {
val sql = sql"""update migrationeventlog set migrationstarttime = ${startTime} where id=${id}""".update
sql.run.attempt.transact(xa).unsafePerformSync
sql.run.transact(xa).attempt.unsafePerformSync
}

/**
Expand All @@ -79,7 +79,7 @@ class MigrationEventLogRepository(val db: Doobie) {
*/
def setMigrationFileFormat(id: Long, fileFormat: Long, endTime: DateTime) : \/[Throwable, Int] = {
val sql = sql"""update migrationeventlog set migrationfileformat=${fileFormat}, migrationendtime=${endTime} where id=${id}""".update
sql.run.attempt.transact(xa).unsafePerformSync
sql.run.transact(xa).attempt.unsafePerformSync
}

/**
Expand All @@ -89,7 +89,7 @@ class MigrationEventLogRepository(val db: Doobie) {
def createNewStatusLine(fileFormat: Long, description: Option[String] = None) : \/[Throwable, DB.MigrationEventLog[Long]] = {
val now = DateTime.now
val sql = sql"""insert into migrationeventlog (detectiontime, detectedfileformat, description) values (${now}, ${fileFormat}, ${description})""".update
sql.withUniqueGeneratedKeys[Long]("id").attempt.transact(xa).unsafePerformSync.map(id =>
sql.withUniqueGeneratedKeys[Long]("id").transact(xa).attempt.unsafePerformSync.map(id =>
DB.MigrationEventLog[Long](id, now, fileFormat, None, None, None, description)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class LastProcessedReportRepositoryImpl (
select lastid, date from statusupdate where key=${PROP_EXECUTION_STATUS}
""".query[(Long, DateTime)].option

sql.attempt.transact(xa).unsafePerformSync match {
sql.transact(xa).attempt.unsafePerformSync match {
case \/-(x) => Full(x)
case -\/(ex) => Failure(s"Error when retrieving '${PROP_EXECUTION_STATUS}' from db: ${ex.getMessage}", Full(ex), Empty)
}
Expand Down Expand Up @@ -108,7 +108,7 @@ class LastProcessedReportRepositoryImpl (
entry
}

action.attempt.transact(xa).unsafePerformSync match {
action.transact(xa).attempt.unsafePerformSync match {
case \/-(x) => Full(DB.StatusUpdate(PROP_EXECUTION_STATUS, newId, reportsDate))
case -\/(ex) => Failure(s"Error when retrieving '${PROP_EXECUTION_STATUS}' from db: ${ex.getMessage}", Full(ex), Empty)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ case class RoReportsExecutionRepositoryImpl (
(run.agentRunId.nodeId, AgentRunWithNodeConfig(run.agentRunId, config, run.isCompleted, run.insertionId))
}).toMap
nodeIds.map(id => (id, runsMap.get(id))).toMap
}).attempt.transact(xa).unsafePerformSync
}).transact(xa).attempt.unsafePerformSync
}
}
}
Expand Down Expand Up @@ -205,7 +205,7 @@ case class WoReportsExecutionRepositoryImpl (
result
}

action.attempt.transact(xa)
action.transact(xa).attempt
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class ComplianceJdbcRepository(doobie: Doobie) extends ComplianceRepository {
} yield {
val saved = runCompliances.map(_.nodeId)
reports.filter(r => saved.contains(r.nodeId))
}).attempt.transact(xa).unsafePerformSync
}).transact(xa).attempt.unsafePerformSync


res match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class EventLogJdbcRepository(
values(${eventLog.creationDate}, ${modId.value}, ${eventLog.principal.name}, ${eventLog.eventType.serialize},
${eventLog.severity}, ${elt}, ${eventLog.eventDetails.reason}, ${eventLog.cause}
)
""".update.withUniqueGeneratedKeys[Int]("id").attempt.transact(xa).unsafePerformSync
""".update.withUniqueGeneratedKeys[Int]("id").transact(xa).attempt.unsafePerformSync

for {
id <- boxId
Expand Down Expand Up @@ -151,7 +151,7 @@ class EventLogJdbcRepository(
entries <- HC.process[(String, EventLogDetails)](q, param, 512).vector
} yield {
entries.map(toEventLog)
}).attempt.transact(xa).unsafePerformSync
}).transact(xa).attempt.unsafePerformSync
}

def getLastEventByChangeRequest(
Expand Down Expand Up @@ -196,7 +196,7 @@ class EventLogJdbcRepository(
entries.map { case (crid, tpe, details) =>
(ChangeRequestId(crid.substring(1, crid.length()-1).toInt), toEventLog((tpe, details)) )
}.toMap
}).attempt.transact(xa).unsafePerformSync
}).transact(xa).attempt.unsafePerformSync
}

def getEventLogByCriteria(criteria : Option[String], optLimit:Option[Int] = None, orderBy:Option[String]) : Box[Vector[EventLog]] = {
Expand All @@ -215,7 +215,7 @@ class EventLogJdbcRepository(
entries <- query[(String, EventLogDetails)](q).vector
} yield {
entries.map(toEventLog)
}).attempt.transact(xa).unsafePerformSync ?~! s"could not find event log with request ${q}"
}).transact(xa).attempt.unsafePerformSync ?~! s"could not find event log with request ${q}"
}

def getEventLogWithChangeRequest(id:Int) : Box[Option[(EventLog,Option[ChangeRequestId])]] = {
Expand All @@ -232,7 +232,7 @@ class EventLogJdbcRepository(
optEntry.map { case (tpe, details, crid) =>
(toEventLog((tpe, details)), crid.flatMap(i => if(i > 0) Some(ChangeRequestId(i)) else None))
}
}).attempt.transact(xa).unsafePerformSync ?~! s"could not find event log with request ${select}"
}).transact(xa).attempt.unsafePerformSync ?~! s"could not find event log with request ${select}"
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class FindExpectedReportsJdbcRepository(
case \/-(x) => Some((NodeAndConfigId(x.nodeId, x.nodeConfigId), x))
}).toMap
nodeConfigIds.map(id => (id, configsMap.get(id))).toMap
}).attempt.transact(xa).unsafePerformSync
}).transact(xa).attempt.unsafePerformSync
}
}

Expand Down Expand Up @@ -162,7 +162,7 @@ class FindExpectedReportsJdbcRepository(
case \/-(x) => Some((x.nodeId, x))
}).toMap
nodeIds.map(id => (id, configsMap.get(id))).toMap
}).attempt.transact(xa).unsafePerformSync
}).transact(xa).attempt.unsafePerformSync
}
}

Expand All @@ -171,7 +171,7 @@ class FindExpectedReportsJdbcRepository(
sql"""
select distinct nodeid from nodeconfigurations
where enddate is null and configuration like ${"%"+ruleId.value+"%"}
""".query[NodeId].to[Set].attempt.transact(xa).unsafePerformSync
""".query[NodeId].to[Set].transact(xa).attempt.unsafePerformSync
}


Expand All @@ -187,7 +187,7 @@ class FindExpectedReportsJdbcRepository(
} yield {
val res = entries.map{ case(nodeId, config) => (nodeId, NodeConfigIdSerializer.unserialize(config)) }.toMap
nodeIds.map(n => (n, res.get(n))).toMap
}).attempt.transact(xa).unsafePerformSync
}).transact(xa).attempt.unsafePerformSync
}
}
}
Expand All @@ -208,7 +208,7 @@ class UpdateExpectedReportsJdbcRepository(
override def closeNodeConfigurations(nodeId: NodeId): Box[NodeId] = {
sql"""
update nodeconfigurations set enddate = ${DateTime.now} where nodeid = ${nodeId} and enddate is null
""".update.run.attempt.transact(xa).unsafePerformSync.map( _ => nodeId )
""".update.run.transact(xa).attempt.unsafePerformSync.map( _ => nodeId )
}


Expand All @@ -228,15 +228,15 @@ class UpdateExpectedReportsJdbcRepository(
from nodeconfigurations
inner join tempnodeid on tempnodeid.id = nodeconfigurations.nodeid
where enddate is NULL"""
).query[A].list.attempt.transact(xa).unsafePerformSync
).query[A].list.transact(xa).attempt.unsafePerformSync

type B = (NodeId, Vector[NodeConfigIdInfo])
val getInfos: \/[Throwable, List[B]] = (
withFrag ++ fr"""
select node_id, config_ids from nodes_info
inner join tempnodeid on tempnodeid.id = nodes_info.node_id
"""
).query[B].list.attempt.transact(xa).unsafePerformSync
).query[B].list.transact(xa).attempt.unsafePerformSync

// common part: find old configs and node config info for all config to update
val time_0 = System.currentTimeMillis
Expand Down Expand Up @@ -331,7 +331,7 @@ class UpdateExpectedReportsJdbcRepository(
""").updateMany(toAdd)
} yield {
configs
}).attempt.transact(xa).unsafePerformSync
}).transact(xa).attempt.unsafePerformSync
}


Expand All @@ -356,7 +356,7 @@ class UpdateExpectedReportsJdbcRepository(
|]]""".stripMargin)

(for {
i <- (copy :: delete :: Nil).traverse(q => Update0(q, None).run).attempt.transact(xa).unsafePerformSync
i <- (copy :: delete :: Nil).traverse(q => Update0(q, None).run).transact(xa).attempt.unsafePerformSync
} yield {
i
}) match {
Expand Down Expand Up @@ -384,7 +384,7 @@ class UpdateExpectedReportsJdbcRepository(
|]]""".stripMargin)

(for {
i <- (d1 :: d2 :: Nil).traverse(q => Update0(q, None).run).attempt.transact(xa).unsafePerformSync
i <- (d1 :: d2 :: Nil).traverse(q => Update0(q, None).run).transact(xa).attempt.unsafePerformSync
} yield {
i
}) match {
Expand Down Expand Up @@ -420,7 +420,7 @@ class UpdateExpectedReportsJdbcRepository(
|]]""".stripMargin)

(for {
i <- (copy :: delete :: Nil).traverse(q => Update0(q, None).run).attempt.transact(xa).unsafePerformSync
i <- (copy :: delete :: Nil).traverse(q => Update0(q, None).run).transact(xa).attempt.unsafePerformSync
} yield {
i
}) match {
Expand Down Expand Up @@ -448,7 +448,7 @@ class UpdateExpectedReportsJdbcRepository(
|]]""".stripMargin)

(for {
i <- (d1 :: d2 :: Nil).traverse(q => Update0(q, None).run).attempt.transact(xa).unsafePerformSync
i <- (d1 :: d2 :: Nil).traverse(q => Update0(q, None).run).transact(xa).attempt.unsafePerformSync
} yield {
i
}) match {
Expand All @@ -473,7 +473,7 @@ class UpdateExpectedReportsJdbcRepository(
|]]""".stripMargin)

(for {
i <- Update0(d1, None).run.attempt.transact(xa).unsafePerformSync
i <- Update0(d1, None).run.transact(xa).attempt.unsafePerformSync
} yield {
i
}) match {
Expand Down Expand Up @@ -501,7 +501,7 @@ class UpdateExpectedReportsJdbcRepository(
update <- updateNodeConfigIdInfo(mapOfBeforeAfter.map{ case (nodeId, (old, current)) => (nodeId, current)})
} yield {
update.size
}).attempt.transact(xa).unsafePerformSync
}).transact(xa).attempt.unsafePerformSync
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class GitModificationRepositoryImpl(
""".update


sql.run.attempt.transact(xa).unsafePerformSync match {
sql.run.transact(xa).attempt.unsafePerformSync match {
case \/-(x) => Full(DB.GitCommitJoin(commit, modId))
case -\/(ex) => Failure(s"Error when trying to add a Git Commit in DB: ${ex.getMessage}", Full(ex), Empty)
}
Expand All @@ -36,7 +36,7 @@ class GitModificationRepositoryImpl(
select gitcommit from gitcommit where modificationid=${modificationId.value}
""".query[String].option

sql.attempt.transact(xa).unsafePerformSync match {
sql.transact(xa).attempt.unsafePerformSync match {
case \/-(x) => Full(x.map(id => GitCommitId(id)))
case -\/(ex) => Failure(s"Error when trying to get Git Commit for modification ID '${modificationId.value}': ${ex.getMessage}", Full(ex), Empty)
}
Expand Down
Loading

0 comments on commit 47b15b1

Please sign in to comment.