Skip to content

Commit

Permalink
some fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Marishka17 committed Aug 27, 2021
1 parent d354b18 commit c1f68a7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
15 changes: 12 additions & 3 deletions cvat/apps/engine/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
ImageDatasetManifestReader, VideoDatasetManifestReader)
from cvat.apps.engine.models import DataChoice, StorageChoice
from cvat.apps.engine.models import DimensionType
from cvat.apps.engine.cloud_provider import get_cloud_storage_instance, Credentials
from cvat.apps.engine.cloud_provider import get_cloud_storage_instance, Credentials, Status
from cvat.apps.engine.utils import md5_hash
class CacheInteraction:
def __init__(self, dimension=DimensionType.DIM_2D):
Expand Down Expand Up @@ -100,9 +100,18 @@ def prepare_chunk_buff(self, db_data, quality, chunk_number):
slogger.cloud_storage[db_cloud_storage.id].warning('Hash sums of files {} do not match'.format(file_name))
images.append((source_path, source_path, None))
except Exception as ex:
if not cloud_storage_instance.exists():
msg = 'The resource {} is no longer available. It may have been deleted'.format(cloud_storage_instance.name)
storage_status = cloud_storage_instance.get_status()
if storage_status == Status.FORBIDDEN:
msg = 'The resource {} is no longer available. Access forbidden.'.format(cloud_storage_instance.name)
elif storage_status == Status.NOT_FOUND:
msg = 'The resource {} not found. It may have been deleted.'.format(cloud_storage_instance.name)
else:
# check status of last file
file_status = cloud_storage_instance.get_file_status(file_name)
if file_status == Status.NOT_FOUND:
raise Exception("'{}' not found on the cloud storage '{}'".format(file_name, cloud_storage_instance.name))
elif file_status == Status.FORBIDDEN:
raise Exception("Access to the file '{}' on the '{}' cloud storage is denied".format(file_name, cloud_storage_instance.name))
msg = str(ex)
raise Exception(msg)
else:
Expand Down
24 changes: 18 additions & 6 deletions cvat/apps/engine/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ def create(self, validated_data):
details = {
'resource': validated_data.get('resource'),
'credentials': credentials,
'specific_attributes': parse_specific_attributes(validate_data.get('specific_attributes'))
'specific_attributes': parse_specific_attributes(validated_data.get('specific_attributes', ''))
}
storage = get_cloud_storage_instance(cloud_provider=provider_type, **details)
if should_be_created:
Expand All @@ -860,13 +860,19 @@ def create(self, validated_data):
storage_status = storage.get_status()
if storage_status == Status.AVAILABLE:
manifests = validated_data.pop('manifests')
# check for existence of manifest files
# check manifest files availability
for manifest in manifests:
if not storage.get_file_status(manifest.get('filename')) == Status.AVAILABLE:
file_status = storage.get_file_status(manifest.get('filename'))
if file_status == Status.NOT_FOUND:
raise serializers.ValidationError({
'manifests': "The '{}' file does not exist on '{}' cloud storage" \
.format(manifest.get('filename'), storage.name)
})
})
elif file_status == Status.FORBIDDEN:
raise serializers.ValidationError({
'manifests': "The '{}' file does not available on '{}' cloud storage. Access denied" \
.format(manifest.get('filename'), storage.name)
})

db_storage = models.CloudStorage.objects.create(
credentials=credentials.convert_to_db(),
Expand Down Expand Up @@ -926,11 +932,17 @@ def update(self, instance, validated_data):
if delta_to_create:
# check manifest files existing
for manifest in delta_to_create:
if not storage.get_file_status(manifest) == Status.AVAILABLE:
file_status = storage.get_file_status(manifest)
if file_status == Status.NOT_FOUND:
raise serializers.ValidationError({
'manifests': "The '{}' file does not exist on '{}' cloud storage"
.format(manifest, storage.name)
})
})
elif file_status == Status.FORBIDDEN:
raise serializers.ValidationError({
'manifests': "The '{}' file does not available on '{}' cloud storage. Access denied" \
.format(manifest.get('filename'), storage.name)
})
manifest_instances = [models.Manifest(filename=f, cloud_storage=instance) for f in delta_to_create]
models.Manifest.objects.bulk_create(manifest_instances)
instance.save()
Expand Down

0 comments on commit c1f68a7

Please sign in to comment.