Skip to content
Snippets Groups Projects
Commit fc129249 authored by Eduardo L. Buratti's avatar Eduardo L. Buratti
Browse files

webservice: Adapt webservice to modification in database and agent

parent f50b6e9c
No related branches found
No related tags found
No related merge requests found
......@@ -47,7 +47,7 @@ public class DataSID {
private static final int WINDOWS = 1;
private static final String SA_INVENTORY = "telecenter_inventory";
private static final String SA_NET_USAGE = "telecenter_net_usage";
private static final String SA_NET_USAGE = "net_usage";
private static final String SA_USER_HISTORY = "telecenter_user_history";
private static final File XML_INVENTORY_SCHEMA = new File("/home/datasid/conf/collected-data.xsd");
......@@ -175,14 +175,14 @@ public class DataSID {
*/
public static String setInventory(String xmlData) {
try {
/*InitialContext cxt = new InitialContext();
InitialContext cxt = new InitialContext();
DataSource ds = (DataSource) cxt.lookup("java:/comp/env/jdbc/datasid");
if (ds == null)
throw new Exception("Data source not found!");
Connection con = ds.getConnection();
if (con == null)
throw new Exception("Failed to get a database connection!");*/
throw new Exception("Failed to get a database connection!");
SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
Schema schema = factory.newSchema(XML_INVENTORY_SCHEMA);
......@@ -204,24 +204,24 @@ public class DataSID {
Calendar cal = Calendar.getInstance();
java.sql.Date contactDate = new java.sql.Date(cal.getTimeInMillis());
/*PreparedStatement st = createInventoryStatement(con, collected, contactDate);
st.executeUpdate();*/
PreparedStatement st = createInventoryStatement(con, collected, contactDate);
st.executeUpdate();
List<User> users = collected.getUserHistory().getUser();
String superid = collected.getTelecentroInfo().getSuperid();
/*List<User> users = collected.getUserHistory().getUser();
String superid = collected.getTelecentroInfo().getIdPoint();*/
List<Interface> interfaces = collected.getInterfaces().getInterface();
org.postgresql.util.PGobject macaddr = new org.postgresql.util.PGobject();
macaddr.setType("macaddr");
macaddr.setValue(interfaces.get(0).getMacAddress());
for(User user: users) {
/*st = createUserHistoryStatement(con, contactDate, superid, macaddr, user.getName(), user.getLogin(), user.getLogout());
st.executeUpdate();*/
}
/*for (User user: users) {
st = createUserHistoryStatement(con, contactDate, superid, macaddr, user.getName(), user.getLogin(), user.getLogout());
st.executeUpdate();
}*/
//con.close();
con.close();
log(INFO, "setInventory(superid=" + collected.getTelecentroInfo().getSuperid() + ", macaddr=" + interfaces.get(0).getMacAddress() + ")");
log(INFO, "setInventory(id_point=" + collected.getTelecentroInfo().getIdPoint() + ", macaddr=" + interfaces.get(0).getMacAddress() + ")");
return "Success";
} catch (Exception e) {
log(ERROR, e.getMessage() + " " + xmlData);
......@@ -232,15 +232,13 @@ public class DataSID {
private static PreparedStatement createInventoryStatement(Connection con, CollectedData collectedData, java.sql.Date contactDate) throws SQLException {
final String query = "INSERT INTO " + SA_INVENTORY + " " +
"(contact_date, machine_type, m_superid, macaddr, version" +
"(contact_date, machine_type, id_point, macaddr, agent_version" +
" os_type, os_distro, os_kernel, " +
" processor, memory, " +
" disk1_model, disk1_size, disk1_used, " +
" disk2_model, disk2_size, disk2_used, " +
" extra_hds, " +
" tl_name, tl_phone, tl_street, tl_numbr, " +
" tl_city, tl_zipcode, tl_neighborhood, " +
" tl_geolocation, tl_admin_name, tl_admin_phone " +
" mirror_timestamp, " +
") VALUES " +
"(?, ?, ?, ?, ?, " +
" ?, ?, ?, " +
......@@ -248,9 +246,7 @@ public class DataSID {
" ?, ?, ?, " +
" ?, ?, ?, " +
" ?, " +
" ?, ?, ?, ?, " +
" ?, ?, ?, " +
" ?, ?, ?);";
" ?);";
PreparedStatement st = con.prepareStatement(query);
......@@ -269,8 +265,8 @@ public class DataSID {
else
st.setInt(2, 1);
// m_superid
st.setString(3, teleCentroInfo.getSuperid());
// id_point
st.setInt(3, teleCentroInfo.getIdPoint().intValue());
// macaddr
org.postgresql.util.PGobject macaddr = new org.postgresql.util.PGobject();
......@@ -278,7 +274,7 @@ public class DataSID {
macaddr.setValue(interfaces.get(0).getMacAddress());
st.setObject(4, macaddr);
// versao
// agent_version
st.setString(5, collectedData.getAgentVersion());
// os_type
......@@ -329,56 +325,17 @@ public class DataSID {
// extra_hds
st.setInt(17, (disks.size() > 2) ? (disks.size() - 2) : 0);
// tl_name
st.setString(18, teleCentroInfo.getTlName());
// tl_phone
st.setString(19, "???"); // TODO
// tl_street
st.setString(20, teleCentroInfo.getTlStreet());
// tl_numbr
st.setString(21, teleCentroInfo.getTlNumber());
//tl_city
st.setString(22, teleCentroInfo.getCity());
// state
//st.setString(???, teleCentroInfo.getState());
// tl_zipcode
st.setString(23, teleCentroInfo.getTlZipcode());
// tl_neighborhood
st.setString(24, teleCentroInfo.getTlNeighborhood());
// tl_geolocation
st.setString(25, teleCentroInfo.getGeolocation());
// tl_admin_name
st.setString(26, teleCentroInfo.getAdminName());
// tl_admin_phone
st.setString(27, "???"); // TODO
// tl_conection
//st.setString(???, teleCentroInfo.getTlConnection());
// tl_beneficiary
//st.setString(???, teleCentroInfo.getTlBeneficiary());
// mirrors_timestamp
st.setString(18, collectedData.getMirrorsTimestamp());
// user_count
//st.setInt(???, teleCentroInfo.getUserCount().intValue());
// mirrors_timestamp
//st.setString(???, collectedData.getMirrorsTimestamp());
return st;
}
private static PreparedStatement createUserHistoryStatement(Connection con, java.sql.Date contactDate,
String m_superid, Object macaddr, String name, String login, String logout) throws SQLException {
int id_point, Object macaddr, String name, String login, String logout) throws SQLException {
final String query = "INSERT INTO " + SA_USER_HISTORY + " " +
"(contact_date, m_superid, macaddr, name, login, logout) VALUES " +
"(?, ?, ?, ?, ?, ?);";
......@@ -386,8 +343,8 @@ public class DataSID {
PreparedStatement st = con.prepareStatement(query);
st.setDate(1, contactDate);
// m_superid = telecentro-id
st.setString(2, m_superid);
st.setInt(2, id_point);
st.setObject(3, macaddr);
......@@ -412,14 +369,14 @@ public class DataSID {
public static String setNetUsage(String xmlData)
{
try {
/*InitialContext cxt = new InitialContext();
InitialContext cxt = new InitialContext();
DataSource ds = (DataSource) cxt.lookup("java:/comp/env/jdbc/datasid");
if (ds == null)
throw new Exception("Data source not found!");
Connection con = ds.getConnection();
if (con == null)
throw new Exception("Failed to get a database connection!");*/
throw new Exception("Failed to get a database connection!");
SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
Schema schema = factory.newSchema(XML_NET_USAGE_SCHEMA);
......@@ -451,13 +408,12 @@ public class DataSID {
List<NetUse> netUses = netCollectedData.getBandwidthUsage().getNetuse();
for(NetUse netUse : netUses) {
/*PreparedStatement st = createNetUsageStatement(con, contactDate, netCollectedData.getTelecentroId(), (Object)macaddr, netUse.getDate(), netUse.getTime(), netUse.getRx().getBytes(), netUse.getRx().getPackets(), netUse.getTx().getBytes(), netUse.getTx().getPackets());
st.executeUpdate();*/
PreparedStatement st = createNetUsageStatement(con, contactDate, netCollectedData.getIdPoint(), (Object)macaddr, netUse.getDate(), netUse.getTime(), netUse.getRx().getBytes(), netUse.getRx().getPackets(), netUse.getTx().getBytes(), netUse.getTx().getPackets());
st.executeUpdate();
}
//con.close();
con.close();
log(DEBUG, "setNetUsage(telecentro-id=" + netCollectedData.getTelecentroId() + ", macaddr=" + interfaces.get(0).getMacAddress() + ")");
log(DEBUG, "setNetUsage(id_point=" + netCollectedData.getIdPoint() + ", macaddr=" + interfaces.get(0).getMacAddress() + ")");
return "Success";
} catch (Exception e) {
log(ERROR, e.getMessage() + " " + xmlData);
......@@ -467,18 +423,18 @@ public class DataSID {
}
private static PreparedStatement createNetUsageStatement(Connection con, java.sql.Date contactDate,
String m_superid, Object macaddr, String collect_date, String collect_time, BigInteger down_kbits,
BigInteger id_point, Object macaddr, String collect_date, String collect_time, BigInteger down_kbits,
BigInteger down_packages, BigInteger up_kbits, BigInteger up_packages) throws SQLException {
final String query = "INSERT INTO " + SA_NET_USAGE + " " +
"(contact_date, m_superid, macaddr, collect_date, collect_time," +
"(contact_date, id_point, macaddr, collect_date, collect_time," +
"down_kbits, down_packages, up_kbits, up_packages) VALUES " +
"(?, ?, ?, ?, ?, ?, ?, ?, ?);";
PreparedStatement st = con.prepareStatement(query);
st.setDate(1, contactDate);
// m_superid = telecentro-id
st.setString(2, m_superid);
st.setInt(2, id_point.intValue());
st.setObject(3, macaddr);
......
......@@ -74,18 +74,7 @@
<xsd:complexType name="TeleCentroInfo">
<xsd:all>
<xsd:element name="admin_name" type="xsd:string" />
<xsd:element name="tl_connection" type="xsd:string" />
<xsd:element name="tl_name" type="xsd:string" />
<xsd:element name="state" type="xsd:string" />
<xsd:element name="city" type="xsd:string" />
<xsd:element name="tl_street" type="xsd:string" />
<xsd:element name="tl_number" type="xsd:string" />
<xsd:element name="tl_zipcode" type="xsd:string" />
<xsd:element name="tl_beneficiary" type="xsd:string" />
<xsd:element name="tl_neighborhood" type="xsd:string" />
<xsd:element name="geolocation" type="xsd:string" />
<xsd:element name="superid" type="xsd:string" />
<xsd:element name="id_point" type="xsd:integer" />
<xsd:element name="user_count" type="xsd:integer" />
</xsd:all>
</xsd:complexType>
......
......@@ -5,7 +5,7 @@
<xsd:complexType name="NetCollectedData">
<xsd:all>
<xsd:element name="agent-version" type="xsd:string" minOccurs="1" />
<xsd:element name="telecentro-id" type="xsd:string" minOccurs="1" />
<xsd:element name="id_point" type="xsd:integer" minOccurs="1" />
<xsd:element name="interfaces" type="Interfaces" minOccurs="1" />
<xsd:element name="bandwidth-usage" type="BandwidthUsage" minOccurs="1" />
</xsd:all>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment