Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DataCatalog
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
eFlows4HPC WP2
DataCatalog
Commits
f10efa7b
Commit
f10efa7b
authored
May 5, 2021
by
Christian Boettcher
Browse files
Options
Downloads
Patches
Plain Diff
add storage interface + json implementation
(see
#1
and
#4
)
parent
60c6c281
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!1
apiserver based on fastAPI
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
api-server/.gitignore
+1
-0
1 addition, 0 deletions
api-server/.gitignore
api-server/JsonFileStorageAdapter.py
+64
-0
64 additions, 0 deletions
api-server/JsonFileStorageAdapter.py
api-server/LocationStorage.py
+29
-0
29 additions, 0 deletions
api-server/LocationStorage.py
with
94 additions
and
0 deletions
api-server/.gitignore
+
1
−
0
View file @
f10efa7b
__pycache__/
app/
\ No newline at end of file
This diff is collapsed.
Click to expand it.
api-server/JsonFileStorageAdapter.py
0 → 100644
+
64
−
0
View file @
f10efa7b
import
os
import
json
import
uuid
from
LocationStorage
import
AbstractLocationDataStorageAdapter
,
LocationData
,
LocationDataType
DEFAULT_JSON_FILEPATH
:
str
=
"
./app/data
"
class
JsonFileStorageAdapter
(
AbstractLocationDataStorageAdapter
):
data_dir
:
str
def
__init__
(
self
,
data_directory
:
str
=
DEFAULT_JSON_FILEPATH
):
AbstractLocationDataStorageAdapter
.
__init__
(
self
)
self
.
data_dir
=
data_directory
if
not
(
os
.
path
.
exists
(
self
.
data_dir
)
and
os
.
path
.
isdir
(
self
.
data_dir
)):
raise
Exception
(
'
Data Directory
\"
'
+
self
.
data_dir
+
'
\"
does not exist.
'
)
def
getList
(
self
,
type
:
LocationDataType
):
localpath
=
os
.
path
.
join
(
self
.
data_dir
,
type
.
value
)
if
not
(
os
.
path
.
isdir
(
localpath
)):
# This type has apparently not yet been used at all, create its directory and return an empty json file
os
.
mkdir
(
localpath
)
return
{}
else
:
allFiles
=
[
f
for
f
in
os
.
listdir
(
localpath
)
if
os
.
path
.
isfile
(
os
.
path
.
join
(
localpath
,
f
))]
# now each file has to be checked for its filename (= id) and the LocationData name (which is inside the json)
retList
=
[]
for
f
in
allFiles
:
with
open
(
os
.
path
.
join
(
localpath
,
f
))
as
file
:
data
=
json
.
load
(
file
)
retList
.
append
({
data
[
'
name
'
]
:
f
})
return
retList
def
addNew
(
self
,
type
:
LocationDataType
,
data
:
LocationData
):
localpath
=
os
.
path
.
join
(
self
.
data_dir
,
type
.
value
)
if
not
(
os
.
path
.
isdir
(
localpath
)):
# This type has apparently not yet been used at all, therefore we need to create its directory
os
.
mkdir
(
localpath
)
# create a unique id, by randomly generating one, and re-choosing if it is already taken
id
=
str
(
uuid
.
uuid4
())
while
(
os
.
path
.
exists
(
os
.
path
.
join
(
localpath
,
id
))):
id
=
str
(
uuid
.
uuid4
())
with
open
(
os
.
path
.
join
(
localpath
,
id
),
'
w
'
)
as
json_file
:
json
.
dump
(
data
.
__dict__
,
json_file
)
return
{
id
:
data
}
def
getDetails
(
self
,
type
:
LocationDataType
,
id
:
str
):
localpath
=
os
.
path
.
join
(
self
.
data_dir
,
type
.
value
)
fullpath
=
os
.
path
.
join
(
localpath
,
id
)
if
not
os
.
path
.
isfile
(
fullpath
):
raise
FileNotFoundError
(
'
The requested Object does not exist.
'
)
with
open
(
fullpath
)
as
file
:
data
=
json
.
load
(
file
)
return
data
def
updateDetails
(
self
,
type
:
LocationDataType
,
id
:
str
,
data
:
LocationData
):
localpath
=
os
.
path
.
join
(
self
.
data_dir
,
type
.
value
)
fullpath
=
os
.
path
.
join
(
localpath
,
id
)
if
not
os
.
path
.
isfile
(
fullpath
):
raise
FileNotFoundError
(
'
The requested Object does not exist.
'
)
with
open
(
fullpath
,
'
w
'
)
as
file
:
json
.
dump
(
data
.
__dict__
,
file
)
return
{
id
:
data
}
This diff is collapsed.
Click to expand it.
api-server/LocationStorage.py
0 → 100644
+
29
−
0
View file @
f10efa7b
from
pydantic
import
BaseModel
from
typing
import
Optional
from
typing
import
Dict
from
enum
import
Enum
class
LocationDataType
(
Enum
):
DATASET
:
str
=
'
dataset
'
STORAGETARGET
:
str
=
'
storage_target
'
class
LocationData
(
BaseModel
):
name
:
str
url
:
str
metadata
:
Optional
[
Dict
[
str
,
str
]]
class
AbstractLocationDataStorageAdapter
:
def
getList
(
self
,
type
:
LocationDataType
):
raise
NotImplementedError
()
def
addNew
(
self
,
type
:
LocationDataType
,
data
:
LocationData
):
raise
NotImplementedError
()
def
getDetails
(
self
,
type
:
LocationDataType
,
id
:
str
):
raise
NotImplementedError
()
def
updateDetails
(
self
,
type
:
LocationDataType
,
id
:
str
,
data
:
LocationData
):
raise
NotImplementedError
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment