2
0
mirror of https://github.com/VinylDNS/vinyldns synced 2025-08-31 06:15:49 +00:00

Address requested changes

This commit is contained in:
Aravindh-Raju
2022-07-06 11:36:54 +05:30
parent 6ad28b46d4
commit 95bbbe43c9
3 changed files with 17 additions and 20 deletions

View File

@@ -33,7 +33,7 @@ import vinyldns.core.queue.MessageQueue
class BatchChangeConverter(batchChangeRepo: BatchChangeRepository, messageQueue: MessageQueue) class BatchChangeConverter(batchChangeRepo: BatchChangeRepository, messageQueue: MessageQueue)
extends BatchChangeConverterAlgebra { extends BatchChangeConverterAlgebra {
private val notExistCompletedMessage: String = " This record does not exist." + private val notExistCompletedMessage: String = "This record does not exist." +
"No further action is required." "No further action is required."
private val failedMessage: String = "Error queueing RecordSetChange for processing" private val failedMessage: String = "Error queueing RecordSetChange for processing"
private val logger = LoggerFactory.getLogger(classOf[BatchChangeConverter]) private val logger = LoggerFactory.getLogger(classOf[BatchChangeConverter])
@@ -70,21 +70,18 @@ class BatchChangeConverter(batchChangeRepo: BatchChangeRepository, messageQueue:
recordSetChanges: List[RecordSetChange] recordSetChanges: List[RecordSetChange]
): BatchResult[Unit] = { ): BatchResult[Unit] = {
val convertedIds = recordSetChanges.flatMap(_.singleBatchChangeIds).toSet val convertedIds = recordSetChanges.flatMap(_.singleBatchChangeIds).toSet
// Each single change has a corresponding recordset id singleChanges.find(ch => !convertedIds.contains(ch.id)) match {
// If they're not equal, then there's a delete request for a record that doesn't exist. So we allow this to process // Each single change has a corresponding recordset id
if(singleChanges.map(_.id).length != recordSetChanges.map(_.id).length && !singleChanges.map(_.typ).contains(UNKNOWN)) { // If they're not equal, then there's a delete request for a record that doesn't exist. So we allow this to process
logger.info(s"Successfully converted SingleChanges [${singleChanges case Some(_) if singleChanges.map(_.id).length != recordSetChanges.map(_.id).length && !singleChanges.map(_.typ).contains(UNKNOWN) =>
.map(_.id)}] to RecordSetChanges [${recordSetChanges.map(_.id)}]") logger.info(s"Successfully converted SingleChanges [${singleChanges
().toRightBatchResult .map(_.id)}] to RecordSetChanges [${recordSetChanges.map(_.id)}]")
} ().toRightBatchResult
else { case Some(change) => BatchConversionError(change).toLeftBatchResult
singleChanges.find(ch => !convertedIds.contains(ch.id)) match { case None =>
case Some(change) => BatchConversionError(change).toLeftBatchResult logger.info(s"Successfully converted SingleChanges [${singleChanges
case None => .map(_.id)}] to RecordSetChanges [${recordSetChanges.map(_.id)}]")
logger.info(s"Successfully converted SingleChanges [${singleChanges ().toRightBatchResult
.map(_.id)}] to RecordSetChanges [${recordSetChanges.map(_.id)}]")
().toRightBatchResult
}
} }
} }

View File

@@ -3724,7 +3724,7 @@ def test_create_batch_with_zone_name_requiring_manual_review(shared_zone_test_co
def test_create_batch_delete_record_that_does_not_exists_completes(shared_zone_test_context): def test_create_batch_delete_record_that_does_not_exists_completes(shared_zone_test_context):
""" """
Test delete record set fails for non-existent record and non-existent record data Test delete record set completes for non-existent record
""" """
client = shared_zone_test_context.ok_vinyldns_client client = shared_zone_test_context.ok_vinyldns_client
ok_zone_name = shared_zone_test_context.ok_zone["name"] ok_zone_name = shared_zone_test_context.ok_zone["name"]
@@ -3739,7 +3739,7 @@ def test_create_batch_delete_record_that_does_not_exists_completes(shared_zone_t
response = client.create_batch_change(batch_change_input, status=202) response = client.create_batch_change(batch_change_input, status=202)
get_batch = client.get_batch_change(response["id"]) get_batch = client.get_batch_change(response["id"])
assert_that(get_batch["changes"][0]["systemMessage"], is_(" This record does not exist." + assert_that(get_batch["changes"][0]["systemMessage"], is_("This record does not exist." +
"No further action is required.")) "No further action is required."))
assert_successful_change_in_error_response(response["changes"][0], input_name=f"delete-non-existent-record.{ok_zone_name}", record_data="1.1.1.1", change_type="DeleteRecordSet") assert_successful_change_in_error_response(response["changes"][0], input_name=f"delete-non-existent-record.{ok_zone_name}", record_data="1.1.1.1", change_type="DeleteRecordSet")

View File

@@ -37,7 +37,7 @@ import vinyldns.core.domain.record._
import vinyldns.core.domain.zone.Zone import vinyldns.core.domain.zone.Zone
class BatchChangeConverterSpec extends AnyWordSpec with Matchers with CatsHelpers { class BatchChangeConverterSpec extends AnyWordSpec with Matchers with CatsHelpers {
private val notExistCompletedMessage: String = " This record does not exist." + private val notExistCompletedMessage: String = "This record does not exist." +
"No further action is required." "No further action is required."
private def makeSingleAddChange( private def makeSingleAddChange(
@@ -545,7 +545,7 @@ class BatchChangeConverterSpec extends AnyWordSpec with Matchers with CatsHelper
savedBatch shouldBe Some(returnedBatch) savedBatch shouldBe Some(returnedBatch)
} }
"set status to complete when deleting a record that does not exists" in { "set status to complete when deleting a record that does not exist" in {
val batchWithBadChange = val batchWithBadChange =
BatchChange( BatchChange(
okUser.id, okUser.id,