-
Notifications
You must be signed in to change notification settings - Fork 16
/
EnvironmentModel.java
179 lines (162 loc) · 4.11 KB
/
EnvironmentModel.java
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import java.util.Map;
import java.sql.*;
import java.net.*;
import java.io.*;
public class EnvironmentModel
{
public static ResultSet getList(String search, String limit, String offset, String sortBy, String sort) throws SQLException
{
String strSQL = "SELECT CASE WHEN restart IS FALSE\n";
strSQL += " THEN '<a href=\"environment?action_type=' || name || '\">' || description || ' (Dynamic)</a>'\n";
strSQL += " ELSE name || ' (Re-run os_install.sh to change this value)'\n";
strSQL += "END as name,\n";
strSQL += "value\n";
strSQL += "FROM (SELECT name, name as description, value, restart FROM os.variables\n";
strSQL += "UNION\n";
strSQL += "SELECT 'Daemon' as name, 'Queue Daemon' as description,\n";
strSQL += "status as value,\n";
strSQL += "false as restart\n";
strSQL += "FROM os.osstatus\n";
strSQL += "UNION\n";
strSQL += "SELECT 'Agent' as name, 'Scheduler Daemon' as description,\n";
strSQL += "status as value,\n";
strSQL += "false as restart\n";
strSQL += "FROM os.agentstatus\n";
strSQL += ") as sub\n";
if (!search.equals(""))
{
strSQL += "WHERE LOWER(name) LIKE '%' || LOWER('" + search + "') || '%'\n";
strSQL += "OR LOWER(value) LIKE '%' || LOWER('" + search + "') || '%'\n";
}
sortBy = sortBy.toLowerCase();
if (sortBy.equals("name") || sortBy.equals("value") || sortBy.equals("restart"))
strSQL += "ORDER BY " + sortBy + " " + sort + "\n";
else
strSQL += "ORDER BY name asc\n";
if (!limit.equals(""))
strSQL += "LIMIT " + limit + " ";
if (!offset.equals(""))
strSQL += "OFFSET " + offset;
try
{
ResultSet rs = OutsourcerModel.getResults(strSQL);
return rs;
}
catch (SQLException ex)
{
throw new SQLException(ex.getMessage());
}
}
public static String getStatus() throws SQLException
{
String strSQL = "SELECT status FROM os.osstatus";
String status = "Down";
try
{
ResultSet rs = OutsourcerModel.getResults(strSQL);
while (rs.next())
{
status = rs.getString(1);
}
return status;
}
catch (SQLException ex)
{
throw new SQLException(ex.getMessage());
}
}
public static String getAgentStatus() throws SQLException
{
String strSQL = "SELECT status FROM os.agentstatus";
String status = "Down";
try
{
ResultSet rs = OutsourcerModel.getResults(strSQL);
while (rs.next())
{
status = rs.getString(1);
}
return status;
}
catch (SQLException ex)
{
throw new SQLException(ex.getMessage());
}
}
public static String getVariable(String name) throws SQLException
{
String strSQL = "SELECT value FROM os.variables WHERE name = '" + name + "'";
String value = "";
try
{
ResultSet rs = OutsourcerModel.getResults(strSQL);
while (rs.next())
{
value = rs.getString(1);
}
return value;
}
catch (SQLException ex)
{
throw new SQLException(ex.getMessage());
}
}
public static void setVariable(String name, String value) throws SQLException
{
name = OutsourcerModel.setSQLString(name);
value = OutsourcerModel.setSQLString(value);
String strSQL = "INSERT INTO os.ao_variables\n";
strSQL += "(name, value, restart)\n";
strSQL += "SELECT name, " + value + " as value, restart\n";
strSQL += "FROM os.variables\n";
strSQL += "WHERE name = " + name;
try
{
OutsourcerModel.updateTable(strSQL);
}
catch (SQLException ex)
{
throw new SQLException(ex.getMessage());
}
}
public static void setStatus(String status) throws SQLException
{
String strSQL = "";
if (status.equals("Down"))
{
strSQL = "SELECT * from os.osstart";
}
else if (status.equals("Up"))
{
strSQL = "SELECT * from os.osstop";
}
try
{
OutsourcerModel.getResults(strSQL);
}
catch (SQLException ex)
{
throw new SQLException(ex.getMessage());
}
}
public static void setAgentStatus(String status) throws SQLException
{
String strSQL = "";
if (status.equals("Down"))
{
strSQL = "SELECT * from os.agentstart";
}
else if (status.equals("Up"))
{
strSQL = "SELECT * from os.agentstop";
}
try
{
OutsourcerModel.getResults(strSQL);
}
catch (SQLException ex)
{
throw new SQLException(ex.getMessage());
}
}
}