Exemplo n.º 1
0
func (r *TarReader) Read() (Job, error) {
	var job Job

	downloadPath, err := r.downloader.Download(r.path)
	if err != nil {
		return job, bosherr.WrapError(err, "Downloading job")
	}

	r.downloadPath = downloadPath

	extractPath, err := r.extractor.Extract(r.downloadPath)
	if err != nil {
		cleanUpErr := r.downloader.CleanUp(r.downloadPath)
		if cleanUpErr != nil {
			r.logger.Debug(tarReaderLogTag, "Failed to clean up downloaded job %v", cleanUpErr)
		}

		return job, bosherr.WrapError(err, "Extracting job")
	}

	r.extractPath = extractPath

	manifestPath := filepath.Join(r.extractPath, "job.MF")

	manifest, err := bpreljobman.NewManifestFromPath(manifestPath, r.fs)
	if err != nil {
		closeErr := r.Close()
		if closeErr != nil {
			r.logger.Debug(tarReaderLogTag, "Failed to close job %v", closeErr)
		}

		return job, bosherr.WrapError(err, "Building manifest")
	}

	r.logger.Debug(tarReaderLogTag, "Done building manifest %#v", manifest)

	job.populateFromManifest(manifest)

	r.populateJobPaths(&job)

	return job, nil
}
Exemplo n.º 2
0
func (r DirReader) Read() (Job, error) {
	var job Job

	manifestPath := filepath.Join(r.dir, "spec")

	manifest, err := bpjobrelman.NewManifestFromPath(manifestPath, r.fs)
	if err != nil {
		closeErr := r.Close()
		if closeErr != nil {
			r.logger.Debug(dirReaderLogTag,
				"Failed to close job %v", closeErr)
		}

		return job, bosherr.WrapError(err, "Building manifest")
	}

	r.logger.Debug(dirReaderLogTag, "Done building manifest %#v", manifest)

	job.populateFromManifest(manifest)

	r.populateJobPaths(&job)

	return job, nil
}