本文整理汇总了Golang中github.com/couchbase/indexing/secondary/common.ClusterInfoCache.GetNodesByServiceType方法的典型用法代码示例。如果您正苦于以下问题:Golang ClusterInfoCache.GetNodesByServiceType方法的具体用法?Golang ClusterInfoCache.GetNodesByServiceType怎么用?Golang ClusterInfoCache.GetNodesByServiceType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/couchbase/indexing/secondary/common.ClusterInfoCache
的用法示例。
在下文中一共展示了ClusterInfoCache.GetNodesByServiceType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getIndexerAdminports
// return adminports for all known indexers.
func getIndexerAdminports(cinfo *common.ClusterInfoCache) ([]string, error) {
iAdminports := make([]string, 0)
for _, node := range cinfo.GetNodesByServiceType("indexAdmin") {
status, err := cinfo.GetNodeStatus(node)
if err != nil {
return nil, err
}
logging.Verbosef("node %v status: %q", node, status)
if status == "healthy" || status == "active" || status == "warmup" {
adminport, err := cinfo.GetServiceAddress(node, "indexAdmin")
if err != nil {
return nil, err
}
iAdminports = append(iAdminports, adminport)
} else {
logging.Warnf("node %v status: %q", node, status)
}
}
return iAdminports, nil
}
示例2: getIndexMetadata
func (m *requestHandlerContext) getIndexMetadata(cinfo *common.ClusterInfoCache,
indexerHostMap map[common.IndexerId]string) (*ClusterIndexMetadata, error) {
if err := cinfo.Fetch(); err != nil {
return nil, err
}
// find all nodes that has a index http service
nids := cinfo.GetNodesByServiceType(common.INDEX_HTTP_SERVICE)
clusterMeta := &ClusterIndexMetadata{Metadata: make([]LocalIndexMetadata, len(nids))}
for i, nid := range nids {
addr, err := cinfo.GetServiceAddress(nid, common.INDEX_HTTP_SERVICE)
if err == nil {
resp, err := getWithAuth(addr + "/getLocalIndexMetadata")
if err != nil {
return nil, errors.New(fmt.Sprintf("Fail to retrieve index definition from url %s", addr))
}
localMeta := new(LocalIndexMetadata)
status := convertResponse(resp, localMeta)
if status == RESP_ERROR {
return nil, errors.New(fmt.Sprintf("Fail to retrieve local metadata from url %s.", addr))
}
indexerHostMap[common.IndexerId(localMeta.IndexerId)] = addr
clusterMeta.Metadata[i] = *localMeta
} else {
return nil, errors.New(fmt.Sprintf("Fail to retrieve http endpoint for index node"))
}
}
return clusterMeta, nil
}
示例3: getIndexStatus
func (m *requestHandlerContext) getIndexStatus(cinfo *common.ClusterInfoCache, bucket string) ([]IndexStatus, []string, error) {
if err := cinfo.Fetch(); err != nil {
return nil, nil, err
}
// find all nodes that has a index http service
nids := cinfo.GetNodesByServiceType(common.INDEX_HTTP_SERVICE)
list := make([]IndexStatus, 0)
failedNodes := make([]string, 0)
for _, nid := range nids {
addr, err := cinfo.GetServiceAddress(nid, common.INDEX_HTTP_SERVICE)
if err == nil {
resp, err := getWithAuth(addr + "/getLocalIndexMetadata")
if err != nil {
failedNodes = append(failedNodes, addr)
continue
}
localMeta := new(LocalIndexMetadata)
status := convertResponse(resp, localMeta)
if status == RESP_ERROR {
failedNodes = append(failedNodes, addr)
continue
}
curl, err := cinfo.GetServiceAddress(nid, "mgmt")
if err != nil {
failedNodes = append(failedNodes, addr)
continue
}
resp, err = getWithAuth(addr + "/stats?async=true")
if err != nil {
failedNodes = append(failedNodes, addr)
continue
}
stats := new(common.Statistics)
status = convertResponse(resp, stats)
if status == RESP_ERROR {
failedNodes = append(failedNodes, addr)
continue
}
for _, defn := range localMeta.IndexDefinitions {
if len(bucket) != 0 && bucket != defn.Bucket {
continue
}
if topology := m.findTopologyByBucket(localMeta.IndexTopologies, defn.Bucket); topology != nil {
state, errStr := topology.GetStatusByDefn(defn.DefnId)
if state != common.INDEX_STATE_DELETED && state != common.INDEX_STATE_NIL {
stateStr := "Not Available"
switch state {
case common.INDEX_STATE_CREATED:
stateStr = "Created"
case common.INDEX_STATE_READY:
stateStr = "Created"
case common.INDEX_STATE_INITIAL:
stateStr = "Building"
case common.INDEX_STATE_CATCHUP:
stateStr = "Building"
case common.INDEX_STATE_ACTIVE:
stateStr = "Ready"
}
if len(errStr) != 0 {
stateStr = "Error"
}
completion := int(0)
key := fmt.Sprintf("%v:%v:build_progress", defn.Bucket, defn.Name)
if progress, ok := stats.ToMap()[key]; ok {
completion = int(progress.(float64))
}
status := IndexStatus{
DefnId: defn.DefnId,
Name: defn.Name,
Bucket: defn.Bucket,
IsPrimary: defn.IsPrimary,
SecExprs: defn.SecExprs,
WhereExpr: defn.WhereExpr,
Status: stateStr,
Error: errStr,
Hosts: []string{curl},
Definition: common.IndexStatement(defn),
Completion: completion,
}
list = append(list, status)
}
//.........这里部分代码省略.........