// NullClusterManager implementations
// Inspect
766863
func (m *NullClusterManager) Inspect(arg0 string) (api.Node, error) {
	return api.Node{}, ErrNotImplemented
}
1056990
func NewClusterStateService(client *Client) *ClusterStateService {
	return &ClusterStateService{
		client:  client,
		indices: make([]string, 0),
		metrics: make([]string, 0),
	}
}
245585
func (k *kubernetesClient) GetClusterMetadata(storageClass string) (*caas.ClusterMetadata, error) {
	var result caas.ClusterMetadata
	var err error
	result.Cloud, result.Regions, err = k.listHostCloudRegions()
	if err != nil {
		return nil, errors.Annotate(err, "cannot determine cluster region")
	}

	if storageClass != "" {
		sc, err := k.client().StorageV1().StorageClasses().Get(storageClass, v1.GetOptions{IncludeUninitialized: true})
		if err != nil && !k8serrors.IsNotFound(err) {
			return nil, errors.Trace(err)
		}
		if err == nil {
			result.NominatedStorageClass = &caas.StorageProvisioner{
				Name:        sc.Name,
				Provisioner: sc.Provisioner,
				Parameters:  sc.Parameters,
			}
			if sc.ReclaimPolicy != nil {
				result.NominatedStorageClass.ReclaimPolicy = string(*sc.ReclaimPolicy)
			}
		}
	}

	// We may have the workload storage but still need to look for operator storage.
	preferredOperatorStorage, havePreferredOperatorStorage := jujuPreferredOperatorStorage[result.Cloud]
	storageClasses, err := k.client().StorageV1().StorageClasses().List(v1.ListOptions{})
	if err != nil {
		return nil, errors.Annotate(err, "listing storage classes")
	}

	var (
		possibleWorkloadStorage []storage.StorageClass
		possibleOperatorStorage []*caas.StorageProvisioner
		defaultOperatorStorage  *caas.StorageProvisioner
	)
	for _, sc := range storageClasses.Items {
		if havePreferredOperatorStorage {
			maybeOperatorStorage := &caas.StorageProvisioner{
				Name:        sc.Name,
				Provisioner: sc.Provisioner,
				Parameters:  sc.Parameters,
			}
			if sc.ReclaimPolicy != nil {
				maybeOperatorStorage.ReclaimPolicy = string(*sc.ReclaimPolicy)
			}
			if err := storageClassMatches(preferredOperatorStorage, maybeOperatorStorage); err == nil {
				possibleOperatorStorage = append(possibleOperatorStorage, maybeOperatorStorage)
				if isDefaultStorageClass(sc) {
					defaultOperatorStorage = maybeOperatorStorage
				}
			}
		}
		if result.NominatedStorageClass != nil {
			continue
		}
		if isDefaultStorageClass(sc) {
			result.NominatedStorageClass = &caas.StorageProvisioner{
				Name:        sc.Name,
				Provisioner: sc.Provisioner,
				Parameters:  sc.Parameters,
			}
			if sc.ReclaimPolicy != nil {
				result.NominatedStorageClass.ReclaimPolicy = string(*sc.ReclaimPolicy)
			}
			break
		}
		possibleWorkloadStorage = append(possibleWorkloadStorage, sc)
	}

	// Prefer operator storage from the default storage class.
	if defaultOperatorStorage != nil {
		result.OperatorStorageClass = defaultOperatorStorage
	} else if len(possibleOperatorStorage) > 0 {
		result.OperatorStorageClass = possibleOperatorStorage[0]
	}

	// Even if no storage class was marked as default for the cluster, if there's only
	// one of them, use it for workload storage.
	if result.NominatedStorageClass == nil && len(possibleWorkloadStorage) == 1 {
		sc := possibleWorkloadStorage[0]
		result.NominatedStorageClass = &caas.StorageProvisioner{
			Name:        sc.Name,
			Provisioner: sc.Provisioner,
			Parameters:  sc.Parameters,
		}
		if sc.ReclaimPolicy != nil {
			result.NominatedStorageClass.ReclaimPolicy = string(*sc.ReclaimPolicy)
		}
	}
	return &result, nil
}
529390
func (manager *configManager) execClusterCallbacks(f CallbackClusterConfigFunc, data *data) {
	config := new(ClusterConfig)
	if err := json.Unmarshal(data.Value, config); err != nil {
		logrus.Error(err)
		return
	}

	f(config)
}
1123
func NewCluster(options *ClusterOptions) (*Cluster, error) {
	if options == nil {
		options = defaultClusterOptions
	}
	if options.NodeManager == nil {
		options.NodeManager = &defaultNodeManager{}
	}
	if options.ExecutionAttempts == 0 {
		options.ExecutionAttempts = defaultExecutionAttempts
	}

	c := &Cluster{
		executionAttempts: options.ExecutionAttempts,
		nodeManager:       options.NodeManager,
	}
	c.initStateData("clusterCreated", "clusterRunning", "clusterShuttingDown", "clusterShutdown", "clusterError")

	if options.Nodes == nil {
		c.nodes = make([]*Node, 0)
	} else {
		c.nodes = options.Nodes
	}

	if options.NoDefaultNode == false && len(c.nodes) == 0 {
		defaultNode, nerr := NewNode(nil)
		if nerr != nil {
			return nil, nerr
		}
		c.nodes = append(c.nodes, defaultNode)
	}

	for _, node := range c.nodes {
		if node == nil {
			return nil, ErrClusterNodesMustBeNonNil
		}
	}

	if options.QueueMaxDepth > 0 {
		if options.QueueExecutionInterval == 0 {
			options.QueueExecutionInterval = defaultQueueExecutionInterval
		}
		c.queueCommands = true
		c.stopChan = make(chan struct{})
		c.cq = newQueue(options.QueueMaxDepth)
		c.commandQueueTicker = time.NewTicker(options.QueueExecutionInterval)
		go c.executeEnqueuedCommands()
	}

	c.setState(clusterCreated)
	return c, nil
}
357457
func NewManager() *Manager {
	session := db.GetSession()
	return &Manager{
		session:    session,
		collection: getConfigCollection(session),
	}
}
287083
func NewMockCluster(ctrl *gomock.Controller) *MockCluster {
	mock := &MockCluster{ctrl: ctrl}
	mock.recorder = &MockClusterMockRecorder{mock}
	return mock
}
427791
func ClusterClusters(clusters []*Cluster, distancer ClusterDistancer, threshold float64) []*Cluster {
	copiedClusters := make([]*Cluster, len(clusters), len(clusters))
	copy(copiedClusters, clusters)

	return cluster(copiedClusters, distancer, threshold)
}
171406
func newManager(kv kvdb.Kvdb) (*configManager, error) {
	manager := new(configManager)

	manager.cbCluster = make(map[string]CallbackClusterConfigFunc)
	manager.cbNode = make(map[string]CallbackNodeConfigFunc)

	// kvdb pointer
	manager.kv = kv

	// register function with kvdb to watch cluster level changes
	if err := kv.WatchTree(filepath.Join(baseKey, clusterKey), 0,
		&dataToKvdb{Type: clusterWatcher}, manager.kvdbCallback); err != nil {
		logrus.Error(err)
		return nil, err
	}
	if err := kv.WatchTree(filepath.Join(baseKey, nodeKey), 0,
		&dataToKvdb{Type: nodeWatcher}, manager.kvdbCallback); err != nil {
		logrus.Error(err)
		return nil, err
	}

	return manager, nil
}
792492
func FindClusters(tx ReadTx, by By) ([]*api.Cluster, error) {
	checkType := func(by By) error {
		switch by.(type) {
		case byName, byNamePrefix, byIDPrefix, byCustom, byCustomPrefix:
			return nil
		default:
			return ErrInvalidFindBy
		}
	}

	clusterList := []*api.Cluster{}
	appendResult := func(o api.StoreObject) {
		clusterList = append(clusterList, o.(*api.Cluster))
	}

	err := tx.find(tableCluster, by, checkType, appendResult)
	return clusterList, err
}
580616
func (c *mockGCECloud) FindClusterStatus(cluster *kops.Cluster) (*kops.ClusterStatus, error) {
	return nil, fmt.Errorf("mockGCECloud::FindClusterStatus not implemented")
}
185273
func (o *VCenterDataCenter) VCenterClusters(info *bambou.FetchingInfo) (VCenterClustersList, *bambou.Error) {

	var list VCenterClustersList
	err := bambou.CurrentSession().FetchChildren(o, VCenterClusterIdentity, &list, info)
	return list, err
}
248891
func findUnusedClusterByVersion(clusterMap *Map, leaseMap *leases.Map, clusterVersion string) (*containerservice.ContainerService, error) {
	clusterNames := clusterMap.ClusterNamesByVersion(clusterVersion)
	if len(clusterNames) > 0 {
		for tries := 0; tries < 10; tries++ {
			clusterName := clusterNames[rand.Intn(len(clusterNames))]
			cluster, err := checkLease(clusterMap, leaseMap, clusterName)
			if err == nil {
				return cluster, nil
			}
		}
	}
	return nil, errUnusedAzureClusterNotFound
}
176898
func (s *Server) UseCluster(c cluster.Cluster) {
	s.netServer.useCluster(c)
	s.udsServer.useCluster(c)
}
889648
func (c *aliCloudImplementation) AddClusterTags(tags map[string]string) {

	if c.tags != nil && len(c.tags) != 0 && tags != nil {
		for k, v := range c.tags {
			tags[k] = v
		}
	}
}
1344804
func (c *VFSClientset) GetCluster(name string) (*kops.Cluster, error) {
	return c.clusters().Get(name, metav1.GetOptions{})
}
408548
func parseCluster(itf interface{}, opts *Options) error {
	m, ok := itf.(map[string]interface{})
	if !ok {
		return fmt.Errorf("expected cluster to be a map/struct, got %v", itf)
	}
	opts.Clustering.Clustered = true
	for k, v := range m {
		name := strings.ToLower(k)
		switch name {
		case "node_id":
			if err := checkType(k, reflect.String, v); err != nil {
				return err
			}
			opts.Clustering.NodeID = v.(string)
		case "bootstrap":
			if err := checkType(k, reflect.Bool, v); err != nil {
				return err
			}
			opts.Clustering.Bootstrap = v.(bool)
		case "peers":
			if err := checkType(k, reflect.Slice, v); err != nil {
				return err
			}
			peers := make([]string, len(v.([]interface{})))
			for i, p := range v.([]interface{}) {
				peers[i] = p.(string)
			}
			opts.Clustering.Peers = peers
		case "log_path":
			if err := checkType(k, reflect.String, v); err != nil {
				return err
			}
			opts.Clustering.RaftLogPath = v.(string)
		case "log_cache_size":
			if err := checkType(k, reflect.Int64, v); err != nil {
				return err
			}
			opts.Clustering.LogCacheSize = int(v.(int64))
		case "log_snapshots":
			if err := checkType(k, reflect.Int64, v); err != nil {
				return err
			}
			opts.Clustering.LogSnapshots = int(v.(int64))
		case "trailing_logs":
			if err := checkType(k, reflect.Int64, v); err != nil {
				return err
			}
			opts.Clustering.TrailingLogs = v.(int64)
		case "sync":
			if err := checkType(k, reflect.Bool, v); err != nil {
				return err
			}
			opts.Clustering.Sync = v.(bool)
		case "raft_logging":
			if err := checkType(k, reflect.Bool, v); err != nil {
				return err
			}
			opts.Clustering.RaftLogging = v.(bool)
		case "raft_heartbeat_timeout":
			fallthrough
		case "raft_election_timeout":
			fallthrough
		case "raft_lease_timeout":
			fallthrough
		case "raft_commit_timeout":
			if err := checkType(k, reflect.String, v); err != nil {
				return err
			}
			dur, err := time.ParseDuration(v.(string))
			if err != nil {
				return err
			}
			switch name {
			case "raft_heartbeat_timeout":
				opts.Clustering.RaftHeartbeatTimeout = dur
			case "raft_election_timeout":
				opts.Clustering.RaftElectionTimeout = dur
			case "raft_lease_timeout":
				opts.Clustering.RaftLeaseTimeout = dur
			case "raft_commit_timeout":
				opts.Clustering.RaftCommitTimeout = dur
			}
		}
	}
	return nil
}