Skip to content

Commit f3e92c8

Browse files
committed
Merge branch 'UserInfo'
2 parents f2c7b03 + 998e577 commit f3e92c8

33 files changed

+2582
-2205
lines changed

pom.xml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>ch.cern</groupId>
66
<artifactId>DBOnDemand</artifactId>
7-
<version>5.4.3</version>
7+
<version>5.5.0</version>
88
<packaging>war</packaging>
99

1010
<name>DBOnDemand</name>
@@ -48,6 +48,16 @@
4848
</repositories>
4949

5050
<dependencies>
51+
<dependency>
52+
<groupId>org.json</groupId>
53+
<artifactId>json</artifactId>
54+
<version>20150729</version>
55+
</dependency>
56+
<dependency>
57+
<groupId>com.google.code.gson</groupId>
58+
<artifactId>gson</artifactId>
59+
<version>2.4</version>
60+
</dependency>
5161
<dependency>
5262
<groupId>javax</groupId>
5363
<artifactId>javaee-web-api</artifactId>
@@ -107,23 +117,20 @@
107117
<version>${log4j.version}</version>
108118
</dependency>
109119
<dependency>
110-
<groupId>org.slf4j</groupId>
111-
<artifactId>slf4j-simple</artifactId>
112-
<version>1.6.4</version>
120+
<groupId>org.slf4j</groupId>
121+
<artifactId>slf4j-simple</artifactId>
122+
<version>1.6.4</version>
113123
</dependency>
114-
115124
<dependency>
116-
<groupId>org.slf4j</groupId>
117-
<artifactId>slf4j-api</artifactId>
118-
<version>1.7.5</version>
125+
<groupId>org.slf4j</groupId>
126+
<artifactId>slf4j-api</artifactId>
127+
<version>1.7.5</version>
119128
</dependency>
120-
121129
<dependency>
122130
<groupId>com.google.visualization</groupId>
123131
<artifactId>visualization-datasource</artifactId>
124132
<version>${google-visualization.version}</version>
125133
</dependency>
126-
127134
<dependency>
128135
<groupId>commons-httpclient</groupId>
129136
<artifactId>commons-httpclient</artifactId>

src/main/java/ch/cern/dbod/appservlet/ConfigLoader.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ public static String getDBTuna4PgPath()
5555
return propertiesFile.getProperty("appdynn_dbtuna4pg_path");
5656
}
5757

58+
public static String getRestApiPath()
59+
{
60+
return propertiesFile.getProperty("restapi_path");
61+
}
62+
5863
private static Properties init()
5964
{
6065
Properties prop = new Properties();

src/main/java/ch/cern/dbod/db/dao/InstanceDAO.java

Lines changed: 37 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
package ch.cern.dbod.db.dao;
1111

12+
import ch.cern.dbod.util.RestHelper;
1213
import ch.cern.dbod.db.entity.Instance;
1314
import ch.cern.dbod.db.entity.InstanceChange;
1415
import ch.cern.dbod.db.entity.Upgrade;
@@ -19,9 +20,7 @@
1920
import java.sql.SQLException;
2021
import java.text.DateFormat;
2122
import java.text.SimpleDateFormat;
22-
import java.util.ArrayList;
23-
import java.util.List;
24-
import java.util.StringTokenizer;
23+
import java.util.*;
2524
import java.util.logging.Level;
2625
import java.util.logging.Logger;
2726
import javax.naming.Context;
@@ -32,6 +31,7 @@
3231
/**
3332
* DAO for Instance entity.
3433
* @author Daniel Gomez Blanco
34+
* @author Jose Andres Cordero Benitez
3535
*/
3636
public class InstanceDAO {
3737

@@ -55,72 +55,29 @@ private Connection getConnection() throws NamingException, SQLException {
5555
* @return List of all the instances in the database.
5656
*/
5757
public List<Instance> selectAll(List<Upgrade> upgrades) {
58-
Connection connection = null;
59-
PreparedStatement statement = null;
60-
ResultSet result = null;
61-
ArrayList<Instance> instances = new ArrayList<>();
62-
try {
63-
//Get connection
64-
connection = getConnection();
65-
66-
//Prepare query for the prepared statement (to avoid SQL injection)
67-
StringBuilder query = new StringBuilder();
68-
query.append("SELECT username, db_name, e_group, category, creation_date, expiry_date, db_type, db_size, no_connections, project, description, version, state, status, master, slave, host"
69-
+ " FROM dod_instances WHERE status = '1'"
70-
+ " ORDER BY db_name");
71-
statement = connection.prepareStatement(query.toString());
72-
73-
//Execute query
74-
result = statement.executeQuery();
75-
76-
//Instantiate instance objects
77-
while (result.next()) {
78-
Instance instance = new Instance();
79-
instance.setUsername(result.getString(1));
80-
instance.setDbName(result.getString(2));
81-
instance.setEGroup(result.getString(3));
82-
instance.setCategory(result.getString(4));
83-
instance.setCreationDate(new java.util.Date(result.getDate(5).getTime()));
84-
if (result.getDate(6) != null)
85-
instance.setExpiryDate(new java.util.Date(result.getDate(6).getTime()));
86-
instance.setDbType(result.getString(7));
87-
instance.setDbSize(result.getInt(8));
88-
instance.setNoConnections(result.getInt(9));
89-
instance.setProject(result.getString(10));
90-
instance.setDescription(result.getString(11));
91-
instance.setVersion(result.getString(12));
92-
instance.setState(result.getString(13));
93-
instance.setStatus(result.getBoolean(14));
94-
instance.setMaster(result.getString(15));
95-
instance.setSlave(result.getString(16));
96-
instance.setHost(result.getString(17));
97-
//Check if instance needs upgrade
98-
if (upgrades != null) {
99-
for (int i=0; i < upgrades.size(); i++) {
100-
Upgrade upgrade = upgrades.get(i);
58+
List<Instance> instances = new ArrayList<>();
59+
try
60+
{
61+
//Get database information from REST API
62+
Instance[] array = RestHelper.getObjectListFromRestApi("/entity/all/", Instance[].class);
63+
if (array != null)
64+
instances = Arrays.asList(array);
65+
66+
//Check if instance needs upgrade
67+
if (upgrades != null) {
68+
for (Instance instance : instances) {
69+
for (Upgrade upgrade : upgrades) {
10170
if (upgrade.getDbType().equals(instance.getDbType()) && upgrade.getCategory().equals(instance.getCategory())
102-
&& upgrade.getVersionFrom().equals(instance.getVersion()))
71+
&& upgrade.getVersionFrom().equals(instance.getVersion()))
10372
instance.setUpgradeTo(upgrade.getVersionTo());
10473
}
10574
}
106-
instances.add(instance);
107-
}
108-
} catch (NamingException | SQLException ex) {
109-
Logger.getLogger(InstanceDAO.class.getName()).log(Level.SEVERE, "ERROR SELECTING INSTANCES FOR ADMIN",ex);
110-
} finally {
111-
try {
112-
result.close();
113-
} catch (Exception e) {
114-
}
115-
try {
116-
statement.close();
117-
} catch (Exception e) {
118-
}
119-
try {
120-
connection.close();
121-
} catch (Exception e) {
12275
}
12376
}
77+
catch (Exception ex) {
78+
Logger.getLogger(InstanceDAO.class.getName()).log(Level.SEVERE, null, ex);
79+
}
80+
12481
return instances;
12582
}
12683

@@ -381,73 +338,27 @@ public List<Instance> selectInstancesPerHost(String host, List<Upgrade> upgrades
381338
* @return instance for the username and DB name specified.
382339
*/
383340
public Instance selectByDbName(String dbName, List<Upgrade> upgrades) {
384-
Connection connection = null;
385-
PreparedStatement statement = null;
386-
ResultSet result = null;
387341
Instance instance = null;
388-
try {
389-
//Get connection
390-
connection = getConnection();
391-
392-
//Prepare query for the prepared statement (to avoid SQL injection)
393-
StringBuilder query = new StringBuilder();
394-
query.append("SELECT username, db_name, e_group, category, creation_date, expiry_date, db_type, db_size, no_connections, project, description, version, state, status, master, slave, host"
395-
+ " FROM dod_instances WHERE db_name = ? AND status = '1'");
396-
statement = connection.prepareStatement(query.toString());
397-
398-
//Assign values to variables
399-
statement.setString(1, dbName);
400-
401-
//Execute query
402-
result = statement.executeQuery();
403-
404-
//Instantiate instance object
405-
if (result.next()) {
406-
instance = new Instance();
407-
instance.setUsername(result.getString(1));
408-
instance.setDbName(result.getString(2));
409-
instance.setEGroup(result.getString(3));
410-
instance.setCategory(result.getString(4));
411-
instance.setCreationDate(new java.util.Date(result.getDate(5).getTime()));
412-
if (result.getDate(6) != null)
413-
instance.setExpiryDate(new java.util.Date(result.getDate(6).getTime()));
414-
instance.setDbType(result.getString(7));
415-
instance.setDbSize(result.getInt(8));
416-
instance.setNoConnections(result.getInt(9));
417-
instance.setProject(result.getString(10));
418-
instance.setDescription(result.getString(11));
419-
instance.setVersion(result.getString(12));
420-
instance.setState(result.getString(13));
421-
instance.setStatus(result.getBoolean(14));
422-
instance.setMaster(result.getString(15));
423-
instance.setSlave(result.getString(16));
424-
instance.setHost(result.getString(17));
425-
//Check if instance needs upgrade
426-
if (upgrades != null) {
427-
for (int i=0; i < upgrades.size(); i++) {
428-
Upgrade upgrade = upgrades.get(i);
429-
if (upgrade.getDbType().equals(instance.getDbType()) && upgrade.getCategory().equals(instance.getCategory())
430-
&& upgrade.getVersionFrom().equals(instance.getVersion()))
431-
instance.setUpgradeTo(upgrade.getVersionTo());
432-
}
342+
343+
try
344+
{
345+
//Get database information from REST API
346+
instance = RestHelper.getObjectFromRestApi("/entity/" + dbName, Instance.class);
347+
348+
//Check if instance needs upgrade
349+
if (instance != null && upgrades != null) {
350+
for (int i=0; i < upgrades.size(); i++) {
351+
Upgrade upgrade = upgrades.get(i);
352+
if (upgrade.getDbType().equals(instance.getDbType()) && upgrade.getCategory().equals(instance.getCategory())
353+
&& upgrade.getVersionFrom().equals(instance.getVersion()))
354+
instance.setUpgradeTo(upgrade.getVersionTo());
433355
}
434356
}
435-
} catch (NamingException | SQLException ex) {
436-
Logger.getLogger(InstanceDAO.class.getName()).log(Level.SEVERE, "ERROR SELECTING INSTANCE FOR DB NAME " + dbName ,ex);
437-
} finally {
438-
try {
439-
result.close();
440-
} catch (Exception e) {
441-
}
442-
try {
443-
statement.close();
444-
} catch (Exception e) {
445-
}
446-
try {
447-
connection.close();
448-
} catch (Exception e) {
449-
}
450357
}
358+
catch (Exception ex) {
359+
Logger.getLogger(InstanceDAO.class.getName()).log(Level.SEVERE, null, ex);
360+
}
361+
451362
return instance;
452363
}
453364

0 commit comments

Comments
 (0)