Skip to content

Commit 02512da

Browse files
authored
Remove old deprecations and implement new blob wrappers with load and save (#1173)
* rm v0.25 deprecations * deprecate update[Blob|data] as obsolete * Basic BlobWrappers ([save|load]Blob * fix doxs
1 parent b94fc85 commit 02512da

File tree

10 files changed

+574
-443
lines changed

10 files changed

+574
-443
lines changed

docs/src/blob_ref.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Pages = [
2626
"DataBlobs/services/BlobEntry.jl",
2727
"DataBlobs/services/BlobStores.jl",
2828
"DataBlobs/services/BlobPacking.jl",
29-
"DataBlobs/services/HelpersDataWrapEntryBlob.jl",
29+
"DataBlobs/services/BlobWrappers.jl",
3030
]
3131
3232
```

src/DataBlobs/entities/BlobEntry.jl

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
##==============================================================================
33
## Blobentry
44
##==============================================================================
5-
5+
#TODO think origin and buildSourceString should be deprecated, description can be used instead
6+
#TODO hash - maybe use both crc32c for fast error check and sha256 for strong integrity check
7+
# stored seperately as crc and sha or as a tuple `hash::Tuple{Symbol, String}` where Symbol is :crc32c or :sha256
8+
# or an enum with suppored hash types
69
"""
710
$(TYPEDEF)
811
@@ -16,9 +19,7 @@ Base.@kwdef struct Blobentry
1619
""" Remotely assigned and globally unique identifier for the `Blobentry` itself (not the `.blobId`). """
1720
id::Union{UUID, Nothing} = nothing
1821
""" Machine friendly and globally unique identifier of the 'Blob', usually assigned from a common point in the system. This can be used to guarantee unique retrieval of the large data blob. """
19-
blobId::Union{UUID, Nothing} = uuid4() #Deprecated in v0.25 TODO remove union, blobId is mandatory
20-
""" TBD if Deprecated. Machine friendly and locally assigned identifier of the 'Blob'."""
21-
originId::Union{UUID, Nothing} = blobId #Deprecated in v0.25 TODO remove union or remove originId completely
22+
blobId::UUID = uuid4()
2223
""" Human friendly label of the `Blob` and also used as unique identifier per node on which a `Blobentry` is added. E.g. do "LEFTCAM_1", "LEFTCAM_2", ... of you need to repeat a label on the same variable. """
2324
label::Symbol
2425
""" A hint about where the `Blob` itself might be stored. Remember that a Blob may be duplicated over multiple blobstores. """
@@ -28,7 +29,7 @@ Base.@kwdef struct Blobentry
2829
""" Context from which a Blobentry=>Blob was first created. E.g. agent|graph|varlabel. """
2930
origin::String = ""
3031
""" number of bytes in blob as a string"""
31-
size::Union{String, Nothing} = "-1" #TODO remove union -> size::String = "-1"
32+
size::String = "-1"
3233
""" Additional information that can help a different user of the Blob. """
3334
description::String = ""
3435
""" MIME description describing the format of binary data in the `Blob`, e.g. 'image/png' or 'application/json; _type=CameraModel'. """
@@ -48,3 +49,42 @@ end
4849
StructTypes.StructType(::Type{Blobentry}) = StructTypes.UnorderedStruct()
4950
StructTypes.idproperty(::Type{Blobentry}) = :id
5051
StructTypes.omitempties(::Type{Blobentry}) = (:id,)
52+
53+
function Blobentry(label::Symbol, blobstore = :default; kwargs...)
54+
return Blobentry(; label, blobstore, kwargs...)
55+
end
56+
# construction helper from existing Blobentry for user overriding via kwargs
57+
function Blobentry(
58+
entry::Blobentry;
59+
id::Union{UUID, Nothing} = entry.id,
60+
blobId::UUID = entry.blobId,
61+
label::Symbol = entry.label,
62+
blobstore::Symbol = entry.blobstore,
63+
hash::String = entry.hash,
64+
size::Union{String, Int, Nothing} = entry.size,
65+
origin::String = entry.origin,
66+
description::String = entry.description,
67+
mimeType::String = entry.mimeType,
68+
metadata::String = entry.metadata,
69+
timestamp::ZonedDateTime = entry.timestamp,
70+
createdTimestamp = entry.createdTimestamp,
71+
lastUpdatedTimestamp = entry.lastUpdatedTimestamp,
72+
_version = entry._version,
73+
)
74+
return Blobentry(;
75+
id,
76+
blobId,
77+
label,
78+
blobstore,
79+
hash,
80+
origin,
81+
size = string(size),
82+
description,
83+
mimeType,
84+
metadata,
85+
timestamp,
86+
createdTimestamp,
87+
lastUpdatedTimestamp,
88+
_version,
89+
)
90+
end

src/DataBlobs/services/BlobEntry.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
##==============================================================================
22
## Blobentry - common
33
##==============================================================================
4-
4+
#TODO think origin and buildSourceString should be deprecated, description can be used instead
55
"""
66
$(SIGNATURES)
77
Function to generate source string - agentLabel|graphLabel|varLabel
@@ -329,15 +329,16 @@ If the blob label `datalabel_1` already exists, then this function will return t
329329
"""
330330
function incrDataLabelSuffix(
331331
dfg::AbstractDFG,
332-
vla::Union{Symbol, <:AbstractString},
333-
bllb::S;
332+
vla::Symbol,
333+
bllb::Union{Symbol, <:AbstractString};
334334
datalabel = Ref(""),
335-
) where {S <: Union{Symbol, <:AbstractString}}
335+
)
336336
count = 1
337337
hasund = false
338338
len = 0
339339
try
340-
de, _ = getData(dfg, Symbol(vla), bllb)
340+
de = getfirstBlobentry(dfg, vla; labelFilter = contains(string(bllb)))
341+
isnothing(de) && return Symbol(bllb) # no match, return as is
341342
bllb = string(bllb)
342343
# bllb *= bllb[end] != '_' ? "_" : ""
343344
datalabel[] = string(de.label)
@@ -361,5 +362,5 @@ function incrDataLabelSuffix(
361362
end
362363
bllb *= string(count)
363364

364-
return S(bllb)
365+
return Symbol(bllb)
365366
end

src/DataBlobs/services/BlobStores.jl

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,6 @@ struct FolderStore{T} <: AbstractBlobstore{T}
123123
folder::String
124124
end
125125

126-
#TODO added in v0.25 to avoid a breaking change in deserialization old DFGs, remove.
127-
StructTypes.StructType(::Type{<:FolderStore}) = StructTypes.OrderedStruct()
128-
129126
function FolderStore(foldername::String; label::Symbol = :default, createfolder = true)
130127
storepath = joinpath(foldername, string(label))
131128
if createfolder && !isdir(storepath)
@@ -367,13 +364,6 @@ function addBlob!(store::RowBlobstore{T}, blobId::UUID, blob::T) where {T}
367364
return blobId
368365
end
369366

370-
function updateBlob!(store::RowBlobstore{T}, blobId::UUID, blob::T) where {T}
371-
if haskey(store.blobs, blobId)
372-
@warn "Key '$blobId' doesn't exist."
373-
end
374-
return store.blobs[blobId] = RowBlob(blobId, blob)
375-
end
376-
377367
function deleteBlob!(store::RowBlobstore, blobId::UUID)
378368
if !haskey(store.blobs, blobId)
379369
throw(IdNotFoundError("Blob", blobId))
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
##==============================================================================
2+
## Blob + Blobentry CRUD interface
3+
##==============================================================================
4+
5+
"""
6+
Convenience wrapper to load a Blob for a given variable and Blobentry label.
7+
8+
$(METHODLIST)
9+
"""
10+
function loadBlob_Variable end
11+
12+
"""
13+
Convenience wrapper to save a Blob to a Blobstore and a Blobentry to a variable.
14+
$(METHODLIST)
15+
"""
16+
function saveBlob_Variable! end
17+
18+
"""
19+
Convenience wrapper to delete a Blob form a Blobstore and its Blobentry from a variable.
20+
$(METHODLIST)
21+
"""
22+
function deleteBlob_Variable! end
23+
24+
"""
25+
Convenience wrapper to load a Blob for a given graph and Blobentry label.
26+
27+
$(METHODLIST)
28+
"""
29+
function loadBlob_Graph end
30+
31+
"""
32+
Convenience wrapper to save a Blob to a Blobstore and a Blobentry to a graph.
33+
34+
$(METHODLIST)
35+
"""
36+
function saveBlob_Graph! end
37+
38+
"""
39+
Convenience wrapper to delete a Blob from a Blobstore and its Blobentry from a graph.
40+
41+
$(METHODLIST)
42+
"""
43+
function deleteBlob_Graph! end
44+
45+
"""
46+
Convenience wrapper to load a Blob for a given agent and Blobentry label.
47+
48+
$(METHODLIST)
49+
"""
50+
function loadBlob_Agent end
51+
52+
"""
53+
Convenience wrapper to save a Blob to a Blobstore and a Blobentry to an agent.
54+
55+
$(METHODLIST)
56+
"""
57+
function saveBlob_Agent! end
58+
59+
"""
60+
Convenience wrapper to delete a Blob from a Blobstore and its Blobentry from an agent.
61+
62+
$(METHODLIST)
63+
"""
64+
function deleteBlob_Agent! end
65+
66+
function loadBlob_Variable(
67+
dfg::AbstractDFG,
68+
variable_label::Symbol,
69+
entry_label::Symbol;
70+
# hashfunction = sha256,
71+
# checkhash::Bool = true,
72+
)
73+
entry = getBlobentry(dfg, variable_label, entry_label)
74+
blob = getBlob(dfg, entry)
75+
# checkhash && assertHash(de, db; hashfunction)
76+
return entry, blob
77+
end
78+
79+
function saveBlob_Variable!(
80+
dfg::AbstractDFG,
81+
variable_label::Symbol,
82+
blob::Vector{UInt8},
83+
entry::Blobentry,
84+
)
85+
addBlobentry!(dfg, variable_label, entry)
86+
addBlob!(dfg, entry, blob)
87+
return entry
88+
end
89+
90+
function saveBlob_Variable!(
91+
dfg::AbstractDFG,
92+
variable_label::Symbol,
93+
blob::Vector{UInt8},
94+
entry_label::Symbol,
95+
blobstore::Symbol = :default;
96+
blobentry_kwargs...,
97+
)
98+
entry = Blobentry(entry_label, blobstore; blobentry_kwargs...)
99+
return saveBlob_Variable!(dfg, variable_label, blob, entry)
100+
end
101+
102+
function deleteBlob_Variable!(dfg::AbstractDFG, variable_label::Symbol, entry_label::Symbol)
103+
entry = getBlobentry(dfg, variable_label, entry_label)
104+
deleteBlobentry!(dfg, variable_label, entry_label)
105+
deleteBlob!(dfg, entry)
106+
return 2
107+
end
108+
109+
function loadBlob_Graph(dfg::AbstractDFG, entry_label::Symbol;)
110+
entry = getGraphBlobentry(dfg, entry_label)
111+
blob = getBlob(dfg, entry)
112+
return entry, blob
113+
end
114+
115+
function saveBlob_Graph!(dfg::AbstractDFG, blob::Vector{UInt8}, entry::Blobentry)
116+
addGraphBlobentry!(dfg, entry)
117+
addBlob!(dfg, entry, blob)
118+
return entry
119+
end
120+
121+
function saveBlob_Graph!(
122+
dfg::AbstractDFG,
123+
blob::Vector{UInt8},
124+
entry_label::Symbol,
125+
blobstore::Symbol = :default;
126+
blobentry_kwargs...,
127+
)
128+
entry = Blobentry(entry_label, blobstore; blobentry_kwargs...)
129+
return saveBlob_Graph!(dfg, blob, entry)
130+
end
131+
132+
function deleteBlob_Graph!(dfg::AbstractDFG, entry_label::Symbol)
133+
entry = getGraphBlobentry(dfg, entry_label)
134+
deleteGraphBlobentry!(dfg, entry_label)
135+
deleteBlob!(dfg, entry)
136+
return 2
137+
end
138+
139+
function loadBlob_Agent(dfg::AbstractDFG, entry_label::Symbol;)
140+
entry = getAgentBlobentry(dfg, entry_label)
141+
blob = getBlob(dfg, entry)
142+
return entry, blob
143+
end
144+
145+
function saveBlob_Agent!(dfg::AbstractDFG, blob::Vector{UInt8}, entry::Blobentry)
146+
addAgentBlobentry!(dfg, entry)
147+
addBlob!(dfg, entry, blob)
148+
return entry
149+
end
150+
151+
function saveBlob_Agent!(
152+
dfg::AbstractDFG,
153+
blob::Vector{UInt8},
154+
entry_label::Symbol,
155+
blobstore::Symbol = :default;
156+
blobentry_kwargs...,
157+
)
158+
entry = Blobentry(entry_label, blobstore; blobentry_kwargs...)
159+
return saveBlob_Agent!(dfg, blob, entry)
160+
end
161+
162+
function deleteBlob_Agent!(dfg::AbstractDFG, entry_label::Symbol)
163+
entry = getAgentBlobentry(dfg, entry_label)
164+
deleteAgentBlobentry!(dfg, entry_label)
165+
deleteBlob!(dfg, entry)
166+
return 2
167+
end
168+
169+
function saveImage_Variable!(
170+
dfg::AbstractDFG,
171+
variable_label::Symbol,
172+
img::AbstractMatrix,
173+
entry_label::Symbol,
174+
blobstore::Symbol = :default;
175+
entry_kwargs...,
176+
)
177+
mimeType = get(entry_kwargs, :mimeType, MIME("image/png"))
178+
format = _MIMETypes[mimeType]
179+
180+
blob, mimeType = packBlob(format, img)
181+
182+
size = string(length(blob))
183+
entry = Blobentry(
184+
entry_label,
185+
blobstore;
186+
blobId = uuid4(),
187+
entry_kwargs...,
188+
size,
189+
mimeType = string(mimeType),
190+
)
191+
192+
return saveBlob_Variable!(dfg, variable_label, blob, entry)
193+
end
194+
195+
function loadImage_Variable(dfg::AbstractDFG, variable_label::Symbol, entry_label::Symbol)
196+
entry, blob = loadBlob_Variable(dfg, variable_label, entry_label)
197+
return entry, unpackBlob(entry, blob)
198+
end

0 commit comments

Comments
 (0)