// Clos closes remote cluster connections
423150
func (s *remoteSite) Close() error {
	s.Lock()
	defer s.Unlock()

	s.cancel()
	for i := range s.connections {
		s.connections[i].Close()
	}
	s.connections = []*remoteConn{}
	return nil
}
1236801
func Close() {
	mu.Lock()
	defer mu.Unlock()

	if portfile != "" {
		os.Remove(portfile)
		portfile = ""
	}
	if listener != nil {
		listener.Close()
	}
}
918122
func (c *GRPCConnection) Close() {
	if !c.setClosed() {
		logger.Debug("Already closed")
		return
	}

	logger.Debug("Releasing connection....")
	c.commManager.ReleaseConn(c.conn)

	logger.Debug("... connection successfully closed.")
}
620229
func (rf *Client) Close() {
	if rf.conn != nil {
		rf.conn.Close()
		rf.conn = nil
	}
}
227842
func (rc *RemoteCache) Close() {
	rc.allocator.remoteCachesMutex.Lock()
	delete(rc.allocator.remoteCaches, rc)
	rc.allocator.remoteCachesMutex.Unlock()

	rc.cache.stop()
}
1039839
func LoadClusters(config string) (map[string]Cluster, error) {

	file, err := os.Open(config)
	if err != nil {
		return nil, errors.Wrap(err, "Error opening file "+config)
	}

	clusters := make([]Cluster, 1)
	err = json.NewDecoder(file).Decode(&clusters)
	if err != nil {
		return nil, errors.Wrap(err, "Error parsing file "+config)
	}

	m := make(map[string]Cluster)
	for _, cluster := range clusters {
		m[cluster.Name] = cluster
	}

	return m, nil
}
1258105
func (c *Client) GetClusterStatus() (map[string]*clientv3.StatusResponse, error) {
	cli, err := clientv3.New(clientv3.Config{
		Endpoints:   c.Endpoints,
		DialTimeout: 5 * time.Second,
		TLS:         c.TLS,
	})
	if err != nil {
		return nil, err
	}
	defer cli.Close()

	clusterStatus := make(map[string]*clientv3.StatusResponse)
	for _, ep := range c.Endpoints {
		ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
		resp, err := cli.Status(ctx, ep)
		cancel()
		if err != nil {
			return nil, err
		}
		clusterStatus[ep] = resp
	}
	return clusterStatus, nil
}
258472
func UnmarshalRemoteCluster(bytes []byte, opts ...MarshalOption) (RemoteCluster, error) {
	cfg, err := collectOptions(opts)
	if err != nil {
		return nil, trace.Wrap(err)
	}

	var cluster RemoteClusterV3

	if len(bytes) == 0 {
		return nil, trace.BadParameter("missing resource data")
	}

	if cfg.SkipValidation {
		err := utils.FastUnmarshal(bytes, &cluster)
		if err != nil {
			return nil, trace.Wrap(err)
		}
	} else {
		err = utils.UnmarshalWithSchema(GetRemoteClusterSchema(), &cluster, bytes)
		if err != nil {
			return nil, trace.BadParameter(err.Error())
		}
	}

	err = cluster.CheckAndSetDefaults()
	if err != nil {
		return nil, trace.Wrap(err)
	}

	return &cluster, nil
}
316701
func (p kubernetesEnvironProvider) FinalizeCloud(ctx environs.FinalizeCloudContext, cld cloud.Cloud) (cloud.Cloud, error) {
	// We special case Microk8s here as we need to query the cluster for the
	// storage details with no input from the user
	if cld.Name != caas.K8sCloudMicrok8s {
		return cld, nil
	}

	if err := ensureMicroK8sSuitable(p.cmdRunner); err != nil {
		return cld, errors.Trace(err)
	}

	// if storage is already defined there is no need to query the cluster
	if opStorage, ok := cld.Config[OperatorStorageKey]; ok && opStorage != "" {
		return cld, nil
	}

	// Need the credentials, need to query for those details
	mk8sCloud, credential, _, err := p.builtinCloudGetter(p.cmdRunner)
	if err != nil {
		return cloud.Cloud{}, errors.Trace(err)
	}

	openParams, err := BaseKubeCloudOpenParams(mk8sCloud, credential)
	if err != nil {
		return cloud.Cloud{}, errors.Trace(err)
	}
	broker, err := p.brokerGetter(openParams)
	if err != nil {
		return cloud.Cloud{}, errors.Trace(err)
	}
	storageUpdateParams := KubeCloudStorageParams{
		MetadataChecker: broker,
		GetClusterMetadataFunc: func(broker caas.ClusterMetadataChecker) (*caas.ClusterMetadata, error) {
			clusterMetadata, err := broker.GetClusterMetadata("")
			if err != nil {
				return nil, errors.Trace(err)
			}
			return clusterMetadata, nil
		},
	}
	_, err = UpdateKubeCloudWithStorage(&mk8sCloud, storageUpdateParams)
	if err != nil {
		return cloud.Cloud{}, errors.Trace(err)
	}
	for i := range mk8sCloud.Regions {
		if mk8sCloud.Regions[i].Endpoint == "" {
			mk8sCloud.Regions[i].Endpoint = mk8sCloud.Endpoint
		}
	}
	return mk8sCloud, nil
}
1133263
func (cli *Client) Close() error {
	cli.Lock()
	defer cli.Unlock()
	defer close(cli.reply)
	return cli.conn.Close()
}
1144566
func (server *UnixServer) Close() {
	if server.listener != nil {
		listener := server.listener
		server.listener = nil
		listener.Close()
	}
}
1185294
func (c *Client) DeleteRemoteCluster(clusterName string) error {
	if clusterName == "" {
		return trace.BadParameter("missing parameter cluster name")
	}
	_, err := c.Delete(c.Endpoint("remoteclusters", clusterName))
	return trace.Wrap(err)
}
351938
func (c *Cluster) Close(optArgs ...CloseOpts) error {
	if c.closed {
		return nil
	}

	for _, node := range c.GetNodes() {
		err := node.Close(optArgs...)
		if err != nil {
			return err
		}
	}

	c.hp.Close()
	c.closed = true

	return nil
}
336142
func (engine *OrcEngine) onClusterNodeLost(nodeName string, downCount int) {
	log.Warnf("Cluster node is down, [%q], %d nodes down in all, will check if need stop the engine", nodeName, downCount)
	if downCount >= maxDownNode {
		log.Warnf("Too many cluster nodes stoped in a short period, need stop the engine")
		ntfController.Send(NewNotifySpec("Cluster", "Deployd",
			1, time.Now(), NotifyClusterAbnormal))
		engine.Stop()
	}
}
101561
func (c *Client) GetRemoteClusters(opts ...services.MarshalOption) ([]services.RemoteCluster, error) {
	out, err := c.Get(c.Endpoint("remoteclusters"), url.Values{})
	if err != nil {
		return nil, trace.Wrap(err)
	}
	var items []json.RawMessage
	if err := json.Unmarshal(out.Bytes(), &items); err != nil {
		return nil, trace.Wrap(err)
	}
	conns := make([]services.RemoteCluster, len(items))
	for i, raw := range items {
		conn, err := services.UnmarshalRemoteCluster(raw, services.SkipValidation())
		if err != nil {
			return nil, trace.Wrap(err)
		}
		conns[i] = conn
	}
	return conns, nil
}
953111
func (cp *ConnectionPool) Close() {
	p := cp.pool()
	if p == nil {
		return
	}
	// We should not hold the lock while calling Close
	// because it waits for connections to be returned.
	p.Close()
	cp.mu.Lock()
	cp.connections = nil
	cp.addresses = nil
	cp.hostIsNotIP = false
	if cp.ticker != nil {
		cp.ticker.Stop()
		close(cp.stop)
	}
	cp.mu.Unlock()
	cp.wg.Wait()
}
163627
func (s *PresenceService) DeleteRemoteCluster(clusterName string) error {
	if clusterName == "" {
		return trace.BadParameter("missing parameter cluster name")
	}
	return s.Delete(context.TODO(), backend.Key(remoteClustersPrefix, clusterName))
}