func (cloudoneAnalysisControl *CloudoneAnalysisControl) testRestAPI() bool {
	result, _ := restclient.HealthCheck(
		"https://127.0.0.1:"+strconv.Itoa(cloudoneAnalysisControl.RestapiPort)+"/apidocs.json",
		nil,
		restApiTimeout)
	return result
}
예제 #2
0
func (privateRegistry *PrivateRegistry) IsAvailable() error {
	_, err := restclient.HealthCheck(privateRegistry.getPrivateRegistryEndpoint()+"/v2/", nil, AvailableTimeoutDuration)
	if err != nil {
		log.Error(err)
		return err
	}
	return nil
}
예제 #3
0
func GetAvailablekubeApiServerEndPoint() (returnedEndPoint string, returnedToken string, returnedError error) {
	defer func() {
		if err := recover(); err != nil {
			returnedEndPoint = ""
			returnedToken = ""
			returnedError = err.(error)
			log.Error("GetAvailablekubeApiServerEndPoint Error: %s", err)
			log.Error(logger.GetStackTrace(4096, false))
		}
	}()

	kubeApiServerEndPointSlice, ok := LocalConfiguration.GetStringSlice("kubeApiServerEndPoints")
	if ok == false {
		log.Error("Fail to get configuration kubeApiServerEndPoints")
		return "", "", errors.New("Fail to get configuration kubeApiServerEndPoints")
	}

	kubeApiServerHealthCheckTimeoutInMilliSecond, ok := LocalConfiguration.GetInt("kubeApiServerHealthCheckTimeoutInMilliSecond")
	if ok == false {
		kubeApiServerHealthCheckTimeoutInMilliSecond = KubeApiServerHealthCheckTimeoutInMilliSecond
	}

	kubeApiServerToken, ok := LocalConfiguration.GetString("kubeApiServerToken")
	if ok == false {
		log.Error("Fail to get configuration kubeApiServerToken")
		return "", "", errors.New("Fail to get configuration kubeApiServerToken")
	}

	token := "Bearer " + kubeApiServerToken
	headerMap := make(map[string]string)
	headerMap["Authorization"] = token

	for _, kubeApiServerEndPoint := range kubeApiServerEndPointSlice {
		result, err := restclient.HealthCheck(
			kubeApiServerEndPoint,
			headerMap,
			time.Duration(kubeApiServerHealthCheckTimeoutInMilliSecond)*time.Millisecond)

		if result {
			return kubeApiServerEndPoint, token, nil
		} else {
			if err != nil {
				log.Error(err)
			}
		}
	}

	log.Error("No available kube apiserver endpoint")
	return "", "", errors.New("No available kube apiserver endpoint")
}