From 7508cd7e3f75f292cc8886d16eeca5a11933051b Mon Sep 17 00:00:00 2001 From: felmer <franz-josef.elmer@id.ethz.ch> Date: Thu, 1 Nov 2018 11:35:13 +0100 Subject: [PATCH] SSDM-7166: monitoring-support module with core plugin dss-monitoring-initialization added --- .../SetEnableTechnologiesVariableAction.java | 2 +- ...tEnableTechnologiesVariableActionTest.java | 16 +-- .../dss-monitoring-initialization.py | 103 ++++++++++++++++++ .../plugin.properties | 3 + 4 files changed, 115 insertions(+), 9 deletions(-) create mode 100644 openbis_standard_technologies/dist/core-plugins/monitoring-support/1/dss/reporting-plugins/dss-monitoring-initialization/dss-monitoring-initialization.py create mode 100644 openbis_standard_technologies/dist/core-plugins/monitoring-support/1/dss/reporting-plugins/dss-monitoring-initialization/plugin.properties diff --git a/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/SetEnableTechnologiesVariableAction.java b/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/SetEnableTechnologiesVariableAction.java index 1a247d1f54d..822b8ef6e9f 100644 --- a/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/SetEnableTechnologiesVariableAction.java +++ b/installation/source/java/ch/systemsx/cisd/openbis/installer/izpack/SetEnableTechnologiesVariableAction.java @@ -37,7 +37,7 @@ import ch.systemsx.cisd.common.shared.basic.string.CommaSeparatedListBuilder; */ public class SetEnableTechnologiesVariableAction implements PanelAction { - private static final String[] MODULES = { "dropbox-monitor", "dataset-uploader", "dataset-file-search" }; + private static final String[] MODULES = { "monitoring-support", "dropbox-monitor", "dataset-uploader", "dataset-file-search" }; static final String ENABLED_TECHNOLOGIES_VARNAME = "ENABLED_TECHNOLOGIES"; diff --git a/installation/sourceTest/java/ch/systemsx/cisd/openbis/installer/izpack/SetEnableTechnologiesVariableActionTest.java b/installation/sourceTest/java/ch/systemsx/cisd/openbis/installer/izpack/SetEnableTechnologiesVariableActionTest.java index a59e0dc2ded..32a8c1b4ec8 100644 --- a/installation/sourceTest/java/ch/systemsx/cisd/openbis/installer/izpack/SetEnableTechnologiesVariableActionTest.java +++ b/installation/sourceTest/java/ch/systemsx/cisd/openbis/installer/izpack/SetEnableTechnologiesVariableActionTest.java @@ -93,7 +93,7 @@ public class SetEnableTechnologiesVariableActionTest extends AbstractFileSystemT variables.setProperty(TECHNOLOGY_SCREENING, "true"); updateEnabledTechnologyProperties(variables, false); - assertEquals("[, enabled-modules = dropbox-monitor, dataset-uploader, dataset-file-search, screening]", + assertEquals("[, enabled-modules = monitoring-support, dropbox-monitor, dataset-uploader, dataset-file-search, screening]", FileUtilities.loadToStringList(corePluginsProperties).toString()); } @@ -101,14 +101,14 @@ public class SetEnableTechnologiesVariableActionTest extends AbstractFileSystemT public void testUpdateInstallationWithOtherEnabledTechnologiesInAs() { FileUtilities.writeToFile(corePluginsProperties, "abc = 123\n" + ENABLED_TECHNOLOGIES_KEY - + "=dropbox-monitor, dataset-uploader, dataset-file-search, proteomics, my-tech"); + + "=monitoring-support, dropbox-monitor, dataset-uploader, dataset-file-search, proteomics, my-tech"); Properties variables = new Properties(); variables.setProperty(TECHNOLOGY_PROTEOMICS, "true"); variables.setProperty(TECHNOLOGY_SCREENING, "false"); updateEnabledTechnologyProperties(variables, false); - assertEquals("[abc = 123, " + ENABLED_TECHNOLOGIES_KEY + "=dropbox-monitor, dataset-uploader, " + assertEquals("[abc = 123, " + ENABLED_TECHNOLOGIES_KEY + "=monitoring-support, dropbox-monitor, dataset-uploader, " + "dataset-file-search, proteomics, my-tech]", FileUtilities.loadToStringList(corePluginsProperties).toString()); } @@ -117,14 +117,14 @@ public class SetEnableTechnologiesVariableActionTest extends AbstractFileSystemT public void testUpdateUnchangedProperty() { FileUtilities.writeToFile(corePluginsProperties, "abc = 123\n" + ENABLED_TECHNOLOGIES_KEY - + "=dropbox-monitor, dataset-uploader, dataset-file-search, proteomics"); + + "=monitoring-support, dropbox-monitor, dataset-uploader, dataset-file-search, proteomics"); Properties variables = new Properties(); variables.setProperty(TECHNOLOGY_PROTEOMICS, "true"); variables.setProperty(TECHNOLOGY_SCREENING, "false"); updateEnabledTechnologyProperties(variables, false); - assertEquals("[abc = 123, " + ENABLED_TECHNOLOGIES_KEY + "=dropbox-monitor, dataset-uploader, " + assertEquals("[abc = 123, " + ENABLED_TECHNOLOGIES_KEY + "=monitoring-support, dropbox-monitor, dataset-uploader, " + "dataset-file-search, proteomics]", FileUtilities .loadToStringList(corePluginsProperties).toString()); } @@ -140,7 +140,7 @@ public class SetEnableTechnologiesVariableActionTest extends AbstractFileSystemT updateEnabledTechnologyProperties(variables, false); - assertEquals("[abc = 123, " + ENABLED_TECHNOLOGIES_KEY + " = dropbox-monitor, dataset-uploader, " + assertEquals("[abc = 123, " + ENABLED_TECHNOLOGIES_KEY + " = monitoring-support, dropbox-monitor, dataset-uploader, " + "dataset-file-search, proteomics, screening, answer = 42]", FileUtilities .loadToStringList(corePluginsProperties).toString()); @@ -156,7 +156,7 @@ public class SetEnableTechnologiesVariableActionTest extends AbstractFileSystemT updateEnabledTechnologyProperties(variables, false); - assertEquals("[abc = 123, " + ENABLED_TECHNOLOGIES_KEY + " = dropbox-monitor, dataset-uploader, " + assertEquals("[abc = 123, " + ENABLED_TECHNOLOGIES_KEY + " = monitoring-support, dropbox-monitor, dataset-uploader, " + "dataset-file-search, screening]", FileUtilities .loadToStringList(corePluginsProperties).toString()); } @@ -172,7 +172,7 @@ public class SetEnableTechnologiesVariableActionTest extends AbstractFileSystemT updateEnabledTechnologyProperties(variables, false); - assertEquals("[a = b, " + ENABLED_TECHNOLOGIES_KEY + " = dropbox-monitor, dataset-uploader, " + assertEquals("[a = b, " + ENABLED_TECHNOLOGIES_KEY + " = monitoring-support, dropbox-monitor, dataset-uploader, " + "dataset-file-search, screening, gamma = alpha]", FileUtilities.loadToStringList(corePluginsProperties).toString()); } diff --git a/openbis_standard_technologies/dist/core-plugins/monitoring-support/1/dss/reporting-plugins/dss-monitoring-initialization/dss-monitoring-initialization.py b/openbis_standard_technologies/dist/core-plugins/monitoring-support/1/dss/reporting-plugins/dss-monitoring-initialization/dss-monitoring-initialization.py new file mode 100644 index 00000000000..fc10827bd41 --- /dev/null +++ b/openbis_standard_technologies/dist/core-plugins/monitoring-support/1/dss/reporting-plugins/dss-monitoring-initialization/dss-monitoring-initialization.py @@ -0,0 +1,103 @@ +import subprocess +from ch.systemsx.cisd.common.exceptions import UserFailureException +from ch.systemsx.cisd.openbis.dss.generic.shared import ServiceProvider +from ch.ethz.sis.openbis.generic.asapi.v3.dto.space.id import SpacePermId +from ch.ethz.sis.openbis.generic.asapi.v3.dto.space.fetchoptions import SpaceFetchOptions +from ch.ethz.sis.openbis.generic.asapi.v3.dto.space.create import SpaceCreation +from ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.id import SampleIdentifier +from ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.fetchoptions import SampleFetchOptions +from ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.create import SampleCreation +from ch.ethz.sis.openbis.generic.asapi.v3.dto.entitytype.id import EntityTypePermId +from ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.fetchoptions import SampleTypeFetchOptions +from ch.ethz.sis.openbis.generic.asapi.v3.dto.sample.create import SampleTypeCreation +from ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.fetchoptions import DataSetTypeFetchOptions +from ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.create import DataSetTypeCreation +from ch.ethz.sis.openbis.generic.asapi.v3.dto.person.id import PersonPermId +from ch.ethz.sis.openbis.generic.asapi.v3.dto.person.fetchoptions import PersonFetchOptions +from ch.ethz.sis.openbis.generic.asapi.v3.dto.person.create import PersonCreation +from ch.ethz.sis.openbis.generic.asapi.v3.dto.roleassignment.create import RoleAssignmentCreation +from ch.ethz.sis.openbis.generic.asapi.v3.dto.roleassignment import Role + +def process(tr, parameters, tableBuilder): + session_token = _get_mandatory_parameter(parameters, "sessionToken") + data_set_code = _get_mandatory_parameter(parameters, "data set code") + space_code = _get_mandatory_parameter(parameters, "space code") + sample_code = _get_mandatory_parameter(parameters, "sample code") + user_id = _get_mandatory_parameter(parameters, "user id") + password = _get_mandatory_parameter(parameters, "password") + + data_set_type_code = _get_parameter(parameters, "data set type code", "MONITORED_DATA_SET") + sample_type_code = _get_parameter(parameters, "sample type code", "MONITOR_SAMPLE") + file_name = _get_parameter(parameters, "file name", "info.txt") + file_content = _get_parameter(parameters, "file content", "blab blah") + + if tr.getSearchService().getDataSet(data_set_code) is None: + _create_data_set_type(session_token, data_set_type_code) + data_set = tr.createNewDataSet(data_set_type_code, data_set_code) + sample_id = _create_sample(tr, session_token, space_code, sample_code, sample_type_code) + data_set.setSample(sample_id) + with open(tr.createNewFile(data_set, file_name), "w") as file: + file.write(file_content) + _create_user(session_token, user_id, password, space_code) + + tableBuilder.addHeader("STATUS") + tableBuilder.addHeader("MESSAGE") + tableBuilder.addHeader("RESULT") + row = tableBuilder.addRow() + row.setCell("STATUS","OK") + row.setCell("MESSAGE", "Operation Successful") + row.setCell("RESULT", "done") + +def _create_data_set_type(session_token, data_set_type_code): + v3 = ServiceProvider.getV3ApplicationService() + data_set_type_permid = EntityTypePermId(data_set_type_code) + if v3.getDataSetTypes(session_token, [data_set_type_permid], DataSetTypeFetchOptions()).get(data_set_type_permid) is None: + data_set_type_creation = DataSetTypeCreation() + data_set_type_creation.setCode(data_set_type_code) + v3.createDataSetTypes(session_token, [data_set_type_creation]) + +def _create_sample(tr, session_token, space_code, sample_code, sample_type_code): + v3 = ServiceProvider.getV3ApplicationService() + space_permid = SpacePermId(space_code) + if v3.getSpaces(session_token, [space_permid], SpaceFetchOptions()).get(space_permid) is None: + space_creation = SpaceCreation() + space_creation.setCode(space_code) + v3.createSpaces(session_token, [space_creation]) + sample_id = SampleIdentifier(space_code, None, sample_code) + if v3.getSamples(session_token, [sample_id], SampleFetchOptions()).get(sample_id) is None: + sample_type_permid = EntityTypePermId(sample_type_code) + if v3.getSampleTypes(session_token, [sample_type_permid], SampleTypeFetchOptions()).get(sample_type_permid) is None: + sample_type_creation = SampleTypeCreation() + sample_type_creation.setCode(sample_type_code) + v3.createSampleTypes(session_token, [sample_type_creation]) + sample_creation = SampleCreation() + sample_creation.setTypeId(sample_type_permid) + sample_creation.setSpaceId(space_permid) + sample_creation.setCode(sample_code) + v3.createSamples(session_token, [sample_creation]) + return tr.getSearchService().getSample(sample_id.getIdentifier()) + +def _create_user(session_token, user_id, password, space_code): + v3 = ServiceProvider.getV3ApplicationService() + person_permid = PersonPermId(user_id) + if v3.getPersons(session_token, [person_permid], PersonFetchOptions()).get(person_permid) is None: + passwdShPath = '../openBIS-server/jetty/bin/passwd.sh' + subprocess.call([passwdShPath, 'add', user_id, '-p', password]) + creation = PersonCreation() + creation.setUserId(user_id) + v3.createPersons(session_token, [creation]) + role_assignment_creation = RoleAssignmentCreation() + role_assignment_creation.setUserId(person_permid) + role_assignment_creation.setRole(Role.OBSERVER) + role_assignment_creation.setSpaceId(SpacePermId(space_code)) + v3.createRoleAssignments(session_token, [role_assignment_creation]) + +def _get_parameter(parameters, key, default_value): + p = parameters.get(key) + return p if p is not None else default_value + +def _get_mandatory_parameter(parameters, key): + p = parameters.get(key) + if p is None: + raise UserFailureException("Parameter '%s' not specified." % key) + return p diff --git a/openbis_standard_technologies/dist/core-plugins/monitoring-support/1/dss/reporting-plugins/dss-monitoring-initialization/plugin.properties b/openbis_standard_technologies/dist/core-plugins/monitoring-support/1/dss/reporting-plugins/dss-monitoring-initialization/plugin.properties new file mode 100644 index 00000000000..da4af6eba30 --- /dev/null +++ b/openbis_standard_technologies/dist/core-plugins/monitoring-support/1/dss/reporting-plugins/dss-monitoring-initialization/plugin.properties @@ -0,0 +1,3 @@ +label = DSS Monitoring Initialization +class = ch.systemsx.cisd.openbis.dss.generic.server.plugins.jython.JythonIngestionService +script-path = dss-monitoring-initialization.py -- GitLab