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


Golang log.Print函數代碼示例

本文整理匯總了Golang中github.com/pachyderm/pachyderm/src/log.Print函數的典型用法代碼示例。如果您正苦於以下問題:Golang Print函數的具體用法?Golang Print怎麽用?Golang Print使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1: Show

func Show(repo string, commit string, out string) error {
	if err := subvolumeCreate(path.Join(repo, out)); err != nil {
		return err
	}
	files, err := NewIn(repo, commit)
	if err != nil {
		return err
	}
	log.Print("Files: ", files)
	var wg sync.WaitGroup
	for _, file := range files {
		wg.Add(1)
		go func(file string) {
			defer wg.Done()
			in, err := Open(path.Join(repo, commit, file))
			if err != nil {
				log.Print(err)
				return
			}
			if _, err := CreateFromReader(path.Join(repo, out, file), in); err != nil {
				log.Print(err)
				return
			}
		}(file)
	}
	wg.Wait()
	return nil
}
開發者ID:plar,項目名稱:pachyderm,代碼行數:28,代碼來源:btrfs.go

示例2: CommitCreate

func (s *shard) CommitCreate(name string, branch string) (Commit, error) {
	if err := btrfs.Commit(s.dataRepo, name, branch); err != nil {
		return Commit{}, err
	}
	// We lock the guard so that we can remove the oldRunner from the map
	// and add the newRunner in.
	s.guard.Lock()
	oldRunner, ok := s.runners[branch]
	newRunner := pipeline.NewRunner("pipeline", s.dataRepo, s.pipelinePrefix, name, branch, s.shardStr, s.cache)
	s.runners[branch] = newRunner
	s.guard.Unlock()
	go func() {
		// cancel oldRunner if it exists
		if ok {
			err := oldRunner.Cancel()
			if err != nil {
				log.Print(err)
			}
		}
		err := newRunner.Run()
		if err != nil {
			log.Print(err)
		}
	}()
	go s.syncToPeers()
	return s.CommitGet(name)
}
開發者ID:bboalimoe,項目名稱:pachyderm,代碼行數:27,代碼來源:shard.go

示例3: FillRole

// FillRole attempts to find a role in the cluster. Once on is found it
// prepares the local storage for the role and announces the shard to the rest
// of the cluster. This function will loop until `cancel` is closed.
func (s *shard) FillRole() {
	shard := fmt.Sprintf("%d-%d", s.shard, s.modulos)
	masterKey := path.Join("/pfs/master", shard)
	replicaDir := path.Join("/pfs/replica", shard)

	amMaster := false //true if we're master
	replicaKey := ""
	for {
		client := etcd.NewClient([]string{"http://172.17.42.1:4001", "http://10.1.42.1:4001"})
		defer client.Close()
		// First we attempt to become the master for this shard
		if !amMaster {
			// We're not master, so we attempt to claim it, this will error if
			// another shard is already master
			backfillingKey := "[backfilling]" + s.url
			if _, err := client.Create(masterKey, backfillingKey, 5*60); err == nil {
				// no error means we succesfully claimed master
				_ = s.syncFromPeers()
				// Attempt to finalize ourselves as master
				_, _ = client.CompareAndSwap(masterKey, s.url, 60, backfillingKey, 0)
				if err == nil {
					// no error means that we succusfully announced ourselves as master
					// Sync the new data we pulled to peers
					go s.syncToPeers()
					//Record that we're master
					amMaster = true
				}
			} else {
				log.Print(err)
			}
		} else {
			// We're already master, renew our lease
			_, err := client.CompareAndSwap(masterKey, s.url, 60, s.url, 0)
			if err != nil { // error means we failed to reclaim master
				log.Print(err)
				amMaster = false
			}
		}

		// We didn't claim master, so we add ourselves as replica instead.
		if replicaKey == "" {
			if resp, err := client.CreateInOrder(replicaDir, s.url, 60); err == nil {
				replicaKey = resp.Node.Key
				// Get ourselves up to date
				go s.syncFromPeers()
			}
		} else {
			_, err := client.CompareAndSwap(replicaKey, s.url, 60, s.url, 0)
			if err != nil {
				replicaKey = ""
			}
		}

		select {
		case <-time.After(time.Second * 45):
			continue
		}
	}
}
開發者ID:plar,項目名稱:pachyderm,代碼行數:62,代碼來源:shard.go

示例4: TestShuffle

func TestShuffle(t *testing.T) {
	t.Parallel()
	cache := etcache.NewTestCache()
	// Setup 2 shards
	shard1 := NewShard("", "TestShuffleData-0-2", "TestShufflePipelines-0-2", 0, 2, cache)
	require.NoError(t, shard1.EnsureRepos())
	s1 := httptest.NewServer(NewShardHTTPHandler(shard1))
	defer s1.Close()
	shard2 := NewShard("", "TestShuffleData-1-2", "TestShufflePipelines-1-2", 1, 2, cache)
	require.NoError(t, shard2.EnsureRepos())
	s2 := httptest.NewServer(NewShardHTTPHandler(shard2))
	defer s2.Close()

	files := []string{"foo", "bar", "fizz", "buzz"}

	for _, file := range files {
		checkWriteFile(t, s1.URL, path.Join("data", file), "master", file)
		checkWriteFile(t, s2.URL, path.Join("data", file), "master", file)
	}

	// Spoof the shards in etcache
	cache.SpoofMany("/pfs/master", []string{s1.URL, s2.URL}, false)

	pipeline := `
image ubuntu

input data

run cp -r /in/data /out

shuffle data
`
	res, err := http.Post(s1.URL+"/pipeline/shuffle", "application/text", strings.NewReader(pipeline))
	require.NoError(t, err)
	res.Body.Close()
	res, err = http.Post(s2.URL+"/pipeline/shuffle", "application/text", strings.NewReader(pipeline))
	require.NoError(t, err)
	res.Body.Close()

	res, err = http.Post(s1.URL+"/commit?commit=commit1", "", nil)
	require.NoError(t, err)
	res, err = http.Post(s2.URL+"/commit?commit=commit1", "", nil)
	require.NoError(t, err)

	for _, file := range files {
		match, err := route.Match(path.Join("data", file), "0-2")
		require.NoError(t, err)
		if match {
			log.Print("shard: s1 file: ", file)
			checkFile(t, s1.URL+"/pipeline/shuffle", path.Join("data", file), "commit1", file+file)
		} else {
			log.Print("shard: s2 file: ", file)
			checkFile(t, s2.URL+"/pipeline/shuffle", path.Join("data", file), "commit1", file+file)
		}
	}
}
開發者ID:plar,項目名稱:pachyderm,代碼行數:56,代碼來源:shard_test.go

示例5: FindNew

// FindNew returns an array of filenames that were created or modified between `from` and `to`
func FindNew(repo, from, to string) ([]string, error) {
	var files []string
	t, err := transid(repo, from)
	if err != nil {
		return files, err
	}
	c := exec.Command("btrfs", "subvolume", "find-new", FilePath(path.Join(repo, to)), t)
	err = util.CallCont(c, func(r io.Reader) error {
		scanner := bufio.NewScanner(r)
		for scanner.Scan() {
			log.Print(scanner.Text())
			// scanner.Text() looks like this:
			// inode 6683 file offset 0 len 107 disk start 0 offset 0 gen 909 flags INLINE jobs/rPqZxsaspy
			// 0     1    2    3      4 5   6   7    8     9 10     11 12 13 14     15     16
			tokens := strings.Split(scanner.Text(), " ")
			// Make sure the line is parseable as a file and the path isn't hidden.
			if len(tokens) == 17 {
				if !strings.HasPrefix(tokens[16], ".") { // check if it's a hidden file
					files = append(files, tokens[16])
				}
			} else if len(tokens) == 4 {
				continue //skip transid messages
			} else {
				return fmt.Errorf("Failed to parse find-new output.")
			}
		}
		return scanner.Err()
	})
	return files, err
}
開發者ID:bboalimoe,項目名稱:pachyderm,代碼行數:31,代碼來源:btrfs.go

示例6: callCont

func callCont(c *exec.Cmd, cont func(io.Reader) error) error {
	_, callerFile, callerLine, _ := runtime.Caller(1)
	log.Printf("%15s:%.3d -> %s", path.Base(callerFile), callerLine, strings.Join(c.Args, " "))
	var reader io.Reader
	var err error
	if cont != nil {
		reader, err = c.StdoutPipe()
		if err != nil {
			return err
		}
	}
	stderr, err := c.StderrPipe()
	if err != nil {
		return err
	}
	if err = c.Start(); err != nil {
		return err
	}
	if cont != nil {
		if err = cont(reader); err != nil {
			return err
		}
	}
	buffer := bytes.NewBuffer(nil)
	buffer.ReadFrom(stderr)
	if buffer.Len() != 0 {
		log.Print("Command had output on stderr.\n Cmd: ", strings.Join(c.Args, " "), "\nstderr: ", buffer)
	}
	return c.Wait()
}
開發者ID:bboalimoe,項目名稱:pachyderm,代碼行數:30,代碼來源:shell.go

示例7: main

func main() {
	if err := do(); err != nil {
		log.Print(err)
		os.Exit(1)
	}
	os.Exit(0)
}
開發者ID:bboalimoe,項目名稱:pachyderm,代碼行數:7,代碼來源:main.go

示例8: FindRole

func (s *shard) FindRole() {
	client := etcd.NewClient([]string{"http://172.17.42.1:4001", "http://10.1.42.1:4001"})
	defer client.Close()
	gotRole := false
	var err error
	for ; true; <-time.After(time.Second * 45) {
		// renew our role if we have one
		if gotRole {
			_, err := client.CompareAndSwap(s.key(), s.url, 60, s.url, 0)
			if err != nil {
				log.Print(err)
			}
			continue
		}
		// figure out if we should take on a new role
		s.shard, err = s.freeRole()
		if err != nil {
			continue
		}
		_, err = client.Create(s.key(), s.url, 60)
		if err != nil {
			continue
		}
		s.dataRepo = fmt.Sprintf("data-%d-%d", s.shard, s.modulos)
		s.pipelinePrefix = fmt.Sprintf("pipe-%d-%d", s.shard, s.modulos)
		err := s.EnsureRepos()
		if err != nil {
			continue
		}
		gotRole = true
	}
}
開發者ID:plar,項目名稱:pachyderm,代碼行數:32,代碼來源:shard.go

示例9: WaitAnyFile

// WaitAnyFile returns as soon as ANY of the files exists.
// It returns an error if waiting for ANY of the files errors.
func WaitAnyFile(files ...string) (string, error) {
	// Channel for files that appear
	done := make(chan string, len(files))
	// Channel for errors that occur
	errors := make(chan error, len(files))

	cancellers := make([]chan struct{}, len(files))
	// Make sure that everyone gets cancelled after this function exits.
	defer func() {
		for _, c := range cancellers {
			c <- struct{}{}
		}
	}()
	for i, _ := range files {
		file := files[i]
		cancellers[i] = make(chan struct{}, 1)
		go func(i int) {
			err := WaitFile(file, cancellers[i])
			if err != nil {
				// Never blocks due to size of channel's buffer.
				errors <- err
			}
			// Never blocks due to size of channel's buffer.
			done <- file
		}(i)
	}

	select {
	case file := <-done:
		log.Print("Done: ", file)
		return file, nil
	case err := <-errors:
		return "", err
	}
}
開發者ID:bboalimoe,項目名稱:pachyderm,代碼行數:37,代碼來源:btrfs.go

示例10: do

func do() error {
	log.Print("Starting up...")
	r, err := router.RouterFromArgs()
	if err != nil {
		return err
	}
	return r.RunServer()
}
開發者ID:plar,項目名稱:pachyderm,代碼行數:8,代碼來源:main.go

示例11: clean

func (p *pipeline) clean() error {
	log.Print("p.createdCommits: ", p.createdCommits)
	for _, commit := range p.createdCommits {
		if err := btrfs.DeleteCommit(commit); err != nil {
			return err
		}
	}
	return nil
}
開發者ID:plar,項目名稱:pachyderm,代碼行數:9,代碼來源:pipeline.go

示例12: image

// Image sets the image that is being used for computations.
func (p *pipeline) image(image string) error {
	p.config.Config.Image = image
	// TODO(pedge): ensure images are on machine
	err := pullImage(image)
	if err != nil {
		log.Print("assuming image is local and continuing")
	}
	return nil
}
開發者ID:bboalimoe,項目名稱:pachyderm,代碼行數:10,代碼來源:pipeline.go

示例13: pushToOutputs

// pushToOutputs should be called after `finish` to push the outputted data to s3
func (p *pipeline) pushToOutputs() error {
	if p.externalOutput == "" {
		return nil
	}
	client := s3utils.NewClient(false)
	bucket, err := s3utils.GetBucket(p.externalOutput)
	if err != nil {
		return err
	}
	pathPrefix, err := s3utils.GetPath(p.externalOutput)
	if err != nil {
		return err
	}
	files, err := btrfs.NewIn(p.outRepo, p.commit)
	if err != nil {
		return err
	}
	var wg sync.WaitGroup
	for _, file := range files {
		wg.Add(1)
		go func(file string) {
			defer wg.Done()
			key := path.Join(pathPrefix, file)
			f, err := btrfs.Open(path.Join(p.outRepo, p.commit, file))
			if err != nil {
				log.Print(err)
				return
			}
			acl := "private"
			defer f.Close()
			if _, err = client.PutObject(&s3.PutObjectInput{
				Bucket: &bucket,
				Key:    &key,
				Body:   f,
				ACL:    &acl,
			}); err != nil {
				log.Print(err)
				return
			}
		}(file)
	}
	wg.Wait()
	return nil
}
開發者ID:plar,項目名稱:pachyderm,代碼行數:45,代碼來源:pipeline.go

示例14: WaitFile

// WaitFile waits for a file to exist in the filesystem
// NOTE: You NEVER want to pass an unbuffered channel as cancel because
// WaitFile provides no guarantee that it will ever read from cancel.  Thus if
// you passed an unbuffered channel as cancel sending to the channel may block
// forever.
func WaitFile(name string, cancel chan struct{}) error {
	log.Print("WaitFile(", name, ")")
	dir, err := largestExistingPath(name)
	if err != nil {
		return err
	}
	watcher, err := fsnotify.NewWatcher()
	if err != nil {
		return err
	}
	defer watcher.Close()

	if err := watcher.Add(FilePath(dir)); err != nil {
		return err
	}

	// Notice that we check to see if the file exists AFTER we create the watcher.
	// That means if we don't see the file with this check we're guaranteed to
	// get a notification for it.
	exists, err := FileExists(name)
	if err != nil {
		return err
	}
	if exists {
		log.Print("Found: ", name)
		return nil
	}

	for {
		select {
		case event := <-watcher.Events:
			if event.Op == fsnotify.Create && event.Name == FilePath(name) {
				return nil
			} else if event.Op == fsnotify.Create && strings.HasPrefix(FilePath(name), event.Name) {
				//fsnotify isn't recursive so we need to recurse for it.
				return WaitFile(name, cancel)
			}
		case err := <-watcher.Errors:
			return err
		case <-cancel:
			return ErrCancelled
		}
	}
}
開發者ID:bboalimoe,項目名稱:pachyderm,代碼行數:49,代碼來源:btrfs.go

示例15: run

// Run runs a command in the container, it assumes that `branch` has already
// been created.
// Notice that any failure in this function leads to the branch having
// uncommitted dirty changes. This state needs to be cleaned up before the
// pipeline is rerun. The reason we don't do it here is that even if we try our
// best the process crashing at the wrong time could still leave it in an
// inconsistent state.
func (p *pipeline) run(cmd []string) error {
	// this function always increments counter
	defer func() { p.counter++ }()
	// Check if the commit already exists
	exists, err := btrfs.FileExists(path.Join(p.outRepo, p.runCommit()))
	if err != nil {
		return err
	}
	// if the commit exists there's no work to be done
	if exists {
		return nil
	}
	// Set the command
	p.config.Config.Cmd = []string{"sh"}
	//p.config.Config.Volumes["/out"] = emptyStruct()
	// Map the out directory in as a bind
	hostPath := btrfs.HostPath(path.Join(p.outRepo, p.branch))
	bind := fmt.Sprintf("%s:/out", hostPath)
	p.config.HostConfig.Binds = append(p.config.HostConfig.Binds, bind)
	log.Print(p.config.HostConfig.Binds)
	// Make sure this bind is only visible for the duration of run
	defer func() { p.config.HostConfig.Binds = p.config.HostConfig.Binds[:len(p.config.HostConfig.Binds)-1] }()
	// Start the container
	p.container, err = startContainer(p.config)
	if err != nil {
		return err
	}
	if err := pipeToStdin(p.container, strings.NewReader(strings.Join(cmd, " ")+"\n")); err != nil {
		return err
	}
	// Create a place to put the logs
	f, err := btrfs.CreateAll(path.Join(p.outRepo, p.branch, ".log"))
	if err != nil {
		return err
	}
	defer f.Close()
	// Copy the logs from the container in to the file.
	if err = containerLogs(p.container, f); err != nil {
		return err
	}
	// Wait for the command to finish:
	exit, err := waitContainer(p.container)
	if err != nil {
		return err
	}
	if exit != 0 {
		// The command errored
		return fmt.Errorf("Command:\n\t%s\nhad exit code: %d.\n",
			strings.Join(cmd, " "), exit)
	}
	return btrfs.Commit(p.outRepo, p.runCommit(), p.branch)
}
開發者ID:plar,項目名稱:pachyderm,代碼行數:59,代碼來源:pipeline.go


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