Exemple #1
0
func getHostnameFromURI(uri string) (hostname string, err error) {
	tokens := strings.Split(uri, ":")
	name := strings.Split(tokens[1], "//")
	switch strings.ToLower(name[1]) {
	case "localhost", "127.0.0.1":
		hostname, err = util.ExternalIP()
	default:
		hostname, err = name[1], nil
	}
	return
}
Exemple #2
0
// Create a query node configuration
func NewQueryNode(query_addr string,
	stndln *clustering.StdStandalone,
	opts *clustering.ClOptions) (clustering.QueryNode, errors.Error) {
	ip_addr, err := util.ExternalIP()
	if err != nil {
		ip_addr = "127.0.0.1"
	}
	// Construct query node name from ip addr and http_addr. Assumption that this will be unique
	queryName := ip_addr + query_addr
	queryEndpoint := "http://" + queryName + "/query"
	// TODO : protocol specification: how do we know it will be http?
	adminEndpoint := "http://" + queryName + "/admin"
	return makeZkQueryNodeConfig("", queryName, queryEndpoint, adminEndpoint, stndln, opts), nil
}
func doConfig(s *server.Server, w http.ResponseWriter, req *http.Request) (interface{}, errors.Error) {
	if localConfig.myConfig != nil {
		return localConfig.myConfig, nil
	}
	var self clustering.QueryNode
	ip, err := util.ExternalIP()
	if err != nil {
		return nil, err
	}

	name, er := os.Hostname()
	if er != nil {
		return nil, err
	}

	cm := s.ConfigurationStore().ConfigurationManager()
	clusters, err := cm.GetClusters()
	if err != nil {
		return nil, err
	}

	for _, c := range clusters {
		clm := c.ClusterManager()
		queryNodes, err := clm.GetQueryNodes()
		if err != nil {
			return nil, err
		}

		for _, qryNode := range queryNodes {
			if qryNode.Name() == ip || qryNode.Name() == name {
				self = qryNode
				break
			}
		}
	}
	localConfig.Lock()
	defer localConfig.Unlock()
	localConfig.myConfig = self
	return localConfig.myConfig, nil
}