Example #1
0
func TestOwnerOf(t *testing.T) {
	if util.OwnerOf("aptrust.receiving.unc.edu") != "unc.edu" {
		t.Error("OwnerOf misidentified receiving bucket owner")
	}
	if util.OwnerOf("aptrust.receiving.test.unc.edu") != "unc.edu" {
		t.Error("OwnerOf misidentified receiving bucket owner")
	}
	if util.OwnerOf("aptrust.restore.unc.edu") != "unc.edu" {
		t.Error("OwnerOf misidentified restoration bucket owner")
	}
}
Example #2
0
func (reader *APTBucketReader) createWorkItem(bucket string, s3Object *s3.Object) *models.WorkItem {
	// Create a WorkItem in Pharos
	institution := reader.Institutions[util.OwnerOf(bucket)]
	if institution == nil {
		errMsg := fmt.Sprintf("Cannot find institution record for item %s/%s. "+
			"Owner computes to '%s'", bucket, *s3Object.Key, util.OwnerOf(bucket))
		reader.Context.MessageLog.Error(errMsg)
		if reader.stats != nil {
			reader.stats.AddError(errMsg)
		}
		return nil
	}
	workItem := &models.WorkItem{}
	workItem.Name = *s3Object.Key
	workItem.Bucket = bucket
	workItem.ETag = strings.Replace(*s3Object.ETag, "\"", "", -1)
	workItem.Size = *s3Object.Size
	workItem.BagDate = *s3Object.LastModified
	workItem.InstitutionId = institution.Id
	workItem.User = constants.APTrustSystemUser
	workItem.Date = time.Now().UTC()
	workItem.Note = "Bag is in receiving bucket"
	workItem.Action = constants.ActionIngest
	workItem.Stage = constants.StageReceive
	workItem.Status = constants.StatusPending
	workItem.Outcome = "Item is pending ingest"
	workItem.Retry = true
	resp := reader.Context.PharosClient.WorkItemSave(workItem)

	if resp.Error != nil {
		errMsg := fmt.Sprintf("Error creating WorkItem for name '%s', etag '%s', time '%s': %v",
			workItem.Name, workItem.ETag, workItem.BagDate, resp.Error)
		reader.Context.MessageLog.Debug("%s", resp.Request.URL.String())
		reader.Context.MessageLog.Error(errMsg)
		if reader.stats != nil {
			reader.stats.AddError(errMsg)
		}
		return nil
	}
	if resp.Response.StatusCode != 201 {
		reader.processPharosError(resp)
		return nil
	}

	savedWorkItem := resp.WorkItem()
	reader.Context.MessageLog.Debug("Created WorkItem with id %d for %s/%s in Pharos",
		savedWorkItem.Id, bucket, *s3Object.Key)
	if reader.stats != nil {
		reader.stats.AddWorkItem("WorkItemsCreated", savedWorkItem)
	}
	return savedWorkItem
}
Example #3
0
// SetBasicObjectInfo sets initial essential properties on the
// IntellectualObject associated with an ingestState
// (ingestState.IngestManifest.Object). This is only used by
// apt_fetcher and is only ever called during the fetch stage.
func SetBasicObjectInfo(ingestState *models.IngestState, _context *context.Context) {
	// instIdentifier is, e.g., virginia.edu, ncsu.edu, etc.
	// We'll download the tar file from the receiving bucket to
	// something like /mnt/apt/data/virginia.edu/name_of_bag.tar
	// See IngestTarFilePath below.
	obj := ingestState.IngestManifest.Object
	instIdentifier := util.OwnerOf(ingestState.IngestManifest.S3Bucket)
	obj.BagName = util.CleanBagName(ingestState.IngestManifest.S3Key)
	obj.Institution = instIdentifier
	obj.InstitutionId = ingestState.WorkItem.InstitutionId
	obj.IngestS3Bucket = ingestState.IngestManifest.S3Bucket
	obj.IngestS3Key = ingestState.IngestManifest.S3Key
	obj.IngestTarFilePath = filepath.Join(
		_context.Config.TarDirectory,
		instIdentifier, ingestState.IngestManifest.S3Key)

	// If this IntellectualObject was created by our validator and VirtualBag,
	// the identifier will be the bag name (minus the .tar extension).
	// That's fine for cases where depositors or other organizations are
	// using the validator outside of APTrust's repository environment, but
	// APTrust requires that we add the Institution name and a slash to
	// the beginning of the identifier. So make sure it's there, and propagate
	// the change all the way down to the GenericFiles.
	if !strings.HasPrefix(obj.Identifier, obj.Institution+"/") {
		obj.Identifier = fmt.Sprintf("%s/%s", obj.Institution, obj.Identifier)
		for _, gf := range obj.GenericFiles {
			if !strings.HasPrefix(gf.Identifier, obj.Identifier) {
				gf.IntellectualObjectIdentifier = obj.Identifier
				gf.Identifier = fmt.Sprintf("%s/%s", obj.Institution, gf.Identifier)
			}
		}
	}
}
Example #4
0
// The name of the owning institution, followed by a slash, followed
// by the name of the tar file. This differs from the ObjectName,
// because it will have the .tar or bag.001.of030.tar suffix.
func (s3File *S3File) BagName() string {
	return fmt.Sprintf("%s/%s", util.OwnerOf(s3File.BucketName), s3File.Key.Key)
}
Example #5
0
// Returns the object identifier that will identify this bag
// in fedora. That's the institution identifier, followed by
// a slash and the tar file name, minus the .tar extension
// and the ".bag1of12" multipart extension. So for BucketName
// "aptrust.receiving.unc.edu" and Key.Key "nc_bag.b001.of030.tar",
// this would return "unc.edu/nc_bag"
func (s3File *S3File) ObjectName() (string, error) {
	institution := util.OwnerOf(s3File.BucketName)
	cleanBagName := util.CleanBagName(s3File.Key.Key)
	return fmt.Sprintf("%s/%s", institution, cleanBagName), nil
}