generated from ministryofjustice/hmpps-template-kotlin
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d77d740
commit bc96425
Showing
11 changed files
with
143 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
version: "3" | ||
services: | ||
opensearch: | ||
container_name: opensearch | ||
image: opensearchproject/opensearch:2.5.0 | ||
localstack: | ||
image: localstack/localstack:2.0 | ||
networks: | ||
- hmpps | ||
environment: | ||
- node.name=opensearch | ||
- cluster.name=prisoner-search-cluster | ||
- discovery.type=single-node | ||
- bootstrap.memory_lock=true | ||
- plugins.security.disabled=true | ||
- "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m" | ||
container_name: localstack-psi | ||
ports: | ||
- "9200:9200" | ||
- "4566:4566" | ||
environment: | ||
- SERVICES=opensearch | ||
volumes: | ||
- "$PWD/src/test/resources/localstack/setup-opensearch.sh:/etc/localstack/init/ready.d/init-aws.sh" | ||
- "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack" | ||
|
||
networks: | ||
hmpps: |
17 changes: 17 additions & 0 deletions
17
src/main/kotlin/uk/gov/justice/digital/hmpps/prisonersearchindexer/health/IndexInfo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package uk.gov.justice.digital.hmpps.prisonersearchindexer.health | ||
|
||
import org.springframework.boot.actuate.info.Info | ||
import org.springframework.boot.actuate.info.InfoContributor | ||
import org.springframework.stereotype.Component | ||
import uk.gov.justice.digital.hmpps.prisonersearchindexer.services.IndexStatusService | ||
|
||
@Component | ||
class IndexInfo( | ||
private val indexStatusService: IndexStatusService, | ||
) : InfoContributor { | ||
|
||
override fun contribute(builder: Info.Builder) { | ||
val indexStatus = indexStatusService.getCurrentIndex() | ||
builder.withDetail("index-status", indexStatus) | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/kotlin/uk/gov/justice/digital/hmpps/prisonersearchindexer/model/IndexStatus.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package uk.gov.justice.digital.hmpps.prisonersearchindexer.model | ||
|
||
import org.springframework.data.annotation.Id | ||
import org.springframework.data.elasticsearch.annotations.DateFormat | ||
import org.springframework.data.elasticsearch.annotations.Document | ||
import org.springframework.data.elasticsearch.annotations.Field | ||
import org.springframework.data.elasticsearch.annotations.FieldType | ||
import java.time.LocalDateTime | ||
|
||
@Document(indexName = "offender-index-status") | ||
class IndexStatus( | ||
@Id | ||
@Field(type = FieldType.Keyword) | ||
var id: String = "STATUS", | ||
|
||
@Field(type = FieldType.Keyword) | ||
var currentIndex: SyncIndex, | ||
|
||
@Field(type = FieldType.Date, format = [DateFormat.date_hour_minute_second]) | ||
var startIndexTime: LocalDateTime?, | ||
|
||
@Field(type = FieldType.Date, format = [DateFormat.date_hour_minute_second]) | ||
var endIndexTime: LocalDateTime?, | ||
|
||
@Field(type = FieldType.Boolean) | ||
var inProgress: Boolean, | ||
|
||
@Field(type = FieldType.Boolean) | ||
var inError: Boolean = false, | ||
|
||
) { | ||
|
||
fun toggleIndex() { | ||
currentIndex = if (currentIndex == SyncIndex.INDEX_A) SyncIndex.INDEX_B else SyncIndex.INDEX_A | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/kotlin/uk/gov/justice/digital/hmpps/prisonersearchindexer/model/SyncIndex.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package uk.gov.justice.digital.hmpps.prisonersearchindexer.model | ||
|
||
enum class SyncIndex(val indexName: String) { | ||
|
||
INDEX_A("prisoner-search-a"), INDEX_B("prisoner-search-b"); | ||
|
||
fun otherIndex(): SyncIndex { | ||
return if (this == INDEX_A) INDEX_B else INDEX_A | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...in/uk/gov/justice/digital/hmpps/prisonersearchindexer/repository/IndexStatusRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package uk.gov.justice.digital.hmpps.prisonersearchindexer.repository | ||
|
||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository | ||
import org.springframework.stereotype.Repository | ||
import uk.gov.justice.digital.hmpps.prisonersearchindexer.model.IndexStatus | ||
|
||
@Repository | ||
interface IndexStatusRepository : ElasticsearchRepository<IndexStatus, String> |
16 changes: 16 additions & 0 deletions
16
.../kotlin/uk/gov/justice/digital/hmpps/prisonersearchindexer/services/IndexStatusService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package uk.gov.justice.digital.hmpps.prisonersearchindexer.services | ||
|
||
import org.springframework.data.repository.findByIdOrNull | ||
import org.springframework.stereotype.Service | ||
import uk.gov.justice.digital.hmpps.prisonersearchindexer.model.IndexStatus | ||
import uk.gov.justice.digital.hmpps.prisonersearchindexer.model.SyncIndex | ||
import uk.gov.justice.digital.hmpps.prisonersearchindexer.repository.IndexStatusRepository | ||
|
||
@Service | ||
class IndexStatusService( | ||
private val indexStatusRepository: IndexStatusRepository, | ||
) { | ||
|
||
fun getCurrentIndex(): IndexStatus = indexStatusRepository.findByIdOrNull("STATUS") | ||
?: indexStatusRepository.save(IndexStatus("STATUS", SyncIndex.INDEX_A, null, null, false)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
export TERM=ansi | ||
export AWS_ACCESS_KEY_ID=foobar | ||
export AWS_SECRET_ACCESS_KEY=foobar | ||
export AWS_DEFAULT_REGION=eu-west-2 | ||
|
||
aws --endpoint-url=http://localhost:4566 opensearch create-domain --domain-name os01 | ||
|
||
echo "OpenSearch configured. Please wait until 'cluster on http://127.0.0.1:xxxxx is ready" |