當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Node.CleanMetadata方法代碼示例

本文整理匯總了Golang中github.com/tsuru/docker-cluster/cluster.Node.CleanMetadata方法的典型用法代碼示例。如果您正苦於以下問題:Golang Node.CleanMetadata方法的具體用法?Golang Node.CleanMetadata怎麽用?Golang Node.CleanMetadata使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/tsuru/docker-cluster/cluster.Node的用法示例。


在下文中一共展示了Node.CleanMetadata方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: cleanMetadata

func cleanMetadata(n *cluster.Node) map[string]string {
    // iaas-id is ignored because it wasn't created in previous tsuru versions
    // and having nodes with and without it would cause unbalanced metadata
    // errors.
    ignoredMetadata := []string{"iaas-id"}
    metadata := n.CleanMetadata()
    for _, val := range ignoredMetadata {
        delete(metadata, val)
    }
    return metadata
}
開發者ID:tsuru,項目名稱:tsuru,代碼行數:11,代碼來源:auto_scale.go

示例2: healNode

func (h *nodeHealer) healNode(node *cluster.Node) (cluster.Node, error) {
    emptyNode := cluster.Node{}
    failingAddr := node.Address
    nodeMetadata := node.CleanMetadata()
    failingHost := urlToHost(failingAddr)
    failures := node.FailureCount()
    machine, err := iaas.CreateMachineForIaaS(nodeMetadata["iaas"], nodeMetadata)
    if err != nil {
        node.ResetFailures()
        return emptyNode, fmt.Errorf("Can't auto-heal after %d failures for node %s: error creating new machine: %s", failures, failingHost, err.Error())
    }
    err = h.provisioner.getCluster().Unregister(failingAddr)
    if err != nil {
        machine.Destroy()
        return emptyNode, fmt.Errorf("Can't auto-heal after %d failures for node %s: error unregistering old node: %s", failures, failingHost, err.Error())
    }
    newAddr := machine.FormatNodeAddress()
    log.Debugf("New machine created during healing process: %s - Waiting for docker to start...", newAddr)
    createdNode, err := h.provisioner.getCluster().WaitAndRegister(newAddr, nodeMetadata, h.waitTimeNewMachine)
    if err != nil {
        node.ResetFailures()
        h.provisioner.getCluster().Register(failingAddr, nodeMetadata)
        machine.Destroy()
        return emptyNode, fmt.Errorf("Can't auto-heal after %d failures for node %s: error registering new node: %s", failures, failingHost, err.Error())
    }
    var buf bytes.Buffer
    err = h.provisioner.moveContainers(failingHost, "", &buf)
    if err != nil {
        log.Errorf("Unable to move containers, skipping containers healing %q -> %q: %s: %s", failingHost, machine.Address, err.Error(), buf.String())
    }
    failingMachine, err := iaas.FindMachineByIdOrAddress(node.Metadata["iaas-id"], failingHost)
    if err != nil {
        return createdNode, fmt.Errorf("Unable to find failing machine %s in IaaS: %s", failingHost, err.Error())
    }
    err = failingMachine.Destroy()
    if err != nil {
        return createdNode, fmt.Errorf("Unable to destroy machine %s from IaaS: %s", failingHost, err.Error())
    }
    log.Debugf("Done auto-healing node %q, node %q created in its place.", failingHost, machine.Address)
    return createdNode, nil
}
開發者ID:RichardKnop,項目名稱:tsuru,代碼行數:41,代碼來源:healer_node.go

示例3: healNode

func (h *NodeHealer) healNode(node *cluster.Node) (cluster.Node, error) {
    emptyNode := cluster.Node{}
    failingAddr := node.Address
    nodeMetadata := node.CleanMetadata()
    failingHost := net.URLToHost(failingAddr)
    failures := node.FailureCount()
    machine, err := iaas.CreateMachineForIaaS(nodeMetadata["iaas"], nodeMetadata)
    if err != nil {
        node.ResetFailures()
        return emptyNode, fmt.Errorf("Can't auto-heal after %d failures for node %s: error creating new machine: %s", failures, failingHost, err.Error())
    }
    err = h.provisioner.Cluster().Unregister(failingAddr)
    if err != nil {
        machine.Destroy()
        return emptyNode, fmt.Errorf("Can't auto-heal after %d failures for node %s: error unregistering old node: %s", failures, failingHost, err.Error())
    }
    newAddr := machine.FormatNodeAddress()
    log.Debugf("New machine created during healing process: %s - Waiting for docker to start...", newAddr)
    createdNode := cluster.Node{
        Address:        newAddr,
        Metadata:       nodeMetadata,
        CreationStatus: cluster.NodeCreationStatusPending,
    }
    err = h.provisioner.Cluster().Register(createdNode)
    if err != nil {
        node.ResetFailures()
        h.provisioner.Cluster().Register(cluster.Node{Address: failingAddr, Metadata: nodeMetadata})
        machine.Destroy()
        return emptyNode, fmt.Errorf("Can't auto-heal after %d failures for node %s: error registering new node: %s", failures, failingHost, err.Error())
    }
    q, err := queue.Queue()
    if err != nil {
        return emptyNode, err
    }
    jobParams := monsterqueue.JobParams{
        "endpoint": createdNode.Address,
        "machine":  machine.Id,
        "metadata": createdNode.Metadata,
    }
    job, err := q.EnqueueWait(bs.QueueTaskName, jobParams, h.waitTimeNewMachine)
    if err == nil {
        _, err = job.Result()
    }
    if err != nil {
        node.ResetFailures()
        h.provisioner.Cluster().Register(cluster.Node{Address: failingAddr, Metadata: nodeMetadata})
        return emptyNode, fmt.Errorf("Can't auto-heal after %d failures for node %s: error waiting for the bs task: %s", failures, failingHost, err.Error())
    }
    var buf bytes.Buffer
    err = h.provisioner.MoveContainers(failingHost, "", &buf)
    if err != nil {
        log.Errorf("Unable to move containers, skipping containers healing %q -> %q: %s: %s", failingHost, machine.Address, err.Error(), buf.String())
    }
    failingMachine, err := iaas.FindMachineByIdOrAddress(node.Metadata["iaas-id"], failingHost)
    if err != nil {
        return createdNode, fmt.Errorf("Unable to find failing machine %s in IaaS: %s", failingHost, err.Error())
    }
    err = failingMachine.Destroy()
    if err != nil {
        return createdNode, fmt.Errorf("Unable to destroy machine %s from IaaS: %s", failingHost, err.Error())
    }
    log.Debugf("Done auto-healing node %q, node %q created in its place.", failingHost, machine.Address)
    return createdNode, nil
}
開發者ID:zhenruyan,項目名稱:tsuru,代碼行數:64,代碼來源:healer_node.go


注:本文中的github.com/tsuru/docker-cluster/cluster.Node.CleanMetadata方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。