本文整理汇总了Golang中github.com/couchbase/cbgt.Manager类的典型用法代码示例。如果您正苦于以下问题:Golang Manager类的具体用法?Golang Manager怎么用?Golang Manager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Manager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: InitStaticRouter
func InitStaticRouter(staticDir, staticETag string,
mgr *cbgt.Manager) *mux.Router {
prefix := ""
if mgr != nil {
prefix = mgr.Options()["urlPrefix"]
}
hfsStaticX := http.FileServer(assetFS())
router := mux.NewRouter()
router.StrictSlash(true)
router.Handle(prefix+"/",
http.RedirectHandler(prefix+"/index.html", 302))
router.Handle(prefix+"/index.html",
http.RedirectHandler(prefix+"/staticx/index.html", 302))
router.Handle(prefix+"/static/partials/index/start.html",
http.RedirectHandler(prefix+"/staticx/partials/index/start.html", 302))
router = rest.InitStaticRouterEx(router,
staticDir, staticETag, []string{
prefix + "/indexes",
prefix + "/nodes",
prefix + "/monitor",
prefix + "/manage",
prefix + "/logs",
prefix + "/debug",
}, http.RedirectHandler(prefix+"/staticx/index.html", 302), mgr)
router.PathPrefix(prefix + "/staticx/").Handler(
http.StripPrefix(prefix+"/staticx/", hfsStaticX))
return router
}
示例2: BlevePIndexImplInitRouter
func BlevePIndexImplInitRouter(r *mux.Router, phase string,
mgr *cbgt.Manager) {
prefix := ""
if mgr != nil {
prefix = mgr.Options()["urlPrefix"]
}
if phase == "static.before" {
staticBleveMapping := http.FileServer(bleveMappingUI.AssetFS())
r.PathPrefix(prefix + "/static-bleve-mapping/").Handler(
http.StripPrefix(prefix+"/static-bleve-mapping/",
staticBleveMapping))
bleveMappingUI.RegisterHandlers(r, prefix+"/api")
}
if phase == "manager.after" {
// Using standard bleveHttp handlers for /api/pindex-bleve endpoints.
//
listIndexesHandler := bleveHttp.NewListIndexesHandler()
r.Handle(prefix+"/api/pindex-bleve",
listIndexesHandler).Methods("GET")
getIndexHandler := bleveHttp.NewGetIndexHandler()
getIndexHandler.IndexNameLookup = rest.PIndexNameLookup
r.Handle(prefix+"/api/pindex-bleve/{pindexName}",
getIndexHandler).Methods("GET")
docCountHandler := bleveHttp.NewDocCountHandler("")
docCountHandler.IndexNameLookup = rest.PIndexNameLookup
r.Handle(prefix+"/api/pindex-bleve/{pindexName}/count",
docCountHandler).Methods("GET")
searchHandler := bleveHttp.NewSearchHandler("")
searchHandler.IndexNameLookup = rest.PIndexNameLookup
r.Handle(prefix+"/api/pindex-bleve/{pindexName}/query",
searchHandler).Methods("POST")
docGetHandler := bleveHttp.NewDocGetHandler("")
docGetHandler.IndexNameLookup = rest.PIndexNameLookup
docGetHandler.DocIDLookup = rest.DocIDLookup
r.Handle(prefix+"/api/pindex-bleve/{pindexName}/doc/{docID}",
docGetHandler).Methods("GET")
debugDocHandler := bleveHttp.NewDebugDocumentHandler("")
debugDocHandler.IndexNameLookup = rest.PIndexNameLookup
debugDocHandler.DocIDLookup = rest.DocIDLookup
r.Handle(prefix+"/api/pindex-bleve/{pindexName}/docDebug/{docID}",
debugDocHandler).Methods("GET")
listFieldsHandler := bleveHttp.NewListFieldsHandler("")
listFieldsHandler.IndexNameLookup = rest.PIndexNameLookup
r.Handle(prefix+"/api/pindex-bleve/{pindexName}/fields",
listFieldsHandler).Methods("GET")
}
}
示例3: InitStaticRouterEx
// InitStaticRouterEx is like InitStaticRouter, but with optional
// manager parameter for more options.
func InitStaticRouterEx(r *mux.Router, staticDir, staticETag string,
pages []string, pagesHandler http.Handler,
mgr *cbgt.Manager) *mux.Router {
prefix := ""
if mgr != nil {
prefix = mgr.Options()["urlPrefix"]
}
PIndexTypesInitRouter(r, "static.before", mgr)
var s http.FileSystem
if staticDir != "" {
if _, err := os.Stat(staticDir); err == nil {
log.Printf("http: serving assets from staticDir: %s", staticDir)
s = http.Dir(staticDir)
}
}
if s == nil {
log.Printf("http: serving assets from embedded data")
s = AssetFS()
}
r.PathPrefix(prefix + "/static/").Handler(
http.StripPrefix(prefix+"/static/",
ETagFileHandler{http.FileServer(s), staticETag}))
// Bootstrap UI insists on loading templates from this path.
r.PathPrefix(prefix + "/template/").Handler(
http.StripPrefix(prefix+"/template/",
ETagFileHandler{http.FileServer(s), staticETag}))
// If client ask for any of the pages, redirect.
for _, p := range pages {
if pagesHandler != nil {
r.PathPrefix(p).Handler(pagesHandler)
} else {
r.PathPrefix(p).Handler(RewriteURL("/", http.FileServer(s)))
}
}
r.Handle(prefix+"/index.html",
http.RedirectHandler(prefix+"/static/index.html", 302))
r.Handle(prefix+"/",
http.RedirectHandler(prefix+"/static/index.html", 302))
PIndexTypesInitRouter(r, "static.after", mgr)
return r
}
示例4: NewQueryHandler
func NewQueryHandler(mgr *cbgt.Manager) *QueryHandler {
slowQueryLogTimeout := time.Duration(0)
slowQueryLogTimeoutV := mgr.Options()["slowQueryLogTimeout"]
if slowQueryLogTimeoutV != "" {
d, err := time.ParseDuration(slowQueryLogTimeoutV)
if err == nil {
slowQueryLogTimeout = d
}
}
return &QueryHandler{
mgr: mgr,
slowQueryLogTimeout: slowQueryLogTimeout,
}
}
示例5: bleveIndexAlias
// Returns a bleve.IndexAlias that represents all the PIndexes for the
// index, including perhaps bleve remote client PIndexes.
//
// TODO: Perhaps need a tighter check around indexUUID, as the current
// implementation might have a race where old pindexes with a matching
// (but invalid) indexUUID might be hit.
//
// TODO: If this returns an error, perhaps the caller somewhere up the
// chain should close the cancelCh to help stop any other inflight
// activities.
func bleveIndexAlias(mgr *cbgt.Manager, indexName, indexUUID string,
ensureCanRead bool, consistencyParams *cbgt.ConsistencyParams,
cancelCh <-chan bool) (bleve.IndexAlias, error) {
planPIndexNodeFilter := cbgt.PlanPIndexNodeOk
if ensureCanRead {
planPIndexNodeFilter = cbgt.PlanPIndexNodeCanRead
}
localPIndexes, remotePlanPIndexes, err :=
mgr.CoveringPIndexes(indexName, indexUUID, planPIndexNodeFilter,
"queries")
if err != nil {
return nil, fmt.Errorf("bleve: bleveIndexAlias, err: %v", err)
}
alias := bleve.NewIndexAlias()
for _, remotePlanPIndex := range remotePlanPIndexes {
baseURL := "http://" + remotePlanPIndex.NodeDef.HostPort +
"/api/pindex/" + remotePlanPIndex.PlanPIndex.Name
alias.Add(&IndexClient{
QueryURL: baseURL + "/query",
CountURL: baseURL + "/count",
Consistency: consistencyParams,
// TODO: Propagate auth to remote client.
})
}
// TODO: Should kickoff remote queries concurrently before we wait.
err = cbgt.ConsistencyWaitGroup(indexName, consistencyParams,
cancelCh, localPIndexes,
func(localPIndex *cbgt.PIndex) error {
bindex, ok := localPIndex.Impl.(bleve.Index)
if !ok || bindex == nil ||
!strings.HasPrefix(localPIndex.IndexType, "bleve") {
return fmt.Errorf("bleve: wrong type, localPIndex: %#v",
localPIndex)
}
alias.Add(bindex)
return nil
})
if err != nil {
return nil, err
}
return alias, nil
}
示例6: CheckAPIAuth
func CheckAPIAuth(mgr *cbgt.Manager,
w http.ResponseWriter, req *http.Request, path string) (allowed bool) {
authType := ""
if mgr != nil && mgr.Options() != nil {
authType = mgr.Options()["authType"]
}
if authType == "" {
return true
}
if authType != "cbauth" {
return false
}
creds, err := cbauth.AuthWebCreds(req)
if err != nil {
http.Error(w, fmt.Sprintf("rest_auth: cbauth.AuthWebCreds,"+
" err: %v ", err), 403)
return false
}
perms, err := preparePerms(mgr, req, req.Method, path)
if err != nil {
http.Error(w, fmt.Sprintf("rest_auth: preparePerm,"+
" err: %v ", err), 403)
return false
}
for _, perm := range perms {
allowed, err = creds.IsAllowed(perm)
if err != nil {
http.Error(w, fmt.Sprintf("rest_auth: cbauth.IsAllowed,"+
" err: %v ", err), 403)
return false
}
if !allowed {
cbauth.SendForbidden(w, perm)
return false
}
}
return true
}
示例7: retrieveCBGTPartitions
func (k *kvChangeIndex) retrieveCBGTPartitions() (partitionDef base.PartitionStorageSet, err error) {
var manager *cbgt.Manager
if k.context != nil {
manager = k.context.BucketSpec.CbgtContext.Manager
} else {
return nil, errors.New("Unable to retrieve CBGT partitions - no database context")
}
if manager == nil {
return nil, errors.New("Unable to retrieve CBGT partitions - no CBGT manager")
}
_, planPIndexesByName, _ := manager.GetPlanPIndexes(true)
indexName := k.context.GetCBGTIndexNameForBucket(k.context.Bucket)
pindexes := planPIndexesByName[indexName]
for _, pIndex := range pindexes {
vbStrings := strings.Split(pIndex.SourcePartitions, ",")
// convert string vbNos to uint16
vbNos := make([]uint16, len(vbStrings))
for i := 0; i < len(vbStrings); i++ {
vbNumber, err := strconv.ParseUint(vbStrings[i], 10, 16)
if err != nil {
base.LogFatal("Error creating index partition definition - unable to parse vbucket number %s as integer:%v", vbStrings[i], err)
}
vbNos[i] = uint16(vbNumber)
}
entry := base.PartitionStorage{
Index: uint16(0), // see below for index assignment
Uuid: pIndex.UUID,
VbNos: vbNos,
}
partitionDef = append(partitionDef, entry)
}
// NOTE: the ordering of pindexes returned by manager.GetPlanPIndexes isn't fixed (it's doing a map iteration somewhere).
// The mapping from UUID to VbNos will always be consistent. Sorting by UUID to maintain a consistent index ordering,
// then assigning index values.
partitionDef.Sort()
for i := 0; i < len(partitionDef); i++ {
partitionDef[i].Index = uint16(i)
}
return partitionDef, nil
}
示例8: bleveIndexTargets
func bleveIndexTargets(mgr *cbgt.Manager, indexName, indexUUID string,
ensureCanRead bool, consistencyParams *cbgt.ConsistencyParams,
cancelCh <-chan bool, collector BleveIndexCollector) error {
planPIndexNodeFilter := cbgt.PlanPIndexNodeOk
if ensureCanRead {
planPIndexNodeFilter = cbgt.PlanPIndexNodeCanRead
}
localPIndexes, remotePlanPIndexes, err :=
mgr.CoveringPIndexes(indexName, indexUUID, planPIndexNodeFilter,
"queries")
if err != nil {
return fmt.Errorf("bleve: bleveIndexTargets, err: %v", err)
}
prefix := mgr.Options()["urlPrefix"]
for _, remotePlanPIndex := range remotePlanPIndexes {
baseURL := "http://" + remotePlanPIndex.NodeDef.HostPort +
prefix + "/api/pindex/" + remotePlanPIndex.PlanPIndex.Name
collector.Add(&IndexClient{
name: fmt.Sprintf("IndexClient - %s", baseURL),
QueryURL: baseURL + "/query",
CountURL: baseURL + "/count",
Consistency: consistencyParams,
// TODO: Propagate auth to remote client.
})
}
// TODO: Should kickoff remote queries concurrently before we wait.
return cbgt.ConsistencyWaitGroup(indexName, consistencyParams,
cancelCh, localPIndexes,
func(localPIndex *cbgt.PIndex) error {
bindex, ok := localPIndex.Impl.(bleve.Index)
if !ok || bindex == nil ||
!strings.HasPrefix(localPIndex.IndexType, "fulltext-index") {
return fmt.Errorf("bleve: wrong type, localPIndex: %#v",
localPIndex)
}
collector.Add(bindex)
return nil
})
}
示例9: NewRESTRouter
// NewRESTRouter creates a mux.Router initialized with the REST API
// and web UI routes. See also InitStaticRouter and InitRESTRouter if
// you need finer control of the router initialization.
func NewRESTRouter(versionMain string, mgr *cbgt.Manager,
staticDir, staticETag string, mr *cbgt.MsgRing,
assetDir func(name string) ([]string, error),
asset func(name string) ([]byte, error)) (
*mux.Router, map[string]RESTMeta, error) {
prefix := mgr.Options()["urlPrefix"]
r := mux.NewRouter()
r.StrictSlash(true)
r = InitStaticRouterEx(r,
staticDir, staticETag, []string{
prefix + "/indexes",
prefix + "/nodes",
prefix + "/monitor",
prefix + "/manage",
prefix + "/logs",
prefix + "/debug",
}, nil, mgr)
return InitRESTRouter(r, versionMain, mgr,
staticDir, staticETag, mr, assetDir, asset)
}
示例10: InitStaticRouter
func InitStaticRouter(staticDir, staticETag string,
mgr *cbgt.Manager) *mux.Router {
router := mux.NewRouter()
router.StrictSlash(true)
showUI := true
if mgr != nil && mgr.Options()["hideUI"] != "" {
hideUI, err := strconv.ParseBool(mgr.Options()["hideUI"])
if err == nil && hideUI {
showUI = false
}
}
if showUI {
prefix := ""
if mgr != nil {
prefix = mgr.Options()["urlPrefix"]
}
hfsStaticX := http.FileServer(assetFS())
router.Handle(prefix+"/",
http.RedirectHandler(prefix+"/index.html", 302))
router.Handle(prefix+"/index.html",
http.RedirectHandler(prefix+"/staticx/index.html", 302))
router.Handle(prefix+"/static/partials/index/start.html",
http.RedirectHandler(prefix+"/staticx/partials/index/start.html", 302))
router = rest.InitStaticRouterEx(router,
staticDir, staticETag, []string{
prefix + "/indexes",
prefix + "/nodes",
prefix + "/monitor",
prefix + "/manage",
prefix + "/logs",
prefix + "/debug",
}, http.RedirectHandler(prefix+"/staticx/index.html", 302), mgr)
router.PathPrefix(prefix + "/staticx/").Handler(
http.StripPrefix(prefix+"/staticx/", hfsStaticX))
}
return router
}
示例11: WriteManagerStatsJSON
// WriteManagerStatsJSON writes JSON stats for a manager, and is
// optionally focus'able on a particular indexName.
func WriteManagerStatsJSON(mgr *cbgt.Manager, w io.Writer,
indexName string) error {
feeds, pindexes := mgr.CurrentMaps()
feedNames := make([]string, 0, len(feeds))
for feedName := range feeds {
feedNames = append(feedNames, feedName)
}
sort.Strings(feedNames)
pindexNames := make([]string, 0, len(pindexes))
for pindexName := range pindexes {
pindexNames = append(pindexNames, pindexName)
}
sort.Strings(pindexNames)
feedStats := make(map[string][]byte)
for _, feedName := range feedNames {
var buf bytes.Buffer
err := feeds[feedName].Stats(&buf)
if err != nil {
return fmt.Errorf("feed stats err: %v", err)
}
feedStats[feedName] = buf.Bytes()
}
pindexStats := make(map[string][]byte)
for _, pindexName := range pindexNames {
var buf bytes.Buffer
err := pindexes[pindexName].Dest.Stats(&buf)
if err != nil {
return fmt.Errorf("pindex stats err: %v", err)
}
pindexStats[pindexName] = buf.Bytes()
}
w.Write(cbgt.JsonOpenBrace)
first := true
w.Write(statsFeedsPrefix)
for _, feedName := range feedNames {
if indexName == "" || indexName == feeds[feedName].IndexName() {
if !first {
w.Write(cbgt.JsonComma)
}
first = false
w.Write(statsNamePrefix)
w.Write([]byte(feedName))
w.Write(statsNameSuffix)
w.Write(feedStats[feedName])
}
}
w.Write(cbgt.JsonCloseBraceComma)
first = true
w.Write(statsPIndexesPrefix)
for _, pindexName := range pindexNames {
if indexName == "" || indexName == pindexes[pindexName].IndexName {
if !first {
w.Write(cbgt.JsonComma)
}
first = false
w.Write(statsNamePrefix)
w.Write([]byte(pindexName))
w.Write(statsNameSuffix)
w.Write(pindexStats[pindexName])
}
}
w.Write(cbgt.JsonCloseBrace)
if indexName == "" {
w.Write(statsManagerPrefix)
var mgrStats cbgt.ManagerStats
mgr.StatsCopyTo(&mgrStats)
mgrStatsJSON, err := json.Marshal(&mgrStats)
if err == nil && len(mgrStatsJSON) > 0 {
w.Write(mgrStatsJSON)
} else {
w.Write(cbgt.JsonNULL)
}
}
w.Write(cbgt.JsonCloseBrace)
return nil
}
示例12: initIndexPartitions
func (k *kvChangeIndex) initIndexPartitions() (*base.IndexPartitions, error) {
k.indexPartitionsLock.Lock()
defer k.indexPartitionsLock.Unlock()
// Check if it's been initialized while we waited for the lock
if k.indexPartitions != nil {
return k.indexPartitions, nil
}
var partitionDef []base.PartitionStorage
// First attempt to load from the bucket
value, _, err := k.reader.indexReadBucket.GetRaw(base.KIndexPartitionKey)
indexExpvars.Add("get_indexPartitionMap", 1)
if err == nil {
if err = json.Unmarshal(value, &partitionDef); err != nil {
return nil, err
}
}
// If unable to load from index bucket - attempt to initialize based on cbgt partitions
if partitionDef == nil {
var manager *cbgt.Manager
if k.context != nil {
manager = k.context.BucketSpec.CbgtContext.Manager
} else {
return nil, errors.New("Unable to determine partition map for index - not found in index, and no database context")
}
if manager == nil {
return nil, errors.New("Unable to determine partition map for index - not found in index, and no CBGT manager")
}
_, planPIndexesByName, _ := manager.GetPlanPIndexes(true)
indexName := k.context.GetCBGTIndexNameForBucket(k.context.Bucket)
pindexes := planPIndexesByName[indexName]
for index, pIndex := range pindexes {
vbStrings := strings.Split(pIndex.SourcePartitions, ",")
// convert string vbNos to uint16
vbNos := make([]uint16, len(vbStrings))
for i := 0; i < len(vbStrings); i++ {
vbNumber, err := strconv.ParseUint(vbStrings[i], 10, 16)
if err != nil {
base.LogFatal("Error creating index partition definition - unable to parse vbucket number %s as integer:%v", vbStrings[i], err)
}
vbNos[i] = uint16(vbNumber)
}
entry := base.PartitionStorage{
Index: uint16(index),
Uuid: pIndex.UUID,
VbNos: vbNos,
}
partitionDef = append(partitionDef, entry)
}
// Persist to bucket
value, err = json.Marshal(partitionDef)
if err != nil {
return nil, err
}
k.reader.indexReadBucket.SetRaw(base.KIndexPartitionKey, 0, value)
}
// Create k.indexPartitions based on partitionDef
k.indexPartitions = base.NewIndexPartitions(partitionDef)
return k.indexPartitions, nil
}
示例13: InitRESTRouterEx
// InitRESTRouter initializes a mux.Router with REST API routes with
// extra option.
func InitRESTRouterEx(r *mux.Router, versionMain string,
mgr *cbgt.Manager, staticDir, staticETag string,
mr *cbgt.MsgRing,
assetDir func(name string) ([]string, error),
asset func(name string) ([]byte, error),
options map[string]interface{}) (
*mux.Router, map[string]RESTMeta, error) {
var authHandler func(http.Handler) http.Handler
mapRESTPathStats := map[string]*RESTPathStats{} // Keyed by path spec.
if options != nil {
if v, ok := options["auth"]; ok {
authHandler, ok = v.(func(http.Handler) http.Handler)
if !ok {
return nil, nil, fmt.Errorf("rest: auth function invalid")
}
}
if v, ok := options["mapRESTPathStats"]; ok {
mapRESTPathStats, ok = v.(map[string]*RESTPathStats)
if !ok {
return nil, nil, fmt.Errorf("rest: mapRESTPathStats invalid")
}
}
}
prefix := mgr.Options()["urlPrefix"]
PIndexTypesInitRouter(r, "manager.before", mgr)
meta := map[string]RESTMeta{}
handle := func(path string, method string, h http.Handler,
opts map[string]string) {
opts["_path"] = path
if a, ok := h.(RESTOpts); ok {
a.RESTOpts(opts)
}
prefixPath := prefix + path
restMeta := RESTMeta{prefixPath, method, opts}
meta[prefixPath+" "+RESTMethodOrds[method]+method] = restMeta
h = &HandlerWithRESTMeta{
h: h,
RESTMeta: &restMeta,
pathStats: mapRESTPathStats[path],
focusName: PathFocusName(path),
}
if authHandler != nil {
h = authHandler(h)
}
r.Handle(prefixPath, h).Methods(method).Name(prefixPath)
}
handle("/api/index", "GET", NewListIndexHandler(mgr),
map[string]string{
"_category": "Indexing|Index definition",
"_about": `Returns all index definitions as JSON.`,
"version introduced": "0.0.1",
})
handle("/api/index/{indexName}", "PUT", NewCreateIndexHandler(mgr),
map[string]string{
"_category": "Indexing|Index definition",
"_about": `Creates/updates an index definition.`,
"version introduced": "0.0.1",
})
handle("/api/index/{indexName}", "DELETE", NewDeleteIndexHandler(mgr),
map[string]string{
"_category": "Indexing|Index definition",
"_about": `Deletes an index definition.`,
"version introduced": "0.0.1",
})
handle("/api/index/{indexName}", "GET", NewGetIndexHandler(mgr),
map[string]string{
"_category": "Indexing|Index definition",
"_about": `Returns the definition of an index as JSON.`,
"version introduced": "0.0.1",
})
if mgr == nil || mgr.TagsMap() == nil || mgr.TagsMap()["queryer"] {
handle("/api/index/{indexName}/count", "GET",
NewCountHandler(mgr),
map[string]string{
"_category": "Indexing|Index querying",
"_about": `Returns the count of indexed documents.`,
"version introduced": "0.0.1",
})
handle("/api/index/{indexName}/query", "POST",
NewQueryHandler(mgr,
mapRESTPathStats["/api/index/{indexName}/query"]),
map[string]string{
"_category": "Indexing|Index querying",
"_about": `Queries an index.`,
"version introduced": "0.2.0",
})
}
handle("/api/index/{indexName}/planFreezeControl/{op}", "POST",
//.........这里部分代码省略.........
示例14: bleveIndexAliasForUserIndexAlias
// The indexName/indexUUID is for a user-defined index alias.
//
// TODO: One day support user-defined aliases for non-bleve indexes.
func bleveIndexAliasForUserIndexAlias(mgr *cbgt.Manager,
indexName, indexUUID string, ensureCanRead bool,
consistencyParams *cbgt.ConsistencyParams,
cancelCh <-chan bool) (
bleve.IndexAlias, error) {
alias := bleve.NewIndexAlias()
indexDefs, _, err := cbgt.CfgGetIndexDefs(mgr.Cfg())
if err != nil {
return nil, fmt.Errorf("alias: could not get indexDefs,"+
" indexName: %s, err: %v", indexName, err)
}
num := 0
var fillAlias func(aliasName, aliasUUID string) error
fillAlias = func(aliasName, aliasUUID string) error {
aliasDef := indexDefs.IndexDefs[aliasName]
if aliasDef == nil {
return fmt.Errorf("alias: could not get aliasDef,"+
" aliasName: %s, indexName: %s",
aliasName, indexName)
}
if aliasDef.Type != "alias" {
return fmt.Errorf("alias: not alias type: %s,"+
" aliasName: %s, indexName: %s",
aliasDef.Type, aliasName, indexName)
}
if aliasUUID != "" &&
aliasUUID != aliasDef.UUID {
return fmt.Errorf("alias: mismatched aliasUUID: %s,"+
" aliasDef.UUID: %s, aliasName: %s, indexName: %s",
aliasUUID, aliasDef.UUID, aliasName, indexName)
}
params := AliasParams{}
err := json.Unmarshal([]byte(aliasDef.Params), ¶ms)
if err != nil {
return fmt.Errorf("alias: could not parse aliasDef.Params: %s,"+
" aliasName: %s, indexName: %s",
aliasDef.Params, aliasName, indexName)
}
for targetName, targetSpec := range params.Targets {
if num > maxAliasTargets {
return fmt.Errorf("alias: too many alias targets,"+
" perhaps there's a cycle,"+
" aliasName: %s, indexName: %s",
aliasName, indexName)
}
targetDef := indexDefs.IndexDefs[targetName]
if targetDef == nil {
return fmt.Errorf("alias: the alias depends upon"+
" a target index that does not exist,"+
" targetName: %q, aliasName: %q",
targetName, aliasName)
}
if targetSpec.IndexUUID != "" &&
targetSpec.IndexUUID != targetDef.UUID {
return fmt.Errorf("alias: mismatched targetSpec.UUID: %s,"+
" targetDef.UUID: %s, targetName: %s,"+
" aliasName: %s, indexName: %s",
targetSpec.IndexUUID, targetDef.UUID, targetName,
aliasName, indexName)
}
// TODO: Convert to registered callbacks instead of if-else-if.
if targetDef.Type == "alias" {
err = fillAlias(targetName, targetSpec.IndexUUID)
if err != nil {
return err
}
} else if strings.HasPrefix(targetDef.Type, "bleve") {
subAlias, err := bleveIndexAlias(mgr, targetName,
targetSpec.IndexUUID, ensureCanRead,
consistencyParams, cancelCh)
if err != nil {
return err
}
alias.Add(subAlias)
num += 1
} else {
return fmt.Errorf("alias: unsupported target type: %s,"+
" targetName: %s, aliasName: %s, indexName: %s",
targetDef.Type, targetName, aliasName, indexName)
}
}
return nil
}
err = fillAlias(indexName, indexUUID)
if err != nil {
return nil, err
}
//.........这里部分代码省略.........
示例15: testCreateIndex
func testCreateIndex(t *testing.T,
mgr *cbgt.Manager,
indexName string,
params map[string]string,
waitUntilEmptyCfgEventsIndexDefs func()) {
sourceType := "primary"
if params["sourceType"] != "" {
sourceType = params["sourceType"]
}
if params[indexName+".sourceType"] != "" {
sourceType = params[indexName+".sourceType"]
}
sourceName := "default"
if params["sourceName"] != "" {
sourceName = params["sourceName"]
}
if params[indexName+".sourceName"] != "" {
sourceName = params[indexName+".sourceName"]
}
sourceUUID := ""
if params["sourceUUID"] != "" {
sourceUUID = params["sourceUUID"]
}
if params[indexName+".sourceUUID"] != "" {
sourceUUID = params[indexName+".sourceUUID"]
}
sourceParams := `{"numPartitions":4}`
if params["sourceParams"] != "" {
sourceParams = params["sourceParams"]
}
if params[indexName+".sourceParams"] != "" {
sourceParams = params[indexName+".sourceParams"]
}
indexType := "blackhole"
if params["indexType"] != "" {
indexType = params["indexType"]
}
if params[indexName+".indexType"] != "" {
indexType = params[indexName+".indexType"]
}
indexParams := ""
if params["indexParams"] != "" {
indexParams = params["indexParams"]
}
if params[indexName+".indexParams"] != "" {
indexParams = params[indexName+".indexParams"]
}
prevIndexUUID := ""
if params["prevIndexUUID"] != "" {
prevIndexUUID = params["prevIndexUUID"]
}
if params[indexName+".prevIndexUUID"] != "" {
prevIndexUUID = params[indexName+".prevIndexUUID"]
}
planParams := cbgt.PlanParams{
MaxPartitionsPerPIndex: 1,
}
waitUntilEmptyCfgEventsIndexDefs()
err := mgr.CreateIndex(
sourceType, sourceName, sourceUUID, sourceParams,
indexType, indexName, indexParams,
planParams,
prevIndexUUID)
if err != nil {
t.Errorf("expected no err, got: %#v", err)
}
waitUntilEmptyCfgEventsIndexDefs()
}