Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions api/src/main/kotlin/edu/wgu/osmt/RoutePaths.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,39 @@ object RoutePaths {
const val SEARCH_SIMILARITIES = "$SEARCH_SKILLS/similarities"
const val SEARCH_COLLECTIONS = "$SEARCH_PATH/collections"

const val SKILLS_PATH = "/api/skills"
const val SKILLS_PATH = "$API/skills"
const val SKILLS_LIST = SKILLS_PATH
const val SKILLS_CREATE = SKILLS_PATH
const val SKILL_PUBLISH = "$SKILLS_PATH/publish"
const val SKILL_DETAIL = "$SKILLS_PATH/{uuid}"
const val SKILL_UPDATE = "$SKILL_DETAIL/update"
const val SKILL_AUDIT_LOG = "${SKILL_DETAIL}/log"
const val SKILL_AUDIT_LOG = "$SKILL_DETAIL/log"


const val COLLECTIONS_PATH = "/api/collections"
const val COLLECTIONS_PATH = "$API/collections"
const val COLLECTIONS_LIST = COLLECTIONS_PATH
const val COLLECTION_CREATE = COLLECTIONS_PATH
const val COLLECTION_PUBLISH = "$COLLECTIONS_PATH/publish"
const val COLLECTION_DETAIL = "${COLLECTIONS_PATH}/{uuid}"
const val COLLECTION_UPDATE = "${COLLECTION_DETAIL}/update"
const val COLLECTION_SKILLS_UPDATE = "${COLLECTION_DETAIL}/updateSkills"
const val COLLECTION_SKILLS = "${COLLECTION_DETAIL}/skills"
const val COLLECTION_AUDIT_LOG = "${COLLECTION_DETAIL}/log"
const val COLLECTION_CSV = "${COLLECTION_DETAIL}/csv"
const val COLLECTION_DETAIL = "$COLLECTIONS_PATH/{uuid}"
const val COLLECTION_UPDATE = "$COLLECTION_DETAIL/update"
const val COLLECTION_SKILLS_UPDATE = "$COLLECTION_DETAIL/updateSkills"
const val COLLECTION_SKILLS = "$COLLECTION_DETAIL/skills"
const val COLLECTION_AUDIT_LOG = "$COLLECTION_DETAIL/log"
const val COLLECTION_CSV = "$COLLECTION_DETAIL/csv"


const val TASKS_PATH = "/api/results"
const val TASK_DETAIL_TEXT = "${TASKS_PATH}/text/{uuid}"
const val TASK_DETAIL_BATCH = "${TASKS_PATH}/batch/{uuid}"
const val TASK_DETAIL_SKILLS = "${TASKS_PATH}/skills/{uuid}"
const val TASKS_PATH = "$API/results"
const val TASK_DETAIL_TEXT = "$TASKS_PATH/text/{uuid}"
const val TASK_DETAIL_BATCH = "$TASKS_PATH/batch/{uuid}"
const val TASK_DETAIL_SKILLS = "$TASKS_PATH/skills/{uuid}"

const val SEARCH_JOBCODES_PATH = "$SEARCH_PATH/jobcodes"

const val SEARCH_KEYWORDS_PATH = "$SEARCH_PATH/keywords"

const val ES_ADMIN = "$API/es-admin"
const val ES_ADMIN_DELETE_INDICES = "$ES_ADMIN/delete-indices"
const val ES_ADMIN_REINDEX = "$ES_ADMIN/reindex"

object QueryParams {
const val FROM = "from"
const val SIZE = "size"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package edu.wgu.osmt.collection

import edu.wgu.osmt.PaginationDefaults
import edu.wgu.osmt.api.model.ApiSearch
import edu.wgu.osmt.config.INDEX_COLLECTION_DOC
import edu.wgu.osmt.db.PublishStatus
import edu.wgu.osmt.elasticsearch.FindsAllByPublishStatus
import edu.wgu.osmt.richskill.RichSkillDoc
Expand All @@ -16,6 +17,7 @@ import org.springframework.data.domain.Pageable
import org.springframework.data.domain.Sort
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate
import org.springframework.data.elasticsearch.core.SearchHits
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories
Expand All @@ -34,6 +36,10 @@ interface CustomCollectionQueries : FindsAllByPublishStatus<CollectionDoc> {
Sort.by("name.keyword").descending()
)
): SearchHits<CollectionDoc>

fun deleteIndex() {
elasticSearchTemplate.indexOps(IndexCoordinates.of(INDEX_COLLECTION_DOC)).delete()
}
}

class CustomCollectionQueriesImpl @Autowired constructor(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package edu.wgu.osmt.elasticsearch

import edu.wgu.osmt.RoutePaths.ES_ADMIN_DELETE_INDICES
import edu.wgu.osmt.RoutePaths.ES_ADMIN_REINDEX
import edu.wgu.osmt.config.AppConfig
import edu.wgu.osmt.security.OAuthHelper
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.stereotype.Controller
import org.springframework.transaction.annotation.Transactional
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.server.ResponseStatusException
import java.util.concurrent.ForkJoinPool

@Controller
@Transactional
class ElasticSearchAdminController @Autowired constructor(
val appConfig: AppConfig,
val oAuthHelper: OAuthHelper,
val esReindexer: ElasticSearchReindexer
) {

@RequestMapping(ES_ADMIN_DELETE_INDICES)
@PostMapping
fun deleteElasticSearchIndices(): ResponseEntity<String> {

if (!oAuthHelper.hasRole(appConfig.roleAdmin)) {
throw ResponseStatusException(HttpStatus.UNAUTHORIZED)
}

ForkJoinPool.commonPool().submit(esReindexer::deleteAllIndices)
return ResponseEntity(
"Deleting ElasticSearch indices in the background. Please refer to the logs.",
HttpStatus.ACCEPTED
)
}

@RequestMapping(ES_ADMIN_REINDEX)
@PostMapping
fun reindexElasticSearch(): ResponseEntity<String> {

if (!oAuthHelper.hasRole(appConfig.roleAdmin)) {
throw ResponseStatusException(HttpStatus.UNAUTHORIZED)
}

ForkJoinPool.commonPool().submit(esReindexer::reindexAll)
return ResponseEntity(
"Reindexing ElasticSearch in the background. Please refer to the logs.",
HttpStatus.ACCEPTED
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,21 @@ class ElasticSearchReindexer {
@Value("\${edu.wgu.osmt.elasticsearch.Reindex.batch_size:1000}")
lateinit var limit: Integer

fun deleteAllIndices() {
richSkillEsRepo.deleteIndex()
collectionEsRepo.deleteIndex()
keywordEsRepo.deleteIndex()
jobCodeEsRepo.deleteIndex()
}

fun reindexAll() {
reimportSkills()
reimportCollections()
reimportKeywords()
reimportJobCodes()
reindexSkills()
reindexCollections()
reindexKeywords()
reindexJobCodes()
}

private fun reimportSkills() {
private fun reindexSkills() {
var page = 0
var exit = false
val trace = ProcessLogger("skills", logger)
Expand All @@ -82,7 +89,7 @@ class ElasticSearchReindexer {
}
}

private fun reimportCollections() {
private fun reindexCollections() {
var page = 0
var exit = false
var trace = ProcessLogger("collections", logger)
Expand All @@ -106,7 +113,7 @@ class ElasticSearchReindexer {
}
}

private fun reimportKeywords() {
private fun reindexKeywords() {
var page = 0
var exit = false
var trace = ProcessLogger("keywords", logger)
Expand All @@ -130,7 +137,7 @@ class ElasticSearchReindexer {
}
}

private fun reimportJobCodes() {
private fun reindexJobCodes() {
var page = 0
var exit = false
var trace = ProcessLogger("jobCodes", logger)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class ReindexCommand: CommandLineRunner {
private lateinit var applicationContext: ApplicationContext

override fun run(vararg args: String?) {
elasticSearchReindexer.deleteAllIndices()
elasticSearchReindexer.reindexAll()
(applicationContext as ConfigurableApplicationContext).close()
}

}

fun main(args: Array<String>) {
Expand Down
6 changes: 6 additions & 0 deletions api/src/main/kotlin/edu/wgu/osmt/jobcode/JobCodeEsRepo.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.wgu.osmt.jobcode

import edu.wgu.osmt.config.INDEX_JOBCODE_DOC
import edu.wgu.osmt.elasticsearch.OffsetPageable
import org.elasticsearch.index.query.BoolQueryBuilder
import org.elasticsearch.index.query.Operator
Expand All @@ -9,13 +10,18 @@ import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Configuration
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate
import org.springframework.data.elasticsearch.core.SearchHits
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories

interface CustomJobCodeRepository {
val elasticSearchTemplate: ElasticsearchRestTemplate
fun typeAheadSearch(query: String): SearchHits<JobCode>

fun deleteIndex() {
elasticSearchTemplate.indexOps(IndexCoordinates.of(INDEX_JOBCODE_DOC)).delete()
}
}

class CustomJobCodeRepositoryImpl @Autowired constructor(override val elasticSearchTemplate: ElasticsearchRestTemplate) :
Expand Down
6 changes: 6 additions & 0 deletions api/src/main/kotlin/edu/wgu/osmt/keyword/KeywordEsRepo.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
package edu.wgu.osmt.keyword

import edu.wgu.osmt.config.INDEX_KEYWORD_DOC
import edu.wgu.osmt.elasticsearch.OffsetPageable
import org.elasticsearch.index.query.QueryBuilders
import org.elasticsearch.search.sort.SortBuilders
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Configuration
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate
import org.springframework.data.elasticsearch.core.SearchHits
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories

interface CustomKeywordRepository {
val elasticSearchTemplate: ElasticsearchRestTemplate
fun typeAheadSearch(query: String, type: KeywordTypeEnum): SearchHits<Keyword>

fun deleteIndex() {
elasticSearchTemplate.indexOps(IndexCoordinates.of(INDEX_KEYWORD_DOC)).delete()
}
}

class CustomKeywordRepositoryImpl @Autowired constructor(override val elasticSearchTemplate: ElasticsearchRestTemplate) :
Expand Down
7 changes: 7 additions & 0 deletions api/src/main/kotlin/edu/wgu/osmt/richskill/RichSkillEsRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import edu.wgu.osmt.PaginationDefaults
import edu.wgu.osmt.api.model.ApiAdvancedSearch
import edu.wgu.osmt.api.model.ApiSearch
import edu.wgu.osmt.api.model.ApiSimilaritySearch
import edu.wgu.osmt.config.INDEX_RICHSKILL_DOC
import edu.wgu.osmt.config.QUOTED_SEARCH_REGEX_PATTERN
import edu.wgu.osmt.db.PublishStatus
import edu.wgu.osmt.elasticsearch.FindsAllByPublishStatus
Expand All @@ -21,6 +22,7 @@ import org.springframework.data.domain.Pageable
import org.springframework.data.domain.Sort
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate
import org.springframework.data.elasticsearch.core.SearchHits
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories
Expand All @@ -46,6 +48,11 @@ interface CustomRichSkillQueries : FindsAllByPublishStatus<RichSkillDoc> {
fun findSimilar(apiSimilaritySearch: ApiSimilaritySearch): SearchHits<RichSkillDoc>

fun occupationQueries(query: String): NestedQueryBuilder


fun deleteIndex() {
elasticSearchTemplate.indexOps(IndexCoordinates.of(INDEX_RICHSKILL_DOC)).delete()
}
}

class CustomRichSkillQueriesImpl @Autowired constructor(override val elasticSearchTemplate: ElasticsearchRestTemplate) :
Expand Down