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
5a83bed2
Commit
5a83bed2
authored
11 years ago
by
Diego Giovane Pasqualin
Browse files
Options
Downloads
Plain Diff
Merge branch 'feature/fix-net-usage-type-conversions' of /home/git/repositories/minicom/datasid
parents
86a6f498
42ce1377
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
webservice/DataSID.java
+58
-36
58 additions, 36 deletions
webservice/DataSID.java
webservice/webservice.properties
+8
-0
8 additions, 0 deletions
webservice/webservice.properties
with
66 additions
and
36 deletions
webservice/DataSID.java
+
58
−
36
View file @
5a83bed2
...
@@ -44,30 +44,52 @@ import javax.xml.validation.SchemaFactory;
...
@@ -44,30 +44,52 @@ import javax.xml.validation.SchemaFactory;
import
javax.xml.transform.stream.StreamSource
;
import
javax.xml.transform.stream.StreamSource
;
public
class
DataSID
{
public
class
DataSID
{
// enum does not work as expected inside an axis web service
// using simple constants instead
private
static
final
int
LINUX
=
0
;
private
static
final
int
LINUX
=
0
;
private
static
final
int
WINDOWS
=
1
;
private
static
final
int
WINDOWS
=
1
;
private
static
final
String
SA_INVENTORY
=
"telecenter_inventory"
;
private
static
final
String
SA_NET_USAGE
=
"net_usage"
;
private
static
final
String
SA_USER_HISTORY
=
"telecenter_user"
;
private
static
final
File
XML_INVENTORY_SCHEMA
=
new
File
(
"/home/datasid/conf/collected-data.xsd"
);
private
static
final
File
XML_NET_USAGE_SCHEMA
=
new
File
(
"/home/datasid/conf/net-collected-data.xsd"
);
private
static
final
String
AGENT_VERSION
=
"1.0.1"
;
private
static
final
String
AGENT_UPDATE_LINK
=
"http://bisimmcdev.c3sl.ufpr.br/download/datasid-1.0.1-update.run"
;
private
static
final
String
WINDOWS_AGENT_VERSION
=
"1.0.0"
;
private
static
final
String
WINDOWS_UPDATE_LINK
=
"http://bisimmcdev.c3sl.ufpr.br/download/datasid-1.0.0-update.exe"
;
// enum does not work as expected inside an axis web service
// using simple constants instead
private
static
final
int
ERROR
=
0
;
private
static
final
int
ERROR
=
0
;
private
static
final
int
WARNING
=
1
;
private
static
final
int
WARNING
=
1
;
private
static
final
int
INFO
=
2
;
private
static
final
int
INFO
=
2
;
private
static
final
int
DEBUG
=
3
;
private
static
final
int
DEBUG
=
3
;
private
Properties
prop
;
private
File
xml_inventory_schema
;
private
File
xml_net_usage_schema
;
private
String
linux_agent_version
;
private
String
linux_agent_update_link
;
private
String
windows_agent_version
;
private
String
windows_agent_update_link
;
public
DataSID
()
throws
IOException
{
try
{
this
.
prop
=
new
Properties
();
this
.
prop
.
load
(
new
FileInputStream
(
"../conf/webservice.properties"
));
}
catch
(
IOException
e
)
{
System
.
err
.
println
(
"Failed to load webservice.properties."
);
throw
e
;
}
this
.
xml_inventory_schema
=
new
File
(
this
.
prop
.
getProperty
(
"xml_inventory_schema"
,
"../conf/collected-data.xsd"
));
this
.
xml_net_usage_schema
=
new
File
(
this
.
prop
.
getProperty
(
"xml_net_usage_schema"
,
"../conf/net-collected-data.xsd"
));
this
.
linux_agent_version
=
this
.
prop
.
getProperty
(
"linux_agent_version"
,
"1.0.0"
);
this
.
linux_agent_update_link
=
this
.
prop
.
getProperty
(
"linux_agent_update_link"
,
"http://bisimmcdev.c3sl.ufpr.br/download/datasid-1.0.0-update.run"
);
this
.
windows_agent_version
=
this
.
prop
.
getProperty
(
"windows_agent_version"
,
"1.0.0"
);
this
.
windows_agent_update_link
=
this
.
prop
.
getProperty
(
"windows_agent_update_link"
,
"http://bisimmcdev.c3sl.ufpr.br/download/datasid-1.0.0-update.exe"
);
}
/**
/**
* Returns the name of the log level
* Returns the name of the log level
*
*
...
@@ -135,12 +157,12 @@ public class DataSID {
...
@@ -135,12 +157,12 @@ public class DataSID {
* @param OS Integer of OS Type
* @param OS Integer of OS Type
* @return String
* @return String
*/
*/
public
static
String
getAgentVersion
(
int
OS
)
{
public
String
getAgentVersion
(
int
OS
)
{
switch
(
OS
){
switch
(
OS
){
case
LINUX:
case
LINUX:
return
AGENT_VERSION
;
return
this
.
linux_agent_version
;
case
WINDOWS:
case
WINDOWS:
return
WINDOWS_AGENT_VERSION
;
return
this
.
windows_agent_version
;
default
:
default
:
return
"ERROR: invalid OS"
;
return
"ERROR: invalid OS"
;
}
}
...
@@ -155,13 +177,13 @@ public class DataSID {
...
@@ -155,13 +177,13 @@ public class DataSID {
* @param OS Integer of OS Type
* @param OS Integer of OS Type
* @return String
* @return String
*/
*/
public
static
String
getUpdateLink
(
int
OS
)
public
String
getUpdateLink
(
int
OS
)
{
{
switch
(
OS
){
switch
(
OS
){
case
LINUX:
case
LINUX:
return
AGENT_UPDATE_LINK
;
return
this
.
linux_agent_update_link
;
case
WINDOWS:
case
WINDOWS:
return
WINDOWS_UPDATE_LINK
;
return
this
.
windows_agent_update_link
;
default
:
default
:
return
"ERROR: invalid OS"
;
return
"ERROR: invalid OS"
;
}
}
...
@@ -176,7 +198,7 @@ public class DataSID {
...
@@ -176,7 +198,7 @@ public class DataSID {
* @param xmlData XML string of inventory
* @param xmlData XML string of inventory
* @return String
* @return String
*/
*/
public
static
String
setInventory
(
String
xmlData
)
{
public
String
setInventory
(
String
xmlData
)
{
try
{
try
{
InitialContext
cxt
=
new
InitialContext
();
InitialContext
cxt
=
new
InitialContext
();
DataSource
ds
=
(
DataSource
)
cxt
.
lookup
(
"java:/comp/env/jdbc/simmc"
);
DataSource
ds
=
(
DataSource
)
cxt
.
lookup
(
"java:/comp/env/jdbc/simmc"
);
...
@@ -188,7 +210,7 @@ public class DataSID {
...
@@ -188,7 +210,7 @@ public class DataSID {
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"
);
SchemaFactory
factory
=
SchemaFactory
.
newInstance
(
"http://www.w3.org/2001/XMLSchema"
);
Schema
schema
=
factory
.
newSchema
(
XML_INVENTORY_SCHEMA
);
Schema
schema
=
factory
.
newSchema
(
this
.
xml_inventory_schema
);
JAXBContext
context
=
JAXBContext
.
newInstance
(
CollectedData
.
class
);
JAXBContext
context
=
JAXBContext
.
newInstance
(
CollectedData
.
class
);
Unmarshaller
unmarshaller
=
context
.
createUnmarshaller
();
Unmarshaller
unmarshaller
=
context
.
createUnmarshaller
();
...
@@ -235,8 +257,8 @@ public class DataSID {
...
@@ -235,8 +257,8 @@ public class DataSID {
}
}
}
}
private
static
PreparedStatement
createInventoryStatement
(
Connection
con
,
CollectedData
collectedData
,
java
.
sql
.
Date
contactDate
)
throws
SQLException
,
ParseException
{
private
PreparedStatement
createInventoryStatement
(
Connection
con
,
CollectedData
collectedData
,
java
.
sql
.
Date
contactDate
)
throws
SQLException
,
ParseException
{
final
String
query
=
"INSERT INTO
"
+
SA_INVENTORY
+
"
"
+
final
String
query
=
"INSERT INTO
telecenter_inventory
"
+
"(contact_date, machine_type, id_point, macaddr, agent_version, "
+
"(contact_date, machine_type, id_point, macaddr, agent_version, "
+
" os_type, os_distro, os_kernel, "
+
" os_type, os_distro, os_kernel, "
+
" processor, memory, "
+
" processor, memory, "
+
...
@@ -345,9 +367,9 @@ public class DataSID {
...
@@ -345,9 +367,9 @@ public class DataSID {
return
st
;
return
st
;
}
}
private
static
PreparedStatement
createUserHistoryStatement
(
Connection
con
,
java
.
sql
.
Date
contactDate
,
private
PreparedStatement
createUserHistoryStatement
(
Connection
con
,
java
.
sql
.
Date
contactDate
,
int
id_point
,
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
+
"
"
+
final
String
query
=
"INSERT INTO
telecenter_user
"
+
"(contact_date, id_point, macaddr, name, login, logout) VALUES "
+
"(contact_date, id_point, macaddr, name, login, logout) VALUES "
+
"(?, ?, ?, ?, ?, ?);"
;
"(?, ?, ?, ?, ?, ?);"
;
...
@@ -385,7 +407,7 @@ public class DataSID {
...
@@ -385,7 +407,7 @@ public class DataSID {
* @param xmlData XML string of inventory
* @param xmlData XML string of inventory
* @return String
* @return String
*/
*/
public
static
String
setNetUsage
(
String
xmlData
)
public
String
setNetUsage
(
String
xmlData
)
{
{
try
{
try
{
InitialContext
cxt
=
new
InitialContext
();
InitialContext
cxt
=
new
InitialContext
();
...
@@ -398,7 +420,7 @@ public class DataSID {
...
@@ -398,7 +420,7 @@ public class DataSID {
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"
);
SchemaFactory
factory
=
SchemaFactory
.
newInstance
(
"http://www.w3.org/2001/XMLSchema"
);
Schema
schema
=
factory
.
newSchema
(
XML_NET_USAGE_SCHEMA
);
Schema
schema
=
factory
.
newSchema
(
this
.
xml_net_usage_schema
);
JAXBContext
context
=
JAXBContext
.
newInstance
(
NetCollectedData
.
class
);
JAXBContext
context
=
JAXBContext
.
newInstance
(
NetCollectedData
.
class
);
Unmarshaller
unmarshaller
=
context
.
createUnmarshaller
();
Unmarshaller
unmarshaller
=
context
.
createUnmarshaller
();
...
@@ -446,10 +468,10 @@ public class DataSID {
...
@@ -446,10 +468,10 @@ public class DataSID {
}
}
}
}
private
static
PreparedStatement
createNetUsageStatement
(
Connection
con
,
java
.
sql
.
Date
contactDate
,
private
PreparedStatement
createNetUsageStatement
(
Connection
con
,
java
.
sql
.
Date
contactDate
,
BigInteger
idpoint
,
Object
macaddr
,
String
collect_date
,
String
collect_time
,
BigInteger
down_kbits
,
BigInteger
idpoint
,
Object
macaddr
,
String
collect_date
,
String
collect_time
,
long
down_kbits
,
BigInteger
down_packages
,
BigInteger
up_kbits
,
BigInteger
up_packages
)
throws
SQLException
{
BigInteger
down_packages
,
long
up_kbits
,
BigInteger
up_packages
)
throws
SQLException
{
final
String
query
=
"INSERT INTO
"
+
SA_NET_USAGE
+
"
"
+
final
String
query
=
"INSERT INTO
net_usage
"
+
"(contact_date, id_point, macaddr, collect_date, collect_time, "
+
"(contact_date, id_point, macaddr, collect_date, collect_time, "
+
"down_kbits, down_packages, up_kbits, up_packages, ip, city_code) VALUES "
+
"down_kbits, down_packages, up_kbits, up_packages, ip, city_code) VALUES "
+
"(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"
;
"(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"
;
...
@@ -466,11 +488,11 @@ public class DataSID {
...
@@ -466,11 +488,11 @@ public class DataSID {
st
.
setTime
(
5
,
java
.
sql
.
Time
.
valueOf
(
collect_time
));
st
.
setTime
(
5
,
java
.
sql
.
Time
.
valueOf
(
collect_time
));
st
.
setLong
(
6
,
down_kbits
.
LongValue
()
);
st
.
setLong
(
6
,
down_kbits
);
st
.
setInt
(
7
,
down_packages
.
intValue
());
st
.
setInt
(
7
,
down_packages
.
intValue
());
st
.
setLong
(
8
,
up_kbits
.
LongValue
()
);
st
.
setLong
(
8
,
up_kbits
);
st
.
setInt
(
9
,
up_packages
.
intValue
());
st
.
setInt
(
9
,
up_packages
.
intValue
());
...
...
This diff is collapsed.
Click to expand it.
webservice/webservice.properties
0 → 100644
+
8
−
0
View file @
5a83bed2
xml_inventory_schema
=
../conf/collected-data.xsd
xml_net_usage_schema
=
../conf/net-collected-data.xsd
linux_agent_version
=
1.0.1
linux_agent_update_link
=
http://bisimmcdev.c3sl.ufpr.br/download/datasid-1.0.1-update.run
windows_agent_version
=
1.0.0
windows_agent_update_link
=
http://bisimmcdev.c3sl.ufpr.br/download/datasid-1.0.0-update.exe
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