Example #1
0
func lockNode(nodeId uuid.UUID, hostname string, operation string) (*lock.AppLock, error) {
	//lock the node
	locks := make(map[uuid.UUID]string)
	if nodeId.IsZero() {
		//Generate temporary UUID from hostname for the node
		//for locking as the UUID is not available at this point
		id, err := uuid.Parse(util.Md5FromString(hostname))
		if err != nil {
			logger.Get().Error(fmt.Sprintf("Unable to create the UUID for locking for host: %s:", hostname), err)
			return nil, err
		}
		nodeId = *id
	}
	locks[nodeId] = fmt.Sprintf("%s : %s", operation, hostname)
	appLock := lock.NewAppLock(locks)
	if err := GetApp().GetLockManager().AcquireLock(*appLock); err != nil {
		return nil, err
	}
	return appLock, nil
}
func (a *App) RouteProviderBasedMonitoring(cluster_id uuid.UUID) {
	provider := a.getProviderFromClusterId(cluster_id)
	if provider == nil {
		logger.Get().Warning("Faield to get provider for cluster: %v", cluster_id)
		return
	}
	var result models.RpcResponse

	vars := make(map[string]string)
	vars["cluster-id"] = cluster_id.String()

	err = provider.Client.Call(fmt.Sprintf("%s.%s",
		provider.Name, "MonitorCluster"),
		models.RpcRequest{RpcRequestVars: vars, RpcRequestData: []byte{}},
		&result)

	if err != nil || result.Status.StatusCode != http.StatusOK {
		logger.Get().Error("Monitoring by Provider: %s failed. Reason :%s", provider.Name, err)
		return
	}

	return
}