OSDN Git Service

Initial commit
[ultramonkey-l7/l7gui.git] / src / WebContent / replication.jsp
1 <%@ page import="org.ultramonkey.l7.model.*,
2                                  org.ultramonkey.l7.controller.*,
3                                  org.ultramonkey.l7.view.*, java.util.*"
4         language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
5 <%
6
7         /*
8          * check session
9          */
10         if (session.isNew()) {
11         MessageView error = new MessageView(41333, LogCategorySet.GUI_USER_AUTHENTICATION,
12                         Message.INVALID_SESSSION);
13         session.setAttribute(SessionKeys.RESULT_MESSAGE, error);
14         response.sendRedirect(RedirectPages.LOGIN);
15         return;
16         }
17
18         /*
19          * get result message
20          */
21         MessageView message = (MessageView) session.getAttribute(SessionKeys.RESULT_MESSAGE);
22         String errorMessage = null;
23         int errorNumber = 0;
24         String category = "";
25         if (message != null) {
26                 errorMessage = message.getMessage();
27                 errorNumber = message.getErrno();
28                 category = message.getCategory();
29                 session.setAttribute(SessionKeys.RESULT_MESSAGE, null);
30         }
31
32         
33         /*
34          * get command message
35          */
36         MessageView commandmessage = (MessageView) session.getAttribute(SessionKeys.COMMAND_MESSAGE);
37         String commandMessage = null;
38         int commandNumber = 0;
39         String commandCategory = "";
40         if (commandmessage != null) {
41                 commandMessage = commandmessage.getMessage();
42                 commandNumber = commandmessage.getErrno();
43                 commandCategory = commandmessage.getCategory();
44                 session.setAttribute(SessionKeys.COMMAND_MESSAGE, null);
45         }
46
47         // get replicationData
48         L7guiFramework framework = new L7guiFramework();
49         ReplicationData rep = framework.getReplicationData();
50         ReplicationStatus repStatus = ReplicationStatus.OUT;
51         if ( null == rep ){
52                 MessageView error = new MessageView(41334, LogCategorySet.GUI_IO,
53                                 Message.UNEXPECTED_ERROR);
54                 session.setAttribute(SessionKeys.RESULT_MESSAGE, error);
55                 response.sendRedirect(RedirectPages.LOGIN);
56                 return;
57         }
58         else {
59                 repStatus = rep.replicationMode;
60         }
61         String printRepStatus = null;
62         String changeModeMessage = null;
63         switch (repStatus){
64                 case MASTER:
65                         printRepStatus = "Master Running";
66                         changeModeMessage = "If you would like to stop sending Replication data, push the following button.";
67                         break;
68                 case SLAVE:
69                         printRepStatus = "Slave Running";
70                         changeModeMessage = "If you would like to stop receiving Replication data, push the following button.";
71                         break;
72                 case MASTER_STOP:
73                         printRepStatus = "Master Stopped";
74                         changeModeMessage = "If you would like to start sending Replication data, push the following button.";
75                         break;
76                 case SLAVE_STOP:
77                         printRepStatus = "Slave Stopped";
78                         changeModeMessage = "If you would like to start receiving Replication data, push the following button.";
79                         break;
80                 case SINGLE:
81                         printRepStatus = "Replication Invalid";
82                         break;
83                 case OUT:
84                         printRepStatus = "In Starting Replication";
85                         break;
86                 default :
87                         MessageView error = new MessageView(41335, LogCategorySet.GUI_REPLICATION,
88                                         Message.UNEXPECTED_ERROR);
89                         session.setAttribute(SessionKeys.RESULT_MESSAGE, error);
90                         response.sendRedirect(RedirectPages.LOGIN);
91                         return;
92         }
93         
94         String selfNic = rep.nic;
95         String peerIp = rep.otherNode.host;
96         
97         if ( (selfNic == null) || (peerIp == null) ){
98                 MessageView error = new MessageView(41336, LogCategorySet.GUI_IO_FILE,
99                                 Message.UNEXPECTED_ERROR);
100                 session.setAttribute(SessionKeys.RESULT_MESSAGE, error);
101                 response.sendRedirect(RedirectPages.LOGIN);
102                 return;
103         }
104                         
105         HashMap<String, Integer> repDatainfo = rep.component;
106         Set keys = null;
107         if (repDatainfo != null){
108                 keys = repDatainfo.keySet();            
109         }
110         
111         /*
112          * get cluster status
113          */
114         ClusterData cd = framework.getClusterData();
115         if (cd == null) {
116                 MessageView error = new MessageView(41337, LogCategorySet.GUI_IO_COMMAND,
117                                 Message.CLUSTER_DATA_ERROR);
118                 session.setAttribute(SessionKeys.RESULT_MESSAGE, error);
119                 response.sendRedirect(RedirectPages.LOGIN);
120                 return;
121         }
122
123         /*
124          * fix style seat
125          */
126         String cssSeat = "l7gui_single_style.css";
127         if ( cd.self_status == ClusterStatus.ACTIVE ){
128                 cssSeat = "l7gui_act_style.css";
129         }
130         else if ( cd.self_status == ClusterStatus.STANDBY ){
131                 cssSeat = "l7gui_sby_style.css";
132         }
133
134 %>
135
136
137
138 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
139 <html>
140         <head>
141                 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
142                 <meta http-equiv="Pragma" content="no-cache">
143                 <meta http-equiv="Cache-Control" content="no-cache">
144                 <meta http-equiv="Expires" content="0">                                 
145                 <meta http-equiv="Content-Script-Type" content="text/javascript" />
146                 <meta http-equiv="Content-Style-Type" content="text/css" />
147                 <script src="l7gui.js" type="text/javascript"></script>
148                 <noscript> 
149         <meta http-equiv="refresh" content="<%= RedirectPages.NOSCRIPT_TIME %>; url=<%= RedirectPages.LOGIN %>"/>
150                 </noscript> 
151                 <link rel="stylesheet" type="text/css" href="<%= cssSeat %>" />
152                 <link rel="shortcut icon" href="images/favicon.ico"/>
153
154                 <title>Replication</title>
155
156         </head>
157
158         <body class="normal">
159         <jsp:include page="menu.jsp" flush="false"/>
160
161         <div id="content">
162
163
164                 <h1>Replication</h1>
165                 <%
166                         if ( (message != null) && (errorMessage != null) ) {
167                 %>
168                 
169                 <p class="error">[<%=category %> - <%=errorNumber %>]</p>
170                 <p class="error"><%=errorMessage %></p>
171                 
172                 <%
173                         }
174                         else if ( (commandmessage != null) && (commandMessage != null) ){
175                 %>
176                 <p class="success">[<%=commandCategory %> - <%=commandNumber %>]</p>
177                 <p class="success"><%=commandMessage %></p>
178                 <%              
179                         }
180                 %>
181
182                 <h2> Replication Current Status</h2>
183
184                 <form method="post" action="ReplicationModeChangeServlet" name="rep" >
185                 <fieldset>
186                 <legend>Replication Current Status</legend>
187                         <table  class="infotable" cellspacing="0">
188                         <thead>
189                                 <tr>
190                                         <th>Replication Mode</th>
191                                         </tr>
192                         </thead>
193                         <tbody>
194                                 <tr>
195                                         <td class="center"><%=printRepStatus %></td>
196                                 </tr>
197                         </tbody>
198                         </table>
199                 </fieldset>             
200                 <% if ( changeModeMessage != null){
201                 %>
202                 <h4><%=changeModeMessage %></h4>
203                 <br />
204                 <% 
205                 }
206                 switch (repStatus){
207                 case MASTER:
208                 %>
209                         <input type="submit" name="button" value="<%=ButtonMode.REP_MASTER_STOPPING %>" onClick="return confirm(replication_stop_send)" />
210                 <%
211                         break;
212                 case SLAVE:
213                 %>
214                         <input type="submit" name="button" value="<%=ButtonMode.REP_SLAVE_STOPPING %>" onClick="return confirm(replication_stop_receive)" />
215                 <%
216                         break;
217                 case MASTER_STOP:
218                 %>
219                         <input type="submit" name="button" value="<%=ButtonMode.REP_MASTER_RUNNING %>" onClick="return confirm(replication_start_send)" />                      
220                 <%
221                         break;
222                 case SLAVE_STOP:
223                         %>
224                         <input type="submit" name="button" value="<%=ButtonMode.REP_SLAVE_RUNNING %>" onClick="return confirm(replication_start_receive)" />    
225                 <%
226                         break;
227                 }
228                 %>
229                 </form>
230
231                 
232                 <%
233                 if ( repStatus != ReplicationStatus.SINGLE ){
234                 %>
235                         <form method="post" action="replication_modify.jsp" name="rep_info">
236                         <h2> Replication Configuration Information</h2>
237                         <fieldset>
238                         <legend>Replication Configuration Information</legend>          
239                                 <table class="infotable" cellspacing="0">
240                                 <thead>
241                                 <tr>
242                                         <th>Self Node</th><th colspan="2">Peer Node</th><th rowspan="2">Interval</th>
243                                 </tr>
244                                 <tr>
245                                         <th>NIC</th><th>IP Address</th><th>Port Number</th>
246                                 </tr>
247                                 </thead>
248                                 <tbody>
249                                 <tr>
250                                         <td class="center"><%=selfNic %></td>
251                                         <td class="center"><%=peerIp %></td>
252                                         <td class="center"><%=rep.otherNode.port %></td>
253                                         <td class="center"><%=rep.interval %> [&#181;sec]</td>
254                                 </tr>
255                                 </tbody>
256                                 </table>
257                         </fieldset>
258                         <h4>If you would like to modify Interval, push the following button.</h4>
259                         <br />          
260                         <input type="submit" value="Modify" />
261                         </form>
262         
263                         <% if (keys != null) {%>
264                         <h2> Replication Data Size Information</h2>
265                         <fieldset>
266                         <legend>Replication Data Size Information</legend>              
267                                 <table class="infotable" cellspacing="0">
268                                 <tr>
269                                 <%
270                                 for (Iterator iterator = keys.iterator(); iterator.hasNext();){
271                                 %>      
272                                         <th><%=iterator.next() %></th>
273                                 <%
274                                 }
275                                 %>
276                                 </tr>
277                                 <tr>
278                                 <%
279                                 for (Iterator iterator = keys.iterator(); iterator.hasNext();){
280                                         String key = (String)iterator.next();
281                                         double size = ((Integer)repDatainfo.get(key)) * 480;
282                                         String sizeUnit = "[byte]";
283                                         if ( (size  >= 1000)  && ( size < 1000000 )){
284                                                 size = size / 1000 ;
285                                                 sizeUnit = "[Kbyte]";
286                                         }
287                                         else if( size >= 1000000 ){
288                                                 size = size / 1000000 ;
289                                                 sizeUnit = "[Mbyte]";
290                                         }
291                                         out.println("<td class=\"center\">" + size + "" + sizeUnit + "</td>");
292                                 }
293                                 %>
294                                 </tr>
295                                 </table>
296                         </fieldset>
297                                         
298                         <%
299                                 if ( repStatus == ReplicationStatus.MASTER ){
300                         %>      
301                         <h2> Immediate Replication</h2>         
302                         <form method="post" action="ReplicationRunServlet" name="rep" > 
303                         <h4>If you would like to execute immediate Replication, push the following button.</h4>
304                         <br />
305                         <input type="submit" name="button_immediate" value="<%=ButtonMode.REP_EXECUTE%>" onClick="return confirm(replication_dump)" />  
306                         </form>
307                         <%
308                         }
309                 }
310                 }
311                 %>
312
313         </div>
314         </body>
315 </html>