Commit c4b393bd877641da4cdb64aab64673fdd1fd7dfe

Authored by Paul Brodner
1 parent 6c7a449a87
Exists in master

add version

src/main/java/org/alfresco/tasenvironment/models/Environment.java
1 package org.alfresco.tasenvironment.models; 1 package org.alfresco.tasenvironment.models;
2 2
3 import org.alfresco.utility.network.ServerHealth; 3 import org.alfresco.utility.network.ServerHealth;
4 import org.alfresco.utility.network.TenantConsole; 4 import org.alfresco.utility.network.TenantConsole;
5 import org.apache.commons.httpclient.HttpClient;
6 import org.apache.commons.httpclient.methods.GetMethod;
7 import org.apache.commons.io.IOUtils;
5 import org.springframework.data.annotation.Id; 8 import org.springframework.data.annotation.Id;
6 import org.springframework.data.annotation.PersistenceConstructor; 9 import org.springframework.data.annotation.PersistenceConstructor;
7 import org.springframework.data.mongodb.core.mapping.Document; 10 import org.springframework.data.mongodb.core.mapping.Document;
8 11
9 /** 12 /**
10 * @author pbrodner 13 * @author pbrodner
11 */ 14 */
12 @Document(collection = "environments") 15 @Document(collection = "environments")
13 public class Environment 16 public class Environment
14 { 17 {
15 18
16 @Id 19 @Id
17 private String id; 20 private String id;
18 21
19 private String name; 22 private String name;
20 private String ip; 23 private String ip;
21 private String port; 24 private String port;
22 25
23 @PersistenceConstructor 26 @PersistenceConstructor
24 public Environment(String name, String ip, String port) 27 public Environment(String name, String ip, String port)
25 { 28 {
26 setName(name); 29 setName(name);
27 setIp(ip); 30 setIp(ip);
28 setPort(port); 31 setPort(port);
29 } 32 }
30 33
31 public String getName() 34 public String getName()
32 { 35 {
33 return name; 36 return name;
34 } 37 }
35 38
36 public void setName(String name) 39 public void setName(String name)
37 { 40 {
38 this.name = name; 41 this.name = name;
39 } 42 }
40 43
41 public String getIp() 44 public String getIp()
42 { 45 {
43 return ip; 46 return ip;
44 } 47 }
45 48
46 public void setIp(String ip) 49 public void setIp(String ip)
47 { 50 {
48 this.ip = ip; 51 this.ip = ip;
49 } 52 }
50 53
51 public String getPort() 54 public String getPort()
52 { 55 {
53 return port; 56 return port;
54 } 57 }
55 58
56 public void setPort(String port) 59 public void setPort(String port)
57 { 60 {
58 this.port = port; 61 this.port = port;
59 } 62 }
60 63
61 public void setId(String id) 64 public void setId(String id)
62 { 65 {
63 this.id = id; 66 this.id = id;
64 } 67 }
65 68
66 public String getId() 69 public String getId()
67 { 70 {
68 return id; 71 return id;
69 } 72 }
70 73
71 @Override 74 @Override
72 public String toString() 75 public String toString()
73 { 76 {
74 return String.format("Environment [id=%s, name=%s, ip=%s]", getId(), getName(), getId()); 77 return String.format("Environment [id=%s, name=%s, ip=%s]", getId(), getName(), getId());
75 } 78 }
76 79
77 public String getAlfrescoPath() 80 public String getAlfrescoPath()
78 { 81 {
79 return String.format("http://%s:%s/alfresco", getIp(), getPort()); 82 return String.format("http://%s:%s/alfresco", getIp(), getPort());
80 } 83 }
81 84
82 public String getSharePath() 85 public String getSharePath()
83 { 86 {
84 return String.format("http://%s:%s/share", getIp(), getPort()); 87 return String.format("http://%s:%s/share", getIp(), getPort());
85 } 88 }
86 89
87 public String getStatus() 90 public String getStatus()
88 { 91 {
89 ServerHealth serverHealth = new ServerHealth(); 92 ServerHealth serverHealth = new ServerHealth();
90 93
91 boolean isOnline = false; 94 boolean isOnline = false;
92 try 95 try
93 { 96 {
94 isOnline = serverHealth.isServerReachable(getIp(), Integer.valueOf(getPort())); 97 isOnline = serverHealth.isServerReachable(getIp(), Integer.valueOf(getPort()));
95 } 98 }
96 catch (Exception e) 99 catch (Exception e)
97 { 100 {
98 e.printStackTrace(); 101 e.printStackTrace();
99 } 102 }
100 103
101 if (isOnline) 104 if (isOnline)
102 return getOnlineIcon(); 105 return getOnlineIcon();
103 else 106 else
104 return getOfflineIcon(); 107 return getOfflineIcon();
105 } 108 }
106 109
107 public String getOnlineIcon() 110 public String getOnlineIcon()
108 { 111 {
109 return "<span class=\"label label-success\"> Online</span>"; 112 return "<span class=\"label label-success\"> Online</span>";
110 } 113 }
111 114
112 public String getOfflineIcon() 115 public String getOfflineIcon()
113 { 116 {
114 return "<span class=\"label label-danger\"> Offline</span>"; 117 return "<span class=\"label label-danger\"> Offline</span>";
115 } 118 }
116 119
117 public String getTenant() 120 public String getTenant()
118 { 121 {
119 TenantConsole tenantConsole = new TenantConsole(); 122 TenantConsole tenantConsole = new TenantConsole();
120 try 123 try
121 { 124 {
122 if (tenantConsole.tenantExist("http", getIp(), Integer.valueOf(getPort()), "admin", "admin")) 125 if (tenantConsole.tenantExist("http", getIp(), Integer.valueOf(getPort()), "admin", "admin"))
123 return "<span class=\"label label-danger\"> Yes</span>"; 126 return "<span class=\"label label-danger\"> Yes</span>";
124 else 127 else
125 return "<span class=\"label label-success\">No</span>"; 128 return "<span class=\"label label-success\">No</span>";
126 } 129 }
127 catch (Exception e) 130 catch (Exception e)
128 { 131 {
129 return "<span class=\"label label-success\">No</span>"; 132 return "<span class=\"label label-success\">No</span>";
130 } 133 }
131 } 134 }
135
136 public String getVersion()
137 {
138 HttpClient client = new HttpClient();
139 GetMethod get = new GetMethod("http://"+ getIp() + "/alfresco/service/api/server");
140 String version = "Unknown";
141 get.getParams().setSoTimeout(5000);
142 try
143 {
144 client.executeMethod(get);
145 version = IOUtils.toString(get.getResponseBodyAsStream());
146 }
147 catch (Exception e)
148 {
149 }
150
151 return version ;
152 }
132 } 153 }
src/main/resources/spark/template/freemarker/environment/index.ftl
1 <a href="/environment/new" data-toggle="tooltip" title="Add a new Environment!">Add New</a> 1 <a href="/environment/new" data-toggle="tooltip" title="Add a new Environment!">Add New</a>
2 <table class="table table-striped table-bordered table-condensed"> 2 <table class="table table-striped table-bordered table-condensed">
3 <thead> 3 <thead>
4 <tr> 4 <tr>
5 <th>Name</th> 5 <th>Name</th>
6 <th>IP</th> 6 <th>IP</th>
7 <th>Alfresco Path</th> 7 <th>Alfresco Path</th>
8 <th>Status</th> 8 <th>Status</th>
9 <th>With Tenant</th> 9 <th>With Tenant</th>
10 <th>Version</th>
10 <th></th> 11 <th></th>
11 </tr> 12 </tr>
12 </thead> 13 </thead>
13 <tbody> 14 <tbody>
14 <#list environments as env> 15 <#list environments as env>
15 <tr> 16 <tr>
16 <td>${env.getName()}</td> 17 <td>${env.getName()}</td>
17 <td>${env.getIp()}</td> 18 <td>${env.getIp()}</td>
18 <td><a href="${env.getAlfrescoPath()}" target="_blank">${env.getAlfrescoPath()}</a></td> 19 <td><a href="${env.getAlfrescoPath()}" target="_blank">${env.getAlfrescoPath()}</a></td>
19 <td align="center">${env.getStatus()}</td> 20 <td align="center">${env.getStatus()}</td>
20 <td align="center">${env.getTenant()}</td> 21 <td align="center">${env.getTenant()}</td>
22 <td><pre>${env.getVersion()}</pre></td>
21 <td> 23 <td>
22 <form method="DELETE" action="/environment/delete/${env.getId()}"> 24 <form method="DELETE" action="/environment/delete/${env.getId()}">
23 <button type="submit" class="btn btn-small">Delete</button> 25 <button type="submit" class="btn btn-small">Delete</button>
24 </form> 26 </form>
25 </td> 27 </td>
26 </tr> 28 </tr>
27 </#list> 29 </#list>
28 </tbody> 30 </tbody>
29 </table> 31 </table>
30 32