コード例 #1
0
ファイル: sky.go プロジェクト: yahame/skynet
func ListInstances(q *skynet.Query) {
	var regFlag *bool

	if *RegisteredFlag == "true" {
		b := true
		regFlag = &b
	} else if *RegisteredFlag == "false" {
		b := false
		regFlag = &b
	}

	q.Registered = regFlag

	results := q.FindInstances()

	for _, instance := range results {
		registered := ""

		if instance.Registered {
			registered = " [Registered]"
		}

		fmt.Println(instance.Config.ServiceAddr.IPAddress + ":" + strconv.Itoa(instance.Config.ServiceAddr.Port) + " - " + instance.Config.Name + " " + instance.Config.Version + registered)
	}
}
コード例 #2
0
ファイル: subservice.go プロジェクト: arjloo/skynet
func (ss *SubService) removeFromDoozer() {
	q := skynet.Query{
		UUID:       ss.UUID,
		DoozerConn: ss.doozer,
	}

	instances := q.FindInstances()
	for _, instance := range instances {
		ss.doozer.Del(instance.GetConfigPath(), ss.doozer.GetCurrentRevision())
	}
}
コード例 #3
0
ファイル: sky.go プロジェクト: yahame/skynet
func PrintTopology(q *skynet.Query) {
	topology := make(map[string]map[string]map[string]map[string][]*skynet.ServiceInfo)

	results := q.FindInstances()

	// Build topology hash first
	for _, instance := range results {
		if topology[instance.Config.Region] == nil {
			topology[instance.Config.Region] = make(map[string]map[string]map[string][]*skynet.ServiceInfo)
		}

		if topology[instance.Config.Region][instance.Config.ServiceAddr.IPAddress] == nil {
			topology[instance.Config.Region][instance.Config.ServiceAddr.IPAddress] = make(map[string]map[string][]*skynet.ServiceInfo)
		}

		if topology[instance.Config.Region][instance.Config.ServiceAddr.IPAddress][instance.Config.Name] == nil {
			topology[instance.Config.Region][instance.Config.ServiceAddr.IPAddress][instance.Config.Name] = make(map[string][]*skynet.ServiceInfo)
		}

		if topology[instance.Config.Region][instance.Config.ServiceAddr.IPAddress][instance.Config.Name][instance.Config.Version] == nil {
			topology[instance.Config.Region][instance.Config.ServiceAddr.IPAddress][instance.Config.Name][instance.Config.Version] = make([]*skynet.ServiceInfo, 0)
		}

		topology[instance.Config.Region][instance.Config.ServiceAddr.IPAddress][instance.Config.Name][instance.Config.Version] = append(topology[instance.Config.Region][instance.Config.ServiceAddr.IPAddress][instance.Config.Name][instance.Config.Version], instance)
	}

	// Now we can print the correct heirarchy
	for regionName, region := range topology {
		fmt.Println("Region: " + regionName)

		for hostName, host := range region {
			fmt.Println("\tHost: " + hostName)

			for serviceName, service := range host {
				fmt.Println("\t\tService: " + serviceName)

				for versionName, version := range service {
					fmt.Println("\t\t\tVersion: " + versionName)

					for _, instance := range version {
						registered := ""

						if instance.Registered {
							registered = " [Registered]"
						}

						fmt.Println("\t\t\t\t" + instance.Config.ServiceAddr.IPAddress + ":" + strconv.Itoa(instance.Config.ServiceAddr.Port) + registered)
					}
				}
			}
		}
	}
}
コード例 #4
0
ファイル: admin.go プロジェクト: arjloo/skynet
func Unregister(q *skynet.Query) {
	instances := filterDaemon(q.FindInstances())
	for _, instance := range instances {
		cladmin := client.Admin{
			Instance: instance,
		}
		_, err := cladmin.Unregister(skynet.UnregisterRequest{})
		if err != nil {
			config.Log.Error(err.Error())
		}
	}
}
コード例 #5
0
ファイル: admin.go プロジェクト: arjloo/skynet
func AdminStop(q *skynet.Query) {
	instances := q.FindInstances()
	for _, instance := range instances {
		cladmin := client.Admin{
			Instance: instance,
		}
		_, err := cladmin.Stop(skynet.StopRequest{
			WaitForClients: true,
		})
		if err != nil {
			config.Log.Error(err.Error())
		}
	}
}
コード例 #6
0
ファイル: subservice.go プロジェクト: arjloo/skynet
func (ss *SubService) sendRPCStop() {
	q := skynet.Query{
		UUID:       ss.UUID,
		DoozerConn: ss.doozer,
	}
	instances := q.FindInstances()
	for _, instance := range instances {
		cladmin := client.Admin{
			Instance: instance,
		}

		cladmin.Stop(skynet.StopRequest{
			WaitForClients: true,
		})
	}

}
コード例 #7
0
ファイル: service.go プロジェクト: yahame/skynet
func (s *Service) cleanupDoozerEntriesForAddr(addr *skynet.BindAddr) {
	if addr == nil {
		return
	}
	q := skynet.Query{
		Host:       addr.IPAddress,
		Port:       strconv.Itoa(addr.Port),
		DoozerConn: s.doozer(),
	}

	instances := q.FindInstances()

	for _, i := range instances {
		s.Log.Item("Cleaning up old doozer entry with conflicting addr " + addr.String() + "(" + i.GetConfigPath() + ")")
		s.doozer().Del(i.GetConfigPath(), s.doozer().GetCurrentRevision())
	}
}
コード例 #8
0
ファイル: admin.go プロジェクト: arjloo/skynet
func Stop(q *skynet.Query) {
	cl := client.NewClient(&config)

	for _, instance := range filterDaemon(q.FindInstances()) {
		cdaemon := daemon.GetDaemonForService(cl, instance)

		in := daemon.StopSubServiceRequest{UUID: instance.Config.UUID}
		out, err := cdaemon.StopSubService(in)

		if err != nil {
			if strings.HasPrefix(err.Error(), "No such service UUID") {
				// no daemon on the service's machine, shut it down directly
				AdminStop(q)
			} else {
				fmt.Println(err)
			}
		} else {
			stopTemplate.Execute(os.Stdout, out)
		}
	}
}
コード例 #9
0
ファイル: admin.go プロジェクト: arjloo/skynet
func Restart(q *skynet.Query) {
	cl := client.NewClient(&config)

	for _, instance := range filterDaemon(q.FindInstances()) {
		cdaemon := daemon.GetDaemonForService(cl, instance)

		in := daemon.RestartSubServiceRequest{UUID: instance.Config.UUID}
		out, err := cdaemon.RestartSubService(in)

		if err != nil {
			if strings.HasPrefix(err.Error(), "No such service UUID") {
				// Commented out for now, we need to determine if we want to try to restart an unmanaged instance, and support it
				// no daemon on the service's machine, shut it down directly
				//AdminStop(q)
			} else {
				fmt.Println(err)
			}
		} else {
			restartTemplate.Execute(os.Stdout, out)
		}
	}

}