本文整理匯總了Golang中github.com/cloudfoundry/bosh-init/ui.Stage類的典型用法代碼示例。如果您正苦於以下問題:Golang Stage類的具體用法?Golang Stage怎麽用?Golang Stage使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Stage類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Upload
// Upload stemcell to an IAAS. It does the following steps:
// 1) uploads the stemcell to the cloud (if needed),
// 2) saves a record of the uploaded stemcell in the repo
func (m *manager) Upload(extractedStemcell ExtractedStemcell, uploadStage biui.Stage) (cloudStemcell CloudStemcell, err error) {
manifest := extractedStemcell.Manifest()
stageName := fmt.Sprintf("Uploading stemcell '%s/%s'", manifest.Name, manifest.Version)
err = uploadStage.Perform(stageName, func() error {
foundStemcellRecord, found, err := m.repo.Find(manifest.Name, manifest.Version)
if err != nil {
return bosherr.WrapError(err, "Finding existing stemcell record in repo")
}
if found {
cloudStemcell = NewCloudStemcell(foundStemcellRecord, m.repo, m.cloud)
return biui.NewSkipStageError(bosherr.Errorf("Found stemcell: %#v", foundStemcellRecord), "Stemcell already uploaded")
}
cid, err := m.cloud.CreateStemcell(manifest.ImagePath, manifest.CloudProperties)
if err != nil {
return bosherr.WrapErrorf(err, "creating stemcell (%s %s)", manifest.Name, manifest.Version)
}
stemcellRecord, err := m.repo.Save(manifest.Name, manifest.Version, cid)
if err != nil {
//TODO: delete stemcell from cloud when saving fails
return bosherr.WrapErrorf(err, "saving stemcell record in repo (cid=%s, stemcell=%s)", cid, extractedStemcell)
}
cloudStemcell = NewCloudStemcell(stemcellRecord, m.repo, m.cloud)
return nil
})
if err != nil {
return cloudStemcell, err
}
return cloudStemcell, nil
}
示例2: UpdateJobs
func (i *instance) UpdateJobs(
deploymentManifest bideplmanifest.Manifest,
stage biui.Stage,
) error {
newState, err := i.stateBuilder.Build(i.jobName, i.id, deploymentManifest, stage)
if err != nil {
return bosherr.WrapErrorf(err, "Building state for instance '%s/%d'", i.jobName, i.id)
}
stepName := fmt.Sprintf("Updating instance '%s/%d'", i.jobName, i.id)
err = stage.Perform(stepName, func() error {
err := i.vm.Stop()
if err != nil {
return bosherr.WrapError(err, "Stopping the agent")
}
err = i.vm.Apply(newState.ToApplySpec())
if err != nil {
return bosherr.WrapError(err, "Applying the agent state")
}
err = i.vm.Start()
if err != nil {
return bosherr.WrapError(err, "Starting the agent")
}
return nil
})
if err != nil {
return err
}
return i.waitUntilJobsAreRunning(deploymentManifest.Update.UpdateWatchTime, stage)
}
示例3: shutdown
func (i *instance) shutdown(
pingTimeout time.Duration,
pingDelay time.Duration,
stage biui.Stage,
) error {
stepName := fmt.Sprintf("Waiting for the agent on VM '%s'", i.vm.CID())
waitingForAgentErr := stage.Perform(stepName, func() error {
if err := i.vm.WaitUntilReady(pingTimeout, pingDelay); err != nil {
return bosherr.WrapError(err, "Agent unreachable")
}
return nil
})
if waitingForAgentErr != nil {
i.logger.Warn(i.logTag, "Gave up waiting for agent: %s", waitingForAgentErr.Error())
return nil
}
if err := i.stopJobs(stage); err != nil {
return err
}
if err := i.unmountDisks(stage); err != nil {
return err
}
return nil
}
示例4: Delete
func (i *instance) Delete(
pingTimeout time.Duration,
pingDelay time.Duration,
stage biui.Stage,
) error {
vmExists, err := i.vm.Exists()
if err != nil {
return bosherr.WrapErrorf(err, "Checking existance of vm for instance '%s/%d'", i.jobName, i.id)
}
if vmExists {
if err = i.shutdown(pingTimeout, pingDelay, stage); err != nil {
return err
}
}
// non-existent VMs still need to be 'deleted' to clean up related resources owned by the CPI
stepName := fmt.Sprintf("Deleting VM '%s'", i.vm.CID())
return stage.Perform(stepName, func() error {
err := i.vm.Delete()
cloudErr, ok := err.(bicloud.Error)
if ok && cloudErr.Type() == bicloud.VMNotFoundError {
return biui.NewSkipStageError(cloudErr, "VM not found")
}
return err
})
}
示例5: GetStemcell
func (s Fetcher) GetStemcell(deploymentManifest bideplmanifest.Manifest, stage biui.Stage) (ExtractedStemcell, error) {
stemcell, err := deploymentManifest.Stemcell(deploymentManifest.JobName())
if err != nil {
return nil, err
}
stemcellTarballPath, err := s.TarballProvider.Get(stemcell, stage)
if err != nil {
return nil, err
}
var extractedStemcell ExtractedStemcell
err = stage.Perform("Validating stemcell", func() error {
extractedStemcell, err = s.StemcellExtractor.Extract(stemcellTarballPath)
if err != nil {
return bosherr.WrapErrorf(err, "Extracting stemcell from '%s'", stemcellTarballPath)
}
return nil
})
if err != nil {
return nil, err
}
return extractedStemcell, nil
}
示例6: renderJobTemplates
// renderJobTemplates renders all the release job templates for multiple release jobs specified
// by a deployment job and randomly uploads them to blobstore
func (b *jobRenderer) renderJobTemplates(
releaseJobs []bireljob.Job,
releaseJobProperties map[string]*biproperty.Map,
jobProperties biproperty.Map,
globalProperties biproperty.Map,
deploymentName string,
stage biui.Stage,
) ([]RenderedJobRef, error) {
renderedJobRefs := make([]RenderedJobRef, 0, len(releaseJobs))
err := stage.Perform("Rendering job templates", func() error {
renderedJobList, err := b.jobListRenderer.Render(releaseJobs, releaseJobProperties, jobProperties, globalProperties, deploymentName, "")
if err != nil {
return err
}
defer renderedJobList.DeleteSilently()
for _, renderedJob := range renderedJobList.All() {
renderedJobRef, err := b.compressAndUpload(renderedJob)
if err != nil {
return err
}
renderedJobRefs = append(renderedJobRefs, renderedJobRef)
}
return nil
})
return renderedJobRefs, err
}
示例7: GetDeploymentManifest
func (y DeploymentManifestParser) GetDeploymentManifest(deploymentManifestPath string, releaseSetManifest birelsetmanifest.Manifest, stage biui.Stage) (bideplmanifest.Manifest, error) {
var deploymentManifest bideplmanifest.Manifest
err := stage.Perform("Validating deployment manifest", func() error {
var err error
deploymentManifest, err = y.DeploymentParser.Parse(deploymentManifestPath)
if err != nil {
return bosherr.WrapErrorf(err, "Parsing deployment manifest '%s'", deploymentManifestPath)
}
err = y.DeploymentValidator.Validate(deploymentManifest, releaseSetManifest)
if err != nil {
return bosherr.WrapError(err, "Validating deployment manifest")
}
err = y.DeploymentValidator.ValidateReleaseJobs(deploymentManifest, y.ReleaseManager)
if err != nil {
return bosherr.WrapError(err, "Validating deployment jobs refer to jobs in release")
}
return nil
})
if err != nil {
return bideplmanifest.Manifest{}, err
}
return deploymentManifest, nil
}
示例8: compilePackages
// compilePackages compiles the specified packages, in the order specified, uploads them to the Blobstore, and returns the blob references
func (c *dependencyCompiler) compilePackages(requiredPackages []*birelpkg.Package, stage biui.Stage) ([]CompiledPackageRef, error) {
packageRefs := make([]CompiledPackageRef, 0, len(requiredPackages))
for _, pkg := range requiredPackages {
stepName := fmt.Sprintf("Compiling package '%s/%s'", pkg.Name, pkg.Fingerprint)
err := stage.Perform(stepName, func() error {
compiledPackageRecord, err := c.packageCompiler.Compile(pkg)
if err != nil {
return err
}
packageRef := CompiledPackageRef{
Name: pkg.Name,
Version: pkg.Fingerprint,
BlobstoreID: compiledPackageRecord.BlobID,
SHA1: compiledPackageRecord.BlobSHA1,
}
packageRefs = append(packageRefs, packageRef)
return nil
})
if err != nil {
return nil, err
}
}
return packageRefs, nil
}
示例9: stopRegistryNice
func (i *installation) stopRegistryNice(logger boshlog.Logger, stage biui.Stage) {
err := stage.Perform("Stopping registry", func() error {
return i.StopRegistry()
})
if err != nil {
logger.Warn("installation", "Registry failed to stop: %s", err)
}
}
示例10: attachDisk
func (d *diskDeployer) attachDisk(disk bidisk.Disk, vm VM, stage biui.Stage) error {
stageName := fmt.Sprintf("Attaching disk '%s' to VM '%s'", disk.CID(), vm.CID())
err := stage.Perform(stageName, func() error {
return vm.AttachDisk(disk)
})
return err
}
示例11: createDisk
func (d *diskDeployer) createDisk(diskPool bideplmanifest.DiskPool, vm VM, stage biui.Stage) (disk bidisk.Disk, err error) {
err = stage.Perform("Creating disk", func() error {
disk, err = d.diskManager.Create(diskPool, vm.CID())
return err
})
return disk, err
}
示例12: WithRunningRegistry
func (i *installation) WithRunningRegistry(logger boshlog.Logger, stage biui.Stage, fn func() error) error {
err := stage.Perform("Starting registry", func() error {
return i.StartRegistry()
})
if err != nil {
return err
}
defer i.stopRegistryNice(logger, stage)
return fn()
}
示例13: migrateDisk
func (d *diskDeployer) migrateDisk(
originalDisk bidisk.Disk,
diskPool bideplmanifest.DiskPool,
vm VM,
stage biui.Stage,
) (newDisk bidisk.Disk, err error) {
d.logger.Debug(d.logTag, "Migrating disk '%s'", originalDisk.CID())
err = stage.Perform("Creating disk", func() error {
newDisk, err = d.diskManager.Create(diskPool, vm.CID())
return err
})
if err != nil {
return newDisk, err
}
stageName := fmt.Sprintf("Attaching disk '%s' to VM '%s'", newDisk.CID(), vm.CID())
err = stage.Perform(stageName, func() error {
return vm.AttachDisk(newDisk)
})
if err != nil {
return newDisk, err
}
stageName = fmt.Sprintf("Migrating disk content from '%s' to '%s'", originalDisk.CID(), newDisk.CID())
err = stage.Perform(stageName, func() error {
return vm.MigrateDisk()
})
if err != nil {
return newDisk, err
}
err = d.updateCurrentDiskRecord(newDisk)
if err != nil {
return newDisk, err
}
stageName = fmt.Sprintf("Detaching disk '%s'", originalDisk.CID())
err = stage.Perform(stageName, func() error {
return vm.DetachDisk(originalDisk)
})
if err != nil {
return newDisk, err
}
stageName = fmt.Sprintf("Deleting disk '%s'", originalDisk.CID())
err = stage.Perform(stageName, func() error {
return originalDisk.Delete()
})
if err != nil {
return newDisk, err
}
return newDisk, nil
}
示例14: deleteDisk
func (d *deployment) deleteDisk(deleteStage biui.Stage, disk bidisk.Disk) error {
stepName := fmt.Sprintf("Deleting disk '%s'", disk.CID())
return deleteStage.Perform(stepName, func() error {
err := disk.Delete()
cloudErr, ok := err.(bicloud.Error)
if ok && cloudErr.Type() == bicloud.DiskNotFoundError {
return biui.NewSkipStageError(cloudErr, "Disk not found")
}
return err
})
}
示例15: deleteStemcell
func (d *deployment) deleteStemcell(deleteStage biui.Stage, stemcell bistemcell.CloudStemcell) error {
stepName := fmt.Sprintf("Deleting stemcell '%s'", stemcell.CID())
return deleteStage.Perform(stepName, func() error {
err := stemcell.Delete()
cloudErr, ok := err.(bicloud.Error)
if ok && cloudErr.Type() == bicloud.StemcellNotFoundError {
return biui.NewSkipStageError(cloudErr, "Stemcell not found")
}
return err
})
}