2
0
mirror of https://github.com/VinylDNS/vinyldns synced 2025-08-30 05:47:56 +00:00
This commit is contained in:
Jay07GIT 2022-04-21 16:42:08 +05:30
parent 1205b7df2a
commit c82cbbdf66
No known key found for this signature in database
GPG Key ID: AC6B0308EFC79008
3 changed files with 107 additions and 106 deletions

View File

@ -39,7 +39,9 @@ class MySqlRecordSetDataRepositoryIntegrationSpec
import vinyldns.core.TestRecordSetData._
import vinyldns.core.TestZoneData._
private val repo = TestMySqlInstance.recordSetDataRepository.asInstanceOf[MySqlRecordSetDataRepository]
private val recordSetDataRepo = TestMySqlInstance.recordSetDataRepository.asInstanceOf[MySqlRecordSetDataRepository]
private val recordSetRepo = TestMySqlInstance.recordSetRepository.asInstanceOf[MySqlRecordSetRepository]
override protected def beforeEach(): Unit = clear()
@ -48,6 +50,7 @@ class MySqlRecordSetDataRepositoryIntegrationSpec
def clear(): Unit =
DB.localTx { s =>
s.executeUpdate("DELETE FROM recordset_data")
s.executeUpdate("DELETE FROM recordset")
}
def generateInserts(zone: Zone, count: Int, word: String = "insert"): List[RecordSetChange] = {
@ -67,7 +70,9 @@ class MySqlRecordSetDataRepositoryIntegrationSpec
val pendingChanges = generateInserts(zone, count, word)
val bigPendingChangeSet = ChangeSet(pendingChanges)
executeWithinTransaction { db: DB =>
repo.save(db, bigPendingChangeSet)
recordSetDataRepo.save(db, bigPendingChangeSet)
recordSetRepo.apply(db, bigPendingChangeSet)
}.unsafeRunSync()
pendingChanges
}
@ -75,7 +80,9 @@ class MySqlRecordSetDataRepositoryIntegrationSpec
def insert(changes: List[RecordSetChange]): Unit = {
val bigPendingChangeSet = ChangeSet(changes)
executeWithinTransaction { db: DB =>
repo.save(db, bigPendingChangeSet)
recordSetDataRepo.save(db, bigPendingChangeSet)
recordSetRepo.apply(db, bigPendingChangeSet)
}.unsafeRunSync()
()
}
@ -95,13 +102,14 @@ class MySqlRecordSetDataRepositoryIntegrationSpec
val deleteChange = makePendingTestDeleteChange(existing(1))
.copy(status = RecordSetChangeStatus.Failed)
executeWithinTransaction { db: DB =>
repo.save(db, ChangeSet(Seq(addChange, updateChange, deleteChange)))
recordSetDataRepo.save(db, ChangeSet(Seq(addChange, updateChange, deleteChange)))
recordSetRepo.apply(db, ChangeSet(Seq(addChange, updateChange, deleteChange)))
}
repo.getRecordSetData(rsOk.id).unsafeRunSync() shouldBe None
repo.getRecordSetData(existing.head.id).unsafeRunSync() shouldBe Some(
recordSetDataRepo.getRecordSetData(rsOk.id).unsafeRunSync() shouldBe None
recordSetDataRepo.getRecordSetData(existing.head.id).unsafeRunSync() shouldBe Some(
recordSetDataWithFQDN(existing.head, okZone)
)
repo.getRecordSetData(existing(1).id).unsafeRunSync() shouldBe Some(
recordSetDataRepo.getRecordSetData(existing(1).id).unsafeRunSync() shouldBe Some(
recordSetDataWithFQDN(existing(1), okZone)
)
}
@ -153,29 +161,31 @@ class MySqlRecordSetDataRepositoryIntegrationSpec
status = RecordSetChangeStatus.Pending
)
executeWithinTransaction { db: DB =>
repo.save(db, ChangeSet(existingPending))
recordSetDataRepo.save(db, ChangeSet(existingPending))
recordSetRepo.apply(db, ChangeSet(existingPending))
}.attempt.unsafeRunSync()
repo.getRecordSetData(failedChange.recordSet.id).unsafeRunSync() shouldBe
recordSetDataRepo.getRecordSetData(failedChange.recordSet.id).unsafeRunSync() shouldBe
Some(
existingPending.recordSet
.copy(fqdn = Some(s"""${failedChange.recordSet.name}.${okZone.name}"""))
)
executeWithinTransaction { db: DB =>
repo.save(db, ChangeSet(Seq(successfulChange, pendingChange, failedChange)))
recordSetDataRepo.save(db, ChangeSet(Seq(successfulChange, pendingChange, failedChange)))
recordSetRepo.apply(db, ChangeSet(Seq(successfulChange, pendingChange, failedChange)))
}.attempt.unsafeRunSync()
// success and pending changes have records saved
repo
recordSetDataRepo
.getRecordSetData(successfulChange.recordSet.id)
.unsafeRunSync() shouldBe
Some(recordSetDataWithFQDN(successfulChange.recordSet, okZone))
repo
recordSetDataRepo
.getRecordSetData(pendingChange.recordSet.id)
.unsafeRunSync() shouldBe
Some(recordSetDataWithFQDN(pendingChange.recordSet, okZone))
// check that the pending record was deleted because of failed record change
repo
recordSetDataRepo
.getRecordSetData(failedChange.recordSet.id)
.unsafeRunSync() shouldBe None
}
@ -185,8 +195,10 @@ class MySqlRecordSetDataRepositoryIntegrationSpec
val pendingChanges = generateInserts(okZone, 1000)
val bigPendingChangeSet = ChangeSet(pendingChanges)
val saveRecSets = executeWithinTransaction { db: DB =>
repo.save(db, bigPendingChangeSet)
repo.save(db, bigPendingChangeSet)
recordSetDataRepo.save(db, bigPendingChangeSet)
recordSetDataRepo.save(db, bigPendingChangeSet)
recordSetRepo.apply(db, bigPendingChangeSet)
recordSetRepo.apply(db, bigPendingChangeSet)
}
saveRecSets.attempt.unsafeRunSync() shouldBe right
}
@ -195,10 +207,12 @@ class MySqlRecordSetDataRepositoryIntegrationSpec
val bigPendingChangeSet = ChangeSet(pendingChanges)
executeWithinTransaction { db: DB =>
repo.save(db, bigPendingChangeSet)
recordSetDataRepo.save(db, bigPendingChangeSet)
recordSetRepo.apply(db, bigPendingChangeSet)
}.attempt.unsafeRunSync()
// let's make sure we have all 1000 records
val recordCount = repo.getRecordSetDataCount(okZone.id).unsafeRunSync()
val recordCount = recordSetDataRepo.getRecordSetDataCount(okZone.id).unsafeRunSync()
recordCount shouldBe 20
}
"work for deletes, updates, and inserts" in {
@ -222,29 +236,31 @@ class MySqlRecordSetDataRepositoryIntegrationSpec
// exercise the entire change set
val cs = ChangeSet(deletes ++ updates ++ inserts)
executeWithinTransaction { db: DB =>
repo.save(db, cs)
recordSetDataRepo.save(db, cs)
recordSetRepo.apply(db, cs)
}.attempt.unsafeRunSync()
// make sure the deletes are gone
repo.getRecordSetData(deletes(0).recordSet.id).unsafeRunSync() shouldBe None
repo.getRecordSetData(deletes(1).recordSet.id).unsafeRunSync() shouldBe None
recordSetDataRepo.getRecordSetData(deletes(0).recordSet.id).unsafeRunSync() shouldBe None
recordSetDataRepo.getRecordSetData(deletes(1).recordSet.id).unsafeRunSync() shouldBe None
// make sure the updates are updated
repo.getRecordSetData(updates(0).recordSet.id).unsafeRunSync().map(_.name) shouldBe
recordSetDataRepo.getRecordSetData(updates(0).recordSet.id).unsafeRunSync().map(_.name) shouldBe
Some(updates(0).recordSet.name)
repo.getRecordSetData(updates(1).recordSet.id).unsafeRunSync().map(_.name) shouldBe
recordSetDataRepo.getRecordSetData(updates(1).recordSet.id).unsafeRunSync().map(_.name) shouldBe
Some(updates(1).recordSet.name)
// make sure the new ones are there
repo.getRecordSetData(inserts(0).recordSet.id).unsafeRunSync().map(_.name) shouldBe
recordSetDataRepo.getRecordSetData(inserts(0).recordSet.id).unsafeRunSync().map(_.name) shouldBe
Some(inserts(0).recordSet.name)
repo.getRecordSetData(inserts(1).recordSet.id).unsafeRunSync().map(_.name) shouldBe
recordSetDataRepo.getRecordSetData(inserts(1).recordSet.id).unsafeRunSync().map(_.name) shouldBe
Some(inserts(1).recordSet.name)
}
}
"list record sets" should {
"return all record sets in a zone when optional params are not set" in {
val existing = insert(okZone, 10).map(_.recordSet)
val found = repo
val found = recordSetDataRepo
.listRecordSetData(Some(okZone.id), None, None, None, None, None, NameSort.ASC)
.unsafeRunSync()
found.recordSets should contain theSameElementsAs existing.map(
@ -255,7 +271,7 @@ class MySqlRecordSetDataRepositoryIntegrationSpec
// load 5, start after the 3rd, we should get back the last two
val existing = insert(okZone, 5).map(_.recordSet).sortBy(_.name)
val startFrom = Some(PagingKey.toNextId(existing(2), true))
val found = repo
val found = recordSetDataRepo
.listRecordSetData(Some(okZone.id), startFrom, None, None, None, None, NameSort.ASC)
.unsafeRunSync()
@ -269,7 +285,7 @@ class MySqlRecordSetDataRepositoryIntegrationSpec
// load 5, start after the 2nd, take 2, we should get back the 3rd and 4th
val existing = insert(okZone, 5).map(_.recordSet).sortBy(_.name)
val startFrom = Some(PagingKey.toNextId(existing(1), true))
val found = repo
val found = recordSetDataRepo
.listRecordSetData(Some(okZone.id), startFrom, Some(2), None, None, None, NameSort.ASC)
.unsafeRunSync()
@ -293,7 +309,7 @@ class MySqlRecordSetDataRepositoryIntegrationSpec
insert(changes)
val startFrom = Some(PagingKey.toNextId(newRecordSets(1), true))
val found = repo
val found = recordSetDataRepo
.listRecordSetData(
Some(okZone.id),
startFrom,
@ -318,7 +334,7 @@ class MySqlRecordSetDataRepositoryIntegrationSpec
val changes = newRecordSets.map(makeTestAddChange(_, okZone))
insert(changes)
val found = repo
val found = recordSetDataRepo
.listRecordSetData(Some(okZone.id), None, Some(3), Some("aa*"), None, None, NameSort.ASC)
.unsafeRunSync()
(found.recordSets.map(_.name) should contain).theSameElementsInOrderAs(expectedNames)
@ -335,7 +351,7 @@ class MySqlRecordSetDataRepositoryIntegrationSpec
val changes = newRecordSets.map(makeTestAddChange(_, okZone))
insert(changes)
val found = repo
val found = recordSetDataRepo
.listRecordSetData(Some(okZone.id), None, Some(3), Some("*b"), None, None, NameSort.ASC)
.unsafeRunSync()
(found.recordSets.map(_.name) should contain).theSameElementsInOrderAs(expectedNames)
@ -353,14 +369,14 @@ class MySqlRecordSetDataRepositoryIntegrationSpec
val changes = newRecordSets.map(makeTestAddChange(_, okZone))
insert(changes)
val found = repo
val found = recordSetDataRepo
.listRecordSetData(Some(okZone.id), None, Some(3), Some("aaa"), None, None, NameSort.ASC)
.unsafeRunSync()
(found.recordSets.map(_.name) should contain).theSameElementsInOrderAs(expectedNames)
}
"return select types of recordsets in a zone" in {
insert(okZone, 10).map(_.recordSet)
val found = repo
val found = recordSetDataRepo
.listRecordSetData(Some(okZone.id), None, None, None, Some(Set(CNAME)), None, NameSort.ASC)
.unsafeRunSync()
found.recordSets shouldBe List()
@ -368,7 +384,7 @@ class MySqlRecordSetDataRepositoryIntegrationSpec
}
"return all recordsets in a zone in descending order" in {
val existing = insert(okZone, 10).map(_.recordSet)
val found = repo
val found = recordSetDataRepo
.listRecordSetData(Some(okZone.id), None, None, None, None, None, NameSort.DESC)
.unsafeRunSync()
found.recordSets should contain theSameElementsAs existing.map(
@ -379,7 +395,7 @@ class MySqlRecordSetDataRepositoryIntegrationSpec
"pages through the list properly" in {
// load 5 records, pages of 2, last page should have 1 result and no next id
val existing = insert(okZone, 5).map(_.recordSet).sortBy(_.name)
val page1 = repo
val page1 = recordSetDataRepo
.listRecordSetData(Some(okZone.id), None, Some(2), None, None, None, NameSort.ASC)
.unsafeRunSync()
(page1.recordSets should contain).theSameElementsInOrderAs(
@ -389,7 +405,7 @@ class MySqlRecordSetDataRepositoryIntegrationSpec
)
page1.nextId shouldBe Some(PagingKey.toNextId(page1.recordSets(1), true))
val page2 = repo
val page2 = recordSetDataRepo
.listRecordSetData(Some(okZone.id), page1.nextId, Some(2), None, None, None, NameSort.ASC)
.unsafeRunSync()
(page2.recordSets should contain).theSameElementsInOrderAs(
@ -399,7 +415,7 @@ class MySqlRecordSetDataRepositoryIntegrationSpec
)
page2.nextId shouldBe Some(PagingKey.toNextId(page2.recordSets(1), true))
val page3 = repo
val page3 = recordSetDataRepo
.listRecordSetData(Some(okZone.id), page2.nextId, Some(2), None, None, None, NameSort.ASC)
.unsafeRunSync()
(page3.recordSets should contain).theSameElementsInOrderAs(
@ -412,7 +428,7 @@ class MySqlRecordSetDataRepositoryIntegrationSpec
"return applicable recordsets in ascending order when recordNameFilter is given" in {
val existing = insert(okZone, 10).map(_.recordSet)
val found = repo
val found = recordSetDataRepo
.listRecordSetData(None, None, None, Some("*.ok*"), None, None, NameSort.ASC)
.unsafeRunSync()
found.recordSets should contain theSameElementsAs existing.map(
@ -421,7 +437,7 @@ class MySqlRecordSetDataRepositoryIntegrationSpec
}
"return applicable recordsets in descending order when recordNameFilter is given and name sort is descending" in {
val existing = insert(okZone, 10).map(_.recordSet)
val found = repo
val found = recordSetDataRepo
.listRecordSetData(None, None, None, Some("*.ok*"), None, None, NameSort.DESC)
.unsafeRunSync()
found.recordSets should contain theSameElementsAs existing
@ -430,7 +446,7 @@ class MySqlRecordSetDataRepositoryIntegrationSpec
}
"return no recordsets when no zoneId or recordNameFilter are given" in {
val found =
repo.listRecordSetData(None, None, None, None, None, None, NameSort.ASC).unsafeRunSync()
recordSetDataRepo.listRecordSetData(None, None, None, None, None, None, NameSort.ASC).unsafeRunSync()
found.recordSets shouldBe empty
}
}
@ -438,31 +454,31 @@ class MySqlRecordSetDataRepositoryIntegrationSpec
"return a record set when there is a match" in {
val existing = insert(okZone, 1).map(_.recordSet)
val results =
repo.getRecordSetDataList(okZone.id, existing.head.name, existing.head.typ).unsafeRunSync()
recordSetDataRepo.getRecordSetDataList(okZone.id, existing.head.name, existing.head.typ).unsafeRunSync()
results.headOption shouldBe Some(recordSetDataWithFQDN(existing.head, okZone))
}
"return none when there is no match" in {
val existing = insert(okZone, 1).map(_.recordSet)
val results = repo.getRecordSetDataList(okZone.id, "not-there", existing.head.typ).unsafeRunSync()
val results = recordSetDataRepo.getRecordSetDataList(okZone.id, "not-there", existing.head.typ).unsafeRunSync()
results shouldBe empty
}
}
"get record set by id" should {
"return a record set when there is a match" in {
val existing = insert(okZone, 1).map(_.recordSet)
val result = repo.getRecordSetData(existing.head.id).unsafeRunSync()
val result = recordSetDataRepo.getRecordSetData(existing.head.id).unsafeRunSync()
result shouldBe Some(recordSetDataWithFQDN(existing.head, okZone))
}
"return none when there is no match" in {
insert(okZone, 1).map(_.recordSet)
val result = repo.getRecordSetData("not-there").unsafeRunSync()
val result = recordSetDataRepo.getRecordSetData("not-there").unsafeRunSync()
result shouldBe None
}
}
"get record set count for zone" should {
"return the correct number of records in the zone" in {
insert(okZone, 10)
repo.getRecordSetDataCount(okZone.id).unsafeRunSync() shouldBe 10
recordSetDataRepo.getRecordSetDataCount(okZone.id).unsafeRunSync() shouldBe 10
}
}
"get record sets by name" should {
@ -474,14 +490,15 @@ class MySqlRecordSetDataRepositoryIntegrationSpec
val changes = newRecordSets.map(makeTestAddChange(_, okZone))
val expected = changes.map(r => recordSetDataWithFQDN(r.recordSet, okZone))
executeWithinTransaction { db: DB =>
repo.save(db, ChangeSet(changes))
recordSetDataRepo.save(db, ChangeSet(changes))
recordSetRepo.apply(db, ChangeSet(changes))
}.attempt.unsafeRunSync()
val results = repo.getRecordSetDataByName(okZone.id, "foo").unsafeRunSync()
val results = recordSetDataRepo.getRecordSetDataByName(okZone.id, "foo").unsafeRunSync()
results should contain theSameElementsAs expected
}
"return none when there is no match" in {
insert(okZone, 1).map(_.recordSet)
val results = repo.getRecordSetDataByName(okZone.id, "not-there").unsafeRunSync()
val results = recordSetDataRepo.getRecordSetDataByName(okZone.id, "not-there").unsafeRunSync()
results shouldBe empty
}
}
@ -497,7 +514,7 @@ class MySqlRecordSetDataRepositoryIntegrationSpec
val change2 = makeTestAddChange(aaaa.copy(name = rname2), okZone)
insert(List(change1, change2))
val result = repo.getRecordSetDataListByFQDNs(Set("no-existo", fqdn1, fqdn2)).unsafeRunSync()
val result = recordSetDataRepo.getRecordSetDataListByFQDNs(Set("no-existo", fqdn1, fqdn2)).unsafeRunSync()
result should contain theSameElementsAs List(
recordSetDataWithFQDN(change1.recordSet, okZone),
recordSetDataWithFQDN(change2.recordSet, okZone)
@ -512,7 +529,7 @@ class MySqlRecordSetDataRepositoryIntegrationSpec
val mxChange = makeTestAddChange(mx.copy(name = rname), okZone)
insert(List(aaaaChange, mxChange))
val result = repo.getRecordSetDataListByFQDNs(Set(fqdn)).unsafeRunSync()
val result = recordSetDataRepo.getRecordSetDataListByFQDNs(Set(fqdn)).unsafeRunSync()
result should contain theSameElementsAs List(
recordSetDataWithFQDN(aaaaChange.recordSet, okZone),
recordSetDataWithFQDN(mxChange.recordSet, okZone)
@ -520,7 +537,7 @@ class MySqlRecordSetDataRepositoryIntegrationSpec
}
"return an empty list when given no ids" in {
val result = repo.getRecordSetDataListByFQDNs(Set[String]()).unsafeRunSync()
val result = recordSetDataRepo.getRecordSetDataListByFQDNs(Set[String]()).unsafeRunSync()
result shouldBe List()
}
@ -535,12 +552,12 @@ class MySqlRecordSetDataRepositoryIntegrationSpec
val change2 = makeTestAddChange(mx.copy(name = rname2), okZone)
insert(List(change1, change2))
val result1 = repo.getRecordSetDataListByFQDNs(Set(fqdn1)).unsafeRunSync()
val result1 = recordSetDataRepo.getRecordSetDataListByFQDNs(Set(fqdn1)).unsafeRunSync()
result1 should contain theSameElementsAs List(
recordSetDataWithFQDN(change1.recordSet, okZone),
recordSetDataWithFQDN(change2.recordSet, okZone)
)
val result2 = repo.getRecordSetDataListByFQDNs(Set(fqdn2)).unsafeRunSync()
val result2 = recordSetDataRepo.getRecordSetDataListByFQDNs(Set(fqdn2)).unsafeRunSync()
result2 should contain theSameElementsAs List(
recordSetDataWithFQDN(change1.recordSet, okZone),
recordSetDataWithFQDN(change2.recordSet, okZone)
@ -554,17 +571,18 @@ class MySqlRecordSetDataRepositoryIntegrationSpec
val testRecord = addChange.recordSet
executeWithinTransaction { db: DB =>
for {
_ <- repo.save(db, ChangeSet(addChange))
get <- repo.getRecordSetData(testRecord.id)
_ <- recordSetDataRepo.save(db, ChangeSet(addChange))
_ <- recordSetRepo.apply(db, ChangeSet(addChange))
get <- recordSetDataRepo.getRecordSetData(testRecord.id)
} yield get
}.attempt.unsafeRunSync()
val result = repo.getFirstOwnedRecordSetDataByGroup("someOwner").unsafeRunSync()
val result = recordSetDataRepo.getFirstOwnedRecordSetDataByGroup("someOwner").unsafeRunSync()
result shouldBe Some(testRecord.id)
}
"return empty string when no record set has the id as ownerGroupId" in {
val result = repo.getFirstOwnedRecordSetDataByGroup("notFound").unsafeRunSync()
val result = recordSetDataRepo.getFirstOwnedRecordSetDataByGroup("notFound").unsafeRunSync()
result shouldBe None
}
}
@ -574,19 +592,19 @@ class MySqlRecordSetDataRepositoryIntegrationSpec
insert(okZone, 20)
insert(abcZone, 10)
repo.getRecordSetDataCount(okZone.id).unsafeRunSync() shouldBe 20
repo.getRecordSetDataCount(abcZone.id).unsafeRunSync() shouldBe 10
recordSetDataRepo.getRecordSetDataCount(okZone.id).unsafeRunSync() shouldBe 20
recordSetDataRepo.getRecordSetDataCount(abcZone.id).unsafeRunSync() shouldBe 10
executeWithinTransaction { db: DB =>
repo.deleteRecordSetDataInZone(db, okZone.id, okZone.name)}.unsafeRunSync() should not be a[Throwable]
recordSetDataRepo.deleteRecordSetDataInZone(db, okZone.id, okZone.name)}.unsafeRunSync() should not be a[Throwable]
repo.getRecordSetDataCount(okZone.id).unsafeRunSync() shouldBe 0
repo.getRecordSetDataCount(abcZone.id).unsafeRunSync() shouldBe 10
recordSetDataRepo.getRecordSetDataCount(okZone.id).unsafeRunSync() shouldBe 0
recordSetDataRepo.getRecordSetDataCount(abcZone.id).unsafeRunSync() shouldBe 10
}
"not fail if there is nothing to delete" in {
repo.getRecordSetDataCount(okZone.id).unsafeRunSync() shouldBe 0
recordSetDataRepo.getRecordSetDataCount(okZone.id).unsafeRunSync() shouldBe 0
executeWithinTransaction { db: DB =>
repo.deleteRecordSetDataInZone(db,okZone.id, okZone.name)}.unsafeRunSync() should not be a[Throwable]
recordSetDataRepo.deleteRecordSetDataInZone(db,okZone.id, okZone.name)}.unsafeRunSync() should not be a[Throwable]
}
}
}

View File

@ -2,12 +2,6 @@ CREATE SCHEMA IF NOT EXISTS ${dbName};
USE ${dbName};
ALTER TABLE recordset_data ADD COLUMN record_name VARCHAR(256) AFTER zone_id;
CREATE INDEX recordset_data_record_name_index ON recordset_data (record_name);
ALTER TABLE recordset_data ADD COLUMN owner_group_id CHAR(36) AFTER ip;
CREATE INDEX recordset_data_owner_group_id_index ON recordset_data (owner_group_id);
/*
Drop recordset_data_fdqn_fulltext_index index from recordset_data table
*/
@ -24,3 +18,5 @@ Drop data column from recordset_data table
*/
ALTER TABLE recordset_data DROP COLUMN data;

View File

@ -36,7 +36,7 @@ class MySqlRecordSetDataRepository
with ProtobufConversions {
private val INSERT_RECORDSETDATA =
sql"INSERT IGNORE INTO recordset_data(recordset_id, zone_id, record_name, fqdn, reverse_fqdn, type, record_data, ip, owner_group_id) VALUES ({recordset_id}, {zone_id}, {record_name}, {fqdn}, {reverse_fqdn}, {type}, {record_data}, {ip}, {owner_group_id})"
sql"INSERT IGNORE INTO recordset_data(recordset_id, zone_id, fqdn, reverse_fqdn, type, record_data, ip) VALUES ({recordset_id}, {zone_id}, {fqdn}, {reverse_fqdn}, {type}, {record_data}, {ip})"
private val DELETE_RECORDSETDATA =
sql"DELETE FROM recordset_data WHERE recordset_id = ?"
@ -48,12 +48,11 @@ class MySqlRecordSetDataRepository
sql"""
|SELECT count(*)
| FROM recordset_data
| INNER JOIN recordset ON recordset.id=recordset_data.recordset_id
| WHERE recordset_data.zone_id = {zone_id}
| WHERE zone_id = {zone_id}
""".stripMargin
private val BASE_FIND_RECORDSETS_BY_FQDNS =
"""
sql"""
|SELECT recordset.data, recordset_data.fqdn
| FROM recordset_data
| INNER JOIN recordset ON recordset.id=recordset_data.recordset_id
@ -65,7 +64,7 @@ class MySqlRecordSetDataRepository
|SELECT recordset.data, recordset_data.fqdn
| FROM recordset_data
| INNER JOIN recordset ON recordset.id=recordset_data.recordset_id
| WHERE recordset_data.zone_id = {zone_id} AND recordset_data.record_name = {record_name} AND recordset_data.type = {type}
| WHERE recordset_data.zone_id = {zone_id} AND recordset.name = {record_name} AND recordset_data.type = {type}
""".stripMargin
private val FIND_BY_ZONEID_NAME =
@ -73,7 +72,7 @@ class MySqlRecordSetDataRepository
|SELECT recordset.data, recordset_data.fqdn
| FROM recordset_data
| INNER JOIN recordset ON recordset.id=recordset_data.recordset_id
| WHERE recordset_data.zone_id = {zone_id} AND recordset_data.record_name = {record_name}
| WHERE recordset_data.zone_id = {zone_id} AND recordset.name = {record_name}
""".stripMargin
@ -97,7 +96,8 @@ class MySqlRecordSetDataRepository
sql"""
|SELECT recordset_id
| FROM recordset_data
|WHERE owner_group_id = {ownerGroupId}
| INNER JOIN recordset ON recordset.id=recordset_data.recordset_id
|WHERE recordset.owner_group_id = {ownerGroupId}
|LIMIT 1
""".stripMargin
@ -116,13 +116,11 @@ class MySqlRecordSetDataRepository
RsData(
db,
oldRs.id,
oldRs.records.toString,
oldRs.typ.toString,
oldRs.zoneId,
oldRs.name,
toFQDN(change.zone.name, oldRs.name),
toFQDN(change.zone.name, oldRs.name).reverse,
oldRs.typ.toString,
oldRs.records.toString,
oldRs.ownerGroupId,
"update"
)
)
@ -146,10 +144,8 @@ class MySqlRecordSetDataRepository
i.recordSet.records.toString,
i.recordSet.typ.toString,
i.recordSet.zoneId,
i.recordSet.name,
toFQDN(i.zone.name, i.recordSet.name),
toFQDN(i.zone.name, i.recordSet.name).reverse,
i.recordSet.ownerGroupId,
"insert"
))
}
@ -161,14 +157,13 @@ class MySqlRecordSetDataRepository
u.recordSet.records.toString,
u.recordSet.typ.toString,
u.recordSet.zoneId,
u.recordSet.name,
toFQDN(u.zone.name, u.recordSet.name),
toFQDN(u.zone.name, u.recordSet.name).reverse,
u.recordSet.ownerGroupId,
"update"
)
)
}
val deletes: Seq[Seq[Any]] = completeDeletes.map(d => Seq[Any](d.recordSet.id))
IO {
db.withinTx { implicit session =>
@ -202,17 +197,15 @@ class MySqlRecordSetDataRepository
recordData: String,
recordType: String,
zoneId: String,
recordName: String,
FQDN: String,
reverseFQDN: String,
ownerGroupId: Option[String],
rs: String
): Unit =
rs match {
/**
* insert the rsdata, as if recordset are created
*/
case "insert" => rsDataSave(db, recordID, recordData, recordType, zoneId, recordName, FQDN, reverseFQDN, ownerGroupId)
case "insert" => rsDataSave(db, recordID, recordData, recordType, zoneId, FQDN, reverseFQDN)
/**
* delete and insert the rsdata, as if recordset are updated.
*/
@ -223,7 +216,7 @@ class MySqlRecordSetDataRepository
.update()
.apply()
}
rsDataSave(db, recordID, recordData, recordType, zoneId, recordName, FQDN, reverseFQDN, ownerGroupId)
rsDataSave(db, recordID, recordData, recordType, zoneId, FQDN, reverseFQDN)
}
def rsDataSave(
@ -232,28 +225,24 @@ class MySqlRecordSetDataRepository
recordData: String,
recordType: String,
zoneId: String,
recordName: String,
FQDN: String,
reverseFQDN: String,
ownerGroupId: Option[String]
): Unit = {
recordType match {
case "DS" => for (ipString<- recordData.split(Pattern.quote("),")).map(_.trim).toList) {
insertRecordSetData(db, recordId, zoneId, recordName, FQDN, reverseFQDN, recordType, ipString, ownerGroupId)}
insertRecordSetData(db, recordId, zoneId, FQDN, reverseFQDN, recordType, ipString)}
case _ => for (ipString <- recordData.split(",").map(_.trim).toList) {
insertRecordSetData(db,recordId,zoneId,recordName,FQDN,reverseFQDN,recordType,ipString,ownerGroupId)}
insertRecordSetData(db,recordId,zoneId,FQDN,reverseFQDN,recordType,ipString)}
}}
def insertRecordSetData(
db: DB,
recordId: String,
zoneId: String,
recordName: String,
FQDN: String,
reverseFQDN: String,
recordType: String,
ipString: String,
ownerGroupId: Option[String]
): Unit = {
var parseIp: String = null
var records: String = null
@ -271,13 +260,11 @@ class MySqlRecordSetDataRepository
.bindByName(
'recordset_id -> recordId,
'zone_id -> zoneId,
'record_name -> recordName,
'fqdn -> FQDN,
'reverse_fqdn -> reverseFQDN,
'type -> recordType,
'record_data -> records,
'ip -> parseIp,
'owner_group_id -> ownerGroupId
'ip -> parseIp
)
.update()
.apply()
@ -461,7 +448,7 @@ class MySqlRecordSetDataRepository
// setup optional filters
val zoneAndNameFilters = (zoneId, recordNameFilter) match {
case (Some(zId), Some(rName)) =>
Some(sqls"recordset_data.zone_id = $zId AND recordset_data.record_name LIKE ${rName.replace('*', '%')} ")
Some(sqls"recordset_data.zone_id = $zId AND recordset.name LIKE ${rName.replace('*', '%')} ")
case (None, Some(fqdn)) => val reversefqdn = fqdn.reverse // reverse the fqdn.
Some(sqls"recordset_data.reverse_fqdn LIKE ${reversefqdn.replace('*', '%')} ")
case (Some(zId), None) => Some(sqls"recordset_data.zone_id = $zId ")
@ -475,38 +462,38 @@ class MySqlRecordSetDataRepository
val sortBy = (searchByZone, nameSort) match {
case (true, NameSort.DESC) =>
pagingKey.as(
sqls"((recordset_data.record_name <= ${pagingKey.map(pk => pk.recordName)} AND recordset_data.type > ${pagingKey.map(pk => pk.recordType)}) OR recordset_data.record_name < ${pagingKey.map(pk => pk.recordName)})"
sqls"((recordset.name <= ${pagingKey.map(pk => pk.recordName)} AND recordset.type > ${pagingKey.map(pk => pk.recordType)}) OR recordset.name < ${pagingKey.map(pk => pk.recordName)})"
)
case (false, NameSort.ASC) =>
pagingKey.as(
sqls"((recordset_data.fqdn >= ${pagingKey.map(pk => pk.recordName)} AND recordset_data.type > ${pagingKey.map(pk => pk.recordType)}) OR recordset_data.fqdn > ${pagingKey.map(pk => pk.recordName)})"
sqls"((recordset_data.fqdn >= ${pagingKey.map(pk => pk.recordName)} AND recordset.type > ${pagingKey.map(pk => pk.recordType)}) OR recordset_data.fqdn > ${pagingKey.map(pk => pk.recordName)})"
)
case (false, NameSort.DESC) =>
pagingKey.as(
sqls"((recordset_data.fqdn <= ${pagingKey.map(pk => pk.recordName)} AND recordset_data.type > ${pagingKey.map(pk => pk.recordType)}) OR recordset_data.fqdn < ${pagingKey.map(pk => pk.recordName)})"
sqls"((recordset_data.fqdn <= ${pagingKey.map(pk => pk.recordName)} AND recordset.type > ${pagingKey.map(pk => pk.recordType)}) OR recordset_data.fqdn < ${pagingKey.map(pk => pk.recordName)})"
)
case _ =>
pagingKey.as(
sqls"((recordset_data.record_name >= ${pagingKey.map(pk => pk.recordName)} AND recordset_data.type > ${pagingKey.map(pk => pk.recordType)}) OR recordset_data.record_name > ${pagingKey.map(pk => pk.recordName)})"
sqls"((recordset.name >= ${pagingKey.map(pk => pk.recordName)} AND recordset.type > ${pagingKey.map(pk => pk.recordType)}) OR recordset.name > ${pagingKey.map(pk => pk.recordName)})"
)
}
val typeFilter = recordTypeFilter.map { t =>
val list = t.map(fromRecordType)
sqls"recordset_data.type IN ($list)"
sqls"recordset.type IN ($list)"
}
val ownerGroupFilter =
recordOwnerGroupFilter.map(owner => sqls"recordset_data.owner_group_id = $owner ")
recordOwnerGroupFilter.map(owner => sqls"recordset.owner_group_id = $owner ")
val opts =
(zoneAndNameFilters ++ sortBy ++ typeFilter ++ ownerGroupFilter).toList
val qualifiers = if (nameSort == ASC) {
sqls"ORDER BY recordset_data.fqdn ASC, recordset_data.type ASC "
sqls"ORDER BY recordset_data.fqdn ASC, recordset.type ASC "
}
else {
sqls"ORDER BY recordset_data.fqdn DESC, recordset_data.type ASC "
sqls"ORDER BY recordset_data.fqdn DESC, recordset.type ASC "
}
val recordLimit = maxPlusOne match {