Example #1
0
    def test_to_dict(self):
        tree_data = TreeData(
            nodes=[
                WorkloadTreeNode(
                    type="jobs",
                    name="loadleveler_jobs",
                    blob_ticket_id=1
                ),
                WorkloadTreeNode(
                    type="abnormal_jobs",
                    name="loadleveler_abnormal_jobs",
                    blob_ticket_id=2
                )
            ]
        )

        tree_data_dict = {
            'nodes': [
                {
                    '_cls': 'WorkloadTreeNode',
                    'type': 'jobs',
                    'name': 'loadleveler_jobs',
                    'blob_ticket_id': 1
                },
                {
                    '_cls': 'WorkloadTreeNode',
                    'type': 'abnormal_jobs',
                    'name': 'loadleveler_abnormal_jobs',
                    'blob_ticket_id': 2
                }
            ]
        }

        assert tree_data.to_dict() == tree_data_dict
Example #2
0
    def test_set_data(self):
        tree = Tree(
            ticket_id=1,
            owner='my',
            repo='my_repo',
            timestamp=datetime(2018, 9, 17, 9, 55, 0)
        )

        tree_data = TreeData(
            nodes=[
                WorkloadTreeNode(
                    type="jobs",
                    name="loadleveler_jobs",
                    blob_ticket_id=1
                ),
                WorkloadTreeNode(
                    type="abnormal_jobs",
                    name="loadleveler_abnormal_jobs",
                    blob_ticket_id=2
                )
            ]
        )

        tree.set_data(tree_data)

        tree_data = {}
        with pytest.raises(TypeError):
            tree.set_data(tree_data)
Example #3
0
    def test_construction(self):
        tree_node = WorkloadTreeNode()

        tree_node = WorkloadTreeNode(
            type="jobs",
            name="loadleveler_jobs",
            blob_ticket_id=1
        )

        tree_node = WorkloadTreeNode(
            type="abnormal_jobs",
            name="loadleveler_abnormal_jobs",
            blob_ticket_id=2
        )
Example #4
0
    def test_to_dict(self):
        tree_node = WorkloadTreeNode(
            type="jobs",
            name="loadleveler_jobs",
            blob_ticket_id=1
        )

        tree_node_dict = {
            '_cls': 'WorkloadTreeNode',
            'type': 'jobs',
            'name': 'loadleveler_jobs',
            'blob_ticket_id': 1
        }

        assert tree_node.to_dict() == tree_node_dict
Example #5
0
    def test_construction(self):
        tree_data = TreeData()

        tree_data = TreeData(
            nodes=[
                WorkloadTreeNode(
                    type="jobs",
                    name="loadleveler_jobs",
                    blob_ticket_id=1
                ),
                WorkloadTreeNode(
                    type="abnormal_jobs",
                    name="loadleveler_abnormal_jobs",
                    blob_ticket_id=2
                )
            ]
        )
Example #6
0
    def test_to_dict(self):
        tree = Tree(
            ticket_id=1,
            owner='my',
            repo='my_repo',
            timestamp=datetime(2018, 9, 17, 9, 55, 0),
            data=TreeData(
                nodes=[
                    WorkloadTreeNode(
                        type="jobs",
                        name="loadleveler_jobs",
                        blob_ticket_id=1
                    ),
                    WorkloadTreeNode(
                        type="abnormal_jobs",
                        name="loadleveler_abnormal_jobs",
                        blob_ticket_id=2
                    )
                ]
            )
        )

        tree_dict = {
            'ticket_id': 1,
            'owner': 'my',
            'repo': 'my_repo',
            'timestamp': datetime(2018, 9, 17, 9, 55, 0),
            'data': {
                'nodes': [
                    {
                        '_cls': 'WorkloadTreeNode',
                        'type': 'jobs',
                        'name': 'loadleveler_jobs',
                        'blob_ticket_id': 1
                    },
                    {
                        '_cls': 'WorkloadTreeNode',
                        'type': 'abnormal_jobs',
                        'name': 'loadleveler_abnormal_jobs',
                        'blob_ticket_id': 2
                    }
                ]
            }
        }

        assert tree.to_dict() == tree_dict
Example #7
0
    def test_construction(self):
        tree = Tree()

        tree = Tree(
            ticket_id=1,
            owner='my',
            repo='my_repo',
            timestamp=datetime(2018, 9, 17, 9, 55, 0),
            data=TreeData(
                nodes=[
                    WorkloadTreeNode(
                        type="jobs",
                        name="loadleveler_jobs",
                        blob_ticket_id=1
                    ),
                    WorkloadTreeNode(
                        type="abnormal_jobs",
                        name="loadleveler_abnormal_jobs",
                        blob_ticket_id=2
                    )
                ]
            )
        )
Example #8
0
def save_abnormal_jobs_to_nmp_model_system(owner: str, repo: str,
                                           plugin_result: dict) -> dict:
    from nmp_model.mongodb.blobs.workload.abnormal_jobs import (
        AbnormalJobsContent, AbnormalJobsBlobData, AbnormalJobsBlob)
    from nmp_model.mongodb.trees.workload_tree_node import WorkloadTreeNode
    from nmp_model.mongodb.tree import TreeData, Tree
    from nmp_model.mongodb.commits.workload_commit import WorkloadCommit, WorkloadCommitData

    abnormal_jobs_blob = AbnormalJobsBlob(
        owner=owner,
        repo=repo,
        ticket_id=get_new_64bit_ticket(),
        data=AbnormalJobsBlobData(
            workload_system=plugin_result['data']['workload_system'],
            user_name=owner,
            collected_time=plugin_result['data']['collected_time'],
            content=AbnormalJobsContent(
                plugins=plugin_result['data']['plugins'],
                abnormal_jobs=plugin_result['data']['target_job_items'])))

    abnormal_jobs_blob.save()

    tree_object = Tree(
        ticket_id=get_new_64bit_ticket(),
        owner=owner,
        repo=repo,
        data=TreeData(nodes=[
            WorkloadTreeNode(type='abnormal_jobs',
                             name='loadleveler.abnormal_jobs',
                             blob_ticket_id=abnormal_jobs_blob.ticket_id)
        ]))

    tree_object.save()

    commit_object = WorkloadCommit(
        ticket_id=get_new_64bit_ticket(),
        owner=owner,
        repo=repo,
        data=WorkloadCommitData(committer='nmp-broker',
                                type='abnormal_jobs',
                                tree_ticket_id=tree_object.ticket_id,
                                committed_time=datetime.datetime.utcnow()))

    commit_object.save()

    return {
        'blobs': [abnormal_jobs_blob],
        'trees': [tree_object],
        'commits': [commit_object]
    }