Example #1
0
func (s *StackDeployScheduler) Registered(driver scheduler.SchedulerDriver, id *mesos.FrameworkID, master *mesos.MasterInfo) {
	Logger.Info("[Registered] framework: %s master: %s:%d", id.GetValue(), master.GetHostname(), master.GetPort())

	s.Storage.FrameworkID = id.GetValue()
	s.Storage.Save()
	s.driver = driver
}
Example #2
0
func MasterInfoToMesosHost(mi *proto.MasterInfo) *MesosHost {
	if mi == nil {
		return &MesosHost{
			Host:         "",
			Ip:           "",
			Port:         0,
			PortString:   "",
			IsLeader:     false,
			IsRegistered: false,
		}
	}

	addr := mi.GetAddress()
	if addr.GetHostname() != "" {
		return &MesosHost{
			Host:         addr.GetHostname(),
			Ip:           addr.GetIp(),
			Port:         int(addr.GetPort()),
			PortString:   fmt.Sprintf("%d", addr.GetPort()),
			IsLeader:     false,
			IsRegistered: false,
		}
	} else {
		log.Debug("Using old protobuf format")
		// Old protobuf format
		return ProtoBufToMesosHost(mi)
	}
}
Example #3
0
func MasterConnStr(masterInfo *mesos.MasterInfo) string {
	ip := make([]byte, 4)
	native.PutUint32(ip, masterInfo.GetIp())
	addr := net.IP(ip).To4().String()
	port := masterInfo.GetPort()
	return fmt.Sprintf("%s:%d", addr, port)
}
Example #4
0
// Registered is called when the Scheduler is Registered
func (s *eremeticScheduler) Registered(driver sched.SchedulerDriver, frameworkID *mesos.FrameworkID, masterInfo *mesos.MasterInfo) {
	log.Debugf("Framework %s registered with master %s", frameworkID.GetValue(), masterInfo.GetHostname())
	if !s.initialised {
		driver.ReconcileTasks([]*mesos.TaskStatus{})
		s.initialised = true
	} else {
		s.Reconcile(driver)
	}
}
func (s *Scheduler) Registered(driver scheduler.SchedulerDriver, id *mesos.FrameworkID, master *mesos.MasterInfo) {
	Logger.Infof("[Registered] framework: %s master: %s:%d", id.GetValue(), master.GetHostname(), master.GetPort())

	s.cluster.frameworkID = id.GetValue()
	s.cluster.Save()

	s.driver = driver
	s.reconcileTasks(true)
}
Example #6
0
// Reregistered is called when the Scheduler is Reregistered
func (s *Scheduler) Reregistered(driver mesossched.SchedulerDriver, masterInfo *mesosproto.MasterInfo) {
	logrus.WithFields(logrus.Fields{
		"master_id": masterInfo.GetId(),
		"master":    masterInfo.GetHostname(),
	}).Debug("Framework re-registered with master.")
	if !s.initialised {
		driver.ReconcileTasks([]*mesosproto.TaskStatus{})
		s.initialised = true
	} else {
		s.Reconcile(driver)
	}
}
Example #7
0
func masterHostPort(info *mesos.MasterInfo) string {
	host := info.GetHostname()

	if host == "" {
		// unpack IPv4
		octets := make([]byte, 4)
		binary.BigEndian.PutUint32(octets, info.GetIp())
		ipv4 := net.IP(octets)
		host = ipv4.String()
	}

	return net.JoinHostPort(host, masterPort(info))
}
Example #8
0
// masterAddr returns an address (ip:port) from the given *mesos.MasterInfo or
// an empty string if it nil.
//
// BUG(tsenart): The byte order of the `ip` field in MasterInfo is platform
// dependent. We assume that Mesos is compiled with the same architecture as
// Mesos-DNS and hence same byte order. If this isn't the case, the address
// returned will be wrong. This only affects Mesos versions < 0.24.0
func masterAddr(info *mesos.MasterInfo) string {
	if info == nil {
		return ""
	}
	ip, port := "", int64(0)
	if addr := info.GetAddress(); addr != nil { // Mesos >= 0.24.0
		ip, port = addr.GetIp(), int64(addr.GetPort())
	} else { // Mesos < 0.24.0
		ipv4 := make([]byte, net.IPv4len)
		byteOrder.PutUint32(ipv4, info.GetIp())
		ip, port = net.IP(ipv4).String(), int64(info.GetPort())
	}
	return net.JoinHostPort(ip, strconv.FormatInt(port, 10))
}
Example #9
0
func (d *ZkLeaderDetector) onLeaderChange(info *mesos.MasterInfo) {
	if info == nil {
		log.Errorln("No leader available in Zookeeper")
	} else {
		leader := ""
		if host := info.GetHostname(); host != "" {
			leader = host
		} else {
			// unpack IPv4
			octets := make([]byte, 4, 4)
			binary.BigEndian.PutUint32(octets, info.GetIp())
			ipv4 := net.IP(octets)
			leader = ipv4.String()
		}
		leader = fmt.Sprintf("%s:%d", leader, info.GetPort())
		log.Infoln("New master in Zookeeper", leader)
		d.newLeader <- &leader
	}
}
Example #10
0
func (m *Mesos) hostFromMasterInfo(mi *mesosproto.MasterInfo) MesosHost {
	var ipstring = ""
	var port = ""

	if mi != nil {
		if host := mi.GetHostname(); host != "" {
			ip, err := net.LookupIP(host)
			if err != nil {
				ipstring = host
			} else {
				for _, i := range ip {
					four := i.To4()
					if four != nil {
						ipstring = i.String()
						break
					}
				}
				// If control reaches here there are no IPv4 addresses
				// returned by net.LookupIP. Use the hostname as ipstring
				//
				ipstring = host
			}
		} else {
			octets := make([]byte, 4, 4)
			binary.BigEndian.PutUint32(octets, mi.GetIp())
			ipv4 := net.IP(octets)
			ipstring = ipv4.String()
		}
	}

	if len(ipstring) > 0 {
		port = fmt.Sprint(mi.GetPort())
	}

	return MesosHost{
		host:     ipstring,
		port:     port,
		isLeader: false,
	}
}
func (u *mesosUpstream) sync() {
	var syncing int32
	syncing = atomic.AddInt32(&u.syncing, 1)
	if syncing > 1 {
		atomic.AddInt32(&u.syncing, -1)
		u.syncWg.Wait()
		return
	}
	u.syncWg.Add(1)
	defer func() {
		u.syncWg.Done()
		atomic.AddInt32(&u.syncing, -1)
		u.lastSync = time.Now()
	}()
	var state mesosState
	var masterHosts []string

	if path, err := url.Parse(u.mesosMaster); err == nil {
		switch path.Scheme {
		case "zk":
			if path.Path == "" || path.Path == "/" {
				log.Printf("[ERROR] no path specified for mesos zk lookup \"%s\"", u.mesosMaster)
				return
			}
			zookeeperPath := path.Path
			if zookeeperPath[0] != '/' {
				zookeeperPath = "/" + zookeeperPath
			}
			if zoo, _, err := zk.Connect(strings.Split(path.Host, ","), 10*time.Second); err == nil {
				defer zoo.Close()
				if children, _, err := zoo.Children(zookeeperPath); err == nil {
					sort.Strings(children)
					for _, child := range children {
						if strings.HasPrefix(child, "info_") {
							if data, _, err := zoo.Get(zookeeperPath + "/" + child); err == nil {
								masterInfo := new(mesosproto.MasterInfo)
								if err := masterInfo.Unmarshal(data); err == nil {
									masterHosts = []string{fmt.Sprintf("%s:%d", masterInfo.GetHostname(), masterInfo.GetPort())}
									break
								} else {
									log.Printf("[ERROR] parsing mesos master from zookeeper. \"%s\"", err.Error())
									return
								}
							} else {
								log.Printf("[ERROR] getting mesos master from zookeeper. \"%s\"", err.Error())
								return
							}
						}
					}
				} else {
					log.Printf("[ERROR] getting mesos masters from zookeeper. \"%s\"", err.Error())
					return
				}
			}
		case "http", "https":
			masterHosts = strings.Split(path.Host, ",")
		default:
			log.Printf("[ERROR] unknown scheme in parsing mesos master url \"%s\"", u.mesosMaster)
			return
		}
	} else {
		masterHosts = strings.Split(u.mesosMaster, ",")
	}

	if len(masterHosts) == 0 {
		log.Printf("[ERROR] No reachable masters.")
		return
	}
	var masterErr error
	for _, host := range masterHosts {
		if resp, err := http.Get("http://" + host + "/state.json"); err == nil {
			defer resp.Body.Close()
			if err := json.NewDecoder(resp.Body).Decode(&state); err == nil {
				masterErr = nil
				break
			} else {
				masterErr = err
			}
		} else {
			masterErr = err
		}
	}
	if masterErr != nil {
		log.Printf("[ERROR] Failed to reach masters. \"%s\"", masterErr.Error())
		return
	}

	if len(state.Frameworks) == 0 {
		log.Println("[WARNING] No frameworks found running.")
		return
	}

	hosts := make(proxy.HostPool, 0, 4)
	for _, framework := range state.Frameworks {
		if framework.Name == u.framework {
			for _, task := range framework.Tasks {
				if task.Name == u.taskName && task.State == "TASK_RUNNING" {
					host := &proxy.UpstreamHost{
						Name:         task.SlaveId,
						Conns:        0,
						Fails:        0,
						FailTimeout:  u.FailTimeout,
						Unhealthy:    false,
						ExtraHeaders: u.proxyHeaders,
						CheckDown: func(upstream *mesosUpstream) proxy.UpstreamHostDownFunc {
							return func(uh *proxy.UpstreamHost) bool {
								if uh.Unhealthy {
									return true
								}
								if uh.Fails >= upstream.MaxFails &&
									upstream.MaxFails != 0 {
									return true
								}
								return false
							}
						}(u),
					}
					if u.Port > 0 {
						host.Name = host.Name + ":" + strconv.Itoa(u.Port)
					} else if u.Port < 0 {
						idx := (u.Port * -1) - 1
						if len(task.Resources.Ports) > 2 {
							portResource := task.Resources.Ports[1 : len(task.Resources.Ports)-1]
							ports := strings.Split(portResource, " ")
							if idx < len(ports) {
								selectedPort := ports[idx]
								if strings.Index(selectedPort, "-") != -1 {
									selectedPort = strings.Split(selectedPort, "-")[0]
									host.Name = host.Name + ":" + selectedPort
								}
							} else {
								continue
							}
						} else {
							continue
						}
					}
					hosts = append(hosts, host)
				}
			}
			break
		}
	}

	for _, host := range hosts {
		id, port := func() (string, string) {
			k := strings.Split(host.Name, ":")
			return k[0], k[1]
		}()
		for _, slave := range state.Slaves {
			if id == slave.Id {
				host.Name = u.Scheme + "://" + slave.Hostname + ":" + port
				break
			}
		}
	}
	oldPool := u.Hosts()
	isSame := len(oldPool) == len(hosts)
	for i, host := range hosts {
		found := false
		for _, oldHost := range oldPool {
			if oldHost.Name == host.Name {
				hosts[i] = oldHost
				found = true
				break
			}
		}
		if !found {
			isSame = false
		}
	}

	for _, host := range hosts {
		if host.ReverseProxy == nil {
			if baseUrl, err := url.Parse(host.Name); err == nil {
				host.ReverseProxy = proxy.NewSingleHostReverseProxy(baseUrl, "")
			} else {
				return
			}
		}
	}

	if !isSame {
		if u.HealthCheck.Path != "" {
			u.healthCheck(hosts)
		}
		u.hosts.Store(hosts)
	}
}
func (sched *testScheduler) Reregistered(dr SchedulerDriver, mi *mesos.MasterInfo) {
	log.Infoln("Sched.Reregistered() called")
	sched.s.Equal(mi.GetIp(), uint32(123456))
	sched.ch <- true
}
func (sched *testScheduler) Registered(dr SchedulerDriver, fw *mesos.FrameworkID, mi *mesos.MasterInfo) {
	log.Infoln("Sched.Registered() called.")
	sched.s.Equal(fw.GetValue(), sched.s.registeredFrameworkId.GetValue(), "driver did not register the expected framework ID")
	sched.s.Equal(mi.GetIp(), uint32(123456))
	sched.ch <- true
}
Example #14
0
func validMasterInfo(info *mesos.MasterInfo) bool {
	return info.GetHostname() != "" || info.GetIp() != 0
}
Example #15
0
func masterString(info *mesos.MasterInfo) string {
	return fmt.Sprintf("Id %v Ip %v Hostname %v Port %v Version %v Pid %v",
		info.GetId(), info.GetIp(), info.GetHostname(), info.GetPort(), info.GetVersion(), info.GetPid())
}
Example #16
0
func (s *Scheduler) Registered(driver scheduler.SchedulerDriver, id *mesos.FrameworkID, master *mesos.MasterInfo) {
	Logger.Infof("[Registered] framework: %s master: %s:%d", id.GetValue(), master.GetHostname(), master.GetPort())

	s.driver = driver
}
Example #17
0
func (sched *Scheduler) Registered(driver sched.SchedulerDriver, frameworkID *mesos.FrameworkID, masterInfo *mesos.MasterInfo) {
	glog.Infof("registered with master %s", masterInfo.GetId())
}
Example #18
0
func (self *MesosManager) Reregistered(driver sched.SchedulerDriver, mi *mesos.MasterInfo) {
	log.Printf("OnReregisterd master:%v:%v", Inet_itoa(mi.GetIp()), mi.GetPort())
}
Example #19
0
func (self *MesosManager) Registered(driver sched.SchedulerDriver, fid *mesos.FrameworkID, mi *mesos.MasterInfo) {
	log.Printf("OnRegisterd master:%v:%v, frameworkId:%v", Inet_itoa(mi.GetIp()), mi.GetPort(), fid.GetValue())

}
Example #20
0
func masterPort(info *mesos.MasterInfo) string {
	return strconv.FormatUint(uint64(info.GetPort()), 10)
}
Example #21
0
func (sched *Scheduler) Reregistered(driver sched.SchedulerDriver, masterInfo *mesos.MasterInfo) {
	glog.Infof("re-registered with master %s", masterInfo.GetId())
}
Example #22
0
func extractMasterAddress(info *mesos.MasterInfo) (host string, port int) {
	if info != nil {
		host = info.GetAddress().GetHostname()
		if host == "" {
			host = info.GetAddress().GetIp()
		}

		if host != "" {
			// use port from Address
			port = int(info.GetAddress().GetPort())
		} else {
			// deprecated: get host and port directly from MasterInfo (and not Address)
			host = info.GetHostname()
			if host == "" {
				host = unpackIPv4(info.GetIp())
			}
			port = int(info.GetPort())
		}
	}
	return
}
Example #23
0
func ProtoBufToMesosHost(mi *proto.MasterInfo) *MesosHost {
	ipstring := ""
	port := ""

	log.WithField("mi.GetHostname()", mi.GetHostname()).Debug("protobuf MasterInfo")
	log.WithField("mi.GetIp()", packedIpToString(mi.GetIp())).Debug("protobuf MasterInfo")
	log.WithField("mi.GetPort()", fmt.Sprint(mi.GetPort())).Debug("protobuf MasterInfo")

	if host := mi.GetHostname(); host != "" {
		if ip, err := net.LookupIP(host); err == nil {
			for _, i := range ip {
				if four := i.To4(); four != nil {
					ipstring = i.String()
					break
				}
			}
		}
	}

	if ipstring == "" {
		ipstring = packedIpToString(mi.GetIp())
	}

	if ipstring == "" {
		ipstring = mi.GetHostname()
	}

	if len(ipstring) > 0 {
		port = fmt.Sprint(mi.GetPort())
	}

	return &MesosHost{
		Host:         mi.GetHostname(),
		Ip:           ipstring,
		Port:         int(mi.GetPort()),
		PortString:   port,
		IsLeader:     false,
		IsRegistered: false,
	}
}
Example #24
0
func (s *Scheduler) Reregistered(driver scheduler.SchedulerDriver, master *mesos.MasterInfo) {
	Logger.Infof("[Reregistered] master: %s:%d", master.GetHostname(), master.GetPort())

	s.driver = driver
}
Example #25
0
// Registered is called when the Scheduler is Registered
func (s *eremeticScheduler) Registered(_ sched.SchedulerDriver, frameworkID *mesos.FrameworkID, masterInfo *mesos.MasterInfo) {
	log.Debugf("Framework %s registered with master %s", frameworkID.GetValue(), masterInfo.GetHostname())
}