當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Connection.CreateDir方法代碼示例

本文整理匯總了Golang中github.com/control-center/serviced/coordinator/client.Connection.CreateDir方法的典型用法代碼示例。如果您正苦於以下問題:Golang Connection.CreateDir方法的具體用法?Golang Connection.CreateDir怎麽用?Golang Connection.CreateDir使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/control-center/serviced/coordinator/client.Connection的用法示例。


在下文中一共展示了Connection.CreateDir方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Run

func (s *Server) Run(shutdown <-chan interface{}, conn client.Connection) error {
	node := &Node{
		Host:       *s.host,
		ExportPath: fmt.Sprintf("%s:%s", s.host.IPAddr, s.driver.ExportPath()),
		ExportTime: strconv.FormatInt(time.Now().UnixNano(), 16),
	}

	// Create the storage leader and client nodes
	if exists, _ := conn.Exists("/storage/leader"); !exists {
		conn.CreateDir("/storage/leader")
	}

	storageClientsPath := "/storage/clients"

	if exists, _ := conn.Exists(storageClientsPath); !exists {
		conn.CreateDir(storageClientsPath)
	}

	leader := conn.NewLeader("/storage/leader", node)
	leaderW, err := leader.TakeLead()
	if err != zookeeper.ErrDeadlock && err != nil {
		glog.Errorf("Could not take storage lead: %s", err)
		return err
	}

	// monitor dfs; log warnings each cycle; restart dfs if needed
	go s.monitor.MonitorDFSVolume(path.Join("/exports", s.driver.ExportPath()), s.host.IPAddr, node.ExportTime, shutdown, s.monitor.DFSVolumeMonitorPollUpdateFunc)

	// loop until shutdown event
	defer leader.ReleaseLead()

	for {
		clients, clientW, err := conn.ChildrenW(storageClientsPath)
		if err != nil {
			glog.Errorf("Could not set up watch for storage clients: %s", err)
			return err
		}

		s.monitor.SetMonitorStorageClients(conn, storageClientsPath)
		s.driver.SetClients(clients...)
		if err := s.driver.Sync(); err != nil {
			glog.Errorf("Error syncing driver: %s", err)
			return err
		}

		select {
		case e := <-clientW:
			glog.Info("storage.server: receieved event: %s", e)
		case <-leaderW:
			err := fmt.Errorf("storage.server: lost lead")
			return err
		case <-shutdown:
			return nil
		}
	}
}
開發者ID:carriercomm,項目名稱:serviced,代碼行數:56,代碼來源:server.go

示例2: CreateEndpointRegistry

// CreateEndpointRegistry creates the endpoint registry and returns the EndpointRegistry type
// This is created in the leader, most other calls will just get that one
func CreateEndpointRegistry(conn client.Connection) (*EndpointRegistry, error) {
	path := zkEndpointsPath()
	if exists, err := zzk.PathExists(conn, path); err != nil {
		return nil, err
	} else if !exists {
		if err := conn.CreateDir(path); err != nil {
			glog.Errorf("error with CreateDir(%s) %+v", path, err)
			return nil, err
		}
	}
	return &EndpointRegistry{registryType{getPath: zkEndpointsPath, ephemeral: true}}, nil
}
開發者ID:carriercomm,項目名稱:serviced,代碼行數:14,代碼來源:endpointregistry.go

示例3: ensureDir

func (r *registryType) ensureDir(conn client.Connection, path string) error {
	timeout := time.After(time.Second * 60)
	var err error
	for {
		err = conn.CreateDir(path)
		if err == client.ErrNodeExists || err == nil {
			return nil
		}
		select {
		case <-timeout:
			break
		default:
		}
	}
	return fmt.Errorf("could not create dir: %s", path, err)
}
開發者ID:carriercomm,項目名稱:serviced,代碼行數:16,代碼來源:registry.go

示例4: VHostRegistry

// VHostRegistry ensures the vhost registry and returns the VhostRegistry type
func VHostRegistry(conn client.Connection) (*VhostRegistry, error) {
	path := vhostPath()

	timeout := time.After(time.Second * 60)
	var err error
	for {
		err = conn.CreateDir(path)
		if err == client.ErrNodeExists || err == nil {
			err = nil
			break
		}
		select {
		case <-timeout:
			break
		default:
		}
	}
	if err != nil {
		glog.Errorf("error with CreateDir(%s) %+v", path, err)
		return nil, fmt.Errorf("could not create dir: %s", path, err)
	}
	return &VhostRegistry{registryType{getPath: vhostPath, ephemeral: true}}, nil
}
開發者ID:eval01-tts,項目名稱:serviced,代碼行數:24,代碼來源:vhostregistry.go


注:本文中的github.com/control-center/serviced/coordinator/client.Connection.CreateDir方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。