本文整理汇总了Golang中github.com/cloudfoundry/bosh-agent/errors.WrapError函数的典型用法代码示例。如果您正苦于以下问题:Golang WrapError函数的具体用法?Golang WrapError怎么用?Golang WrapError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了WrapError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Pull
func (r CIRepository) Pull() (ImportRec, bool, error) {
var relSourceRecs []relSourceRec
err := r.index.ListKeys(&relSourceRecs)
if err != nil {
return ImportRec{}, false, bosherr.WrapError(err, "Finding release sources")
}
if len(relSourceRecs) == 0 {
return ImportRec{}, false, nil
}
rec := relSourceRecs[0]
r.logger.Debug(ciRepositoryLogTag, "Pulling import '%v'", rec)
importRec := ImportRec{
RelSource: rec.RelSource,
Version: rec.Version,
}
err = r.index.Remove(relSourceRec{rec.RelSource, rec.Version})
if err != nil {
return ImportRec{}, false, bosherr.WrapError(err, "Removing import")
}
return importRec, true, nil
}
示例2: diskMatchesPartitions
func (p sfdiskPartitioner) diskMatchesPartitions(devicePath string, partitionsToMatch []Partition) (result bool) {
existingPartitions, err := p.getPartitions(devicePath)
if err != nil {
err = bosherr.WrapError(err, "Getting partitions for %s", devicePath)
return
}
if len(existingPartitions) < len(partitionsToMatch) {
return
}
remainingDiskSpace, err := p.GetDeviceSizeInMb(devicePath)
if err != nil {
err = bosherr.WrapError(err, "Getting device size for %s", devicePath)
return
}
for index, partitionToMatch := range partitionsToMatch {
if index == len(partitionsToMatch)-1 {
partitionToMatch.SizeInMb = remainingDiskSpace
}
existingPartition := existingPartitions[index]
switch {
case existingPartition.Type != partitionToMatch.Type:
return
case notWithinDelta(existingPartition.SizeInMb, partitionToMatch.SizeInMb, 20):
return
}
remainingDiskSpace = remainingDiskSpace - partitionToMatch.SizeInMb
}
return true
}
示例3: validate
func (c Config) validate() error {
if c.AssetsDir == "" {
return bosherr.New("Must provide non-empty assets_dir")
}
if c.ReposDir == "" {
return bosherr.New("Must provide non-empty repos_dir")
}
err := c.EventLog.Validate()
if err != nil {
return bosherr.WrapError(err, "Validating event_log configuration")
}
if c.Blobstore.Type != bpprov.BlobstoreConfigTypeLocal {
return bosherr.New("Blobstore type must be local")
}
err = c.Blobstore.Validate()
if err != nil {
return bosherr.WrapError(err, "Validating blobstore configuration")
}
return nil
}
示例4: compileRelease
func (p ReleaseCompiler) compileRelease(pkgsCompiler bppkgscomp.PackagesCompiler, depRelease bpdep.Release) error {
relReader := p.releaseReaderFactory.NewReader(
depRelease.Name,
depRelease.Version,
depRelease.URL,
)
relRelease, err := relReader.Read()
if err != nil {
return bosherr.WrapError(err, "Reading release")
}
defer relReader.Close()
err = pkgsCompiler.Compile(relRelease)
if err != nil {
return bosherr.WrapError(err, "Compiling release packages")
}
err = p.templatesCompiler.Precompile(relRelease)
if err != nil {
return bosherr.WrapError(err, "Precompiling release job templates")
}
return nil
}
示例5: importNotes
func (i PeriodicGithubNoteImporter) importNotes() error {
// todo getting all releases; could be big
sources, err := i.releasesRepo.ListAll()
if err != nil {
return bosherr.WrapError(err, "Listing releases")
}
for _, source := range sources {
ghSource, valid := newGithubSource(source)
if !valid {
continue
}
// todo convert Source to string; argh
relVerRecs, err := i.releasesRepo.FindAll(source.Full)
if err != nil {
return bosherr.WrapError(err, "Listing all versions for release source '%s'", source)
}
err = i.importNotesForRelease(ghSource, relVerRecs)
if err != nil {
return bosherr.WrapError(err, "Importing notes for release source '%s'", source)
}
}
return nil
}
示例6: Get
func (p BlobstoreProvider) Get(provider string, options map[string]interface{}) (boshblob.Blobstore, error) {
configDir, err := p.fs.TempDir("blobstore-s3-config")
if err != nil {
return nil, bosherr.WrapError(err, "Cerating tmp dir for blobstore config")
}
configPath := filepath.Join(configDir, "config.json")
blobstore := boshblob.NewExternalBlobstore(
provider,
options,
p.fs,
p.runner,
p.uuidGen,
configPath,
)
blobstore = boshblob.NewSHA1VerifiableBlobstore(blobstore)
blobstore = boshblob.NewRetryableBlobstore(blobstore, 3, p.logger)
err = blobstore.Validate()
if err != nil {
return nil, bosherr.WrapError(err, "Validating blobstore")
}
return blobstore, nil
}
示例7: fetchOnce
func (p *PlainBucketPage) fetchOnce() (plainBucketPage_ListBucketResult, error) {
// Return memoized results; not thread safe
if p.fetchedResult != nil || p.fetchedErr != nil {
return *p.fetchedResult, p.fetchedErr
}
fullURL := p.fullURL()
p.logger.Debug(p.logTag, "Fetching bucket page from url '%s'", fullURL)
var result plainBucketPage_ListBucketResult
resp, err := http.Get(fullURL)
if err != nil {
p.fetchedErr = err
return result, bosherr.WrapError(err, "Requesting bucket page")
}
defer resp.Body.Close()
decoder := xml.NewDecoder(resp.Body)
decoder.CharsetReader = charset.NewReader
err = decoder.Decode(&result)
if err != nil {
p.fetchedErr = err
return result, bosherr.WrapError(err, "Parsing bucket page")
}
p.logger.Debug(p.logTag, "Saving bucket page result '%v'", result)
p.fetchedResult = &result
return result, nil
}
示例8: SaveAll
func (r S3StemcellsRepository) SaveAll(s3Files []bhs3.File) error {
var s3StemcellRecs []s3StemcellRec
for _, s3File := range s3Files {
url, err := s3File.URL()
if err != nil {
return bosherr.WrapError(err, "Generating S3 stemcell URL")
}
rec := s3StemcellRec{
Key: s3File.Key(),
ETag: s3File.ETag(),
Size: s3File.Size(),
LastModified: s3File.LastModified(),
URL: url,
}
s3StemcellRecs = append(s3StemcellRecs, rec)
}
err := r.index.Save(s3StemcellsKeyLatest, s3StemcellRecs)
if err != nil {
return bosherr.WrapError(err, "Saving all S3 stemcell recs")
}
return nil
}
示例9: Run
func (a MountDiskAction) Run(diskCid string) (interface{}, error) {
err := a.settingsService.LoadSettings()
if err != nil {
return nil, bosherr.WrapError(err, "Refreshing the settings")
}
settings := a.settingsService.GetSettings()
devicePath, found := settings.Disks.Persistent[diskCid]
if !found {
return nil, bosherr.New("Persistent disk with volume id '%s' could not be found", diskCid)
}
mountPoint := a.dirProvider.StoreDir()
isMountPoint, err := a.mountPoints.IsMountPoint(mountPoint)
if err != nil {
return nil, bosherr.WrapError(err, "Checking mount point")
}
if isMountPoint {
mountPoint = a.dirProvider.StoreMigrationDir()
}
err = a.diskMounter.MountPersistentDisk(devicePath, mountPoint)
if err != nil {
return nil, bosherr.WrapError(err, "Mounting persistent disk")
}
return map[string]string{}, nil
}
示例10: extractReleaseAndJobs
func (e Extractor) extractReleaseAndJobs(tgzPath string) (bprel.Release, []bpreljob.Job, error) {
var rel bprel.Release
relReader := e.releaseReaderFactory.NewTarReader("file://" + tgzPath)
rel, err := relReader.Read()
if err != nil {
return rel, nil, bosherr.WrapError(err, "Reading release")
}
defer relReader.Close()
var relJobs []bpreljob.Job
for _, j := range rel.Jobs {
relJobReader := e.jobReaderFactory.NewTarReader("file://" + j.TarPath)
relJob, err := relJobReader.Read()
if err != nil {
return rel, nil, bosherr.WrapError(err, "Reading release job '%s'", j.Name)
}
defer relJobReader.Close()
relJobs = append(relJobs, relJob)
}
return rel, relJobs, nil
}
示例11: buildPackageSpecs
func (s JobState) buildPackageSpecs() (map[string]boshas.PackageSpec, error) {
specs := map[string]boshas.PackageSpec{}
for _, template := range s.depJob.Templates {
pkgs, err := s.templatesCompiler.FindPackages(template)
if err != nil {
return specs, bosherr.WrapError(err, "Finding packages for template %s", template.Name)
}
for _, pkg := range pkgs {
rec, err := s.packagesCompiler.FindCompiledPackage(pkg)
if err != nil {
return specs, bosherr.WrapError(err, "Finding compiled package %s", pkg.Name)
}
specs[pkg.Name] = boshas.PackageSpec{
Name: pkg.Name,
Version: pkg.Version,
Sha1: rec.SHA1,
BlobstoreID: rec.BlobID,
}
}
}
return specs, nil
}
示例12: Extract
func (e Extractor) Extract(url, tgzPath string) (bhrelsrepo.ReleaseVersionRec, error) {
e.logger.Debug(e.logTag, "Extracting from '%s' (url '%s')", tgzPath, url)
var relVerRec bhrelsrepo.ReleaseVersionRec
rel, relJobs, err := e.extractReleaseAndJobs(tgzPath)
if err != nil {
return relVerRec, bosherr.WrapError(err, "Extracting release and jobs")
}
relVerRec, err = e.releasesRepo.Find(url, rel.Version)
if err != nil {
return relVerRec, bosherr.WrapError(err, "Finding release")
}
err = e.jobsRepo.SaveAll(relVerRec, relJobs)
if err != nil {
return relVerRec, bosherr.WrapError(err, "Saving release jobs into jobs repository")
}
err = e.releaseVersionsRepo.Save(relVerRec, rel)
if err != nil {
return relVerRec, bosherr.WrapError(err, "Saving release into releases repository")
}
return relVerRec, nil
}
示例13: Provision
func (p RunitProvisioner) Provision(name string, stopTimeout time.Duration) error {
p.logger.Info(runitProvisionerLogTag, "Provisioning %s service", name)
err := p.depsProvisioner.InstallRunit()
if err != nil {
return bosherr.WrapError(err, "Installing runit")
}
servicePath, enableServicePath := p.buildServicePaths(name)
err = p.stopRunAndLog(servicePath, enableServicePath, name, stopTimeout)
if err != nil {
return bosherr.WrapError(err, "Stopping run and log")
}
err = p.setUpRun(servicePath, name)
if err != nil {
return bosherr.WrapError(err, "Setting up run")
}
err = p.setUpLog(servicePath, name)
if err != nil {
return bosherr.WrapError(err, "Setting up log")
}
err = p.startRunAndLog(servicePath, enableServicePath, name)
if err != nil {
return bosherr.WrapError(err, "Starting run and log")
}
return nil
}
示例14: buildJobReaders
func (tc ConcreteTemplatesCompiler) buildJobReaders(job bpdep.Job) ([]jobReader, error) {
var readers []jobReader
for _, template := range job.Templates {
rec, found, err := tc.tplToJobRepo.FindByTemplate(template)
if err != nil {
return readers, bosherr.WrapError(err, "Finding dep-template -> release-job record %s", template.Name)
} else if !found {
return readers, bosherr.New("Expected to find dep-template -> release-job record %s", template.Name)
}
jobRec, found, err := tc.jobsRepo.FindByReleaseJob(rec)
if err != nil {
return readers, bosherr.WrapError(err, "Finding job source blob %s", template.Name)
} else if !found {
return readers, bosherr.New("Expected to find job source blob %s -- %s", template.Name, rec)
}
jobURL := fmt.Sprintf("blobstore:///%s?fingerprint=%s", jobRec.BlobID, jobRec.SHA1)
reader := jobReader{
rec: rec,
tarReader: tc.jobReaderFactory.NewReader(jobURL),
}
readers = append(readers, reader)
}
return readers, nil
}
示例15: Import
func (tr TarballRelease) Import(url string) error {
tr.logger.Debug(tr.logTag, "Importing tarball release from '%s'", url)
tgzPath, err := tr.builder.Build(tr.manifestPath)
if err != nil {
return bosherr.WrapError(err, "Building release tarball from manifest '%s'", tr.manifestPath)
}
defer tr.builder.CleanUp(tgzPath)
relVerRec, err := tr.extractor.Extract(url, tgzPath)
if err != nil {
return bosherr.WrapError(err, "Importing release version from tgz '%s'", tgzPath)
}
err = tr.uploader.Upload(relVerRec, tgzPath)
if err != nil {
return bosherr.WrapError(err, "Uploading release verison '%v'", relVerRec)
}
// Save release version only after everything else was successfully imported
err = tr.releasesRepo.Add(relVerRec)
if err != nil {
return bosherr.WrapError(err, "Saving release version into release versions repository")
}
return nil
}