コード例 #1
0
func serviceGetter(ctx datastore.Context, f *facade.Facade) service.GetService {
	return func(svcID string) (service.Service, error) {
		svc, err := f.GetService(ctx, svcID)
		if err != nil {
			return service.Service{}, err
		}
		return *svc, nil
	}
}
コード例 #2
0
func childFinder(ctx datastore.Context, f *facade.Facade) service.FindChildService {
	return func(svcID, childName string) (service.Service, error) {
		svc, err := f.FindChildService(ctx, svcID, childName)
		if err != nil {
			return service.Service{}, err
		} else if svc == nil {
			return service.Service{}, fmt.Errorf("no service found")
		}
		return *svc, nil
	}
}
コード例 #3
0
ファイル: health.go プロジェクト: eval01-tts/serviced
// RegisterHealthCheck updates the healthStatus and healthTime structures with a health check result.
func RegisterHealthCheck(serviceID string, instanceID string, name string, passed string, f *facade.Facade) {
	lock.Lock()
	defer lock.Unlock()
	serviceStatus, ok := healthStatuses[serviceID]
	if !ok {
		serviceStatus = make(map[string]map[string]*domain.HealthCheckStatus)
		healthStatuses[serviceID] = serviceStatus
	}
	instanceStatus, ok := serviceStatus[instanceID]
	if !ok {
		instanceStatus = make(map[string]*domain.HealthCheckStatus)
		serviceStatus[instanceID] = instanceStatus
	}
	if name == "__instance_shutdown" {
		delete(serviceStatus, instanceID)
		return
	}
	thisStatus, ok := instanceStatus[name]
	if !ok {
		healthChecks, err := f.GetHealthChecksForService(datastore.Get(), serviceID)
		if err != nil {
			glog.Errorf("Unable to acquire health checks: %+v", err)
			return
		}
		for iname, icheck := range healthChecks {
			_, ok = instanceStatus[iname]
			if !ok {
				instanceStatus[iname] = &domain.HealthCheckStatus{name, "unknown", 0, icheck.Interval.Seconds(), time.Now().Unix(), ""}
			}
		}
	}
	thisStatus, ok = instanceStatus[name]
	if !ok {
		glog.Warningf("ignoring %s health status %s, not found in service %s", passed, name, serviceID)
		return
	}
	thisStatus.Status = passed
	thisStatus.Timestamp = time.Now().UTC().Unix()
}