Exemplo n.º 1
0
// GetHealthCheck returns the health check configuration for a service, if it exists
func (a *HostAgent) GetHealthCheck(req HealthCheckRequest, healthChecks *map[string]domain.HealthCheck) error {
	glog.V(4).Infof("ControlPlaneAgent.GetHealthCheck()")
	*healthChecks = make(map[string]domain.HealthCheck, 0)

	controlClient, err := NewControlClient(a.master)
	if err != nil {
		glog.Errorf("Could not start ControlPlane client %v", err)
		return err
	}
	defer controlClient.Close()

	var svc service.Service
	err = controlClient.GetService(req.ServiceID, &svc)
	if err != nil {
		return err
	}
	getSvc := func(svcID string) (service.Service, error) {
		svc := service.Service{}
		err := controlClient.GetService(svcID, &svc)
		return svc, err
	}

	findChild := func(svcID, childName string) (service.Service, error) {
		svc := service.Service{}
		err := controlClient.FindChildService(dao.FindChildRequest{svcID, childName}, &svc)
		return svc, err
	}
	svc.EvaluateHealthCheckTemplate(getSvc, findChild, req.InstanceID)
	if svc.HealthChecks != nil {
		*healthChecks = svc.HealthChecks
	}
	return nil
}