首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

构建基于移动终端的数据中心能源管理器--Mobile AEM 系统架构

构建基于移动终端的数据中心能源管理器--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。
  • Activity:基本模块,通常代表一个单独的屏幕,用于处理应用程序的整体性工作,如为用户显示指定的 View、启动其它 Activity 等。在 Android 软件环境中,应用程序由一系列的 Activity 组成。本系统由完成用户登录的 Login Activity、用来查看资源信息的 Property Activity、用来查看事件的 Event Activity 等组成;
  • Intent:执行操作的一个抽象描述,用于协调应用程序内部或应用程序间的交互与通讯。Intent 的结构包括动作和动作所对应的数据,Intent 常用来实现 Activity 的切换,并传递相关信息;
  • Content Provider:在 Android 中,Content Provider 提供了一套标准的接口来获取和存储数据,以方便其它应用保存和读取;
  • Service:一个无固定期限在后台运行的应用组件,用来实现无需在用户 UI 上进行交互的处理任务。
基于 Android 应用组件构建的 Mobile AEM 的程序结构如下图所示:
图 4. Mobile AEM 程序结构图如上图所示,Mobile AEM 的源代码主要由三个 package 组成:
  • com.ibm.cn.mAEM 包含了从登录到监控和管理功能的所有 Activity,其中 BaseActivity 类继承实现了 Android Activity 类,并在其中定义实现了系统的功能菜单,其它子类其如:LoginPage 等通过继承该类,从而使功能菜单在每一个 View 中均为可见,方便用户使用。除了功能菜单外,还在其中定义实现了系统中不同的 View 之间的跳转方法,对用户界面跳转进行了规划;HttpsUrlConnection 类为系统提供建立 HTTP 及 SSL 连接等方法;DbHelper 类提供访问 Android 中集成的 SQLite 数据库的基本方法,在其中创建了一个数据表用来保存系统用户所设定的目标 Systems Director Server 的地址,用户名及密码;
  • com.ibm.cn.mAEM.datamodel 包含了系统抽象定义的数据模型,如用户信息模型等;
  • com.ibm.cn.mAEM.httputil 包含了实现基于 HTTP 的 REST 交互类等。
清单 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();
       }
   }

返回列表