예제 #1
0
func (s *snapshotter) Snapshot() (task.Artifact, error) {
	s.logger.Info("snapshot",
		lager.Data{
			"task":    "create-snapshot",
			"event":   "starting",
			"timeout": s.timeout.String(),
		},
	)

	if err := s.createSnapshot(); err != nil {
		s.logger.Error("snapshot",
			err,
			lager.Data{
				"task":  "create-snapshot",
				"event": "failed",
			},
		)
		return nil, err
	}

	s.logger.Info("snapshot",
		lager.Data{
			"task":    "create-snapshot",
			"event":   "done",
			"timeout": s.timeout.String(),
		},
	)

	s.logger.Info("snapshot",
		lager.Data{
			"task":  "get-rdb-path",
			"event": "starting",
		},
	)

	path, err := s.client.RDBPath()
	if err != nil {
		s.logger.Error("snapshot",
			err,
			lager.Data{
				"task":  "get-rdb-path",
				"event": "failed",
			},
		)
		return nil, err
	}

	s.logger.Info("snapshot",
		lager.Data{
			"task":  "get-rdb-path",
			"event": "done",
			"path":  path,
		},
	)

	return task.NewArtifact(path), nil
}
예제 #2
0
func (f *fakeTask) Run(artifact task.Artifact) (task.Artifact, error) {
	f.Artifact = artifact
	return task.NewArtifact(f.Name()), f.ExpectedErr
}
예제 #3
0
	})

	Describe(".Name", func() {
		It("returns the pipeline name", func() {
			pipeline := task.NewPipeline("some-pipeline", logger)

			Expect(pipeline.Name()).To(Equal("some-pipeline"))
		})

	})

	Describe(".Run", func() {
		var (
			task1            *fakeTask
			task2            *fakeTask
			originalArtifact = task.NewArtifact("path/to/artifact")
			finalArtifact    task.Artifact
			runErr           error
		)

		Context("with multiple successful tasks", func() {
			BeforeEach(func() {
				task1 = &fakeTask{TaskName: "task1"}
				task2 = &fakeTask{TaskName: "task2"}

				pipeline := task.NewPipeline("some-name", logger, task1, task2)

				finalArtifact, runErr = pipeline.Run(originalArtifact)
			})

			It("executes all tasks with given artifact", func() {
	})

	Describe(".Run", func() {
		var (
			expectedSourcePath = "path/to/source"
			expectedTargetPath = "path/to/target"
			expectedBucketName = "some-bucket-name"
			artifactOut        task.Artifact
			runErr             error
			client             *fakeS3Client
			bucket             *fakeS3Bucket
			upload             task.Task
		)

		JustBeforeEach(func() {
			artifactOut, runErr = upload.Run(task.NewArtifact(expectedSourcePath))
		})

		BeforeEach(func() {
			bucket = &fakeS3Bucket{
				BucketName: expectedBucketName,
			}

			client = &fakeS3Client{
				GetOrCreateBucketResult: bucket,
			}

			upload = task.NewS3Upload(
				expectedBucketName,
				expectedTargetPath,
				"endpoint",
예제 #5
0
			renamedDumpPath  string
			redisDir         string
			cleanup          task.Task
			artifactIn       task.Artifact
			artifactOut      task.Artifact
			runErr           error
			log              *gbytes.Buffer
			logger           lager.Logger
		)

		BeforeEach(func() {
			log = gbytes.NewBuffer()
			logger = lager.NewLogger("redis")
			logger.RegisterSink(lager.NewWriterSink(log, lager.INFO))

			artifactIn = task.NewArtifact("path/to/artifact")

			var err error
			redisDir, err = ioutil.TempDir("", "cleanup-test")
			Expect(err).ToNot(HaveOccurred())

			originalDumpPath = filepath.Join(redisDir, "dump.rdb")
			renamedDumpPath = filepath.Join(redisDir, "renamed.rdb")

			cleanup = backup.NewCleanup(originalDumpPath, renamedDumpPath, logger)
		})

		JustBeforeEach(func() {
			artifactOut, runErr = cleanup.Run(artifactIn)
		})
예제 #6
0
			logger          lager.Logger
			log             *gbytes.Buffer
		)

		BeforeEach(func() {
			tmpDirPath, err := ioutil.TempDir("", "temp")
			Expect(err).ToNot(HaveOccurred())

			finalPath = filepath.Join(tmpDirPath, "newName")
			Expect(finalPath).ToNot(BeAnExistingFile())

			file, err := ioutil.TempFile(tmpDirPath, "artifact")
			Expect(err).ToNot(HaveOccurred())

			originalPath = file.Name()
			artifact := task.NewArtifact(originalPath)

			logger = lager.NewLogger("logger")
			log = gbytes.NewBuffer()
			logger.RegisterSink(lager.NewWriterSink(log, lager.INFO))

			renameTask := task.NewRename(finalPath, logger)
			renamedArtifact, runErr = renameTask.Run(artifact)
		})

		AfterEach(func() {
			os.Remove(tmpDirPath)
		})

		It("renames the artifact on disk", func() {
			Expect(originalPath).ToNot(BeAnExistingFile())
예제 #7
0
			backuper        backup.RedisBackuper

			expectedTimeout    = 123 * time.Second
			expectedBucketName = "some-bucket-name"
			expectedTargetPath = "some-target-path"
			expectedEndpoint   = "some-endpoint"
			expectedAccessKey  = "some-access-key"
			expectedSecretKey  = "some-secret-key"
		)

		BeforeEach(func() {
			log = gbytes.NewBuffer()
			logger = lager.NewLogger("logger")
			logger.RegisterSink(lager.NewWriterSink(log, lager.INFO))

			initialArtifact = task.NewArtifact("path/to/artifact")

			providerFactory = new(fakes.FakeProviderFactory)

			snapshotter = new(fakes.FakeSnapshotter)
			snapshotter.SnapshotReturns(initialArtifact, nil)
			providerFactory.SnapshotterProviderReturns(snapshotter)

			renameTask = new(fakes.FakeTask)
			renameTask.NameReturns("rename")
			renameTask.RunReturns(task.NewArtifact("rename"), nil)
			providerFactory.RenameTaskProviderReturns(renameTask)

			s3UploadTask = new(fakes.FakeTask)
			s3UploadTask.NameReturns("s3upload")
			s3UploadTask.RunReturns(task.NewArtifact("s3upload"), nil)