| 87 | |
| 88 | |
| 89 | class CreateSource(Action): |
| 90 | def __init__(self, capabilities: Capabilities, source: SourceExists) -> None: |
| 91 | self.source = source |
| 92 | super().__init__(capabilities) |
| 93 | |
| 94 | def run(self, c: Composition, state: State) -> None: |
| 95 | envelope = str(self.source.topic.envelope).split(".")[1] |
| 96 | kafka_connection_name = f"{self.source.name}_kafka_conn" |
| 97 | c.testdrive( |
| 98 | dedent(f""" |
| 99 | > CREATE CONNECTION IF NOT EXISTS {self.source.name}_csr_conn |
| 100 | TO CONFLUENT SCHEMA REGISTRY (URL '${{testdrive.schema-registry-url}}'); |
| 101 | |
| 102 | > CREATE CONNECTION IF NOT EXISTS {kafka_connection_name} |
| 103 | TO KAFKA (BROKER '${{testdrive.kafka-addr}}' {'USING SSH TUNNEL zippy_ssh' if self.source.uses_ssh_tunnel else ''}, SECURITY PROTOCOL PLAINTEXT); |
| 104 | |
| 105 | > CREATE SOURCE {self.source.name} |
| 106 | IN CLUSTER {self.source.cluster_name} |
| 107 | FROM KAFKA CONNECTION {kafka_connection_name} |
| 108 | (TOPIC 'testdrive-{self.source.topic.name}-${{testdrive.seed}}') |
| 109 | |
| 110 | > CREATE TABLE {self.source.get_name_for_query()} FROM SOURCE {self.source.name} (REFERENCE "testdrive-{self.source.topic.name}-${{testdrive.seed}}") |
| 111 | FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION {self.source.name}_csr_conn |
| 112 | ENVELOPE {envelope} |
| 113 | """), |
| 114 | mz_service=state.mz_service, |
| 115 | ) |
| 116 | |
| 117 | def provides(self) -> list[Capability]: |
| 118 | return [self.source] |
| 119 | |
| 120 | |
| 121 | class AlterSourceConnection(Action): |
no outgoing calls
no test coverage detected