Skip to content
Snippets Groups Projects
Commit 05f6fd1f authored by Swen Vermeul's avatar Swen Vermeul
Browse files

complete working uploader

parent 4a7bef52
No related branches found
No related tags found
No related merge requests found
...@@ -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_folder) print("transaction.move from incoming folder: " + incoming_dir)
transaction.moveFile(File(dst_dir2).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()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment