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
1b11643e
Commit
1b11643e
authored
11 years ago
by
Eduardo L. Buratti
Browse files
Options
Downloads
Patches
Plain Diff
webservice: Fix field names in SQL queries and XML schema
Signed-off-by:
Eduardo L. Buratti
<
elb09@c3sl.ufpr.br
>
parent
8a9d1b9f
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
webservice/DataSID.java
+35
-71
35 additions, 71 deletions
webservice/DataSID.java
webservice/collected-data.xsd
+2
-13
2 additions, 13 deletions
webservice/collected-data.xsd
webservice/net-collected-data.xsd
+1
-1
1 addition, 1 deletion
webservice/net-collected-data.xsd
with
38 additions
and
85 deletions
webservice/DataSID.java
+
35
−
71
View file @
1b11643e
...
...
@@ -39,6 +39,7 @@ import javax.xml.bind.util.ValidationEventCollector;
import
javax.xml.bind.helpers.DefaultValidationEventHandler
;
import
javax.xml.validation.Schema
;
import
javax.xml.validation.SchemaFactory
;
import
javax.xml.transform.stream.StreamSource
;
public
class
DataSID
{
...
...
@@ -176,7 +177,7 @@ public class DataSID {
public
static
String
setInventory
(
String
xmlData
)
{
try
{
InitialContext
cxt
=
new
InitialContext
();
DataSource
ds
=
(
DataSource
)
cxt
.
lookup
(
"java:/comp/env/jdbc/
datasid
"
);
DataSource
ds
=
(
DataSource
)
cxt
.
lookup
(
"java:/comp/env/jdbc/
simmc
"
);
if
(
ds
==
null
)
throw
new
Exception
(
"Data source not found!"
);
...
...
@@ -187,7 +188,7 @@ public class DataSID {
SchemaFactory
factory
=
SchemaFactory
.
newInstance
(
"http://www.w3.org/2001/XMLSchema"
);
Schema
schema
=
factory
.
newSchema
(
XML_INVENTORY_SCHEMA
);
JAXBContext
context
=
JAXBContext
.
newInstance
(
"br.ufpr.c3sl.datasid"
);
JAXBContext
context
=
JAXBContext
.
newInstance
(
CollectedData
.
class
);
Unmarshaller
unmarshaller
=
context
.
createUnmarshaller
();
unmarshaller
.
setSchema
(
schema
);
...
...
@@ -198,7 +199,7 @@ public class DataSID {
InputStream
is
=
new
ByteArrayInputStream
(
xmlData
.
getBytes
());
// Decode the XML into a Java Object
JAXBElement
<
CollectedData
>
element
=
(
JAXBElement
<
CollectedData
>)
unmarshaller
.
unmarshal
(
i
s
);
JAXBElement
<
CollectedData
>
element
=
(
JAXBElement
<
CollectedData
>)
unmarshaller
.
unmarshal
(
new
StreamSource
(
is
),
CollectedData
.
clas
s
);
CollectedData
collected
=
element
.
getValue
();
// contact_date = current date
Calendar
cal
=
Calendar
.
getInstance
();
...
...
@@ -207,8 +208,8 @@ public class DataSID {
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().getSuperid();
*/
List
<
Interface
>
interfaces
=
collected
.
getInterfaces
().
getInterface
();
org
.
postgresql
.
util
.
PGobject
macaddr
=
new
org
.
postgresql
.
util
.
PGobject
();
macaddr
.
setType
(
"macaddr"
);
...
...
@@ -220,6 +221,7 @@ public class DataSID {
}
con
.
close
();
log
(
INFO
,
"setInventory(superid="
+
collected
.
getTelecentroInfo
().
getSuperid
()
+
", macaddr="
+
interfaces
.
get
(
0
).
getMacAddress
()
+
")"
);
return
"Success"
;
}
catch
(
Exception
e
)
{
log
(
ERROR
,
e
.
getMessage
()
+
" "
+
xmlData
);
...
...
@@ -230,25 +232,20 @@ 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 "
+
" extra_hds "
+
") VALUES "
+
"(?, ?, ?, ?, ?, "
+
" ?, ?, ?, "
+
" ?, ?, "
+
" ?, ?, ?, "
+
" ?, ?, ?, "
+
" ?, "
+
" ?, ?, ?, ?, "
+
" ?, ?, ?, "
+
" ?, ?, ?);"
;
" ? "
+
" );"
;
PreparedStatement
st
=
con
.
prepareStatement
(
query
);
...
...
@@ -267,8 +264,8 @@ public class DataSID {
else
st
.
setInt
(
2
,
1
);
//
m_
superid
st
.
set
String
(
3
,
teleCentroInfo
.
getSuperid
());
// superid
st
.
set
Int
(
3
,
teleCentroInfo
.
getSuperid
()
.
intValue
()
);
// macaddr
org
.
postgresql
.
util
.
PGobject
macaddr
=
new
org
.
postgresql
.
util
.
PGobject
();
...
...
@@ -327,44 +324,8 @@ 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());
...
...
@@ -374,8 +335,9 @@ public class DataSID {
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
{
private
static
PreparedStatement
createUserHistoryStatement
(
Connection
con
,
java
.
sql
.
Date
contactDate
,
int
superid
,
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 "
+
"(?, ?, ?, ?, ?, ?);"
;
...
...
@@ -383,9 +345,9 @@ 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
,
superid
);
st
.
setObject
(
3
,
macaddr
);
st
.
setString
(
4
,
name
);
...
...
@@ -410,7 +372,7 @@ public class DataSID {
{
try
{
InitialContext
cxt
=
new
InitialContext
();
DataSource
ds
=
(
DataSource
)
cxt
.
lookup
(
"java:/comp/env/jdbc/
datasid
"
);
DataSource
ds
=
(
DataSource
)
cxt
.
lookup
(
"java:/comp/env/jdbc/
simmc
"
);
if
(
ds
==
null
)
throw
new
Exception
(
"Data source not found!"
);
...
...
@@ -421,7 +383,7 @@ public class DataSID {
SchemaFactory
factory
=
SchemaFactory
.
newInstance
(
"http://www.w3.org/2001/XMLSchema"
);
Schema
schema
=
factory
.
newSchema
(
XML_NET_USAGE_SCHEMA
);
JAXBContext
context
=
JAXBContext
.
newInstance
(
"br.ufpr.c3sl.datasid"
);
JAXBContext
context
=
JAXBContext
.
newInstance
(
NetCollectedData
.
class
);
Unmarshaller
unmarshaller
=
context
.
createUnmarshaller
();
unmarshaller
.
setSchema
(
schema
);
...
...
@@ -432,7 +394,7 @@ public class DataSID {
InputStream
is
=
new
ByteArrayInputStream
(
xmlData
.
getBytes
());
// Decode the XML into a Java Object
JAXBElement
<
NetCollectedData
>
element
=
(
JAXBElement
<
NetCollectedData
>)
unmarshaller
.
unmarshal
(
i
s
);
JAXBElement
<
NetCollectedData
>
element
=
(
JAXBElement
<
NetCollectedData
>)
unmarshaller
.
unmarshal
(
new
StreamSource
(
is
),
NetCollectedData
.
clas
s
);
NetCollectedData
netCollectedData
=
element
.
getValue
();
List
<
Interface
>
interfaces
=
netCollectedData
.
getInterfaces
().
getInterface
();
...
...
@@ -448,12 +410,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
.
getSuperid
(),
(
Object
)
macaddr
,
netUse
.
getDate
(),
netUse
.
getTime
(),
netUse
.
getRx
().
getBytes
(),
netUse
.
getRx
().
getPackets
(),
netUse
.
getTx
().
getBytes
(),
netUse
.
getTx
().
getPackets
());
st
.
executeUpdate
();
}
con
.
close
();
log
(
DEBUG
,
"setNetUsage(superid="
+
netCollectedData
.
getSuperid
()
+
", macaddr="
+
interfaces
.
get
(
0
).
getMacAddress
()
+
")"
);
return
"Success"
;
}
catch
(
Exception
e
)
{
log
(
ERROR
,
e
.
getMessage
()
+
" "
+
xmlData
);
...
...
@@ -461,19 +423,21 @@ public class DataSID {
return
"ERROR: "
+
e
.
getMessage
();
}
}
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
down_packages
,
BigInteger
up_kbits
,
BigInteger
up_packages
)
throws
SQLException
{
private
static
PreparedStatement
createNetUsageStatement
(
Connection
con
,
java
.
sql
.
Date
contactDate
,
BigInteger
superid
,
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
,
superid
.
intValue
()
);
st
.
setObject
(
3
,
macaddr
);
st
.
setString
(
4
,
collect_date
);
...
...
This diff is collapsed.
Click to expand it.
webservice/collected-data.xsd
+
2
−
13
View file @
1b11643e
...
...
@@ -71,21 +71,10 @@
<xsd:element
name=
"logout"
type=
"xsd:string"
/>
</xsd:all>
</xsd:complexType>
<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=
"superid"
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 @
1b11643e
...
...
@@ -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=
"telecentro-id"
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