forked from jlandersen/vscode-kafka
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes jlandersen#123 Signed-off-by: azerr <[email protected]>
- Loading branch information
1 parent
7a0914c
commit c9096ef
Showing
5 changed files
with
136 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Kafka } from "kafkajs"; | ||
import { Cluster, ConnectionOptions } from "../client/client"; | ||
import { ClusterSettings } from "../settings/clusters"; | ||
|
||
export interface ClusterProvider { | ||
id: string; | ||
name?: string; | ||
collectClusters(clusterSettings: ClusterSettings): Promise<Cluster[] | undefined>; | ||
createKafka(connectionOptions: ConnectionOptions): Kafka; | ||
} | ||
|
||
export interface KafkaApi { | ||
registerClusterProvider(provider: ClusterProvider): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Kafka } from "kafkajs"; | ||
import { Cluster, ConnectionOptions, createDefaultKafka } from "../client/client"; | ||
import { ClusterSettings } from "../settings/clusters"; | ||
import { collectDefaultClusters } from "../wizards/clusters"; | ||
import { ClusterProvider } from "./api"; | ||
|
||
const defaultClusterProviderId = 'default'; | ||
|
||
const providers: Map<string, ClusterProvider> = new Map(); | ||
|
||
export function registerClusterProvider(provider: ClusterProvider): void { | ||
providers.set(provider.id, provider); | ||
} | ||
|
||
export function getClusterProvider(clusterProviderId?: string): ClusterProvider | undefined { | ||
return providers.get(clusterProviderId || defaultClusterProviderId); | ||
} | ||
|
||
export function getClusterProviders(): ClusterProvider[] { | ||
return [...providers.values()]; | ||
} | ||
|
||
class DefaultClusterProvider implements ClusterProvider { | ||
id = defaultClusterProviderId; | ||
name = 'Manual'; | ||
createKafka = (connectionOptions: ConnectionOptions): Kafka => createDefaultKafka(connectionOptions); | ||
collectClusters = (clusterSettings: ClusterSettings): Promise<Cluster[] | undefined> => collectDefaultClusters(clusterSettings); | ||
} | ||
|
||
registerClusterProvider(new DefaultClusterProvider()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters