コード例 #1
0
ファイル: server.go プロジェクト: sanmiguel/riak-mesos
func (schttp *SchedulerHTTPServer) nodeTypes(w http.ResponseWriter, r *http.Request) {
	schttp.sc.lock.Lock()
	defer schttp.sc.lock.Unlock()
	vars := mux.Vars(r)
	clusterName := vars["cluster"]
	nodeName := vars["node"]
	cluster, assigned := schttp.sc.schedulerState.Clusters[clusterName]
	if !assigned {
		w.WriteHeader(404)
		fmt.Fprintf(w, "Cluster %s not found", clusterName)
		return
	}
	node, assigned := cluster.Nodes[nodeName]
	if !assigned {
		w.WriteHeader(404)
		fmt.Fprintf(w, "Node %s not found", nodeName)
		return
	}
	rexHostname := fmt.Sprintf("%s:%d", node.Hostname, node.TaskData.HTTPPort)
	rexc := rexclient.NewRiakExplorerClient(rexHostname)
	body, err := rexc.GetBucketTypesJSON(node.TaskData.FullyQualifiedNodeName)
	if err != nil {
		w.WriteHeader(503)
		fmt.Fprintln(w, "Unable to read data: ", err)
		return
	}

	w.WriteHeader(200)
	fmt.Fprintf(w, body)
}
コード例 #2
0
ファイル: cluster.go プロジェクト: sanmiguel/riak-mesos
func doLeave(stayingNode *FrameworkRiakNode, leavingNode *FrameworkRiakNode, retry int, maxRetry int) bool {
	if retry > maxRetry {
		log.Infof("Attempted removing %+v to %+v's cluster %+v times and failed.", leavingNode.TaskData.FullyQualifiedNodeName, stayingNode.TaskData.FullyQualifiedNodeName, maxRetry)
		return false
	}

	rexHostname := fmt.Sprintf("%s:%d", stayingNode.Hostname, stayingNode.TaskData.HTTPPort)
	rexc := rexclient.NewRiakExplorerClient(rexHostname)
	// We should try to join against this node
	log.Infof("Removing %+v from %+v's cluster", leavingNode.TaskData.FullyQualifiedNodeName, stayingNode.TaskData.FullyQualifiedNodeName)
	leaveReply, leaveErr := rexc.ForceRemove(stayingNode.TaskData.FullyQualifiedNodeName, leavingNode.TaskData.FullyQualifiedNodeName)
	log.Infof("Triggered force remove: %+v, %+v", leaveReply, leaveErr)
	if leaveReply.ForceRemove.Success == "ok" {
		log.Info("Leave successful")
		return true
	}
	if leaveReply.ForceRemove.Error == "not_member" {
		log.Info("Node already removed")
		return true
	}

	time.Sleep(5 * time.Second)
	return doLeave(stayingNode, leavingNode, retry+1, maxRetry)
}
コード例 #3
0
ファイル: cluster.go プロジェクト: sanmiguel/riak-mesos
func doJoin(oldNode *FrameworkRiakNode, newNode *FrameworkRiakNode, retry int, maxRetry int) bool {
	if retry > maxRetry {
		log.Infof("Attempted joining %+v to %+v %+v times and failed.", newNode.TaskData.FullyQualifiedNodeName, oldNode.TaskData.FullyQualifiedNodeName, maxRetry)
		return false
	}

	rexHostname := fmt.Sprintf("%s:%d", oldNode.Hostname, oldNode.TaskData.HTTPPort)
	rexc := rexclient.NewRiakExplorerClient(rexHostname)
	// We should try to join against this node
	log.Infof("Joining %+v to %+v", newNode.TaskData.FullyQualifiedNodeName, oldNode.TaskData.FullyQualifiedNodeName)
	joinReply, joinErr := rexc.Join(newNode.TaskData.FullyQualifiedNodeName, oldNode.TaskData.FullyQualifiedNodeName)
	log.Infof("Triggered join: %+v, %+v", joinReply, joinErr)
	if joinReply.Join.Success == "ok" {
		log.Info("Join successful")
		return true
	}
	if joinReply.Join.Error == "not_single_node" {
		log.Info("Node already joined")
		return true
	}

	time.Sleep(5 * time.Second)
	return doJoin(oldNode, newNode, retry+1, maxRetry)
}