Skip to content

Commit 95b623b

Browse files
committed
Fixed issue with auto-ingesting newly published icd in certain cases
1 parent 2fd920d commit 95b623b

5 files changed

Lines changed: 81 additions & 49 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ See also [JsonSchemaChanges.md](JsonSchemaChanges.md) for a list of changes in t
1212

1313
- Added "Command: " to command description heading to match event headings.
1414

15+
- Fixed an issue that could cause a newly published ICD version to not be automatically ingested into the local icd database in certain circumstances
16+
1517
## [ICD v2.1.0] - 2020-10-12
1618

1719
### Added

icd-db/src/test/scala/csw/services/icd/db/ArchivedItemsTest.scala

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,33 +41,33 @@ class ArchivedItemsTest extends AnyFunSuite {
4141
)
4242
m.name match {
4343
case "engMode" =>
44-
assert(m.totalSizeInBytes == 109)
44+
assert(m.totalSizeInBytes == 339)
4545
assert(!m.archive)
4646
assert(m.totalArchiveSpacePerYear.isEmpty)
4747
case "engMode2" =>
48-
assert(m.totalSizeInBytes == 110)
48+
assert(m.totalSizeInBytes == 340)
4949
assert(m.archive)
50-
assert(m.totalArchiveSpacePerYear == "3.2 GB")
50+
assert(m.totalArchiveSpacePerYear == "5.0 GB")
5151
case "engMode2Error" =>
52-
assert(m.totalSizeInBytes == 113)
52+
assert(m.totalSizeInBytes == 180)
5353
case "engMode3" =>
54-
assert(m.totalSizeInBytes == 193)
54+
assert(m.totalSizeInBytes == 432)
5555
assert(m.archive)
56-
assert(m.totalArchiveSpacePerYear == "5.7 GB")
56+
assert(m.totalArchiveSpacePerYear == "6.3 GB")
5757
case "contRead" =>
58-
assert(m.totalSizeInBytes == 109)
58+
assert(m.totalSizeInBytes == 229)
5959
assert(!m.archive)
6060
assert(m.totalArchiveSpacePerYear.isEmpty)
6161
case "intTime" =>
62-
assert(m.totalSizeInBytes == 111)
62+
assert(m.totalSizeInBytes == 231)
6363
assert(m.archive)
64-
assert(m.totalArchiveSpacePerYear == "3.3 GB")
64+
assert(m.totalArchiveSpacePerYear == "3.4 GB")
6565
case "state" =>
66-
assert(m.totalSizeInBytes == 113)
66+
assert(m.totalSizeInBytes == 233)
6767
assert(!m.archive)
6868
assert(m.totalArchiveSpacePerYear.isEmpty)
6969
case "heartbeat" =>
70-
assert(m.totalSizeInBytes == 113)
70+
assert(m.totalSizeInBytes == 237)
7171
assert(!m.archive)
7272
assert(m.totalArchiveSpacePerYear.isEmpty)
7373
case x =>

icd-git/src/main/scala/csw/services/icd/github/IcdGit.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,6 @@ object IcdGit extends App {
381381

382382
private def ingestMissing(options: Options): Unit = {
383383
val db = IcdDb(options.dbName, options.host, options.port)
384-
IcdGitManager.ingestMissing(db)
384+
IcdGitManager. ingestMissing(db)
385385
}
386386
}

icd-git/src/main/scala/csw/services/icd/github/IcdGitManager.scala

Lines changed: 66 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ import play.api.libs.json.Json
1717

1818
import scala.jdk.CollectionConverters._
1919
import scala.concurrent.ExecutionContext.Implicits.global
20-
import scala.concurrent.duration.DurationLong
21-
import scala.concurrent.{Await, Future}
20+
import scala.concurrent.Future
2221

2322
/**
2423
* Provides methods for managing ICD versions in Git and
@@ -67,7 +66,8 @@ object IcdGitManager {
6766
val git = Git.cloneRepository.setDirectory(gitWorkDir).setURI(gitBaseUri).call
6867
git.close()
6968
getAllVersions(gitWorkDir)
70-
} finally {
69+
}
70+
finally {
7171
deleteDirectoryRecursively(gitWorkDir)
7272
}
7373
}
@@ -92,7 +92,8 @@ object IcdGitManager {
9292
val user = ""
9393
val comment = ""
9494
Some(ApiVersions.ApiEntry("master", info.commitId, user, comment, date))
95-
} else None
95+
}
96+
else None
9697
}
9798

9899
/**
@@ -304,7 +305,8 @@ object IcdGitManager {
304305
}
305306
git.close()
306307
maybeIcd
307-
} finally {
308+
}
309+
finally {
308310
deleteDirectoryRecursively(gitWorkDir)
309311
}
310312
}
@@ -378,7 +380,8 @@ object IcdGitManager {
378380
maybeApi
379381
}
380382
maybeApiEntry.map(e => ApiVersionInfo(sv.subsystem, e.version, e.user, e.comment, e.date, e.commit))
381-
} finally {
383+
}
384+
finally {
382385
deleteDirectoryRecursively(gitWorkDir)
383386
}
384387
}
@@ -440,7 +443,8 @@ object IcdGitManager {
440443
if (updateTag)
441444
tag(ApiVersions(subsystem, List(apiEntry)), user, password, comment, (s: String) => println(s))
442445
ApiVersionInfo(subsystem, apiEntry.version, user, comment, date, commit)
443-
} finally {
446+
}
447+
finally {
444448
deleteDirectoryRecursively(gitWorkDir)
445449
}
446450
}
@@ -476,14 +480,16 @@ object IcdGitManager {
476480
feedback(s"Removing tag $subsystem: v${e.version}")
477481
// TODO: Does not seem to work
478482
git.tagDelete().setTags(s"v${e.version}").call()
479-
} else {
483+
}
484+
else {
480485
feedback(s"Tagging $subsystem: v${e.version}")
481486
git.tag().setForceUpdate(true).setMessage(comment).setName(s"v${e.version}").setObjectId(commit).call()
482487
}
483488
}
484489
git.push().setPushTags().setCredentialsProvider(new UsernamePasswordCredentialsProvider(user, password)).call()
485490
git.close()
486-
} finally {
491+
}
492+
finally {
487493
deleteDirectoryRecursively(gitWorkDir)
488494
}
489495
}
@@ -634,7 +640,8 @@ object IcdGitManager {
634640
git.push.setCredentialsProvider(new UsernamePasswordCredentialsProvider(user, password)).call()
635641
git.close()
636642
IcdVersionInfo(IcdVersion(newIcdVersion, sv.subsystem, v1, targetSv.subsystem, v2), user, comment, date)
637-
} finally {
643+
}
644+
finally {
638645
deleteDirectoryRecursively(gitWorkDir)
639646
}
640647
}
@@ -653,7 +660,8 @@ object IcdGitManager {
653660
val file = new File(dir, filePath)
654661
if (file.isDirectory) {
655662
deleteDirectoryRecursively(file)
656-
} else {
663+
}
664+
else {
657665
file.delete()
658666
}
659667
}
@@ -682,7 +690,8 @@ object IcdGitManager {
682690
if (subsystemList.nonEmpty) {
683691
// sort by convention to avoid duplicate ICDs,
684692
subsystemList.sorted
685-
} else {
693+
}
694+
else {
686695
Subsystems.allSubsystems.map(s => SubsystemAndVersion(s, None))
687696
}
688697
}
@@ -725,29 +734,31 @@ object IcdGitManager {
725734
* @param apiEntries the (GitHub version) entries for the published versions to ingest
726735
* @param feedback optional feedback function
727736
*/
728-
def ingest(db: IcdDb, subsystem: String, apiEntries: List[ApiEntry], feedback: String => Unit): Unit = this.synchronized {
729-
// Checkout the subsystem repo in a temp dir
730-
val url = getSubsystemGitHubUrl(subsystem)
731-
val gitWorkDir = Files.createTempDirectory("icds").toFile
732-
try {
733-
val git = Git.cloneRepository.setDirectory(gitWorkDir).setURI(url).call()
734-
apiEntries.reverse.foreach { e =>
735-
feedback(s"Checking out $subsystem-${e.version} (commit: ${e.commit})")
736-
git.checkout().setName(e.commit).call
737-
feedback(s"Ingesting $subsystem-${e.version}")
738-
val (_, problems) = db.ingest(gitWorkDir)
739-
problems.foreach(p => feedback(p.errorMessage()))
740-
db.query.afterIngestSubsystem(subsystem, problems, db.dbName)
741-
if (!problems.exists(_.severity != "warning")) {
742-
val date = DateTime.parse(e.date)
743-
db.versionManager.publishApi(subsystem, Some(e.version), majorVersion = false, e.comment, e.user, date, e.commit)
737+
def ingest(db: IcdDb, subsystem: String, apiEntries: List[ApiEntry], feedback: String => Unit): Unit =
738+
this.synchronized {
739+
// Checkout the subsystem repo in a temp dir
740+
val url = getSubsystemGitHubUrl(subsystem)
741+
val gitWorkDir = Files.createTempDirectory("icds").toFile
742+
try {
743+
val git = Git.cloneRepository.setDirectory(gitWorkDir).setURI(url).call()
744+
apiEntries.reverse.foreach { e =>
745+
feedback(s"Checking out $subsystem-${e.version} (commit: ${e.commit})")
746+
git.checkout().setName(e.commit).call
747+
feedback(s"Ingesting $subsystem-${e.version}")
748+
val (_, problems) = db.ingest(gitWorkDir)
749+
problems.foreach(p => feedback(p.errorMessage()))
750+
db.query.afterIngestSubsystem(subsystem, problems, db.dbName)
751+
if (!problems.exists(_.severity != "warning")) {
752+
val date = DateTime.parse(e.date)
753+
db.versionManager.publishApi(subsystem, Some(e.version), majorVersion = false, e.comment, e.user, date, e.commit)
754+
}
744755
}
756+
git.close()
757+
}
758+
finally {
759+
deleteDirectoryRecursively(gitWorkDir)
745760
}
746-
git.close()
747-
} finally {
748-
deleteDirectoryRecursively(gitWorkDir)
749761
}
750-
}
751762

752763
/**
753764
* Validates the current version of the given subsystem that is checked in on GitHub
@@ -763,13 +774,14 @@ object IcdGitManager {
763774
val problems = IcdValidator.validateDirRecursive(gitWorkDir)
764775
git.close()
765776
problems
766-
} finally {
777+
}
778+
finally {
767779
deleteDirectoryRecursively(gitWorkDir)
768780
}
769781
}
770782

771783
// Imports the ICD release information for the two subsystems, or all subsystems
772-
private def importIcdFiles(
784+
def importIcdFiles(
773785
db: IcdDb,
774786
subsystems: List[SubsystemAndVersion],
775787
feedback: String => Unit,
@@ -831,7 +843,8 @@ object IcdGitManager {
831843
.setCredentialsProvider(new UsernamePasswordCredentialsProvider(gitHubCredentials.user, gitHubCredentials.password))
832844
.call()
833845
git.close()
834-
} finally {
846+
}
847+
finally {
835848
deleteDirectoryRecursively(gitWorkDir)
836849
}
837850
}
@@ -918,15 +931,31 @@ object IcdGitManager {
918931
.flatMap { apiVersions =>
919932
val versions = db.versionManager.getVersions(apiVersions.subsystem).tail.toSet
920933
apiVersions.apis
921-
.filter(
922-
apiEntry => !versions.exists(info => info.maybeVersion.contains(apiEntry.version) && info.commit == apiEntry.commit)
934+
.filter(apiEntry =>
935+
!versions.exists(info => info.maybeVersion.contains(apiEntry.version) && info.commit == apiEntry.commit)
923936
)
924937
.map(apiEntry => SubsystemAndVersion(apiVersions.subsystem, Some(apiEntry.version)))
925938
}
926939
if (missingSubsystemVersions.nonEmpty) {
927940
println(s"Updating the ICD database with newly published changes from GitHub")
928941
IcdGitManager.ingest(db, missingSubsystemVersions, (s: String) => println(s), allApiVersions, allIcdVersions)
929942
}
943+
else {
944+
// There might still be icds that have not yet been ingested in the local database
945+
// Ingest any missing published icd versions
946+
val missingIcdVersions = allIcdVersions
947+
.flatMap { icdVersions =>
948+
val s = icdVersions.subsystems.head
949+
val t = icdVersions.subsystems.tail.head
950+
val versions = db.versionManager.getIcdVersions(s, t).toSet
951+
if (icdVersions.icds.exists(icdEntry => !versions.exists(_.icdVersion.icdVersion == icdEntry.icdVersion)))
952+
Some(List(SubsystemAndVersion(s, None), SubsystemAndVersion(t, None)))
953+
else None
954+
}
955+
missingIcdVersions.foreach { subsystems =>
956+
IcdGitManager.importIcdFiles(db, subsystems, (s: String) => println(s), allIcdVersions)
957+
}
958+
}
930959

931960
(allApiVersions, allIcdVersions)
932961
}

icd-web-server/app/controllers/ApplicationImpl.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ class ApplicationImpl(db: IcdDb) {
386386
publishIcdInfo.comment
387387
)
388388
updateAfterPublish()
389+
IcdGitManager.importIcdFiles(db, subsystems, (s: String) => println(s), allIcdVersions)
389390
icdVersionInfo
390391
}
391392
}

0 commit comments

Comments
 (0)