本文整理汇总了Golang中github.com/pachyderm/pachyderm/src/pfs/pfsutil.PutFile函数的典型用法代码示例。如果您正苦于以下问题:Golang PutFile函数的具体用法?Golang PutFile怎么用?Golang PutFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PutFile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestFromCommit
func TestFromCommit(t *testing.T) {
t.Parallel()
repo := uniqueString("TestFromCommit")
pachClient := getPachClient(t)
seed := time.Now().UnixNano()
rand := rand.New(rand.NewSource(seed))
err := pfsutil.CreateRepo(pachClient, repo)
require.NoError(t, err)
commit1, err := pfsutil.StartCommit(pachClient, repo, "")
require.NoError(t, err)
_, err = pfsutil.PutFile(pachClient, repo, commit1.Id, "file", 0, workload.NewReader(rand, KB))
require.NoError(t, err)
err = pfsutil.FinishCommit(pachClient, repo, commit1.Id)
require.NoError(t, err)
commit2, err := pfsutil.StartCommit(pachClient, repo, commit1.Id)
require.NoError(t, err)
_, err = pfsutil.PutFile(pachClient, repo, commit2.Id, "file", 0, workload.NewReader(rand, KB))
require.NoError(t, err)
err = pfsutil.FinishCommit(pachClient, repo, commit2.Id)
require.NoError(t, err)
var buffer bytes.Buffer
require.NoError(t, pfsutil.GetFile(pachClient, repo, commit2.Id, "file", 0, 0, commit1.Id, nil, &buffer))
require.Equal(t, buffer.Len(), KB)
buffer = bytes.Buffer{}
require.NoError(t, pfsutil.GetFile(pachClient, repo, commit2.Id, "file", 0, 0, "", nil, &buffer))
require.Equal(t, buffer.Len(), 2*KB)
}
示例2: TestJob
func TestJob(t *testing.T) {
dataRepo := uniqueString("TestJob.data")
pfsClient := getPfsClient(t)
require.NoError(t, pfsutil.CreateRepo(pfsClient, dataRepo))
commit, err := pfsutil.StartCommit(pfsClient, dataRepo, "")
require.NoError(t, err)
_, err = pfsutil.PutFile(pfsClient, dataRepo, commit.Id, "file", 0, strings.NewReader("foo"))
require.NoError(t, err)
require.NoError(t, pfsutil.FinishCommit(pfsClient, dataRepo, commit.Id))
ppsClient := getPpsClient(t)
job, err := ppsutil.CreateJob(
ppsClient,
"",
[]string{"cp", path.Join("/pfs", dataRepo, "file"), "/pfs/out/file"},
"",
1,
[]*pfs.Commit{commit},
"",
)
require.NoError(t, err)
inspectJobRequest := &pps.InspectJobRequest{
Job: job,
BlockOutput: true,
BlockState: true,
}
jobInfo, err := ppsClient.InspectJob(context.Background(), inspectJobRequest)
require.NoError(t, err)
var buffer bytes.Buffer
require.NoError(t, pfsutil.GetFile(pfsClient, jobInfo.OutputCommit.Repo.Name, jobInfo.OutputCommit.Id, "file", 0, 0, nil, &buffer))
require.Equal(t, "foo", buffer.String())
}
示例3: TestJob
func TestJob(t *testing.T) {
t.Parallel()
dataRepo := uniqueString("TestJob.data")
pachClient := getPachClient(t)
require.NoError(t, pfsutil.CreateRepo(pachClient, dataRepo))
commit, err := pfsutil.StartCommit(pachClient, dataRepo, "")
require.NoError(t, err)
_, err = pfsutil.PutFile(pachClient, dataRepo, commit.Id, "file", 0, strings.NewReader("foo\n"))
require.NoError(t, err)
require.NoError(t, pfsutil.FinishCommit(pachClient, dataRepo, commit.Id))
job, err := ppsutil.CreateJob(
pachClient,
"",
[]string{"cp", path.Join("/pfs", dataRepo, "file"), "/pfs/out/file"},
nil,
1,
[]*pps.JobInput{{Commit: commit}},
"",
)
require.NoError(t, err)
inspectJobRequest := &pps.InspectJobRequest{
Job: job,
BlockOutput: true,
BlockState: true,
}
jobInfo, err := pachClient.InspectJob(context.Background(), inspectJobRequest)
require.NoError(t, err)
require.Equal(t, pps.JobState_JOB_STATE_SUCCESS.String(), jobInfo.State.String())
commitInfo, err := pfsutil.InspectCommit(pachClient, jobInfo.OutputCommit.Repo.Name, jobInfo.OutputCommit.Id)
require.NoError(t, err)
require.Equal(t, pfs.CommitType_COMMIT_TYPE_READ, commitInfo.CommitType)
var buffer bytes.Buffer
require.NoError(t, pfsutil.GetFile(pachClient, jobInfo.OutputCommit.Repo.Name, jobInfo.OutputCommit.Id, "file", 0, 0, "", nil, &buffer))
require.Equal(t, "foo\n", buffer.String())
}
示例4: doWrites
func doWrites(tb testing.TB, apiClient pfs.APIClient, repoName string, commitID string) {
var wg sync.WaitGroup
defer wg.Wait()
for i := 0; i < testSize; i++ {
i := i
wg.Add(1)
go func() {
defer wg.Done()
_, iErr := pfsutil.PutFile(apiClient, repoName, commitID,
fmt.Sprintf("a/b/file%d", i), 0, strings.NewReader(fmt.Sprintf("hello%d", i)))
require.NoError(tb, iErr)
_, iErr = pfsutil.PutFile(apiClient, repoName, commitID,
fmt.Sprintf("a/c/file%d", i), 0, strings.NewReader(fmt.Sprintf("hello%d", i)))
require.NoError(tb, iErr)
}()
}
}
示例5: Write
func (f *file) Write(ctx context.Context, request *fuse.WriteRequest, response *fuse.WriteResponse) error {
written, err := pfsutil.PutFile(f.fs.apiClient, f.fs.repositoryName, f.commitID, f.path, request.Offset, bytes.NewReader(request.Data))
if err != nil {
return err
}
response.Size = written
if f.size < request.Offset+int64(written) {
f.size = request.Offset + int64(written)
}
return nil
}
示例6: TestGrep
func TestGrep(t *testing.T) {
t.Skip()
t.Parallel()
dataRepo := uniqueString("TestGrep.data")
pfsClient := getPfsClient(t)
require.NoError(t, pfsutil.CreateRepo(pfsClient, dataRepo))
commit, err := pfsutil.StartCommit(pfsClient, dataRepo, "")
require.NoError(t, err)
for i := 0; i < 100; i++ {
_, err = pfsutil.PutFile(pfsClient, dataRepo, commit.Id, fmt.Sprintf("file%d", i), 0, strings.NewReader("foo\nbar\nfizz\nbuzz\n"))
require.NoError(t, err)
}
require.NoError(t, pfsutil.FinishCommit(pfsClient, dataRepo, commit.Id))
ppsClient := getPpsClient(t)
job1, err := ppsutil.CreateJob(
ppsClient,
"",
[]string{"bash"},
fmt.Sprintf("grep foo /pfs/%s/* >/pfs/out/foo", dataRepo),
1,
[]*pps.JobInput{{Commit: commit}},
"",
)
require.NoError(t, err)
job2, err := ppsutil.CreateJob(
ppsClient,
"",
[]string{"bash"},
fmt.Sprintf("grep foo /pfs/%s/* >/pfs/out/foo", dataRepo),
4,
[]*pps.JobInput{{Commit: commit}},
"",
)
require.NoError(t, err)
inspectJobRequest := &pps.InspectJobRequest{
Job: job1,
BlockOutput: true,
BlockState: true,
}
job1Info, err := ppsClient.InspectJob(context.Background(), inspectJobRequest)
require.NoError(t, err)
inspectJobRequest.Job = job2
job2Info, err := ppsClient.InspectJob(context.Background(), inspectJobRequest)
require.NoError(t, err)
repo1Info, err := pfsutil.InspectRepo(pfsClient, job1Info.OutputCommit.Repo.Name)
require.NoError(t, err)
repo2Info, err := pfsutil.InspectRepo(pfsClient, job2Info.OutputCommit.Repo.Name)
require.NoError(t, err)
require.Equal(t, repo1Info.SizeBytes, repo2Info.SizeBytes)
}
示例7: Write
func (f *file) Write(ctx context.Context, request *fuse.WriteRequest, response *fuse.WriteResponse) (retErr error) {
defer func() {
protolog.Info(&FileWrite{&f.Node, errorToString(retErr)})
}()
written, err := pfsutil.PutFile(f.fs.apiClient, f.File.Commit.Repo.Name, f.File.Commit.Id, f.File.Path, request.Offset, bytes.NewReader(request.Data))
if err != nil {
return err
}
response.Size = written
if f.size < request.Offset+int64(written) {
f.size = request.Offset + int64(written)
}
return nil
}
示例8: TestSharding
func TestSharding(t *testing.T) {
t.Parallel()
repo := uniqueString("TestSharding")
pachClient := getPachClient(t)
err := pfsutil.CreateRepo(pachClient, repo)
require.NoError(t, err)
commit, err := pfsutil.StartCommit(pachClient, repo, "")
require.NoError(t, err)
var wg sync.WaitGroup
for i := 0; i < NUMFILES; i++ {
i := i
wg.Add(1)
go func() {
defer wg.Done()
rand := rand.New(rand.NewSource(int64(i)))
_, err = pfsutil.PutFile(pachClient, repo, commit.Id, fmt.Sprintf("file%d", i), 0, workload.NewReader(rand, KB))
require.NoError(t, err)
}()
}
wg.Wait()
err = pfsutil.FinishCommit(pachClient, repo, commit.Id)
require.NoError(t, err)
wg = sync.WaitGroup{}
for i := 0; i < NUMFILES; i++ {
i := i
wg.Add(1)
go func() {
defer wg.Done()
var buffer1Shard bytes.Buffer
var buffer4Shard bytes.Buffer
shard := &pfs.Shard{FileModulus: 1, BlockModulus: 1}
err := pfsutil.GetFile(pachClient, repo, commit.Id,
fmt.Sprintf("file%d", i), 0, 0, "", shard, &buffer1Shard)
require.NoError(t, err)
shard.BlockModulus = 4
for blockNumber := uint64(0); blockNumber < 4; blockNumber++ {
shard.BlockNumber = blockNumber
err := pfsutil.GetFile(pachClient, repo, commit.Id,
fmt.Sprintf("file%d", i), 0, 0, "", shard, &buffer4Shard)
require.NoError(t, err)
}
require.Equal(t, buffer1Shard.Len(), buffer4Shard.Len())
}()
}
wg.Wait()
}
示例9: TestBigWrite
func TestBigWrite(t *testing.T) {
t.Parallel()
protolog.SetLevel(protolog.Level_LEVEL_DEBUG)
repo := uniqueString("TestBigWrite")
pfsClient := getPfsClient(t)
err := pfsutil.CreateRepo(pfsClient, repo)
require.NoError(t, err)
commit, err := pfsutil.StartCommit(pfsClient, repo, "")
require.NoError(t, err)
rand := rand.New(rand.NewSource(5))
_, err = pfsutil.PutFile(pfsClient, repo, commit.Id, "file", 0, workload.NewReader(rand, 10000))
require.NoError(t, err)
err = pfsutil.FinishCommit(pfsClient, repo, commit.Id)
require.NoError(t, err)
var buffer bytes.Buffer
err = pfsutil.GetFile(pfsClient, repo, commit.Id, "file", 0, 0, nil, &buffer)
require.NoError(t, err)
}
示例10: TestSharding
func TestSharding(t *testing.T) {
t.Parallel()
repo := uniqueString("TestSharding")
pfsClient := getPfsClient(t)
err := pfsutil.CreateRepo(pfsClient, repo)
require.NoError(t, err)
commit, err := pfsutil.StartCommit(pfsClient, repo, "")
require.NoError(t, err)
var wg sync.WaitGroup
for i := 0; i < NUMFILES; i++ {
i := i
wg.Add(1)
go func() {
defer wg.Done()
rand := rand.New(rand.NewSource(int64(i)))
_, err = pfsutil.PutFile(pfsClient, repo, commit.Id, fmt.Sprintf("file%d", i), 0, workload.NewReader(rand, 128*1024*1024))
require.NoError(t, err)
}()
}
wg.Wait()
err = pfsutil.FinishCommit(pfsClient, repo, commit.Id)
require.NoError(t, err)
}
示例11: TestGrep
func TestGrep(t *testing.T) {
t.Parallel()
dataRepo := uniqueString("pachyderm.TestGrep.data")
pfsClient := getPfsClient(t)
require.NoError(t, pfsutil.CreateRepo(pfsClient, dataRepo))
commit, err := pfsutil.StartCommit(pfsClient, dataRepo, "")
require.NoError(t, err)
for i := 0; i < 100; i++ {
_, err = pfsutil.PutFile(pfsClient, dataRepo, commit.Id, fmt.Sprintf("file%d", i), 0, strings.NewReader("foo\nbar\nfizz\nbuzz\n"))
require.NoError(t, err)
}
require.NoError(t, pfsutil.FinishCommit(pfsClient, dataRepo, commit.Id))
ppsClient := getPpsClient(t)
_, err = ppsutil.CreateJob(
ppsClient,
"",
[]string{"bash"},
fmt.Sprintf("grep foo /pfs/%s/* >/pfs/out/foo", dataRepo),
1,
[]*pps.JobInput{{Commit: commit}},
"",
)
require.NoError(t, err)
}
示例12: testMount
func testMount(t *testing.T, apiClient pfs.ApiClient, internalAPIClient pfs.InternalApiClient, cluster Cluster) {
repositoryName := "testMountRepo"
err := pfsutil.CreateRepo(apiClient, repositoryName)
require.NoError(t, err)
directory := "/compile/testMount"
mounter := fuse.NewMounter(apiClient)
err = mounter.Mount(repositoryName, directory, "", 0, 1)
require.NoError(t, err)
_, err = os.Stat(filepath.Join(directory, "scratch"))
require.NoError(t, err)
commit, err := pfsutil.StartCommit(apiClient, repositoryName, "scratch")
require.NoError(t, err)
require.NotNil(t, commit)
newCommitID := commit.Id
_, err = os.Stat(filepath.Join(directory, newCommitID))
require.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(directory, newCommitID, "foo"), []byte("foo"), 0666)
require.NoError(t, err)
_, err = pfsutil.PutFile(apiClient, repositoryName, newCommitID, "bar", 0, strings.NewReader("bar"))
require.NoError(t, err)
bigValue := make([]byte, 1024*1024)
for i := 0; i < 1024*1024; i++ {
bigValue[i] = 'a'
}
err = ioutil.WriteFile(filepath.Join(directory, newCommitID, "big1"), bigValue, 0666)
require.NoError(t, err)
_, err = pfsutil.PutFile(apiClient, repositoryName, newCommitID, "big2", 0, bytes.NewReader(bigValue))
require.NoError(t, err)
err = pfsutil.FinishCommit(apiClient, repositoryName, newCommitID)
require.NoError(t, err)
fInfo, err := os.Stat(filepath.Join(directory, newCommitID, "foo"))
require.NoError(t, err)
require.Equal(t, int64(3), fInfo.Size())
data, err := ioutil.ReadFile(filepath.Join(directory, newCommitID, "foo"))
require.NoError(t, err)
require.Equal(t, "foo", string(data))
data, err = ioutil.ReadFile(filepath.Join(directory, newCommitID, "bar"))
require.NoError(t, err)
require.Equal(t, "bar", string(data))
data, err = ioutil.ReadFile(filepath.Join(directory, newCommitID, "big1"))
require.NoError(t, err)
require.Equal(t, bigValue, data)
data, err = ioutil.ReadFile(filepath.Join(directory, newCommitID, "big2"))
require.NoError(t, err)
require.Equal(t, bigValue, data)
err = mounter.Unmount(directory)
require.NoError(t, err)
err = mounter.Wait(directory)
require.NoError(t, err)
}
示例13: testMount
func testMount(t *testing.T, apiClient pfs.APIClient, cluster Cluster) {
repoName := "testMountRepo"
err := pfsutil.CreateRepo(apiClient, repoName)
require.NoError(t, err)
directory := "/compile/testMount"
mounter := fuse.NewMounter("localhost", apiClient)
ready := make(chan bool)
go func() {
err = mounter.Mount(directory, &pfs.Shard{Number: 0, Modulus: 1}, nil, ready)
require.NoError(t, err)
}()
<-ready
_, err = os.Stat(filepath.Join(directory, repoName))
require.NoError(t, err)
commit, err := pfsutil.StartCommit(apiClient, repoName, "")
require.NoError(t, err)
require.NotNil(t, commit)
newCommitID := commit.Id
_, err = os.Stat(filepath.Join(directory, repoName, newCommitID))
require.NoError(t, err)
err = ioutil.WriteFile(filepath.Join(directory, repoName, newCommitID, "foo"), []byte("foo"), 0666)
require.NoError(t, err)
_, err = pfsutil.PutFile(apiClient, repoName, newCommitID, "bar", 0, strings.NewReader("bar"))
require.NoError(t, err)
bigValue := make([]byte, 1024*1024)
for i := 0; i < 1024*1024; i++ {
bigValue[i] = 'a'
}
err = ioutil.WriteFile(filepath.Join(directory, repoName, newCommitID, "big1"), bigValue, 0666)
require.NoError(t, err)
_, err = pfsutil.PutFile(apiClient, repoName, newCommitID, "big2", 0, bytes.NewReader(bigValue))
require.NoError(t, err)
err = pfsutil.FinishCommit(apiClient, repoName, newCommitID)
require.NoError(t, err)
fInfo, err := os.Stat(filepath.Join(directory, repoName, newCommitID, "foo"))
require.NoError(t, err)
require.Equal(t, int64(3), fInfo.Size())
data, err := ioutil.ReadFile(filepath.Join(directory, repoName, newCommitID, "foo"))
require.NoError(t, err)
require.Equal(t, "foo", string(data))
data, err = ioutil.ReadFile(filepath.Join(directory, repoName, newCommitID, "bar"))
require.NoError(t, err)
require.Equal(t, "bar", string(data))
data, err = ioutil.ReadFile(filepath.Join(directory, repoName, newCommitID, "big1"))
require.NoError(t, err)
require.Equal(t, bigValue, data)
data, err = ioutil.ReadFile(filepath.Join(directory, repoName, newCommitID, "big2"))
require.NoError(t, err)
require.Equal(t, bigValue, data)
err = mounter.Unmount(directory)
require.NoError(t, err)
}
示例14: Cmds
//.........这里部分代码省略.........
Short: "Delete a commit.",
Long: "Delete a commit.",
Run: pkgcobra.RunFixedArgs(2, func(args []string) error {
apiClient, err := getAPIClient(address)
if err != nil {
return err
}
return pfsutil.DeleteCommit(apiClient, args[0], args[1])
}),
}
mkdir := &cobra.Command{
Use: "mkdir repo-name commit-id path/to/dir",
Short: "Make a directory.",
Long: "Make a directory. Parent directories need not exist.",
Run: pkgcobra.RunFixedArgs(3, func(args []string) error {
apiClient, err := getAPIClient(address)
if err != nil {
return err
}
return pfsutil.MakeDirectory(apiClient, args[0], args[1], args[2])
}),
}
putFile := &cobra.Command{
Use: "put-file repo-name commit-id path/to/file",
Short: "Put a file from stdin",
Long: "Put a file from stdin. Directories must exist. commit-id must be a writeable commit.",
Run: pkgcobra.RunFixedArgs(3, func(args []string) error {
apiClient, err := getAPIClient(address)
if err != nil {
return err
}
_, err = pfsutil.PutFile(apiClient, args[0], args[1], args[2], 0, os.Stdin)
return err
}),
}
getFile := &cobra.Command{
Use: "get-file repo-name commit-id path/to/file",
Short: "Return the contents of a file.",
Long: "Return the contents of a file.",
Run: pkgcobra.RunFixedArgs(3, func(args []string) error {
apiClient, err := getAPIClient(address)
if err != nil {
return err
}
return pfsutil.GetFile(apiClient, args[0], args[1], args[2], 0, math.MaxInt64, shard(), os.Stdout)
}),
}
getFile.Flags().IntVarP(&number, "shard", "s", 0, "shard to read from")
getFile.Flags().IntVarP(&modulus, "modulus", "m", 1, "modulus of the shards")
inspectFile := &cobra.Command{
Use: "inspect-file repo-name commit-id path/to/file",
Short: "Return info about a file.",
Long: "Return info about a file.",
Run: pkgcobra.RunFixedArgs(3, func(args []string) error {
apiClient, err := getAPIClient(address)
if err != nil {
return err
}
fileInfo, err := pfsutil.InspectFile(apiClient, args[0], args[1], args[2], shard())
if err != nil {
return err
}
示例15: testReplica
func testReplica(t *testing.T, apiClient pfs.ApiClient, internalAPIClient pfs.InternalApiClient) {
masterName := TestRepositoryName()
err := pfsutil.InitRepository(apiClient, masterName, false)
require.NoError(t, err)
replicaName := TestRepositoryName()
err = pfsutil.InitRepository(apiClient, replicaName, true)
require.NoError(t, err)
for i := 0; i < testShardsPerServer*testNumServers; i++ {
var buffer bytes.Buffer
err := pfsutil.PullDiff(internalAPIClient, masterName, "scratch", uint64(i), &buffer)
require.NoError(t, err)
err = pfsutil.PushDiff(internalAPIClient, replicaName, "scratch", uint64(i), &buffer)
require.NoError(t, err)
}
getCommitInfoResponse, err := pfsutil.GetCommitInfo(apiClient, replicaName, "scratch")
require.NoError(t, err)
require.NotNil(t, getCommitInfoResponse)
require.NotNil(t, getCommitInfoResponse.CommitInfo)
require.Equal(t, "scratch", getCommitInfoResponse.CommitInfo.Commit.Id)
require.Equal(t, pfs.CommitType_COMMIT_TYPE_READ, getCommitInfoResponse.CommitInfo.CommitType)
require.Nil(t, getCommitInfoResponse.CommitInfo.ParentCommit)
branchResponse, err := pfsutil.Branch(apiClient, masterName, "scratch")
require.NoError(t, err)
require.NotNil(t, branchResponse)
newCommitID := branchResponse.Commit.Id
var wg sync.WaitGroup
for i := 0; i < testSize; i++ {
i := i
wg.Add(1)
go func() {
defer wg.Done()
_, iErr := pfsutil.PutFile(apiClient, masterName, newCommitID,
fmt.Sprintf("file%d", i), 0, strings.NewReader(fmt.Sprintf("hello%d", i)))
require.NoError(t, iErr)
}()
}
wg.Wait()
err = pfsutil.Commit(apiClient, masterName, newCommitID)
require.NoError(t, err)
for i := 0; i < testShardsPerServer*testNumServers; i++ {
var buffer bytes.Buffer
err := pfsutil.PullDiff(internalAPIClient, masterName, newCommitID, uint64(i), &buffer)
require.NoError(t, err)
err = pfsutil.PushDiff(internalAPIClient, replicaName, newCommitID, uint64(i), &buffer)
require.NoError(t, err)
}
getCommitInfoResponse, err = pfsutil.GetCommitInfo(apiClient, replicaName, newCommitID)
require.NoError(t, err)
require.NotNil(t, getCommitInfoResponse)
require.NotNil(t, getCommitInfoResponse.CommitInfo)
require.Equal(t, newCommitID, getCommitInfoResponse.CommitInfo.Commit.Id)
require.Equal(t, pfs.CommitType_COMMIT_TYPE_READ, getCommitInfoResponse.CommitInfo.CommitType)
require.Equal(t, "scratch", getCommitInfoResponse.CommitInfo.ParentCommit.Id)
}