Skip to content

Commit

Permalink
#2265 Fix index creation and rebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Nov 29, 2021
1 parent 1a0c20f commit eeea9ad
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CortexSchemaDefinition @Inject() () extends Schema with UpdatableSchema {
.map(modelClass => rm.reflectModule(rm.classSymbol(modelClass).companion.companion.asModule).instance)
.collect {
case hasModel: HasModel =>
logger.info(s"Loading model ${hasModel.model.label}")
logger.debug(s"Loading model ${hasModel.model.label}")
hasModel.model
}
.toSeq
Expand Down
13 changes: 8 additions & 5 deletions thehive/app/org/thp/thehive/controllers/v1/AdminCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,12 @@ class AdminCtrl @Inject() (
def rebuild(name: String): Action[AnyContent] =
entrypoint("Rebuild index")
.authPermitted(Permissions.managePlatform) { _ =>
db
.removeIndex(name, IndexType.fulltext, Nil)
.flatMap(_ => schemas.toTry(db.addSchemaIndexes))
val removalResult =
if (name == "all") db.removeAllIndex()
else db.removeIndex(name, IndexType.fulltext, Nil)
schemas
.toTry(db.addSchemaIndexes)
.flatMap(_ => removalResult)
.map(_ => Results.NoContent)
}

Expand Down Expand Up @@ -188,8 +191,8 @@ class AdminCtrl @Inject() (
case (_: AddIndex, _) =>
filter.contains("AddIndex") || filter
.contains("index") || (filters.contains("all") && !filter.contains("!index") && !filter.contains("!AddIndex"))
case (RebuildIndexes, _) =>
filter.contains("RebuildIndexes") || filter
case (ReindexData, _) =>
filter.contains("ReindexData") || filter
.contains("index") || (filters.contains("all") && !filter.contains("!index") && !filter.contains("!RebuildIndexes"))
case (NoOperation, _) => false
case (_: RemoveIndex, _) =>
Expand Down
13 changes: 2 additions & 11 deletions thehive/app/org/thp/thehive/models/TheHiveSchemaDefinition.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,14 @@ class TheHiveSchemaDefinition @Inject() extends Schema with UpdatableSchema {
case error => logger.warn(s"Unable to remove lock on property $name: $error")
}
}
// TODO remove unused commented code ?
// def removeIndexLock(name: String): Try[Unit] =
// db.managementTransaction { mgmt =>
// Try(mgmt.setConsistency(mgmt.getGraphIndex(name), ConsistencyModifier.DEFAULT))
// .recover {
// case error => logger.warn(s"Unable to remove lock on index $name: $error")
// }
// }

// removeIndexLock("CaseNumber")
removePropertyLock("number")
// removeIndexLock("DataData")
removePropertyLock("data")
}
.noop // .addIndex("Tag", IndexType.unique, "namespace", "predicate", "value")
.noop // .addIndex("Audit", IndexType.basic, "requestId", "mainAction")
.rebuildIndexes
.noop // .reindexData
//=====[release 4.0.0]=====
.updateGraph("Remove cases with a Deleted status", "Case") { traversal =>
traversal.unsafeHas("status", "Deleted").remove()
Expand Down Expand Up @@ -517,7 +508,7 @@ class TheHiveSchemaDefinition @Inject() extends Schema with UpdatableSchema {
.filterNot(c => Modifier.isAbstract(c.getModifiers))
.map { modelClass =>
val hasModel = rm.reflectModule(rm.classSymbol(modelClass).companion.companion.asModule).instance.asInstanceOf[HasModel]
logger.info(s"Loading model ${hasModel.model.label}")
logger.debug(s"Loading model ${hasModel.model.label}")
hasModel.model
}
.toSeq
Expand Down
2 changes: 1 addition & 1 deletion thehive/app/org/thp/thehive/services/AuditSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ object AuditOps {
.coalesceIdent[Vertex](
_.share.in[OrganisationShare],
_.out[AlertOrganisation],
_.hasLabel("Organisation"),
_.unsafeHas("_label", "Organisation"),
_.out[CaseTemplateOrganisation],
_.in[OrganisationDashboard]
)
Expand Down

0 comments on commit eeea9ad

Please sign in to comment.