コード例 #1
0
ファイル: create.go プロジェクト: imoapps/juju
// Create is the API method that requests juju to create a new backup
// of its state.  It returns the metadata for that backup.
func (a *API) Create(args params.BackupsCreateArgs) (p params.BackupsMetadataResult, err error) {
	backupsMethods, closer := newBackups(a.st)
	defer closer.Close()

	session := a.st.MongoSession().Copy()
	defer session.Close()

	// Don't go if HA isn't ready.
	err = waitUntilReady(session, 60)
	if err != nil {
		return p, errors.Annotatef(err, "HA not ready; try again later")
	}

	mgoInfo := a.st.MongoConnectionInfo()
	dbInfo, err := backups.NewDBInfo(mgoInfo, session)
	if err != nil {
		return p, errors.Trace(err)
	}

	meta, err := backups.NewMetadataState(a.st, a.machineID)
	if err != nil {
		return p, errors.Trace(err)
	}
	meta.Notes = args.Notes

	err = backupsMethods.Create(meta, a.paths, dbInfo)
	if err != nil {
		return p, errors.Trace(err)
	}

	return ResultFromMetadata(meta), nil
}
コード例 #2
0
ファイル: download_test.go プロジェクト: exekias/juju
func (s *downloadSuite) TestSuccessfulRequest(c *gc.C) {
	store := backups.NewStorage(s.State)
	defer store.Close()
	backupsState := backups.NewBackups(store)

	r := strings.NewReader("<compressed archive data>")
	meta, err := backups.NewMetadataState(s.State, "0")
	c.Assert(err, jc.ErrorIsNil)
	// The Add method requires the length to be set
	// otherwise the content is assumed to have length 0.
	meta.Raw.Size = int64(r.Len())
	id, err := backupsState.Add(r, meta)
	c.Assert(err, jc.ErrorIsNil)
	resultArchive, err := s.client.Download(id)
	c.Assert(err, jc.ErrorIsNil)

	resultData, err := ioutil.ReadAll(resultArchive)
	c.Assert(err, jc.ErrorIsNil)
	c.Check(string(resultData), gc.Equals, "<compressed archive data>")
}