Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes cloud storage #3336

Merged
merged 5 commits into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cvat/apps/engine/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ def prepare_chunk_buff(self, db_data, quality, chunk_number):
source_path = temp_file.name
buf = cloud_storage_instance.download_fileobj(name)
temp_file.write(buf.getvalue())
if not (checksum := item.get('checksum', None)):
checksum = item.get('checksum', None)
if not checksum:
slogger.glob.warning('A manifest file does not contain checksum for image {}'.format(item.get('name')))
if checksum and not md5_hash(source_path) == checksum:
slogger.glob.warning('Hash sums of files {} do not match'.format(name))
Expand All @@ -103,7 +104,7 @@ def prepare_chunk_buff(self, db_data, quality, chunk_number):
writer.save_as_chunk(images, buff)
buff.seek(0)
if db_data.storage == StorageChoice.CLOUD_STORAGE:
images = [image_path for image in images if os.path.exists((image_path := image[0]))]
images = [image[0] for image in images if os.path.exists(image[0])]
for image_path in images:
os.remove(image_path)
return buff, mime_type
Expand Down
6 changes: 3 additions & 3 deletions cvat/apps/engine/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,8 +608,8 @@ def get_log_path(self):
return os.path.join(self.get_storage_dirname(), "storage.log")

def get_specific_attributes(self):
attributes = self.specific_attributes.split('&')
specific_attributes = self.specific_attributes
return {
item.split('=')[0].strip(): item.split('=')[1].strip()
for item in attributes
} if len(attributes) else dict()
for item in specific_attributes.split('&')
} if specific_attributes else dict()
2 changes: 2 additions & 0 deletions cvat/apps/engine/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,9 +772,11 @@ def create(self, validated_data):
return db_review

class BaseCloudStorageSerializer(serializers.ModelSerializer):
owner = BasicUserSerializer(required=False)
class Meta:
model = models.CloudStorage
exclude = ['credentials']
read_only_fields = ('created_date', 'updated_date', 'owner')

class CloudStorageSerializer(serializers.ModelSerializer):
owner = BasicUserSerializer(required=False)
Expand Down
5 changes: 3 additions & 2 deletions cvat/apps/engine/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def _create_thread(tid, data, isImport=False):
credentials = Credentials()
credentials.convert_from_db({
'type': db_cloud_storage.credentials_type,
'value': db_cloud_storage.value,
'value': db_cloud_storage.credentials,
})

details = {
Expand All @@ -253,7 +253,8 @@ def _create_thread(tid, data, isImport=False):
}
cloud_storage_instance = get_cloud_storage_instance(cloud_provider=db_cloud_storage.provider_type, **details)
cloud_storage_instance.download_file(manifest_file[0], db_data.get_manifest_path())
cloud_storage_instance.download_file(media['image'][0], os.path.join(upload_dir, media['image'][0]))
first_sorted_media_image = sorted(media['image'])[0]
cloud_storage_instance.download_file(first_sorted_media_image, os.path.join(upload_dir, first_sorted_media_image))

av_scan_paths(upload_dir)

Expand Down
12 changes: 7 additions & 5 deletions cvat/apps/engine/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import uuid
from datetime import datetime
from distutils.util import strtobool
from tempfile import mkstemp, NamedTemporaryFile
from tempfile import mkstemp, TemporaryDirectory

import cv2
from django.db.models.query import Prefetch
Expand Down Expand Up @@ -1176,7 +1176,8 @@ def get_serializer_class(self):

def get_queryset(self):
queryset = super().get_queryset()
if (provider_type := self.request.query_params.get('provider_type', None)):
provider_type = self.request.query_params.get('provider_type', None)
if provider_type:
if provider_type in CloudProviderChoice.list():
return queryset.filter(provider_type=provider_type)
raise ValidationError('Unsupported type of cloud provider')
Expand Down Expand Up @@ -1278,9 +1279,10 @@ def content(self, request, pk):
storage_files = storage.content

manifest_path = request.query_params.get('manifest_path', 'manifest.jsonl')
with NamedTemporaryFile(mode='w+b', suffix='manifest', prefix='cvat') as tmp_manifest:
storage.download_file(manifest_path, tmp_manifest.name)
manifest = ImageManifestManager(tmp_manifest.name)
with TemporaryDirectory(suffix='manifest', prefix='cvat') as tmp_dir:
tmp_manifest_path = os.path.join(tmp_dir, 'manifest.jsonl')
storage.download_file(manifest_path, tmp_manifest_path)
manifest = ImageManifestManager(tmp_manifest_path)
manifest.init_index()
manifest_files = manifest.data
content = {f:[] for f in set(storage_files) | set(manifest_files)}
Expand Down