mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(pipes): restore a CloudFormation snapshot without re-validating it (#3218)
* fix(pipes): restore a CloudFormation snapshot without re-validating it restorePipe went through the same source validation as UpdatePipe, so a pipe whose persisted configuration predates a rule added since (a Kafka source without TopicName, or a ParallelizationFactor outside 1..10 after #3192) could not be put back after a failed stack update and the resource ended up UPDATE_ROLLBACK_FAILED. Validation now runs on the UpdatePipe path only; a restore writes the configuration that was already accepted. Fixes #3209 * fix(pipes): validate an update against the pipe it mutates UpdatePipe looked the pipe up once to validate the source configuration and writePipeConfiguration looked it up again to mutate it, so a pipe deleted and recreated between the two would be validated as the old pipe and written as the new one. Validate inside writePipeConfiguration on the single retrieved instance, skipped only on the restore path.
This commit is contained in:
1 parent
f7efb71467
commit
d95ed9f8fe
2 files changed
+49
-7
No files matched your search
@@ -141,6 +141,10 @@ public class PipesService implements TagHandler, ResourceProvider {
|
||||
/**
|
||||
* Puts the pipe back to a configuration held in full: a property given as null is cleared, so
|
||||
* the pipe ends up carrying exactly what is passed here and nothing the caller left out.
|
||||
*
|
||||
* <p>The configuration was accepted when the pipe was written, so it is not validated again:
|
||||
* a snapshot that predates a rule added since must still be restorable, or a CloudFormation
|
||||
* rollback would fail on the very pipe it is putting back.
|
||||
*/
|
||||
public Pipe restorePipe(String name, String target, String roleArn, String description,
|
||||
DesiredState desiredState, String enrichment,
|
||||
@@ -155,7 +159,11 @@ public class PipesService implements TagHandler, ResourceProvider {
|
||||
*
|
||||
* <p>With {@code clearUnsetProperties} false, a null property leaves the pipe's value alone:
|
||||
* that is what UpdatePipe promises its callers. With it true, a null property clears the pipe's
|
||||
* value, which is what putting a pipe back to a configuration recorded in full needs.
|
||||
* value, which is what putting a pipe back to a configuration recorded in full needs; that
|
||||
* configuration was accepted when it was written, so only the update path validates.
|
||||
*
|
||||
* <p>Validation runs on the same retrieved pipe the write then mutates, so a pipe replaced
|
||||
* between two lookups cannot be validated as one pipe and updated as another.
|
||||
*/
|
||||
private Pipe writePipeConfiguration(String name, String target, String roleArn, String description,
|
||||
DesiredState desiredState, String enrichment,
|
||||
@@ -167,10 +175,10 @@ public class PipesService implements TagHandler, ResourceProvider {
|
||||
.orElseThrow(() -> new AwsException("NotFoundException",
|
||||
"Pipe " + name + " does not exist.", 404));
|
||||
|
||||
JsonNode effectiveSourceParameters = sourceParameters == null && !clearUnsetProperties
|
||||
? pipe.getSourceParameters()
|
||||
: sourceParameters;
|
||||
validateSourceConfiguration(pipe.getSource(), effectiveSourceParameters);
|
||||
if (!clearUnsetProperties) {
|
||||
validateSourceConfiguration(pipe.getSource(),
|
||||
sourceParameters != null ? sourceParameters : pipe.getSourceParameters());
|
||||
}
|
||||
|
||||
writeProperty(target, clearUnsetProperties, pipe::setTarget);
|
||||
writeProperty(roleArn, clearUnsetProperties, pipe::setRoleArn);
|
||||
|
||||
@@ -25,13 +25,15 @@ class PipesServiceTest {
|
||||
|
||||
private static final ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private AccountAwareStorageBackend<Pipe> storage;
|
||||
private PipesService pipesService;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
storage = AccountAwareStorageBackend.inMemory("000000000000");
|
||||
StorageFactory storageFactory = Mockito.mock(StorageFactory.class);
|
||||
when(storageFactory.create(Mockito.anyString(), Mockito.anyString(), Mockito.any()))
|
||||
.thenReturn(AccountAwareStorageBackend.inMemory("000000000000"));
|
||||
Mockito.doReturn(storage).when(storageFactory)
|
||||
.create(Mockito.anyString(), Mockito.anyString(), Mockito.any());
|
||||
|
||||
RegionResolver regionResolver = new RegionResolver("us-east-1", "000000000000");
|
||||
|
||||
@@ -233,6 +235,38 @@ class PipesServiceTest {
|
||||
assertEquals(PipeState.STOPPED, restored.getCurrentState());
|
||||
}
|
||||
|
||||
/**
|
||||
* A restore puts back a configuration that was accepted when it was written, so it is not run
|
||||
* through the source validation again. A persisted pipe can predate a rule added since, and a
|
||||
* CloudFormation rollback that re-validated its snapshot would fail on the very pipe it is
|
||||
* putting back. The pipe is seeded straight into storage, as one written before the Kafka
|
||||
* TopicName check existed would be.
|
||||
*/
|
||||
@Test
|
||||
void restorePipeDoesNotRevalidateAnAlreadyAcceptedConfiguration() {
|
||||
JsonNode legacyParameters = sourceParameters("""
|
||||
{"SelfManagedKafkaParameters":{"BatchSize":10}}""");
|
||||
Pipe legacy = new Pipe();
|
||||
legacy.setName("legacy-pipe");
|
||||
legacy.setArn("arn:aws:pipes:us-east-1:000000000000:pipe/legacy-pipe");
|
||||
legacy.setSource("smk://broker:9092");
|
||||
legacy.setTarget("arn:aws:sqs:us-east-1:000000000000:target");
|
||||
legacy.setRoleArn("arn:aws:iam::000000000000:role/role");
|
||||
legacy.setDesiredState(DesiredState.RUNNING);
|
||||
legacy.setCurrentState(PipeState.RUNNING);
|
||||
legacy.setSourceParameters(legacyParameters);
|
||||
storage.put("us-east-1::legacy-pipe", legacy);
|
||||
|
||||
Pipe restored = pipesService.restorePipe("legacy-pipe",
|
||||
"arn:aws:sqs:us-east-1:000000000000:target",
|
||||
"arn:aws:iam::000000000000:role/role",
|
||||
null, null, null, legacyParameters, null, null, "us-east-1");
|
||||
|
||||
assertEquals(legacyParameters, restored.getSourceParameters());
|
||||
assertEquals(legacyParameters,
|
||||
pipesService.describePipe("legacy-pipe", "us-east-1").getSourceParameters());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deletePipe() {
|
||||
pipesService.createPipe("del-pipe",
|
||||
|
||||
Reference in new issue
Block a user