当前位置: 首页>>代码示例>>Python>>正文


Python ObservatoryUtil.get_status_roll_ups方法代码示例

本文整理汇总了Python中ion.services.sa.observatory.observatory_util.ObservatoryUtil.get_status_roll_ups方法的典型用法代码示例。如果您正苦于以下问题:Python ObservatoryUtil.get_status_roll_ups方法的具体用法?Python ObservatoryUtil.get_status_roll_ups怎么用?Python ObservatoryUtil.get_status_roll_ups使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ion.services.sa.observatory.observatory_util.ObservatoryUtil的用法示例。


在下文中一共展示了ObservatoryUtil.get_status_roll_ups方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestObservatoryUtil

# 需要导入模块: from ion.services.sa.observatory.observatory_util import ObservatoryUtil [as 别名]
# 或者: from ion.services.sa.observatory.observatory_util.ObservatoryUtil import get_status_roll_ups [as 别名]

#.........这里部分代码省略.........
        self.assertIn('DP_1', res_dict['device_data_products']['ID_1'])
        self.assertIn('PD_1', res_dict['device_data_products'])
        self.assertEquals(len(res_dict['device_data_products']['PD_1']), 3)

        res_dict = self.obs_util.get_site_data_products('Org_1', RT.Org)
        self.assertIn('DP_1', res_dict['device_data_products']['ID_1'])

        res_dict = self.obs_util.get_site_data_products('PS_1', RT.PlatformSite, include_data_products=True)
        self.assertIsNotNone(res_dict['data_product_resources'])
        self.assertIn('DP_1', res_dict['data_product_resources'])

        #import pprint
        #pprint.pprint(res_dict)


    status_by_device_1 = {
        "ID_1": _devstat("ID_1", DST.STATUS_OK, DST.STATUS_OK, DST.STATUS_OK, DST.STATUS_OK),
        "PD_1": _devstat("PD_1", DST.STATUS_OK, DST.STATUS_OK, DST.STATUS_OK, DST.STATUS_OK),
    }
    status_by_device_2 = {
        "ID_1": _devstat("ID_1", DST.STATUS_WARNING, DST.STATUS_OK, DST.STATUS_OK, DST.STATUS_OK),
        "PD_1": _devstat("PD_1", DST.STATUS_OK, DST.STATUS_OK, DST.STATUS_OK, DST.STATUS_OK),
    }
    status_by_device_3 = {
        "ID_1": _devstat("ID_1", DST.STATUS_WARNING, DST.STATUS_WARNING, DST.STATUS_OK, DST.STATUS_OK),
        "PD_1": _devstat("PD_1", DST.STATUS_OK, DST.STATUS_OK, DST.STATUS_OK, DST.STATUS_OK),
    }
    status_by_device_4 = {
        "ID_1": _devstat("ID_1", DST.STATUS_OK, DST.STATUS_OK, DST.STATUS_OK, DST.STATUS_OK),
        "PD_1": _devstat("PD_1", DST.STATUS_WARNING, DST.STATUS_WARNING, DST.STATUS_OK, DST.STATUS_OK),
    }


    def test_get_status_roll_ups(self):
        self.mu.load_mock_resources(self.res_list)
        self.mu.load_mock_associations(self.assoc_list + self.assoc_list1 + self.assoc_list2)
        self.mu.load_mock_device_statuses(self.status_by_device_1)

        self.obs_util = ObservatoryUtil(self.process_mock, self.container_mock, device_status_mgr=self.dsm_mock)

        # No problems
        status_rollups = self.obs_util.get_status_roll_ups('ID_1', RT.InstrumentDevice)
        self.assertIn('ID_1', status_rollups)
        self._assert_status(status_rollups, 'ID_1')

        status_rollups = self.obs_util.get_status_roll_ups('PD_1', RT.PlatformDevice)
        self.assertIn('PD_1', status_rollups)
        self.assertIn('ID_1', status_rollups)
        self._assert_status(status_rollups, 'PD_1')
        self._assert_status(status_rollups, 'ID_1')

        status_rollups = self.obs_util.get_status_roll_ups('IS_1', RT.InstrumentSite)
        self.assertEquals(len(status_rollups), 6)
        self.assertIn('IS_1', status_rollups)
        self.assertIn('ID_1', status_rollups)
        self._assert_status(status_rollups, 'IS_1')
        self._assert_status(status_rollups, 'ID_1')

        status_rollups = self.obs_util.get_status_roll_ups('PS_1', RT.PlatformSite)
        self.assertEquals(len(status_rollups), 6)
        self.assertIn('PS_1', status_rollups)
        self.assertIn('PD_1', status_rollups)
        self.assertIn('IS_1', status_rollups)
        self.assertIn('ID_1', status_rollups)
        self._assert_status(status_rollups, 'PS_1')
        self._assert_status(status_rollups, 'PD_1')
开发者ID:MatthewArrott,项目名称:coi-services,代码行数:70,代码来源:test_observatory_util.py

示例2: _process_cmd_sites

# 需要导入模块: from ion.services.sa.observatory.observatory_util import ObservatoryUtil [as 别名]
# 或者: from ion.services.sa.observatory.observatory_util.ObservatoryUtil import get_status_roll_ups [as 别名]
def _process_cmd_sites(resource_id, res_obj=None):
    from ion.services.sa.observatory.observatory_util import ObservatoryUtil
    outil = ObservatoryUtil(container=Container.instance)
    statuses = outil.get_status_roll_ups(resource_id, include_structure=True)
    fragments = [
        "</pre><h3>Org, Site and Device Status</h3>",
        ]

    if '_system' in statuses:
        extra = statuses['_system']
        child_sites, ancestors, devices = extra.get('sites', {}), extra.get('ancestors', {}), extra.get('devices', {})
        root_id = outil.get_site_root(resource_id, ancestors=ancestors) if ancestors else resource_id

        fragments.append("<p><table>")
        fragments.append("<tr><th>Resource</th><th>Type</th><th>AGG</th><th>PWR</th><th>COMM</th><th>DATA</th><th>LOC</th></tr>")
        device_info = {}
        if devices:
            dev_id_list = [dev[1] for dev in devices.values() if dev is not None]
            if dev_id_list:
                dev_list = Container.instance.resource_registry.read_mult(dev_id_list)
                device_info = dict(zip([res._id for res in dev_list], dev_list))
        elif ancestors:
            dev_id_list = [anc for anc_list in ancestors.values() if anc_list is not None for anc in anc_list]
            dev_id_list.append(resource_id)
            dev_list = Container.instance.resource_registry.read_mult(dev_id_list)
            device_info = dict(zip([res._id for res in dev_list], dev_list))

        def stat(status, stype):
            stat = status.get(stype, 4)
            stat_str = ['', "<span style='color:green'>OK</span>","<span style='color:orange'>WARN</span>","<span style='color:red'>ERROR</span>",'?']
            return stat_str[stat]

        def status_table(parent_id, level):
            fragments.append("<tr>")
            par_detail = child_sites.get(parent_id, None) or device_info.get(parent_id, None)
            par_status = statuses.get(parent_id, {})
            entryname = "&nbsp;"*level + build_link(par_detail.name if par_detail else parent_id, "/view/%s" % parent_id)
            if parent_id == resource_id:
                entryname = "<b>" + entryname + "</b>"
            fragments.append("<td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td>" % (
                entryname,
                par_detail._get_type() if par_detail else "?",
                stat(par_status, 'agg'), stat(par_status, 'power'), stat(par_status, 'comms'), stat(par_status, 'data'), stat(par_status, 'loc')))
            fragments.append("</tr>")
            device = devices.get(parent_id, None)
            if device:
                status_table(device[1], level+1)

            ch_ids = ancestors.get(parent_id, None) or []
            for ch_id in ch_ids:
                status_table(ch_id, level+1)

        status_table(root_id, 0)
        fragments.append("</table></p>")
        fragments.append("<pre>%s</pre>" % (pprint.pformat(statuses))),

    else:
        fragments.append("<pre>%s</pre>" % (pprint.pformat(statuses))),

    fragments.append("<pre>")
    content = "\n".join(fragments)
    return content
开发者ID:blazetopher,项目名称:coi-services,代码行数:64,代码来源:containerui.py

示例3: TestObservatoryUtil

# 需要导入模块: from ion.services.sa.observatory.observatory_util import ObservatoryUtil [as 别名]
# 或者: from ion.services.sa.observatory.observatory_util.ObservatoryUtil import get_status_roll_ups [as 别名]

#.........这里部分代码省略.........
        self.mu.load_mock_resources(self.res_list)
        self.mu.load_mock_associations(self.assoc_list2)

        self.obs_util = ObservatoryUtil(self.process_mock, self.container_mock)
        child_devices = self.obs_util.get_child_devices('PD_1')
        self.assertEquals(len(child_devices), 1)
        self.assertEquals(child_devices['PD_1'][0][1], 'ID_1')

        child_devices = self.obs_util.get_child_devices('ID_1')
        self.assertEquals(len(child_devices), 1)
        self.assertEquals(child_devices['ID_1'], [])

        child_devices = self.obs_util.get_child_devices('Sub_1')
        self.assertEquals(len(child_devices), 1)
        self.assertEquals(child_devices['Sub_1'], [])

        child_devices = self.obs_util.get_child_devices('XXX')
        self.assertEquals(len(child_devices), 1)

    event_list1 = [
        dict(et='DeviceStatusEvent', o='ID_1', attr=dict(status=DeviceStatusType.STATUS_WARNING) )
    ]
    event_list2 = [
        dict(et='DeviceStatusEvent', o='ID_1', attr=dict(status=DeviceStatusType.STATUS_WARNING))
    ]
    event_list3 = [
        dict(et='DeviceCommsEvent', o='ID_1', attr=dict(state=DeviceCommsType.DATA_DELIVERY_INTERRUPTION))
    ]
    event_list4 = [
        dict(et='DeviceStatusEvent', o='PD_1', attr=dict(status=DeviceStatusType.STATUS_WARNING)),
        dict(et='DeviceCommsEvent', o='PD_1', attr=dict(state=DeviceCommsType.DATA_DELIVERY_INTERRUPTION))
    ]

    def test_get_status_roll_ups(self):
        self.mu.load_mock_resources(self.res_list)
        self.mu.load_mock_associations(self.assoc_list + self.assoc_list1 + self.assoc_list2)
        self.mu.load_mock_events(self.event_list1)

        self.obs_util = ObservatoryUtil(self.process_mock, self.container_mock)

        # No problems
        status_rollups = self.obs_util.get_status_roll_ups('ID_1', RT.InstrumentDevice)
        self.assertIn('ID_1', status_rollups)
        self._assert_status(status_rollups, 'ID_1')

        status_rollups = self.obs_util.get_status_roll_ups('PD_1', RT.PlatformDevice)
        self.assertIn('PD_1', status_rollups)
        self.assertIn('ID_1', status_rollups)
        self._assert_status(status_rollups, 'PD_1')
        self._assert_status(status_rollups, 'ID_1')

        status_rollups = self.obs_util.get_status_roll_ups('IS_1', RT.InstrumentSite)
        self.assertEquals(len(status_rollups), 6)
        self.assertIn('IS_1', status_rollups)
        self.assertIn('ID_1', status_rollups)
        self._assert_status(status_rollups, 'IS_1')
        self._assert_status(status_rollups, 'ID_1')

        status_rollups = self.obs_util.get_status_roll_ups('PS_1', RT.PlatformSite)
        self.assertEquals(len(status_rollups), 6)
        self.assertIn('PS_1', status_rollups)
        self.assertIn('PD_1', status_rollups)
        self.assertIn('IS_1', status_rollups)
        self.assertIn('ID_1', status_rollups)
        self._assert_status(status_rollups, 'PS_1')
        self._assert_status(status_rollups, 'PD_1')
开发者ID:shenrie,项目名称:coi-services,代码行数:70,代码来源:test_observatory_util.py

示例4: ObservatoryManagementService

# 需要导入模块: from ion.services.sa.observatory.observatory_util import ObservatoryUtil [as 别名]
# 或者: from ion.services.sa.observatory.observatory_util.ObservatoryUtil import get_status_roll_ups [as 别名]

#.........这里部分代码省略.........
        if not isinstance(exclude_site_types, list):
            raise BadRequest("exclude_site_types mut be a list, is: %s" % type(exclude_site_types))

        parent_resource = self.RR.read(parent_resource_id)

        org_id, site_id = None, None
        if parent_resource.type_ == RT.Org:
            org_id = parent_resource_id
        elif RT.Site in parent_resource._get_extends():
            site_id = parent_resource_id
        else:
            raise BadRequest("Illegal parent_resource_id type. Expected Org/Site, given:%s" % parent_resource.type_)

        site_resources, site_children = self.outil.get_child_sites(site_id, org_id,
                                   exclude_types=exclude_site_types, include_parents=include_parents, id_only=id_only)

        return site_resources, site_children


    def get_sites_devices_status(self, parent_resource_id='', include_devices=False, include_status=False):
        if not parent_resource_id:
            raise BadRequest("Must provide a parent parent_resource_id")

        parent_resource = self.RR.read(parent_resource_id)

        org_id, site_id = None, None
        if parent_resource.type_ == RT.Org:
            org_id = parent_resource_id
        elif RT.Site in parent_resource._get_extends():
            site_id = parent_resource_id

        result_dict = {}
        if include_status:
            status_rollups = self.outil.get_status_roll_ups(parent_resource_id, parent_resource.type_, include_structure=True)
            struct_dict = status_rollups.pop("_system") if "_system" in status_rollups else {}

            result_dict["site_resources"] = struct_dict.get("sites", {})
            result_dict["site_children"] = struct_dict.get("ancestors", {})
            if include_devices:
                site_devices = struct_dict.get("devices", {})
                result_dict["site_devices"] = site_devices
                device_ids = [tuple_list[0][1] for tuple_list in site_devices.values() if tuple_list]
                device_objs = self.RR.read_mult(device_ids)
                result_dict["device_resources"] = dict(zip(device_ids, device_objs))
            result_dict["site_status"] = status_rollups

        else:
            site_resources, site_children = self.outil.get_child_sites(site_id, org_id, include_parents=True, id_only=False)
            result_dict["site_resources"] = site_resources
            result_dict["site_children"] = site_children

        return result_dict

    def find_site_data_products(self, parent_resource_id='', include_sites=False, include_devices=False,
                                include_data_products=False):
        if not parent_resource_id:
            raise BadRequest("Must provide a parent parent_resource_id")

        res_dict = self.outil.get_site_data_products(parent_resource_id, include_sites=include_sites,
                                                     include_devices=include_devices,
                                                     include_data_products=include_data_products)

        return res_dict


    ############################
开发者ID:jamie-cyber1,项目名称:coi-services,代码行数:70,代码来源:observatory_management_service.py


注:本文中的ion.services.sa.observatory.observatory_util.ObservatoryUtil.get_status_roll_ups方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。