-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EHN] Add topic creation for RendezvousAssignmentPolicy (#1463)
## Description of changes *Summarize the changes made by this PR.* - Improvements & Bug fixes - This PR adds Pulsar topic creation for RendezvousAssignmentPolicy - New functionality - ... ## Test plan *How are these changes tested?* - [ ] Local testing with Pulsar ## Documentation Changes *Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the [docs repository](https://github.com/chroma-core/docs)?*
- Loading branch information
Showing
6 changed files
with
92 additions
and
3 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
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,44 @@ | ||
package utils | ||
|
||
import ( | ||
"github.com/pingcap/log" | ||
"go.uber.org/zap" | ||
|
||
"github.com/apache/pulsar-client-go/pulsaradmin" | ||
pulsar_utils "github.com/apache/pulsar-client-go/pulsaradmin/pkg/utils" | ||
) | ||
|
||
// This function creates topics in Pulsar. It takes in a list of topics and creates them in pulsar. | ||
// It assumes that the tenant and namespace already exist in Pulsar. | ||
func CreateTopics(pulsarAdminURL string, tenant string, namespace string, topics []string) error { | ||
cfg := &pulsaradmin.Config{ | ||
WebServiceURL: pulsarAdminURL, | ||
} | ||
admin, err := pulsaradmin.NewClient(cfg) | ||
if err != nil { | ||
log.Error("Failed to create pulsar admin client", zap.Error(err)) | ||
return err | ||
} | ||
|
||
for _, topic := range topics { | ||
topicSchema := "persistent://" + tenant + "/" + namespace + "/" + topic | ||
topicName, err := pulsar_utils.GetTopicName(topicSchema) | ||
if err != nil { | ||
log.Error("Failed to get topic name", zap.Error(err)) | ||
return err | ||
} | ||
metadata, err := admin.Topics().GetMetadata(*topicName) | ||
if err != nil { | ||
log.Info("Failed to get topic metadata, needs to create", zap.Error(err)) | ||
} else { | ||
log.Info("Topic already exists", zap.String("topic", topic), zap.Any("metadata", metadata)) | ||
continue | ||
} | ||
err = admin.Topics().Create(*topicName, 1) | ||
if err != nil { | ||
log.Error("Failed to create topic", zap.Error(err)) | ||
return err | ||
} | ||
} | ||
return nil | ||
} |