Beispiel #1
0
    def test_create_workflow(self):
        notebook = nbformat.v4.new_notebook()
        pattern_name = 'test_pattern'
        recipe_name = 'test_recipe'
        recipe = {
            'name': recipe_name,
            'vgrid': self.test_vgrid,
            'recipe': notebook
        }

        created, recipe_id = workflow_api_create(self.configuration,
                                                 self.workflow_session,
                                                 WORKFLOW_RECIPE, **recipe)
        self.logger.info(recipe_id)
        self.assertTrue(created)
        pattern = {
            'name': pattern_name,
            'vgrid': self.test_vgrid,
            'input_paths': ['input_dir/*hdf5'],
            'input_file': 'hdf5_input',
            'output': {
                'output_dir': 'pattern_0_output_variable_name'
            },
            'recipes': [recipe_name],
            'variables': {}
        }

        created, pattern_id = workflow_api_create(self.configuration,
                                                  self.workflow_session,
                                                  WORKFLOW_PATTERN, **pattern)

        self.assertTrue(created)
Beispiel #2
0
    def test_create_workflow_recipe(self):
        notebook = nbformat.v4.new_notebook()
        recipe_name = 'test_recipe_0'
        recipe_attributes = {
            'name': recipe_name,
            'vgrid': self.test_vgrid,
            'recipe': notebook,
            'source': ''
        }

        created, recipe_id = workflow_api_create(self.configuration,
                                                 self.workflow_session,
                                                 WORKFLOW_RECIPE,
                                                 **recipe_attributes)
        self.logger.info(recipe_id)
        self.assertTrue(created)
        workflow = get_workflow_with(self.configuration,
                                     client_id=self.username,
                                     user_query=True,
                                     workflow_type=WORKFLOW_RECIPE,
                                     **{'persistence_id': recipe_id})
        self.assertIsNotNone(workflow)
        self.logger.info(workflow)
        self.assertEqual(len(workflow), 1)
        # Check internal attributes
        for k, v in recipe_attributes.items():
            self.assertEqual(workflow[0][k], v)
Beispiel #3
0
    def test_create_read_delete_pattern(self):
        pattern_name = 'test_pattern_0'
        recipe_name = 'test_recipe_0'
        pattern_attributes = {
            'name': pattern_name,
            'vgrid': self.test_vgrid,
            'input_paths': ['initial_data/*.hdf5'],
            'input_file': 'hdf5_input',
            'output': {
                'output_dir': 'pattern_0_output_variable_name'
            },
            'recipes': [recipe_name],
            'variables': {
                'iterations': 20
            }
        }

        created, pattern_id = workflow_api_create(self.configuration,
                                                  self.workflow_session,
                                                  WORKFLOW_PATTERN,
                                                  **pattern_attributes)
        self.logger.info(pattern_id)
        self.assertTrue(created)

        workflow, msg = workflow_api_read(self.configuration,
                                          self.workflow_session,
                                          WORKFLOW_PATTERN,
                                          **{'persistence_id': pattern_id})
        self.assertIsNot(workflow, False)
        self.assertEqual(len(workflow), 1)
        # Check internal attributes
        self.assertEqual(workflow[0]['persistence_id'], pattern_id)
        self.assertEqual(workflow[0]['name'], pattern_attributes['name'])
        self.assertEqual(workflow[0]['vgrid'], pattern_attributes['vgrid'])
        # TODO, update input_paths and recipe testing

        # TODO, validate it has the expected attributes
        delete_attributes = {
            'vgrid': self.test_vgrid,
            'persistence_id': pattern_id
        }

        deleted, deleted_id = workflow_api_delete(self.configuration,
                                                  self.workflow_session,
                                                  WORKFLOW_PATTERN,
                                                  **delete_attributes)
        self.logger.info(deleted_id)
        self.assertTrue(deleted)

        workflow, msg = workflow_api_read(self.configuration,
                                          self.workflow_session,
                                          WORKFLOW_PATTERN,
                                          **{'persistence_id': deleted_id})
        self.assertFalse(workflow)
Beispiel #4
0
    def test_update_pattern(self):
        pattern_name = 'test_pattern'
        recipe_name = 'test_recipe'
        pattern_attributes = {
            'name': pattern_name,
            'vgrid': self.test_vgrid,
            'input_paths': ['input_dir/*.hdf5'],
            'input_file': 'hdf5_input',
            'output': {
                'output_dir': 'pattern_0_output_variable_name'
            },
            'recipes': [recipe_name],
            'variables': {
                'iterations': 20
            }
        }

        created, pattern_id = workflow_api_create(self.configuration,
                                                  self.workflow_session,
                                                  WORKFLOW_PATTERN,
                                                  **pattern_attributes)
        self.logger.info(pattern_id)
        self.assertTrue(created)
        pattern_new_name = 'test_updated_pattern'
        new_attributes = {
            'name': pattern_new_name,
            'vgrid': self.test_vgrid,
            'persistence_id': pattern_id
        }

        # TODO Try update without persistence_id
        updated, pattern_id = workflow_api_update(self.configuration,
                                                  self.workflow_session,
                                                  WORKFLOW_PATTERN,
                                                  **new_attributes)
        self.logger.info(pattern_id)
        self.assertTrue(updated)
        workflow, msg = workflow_api_read(self.configuration,
                                          self.workflow_session,
                                          WORKFLOW_PATTERN,
                                          **{'persistence_id': pattern_id})
        self.assertEqual(len(workflow), 1)
        self.assertEqual(workflow[0]['persistence_id'], pattern_id)
        self.assertEqual(workflow[0]['name'], new_attributes['name'])
        self.assertEqual(workflow[0]['vgrid'], new_attributes['vgrid'])
Beispiel #5
0
    def test_create_read_delete_recipe(self):
        notebook = nbformat.v4.new_notebook()
        recipe_name = 'test_recipe_0'
        recipe_attributes = {
            'name': recipe_name,
            'vgrid': self.test_vgrid,
            'recipe': notebook,
            'source': ''
        }

        created, recipe_id = workflow_api_create(self.configuration,
                                                 self.workflow_session,
                                                 WORKFLOW_RECIPE,
                                                 **recipe_attributes)
        self.logger.info(recipe_id)
        self.assertTrue(created)
        workflow, msg = workflow_api_read(self.configuration,
                                          self.workflow_session,
                                          WORKFLOW_RECIPE,
                                          **{'persistence_id': recipe_id})
        self.assertIsNot(workflow, False)
        self.assertEqual(len(workflow), 1)
        # Check internal attributes
        for k, v in recipe_attributes.items():
            self.assertEqual(workflow[0][k], v)

        # TODO, validate it has the expected attributes
        delete_attributes = {
            'vgrid': self.test_vgrid,
            'persistence_id': recipe_id
        }

        deleted, msg = workflow_api_delete(self.configuration,
                                           self.workflow_session,
                                           WORKFLOW_RECIPE,
                                           **delete_attributes)
        self.logger.info(msg)
        self.assertTrue(deleted)

        workflow, msg = workflow_api_read(self.configuration,
                                          self.workflow_session,
                                          WORKFLOW_RECIPE,
                                          **{'persistence_id': msg})
        self.assertFalse(workflow)
Beispiel #6
0
    def test_delete_pattern(self):
        pattern_name = 'test_pattern'
        recipe_name = 'test_recipe'
        pattern_attributes = {
            'name': pattern_name,
            'vgrid': self.test_vgrid,
            'input_paths': ['initial_data/*hdf5'],
            'input_file': 'hdf5_input',
            'output': {
                'output_dir': 'pattern_0_output_variable_name'
            },
            'recipes': [recipe_name],
            'variables': {
                'iterations': 20
            }
        }

        created, pattern_id = workflow_api_create(self.configuration,
                                                  self.workflow_session,
                                                  WORKFLOW_PATTERN,
                                                  **pattern_attributes)
        self.logger.info(pattern_id)
        self.assertTrue(created)

        deletion_attributes = {
            'persistence_id': pattern_id,
            'vgrid': self.test_vgrid
        }

        deleted, msg = workflow_api_delete(self.configuration,
                                           self.workflow_session,
                                           workflow_type=WORKFLOW_PATTERN,
                                           **deletion_attributes)

        self.logger.info(msg)
        self.assertTrue(deleted)
        workflow = get_workflow_with(self.configuration,
                                     client_id=self.username,
                                     user_query=True,
                                     **deletion_attributes)

        self.assertEqual(workflow, [])
Beispiel #7
0
    def test_update_recipe(self):
        notebook = nbformat.v4.new_notebook()
        recipe_name = 'test_recipe'
        recipe_attributes = {
            'name': recipe_name,
            'vgrid': self.test_vgrid,
            'recipe': notebook,
            'source': ''
        }

        created, recipe_id = workflow_api_create(self.configuration,
                                                 self.workflow_session,
                                                 WORKFLOW_RECIPE,
                                                 **recipe_attributes)
        self.assertTrue(created)
        recipe_new_name = 'test_updated_recipe'
        new_attributes = {
            'name': recipe_new_name,
            'vgrid': self.test_vgrid,
            'persistence_id': recipe_id
        }
        # TODO Try update without persistence_id
        updated, recipe_id = workflow_api_update(self.configuration,
                                                 self.workflow_session,
                                                 WORKFLOW_RECIPE,
                                                 **new_attributes)
        self.logger.info(recipe_id)
        self.assertTrue(updated)

        workflow, msg = workflow_api_read(self.configuration,
                                          self.workflow_session,
                                          WORKFLOW_RECIPE,
                                          **{'persistence_id': recipe_id})
        self.assertEqual(len(workflow), 1)
        self.assertEqual(workflow[0]['persistence_id'], recipe_id)
        self.assertEqual(workflow[0]['name'], new_attributes['name'])
        self.assertEqual(workflow[0]['vgrid'], new_attributes['vgrid'])
Beispiel #8
0
    def test_delete_recipe(self):
        notebook = nbformat.v4.new_notebook()
        recipe_name = 'test_recipe'
        recipe_attributes = {
            'name': recipe_name,
            'vgrid': self.test_vgrid,
            'recipe': notebook,
            'source': ''
        }

        created, recipe_id = workflow_api_create(self.configuration,
                                                 self.workflow_session,
                                                 WORKFLOW_RECIPE,
                                                 **recipe_attributes)
        self.logger.info(recipe_id)
        self.assertTrue(created)

        deletion_attributes = {
            'persistence_id': recipe_id,
            'vgrid': self.test_vgrid
        }

        deleted, msg = workflow_api_delete(self.configuration,
                                           self.workflow_session,
                                           workflow_type=WORKFLOW_RECIPE,
                                           **deletion_attributes)

        self.logger.info(msg)
        self.assertTrue(deleted)

        workflow = get_workflow_with(self.configuration,
                                     client_id=self.username,
                                     user_query=True,
                                     **deletion_attributes)

        self.assertEqual(workflow, [])
Beispiel #9
0
    def test_clear_user_workflows(self):
        pattern_name = 'test_pattern'
        recipe_name = 'test_recipe'
        pattern_attributes = {
            'name': pattern_name,
            'vgrid': self.test_vgrid,
            'input_paths': ['input_dir/*hdf5'],
            'input_file': 'hdf5_input',
            'output': {
                'output_dir': 'pattern_0_output_variable_name'
            },
            'recipes': [recipe_name],
            'variables': {
                'iterations': 20
            }
        }
        created, pattern_id = workflow_api_create(self.configuration,
                                                  self.workflow_session,
                                                  WORKFLOW_PATTERN,
                                                  **pattern_attributes)
        self.logger.info(pattern_id)
        self.assertTrue(created)

        notebook = nbformat.v4.new_notebook()
        recipe_name = 'test_update_recipe'
        recipe_attributes = {
            'name': recipe_name,
            'vgrid': self.test_vgrid,
            'recipe': notebook,
            'source': ''
        }
        created, recipe_id = workflow_api_create(self.configuration,
                                                 self.workflow_session,
                                                 WORKFLOW_RECIPE,
                                                 **recipe_attributes)
        self.logger.info(recipe_id)
        self.assertTrue(created)

        # Get every workflow in vgrid
        workflows, msg = workflow_api_read(self.configuration,
                                           self.workflow_session, WORKFLOW_ANY,
                                           **{'vgrid': self.test_vgrid})
        self.logger.info(workflows)
        self.assertIsNotNone(workflows)
        # Verify that the created objects exist
        self.assertEqual(len(workflows), 2)
        for workflow in workflows:
            if workflow['object_type'] == WORKFLOW_PATTERN:
                self.assertEqual(workflow['persistence_id'], pattern_id)
                self.assertEqual(workflow['name'], pattern_attributes['name'])
                self.assertEqual(workflow['vgrid'],
                                 pattern_attributes['vgrid'])
                self.assertEqual(workflow['variables'],
                                 pattern_attributes['variables'])
                continue

            if workflow['object_type'] == WORKFLOW_RECIPE:
                self.assertEqual(workflow['persistence_id'], recipe_id)
                for k, v in recipe_attributes.items():
                    self.assertEqual(workflow[k], v)
        self.assertTrue(
            reset_workflows(self.configuration, client_id=self.username))

        no_workflows, msg = workflow_api_read(self.configuration,
                                              self.workflow_session,
                                              WORKFLOW_ANY,
                                              **{'vgrid': self.test_vgrid})
        self.assertFalse(no_workflows)
Beispiel #10
0
    def test_create_workflow_pattern(self):
        pattern_name = 'test_pattern_0'
        recipe_name = 'test_recipe_0'
        minimum_pattern_attributes = {
            'name': pattern_name,
            'vgrid': self.test_vgrid,
            'input_paths': ['input_dir/*.hdf5'],
            'input_file': 'hdf5_input',
            'output': {},
            'recipes': [recipe_name]
        }

        created, pattern_id = workflow_api_create(self.configuration,
                                                  self.workflow_session,
                                                  WORKFLOW_PATTERN,
                                                  **minimum_pattern_attributes)
        self.logger.info(pattern_id)
        self.assertTrue(created)
        workflow = get_workflow_with(self.configuration,
                                     client_id=self.username,
                                     user_query=True,
                                     **{'persistence_id': pattern_id})

        self.logger.warning("Workflow returned '%s'" % workflow)
        self.assertIsNotNone(workflow)
        self.assertEqual(len(workflow), 1)
        # Check internal attributes
        self.assertEqual(workflow[0]['persistence_id'], pattern_id)
        self.assertEqual(workflow[0]['name'],
                         minimum_pattern_attributes['name'])
        self.assertEqual(workflow[0]['vgrid'],
                         minimum_pattern_attributes['vgrid'])
        # TODO, update input_paths and recipe testing

        self.assertTrue(
            reset_workflows(self.configuration, client_id=self.username))

        pattern_name = 'test_pattern_1'
        full_pattern_attributes = {
            'name': pattern_name,
            'vgrid': self.test_vgrid,
            'input_paths': ['input_dir/*hdf5'],
            'input_file': 'hdf5_input',
            'output': {
                'output_dir': 'pattern_0_output_variable_name'
            },
            'recipes': [recipe_name],
            'variables': {
                'iterations': 20
            }
        }

        created, pattern_id_1 = workflow_api_create(self.configuration,
                                                    self.workflow_session,
                                                    WORKFLOW_PATTERN,
                                                    **full_pattern_attributes)
        self.logger.info(pattern_id_1)
        self.assertTrue(created)
        workflow = get_workflow_with(self.configuration,
                                     client_id=self.username,
                                     user_query=True,
                                     **{'persistence_id': pattern_id_1})
        self.assertIsNotNone(workflow)
        self.assertEqual(len(workflow), 1)
        # Check internal attributes
        self.assertEqual(workflow[0]['persistence_id'], pattern_id_1)
        self.assertEqual(workflow[0]['name'], full_pattern_attributes['name'])
        self.assertEqual(workflow[0]['vgrid'],
                         full_pattern_attributes['vgrid'])