Example #1
0
func (dpnSync *DPNSync) syncRestoreRequests(xfers []*models.RestoreTransfer, result *models.SyncResult) {
	log := dpnSync.Context.MessageLog
	for _, xfer := range xfers {
		log.Debug("Processing restore %s from %s (bag %s)", xfer.RestoreId,
			xfer.FromNode, xfer.Bag)
		resp := dpnSync.LocalClient.RestoreTransferGet(xfer.RestoreId)
		if resp.Error != nil {
			result.AddError(dpn.DPNTypeRestore, resp.Error)
			return
		}
		existingXfer := resp.RestoreTransfer()
		if existingXfer == nil {
			log.Debug("Creating new restore request %s", xfer.RestoreId)
			resp = dpnSync.LocalClient.RestoreTransferCreate(xfer)
			if resp.Error != nil {
				result.AddError(dpn.DPNTypeRestore, resp.Error)
				return
			}
		} else if !existingXfer.UpdatedAt.Before(xfer.UpdatedAt) {
			log.Debug("Skipping restore %s, because ours is same age or newer.", xfer.RestoreId)
		} else {
			log.Debug("Updating restore %s", xfer.RestoreId)
			resp = dpnSync.LocalClient.RestoreTransferUpdate(xfer)
			if resp.Error != nil {
				result.AddError(dpn.DPNTypeRestore, resp.Error)
				return
			}
		}
		result.AddToSyncCount(dpn.DPNTypeRestore, 1)
	}
}
Example #2
0
func (dpnSync *DPNSync) syncBags(bags []*models.DPNBag, result *models.SyncResult) {
	log := dpnSync.Context.MessageLog
	for _, bag := range bags {
		log.Debug("Processing bag %s from %s", bag.UUID, bag.AdminNode)
		resp := dpnSync.LocalClient.DPNBagGet(bag.UUID)
		if resp.Error != nil {
			log.Error(resp.Error.Error())
			result.AddError(dpn.DPNTypeBag, resp.Error)
			return
		}
		existingBag := resp.Bag()
		if existingBag == nil {
			log.Debug("Creating new bag %s", bag.UUID)
			resp = dpnSync.LocalClient.DPNBagCreate(bag)
			if resp.Error != nil {
				log.Error(resp.Error.Error())
				result.AddError(dpn.DPNTypeBag, resp.Error)
				return
			}
		} else if !existingBag.UpdatedAt.Before(bag.UpdatedAt) {
			log.Debug("Skipping bag %s, because ours is same age or newer.", bag.UUID)
		} else {
			log.Debug("Updating bag %s", bag.UUID)
			resp = dpnSync.LocalClient.DPNBagUpdate(bag)
			if resp.Error != nil {
				log.Error(resp.Error.Error())
				result.AddError(dpn.DPNTypeBag, resp.Error)
				return
			}
		}
		dpnSync.SyncIngests(bag)
		result.AddToSyncCount(dpn.DPNTypeBag, 1)
	}
}
Example #3
0
func (dpnSync *DPNSync) syncFixities(fixities []*models.FixityCheck, result *models.SyncResult) {
	log := dpnSync.Context.MessageLog
	for _, fixity := range fixities {
		resp := dpnSync.LocalClient.FixityCheckCreate(fixity)
		if resp.Response.StatusCode == 409 {
			// Do nothing. This fixity record already exists
			// on our local server.
		} else if resp.Error != nil {
			result.AddError(dpn.DPNTypeFixityCheck, resp.Error)
			return
		} else {
			log.Debug("Created new fixity %s (bag %s)", fixity.FixityCheckId, fixity.Bag)
		}
		result.AddToSyncCount(dpn.DPNTypeFixityCheck, 1)
	}
}
Example #4
0
func (dpnSync *DPNSync) syncIngests(ingests []*models.Ingest, result *models.SyncResult) {
	log := dpnSync.Context.MessageLog
	for _, ingest := range ingests {
		resp := dpnSync.LocalClient.IngestCreate(ingest)
		if resp.Response.StatusCode == 409 {
			// Do nothing. This ingest record already exists
			// on our local server.
		} else if resp.Error != nil {
			result.AddError(dpn.DPNTypeIngest, resp.Error)
			return
		} else {
			log.Debug("Created new ingest %s (bag %s)", ingest.IngestId, ingest.Bag)
		}
		result.AddToSyncCount(dpn.DPNTypeIngest, 1)
	}
}
Example #5
0
func (dpnSync *DPNSync) syncDigests(digests []*models.MessageDigest, result *models.SyncResult) {
	log := dpnSync.Context.MessageLog
	for _, digest := range digests {
		resp := dpnSync.LocalClient.DigestGet(digest.Bag, digest.Algorithm)
		if resp.Error != nil {
			result.AddError(dpn.DPNTypeDigest, resp.Error)
			return
		}
		existingDigest := resp.Digest()
		if existingDigest == nil {
			log.Debug("Creating new %s digest for bag %s", digest.Algorithm, digest.Bag)
			resp = dpnSync.LocalClient.DigestCreate(digest)
			if resp.Error != nil {
				result.AddError(dpn.DPNTypeDigest, resp.Error)
				return
			}
		}
		result.AddToSyncCount(dpn.DPNTypeDigest, 1)
	}
}
Example #6
0
func (dpnSync *DPNSync) syncMembers(members []*models.Member, result *models.SyncResult) {
	log := dpnSync.Context.MessageLog
	for _, member := range members {
		resp := dpnSync.LocalClient.MemberGet(member.MemberId)
		if resp.Error != nil {
			result.AddError(dpn.DPNTypeMember, resp.Error)
			return
		}
		existingMember := resp.Member()
		if existingMember == nil {
			log.Debug("Creating new member %s (%s)", member.Name, member.MemberId)
			resp = dpnSync.LocalClient.MemberCreate(member)
			if resp.Error != nil {
				result.AddError(dpn.DPNTypeMember, resp.Error)
				return
			}
		}
		result.AddToSyncCount(dpn.DPNTypeMember, 1)
	}
}