Exemple #1
0
// newClient initialises a new Client
func newClient() Client {
	c := &client{}

	uuid, _ := uuid.NewV4()
	c.instanceID = "client-" + uuid.String()
	c.responses = &inflight{m: make(map[string]chan *Response)}
	c.defaults = Options{"retries": 2}
	c.timeout = NewTimeout(c)

	c.hostname, _ = os.Hostname()
	c.az, _ = plutil.GetAwsAZName()

	return c
}
Exemple #2
0
func init() {
	// Set defaults for top level vars
	ServiceName = "com.hailocab.unknown-service"
	ServiceVersion = 20140101000000
	ServiceType = "h2.unknown"

	var err error
	if hostname, err = os.Hostname(); err != nil {
		hostname = "localhost.unknown"
	}

	if uuid, err := uuid.NewV4(); err != nil {
		InstanceID = newUuid()
	} else {
		InstanceID = uuid.String()
	}

	AzName, _ = util.GetAwsAZName()
}
Exemple #3
0
func init() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	postConnHdlrs = make([]PostConnectHandler, 0)

	// get boxen AMQP config from environment
	if configDir = os.Getenv("BOXEN_CONFIG_DIR"); configDir == "" {
		configDir = "/opt/hailo/etc"
	}

	configFile := filepath.Join(configDir, "seelog.xml")
	loadLogConfig(configFile)

	var err error
	hostname, err = os.Hostname()
	if err != nil {
		log.Criticalf("[Server] Unable to determine hostname: %v", err)
		panic(err)
	}
	az, _ = plutil.GetAwsAZName()
}
Exemple #4
0
// callDiscoveryService sends off a request to register or unregister to the discovery service
func (self *discovery) callDiscoveryService(action string, successState bool) error {
	log.Infof("[Server] Attempting to %s with the discovery service...", action)

	azName, _ := util.GetAwsAZName()
	regSize := reg.size()
	machineClass := os.Getenv("H2O_MACHINE_CLASS")

	endpoints := make([]*register.MultiRequest_Endpoint, regSize)
	i := 0
	for _, endpoint := range reg.iterate() {
		endpoints[i] = &register.MultiRequest_Endpoint{
			Name:      proto.String(endpoint.Name),
			Mean:      proto.Int32(endpoint.Mean),
			Upper95:   proto.Int32(endpoint.Upper95),
			Subscribe: proto.String(endpoint.Subscribe),
		}

		i++
	}

	service := &dscShared.Service{
		Name:        proto.String(Name),
		Description: proto.String(Description),
		Version:     proto.Uint64(Version),
		Source:      proto.String(Source),
		OwnerEmail:  proto.String(OwnerEmail),
		OwnerMobile: proto.String(OwnerMobile),
		OwnerTeam:   proto.String(OwnerTeam),
	}

	request, err := ScopedRequest(
		"com.hailocab.kernel.discovery",
		action,
		&register.MultiRequest{
			InstanceId:   proto.String(InstanceID),
			Hostname:     proto.String(self.hostname),
			MachineClass: proto.String(machineClass),
			AzName:       proto.String(azName),
			Service:      service,
			Endpoints:    endpoints,
		},
	)

	if err != nil {
		log.Warnf("[Server] Failed to build request when %sing services", action)
		return err
	}

	// explicitly define timeout, since we're happy to wait
	clientOptions := client.Options{"retries": 0, "timeout": 5 * time.Second}

	rsp := &register.Response{}
	if err := client.Req(request, rsp, clientOptions); err != nil {
		log.Warnf("[Server] Failed to %s services: %v", action, err)
		return err
	}

	// ok -- all done!
	self.connected = successState
	log.Infof("[Server] Successfully %sed with the hive mind!", action)

	return nil
}