Board logo

标题: 构建基于移动终端的数据中心能源管理器--Mobile AEM 系统架构 [打印本页]

作者: look_w    时间: 2018-1-10 22:16     标题: 构建基于移动终端的数据中心能源管理器--Mobile AEM 系统架构

Mobile AEM 系统架构
Mobile AEM 旨在 Android 平台上搭建一个基于移动互联网的移动数据中心能源管理器,通过该移动管理器用户可以登录到目标 IBM Systems Director Server,在该管理器提供的 AEM 监控和管理界面中进行数据中心能源消耗的监控、查看能耗事件、查看数据中心基础信息等日常监控管理工作。本系统使用 AEM REST API 通过 HTTP 协议远程获取资源信息,解析资源数据并在系统界面中以图表方式进行展现,系统架构如下图所示:
图 3. Mobile AEM 系统架构图Mobile AEM 由用户登录界面、欢迎界面、功能菜单、概要信息界面、事件查看界面、资源管理界面、能量监控界面等组成(参见基于 Android 的 AEM 功能展示)。整个系统主要通过 Android 应用组件来构造实现,Android 应用组件对象包括:Activity、Intent、Content Provider、Service。
基于 Android 应用组件构建的 Mobile AEM 的程序结构如下图所示:
图 4. Mobile AEM 程序结构图如上图所示,Mobile AEM 的源代码主要由三个 package 组成:
清单 1. 基于 HTTP 的 REST 交互
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
void Connect() {
         try {   
         SSLSocketFactory sf = getSSLSocketFactory();
         HttpsURLConnection.setDefaultSSLSocketFactory(sf);  
            
HttpsURLConnection.setDefaultHostnameVerifier(new TrustAnyHostnameVerifier());
             try {
                 URL url = new URL(strURL);                     
                 conn = (HttpsURLConnection) url.openConnection();
                 
    //set userID/userPassword for the IBM Systems Director authentication.
                 Authenticator.setDefault(new Authenticator() {
                  protected PasswordAuthentication getPasswordAuthentication() {
    return new PasswordAuthentication (username, password.toCharArray());
                  }
                 });
                 conn.connect();
                 this.responseCode = conn.getResponseCode();
                 //get response result from the connection
                 BufferedReader br;
                 String line ;
                 try {
    br = new BufferedReader(new InputStreamReader(conn.getInputStream()));   
                    while( (line = br.readLine()) != null ){
                         responseResult += line + "\n";
                    }
                    br.close();
                 } catch (IOException e) {
                     e.printStackTrace();
                 }
         //get sub response result in the form of array "[...]" from the response info
                 int start = responseResult.indexOf("[");
                 int end = responseResult.lastIndexOf("]") + 1;
                 this.resultArray = responseResult.substring(start, end);
                 
             }catch (MalformedURLException e) {
                 e.printStackTrace();
             }catch(IOException e){
                 e.printStackTrace();
             }
        } catch (Exception e) {   
            e.printStackTrace();  
        }   
     }




与 view 相关联的 Activity 组成了系统的主体,在 Activity 中通过 HTTP 协议访问服务端的 REST API 获取 JSON 对象解析并在 View 中通过曲线图、以及列表的方式进行展现,下图以查看 AEM 事件为例展示了系统中 EventDetailPage Activity 调用 REST API 获取事件详细信息的过程:
图 5. REST API 调用过程清单 2. EventDetailPage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.propertylist);
        
       ListView listView = (ListView) findViewById(R.id.eventdetailslistview);
       registerForContextMenu(listView);

       final TextView tv0 = (TextView) findViewById(R.id.edtitle);
       tv0.setText(this.getString(R.string.event_detail_page_title));
       final TextView tv = (TextView) findViewById(R.id.eventdetailshostname);
       tv.setText(_resName);

       HttpResponse resp;
       JSONObject jo;
       JSONObject objTime;
       try {
           resp = s_httpFecther.sendRequest(_resUri, HttpMethodType.GET, null);
           jo = new JSONObject(HttpFetcher.getContentAsString(resp));

           // Generate dynamic array and fill data into the array
  ArrayList<HashMap<String, Object>> eventlistItem=\
  new ArrayList<HashMap<String, Object>>();
           HashMap<String, Object> map;
           map = new HashMap<String, Object>();
           map.put("key", "ComponentType");
           map.put("value", jo.getString("ComponentType"));
           eventlistItem.add(map);
           map = new HashMap<String, Object>();
           map.put("key", "Severity");
           map.put("value", jo.getString("Severity"));
           eventlistItem.add(map);
           map = new HashMap<String, Object>();
           map.put("key", "EventText");
           map.put("value", jo.getString("EventText"));
           eventlistItem.add(map);

           objTime = new JSONObject(jo.getString("GeneratedDate"));
           Date d = new Date();
           d.setTime(Long.parseLong(objTime.getString("Date").toString()));
           HashMap<String, Object> map5 = new HashMap<String, Object>();
           map5.put("key", "GeneratedTime");
           map5.put("value", d.toLocaleString());
           eventlistItem.add(map5);
           // Generate adapter
           final SimpleAdapter propertylistItemAdapter=
           new SimpleAdapter(getBaseContext(), eventlistItem,
           R.layout.propertylistitem,
           new String[] { "key", "value" },
           new int[] { R.id.key, R.id.value });
           listView.setAdapter(propertylistItemAdapter);
       } catch (JSONException e) {
           e.printStackTrace();
       } catch (IOException e) {
           e.printStackTrace();
       }
   }






欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0