Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openbis
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sispub
openbis
Commits
05f6fd1f
Commit
05f6fd1f
authored
8 years ago
by
Swen Vermeul
Browse files
Options
Downloads
Patches
Plain Diff
complete working uploader
parent
4a7bef52
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/core-plugins/jupyter-api/1/dss/reporting-plugins/jupyter-uploader-api/dataset-uploader-api.py
+47
-65
47 additions, 65 deletions
...ting-plugins/jupyter-uploader-api/dataset-uploader-api.py
with
47 additions
and
65 deletions
src/core-plugins/jupyter-api/1/dss/reporting-plugins/jupyter-uploader-api/dataset-uploader-api.py
+
47
−
65
View file @
05f6fd1f
...
@@ -35,7 +35,6 @@ import shutil
...
@@ -35,7 +35,6 @@ import shutil
import
errno
import
errno
def
getSampleByIdentifier
(
transaction
,
identifier
):
def
getSampleByIdentifier
(
transaction
,
identifier
):
space
=
identifier
.
split
(
"
/
"
)[
1
]
space
=
identifier
.
split
(
"
/
"
)[
1
]
code
=
identifier
.
split
(
"
/
"
)[
2
]
code
=
identifier
.
split
(
"
/
"
)[
2
]
...
@@ -58,10 +57,11 @@ def get_dataset_for_name(transaction, dataset_name):
...
@@ -58,10 +57,11 @@ def get_dataset_for_name(transaction, dataset_name):
search_service
=
transaction
.
getSearchService
()
search_service
=
transaction
.
getSearchService
()
criteria
=
SearchCriteria
()
criteria
=
SearchCriteria
()
criteria
.
addMatchClause
(
MatchClause
.
createPropertyMatch
(
'
NAME
'
,
dataset_name
))
criteria
.
addMatchClause
(
MatchClause
.
createPropertyMatch
(
'
NAME
'
,
dataset_name
))
found
=
list
(
search_service
.
searchForDataSets
(
criteria
))
found
=
list
(
search_service
.
searchForDataSets
(
criteria
))
if
len
(
found
)
==
1
:
if
len
(
found
)
==
1
:
return
found
[
0
]
print
(
"
DataSetCode of found dataset =
"
+
found
[
0
].
getDataSetCode
())
return
transaction
.
getDataSetForUpdate
(
found
[
0
].
getDataSetCode
())
#return found[0]
else
:
else
:
return
None
return
None
...
@@ -110,7 +110,7 @@ def process(transaction, parameters, tableBuilder):
...
@@ -110,7 +110,7 @@ def process(transaction, parameters, tableBuilder):
print
(
'
userSessionToken:
'
+
userSessionToken
)
print
(
'
userSessionToken:
'
+
userSessionToken
)
# get mandatory sample to connect the container to
# get mandatory sample to connect the container to
sampleIdentifier
=
parameters
.
get
(
"
sample
"
).
get
(
"
identifier
"
)
sampleIdentifier
=
parameters
.
get
(
"
sample
"
).
get
(
"
identifier
"
)
.
get
(
"
identifier
"
)
print
(
'
looking for sample with identifier:
'
+
sampleIdentifier
)
print
(
'
looking for sample with identifier:
'
+
sampleIdentifier
)
if
sampleIdentifier
is
None
:
if
sampleIdentifier
is
None
:
raise
UserFailureException
(
'
mandatory parameter sample[
"
identifier
"
] is missing
'
)
raise
UserFailureException
(
'
mandatory parameter sample[
"
identifier
"
] is missing
'
)
...
@@ -133,29 +133,23 @@ def process(transaction, parameters, tableBuilder):
...
@@ -133,29 +133,23 @@ def process(transaction, parameters, tableBuilder):
)
)
dataset_codes
.
append
(
dataset_code
)
dataset_codes
.
append
(
dataset_code
)
# if parameters.get("result").get("fileNames") is not None:
# dataset_code = register_dataset(
if
parameters
.
get
(
"
containers
"
)
is
not
None
:
# transaction,
print
(
"
...creating container...
"
)
# "JUPYTER_RESULT",
for
container
in
parameters
.
get
(
"
containers
"
):
# sample,
#print("transaction = " + str(transaction))
# 'container_permId',
#print("dataSetType = " + container.get("dataSetType"))
#
#print("sample = " + str(sample))
# parameters.get("result").get("fileNames")
#print("properties = " + str(container.get("properties")) )
# )
#print("dataset_codes: " + str(dataset_codes))
# dataset_codes.append(dataset_code)
container_code
=
register_container
(
transaction
,
# if parameters.get("containers") is not None:
container
.
get
(
"
dataSetType
"
),
# for container in parameters.get("containers"):
sample
,
# container_code = register_container(
container
.
get
(
"
properties
"
),
# transaction,
dataset_codes
# container.get("dataSetType"),
)
# sample,
# container.get("properties"),
# dataset_codes
# )
#
# create the dataset
# create the dataset
if
everything_ok
:
if
everything_ok
:
# Success message
# Success message
...
@@ -178,16 +172,21 @@ def process(transaction, parameters, tableBuilder):
...
@@ -178,16 +172,21 @@ def process(transaction, parameters, tableBuilder):
def
register_container
(
transaction
,
dataset_type
,
sample
,
properties
,
contained_dataset_codes
):
def
register_container
(
transaction
,
dataset_type
,
sample
,
properties
,
contained_dataset_codes
):
container_name
=
properties
.
get
(
"
NAME
"
)
print
(
"
check if the JUPYTER_CONTAINER already exists with name:
"
+
container_name
)
# make sure container dataset doesn't exist yet
# make sure container dataset doesn't exist yet
container
=
get_dataset_for_name
(
transaction
,
properties
.
get
(
"
name
"
)
)
container
=
get_dataset_for_name
(
transaction
,
container_
name
)
if
container
is
None
:
if
container
is
None
:
print
(
"
creating new JUPYTER_CONTAINER dataset...
"
)
print
(
"
creating new JUPYTER_CONTAINER dataset...
with name:
"
+
container_name
)
# Create new container (a dataset of type "JUPYTER_CONTAINER")
# Create new container (a dataset of type "JUPYTER_CONTAINER")
container
=
transaction
.
createNewDataSet
(
dataset_type
)
container
=
transaction
.
createNewDataSet
(
dataset_type
)
container
.
setSample
(
sample
)
container
.
setSample
(
sample
)
container
.
setRegistrator
(
userId
)
container
.
setRegistrator
(
userId
)
else
:
print
(
"
JUPYTER_CONTAINER already exists:
"
+
container_name
)
print
(
"
setting properties...
"
)
for
key
in
properties
.
keySet
():
for
key
in
properties
.
keySet
():
propertyValue
=
unicode
(
properties
[
key
])
propertyValue
=
unicode
(
properties
[
key
])
print
(
"
container: setting
"
+
key
+
"
=
"
+
propertyValue
)
print
(
"
container: setting
"
+
key
+
"
=
"
+
propertyValue
)
...
@@ -203,19 +202,18 @@ def register_container(transaction, dataset_type, sample, properties, contained_
...
@@ -203,19 +202,18 @@ def register_container(transaction, dataset_type, sample, properties, contained_
def
register_dataset
(
transaction
,
dataset_type
,
sample
,
properties
,
ws_folder
,
file_names
):
def
register_dataset
(
transaction
,
dataset_type
,
sample
,
properties
,
ws_folder
,
file_names
):
"""
creates a new dataset of type JUPYTER_RESULT.
"""
creates a new dataset of a given type.
the parent dataset is the JUPYTER_CONTAINER we just created
- the result files are copied from the session workspace
- the result files are copied from the session workspace
to a temp dir close to the DSS: prepareFilesForRegistration()
to a temp dir close to the DSS: prepareFilesForRegistration()
- from there, the files are moved to the DSS: transaction.moveFile()
- from there, the files are moved to the DSS: transaction.moveFile()
- finally, the remaining files are deleted from the session workspace
- finally, the remaining files are deleted from the session workspace
"""
"""
print
(
"
dataset_type =
"
+
dataset_type
)
print
(
"
creating
"
+
dataset
_
type
+
"
dataset
...
"
)
print
(
"
creating dataset
of
type
:
"
+
dataset
_type
)
dataset
=
transaction
.
createNewDataSet
(
dataset_type
)
dataset
=
transaction
.
createNewDataSet
(
dataset_type
)
dataset
.
setSample
(
sample
)
dataset
.
setSample
(
sample
)
# setting any given properties
for
key
in
properties
.
keySet
():
for
key
in
properties
.
keySet
():
propertyValue
=
unicode
(
properties
[
key
]);
propertyValue
=
unicode
(
properties
[
key
]);
print
(
"
setting propertyValue:
"
+
key
+
"
=
"
+
propertyValue
)
print
(
"
setting propertyValue:
"
+
key
+
"
=
"
+
propertyValue
)
...
@@ -223,39 +221,40 @@ def register_dataset(transaction, dataset_type, sample, properties, ws_folder, f
...
@@ -223,39 +221,40 @@ def register_dataset(transaction, dataset_type, sample, properties, ws_folder, f
propertyValue
=
None
;
propertyValue
=
None
;
dataset
.
setPropertyValue
(
key
,
propertyValue
);
dataset
.
setPropertyValue
(
key
,
propertyValue
);
print
(
"
JUPYTER_RESULT
permId:
"
+
dataset
.
getDataSetCode
())
print
(
"
dataset created with
permId:
"
+
dataset
.
getDataSetCode
())
print
(
"
workspace folder is:
"
+
ws_folder
)
# create temporary folder in incoming-dir ( openbis/servers/datastore_server/data/incoming )
# create temporary folder in incoming-dir ( openbis/servers/datastore_server/data/incoming )
threadProperties
=
getThreadProperties
(
transaction
)
threadProperties
=
getThreadProperties
(
transaction
)
print
(
threadProperties
)
incoming_dir
=
os
.
path
.
join
(
threadProperties
[
u
'
incoming-dir
'
],
str
(
time
.
time
())
)
dst_dir
=
os
.
path
.
join
(
threadProperties
[
u
'
incoming-dir
'
],
str
(
time
.
time
())
)
print
(
"
incoming folder is:
"
+
incoming_dir
)
print
(
"
incoming folder:
"
+
dst_dir
)
dss_service
=
ServiceProvider
.
getDssServiceRpcGeneric
().
getService
()
dss_service
=
ServiceProvider
.
getDssServiceRpcGeneric
().
getService
()
# copy all files from session workspace to (temporary) incoming directory.
for
file_name
in
file_names
:
for
file_name
in
file_names
:
print
(
"
copying file:
"
+
file_name
)
ws_file_path
=
os
.
path
.
join
(
ws_folder
,
file_name
)
file_path
=
os
.
path
.
join
(
dst_dir
,
file_name
)
print
(
"
copying file from session workspace:
"
+
ws_file_path
)
print
(
"
to:
"
+
file_path
)
incoming_file_path
=
os
.
path
.
join
(
incoming_dir
,
file_name
)
print
(
"
to incoming:
"
+
incoming_file_path
)
# ensure that all necessary folders exist
# ensure that all necessary folders exist
try
:
try
:
os
.
makedirs
(
os
.
path
.
dirname
(
file_path
))
os
.
makedirs
(
os
.
path
.
dirname
(
incoming_
file_path
))
print
(
"
subdir created:
"
+
os
.
path
.
dirname
(
file_path
))
print
(
"
subdir created:
"
+
os
.
path
.
dirname
(
incoming_
file_path
))
except
:
except
:
pass
pass
# create input and output stream
# create input and output stream
inputStream
=
dss_service
.
getFileFromSessionWorkspace
(
userSessionToken
,
file_
name
)
inputStream
=
dss_service
.
getFileFromSessionWorkspace
(
userSessionToken
,
ws_
file_
path
)
outputStream
=
FileOutputStream
(
File
(
file_path
))
outputStream
=
FileOutputStream
(
File
(
incoming_
file_path
))
IOUtils
.
copyLarge
(
inputStream
,
outputStream
)
IOUtils
.
copyLarge
(
inputStream
,
outputStream
)
IOUtils
.
closeQuietly
(
inputStream
)
IOUtils
.
closeQuietly
(
inputStream
)
IOUtils
.
closeQuietly
(
outputStream
)
IOUtils
.
closeQuietly
(
outputStream
)
dst_dir2
=
os
.
path
.
join
(
dst_dir
,
ws_folde
r
)
print
(
"
transaction.move from incoming folder:
"
+
incoming_di
r
)
transaction
.
moveFile
(
File
(
dst
_dir
2
).
getAbsolutePath
(),
dataset
);
transaction
.
moveFile
(
File
(
incoming
_dir
).
getAbsolutePath
(),
dataset
);
# temp_dir = prepareFilesForRegistration(transaction, file_names)
# temp_dir = prepareFilesForRegistration(transaction, file_names)
# ...and delete all files from the session workspace
# ...and delete all files from the session workspace
...
@@ -279,23 +278,6 @@ def getThreadProperties(transaction):
...
@@ -279,23 +278,6 @@ def getThreadProperties(transaction):
return
threadPropertyDict
return
threadPropertyDict
def
registerNotebook
(
transaction
,
sample
,
container
,
parameters
):
"""
creates a new dataset of type JUPYTER_NOTEBOOK.
the parent dataset is the container.
"""
dataSet
=
transaction
.
createNewDataSet
(
"
JUPYTER_NOTEBOOK
"
)
dataSet
.
setSample
(
sample
)
parent_codes
=
[
container
.
getDataSetCode
()]
dataSet
.
setParentDatasets
(
parent_codes
)
files
=
parameters
.
get
(
"
notebook
"
).
get
(
"
fileNames
"
)
for
file
in
files
:
pass
return
dataSet
def
getThreadProperties
(
transaction
):
def
getThreadProperties
(
transaction
):
threadPropertyDict
=
{}
threadPropertyDict
=
{}
threadProperties
=
transaction
.
getGlobalState
().
getThreadParameters
().
getThreadProperties
()
threadProperties
=
transaction
.
getGlobalState
().
getThreadParameters
().
getThreadProperties
()
...
...
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