Remove pending_delete status for blobs
Currently if artifact is marked as deleted all its blobs logicaly become 'pending_delete' and can't be used anymore. For this reason there is no need to have addtional blob status and explicitely mark blobs - it's all done when we change artifact status to 'deleted' ApiImpact Change-Id: Ide2bb3130d400b7ddcde0760246003b745ef4ff0
This commit is contained in:
parent
84c31bac4c
commit
0cbb8b77f3
@ -164,7 +164,7 @@ using Representational State Transfer concept (ReST).
|
|||||||
"external": {"type": "boolean"},
|
"external": {"type": "boolean"},
|
||||||
"id": {"type": "string"},
|
"id": {"type": "string"},
|
||||||
"status": {"type": "string",
|
"status": {"type": "string",
|
||||||
"enum": ["saving", "active", "pending_delete"]},
|
"enum": ["saving", "active"]},
|
||||||
"content_type": {"type": ["string", "null"]},
|
"content_type": {"type": ["string", "null"]},
|
||||||
},
|
},
|
||||||
"required": ["url", "size", "md5", "sha1", "sha256", "external",
|
"required": ["url", "size", "md5", "sha1", "sha256", "external",
|
||||||
@ -177,31 +177,20 @@ using Representational State Transfer concept (ReST).
|
|||||||
|
|
||||||
* *active* - blob upload successfully finished.
|
* *active* - blob upload successfully finished.
|
||||||
|
|
||||||
* *pending_delete* - indicates that blob will be deleted soon by Scrubber
|
|
||||||
(if delayed delete is enabled) or by Glare itself.
|
|
||||||
|
|
||||||
.. list-table:: **Blob status transition table**
|
.. list-table:: **Blob status transition table**
|
||||||
:header-rows: 1
|
:header-rows: 1
|
||||||
|
|
||||||
* - Blob Status
|
* - Blob Status
|
||||||
- saving
|
- saving
|
||||||
- active
|
- active
|
||||||
- pending delete
|
|
||||||
|
|
||||||
* - **saving**
|
* - **saving**
|
||||||
- X
|
- X
|
||||||
- finish blob upload
|
- finish blob upload
|
||||||
- request for artifact delete
|
|
||||||
|
|
||||||
* - **active**
|
* - **active**
|
||||||
- N/A
|
- N/A
|
||||||
- X
|
- X
|
||||||
- request for artifact delete
|
|
||||||
|
|
||||||
* - **pending_delete**
|
|
||||||
- N/A
|
|
||||||
- N/A
|
|
||||||
- X
|
|
||||||
|
|
||||||
* *Artifact Dict and List* - compound generic field types that
|
* *Artifact Dict and List* - compound generic field types that
|
||||||
implement Dict or List interfaces respectively, and contain values of some
|
implement Dict or List interfaces respectively, and contain values of some
|
||||||
|
@ -582,14 +582,6 @@ class BaseArtifact(base.VersionedObject):
|
|||||||
for af in cls.db_api.list(
|
for af in cls.db_api.list(
|
||||||
context, filters, marker, limit, sort, latest)]
|
context, filters, marker, limit, sort, latest)]
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _prepare_blob_delete(b, af, name):
|
|
||||||
if b['status'] == glare_fields.BlobFieldType.SAVING:
|
|
||||||
msg = _('Blob %(name)s is saving for artifact %(id)s'
|
|
||||||
) % {'name': name, 'id': af.id}
|
|
||||||
raise exception.Conflict(msg)
|
|
||||||
b['status'] = glare_fields.BlobFieldType.PENDING_DELETE
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _delete_blobs(cls, blobs, context, af):
|
def _delete_blobs(cls, blobs, context, af):
|
||||||
for name, blob in blobs.items():
|
for name, blob in blobs.items():
|
||||||
@ -623,24 +615,16 @@ class BaseArtifact(base.VersionedObject):
|
|||||||
# marking artifact as deleted
|
# marking artifact as deleted
|
||||||
cls.db_api.update(context, af.id, {'status': cls.STATUS.DELETED})
|
cls.db_api.update(context, af.id, {'status': cls.STATUS.DELETED})
|
||||||
|
|
||||||
# marking all blobs as pending delete
|
# collect all uploaded blobs
|
||||||
blobs = {}
|
blobs = {}
|
||||||
for name, field in af.fields.items():
|
for name in af.fields:
|
||||||
if cls.is_blob(name):
|
if cls.is_blob(name) or cls.is_blob_dict(name):
|
||||||
b = getattr(af, name)
|
field = getattr(af, name)
|
||||||
if b:
|
if field:
|
||||||
cls._prepare_blob_delete(b, af, name)
|
blobs[name] = field
|
||||||
blobs[name] = b
|
|
||||||
elif cls.is_blob_dict(name):
|
LOG.debug("Marked artifact %(artifact)s as deleted.",
|
||||||
bd = getattr(af, name)
|
{'artifact': af.id})
|
||||||
if bd:
|
|
||||||
for key, b in bd.items():
|
|
||||||
cls._prepare_blob_delete(b, af, name)
|
|
||||||
blobs[name] = bd
|
|
||||||
LOG.debug("Marked artifact %(artifact)s as deleted and all its blobs "
|
|
||||||
"%(blobs) as pending delete.",
|
|
||||||
{'artifact': af.id, 'blobs': blobs})
|
|
||||||
cls.db_api.update_blob(context, af.id, blobs)
|
|
||||||
|
|
||||||
if not CONF.delayed_delete:
|
if not CONF.delayed_delete:
|
||||||
if blobs:
|
if blobs:
|
||||||
|
@ -54,8 +54,7 @@ class VersionField(fields.AutoTypedField):
|
|||||||
class BlobFieldType(fields.FieldType):
|
class BlobFieldType(fields.FieldType):
|
||||||
"""Blob field contains reference to blob location.
|
"""Blob field contains reference to blob location.
|
||||||
"""
|
"""
|
||||||
BLOB_STATUS = (SAVING, ACTIVE, PENDING_DELETE) = (
|
BLOB_STATUS = (SAVING, ACTIVE) = ('saving', 'active')
|
||||||
'saving', 'active', 'pending_delete')
|
|
||||||
|
|
||||||
BLOB_SCHEMA = {
|
BLOB_SCHEMA = {
|
||||||
'type': 'object',
|
'type': 'object',
|
||||||
|
@ -178,8 +178,7 @@ fixtures = {
|
|||||||
u'status': {
|
u'status': {
|
||||||
u'enum': [
|
u'enum': [
|
||||||
u'saving',
|
u'saving',
|
||||||
u'active',
|
u'active'],
|
||||||
u'pending_delete'],
|
|
||||||
u'type': u'string'}},
|
u'type': u'string'}},
|
||||||
u'required': [u'size',
|
u'required': [u'size',
|
||||||
u'md5', u'sha1', u'sha256',
|
u'md5', u'sha1', u'sha256',
|
||||||
@ -231,8 +230,7 @@ fixtures = {
|
|||||||
u'status': {
|
u'status': {
|
||||||
u'enum': [
|
u'enum': [
|
||||||
u'saving',
|
u'saving',
|
||||||
u'active',
|
u'active'],
|
||||||
u'pending_delete'],
|
|
||||||
u'type': u'string'}},
|
u'type': u'string'}},
|
||||||
u'required': [u'size',
|
u'required': [u'size',
|
||||||
u'md5', u'sha1', u'sha256',
|
u'md5', u'sha1', u'sha256',
|
||||||
@ -412,8 +410,7 @@ fixtures = {
|
|||||||
u'status': {
|
u'status': {
|
||||||
u'enum': [
|
u'enum': [
|
||||||
u'saving',
|
u'saving',
|
||||||
u'active',
|
u'active'],
|
||||||
u'pending_delete'],
|
|
||||||
u'type': u'string'}},
|
u'type': u'string'}},
|
||||||
u'required': [u'size',
|
u'required': [u'size',
|
||||||
u'md5', u'sha1', u'sha256',
|
u'md5', u'sha1', u'sha256',
|
||||||
@ -494,8 +491,7 @@ fixtures = {
|
|||||||
u'size': {u'type': [u'number',
|
u'size': {u'type': [u'number',
|
||||||
u'null']},
|
u'null']},
|
||||||
u'status': {u'enum': [u'saving',
|
u'status': {u'enum': [u'saving',
|
||||||
u'active',
|
u'active'],
|
||||||
u'pending_delete'],
|
|
||||||
u'type': u'string'}},
|
u'type': u'string'}},
|
||||||
u'required': [u'size',
|
u'required': [u'size',
|
||||||
u'md5', u'sha1', u'sha256',
|
u'md5', u'sha1', u'sha256',
|
||||||
@ -605,8 +601,7 @@ fixtures = {
|
|||||||
u'size': {u'type': [u'number',
|
u'size': {u'type': [u'number',
|
||||||
u'null']},
|
u'null']},
|
||||||
u'status': {u'enum': [u'saving',
|
u'status': {u'enum': [u'saving',
|
||||||
u'active',
|
u'active'],
|
||||||
u'pending_delete'],
|
|
||||||
u'type': u'string'}},
|
u'type': u'string'}},
|
||||||
u'required': [u'size',
|
u'required': [u'size',
|
||||||
u'md5', u'sha1', u'sha256',
|
u'md5', u'sha1', u'sha256',
|
||||||
@ -698,8 +693,7 @@ fixtures = {
|
|||||||
u'size': {u'type': [u'number',
|
u'size': {u'type': [u'number',
|
||||||
u'null']},
|
u'null']},
|
||||||
u'status': {u'enum': [u'saving',
|
u'status': {u'enum': [u'saving',
|
||||||
u'active',
|
u'active'],
|
||||||
u'pending_delete'],
|
|
||||||
u'type': u'string'}},
|
u'type': u'string'}},
|
||||||
u'required': [u'size',
|
u'required': [u'size',
|
||||||
u'md5', u'sha1', u'sha256',
|
u'md5', u'sha1', u'sha256',
|
||||||
@ -844,8 +838,7 @@ fixtures = {
|
|||||||
u'size': {u'type': [u'number',
|
u'size': {u'type': [u'number',
|
||||||
u'null']},
|
u'null']},
|
||||||
u'status': {u'enum': [u'saving',
|
u'status': {u'enum': [u'saving',
|
||||||
u'active',
|
u'active'],
|
||||||
u'pending_delete'],
|
|
||||||
u'type': u'string'}},
|
u'type': u'string'}},
|
||||||
u'required': [u'size',
|
u'required': [u'size',
|
||||||
u'md5', u'sha1', u'sha256',
|
u'md5', u'sha1', u'sha256',
|
||||||
@ -878,8 +871,7 @@ fixtures = {
|
|||||||
u'size': {u'type': [u'number',
|
u'size': {u'type': [u'number',
|
||||||
u'null']},
|
u'null']},
|
||||||
u'status': {u'enum': [u'saving',
|
u'status': {u'enum': [u'saving',
|
||||||
u'active',
|
u'active'],
|
||||||
u'pending_delete'],
|
|
||||||
u'type': u'string'}},
|
u'type': u'string'}},
|
||||||
u'required': [u'size',
|
u'required': [u'size',
|
||||||
u'md5', u'sha1', u'sha256',
|
u'md5', u'sha1', u'sha256',
|
||||||
@ -910,8 +902,7 @@ fixtures = {
|
|||||||
u'size': {u'type': [u'number',
|
u'size': {u'type': [u'number',
|
||||||
u'null']},
|
u'null']},
|
||||||
u'status': {u'enum': [u'saving',
|
u'status': {u'enum': [u'saving',
|
||||||
u'active',
|
u'active'],
|
||||||
u'pending_delete'],
|
|
||||||
u'type': u'string'}},
|
u'type': u'string'}},
|
||||||
u'required': [u'size',
|
u'required': [u'size',
|
||||||
u'md5', u'sha1', u'sha256',
|
u'md5', u'sha1', u'sha256',
|
||||||
|
@ -163,7 +163,7 @@ class TestArtifactUpdate(base.BaseTestArtifactAPI):
|
|||||||
self.artifact = self.controller.show(
|
self.artifact = self.controller.show(
|
||||||
self.req, 'sample_artifact', self.artifact['id'])
|
self.req, 'sample_artifact', self.artifact['id'])
|
||||||
self.assertEqual('deleted', self.artifact['status'])
|
self.assertEqual('deleted', self.artifact['status'])
|
||||||
self.assertEqual('pending_delete', self.artifact['blob']['status'])
|
self.assertEqual('active', self.artifact['blob']['status'])
|
||||||
# Disable delayed delete
|
# Disable delayed delete
|
||||||
self.config(delayed_delete=False)
|
self.config(delayed_delete=False)
|
||||||
# Delete artifact and check that 'delete_blob' was called this time
|
# Delete artifact and check that 'delete_blob' was called this time
|
||||||
|
Loading…
Reference in New Issue
Block a user