Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
datasid
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
simmctic
datasid
Commits
fc129249
Commit
fc129249
authored
11 years ago
by
Eduardo L. Buratti
Browse files
Options
Downloads
Patches
Plain Diff
webservice: Adapt webservice to modification in database and agent
Signed-off-by:
Eduardo L. Buratti
<
elb09@c3sl.ufpr.br
>
parent
f50b6e9c
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
webservice/DataSID.java
+35
-79
35 additions, 79 deletions
webservice/DataSID.java
webservice/collected-data.xsd
+1
-12
1 addition, 12 deletions
webservice/collected-data.xsd
webservice/net-collected-data.xsd
+1
-1
1 addition, 1 deletion
webservice/net-collected-data.xsd
with
37 additions
and
92 deletions
webservice/DataSID.java
+
35
−
79
View file @
fc129249
...
...
@@ -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
().
get
Superid
();
/*
List<User> users = collected.getUserHistory().getUser();
String superid = collected.getTelecentroInfo().get
IdPoint
();
*/
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
().
get
Superid
()
+
", macaddr="
+
interfaces
.
get
(
0
).
getMacAddress
()
+
")"
);
log
(
INFO
,
"setInventory(
id_point
="
+
collected
.
getTelecentroInfo
().
get
IdPoint
()
+
", 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
.
set
String
(
3
,
teleCentroInfo
.
get
Superid
());
//
id_point
st
.
set
Int
(
3
,
teleCentroInfo
.
get
IdPoint
().
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
);
// vers
ao
//
agent_
vers
ion
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
.
set
String
(
2
,
m_superid
);
st
.
set
Int
(
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
.
get
TelecentroId
()
+
", macaddr="
+
interfaces
.
get
(
0
).
getMacAddress
()
+
")"
);
log
(
DEBUG
,
"setNetUsage(
id_point
="
+
netCollectedData
.
get
IdPoint
()
+
", 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
.
set
String
(
2
,
m_superid
);
st
.
set
Int
(
2
,
id_point
.
intValue
()
);
st
.
setObject
(
3
,
macaddr
);
...
...
This diff is collapsed.
Click to expand it.
webservice/collected-data.xsd
+
1
−
12
View file @
fc129249
...
...
@@ -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>
...
...
This diff is collapsed.
Click to expand it.
webservice/net-collected-data.xsd
+
1
−
1
View file @
fc129249
...
...
@@ -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>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment